misc: fix platform driver hotplug/coldplug
[linux-2.6/zen-sources.git] / drivers / misc / hdpuftrs / hdpu_nexus.c
blob2fa36f7a6eb388ec02db087560ec3dca4c8b2d1d
1 /*
2 * Sky Nexus Register Driver
4 * Copyright (C) 2002 Brian Waite
6 * This driver allows reading the Nexus register
7 * It exports the /proc/sky_chassis_id and also
8 * /proc/sky_slot_id pseudo-file for status information.
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version
13 * 2 of the License, or (at your option) any later version.
17 #include <linux/module.h>
18 #include <linux/kernel.h>
19 #include <linux/proc_fs.h>
20 #include <linux/hdpu_features.h>
21 #include <linux/platform_device.h>
22 #include <linux/seq_file.h>
23 #include <asm/io.h>
25 static int hdpu_nexus_probe(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);
32 static struct proc_dir_entry *hdpu_slot_id;
33 static struct proc_dir_entry *hdpu_chassis_id;
34 static int slot_id = -1;
35 static int chassis_id = -1;
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,
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,
53 static struct platform_driver hdpu_nexus_driver = {
54 .probe = hdpu_nexus_probe,
55 .remove = hdpu_nexus_remove,
56 .driver = {
57 .name = HDPU_NEXUS_NAME,
58 .owner = THIS_MODULE,
62 static int hdpu_slot_id_open(struct inode *inode, struct file *file)
64 return single_open(file, hdpu_slot_id_read, NULL);
67 static int hdpu_slot_id_read(struct seq_file *seq, void *offset)
69 seq_printf(seq, "%d\n", slot_id);
70 return 0;
73 static int hdpu_chassis_id_open(struct inode *inode, struct file *file)
75 return single_open(file, hdpu_chassis_id_read, NULL);
78 static int hdpu_chassis_id_read(struct seq_file *seq, void *offset)
80 seq_printf(seq, "%d\n", chassis_id);
81 return 0;
84 static int hdpu_nexus_probe(struct platform_device *pdev)
86 struct resource *res;
87 int *nexus_id_addr;
89 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
90 if (!res) {
91 printk(KERN_ERR "sky_nexus: "
92 "Invalid memory resource.\n");
93 return -EINVAL;
95 nexus_id_addr = ioremap(res->start,
96 (unsigned long)(res->end - res->start));
97 if (nexus_id_addr) {
98 slot_id = (*nexus_id_addr >> 8) & 0x1f;
99 chassis_id = *nexus_id_addr & 0xff;
100 iounmap(nexus_id_addr);
101 } else {
102 printk(KERN_ERR "sky_nexus: Could not map slot id\n");
105 hdpu_slot_id = create_proc_entry("sky_slot_id", 0666, &proc_root);
106 if (!hdpu_slot_id) {
107 printk(KERN_WARNING "sky_nexus: "
108 "Unable to create proc dir entry: sky_slot_id\n");
109 } else {
110 hdpu_slot_id->proc_fops = &proc_slot_id;
111 hdpu_slot_id->owner = THIS_MODULE;
114 hdpu_chassis_id = create_proc_entry("sky_chassis_id", 0666, &proc_root);
115 if (!hdpu_chassis_id) {
116 printk(KERN_WARNING "sky_nexus: "
117 "Unable to create proc dir entry: sky_chassis_id\n");
118 } else {
119 hdpu_chassis_id->proc_fops = &proc_chassis_id;
120 hdpu_chassis_id->owner = THIS_MODULE;
123 return 0;
126 static int hdpu_nexus_remove(struct platform_device *pdev)
128 slot_id = -1;
129 chassis_id = -1;
131 remove_proc_entry("sky_slot_id", &proc_root);
132 remove_proc_entry("sky_chassis_id", &proc_root);
134 hdpu_slot_id = 0;
135 hdpu_chassis_id = 0;
137 return 0;
140 static int __init nexus_init(void)
142 return platform_driver_register(&hdpu_nexus_driver);
145 static void __exit nexus_exit(void)
147 platform_driver_unregister(&hdpu_nexus_driver);
150 module_init(nexus_init);
151 module_exit(nexus_exit);
153 MODULE_AUTHOR("Brian Waite");
154 MODULE_LICENSE("GPL");
155 MODULE_ALIAS("platform:" HDPU_NEXUS_NAME);