2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License version 2 as
4 * published by the Free Software Foundation.
6 * h3xxx atmel micro companion support, notification LED subdevice
8 * Author : Linus Walleij <linus.walleij@linaro.org>
11 #include <linux/module.h>
12 #include <linux/platform_device.h>
13 #include <linux/mfd/ipaq-micro.h>
14 #include <linux/leds.h>
16 #define LED_YELLOW 0x00
17 #define LED_GREEN 0x01
19 #define LED_EN (1 << 4) /* LED ON/OFF 0:off, 1:on */
20 #define LED_AUTOSTOP (1 << 5) /* LED ON/OFF auto stop set 0:disable, 1:enable */
21 #define LED_ALWAYS (1 << 6) /* LED Interrupt Mask 0:No mask, 1:mask */
23 static void micro_leds_brightness_set(struct led_classdev
*led_cdev
,
24 enum led_brightness value
)
26 struct ipaq_micro
*micro
= dev_get_drvdata(led_cdev
->dev
->parent
->parent
);
29 * Byte 0 = LED color: 0 = yellow, 1 = green
30 * yellow LED is always ~30 blinks per minute
31 * Byte 1 = duration (flags?) appears to be ignored
32 * Byte 2 = green ontime in 1/10 sec (deciseconds)
35 * Byte 3 = green offtime in 1/10 sec (deciseconds)
39 struct ipaq_micro_msg msg
= {
44 msg
.tx_data
[0] = LED_GREEN
;
47 msg
.tx_data
[2] = 0; /* Duty cycle 256 */
51 msg
.tx_data
[3] = 0; /* Duty cycle 256 */
53 ipaq_micro_tx_msg_sync(micro
, &msg
);
56 /* Maximum duty cycle in ms 256/10 sec = 25600 ms */
57 #define IPAQ_LED_MAX_DUTY 25600
59 static int micro_leds_blink_set(struct led_classdev
*led_cdev
,
60 unsigned long *delay_on
,
61 unsigned long *delay_off
)
63 struct ipaq_micro
*micro
= dev_get_drvdata(led_cdev
->dev
->parent
->parent
);
66 * Byte 0 = LED color: 0 = yellow, 1 = green
67 * yellow LED is always ~30 blinks per minute
68 * Byte 1 = duration (flags?) appears to be ignored
69 * Byte 2 = green ontime in 1/10 sec (deciseconds)
72 * Byte 3 = green offtime in 1/10 sec (deciseconds)
76 struct ipaq_micro_msg msg
= {
81 msg
.tx_data
[0] = LED_GREEN
;
82 if (*delay_on
> IPAQ_LED_MAX_DUTY
||
83 *delay_off
> IPAQ_LED_MAX_DUTY
)
86 if (*delay_on
== 0 && *delay_off
== 0) {
92 if (*delay_on
>= IPAQ_LED_MAX_DUTY
)
95 msg
.tx_data
[2] = (u8
) DIV_ROUND_CLOSEST(*delay_on
, 100);
96 if (*delay_off
>= IPAQ_LED_MAX_DUTY
)
99 msg
.tx_data
[3] = (u8
) DIV_ROUND_CLOSEST(*delay_off
, 100);
100 return ipaq_micro_tx_msg_sync(micro
, &msg
);
103 static struct led_classdev micro_led
= {
104 .name
= "led-ipaq-micro",
105 .brightness_set
= micro_leds_brightness_set
,
106 .blink_set
= micro_leds_blink_set
,
107 .flags
= LED_CORE_SUSPENDRESUME
,
110 static int micro_leds_probe(struct platform_device
*pdev
)
114 ret
= led_classdev_register(&pdev
->dev
, µ_led
);
116 dev_err(&pdev
->dev
, "registering led failed: %d\n", ret
);
119 dev_info(&pdev
->dev
, "iPAQ micro notification LED driver\n");
124 static int micro_leds_remove(struct platform_device
*pdev
)
126 led_classdev_unregister(µ_led
);
130 static struct platform_driver micro_leds_device_driver
= {
132 .name
= "ipaq-micro-leds",
134 .probe
= micro_leds_probe
,
135 .remove
= micro_leds_remove
,
137 module_platform_driver(micro_leds_device_driver
);
139 MODULE_LICENSE("GPL");
140 MODULE_DESCRIPTION("driver for iPAQ Atmel micro leds");
141 MODULE_ALIAS("platform:ipaq-micro-leds");