Skip to contentSkip to conversation

bluetooth: core: add LED trigger for indicating HCI is powered up

PATCH In review Heiner Kallweit 2 participants 2 messages Jan 8, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 bluetooth: core: add LED trigger for indicating HCI is powered up

Add support for LED triggers to the bluetooth core and add kernel config symbol BT_LEDS for it.
For now one trigger for indicating "HCI is powered up" is supported.

---
v2:
- completely rewrote the code to be as generic as possible and minimize the changes to struct hci_dev
- make the details of the LED triggers opaque to struct hci_dev
- avoid using ifdef CONFIG_BT_LEDS in hci_core.h
- start with the radio trigger only
- factor out the generic basic led trigger code to facilitate adding further basic LED triggers
- fix indentation in Kconfig
- rename led.[ch] to leds.[ch]
v3:
- use term power instead of radio
- rename hci_led_ to hci_leds_
- remove the counter
- use IS_ENABLED for checking the config option
v4:
- rework commit message
- shorten static function names
- remove empty line at end of file

---
 include/net/bluetooth/hci_core.h |  3 ++
 net/bluetooth/Kconfig            |  9 +++++
 net/bluetooth/Makefile           |  1 +
 net/bluetooth/hci_core.c         |  8 ++++
 net/bluetooth/leds.c             | 80 ++++++++++++++++++++++++++++++++++++++++
 net/bluetooth/leds.h             | 18 +++++++++
 6 files changed, 119 insertions(+)
 create mode 100644 net/bluetooth/leds.c
 create mode 100644 net/bluetooth/leds.h
include/net/bluetooth/hci_core.h +3 -0
index c95e032..0f084b4 100644
@@ -25,6 +25,7 @@
 #ifndef __HCI_CORE_H
 #define __HCI_CORE_H
 
+#include <linux/leds.h>
 #include <net/bluetooth/hci.h>
 #include <net/bluetooth/hci_sock.h>
 
@@ -395,6 +396,8 @@ struct hci_dev {
 	struct delayed_work	rpa_expired;
 	bdaddr_t		rpa;
 
+	struct led_trigger	*power_led;
+
 	int (*open)(struct hci_dev *hdev);
 	int (*close)(struct hci_dev *hdev);
 	int (*flush)(struct hci_dev *hdev);
net/bluetooth/Kconfig +9 -0
index 95d1a66..06c31b9 100644
@@ -69,6 +69,15 @@ config BT_6LOWPAN
 	help
 	  IPv6 compression over Bluetooth Low Energy.
 
+config BT_LEDS
+	bool "Enable LED triggers"
+	depends on BT
+	depends on LEDS_CLASS
+	select LEDS_TRIGGERS
+	help
+	  This option selects a few LED triggers for different
+	  Bluetooth events.
+
 config BT_SELFTEST
 	bool "Bluetooth self testing support"
 	depends on BT && DEBUG_KERNEL
net/bluetooth/Makefile +1 -0
index 2b15ae8..b3ff12e 100644
@@ -17,6 +17,7 @@ bluetooth-y := af_bluetooth.o hci_core.o hci_conn.o hci_event.o mgmt.o \
 
 bluetooth-$(CONFIG_BT_BREDR) += sco.o
 bluetooth-$(CONFIG_BT_HS) += a2mp.o amp.o
+bluetooth-$(CONFIG_BT_LEDS) += leds.o
 bluetooth-$(CONFIG_BT_DEBUGFS) += hci_debugfs.o
 bluetooth-$(CONFIG_BT_SELFTEST) += selftest.o
 
net/bluetooth/hci_core.c +8 -0
index 47bcef7..06f603a 100644
@@ -40,6 +40,7 @@
 #include "hci_request.h"
 #include "hci_debugfs.h"
 #include "smp.h"
+#include "leds.h"
 
 static void hci_rx_work(struct work_struct *work);
 static void hci_cmd_work(struct work_struct *work);
@@ -1395,6 +1396,7 @@ static int hci_dev_do_open(struct hci_dev *hdev)
 		hci_dev_set_flag(hdev, HCI_RPA_EXPIRED);
 		set_bit(HCI_UP, &hdev->flags);
 		hci_sock_dev_event(hdev, HCI_DEV_UP);
+		hci_leds_update_powered(hdev, true);
 		if (!hci_dev_test_flag(hdev, HCI_SETUP) &&
 		    !hci_dev_test_flag(hdev, HCI_CONFIG) &&
 		    !hci_dev_test_flag(hdev, HCI_UNCONFIGURED) &&
@@ -1532,6 +1534,8 @@ int hci_dev_do_close(struct hci_dev *hdev)
 		return 0;
 	}
 
+	hci_leds_update_powered(hdev, false);
+
 	/* Flush RX and TX works */
 	flush_work(&hdev->tx_work);
 	flush_work(&hdev->rx_work);
@@ -3067,6 +3071,8 @@ int hci_register_dev(struct hci_dev *hdev)
 	if (error < 0)
 		goto err_wqueue;
 
+	hci_leds_init(hdev);
+
 	hdev->rfkill = rfkill_alloc(hdev->name, &hdev->dev,
 				    RFKILL_TYPE_BLUETOOTH, &hci_rfkill_ops,
 				    hdev);
@@ -3128,6 +3134,8 @@ void hci_unregister_dev(struct hci_dev *hdev)
 
 	id = hdev->id;
 
+	hci_leds_exit(hdev);
+
 	write_lock(&hci_dev_list_lock);
 	list_del(&hdev->list);
 	write_unlock(&hci_dev_list_lock);
net/bluetooth/leds.c new file +80 -0

80 lines not on this page · raw message

net/bluetooth/leds.h new file +18 -0
new file mode 100644
index 0000000..068261a
@@ -0,0 +1,18 @@
+/*
+ * Copyright 2015, Heiner Kallweit <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#if IS_ENABLED(CONFIG_BT_LEDS)
+void hci_leds_update_powered(struct hci_dev *hdev, bool enabled);
+void hci_leds_init(struct hci_dev *hdev);
+void hci_leds_exit(struct hci_dev *hdev);
+#else
+static inline void hci_leds_update_powered(struct hci_dev *hdev,
+					   bool enabled) {}
+static inline void hci_leds_init(struct hci_dev *hdev) {}
+static inline void hci_leds_exit(struct hci_dev *hdev) {}
+#endif
Signature · 1 line
2.6.4
maintainer
#1 lore raw

Hi Heiner,

Quoted 33 lines

Add support for LED triggers to the bluetooth core and add kernel config symbol BT_LEDS for it.
For now one trigger for indicating "HCI is powered up" is supported.

---
v2:
- completely rewrote the code to be as generic as possible and minimize the changes to struct hci_dev
- make the details of the LED triggers opaque to struct hci_dev
- avoid using ifdef CONFIG_BT_LEDS in hci_core.h
- start with the radio trigger only
- factor out the generic basic led trigger code to facilitate adding further basic LED triggers
- fix indentation in Kconfig
- rename led.[ch] to leds.[ch]
v3:
- use term power instead of radio
- rename hci_led_ to hci_leds_
- remove the counter
- use IS_ENABLED for checking the config option
v4:
- rework commit message
- shorten static function names
- remove empty line at end of file
---

include/net/bluetooth/hci_core.h |  3 ++
net/bluetooth/Kconfig            |  9 +++++
net/bluetooth/Makefile           |  1 +
net/bluetooth/hci_core.c         |  8 ++++
net/bluetooth/leds.c             | 80 ++++++++++++++++++++++++++++++++++++++++
net/bluetooth/leds.h             | 18 +++++++++
6 files changed, 119 insertions(+)
Quoted 2 lines

create mode 100644 net/bluetooth/leds.c
create mode 100644 net/bluetooth/leds.h

patch has been applied to bluetooth-next tree.

Regards

Marcel