1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * LEDs driver for the "User LED" on Routerboard532
4 *
5 * Copyright (C) 2009 Phil Sutter <n0-1@freewrt.org>
6 *
7 * Based on leds-cobalt-qube.c by Florian Fainelly and
8 * rb-diag.c (my own standalone driver for both LED and
9 * button of Routerboard532).
10 */
11
12 #include <linux/leds.h>
13 #include <linux/module.h>
14 #include <linux/platform_device.h>
15
16 #include <asm/mach-rc32434/gpio.h>
17 #include <asm/mach-rc32434/rb.h>
18
rb532_led_set(struct led_classdev * cdev,enum led_brightness brightness)19 static void rb532_led_set(struct led_classdev *cdev,
20 enum led_brightness brightness)
21 {
22 if (brightness)
23 set_latch_u5(LO_ULED, 0);
24 else
25 set_latch_u5(0, LO_ULED);
26 }
27
rb532_led_get(struct led_classdev * cdev)28 static enum led_brightness rb532_led_get(struct led_classdev *cdev)
29 {
30 return (get_latch_u5() & LO_ULED) ? LED_FULL : LED_OFF;
31 }
32
33 static struct led_classdev rb532_uled = {
34 .name = "uled",
35 .brightness_set = rb532_led_set,
36 .brightness_get = rb532_led_get,
37 .default_trigger = "nand-disk",
38 };
39
rb532_led_probe(struct platform_device * pdev)40 static int rb532_led_probe(struct platform_device *pdev)
41 {
42 return led_classdev_register(&pdev->dev, &rb532_uled);
43 }
44
rb532_led_remove(struct platform_device * pdev)45 static void rb532_led_remove(struct platform_device *pdev)
46 {
47 led_classdev_unregister(&rb532_uled);
48 }
49
50 static struct platform_driver rb532_led_driver = {
51 .probe = rb532_led_probe,
52 .remove_new = rb532_led_remove,
53 .driver = {
54 .name = "rb532-led",
55 },
56 };
57
58 module_platform_driver(rb532_led_driver);
59
60 MODULE_LICENSE("GPL");
61 MODULE_DESCRIPTION("User LED support for Routerboard532");
62 MODULE_AUTHOR("Phil Sutter <n0-1@freewrt.org>");
63 MODULE_ALIAS("platform:rb532-led");
64