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.
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.
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.
16 * Copyright (C) 2006 infineon
17 * Copyright (C) 2007 John Crispin <blogic@openwrt.org>
21 #include <linux/kernel.h>
22 #include <linux/module.h>
23 #include <linux/version.h>
24 #include <linux/types.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>
35 #define DRVNAME "ifxmips_led"
37 #define IFXMIPS_LED_CLK_EDGE IFXMIPS_LED_FALLING
38 //#define IFXMIPS_LED_CLK_EDGE IFXMIPS_LED_RISING
40 #define IFXMIPS_LED_SPEED IFXMIPS_LED_8HZ
42 #define IFXMIPS_LED_GPIO_PORT 0
44 static int ifxmips_led_major
;
47 ifxmips_led_set (unsigned int led
)
50 writel(readl(IFXMIPS_LED_CPU0
) | led
, IFXMIPS_LED_CPU0
);
52 EXPORT_SYMBOL(ifxmips_led_set
);
55 ifxmips_led_clear (unsigned int led
)
57 led
= ~(led
& 0xffffff);
58 writel(readl(IFXMIPS_LED_CPU0
) & led
, IFXMIPS_LED_CPU0
);
60 EXPORT_SYMBOL(ifxmips_led_clear
);
63 ifxmips_led_blink_set (unsigned int led
)
66 writel(readl(IFXMIPS_LED_CON0
) | led
, IFXMIPS_LED_CON0
);
68 EXPORT_SYMBOL(ifxmips_led_blink_set
);
71 ifxmips_led_blink_clear (unsigned int led
)
73 led
= ~(led
& 0xffffff);
74 writel(readl(IFXMIPS_LED_CON0
) & led
, IFXMIPS_LED_CON0
);
76 EXPORT_SYMBOL(ifxmips_led_blink_clear
);
79 ifxmips_led_setup_gpio (void)
83 /* we need to setup pins SH,D,ST (4,5,6) */
84 for (i
= 4; i
< 7; i
++)
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
);
94 led_ioctl (struct inode
*inode
, struct file
*file
, unsigned int cmd
, unsigned long arg
)
106 led_open (struct inode
*inode
, struct file
*file
)
112 led_release (struct inode
*inode
, struct file
*file
)
117 static struct file_operations ifxmips_led_fops
= {
118 .owner
= THIS_MODULE
,
121 .release
= led_release
125 ifxmips_led_probe(struct platform_device
*dev
)
129 ifxmips_led_setup_gpio();
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
);
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
);
141 /* per default leds 15-0 are set */
142 writel(IFXMIPS_LED_GROUP1
| IFXMIPS_LED_GROUP0
, IFXMIPS_LED_CON1
);
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
);
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
);
152 /* adsl 0 and 1 leds are updated by the arc */
153 writel(readl(IFXMIPS_LED_CON0
) | IFXMIPS_LED_ADSL_SRC
, IFXMIPS_LED_CON0
);
155 /* per default, the leds are turned on */
156 ifxmips_pmu_enable(IFXMIPS_PMU_PWDCR_LED
);
158 ifxmips_led_major
= register_chrdev(0, "ifxmips_led", &ifxmips_led_fops
);
160 if (!ifxmips_led_major
)
162 printk("ifxmips_led: Error! Could not register device. %d\n", ifxmips_led_major
);
168 printk(KERN_INFO
"ifxmips_led: device successfully initialized #%d.\n", ifxmips_led_major
);
175 ifxmips_led_remove(struct platform_device
*pdev
)
177 unregister_chrdev(ifxmips_led_major
, "ifxmips_led");
182 platform_driver ifxmips_led_driver
= {
183 .probe
= ifxmips_led_probe
,
184 .remove
= ifxmips_led_remove
,
187 .owner
= THIS_MODULE
,
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
202 ADSL2_TRAFFIC LED31 OUT16 0
203 Map for hardware relay on reference board
209 ifxmips_led_init (void)
211 int ret
= platform_driver_register(&ifxmips_led_driver
);
213 printk(KERN_INFO
"ifxmips_led: Error registering platfom driver!");
219 ifxmips_led_exit (void)
221 platform_driver_unregister(&ifxmips_led_driver
);
224 module_init(ifxmips_led_init
);
225 module_exit(ifxmips_led_exit
);