Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/module.h> |
| 18 | #include <linux/kernel.h> |
| 19 | #include <linux/proc_fs.h> |
| 20 | #include <linux/hdpu_features.h> |
Russell King | d052d1b | 2005-10-29 19:07:23 +0100 | [diff] [blame] | 21 | #include <linux/platform_device.h> |
Cyrill Gorcunov | 3049ea7 | 2007-10-02 13:30:09 -0700 | [diff] [blame] | 22 | #include <linux/seq_file.h> |
Cyrill Gorcunov | d2ceb47 | 2007-10-02 13:30:06 -0700 | [diff] [blame] | 23 | #include <asm/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 25 | static int hdpu_nexus_probe(struct platform_device *pdev); |
| 26 | static int hdpu_nexus_remove(struct platform_device *pdev); |
Cyrill Gorcunov | 3049ea7 | 2007-10-02 13:30:09 -0700 | [diff] [blame] | 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); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
| 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; |
| 36 | |
Cyrill Gorcunov | 3049ea7 | 2007-10-02 13:30:09 -0700 | [diff] [blame] | 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 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 53 | static struct platform_driver hdpu_nexus_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | .probe = hdpu_nexus_probe, |
| 55 | .remove = hdpu_nexus_remove, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 56 | .driver = { |
| 57 | .name = HDPU_NEXUS_NAME, |
| 58 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | }; |
| 60 | |
Cyrill Gorcunov | 3049ea7 | 2007-10-02 13:30:09 -0700 | [diff] [blame] | 61 | static int hdpu_slot_id_open(struct inode *inode, struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | { |
Cyrill Gorcunov | 3049ea7 | 2007-10-02 13:30:09 -0700 | [diff] [blame] | 63 | return single_open(file, hdpu_slot_id_read, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | } |
| 65 | |
Cyrill Gorcunov | 3049ea7 | 2007-10-02 13:30:09 -0700 | [diff] [blame] | 66 | static int hdpu_slot_id_read(struct seq_file *seq, void *offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | { |
Cyrill Gorcunov | 3049ea7 | 2007-10-02 13:30:09 -0700 | [diff] [blame] | 68 | seq_printf(seq, "%d\n", slot_id); |
| 69 | return 0; |
| 70 | } |
Cyrill Gorcunov | a4e32b5 | 2007-10-02 13:30:05 -0700 | [diff] [blame] | 71 | |
Cyrill Gorcunov | 3049ea7 | 2007-10-02 13:30:09 -0700 | [diff] [blame] | 72 | static int hdpu_chassis_id_open(struct inode *inode, struct file *file) |
| 73 | { |
| 74 | return single_open(file, hdpu_chassis_id_read, NULL); |
| 75 | } |
| 76 | |
| 77 | static int hdpu_chassis_id_read(struct seq_file *seq, void *offset) |
| 78 | { |
| 79 | seq_printf(seq, "%d\n", chassis_id); |
| 80 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | } |
| 82 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 83 | static int hdpu_nexus_probe(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | struct resource *res; |
Cyrill Gorcunov | a4e32b5 | 2007-10-02 13:30:05 -0700 | [diff] [blame] | 86 | int *nexus_id_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | |
| 88 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Cyrill Gorcunov | 7472fd3 | 2007-10-02 13:30:06 -0700 | [diff] [blame] | 89 | if (!res) { |
| 90 | printk(KERN_ERR "sky_nexus: " |
| 91 | "Invalid memory resource.\n"); |
| 92 | return -EINVAL; |
| 93 | } |
Cyrill Gorcunov | a4e32b5 | 2007-10-02 13:30:05 -0700 | [diff] [blame] | 94 | nexus_id_addr = ioremap(res->start, |
| 95 | (unsigned long)(res->end - res->start)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | 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 Gorcunov | a4e32b5 | 2007-10-02 13:30:05 -0700 | [diff] [blame] | 100 | } else { |
Cyrill Gorcunov | 7472fd3 | 2007-10-02 13:30:06 -0700 | [diff] [blame] | 101 | printk(KERN_ERR "sky_nexus: Could not map slot id\n"); |
Cyrill Gorcunov | a4e32b5 | 2007-10-02 13:30:05 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | hdpu_slot_id = create_proc_entry("sky_slot_id", 0666, &proc_root); |
Cyrill Gorcunov | 5f725fe | 2007-10-02 13:30:07 -0700 | [diff] [blame] | 105 | if (!hdpu_slot_id) { |
| 106 | printk(KERN_WARNING "sky_nexus: " |
| 107 | "Unable to create proc dir entry: sky_slot_id\n"); |
| 108 | } else { |
Cyrill Gorcunov | 3049ea7 | 2007-10-02 13:30:09 -0700 | [diff] [blame] | 109 | hdpu_slot_id->proc_fops = &proc_slot_id; |
| 110 | hdpu_slot_id->owner = THIS_MODULE; |
Cyrill Gorcunov | 5f725fe | 2007-10-02 13:30:07 -0700 | [diff] [blame] | 111 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | |
| 113 | hdpu_chassis_id = create_proc_entry("sky_chassis_id", 0666, &proc_root); |
Cyrill Gorcunov | 5f725fe | 2007-10-02 13:30:07 -0700 | [diff] [blame] | 114 | if (!hdpu_chassis_id) { |
| 115 | printk(KERN_WARNING "sky_nexus: " |
| 116 | "Unable to create proc dir entry: sky_chassis_id\n"); |
| 117 | } else { |
Cyrill Gorcunov | 3049ea7 | 2007-10-02 13:30:09 -0700 | [diff] [blame] | 118 | hdpu_chassis_id->proc_fops = &proc_chassis_id; |
| 119 | hdpu_chassis_id->owner = THIS_MODULE; |
Cyrill Gorcunov | 5f725fe | 2007-10-02 13:30:07 -0700 | [diff] [blame] | 120 | } |
Cyrill Gorcunov | a4e32b5 | 2007-10-02 13:30:05 -0700 | [diff] [blame] | 121 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | return 0; |
| 123 | } |
| 124 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 125 | static int hdpu_nexus_remove(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | { |
| 127 | slot_id = -1; |
| 128 | chassis_id = -1; |
Cyrill Gorcunov | a4e32b5 | 2007-10-02 13:30:05 -0700 | [diff] [blame] | 129 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | remove_proc_entry("sky_slot_id", &proc_root); |
| 131 | remove_proc_entry("sky_chassis_id", &proc_root); |
Cyrill Gorcunov | a4e32b5 | 2007-10-02 13:30:05 -0700 | [diff] [blame] | 132 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | hdpu_slot_id = 0; |
| 134 | hdpu_chassis_id = 0; |
Cyrill Gorcunov | a4e32b5 | 2007-10-02 13:30:05 -0700 | [diff] [blame] | 135 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | return 0; |
| 137 | } |
| 138 | |
| 139 | static int __init nexus_init(void) |
| 140 | { |
Cyrill Gorcunov | a4e32b5 | 2007-10-02 13:30:05 -0700 | [diff] [blame] | 141 | return platform_driver_register(&hdpu_nexus_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | static void __exit nexus_exit(void) |
| 145 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 146 | platform_driver_unregister(&hdpu_nexus_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | module_init(nexus_init); |
| 150 | module_exit(nexus_exit); |
| 151 | |
| 152 | MODULE_AUTHOR("Brian Waite"); |
| 153 | MODULE_LICENSE("GPL"); |