X-Git-Url: http://git.rohieb.name/openwrt.git/blobdiff_plain/20abafaaf5fdb4dd7cb1e09a028b1c2c689557b7..43ba67e0d51fc116099a5556191bf09669cd8601:/target/linux/ifxmips/files/drivers/char/ifxmips_led.c diff --git a/target/linux/ifxmips/files/drivers/char/ifxmips_led.c b/target/linux/ifxmips/files/drivers/char/ifxmips_led.c index b0b8e8289..40d2c96f6 100644 --- a/target/linux/ifxmips/files/drivers/char/ifxmips_led.c +++ b/target/linux/ifxmips/files/drivers/char/ifxmips_led.c @@ -24,27 +24,37 @@ #include #include #include +#include #include #include #include #include #include #include +#include +#include -#define IFXMIPS_LED_CLK_EDGE IFXMIPS_LED_FALLING +#define DRVNAME "ifxmips_led" + +#define IFXMIPS_LED_CLK_EDGE IFXMIPS_LED_FALLING //#define IFXMIPS_LED_CLK_EDGE IFXMIPS_LED_RISING #define IFXMIPS_LED_SPEED IFXMIPS_LED_8HZ -#define IFXMIPS_LED_GPIO_PORT 0 +#define IFXMIPS_LED_GPIO_PORT 0 + +#define IFXMIPS_MAX_LED 24 -static int ifxmips_led_major; +struct ifxmips_led { + struct led_classdev cdev; + u8 bit; +}; void ifxmips_led_set (unsigned int led) { led &= 0xffffff; - writel(readl(IFXMIPS_LED_CPU0) | led, IFXMIPS_LED_CPU0); + ifxmips_w32(ifxmips_r32(IFXMIPS_LED_CPU0) | led, IFXMIPS_LED_CPU0); } EXPORT_SYMBOL(ifxmips_led_set); @@ -52,7 +62,7 @@ void ifxmips_led_clear (unsigned int led) { led = ~(led & 0xffffff); - writel(readl(IFXMIPS_LED_CPU0) & led, IFXMIPS_LED_CPU0); + ifxmips_w32(ifxmips_r32(IFXMIPS_LED_CPU0) & led, IFXMIPS_LED_CPU0); } EXPORT_SYMBOL(ifxmips_led_clear); @@ -60,7 +70,7 @@ void ifxmips_led_blink_set (unsigned int led) { led &= 0xffffff; - writel(readl(IFXMIPS_LED_CON0) | led, IFXMIPS_LED_CON0); + ifxmips_w32(ifxmips_r32(IFXMIPS_LED_CON0) | led, IFXMIPS_LED_CON0); } EXPORT_SYMBOL(ifxmips_led_blink_set); @@ -68,10 +78,21 @@ void ifxmips_led_blink_clear (unsigned int led) { led = ~(led & 0xffffff); - writel(readl(IFXMIPS_LED_CON0) & led, IFXMIPS_LED_CON0); + ifxmips_w32(ifxmips_r32(IFXMIPS_LED_CON0) & led, IFXMIPS_LED_CON0); } EXPORT_SYMBOL(ifxmips_led_blink_clear); +void +ifxmips_ledapi_set(struct led_classdev *led_cdev, enum led_brightness value) +{ + struct ifxmips_led *led_dev = container_of(led_cdev, struct ifxmips_led, cdev); + + if(value) + ifxmips_led_set(1 << led_dev->bit); + else + ifxmips_led_clear(1 << led_dev->bit); +} + void ifxmips_led_setup_gpio (void) { @@ -88,109 +109,83 @@ ifxmips_led_setup_gpio (void) } static int -led_ioctl (struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) -{ - int ret = -EINVAL; - - switch ( cmd ) - { - } - - return ret; -} - -static int -led_open (struct inode *inode, struct file *file) -{ - return 0; -} - -static int -led_release (struct inode *inode, struct file *file) -{ - return 0; -} - -static struct file_operations ifxmips_led_fops = { - .owner = THIS_MODULE, - .ioctl = led_ioctl, - .open = led_open, - .release = led_release -}; - - -/* -Map for LED on reference board - WLAN_READ LED11 OUT1 15 - WARNING LED12 OUT2 14 - FXS1_LINK LED13 OUT3 13 - FXS2_LINK LED14 OUT4 12 - FXO_ACT LED15 OUT5 11 - USB_LINK LED16 OUT6 10 - ADSL2_LINK LED19 OUT7 9 - BT_LINK LED17 OUT8 8 - SD_LINK LED20 OUT9 7 - ADSL2_TRAFFIC LED31 OUT16 0 -Map for hardware relay on reference board - USB Power On OUT11 5 - RELAY OUT12 4 -*/ - - -int __init -ifxmips_led_init (void) +ifxmips_led_probe(struct platform_device *dev) { - int ret = 0; + int i = 0; ifxmips_led_setup_gpio(); - writel(0, IFXMIPS_LED_AR); - writel(0, IFXMIPS_LED_CPU0); - writel(0, IFXMIPS_LED_CPU1); - writel(LED_CON0_SWU, IFXMIPS_LED_CON0); - writel(0, IFXMIPS_LED_CON1); + ifxmips_w32(0, IFXMIPS_LED_AR); + ifxmips_w32(0, IFXMIPS_LED_CPU0); + ifxmips_w32(0, IFXMIPS_LED_CPU1); + ifxmips_w32(LED_CON0_SWU, IFXMIPS_LED_CON0); + ifxmips_w32(0, IFXMIPS_LED_CON1); /* setup the clock edge that the shift register is triggered on */ - writel(readl(IFXMIPS_LED_CON0) & ~IFXMIPS_LED_EDGE_MASK, IFXMIPS_LED_CON0); - writel(readl(IFXMIPS_LED_CON0) | IFXMIPS_LED_CLK_EDGE, IFXMIPS_LED_CON0); + ifxmips_w32(ifxmips_r32(IFXMIPS_LED_CON0) & ~IFXMIPS_LED_EDGE_MASK, IFXMIPS_LED_CON0); + ifxmips_w32(ifxmips_r32(IFXMIPS_LED_CON0) | IFXMIPS_LED_CLK_EDGE, IFXMIPS_LED_CON0); /* per default leds 15-0 are set */ - writel(IFXMIPS_LED_GROUP1 | IFXMIPS_LED_GROUP0, IFXMIPS_LED_CON1); + ifxmips_w32(IFXMIPS_LED_GROUP1 | IFXMIPS_LED_GROUP0, IFXMIPS_LED_CON1); /* leds are update periodically by the FPID */ - writel(readl(IFXMIPS_LED_CON1) & ~IFXMIPS_LED_UPD_MASK, IFXMIPS_LED_CON1); - writel(readl(IFXMIPS_LED_CON1) | IFXMIPS_LED_UPD_SRC_FPI, IFXMIPS_LED_CON1); + ifxmips_w32(ifxmips_r32(IFXMIPS_LED_CON1) & ~IFXMIPS_LED_UPD_MASK, IFXMIPS_LED_CON1); + ifxmips_w32(ifxmips_r32(IFXMIPS_LED_CON1) | IFXMIPS_LED_UPD_SRC_FPI, IFXMIPS_LED_CON1); /* set led update speed */ - writel(readl(IFXMIPS_LED_CON1) & ~IFXMIPS_LED_MASK, IFXMIPS_LED_CON1); - writel(readl(IFXMIPS_LED_CON1) | IFXMIPS_LED_SPEED, IFXMIPS_LED_CON1); + ifxmips_w32(ifxmips_r32(IFXMIPS_LED_CON1) & ~IFXMIPS_LED_MASK, IFXMIPS_LED_CON1); + ifxmips_w32(ifxmips_r32(IFXMIPS_LED_CON1) | IFXMIPS_LED_SPEED, IFXMIPS_LED_CON1); /* adsl 0 and 1 leds are updated by the arc */ - writel(readl(IFXMIPS_LED_CON0) | IFXMIPS_LED_ADSL_SRC, IFXMIPS_LED_CON0); + ifxmips_w32(ifxmips_r32(IFXMIPS_LED_CON0) | IFXMIPS_LED_ADSL_SRC, IFXMIPS_LED_CON0); /* per default, the leds are turned on */ ifxmips_pmu_enable(IFXMIPS_PMU_PWDCR_LED); - ifxmips_led_major = register_chrdev(0, "ifxmips_led", &ifxmips_led_fops); - - if (!ifxmips_led_major) + for(i = 0; i < IFXMIPS_MAX_LED; i++) { - printk("ifxmips_led: Error! Could not register device. %d\n", ifxmips_led_major); - ret = -EINVAL; - - goto out; + struct ifxmips_led *tmp = kzalloc(sizeof(struct ifxmips_led), GFP_KERNEL); + tmp->cdev.brightness_set = ifxmips_ledapi_set; + tmp->cdev.name = kmalloc(sizeof("ifxmips:led:00"), GFP_KERNEL); + sprintf(tmp->cdev.name, "ifxmips:led:%02d", i); + tmp->cdev.default_trigger = NULL; + tmp->bit = i; + led_classdev_register(&dev->dev, &tmp->cdev); } - printk(KERN_INFO "ifxmips_led : device registered on major %d\n", ifxmips_led_major); + return 0; +} + +static int +ifxmips_led_remove(struct platform_device *pdev) +{ + return 0; +} + +static struct +platform_driver ifxmips_led_driver = { + .probe = ifxmips_led_probe, + .remove = ifxmips_led_remove, + .driver = { + .name = DRVNAME, + .owner = THIS_MODULE, + }, +}; + +int __init +ifxmips_led_init (void) +{ + int ret = platform_driver_register(&ifxmips_led_driver); + if (ret) + printk(KERN_INFO "ifxmips_led: Error registering platfom driver!"); -out: return ret; } void __exit ifxmips_led_exit (void) { - unregister_chrdev(ifxmips_led_major, "ifxmips_led"); + platform_driver_unregister(&ifxmips_led_driver); } module_init(ifxmips_led_init);