~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/net/bluetooth/leds.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-only
  2 /*
  3  * Copyright 2015, Heiner Kallweit <hkallweit1@gmail.com>
  4  */
  5 
  6 #include <net/bluetooth/bluetooth.h>
  7 #include <net/bluetooth/hci_core.h>
  8 
  9 #include "leds.h"
 10 
 11 DEFINE_LED_TRIGGER(bt_power_led_trigger);
 12 
 13 struct hci_basic_led_trigger {
 14         struct led_trigger      led_trigger;
 15         struct hci_dev          *hdev;
 16 };
 17 
 18 #define to_hci_basic_led_trigger(arg) container_of(arg, \
 19                         struct hci_basic_led_trigger, led_trigger)
 20 
 21 void hci_leds_update_powered(struct hci_dev *hdev, bool enabled)
 22 {
 23         if (hdev->power_led)
 24                 led_trigger_event(hdev->power_led,
 25                                   enabled ? LED_FULL : LED_OFF);
 26 
 27         if (!enabled) {
 28                 struct hci_dev *d;
 29 
 30                 read_lock(&hci_dev_list_lock);
 31 
 32                 list_for_each_entry(d, &hci_dev_list, list) {
 33                         if (test_bit(HCI_UP, &d->flags))
 34                                 enabled = true;
 35                 }
 36 
 37                 read_unlock(&hci_dev_list_lock);
 38         }
 39 
 40         led_trigger_event(bt_power_led_trigger, enabled ? LED_FULL : LED_OFF);
 41 }
 42 
 43 static int power_activate(struct led_classdev *led_cdev)
 44 {
 45         struct hci_basic_led_trigger *htrig;
 46         bool powered;
 47 
 48         htrig = to_hci_basic_led_trigger(led_cdev->trigger);
 49         powered = test_bit(HCI_UP, &htrig->hdev->flags);
 50 
 51         led_trigger_event(led_cdev->trigger, powered ? LED_FULL : LED_OFF);
 52 
 53         return 0;
 54 }
 55 
 56 static struct led_trigger *led_allocate_basic(struct hci_dev *hdev,
 57                         int (*activate)(struct led_classdev *led_cdev),
 58                         const char *name)
 59 {
 60         struct hci_basic_led_trigger *htrig;
 61 
 62         htrig = devm_kzalloc(&hdev->dev, sizeof(*htrig), GFP_KERNEL);
 63         if (!htrig)
 64                 return NULL;
 65 
 66         htrig->hdev = hdev;
 67         htrig->led_trigger.activate = activate;
 68         htrig->led_trigger.name = devm_kasprintf(&hdev->dev, GFP_KERNEL,
 69                                                  "%s-%s", hdev->name,
 70                                                  name);
 71         if (!htrig->led_trigger.name)
 72                 goto err_alloc;
 73 
 74         if (devm_led_trigger_register(&hdev->dev, &htrig->led_trigger))
 75                 goto err_register;
 76 
 77         return &htrig->led_trigger;
 78 
 79 err_register:
 80         devm_kfree(&hdev->dev, (void *)htrig->led_trigger.name);
 81 err_alloc:
 82         devm_kfree(&hdev->dev, htrig);
 83         return NULL;
 84 }
 85 
 86 void hci_leds_init(struct hci_dev *hdev)
 87 {
 88         /* initialize power_led */
 89         hdev->power_led = led_allocate_basic(hdev, power_activate, "power");
 90 }
 91 
 92 void bt_leds_init(void)
 93 {
 94         led_trigger_register_simple("bluetooth-power", &bt_power_led_trigger);
 95 }
 96 
 97 void bt_leds_cleanup(void)
 98 {
 99         led_trigger_unregister_simple(bt_power_led_trigger);
100 }
101 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php