From 64d7e23115dd91997858eb0c370d798a0d6bf118 Mon Sep 17 00:00:00 2001 From: Thomas Bogendoerfer Date: Mon, 24 Feb 2020 12:17:33 +0100 Subject: leds: add SGI IP30 led support This patch implemenets a driver to support the front panel LEDs of SGI Octane (IP30) workstations. Reviewed-by: Dan Murphy Signed-off-by: Thomas Bogendoerfer Acked-by: Jacek Anaszewski Signed-off-by: Pavel Machek --- drivers/leds/leds-ip30.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 drivers/leds/leds-ip30.c (limited to 'drivers/leds/leds-ip30.c') diff --git a/drivers/leds/leds-ip30.c b/drivers/leds/leds-ip30.c new file mode 100644 index 000000000000..e95ea786a43e --- /dev/null +++ b/drivers/leds/leds-ip30.c @@ -0,0 +1,86 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * LED Driver for SGI Octane machines + */ + +#include +#include +#include +#include + +#define IP30_LED_SYSTEM 0 +#define IP30_LED_FAULT 1 + +struct ip30_led { + struct led_classdev cdev; + u32 __iomem *reg; +}; + +static void ip30led_set(struct led_classdev *led_cdev, + enum led_brightness value) +{ + struct ip30_led *led = container_of(led_cdev, struct ip30_led, cdev); + + writel(value, led->reg); +} + +static int ip30led_create(struct platform_device *pdev, int num) +{ + struct resource *res; + struct ip30_led *data; + + res = platform_get_resource(pdev, IORESOURCE_MEM, num); + if (!res) + return -EBUSY; + + data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + if (!data) + return -ENOMEM; + + data->reg = devm_ioremap_resource(&pdev->dev, res); + if (IS_ERR(data->reg)) + return PTR_ERR(data->reg); + + + switch (num) { + case IP30_LED_SYSTEM: + data->cdev.name = "white:system"; + break; + case IP30_LED_FAULT: + data->cdev.name = "red:fault"; + break; + default: + return -EINVAL; + } + + data->cdev.brightness = readl(data->reg); + data->cdev.max_brightness = 1; + data->cdev.brightness_set = ip30led_set; + + return devm_led_classdev_register(&pdev->dev, &data->cdev); +} + +static int ip30led_probe(struct platform_device *pdev) +{ + int ret; + + ret = ip30led_create(pdev, IP30_LED_SYSTEM); + if (ret < 0) + return ret; + + return ip30led_create(pdev, IP30_LED_FAULT); +} + +static struct platform_driver ip30led_driver = { + .probe = ip30led_probe, + .driver = { + .name = "ip30-leds", + }, +}; + +module_platform_driver(ip30led_driver); + +MODULE_AUTHOR("Thomas Bogendoerfer "); +MODULE_DESCRIPTION("SGI Octane LED driver"); +MODULE_LICENSE("GPL"); +MODULE_ALIAS("platform:ip30-leds"); -- cgit v1.2.3 From 19aa98409066b6e0f1f7ecfb404a983724f946f0 Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Sat, 21 Mar 2020 17:00:27 +0100 Subject: leds: ip30: label power LED as such Make label "white:power" to be consistent with dt-bindings/leds/common.h . Signed-off-by: Pavel Machek --- drivers/leds/leds-ip30.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/leds/leds-ip30.c') diff --git a/drivers/leds/leds-ip30.c b/drivers/leds/leds-ip30.c index e95ea786a43e..d4ec7361c616 100644 --- a/drivers/leds/leds-ip30.c +++ b/drivers/leds/leds-ip30.c @@ -44,7 +44,7 @@ static int ip30led_create(struct platform_device *pdev, int num) switch (num) { case IP30_LED_SYSTEM: - data->cdev.name = "white:system"; + data->cdev.name = "white:power"; break; case IP30_LED_FAULT: data->cdev.name = "red:fault"; -- cgit v1.2.3