blob: 946562389ca80fe07040536c108fdaa5d8bb59df [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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090019#include <linux/slab.h>
Maciej W. Rozyckia5fc9c02005-07-01 16:10:40 +000020#include <linux/string.h>
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -080021#include <linux/tc.h>
Maciej W. Rozyckia5fc9c02005-07-01 16:10:40 +000022#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
Maciej W. Rozyckia5fc9c02005-07-01 16:10:40 +000024#include <asm/io.h>
Maciej W. Rozyckia5fc9c02005-07-01 16:10:40 +000025
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -080026static struct tc_bus tc_bus = {
27 .name = "TURBOchannel",
28};
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
Linus Torvalds1da177e2005-04-16 15:20:36 -070030/*
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -080031 * Probing for TURBOchannel modules.
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 */
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -080033static void __init tc_bus_add_devices(struct tc_bus *tbus)
Linus Torvalds1da177e2005-04-16 15:20:36 -070034{
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -080035 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 int i, slot, err;
Maciej W. Rozyckia5fc9c02005-07-01 16:10:40 +000043 u8 pattern[4];
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -080044 long offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -080046 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);
Maciej W. Rozyckia5fc9c02005-07-01 16:10:40 +000050 BUG_ON(!module);
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -080052 offset = TC_OLDCARD;
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54 err = 0;
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -080055 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
62 if (pattern[0] != 0x55 || pattern[1] != 0x00 ||
63 pattern[2] != 0xaa || pattern[3] != 0xff) {
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -080064 offset = TC_NEWCARD;
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
66 err = 0;
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -080067 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 }
78
79 if (pattern[0] != 0x55 || pattern[1] != 0x00 ||
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -080080 pattern[2] != 0xaa || pattern[3] != 0xff)
81 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -080083 /* 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;
89 }
Kay Sieversdf388552009-03-24 16:38:22 -070090 dev_set_name(&tdev->dev, "tc%x", slot);
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -080091 tdev->bus = tbus;
92 tdev->dev.parent = &tbus->dev;
93 tdev->dev.bus = &tc_bus_type;
94 tdev->slot = slot;
95
Maciej W. Rozyckia5fc9c02005-07-01 16:10:40 +000096 for (i = 0; i < 8; i++) {
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -080097 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 }
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -0800104 tdev->firmware[8] = 0;
105 tdev->vendor[8] = 0;
106 tdev->name[8] = 0;
Maciej W. Rozyckia5fc9c02005-07-01 16:10:40 +0000107
Kay Sieversdf388552009-03-24 16:38:22 -0700108 pr_info("%s: %s %s %s\n", dev_name(&tdev->dev), tdev->vendor,
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -0800109 tdev->name, tdev->firmware);
110
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",
Kay Sieversdf388552009-03-24 16:38:22 -0700122 dev_name(&tdev->dev), devsize >> 20,
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -0800123 max(slotsize, extslotsize) >> 20);
124 kfree(tdev);
125 goto out_err;
126 }
127 tdev->resource.name = tdev->name;
128 tdev->resource.flags = IORESOURCE_MEM;
129
130 tc_device_get_irq(tdev);
131
Levente Kurusa5bb78892014-04-02 12:00:37 +0200132 if (device_register(&tdev->dev)) {
133 put_device(&tdev->dev);
134 goto out_err;
135 }
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -0800136 list_add_tail(&tdev->node, &tbus->devices);
137
138out_err:
Maciej W. Rozyckia5fc9c02005-07-01 16:10:40 +0000139 iounmap(module);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 }
141}
142
143/*
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -0800144 * The main entry.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 */
Maciej W. Rozycki778220f2005-06-16 20:37:40 +0000146static int __init tc_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147{
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -0800148 /* Initialize the TURBOchannel bus */
149 if (tc_bus_get_info(&tc_bus))
Maciej W. Rozycki778220f2005-06-16 20:37:40 +0000150 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -0800152 INIT_LIST_HEAD(&tc_bus.devices);
Kay Sieversdf388552009-03-24 16:38:22 -0700153 dev_set_name(&tc_bus.dev, "tc");
Levente Kurusa5bb78892014-04-02 12:00:37 +0200154 if (device_register(&tc_bus.dev)) {
155 put_device(&tc_bus.dev);
156 return 0;
157 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -0800159 if (tc_bus.info.slot_size) {
160 unsigned int tc_clock = tc_get_speed(&tc_bus) / 100000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -0800162 pr_info("tc: TURBOchannel rev. %d at %d.%d MHz "
163 "(with%s parity)\n", tc_bus.info.revision,
164 tc_clock / 10, tc_clock % 10,
165 tc_bus.info.parity ? "" : "out");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -0800167 tc_bus.resource[0].start = tc_bus.slot_base;
168 tc_bus.resource[0].end = tc_bus.slot_base +
169 (tc_bus.info.slot_size << 20) *
Maciej W. Rozycki56a47da2007-02-05 16:28:26 -0800170 tc_bus.num_tcslots - 1;
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -0800171 tc_bus.resource[0].name = tc_bus.name;
172 tc_bus.resource[0].flags = IORESOURCE_MEM;
173 if (request_resource(&iomem_resource,
174 &tc_bus.resource[0]) < 0) {
175 printk(KERN_ERR "tc: Cannot reserve resource\n");
176 return 0;
Maciej W. Rozyckia5fc9c02005-07-01 16:10:40 +0000177 }
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -0800178 if (tc_bus.ext_slot_size) {
179 tc_bus.resource[1].start = tc_bus.ext_slot_base;
180 tc_bus.resource[1].end = tc_bus.ext_slot_base +
181 tc_bus.ext_slot_size *
Maciej W. Rozycki56a47da2007-02-05 16:28:26 -0800182 tc_bus.num_tcslots - 1;
Maciej W. Rozyckib454cc62007-02-05 16:28:25 -0800183 tc_bus.resource[1].name = tc_bus.name;
184 tc_bus.resource[1].flags = IORESOURCE_MEM;
185 if (request_resource(&iomem_resource,
186 &tc_bus.resource[1]) < 0) {
187 printk(KERN_ERR
188 "tc: Cannot reserve resource\n");
189 release_resource(&tc_bus.resource[0]);
190 return 0;
191 }
192 }
193
194 tc_bus_add_devices(&tc_bus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 }
Maciej W. Rozycki778220f2005-06-16 20:37:40 +0000196
197 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198}
199
200subsys_initcall(tc_init);