diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2016-07-21 08:12:41 -0400 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2016-09-19 14:19:34 -0400 |
commit | e64c97b53bc6727aa4385535166aaa047281e02d (patch) | |
tree | 6fae09aba7074eefce0b49b31dca5db676daccd4 | |
parent | 53f863a66904542b03204f2b115d050b04c11ba5 (diff) |
Bluetooth: Add combined LED trigger for controller power
Instead of just having a LED trigger for power on a specific controller,
this adds the LED trigger "bluetooth-power" that combines the power
states of all controllers into a single trigger. This simplifies the
trigger selection and also supports multiple controllers per host
system via a single LED.
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
-rw-r--r-- | net/bluetooth/af_bluetooth.c | 5 | ||||
-rw-r--r-- | net/bluetooth/leds.c | 27 | ||||
-rw-r--r-- | net/bluetooth/leds.h | 10 |
3 files changed, 42 insertions, 0 deletions
diff --git a/net/bluetooth/af_bluetooth.c b/net/bluetooth/af_bluetooth.c index 0b5f729d08d2..1d96ff3a8d87 100644 --- a/net/bluetooth/af_bluetooth.c +++ b/net/bluetooth/af_bluetooth.c | |||
@@ -31,6 +31,7 @@ | |||
31 | #include <net/bluetooth/bluetooth.h> | 31 | #include <net/bluetooth/bluetooth.h> |
32 | #include <linux/proc_fs.h> | 32 | #include <linux/proc_fs.h> |
33 | 33 | ||
34 | #include "leds.h" | ||
34 | #include "selftest.h" | 35 | #include "selftest.h" |
35 | 36 | ||
36 | /* Bluetooth sockets */ | 37 | /* Bluetooth sockets */ |
@@ -726,6 +727,8 @@ static int __init bt_init(void) | |||
726 | 727 | ||
727 | bt_debugfs = debugfs_create_dir("bluetooth", NULL); | 728 | bt_debugfs = debugfs_create_dir("bluetooth", NULL); |
728 | 729 | ||
730 | bt_leds_init(); | ||
731 | |||
729 | err = bt_sysfs_init(); | 732 | err = bt_sysfs_init(); |
730 | if (err < 0) | 733 | if (err < 0) |
731 | return err; | 734 | return err; |
@@ -785,6 +788,8 @@ static void __exit bt_exit(void) | |||
785 | 788 | ||
786 | bt_sysfs_cleanup(); | 789 | bt_sysfs_cleanup(); |
787 | 790 | ||
791 | bt_leds_cleanup(); | ||
792 | |||
788 | debugfs_remove_recursive(bt_debugfs); | 793 | debugfs_remove_recursive(bt_debugfs); |
789 | } | 794 | } |
790 | 795 | ||
diff --git a/net/bluetooth/leds.c b/net/bluetooth/leds.c index 8319c8440c89..cb670b5594eb 100644 --- a/net/bluetooth/leds.c +++ b/net/bluetooth/leds.c | |||
@@ -11,6 +11,8 @@ | |||
11 | 11 | ||
12 | #include "leds.h" | 12 | #include "leds.h" |
13 | 13 | ||
14 | DEFINE_LED_TRIGGER(bt_power_led_trigger); | ||
15 | |||
14 | struct hci_basic_led_trigger { | 16 | struct hci_basic_led_trigger { |
15 | struct led_trigger led_trigger; | 17 | struct led_trigger led_trigger; |
16 | struct hci_dev *hdev; | 18 | struct hci_dev *hdev; |
@@ -24,6 +26,21 @@ void hci_leds_update_powered(struct hci_dev *hdev, bool enabled) | |||
24 | if (hdev->power_led) | 26 | if (hdev->power_led) |
25 | led_trigger_event(hdev->power_led, | 27 | led_trigger_event(hdev->power_led, |
26 | enabled ? LED_FULL : LED_OFF); | 28 | enabled ? LED_FULL : LED_OFF); |
29 | |||
30 | if (!enabled) { | ||
31 | struct hci_dev *d; | ||
32 | |||
33 | read_lock(&hci_dev_list_lock); | ||
34 | |||
35 | list_for_each_entry(d, &hci_dev_list, list) { | ||
36 | if (test_bit(HCI_UP, &d->flags)) | ||
37 | enabled = true; | ||
38 | } | ||
39 | |||
40 | read_unlock(&hci_dev_list_lock); | ||
41 | } | ||
42 | |||
43 | led_trigger_event(bt_power_led_trigger, enabled ? LED_FULL : LED_OFF); | ||
27 | } | 44 | } |
28 | 45 | ||
29 | static void power_activate(struct led_classdev *led_cdev) | 46 | static void power_activate(struct led_classdev *led_cdev) |
@@ -72,3 +89,13 @@ void hci_leds_init(struct hci_dev *hdev) | |||
72 | /* initialize power_led */ | 89 | /* initialize power_led */ |
73 | hdev->power_led = led_allocate_basic(hdev, power_activate, "power"); | 90 | hdev->power_led = led_allocate_basic(hdev, power_activate, "power"); |
74 | } | 91 | } |
92 | |||
93 | void bt_leds_init(void) | ||
94 | { | ||
95 | led_trigger_register_simple("bluetooth-power", &bt_power_led_trigger); | ||
96 | } | ||
97 | |||
98 | void bt_leds_cleanup(void) | ||
99 | { | ||
100 | led_trigger_unregister_simple(bt_power_led_trigger); | ||
101 | } | ||
diff --git a/net/bluetooth/leds.h b/net/bluetooth/leds.h index a9c4d6ea01cf..08725a2fbd9b 100644 --- a/net/bluetooth/leds.h +++ b/net/bluetooth/leds.h | |||
@@ -7,10 +7,20 @@ | |||
7 | */ | 7 | */ |
8 | 8 | ||
9 | #if IS_ENABLED(CONFIG_BT_LEDS) | 9 | #if IS_ENABLED(CONFIG_BT_LEDS) |
10 | |||
10 | void hci_leds_update_powered(struct hci_dev *hdev, bool enabled); | 11 | void hci_leds_update_powered(struct hci_dev *hdev, bool enabled); |
11 | void hci_leds_init(struct hci_dev *hdev); | 12 | void hci_leds_init(struct hci_dev *hdev); |
13 | |||
14 | void bt_leds_init(void); | ||
15 | void bt_leds_cleanup(void); | ||
16 | |||
12 | #else | 17 | #else |
18 | |||
13 | static inline void hci_leds_update_powered(struct hci_dev *hdev, | 19 | static inline void hci_leds_update_powered(struct hci_dev *hdev, |
14 | bool enabled) {} | 20 | bool enabled) {} |
15 | static inline void hci_leds_init(struct hci_dev *hdev) {} | 21 | static inline void hci_leds_init(struct hci_dev *hdev) {} |
22 | |||
23 | static inline void bt_leds_init(void) {} | ||
24 | static inline void bt_leds_cleanup(void) {} | ||
25 | |||
16 | #endif | 26 | #endif |