ipv6: flowlabel: fl6_sock_lookup() must use atomic_inc_not_zero
[linux/fpc-iii.git] / net / bluetooth / leds.c
blobcb670b5594eb4ddb06e535643554c520f185daf8
1 /*
2 * Copyright 2015, Heiner Kallweit <hkallweit1@gmail.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 */
9 #include <net/bluetooth/bluetooth.h>
10 #include <net/bluetooth/hci_core.h>
12 #include "leds.h"
14 DEFINE_LED_TRIGGER(bt_power_led_trigger);
16 struct hci_basic_led_trigger {
17 struct led_trigger led_trigger;
18 struct hci_dev *hdev;
21 #define to_hci_basic_led_trigger(arg) container_of(arg, \
22 struct hci_basic_led_trigger, led_trigger)
24 void hci_leds_update_powered(struct hci_dev *hdev, bool enabled)
26 if (hdev->power_led)
27 led_trigger_event(hdev->power_led,
28 enabled ? LED_FULL : LED_OFF);
30 if (!enabled) {
31 struct hci_dev *d;
33 read_lock(&hci_dev_list_lock);
35 list_for_each_entry(d, &hci_dev_list, list) {
36 if (test_bit(HCI_UP, &d->flags))
37 enabled = true;
40 read_unlock(&hci_dev_list_lock);
43 led_trigger_event(bt_power_led_trigger, enabled ? LED_FULL : LED_OFF);
46 static void power_activate(struct led_classdev *led_cdev)
48 struct hci_basic_led_trigger *htrig;
49 bool powered;
51 htrig = to_hci_basic_led_trigger(led_cdev->trigger);
52 powered = test_bit(HCI_UP, &htrig->hdev->flags);
54 led_trigger_event(led_cdev->trigger, powered ? LED_FULL : LED_OFF);
57 static struct led_trigger *led_allocate_basic(struct hci_dev *hdev,
58 void (*activate)(struct led_classdev *led_cdev),
59 const char *name)
61 struct hci_basic_led_trigger *htrig;
63 htrig = devm_kzalloc(&hdev->dev, sizeof(*htrig), GFP_KERNEL);
64 if (!htrig)
65 return NULL;
67 htrig->hdev = hdev;
68 htrig->led_trigger.activate = activate;
69 htrig->led_trigger.name = devm_kasprintf(&hdev->dev, GFP_KERNEL,
70 "%s-%s", hdev->name,
71 name);
72 if (!htrig->led_trigger.name)
73 goto err_alloc;
75 if (devm_led_trigger_register(&hdev->dev, &htrig->led_trigger))
76 goto err_register;
78 return &htrig->led_trigger;
80 err_register:
81 devm_kfree(&hdev->dev, (void *)htrig->led_trigger.name);
82 err_alloc:
83 devm_kfree(&hdev->dev, htrig);
84 return NULL;
87 void hci_leds_init(struct hci_dev *hdev)
89 /* initialize power_led */
90 hdev->power_led = led_allocate_basic(hdev, power_activate, "power");
93 void bt_leds_init(void)
95 led_trigger_register_simple("bluetooth-power", &bt_power_led_trigger);
98 void bt_leds_cleanup(void)
100 led_trigger_unregister_simple(bt_power_led_trigger);