blob: 0398258c20cd52f392bd0d312a07faeef582b2fc [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Bryan Wu3dd6b992011-06-30 22:56:17 +08002 * Driver for the LED found on the EBSA110 machine
3 * Based on Versatile and RealView machine LED code
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Bryan Wu3dd6b992011-06-30 22:56:17 +08005 * License terms: GNU General Public License (GPL) version 2
6 * Author: Bryan Wu <bryan.wu@canonical.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 */
Bryan Wu3dd6b992011-06-30 22:56:17 +08008#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include <linux/init.h>
Bryan Wu3dd6b992011-06-30 22:56:17 +080010#include <linux/io.h>
11#include <linux/slab.h>
12#include <linux/leds.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <asm/mach-types.h>
15
Russell Kingbcbbf902011-06-10 11:13:05 +010016#include "core.h"
17
Bryan Wu3dd6b992011-06-30 22:56:17 +080018#if defined(CONFIG_NEW_LEDS) && defined(CONFIG_LEDS_CLASS)
19static void ebsa110_led_set(struct led_classdev *cdev,
20 enum led_brightness b)
Linus Torvalds1da177e2005-04-16 15:20:36 -070021{
Bryan Wu3dd6b992011-06-30 22:56:17 +080022 u8 reg = __raw_readb(SOFT_BASE);
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
Bryan Wu3dd6b992011-06-30 22:56:17 +080024 if (b != LED_OFF)
25 reg |= 0x80;
26 else
27 reg &= ~0x80;
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Bryan Wu3dd6b992011-06-30 22:56:17 +080029 __raw_writeb(reg, SOFT_BASE);
Linus Torvalds1da177e2005-04-16 15:20:36 -070030}
31
Bryan Wu3dd6b992011-06-30 22:56:17 +080032static enum led_brightness ebsa110_led_get(struct led_classdev *cdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070033{
Bryan Wu3dd6b992011-06-30 22:56:17 +080034 u8 reg = __raw_readb(SOFT_BASE);
35
36 return (reg & 0x80) ? LED_FULL : LED_OFF;
37}
38
39static int __init ebsa110_leds_init(void)
40{
41
42 struct led_classdev *cdev;
43 int ret;
44
45 if (!machine_is_ebsa110())
46 return -ENODEV;
47
48 cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
49 if (!cdev)
50 return -ENOMEM;
51
52 cdev->name = "ebsa110:0";
53 cdev->brightness_set = ebsa110_led_set;
54 cdev->brightness_get = ebsa110_led_get;
55 cdev->default_trigger = "heartbeat";
56
57 ret = led_classdev_register(NULL, cdev);
58 if (ret < 0) {
59 kfree(cdev);
60 return ret;
61 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
63 return 0;
64}
65
Bryan Wu3dd6b992011-06-30 22:56:17 +080066/*
67 * Since we may have triggers on any subsystem, defer registration
68 * until after subsystem_init.
69 */
70fs_initcall(ebsa110_leds_init);
71#endif