summaryrefslogtreecommitdiff
path: root/net/bluetooth/leds.c
blob: f46847632ffa1e95e30537c173e078c7aa8f9be9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright 2015, Heiner Kallweit <hkallweit1@gmail.com>
 */

#include <net/bluetooth/bluetooth.h>
#include <net/bluetooth/hci_core.h>

#include "leds.h"

DEFINE_LED_TRIGGER(bt_power_led_trigger);

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);

	if (!enabled) {
		struct hci_dev *d;

		read_lock(&hci_dev_list_lock);

		list_for_each_entry(d, &hci_dev_list, list) {
			if (test_bit(HCI_UP, &d->flags))
				enabled = true;
		}

		read_unlock(&hci_dev_list_lock);
	}

	led_trigger_event(bt_power_led_trigger, enabled ? LED_FULL : LED_OFF);
}

static int 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);

	return 0;
}

static struct led_trigger *led_allocate_basic(struct hci_dev *hdev,
			int (*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");
}

void bt_leds_init(void)
{
	led_trigger_register_simple("bluetooth-power", &bt_power_led_trigger);
}

void bt_leds_cleanup(void)
{
	led_trigger_unregister_simple(bt_power_led_trigger);
}
Signed-off-by: Hong Liu <hong.liu@intel.com> Signed-off-by: Alan Cox <alan@linux.intel.com> Signed-off-by: Matthew Garrett <mjg@redhat.com> 2010-08-03intel_scu_ipc: fix data packing of PMIC command on MoorestownHong Liu1-5/+6 Data is 2-byte per entry for PMIC read-modify-update command. Signed-off-by: Hong Liu <hong.liu@intel.com> Signed-off-by: Alan Cox <alan@linux.intel.com> Signed-off-by: Matthew Garrett <mjg@redhat.com> 2010-08-03Clean up command packing on MRST.Andy Ross1-18/+11 Don't pass more bytes in the command length field than we filled. Signed-off-by: Andy Ross <andy.ross@windriver.com> Signed-off-by: Alan Cox <alan@linux.intel.com> Signed-off-by: Matthew Garrett <mjg@redhat.com> 2010-08-03zero the stack buffer before giving random garbage to the SCUArjan van de Ven1-0/+2 some messages take 4 bytes, but only fill 3 bytes.... this patch makes sure that whatever we send to the SCU is zeroed first Signed-off-by: Arjan van de Ven <arjan@linux.intel.com> Signed-off-by: Alan Cox <alan@linux.intel.com> Signed-off-by: Matthew Garrett <mjg@redhat.com> 2010-08-03Fix stack buffer size for IPC writev messagesArjan van de Ven1-2/+2 The stack buffer for IPC messages was 16 bytes, limiting messages to a size of 4 (each message is 32 bit). However, the touch screen driver is trying to send messages of size 5.... (AC: Set to 20 bytes having checked the max size allowed) Signed-off-by: Arjan van de Ven <arjan@linux.intel.com> Signed-off-by: Alan Cox <alan@linux.intel.com> Signed-off-by: Matthew Garrett <mjg@redhat.com> 2010-08-03intel_scu_ipc: Use the new cpu identification functionAlan Cox1-12/+5 This provides an architecture level board identify function to replace the cpuid direct usage Signed-off-by: Alan Cox <alan@linux.intel.com> Signed-off-by: Matthew Garrett <mjg@redhat.com> 2010-08-03intel_scu_ipc: tidy up unused bitsSreedhara DS1-4/+0 Delete unused constants IPC_CMD_INDIRECT_RD and IPC_CMD_INDIRECT_WR Remove multiple inclusion of header file "asm/mrst.h" Signed-off-by: Sreedhara DS <sreedhara.ds@intel.com> Signed-off-by: Alan Cox <alan@linux.intel.com> Signed-off-by: Matthew Garrett <mjg@redhat.com> 2010-08-03Remove indirect read write api support.Sreedhara DS1-82/+0 The firmware of production devices does not support this interface so this is dead code. Signed-off-by: Sreedhara DS <sreedhara.ds@intel.com> Signed-off-by: Alan Cox <alan@linux.intel.com> Signed-off-by: Matthew Garrett <mjg@redhat.com> 2010-08-03intel_scu_ipc: Support Medfield processorsSreedhara DS1-20/+33 Changes to work on bothMmoorestown and Medfield New pci id added for Medfield Return type of ipc_data_readl chnaged from u8 to u32 Signed-off-by: Sreedhara DS <sreedhara.ds@intel.com> Signed-off-by: Alan Cox <alan@linux.intel.com> Signed-off-by: Matthew Garrett <mjg@redhat.com> 2010-08-03intel_scu_ipc: detect CPU type automaticallySreedhara DS1-7/+12 Intel SCU message formats depend upon the processor type. Replace the module option with automatic detection of the processor type. Signed-off-by: Sreedhara DS <sreedhara.ds@intel.com> Signed-off-by: Matthew Garrett <mjg@redhat.com> 2010-07-19intel_scu_ipc: Oops/crash fixesSreedhara DS1-4/+8 - fix reversing of command/sub arguments - fix a crash if the i2c interface is called before the device is found Signed-off-by: Sreedhara DS <sreedhara.ds@intel.com> Signed-off-by: Alan Cox <alan@linux.intel.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> 2010-06-01intel_scu_ipc: Length fixAlan Cox1-1/+1 Commands with data must set the length in the message. Signed-off-by: Alan Cox <alan@linux.intel.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> 2010-05-17IPC driver for Intel Mobile Internet Device (MID) platformsSreedhara DS1-0/+829 The IPC (inter processor communications) is used to provide the communications between kernel and system control units on some embedded Intel x86 platforms. (Various bits of clean up and restructuring by Alan Cox) Signed-off-by: Sreedhara DS <sreedhara.ds@intel.com> Signed-off-by: Alan Cox <alan@linux.intel.com>