aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/tc
diff options
context:
space:
mode:
authorMaciej W. Rozycki <macro@linux-mips.org>2007-02-05 19:28:25 -0500
committerRalf Baechle <ralf@linux-mips.org>2007-02-09 11:23:15 -0500
commitb454cc6636d254fbf6049b73e9560aee76fb04a3 (patch)
tree5d3d0067ba49fa9e7bb2d6590db3ef8f3c1f499f /drivers/tc
parent5986a2ec35836a878350c54af4bd91b1de6abc59 (diff)
[TC] MIPS: TURBOchannel update to the driver model
This is a set of changes to convert support for the TURBOchannel bus to the driver model. It implements the usual set of calls similar to what other bus drivers have: tc_register_driver(), tc_unregister_driver(), etc. All the platform-specific bits have been removed and headers from asm-mips/dec/ have been merged into linux/tc.h, which should be included by drivers. Signed-off-by: Maciej W. Rozycki <macro@linux-mips.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Diffstat (limited to 'drivers/tc')
-rw-r--r--drivers/tc/Makefile2
-rw-r--r--drivers/tc/tc-driver.c110
-rw-r--r--drivers/tc/tc.c339
3 files changed, 250 insertions, 201 deletions
diff --git a/drivers/tc/Makefile b/drivers/tc/Makefile
index 83b5bd75ce26..967342692211 100644
--- a/drivers/tc/Makefile
+++ b/drivers/tc/Makefile
@@ -4,7 +4,7 @@
4 4
5# Object file lists. 5# Object file lists.
6 6
7obj-$(CONFIG_TC) += tc.o 7obj-$(CONFIG_TC) += tc.o tc-driver.o
8obj-$(CONFIG_ZS) += zs.o 8obj-$(CONFIG_ZS) += zs.o
9obj-$(CONFIG_VT) += lk201.o lk201-map.o lk201-remap.o 9obj-$(CONFIG_VT) += lk201.o lk201-map.o lk201-remap.o
10 10
diff --git a/drivers/tc/tc-driver.c b/drivers/tc/tc-driver.c
new file mode 100644
index 000000000000..16b5bae63c74
--- /dev/null
+++ b/drivers/tc/tc-driver.c
@@ -0,0 +1,110 @@
1/*
2 * TURBOchannel driver services.
3 *
4 * Copyright (c) 2005 James Simmons
5 * Copyright (c) 2006 Maciej W. Rozycki
6 *
7 * Loosely based on drivers/dio/dio-driver.c and
8 * drivers/pci/pci-driver.c.
9 *
10 * This file is subject to the terms and conditions of the GNU
11 * General Public License. See the file "COPYING" in the main
12 * directory of this archive for more details.
13 */
14
15#include <linux/init.h>
16#include <linux/module.h>
17#include <linux/tc.h>
18
19/**
20 * tc_register_driver - register a new TC driver
21 * @drv: the driver structure to register
22 *
23 * Adds the driver structure to the list of registered drivers
24 * Returns a negative value on error, otherwise 0.
25 * If no error occurred, the driver remains registered even if
26 * no device was claimed during registration.
27 */
28int tc_register_driver(struct tc_driver *tdrv)
29{
30 return driver_register(&tdrv->driver);
31}
32EXPORT_SYMBOL(tc_register_driver);
33
34/**
35 * tc_unregister_driver - unregister a TC driver
36 * @drv: the driver structure to unregister
37 *
38 * Deletes the driver structure from the list of registered TC drivers,
39 * gives it a chance to clean up by calling its remove() function for
40 * each device it was responsible for, and marks those devices as
41 * driverless.
42 */
43void tc_unregister_driver(struct tc_driver *tdrv)
44{
45 driver_unregister(&tdrv->driver);
46}
47EXPORT_SYMBOL(tc_unregister_driver);
48
49/**
50 * tc_match_device - tell if a TC device structure has a matching
51 * TC device ID structure
52 * @tdrv: the TC driver to earch for matching TC device ID strings
53 * @tdev: the TC device structure to match against
54 *
55 * Used by a driver to check whether a TC device present in the
56 * system is in its list of supported devices. Returns the matching
57 * tc_device_id structure or %NULL if there is no match.
58 */
59const struct tc_device_id *tc_match_device(struct tc_driver *tdrv,
60 struct tc_dev *tdev)
61{
62 const struct tc_device_id *id = tdrv->id_table;
63
64 if (id) {
65 while (id->name[0] || id->vendor[0]) {
66 if (strcmp(tdev->name, id->name) == 0 &&
67 strcmp(tdev->vendor, id->vendor) == 0)
68 return id;
69 id++;
70 }
71 }
72 return NULL;
73}
74EXPORT_SYMBOL(tc_match_device);
75
76/**
77 * tc_bus_match - Tell if a device structure has a matching
78 * TC device ID structure
79 * @dev: the device structure to match against
80 * @drv: the device driver to search for matching TC device ID strings
81 *
82 * Used by a driver to check whether a TC device present in the
83 * system is in its list of supported devices. Returns 1 if there
84 * is a match or 0 otherwise.
85 */
86static int tc_bus_match(struct device *dev, struct device_driver *drv)
87{
88 struct tc_dev *tdev = to_tc_dev(dev);
89 struct tc_driver *tdrv = to_tc_driver(drv);
90 const struct tc_device_id *id;
91
92 id = tc_match_device(tdrv, tdev);
93 if (id)
94 return 1;
95
96 return 0;
97}
98
99struct bus_type tc_bus_type = {
100 .name = "tc",
101 .match = tc_bus_match,
102};
103EXPORT_SYMBOL(tc_bus_type);
104
105static int __init tc_driver_init(void)
106{
107 return bus_register(&tc_bus_type);
108}
109
110postcore_initcall(tc_driver_init);
diff --git a/drivers/tc/tc.c b/drivers/tc/tc.c
index 4a51e56f85b6..5514e5283616 100644
--- a/drivers/tc/tc.c
+++ b/drivers/tc/tc.c
@@ -1,254 +1,193 @@
1/* 1/*
2 * tc-init: We assume the TURBOchannel to be up and running so 2 * TURBOchannel bus services.
3 * just probe for Modules and fill in the global data structure
4 * tc_bus.
5 * 3 *
6 * This file is subject to the terms and conditions of the GNU General Public 4 * Copyright (c) Harald Koerfgen, 1998
7 * License. See the file "COPYING" in the main directory of this archive 5 * Copyright (c) 2001, 2003, 2005, 2006 Maciej W. Rozycki
8 * for more details. 6 * Copyright (c) 2005 James Simmons
9 * 7 *
10 * Copyright (c) Harald Koerfgen, 1998 8 * This file is subject to the terms and conditions of the GNU
11 * Copyright (c) 2001, 2003, 2005 Maciej W. Rozycki 9 * General Public License. See the file "COPYING" in the main
10 * directory of this archive for more details.
12 */ 11 */
12#include <linux/compiler.h>
13#include <linux/errno.h>
13#include <linux/init.h> 14#include <linux/init.h>
15#include <linux/ioport.h>
14#include <linux/kernel.h> 16#include <linux/kernel.h>
17#include <linux/list.h>
15#include <linux/module.h> 18#include <linux/module.h>
16#include <linux/string.h> 19#include <linux/string.h>
20#include <linux/tc.h>
17#include <linux/types.h> 21#include <linux/types.h>
18 22
19#include <asm/addrspace.h>
20#include <asm/errno.h>
21#include <asm/io.h> 23#include <asm/io.h>
22#include <asm/paccess.h>
23 24
24#include <asm/dec/machtype.h> 25static struct tc_bus tc_bus = {
25#include <asm/dec/prom.h> 26 .name = "TURBOchannel",
26#include <asm/dec/tcinfo.h> 27};
27#include <asm/dec/tcmodule.h>
28#include <asm/dec/interrupts.h>
29
30MODULE_LICENSE("GPL");
31slot_info tc_bus[MAX_SLOT];
32static int num_tcslots;
33static tcinfo *info;
34 28
35/* 29/*
36 * Interface to the world. Read comment in include/asm-mips/tc.h. 30 * Probing for TURBOchannel modules.
37 */ 31 */
38 32static void __init tc_bus_add_devices(struct tc_bus *tbus)
39int search_tc_card(const char *name)
40{
41 int slot;
42 slot_info *sip;
43
44 for (slot = 0; slot < num_tcslots; slot++) {
45 sip = &tc_bus[slot];
46 if ((sip->flags & FREE) &&
47 (strncmp(sip->name, name, strlen(name)) == 0)) {
48 return slot;
49 }
50 }
51
52 return -ENODEV;
53}
54
55void claim_tc_card(int slot)
56{
57 if (tc_bus[slot].flags & IN_USE) {
58 printk("claim_tc_card: attempting to claim a card already in use\n");
59 return;
60 }
61 tc_bus[slot].flags &= ~FREE;
62 tc_bus[slot].flags |= IN_USE;
63}
64
65void release_tc_card(int slot)
66{ 33{
67 if (tc_bus[slot].flags & FREE) { 34 resource_size_t slotsize = tbus->info.slot_size << 20;
68 printk("release_tc_card: " 35 resource_size_t extslotsize = tbus->ext_slot_size;
69 "attempting to release a card already free\n"); 36 resource_size_t slotaddr;
70 return; 37 resource_size_t extslotaddr;
71 } 38 resource_size_t devsize;
72 tc_bus[slot].flags &= ~IN_USE; 39 void __iomem *module;
73 tc_bus[slot].flags |= FREE; 40 struct tc_dev *tdev;
74}
75
76unsigned long get_tc_base_addr(int slot)
77{
78 return tc_bus[slot].base_addr;
79}
80
81unsigned long get_tc_irq_nr(int slot)
82{
83 return tc_bus[slot].interrupt;
84}
85
86unsigned long get_tc_speed(void)
87{
88 return 100000 * (10000 / (unsigned long)info->clk_period);
89}
90
91/*
92 * Probing for TURBOchannel modules
93 */
94static void __init tc_probe(unsigned long startaddr, unsigned long size,
95 int slots)
96{
97 unsigned long slotaddr;
98 int i, slot, err; 41 int i, slot, err;
99 long offset;
100 u8 pattern[4]; 42 u8 pattern[4];
101 volatile u8 *module; 43 long offset;
102 44
103 for (slot = 0; slot < slots; slot++) { 45 for (slot = 0; slot < tbus->num_tcslots; slot++) {
104 slotaddr = startaddr + slot * size; 46 slotaddr = tbus->slot_base + slot * slotsize;
105 module = ioremap_nocache(slotaddr, size); 47 extslotaddr = tbus->ext_slot_base + slot * extslotsize;
48 module = ioremap_nocache(slotaddr, slotsize);
106 BUG_ON(!module); 49 BUG_ON(!module);
107 50
108 offset = OLDCARD; 51 offset = TC_OLDCARD;
109 52
110 err = 0; 53 err = 0;
111 err |= get_dbe(pattern[0], module + OLDCARD + TC_PATTERN0); 54 err |= tc_preadb(pattern + 0, module + offset + TC_PATTERN0);
112 err |= get_dbe(pattern[1], module + OLDCARD + TC_PATTERN1); 55 err |= tc_preadb(pattern + 1, module + offset + TC_PATTERN1);
113 err |= get_dbe(pattern[2], module + OLDCARD + TC_PATTERN2); 56 err |= tc_preadb(pattern + 2, module + offset + TC_PATTERN2);
114 err |= get_dbe(pattern[3], module + OLDCARD + TC_PATTERN3); 57 err |= tc_preadb(pattern + 3, module + offset + TC_PATTERN3);
115 if (err) { 58 if (err)
116 iounmap(module); 59 goto out_err;
117 continue;
118 }
119 60
120 if (pattern[0] != 0x55 || pattern[1] != 0x00 || 61 if (pattern[0] != 0x55 || pattern[1] != 0x00 ||
121 pattern[2] != 0xaa || pattern[3] != 0xff) { 62 pattern[2] != 0xaa || pattern[3] != 0xff) {
122 offset = NEWCARD; 63 offset = TC_NEWCARD;
123 64
124 err = 0; 65 err = 0;
125 err |= get_dbe(pattern[0], module + TC_PATTERN0); 66 err |= tc_preadb(pattern + 0,
126 err |= get_dbe(pattern[1], module + TC_PATTERN1); 67 module + offset + TC_PATTERN0);
127 err |= get_dbe(pattern[2], module + TC_PATTERN2); 68 err |= tc_preadb(pattern + 1,
128 err |= get_dbe(pattern[3], module + TC_PATTERN3); 69 module + offset + TC_PATTERN1);
129 if (err) { 70 err |= tc_preadb(pattern + 2,
130 iounmap(module); 71 module + offset + TC_PATTERN2);
131 continue; 72 err |= tc_preadb(pattern + 3,
132 } 73 module + offset + TC_PATTERN3);
74 if (err)
75 goto out_err;
133 } 76 }
134 77
135 if (pattern[0] != 0x55 || pattern[1] != 0x00 || 78 if (pattern[0] != 0x55 || pattern[1] != 0x00 ||
136 pattern[2] != 0xaa || pattern[3] != 0xff) { 79 pattern[2] != 0xaa || pattern[3] != 0xff)
137 iounmap(module); 80 goto out_err;
138 continue; 81
82 /* Found a board, allocate it an entry in the list */
83 tdev = kzalloc(sizeof(*tdev), GFP_KERNEL);
84 if (!tdev) {
85 printk(KERN_ERR "tc%x: unable to allocate tc_dev\n",
86 slot);
87 goto out_err;
139 } 88 }
89 sprintf(tdev->dev.bus_id, "tc%x", slot);
90 tdev->bus = tbus;
91 tdev->dev.parent = &tbus->dev;
92 tdev->dev.bus = &tc_bus_type;
93 tdev->slot = slot;
140 94
141 tc_bus[slot].base_addr = slotaddr;
142 for (i = 0; i < 8; i++) { 95 for (i = 0; i < 8; i++) {
143 tc_bus[slot].firmware[i] = 96 tdev->firmware[i] =
144 module[TC_FIRM_VER + offset + 4 * i]; 97 readb(module + offset + TC_FIRM_VER + 4 * i);
145 tc_bus[slot].vendor[i] = 98 tdev->vendor[i] =
146 module[TC_VENDOR + offset + 4 * i]; 99 readb(module + offset + TC_VENDOR + 4 * i);
147 tc_bus[slot].name[i] = 100 tdev->name[i] =
148 module[TC_MODULE + offset + 4 * i]; 101 readb(module + offset + TC_MODULE + 4 * i);
149 } 102 }
150 tc_bus[slot].firmware[8] = 0; 103 tdev->firmware[8] = 0;
151 tc_bus[slot].vendor[8] = 0; 104 tdev->vendor[8] = 0;
152 tc_bus[slot].name[8] = 0; 105 tdev->name[8] = 0;
153 /* 106
154 * Looks unneccesary, but we may change 107 pr_info("%s: %s %s %s\n", tdev->dev.bus_id, tdev->vendor,
155 * TC? in the future 108 tdev->name, tdev->firmware);
156 */ 109
157 switch (slot) { 110 devsize = readb(module + offset + TC_SLOT_SIZE);
158 case 0: 111 devsize <<= 22;
159 tc_bus[slot].interrupt = dec_interrupt[DEC_IRQ_TC0]; 112 if (devsize <= slotsize) {
160 break; 113 tdev->resource.start = slotaddr;
161 case 1: 114 tdev->resource.end = slotaddr + devsize - 1;
162 tc_bus[slot].interrupt = dec_interrupt[DEC_IRQ_TC1]; 115 } else if (devsize <= extslotsize) {
163 break; 116 tdev->resource.start = extslotaddr;
164 case 2: 117 tdev->resource.end = extslotaddr + devsize - 1;
165 tc_bus[slot].interrupt = dec_interrupt[DEC_IRQ_TC2]; 118 } else {
166 break; 119 printk(KERN_ERR "%s: Cannot provide slot space "
167 /* 120 "(%dMiB required, up to %dMiB supported)\n",
168 * Yuck! DS5000/200 onboard devices 121 tdev->dev.bus_id, devsize >> 20,
169 */ 122 max(slotsize, extslotsize) >> 20);
170 case 5: 123 kfree(tdev);
171 tc_bus[slot].interrupt = dec_interrupt[DEC_IRQ_TC5]; 124 goto out_err;
172 break;
173 case 6:
174 tc_bus[slot].interrupt = dec_interrupt[DEC_IRQ_TC6];
175 break;
176 default:
177 tc_bus[slot].interrupt = -1;
178 break;
179 } 125 }
126 tdev->resource.name = tdev->name;
127 tdev->resource.flags = IORESOURCE_MEM;
128
129 tc_device_get_irq(tdev);
180 130
131 device_register(&tdev->dev);
132 list_add_tail(&tdev->node, &tbus->devices);
133
134out_err:
181 iounmap(module); 135 iounmap(module);
182 } 136 }
183} 137}
184 138
185/* 139/*
186 * the main entry 140 * The main entry.
187 */ 141 */
188static int __init tc_init(void) 142static int __init tc_init(void)
189{ 143{
190 int tc_clock; 144 /* Initialize the TURBOchannel bus */
191 int i; 145 if (tc_bus_get_info(&tc_bus))
192 unsigned long slot0addr;
193 unsigned long slot_size;
194
195 if (!TURBOCHANNEL)
196 return 0; 146 return 0;
197 147
198 for (i = 0; i < MAX_SLOT; i++) { 148 INIT_LIST_HEAD(&tc_bus.devices);
199 tc_bus[i].base_addr = 0; 149 strcpy(tc_bus.dev.bus_id, "tc");
200 tc_bus[i].name[0] = 0; 150 device_register(&tc_bus.dev);
201 tc_bus[i].vendor[0] = 0; 151
202 tc_bus[i].firmware[0] = 0; 152 if (tc_bus.info.slot_size) {
203 tc_bus[i].interrupt = -1; 153 unsigned int tc_clock = tc_get_speed(&tc_bus) / 100000;
204 tc_bus[i].flags = FREE; 154
205 } 155 pr_info("tc: TURBOchannel rev. %d at %d.%d MHz "
206 156 "(with%s parity)\n", tc_bus.info.revision,
207 info = rex_gettcinfo(); 157 tc_clock / 10, tc_clock % 10,
208 slot0addr = CPHYSADDR((long)rex_slot_address(0)); 158 tc_bus.info.parity ? "" : "out");
209 159
210 switch (mips_machtype) { 160 tc_bus.resource[0].start = tc_bus.slot_base;
211 case MACH_DS5000_200: 161 tc_bus.resource[0].end = tc_bus.slot_base +
212 num_tcslots = 7; 162 (tc_bus.info.slot_size << 20) *
213 break; 163 tc_bus.num_tcslots;
214 case MACH_DS5000_1XX: 164 tc_bus.resource[0].name = tc_bus.name;
215 case MACH_DS5000_2X0: 165 tc_bus.resource[0].flags = IORESOURCE_MEM;
216 case MACH_DS5900: 166 if (request_resource(&iomem_resource,
217 num_tcslots = 3; 167 &tc_bus.resource[0]) < 0) {
218 break; 168 printk(KERN_ERR "tc: Cannot reserve resource\n");
219 case MACH_DS5000_XX: 169 return 0;
220 default: 170 }
221 num_tcslots = 2; 171 if (tc_bus.ext_slot_size) {
222 break; 172 tc_bus.resource[1].start = tc_bus.ext_slot_base;
223 } 173 tc_bus.resource[1].end = tc_bus.ext_slot_base +
224 174 tc_bus.ext_slot_size *
225 tc_clock = 10000 / info->clk_period; 175 tc_bus.num_tcslots;
226 176 tc_bus.resource[1].name = tc_bus.name;
227 if (info->slot_size && slot0addr) { 177 tc_bus.resource[1].flags = IORESOURCE_MEM;
228 pr_info("TURBOchannel rev. %d at %d.%d MHz (with%s parity)\n", 178 if (request_resource(&iomem_resource,
229 info->revision, tc_clock / 10, tc_clock % 10, 179 &tc_bus.resource[1]) < 0) {
230 info->parity ? "" : "out"); 180 printk(KERN_ERR
231 181 "tc: Cannot reserve resource\n");
232 slot_size = info->slot_size << 20; 182 release_resource(&tc_bus.resource[0]);
233 183 return 0;
234 tc_probe(slot0addr, slot_size, num_tcslots); 184 }
235
236 for (i = 0; i < num_tcslots; i++) {
237 if (!tc_bus[i].base_addr)
238 continue;
239 pr_info(" slot %d: %s %s %s\n", i, tc_bus[i].vendor,
240 tc_bus[i].name, tc_bus[i].firmware);
241 } 185 }
186
187 tc_bus_add_devices(&tc_bus);
242 } 188 }
243 189
244 return 0; 190 return 0;
245} 191}
246 192
247subsys_initcall(tc_init); 193subsys_initcall(tc_init);
248
249EXPORT_SYMBOL(search_tc_card);
250EXPORT_SYMBOL(claim_tc_card);
251EXPORT_SYMBOL(release_tc_card);
252EXPORT_SYMBOL(get_tc_base_addr);
253EXPORT_SYMBOL(get_tc_irq_nr);
254EXPORT_SYMBOL(get_tc_speed);