thermal: fix Mediatek thermal controller build
[linux/fpc-iii.git] / net / bluetooth / leds.c
blob8319c8440c899897a3f5c082ce611fd5fdeaed07
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 struct hci_basic_led_trigger {
15 struct led_trigger led_trigger;
16 struct hci_dev *hdev;
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)
24 if (hdev->power_led)
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;
32 bool powered;
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),
42 const char *name)
44 struct hci_basic_led_trigger *htrig;
46 htrig = devm_kzalloc(&hdev->dev, sizeof(*htrig), GFP_KERNEL);
47 if (!htrig)
48 return NULL;
50 htrig->hdev = hdev;
51 htrig->led_trigger.activate = activate;
52 htrig->led_trigger.name = devm_kasprintf(&hdev->dev, GFP_KERNEL,
53 "%s-%s", hdev->name,
54 name);
55 if (!htrig->led_trigger.name)
56 goto err_alloc;
58 if (devm_led_trigger_register(&hdev->dev, &htrig->led_trigger))
59 goto err_register;
61 return &htrig->led_trigger;
63 err_register:
64 devm_kfree(&hdev->dev, (void *)htrig->led_trigger.name);
65 err_alloc:
66 devm_kfree(&hdev->dev, htrig);
67 return NULL;
70 void hci_leds_init(struct hci_dev *hdev)
72 /* initialize power_led */
73 hdev->power_led = led_allocate_basic(hdev, power_activate, "power");