diff options
Diffstat (limited to 'drivers/misc/hdpuftrs/hdpu_nexus.c')
-rw-r--r-- | drivers/misc/hdpuftrs/hdpu_nexus.c | 88 |
1 files changed, 67 insertions, 21 deletions
diff --git a/drivers/misc/hdpuftrs/hdpu_nexus.c b/drivers/misc/hdpuftrs/hdpu_nexus.c index 60c8b26f0678..2887b2147980 100644 --- a/drivers/misc/hdpuftrs/hdpu_nexus.c +++ b/drivers/misc/hdpuftrs/hdpu_nexus.c | |||
@@ -18,17 +18,38 @@ | |||
18 | #include <linux/kernel.h> | 18 | #include <linux/kernel.h> |
19 | #include <linux/proc_fs.h> | 19 | #include <linux/proc_fs.h> |
20 | #include <linux/hdpu_features.h> | 20 | #include <linux/hdpu_features.h> |
21 | |||
22 | #include <linux/platform_device.h> | 21 | #include <linux/platform_device.h> |
22 | #include <linux/seq_file.h> | ||
23 | #include <asm/io.h> | ||
23 | 24 | ||
24 | static int hdpu_nexus_probe(struct platform_device *pdev); | 25 | static int hdpu_nexus_probe(struct platform_device *pdev); |
25 | static int hdpu_nexus_remove(struct platform_device *pdev); | 26 | static int hdpu_nexus_remove(struct platform_device *pdev); |
27 | static int hdpu_slot_id_open(struct inode *inode, struct file *file); | ||
28 | static int hdpu_slot_id_read(struct seq_file *seq, void *offset); | ||
29 | static int hdpu_chassis_id_open(struct inode *inode, struct file *file); | ||
30 | static int hdpu_chassis_id_read(struct seq_file *seq, void *offset); | ||
26 | 31 | ||
27 | static struct proc_dir_entry *hdpu_slot_id; | 32 | static struct proc_dir_entry *hdpu_slot_id; |
28 | static struct proc_dir_entry *hdpu_chassis_id; | 33 | static struct proc_dir_entry *hdpu_chassis_id; |
29 | static int slot_id = -1; | 34 | static int slot_id = -1; |
30 | static int chassis_id = -1; | 35 | static int chassis_id = -1; |
31 | 36 | ||
37 | static const struct file_operations proc_slot_id = { | ||
38 | .open = hdpu_slot_id_open, | ||
39 | .read = seq_read, | ||
40 | .llseek = seq_lseek, | ||
41 | .release = single_release, | ||
42 | .owner = THIS_MODULE, | ||
43 | }; | ||
44 | |||
45 | static const struct file_operations proc_chassis_id = { | ||
46 | .open = hdpu_chassis_id_open, | ||
47 | .read = seq_read, | ||
48 | .llseek = seq_lseek, | ||
49 | .release = single_release, | ||
50 | .owner = THIS_MODULE, | ||
51 | }; | ||
52 | |||
32 | static struct platform_driver hdpu_nexus_driver = { | 53 | static struct platform_driver hdpu_nexus_driver = { |
33 | .probe = hdpu_nexus_probe, | 54 | .probe = hdpu_nexus_probe, |
34 | .remove = hdpu_nexus_remove, | 55 | .remove = hdpu_nexus_remove, |
@@ -37,43 +58,67 @@ static struct platform_driver hdpu_nexus_driver = { | |||
37 | }, | 58 | }, |
38 | }; | 59 | }; |
39 | 60 | ||
40 | int hdpu_slot_id_read(char *buffer, char **buffer_location, off_t offset, | 61 | static int hdpu_slot_id_open(struct inode *inode, struct file *file) |
41 | int buffer_length, int *zero, void *ptr) | ||
42 | { | 62 | { |
63 | return single_open(file, hdpu_slot_id_read, NULL); | ||
64 | } | ||
43 | 65 | ||
44 | if (offset > 0) | 66 | static int hdpu_slot_id_read(struct seq_file *seq, void *offset) |
45 | return 0; | 67 | { |
46 | return sprintf(buffer, "%d\n", slot_id); | 68 | seq_printf(seq, "%d\n", slot_id); |
69 | return 0; | ||
47 | } | 70 | } |
48 | 71 | ||
49 | int hdpu_chassis_id_read(char *buffer, char **buffer_location, off_t offset, | 72 | static int hdpu_chassis_id_open(struct inode *inode, struct file *file) |
50 | int buffer_length, int *zero, void *ptr) | ||
51 | { | 73 | { |
74 | return single_open(file, hdpu_chassis_id_read, NULL); | ||
75 | } | ||
52 | 76 | ||
53 | if (offset > 0) | 77 | static int hdpu_chassis_id_read(struct seq_file *seq, void *offset) |
54 | return 0; | 78 | { |
55 | return sprintf(buffer, "%d\n", chassis_id); | 79 | seq_printf(seq, "%d\n", chassis_id); |
80 | return 0; | ||
56 | } | 81 | } |
57 | 82 | ||
58 | static int hdpu_nexus_probe(struct platform_device *pdev) | 83 | static int hdpu_nexus_probe(struct platform_device *pdev) |
59 | { | 84 | { |
60 | struct resource *res; | 85 | struct resource *res; |
86 | int *nexus_id_addr; | ||
61 | 87 | ||
62 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 88 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
63 | int *nexus_id_addr; | 89 | if (!res) { |
64 | nexus_id_addr = | 90 | printk(KERN_ERR "sky_nexus: " |
65 | ioremap(res->start, (unsigned long)(res->end - res->start)); | 91 | "Invalid memory resource.\n"); |
92 | return -EINVAL; | ||
93 | } | ||
94 | nexus_id_addr = ioremap(res->start, | ||
95 | (unsigned long)(res->end - res->start)); | ||
66 | if (nexus_id_addr) { | 96 | if (nexus_id_addr) { |
67 | slot_id = (*nexus_id_addr >> 8) & 0x1f; | 97 | slot_id = (*nexus_id_addr >> 8) & 0x1f; |
68 | chassis_id = *nexus_id_addr & 0xff; | 98 | chassis_id = *nexus_id_addr & 0xff; |
69 | iounmap(nexus_id_addr); | 99 | iounmap(nexus_id_addr); |
70 | } else | 100 | } else { |
71 | printk("Could not map slot id\n"); | 101 | printk(KERN_ERR "sky_nexus: Could not map slot id\n"); |
102 | } | ||
103 | |||
72 | hdpu_slot_id = create_proc_entry("sky_slot_id", 0666, &proc_root); | 104 | hdpu_slot_id = create_proc_entry("sky_slot_id", 0666, &proc_root); |
73 | hdpu_slot_id->read_proc = hdpu_slot_id_read; | 105 | if (!hdpu_slot_id) { |
106 | printk(KERN_WARNING "sky_nexus: " | ||
107 | "Unable to create proc dir entry: sky_slot_id\n"); | ||
108 | } else { | ||
109 | hdpu_slot_id->proc_fops = &proc_slot_id; | ||
110 | hdpu_slot_id->owner = THIS_MODULE; | ||
111 | } | ||
74 | 112 | ||
75 | hdpu_chassis_id = create_proc_entry("sky_chassis_id", 0666, &proc_root); | 113 | hdpu_chassis_id = create_proc_entry("sky_chassis_id", 0666, &proc_root); |
76 | hdpu_chassis_id->read_proc = hdpu_chassis_id_read; | 114 | if (!hdpu_chassis_id) { |
115 | printk(KERN_WARNING "sky_nexus: " | ||
116 | "Unable to create proc dir entry: sky_chassis_id\n"); | ||
117 | } else { | ||
118 | hdpu_chassis_id->proc_fops = &proc_chassis_id; | ||
119 | hdpu_chassis_id->owner = THIS_MODULE; | ||
120 | } | ||
121 | |||
77 | return 0; | 122 | return 0; |
78 | } | 123 | } |
79 | 124 | ||
@@ -81,18 +126,19 @@ static int hdpu_nexus_remove(struct platform_device *pdev) | |||
81 | { | 126 | { |
82 | slot_id = -1; | 127 | slot_id = -1; |
83 | chassis_id = -1; | 128 | chassis_id = -1; |
129 | |||
84 | remove_proc_entry("sky_slot_id", &proc_root); | 130 | remove_proc_entry("sky_slot_id", &proc_root); |
85 | remove_proc_entry("sky_chassis_id", &proc_root); | 131 | remove_proc_entry("sky_chassis_id", &proc_root); |
132 | |||
86 | hdpu_slot_id = 0; | 133 | hdpu_slot_id = 0; |
87 | hdpu_chassis_id = 0; | 134 | hdpu_chassis_id = 0; |
135 | |||
88 | return 0; | 136 | return 0; |
89 | } | 137 | } |
90 | 138 | ||
91 | static int __init nexus_init(void) | 139 | static int __init nexus_init(void) |
92 | { | 140 | { |
93 | int rc; | 141 | return platform_driver_register(&hdpu_nexus_driver); |
94 | rc = platform_driver_register(&hdpu_nexus_driver); | ||
95 | return rc; | ||
96 | } | 142 | } |
97 | 143 | ||
98 | static void __exit nexus_exit(void) | 144 | static void __exit nexus_exit(void) |