linux/arch/sparc/kernel/led.c

151 lines
3.1 KiB
C
Raw Normal View History

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <linux/string.h>
[SPARC]: Fix build in arch/sparc/kernel/led.c CC [M] arch/sparc/kernel/led.o arch/sparc/kernel/led.c: In function 'led_blink': arch/sparc/kernel/led.c:35: error: invalid use of undefined type 'struct timer_list' arch/sparc/kernel/led.c:35: error: 'jiffies' undeclared (first use in this function) arch/sparc/kernel/led.c:35: error: (Each undeclared identifier is reported only once arch/sparc/kernel/led.c:35: error: for each function it appears in.) arch/sparc/kernel/led.c:36: error: 'avenrun' undeclared (first use in this function) arch/sparc/kernel/led.c:36: error: 'FSHIFT' undeclared (first use in this function) arch/sparc/kernel/led.c:36: error: 'HZ' undeclared (first use in this function) arch/sparc/kernel/led.c:37: error: invalid use of undefined type 'struct timer_list' arch/sparc/kernel/led.c:39: error: invalid use of undefined type 'struct timer_list' arch/sparc/kernel/led.c:40: error: invalid use of undefined type 'struct timer_list' arch/sparc/kernel/led.c:42: error: implicit declaration of function 'add_timer' arch/sparc/kernel/led.c: In function 'led_write_proc': arch/sparc/kernel/led.c:70: error: implicit declaration of function 'copy_from_user' arch/sparc/kernel/led.c:84: error: implicit declaration of function 'del_timer_sync' arch/sparc/kernel/led.c: In function 'led_init': arch/sparc/kernel/led.c:109: error: implicit declaration of function 'init_timer' arch/sparc/kernel/led.c:110: error: invalid use of undefined type 'struct timer_list' make[1]: *** [arch/sparc/kernel/led.o] Error 1 Based upon original patch by Robert Reif. Signed-off-by: David S. Miller <davem@davemloft.net>
2008-02-25 02:45:09 +00:00
#include <linux/jiffies.h>
#include <linux/timer.h>
#include <linux/uaccess.h>
#include <asm/auxio.h>
#define LED_MAX_LENGTH 8 /* maximum chars written to proc file */
static inline void led_toggle(void)
{
unsigned char val = get_auxio();
unsigned char on, off;
if (val & AUXIO_LED) {
on = 0;
off = AUXIO_LED;
} else {
on = AUXIO_LED;
off = 0;
}
set_auxio(on, off);
}
static struct timer_list led_blink_timer;
static void led_blink(unsigned long timeout)
{
led_toggle();
/* reschedule */
if (!timeout) { /* blink according to load */
led_blink_timer.expires = jiffies +
((1 + (avenrun[0] >> FSHIFT)) * HZ);
led_blink_timer.data = 0;
} else { /* blink at user specified interval */
led_blink_timer.expires = jiffies + (timeout * HZ);
led_blink_timer.data = timeout;
}
add_timer(&led_blink_timer);
}
static int led_proc_show(struct seq_file *m, void *v)
{
if (get_auxio() & AUXIO_LED)
seq_puts(m, "on\n");
else
seq_puts(m, "off\n");
return 0;
}
static int led_proc_open(struct inode *inode, struct file *file)
{
return single_open(file, led_proc_show, NULL);
}
static ssize_t led_proc_write(struct file *file, const char __user *buffer,
size_t count, loff_t *ppos)
{
char *buf = NULL;
if (count > LED_MAX_LENGTH)
count = LED_MAX_LENGTH;
buf = kmalloc(sizeof(char) * (count + 1), GFP_KERNEL);
if (!buf)
return -ENOMEM;
if (copy_from_user(buf, buffer, count)) {
kfree(buf);
return -EFAULT;
}
buf[count] = '\0';
/* work around \n when echo'ing into proc */
if (buf[count - 1] == '\n')
buf[count - 1] = '\0';
/* before we change anything we want to stop any running timers,
* otherwise calls such as on will have no persistent effect
*/
del_timer_sync(&led_blink_timer);
if (!strcmp(buf, "on")) {
auxio_set_led(AUXIO_LED_ON);
} else if (!strcmp(buf, "toggle")) {
led_toggle();
} else if ((*buf > '0') && (*buf <= '9')) {
led_blink(simple_strtoul(buf, NULL, 10));
} else if (!strcmp(buf, "load")) {
led_blink(0);
} else {
auxio_set_led(AUXIO_LED_OFF);
}
kfree(buf);
return count;
}
static const struct file_operations led_proc_fops = {
.owner = THIS_MODULE,
.open = led_proc_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
.write = led_proc_write,
};
static struct proc_dir_entry *led;
#define LED_VERSION "0.1"
static int __init led_init(void)
{
init_timer(&led_blink_timer);
led_blink_timer.function = led_blink;
led = proc_create("led", 0, NULL, &led_proc_fops);
if (!led)
return -ENOMEM;
led->owner = THIS_MODULE;
printk(KERN_INFO
"led: version %s, Lars Kotthoff <metalhead@metalhead.ws>\n",
LED_VERSION);
return 0;
}
static void __exit led_exit(void)
{
remove_proc_entry("led", NULL);
del_timer_sync(&led_blink_timer);
}
module_init(led_init);
module_exit(led_exit);
MODULE_AUTHOR("Lars Kotthoff <metalhead@metalhead.ws>");
MODULE_DESCRIPTION("Provides control of the front LED on SPARC systems.");
MODULE_LICENSE("GPL");
MODULE_VERSION(LED_VERSION);