1 // SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0-or-later
3 * Dell Wyse 3020 a.k.a. "Ariel" Embedded Controller LED Driver
5 * Copyright (C) 2020 Lubomir Rintel
8 #include <linux/module.h>
9 #include <linux/leds.h>
10 #include <linux/regmap.h>
11 #include <linux/of_platform.h>
27 struct regmap *ec_ram;
28 enum ec_index ec_index;
29 struct led_classdev led_cdev;
32 #define led_cdev_to_ariel_led(c) container_of(c, struct ariel_led, led_cdev)
34 static enum led_brightness ariel_led_get(struct led_classdev *led_cdev)
36 struct ariel_led *led = led_cdev_to_ariel_led(led_cdev);
37 unsigned int led_status = 0;
39 if (regmap_read(led->ec_ram, led->ec_index, &led_status))
42 if (led_status == EC_LED_STILL)
48 static void ariel_led_set(struct led_classdev *led_cdev,
49 enum led_brightness brightness)
51 struct ariel_led *led = led_cdev_to_ariel_led(led_cdev);
53 if (brightness == LED_OFF)
54 regmap_write(led->ec_ram, led->ec_index, EC_LED_OFF);
56 regmap_write(led->ec_ram, led->ec_index, EC_LED_STILL);
59 static int ariel_blink_set(struct led_classdev *led_cdev,
60 unsigned long *delay_on, unsigned long *delay_off)
62 struct ariel_led *led = led_cdev_to_ariel_led(led_cdev);
64 if (*delay_on == 0 && *delay_off == 0)
68 regmap_write(led->ec_ram, led->ec_index, EC_LED_OFF);
69 } else if (*delay_off == 0) {
70 regmap_write(led->ec_ram, led->ec_index, EC_LED_STILL);
74 regmap_write(led->ec_ram, led->ec_index, EC_LED_BLINK);
82 static int ariel_led_probe(struct platform_device *pdev)
84 struct device *dev = &pdev->dev;
85 struct ariel_led *leds;
86 struct regmap *ec_ram;
90 ec_ram = dev_get_regmap(dev->parent, "ec_ram");
94 leds = devm_kcalloc(dev, NLEDS, sizeof(*leds), GFP_KERNEL);
98 leds[0].ec_index = EC_BLUE_LED;
99 leds[0].led_cdev.name = "blue:power";
100 leds[0].led_cdev.default_trigger = "default-on";
102 leds[1].ec_index = EC_AMBER_LED;
103 leds[1].led_cdev.name = "amber:status";
105 leds[2].ec_index = EC_GREEN_LED;
106 leds[2].led_cdev.name = "green:status";
107 leds[2].led_cdev.default_trigger = "default-on";
109 for (i = 0; i < NLEDS; i++) {
110 leds[i].ec_ram = ec_ram;
111 leds[i].led_cdev.brightness_get = ariel_led_get;
112 leds[i].led_cdev.brightness_set = ariel_led_set;
113 leds[i].led_cdev.blink_set = ariel_blink_set;
115 ret = devm_led_classdev_register(dev, &leds[i].led_cdev);
123 static struct platform_driver ariel_led_driver = {
124 .probe = ariel_led_probe,
126 .name = "dell-wyse-ariel-led",
129 module_platform_driver(ariel_led_driver);
131 MODULE_AUTHOR("Lubomir Rintel <lkundrak@v3.sk>");
132 MODULE_DESCRIPTION("Dell Wyse 3020 Status LEDs Driver");
133 MODULE_LICENSE("Dual BSD/GPL");