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