1 // SPDX-License-Identifier: GPL-2.0-only
3 * LEDs driver for PCEngines WRAP
5 * Copyright (C) 2006 Kristian Kielhofner <kris@krisk.org>
7 * Based on leds-net48xx.c
10 #include <linux/kernel.h>
11 #include <linux/init.h>
12 #include <linux/platform_device.h>
13 #include <linux/leds.h>
14 #include <linux/err.h>
16 #include <linux/scx200_gpio.h>
17 #include <linux/module.h>
19 #define DRVNAME "wrap-led"
20 #define WRAP_POWER_LED_GPIO 2
21 #define WRAP_ERROR_LED_GPIO 3
22 #define WRAP_EXTRA_LED_GPIO 18
24 static struct platform_device *pdev;
26 static void wrap_power_led_set(struct led_classdev *led_cdev,
27 enum led_brightness value)
30 scx200_gpio_set_low(WRAP_POWER_LED_GPIO);
32 scx200_gpio_set_high(WRAP_POWER_LED_GPIO);
35 static void wrap_error_led_set(struct led_classdev *led_cdev,
36 enum led_brightness value)
39 scx200_gpio_set_low(WRAP_ERROR_LED_GPIO);
41 scx200_gpio_set_high(WRAP_ERROR_LED_GPIO);
44 static void wrap_extra_led_set(struct led_classdev *led_cdev,
45 enum led_brightness value)
48 scx200_gpio_set_low(WRAP_EXTRA_LED_GPIO);
50 scx200_gpio_set_high(WRAP_EXTRA_LED_GPIO);
53 static struct led_classdev wrap_power_led = {
54 .name = "wrap::power",
55 .brightness_set = wrap_power_led_set,
56 .default_trigger = "default-on",
57 .flags = LED_CORE_SUSPENDRESUME,
60 static struct led_classdev wrap_error_led = {
61 .name = "wrap::error",
62 .brightness_set = wrap_error_led_set,
63 .flags = LED_CORE_SUSPENDRESUME,
66 static struct led_classdev wrap_extra_led = {
67 .name = "wrap::extra",
68 .brightness_set = wrap_extra_led_set,
69 .flags = LED_CORE_SUSPENDRESUME,
72 static int wrap_led_probe(struct platform_device *pdev)
76 ret = devm_led_classdev_register(&pdev->dev, &wrap_power_led);
80 ret = devm_led_classdev_register(&pdev->dev, &wrap_error_led);
84 return devm_led_classdev_register(&pdev->dev, &wrap_extra_led);
87 static struct platform_driver wrap_led_driver = {
88 .probe = wrap_led_probe,
94 static int __init wrap_led_init(void)
98 if (!scx200_gpio_present()) {
103 ret = platform_driver_register(&wrap_led_driver);
107 pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0);
110 platform_driver_unregister(&wrap_led_driver);
118 static void __exit wrap_led_exit(void)
120 platform_device_unregister(pdev);
121 platform_driver_unregister(&wrap_led_driver);
124 module_init(wrap_led_init);
125 module_exit(wrap_led_exit);
127 MODULE_AUTHOR("Kristian Kielhofner <kris@krisk.org>");
128 MODULE_DESCRIPTION("PCEngines WRAP LED driver");
129 MODULE_LICENSE("GPL");