Loading...
Note: File does not exist in v3.1.
1// SPDX-License-Identifier: GPL-2.0
2/* Author: Hans de Goede <hdegoede@redhat.com> */
3
4#include <linux/acpi.h>
5#include <linux/gpio/consumer.h>
6#include <linux/leds.h>
7#include "common.h"
8
9static int int3472_pled_set(struct led_classdev *led_cdev,
10 enum led_brightness brightness)
11{
12 struct int3472_discrete_device *int3472 =
13 container_of(led_cdev, struct int3472_discrete_device, pled.classdev);
14
15 gpiod_set_value_cansleep(int3472->pled.gpio, brightness);
16 return 0;
17}
18
19int skl_int3472_register_pled(struct int3472_discrete_device *int3472, struct gpio_desc *gpio)
20{
21 char *p;
22 int ret;
23
24 if (int3472->pled.classdev.dev)
25 return -EBUSY;
26
27 int3472->pled.gpio = gpio;
28
29 /* Generate the name, replacing the ':' in the ACPI devname with '_' */
30 snprintf(int3472->pled.name, sizeof(int3472->pled.name),
31 "%s::privacy_led", acpi_dev_name(int3472->sensor));
32 p = strchr(int3472->pled.name, ':');
33 if (p)
34 *p = '_';
35
36 int3472->pled.classdev.name = int3472->pled.name;
37 int3472->pled.classdev.max_brightness = 1;
38 int3472->pled.classdev.brightness_set_blocking = int3472_pled_set;
39
40 ret = led_classdev_register(int3472->dev, &int3472->pled.classdev);
41 if (ret)
42 return ret;
43
44 int3472->pled.lookup.provider = int3472->pled.name;
45 int3472->pled.lookup.dev_id = int3472->sensor_name;
46 int3472->pled.lookup.con_id = "privacy-led";
47 led_add_lookup(&int3472->pled.lookup);
48
49 return 0;
50}
51
52void skl_int3472_unregister_pled(struct int3472_discrete_device *int3472)
53{
54 if (IS_ERR_OR_NULL(int3472->pled.classdev.dev))
55 return;
56
57 led_remove_lookup(&int3472->pled.lookup);
58 led_classdev_unregister(&int3472->pled.classdev);
59}