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/init.h> |
| 7 | #include <linux/io.h> |
| 8 | #include <linux/ioport.h> |
Florian Fainelli | 2fea6f3 | 2007-02-12 23:16:27 +0000 | [diff] [blame] | 9 | #include <linux/leds.h> |
Yoichi Yuasa | 4276fd7 | 2007-09-27 17:51:17 +0900 | [diff] [blame] | 10 | #include <linux/module.h> |
| 11 | #include <linux/platform_device.h> |
| 12 | #include <linux/types.h> |
Florian Fainelli | 2fea6f3 | 2007-02-12 23:16:27 +0000 | [diff] [blame] | 13 | |
Yoichi Yuasa | 4276fd7 | 2007-09-27 17:51:17 +0900 | [diff] [blame] | 14 | #define LED_FRONT_LEFT 0x01 |
| 15 | #define LED_FRONT_RIGHT 0x02 |
| 16 | |
| 17 | static void __iomem *led_port; |
| 18 | static u8 led_value; |
| 19 | |
| 20 | 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] | 21 | enum led_brightness brightness) |
Florian Fainelli | 2fea6f3 | 2007-02-12 23:16:27 +0000 | [diff] [blame] | 22 | { |
| 23 | if (brightness) |
Yoichi Yuasa | 4276fd7 | 2007-09-27 17:51:17 +0900 | [diff] [blame] | 24 | led_value = LED_FRONT_LEFT | LED_FRONT_RIGHT; |
Florian Fainelli | 2fea6f3 | 2007-02-12 23:16:27 +0000 | [diff] [blame] | 25 | else |
Yoichi Yuasa | 4276fd7 | 2007-09-27 17:51:17 +0900 | [diff] [blame] | 26 | led_value = ~(LED_FRONT_LEFT | LED_FRONT_RIGHT); |
| 27 | writeb(led_value, led_port); |
Florian Fainelli | 2fea6f3 | 2007-02-12 23:16:27 +0000 | [diff] [blame] | 28 | } |
| 29 | |
Yoichi Yuasa | 4276fd7 | 2007-09-27 17:51:17 +0900 | [diff] [blame] | 30 | static struct led_classdev qube_front_led = { |
Olaf Hering | db3f520 | 2009-09-07 14:37:27 +0100 | [diff] [blame] | 31 | .name = "qube::front", |
Yoichi Yuasa | 4276fd7 | 2007-09-27 17:51:17 +0900 | [diff] [blame] | 32 | .brightness = LED_FULL, |
| 33 | .brightness_set = qube_front_led_set, |
Florian Fainelli | 51de036 | 2009-11-26 19:41:02 +0100 | [diff] [blame] | 34 | .default_trigger = "default-on", |
Florian Fainelli | 2fea6f3 | 2007-02-12 23:16:27 +0000 | [diff] [blame] | 35 | }; |
| 36 | |
Bill Pemberton | 98ea1ea | 2012-11-19 13:23:02 -0500 | [diff] [blame] | 37 | static int cobalt_qube_led_probe(struct platform_device *pdev) |
Florian Fainelli | 2fea6f3 | 2007-02-12 23:16:27 +0000 | [diff] [blame] | 38 | { |
Yoichi Yuasa | 4276fd7 | 2007-09-27 17:51:17 +0900 | [diff] [blame] | 39 | struct resource *res; |
| 40 | int retval; |
| 41 | |
| 42 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 43 | if (!res) |
| 44 | return -EBUSY; |
| 45 | |
Jingoo Han | f87ef10 | 2012-10-23 05:21:27 -0700 | [diff] [blame] | 46 | led_port = devm_ioremap(&pdev->dev, res->start, resource_size(res)); |
Yoichi Yuasa | 4276fd7 | 2007-09-27 17:51:17 +0900 | [diff] [blame] | 47 | if (!led_port) |
| 48 | return -ENOMEM; |
| 49 | |
| 50 | led_value = LED_FRONT_LEFT | LED_FRONT_RIGHT; |
| 51 | writeb(led_value, led_port); |
| 52 | |
| 53 | retval = led_classdev_register(&pdev->dev, &qube_front_led); |
| 54 | if (retval) |
Jingoo Han | f87ef10 | 2012-10-23 05:21:27 -0700 | [diff] [blame] | 55 | goto err_null; |
Yoichi Yuasa | 4276fd7 | 2007-09-27 17:51:17 +0900 | [diff] [blame] | 56 | |
| 57 | return 0; |
| 58 | |
Jingoo Han | f87ef10 | 2012-10-23 05:21:27 -0700 | [diff] [blame] | 59 | err_null: |
Yoichi Yuasa | 4276fd7 | 2007-09-27 17:51:17 +0900 | [diff] [blame] | 60 | led_port = NULL; |
| 61 | |
| 62 | return retval; |
Florian Fainelli | 2fea6f3 | 2007-02-12 23:16:27 +0000 | [diff] [blame] | 63 | } |
| 64 | |
Bill Pemberton | 678e8a6 | 2012-11-19 13:26:00 -0500 | [diff] [blame] | 65 | static int cobalt_qube_led_remove(struct platform_device *pdev) |
Florian Fainelli | 2fea6f3 | 2007-02-12 23:16:27 +0000 | [diff] [blame] | 66 | { |
Yoichi Yuasa | 4276fd7 | 2007-09-27 17:51:17 +0900 | [diff] [blame] | 67 | led_classdev_unregister(&qube_front_led); |
| 68 | |
Jingoo Han | f87ef10 | 2012-10-23 05:21:27 -0700 | [diff] [blame] | 69 | if (led_port) |
Yoichi Yuasa | 4276fd7 | 2007-09-27 17:51:17 +0900 | [diff] [blame] | 70 | led_port = NULL; |
Yoichi Yuasa | 4276fd7 | 2007-09-27 17:51:17 +0900 | [diff] [blame] | 71 | |
| 72 | return 0; |
Florian Fainelli | 2fea6f3 | 2007-02-12 23:16:27 +0000 | [diff] [blame] | 73 | } |
| 74 | |
Yoichi Yuasa | 4276fd7 | 2007-09-27 17:51:17 +0900 | [diff] [blame] | 75 | static struct platform_driver cobalt_qube_led_driver = { |
| 76 | .probe = cobalt_qube_led_probe, |
Bill Pemberton | df07cf8 | 2012-11-19 13:20:20 -0500 | [diff] [blame] | 77 | .remove = cobalt_qube_led_remove, |
Yoichi Yuasa | 4276fd7 | 2007-09-27 17:51:17 +0900 | [diff] [blame] | 78 | .driver = { |
| 79 | .name = "cobalt-qube-leds", |
| 80 | .owner = THIS_MODULE, |
| 81 | }, |
| 82 | }; |
| 83 | |
Axel Lin | 892a884 | 2012-01-10 15:09:24 -0800 | [diff] [blame] | 84 | module_platform_driver(cobalt_qube_led_driver); |
Florian Fainelli | 2fea6f3 | 2007-02-12 23:16:27 +0000 | [diff] [blame] | 85 | |
| 86 | MODULE_LICENSE("GPL"); |
| 87 | MODULE_DESCRIPTION("Front LED support for Cobalt Server"); |
| 88 | MODULE_AUTHOR("Florian Fainelli <florian@openwrt.org>"); |
Axel Lin | 892a884 | 2012-01-10 15:09:24 -0800 | [diff] [blame] | 89 | MODULE_ALIAS("platform:cobalt-qube-leds"); |