Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / drivers / platform / x86 / intel / int3472 / led.c
blob9cbed694e2caae5bed8959c5f0cd61307e92ce90
1 // SPDX-License-Identifier: GPL-2.0
2 /* Author: Hans de Goede <hdegoede@redhat.com> */
4 #include <linux/acpi.h>
5 #include <linux/gpio/consumer.h>
6 #include <linux/leds.h>
7 #include "common.h"
9 static int int3472_pled_set(struct led_classdev *led_cdev,
10 enum led_brightness brightness)
12 struct int3472_discrete_device *int3472 =
13 container_of(led_cdev, struct int3472_discrete_device, pled.classdev);
15 gpiod_set_value_cansleep(int3472->pled.gpio, brightness);
16 return 0;
19 int skl_int3472_register_pled(struct int3472_discrete_device *int3472, struct gpio_desc *gpio)
21 char *p;
22 int ret;
24 if (int3472->pled.classdev.dev)
25 return -EBUSY;
27 int3472->pled.gpio = gpio;
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 = '_';
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;
40 ret = led_classdev_register(int3472->dev, &int3472->pled.classdev);
41 if (ret)
42 return ret;
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);
49 return 0;
52 void skl_int3472_unregister_pled(struct int3472_discrete_device *int3472)
54 if (IS_ERR_OR_NULL(int3472->pled.classdev.dev))
55 return;
57 led_remove_lookup(&int3472->pled.lookup);
58 led_classdev_unregister(&int3472->pled.classdev);