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.
9 #include <net/bluetooth/bluetooth.h>
10 #include <net/bluetooth/hci_core.h>
14 struct hci_basic_led_trigger
{
15 struct led_trigger led_trigger
;
19 #define to_hci_basic_led_trigger(arg) container_of(arg, \
20 struct hci_basic_led_trigger, led_trigger)
22 void hci_leds_update_powered(struct hci_dev
*hdev
, bool enabled
)
25 led_trigger_event(hdev
->power_led
,
26 enabled
? LED_FULL
: LED_OFF
);
29 static void power_activate(struct led_classdev
*led_cdev
)
31 struct hci_basic_led_trigger
*htrig
;
34 htrig
= to_hci_basic_led_trigger(led_cdev
->trigger
);
35 powered
= test_bit(HCI_UP
, &htrig
->hdev
->flags
);
37 led_trigger_event(led_cdev
->trigger
, powered
? LED_FULL
: LED_OFF
);
40 static struct led_trigger
*led_allocate_basic(struct hci_dev
*hdev
,
41 void (*activate
)(struct led_classdev
*led_cdev
),
44 struct hci_basic_led_trigger
*htrig
;
46 htrig
= devm_kzalloc(&hdev
->dev
, sizeof(*htrig
), GFP_KERNEL
);
51 htrig
->led_trigger
.activate
= activate
;
52 htrig
->led_trigger
.name
= devm_kasprintf(&hdev
->dev
, GFP_KERNEL
,
55 if (!htrig
->led_trigger
.name
)
58 if (devm_led_trigger_register(&hdev
->dev
, &htrig
->led_trigger
))
61 return &htrig
->led_trigger
;
64 devm_kfree(&hdev
->dev
, (void *)htrig
->led_trigger
.name
);
66 devm_kfree(&hdev
->dev
, htrig
);
70 void hci_leds_init(struct hci_dev
*hdev
)
72 /* initialize power_led */
73 hdev
->power_led
= led_allocate_basic(hdev
, power_activate
, "power");