summaryrefslogtreecommitdiffstats
path: root/net/rfkill/rfkill.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/rfkill/rfkill.c')
-rw-r--r--net/rfkill/rfkill.c57
1 files changed, 51 insertions, 6 deletions
diff --git a/net/rfkill/rfkill.c b/net/rfkill/rfkill.c
index db3395b..51d151c 100644
--- a/net/rfkill/rfkill.c
+++ b/net/rfkill/rfkill.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2006 Ivo van Doorn
+ * Copyright (C) 2006 - 2007 Ivo van Doorn
* Copyright (C) 2007 Dmitry Torokhov
*
* This program is free software; you can redistribute it and/or modify
@@ -37,6 +37,22 @@ static DEFINE_MUTEX(rfkill_mutex);
static enum rfkill_state rfkill_states[RFKILL_TYPE_MAX];
+
+static void rfkill_led_trigger(struct rfkill *rfkill,
+ enum rfkill_state state)
+{
+#ifdef CONFIG_RFKILL_LEDS
+ struct led_trigger *led = &rfkill->led_trigger;
+
+ if (!led->name)
+ return;
+ if (state == RFKILL_STATE_OFF)
+ led_trigger_event(led, LED_OFF);
+ else
+ led_trigger_event(led, LED_FULL);
+#endif /* CONFIG_RFKILL_LEDS */
+}
+
static int rfkill_toggle_radio(struct rfkill *rfkill,
enum rfkill_state state)
{
@@ -48,8 +64,10 @@ static int rfkill_toggle_radio(struct rfkill *rfkill,
if (state != rfkill->state) {
retval = rfkill->toggle_radio(rfkill->data, state);
- if (!retval)
+ if (!retval) {
rfkill->state = state;
+ rfkill_led_trigger(rfkill, state);
+ }
}
mutex_unlock(&rfkill->mutex);
@@ -106,8 +124,8 @@ static ssize_t rfkill_type_show(struct device *dev,
case RFKILL_TYPE_BLUETOOTH:
type = "bluetooth";
break;
- case RFKILL_TYPE_IRDA:
- type = "irda";
+ case RFKILL_TYPE_UWB:
+ type = "ultrawideband";
break;
default:
BUG();
@@ -172,6 +190,10 @@ static ssize_t rfkill_claim_store(struct device *dev,
if (error)
return error;
+ if (rfkill->user_claim_unsupported) {
+ error = -EOPNOTSUPP;
+ goto out_unlock;
+ }
if (rfkill->user_claim != claim) {
if (!claim)
rfkill_toggle_radio(rfkill,
@@ -179,9 +201,10 @@ static ssize_t rfkill_claim_store(struct device *dev,
rfkill->user_claim = claim;
}
+out_unlock:
mutex_unlock(&rfkill_mutex);
- return count;
+ return error ? error : count;
}
static struct device_attribute rfkill_dev_attrs[] = {
@@ -281,7 +304,7 @@ static void rfkill_remove_switch(struct rfkill *rfkill)
/**
* rfkill_allocate - allocate memory for rfkill structure.
* @parent: device that has rf switch on it
- * @type: type of the switch (wlan, bluetooth, irda)
+ * @type: type of the switch (RFKILL_TYPE_*)
*
* This function should be called by the network driver when it needs
* rfkill structure. Once the structure is allocated the driver shoud
@@ -328,6 +351,26 @@ void rfkill_free(struct rfkill *rfkill)
}
EXPORT_SYMBOL(rfkill_free);
+static void rfkill_led_trigger_register(struct rfkill *rfkill)
+{
+#ifdef CONFIG_RFKILL_LEDS
+ int error;
+
+ rfkill->led_trigger.name = rfkill->dev.bus_id;
+ error = led_trigger_register(&rfkill->led_trigger);
+ if (error)
+ rfkill->led_trigger.name = NULL;
+#endif /* CONFIG_RFKILL_LEDS */
+}
+
+static void rfkill_led_trigger_unregister(struct rfkill *rfkill)
+{
+#ifdef CONFIG_RFKILL_LEDS
+ if (rfkill->led_trigger.name)
+ led_trigger_unregister(&rfkill->led_trigger);
+#endif
+}
+
/**
* rfkill_register - Register a rfkill structure.
* @rfkill: rfkill structure to be registered
@@ -357,6 +400,7 @@ int rfkill_register(struct rfkill *rfkill)
rfkill_remove_switch(rfkill);
return error;
}
+ rfkill_led_trigger_register(rfkill);
return 0;
}
@@ -372,6 +416,7 @@ EXPORT_SYMBOL(rfkill_register);
*/
void rfkill_unregister(struct rfkill *rfkill)
{
+ rfkill_led_trigger_unregister(rfkill);
device_del(&rfkill->dev);
rfkill_remove_switch(rfkill);
put_device(&rfkill->dev);
OpenPOWER on IntegriCloud