]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
Merge remote-tracking branch 'bluetooth/master'
authorStephen Rothwell <sfr@canb.auug.org.au>
Thu, 11 Feb 2016 01:03:08 +0000 (12:03 +1100)
committerStephen Rothwell <sfr@canb.auug.org.au>
Thu, 11 Feb 2016 01:03:08 +0000 (12:03 +1100)
drivers/bluetooth/ath3k.c
include/net/bluetooth/hci_core.h
net/bluetooth/Kconfig
net/bluetooth/Makefile
net/bluetooth/hci_core.c
net/bluetooth/leds.c [new file with mode: 0644]
net/bluetooth/leds.h [new file with mode: 0644]

index fa893c3ec4087f39382f3dc83b968c9859f41cca..ebd641b85396d63a7a07a2039b008008d7f0d459 100644 (file)
@@ -497,6 +497,7 @@ static int ath3k_probe(struct usb_interface *intf,
        /* match device ID in ath3k blacklist table */
        if (!id->driver_info) {
                const struct usb_device_id *match;
+
                match = usb_match_id(intf, ath3k_blist_tbl);
                if (match)
                        id = match;
index d4f82edb5cffe0528719dc416e8b28b71460e485..dc71473462ac9f60680dad7c7cce8e9878b1a8a5 100644 (file)
@@ -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>
 
@@ -396,6 +397,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);
index 95d1a66ba03aa20095932a1c45f9f76af2cc1393..06c31b9a68b0bce3cc4f28224c3c23864f78e7c9 100644 (file)
@@ -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
index 2b15ae8c1def06642682c488a9439f0e57feeb13..b3ff12eb9b6dcdaa590bacc997cbe2e0e566783e 100644 (file)
@@ -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
 
index 47bcef7547967ce544ff0cf5ea7dabecdd080d90..541760fe53d4cf91553fb0b126de340007d453e5 100644 (file)
@@ -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);
diff --git a/net/bluetooth/leds.c b/net/bluetooth/leds.c
new file mode 100644 (file)
index 0000000..8319c84
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2015, Heiner Kallweit <hkallweit1@gmail.com>
+ *
+ * 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.
+ */
+
+#include <net/bluetooth/bluetooth.h>
+#include <net/bluetooth/hci_core.h>
+
+#include "leds.h"
+
+struct hci_basic_led_trigger {
+       struct led_trigger      led_trigger;
+       struct hci_dev          *hdev;
+};
+
+#define to_hci_basic_led_trigger(arg) container_of(arg, \
+                       struct hci_basic_led_trigger, led_trigger)
+
+void hci_leds_update_powered(struct hci_dev *hdev, bool enabled)
+{
+       if (hdev->power_led)
+               led_trigger_event(hdev->power_led,
+                                 enabled ? LED_FULL : LED_OFF);
+}
+
+static void power_activate(struct led_classdev *led_cdev)
+{
+       struct hci_basic_led_trigger *htrig;
+       bool powered;
+
+       htrig = to_hci_basic_led_trigger(led_cdev->trigger);
+       powered = test_bit(HCI_UP, &htrig->hdev->flags);
+
+       led_trigger_event(led_cdev->trigger, powered ? LED_FULL : LED_OFF);
+}
+
+static struct led_trigger *led_allocate_basic(struct hci_dev *hdev,
+                       void (*activate)(struct led_classdev *led_cdev),
+                       const char *name)
+{
+       struct hci_basic_led_trigger *htrig;
+
+       htrig = devm_kzalloc(&hdev->dev, sizeof(*htrig), GFP_KERNEL);
+       if (!htrig)
+               return NULL;
+
+       htrig->hdev = hdev;
+       htrig->led_trigger.activate = activate;
+       htrig->led_trigger.name = devm_kasprintf(&hdev->dev, GFP_KERNEL,
+                                                "%s-%s", hdev->name,
+                                                name);
+       if (!htrig->led_trigger.name)
+               goto err_alloc;
+
+       if (devm_led_trigger_register(&hdev->dev, &htrig->led_trigger))
+               goto err_register;
+
+       return &htrig->led_trigger;
+
+err_register:
+       devm_kfree(&hdev->dev, (void *)htrig->led_trigger.name);
+err_alloc:
+       devm_kfree(&hdev->dev, htrig);
+       return NULL;
+}
+
+void hci_leds_init(struct hci_dev *hdev)
+{
+       /* initialize power_led */
+       hdev->power_led = led_allocate_basic(hdev, power_activate, "power");
+}
diff --git a/net/bluetooth/leds.h b/net/bluetooth/leds.h
new file mode 100644 (file)
index 0000000..a9c4d6e
--- /dev/null
@@ -0,0 +1,16 @@
+/*
+ * Copyright 2015, Heiner Kallweit <hkallweit1@gmail.com>
+ *
+ * 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);
+#else
+static inline void hci_leds_update_powered(struct hci_dev *hdev,
+                                          bool enabled) {}
+static inline void hci_leds_init(struct hci_dev *hdev) {}
+#endif