summaryrefslogtreecommitdiffstats
path: root/drivers/leds/leds-ams-delta.c
blob: 9e3077463d8481944e351b466e3d4e6749751cb9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
 * LEDs driver for Amstrad Delta (E3)
 *
 * Copyright (C) 2006 Jonathan McDowell <noodles@earth.li>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */

#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/platform_device.h>
#include <linux/leds.h>
#include <asm/arch/board-ams-delta.h>

/*
 * Our context
 */
struct ams_delta_led {
	struct led_classdev	cdev;
	u8			bitmask;
};

static void ams_delta_led_set(struct led_classdev *led_cdev,
		enum led_brightness value)
{
	struct ams_delta_led *led_dev =
		container_of(led_cdev, struct ams_delta_led, cdev);

	if (value)
		ams_delta_latch1_write(led_dev->bitmask, led_dev->bitmask);
	else
		ams_delta_latch1_write(led_dev->bitmask, 0);
}

static struct ams_delta_led ams_delta_leds[] = {
	{
		.cdev		= {
			.name		= "ams-delta::camera",
			.brightness_set = ams_delta_led_set,
		},
		.bitmask	= AMS_DELTA_LATCH1_LED_CAMERA,
	},
	{
		.cdev		= {
			.name		= "ams-delta::advert",
			.brightness_set = ams_delta_led_set,
		},
		.bitmask	= AMS_DELTA_LATCH1_LED_ADVERT,
	},
	{
		.cdev		= {
			.name		= "ams-delta::email",
			.brightness_set = ams_delta_led_set,
		},
		.bitmask	= AMS_DELTA_LATCH1_LED_EMAIL,
	},
	{
		.cdev		= {
			.name		= "ams-delta::handsfree",
			.brightness_set = ams_delta_led_set,
		},
		.bitmask	= AMS_DELTA_LATCH1_LED_HANDSFREE,
	},
	{
		.cdev		= {
			.name		= "ams-delta::voicemail",
			.brightness_set = ams_delta_led_set,
		},
		.bitmask	= AMS_DELTA_LATCH1_LED_VOICEMAIL,
	},
	{
		.cdev		= {
			.name		= "ams-delta::voice",
			.brightness_set = ams_delta_led_set,
		},
		.bitmask	= AMS_DELTA_LATCH1_LED_VOICE,
	},
};

#ifdef CONFIG_PM
static int ams_delta_led_suspend(struct platform_device *dev,
		pm_message_t state)
{
	int i;

	for (i = 0; i < ARRAY_SIZE(ams_delta_leds); i++)
		led_classdev_suspend(&ams_delta_leds[i].cdev);

	return 0;
}

static int ams_delta_led_resume(struct platform_device *dev)
{
	int i;

	for (i = 0; i < ARRAY_SIZE(ams_delta_leds); i++)
		led_classdev_resume(&ams_delta_leds[i].cdev);

	return 0;
}
#else
#define ams_delta_led_suspend NULL
#define ams_delta_led_resume NULL
#endif

static int ams_delta_led_probe(struct platform_device *pdev)
{
	int i;
	int ret;

	for (i = ret = 0; ret >= 0 && i < ARRAY_SIZE(ams_delta_leds); i++) {
		ret = led_classdev_register(&pdev->dev,
				&ams_delta_leds[i].cdev);
	}

	if (ret < 0 && i > 1) {
		for (i = i - 2; i >= 0; i--)
			led_classdev_unregister(&ams_delta_leds[i].cdev);
	}

	return ret;
}

static int ams_delta_led_remove(struct platform_device *pdev)
{
	int i;

	for (i = ARRAY_SIZE(ams_delta_leds) - 1; i >= 0; i--)
		led_classdev_unregister(&ams_delta_leds[i].cdev);

	return 0;
}

static struct platform_driver ams_delta_led_driver = {
	.probe		= ams_delta_led_probe,
	.remove		= ams_delta_led_remove,
	.suspend	= ams_delta_led_suspend,
	.resume		= ams_delta_led_resume,
	.driver		= {
		.name = "ams-delta-led",
	},
};

static int __init ams_delta_led_init(void)
{
	return platform_driver_register(&ams_delta_led_driver);
}

static void __exit ams_delta_led_exit(void)
{
	return platform_driver_unregister(&ams_delta_led_driver);
}

module_init(ams_delta_led_init);
module_exit(ams_delta_led_exit);

MODULE_AUTHOR("Jonathan McDowell <noodles@earth.li>");
MODULE_DESCRIPTION("Amstrad Delta LED driver");
MODULE_LICENSE("GPL");