blob: 178831c64bfb2dbed496df7886f151235bb80a01 [file] [log] [blame]
Richard Purdie31791082006-03-31 02:31:09 -08001/*
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 Purdie31791082006-03-31 02:31:09 -080014#include <linux/kernel.h>
15#include <linux/init.h>
16#include <linux/platform_device.h>
17#include <linux/leds.h>
18#include <asm/hardware/scoop.h>
19#include <asm/mach-types.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010020#include <mach/hardware.h>
21#include <mach/pxa-regs.h>
22#include <mach/spitz.h>
Richard Purdie31791082006-03-31 02:31:09 -080023
Németh Márton4d404fd2008-03-09 20:59:57 +000024static void spitzled_amber_set(struct led_classdev *led_cdev,
25 enum led_brightness value)
Richard Purdie31791082006-03-31 02:31:09 -080026{
27 if (value)
28 set_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_LED_ORANGE);
29 else
30 reset_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_LED_ORANGE);
31}
32
Németh Márton4d404fd2008-03-09 20:59:57 +000033static void spitzled_green_set(struct led_classdev *led_cdev,
34 enum led_brightness value)
Richard Purdie31791082006-03-31 02:31:09 -080035{
36 if (value)
37 set_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_LED_GREEN);
38 else
39 reset_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_LED_GREEN);
40}
41
42static struct led_classdev spitz_amber_led = {
Richard Purdie6c152be2007-10-31 15:00:07 +010043 .name = "spitz:amber:charge",
Richard Purdie31791082006-03-31 02:31:09 -080044 .default_trigger = "sharpsl-charge",
45 .brightness_set = spitzled_amber_set,
46};
47
48static struct led_classdev spitz_green_led = {
Richard Purdie6c152be2007-10-31 15:00:07 +010049 .name = "spitz:green:hddactivity",
Richard Purdie31791082006-03-31 02:31:09 -080050 .default_trigger = "ide-disk",
51 .brightness_set = spitzled_green_set,
52};
53
54#ifdef CONFIG_PM
55static int spitzled_suspend(struct platform_device *dev, pm_message_t state)
56{
57#ifdef CONFIG_LEDS_TRIGGERS
Németh Márton4d404fd2008-03-09 20:59:57 +000058 if (spitz_amber_led.trigger &&
59 strcmp(spitz_amber_led.trigger->name, "sharpsl-charge"))
Richard Purdie31791082006-03-31 02:31:09 -080060#endif
61 led_classdev_suspend(&spitz_amber_led);
62 led_classdev_suspend(&spitz_green_led);
63 return 0;
64}
65
66static int spitzled_resume(struct platform_device *dev)
67{
68 led_classdev_resume(&spitz_amber_led);
69 led_classdev_resume(&spitz_green_led);
70 return 0;
71}
72#endif
73
74static int spitzled_probe(struct platform_device *pdev)
75{
76 int ret;
77
Richard Purdie6c152be2007-10-31 15:00:07 +010078 if (machine_is_akita()) {
79 spitz_green_led.name = "spitz:green:mail";
Richard Purdie31791082006-03-31 02:31:09 -080080 spitz_green_led.default_trigger = "nand-disk";
Richard Purdie6c152be2007-10-31 15:00:07 +010081 }
Richard Purdie31791082006-03-31 02:31:09 -080082
83 ret = led_classdev_register(&pdev->dev, &spitz_amber_led);
84 if (ret < 0)
85 return ret;
86
87 ret = led_classdev_register(&pdev->dev, &spitz_green_led);
88 if (ret < 0)
89 led_classdev_unregister(&spitz_amber_led);
90
91 return ret;
92}
93
94static int spitzled_remove(struct platform_device *pdev)
95{
96 led_classdev_unregister(&spitz_amber_led);
97 led_classdev_unregister(&spitz_green_led);
98
99 return 0;
100}
101
102static struct platform_driver spitzled_driver = {
103 .probe = spitzled_probe,
104 .remove = spitzled_remove,
105#ifdef CONFIG_PM
106 .suspend = spitzled_suspend,
107 .resume = spitzled_resume,
108#endif
109 .driver = {
110 .name = "spitz-led",
Kay Sievers3c4ded92008-04-15 14:34:30 -0700111 .owner = THIS_MODULE,
Richard Purdie31791082006-03-31 02:31:09 -0800112 },
113};
114
115static int __init spitzled_init(void)
116{
117 return platform_driver_register(&spitzled_driver);
118}
119
120static void __exit spitzled_exit(void)
121{
Németh Márton4d404fd2008-03-09 20:59:57 +0000122 platform_driver_unregister(&spitzled_driver);
Richard Purdie31791082006-03-31 02:31:09 -0800123}
124
125module_init(spitzled_init);
126module_exit(spitzled_exit);
127
128MODULE_AUTHOR("Richard Purdie <rpurdie@openedhand.com>");
129MODULE_DESCRIPTION("Spitz LED driver");
130MODULE_LICENSE("GPL");
Kay Sievers3c4ded92008-04-15 14:34:30 -0700131MODULE_ALIAS("platform:spitz-led");