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. |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 36 | */ |
| 37 | enum rfkill_type { |
Ivo van Doorn | 234a0ca | 2007-09-13 09:20:42 +0200 | [diff] [blame] | 38 | RFKILL_TYPE_WLAN , |
| 39 | RFKILL_TYPE_BLUETOOTH, |
Ivo van Doorn | e0665486 | 2007-09-13 09:21:31 +0200 | [diff] [blame] | 40 | RFKILL_TYPE_UWB, |
Ivo van Doorn | 234a0ca | 2007-09-13 09:20:42 +0200 | [diff] [blame] | 41 | RFKILL_TYPE_MAX, |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 42 | }; |
| 43 | |
| 44 | enum rfkill_state { |
| 45 | RFKILL_STATE_OFF = 0, |
| 46 | RFKILL_STATE_ON = 1, |
| 47 | }; |
| 48 | |
| 49 | /** |
| 50 | * struct rfkill - rfkill control structure. |
| 51 | * @name: Name of the switch. |
| 52 | * @type: Radio type which the button controls, the value stored |
| 53 | * here should be a value from enum rfkill_type. |
| 54 | * @state: State of the switch (on/off). |
Michael Buesch | 20405c0 | 2007-09-27 21:34:23 +0200 | [diff] [blame] | 55 | * @user_claim_unsupported: Whether the hardware supports exclusive |
| 56 | * RF-kill control by userspace. Set this before registering. |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 57 | * @user_claim: Set when the switch is controlled exlusively by userspace. |
| 58 | * @mutex: Guards switch state transitions |
| 59 | * @data: Pointer to the RF button drivers private data which will be |
| 60 | * passed along when toggling radio state. |
| 61 | * @toggle_radio(): Mandatory handler to control state of the radio. |
Michael Buesch | 135900c | 2007-09-27 21:33:12 +0200 | [diff] [blame] | 62 | * @led_trigger: A LED trigger for this button's LED. |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 63 | * @dev: Device structure integrating the switch into device tree. |
| 64 | * @node: Used to place switch into list of all switches known to the |
| 65 | * the system. |
| 66 | * |
| 67 | * This structure represents a RF switch located on a network device. |
| 68 | */ |
| 69 | struct rfkill { |
Ivo van Doorn | c36befb | 2007-06-05 00:04:46 -0700 | [diff] [blame] | 70 | const char *name; |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 71 | enum rfkill_type type; |
| 72 | |
| 73 | enum rfkill_state state; |
Michael Buesch | 20405c0 | 2007-09-27 21:34:23 +0200 | [diff] [blame] | 74 | bool user_claim_unsupported; |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 75 | bool user_claim; |
| 76 | |
| 77 | struct mutex mutex; |
| 78 | |
| 79 | void *data; |
| 80 | int (*toggle_radio)(void *data, enum rfkill_state state); |
| 81 | |
Michael Buesch | 135900c | 2007-09-27 21:33:12 +0200 | [diff] [blame] | 82 | #ifdef CONFIG_RFKILL_LEDS |
| 83 | struct led_trigger led_trigger; |
| 84 | #endif |
| 85 | |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 86 | struct device dev; |
| 87 | struct list_head node; |
| 88 | }; |
| 89 | #define to_rfkill(d) container_of(d, struct rfkill, dev) |
| 90 | |
| 91 | struct rfkill *rfkill_allocate(struct device *parent, enum rfkill_type type); |
| 92 | void rfkill_free(struct rfkill *rfkill); |
| 93 | int rfkill_register(struct rfkill *rfkill); |
| 94 | void rfkill_unregister(struct rfkill *rfkill); |
| 95 | |
Michael Buesch | 135900c | 2007-09-27 21:33:12 +0200 | [diff] [blame] | 96 | /** |
| 97 | * rfkill_get_led_name - Get the LED trigger name for the button's LED. |
| 98 | * This function might return a NULL pointer if registering of the |
| 99 | * LED trigger failed. |
| 100 | * Use this as "default_trigger" for the LED. |
| 101 | */ |
| 102 | static inline char *rfkill_get_led_name(struct rfkill *rfkill) |
| 103 | { |
| 104 | #ifdef CONFIG_RFKILL_LEDS |
| 105 | return (char *)(rfkill->led_trigger.name); |
| 106 | #else |
| 107 | return NULL; |
| 108 | #endif |
| 109 | } |
| 110 | |
Ivo van Doorn | cf4328c | 2007-05-07 00:34:20 -0700 | [diff] [blame] | 111 | #endif /* RFKILL_H */ |