rfkill.h 4.6 KB
Newer Older
1 2 3 4
#ifndef __RFKILL_H
#define __RFKILL_H

/*
5
 * Copyright (C) 2006 - 2007 Ivo van Doorn
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
 * Copyright (C) 2007 Dmitry Torokhov
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the
 * Free Software Foundation, Inc.,
 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/list.h>
#include <linux/mutex.h>
#include <linux/device.h>
29
#include <linux/leds.h>
30 31 32

/**
 * enum rfkill_type - type of rfkill switch.
33 34 35
 * RFKILL_TYPE_WLAN: switch is on a 802.11 wireless network device.
 * RFKILL_TYPE_BLUETOOTH: switch is on a bluetooth device.
 * 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 {
I
Ivo van Doorn 已提交
40 41
	RFKILL_TYPE_WLAN ,
	RFKILL_TYPE_BLUETOOTH,
42
	RFKILL_TYPE_UWB,
43
	RFKILL_TYPE_WIMAX,
44
	RFKILL_TYPE_WWAN,
I
Ivo van Doorn 已提交
45
	RFKILL_TYPE_MAX,
46 47 48
};

enum rfkill_state {
49 50 51
	RFKILL_STATE_SOFT_BLOCKED = 0,	/* Radio output blocked */
	RFKILL_STATE_UNBLOCKED    = 1,	/* Radio output allowed */
	RFKILL_STATE_HARD_BLOCKED = 2,	/* Output blocked, non-overrideable */
52
	RFKILL_STATE_MAX,		/* marker for last valid state */
53 54 55 56 57 58 59
};

/**
 * struct rfkill - rfkill control structure.
 * @name: Name of the switch.
 * @type: Radio type which the button controls, the value stored
 *	here should be a value from enum rfkill_type.
60
 * @state: State of the switch, "UNBLOCKED" means radio can operate.
61 62
 * @mutex: Guards switch state transitions.  It serializes callbacks
 *	and also protects the state.
63 64 65
 * @data: Pointer to the RF button drivers private data which will be
 *	passed along when toggling radio state.
 * @toggle_radio(): Mandatory handler to control state of the radio.
66 67
 *	only RFKILL_STATE_SOFT_BLOCKED and RFKILL_STATE_UNBLOCKED are
 *	valid parameters.
68 69
 * @get_state(): handler to read current radio state from hardware,
 *      may be called from atomic context, should return 0 on success.
70 71
 *      Either this handler OR judicious use of rfkill_force_state() is
 *      MANDATORY for any driver capable of RFKILL_STATE_HARD_BLOCKED.
72
 * @led_trigger: A LED trigger for this button's LED.
73 74 75 76 77 78 79
 * @dev: Device structure integrating the switch into device tree.
 * @node: Used to place switch into list of all switches known to the
 *	the system.
 *
 * This structure represents a RF switch located on a network device.
 */
struct rfkill {
80
	const char *name;
81 82
	enum rfkill_type type;

83 84
	/* the mutex serializes callbacks and also protects
	 * the state */
85
	struct mutex mutex;
86
	enum rfkill_state state;
87 88
	void *data;
	int (*toggle_radio)(void *data, enum rfkill_state state);
89
	int (*get_state)(void *data, enum rfkill_state *state);
90

91 92 93 94
#ifdef CONFIG_RFKILL_LEDS
	struct led_trigger led_trigger;
#endif

95 96
	struct device dev;
	struct list_head node;
97
	enum rfkill_state state_for_resume;
98 99 100
};
#define to_rfkill(d)	container_of(d, struct rfkill, dev)

101 102
struct rfkill * __must_check rfkill_allocate(struct device *parent,
					     enum rfkill_type type);
103
void rfkill_free(struct rfkill *rfkill);
104
int __must_check rfkill_register(struct rfkill *rfkill);
105 106
void rfkill_unregister(struct rfkill *rfkill);

107
int rfkill_force_state(struct rfkill *rfkill, enum rfkill_state state);
108
int rfkill_set_default(enum rfkill_type type, enum rfkill_state state);
109

110 111 112 113 114 115 116 117 118 119 120 121 122
/**
 * rfkill_state_complement - return complementar state
 * @state: state to return the complement of
 *
 * Returns RFKILL_STATE_SOFT_BLOCKED if @state is RFKILL_STATE_UNBLOCKED,
 * returns RFKILL_STATE_UNBLOCKED otherwise.
 */
static inline enum rfkill_state rfkill_state_complement(enum rfkill_state state)
{
	return (state == RFKILL_STATE_UNBLOCKED) ?
		RFKILL_STATE_SOFT_BLOCKED : RFKILL_STATE_UNBLOCKED;
}

123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
/**
 * rfkill_get_led_name - Get the LED trigger name for the button's LED.
 * This function might return a NULL pointer if registering of the
 * LED trigger failed.
 * Use this as "default_trigger" for the LED.
 */
static inline char *rfkill_get_led_name(struct rfkill *rfkill)
{
#ifdef CONFIG_RFKILL_LEDS
	return (char *)(rfkill->led_trigger.name);
#else
	return NULL;
#endif
}

138
#endif /* RFKILL_H */