Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 1 | #ifndef __RFKILL_H |
| 2 | #define __RFKILL_H |
| 3 | |
| 4 | /* |
Ivo van Doorn | fe242cf | 2007-09-27 14:57:05 -0700 | [diff] [blame] | 5 | * Copyright (C) 2006 - 2007 Ivo van Doorn |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 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> |
Michael Buesch | 135900c | 2007-09-27 21:33:12 +0200 | [diff] [blame] | 29 | #include <linux/leds.h> |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 30 | |
| 31 | /** |
| 32 | * enum rfkill_type - type of rfkill switch. |
Michael Buesch | 279632b | 2007-09-27 14:42:42 +0200 | [diff] [blame] | 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. |
Iñaky Pérez-González | 303d9bf | 2008-01-23 13:40:27 -0800 | [diff] [blame] | 36 | * RFKILL_TYPE_WIMAX: switch is on a WiMAX device. |
Henrique de Moraes Holschuh | 477576a | 2008-06-23 17:23:01 -0300 | [diff] [blame] | 37 | * RFKILL_TYPE_WWAN: switch is on a wireless WAN device. |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 38 | */ |
| 39 | enum rfkill_type { |
Ivo van Doorn | 234a0ca | 2007-09-13 09:20:42 +0200 | [diff] [blame] | 40 | RFKILL_TYPE_WLAN , |
| 41 | RFKILL_TYPE_BLUETOOTH, |
Ivo van Doorn | e0665486 | 2007-09-13 09:21:31 +0200 | [diff] [blame] | 42 | RFKILL_TYPE_UWB, |
Iñaky Pérez-González | 303d9bf | 2008-01-23 13:40:27 -0800 | [diff] [blame] | 43 | RFKILL_TYPE_WIMAX, |
Henrique de Moraes Holschuh | 477576a | 2008-06-23 17:23:01 -0300 | [diff] [blame] | 44 | RFKILL_TYPE_WWAN, |
Ivo van Doorn | 234a0ca | 2007-09-13 09:20:42 +0200 | [diff] [blame] | 45 | RFKILL_TYPE_MAX, |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 46 | }; |
| 47 | |
| 48 | enum rfkill_state { |
Henrique de Moraes Holschuh | 5005657 | 2008-06-23 17:46:42 -0300 | [diff] [blame] | 49 | RFKILL_STATE_SOFT_BLOCKED = 0, /* Radio output blocked */ |
| 50 | RFKILL_STATE_UNBLOCKED = 1, /* Radio output allowed */ |
| 51 | RFKILL_STATE_HARD_BLOCKED = 2, /* Output blocked, non-overrideable */ |
Henrique de Moraes Holschuh | 96c8760 | 2008-08-02 15:11:00 -0300 | [diff] [blame] | 52 | RFKILL_STATE_MAX, /* marker for last valid state */ |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 53 | }; |
| 54 | |
Henrique de Moraes Holschuh | 5005657 | 2008-06-23 17:46:42 -0300 | [diff] [blame] | 55 | /* |
| 56 | * These are DEPRECATED, drivers using them should be verified to |
| 57 | * comply with the rfkill usage guidelines in Documentation/rfkill.txt |
| 58 | * and then converted to use the new names for rfkill_state |
| 59 | */ |
| 60 | #define RFKILL_STATE_OFF RFKILL_STATE_SOFT_BLOCKED |
| 61 | #define RFKILL_STATE_ON RFKILL_STATE_UNBLOCKED |
| 62 | |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 63 | /** |
| 64 | * struct rfkill - rfkill control structure. |
| 65 | * @name: Name of the switch. |
| 66 | * @type: Radio type which the button controls, the value stored |
| 67 | * here should be a value from enum rfkill_type. |
Henrique de Moraes Holschuh | 5005657 | 2008-06-23 17:46:42 -0300 | [diff] [blame] | 68 | * @state: State of the switch, "UNBLOCKED" means radio can operate. |
Michael Buesch | 20405c0 | 2007-09-27 21:34:23 +0200 | [diff] [blame] | 69 | * @user_claim_unsupported: Whether the hardware supports exclusive |
| 70 | * RF-kill control by userspace. Set this before registering. |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 71 | * @user_claim: Set when the switch is controlled exlusively by userspace. |
Henrique de Moraes Holschuh | f1b2336 | 2008-07-21 21:18:19 -0300 | [diff] [blame] | 72 | * @mutex: Guards switch state transitions. It serializes callbacks |
| 73 | * and also protects the state. |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 74 | * @data: Pointer to the RF button drivers private data which will be |
| 75 | * passed along when toggling radio state. |
| 76 | * @toggle_radio(): Mandatory handler to control state of the radio. |
Henrique de Moraes Holschuh | 5005657 | 2008-06-23 17:46:42 -0300 | [diff] [blame] | 77 | * only RFKILL_STATE_SOFT_BLOCKED and RFKILL_STATE_UNBLOCKED are |
| 78 | * valid parameters. |
Henrique de Moraes Holschuh | 801e49a | 2008-06-23 17:23:00 -0300 | [diff] [blame] | 79 | * @get_state(): handler to read current radio state from hardware, |
| 80 | * may be called from atomic context, should return 0 on success. |
Henrique de Moraes Holschuh | 5005657 | 2008-06-23 17:46:42 -0300 | [diff] [blame] | 81 | * Either this handler OR judicious use of rfkill_force_state() is |
| 82 | * MANDATORY for any driver capable of RFKILL_STATE_HARD_BLOCKED. |
Michael Buesch | 135900c | 2007-09-27 21:33:12 +0200 | [diff] [blame] | 83 | * @led_trigger: A LED trigger for this button's LED. |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 84 | * @dev: Device structure integrating the switch into device tree. |
| 85 | * @node: Used to place switch into list of all switches known to the |
| 86 | * the system. |
| 87 | * |
| 88 | * This structure represents a RF switch located on a network device. |
| 89 | */ |
| 90 | struct rfkill { |
Ivo van Doorn | c36befb | 2007-06-05 00:04:46 -0700 | [diff] [blame] | 91 | const char *name; |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 92 | enum rfkill_type type; |
| 93 | |
Michael Buesch | 20405c0 | 2007-09-27 21:34:23 +0200 | [diff] [blame] | 94 | bool user_claim_unsupported; |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 95 | bool user_claim; |
| 96 | |
Henrique de Moraes Holschuh | f1b2336 | 2008-07-21 21:18:19 -0300 | [diff] [blame] | 97 | /* the mutex serializes callbacks and also protects |
| 98 | * the state */ |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 99 | struct mutex mutex; |
Henrique de Moraes Holschuh | f1b2336 | 2008-07-21 21:18:19 -0300 | [diff] [blame] | 100 | enum rfkill_state state; |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 101 | void *data; |
| 102 | int (*toggle_radio)(void *data, enum rfkill_state state); |
Henrique de Moraes Holschuh | 801e49a | 2008-06-23 17:23:00 -0300 | [diff] [blame] | 103 | int (*get_state)(void *data, enum rfkill_state *state); |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 104 | |
Michael Buesch | 135900c | 2007-09-27 21:33:12 +0200 | [diff] [blame] | 105 | #ifdef CONFIG_RFKILL_LEDS |
| 106 | struct led_trigger led_trigger; |
| 107 | #endif |
| 108 | |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 109 | struct device dev; |
| 110 | struct list_head node; |
| 111 | }; |
| 112 | #define to_rfkill(d) container_of(d, struct rfkill, dev) |
| 113 | |
Henrique de Moraes Holschuh | 77fba13 | 2008-08-02 15:10:59 -0300 | [diff] [blame] | 114 | struct rfkill * __must_check rfkill_allocate(struct device *parent, |
| 115 | enum rfkill_type type); |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 116 | void rfkill_free(struct rfkill *rfkill); |
Henrique de Moraes Holschuh | 77fba13 | 2008-08-02 15:10:59 -0300 | [diff] [blame] | 117 | int __must_check rfkill_register(struct rfkill *rfkill); |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 118 | void rfkill_unregister(struct rfkill *rfkill); |
| 119 | |
Henrique de Moraes Holschuh | 801e49a | 2008-06-23 17:23:00 -0300 | [diff] [blame] | 120 | int rfkill_force_state(struct rfkill *rfkill, enum rfkill_state state); |
Henrique de Moraes Holschuh | 9961920 | 2008-08-02 15:10:58 -0300 | [diff] [blame] | 121 | int rfkill_set_default(enum rfkill_type type, enum rfkill_state state); |
Henrique de Moraes Holschuh | 801e49a | 2008-06-23 17:23:00 -0300 | [diff] [blame] | 122 | |
Michael Buesch | 135900c | 2007-09-27 21:33:12 +0200 | [diff] [blame] | 123 | /** |
Henrique de Moraes Holschuh | 5005657 | 2008-06-23 17:46:42 -0300 | [diff] [blame] | 124 | * rfkill_state_complement - return complementar state |
| 125 | * @state: state to return the complement of |
| 126 | * |
| 127 | * Returns RFKILL_STATE_SOFT_BLOCKED if @state is RFKILL_STATE_UNBLOCKED, |
| 128 | * returns RFKILL_STATE_UNBLOCKED otherwise. |
| 129 | */ |
| 130 | static inline enum rfkill_state rfkill_state_complement(enum rfkill_state state) |
| 131 | { |
| 132 | return (state == RFKILL_STATE_UNBLOCKED) ? |
| 133 | RFKILL_STATE_SOFT_BLOCKED : RFKILL_STATE_UNBLOCKED; |
| 134 | } |
| 135 | |
| 136 | /** |
Michael Buesch | 135900c | 2007-09-27 21:33:12 +0200 | [diff] [blame] | 137 | * rfkill_get_led_name - Get the LED trigger name for the button's LED. |
| 138 | * This function might return a NULL pointer if registering of the |
| 139 | * LED trigger failed. |
| 140 | * Use this as "default_trigger" for the LED. |
| 141 | */ |
| 142 | static inline char *rfkill_get_led_name(struct rfkill *rfkill) |
| 143 | { |
| 144 | #ifdef CONFIG_RFKILL_LEDS |
| 145 | return (char *)(rfkill->led_trigger.name); |
| 146 | #else |
| 147 | return NULL; |
| 148 | #endif |
| 149 | } |
| 150 | |
Henrique de Moraes Holschuh | 79399a8 | 2008-06-23 17:23:03 -0300 | [diff] [blame] | 151 | /* rfkill notification chain */ |
| 152 | #define RFKILL_STATE_CHANGED 0x0001 /* state of a normal rfkill |
| 153 | switch has changed */ |
| 154 | |
| 155 | int register_rfkill_notifier(struct notifier_block *nb); |
| 156 | int unregister_rfkill_notifier(struct notifier_block *nb); |
| 157 | |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 158 | #endif /* RFKILL_H */ |