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 <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>
34 #define IFXMIPS_LED_CLK_EDGE IFXMIPS_LED_FALLING
35 //#define IFXMIPS_LED_CLK_EDGE IFXMIPS_LED_RISING
37 #define IFXMIPS_LED_SPEED IFXMIPS_LED_8HZ
39 #define IFXMIPS_LED_GPIO_PORT 0
41 static int ifxmips_led_major
;
44 ifxmips_led_set (unsigned int led
)
47 writel(readl(IFXMIPS_LED_CPU0
) | led
, IFXMIPS_LED_CPU0
);
49 EXPORT_SYMBOL(ifxmips_led_set
);
52 ifxmips_led_clear (unsigned int led
)
54 led
= ~(led
& 0xffffff);
55 writel(readl(IFXMIPS_LED_CPU0
) & led
, IFXMIPS_LED_CPU0
);
57 EXPORT_SYMBOL(ifxmips_led_clear
);
60 ifxmips_led_blink_set (unsigned int led
)
63 writel(readl(IFXMIPS_LED_CON0
) | led
, IFXMIPS_LED_CON0
);
65 EXPORT_SYMBOL(ifxmips_led_blink_set
);
68 ifxmips_led_blink_clear (unsigned int led
)
70 led
= ~(led
& 0xffffff);
71 writel(readl(IFXMIPS_LED_CON0
) & led
, IFXMIPS_LED_CON0
);
73 EXPORT_SYMBOL(ifxmips_led_blink_clear
);
76 ifxmips_led_setup_gpio (void)
80 /* we need to setup pins SH,D,ST (4,5,6) */
81 for (i
= 4; i
< 7; i
++)
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
);
91 led_ioctl (struct inode
*inode
, struct file
*file
, unsigned int cmd
, unsigned long arg
)
103 led_open (struct inode
*inode
, struct file
*file
)
109 led_release (struct inode
*inode
, struct file
*file
)
114 static struct file_operations ifxmips_led_fops
= {
115 .owner
= THIS_MODULE
,
118 .release
= led_release
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
133 ADSL2_TRAFFIC LED31 OUT16 0
134 Map for hardware relay on reference board
141 ifxmips_led_init (void)
145 ifxmips_led_setup_gpio();
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
);
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
);
157 /* per default leds 15-0 are set */
158 writel(IFXMIPS_LED_GROUP1
| IFXMIPS_LED_GROUP0
, IFXMIPS_LED_CON1
);
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
);
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
);
168 /* adsl 0 and 1 leds are updated by the arc */
169 writel(readl(IFXMIPS_LED_CON0
) | IFXMIPS_LED_ADSL_SRC
, IFXMIPS_LED_CON0
);
171 /* per default, the leds are turned on */
172 ifxmips_pmu_enable(IFXMIPS_PMU_PWDCR_LED
);
174 ifxmips_led_major
= register_chrdev(0, "ifxmips_led", &ifxmips_led_fops
);
176 if (!ifxmips_led_major
)
178 printk("ifxmips_led: Error! Could not register device. %d\n", ifxmips_led_major
);
184 printk(KERN_INFO
"ifxmips_led : device registered on major %d\n", ifxmips_led_major
);
191 ifxmips_led_exit (void)
193 unregister_chrdev(ifxmips_led_major
, "ifxmips_led");
196 module_init(ifxmips_led_init
);
197 module_exit(ifxmips_led_exit
);