blob: 7ac61a7b56ad9b5d62a035f05f530a567c5deacb [file] [log] [blame]
Kristian Kielhofner0d755652006-12-06 20:37:28 -08001/*
2 * LEDs driver for PCEngines WRAP
3 *
4 * Copyright (C) 2006 Kristian Kielhofner <kris@krisk.org>
5 *
6 * Based on leds-net48xx.c
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
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 <asm/io.h>
19#include <linux/scx200_gpio.h>
20
21#define DRVNAME "wrap-led"
Michael Loefflerf5506a22008-01-13 23:20:52 +000022#define WRAP_POWER_LED_GPIO 2
Kristian Kielhofner0d755652006-12-06 20:37:28 -080023#define WRAP_ERROR_LED_GPIO 3
Michael Loefflerf5506a22008-01-13 23:20:52 +000024#define WRAP_EXTRA_LED_GPIO 18
Kristian Kielhofner0d755652006-12-06 20:37:28 -080025
26static struct platform_device *pdev;
27
Michael Loefflerf5506a22008-01-13 23:20:52 +000028static void wrap_power_led_set(struct led_classdev *led_cdev,
29 enum led_brightness value)
30{
31 if (value)
32 scx200_gpio_set_low(WRAP_POWER_LED_GPIO);
33 else
34 scx200_gpio_set_high(WRAP_POWER_LED_GPIO);
35}
36
Kristian Kielhofner0d755652006-12-06 20:37:28 -080037static void wrap_error_led_set(struct led_classdev *led_cdev,
38 enum led_brightness value)
39{
40 if (value)
41 scx200_gpio_set_low(WRAP_ERROR_LED_GPIO);
42 else
43 scx200_gpio_set_high(WRAP_ERROR_LED_GPIO);
44}
45
46static void wrap_extra_led_set(struct led_classdev *led_cdev,
47 enum led_brightness value)
48{
49 if (value)
50 scx200_gpio_set_low(WRAP_EXTRA_LED_GPIO);
51 else
52 scx200_gpio_set_high(WRAP_EXTRA_LED_GPIO);
53}
54
Michael Loefflerf5506a22008-01-13 23:20:52 +000055static struct led_classdev wrap_power_led = {
56 .name = "wrap::power",
57 .brightness_set = wrap_power_led_set,
58};
59
Kristian Kielhofner0d755652006-12-06 20:37:28 -080060static struct led_classdev wrap_error_led = {
Richard Purdie6c152be2007-10-31 15:00:07 +010061 .name = "wrap::error",
Kristian Kielhofner0d755652006-12-06 20:37:28 -080062 .brightness_set = wrap_error_led_set,
63};
64
65static struct led_classdev wrap_extra_led = {
Richard Purdie6c152be2007-10-31 15:00:07 +010066 .name = "wrap::extra",
Kristian Kielhofner0d755652006-12-06 20:37:28 -080067 .brightness_set = wrap_extra_led_set,
68};
69
70#ifdef CONFIG_PM
71static int wrap_led_suspend(struct platform_device *dev,
72 pm_message_t state)
73{
Michael Loefflerf5506a22008-01-13 23:20:52 +000074 led_classdev_suspend(&wrap_power_led);
Kristian Kielhofner0d755652006-12-06 20:37:28 -080075 led_classdev_suspend(&wrap_error_led);
76 led_classdev_suspend(&wrap_extra_led);
77 return 0;
78}
79
80static int wrap_led_resume(struct platform_device *dev)
81{
Michael Loefflerf5506a22008-01-13 23:20:52 +000082 led_classdev_resume(&wrap_power_led);
Kristian Kielhofner0d755652006-12-06 20:37:28 -080083 led_classdev_resume(&wrap_error_led);
84 led_classdev_resume(&wrap_extra_led);
85 return 0;
86}
87#else
88#define wrap_led_suspend NULL
89#define wrap_led_resume NULL
90#endif
91
92static int wrap_led_probe(struct platform_device *pdev)
93{
94 int ret;
95
Michael Loefflerf5506a22008-01-13 23:20:52 +000096 ret = led_classdev_register(&pdev->dev, &wrap_power_led);
97 if (ret < 0)
98 return ret;
99
Kristian Kielhofner0d755652006-12-06 20:37:28 -0800100 ret = led_classdev_register(&pdev->dev, &wrap_error_led);
Michael Loefflerf5506a22008-01-13 23:20:52 +0000101 if (ret < 0)
102 goto err1;
103
104 ret = led_classdev_register(&pdev->dev, &wrap_extra_led);
105 if (ret < 0)
106 goto err2;
107
108 return ret;
109
110err2:
111 led_classdev_unregister(&wrap_error_led);
112err1:
113 led_classdev_unregister(&wrap_power_led);
114
Kristian Kielhofner0d755652006-12-06 20:37:28 -0800115 return ret;
116}
117
118static int wrap_led_remove(struct platform_device *pdev)
119{
Michael Loefflerf5506a22008-01-13 23:20:52 +0000120 led_classdev_unregister(&wrap_power_led);
Kristian Kielhofner0d755652006-12-06 20:37:28 -0800121 led_classdev_unregister(&wrap_error_led);
122 led_classdev_unregister(&wrap_extra_led);
123 return 0;
124}
125
126static struct platform_driver wrap_led_driver = {
127 .probe = wrap_led_probe,
128 .remove = wrap_led_remove,
129 .suspend = wrap_led_suspend,
130 .resume = wrap_led_resume,
131 .driver = {
132 .name = DRVNAME,
133 .owner = THIS_MODULE,
134 },
135};
136
137static int __init wrap_led_init(void)
138{
139 int ret;
140
141 if (!scx200_gpio_present()) {
142 ret = -ENODEV;
143 goto out;
144 }
145
146 ret = platform_driver_register(&wrap_led_driver);
147 if (ret < 0)
148 goto out;
149
150 pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0);
151 if (IS_ERR(pdev)) {
152 ret = PTR_ERR(pdev);
153 platform_driver_unregister(&wrap_led_driver);
154 goto out;
155 }
156
157out:
158 return ret;
159}
160
161static void __exit wrap_led_exit(void)
162{
163 platform_device_unregister(pdev);
164 platform_driver_unregister(&wrap_led_driver);
165}
166
167module_init(wrap_led_init);
168module_exit(wrap_led_exit);
169
170MODULE_AUTHOR("Kristian Kielhofner <kris@krisk.org>");
171MODULE_DESCRIPTION("PCEngines WRAP LED driver");
172MODULE_LICENSE("GPL");
173