]>
Commit | Line | Data |
---|---|---|
9becde79 JM |
1 | /* |
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 | ||
9becde79 JM |
11 | #include <linux/kernel.h> |
12 | #include <linux/init.h> | |
13 | #include <linux/platform_device.h> | |
14 | #include <linux/leds.h> | |
a09e64fb | 15 | #include <mach/board-ams-delta.h> |
9becde79 JM |
16 | |
17 | /* | |
18 | * Our context | |
19 | */ | |
20 | struct ams_delta_led { | |
21 | struct led_classdev cdev; | |
22 | u8 bitmask; | |
23 | }; | |
24 | ||
25 | static 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 | ||
37 | static struct ams_delta_led ams_delta_leds[] = { | |
38 | { | |
39 | .cdev = { | |
6c152bee | 40 | .name = "ams-delta::camera", |
9becde79 JM |
41 | .brightness_set = ams_delta_led_set, |
42 | }, | |
43 | .bitmask = AMS_DELTA_LATCH1_LED_CAMERA, | |
44 | }, | |
45 | { | |
46 | .cdev = { | |
6c152bee | 47 | .name = "ams-delta::advert", |
9becde79 JM |
48 | .brightness_set = ams_delta_led_set, |
49 | }, | |
50 | .bitmask = AMS_DELTA_LATCH1_LED_ADVERT, | |
51 | }, | |
52 | { | |
53 | .cdev = { | |
6c152bee | 54 | .name = "ams-delta::email", |
9becde79 JM |
55 | .brightness_set = ams_delta_led_set, |
56 | }, | |
57 | .bitmask = AMS_DELTA_LATCH1_LED_EMAIL, | |
58 | }, | |
59 | { | |
60 | .cdev = { | |
6c152bee | 61 | .name = "ams-delta::handsfree", |
9becde79 JM |
62 | .brightness_set = ams_delta_led_set, |
63 | }, | |
64 | .bitmask = AMS_DELTA_LATCH1_LED_HANDSFREE, | |
65 | }, | |
66 | { | |
67 | .cdev = { | |
6c152bee | 68 | .name = "ams-delta::voicemail", |
9becde79 JM |
69 | .brightness_set = ams_delta_led_set, |
70 | }, | |
71 | .bitmask = AMS_DELTA_LATCH1_LED_VOICEMAIL, | |
72 | }, | |
73 | { | |
74 | .cdev = { | |
6c152bee | 75 | .name = "ams-delta::voice", |
9becde79 JM |
76 | .brightness_set = ams_delta_led_set, |
77 | }, | |
78 | .bitmask = AMS_DELTA_LATCH1_LED_VOICE, | |
79 | }, | |
80 | }; | |
81 | ||
9becde79 JM |
82 | static int ams_delta_led_probe(struct platform_device *pdev) |
83 | { | |
fbf0baee | 84 | int i, ret; |
9becde79 | 85 | |
fbf0baee | 86 | for (i = 0; i < ARRAY_SIZE(ams_delta_leds); i++) { |
859cb7f2 | 87 | ams_delta_leds[i].cdev.flags |= LED_CORE_SUSPENDRESUME; |
9becde79 JM |
88 | ret = led_classdev_register(&pdev->dev, |
89 | &ams_delta_leds[i].cdev); | |
fbf0baee RP |
90 | if (ret < 0) |
91 | goto fail; | |
9becde79 JM |
92 | } |
93 | ||
fbf0baee RP |
94 | return 0; |
95 | fail: | |
96 | while (--i >= 0) | |
97 | led_classdev_unregister(&ams_delta_leds[i].cdev); | |
98 | return ret; | |
9becde79 JM |
99 | } |
100 | ||
101 | static int ams_delta_led_remove(struct platform_device *pdev) | |
102 | { | |
103 | int i; | |
104 | ||
12276efc | 105 | for (i = 0; i < ARRAY_SIZE(ams_delta_leds); i++) |
9becde79 JM |
106 | led_classdev_unregister(&ams_delta_leds[i].cdev); |
107 | ||
108 | return 0; | |
109 | } | |
110 | ||
111 | static struct platform_driver ams_delta_led_driver = { | |
112 | .probe = ams_delta_led_probe, | |
113 | .remove = ams_delta_led_remove, | |
9becde79 JM |
114 | .driver = { |
115 | .name = "ams-delta-led", | |
3c4ded97 | 116 | .owner = THIS_MODULE, |
9becde79 JM |
117 | }, |
118 | }; | |
119 | ||
120 | static int __init ams_delta_led_init(void) | |
121 | { | |
122 | return platform_driver_register(&ams_delta_led_driver); | |
123 | } | |
124 | ||
125 | static void __exit ams_delta_led_exit(void) | |
126 | { | |
5a48503d | 127 | platform_driver_unregister(&ams_delta_led_driver); |
9becde79 JM |
128 | } |
129 | ||
130 | module_init(ams_delta_led_init); | |
131 | module_exit(ams_delta_led_exit); | |
132 | ||
133 | MODULE_AUTHOR("Jonathan McDowell <noodles@earth.li>"); | |
134 | MODULE_DESCRIPTION("Amstrad Delta LED driver"); | |
135 | MODULE_LICENSE("GPL"); | |
3c4ded97 | 136 | MODULE_ALIAS("platform:ams-delta-led"); |