more danube 2 ifxmips transitions
[openwrt.git] / target / linux / ifxmips / files / drivers / char / ifxmips_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/ifxmips/ifxmips.h>
31 #include <asm/ifxmips/ifxmips_gpio.h>
32 #include <asm/ifxmips/ifxmips_pmu.h>
33
34 #define IFXMIPS_LED_CLK_EDGE                            IFXMIPS_LED_FALLING
35 //#define IFXMIPS_LED_CLK_EDGE                  IFXMIPS_LED_RISING
36
37 #define IFXMIPS_LED_SPEED                               IFXMIPS_LED_8HZ
38
39 #define IFXMIPS_LED_GPIO_PORT   0
40
41 static int ifxmips_led_major;
42
43 void
44 ifxmips_led_set (unsigned int led)
45 {
46         led &= 0xffffff;
47         writel(readl(IFXMIPS_LED_CPU0) | led, IFXMIPS_LED_CPU0);
48 }
49 EXPORT_SYMBOL(ifxmips_led_set);
50
51 void
52 ifxmips_led_clear (unsigned int led)
53 {
54         led = ~(led & 0xffffff);
55         writel(readl(IFXMIPS_LED_CPU0) & led, IFXMIPS_LED_CPU0);
56 }
57 EXPORT_SYMBOL(ifxmips_led_clear);
58
59 void
60 ifxmips_led_blink_set (unsigned int led)
61 {
62         led &= 0xffffff;
63         writel(readl(IFXMIPS_LED_CON0) | led, IFXMIPS_LED_CON0);
64 }
65 EXPORT_SYMBOL(ifxmips_led_blink_set);
66
67 void
68 ifxmips_led_blink_clear (unsigned int led)
69 {
70         led = ~(led & 0xffffff);
71         writel(readl(IFXMIPS_LED_CON0) & led, IFXMIPS_LED_CON0);
72 }
73 EXPORT_SYMBOL(ifxmips_led_blink_clear);
74
75 void
76 ifxmips_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                 ifxmips_port_set_altsel0(IFXMIPS_LED_GPIO_PORT, i);
84                 ifxmips_port_clear_altsel1(IFXMIPS_LED_GPIO_PORT, i);
85                 ifxmips_port_set_dir_out(IFXMIPS_LED_GPIO_PORT, i);
86                 ifxmips_port_set_open_drain(IFXMIPS_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 ifxmips_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 ifxmips_led_init (void)
142 {
143         int ret = 0;
144
145         ifxmips_led_setup_gpio();
146
147         writel(0, IFXMIPS_LED_AR);
148         writel(0, IFXMIPS_LED_CPU0);
149         writel(0, IFXMIPS_LED_CPU1);
150         writel(LED_CON0_SWU, IFXMIPS_LED_CON0);
151         writel(0, IFXMIPS_LED_CON1);
152
153         /* setup the clock edge that the shift register is triggered on */
154         writel(readl(IFXMIPS_LED_CON0) & ~IFXMIPS_LED_EDGE_MASK, IFXMIPS_LED_CON0);
155         writel(readl(IFXMIPS_LED_CON0) | IFXMIPS_LED_CLK_EDGE, IFXMIPS_LED_CON0);
156
157         /* per default leds 15-0 are set */
158         writel(IFXMIPS_LED_GROUP1 | IFXMIPS_LED_GROUP0, IFXMIPS_LED_CON1);
159
160         /* leds are update periodically by the FPID */
161         writel(readl(IFXMIPS_LED_CON1) & ~IFXMIPS_LED_UPD_MASK, IFXMIPS_LED_CON1);
162         writel(readl(IFXMIPS_LED_CON1) | IFXMIPS_LED_UPD_SRC_FPI, IFXMIPS_LED_CON1);
163
164         /* set led update speed */
165         writel(readl(IFXMIPS_LED_CON1) & ~IFXMIPS_LED_MASK, IFXMIPS_LED_CON1);
166         writel(readl(IFXMIPS_LED_CON1) | IFXMIPS_LED_SPEED, IFXMIPS_LED_CON1);
167
168         /* adsl 0 and 1 leds are updated by the arc */
169         writel(readl(IFXMIPS_LED_CON0) | IFXMIPS_LED_ADSL_SRC, IFXMIPS_LED_CON0);
170
171         /* per default, the leds are turned on */
172         ifxmips_pmu_enable(IFXMIPS_PMU_PWDCR_LED);
173
174         ifxmips_led_major = register_chrdev(0, "ifxmips_led", &ifxmips_led_fops);
175
176         if (!ifxmips_led_major)
177         {
178                 printk("ifxmips_led: Error! Could not register device. %d\n", ifxmips_led_major);
179                 ret = -EINVAL;
180
181                 goto out;
182         }
183
184         printk(KERN_INFO "ifxmips_led : device registered on major %d\n", ifxmips_led_major);
185
186 out:
187         return ret;
188 }
189
190 void __exit
191 ifxmips_led_exit (void)
192 {
193         unregister_chrdev(ifxmips_led_major, "ifxmips_led");
194 }
195
196 module_init(ifxmips_led_init);
197 module_exit(ifxmips_led_exit);