1
2
3
4
5
6
7
8
9
10
11
12
13#include <linux/kernel.h>
14#include <linux/init.h>
15#include <linux/platform_device.h>
16#include <linux/leds.h>
17#include <linux/err.h>
18#include <linux/io.h>
19#include <linux/scx200_gpio.h>
20#include <linux/module.h>
21
22#define DRVNAME "wrap-led"
23#define WRAP_POWER_LED_GPIO 2
24#define WRAP_ERROR_LED_GPIO 3
25#define WRAP_EXTRA_LED_GPIO 18
26
27static struct platform_device *pdev;
28
29static void wrap_power_led_set(struct led_classdev *led_cdev,
30 enum led_brightness value)
31{
32 if (value)
33 scx200_gpio_set_low(WRAP_POWER_LED_GPIO);
34 else
35 scx200_gpio_set_high(WRAP_POWER_LED_GPIO);
36}
37
38static void wrap_error_led_set(struct led_classdev *led_cdev,
39 enum led_brightness value)
40{
41 if (value)
42 scx200_gpio_set_low(WRAP_ERROR_LED_GPIO);
43 else
44 scx200_gpio_set_high(WRAP_ERROR_LED_GPIO);
45}
46
47static void wrap_extra_led_set(struct led_classdev *led_cdev,
48 enum led_brightness value)
49{
50 if (value)
51 scx200_gpio_set_low(WRAP_EXTRA_LED_GPIO);
52 else
53 scx200_gpio_set_high(WRAP_EXTRA_LED_GPIO);
54}
55
56static struct led_classdev wrap_power_led = {
57 .name = "wrap::power",
58 .brightness_set = wrap_power_led_set,
59 .default_trigger = "default-on",
60 .flags = LED_CORE_SUSPENDRESUME,
61};
62
63static struct led_classdev wrap_error_led = {
64 .name = "wrap::error",
65 .brightness_set = wrap_error_led_set,
66 .flags = LED_CORE_SUSPENDRESUME,
67};
68
69static struct led_classdev wrap_extra_led = {
70 .name = "wrap::extra",
71 .brightness_set = wrap_extra_led_set,
72 .flags = LED_CORE_SUSPENDRESUME,
73};
74
75static int wrap_led_probe(struct platform_device *pdev)
76{
77 int ret;
78
79 ret = led_classdev_register(&pdev->dev, &wrap_power_led);
80 if (ret < 0)
81 return ret;
82
83 ret = led_classdev_register(&pdev->dev, &wrap_error_led);
84 if (ret < 0)
85 goto err1;
86
87 ret = led_classdev_register(&pdev->dev, &wrap_extra_led);
88 if (ret < 0)
89 goto err2;
90
91 return ret;
92
93err2:
94 led_classdev_unregister(&wrap_error_led);
95err1:
96 led_classdev_unregister(&wrap_power_led);
97
98 return ret;
99}
100
101static int wrap_led_remove(struct platform_device *pdev)
102{
103 led_classdev_unregister(&wrap_power_led);
104 led_classdev_unregister(&wrap_error_led);
105 led_classdev_unregister(&wrap_extra_led);
106 return 0;
107}
108
109static struct platform_driver wrap_led_driver = {
110 .probe = wrap_led_probe,
111 .remove = wrap_led_remove,
112 .driver = {
113 .name = DRVNAME,
114 },
115};
116
117static int __init wrap_led_init(void)
118{
119 int ret;
120
121 if (!scx200_gpio_present()) {
122 ret = -ENODEV;
123 goto out;
124 }
125
126 ret = platform_driver_register(&wrap_led_driver);
127 if (ret < 0)
128 goto out;
129
130 pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0);
131 if (IS_ERR(pdev)) {
132 ret = PTR_ERR(pdev);
133 platform_driver_unregister(&wrap_led_driver);
134 goto out;
135 }
136
137out:
138 return ret;
139}
140
141static void __exit wrap_led_exit(void)
142{
143 platform_device_unregister(pdev);
144 platform_driver_unregister(&wrap_led_driver);
145}
146
147module_init(wrap_led_init);
148module_exit(wrap_led_exit);
149
150MODULE_AUTHOR("Kristian Kielhofner <kris@krisk.org>");
151MODULE_DESCRIPTION("PCEngines WRAP LED driver");
152MODULE_LICENSE("GPL");
153
154