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