blob: e5bd4470a570a4d45fcd7ef97d6a93c0a90aa601 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -08002 * TURBOchannel bus services.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -08004 * Copyright (c) Harald Koerfgen, 1998
5 * Copyright (c) 2001, 2003, 2005, 2006 Maciej W. Rozycki
6 * Copyright (c) 2005 James Simmons
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 *
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -08008 * 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.
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 */
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -080012#include <linux/compiler.h>
13#include <linux/errno.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/init.h>
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -080015#include <linux/ioport.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/kernel.h>
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -080017#include <linux/list.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <linux/module.h>
Maciej W. Rozyckia5fc9c02005-07-01 16:10:40 +000019#include <linux/string.h>
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -080020#include <linux/tc.h>
Maciej W. Rozyckia5fc9c02005-07-01 16:10:40 +000021#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
Maciej W. Rozyckia5fc9c02005-07-01 16:10:40 +000023#include <asm/io.h>
Maciej W. Rozyckia5fc9c02005-07-01 16:10:40 +000024
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -080025static struct tc_bus tc_bus = {
26 .name = "TURBOchannel",
27};
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Linus Torvalds1da177e2005-04-16 15:20:36 -070029/*
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -080030 * Probing for TURBOchannel modules.
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 */
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -080032static void __init tc_bus_add_devices(struct tc_bus *tbus)
Linus Torvalds1da177e2005-04-16 15:20:36 -070033{
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -080034 resource_size_t slotsize = tbus->info.slot_size << 20;
35 resource_size_t extslotsize = tbus->ext_slot_size;
36 resource_size_t slotaddr;
37 resource_size_t extslotaddr;
38 resource_size_t devsize;
39 void __iomem *module;
40 struct tc_dev *tdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 int i, slot, err;
Maciej W. Rozyckia5fc9c02005-07-01 16:10:40 +000042 u8 pattern[4];
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -080043 long offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -080045 for (slot = 0; slot < tbus->num_tcslots; slot++) {
46 slotaddr = tbus->slot_base + slot * slotsize;
47 extslotaddr = tbus->ext_slot_base + slot * extslotsize;
48 module = ioremap_nocache(slotaddr, slotsize);
Maciej W. Rozyckia5fc9c02005-07-01 16:10:40 +000049 BUG_ON(!module);
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -080051 offset = TC_OLDCARD;
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53 err = 0;
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -080054 err |= tc_preadb(pattern + 0, module + offset + TC_PATTERN0);
55 err |= tc_preadb(pattern + 1, module + offset + TC_PATTERN1);
56 err |= tc_preadb(pattern + 2, module + offset + TC_PATTERN2);
57 err |= tc_preadb(pattern + 3, module + offset + TC_PATTERN3);
58 if (err)
59 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
61 if (pattern[0] != 0x55 || pattern[1] != 0x00 ||
62 pattern[2] != 0xaa || pattern[3] != 0xff) {
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -080063 offset = TC_NEWCARD;
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
65 err = 0;
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -080066 err |= tc_preadb(pattern + 0,
67 module + offset + TC_PATTERN0);
68 err |= tc_preadb(pattern + 1,
69 module + offset + TC_PATTERN1);
70 err |= tc_preadb(pattern + 2,
71 module + offset + TC_PATTERN2);
72 err |= tc_preadb(pattern + 3,
73 module + offset + TC_PATTERN3);
74 if (err)
75 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 }
77
78 if (pattern[0] != 0x55 || pattern[1] != 0x00 ||
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -080079 pattern[2] != 0xaa || pattern[3] != 0xff)
80 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -080082 /* 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;
88 }
Kay Sieversdf388552009-03-24 16:38:22 -070089 dev_set_name(&tdev->dev, "tc%x", slot);
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -080090 tdev->bus = tbus;
91 tdev->dev.parent = &tbus->dev;
92 tdev->dev.bus = &tc_bus_type;
93 tdev->slot = slot;
94
Maciej W. Rozyckia5fc9c02005-07-01 16:10:40 +000095 for (i = 0; i < 8; i++) {
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -080096 tdev->firmware[i] =
97 readb(module + offset + TC_FIRM_VER + 4 * i);
98 tdev->vendor[i] =
99 readb(module + offset + TC_VENDOR + 4 * i);
100 tdev->name[i] =
101 readb(module + offset + TC_MODULE + 4 * i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 }
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -0800103 tdev->firmware[8] = 0;
104 tdev->vendor[8] = 0;
105 tdev->name[8] = 0;
Maciej W. Rozyckia5fc9c02005-07-01 16:10:40 +0000106
Kay Sieversdf388552009-03-24 16:38:22 -0700107 pr_info("%s: %s %s %s\n", dev_name(&tdev->dev), tdev->vendor,
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -0800108 tdev->name, tdev->firmware);
109
110 devsize = readb(module + offset + TC_SLOT_SIZE);
111 devsize <<= 22;
112 if (devsize <= slotsize) {
113 tdev->resource.start = slotaddr;
114 tdev->resource.end = slotaddr + devsize - 1;
115 } else if (devsize <= extslotsize) {
116 tdev->resource.start = extslotaddr;
117 tdev->resource.end = extslotaddr + devsize - 1;
118 } else {
119 printk(KERN_ERR "%s: Cannot provide slot space "
120 "(%dMiB required, up to %dMiB supported)\n",
Kay Sieversdf388552009-03-24 16:38:22 -0700121 dev_name(&tdev->dev), devsize >> 20,
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -0800122 max(slotsize, extslotsize) >> 20);
123 kfree(tdev);
124 goto out_err;
125 }
126 tdev->resource.name = tdev->name;
127 tdev->resource.flags = IORESOURCE_MEM;
128
129 tc_device_get_irq(tdev);
130
131 device_register(&tdev->dev);
132 list_add_tail(&tdev->node, &tbus->devices);
133
134out_err:
Maciej W. Rozyckia5fc9c02005-07-01 16:10:40 +0000135 iounmap(module);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 }
137}
138
139/*
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -0800140 * The main entry.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 */
Maciej W. Rozycki778220f2005-06-16 20:37:40 +0000142static int __init tc_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143{
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -0800144 /* Initialize the TURBOchannel bus */
145 if (tc_bus_get_info(&tc_bus))
Maciej W. Rozycki778220f2005-06-16 20:37:40 +0000146 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -0800148 INIT_LIST_HEAD(&tc_bus.devices);
Kay Sieversdf388552009-03-24 16:38:22 -0700149 dev_set_name(&tc_bus.dev, "tc");
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -0800150 device_register(&tc_bus.dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -0800152 if (tc_bus.info.slot_size) {
153 unsigned int tc_clock = tc_get_speed(&tc_bus) / 100000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -0800155 pr_info("tc: TURBOchannel rev. %d at %d.%d MHz "
156 "(with%s parity)\n", tc_bus.info.revision,
157 tc_clock / 10, tc_clock % 10,
158 tc_bus.info.parity ? "" : "out");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -0800160 tc_bus.resource[0].start = tc_bus.slot_base;
161 tc_bus.resource[0].end = tc_bus.slot_base +
162 (tc_bus.info.slot_size << 20) *
Maciej W. Rozycki56a47da2007-02-05 16:28:26 -0800163 tc_bus.num_tcslots - 1;
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -0800164 tc_bus.resource[0].name = tc_bus.name;
165 tc_bus.resource[0].flags = IORESOURCE_MEM;
166 if (request_resource(&iomem_resource,
167 &tc_bus.resource[0]) < 0) {
168 printk(KERN_ERR "tc: Cannot reserve resource\n");
169 return 0;
Maciej W. Rozyckia5fc9c02005-07-01 16:10:40 +0000170 }
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -0800171 if (tc_bus.ext_slot_size) {
172 tc_bus.resource[1].start = tc_bus.ext_slot_base;
173 tc_bus.resource[1].end = tc_bus.ext_slot_base +
174 tc_bus.ext_slot_size *
Maciej W. Rozycki56a47da2007-02-05 16:28:26 -0800175 tc_bus.num_tcslots - 1;
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -0800176 tc_bus.resource[1].name = tc_bus.name;
177 tc_bus.resource[1].flags = IORESOURCE_MEM;
178 if (request_resource(&iomem_resource,
179 &tc_bus.resource[1]) < 0) {
180 printk(KERN_ERR
181 "tc: Cannot reserve resource\n");
182 release_resource(&tc_bus.resource[0]);
183 return 0;
184 }
185 }
186
187 tc_bus_add_devices(&tc_bus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 }
Maciej W. Rozycki778220f2005-06-16 20:37:40 +0000189
190 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191}
192
193subsys_initcall(tc_init);