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>
21 #include <linux/string_choices.h>
23 #include <asm/byteorder.h>
24 #include <asm/setup.h>
25 #include <asm/amigahw.h>
31 * Zorro Expansion Devices
34 unsigned int zorro_num_autocon
;
35 struct zorro_dev_init zorro_autocon_init
[ZORRO_NUM_AUTO
] __initdata
;
36 struct zorro_dev
*zorro_autocon
;
45 struct zorro_dev devices
[];
53 struct zorro_dev
*zorro_find_device(zorro_id id
, struct zorro_dev
*from
)
57 if (!zorro_num_autocon
)
60 for (z
= from
? from
+1 : &zorro_autocon
[0];
61 z
< zorro_autocon
+zorro_num_autocon
;
63 if (id
== ZORRO_WILDCARD
|| id
== z
->id
)
67 EXPORT_SYMBOL(zorro_find_device
);
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.
80 * - SCSI DMA bounce buffers
82 * FIXME: use the normal resource management
85 DECLARE_BITMAP(zorro_unused_z2ram
, 128);
86 EXPORT_SYMBOL(zorro_unused_z2ram
);
89 static void __init
mark_region(unsigned long start
, unsigned long end
,
93 start
+= Z2RAM_CHUNKMASK
;
95 end
+= Z2RAM_CHUNKMASK
;
96 start
&= ~Z2RAM_CHUNKMASK
;
97 end
&= ~Z2RAM_CHUNKMASK
;
99 if (end
<= Z2RAM_START
|| start
>= Z2RAM_END
)
101 start
= start
< Z2RAM_START
? 0x00000000 : start
-Z2RAM_START
;
102 end
= end
> Z2RAM_END
? Z2RAM_SIZE
: end
-Z2RAM_START
;
103 while (start
< end
) {
104 u32 chunk
= start
>>Z2RAM_CHUNKSHIFT
;
107 set_bit(chunk
, zorro_unused_z2ram
);
109 clear_bit(chunk
, zorro_unused_z2ram
);
110 start
+= Z2RAM_CHUNKSIZE
;
115 static struct resource __init
*zorro_find_parent_resource(
116 struct platform_device
*bridge
, struct zorro_dev
*z
)
120 for (i
= 0; i
< bridge
->num_resources
; i
++) {
121 if (resource_contains(&bridge
->resource
[i
], &z
->resource
))
122 return &bridge
->resource
[i
];
125 return &iomem_resource
;
128 static int __init
amiga_zorro_probe(struct platform_device
*pdev
)
130 struct zorro_bus
*bus
;
131 struct zorro_dev_init
*zi
;
137 /* Initialize the Zorro bus */
138 bus
= kzalloc(struct_size(bus
, devices
, zorro_num_autocon
),
143 zorro_autocon
= bus
->devices
;
144 bus
->dev
.parent
= &pdev
->dev
;
145 dev_set_name(&bus
->dev
, zorro_bus_type
.name
);
146 error
= device_register(&bus
->dev
);
148 pr_err("Zorro: Error registering zorro_bus\n");
149 put_device(&bus
->dev
);
153 platform_set_drvdata(pdev
, bus
);
155 pr_info("Zorro: Probing AutoConfig expansion devices: %u device%s\n",
156 zorro_num_autocon
, str_plural(zorro_num_autocon
));
158 /* First identify all devices ... */
159 for (i
= 0; i
< zorro_num_autocon
; i
++) {
160 zi
= &zorro_autocon_init
[i
];
161 z
= &zorro_autocon
[i
];
164 z
->id
= (be16_to_cpu(z
->rom
.er_Manufacturer
) << 16) |
165 (z
->rom
.er_Product
<< 8);
166 if (z
->id
== ZORRO_PROD_GVP_EPC_BASE
) {
168 unsigned long magic
= zi
->boardaddr
+ 0x8000;
170 z
->id
|= *(u16
*)ZTWO_VADDR(magic
) & GVP_PRODMASK
;
172 z
->slotaddr
= zi
->slotaddr
;
173 z
->slotsize
= zi
->slotsize
;
174 sprintf(z
->name
, "Zorro device %08x", z
->id
);
175 zorro_name_device(z
);
176 z
->resource
= DEFINE_RES_MEM_NAMED(zi
->boardaddr
, zi
->boardsize
, z
->name
);
177 r
= zorro_find_parent_resource(pdev
, z
);
178 error
= request_resource(r
, &z
->resource
);
179 if (error
&& !(z
->rom
.er_Type
& ERTF_MEMLIST
))
181 "Address space collision on device %s %pR\n",
182 z
->name
, &z
->resource
);
183 z
->dev
.parent
= &bus
->dev
;
184 z
->dev
.bus
= &zorro_bus_type
;
186 switch (z
->rom
.er_Type
& ERT_TYPEMASK
) {
188 z
->dev
.coherent_dma_mask
= DMA_BIT_MASK(32);
193 z
->dev
.coherent_dma_mask
= DMA_BIT_MASK(24);
196 z
->dev
.dma_mask
= &z
->dev
.coherent_dma_mask
;
199 /* ... then register them */
200 for (i
= 0; i
< zorro_num_autocon
; i
++) {
201 z
= &zorro_autocon
[i
];
202 error
= device_register(&z
->dev
);
204 dev_err(&bus
->dev
, "Error registering device %s\n",
211 /* Mark all available Zorro II memory */
212 zorro_for_each_dev(z
) {
213 if (z
->rom
.er_Type
& ERTF_MEMLIST
)
214 mark_region(zorro_resource_start(z
),
215 zorro_resource_end(z
)+1, 1);
218 /* Unmark all used Zorro II memory */
219 for (i
= 0; i
< m68k_num_memory
; i
++)
220 if (m68k_memory
[i
].addr
< 16*1024*1024)
221 mark_region(m68k_memory
[i
].addr
,
222 m68k_memory
[i
].addr
+m68k_memory
[i
].size
,
228 static struct platform_driver amiga_zorro_driver
= {
230 .name
= "amiga-zorro",
234 static int __init
amiga_zorro_init(void)
236 return platform_driver_probe(&amiga_zorro_driver
, amiga_zorro_probe
);
239 module_init(amiga_zorro_init
);
241 MODULE_LICENSE("GPL");