rfkill: add notifier chains support
[pandora-kernel.git] / include / linux / rfkill.h
1 #ifndef __RFKILL_H
2 #define __RFKILL_H
3
4 /*
5  * Copyright (C) 2006 - 2007 Ivo van Doorn
6  * Copyright (C) 2007 Dmitry Torokhov
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the
20  * Free Software Foundation, Inc.,
21  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22  */
23
24 #include <linux/types.h>
25 #include <linux/kernel.h>
26 #include <linux/list.h>
27 #include <linux/mutex.h>
28 #include <linux/device.h>
29 #include <linux/leds.h>
30
31 /**
32  * enum rfkill_type - type of rfkill switch.
33  * RFKILL_TYPE_WLAN: switch is on a 802.11 wireless network device.
34  * RFKILL_TYPE_BLUETOOTH: switch is on a bluetooth device.
35  * RFKILL_TYPE_UWB: switch is on a ultra wideband device.
36  * RFKILL_TYPE_WIMAX: switch is on a WiMAX device.
37  * RFKILL_TYPE_WWAN: switch is on a wireless WAN device.
38  */
39 enum rfkill_type {
40         RFKILL_TYPE_WLAN ,
41         RFKILL_TYPE_BLUETOOTH,
42         RFKILL_TYPE_UWB,
43         RFKILL_TYPE_WIMAX,
44         RFKILL_TYPE_WWAN,
45         RFKILL_TYPE_MAX,
46 };
47
48 enum rfkill_state {
49         RFKILL_STATE_OFF        = 0,    /* Radio output blocked */
50         RFKILL_STATE_ON         = 1,    /* Radio output active */
51 };
52
53 /**
54  * struct rfkill - rfkill control structure.
55  * @name: Name of the switch.
56  * @type: Radio type which the button controls, the value stored
57  *      here should be a value from enum rfkill_type.
58  * @state: State of the switch, "ON" means radio can operate.
59  * @user_claim_unsupported: Whether the hardware supports exclusive
60  *      RF-kill control by userspace. Set this before registering.
61  * @user_claim: Set when the switch is controlled exlusively by userspace.
62  * @mutex: Guards switch state transitions
63  * @data: Pointer to the RF button drivers private data which will be
64  *      passed along when toggling radio state.
65  * @toggle_radio(): Mandatory handler to control state of the radio.
66  * @get_state(): handler to read current radio state from hardware,
67  *      may be called from atomic context, should return 0 on success.
68  * @led_trigger: A LED trigger for this button's LED.
69  * @dev: Device structure integrating the switch into device tree.
70  * @node: Used to place switch into list of all switches known to the
71  *      the system.
72  *
73  * This structure represents a RF switch located on a network device.
74  */
75 struct rfkill {
76         const char *name;
77         enum rfkill_type type;
78
79         enum rfkill_state state;
80         bool user_claim_unsupported;
81         bool user_claim;
82
83         struct mutex mutex;
84
85         void *data;
86         int (*toggle_radio)(void *data, enum rfkill_state state);
87         int (*get_state)(void *data, enum rfkill_state *state);
88
89 #ifdef CONFIG_RFKILL_LEDS
90         struct led_trigger led_trigger;
91 #endif
92
93         struct device dev;
94         struct list_head node;
95 };
96 #define to_rfkill(d)    container_of(d, struct rfkill, dev)
97
98 struct rfkill *rfkill_allocate(struct device *parent, enum rfkill_type type);
99 void rfkill_free(struct rfkill *rfkill);
100 int rfkill_register(struct rfkill *rfkill);
101 void rfkill_unregister(struct rfkill *rfkill);
102
103 int rfkill_force_state(struct rfkill *rfkill, enum rfkill_state state);
104
105 /**
106  * rfkill_get_led_name - Get the LED trigger name for the button's LED.
107  * This function might return a NULL pointer if registering of the
108  * LED trigger failed.
109  * Use this as "default_trigger" for the LED.
110  */
111 static inline char *rfkill_get_led_name(struct rfkill *rfkill)
112 {
113 #ifdef CONFIG_RFKILL_LEDS
114         return (char *)(rfkill->led_trigger.name);
115 #else
116         return NULL;
117 #endif
118 }
119
120 /* rfkill notification chain */
121 #define RFKILL_STATE_CHANGED            0x0001  /* state of a normal rfkill
122                                                    switch has changed */
123
124 int register_rfkill_notifier(struct notifier_block *nb);
125 int unregister_rfkill_notifier(struct notifier_block *nb);
126
127 #endif /* RFKILL_H */