MOXA linux-2.6.x / linux-2.6.9-uc0 from sdlinux-moxaart.tgz
[linux-2.6.9-moxart.git] / drivers / zorro / zorro.c
blobc10bc4bcd3833bc6e81e8d8b9674b480537b3ba3
1 /*
2 * $Id: zorro.c,v 1.1.2.1 1998/06/07 23:21:02 geert Exp $
4 * Zorro Bus Services
6 * Copyright (C) 1995-2003 Geert Uytterhoeven
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file COPYING in the main directory of this archive
10 * for more details.
13 #include <linux/module.h>
14 #include <linux/types.h>
15 #include <linux/kernel.h>
16 #include <linux/init.h>
17 #include <linux/zorro.h>
18 #include <asm/setup.h>
19 #include <asm/bitops.h>
20 #include <asm/amigahw.h>
22 #include "zorro.h"
26 * Zorro Expansion Devices
29 u_int zorro_num_autocon = 0;
30 struct zorro_dev zorro_autocon[ZORRO_NUM_AUTO];
34 * Single Zorro bus
37 struct zorro_bus zorro_bus = {\
38 .resources = {
39 /* Zorro II regions (on Zorro II/III) */
40 { .name = "Zorro II exp", .start = 0x00e80000, .end = 0x00efffff },
41 { .name = "Zorro II mem", .start = 0x00200000, .end = 0x009fffff },
42 /* Zorro III regions (on Zorro III only) */
43 { .name = "Zorro III exp", .start = 0xff000000, .end = 0xffffffff },
44 { .name = "Zorro III cfg", .start = 0x40000000, .end = 0x7fffffff }
46 .name = "Zorro bus"
51 * Find Zorro Devices
54 struct zorro_dev *zorro_find_device(zorro_id id, struct zorro_dev *from)
56 struct zorro_dev *z;
58 if (!MACH_IS_AMIGA || !AMIGAHW_PRESENT(ZORRO))
59 return NULL;
61 for (z = from ? from+1 : &zorro_autocon[0];
62 z < zorro_autocon+zorro_num_autocon;
63 z++)
64 if (id == ZORRO_WILDCARD || id == z->id)
65 return z;
66 return NULL;
71 * Bitmask indicating portions of available Zorro II RAM that are unused
72 * by the system. Every bit represents a 64K chunk, for a maximum of 8MB
73 * (128 chunks, physical 0x00200000-0x009fffff).
75 * If you want to use (= allocate) portions of this RAM, you should clear
76 * the corresponding bits.
78 * Possible uses:
79 * - z2ram device
80 * - SCSI DMA bounce buffers
82 * FIXME: use the normal resource management
85 DECLARE_BITMAP(zorro_unused_z2ram, 128);
88 static void __init mark_region(unsigned long start, unsigned long end,
89 int flag)
91 if (flag)
92 start += Z2RAM_CHUNKMASK;
93 else
94 end += Z2RAM_CHUNKMASK;
95 start &= ~Z2RAM_CHUNKMASK;
96 end &= ~Z2RAM_CHUNKMASK;
98 if (end <= Z2RAM_START || start >= Z2RAM_END)
99 return;
100 start = start < Z2RAM_START ? 0x00000000 : start-Z2RAM_START;
101 end = end > Z2RAM_END ? Z2RAM_SIZE : end-Z2RAM_START;
102 while (start < end) {
103 u32 chunk = start>>Z2RAM_CHUNKSHIFT;
104 if (flag)
105 set_bit(chunk, zorro_unused_z2ram);
106 else
107 clear_bit(chunk, zorro_unused_z2ram);
108 start += Z2RAM_CHUNKSIZE;
113 static struct resource __init *zorro_find_parent_resource(struct zorro_dev *z)
115 int i;
117 for (i = 0; i < zorro_bus.num_resources; i++)
118 if (zorro_resource_start(z) >= zorro_bus.resources[i].start &&
119 zorro_resource_end(z) <= zorro_bus.resources[i].end)
120 return &zorro_bus.resources[i];
121 return &iomem_resource;
126 * Initialization
129 static int __init zorro_init(void)
131 struct zorro_dev *z;
132 unsigned int i;
134 if (!MACH_IS_AMIGA || !AMIGAHW_PRESENT(ZORRO))
135 return 0;
137 printk("Zorro: Probing AutoConfig expansion devices: %d device%s\n",
138 zorro_num_autocon, zorro_num_autocon == 1 ? "" : "s");
140 /* Initialize the Zorro bus */
141 INIT_LIST_HEAD(&zorro_bus.devices);
142 strcpy(zorro_bus.dev.bus_id, "zorro");
143 device_register(&zorro_bus.dev);
145 /* Request the resources */
146 zorro_bus.num_resources = AMIGAHW_PRESENT(ZORRO3) ? 4 : 2;
147 for (i = 0; i < zorro_bus.num_resources; i++)
148 request_resource(&iomem_resource, &zorro_bus.resources[i]);
150 /* Register all devices */
151 for (i = 0; i < zorro_num_autocon; i++) {
152 z = &zorro_autocon[i];
153 z->id = (z->rom.er_Manufacturer<<16) | (z->rom.er_Product<<8);
154 if (z->id == ZORRO_PROD_GVP_EPC_BASE) {
155 /* GVP quirk */
156 unsigned long magic = zorro_resource_start(z)+0x8000;
157 z->id |= *(u16 *)ZTWO_VADDR(magic) & GVP_PRODMASK;
159 sprintf(z->name, "Zorro device %08x", z->id);
160 zorro_name_device(z);
161 z->resource.name = z->name;
162 if (request_resource(zorro_find_parent_resource(z), &z->resource))
163 printk(KERN_ERR "Zorro: Address space collision on device %s "
164 "[%lx:%lx]\n",
165 z->name, zorro_resource_start(z), zorro_resource_end(z));
166 sprintf(z->dev.bus_id, "%02x", i);
167 z->dev.parent = &zorro_bus.dev;
168 z->dev.bus = &zorro_bus_type;
169 device_register(&z->dev);
170 zorro_create_sysfs_dev_files(z);
173 /* Mark all available Zorro II memory */
174 zorro_for_each_dev(z) {
175 if (z->rom.er_Type & ERTF_MEMLIST)
176 mark_region(zorro_resource_start(z), zorro_resource_end(z)+1, 1);
179 /* Unmark all used Zorro II memory */
180 for (i = 0; i < m68k_num_memory; i++)
181 if (m68k_memory[i].addr < 16*1024*1024)
182 mark_region(m68k_memory[i].addr,
183 m68k_memory[i].addr+m68k_memory[i].size, 0);
185 return 0;
188 subsys_initcall(zorro_init);
190 EXPORT_SYMBOL(zorro_find_device);
191 EXPORT_SYMBOL(zorro_unused_z2ram);
193 MODULE_LICENSE("GPL");