blob: 8c00937bf7e74d02bc1759cbab01ca6eba1bc13e [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
Axel Lin86383b52011-08-25 15:59:15 -070011#include <linux/module.h>
Jonathan McDowell9becde72006-06-23 02:05:33 -070012#include <linux/kernel.h>
13#include <linux/init.h>
14#include <linux/platform_device.h>
15#include <linux/leds.h>
Tony Lindgrence491cf2009-10-20 09:40:47 -070016#include <plat/board-ams-delta.h>
Jonathan McDowell9becde72006-06-23 02:05:33 -070017
18/*
19 * Our context
20 */
21struct ams_delta_led {
22 struct led_classdev cdev;
23 u8 bitmask;
24};
25
26static void ams_delta_led_set(struct led_classdev *led_cdev,
27 enum led_brightness value)
28{
29 struct ams_delta_led *led_dev =
30 container_of(led_cdev, struct ams_delta_led, cdev);
31
32 if (value)
33 ams_delta_latch1_write(led_dev->bitmask, led_dev->bitmask);
34 else
35 ams_delta_latch1_write(led_dev->bitmask, 0);
36}
37
38static struct ams_delta_led ams_delta_leds[] = {
39 {
40 .cdev = {
Richard Purdie6c152be2007-10-31 15:00:07 +010041 .name = "ams-delta::camera",
Jonathan McDowell9becde72006-06-23 02:05:33 -070042 .brightness_set = ams_delta_led_set,
43 },
44 .bitmask = AMS_DELTA_LATCH1_LED_CAMERA,
45 },
46 {
47 .cdev = {
Richard Purdie6c152be2007-10-31 15:00:07 +010048 .name = "ams-delta::advert",
Jonathan McDowell9becde72006-06-23 02:05:33 -070049 .brightness_set = ams_delta_led_set,
50 },
51 .bitmask = AMS_DELTA_LATCH1_LED_ADVERT,
52 },
53 {
54 .cdev = {
Richard Purdie6c152be2007-10-31 15:00:07 +010055 .name = "ams-delta::email",
Jonathan McDowell9becde72006-06-23 02:05:33 -070056 .brightness_set = ams_delta_led_set,
57 },
58 .bitmask = AMS_DELTA_LATCH1_LED_EMAIL,
59 },
60 {
61 .cdev = {
Richard Purdie6c152be2007-10-31 15:00:07 +010062 .name = "ams-delta::handsfree",
Jonathan McDowell9becde72006-06-23 02:05:33 -070063 .brightness_set = ams_delta_led_set,
64 },
65 .bitmask = AMS_DELTA_LATCH1_LED_HANDSFREE,
66 },
67 {
68 .cdev = {
Richard Purdie6c152be2007-10-31 15:00:07 +010069 .name = "ams-delta::voicemail",
Jonathan McDowell9becde72006-06-23 02:05:33 -070070 .brightness_set = ams_delta_led_set,
71 },
72 .bitmask = AMS_DELTA_LATCH1_LED_VOICEMAIL,
73 },
74 {
75 .cdev = {
Richard Purdie6c152be2007-10-31 15:00:07 +010076 .name = "ams-delta::voice",
Jonathan McDowell9becde72006-06-23 02:05:33 -070077 .brightness_set = ams_delta_led_set,
78 },
79 .bitmask = AMS_DELTA_LATCH1_LED_VOICE,
80 },
81};
82
Jonathan McDowell9becde72006-06-23 02:05:33 -070083static int ams_delta_led_probe(struct platform_device *pdev)
84{
Richard Purdiefbf0bae2008-10-20 23:46:15 +010085 int i, ret;
Jonathan McDowell9becde72006-06-23 02:05:33 -070086
Richard Purdiefbf0bae2008-10-20 23:46:15 +010087 for (i = 0; i < ARRAY_SIZE(ams_delta_leds); i++) {
Richard Purdie859cb7f2009-01-08 17:55:03 +000088 ams_delta_leds[i].cdev.flags |= LED_CORE_SUSPENDRESUME;
Jonathan McDowell9becde72006-06-23 02:05:33 -070089 ret = led_classdev_register(&pdev->dev,
90 &ams_delta_leds[i].cdev);
Richard Purdiefbf0bae2008-10-20 23:46:15 +010091 if (ret < 0)
92 goto fail;
Jonathan McDowell9becde72006-06-23 02:05:33 -070093 }
94
Richard Purdiefbf0bae2008-10-20 23:46:15 +010095 return 0;
96fail:
97 while (--i >= 0)
98 led_classdev_unregister(&ams_delta_leds[i].cdev);
99 return ret;
Jonathan McDowell9becde72006-06-23 02:05:33 -0700100}
101
102static int ams_delta_led_remove(struct platform_device *pdev)
103{
104 int i;
105
Sven Wegener12276ef2008-12-03 08:11:17 +0000106 for (i = 0; i < ARRAY_SIZE(ams_delta_leds); i++)
Jonathan McDowell9becde72006-06-23 02:05:33 -0700107 led_classdev_unregister(&ams_delta_leds[i].cdev);
108
109 return 0;
110}
111
112static struct platform_driver ams_delta_led_driver = {
113 .probe = ams_delta_led_probe,
114 .remove = ams_delta_led_remove,
Jonathan McDowell9becde72006-06-23 02:05:33 -0700115 .driver = {
116 .name = "ams-delta-led",
Kay Sievers3c4ded92008-04-15 14:34:30 -0700117 .owner = THIS_MODULE,
Jonathan McDowell9becde72006-06-23 02:05:33 -0700118 },
119};
120
121static int __init ams_delta_led_init(void)
122{
123 return platform_driver_register(&ams_delta_led_driver);
124}
125
126static void __exit ams_delta_led_exit(void)
127{
Sven Wegener5a485032008-12-03 08:06:42 +0000128 platform_driver_unregister(&ams_delta_led_driver);
Jonathan McDowell9becde72006-06-23 02:05:33 -0700129}
130
131module_init(ams_delta_led_init);
132module_exit(ams_delta_led_exit);
133
134MODULE_AUTHOR("Jonathan McDowell <noodles@earth.li>");
135MODULE_DESCRIPTION("Amstrad Delta LED driver");
136MODULE_LICENSE("GPL");
Kay Sievers3c4ded92008-04-15 14:34:30 -0700137MODULE_ALIAS("platform:ams-delta-led");