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/danube/danube.h>
31 #include <asm/danube/danube_gpio.h>
32 #include <asm/danube/danube_pmu.h>
34 #define DANUBE_LED_CLK_EDGE DANUBE_LED_FALLING
35 //#define DANUBE_LED_CLK_EDGE DANUBE_LED_RISING
37 #define DANUBE_LED_SPEED DANUBE_LED_8HZ
39 #define DANUBE_LED_GPIO_PORT 0
41 static int danube_led_major
;
44 danube_led_set (unsigned int led
)
47 writel(readl(DANUBE_LED_CPU0
) | led
, DANUBE_LED_CPU0
);
49 EXPORT_SYMBOL(danube_led_set
);
52 danube_led_clear (unsigned int led
)
54 led
= ~(led
& 0xffffff);
55 writel(readl(DANUBE_LED_CPU0
) & led
, DANUBE_LED_CPU0
);
57 EXPORT_SYMBOL(danube_led_clear
);
60 danube_led_blink_set (unsigned int led
)
63 writel(readl(DANUBE_LED_CON0
) | led
, DANUBE_LED_CON0
);
65 EXPORT_SYMBOL(danube_led_blink_set
);
68 danube_led_blink_clear (unsigned int led
)
70 led
= ~(led
& 0xffffff);
71 writel(readl(DANUBE_LED_CON0
) & led
, DANUBE_LED_CON0
);
73 EXPORT_SYMBOL(danube_led_blink_clear
);
76 danube_led_setup_gpio (void)
80 /* we need to setup pins SH,D,ST (4,5,6) */
81 for (i
= 4; i
< 7; i
++)
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
);
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 danube_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 danube_led_init (void)
145 danube_led_setup_gpio();
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
);
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
);
157 /* per default leds 15-0 are set */
158 writel(DANUBE_LED_GROUP1
| DANUBE_LED_GROUP0
, DANUBE_LED_CON1
);
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
);
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
);
168 /* adsl 0 and 1 leds are updated by the arc */
169 writel(readl(DANUBE_LED_CON0
) | DANUBE_LED_ADSL_SRC
, DANUBE_LED_CON0
);
171 /* per default, the leds are turned on */
172 danube_pmu_enable(DANUBE_PMU_PWDCR_LED
);
174 danube_led_major
= register_chrdev(0, "danube_led", &danube_led_fops
);
176 if (!danube_led_major
)
178 printk("danube_led: Error! Could not register device. %d\n", danube_led_major
);
184 printk(KERN_INFO
"danube_led : device registered on major %d\n", danube_led_major
);
191 danube_led_exit (void)
193 unregister_chrdev(danube_led_major
, "danube_led");
196 module_init(danube_led_init
);
197 module_exit(danube_led_exit
);