Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
[linux-2.6-block.git] / drivers / misc / hdpuftrs / hdpu_nexus.c
CommitLineData
1da177e4
LT
1/*
2 * Sky Nexus Register Driver
3 *
4 * Copyright (C) 2002 Brian Waite
5 *
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.
9 *
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.
14 *
15 */
16
1da177e4
LT
17#include <linux/module.h>
18#include <linux/kernel.h>
19#include <linux/proc_fs.h>
20#include <linux/hdpu_features.h>
d052d1be 21#include <linux/platform_device.h>
3049ea7e 22#include <linux/seq_file.h>
d2ceb47a 23#include <asm/io.h>
1da177e4 24
3ae5eaec
RK
25static int hdpu_nexus_probe(struct platform_device *pdev);
26static int hdpu_nexus_remove(struct platform_device *pdev);
3049ea7e
CG
27static int hdpu_slot_id_open(struct inode *inode, struct file *file);
28static int hdpu_slot_id_read(struct seq_file *seq, void *offset);
29static int hdpu_chassis_id_open(struct inode *inode, struct file *file);
30static int hdpu_chassis_id_read(struct seq_file *seq, void *offset);
1da177e4
LT
31
32static struct proc_dir_entry *hdpu_slot_id;
33static struct proc_dir_entry *hdpu_chassis_id;
34static int slot_id = -1;
35static int chassis_id = -1;
36
3049ea7e
CG
37static 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
45static 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
3ae5eaec 53static struct platform_driver hdpu_nexus_driver = {
1da177e4
LT
54 .probe = hdpu_nexus_probe,
55 .remove = hdpu_nexus_remove,
3ae5eaec
RK
56 .driver = {
57 .name = HDPU_NEXUS_NAME,
d6c23850 58 .owner = THIS_MODULE,
3ae5eaec 59 },
1da177e4
LT
60};
61
3049ea7e 62static int hdpu_slot_id_open(struct inode *inode, struct file *file)
1da177e4 63{
3049ea7e
CG
64 return single_open(file, hdpu_slot_id_read, NULL);
65}
a4e32b5f 66
3049ea7e
CG
67static int hdpu_slot_id_read(struct seq_file *seq, void *offset)
68{
69 seq_printf(seq, "%d\n", slot_id);
70 return 0;
1da177e4
LT
71}
72
3049ea7e 73static int hdpu_chassis_id_open(struct inode *inode, struct file *file)
1da177e4 74{
3049ea7e
CG
75 return single_open(file, hdpu_chassis_id_read, NULL);
76}
a4e32b5f 77
3049ea7e
CG
78static int hdpu_chassis_id_read(struct seq_file *seq, void *offset)
79{
80 seq_printf(seq, "%d\n", chassis_id);
81 return 0;
1da177e4
LT
82}
83
3ae5eaec 84static int hdpu_nexus_probe(struct platform_device *pdev)
1da177e4 85{
1da177e4 86 struct resource *res;
a4e32b5f 87 int *nexus_id_addr;
1da177e4
LT
88
89 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
7472fd36
CG
90 if (!res) {
91 printk(KERN_ERR "sky_nexus: "
92 "Invalid memory resource.\n");
93 return -EINVAL;
94 }
a4e32b5f
CG
95 nexus_id_addr = ioremap(res->start,
96 (unsigned long)(res->end - res->start));
1da177e4
LT
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);
a4e32b5f 101 } else {
7472fd36 102 printk(KERN_ERR "sky_nexus: Could not map slot id\n");
a4e32b5f
CG
103 }
104
c7705f34
DL
105 hdpu_slot_id = proc_create("sky_slot_id", 0666, NULL, &proc_slot_id);
106 if (!hdpu_slot_id) {
5f725fe9
CG
107 printk(KERN_WARNING "sky_nexus: "
108 "Unable to create proc dir entry: sky_slot_id\n");
5f725fe9 109 }
1da177e4 110
c7705f34
DL
111 hdpu_chassis_id = proc_create("sky_chassis_id", 0666, NULL,
112 &proc_chassis_id);
c74c120a 113 if (!hdpu_chassis_id)
5f725fe9
CG
114 printk(KERN_WARNING "sky_nexus: "
115 "Unable to create proc dir entry: sky_chassis_id\n");
a4e32b5f 116
1da177e4
LT
117 return 0;
118}
119
3ae5eaec 120static int hdpu_nexus_remove(struct platform_device *pdev)
1da177e4
LT
121{
122 slot_id = -1;
123 chassis_id = -1;
a4e32b5f 124
c74c120a
AD
125 remove_proc_entry("sky_slot_id", NULL);
126 remove_proc_entry("sky_chassis_id", NULL);
a4e32b5f 127
1da177e4
LT
128 hdpu_slot_id = 0;
129 hdpu_chassis_id = 0;
a4e32b5f 130
1da177e4
LT
131 return 0;
132}
133
134static int __init nexus_init(void)
135{
a4e32b5f 136 return platform_driver_register(&hdpu_nexus_driver);
1da177e4
LT
137}
138
139static void __exit nexus_exit(void)
140{
3ae5eaec 141 platform_driver_unregister(&hdpu_nexus_driver);
1da177e4
LT
142}
143
144module_init(nexus_init);
145module_exit(nexus_exit);
146
147MODULE_AUTHOR("Brian Waite");
148MODULE_LICENSE("GPL");
d6c23850 149MODULE_ALIAS("platform:" HDPU_NEXUS_NAME);