blob: e3ab21d7fc7f1973ec9483885012d83e800e1eb9 [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.
Ivo van Doorncf4328c2007-05-07 00:34:20 -070037 */
38enum rfkill_type {
Ivo van Doorn234a0ca2007-09-13 09:20:42 +020039 RFKILL_TYPE_WLAN ,
40 RFKILL_TYPE_BLUETOOTH,
Ivo van Doorne06654862007-09-13 09:21:31 +020041 RFKILL_TYPE_UWB,
Iñaky Pérez-González303d9bf2008-01-23 13:40:27 -080042 RFKILL_TYPE_WIMAX,
Ivo van Doorn234a0ca2007-09-13 09:20:42 +020043 RFKILL_TYPE_MAX,
Ivo van Doorncf4328c2007-05-07 00:34:20 -070044};
45
46enum rfkill_state {
47 RFKILL_STATE_OFF = 0,
48 RFKILL_STATE_ON = 1,
49};
50
51/**
52 * struct rfkill - rfkill control structure.
53 * @name: Name of the switch.
54 * @type: Radio type which the button controls, the value stored
55 * here should be a value from enum rfkill_type.
56 * @state: State of the switch (on/off).
Michael Buesch20405c02007-09-27 21:34:23 +020057 * @user_claim_unsupported: Whether the hardware supports exclusive
58 * RF-kill control by userspace. Set this before registering.
Ivo van Doorncf4328c2007-05-07 00:34:20 -070059 * @user_claim: Set when the switch is controlled exlusively by userspace.
60 * @mutex: Guards switch state transitions
61 * @data: Pointer to the RF button drivers private data which will be
62 * passed along when toggling radio state.
63 * @toggle_radio(): Mandatory handler to control state of the radio.
Michael Buesch135900c2007-09-27 21:33:12 +020064 * @led_trigger: A LED trigger for this button's LED.
Ivo van Doorncf4328c2007-05-07 00:34:20 -070065 * @dev: Device structure integrating the switch into device tree.
66 * @node: Used to place switch into list of all switches known to the
67 * the system.
68 *
69 * This structure represents a RF switch located on a network device.
70 */
71struct rfkill {
Ivo van Doornc36befb2007-06-05 00:04:46 -070072 const char *name;
Ivo van Doorncf4328c2007-05-07 00:34:20 -070073 enum rfkill_type type;
74
75 enum rfkill_state state;
Michael Buesch20405c02007-09-27 21:34:23 +020076 bool user_claim_unsupported;
Ivo van Doorncf4328c2007-05-07 00:34:20 -070077 bool user_claim;
78
79 struct mutex mutex;
80
81 void *data;
82 int (*toggle_radio)(void *data, enum rfkill_state state);
83
Michael Buesch135900c2007-09-27 21:33:12 +020084#ifdef CONFIG_RFKILL_LEDS
85 struct led_trigger led_trigger;
86#endif
87
Ivo van Doorncf4328c2007-05-07 00:34:20 -070088 struct device dev;
89 struct list_head node;
90};
91#define to_rfkill(d) container_of(d, struct rfkill, dev)
92
93struct rfkill *rfkill_allocate(struct device *parent, enum rfkill_type type);
94void rfkill_free(struct rfkill *rfkill);
95int rfkill_register(struct rfkill *rfkill);
96void rfkill_unregister(struct rfkill *rfkill);
97
Michael Buesch135900c2007-09-27 21:33:12 +020098/**
99 * rfkill_get_led_name - Get the LED trigger name for the button's LED.
100 * This function might return a NULL pointer if registering of the
101 * LED trigger failed.
102 * Use this as "default_trigger" for the LED.
103 */
104static inline char *rfkill_get_led_name(struct rfkill *rfkill)
105{
106#ifdef CONFIG_RFKILL_LEDS
107 return (char *)(rfkill->led_trigger.name);
108#else
109 return NULL;
110#endif
111}
112
Ivo van Doorncf4328c2007-05-07 00:34:20 -0700113#endif /* RFKILL_H */