blob: 2887b21479800669f0af10b66e7dd79ddbdb0d19 [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 Gorcunovd2ceb472007-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,
58 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070059};
60
Cyrill Gorcunov3049ea72007-10-02 13:30:09 -070061static int hdpu_slot_id_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -070062{
Cyrill Gorcunov3049ea72007-10-02 13:30:09 -070063 return single_open(file, hdpu_slot_id_read, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064}
65
Cyrill Gorcunov3049ea72007-10-02 13:30:09 -070066static int hdpu_slot_id_read(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -070067{
Cyrill Gorcunov3049ea72007-10-02 13:30:09 -070068 seq_printf(seq, "%d\n", slot_id);
69 return 0;
70}
Cyrill Gorcunova4e32b52007-10-02 13:30:05 -070071
Cyrill Gorcunov3049ea72007-10-02 13:30:09 -070072static int hdpu_chassis_id_open(struct inode *inode, struct file *file)
73{
74 return single_open(file, hdpu_chassis_id_read, NULL);
75}
76
77static int hdpu_chassis_id_read(struct seq_file *seq, void *offset)
78{
79 seq_printf(seq, "%d\n", chassis_id);
80 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070081}
82
Russell King3ae5eae2005-11-09 22:32:44 +000083static int hdpu_nexus_probe(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070084{
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 struct resource *res;
Cyrill Gorcunova4e32b52007-10-02 13:30:05 -070086 int *nexus_id_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
88 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Cyrill Gorcunov7472fd32007-10-02 13:30:06 -070089 if (!res) {
90 printk(KERN_ERR "sky_nexus: "
91 "Invalid memory resource.\n");
92 return -EINVAL;
93 }
Cyrill Gorcunova4e32b52007-10-02 13:30:05 -070094 nexus_id_addr = ioremap(res->start,
95 (unsigned long)(res->end - res->start));
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 if (nexus_id_addr) {
97 slot_id = (*nexus_id_addr >> 8) & 0x1f;
98 chassis_id = *nexus_id_addr & 0xff;
99 iounmap(nexus_id_addr);
Cyrill Gorcunova4e32b52007-10-02 13:30:05 -0700100 } else {
Cyrill Gorcunov7472fd32007-10-02 13:30:06 -0700101 printk(KERN_ERR "sky_nexus: Could not map slot id\n");
Cyrill Gorcunova4e32b52007-10-02 13:30:05 -0700102 }
103
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 hdpu_slot_id = create_proc_entry("sky_slot_id", 0666, &proc_root);
Cyrill Gorcunov5f725fe2007-10-02 13:30:07 -0700105 if (!hdpu_slot_id) {
106 printk(KERN_WARNING "sky_nexus: "
107 "Unable to create proc dir entry: sky_slot_id\n");
108 } else {
Cyrill Gorcunov3049ea72007-10-02 13:30:09 -0700109 hdpu_slot_id->proc_fops = &proc_slot_id;
110 hdpu_slot_id->owner = THIS_MODULE;
Cyrill Gorcunov5f725fe2007-10-02 13:30:07 -0700111 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
113 hdpu_chassis_id = create_proc_entry("sky_chassis_id", 0666, &proc_root);
Cyrill Gorcunov5f725fe2007-10-02 13:30:07 -0700114 if (!hdpu_chassis_id) {
115 printk(KERN_WARNING "sky_nexus: "
116 "Unable to create proc dir entry: sky_chassis_id\n");
117 } else {
Cyrill Gorcunov3049ea72007-10-02 13:30:09 -0700118 hdpu_chassis_id->proc_fops = &proc_chassis_id;
119 hdpu_chassis_id->owner = THIS_MODULE;
Cyrill Gorcunov5f725fe2007-10-02 13:30:07 -0700120 }
Cyrill Gorcunova4e32b52007-10-02 13:30:05 -0700121
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 return 0;
123}
124
Russell King3ae5eae2005-11-09 22:32:44 +0000125static int hdpu_nexus_remove(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126{
127 slot_id = -1;
128 chassis_id = -1;
Cyrill Gorcunova4e32b52007-10-02 13:30:05 -0700129
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 remove_proc_entry("sky_slot_id", &proc_root);
131 remove_proc_entry("sky_chassis_id", &proc_root);
Cyrill Gorcunova4e32b52007-10-02 13:30:05 -0700132
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 hdpu_slot_id = 0;
134 hdpu_chassis_id = 0;
Cyrill Gorcunova4e32b52007-10-02 13:30:05 -0700135
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 return 0;
137}
138
139static int __init nexus_init(void)
140{
Cyrill Gorcunova4e32b52007-10-02 13:30:05 -0700141 return platform_driver_register(&hdpu_nexus_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142}
143
144static void __exit nexus_exit(void)
145{
Russell King3ae5eae2005-11-09 22:32:44 +0000146 platform_driver_unregister(&hdpu_nexus_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147}
148
149module_init(nexus_init);
150module_exit(nexus_exit);
151
152MODULE_AUTHOR("Brian Waite");
153MODULE_LICENSE("GPL");