login
Header Space

 
 

[PATCH 5/8] rfkill: add read-only rfkill switch support

Score:
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: <linux-kernel@...>
Cc: Henrique de Moraes Holschuh <hmh@...>, Ivo van Doorn <IvDoorn@...>, John W. Linville <linville@...>, Dmitry Torokhov <dtor@...>
Date: Friday, April 11, 2008 - 4:37 pm

Some devices (notably laptops) have read-only rfkill switches.  Those
devices are slider or rocker switches that are *physically* manipulated by
the user, most of the time tied to hardware or firmware functions that
automatically rf-kill and/or hot-unplug radio devices when in the "radios
off" position.

Software must not (and in fact, cannot) attempt to change the state of any
such switch.  These switches exist because of international regulations
regarding radio emission devices on airplanes and other sensitive areas.
They must never be overriden.

While one can easily report the *change* of state of these switches using
the input layer EV_SW SW_RADIO event, typically userspace needs to have
immediate access of the current switch state.  It makes sense to have all
radio kill switches grouped under the rfkill sysfs interface instead of
every driver doing its own thing.

Make the toggle_radio() hook no longer be mandatory.  read-only rfkill
switches are those who have their toggle_radio() hook set to NULL.

Signed-off-by: Henrique de Moraes Holschuh <hmh@hmh.eng.br>
Cc: Ivo van Doorn <IvDoorn@gmail.com>
Cc: John W. Linville <linville@tuxdriver.com>
Cc: Dmitry Torokhov <dtor@mail.ru>
---
 include/linux/rfkill.h |    3 ++-
 net/rfkill/rfkill.c    |   18 +++++++++++++-----
 2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
index 844e961..931d32b 100644
--- a/include/linux/rfkill.h
+++ b/include/linux/rfkill.h
@@ -60,7 +60,8 @@ enum rfkill_state {
  * @mutex: Guards switch state transitions
  * @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.
+ * @toggle_radio(): handler to control state of the radio. Must be
+ *	NULL for read-only switches.
  * @get_state(): handler to read current radio state from hardware,
  *      may be called from atomic context, should return 0 on success.
  * @led_trigger: A LED trigger for this button's LED.
diff --git a/net/rfkill/rfkill.c b/net/rfkill/rfkill.c
index 88b0558..d149d94 100644
--- a/net/rfkill/rfkill.c
+++ b/net/rfkill/rfkill.c
@@ -81,7 +81,7 @@ static int rfkill_toggle_radio(struct rfkill *rfkill,
 	    !rfkill->get_state(rfkill->data, &newstate))
 		rfkill->state = newstate;
 
-	if (state != rfkill->state) {
+	if (rfkill->toggle_radio && state != rfkill->state) {
 		retval = rfkill->toggle_radio(rfkill->data, state);
 		if (!retval)
 			rfkill->state = state;
@@ -196,6 +196,9 @@ static ssize_t rfkill_state_store(struct device *dev,
 	unsigned int state = simple_strtoul(buf, NULL, 0);
 	int error;
 
+	if (!rfkill->toggle_radio)
+		return -EACCES;
+
 	if (!capable(CAP_NET_ADMIN))
 		return -EPERM;
 
@@ -278,7 +281,8 @@ static int rfkill_suspend(struct device *dev, pm_message_t state)
 		if (state.event & PM_EVENT_SLEEP) {
 			mutex_lock(&rfkill->mutex);
 
-			if (rfkill->state == RFKILL_STATE_ON)
+			if (rfkill->state == RFKILL_STATE_ON &&
+			    rfkill->toggle_radio)
 				rfkill->toggle_radio(rfkill->data,
 						     RFKILL_STATE_OFF);
 
@@ -298,7 +302,8 @@ static int rfkill_resume(struct device *dev)
 	if (dev->power.power_state.event != PM_EVENT_ON) {
 		mutex_lock(&rfkill->mutex);
 
-		if (rfkill->state == RFKILL_STATE_ON)
+		if (rfkill->state == RFKILL_STATE_ON &&
+		    rfkill->toggle_radio)
 			rfkill->toggle_radio(rfkill->data, RFKILL_STATE_ON);
 
 		mutex_unlock(&rfkill->mutex);
@@ -427,11 +432,14 @@ int rfkill_register(struct rfkill *rfkill)
 	struct device *dev = &rfkill->dev;
 	int error;
 
-	if (!rfkill->toggle_radio)
-		return -EINVAL;
 	if (rfkill->type >= RFKILL_TYPE_MAX)
 		return -EINVAL;
 
+	if (!rfkill->toggle_radio) {
+		rfkill->user_claim_unsupported = 1;
+		rfkill->user_claim = 0;
+	}
+
 	snprintf(dev->bus_id, sizeof(dev->bus_id),
 		 "rfkill%ld", (long)atomic_inc_return(&rfkill_no) - 1);
 
-- 
1.5.4.4

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[GIT PATCH] rfkill support for r/w and r/o rfkill switches, Henrique de Moraes Holschuh..., (Fri Apr 11, 4:37 pm)
[PATCH 6/8] rfkill: add the WWAN radio type, Henrique de Moraes Holschuh..., (Fri Apr 11, 4:37 pm)
Re: [PATCH 6/8] rfkill: add the WWAN radio type, Ivo van Doorn, (Sat Apr 12, 6:36 am)
Re: [PATCH 6/8] rfkill: add the WWAN radio type, Henrique de Moraes Holschuh..., (Sat Apr 12, 8:15 am)
Re: [PATCH 6/8] rfkill: add the WWAN radio type, Inaky Perez-Gonzalez, (Sat Apr 12, 7:23 pm)
Re: [PATCH 6/8] rfkill: add the WWAN radio type, Henrique de Moraes Holschuh..., (Sun Apr 13, 1:25 pm)
Re: [PATCH 6/8] rfkill: add the WWAN radio type, Ivo van Doorn, (Sun Apr 13, 1:37 pm)
Re: [PATCH 6/8] rfkill: add the WWAN radio type, Henrique de Moraes Holschuh..., (Sun Apr 13, 2:16 pm)
Re: [PATCH 6/8] rfkill: add the WWAN radio type, Dmitry Torokhov, (Mon Apr 14, 12:20 am)
Re: [PATCH 6/8] rfkill: add the WWAN radio type, Ivo van Doorn, (Sat Apr 12, 8:28 am)
Re: [PATCH 6/8] rfkill: add the WWAN radio type, Inaky Perez-Gonzalez, (Fri Apr 11, 4:44 pm)
Re: [PATCH 6/8] rfkill: add the WWAN radio type, Henrique de Moraes Holschuh..., (Fri Apr 11, 4:53 pm)
[PATCH 8/8] rfkill: add parameter to disable radios by default, Henrique de Moraes Holschuh..., (Fri Apr 11, 4:37 pm)
Re: [PATCH 8/8] rfkill: add parameter to disable radios by d..., Henrique de Moraes Holschuh..., (Sat Apr 12, 8:56 am)
Re: [PATCH 8/8] rfkill: add parameter to disable radios by d..., Henrique de Moraes Holschuh..., (Sat Apr 12, 10:43 am)
Re: [PATCH 8/8] rfkill: add parameter to disable radios by d..., Henrique de Moraes Holschuh..., (Sat Apr 12, 2:36 pm)
[PATCH 5/8] rfkill: add read-only rfkill switch support, Henrique de Moraes Holschuh..., (Fri Apr 11, 4:37 pm)
[PATCH 7/8] rfkill: add an "any radio" switch type and funct..., Henrique de Moraes Holschuh..., (Fri Apr 11, 4:37 pm)
Re: [PATCH 7/8] rfkill: add an "any radio" switch type and f..., Henrique de Moraes Holschuh..., (Sun Apr 13, 1:40 pm)
[PATCH 3/8] rfkill: handle KEY_RADIO and SW_RADIO events, Henrique de Moraes Holschuh..., (Fri Apr 11, 4:37 pm)
Re: [PATCH 3/8] rfkill: handle KEY_RADIO and SW_RADIO events, Dmitry Torokhov, (Sat Apr 12, 11:47 am)
Re: [PATCH 3/8] rfkill: handle KEY_RADIO and SW_RADIO events, Henrique de Moraes Holschuh..., (Sat Apr 12, 2:02 pm)
Re: [PATCH 3/8] rfkill: handle KEY_RADIO and SW_RADIO events, Carlos Corbacho, (Sat Apr 12, 3:09 pm)
Re: [PATCH 3/8] rfkill: handle KEY_RADIO and SW_RADIO events, Henrique de Moraes Holschuh..., (Sat Apr 12, 4:36 pm)
Re: [PATCH 3/8] rfkill: handle KEY_RADIO and SW_RADIO events, Henrique de Moraes Holschuh..., (Sat Apr 12, 8:05 am)
Re: [PATCH 3/8] rfkill: handle KEY_RADIO and SW_RADIO events, Henrique de Moraes Holschuh..., (Sat Apr 12, 9:08 am)
[PATCH 2/8] rfkill: fix minor typo in kernel doc, Henrique de Moraes Holschuh..., (Fri Apr 11, 4:37 pm)
[PATCH 4/8] rfkill: add read-write rfkill switch support, Henrique de Moraes Holschuh..., (Fri Apr 11, 4:37 pm)
Re: [PATCH 4/8] rfkill: add read-write rfkill switch support, Henrique de Moraes Holschuh..., (Sun Apr 13, 9:20 pm)
Re: [PATCH 4/8] rfkill: add read-write rfkill switch support, Carlos Corbacho, (Mon Apr 14, 3:06 pm)
Re: [PATCH 4/8] rfkill: add read-write rfkill switch support, Henrique de Moraes Holschuh..., (Mon Apr 14, 5:46 pm)
Re: [PATCH 4/8] rfkill: add read-write rfkill switch support, Dmitry Torokhov, (Mon Apr 14, 4:23 pm)
Re: [PATCH 4/8] rfkill: add read-write rfkill switch support, Carlos Corbacho, (Tue Apr 15, 3:27 am)
Re: [PATCH 4/8] rfkill: add read-write rfkill switch support, Dmitry Torokhov, (Tue Apr 15, 8:58 am)
Re: [PATCH 4/8] rfkill: add read-write rfkill switch support, Dmitry Torokhov, (Mon Apr 14, 10:16 am)
Re: [PATCH 4/8] rfkill: add read-write rfkill switch support, Henrique de Moraes Holschuh..., (Mon Apr 14, 10:36 am)
Re: [PATCH 4/8] rfkill: add read-write rfkill switch support, Dmitry Torokhov, (Mon Apr 14, 11:19 am)
Re: [PATCH 4/8] rfkill: add read-write rfkill switch support, Henrique de Moraes Holschuh..., (Mon Apr 14, 12:33 pm)
Re: [PATCH 4/8] rfkill: add read-write rfkill switch support, Dmitry Torokhov, (Mon Apr 14, 2:05 pm)
Re: [PATCH 4/8] rfkill: add read-write rfkill switch support, Henrique de Moraes Holschuh..., (Mon Apr 14, 5:41 pm)
[PATCH 1/8] rfkill: clarify meaning of rfkill states, Henrique de Moraes Holschuh..., (Fri Apr 11, 4:37 pm)
Re: [PATCH 1/8] rfkill: clarify meaning of rfkill states, Dmitry Torokhov, (Mon Apr 14, 12:22 am)
speck-geostationary