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