Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * Zorro Bus Services |
| 3 | * |
| 4 | * Copyright (C) 1995-2003 Geert Uytterhoeven |
| 5 | * |
| 6 | * This file is subject to the terms and conditions of the GNU General Public |
| 7 | * License. See the file COPYING in the main directory of this archive |
| 8 | * for more details. |
| 9 | */ |
| 10 | |
| 11 | #include <linux/module.h> |
| 12 | #include <linux/types.h> |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/init.h> |
| 15 | #include <linux/zorro.h> |
| 16 | #include <linux/bitops.h> |
Tim Schmielau | 4e57b68 | 2005-10-30 15:03:48 -0800 | [diff] [blame] | 17 | #include <linux/string.h> |
Geert Uytterhoeven | 0d30546 | 2009-04-05 12:40:41 +0200 | [diff] [blame] | 18 | #include <linux/platform_device.h> |
| 19 | #include <linux/slab.h> |
Tim Schmielau | 4e57b68 | 2005-10-30 15:03:48 -0800 | [diff] [blame] | 20 | |
Geert Uytterhoeven | bd9ba8f | 2013-10-04 09:38:53 +0200 | [diff] [blame] | 21 | #include <asm/byteorder.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <asm/setup.h> |
| 23 | #include <asm/amigahw.h> |
| 24 | |
| 25 | #include "zorro.h" |
| 26 | |
| 27 | |
| 28 | /* |
| 29 | * Zorro Expansion Devices |
| 30 | */ |
| 31 | |
Geert Uytterhoeven | 0d30546 | 2009-04-05 12:40:41 +0200 | [diff] [blame] | 32 | unsigned int zorro_num_autocon; |
Geert Uytterhoeven | c293738 | 2013-06-29 10:40:20 +0200 | [diff] [blame] | 33 | struct zorro_dev_init zorro_autocon_init[ZORRO_NUM_AUTO] __initdata; |
| 34 | struct zorro_dev *zorro_autocon; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
| 36 | |
| 37 | /* |
Geert Uytterhoeven | 0d30546 | 2009-04-05 12:40:41 +0200 | [diff] [blame] | 38 | * Zorro bus |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | */ |
| 40 | |
Geert Uytterhoeven | 0d30546 | 2009-04-05 12:40:41 +0200 | [diff] [blame] | 41 | struct zorro_bus { |
Geert Uytterhoeven | 0d30546 | 2009-04-05 12:40:41 +0200 | [diff] [blame] | 42 | struct device dev; |
Geert Uytterhoeven | c293738 | 2013-06-29 10:40:20 +0200 | [diff] [blame] | 43 | struct zorro_dev devices[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | }; |
| 45 | |
| 46 | |
| 47 | /* |
| 48 | * Find Zorro Devices |
| 49 | */ |
| 50 | |
| 51 | struct zorro_dev *zorro_find_device(zorro_id id, struct zorro_dev *from) |
| 52 | { |
Geert Uytterhoeven | 0d30546 | 2009-04-05 12:40:41 +0200 | [diff] [blame] | 53 | struct zorro_dev *z; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
Geert Uytterhoeven | 0d30546 | 2009-04-05 12:40:41 +0200 | [diff] [blame] | 55 | if (!zorro_num_autocon) |
| 56 | return NULL; |
| 57 | |
| 58 | for (z = from ? from+1 : &zorro_autocon[0]; |
| 59 | z < zorro_autocon+zorro_num_autocon; |
| 60 | z++) |
| 61 | if (id == ZORRO_WILDCARD || id == z->id) |
| 62 | return z; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | } |
Geert Uytterhoeven | 0d30546 | 2009-04-05 12:40:41 +0200 | [diff] [blame] | 65 | EXPORT_SYMBOL(zorro_find_device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
| 67 | |
| 68 | /* |
| 69 | * Bitmask indicating portions of available Zorro II RAM that are unused |
| 70 | * by the system. Every bit represents a 64K chunk, for a maximum of 8MB |
| 71 | * (128 chunks, physical 0x00200000-0x009fffff). |
| 72 | * |
| 73 | * If you want to use (= allocate) portions of this RAM, you should clear |
| 74 | * the corresponding bits. |
| 75 | * |
| 76 | * Possible uses: |
| 77 | * - z2ram device |
| 78 | * - SCSI DMA bounce buffers |
| 79 | * |
| 80 | * FIXME: use the normal resource management |
| 81 | */ |
| 82 | |
| 83 | DECLARE_BITMAP(zorro_unused_z2ram, 128); |
Geert Uytterhoeven | 0d30546 | 2009-04-05 12:40:41 +0200 | [diff] [blame] | 84 | EXPORT_SYMBOL(zorro_unused_z2ram); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | |
| 86 | |
| 87 | static void __init mark_region(unsigned long start, unsigned long end, |
| 88 | int flag) |
| 89 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | if (flag) |
Geert Uytterhoeven | 0d30546 | 2009-04-05 12:40:41 +0200 | [diff] [blame] | 91 | start += Z2RAM_CHUNKMASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | else |
Geert Uytterhoeven | 0d30546 | 2009-04-05 12:40:41 +0200 | [diff] [blame] | 93 | end += Z2RAM_CHUNKMASK; |
| 94 | start &= ~Z2RAM_CHUNKMASK; |
| 95 | end &= ~Z2RAM_CHUNKMASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | |
Geert Uytterhoeven | 0d30546 | 2009-04-05 12:40:41 +0200 | [diff] [blame] | 97 | if (end <= Z2RAM_START || start >= Z2RAM_END) |
| 98 | return; |
| 99 | start = start < Z2RAM_START ? 0x00000000 : start-Z2RAM_START; |
| 100 | end = end > Z2RAM_END ? Z2RAM_SIZE : end-Z2RAM_START; |
| 101 | while (start < end) { |
| 102 | u32 chunk = start>>Z2RAM_CHUNKSHIFT; |
| 103 | if (flag) |
| 104 | set_bit(chunk, zorro_unused_z2ram); |
| 105 | else |
| 106 | clear_bit(chunk, zorro_unused_z2ram); |
| 107 | start += Z2RAM_CHUNKSIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | } |
Geert Uytterhoeven | 0d30546 | 2009-04-05 12:40:41 +0200 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | |
| 112 | static struct resource __init *zorro_find_parent_resource( |
| 113 | struct platform_device *bridge, struct zorro_dev *z) |
| 114 | { |
| 115 | int i; |
| 116 | |
| 117 | for (i = 0; i < bridge->num_resources; i++) { |
| 118 | struct resource *r = &bridge->resource[i]; |
| 119 | if (zorro_resource_start(z) >= r->start && |
| 120 | zorro_resource_end(z) <= r->end) |
| 121 | return r; |
| 122 | } |
| 123 | return &iomem_resource; |
| 124 | } |
| 125 | |
| 126 | |
| 127 | |
| 128 | static int __init amiga_zorro_probe(struct platform_device *pdev) |
| 129 | { |
| 130 | struct zorro_bus *bus; |
Geert Uytterhoeven | c293738 | 2013-06-29 10:40:20 +0200 | [diff] [blame] | 131 | struct zorro_dev_init *zi; |
Geert Uytterhoeven | 0d30546 | 2009-04-05 12:40:41 +0200 | [diff] [blame] | 132 | struct zorro_dev *z; |
| 133 | struct resource *r; |
| 134 | unsigned int i; |
| 135 | int error; |
| 136 | |
| 137 | /* Initialize the Zorro bus */ |
Geert Uytterhoeven | c293738 | 2013-06-29 10:40:20 +0200 | [diff] [blame] | 138 | bus = kzalloc(sizeof(*bus) + |
| 139 | zorro_num_autocon * sizeof(bus->devices[0]), |
| 140 | GFP_KERNEL); |
Geert Uytterhoeven | 0d30546 | 2009-04-05 12:40:41 +0200 | [diff] [blame] | 141 | if (!bus) |
| 142 | return -ENOMEM; |
| 143 | |
Geert Uytterhoeven | c293738 | 2013-06-29 10:40:20 +0200 | [diff] [blame] | 144 | zorro_autocon = bus->devices; |
Geert Uytterhoeven | 0d30546 | 2009-04-05 12:40:41 +0200 | [diff] [blame] | 145 | bus->dev.parent = &pdev->dev; |
Geert Uytterhoeven | 83b7bce | 2013-10-16 11:28:54 +0200 | [diff] [blame] | 146 | dev_set_name(&bus->dev, zorro_bus_type.name); |
Geert Uytterhoeven | 0d30546 | 2009-04-05 12:40:41 +0200 | [diff] [blame] | 147 | error = device_register(&bus->dev); |
Geert Uytterhoeven | 11a8b2c | 2008-12-30 14:21:19 +0100 | [diff] [blame] | 148 | if (error) { |
Geert Uytterhoeven | 0d30546 | 2009-04-05 12:40:41 +0200 | [diff] [blame] | 149 | pr_err("Zorro: Error registering zorro_bus\n"); |
Vasiliy Kulikov | 10b6879 | 2010-09-19 16:55:21 +0400 | [diff] [blame] | 150 | put_device(&bus->dev); |
Geert Uytterhoeven | 0d30546 | 2009-04-05 12:40:41 +0200 | [diff] [blame] | 151 | kfree(bus); |
| 152 | return error; |
Geert Uytterhoeven | 11a8b2c | 2008-12-30 14:21:19 +0100 | [diff] [blame] | 153 | } |
Geert Uytterhoeven | 0d30546 | 2009-04-05 12:40:41 +0200 | [diff] [blame] | 154 | platform_set_drvdata(pdev, bus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | |
Geert Uytterhoeven | 0d30546 | 2009-04-05 12:40:41 +0200 | [diff] [blame] | 156 | pr_info("Zorro: Probing AutoConfig expansion devices: %u device%s\n", |
| 157 | zorro_num_autocon, zorro_num_autocon == 1 ? "" : "s"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | |
Geert Uytterhoeven | a7f4d00 | 2011-09-22 21:47:38 +0200 | [diff] [blame] | 159 | /* First identify all devices ... */ |
Geert Uytterhoeven | 0d30546 | 2009-04-05 12:40:41 +0200 | [diff] [blame] | 160 | for (i = 0; i < zorro_num_autocon; i++) { |
Geert Uytterhoeven | c293738 | 2013-06-29 10:40:20 +0200 | [diff] [blame] | 161 | zi = &zorro_autocon_init[i]; |
Geert Uytterhoeven | 0d30546 | 2009-04-05 12:40:41 +0200 | [diff] [blame] | 162 | z = &zorro_autocon[i]; |
Geert Uytterhoeven | c293738 | 2013-06-29 10:40:20 +0200 | [diff] [blame] | 163 | |
| 164 | z->rom = zi->rom; |
Geert Uytterhoeven | bd9ba8f | 2013-10-04 09:38:53 +0200 | [diff] [blame] | 165 | z->id = (be16_to_cpu(z->rom.er_Manufacturer) << 16) | |
| 166 | (z->rom.er_Product << 8); |
Geert Uytterhoeven | 0d30546 | 2009-04-05 12:40:41 +0200 | [diff] [blame] | 167 | if (z->id == ZORRO_PROD_GVP_EPC_BASE) { |
| 168 | /* GVP quirk */ |
Geert Uytterhoeven | c293738 | 2013-06-29 10:40:20 +0200 | [diff] [blame] | 169 | unsigned long magic = zi->boardaddr + 0x8000; |
Geert Uytterhoeven | 0d30546 | 2009-04-05 12:40:41 +0200 | [diff] [blame] | 170 | z->id |= *(u16 *)ZTWO_VADDR(magic) & GVP_PRODMASK; |
| 171 | } |
Geert Uytterhoeven | c293738 | 2013-06-29 10:40:20 +0200 | [diff] [blame] | 172 | z->slotaddr = zi->slotaddr; |
| 173 | z->slotsize = zi->slotsize; |
Geert Uytterhoeven | 0d30546 | 2009-04-05 12:40:41 +0200 | [diff] [blame] | 174 | sprintf(z->name, "Zorro device %08x", z->id); |
| 175 | zorro_name_device(z); |
Geert Uytterhoeven | c293738 | 2013-06-29 10:40:20 +0200 | [diff] [blame] | 176 | z->resource.start = zi->boardaddr; |
| 177 | z->resource.end = zi->boardaddr + zi->boardsize - 1; |
Geert Uytterhoeven | 0d30546 | 2009-04-05 12:40:41 +0200 | [diff] [blame] | 178 | z->resource.name = z->name; |
| 179 | r = zorro_find_parent_resource(pdev, z); |
| 180 | error = request_resource(r, &z->resource); |
| 181 | if (error) |
| 182 | dev_err(&bus->dev, |
| 183 | "Address space collision on device %s %pR\n", |
| 184 | z->name, &z->resource); |
Geert Uytterhoeven | 0d30546 | 2009-04-05 12:40:41 +0200 | [diff] [blame] | 185 | z->dev.parent = &bus->dev; |
| 186 | z->dev.bus = &zorro_bus_type; |
Geert Uytterhoeven | 83b7bce | 2013-10-16 11:28:54 +0200 | [diff] [blame] | 187 | z->dev.id = i; |
Geert Uytterhoeven | a7f4d00 | 2011-09-22 21:47:38 +0200 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | /* ... then register them */ |
| 191 | for (i = 0; i < zorro_num_autocon; i++) { |
| 192 | z = &zorro_autocon[i]; |
Geert Uytterhoeven | 0d30546 | 2009-04-05 12:40:41 +0200 | [diff] [blame] | 193 | error = device_register(&z->dev); |
| 194 | if (error) { |
| 195 | dev_err(&bus->dev, "Error registering device %s\n", |
| 196 | z->name); |
Vasiliy Kulikov | 10b6879 | 2010-09-19 16:55:21 +0400 | [diff] [blame] | 197 | put_device(&z->dev); |
Geert Uytterhoeven | 0d30546 | 2009-04-05 12:40:41 +0200 | [diff] [blame] | 198 | continue; |
| 199 | } |
| 200 | error = zorro_create_sysfs_dev_files(z); |
| 201 | if (error) |
| 202 | dev_err(&z->dev, "Error creating sysfs files\n"); |
| 203 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | |
Geert Uytterhoeven | 0d30546 | 2009-04-05 12:40:41 +0200 | [diff] [blame] | 205 | /* Mark all available Zorro II memory */ |
| 206 | zorro_for_each_dev(z) { |
| 207 | if (z->rom.er_Type & ERTF_MEMLIST) |
| 208 | mark_region(zorro_resource_start(z), |
| 209 | zorro_resource_end(z)+1, 1); |
| 210 | } |
| 211 | |
| 212 | /* Unmark all used Zorro II memory */ |
| 213 | for (i = 0; i < m68k_num_memory; i++) |
| 214 | if (m68k_memory[i].addr < 16*1024*1024) |
| 215 | mark_region(m68k_memory[i].addr, |
| 216 | m68k_memory[i].addr+m68k_memory[i].size, |
| 217 | 0); |
| 218 | |
| 219 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | } |
| 221 | |
Geert Uytterhoeven | 0d30546 | 2009-04-05 12:40:41 +0200 | [diff] [blame] | 222 | static struct platform_driver amiga_zorro_driver = { |
| 223 | .driver = { |
| 224 | .name = "amiga-zorro", |
| 225 | .owner = THIS_MODULE, |
| 226 | }, |
| 227 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | |
Geert Uytterhoeven | 0d30546 | 2009-04-05 12:40:41 +0200 | [diff] [blame] | 229 | static int __init amiga_zorro_init(void) |
| 230 | { |
| 231 | return platform_driver_probe(&amiga_zorro_driver, amiga_zorro_probe); |
| 232 | } |
| 233 | |
| 234 | module_init(amiga_zorro_init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | |
| 236 | MODULE_LICENSE("GPL"); |