more danube 2 ifxmips transitions
[openwrt.git] / target / linux / danube / files / drivers / char / danube_led.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 <asm/uaccess.h>
28 #include <asm/unistd.h>
29 #include <linux/errno.h>
30 #include <asm/danube/danube.h>
31 #include <asm/danube/danube_gpio.h>
32 #include <asm/danube/danube_pmu.h>
33
34 #define DANUBE_LED_CLK_EDGE DANUBE_LED_FALLING
35 //#define DANUBE_LED_CLK_EDGE DANUBE_LED_RISING
36
37 #define DANUBE_LED_SPEED DANUBE_LED_8HZ
38
39 #define DANUBE_LED_GPIO_PORT 0
40
41 static int danube_led_major;
42
43 void
44 danube_led_set (unsigned int led)
45 {
46 led &= 0xffffff;
47 writel(readl(DANUBE_LED_CPU0) | led, DANUBE_LED_CPU0);
48 }
49 EXPORT_SYMBOL(danube_led_set);
50
51 void
52 danube_led_clear (unsigned int led)
53 {
54 led = ~(led & 0xffffff);
55 writel(readl(DANUBE_LED_CPU0) & led, DANUBE_LED_CPU0);
56 }
57 EXPORT_SYMBOL(danube_led_clear);
58
59 void
60 danube_led_blink_set (unsigned int led)
61 {
62 led &= 0xffffff;
63 writel(readl(DANUBE_LED_CON0) | led, DANUBE_LED_CON0);
64 }
65 EXPORT_SYMBOL(danube_led_blink_set);
66
67 void
68 danube_led_blink_clear (unsigned int led)
69 {
70 led = ~(led & 0xffffff);
71 writel(readl(DANUBE_LED_CON0) & led, DANUBE_LED_CON0);
72 }
73 EXPORT_SYMBOL(danube_led_blink_clear);
74
75 void
76 danube_led_setup_gpio (void)
77 {
78 int i = 0;
79
80 /* we need to setup pins SH,D,ST (4,5,6) */
81 for (i = 4; i < 7; i++)
82 {
83 danube_port_set_altsel0(DANUBE_LED_GPIO_PORT, i);
84 danube_port_clear_altsel1(DANUBE_LED_GPIO_PORT, i);
85 danube_port_set_dir_out(DANUBE_LED_GPIO_PORT, i);
86 danube_port_set_open_drain(DANUBE_LED_GPIO_PORT, i);
87 }
88 }
89
90 static int
91 led_ioctl (struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
92 {
93 int ret = -EINVAL;
94
95 switch ( cmd )
96 {
97 }
98
99 return ret;
100 }
101
102 static int
103 led_open (struct inode *inode, struct file *file)
104 {
105 return 0;
106 }
107
108 static int
109 led_release (struct inode *inode, struct file *file)
110 {
111 return 0;
112 }
113
114 static struct file_operations danube_led_fops = {
115 .owner = THIS_MODULE,
116 .ioctl = led_ioctl,
117 .open = led_open,
118 .release = led_release
119 };
120
121
122 /*
123 Map for LED on reference board
124 WLAN_READ LED11 OUT1 15
125 WARNING LED12 OUT2 14
126 FXS1_LINK LED13 OUT3 13
127 FXS2_LINK LED14 OUT4 12
128 FXO_ACT LED15 OUT5 11
129 USB_LINK LED16 OUT6 10
130 ADSL2_LINK LED19 OUT7 9
131 BT_LINK LED17 OUT8 8
132 SD_LINK LED20 OUT9 7
133 ADSL2_TRAFFIC LED31 OUT16 0
134 Map for hardware relay on reference board
135 USB Power On OUT11 5
136 RELAY OUT12 4
137 */
138
139
140 int __init
141 danube_led_init (void)
142 {
143 int ret = 0;
144
145 danube_led_setup_gpio();
146
147 writel(0, DANUBE_LED_AR);
148 writel(0, DANUBE_LED_CPU0);
149 writel(0, DANUBE_LED_CPU1);
150 writel(LED_CON0_SWU, DANUBE_LED_CON0);
151 writel(0, DANUBE_LED_CON1);
152
153 /* setup the clock edge that the shift register is triggered on */
154 writel(readl(DANUBE_LED_CON0) & ~DANUBE_LED_EDGE_MASK, DANUBE_LED_CON0);
155 writel(readl(DANUBE_LED_CON0) | DANUBE_LED_CLK_EDGE, DANUBE_LED_CON0);
156
157 /* per default leds 15-0 are set */
158 writel(DANUBE_LED_GROUP1 | DANUBE_LED_GROUP0, DANUBE_LED_CON1);
159
160 /* leds are update periodically by the FPID */
161 writel(readl(DANUBE_LED_CON1) & ~DANUBE_LED_UPD_MASK, DANUBE_LED_CON1);
162 writel(readl(DANUBE_LED_CON1) | DANUBE_LED_UPD_SRC_FPI, DANUBE_LED_CON1);
163
164 /* set led update speed */
165 writel(readl(DANUBE_LED_CON1) & ~DANUBE_LED_MASK, DANUBE_LED_CON1);
166 writel(readl(DANUBE_LED_CON1) | DANUBE_LED_SPEED, DANUBE_LED_CON1);
167
168 /* adsl 0 and 1 leds are updated by the arc */
169 writel(readl(DANUBE_LED_CON0) | DANUBE_LED_ADSL_SRC, DANUBE_LED_CON0);
170
171 /* per default, the leds are turned on */
172 danube_pmu_enable(DANUBE_PMU_PWDCR_LED);
173
174 danube_led_major = register_chrdev(0, "danube_led", &danube_led_fops);
175
176 if (!danube_led_major)
177 {
178 printk("danube_led: Error! Could not register device. %d\n", danube_led_major);
179 ret = -EINVAL;
180
181 goto out;
182 }
183
184 printk(KERN_INFO "danube_led : device registered on major %d\n", danube_led_major);
185
186 out:
187 return ret;
188 }
189
190 void __exit
191 danube_led_exit (void)
192 {
193 unregister_chrdev(danube_led_major, "danube_led");
194 }
195
196 module_init(danube_led_init);
197 module_exit(danube_led_exit);
This page took 0.055114 seconds and 5 git commands to generate.