[POWERPC] Sky Cpu and Nexus: use seq_file/single_open on proc interface
authorCyrill Gorcunov <gorcunov@gmail.com>
Tue, 2 Oct 2007 20:30:09 +0000 (13:30 -0700)
committerPaul Mackerras <paulus@samba.org>
Wed, 3 Oct 2007 02:02:44 +0000 (12:02 +1000)
This patch changes proc interface to be used with single_file/seq_open
calls.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Paul Mackerras <paulus@samba.org>
drivers/misc/hdpuftrs/hdpu_cpustate.c
drivers/misc/hdpuftrs/hdpu_nexus.c

index 32f65a3e07ceb49052bfbf5957fd09b3765d4357..aa8ce7abe9221666b6e7c01dff4f7dc7321dfc84 100644 (file)
 #include <linux/spinlock.h>
 #include <linux/miscdevice.h>
 #include <linux/proc_fs.h>
+#include <linux/hdpu_features.h>
 #include <linux/platform_device.h>
 #include <asm/uaccess.h>
-#include <linux/hdpu_features.h>
+#include <linux/seq_file.h>
 #include <asm/io.h>
 
 #define SKY_CPUSTATE_VERSION           "1.1"
 static int hdpu_cpustate_probe(struct platform_device *pdev);
 static int hdpu_cpustate_remove(struct platform_device *pdev);
 
-struct cpustate_t cpustate;
+static unsigned char cpustate_get_state(void);
+static int cpustate_proc_open(struct inode *inode, struct file *file);
+static int cpustate_proc_read(struct seq_file *seq, void *offset);
+
+static struct cpustate_t cpustate;
+
+static const struct file_operations proc_cpustate = {
+       .open = cpustate_proc_open,
+       .read = seq_read,
+       .llseek = seq_lseek,
+       .release = single_release,
+       .owner = THIS_MODULE,
+};
+
+static int cpustate_proc_open(struct inode *inode, struct file *file)
+{
+       return single_open(file, cpustate_proc_read, NULL);
+}
+
+static int cpustate_proc_read(struct seq_file *seq, void *offset)
+{
+       seq_printf(seq, "CPU State: %04x\n", cpustate_get_state());
+       return 0;
+}
 
 static int cpustate_get_ref(int excl)
 {
@@ -67,13 +91,13 @@ static int cpustate_free_ref(void)
        return 0;
 }
 
-unsigned char cpustate_get_state(void)
+static unsigned char cpustate_get_state(void)
 {
 
        return cpustate.cached_val;
 }
 
-void cpustate_set_state(unsigned char new_state)
+static void cpustate_set_state(unsigned char new_state)
 {
        unsigned int state = (new_state << 21);
 
@@ -135,29 +159,6 @@ static int cpustate_release(struct inode *inode, struct file *file)
        return cpustate_free_ref();
 }
 
-/*
- *     Info exported via "/proc/sky_cpustate".
- */
-static int cpustate_read_proc(char *page, char **start, off_t off,
-                             int count, int *eof, void *data)
-{
-       char *p = page;
-       int len = 0;
-
-       p += sprintf(p, "CPU State: %04x\n", cpustate_get_state());
-       len = p - page;
-
-       if (len <= off + count)
-               *eof = 1;
-       *start = page + off;
-       len -= off;
-       if (len > count)
-               len = count;
-       if (len < 0)
-               len = 0;
-       return len;
-}
-
 static struct platform_driver hdpu_cpustate_driver = {
        .probe = hdpu_cpustate_probe,
        .remove = hdpu_cpustate_remove,
@@ -208,11 +209,14 @@ static int hdpu_cpustate_probe(struct platform_device *pdev)
                return ret;
        }
 
-       proc_de = create_proc_read_entry("sky_cpustate", 0, 0,
-                                        cpustate_read_proc, NULL);
-       if (proc_de == NULL)
+       proc_de = create_proc_entry("sky_cpustate", 0666, &proc_root);
+       if (!proc_de) {
                printk(KERN_WARNING "sky_cpustate: "
-                      "Unable to create proc dir entry\n");
+                      "Unable to create proc entry\n");
+       } else {
+               proc_de->proc_fops = &proc_cpustate;
+               proc_de->owner = THIS_MODULE;
+       }
 
        printk(KERN_INFO "Sky CPU State Driver v" SKY_CPUSTATE_VERSION "\n");
        return 0;
index cc818532c7ec4b0d1d573250ef7b15d9fa8f0aa7..2887b21479800669f0af10b66e7dd79ddbdb0d19 100644 (file)
 #include <linux/kernel.h>
 #include <linux/proc_fs.h>
 #include <linux/hdpu_features.h>
-
 #include <linux/platform_device.h>
+#include <linux/seq_file.h>
 #include <asm/io.h>
 
 static int hdpu_nexus_probe(struct platform_device *pdev);
 static int hdpu_nexus_remove(struct platform_device *pdev);
+static int hdpu_slot_id_open(struct inode *inode, struct file *file);
+static int hdpu_slot_id_read(struct seq_file *seq, void *offset);
+static int hdpu_chassis_id_open(struct inode *inode, struct file *file);
+static int hdpu_chassis_id_read(struct seq_file *seq, void *offset);
 
 static struct proc_dir_entry *hdpu_slot_id;
 static struct proc_dir_entry *hdpu_chassis_id;
 static int slot_id = -1;
 static int chassis_id = -1;
 
+static const struct file_operations proc_slot_id = {
+       .open = hdpu_slot_id_open,
+       .read = seq_read,
+       .llseek = seq_lseek,
+       .release = single_release,
+       .owner = THIS_MODULE,
+};
+
+static const struct file_operations proc_chassis_id = {
+       .open = hdpu_chassis_id_open,
+       .read = seq_read,
+       .llseek = seq_lseek,
+       .release = single_release,
+       .owner = THIS_MODULE,
+};
+
 static struct platform_driver hdpu_nexus_driver = {
        .probe = hdpu_nexus_probe,
        .remove = hdpu_nexus_remove,
@@ -38,22 +58,26 @@ static struct platform_driver hdpu_nexus_driver = {
        },
 };
 
-int hdpu_slot_id_read(char *buffer, char **buffer_location, off_t offset,
-                     int buffer_length, int *zero, void *ptr)
+static int hdpu_slot_id_open(struct inode *inode, struct file *file)
 {
-       if (offset > 0)
-               return 0;
+       return single_open(file, hdpu_slot_id_read, NULL);
+}
 
-       return sprintf(buffer, "%d\n", slot_id);
+static int hdpu_slot_id_read(struct seq_file *seq, void *offset)
+{
+       seq_printf(seq, "%d\n", slot_id);
+       return 0;
 }
 
-int hdpu_chassis_id_read(char *buffer, char **buffer_location, off_t offset,
-                        int buffer_length, int *zero, void *ptr)
+static int hdpu_chassis_id_open(struct inode *inode, struct file *file)
 {
-       if (offset > 0)
-               return 0;
+       return single_open(file, hdpu_chassis_id_read, NULL);
+}
 
-       return sprintf(buffer, "%d\n", chassis_id);
+static int hdpu_chassis_id_read(struct seq_file *seq, void *offset)
+{
+       seq_printf(seq, "%d\n", chassis_id);
+       return 0;
 }
 
 static int hdpu_nexus_probe(struct platform_device *pdev)
@@ -82,7 +106,8 @@ static int hdpu_nexus_probe(struct platform_device *pdev)
                printk(KERN_WARNING "sky_nexus: "
                       "Unable to create proc dir entry: sky_slot_id\n");
        } else {
-               hdpu_slot_id->read_proc = hdpu_slot_id_read;
+               hdpu_slot_id->proc_fops = &proc_slot_id;
+               hdpu_slot_id->owner = THIS_MODULE;
        }
 
        hdpu_chassis_id = create_proc_entry("sky_chassis_id", 0666, &proc_root);
@@ -90,7 +115,8 @@ static int hdpu_nexus_probe(struct platform_device *pdev)
                printk(KERN_WARNING "sky_nexus: "
                       "Unable to create proc dir entry: sky_chassis_id\n");
        } else {
-               hdpu_chassis_id->read_proc = hdpu_chassis_id_read;
+               hdpu_chassis_id->proc_fops = &proc_chassis_id;
+               hdpu_chassis_id->owner = THIS_MODULE;
        }
 
        return 0;