blob: ce39fa54949ba39645d80e1af92a035bc0aa099b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/module.h>
18#include <linux/kernel.h>
19#include <linux/proc_fs.h>
20#include <linux/hdpu_features.h>
Russell Kingd052d1b2005-10-29 19:07:23 +010021#include <linux/platform_device.h>
Cyrill Gorcunov3049ea72007-10-02 13:30:09 -070022#include <linux/seq_file.h>
Cyrill Gorcunovd2ceb47a2007-10-02 13:30:06 -070023#include <asm/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
Russell King3ae5eae2005-11-09 22:32:44 +000025static int hdpu_nexus_probe(struct platform_device *pdev);
26static int hdpu_nexus_remove(struct platform_device *pdev);
Cyrill Gorcunov3049ea72007-10-02 13:30:09 -070027static 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
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
Cyrill Gorcunov3049ea72007-10-02 13:30:09 -070037static 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
Russell King3ae5eae2005-11-09 22:32:44 +000053static struct platform_driver hdpu_nexus_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 .probe = hdpu_nexus_probe,
55 .remove = hdpu_nexus_remove,
Russell King3ae5eae2005-11-09 22:32:44 +000056 .driver = {
57 .name = HDPU_NEXUS_NAME,
Kay Sieversd6c23852008-04-15 14:34:33 -070058 .owner = THIS_MODULE,
Russell King3ae5eae2005-11-09 22:32:44 +000059 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070060};
61
Cyrill Gorcunov3049ea72007-10-02 13:30:09 -070062static int hdpu_slot_id_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -070063{
Cyrill Gorcunov3049ea72007-10-02 13:30:09 -070064 return single_open(file, hdpu_slot_id_read, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070065}
66
Cyrill Gorcunov3049ea72007-10-02 13:30:09 -070067static int hdpu_slot_id_read(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068{
Cyrill Gorcunov3049ea72007-10-02 13:30:09 -070069 seq_printf(seq, "%d\n", slot_id);
70 return 0;
71}
Cyrill Gorcunova4e32b52007-10-02 13:30:05 -070072
Cyrill Gorcunov3049ea72007-10-02 13:30:09 -070073static int hdpu_chassis_id_open(struct inode *inode, struct file *file)
74{
75 return single_open(file, hdpu_chassis_id_read, NULL);
76}
77
78static int hdpu_chassis_id_read(struct seq_file *seq, void *offset)
79{
80 seq_printf(seq, "%d\n", chassis_id);
81 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070082}
83
Russell King3ae5eae2005-11-09 22:32:44 +000084static int hdpu_nexus_probe(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070085{
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 struct resource *res;
Cyrill Gorcunova4e32b52007-10-02 13:30:05 -070087 int *nexus_id_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
89 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Cyrill Gorcunov7472fd32007-10-02 13:30:06 -070090 if (!res) {
91 printk(KERN_ERR "sky_nexus: "
92 "Invalid memory resource.\n");
93 return -EINVAL;
94 }
Cyrill Gorcunova4e32b52007-10-02 13:30:05 -070095 nexus_id_addr = ioremap(res->start,
96 (unsigned long)(res->end - res->start));
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 if (nexus_id_addr) {
98 slot_id = (*nexus_id_addr >> 8) & 0x1f;
99 chassis_id = *nexus_id_addr & 0xff;
100 iounmap(nexus_id_addr);
Cyrill Gorcunova4e32b52007-10-02 13:30:05 -0700101 } else {
Cyrill Gorcunov7472fd32007-10-02 13:30:06 -0700102 printk(KERN_ERR "sky_nexus: Could not map slot id\n");
Cyrill Gorcunova4e32b52007-10-02 13:30:05 -0700103 }
104
Denis V. Lunevc7705f32008-04-29 01:02:35 -0700105 hdpu_slot_id = proc_create("sky_slot_id", 0666, NULL, &proc_slot_id);
106 if (!hdpu_slot_id) {
Cyrill Gorcunov5f725fe2007-10-02 13:30:07 -0700107 printk(KERN_WARNING "sky_nexus: "
108 "Unable to create proc dir entry: sky_slot_id\n");
Cyrill Gorcunov5f725fe2007-10-02 13:30:07 -0700109 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
Denis V. Lunevc7705f32008-04-29 01:02:35 -0700111 hdpu_chassis_id = proc_create("sky_chassis_id", 0666, NULL,
112 &proc_chassis_id);
Alexey Dobriyanc74c1202008-04-29 01:01:44 -0700113 if (!hdpu_chassis_id)
Cyrill Gorcunov5f725fe2007-10-02 13:30:07 -0700114 printk(KERN_WARNING "sky_nexus: "
115 "Unable to create proc dir entry: sky_chassis_id\n");
Cyrill Gorcunova4e32b52007-10-02 13:30:05 -0700116
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 return 0;
118}
119
Russell King3ae5eae2005-11-09 22:32:44 +0000120static int hdpu_nexus_remove(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121{
122 slot_id = -1;
123 chassis_id = -1;
Cyrill Gorcunova4e32b52007-10-02 13:30:05 -0700124
Alexey Dobriyanc74c1202008-04-29 01:01:44 -0700125 remove_proc_entry("sky_slot_id", NULL);
126 remove_proc_entry("sky_chassis_id", NULL);
Cyrill Gorcunova4e32b52007-10-02 13:30:05 -0700127
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 hdpu_slot_id = 0;
129 hdpu_chassis_id = 0;
Cyrill Gorcunova4e32b52007-10-02 13:30:05 -0700130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 return 0;
132}
133
134static int __init nexus_init(void)
135{
Cyrill Gorcunova4e32b52007-10-02 13:30:05 -0700136 return platform_driver_register(&hdpu_nexus_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137}
138
139static void __exit nexus_exit(void)
140{
Russell King3ae5eae2005-11-09 22:32:44 +0000141 platform_driver_unregister(&hdpu_nexus_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142}
143
144module_init(nexus_init);
145module_exit(nexus_exit);
146
147MODULE_AUTHOR("Brian Waite");
148MODULE_LICENSE("GPL");
Kay Sieversd6c23852008-04-15 14:34:33 -0700149MODULE_ALIAS("platform:" HDPU_NEXUS_NAME);