Richard Purdie | 3179108 | 2006-03-31 02:31:09 -0800 | [diff] [blame] | 1 | /* |
| 2 | * LED Triggers Core |
| 3 | * |
| 4 | * Copyright 2005-2006 Openedhand Ltd. |
| 5 | * |
| 6 | * Author: Richard Purdie <rpurdie@openedhand.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License version 2 as |
| 10 | * published by the Free Software Foundation. |
| 11 | * |
| 12 | */ |
| 13 | |
Richard Purdie | 3179108 | 2006-03-31 02:31:09 -0800 | [diff] [blame] | 14 | #include <linux/kernel.h> |
| 15 | #include <linux/init.h> |
| 16 | #include <linux/platform_device.h> |
| 17 | #include <linux/leds.h> |
| 18 | #include <asm/mach-types.h> |
| 19 | #include <asm/arch/corgi.h> |
| 20 | #include <asm/arch/hardware.h> |
| 21 | #include <asm/arch/pxa-regs.h> |
| 22 | #include <asm/hardware/scoop.h> |
| 23 | |
| 24 | static void corgiled_amber_set(struct led_classdev *led_cdev, enum led_brightness value) |
| 25 | { |
| 26 | if (value) |
| 27 | GPSR0 = GPIO_bit(CORGI_GPIO_LED_ORANGE); |
| 28 | else |
| 29 | GPCR0 = GPIO_bit(CORGI_GPIO_LED_ORANGE); |
| 30 | } |
| 31 | |
| 32 | static void corgiled_green_set(struct led_classdev *led_cdev, enum led_brightness value) |
| 33 | { |
| 34 | if (value) |
| 35 | set_scoop_gpio(&corgiscoop_device.dev, CORGI_SCP_LED_GREEN); |
| 36 | else |
| 37 | reset_scoop_gpio(&corgiscoop_device.dev, CORGI_SCP_LED_GREEN); |
| 38 | } |
| 39 | |
| 40 | static struct led_classdev corgi_amber_led = { |
Richard Purdie | 6c152be | 2007-10-31 15:00:07 +0100 | [diff] [blame] | 41 | .name = "corgi:amber:charge", |
Richard Purdie | 3179108 | 2006-03-31 02:31:09 -0800 | [diff] [blame] | 42 | .default_trigger = "sharpsl-charge", |
| 43 | .brightness_set = corgiled_amber_set, |
| 44 | }; |
| 45 | |
| 46 | static struct led_classdev corgi_green_led = { |
Richard Purdie | 6c152be | 2007-10-31 15:00:07 +0100 | [diff] [blame] | 47 | .name = "corgi:green:mail", |
Richard Purdie | 3179108 | 2006-03-31 02:31:09 -0800 | [diff] [blame] | 48 | .default_trigger = "nand-disk", |
| 49 | .brightness_set = corgiled_green_set, |
| 50 | }; |
| 51 | |
| 52 | #ifdef CONFIG_PM |
| 53 | static int corgiled_suspend(struct platform_device *dev, pm_message_t state) |
| 54 | { |
| 55 | #ifdef CONFIG_LEDS_TRIGGERS |
| 56 | if (corgi_amber_led.trigger && strcmp(corgi_amber_led.trigger->name, "sharpsl-charge")) |
| 57 | #endif |
| 58 | led_classdev_suspend(&corgi_amber_led); |
| 59 | led_classdev_suspend(&corgi_green_led); |
| 60 | return 0; |
| 61 | } |
| 62 | |
| 63 | static int corgiled_resume(struct platform_device *dev) |
| 64 | { |
| 65 | led_classdev_resume(&corgi_amber_led); |
| 66 | led_classdev_resume(&corgi_green_led); |
| 67 | return 0; |
| 68 | } |
| 69 | #endif |
| 70 | |
| 71 | static int corgiled_probe(struct platform_device *pdev) |
| 72 | { |
| 73 | int ret; |
| 74 | |
| 75 | ret = led_classdev_register(&pdev->dev, &corgi_amber_led); |
| 76 | if (ret < 0) |
| 77 | return ret; |
| 78 | |
| 79 | ret = led_classdev_register(&pdev->dev, &corgi_green_led); |
| 80 | if (ret < 0) |
| 81 | led_classdev_unregister(&corgi_amber_led); |
| 82 | |
| 83 | return ret; |
| 84 | } |
| 85 | |
| 86 | static int corgiled_remove(struct platform_device *pdev) |
| 87 | { |
| 88 | led_classdev_unregister(&corgi_amber_led); |
| 89 | led_classdev_unregister(&corgi_green_led); |
| 90 | return 0; |
| 91 | } |
| 92 | |
| 93 | static struct platform_driver corgiled_driver = { |
| 94 | .probe = corgiled_probe, |
| 95 | .remove = corgiled_remove, |
| 96 | #ifdef CONFIG_PM |
| 97 | .suspend = corgiled_suspend, |
| 98 | .resume = corgiled_resume, |
| 99 | #endif |
| 100 | .driver = { |
| 101 | .name = "corgi-led", |
Kay Sievers | 3c4ded9 | 2008-04-15 14:34:30 -0700 | [diff] [blame] | 102 | .owner = THIS_MODULE, |
Richard Purdie | 3179108 | 2006-03-31 02:31:09 -0800 | [diff] [blame] | 103 | }, |
| 104 | }; |
| 105 | |
| 106 | static int __init corgiled_init(void) |
| 107 | { |
| 108 | return platform_driver_register(&corgiled_driver); |
| 109 | } |
| 110 | |
| 111 | static void __exit corgiled_exit(void) |
| 112 | { |
| 113 | platform_driver_unregister(&corgiled_driver); |
| 114 | } |
| 115 | |
| 116 | module_init(corgiled_init); |
| 117 | module_exit(corgiled_exit); |
| 118 | |
| 119 | MODULE_AUTHOR("Richard Purdie <rpurdie@openedhand.com>"); |
| 120 | MODULE_DESCRIPTION("Corgi LED driver"); |
| 121 | MODULE_LICENSE("GPL"); |
Kay Sievers | 3c4ded9 | 2008-04-15 14:34:30 -0700 | [diff] [blame] | 122 | MODULE_ALIAS("platform:corgi-led"); |