14d3cb354SRichard Purdie /* 24d3cb354SRichard Purdie * linux/drivers/leds/locomo.c 34d3cb354SRichard Purdie * 44d3cb354SRichard Purdie * Copyright (C) 2005 John Lenz <lenz@cs.wisc.edu> 54d3cb354SRichard Purdie * 64d3cb354SRichard Purdie * This program is free software; you can redistribute it and/or modify 74d3cb354SRichard Purdie * it under the terms of the GNU General Public License version 2 as 84d3cb354SRichard Purdie * published by the Free Software Foundation. 94d3cb354SRichard Purdie */ 104d3cb354SRichard Purdie 114d3cb354SRichard Purdie #include <linux/config.h> 124d3cb354SRichard Purdie #include <linux/kernel.h> 134d3cb354SRichard Purdie #include <linux/init.h> 144d3cb354SRichard Purdie #include <linux/device.h> 154d3cb354SRichard Purdie #include <linux/leds.h> 164d3cb354SRichard Purdie 174d3cb354SRichard Purdie #include <asm/hardware.h> 184d3cb354SRichard Purdie #include <asm/hardware/locomo.h> 194d3cb354SRichard Purdie 204d3cb354SRichard Purdie static void locomoled_brightness_set(struct led_classdev *led_cdev, 214d3cb354SRichard Purdie enum led_brightness value, int offset) 224d3cb354SRichard Purdie { 234d3cb354SRichard Purdie struct locomo_dev *locomo_dev = LOCOMO_DEV(led_cdev->class_dev->dev); 244d3cb354SRichard Purdie unsigned long flags; 254d3cb354SRichard Purdie 264d3cb354SRichard Purdie local_irq_save(flags); 274d3cb354SRichard Purdie if (value) 284d3cb354SRichard Purdie locomo_writel(LOCOMO_LPT_TOFH, locomo_dev->mapbase + offset); 294d3cb354SRichard Purdie else 304d3cb354SRichard Purdie locomo_writel(LOCOMO_LPT_TOFL, locomo_dev->mapbase + offset); 314d3cb354SRichard Purdie local_irq_restore(flags); 324d3cb354SRichard Purdie } 334d3cb354SRichard Purdie 344d3cb354SRichard Purdie static void locomoled_brightness_set0(struct led_classdev *led_cdev, 354d3cb354SRichard Purdie enum led_brightness value) 364d3cb354SRichard Purdie { 374d3cb354SRichard Purdie locomoled_brightness_set(led_cdev, value, LOCOMO_LPT0); 384d3cb354SRichard Purdie } 394d3cb354SRichard Purdie 404d3cb354SRichard Purdie static void locomoled_brightness_set1(struct led_classdev *led_cdev, 414d3cb354SRichard Purdie enum led_brightness value) 424d3cb354SRichard Purdie { 434d3cb354SRichard Purdie locomoled_brightness_set(led_cdev, value, LOCOMO_LPT1); 444d3cb354SRichard Purdie } 454d3cb354SRichard Purdie 464d3cb354SRichard Purdie static struct led_classdev locomo_led0 = { 474d3cb354SRichard Purdie .name = "locomo:amber", 48*b7408affSRichard Purdie .default_trigger = "sharpsl-charge", 494d3cb354SRichard Purdie .brightness_set = locomoled_brightness_set0, 504d3cb354SRichard Purdie }; 514d3cb354SRichard Purdie 524d3cb354SRichard Purdie static struct led_classdev locomo_led1 = { 534d3cb354SRichard Purdie .name = "locomo:green", 54*b7408affSRichard Purdie .default_trigger = "nand-disk", 554d3cb354SRichard Purdie .brightness_set = locomoled_brightness_set1, 564d3cb354SRichard Purdie }; 574d3cb354SRichard Purdie 584d3cb354SRichard Purdie static int locomoled_probe(struct locomo_dev *ldev) 594d3cb354SRichard Purdie { 604d3cb354SRichard Purdie int ret; 614d3cb354SRichard Purdie 624d3cb354SRichard Purdie ret = led_classdev_register(&ldev->dev, &locomo_led0); 634d3cb354SRichard Purdie if (ret < 0) 644d3cb354SRichard Purdie return ret; 654d3cb354SRichard Purdie 664d3cb354SRichard Purdie ret = led_classdev_register(&ldev->dev, &locomo_led1); 674d3cb354SRichard Purdie if (ret < 0) 684d3cb354SRichard Purdie led_classdev_unregister(&locomo_led0); 694d3cb354SRichard Purdie 704d3cb354SRichard Purdie return ret; 714d3cb354SRichard Purdie } 724d3cb354SRichard Purdie 734d3cb354SRichard Purdie static int locomoled_remove(struct locomo_dev *dev) 744d3cb354SRichard Purdie { 754d3cb354SRichard Purdie led_classdev_unregister(&locomo_led0); 764d3cb354SRichard Purdie led_classdev_unregister(&locomo_led1); 774d3cb354SRichard Purdie return 0; 784d3cb354SRichard Purdie } 794d3cb354SRichard Purdie 804d3cb354SRichard Purdie static struct locomo_driver locomoled_driver = { 814d3cb354SRichard Purdie .drv = { 824d3cb354SRichard Purdie .name = "locomoled" 834d3cb354SRichard Purdie }, 844d3cb354SRichard Purdie .devid = LOCOMO_DEVID_LED, 854d3cb354SRichard Purdie .probe = locomoled_probe, 864d3cb354SRichard Purdie .remove = locomoled_remove, 874d3cb354SRichard Purdie }; 884d3cb354SRichard Purdie 894d3cb354SRichard Purdie static int __init locomoled_init(void) 904d3cb354SRichard Purdie { 914d3cb354SRichard Purdie return locomo_driver_register(&locomoled_driver); 924d3cb354SRichard Purdie } 934d3cb354SRichard Purdie module_init(locomoled_init); 944d3cb354SRichard Purdie 954d3cb354SRichard Purdie MODULE_AUTHOR("John Lenz <lenz@cs.wisc.edu>"); 964d3cb354SRichard Purdie MODULE_DESCRIPTION("Locomo LED driver"); 974d3cb354SRichard Purdie MODULE_LICENSE("GPL"); 98