blob: 741d1a62cc3f28e68ff4ce0f2e0ac5ef636aabb7 [file] [log] [blame]
Ivo van Doorncf4328c2007-05-07 00:34:20 -07001#ifndef __RFKILL_H
2#define __RFKILL_H
3
4/*
Ivo van Doornfe242cf2007-09-27 14:57:05 -07005 * Copyright (C) 2006 - 2007 Ivo van Doorn
Ivo van Doorncf4328c2007-05-07 00:34:20 -07006 * 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 Buesch135900c2007-09-27 21:33:12 +020029#include <linux/leds.h>
Ivo van Doorncf4328c2007-05-07 00:34:20 -070030
31/**
32 * enum rfkill_type - type of rfkill switch.
Michael Buesch279632b2007-09-27 14:42:42 +020033 * 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ález303d9bf2008-01-23 13:40:27 -080036 * RFKILL_TYPE_WIMAX: switch is on a WiMAX device.
Henrique de Moraes Holschuh477576a2008-06-23 17:23:01 -030037 * RFKILL_TYPE_WWAN: switch is on a wireless WAN device.
Ivo van Doorncf4328c2007-05-07 00:34:20 -070038 */
39enum rfkill_type {
Ivo van Doorn234a0ca2007-09-13 09:20:42 +020040 RFKILL_TYPE_WLAN ,
41 RFKILL_TYPE_BLUETOOTH,
Ivo van Doorne0665482007-09-13 09:21:31 +020042 RFKILL_TYPE_UWB,
Iñaky Pérez-González303d9bf2008-01-23 13:40:27 -080043 RFKILL_TYPE_WIMAX,
Henrique de Moraes Holschuh477576a2008-06-23 17:23:01 -030044 RFKILL_TYPE_WWAN,
Ivo van Doorn234a0ca2007-09-13 09:20:42 +020045 RFKILL_TYPE_MAX,
Ivo van Doorncf4328c2007-05-07 00:34:20 -070046};
47
48enum rfkill_state {
Henrique de Moraes Holschuh50056572008-06-23 17:46:42 -030049 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 */
Ivo van Doorncf4328c2007-05-07 00:34:20 -070052};
53
Henrique de Moraes Holschuh50056572008-06-23 17:46:42 -030054/*
55 * These are DEPRECATED, drivers using them should be verified to
56 * comply with the rfkill usage guidelines in Documentation/rfkill.txt
57 * and then converted to use the new names for rfkill_state
58 */
59#define RFKILL_STATE_OFF RFKILL_STATE_SOFT_BLOCKED
60#define RFKILL_STATE_ON RFKILL_STATE_UNBLOCKED
61
Ivo van Doorncf4328c2007-05-07 00:34:20 -070062/**
63 * struct rfkill - rfkill control structure.
64 * @name: Name of the switch.
65 * @type: Radio type which the button controls, the value stored
66 * here should be a value from enum rfkill_type.
Henrique de Moraes Holschuh50056572008-06-23 17:46:42 -030067 * @state: State of the switch, "UNBLOCKED" means radio can operate.
Michael Buesch20405c02007-09-27 21:34:23 +020068 * @user_claim_unsupported: Whether the hardware supports exclusive
69 * RF-kill control by userspace. Set this before registering.
Ivo van Doorncf4328c2007-05-07 00:34:20 -070070 * @user_claim: Set when the switch is controlled exlusively by userspace.
Henrique de Moraes Holschuhf1b23362008-07-21 21:18:19 -030071 * @mutex: Guards switch state transitions. It serializes callbacks
72 * and also protects the state.
Ivo van Doorncf4328c2007-05-07 00:34:20 -070073 * @data: Pointer to the RF button drivers private data which will be
74 * passed along when toggling radio state.
75 * @toggle_radio(): Mandatory handler to control state of the radio.
Henrique de Moraes Holschuh50056572008-06-23 17:46:42 -030076 * only RFKILL_STATE_SOFT_BLOCKED and RFKILL_STATE_UNBLOCKED are
77 * valid parameters.
Henrique de Moraes Holschuh801e49a2008-06-23 17:23:00 -030078 * @get_state(): handler to read current radio state from hardware,
79 * may be called from atomic context, should return 0 on success.
Henrique de Moraes Holschuh50056572008-06-23 17:46:42 -030080 * Either this handler OR judicious use of rfkill_force_state() is
81 * MANDATORY for any driver capable of RFKILL_STATE_HARD_BLOCKED.
Michael Buesch135900c2007-09-27 21:33:12 +020082 * @led_trigger: A LED trigger for this button's LED.
Ivo van Doorncf4328c2007-05-07 00:34:20 -070083 * @dev: Device structure integrating the switch into device tree.
84 * @node: Used to place switch into list of all switches known to the
85 * the system.
86 *
87 * This structure represents a RF switch located on a network device.
88 */
89struct rfkill {
Ivo van Doornc36befb2007-06-05 00:04:46 -070090 const char *name;
Ivo van Doorncf4328c2007-05-07 00:34:20 -070091 enum rfkill_type type;
92
Michael Buesch20405c02007-09-27 21:34:23 +020093 bool user_claim_unsupported;
Ivo van Doorncf4328c2007-05-07 00:34:20 -070094 bool user_claim;
95
Henrique de Moraes Holschuhf1b23362008-07-21 21:18:19 -030096 /* the mutex serializes callbacks and also protects
97 * the state */
Ivo van Doorncf4328c2007-05-07 00:34:20 -070098 struct mutex mutex;
Henrique de Moraes Holschuhf1b23362008-07-21 21:18:19 -030099 enum rfkill_state state;
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700100 void *data;
101 int (*toggle_radio)(void *data, enum rfkill_state state);
Henrique de Moraes Holschuh801e49a2008-06-23 17:23:00 -0300102 int (*get_state)(void *data, enum rfkill_state *state);
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700103
Michael Buesch135900c2007-09-27 21:33:12 +0200104#ifdef CONFIG_RFKILL_LEDS
105 struct led_trigger led_trigger;
106#endif
107
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700108 struct device dev;
109 struct list_head node;
110};
111#define to_rfkill(d) container_of(d, struct rfkill, dev)
112
113struct rfkill *rfkill_allocate(struct device *parent, enum rfkill_type type);
114void rfkill_free(struct rfkill *rfkill);
115int rfkill_register(struct rfkill *rfkill);
116void rfkill_unregister(struct rfkill *rfkill);
117
Henrique de Moraes Holschuh801e49a2008-06-23 17:23:00 -0300118int rfkill_force_state(struct rfkill *rfkill, enum rfkill_state state);
119
Michael Buesch135900c2007-09-27 21:33:12 +0200120/**
Henrique de Moraes Holschuh50056572008-06-23 17:46:42 -0300121 * rfkill_state_complement - return complementar state
122 * @state: state to return the complement of
123 *
124 * Returns RFKILL_STATE_SOFT_BLOCKED if @state is RFKILL_STATE_UNBLOCKED,
125 * returns RFKILL_STATE_UNBLOCKED otherwise.
126 */
127static inline enum rfkill_state rfkill_state_complement(enum rfkill_state state)
128{
129 return (state == RFKILL_STATE_UNBLOCKED) ?
130 RFKILL_STATE_SOFT_BLOCKED : RFKILL_STATE_UNBLOCKED;
131}
132
133/**
Michael Buesch135900c2007-09-27 21:33:12 +0200134 * rfkill_get_led_name - Get the LED trigger name for the button's LED.
135 * This function might return a NULL pointer if registering of the
136 * LED trigger failed.
137 * Use this as "default_trigger" for the LED.
138 */
139static inline char *rfkill_get_led_name(struct rfkill *rfkill)
140{
141#ifdef CONFIG_RFKILL_LEDS
142 return (char *)(rfkill->led_trigger.name);
143#else
144 return NULL;
145#endif
146}
147
Henrique de Moraes Holschuh79399a82008-06-23 17:23:03 -0300148/* rfkill notification chain */
149#define RFKILL_STATE_CHANGED 0x0001 /* state of a normal rfkill
150 switch has changed */
151
152int register_rfkill_notifier(struct notifier_block *nb);
153int unregister_rfkill_notifier(struct notifier_block *nb);
154
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700155#endif /* RFKILL_H */