Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / leds / leds-wrap.c
blob794697e160685cbfd8ccb381f9e814880f62965d
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * LEDs driver for PCEngines WRAP
5 * Copyright (C) 2006 Kristian Kielhofner <kris@krisk.org>
7 * Based on leds-net48xx.c
8 */
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>
15 #include <linux/io.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)
29 if (value)
30 scx200_gpio_set_low(WRAP_POWER_LED_GPIO);
31 else
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)
38 if (value)
39 scx200_gpio_set_low(WRAP_ERROR_LED_GPIO);
40 else
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)
47 if (value)
48 scx200_gpio_set_low(WRAP_EXTRA_LED_GPIO);
49 else
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)
74 int ret;
76 ret = devm_led_classdev_register(&pdev->dev, &wrap_power_led);
77 if (ret < 0)
78 return ret;
80 ret = devm_led_classdev_register(&pdev->dev, &wrap_error_led);
81 if (ret < 0)
82 return ret;
84 return devm_led_classdev_register(&pdev->dev, &wrap_extra_led);
87 static struct platform_driver wrap_led_driver = {
88 .probe = wrap_led_probe,
89 .driver = {
90 .name = DRVNAME,
94 static int __init wrap_led_init(void)
96 int ret;
98 if (!scx200_gpio_present()) {
99 ret = -ENODEV;
100 goto out;
103 ret = platform_driver_register(&wrap_led_driver);
104 if (ret < 0)
105 goto out;
107 pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0);
108 if (IS_ERR(pdev)) {
109 ret = PTR_ERR(pdev);
110 platform_driver_unregister(&wrap_led_driver);
111 goto out;
114 out:
115 return ret;
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");