several cleanups for ifxmips. removes all code that has not been cleaned up properly
[openwrt.git] / target / linux / ifxmips / files / drivers / leds / leds-ifxmips.c
1 /*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
15 *
16 * Copyright (C) 2006 infineon
17 * Copyright (C) 2007 John Crispin <blogic@openwrt.org>
18 *
19 */
20
21 #include <linux/kernel.h>
22 #include <linux/module.h>
23 #include <linux/version.h>
24 #include <linux/types.h>
25 #include <linux/fs.h>
26 #include <linux/init.h>
27 #include <linux/platform_device.h>
28 #include <linux/uaccess.h>
29 #include <linux/unistd.h>
30 #include <linux/errno.h>
31 #include <linux/leds.h>
32 #include <linux/delay.h>
33
34 #include <asm/ifxmips/ifxmips.h>
35 #include <asm/ifxmips/ifxmips_gpio.h>
36 #include <asm/ifxmips/ifxmips_pmu.h>
37
38 #define DRVNAME "ifxmips_led"
39
40 /* might need to be changed depending on shift register used on the pcb */
41 #if 1
42 #define IFXMIPS_LED_CLK_EDGE IFXMIPS_LED_FALLING
43 #else
44 #define IFXMIPS_LED_CLK_EDGE IFXMIPS_LED_RISING
45 #endif
46
47 #define IFXMIPS_LED_SPEED IFXMIPS_LED_8HZ
48
49 #define IFXMIPS_LED_GPIO_PORT 0
50
51 #define IFXMIPS_MAX_LED 24
52
53 struct ifxmips_led {
54 struct led_classdev cdev;
55 u8 bit;
56 };
57
58 void ifxmips_led_set(unsigned int led)
59 {
60 led &= 0xffffff;
61 ifxmips_w32(ifxmips_r32(IFXMIPS_LED_CPU0) | led, IFXMIPS_LED_CPU0);
62 }
63 EXPORT_SYMBOL(ifxmips_led_set);
64
65 void ifxmips_led_clear(unsigned int led)
66 {
67 led = ~(led & 0xffffff);
68 ifxmips_w32(ifxmips_r32(IFXMIPS_LED_CPU0) & led, IFXMIPS_LED_CPU0);
69 }
70 EXPORT_SYMBOL(ifxmips_led_clear);
71
72 void ifxmips_led_blink_set(unsigned int led)
73 {
74 led &= 0xffffff;
75 ifxmips_w32(ifxmips_r32(IFXMIPS_LED_CON0) | led, IFXMIPS_LED_CON0);
76 }
77 EXPORT_SYMBOL(ifxmips_led_blink_set);
78
79 void ifxmips_led_blink_clear(unsigned int led)
80 {
81 led = ~(led & 0xffffff);
82 ifxmips_w32(ifxmips_r32(IFXMIPS_LED_CON0) & led, IFXMIPS_LED_CON0);
83 }
84 EXPORT_SYMBOL(ifxmips_led_blink_clear);
85
86 static void ifxmips_ledapi_set(struct led_classdev *led_cdev,
87 enum led_brightness value)
88 {
89 struct ifxmips_led *led_dev =
90 container_of(led_cdev, struct ifxmips_led, cdev);
91
92 if (value)
93 ifxmips_led_set(1 << led_dev->bit);
94 else
95 ifxmips_led_clear(1 << led_dev->bit);
96 }
97
98 void ifxmips_led_setup_gpio(void)
99 {
100 int i = 0;
101
102 /* leds are controlled via a shift register
103 we need to setup pins SH,D,ST (4,5,6) to make it work */
104 for (i = 4; i < 7; i++) {
105 ifxmips_port_set_altsel0(IFXMIPS_LED_GPIO_PORT, i);
106 ifxmips_port_clear_altsel1(IFXMIPS_LED_GPIO_PORT, i);
107 ifxmips_port_set_dir_out(IFXMIPS_LED_GPIO_PORT, i);
108 ifxmips_port_set_open_drain(IFXMIPS_LED_GPIO_PORT, i);
109 }
110 }
111
112 static int ifxmips_led_probe(struct platform_device *dev)
113 {
114 int i = 0;
115
116 ifxmips_led_setup_gpio();
117
118 ifxmips_w32(0, IFXMIPS_LED_AR);
119 ifxmips_w32(0, IFXMIPS_LED_CPU0);
120 ifxmips_w32(0, IFXMIPS_LED_CPU1);
121 ifxmips_w32(LED_CON0_SWU, IFXMIPS_LED_CON0);
122 ifxmips_w32(0, IFXMIPS_LED_CON1);
123
124 /* setup the clock edge that the shift register is triggered on */
125 ifxmips_w32(ifxmips_r32(IFXMIPS_LED_CON0) & ~IFXMIPS_LED_EDGE_MASK,
126 IFXMIPS_LED_CON0);
127 ifxmips_w32(ifxmips_r32(IFXMIPS_LED_CON0) | IFXMIPS_LED_CLK_EDGE,
128 IFXMIPS_LED_CON0);
129
130 /* per default leds 15-0 are set */
131 ifxmips_w32(IFXMIPS_LED_GROUP1 | IFXMIPS_LED_GROUP0, IFXMIPS_LED_CON1);
132
133 /* leds are update periodically by the FPID */
134 ifxmips_w32(ifxmips_r32(IFXMIPS_LED_CON1) & ~IFXMIPS_LED_UPD_MASK,
135 IFXMIPS_LED_CON1);
136 ifxmips_w32(ifxmips_r32(IFXMIPS_LED_CON1) | IFXMIPS_LED_UPD_SRC_FPI,
137 IFXMIPS_LED_CON1);
138
139 /* set led update speed */
140 ifxmips_w32(ifxmips_r32(IFXMIPS_LED_CON1) & ~IFXMIPS_LED_MASK,
141 IFXMIPS_LED_CON1);
142 ifxmips_w32(ifxmips_r32(IFXMIPS_LED_CON1) | IFXMIPS_LED_SPEED,
143 IFXMIPS_LED_CON1);
144
145 /* adsl 0 and 1 leds are updated by the arc */
146 ifxmips_w32(ifxmips_r32(IFXMIPS_LED_CON0) | IFXMIPS_LED_ADSL_SRC,
147 IFXMIPS_LED_CON0);
148
149 /* per default, the leds are turned on */
150 ifxmips_pmu_enable(IFXMIPS_PMU_PWDCR_LED);
151
152 for (i = 0; i < IFXMIPS_MAX_LED; i++) {
153 struct ifxmips_led *tmp =
154 kzalloc(sizeof(struct ifxmips_led), GFP_KERNEL);
155 tmp->cdev.brightness_set = ifxmips_ledapi_set;
156 tmp->cdev.name = kmalloc(sizeof("ifxmips:led:00"), GFP_KERNEL);
157 sprintf((char *)tmp->cdev.name, "ifxmips:led:%02d", i);
158 tmp->cdev.default_trigger = NULL;
159 tmp->bit = i;
160 led_classdev_register(&dev->dev, &tmp->cdev);
161 }
162
163 return 0;
164 }
165
166 static int ifxmips_led_remove(struct platform_device *pdev)
167 {
168 return 0;
169 }
170
171 static struct platform_driver ifxmips_led_driver = {
172 .probe = ifxmips_led_probe,
173 .remove = ifxmips_led_remove,
174 .driver = {
175 .name = DRVNAME,
176 .owner = THIS_MODULE,
177 },
178 };
179
180 int __init ifxmips_led_init(void)
181 {
182 int ret = platform_driver_register(&ifxmips_led_driver);
183 if (ret)
184 printk(KERN_INFO
185 "ifxmips_led: Error registering platfom driver!");
186
187 return ret;
188 }
189
190 void __exit ifxmips_led_exit(void)
191 {
192 platform_driver_unregister(&ifxmips_led_driver);
193 }
194
195 module_init(ifxmips_led_init);
196 module_exit(ifxmips_led_exit);
This page took 0.059325 seconds and 5 git commands to generate.