1 // SPDX-License-Identifier: GPL-2.0-only
4 * h3xxx atmel micro companion support, notification LED subdevice
6 * Author : Linus Walleij <linus.walleij@linaro.org>
9 #include <linux/module.h>
10 #include <linux/platform_device.h>
11 #include <linux/mfd/ipaq-micro.h>
12 #include <linux/leds.h>
14 #define LED_YELLOW 0x00
15 #define LED_GREEN 0x01
17 #define LED_EN (1 << 4) /* LED ON/OFF 0:off, 1:on */
18 #define LED_AUTOSTOP (1 << 5) /* LED ON/OFF auto stop set 0:disable, 1:enable */
19 #define LED_ALWAYS (1 << 6) /* LED Interrupt Mask 0:No mask, 1:mask */
21 static int micro_leds_brightness_set(struct led_classdev *led_cdev,
22 enum led_brightness value)
24 struct ipaq_micro *micro = dev_get_drvdata(led_cdev->dev->parent->parent);
27 * Byte 0 = LED color: 0 = yellow, 1 = green
28 * yellow LED is always ~30 blinks per minute
29 * Byte 1 = duration (flags?) appears to be ignored
30 * Byte 2 = green ontime in 1/10 sec (deciseconds)
33 * Byte 3 = green offtime in 1/10 sec (deciseconds)
37 struct ipaq_micro_msg msg = {
42 msg.tx_data[0] = LED_GREEN;
45 msg.tx_data[2] = 0; /* Duty cycle 256 */
49 msg.tx_data[3] = 0; /* Duty cycle 256 */
51 return ipaq_micro_tx_msg_sync(micro, &msg);
54 /* Maximum duty cycle in ms 256/10 sec = 25600 ms */
55 #define IPAQ_LED_MAX_DUTY 25600
57 static int micro_leds_blink_set(struct led_classdev *led_cdev,
58 unsigned long *delay_on,
59 unsigned long *delay_off)
61 struct ipaq_micro *micro = dev_get_drvdata(led_cdev->dev->parent->parent);
64 * Byte 0 = LED color: 0 = yellow, 1 = green
65 * yellow LED is always ~30 blinks per minute
66 * Byte 1 = duration (flags?) appears to be ignored
67 * Byte 2 = green ontime in 1/10 sec (deciseconds)
70 * Byte 3 = green offtime in 1/10 sec (deciseconds)
74 struct ipaq_micro_msg msg = {
79 msg.tx_data[0] = LED_GREEN;
80 if (*delay_on > IPAQ_LED_MAX_DUTY ||
81 *delay_off > IPAQ_LED_MAX_DUTY)
84 if (*delay_on == 0 && *delay_off == 0) {
90 if (*delay_on >= IPAQ_LED_MAX_DUTY)
93 msg.tx_data[2] = (u8) DIV_ROUND_CLOSEST(*delay_on, 100);
94 if (*delay_off >= IPAQ_LED_MAX_DUTY)
97 msg.tx_data[3] = (u8) DIV_ROUND_CLOSEST(*delay_off, 100);
98 return ipaq_micro_tx_msg_sync(micro, &msg);
101 static struct led_classdev micro_led = {
102 .name = "led-ipaq-micro",
103 .brightness_set_blocking = micro_leds_brightness_set,
104 .blink_set = micro_leds_blink_set,
105 .flags = LED_CORE_SUSPENDRESUME,
108 static int micro_leds_probe(struct platform_device *pdev)
112 ret = devm_led_classdev_register(&pdev->dev, µ_led);
114 dev_err(&pdev->dev, "registering led failed: %d\n", ret);
117 dev_info(&pdev->dev, "iPAQ micro notification LED driver\n");
122 static struct platform_driver micro_leds_device_driver = {
124 .name = "ipaq-micro-leds",
126 .probe = micro_leds_probe,
128 module_platform_driver(micro_leds_device_driver);
130 MODULE_LICENSE("GPL");
131 MODULE_DESCRIPTION("driver for iPAQ Atmel micro leds");
132 MODULE_ALIAS("platform:ipaq-micro-leds");