2 * LED support code, ripped out of arch/arm/kernel/time.c
4 * Copyright (C) 1994-2001 Russell King
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 #include <linux/module.h>
11 #include <linux/init.h>
12 #include <linux/sysdev.h>
16 static void dummy_leds_event(led_event_t evt
)
20 void (*leds_event
)(led_event_t
) = dummy_leds_event
;
22 struct leds_evt_name
{
28 static const struct leds_evt_name evt_names
[] = {
29 { "amber", led_amber_on
, led_amber_off
},
30 { "blue", led_blue_on
, led_blue_off
},
31 { "green", led_green_on
, led_green_off
},
32 { "red", led_red_on
, led_red_off
},
35 static ssize_t
leds_store(struct sys_device
*dev
,
36 struct sysdev_attribute
*attr
,
37 const char *buf
, size_t size
)
39 int ret
= -EINVAL
, len
= strcspn(buf
, " ");
41 if (len
> 0 && buf
[len
] == '\0')
44 if (strncmp(buf
, "claim", len
) == 0) {
45 leds_event(led_claim
);
47 } else if (strncmp(buf
, "release", len
) == 0) {
48 leds_event(led_release
);
53 for (i
= 0; i
< ARRAY_SIZE(evt_names
); i
++) {
54 if (strlen(evt_names
[i
].name
) != len
||
55 strncmp(buf
, evt_names
[i
].name
, len
) != 0)
57 if (strncmp(buf
+len
, " on", 3) == 0) {
58 leds_event(evt_names
[i
].on
);
60 } else if (strncmp(buf
+len
, " off", 4) == 0) {
61 leds_event(evt_names
[i
].off
);
70 static SYSDEV_ATTR(event
, 0200, NULL
, leds_store
);
72 static int leds_suspend(struct sys_device
*dev
, pm_message_t state
)
78 static int leds_resume(struct sys_device
*dev
)
80 leds_event(led_start
);
84 static int leds_shutdown(struct sys_device
*dev
)
86 leds_event(led_halted
);
90 static struct sysdev_class leds_sysclass
= {
92 .shutdown
= leds_shutdown
,
93 .suspend
= leds_suspend
,
94 .resume
= leds_resume
,
97 static struct sys_device leds_device
= {
99 .cls
= &leds_sysclass
,
102 static int __init
leds_init(void)
105 ret
= sysdev_class_register(&leds_sysclass
);
107 ret
= sysdev_register(&leds_device
);
109 ret
= sysdev_create_file(&leds_device
, &attr_event
);
113 device_initcall(leds_init
);
115 EXPORT_SYMBOL(leds_event
);