Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Maciej W. Rozycki | b454cc6 | 2007-02-05 16:28:25 -0800 | [diff] [blame] | 2 | * TURBOchannel bus services. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
Maciej W. Rozycki | b454cc6 | 2007-02-05 16:28:25 -0800 | [diff] [blame] | 4 | * Copyright (c) Harald Koerfgen, 1998 |
Maciej W. Rozycki | b0b6284 | 2018-10-03 13:21:07 +0100 | [diff] [blame] | 5 | * Copyright (c) 2001, 2003, 2005, 2006, 2018 Maciej W. Rozycki |
Maciej W. Rozycki | b454cc6 | 2007-02-05 16:28:25 -0800 | [diff] [blame] | 6 | * Copyright (c) 2005 James Simmons |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * |
Maciej W. Rozycki | b454cc6 | 2007-02-05 16:28:25 -0800 | [diff] [blame] | 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. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | */ |
Maciej W. Rozycki | b454cc6 | 2007-02-05 16:28:25 -0800 | [diff] [blame] | 12 | #include <linux/compiler.h> |
Maciej W. Rozycki | b0b6284 | 2018-10-03 13:21:07 +0100 | [diff] [blame] | 13 | #include <linux/dma-mapping.h> |
Maciej W. Rozycki | b454cc6 | 2007-02-05 16:28:25 -0800 | [diff] [blame] | 14 | #include <linux/errno.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/init.h> |
Maciej W. Rozycki | b454cc6 | 2007-02-05 16:28:25 -0800 | [diff] [blame] | 16 | #include <linux/ioport.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/kernel.h> |
Maciej W. Rozycki | b454cc6 | 2007-02-05 16:28:25 -0800 | [diff] [blame] | 18 | #include <linux/list.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 20 | #include <linux/slab.h> |
Maciej W. Rozycki | a5fc9c0 | 2005-07-01 16:10:40 +0000 | [diff] [blame] | 21 | #include <linux/string.h> |
Maciej W. Rozycki | b454cc6 | 2007-02-05 16:28:25 -0800 | [diff] [blame] | 22 | #include <linux/tc.h> |
Maciej W. Rozycki | a5fc9c0 | 2005-07-01 16:10:40 +0000 | [diff] [blame] | 23 | #include <linux/types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | |
Maciej W. Rozycki | a5fc9c0 | 2005-07-01 16:10:40 +0000 | [diff] [blame] | 25 | #include <asm/io.h> |
Maciej W. Rozycki | a5fc9c0 | 2005-07-01 16:10:40 +0000 | [diff] [blame] | 26 | |
Maciej W. Rozycki | b454cc6 | 2007-02-05 16:28:25 -0800 | [diff] [blame] | 27 | static struct tc_bus tc_bus = { |
| 28 | .name = "TURBOchannel", |
| 29 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | /* |
Maciej W. Rozycki | b454cc6 | 2007-02-05 16:28:25 -0800 | [diff] [blame] | 32 | * Probing for TURBOchannel modules. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | */ |
Maciej W. Rozycki | b454cc6 | 2007-02-05 16:28:25 -0800 | [diff] [blame] | 34 | static void __init tc_bus_add_devices(struct tc_bus *tbus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | { |
Maciej W. Rozycki | b454cc6 | 2007-02-05 16:28:25 -0800 | [diff] [blame] | 36 | resource_size_t slotsize = tbus->info.slot_size << 20; |
| 37 | resource_size_t extslotsize = tbus->ext_slot_size; |
| 38 | resource_size_t slotaddr; |
| 39 | resource_size_t extslotaddr; |
| 40 | resource_size_t devsize; |
| 41 | void __iomem *module; |
| 42 | struct tc_dev *tdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | int i, slot, err; |
Maciej W. Rozycki | a5fc9c0 | 2005-07-01 16:10:40 +0000 | [diff] [blame] | 44 | u8 pattern[4]; |
Maciej W. Rozycki | b454cc6 | 2007-02-05 16:28:25 -0800 | [diff] [blame] | 45 | long offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
Maciej W. Rozycki | b454cc6 | 2007-02-05 16:28:25 -0800 | [diff] [blame] | 47 | for (slot = 0; slot < tbus->num_tcslots; slot++) { |
| 48 | slotaddr = tbus->slot_base + slot * slotsize; |
| 49 | extslotaddr = tbus->ext_slot_base + slot * extslotsize; |
| 50 | module = ioremap_nocache(slotaddr, slotsize); |
Maciej W. Rozycki | a5fc9c0 | 2005-07-01 16:10:40 +0000 | [diff] [blame] | 51 | BUG_ON(!module); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
Maciej W. Rozycki | b454cc6 | 2007-02-05 16:28:25 -0800 | [diff] [blame] | 53 | offset = TC_OLDCARD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
| 55 | err = 0; |
Maciej W. Rozycki | b454cc6 | 2007-02-05 16:28:25 -0800 | [diff] [blame] | 56 | err |= tc_preadb(pattern + 0, module + offset + TC_PATTERN0); |
| 57 | err |= tc_preadb(pattern + 1, module + offset + TC_PATTERN1); |
| 58 | err |= tc_preadb(pattern + 2, module + offset + TC_PATTERN2); |
| 59 | err |= tc_preadb(pattern + 3, module + offset + TC_PATTERN3); |
| 60 | if (err) |
| 61 | goto out_err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | |
| 63 | if (pattern[0] != 0x55 || pattern[1] != 0x00 || |
| 64 | pattern[2] != 0xaa || pattern[3] != 0xff) { |
Maciej W. Rozycki | b454cc6 | 2007-02-05 16:28:25 -0800 | [diff] [blame] | 65 | offset = TC_NEWCARD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
| 67 | err = 0; |
Maciej W. Rozycki | b454cc6 | 2007-02-05 16:28:25 -0800 | [diff] [blame] | 68 | err |= tc_preadb(pattern + 0, |
| 69 | module + offset + TC_PATTERN0); |
| 70 | err |= tc_preadb(pattern + 1, |
| 71 | module + offset + TC_PATTERN1); |
| 72 | err |= tc_preadb(pattern + 2, |
| 73 | module + offset + TC_PATTERN2); |
| 74 | err |= tc_preadb(pattern + 3, |
| 75 | module + offset + TC_PATTERN3); |
| 76 | if (err) |
| 77 | goto out_err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | if (pattern[0] != 0x55 || pattern[1] != 0x00 || |
Maciej W. Rozycki | b454cc6 | 2007-02-05 16:28:25 -0800 | [diff] [blame] | 81 | pattern[2] != 0xaa || pattern[3] != 0xff) |
| 82 | goto out_err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | |
Maciej W. Rozycki | b454cc6 | 2007-02-05 16:28:25 -0800 | [diff] [blame] | 84 | /* Found a board, allocate it an entry in the list */ |
| 85 | tdev = kzalloc(sizeof(*tdev), GFP_KERNEL); |
| 86 | if (!tdev) { |
Maciej W. Rozycki | e2afb7d | 2014-04-06 20:52:37 +0100 | [diff] [blame] | 87 | pr_err("tc%x: unable to allocate tc_dev\n", slot); |
Maciej W. Rozycki | b454cc6 | 2007-02-05 16:28:25 -0800 | [diff] [blame] | 88 | goto out_err; |
| 89 | } |
Kay Sievers | df38855 | 2009-03-24 16:38:22 -0700 | [diff] [blame] | 90 | dev_set_name(&tdev->dev, "tc%x", slot); |
Maciej W. Rozycki | b454cc6 | 2007-02-05 16:28:25 -0800 | [diff] [blame] | 91 | tdev->bus = tbus; |
| 92 | tdev->dev.parent = &tbus->dev; |
| 93 | tdev->dev.bus = &tc_bus_type; |
| 94 | tdev->slot = slot; |
| 95 | |
Maciej W. Rozycki | b0b6284 | 2018-10-03 13:21:07 +0100 | [diff] [blame] | 96 | /* TURBOchannel has 34-bit DMA addressing (16GiB space). */ |
| 97 | tdev->dma_mask = DMA_BIT_MASK(34); |
| 98 | tdev->dev.dma_mask = &tdev->dma_mask; |
| 99 | tdev->dev.coherent_dma_mask = DMA_BIT_MASK(34); |
| 100 | |
Maciej W. Rozycki | a5fc9c0 | 2005-07-01 16:10:40 +0000 | [diff] [blame] | 101 | for (i = 0; i < 8; i++) { |
Maciej W. Rozycki | b454cc6 | 2007-02-05 16:28:25 -0800 | [diff] [blame] | 102 | tdev->firmware[i] = |
| 103 | readb(module + offset + TC_FIRM_VER + 4 * i); |
| 104 | tdev->vendor[i] = |
| 105 | readb(module + offset + TC_VENDOR + 4 * i); |
| 106 | tdev->name[i] = |
| 107 | readb(module + offset + TC_MODULE + 4 * i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | } |
Maciej W. Rozycki | b454cc6 | 2007-02-05 16:28:25 -0800 | [diff] [blame] | 109 | tdev->firmware[8] = 0; |
| 110 | tdev->vendor[8] = 0; |
| 111 | tdev->name[8] = 0; |
Maciej W. Rozycki | a5fc9c0 | 2005-07-01 16:10:40 +0000 | [diff] [blame] | 112 | |
Kay Sievers | df38855 | 2009-03-24 16:38:22 -0700 | [diff] [blame] | 113 | pr_info("%s: %s %s %s\n", dev_name(&tdev->dev), tdev->vendor, |
Maciej W. Rozycki | b454cc6 | 2007-02-05 16:28:25 -0800 | [diff] [blame] | 114 | tdev->name, tdev->firmware); |
| 115 | |
| 116 | devsize = readb(module + offset + TC_SLOT_SIZE); |
| 117 | devsize <<= 22; |
| 118 | if (devsize <= slotsize) { |
| 119 | tdev->resource.start = slotaddr; |
| 120 | tdev->resource.end = slotaddr + devsize - 1; |
| 121 | } else if (devsize <= extslotsize) { |
| 122 | tdev->resource.start = extslotaddr; |
| 123 | tdev->resource.end = extslotaddr + devsize - 1; |
| 124 | } else { |
Maciej W. Rozycki | e2afb7d | 2014-04-06 20:52:37 +0100 | [diff] [blame] | 125 | pr_err("%s: Cannot provide slot space " |
| 126 | "(%ldMiB required, up to %ldMiB supported)\n", |
| 127 | dev_name(&tdev->dev), (long)(devsize >> 20), |
| 128 | (long)(max(slotsize, extslotsize) >> 20)); |
Maciej W. Rozycki | b454cc6 | 2007-02-05 16:28:25 -0800 | [diff] [blame] | 129 | kfree(tdev); |
| 130 | goto out_err; |
| 131 | } |
| 132 | tdev->resource.name = tdev->name; |
| 133 | tdev->resource.flags = IORESOURCE_MEM; |
| 134 | |
| 135 | tc_device_get_irq(tdev); |
| 136 | |
Levente Kurusa | 5bb7889 | 2014-04-02 12:00:37 +0200 | [diff] [blame] | 137 | if (device_register(&tdev->dev)) { |
| 138 | put_device(&tdev->dev); |
| 139 | goto out_err; |
| 140 | } |
Maciej W. Rozycki | b454cc6 | 2007-02-05 16:28:25 -0800 | [diff] [blame] | 141 | list_add_tail(&tdev->node, &tbus->devices); |
| 142 | |
| 143 | out_err: |
Maciej W. Rozycki | a5fc9c0 | 2005-07-01 16:10:40 +0000 | [diff] [blame] | 144 | iounmap(module); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | } |
| 146 | } |
| 147 | |
| 148 | /* |
Maciej W. Rozycki | b454cc6 | 2007-02-05 16:28:25 -0800 | [diff] [blame] | 149 | * The main entry. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | */ |
Maciej W. Rozycki | 778220f | 2005-06-16 20:37:40 +0000 | [diff] [blame] | 151 | static int __init tc_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | { |
Maciej W. Rozycki | b454cc6 | 2007-02-05 16:28:25 -0800 | [diff] [blame] | 153 | /* Initialize the TURBOchannel bus */ |
| 154 | if (tc_bus_get_info(&tc_bus)) |
Maciej W. Rozycki | e2afb7d | 2014-04-06 20:52:37 +0100 | [diff] [blame] | 155 | goto out_err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | |
Maciej W. Rozycki | b454cc6 | 2007-02-05 16:28:25 -0800 | [diff] [blame] | 157 | INIT_LIST_HEAD(&tc_bus.devices); |
Kay Sievers | df38855 | 2009-03-24 16:38:22 -0700 | [diff] [blame] | 158 | dev_set_name(&tc_bus.dev, "tc"); |
Maciej W. Rozycki | e2afb7d | 2014-04-06 20:52:37 +0100 | [diff] [blame] | 159 | if (device_register(&tc_bus.dev)) |
| 160 | goto out_err_device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | |
Maciej W. Rozycki | b454cc6 | 2007-02-05 16:28:25 -0800 | [diff] [blame] | 162 | if (tc_bus.info.slot_size) { |
| 163 | unsigned int tc_clock = tc_get_speed(&tc_bus) / 100000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | |
Maciej W. Rozycki | b454cc6 | 2007-02-05 16:28:25 -0800 | [diff] [blame] | 165 | pr_info("tc: TURBOchannel rev. %d at %d.%d MHz " |
| 166 | "(with%s parity)\n", tc_bus.info.revision, |
| 167 | tc_clock / 10, tc_clock % 10, |
| 168 | tc_bus.info.parity ? "" : "out"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | |
Maciej W. Rozycki | b454cc6 | 2007-02-05 16:28:25 -0800 | [diff] [blame] | 170 | tc_bus.resource[0].start = tc_bus.slot_base; |
| 171 | tc_bus.resource[0].end = tc_bus.slot_base + |
| 172 | (tc_bus.info.slot_size << 20) * |
Maciej W. Rozycki | 56a47da | 2007-02-05 16:28:26 -0800 | [diff] [blame] | 173 | tc_bus.num_tcslots - 1; |
Maciej W. Rozycki | b454cc6 | 2007-02-05 16:28:25 -0800 | [diff] [blame] | 174 | tc_bus.resource[0].name = tc_bus.name; |
| 175 | tc_bus.resource[0].flags = IORESOURCE_MEM; |
| 176 | if (request_resource(&iomem_resource, |
| 177 | &tc_bus.resource[0]) < 0) { |
Maciej W. Rozycki | e2afb7d | 2014-04-06 20:52:37 +0100 | [diff] [blame] | 178 | pr_err("tc: Cannot reserve resource\n"); |
| 179 | goto out_err_device; |
Maciej W. Rozycki | a5fc9c0 | 2005-07-01 16:10:40 +0000 | [diff] [blame] | 180 | } |
Maciej W. Rozycki | b454cc6 | 2007-02-05 16:28:25 -0800 | [diff] [blame] | 181 | if (tc_bus.ext_slot_size) { |
| 182 | tc_bus.resource[1].start = tc_bus.ext_slot_base; |
| 183 | tc_bus.resource[1].end = tc_bus.ext_slot_base + |
| 184 | tc_bus.ext_slot_size * |
Maciej W. Rozycki | 56a47da | 2007-02-05 16:28:26 -0800 | [diff] [blame] | 185 | tc_bus.num_tcslots - 1; |
Maciej W. Rozycki | b454cc6 | 2007-02-05 16:28:25 -0800 | [diff] [blame] | 186 | tc_bus.resource[1].name = tc_bus.name; |
| 187 | tc_bus.resource[1].flags = IORESOURCE_MEM; |
| 188 | if (request_resource(&iomem_resource, |
| 189 | &tc_bus.resource[1]) < 0) { |
Maciej W. Rozycki | e2afb7d | 2014-04-06 20:52:37 +0100 | [diff] [blame] | 190 | pr_err("tc: Cannot reserve resource\n"); |
| 191 | goto out_err_resource; |
Maciej W. Rozycki | b454cc6 | 2007-02-05 16:28:25 -0800 | [diff] [blame] | 192 | } |
| 193 | } |
| 194 | |
| 195 | tc_bus_add_devices(&tc_bus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | } |
Maciej W. Rozycki | 778220f | 2005-06-16 20:37:40 +0000 | [diff] [blame] | 197 | |
| 198 | return 0; |
Maciej W. Rozycki | e2afb7d | 2014-04-06 20:52:37 +0100 | [diff] [blame] | 199 | |
| 200 | out_err_resource: |
| 201 | release_resource(&tc_bus.resource[0]); |
| 202 | out_err_device: |
| 203 | put_device(&tc_bus.dev); |
| 204 | out_err: |
| 205 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | subsys_initcall(tc_init); |