2006-03-31 17:31:07 +07:00
|
|
|
/*
|
|
|
|
* LED Kernel Timer Trigger
|
|
|
|
*
|
|
|
|
* Copyright 2005-2006 Openedhand Ltd.
|
|
|
|
*
|
|
|
|
* Author: Richard Purdie <rpurdie@openedhand.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/device.h>
|
2006-05-15 23:44:17 +07:00
|
|
|
#include <linux/ctype.h>
|
2006-03-31 17:31:07 +07:00
|
|
|
#include <linux/leds.h>
|
|
|
|
#include "leds.h"
|
|
|
|
|
2008-03-10 03:59:57 +07:00
|
|
|
static ssize_t led_delay_on_show(struct device *dev,
|
2007-07-09 05:19:31 +07:00
|
|
|
struct device_attribute *attr, char *buf)
|
2006-03-31 17:31:07 +07:00
|
|
|
{
|
2007-07-09 05:19:31 +07:00
|
|
|
struct led_classdev *led_cdev = dev_get_drvdata(dev);
|
2006-03-31 17:31:07 +07:00
|
|
|
|
2010-11-12 05:05:21 +07:00
|
|
|
return sprintf(buf, "%lu\n", led_cdev->blink_delay_on);
|
2006-03-31 17:31:07 +07:00
|
|
|
}
|
|
|
|
|
2008-03-10 03:59:57 +07:00
|
|
|
static ssize_t led_delay_on_store(struct device *dev,
|
2007-07-09 05:19:31 +07:00
|
|
|
struct device_attribute *attr, const char *buf, size_t size)
|
2006-03-31 17:31:07 +07:00
|
|
|
{
|
2007-07-09 05:19:31 +07:00
|
|
|
struct led_classdev *led_cdev = dev_get_drvdata(dev);
|
2006-03-31 17:31:07 +07:00
|
|
|
int ret = -EINVAL;
|
|
|
|
char *after;
|
|
|
|
unsigned long state = simple_strtoul(buf, &after, 10);
|
2006-05-15 23:44:17 +07:00
|
|
|
size_t count = after - buf;
|
2006-03-31 17:31:07 +07:00
|
|
|
|
2009-12-15 09:01:06 +07:00
|
|
|
if (isspace(*after))
|
2006-05-15 23:44:17 +07:00
|
|
|
count++;
|
|
|
|
|
|
|
|
if (count == size) {
|
2010-11-12 05:05:21 +07:00
|
|
|
led_blink_set(led_cdev, &state, &led_cdev->blink_delay_off);
|
2011-09-15 06:22:16 +07:00
|
|
|
led_cdev->blink_delay_on = state;
|
2006-05-15 23:44:17 +07:00
|
|
|
ret = count;
|
2006-03-31 17:31:07 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-03-10 03:59:57 +07:00
|
|
|
static ssize_t led_delay_off_show(struct device *dev,
|
2007-07-09 05:19:31 +07:00
|
|
|
struct device_attribute *attr, char *buf)
|
2006-03-31 17:31:07 +07:00
|
|
|
{
|
2007-07-09 05:19:31 +07:00
|
|
|
struct led_classdev *led_cdev = dev_get_drvdata(dev);
|
2006-03-31 17:31:07 +07:00
|
|
|
|
2010-11-12 05:05:21 +07:00
|
|
|
return sprintf(buf, "%lu\n", led_cdev->blink_delay_off);
|
2006-03-31 17:31:07 +07:00
|
|
|
}
|
|
|
|
|
2008-03-10 03:59:57 +07:00
|
|
|
static ssize_t led_delay_off_store(struct device *dev,
|
2007-07-09 05:19:31 +07:00
|
|
|
struct device_attribute *attr, const char *buf, size_t size)
|
2006-03-31 17:31:07 +07:00
|
|
|
{
|
2007-07-09 05:19:31 +07:00
|
|
|
struct led_classdev *led_cdev = dev_get_drvdata(dev);
|
2006-03-31 17:31:07 +07:00
|
|
|
int ret = -EINVAL;
|
|
|
|
char *after;
|
|
|
|
unsigned long state = simple_strtoul(buf, &after, 10);
|
2006-05-15 23:44:17 +07:00
|
|
|
size_t count = after - buf;
|
|
|
|
|
2009-12-15 09:01:06 +07:00
|
|
|
if (isspace(*after))
|
2006-05-15 23:44:17 +07:00
|
|
|
count++;
|
2006-03-31 17:31:07 +07:00
|
|
|
|
2006-05-15 23:44:17 +07:00
|
|
|
if (count == size) {
|
2010-11-12 05:05:21 +07:00
|
|
|
led_blink_set(led_cdev, &led_cdev->blink_delay_on, &state);
|
2011-09-15 06:22:16 +07:00
|
|
|
led_cdev->blink_delay_off = state;
|
2006-05-15 23:44:17 +07:00
|
|
|
ret = count;
|
2006-03-31 17:31:07 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-07-09 05:19:31 +07:00
|
|
|
static DEVICE_ATTR(delay_on, 0644, led_delay_on_show, led_delay_on_store);
|
|
|
|
static DEVICE_ATTR(delay_off, 0644, led_delay_off_show, led_delay_off_store);
|
2006-03-31 17:31:07 +07:00
|
|
|
|
|
|
|
static void timer_trig_activate(struct led_classdev *led_cdev)
|
|
|
|
{
|
2006-10-17 14:10:20 +07:00
|
|
|
int rc;
|
2006-03-31 17:31:07 +07:00
|
|
|
|
2010-11-12 05:05:21 +07:00
|
|
|
led_cdev->trigger_data = NULL;
|
2006-03-31 17:31:07 +07:00
|
|
|
|
2007-07-09 05:19:31 +07:00
|
|
|
rc = device_create_file(led_cdev->dev, &dev_attr_delay_on);
|
|
|
|
if (rc)
|
2010-11-12 05:05:21 +07:00
|
|
|
return;
|
2007-07-09 05:19:31 +07:00
|
|
|
rc = device_create_file(led_cdev->dev, &dev_attr_delay_off);
|
|
|
|
if (rc)
|
|
|
|
goto err_out_delayon;
|
2006-10-17 14:10:20 +07:00
|
|
|
|
2011-05-25 07:13:22 +07:00
|
|
|
led_blink_set(led_cdev, &led_cdev->blink_delay_on,
|
|
|
|
&led_cdev->blink_delay_off);
|
|
|
|
|
2010-11-12 05:05:21 +07:00
|
|
|
led_cdev->trigger_data = (void *)1;
|
2007-10-31 21:07:12 +07:00
|
|
|
|
2006-10-17 14:10:20 +07:00
|
|
|
return;
|
|
|
|
|
|
|
|
err_out_delayon:
|
2007-07-09 05:19:31 +07:00
|
|
|
device_remove_file(led_cdev->dev, &dev_attr_delay_on);
|
2006-03-31 17:31:07 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void timer_trig_deactivate(struct led_classdev *led_cdev)
|
|
|
|
{
|
2010-11-12 05:05:21 +07:00
|
|
|
if (led_cdev->trigger_data) {
|
2007-07-09 05:19:31 +07:00
|
|
|
device_remove_file(led_cdev->dev, &dev_attr_delay_on);
|
|
|
|
device_remove_file(led_cdev->dev, &dev_attr_delay_off);
|
2006-03-31 17:31:07 +07:00
|
|
|
}
|
2009-01-09 02:50:15 +07:00
|
|
|
|
2010-11-12 05:05:21 +07:00
|
|
|
/* Stop blinking */
|
|
|
|
led_brightness_set(led_cdev, LED_OFF);
|
2006-03-31 17:31:07 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct led_trigger timer_led_trigger = {
|
|
|
|
.name = "timer",
|
|
|
|
.activate = timer_trig_activate,
|
|
|
|
.deactivate = timer_trig_deactivate,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init timer_trig_init(void)
|
|
|
|
{
|
|
|
|
return led_trigger_register(&timer_led_trigger);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit timer_trig_exit(void)
|
|
|
|
{
|
|
|
|
led_trigger_unregister(&timer_led_trigger);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(timer_trig_init);
|
|
|
|
module_exit(timer_trig_exit);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Richard Purdie <rpurdie@openedhand.com>");
|
|
|
|
MODULE_DESCRIPTION("Timer LED trigger");
|
|
|
|
MODULE_LICENSE("GPL");
|