Split the led driver
[openwrt.git] / target / linux / au1000-2.6 / files / drivers / leds / leds-mtx1.c
1 /*
2 * LED driver for MTX-1 boards
3 *
4 * Copyright 2007 Florian Fainelli <florian@openwrt.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 */
11
12 #include <linux/kernel.h>
13 #include <linux/init.h>
14 #include <linux/platform_device.h>
15 #include <linux/leds.h>
16 #include <linux/err.h>
17 #include <asm/mach-au1x00/au1000.h>
18
19 static struct platform_device *pdev;
20
21 static void mtx1_green_led_set(struct led_classdev *led_cdev, enum led_brightness brightness)
22 {
23 /* The power LED cannot be controlled the same way as for the Status LED */
24 if (brightness) {
25 au_writel( 0x18000800, GPIO2_OUTPUT );
26 } else {
27 au_writel( 0x18000000, GPIO2_OUTPUT);
28 }
29 }
30
31 static void mtx1_red_led_set(struct led_classdev *led_cdev, enum led_brightness brightness)
32 {
33 /* We store GPIO address (originally address - 200) in the "flags" field*/
34 unsigned long pinmask = 1 << led_cdev->flags;
35 if (brightness) {
36 au_writel((pinmask << 16) | pinmask, GPIO2_OUTPUT);
37 } else {
38 au_writel((pinmask << 16) | 0, GPIO2_OUTPUT);
39 }
40 }
41
42 static struct led_classdev mtx1_green_led = {
43 .name = "mtx1:green",
44 .brightness_set = mtx1_green_led_set,
45 };
46
47 static struct led_classdev mtx1_red_led = {
48 .name = "mtx1:red",
49 .flags = 12,
50 .brightness_set = mtx1_red_led_set,
51 .default_trigger = "ide-disk",
52 };
53
54 static int mtx1_leds_probe(struct platform_device *pdev)
55 {
56 int ret;
57
58 ret = led_classdev_register(&pdev->dev, &mtx1_green_led);
59 if (ret < 0)
60 goto out;
61
62 ret = led_classdev_register(&pdev->dev, &mtx1_red_led);
63 if (ret < 0)
64 led_classdev_unregister(&mtx1_green_led);
65
66 out:
67 return ret;
68 }
69
70 static int mtx1_leds_remove(struct platform_device *pdev)
71 {
72 led_classdev_unregister(&mtx1_green_led);
73 led_classdev_unregister(&mtx1_red_led);
74 return 0;
75 }
76
77 static struct platform_driver mtx1_leds_driver = {
78 .probe = mtx1_leds_probe,
79 .remove = mtx1_leds_remove,
80 .driver = {
81 .name = "mtx1-leds",
82 }
83 };
84
85 static int __init mtx1_leds_init(void)
86 {
87 int ret;
88
89 ret = platform_driver_register(&mtx1_leds_driver);
90 if (ret < 0)
91 goto out;
92
93 pdev = platform_device_register_simple("mtx1-leds", -1, NULL, 0);
94 if (IS_ERR(pdev)) {
95 ret = PTR_ERR(pdev);
96 platform_driver_unregister(&mtx1_leds_driver);
97 goto out;
98 }
99
100 out:
101 return ret;
102
103 }
104
105 static void __exit mtx1_leds_exit(void)
106 {
107 platform_device_unregister(pdev);
108 platform_driver_unregister(&mtx1_leds_driver);
109 }
110
111 module_init(mtx1_leds_init);
112 module_exit(mtx1_leds_exit);
113
114 MODULE_AUTHOR("Florian Fainelli <florian@openwrt.org>");
115 MODULE_DESCRIPTION("MTX-1 LED driver");
116 MODULE_LICENSE("GPL");
This page took 0.051467 seconds and 5 git commands to generate.