Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
[linux-btrfs-devel.git] / drivers / tc / tc.c
bloba8aaf6ac2ae2275e2071dc53c174d0543db64dd8
1 /*
2 * TURBOchannel bus services.
4 * Copyright (c) Harald Koerfgen, 1998
5 * Copyright (c) 2001, 2003, 2005, 2006 Maciej W. Rozycki
6 * Copyright (c) 2005 James Simmons
8 * This file is subject to the terms and conditions of the GNU
9 * General Public License. See the file "COPYING" in the main
10 * directory of this archive for more details.
12 #include <linux/compiler.h>
13 #include <linux/errno.h>
14 #include <linux/init.h>
15 #include <linux/ioport.h>
16 #include <linux/kernel.h>
17 #include <linux/list.h>
18 #include <linux/module.h>
19 #include <linux/slab.h>
20 #include <linux/string.h>
21 #include <linux/tc.h>
22 #include <linux/types.h>
24 #include <asm/io.h>
26 static struct tc_bus tc_bus = {
27 .name = "TURBOchannel",
31 * Probing for TURBOchannel modules.
33 static void __init tc_bus_add_devices(struct tc_bus *tbus)
35 resource_size_t slotsize = tbus->info.slot_size << 20;
36 resource_size_t extslotsize = tbus->ext_slot_size;
37 resource_size_t slotaddr;
38 resource_size_t extslotaddr;
39 resource_size_t devsize;
40 void __iomem *module;
41 struct tc_dev *tdev;
42 int i, slot, err;
43 u8 pattern[4];
44 long offset;
46 for (slot = 0; slot < tbus->num_tcslots; slot++) {
47 slotaddr = tbus->slot_base + slot * slotsize;
48 extslotaddr = tbus->ext_slot_base + slot * extslotsize;
49 module = ioremap_nocache(slotaddr, slotsize);
50 BUG_ON(!module);
52 offset = TC_OLDCARD;
54 err = 0;
55 err |= tc_preadb(pattern + 0, module + offset + TC_PATTERN0);
56 err |= tc_preadb(pattern + 1, module + offset + TC_PATTERN1);
57 err |= tc_preadb(pattern + 2, module + offset + TC_PATTERN2);
58 err |= tc_preadb(pattern + 3, module + offset + TC_PATTERN3);
59 if (err)
60 goto out_err;
62 if (pattern[0] != 0x55 || pattern[1] != 0x00 ||
63 pattern[2] != 0xaa || pattern[3] != 0xff) {
64 offset = TC_NEWCARD;
66 err = 0;
67 err |= tc_preadb(pattern + 0,
68 module + offset + TC_PATTERN0);
69 err |= tc_preadb(pattern + 1,
70 module + offset + TC_PATTERN1);
71 err |= tc_preadb(pattern + 2,
72 module + offset + TC_PATTERN2);
73 err |= tc_preadb(pattern + 3,
74 module + offset + TC_PATTERN3);
75 if (err)
76 goto out_err;
79 if (pattern[0] != 0x55 || pattern[1] != 0x00 ||
80 pattern[2] != 0xaa || pattern[3] != 0xff)
81 goto out_err;
83 /* Found a board, allocate it an entry in the list */
84 tdev = kzalloc(sizeof(*tdev), GFP_KERNEL);
85 if (!tdev) {
86 printk(KERN_ERR "tc%x: unable to allocate tc_dev\n",
87 slot);
88 goto out_err;
90 dev_set_name(&tdev->dev, "tc%x", slot);
91 tdev->bus = tbus;
92 tdev->dev.parent = &tbus->dev;
93 tdev->dev.bus = &tc_bus_type;
94 tdev->slot = slot;
96 for (i = 0; i < 8; i++) {
97 tdev->firmware[i] =
98 readb(module + offset + TC_FIRM_VER + 4 * i);
99 tdev->vendor[i] =
100 readb(module + offset + TC_VENDOR + 4 * i);
101 tdev->name[i] =
102 readb(module + offset + TC_MODULE + 4 * i);
104 tdev->firmware[8] = 0;
105 tdev->vendor[8] = 0;
106 tdev->name[8] = 0;
108 pr_info("%s: %s %s %s\n", dev_name(&tdev->dev), tdev->vendor,
109 tdev->name, tdev->firmware);
111 devsize = readb(module + offset + TC_SLOT_SIZE);
112 devsize <<= 22;
113 if (devsize <= slotsize) {
114 tdev->resource.start = slotaddr;
115 tdev->resource.end = slotaddr + devsize - 1;
116 } else if (devsize <= extslotsize) {
117 tdev->resource.start = extslotaddr;
118 tdev->resource.end = extslotaddr + devsize - 1;
119 } else {
120 printk(KERN_ERR "%s: Cannot provide slot space "
121 "(%dMiB required, up to %dMiB supported)\n",
122 dev_name(&tdev->dev), devsize >> 20,
123 max(slotsize, extslotsize) >> 20);
124 kfree(tdev);
125 goto out_err;
127 tdev->resource.name = tdev->name;
128 tdev->resource.flags = IORESOURCE_MEM;
130 tc_device_get_irq(tdev);
132 device_register(&tdev->dev);
133 list_add_tail(&tdev->node, &tbus->devices);
135 out_err:
136 iounmap(module);
141 * The main entry.
143 static int __init tc_init(void)
145 /* Initialize the TURBOchannel bus */
146 if (tc_bus_get_info(&tc_bus))
147 return 0;
149 INIT_LIST_HEAD(&tc_bus.devices);
150 dev_set_name(&tc_bus.dev, "tc");
151 device_register(&tc_bus.dev);
153 if (tc_bus.info.slot_size) {
154 unsigned int tc_clock = tc_get_speed(&tc_bus) / 100000;
156 pr_info("tc: TURBOchannel rev. %d at %d.%d MHz "
157 "(with%s parity)\n", tc_bus.info.revision,
158 tc_clock / 10, tc_clock % 10,
159 tc_bus.info.parity ? "" : "out");
161 tc_bus.resource[0].start = tc_bus.slot_base;
162 tc_bus.resource[0].end = tc_bus.slot_base +
163 (tc_bus.info.slot_size << 20) *
164 tc_bus.num_tcslots - 1;
165 tc_bus.resource[0].name = tc_bus.name;
166 tc_bus.resource[0].flags = IORESOURCE_MEM;
167 if (request_resource(&iomem_resource,
168 &tc_bus.resource[0]) < 0) {
169 printk(KERN_ERR "tc: Cannot reserve resource\n");
170 return 0;
172 if (tc_bus.ext_slot_size) {
173 tc_bus.resource[1].start = tc_bus.ext_slot_base;
174 tc_bus.resource[1].end = tc_bus.ext_slot_base +
175 tc_bus.ext_slot_size *
176 tc_bus.num_tcslots - 1;
177 tc_bus.resource[1].name = tc_bus.name;
178 tc_bus.resource[1].flags = IORESOURCE_MEM;
179 if (request_resource(&iomem_resource,
180 &tc_bus.resource[1]) < 0) {
181 printk(KERN_ERR
182 "tc: Cannot reserve resource\n");
183 release_resource(&tc_bus.resource[0]);
184 return 0;
188 tc_bus_add_devices(&tc_bus);
191 return 0;
194 subsys_initcall(tc_init);