]> git.enpas.org Git - openwrt.git/blob - target/linux/ifxmips/files/drivers/char/ifxmips_led.c
make ifxmips led driver a platform device
[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 <linux/platform_device.h>
28 #include <asm/uaccess.h>
29 #include <asm/unistd.h>
30 #include <linux/errno.h>
31 #include <asm/ifxmips/ifxmips.h>
32 #include <asm/ifxmips/ifxmips_gpio.h>
33 #include <asm/ifxmips/ifxmips_pmu.h>
34
35 #define DRVNAME                                                 "ifxmips_led" 
36
37 #define IFXMIPS_LED_CLK_EDGE                    IFXMIPS_LED_FALLING
38 //#define IFXMIPS_LED_CLK_EDGE                  IFXMIPS_LED_RISING
39
40 #define IFXMIPS_LED_SPEED                               IFXMIPS_LED_8HZ
41
42 #define IFXMIPS_LED_GPIO_PORT                   0
43
44 static int ifxmips_led_major;
45
46 void
47 ifxmips_led_set (unsigned int led)
48 {
49         led &= 0xffffff;
50         writel(readl(IFXMIPS_LED_CPU0) | led, IFXMIPS_LED_CPU0);
51 }
52 EXPORT_SYMBOL(ifxmips_led_set);
53
54 void
55 ifxmips_led_clear (unsigned int led)
56 {
57         led = ~(led & 0xffffff);
58         writel(readl(IFXMIPS_LED_CPU0) & led, IFXMIPS_LED_CPU0);
59 }
60 EXPORT_SYMBOL(ifxmips_led_clear);
61
62 void
63 ifxmips_led_blink_set (unsigned int led)
64 {
65         led &= 0xffffff;
66         writel(readl(IFXMIPS_LED_CON0) | led, IFXMIPS_LED_CON0);
67 }
68 EXPORT_SYMBOL(ifxmips_led_blink_set);
69
70 void
71 ifxmips_led_blink_clear (unsigned int led)
72 {
73         led = ~(led & 0xffffff);
74         writel(readl(IFXMIPS_LED_CON0) & led, IFXMIPS_LED_CON0);
75 }
76 EXPORT_SYMBOL(ifxmips_led_blink_clear);
77
78 void
79 ifxmips_led_setup_gpio (void)
80 {
81         int i = 0;
82
83         /* we need to setup pins SH,D,ST (4,5,6) */
84         for (i = 4; i < 7; i++)
85         {
86                 ifxmips_port_set_altsel0(IFXMIPS_LED_GPIO_PORT, i);
87                 ifxmips_port_clear_altsel1(IFXMIPS_LED_GPIO_PORT, i);
88                 ifxmips_port_set_dir_out(IFXMIPS_LED_GPIO_PORT, i);
89                 ifxmips_port_set_open_drain(IFXMIPS_LED_GPIO_PORT, i);
90         }
91 }
92
93 static int
94 led_ioctl (struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
95 {
96         int ret = -EINVAL;
97
98         switch ( cmd )
99         {
100         }
101
102         return ret;
103 }
104
105 static int
106 led_open (struct inode *inode, struct file *file)
107 {
108         return 0;
109 }
110
111 static int
112 led_release (struct inode *inode, struct file *file)
113 {
114         return 0;
115 }
116
117 static struct file_operations ifxmips_led_fops = {
118         .owner = THIS_MODULE,
119         .ioctl = led_ioctl,
120         .open = led_open,
121         .release = led_release
122 };
123
124 static int
125 ifxmips_led_probe(struct platform_device *dev)
126 {
127         int ret = 0;
128
129         ifxmips_led_setup_gpio();
130
131         writel(0, IFXMIPS_LED_AR);
132         writel(0, IFXMIPS_LED_CPU0);
133         writel(0, IFXMIPS_LED_CPU1);
134         writel(LED_CON0_SWU, IFXMIPS_LED_CON0);
135         writel(0, IFXMIPS_LED_CON1);
136
137         /* setup the clock edge that the shift register is triggered on */
138         writel(readl(IFXMIPS_LED_CON0) & ~IFXMIPS_LED_EDGE_MASK, IFXMIPS_LED_CON0);
139         writel(readl(IFXMIPS_LED_CON0) | IFXMIPS_LED_CLK_EDGE, IFXMIPS_LED_CON0);
140
141         /* per default leds 15-0 are set */
142         writel(IFXMIPS_LED_GROUP1 | IFXMIPS_LED_GROUP0, IFXMIPS_LED_CON1);
143
144         /* leds are update periodically by the FPID */
145         writel(readl(IFXMIPS_LED_CON1) & ~IFXMIPS_LED_UPD_MASK, IFXMIPS_LED_CON1);
146         writel(readl(IFXMIPS_LED_CON1) | IFXMIPS_LED_UPD_SRC_FPI, IFXMIPS_LED_CON1);
147
148         /* set led update speed */
149         writel(readl(IFXMIPS_LED_CON1) & ~IFXMIPS_LED_MASK, IFXMIPS_LED_CON1);
150         writel(readl(IFXMIPS_LED_CON1) | IFXMIPS_LED_SPEED, IFXMIPS_LED_CON1);
151
152         /* adsl 0 and 1 leds are updated by the arc */
153         writel(readl(IFXMIPS_LED_CON0) | IFXMIPS_LED_ADSL_SRC, IFXMIPS_LED_CON0);
154
155         /* per default, the leds are turned on */
156         ifxmips_pmu_enable(IFXMIPS_PMU_PWDCR_LED);
157
158         ifxmips_led_major = register_chrdev(0, "ifxmips_led", &ifxmips_led_fops);
159
160         if (!ifxmips_led_major)
161         {
162                 printk("ifxmips_led: Error! Could not register device. %d\n", ifxmips_led_major);
163                 ret = -EINVAL;
164
165                 goto out;
166         }
167
168         printk(KERN_INFO "ifxmips_led: device successfully initialized #%d.\n", ifxmips_led_major);
169
170 out:
171         return ret;
172 }
173
174 static int
175 ifxmips_led_remove(struct platform_device *pdev)
176 {
177         unregister_chrdev(ifxmips_led_major, "ifxmips_led");
178         return 0;
179 }
180
181 static struct
182 platform_driver ifxmips_led_driver = {
183         .probe = ifxmips_led_probe,
184         .remove = ifxmips_led_remove,
185         .driver = {
186                 .name = DRVNAME,
187                 .owner = THIS_MODULE,
188         },
189 };
190
191 /*
192 Map for LED on reference board
193         WLAN_READ     LED11   OUT1    15
194         WARNING       LED12   OUT2    14
195         FXS1_LINK     LED13   OUT3    13
196         FXS2_LINK     LED14   OUT4    12
197         FXO_ACT       LED15   OUT5    11
198         USB_LINK      LED16   OUT6    10
199         ADSL2_LINK    LED19   OUT7    9
200         BT_LINK       LED17   OUT8    8
201         SD_LINK       LED20   OUT9    7
202         ADSL2_TRAFFIC LED31   OUT16   0
203 Map for hardware relay on reference board
204         USB Power On          OUT11   5
205         RELAY                 OUT12   4
206 */
207
208 int __init
209 ifxmips_led_init (void)
210 {
211         int ret = platform_driver_register(&ifxmips_led_driver);
212         if (ret)
213                 printk(KERN_INFO "ifxmips_led: Error registering platfom driver!");
214
215         return ret;
216 }
217
218 void __exit
219 ifxmips_led_exit (void)
220 {
221         platform_driver_unregister(&ifxmips_led_driver);
222 }
223
224 module_init(ifxmips_led_init);
225 module_exit(ifxmips_led_exit);