Commit e64c97b5 authored by Marcel Holtmann's avatar Marcel Holtmann

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: default avatarMarcel Holtmann <marcel@holtmann.org>
Signed-off-by: default avatarJohan Hedberg <johan.hedberg@intel.com>
parent 53f863a6
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include <net/bluetooth/bluetooth.h> #include <net/bluetooth/bluetooth.h>
#include <linux/proc_fs.h> #include <linux/proc_fs.h>
#include "leds.h"
#include "selftest.h" #include "selftest.h"
/* Bluetooth sockets */ /* Bluetooth sockets */
...@@ -726,6 +727,8 @@ static int __init bt_init(void) ...@@ -726,6 +727,8 @@ static int __init bt_init(void)
bt_debugfs = debugfs_create_dir("bluetooth", NULL); bt_debugfs = debugfs_create_dir("bluetooth", NULL);
bt_leds_init();
err = bt_sysfs_init(); err = bt_sysfs_init();
if (err < 0) if (err < 0)
return err; return err;
...@@ -785,6 +788,8 @@ static void __exit bt_exit(void) ...@@ -785,6 +788,8 @@ static void __exit bt_exit(void)
bt_sysfs_cleanup(); bt_sysfs_cleanup();
bt_leds_cleanup();
debugfs_remove_recursive(bt_debugfs); debugfs_remove_recursive(bt_debugfs);
} }
......
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
#include "leds.h" #include "leds.h"
DEFINE_LED_TRIGGER(bt_power_led_trigger);
struct hci_basic_led_trigger { struct hci_basic_led_trigger {
struct led_trigger led_trigger; struct led_trigger led_trigger;
struct hci_dev *hdev; struct hci_dev *hdev;
...@@ -24,6 +26,21 @@ void hci_leds_update_powered(struct hci_dev *hdev, bool enabled) ...@@ -24,6 +26,21 @@ void hci_leds_update_powered(struct hci_dev *hdev, bool enabled)
if (hdev->power_led) if (hdev->power_led)
led_trigger_event(hdev->power_led, led_trigger_event(hdev->power_led,
enabled ? LED_FULL : LED_OFF); enabled ? LED_FULL : LED_OFF);
if (!enabled) {
struct hci_dev *d;
read_lock(&hci_dev_list_lock);
list_for_each_entry(d, &hci_dev_list, list) {
if (test_bit(HCI_UP, &d->flags))
enabled = true;
}
read_unlock(&hci_dev_list_lock);
}
led_trigger_event(bt_power_led_trigger, enabled ? LED_FULL : LED_OFF);
} }
static void power_activate(struct led_classdev *led_cdev) static void power_activate(struct led_classdev *led_cdev)
...@@ -72,3 +89,13 @@ void hci_leds_init(struct hci_dev *hdev) ...@@ -72,3 +89,13 @@ void hci_leds_init(struct hci_dev *hdev)
/* initialize power_led */ /* initialize power_led */
hdev->power_led = led_allocate_basic(hdev, power_activate, "power"); hdev->power_led = led_allocate_basic(hdev, power_activate, "power");
} }
void bt_leds_init(void)
{
led_trigger_register_simple("bluetooth-power", &bt_power_led_trigger);
}
void bt_leds_cleanup(void)
{
led_trigger_unregister_simple(bt_power_led_trigger);
}
...@@ -7,10 +7,20 @@ ...@@ -7,10 +7,20 @@
*/ */
#if IS_ENABLED(CONFIG_BT_LEDS) #if IS_ENABLED(CONFIG_BT_LEDS)
void hci_leds_update_powered(struct hci_dev *hdev, bool enabled); void hci_leds_update_powered(struct hci_dev *hdev, bool enabled);
void hci_leds_init(struct hci_dev *hdev); void hci_leds_init(struct hci_dev *hdev);
void bt_leds_init(void);
void bt_leds_cleanup(void);
#else #else
static inline void hci_leds_update_powered(struct hci_dev *hdev, static inline void hci_leds_update_powered(struct hci_dev *hdev,
bool enabled) {} bool enabled) {}
static inline void hci_leds_init(struct hci_dev *hdev) {} static inline void hci_leds_init(struct hci_dev *hdev) {}
static inline void bt_leds_init(void) {}
static inline void bt_leds_cleanup(void) {}
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment