4 * Copyright (C) 1995-2003 Geert Uytterhoeven
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
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>
17 #include <linux/string.h>
18 #include <linux/platform_device.h>
19 #include <linux/dma-mapping.h>
20 #include <linux/slab.h>
22 #include <asm/byteorder.h>
23 #include <asm/setup.h>
24 #include <asm/amigahw.h>
30 * Zorro Expansion Devices
33 unsigned int zorro_num_autocon
;
34 struct zorro_dev_init zorro_autocon_init
[ZORRO_NUM_AUTO
] __initdata
;
35 struct zorro_dev
*zorro_autocon
;
44 struct zorro_dev devices
[];
52 struct zorro_dev
*zorro_find_device(zorro_id id
, struct zorro_dev
*from
)
56 if (!zorro_num_autocon
)
59 for (z
= from
? from
+1 : &zorro_autocon
[0];
60 z
< zorro_autocon
+zorro_num_autocon
;
62 if (id
== ZORRO_WILDCARD
|| id
== z
->id
)
66 EXPORT_SYMBOL(zorro_find_device
);
70 * Bitmask indicating portions of available Zorro II RAM that are unused
71 * by the system. Every bit represents a 64K chunk, for a maximum of 8MB
72 * (128 chunks, physical 0x00200000-0x009fffff).
74 * If you want to use (= allocate) portions of this RAM, you should clear
75 * the corresponding bits.
79 * - SCSI DMA bounce buffers
81 * FIXME: use the normal resource management
84 DECLARE_BITMAP(zorro_unused_z2ram
, 128);
85 EXPORT_SYMBOL(zorro_unused_z2ram
);
88 static void __init
mark_region(unsigned long start
, unsigned long end
,
92 start
+= Z2RAM_CHUNKMASK
;
94 end
+= Z2RAM_CHUNKMASK
;
95 start
&= ~Z2RAM_CHUNKMASK
;
96 end
&= ~Z2RAM_CHUNKMASK
;
98 if (end
<= Z2RAM_START
|| start
>= Z2RAM_END
)
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
;
106 set_bit(chunk
, zorro_unused_z2ram
);
108 clear_bit(chunk
, zorro_unused_z2ram
);
109 start
+= Z2RAM_CHUNKSIZE
;
114 static struct resource __init
*zorro_find_parent_resource(
115 struct platform_device
*bridge
, struct zorro_dev
*z
)
119 for (i
= 0; i
< bridge
->num_resources
; i
++) {
120 struct resource
*r
= &bridge
->resource
[i
];
122 if (zorro_resource_start(z
) >= r
->start
&&
123 zorro_resource_end(z
) <= r
->end
)
126 return &iomem_resource
;
131 static int __init
amiga_zorro_probe(struct platform_device
*pdev
)
133 struct zorro_bus
*bus
;
134 struct zorro_dev_init
*zi
;
140 /* Initialize the Zorro bus */
141 bus
= kzalloc(struct_size(bus
, devices
, zorro_num_autocon
),
146 zorro_autocon
= bus
->devices
;
147 bus
->dev
.parent
= &pdev
->dev
;
148 dev_set_name(&bus
->dev
, zorro_bus_type
.name
);
149 error
= device_register(&bus
->dev
);
151 pr_err("Zorro: Error registering zorro_bus\n");
152 put_device(&bus
->dev
);
156 platform_set_drvdata(pdev
, bus
);
158 pr_info("Zorro: Probing AutoConfig expansion devices: %u device%s\n",
159 zorro_num_autocon
, zorro_num_autocon
== 1 ? "" : "s");
161 /* First identify all devices ... */
162 for (i
= 0; i
< zorro_num_autocon
; i
++) {
163 zi
= &zorro_autocon_init
[i
];
164 z
= &zorro_autocon
[i
];
167 z
->id
= (be16_to_cpu(z
->rom
.er_Manufacturer
) << 16) |
168 (z
->rom
.er_Product
<< 8);
169 if (z
->id
== ZORRO_PROD_GVP_EPC_BASE
) {
171 unsigned long magic
= zi
->boardaddr
+ 0x8000;
173 z
->id
|= *(u16
*)ZTWO_VADDR(magic
) & GVP_PRODMASK
;
175 z
->slotaddr
= zi
->slotaddr
;
176 z
->slotsize
= zi
->slotsize
;
177 sprintf(z
->name
, "Zorro device %08x", z
->id
);
178 zorro_name_device(z
);
179 z
->resource
.start
= zi
->boardaddr
;
180 z
->resource
.end
= zi
->boardaddr
+ zi
->boardsize
- 1;
181 z
->resource
.name
= z
->name
;
182 r
= zorro_find_parent_resource(pdev
, z
);
183 error
= request_resource(r
, &z
->resource
);
184 if (error
&& !(z
->rom
.er_Type
& ERTF_MEMLIST
))
186 "Address space collision on device %s %pR\n",
187 z
->name
, &z
->resource
);
188 z
->dev
.parent
= &bus
->dev
;
189 z
->dev
.bus
= &zorro_bus_type
;
191 switch (z
->rom
.er_Type
& ERT_TYPEMASK
) {
193 z
->dev
.coherent_dma_mask
= DMA_BIT_MASK(32);
198 z
->dev
.coherent_dma_mask
= DMA_BIT_MASK(24);
201 z
->dev
.dma_mask
= &z
->dev
.coherent_dma_mask
;
204 /* ... then register them */
205 for (i
= 0; i
< zorro_num_autocon
; i
++) {
206 z
= &zorro_autocon
[i
];
207 error
= device_register(&z
->dev
);
209 dev_err(&bus
->dev
, "Error registering device %s\n",
216 /* Mark all available Zorro II memory */
217 zorro_for_each_dev(z
) {
218 if (z
->rom
.er_Type
& ERTF_MEMLIST
)
219 mark_region(zorro_resource_start(z
),
220 zorro_resource_end(z
)+1, 1);
223 /* Unmark all used Zorro II memory */
224 for (i
= 0; i
< m68k_num_memory
; i
++)
225 if (m68k_memory
[i
].addr
< 16*1024*1024)
226 mark_region(m68k_memory
[i
].addr
,
227 m68k_memory
[i
].addr
+m68k_memory
[i
].size
,
233 static struct platform_driver amiga_zorro_driver
= {
235 .name
= "amiga-zorro",
239 static int __init
amiga_zorro_init(void)
241 return platform_driver_probe(&amiga_zorro_driver
, amiga_zorro_probe
);
244 module_init(amiga_zorro_init
);
246 MODULE_LICENSE("GPL");