Linux Audio

Check our new training course

Loading...
v3.1
 
 1/*
 2 * Support for rfkill through the OLPC XO-1 laptop embedded controller
 3 *
 4 * Copyright (C) 2010 One Laptop per Child
 5 *
 6 * This program is free software; you can redistribute it and/or modify
 7 * it under the terms of the GNU General Public License as published by
 8 * the Free Software Foundation; either version 2 of the License, or
 9 * (at your option) any later version.
10 */
11
12#include <linux/module.h>
13#include <linux/platform_device.h>
14#include <linux/rfkill.h>
 
15
16#include <asm/olpc.h>
17
18static int rfkill_set_block(void *data, bool blocked)
19{
20	unsigned char cmd;
 
 
 
 
 
21	if (blocked)
22		cmd = EC_WLAN_ENTER_RESET;
23	else
24		cmd = EC_WLAN_LEAVE_RESET;
25
26	return olpc_ec_cmd(cmd, NULL, 0, NULL, 0);
 
 
 
 
27}
28
29static const struct rfkill_ops rfkill_ops = {
30	.set_block = rfkill_set_block,
31};
32
33static int __devinit xo1_rfkill_probe(struct platform_device *pdev)
34{
35	struct rfkill *rfk;
36	int r;
37
38	rfk = rfkill_alloc(pdev->name, &pdev->dev, RFKILL_TYPE_WLAN,
39			   &rfkill_ops, NULL);
40	if (!rfk)
41		return -ENOMEM;
42
43	r = rfkill_register(rfk);
44	if (r) {
45		rfkill_destroy(rfk);
46		return r;
47	}
48
49	platform_set_drvdata(pdev, rfk);
50	return 0;
51}
52
53static int __devexit xo1_rfkill_remove(struct platform_device *pdev)
54{
55	struct rfkill *rfk = platform_get_drvdata(pdev);
56	rfkill_unregister(rfk);
57	rfkill_destroy(rfk);
58	return 0;
59}
60
61static struct platform_driver xo1_rfkill_driver = {
62	.driver = {
63		.name = "xo1-rfkill",
64		.owner = THIS_MODULE,
65	},
66	.probe		= xo1_rfkill_probe,
67	.remove		= __devexit_p(xo1_rfkill_remove),
68};
69
70static int __init xo1_rfkill_init(void)
71{
72	return platform_driver_register(&xo1_rfkill_driver);
73}
74
75static void __exit xo1_rfkill_exit(void)
76{
77	platform_driver_unregister(&xo1_rfkill_driver);
78}
79
80MODULE_AUTHOR("Daniel Drake <dsd@laptop.org>");
81MODULE_LICENSE("GPL");
82MODULE_ALIAS("platform:xo1-rfkill");
83
84module_init(xo1_rfkill_init);
85module_exit(xo1_rfkill_exit);
v6.2
 1// SPDX-License-Identifier: GPL-2.0-or-later
 2/*
 3 * Support for rfkill through the OLPC XO-1 laptop embedded controller
 4 *
 5 * Copyright (C) 2010 One Laptop per Child
 
 
 
 
 
 6 */
 7
 8#include <linux/module.h>
 9#include <linux/platform_device.h>
10#include <linux/rfkill.h>
11#include <linux/olpc-ec.h>
12
13static bool card_blocked;
14
15static int rfkill_set_block(void *data, bool blocked)
16{
17	unsigned char cmd;
18	int r;
19
20	if (blocked == card_blocked)
21		return 0;
22
23	if (blocked)
24		cmd = EC_WLAN_ENTER_RESET;
25	else
26		cmd = EC_WLAN_LEAVE_RESET;
27
28	r = olpc_ec_cmd(cmd, NULL, 0, NULL, 0);
29	if (r == 0)
30		card_blocked = blocked;
31
32	return r;
33}
34
35static const struct rfkill_ops rfkill_ops = {
36	.set_block = rfkill_set_block,
37};
38
39static int xo1_rfkill_probe(struct platform_device *pdev)
40{
41	struct rfkill *rfk;
42	int r;
43
44	rfk = rfkill_alloc(pdev->name, &pdev->dev, RFKILL_TYPE_WLAN,
45			   &rfkill_ops, NULL);
46	if (!rfk)
47		return -ENOMEM;
48
49	r = rfkill_register(rfk);
50	if (r) {
51		rfkill_destroy(rfk);
52		return r;
53	}
54
55	platform_set_drvdata(pdev, rfk);
56	return 0;
57}
58
59static int xo1_rfkill_remove(struct platform_device *pdev)
60{
61	struct rfkill *rfk = platform_get_drvdata(pdev);
62	rfkill_unregister(rfk);
63	rfkill_destroy(rfk);
64	return 0;
65}
66
67static struct platform_driver xo1_rfkill_driver = {
68	.driver = {
69		.name = "xo1-rfkill",
 
70	},
71	.probe		= xo1_rfkill_probe,
72	.remove		= xo1_rfkill_remove,
73};
74
75module_platform_driver(xo1_rfkill_driver);
 
 
 
 
 
 
 
 
76
77MODULE_AUTHOR("Daniel Drake <dsd@laptop.org>");
78MODULE_LICENSE("GPL");
79MODULE_ALIAS("platform:xo1-rfkill");