blob: 2982c86ac4cffb9e93da0a252b232a573c02ac22 [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 = {
Sven Wegener6af4f552008-10-13 10:43:47 +010056 .name = "wrap::power",
57 .brightness_set = wrap_power_led_set,
58 .default_trigger = "default-on",
Richard Purdie859cb7f2009-01-08 17:55:03 +000059 .flags = LED_CORE_SUSPENDRESUME,
Michael Loefflerf5506a22008-01-13 23:20:52 +000060};
61
Kristian Kielhofner0d755652006-12-06 20:37:28 -080062static struct led_classdev wrap_error_led = {
Richard Purdie6c152be2007-10-31 15:00:07 +010063 .name = "wrap::error",
Kristian Kielhofner0d755652006-12-06 20:37:28 -080064 .brightness_set = wrap_error_led_set,
Richard Purdie859cb7f2009-01-08 17:55:03 +000065 .flags = LED_CORE_SUSPENDRESUME,
Kristian Kielhofner0d755652006-12-06 20:37:28 -080066};
67
68static struct led_classdev wrap_extra_led = {
Richard Purdie6c152be2007-10-31 15:00:07 +010069 .name = "wrap::extra",
Kristian Kielhofner0d755652006-12-06 20:37:28 -080070 .brightness_set = wrap_extra_led_set,
Richard Purdie859cb7f2009-01-08 17:55:03 +000071 .flags = LED_CORE_SUSPENDRESUME,
Kristian Kielhofner0d755652006-12-06 20:37:28 -080072};
73
Kristian Kielhofner0d755652006-12-06 20:37:28 -080074static int wrap_led_probe(struct platform_device *pdev)
75{
76 int ret;
77
Michael Loefflerf5506a22008-01-13 23:20:52 +000078 ret = led_classdev_register(&pdev->dev, &wrap_power_led);
79 if (ret < 0)
80 return ret;
81
Kristian Kielhofner0d755652006-12-06 20:37:28 -080082 ret = led_classdev_register(&pdev->dev, &wrap_error_led);
Michael Loefflerf5506a22008-01-13 23:20:52 +000083 if (ret < 0)
84 goto err1;
85
86 ret = led_classdev_register(&pdev->dev, &wrap_extra_led);
87 if (ret < 0)
88 goto err2;
89
90 return ret;
91
92err2:
93 led_classdev_unregister(&wrap_error_led);
94err1:
95 led_classdev_unregister(&wrap_power_led);
96
Kristian Kielhofner0d755652006-12-06 20:37:28 -080097 return ret;
98}
99
100static int wrap_led_remove(struct platform_device *pdev)
101{
Michael Loefflerf5506a22008-01-13 23:20:52 +0000102 led_classdev_unregister(&wrap_power_led);
Kristian Kielhofner0d755652006-12-06 20:37:28 -0800103 led_classdev_unregister(&wrap_error_led);
104 led_classdev_unregister(&wrap_extra_led);
105 return 0;
106}
107
108static struct platform_driver wrap_led_driver = {
109 .probe = wrap_led_probe,
110 .remove = wrap_led_remove,
Kristian Kielhofner0d755652006-12-06 20:37:28 -0800111 .driver = {
112 .name = DRVNAME,
113 .owner = THIS_MODULE,
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