Florian Fainelli | 2fea6f3 | 2007-02-12 23:16:27 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2006 - Florian Fainelli <florian@openwrt.org> |
| 3 | * |
| 4 | * Control the Cobalt Qube/RaQ front LED |
| 5 | */ |
Yoichi Yuasa | 4276fd7 | 2007-09-27 17:51:17 +0900 | [diff] [blame] | 6 | #include <linux/io.h> |
| 7 | #include <linux/ioport.h> |
Florian Fainelli | 2fea6f3 | 2007-02-12 23:16:27 +0000 | [diff] [blame] | 8 | #include <linux/leds.h> |
Yoichi Yuasa | 4276fd7 | 2007-09-27 17:51:17 +0900 | [diff] [blame] | 9 | #include <linux/module.h> |
| 10 | #include <linux/platform_device.h> |
| 11 | #include <linux/types.h> |
Florian Fainelli | 2fea6f3 | 2007-02-12 23:16:27 +0000 | [diff] [blame] | 12 | |
Yoichi Yuasa | 4276fd7 | 2007-09-27 17:51:17 +0900 | [diff] [blame] | 13 | #define LED_FRONT_LEFT 0x01 |
| 14 | #define LED_FRONT_RIGHT 0x02 |
| 15 | |
| 16 | static void __iomem *led_port; |
| 17 | static u8 led_value; |
| 18 | |
| 19 | static void qube_front_led_set(struct led_classdev *led_cdev, |
Németh Márton | 4d404fd | 2008-03-09 20:59:57 +0000 | [diff] [blame] | 20 | enum led_brightness brightness) |
Florian Fainelli | 2fea6f3 | 2007-02-12 23:16:27 +0000 | [diff] [blame] | 21 | { |
| 22 | if (brightness) |
Yoichi Yuasa | 4276fd7 | 2007-09-27 17:51:17 +0900 | [diff] [blame] | 23 | led_value = LED_FRONT_LEFT | LED_FRONT_RIGHT; |
Florian Fainelli | 2fea6f3 | 2007-02-12 23:16:27 +0000 | [diff] [blame] | 24 | else |
Yoichi Yuasa | 4276fd7 | 2007-09-27 17:51:17 +0900 | [diff] [blame] | 25 | led_value = ~(LED_FRONT_LEFT | LED_FRONT_RIGHT); |
| 26 | writeb(led_value, led_port); |
Florian Fainelli | 2fea6f3 | 2007-02-12 23:16:27 +0000 | [diff] [blame] | 27 | } |
| 28 | |
Yoichi Yuasa | 4276fd7 | 2007-09-27 17:51:17 +0900 | [diff] [blame] | 29 | static struct led_classdev qube_front_led = { |
Olaf Hering | db3f520 | 2009-09-07 14:37:27 +0100 | [diff] [blame] | 30 | .name = "qube::front", |
Yoichi Yuasa | 4276fd7 | 2007-09-27 17:51:17 +0900 | [diff] [blame] | 31 | .brightness = LED_FULL, |
| 32 | .brightness_set = qube_front_led_set, |
Florian Fainelli | 51de036 | 2009-11-26 19:41:02 +0100 | [diff] [blame] | 33 | .default_trigger = "default-on", |
Florian Fainelli | 2fea6f3 | 2007-02-12 23:16:27 +0000 | [diff] [blame] | 34 | }; |
| 35 | |
Bill Pemberton | 98ea1ea | 2012-11-19 13:23:02 -0500 | [diff] [blame] | 36 | static int cobalt_qube_led_probe(struct platform_device *pdev) |
Florian Fainelli | 2fea6f3 | 2007-02-12 23:16:27 +0000 | [diff] [blame] | 37 | { |
Yoichi Yuasa | 4276fd7 | 2007-09-27 17:51:17 +0900 | [diff] [blame] | 38 | struct resource *res; |
Yoichi Yuasa | 4276fd7 | 2007-09-27 17:51:17 +0900 | [diff] [blame] | 39 | |
| 40 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 41 | if (!res) |
| 42 | return -EBUSY; |
| 43 | |
Jingoo Han | f87ef10 | 2012-10-23 05:21:27 -0700 | [diff] [blame] | 44 | led_port = devm_ioremap(&pdev->dev, res->start, resource_size(res)); |
Yoichi Yuasa | 4276fd7 | 2007-09-27 17:51:17 +0900 | [diff] [blame] | 45 | if (!led_port) |
| 46 | return -ENOMEM; |
| 47 | |
| 48 | led_value = LED_FRONT_LEFT | LED_FRONT_RIGHT; |
| 49 | writeb(led_value, led_port); |
| 50 | |
Vaishali Thakkar | aa4e252 | 2015-09-04 12:12:01 +0200 | [diff] [blame] | 51 | return devm_led_classdev_register(&pdev->dev, &qube_front_led); |
Florian Fainelli | 2fea6f3 | 2007-02-12 23:16:27 +0000 | [diff] [blame] | 52 | } |
| 53 | |
Yoichi Yuasa | 4276fd7 | 2007-09-27 17:51:17 +0900 | [diff] [blame] | 54 | static struct platform_driver cobalt_qube_led_driver = { |
| 55 | .probe = cobalt_qube_led_probe, |
Yoichi Yuasa | 4276fd7 | 2007-09-27 17:51:17 +0900 | [diff] [blame] | 56 | .driver = { |
| 57 | .name = "cobalt-qube-leds", |
Yoichi Yuasa | 4276fd7 | 2007-09-27 17:51:17 +0900 | [diff] [blame] | 58 | }, |
| 59 | }; |
| 60 | |
Axel Lin | 892a884 | 2012-01-10 15:09:24 -0800 | [diff] [blame] | 61 | module_platform_driver(cobalt_qube_led_driver); |
Florian Fainelli | 2fea6f3 | 2007-02-12 23:16:27 +0000 | [diff] [blame] | 62 | |
| 63 | MODULE_LICENSE("GPL"); |
| 64 | MODULE_DESCRIPTION("Front LED support for Cobalt Server"); |
| 65 | MODULE_AUTHOR("Florian Fainelli <florian@openwrt.org>"); |
Axel Lin | 892a884 | 2012-01-10 15:09:24 -0800 | [diff] [blame] | 66 | MODULE_ALIAS("platform:cobalt-qube-leds"); |