Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/roland...
[safe/jmp/linux-2.6] / drivers / parisc / led.c
index 133a616..188bc84 100644 (file)
@@ -3,7 +3,7 @@
  *
  *      (c) Copyright 2000 Red Hat Software
  *      (c) Copyright 2000 Helge Deller <hdeller@redhat.com>
- *      (c) Copyright 2001-2005 Helge Deller <deller@gmx.de>
+ *      (c) Copyright 2001-2009 Helge Deller <deller@gmx.de>
  *      (c) Copyright 2001 Randolph Chung <tausq@debian.org>
  *
  *      This program is free software; you can redistribute it and/or modify
@@ -38,6 +38,7 @@
 #include <linux/kernel_stat.h>
 #include <linux/reboot.h>
 #include <linux/proc_fs.h>
+#include <linux/seq_file.h>
 #include <linux/ctype.h>
 #include <linux/blkdev.h>
 #include <linux/workqueue.h>
@@ -66,8 +67,8 @@ static char lcd_text_default[32]  __read_mostly;
 
 
 static struct workqueue_struct *led_wq;
-static void led_work_func(void *);
-static DECLARE_WORK(led_task, led_work_func, NULL);
+static void led_work_func(struct work_struct *);
+static DECLARE_DELAYED_WORK(led_task, led_work_func);
 
 #if 0
 #define DPRINTK(x)     printk x
@@ -136,7 +137,7 @@ static int start_task(void)
 
        /* Create the work queue and queue the LED task */
        led_wq = create_singlethread_workqueue("led_wq");       
-       queue_work(led_wq, &led_task);
+       queue_delayed_work(led_wq, &led_task, 0);
 
        return 0;
 }
@@ -147,41 +148,34 @@ device_initcall(start_task);
 static void (*led_func_ptr) (unsigned char) __read_mostly;
 
 #ifdef CONFIG_PROC_FS
-static int led_proc_read(char *page, char **start, off_t off, int count, 
-       int *eof, void *data)
+static int led_proc_show(struct seq_file *m, void *v)
 {
-       char *out = page;
-       int len;
-
-       switch ((long)data)
+       switch ((long)m->private)
        {
        case LED_NOLCD:
-               out += sprintf(out, "Heartbeat: %d\n", led_heartbeat);
-               out += sprintf(out, "Disk IO: %d\n", led_diskio);
-               out += sprintf(out, "LAN Rx/Tx: %d\n", led_lanrxtx);
+               seq_printf(m, "Heartbeat: %d\n", led_heartbeat);
+               seq_printf(m, "Disk IO: %d\n", led_diskio);
+               seq_printf(m, "LAN Rx/Tx: %d\n", led_lanrxtx);
                break;
        case LED_HASLCD:
-               out += sprintf(out, "%s\n", lcd_text);
+               seq_printf(m, "%s\n", lcd_text);
                break;
        default:
-               *eof = 1;
                return 0;
        }
+       return 0;
+}
 
-       len = out - page - off;
-       if (len < count) {
-               *eof = 1;
-               if (len <= 0) return 0;
-       } else {
-               len = count;
-       }
-       *start = page + off;
-       return len;
+static int led_proc_open(struct inode *inode, struct file *file)
+{
+       return single_open(file, led_proc_show, PDE(inode)->data);
 }
 
-static int led_proc_write(struct file *file, const char *buf, 
-       unsigned long count, void *data)
+
+static ssize_t led_proc_write(struct file *file, const char *buf,
+       size_t count, loff_t *pos)
 {
+       void *data = PDE(file->f_path.dentry->d_inode)->data;
        char *cur, lbuf[count + 1];
        int d;
 
@@ -195,12 +189,6 @@ static int led_proc_write(struct file *file, const char *buf,
 
        cur = lbuf;
 
-       /* skip initial spaces */
-       while (*cur && isspace(*cur))
-       {
-               cur++;
-       }
-
        switch ((long)data)
        {
        case LED_NOLCD:
@@ -240,6 +228,15 @@ parse_error:
        return -EINVAL;
 }
 
+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 int __init led_create_procfs(void)
 {
        struct proc_dir_entry *proc_pdc_root = NULL;
@@ -249,24 +246,15 @@ static int __init led_create_procfs(void)
 
        proc_pdc_root = proc_mkdir("pdc", 0);
        if (!proc_pdc_root) return -1;
-       proc_pdc_root->owner = THIS_MODULE;
-       ent = create_proc_entry("led", S_IFREG|S_IRUGO|S_IWUSR, proc_pdc_root);
+       ent = proc_create_data("led", S_IRUGO|S_IWUSR, proc_pdc_root,
+                               &led_proc_fops, (void *)LED_NOLCD); /* LED */
        if (!ent) return -1;
-       ent->nlink = 1;
-       ent->data = (void *)LED_NOLCD; /* LED */
-       ent->read_proc = led_proc_read;
-       ent->write_proc = led_proc_write;
-       ent->owner = THIS_MODULE;
 
        if (led_type == LED_HASLCD)
        {
-               ent = create_proc_entry("lcd", S_IFREG|S_IRUGO|S_IWUSR, proc_pdc_root);
+               ent = proc_create_data("lcd", S_IRUGO|S_IWUSR, proc_pdc_root,
+                                       &led_proc_fops, (void *)LED_HASLCD); /* LCD */
                if (!ent) return -1;
-               ent->nlink = 1;
-               ent->data = (void *)LED_HASLCD; /* LCD */
-               ent->read_proc = led_proc_read;
-               ent->write_proc = led_proc_write;
-               ent->owner = THIS_MODULE;
        }
 
        return 0;
@@ -363,25 +351,20 @@ static __inline__ int led_get_net_activity(void)
 
        rx_total = tx_total = 0;
        
-       /* we are running as a workqueue task, so locking dev_base 
-        * for reading should be OK */
-       read_lock(&dev_base_lock);
+       /* we are running as a workqueue task, so we can use an RCU lookup */
        rcu_read_lock();
-       for (dev = dev_base; dev; dev = dev->next) {
-           struct net_device_stats *stats;
+       for_each_netdev_rcu(&init_net, dev) {
+           const struct net_device_stats *stats;
            struct in_device *in_dev = __in_dev_get_rcu(dev);
            if (!in_dev || !in_dev->ifa_list)
                continue;
-           if (LOOPBACK(in_dev->ifa_list->ifa_local))
+           if (ipv4_is_loopback(in_dev->ifa_list->ifa_local))
                continue;
-           if (!dev->get_stats) 
-               continue;
-           stats = dev->get_stats(dev);
+           stats = dev_get_stats(dev);
            rx_total += stats->rx_packets;
            tx_total += stats->tx_packets;
        }
        rcu_read_unlock();
-       read_unlock(&dev_base_lock);
 
        retval = 0;
 
@@ -410,16 +393,17 @@ static __inline__ int led_get_net_activity(void)
 static __inline__ int led_get_diskio_activity(void)
 {      
        static unsigned long last_pgpgin, last_pgpgout;
-       struct page_state pgstat;
+       unsigned long events[NR_VM_EVENT_ITEMS];
        int changed;
 
-       get_full_page_state(&pgstat); /* get no of sectors in & out */
+       all_vm_events(events);
 
        /* Just use a very simple calculation here. Do not care about overflow,
           since we only want to know if there was activity or not. */
-       changed = (pgstat.pgpgin != last_pgpgin) || (pgstat.pgpgout != last_pgpgout);
-       last_pgpgin  = pgstat.pgpgin;
-       last_pgpgout = pgstat.pgpgout;
+       changed = (events[PGPGIN] != last_pgpgin) ||
+                 (events[PGPGOUT] != last_pgpgout);
+       last_pgpgin  = events[PGPGIN];
+       last_pgpgout = events[PGPGOUT];
 
        return (changed ? LED_DISK_IO : 0);
 }
@@ -442,7 +426,7 @@ static __inline__ int led_get_diskio_activity(void)
 
 #define LED_UPDATE_INTERVAL (1 + (HZ*19/1000))
 
-static void led_work_func (void *unused)
+static void led_work_func (struct work_struct *unused)
 {
        static unsigned long last_jiffies;
        static unsigned long count_HZ; /* counter in range 0..HZ */
@@ -472,9 +456,20 @@ static void led_work_func (void *unused)
        if (likely(led_lanrxtx))  currentleds |= led_get_net_activity();
        if (likely(led_diskio))   currentleds |= led_get_diskio_activity();
 
-       /* blink all LEDs twice a second if we got an Oops (HPMC) */
-       if (unlikely(oops_in_progress)) 
-               currentleds = (count_HZ<=(HZ/2)) ? 0 : 0xff;
+       /* blink LEDs if we got an Oops (HPMC) */
+       if (unlikely(oops_in_progress)) {
+               if (boot_cpu_data.cpu_type >= pcxl2) {
+                       /* newer machines don't have loadavg. LEDs, so we
+                        * let all LEDs blink twice per second instead */
+                       currentleds = (count_HZ <= (HZ/2)) ? 0 : 0xff;
+               } else {
+                       /* old machines: blink loadavg. LEDs twice per second */
+                       if (count_HZ <= (HZ/2))
+                               currentleds &= ~(LED4|LED5|LED6|LED7);
+                       else
+                               currentleds |= (LED4|LED5|LED6|LED7);
+               }
+       }
 
        if (currentleds != lastleds)
        {
@@ -520,7 +515,7 @@ static int led_halt(struct notifier_block *nb, unsigned long event, void *buf)
        
        /* Cancel the work item and delete the queue */
        if (led_wq) {
-               cancel_rearming_delayed_workqueue(led_wq, &led_task);
+               cancel_delayed_work_sync(&led_task);
                destroy_workqueue(led_wq);
                led_wq = NULL;
        }
@@ -578,7 +573,7 @@ int __init register_led_driver(int model, unsigned long cmd_reg, unsigned long d
 
        default:
                printk(KERN_ERR "%s: Wrong LCD/LED model %d !\n",
-                      __FUNCTION__, lcd_info.model);
+                      __func__, lcd_info.model);
                return 1;
        }
        
@@ -589,7 +584,7 @@ int __init register_led_driver(int model, unsigned long cmd_reg, unsigned long d
 
        /* Ensure the work is queued */
        if (led_wq) {
-               queue_work(led_wq, &led_task);
+               queue_delayed_work(led_wq, &led_task, 0);
        }
 
        return 0;
@@ -630,7 +625,7 @@ void __init register_led_regions(void)
    ** avoid a race condition while writing the CMD/DATA register pair.
    **
  */
-int lcd_print( char *str )
+int lcd_print( const char *str )
 {
        int i;
 
@@ -639,7 +634,7 @@ int lcd_print( char *str )
        
        /* temporarily disable the led work task */
        if (led_wq)
-               cancel_rearming_delayed_workqueue(led_wq, &led_task);
+               cancel_delayed_work_sync(&led_task);
 
        /* copy display string to buffer for procfs */
        strlcpy(lcd_text, str, sizeof(lcd_text));
@@ -659,7 +654,7 @@ int lcd_print( char *str )
        
        /* re-queue the work */
        if (led_wq) {
-               queue_work(led_wq, &led_task);
+               queue_delayed_work(led_wq, &led_task, 0);
        }
 
        return lcd_info.lcd_width;
@@ -683,7 +678,7 @@ int __init led_init(void)
        int ret;
 
        snprintf(lcd_text_default, sizeof(lcd_text_default),
-               "Linux %s", system_utsname.release);
+               "Linux %s", init_utsname()->release);
 
        /* Work around the buggy PDC of KittyHawk-machines */
        switch (CPU_HVERSION) {