blob: b9826032450b4609c955260938a7d0889de40ef3 [file] [log] [blame]
Jonathan McDowell9becde72006-06-23 02:05:33 -07001/*
2 * LEDs driver for Amstrad Delta (E3)
3 *
4 * Copyright (C) 2006 Jonathan McDowell <noodles@earth.li>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
Jonathan McDowell9becde72006-06-23 02:05:33 -070011#include <linux/kernel.h>
12#include <linux/init.h>
13#include <linux/platform_device.h>
14#include <linux/leds.h>
Tony Lindgrence491cf2009-10-20 09:40:47 -070015#include <plat/board-ams-delta.h>
Jonathan McDowell9becde72006-06-23 02:05:33 -070016
17/*
18 * Our context
19 */
20struct ams_delta_led {
21 struct led_classdev cdev;
22 u8 bitmask;
23};
24
25static void ams_delta_led_set(struct led_classdev *led_cdev,
26 enum led_brightness value)
27{
28 struct ams_delta_led *led_dev =
29 container_of(led_cdev, struct ams_delta_led, cdev);
30
31 if (value)
32 ams_delta_latch1_write(led_dev->bitmask, led_dev->bitmask);
33 else
34 ams_delta_latch1_write(led_dev->bitmask, 0);
35}
36
37static struct ams_delta_led ams_delta_leds[] = {
38 {
39 .cdev = {
Richard Purdie6c152be2007-10-31 15:00:07 +010040 .name = "ams-delta::camera",
Jonathan McDowell9becde72006-06-23 02:05:33 -070041 .brightness_set = ams_delta_led_set,
42 },
43 .bitmask = AMS_DELTA_LATCH1_LED_CAMERA,
44 },
45 {
46 .cdev = {
Richard Purdie6c152be2007-10-31 15:00:07 +010047 .name = "ams-delta::advert",
Jonathan McDowell9becde72006-06-23 02:05:33 -070048 .brightness_set = ams_delta_led_set,
49 },
50 .bitmask = AMS_DELTA_LATCH1_LED_ADVERT,
51 },
52 {
53 .cdev = {
Richard Purdie6c152be2007-10-31 15:00:07 +010054 .name = "ams-delta::email",
Jonathan McDowell9becde72006-06-23 02:05:33 -070055 .brightness_set = ams_delta_led_set,
56 },
57 .bitmask = AMS_DELTA_LATCH1_LED_EMAIL,
58 },
59 {
60 .cdev = {
Richard Purdie6c152be2007-10-31 15:00:07 +010061 .name = "ams-delta::handsfree",
Jonathan McDowell9becde72006-06-23 02:05:33 -070062 .brightness_set = ams_delta_led_set,
63 },
64 .bitmask = AMS_DELTA_LATCH1_LED_HANDSFREE,
65 },
66 {
67 .cdev = {
Richard Purdie6c152be2007-10-31 15:00:07 +010068 .name = "ams-delta::voicemail",
Jonathan McDowell9becde72006-06-23 02:05:33 -070069 .brightness_set = ams_delta_led_set,
70 },
71 .bitmask = AMS_DELTA_LATCH1_LED_VOICEMAIL,
72 },
73 {
74 .cdev = {
Richard Purdie6c152be2007-10-31 15:00:07 +010075 .name = "ams-delta::voice",
Jonathan McDowell9becde72006-06-23 02:05:33 -070076 .brightness_set = ams_delta_led_set,
77 },
78 .bitmask = AMS_DELTA_LATCH1_LED_VOICE,
79 },
80};
81
Jonathan McDowell9becde72006-06-23 02:05:33 -070082static int ams_delta_led_probe(struct platform_device *pdev)
83{
Richard Purdiefbf0bae2008-10-20 23:46:15 +010084 int i, ret;
Jonathan McDowell9becde72006-06-23 02:05:33 -070085
Richard Purdiefbf0bae2008-10-20 23:46:15 +010086 for (i = 0; i < ARRAY_SIZE(ams_delta_leds); i++) {
Richard Purdie859cb7f2009-01-08 17:55:03 +000087 ams_delta_leds[i].cdev.flags |= LED_CORE_SUSPENDRESUME;
Jonathan McDowell9becde72006-06-23 02:05:33 -070088 ret = led_classdev_register(&pdev->dev,
89 &ams_delta_leds[i].cdev);
Richard Purdiefbf0bae2008-10-20 23:46:15 +010090 if (ret < 0)
91 goto fail;
Jonathan McDowell9becde72006-06-23 02:05:33 -070092 }
93
Richard Purdiefbf0bae2008-10-20 23:46:15 +010094 return 0;
95fail:
96 while (--i >= 0)
97 led_classdev_unregister(&ams_delta_leds[i].cdev);
98 return ret;
Jonathan McDowell9becde72006-06-23 02:05:33 -070099}
100
101static int ams_delta_led_remove(struct platform_device *pdev)
102{
103 int i;
104
Sven Wegener12276ef2008-12-03 08:11:17 +0000105 for (i = 0; i < ARRAY_SIZE(ams_delta_leds); i++)
Jonathan McDowell9becde72006-06-23 02:05:33 -0700106 led_classdev_unregister(&ams_delta_leds[i].cdev);
107
108 return 0;
109}
110
111static struct platform_driver ams_delta_led_driver = {
112 .probe = ams_delta_led_probe,
113 .remove = ams_delta_led_remove,
Jonathan McDowell9becde72006-06-23 02:05:33 -0700114 .driver = {
115 .name = "ams-delta-led",
Kay Sievers3c4ded92008-04-15 14:34:30 -0700116 .owner = THIS_MODULE,
Jonathan McDowell9becde72006-06-23 02:05:33 -0700117 },
118};
119
120static int __init ams_delta_led_init(void)
121{
122 return platform_driver_register(&ams_delta_led_driver);
123}
124
125static void __exit ams_delta_led_exit(void)
126{
Sven Wegener5a485032008-12-03 08:06:42 +0000127 platform_driver_unregister(&ams_delta_led_driver);
Jonathan McDowell9becde72006-06-23 02:05:33 -0700128}
129
130module_init(ams_delta_led_init);
131module_exit(ams_delta_led_exit);
132
133MODULE_AUTHOR("Jonathan McDowell <noodles@earth.li>");
134MODULE_DESCRIPTION("Amstrad Delta LED driver");
135MODULE_LICENSE("GPL");
Kay Sievers3c4ded92008-04-15 14:34:30 -0700136MODULE_ALIAS("platform:ams-delta-led");