diff options
author | Geert Uytterhoeven <geert@linux-m68k.org> | 2009-04-05 06:40:41 -0400 |
---|---|---|
committer | Geert Uytterhoeven <geert@linux-m68k.org> | 2010-05-17 15:37:42 -0400 |
commit | 0d305464aefff342c85b4db8b3d7a4345246e5a1 (patch) | |
tree | c3cd06f58d7cf126500258d0a8fc531bd3ed4da2 /drivers/zorro | |
parent | bf54a2b3c0dbf76136f00ff785bf6d8f6291311d (diff) |
m68k: amiga - Zorro host bridge platform device conversion
Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
Diffstat (limited to 'drivers/zorro')
-rw-r--r-- | drivers/zorro/proc.c | 6 | ||||
-rw-r--r-- | drivers/zorro/zorro.c | 243 |
2 files changed, 131 insertions, 118 deletions
diff --git a/drivers/zorro/proc.c b/drivers/zorro/proc.c index d47c47fc048..3c7046d7965 100644 --- a/drivers/zorro/proc.c +++ b/drivers/zorro/proc.c | |||
@@ -97,7 +97,7 @@ static void zorro_seq_stop(struct seq_file *m, void *v) | |||
97 | 97 | ||
98 | static int zorro_seq_show(struct seq_file *m, void *v) | 98 | static int zorro_seq_show(struct seq_file *m, void *v) |
99 | { | 99 | { |
100 | u_int slot = *(loff_t *)v; | 100 | unsigned int slot = *(loff_t *)v; |
101 | struct zorro_dev *z = &zorro_autocon[slot]; | 101 | struct zorro_dev *z = &zorro_autocon[slot]; |
102 | 102 | ||
103 | seq_printf(m, "%02x\t%08x\t%08lx\t%08lx\t%02x\n", slot, z->id, | 103 | seq_printf(m, "%02x\t%08x\t%08lx\t%08lx\t%02x\n", slot, z->id, |
@@ -129,7 +129,7 @@ static const struct file_operations zorro_devices_proc_fops = { | |||
129 | 129 | ||
130 | static struct proc_dir_entry *proc_bus_zorro_dir; | 130 | static struct proc_dir_entry *proc_bus_zorro_dir; |
131 | 131 | ||
132 | static int __init zorro_proc_attach_device(u_int slot) | 132 | static int __init zorro_proc_attach_device(unsigned int slot) |
133 | { | 133 | { |
134 | struct proc_dir_entry *entry; | 134 | struct proc_dir_entry *entry; |
135 | char name[4]; | 135 | char name[4]; |
@@ -146,7 +146,7 @@ static int __init zorro_proc_attach_device(u_int slot) | |||
146 | 146 | ||
147 | static int __init zorro_proc_init(void) | 147 | static int __init zorro_proc_init(void) |
148 | { | 148 | { |
149 | u_int slot; | 149 | unsigned int slot; |
150 | 150 | ||
151 | if (MACH_IS_AMIGA && AMIGAHW_PRESENT(ZORRO)) { | 151 | if (MACH_IS_AMIGA && AMIGAHW_PRESENT(ZORRO)) { |
152 | proc_bus_zorro_dir = proc_mkdir("bus/zorro", NULL); | 152 | proc_bus_zorro_dir = proc_mkdir("bus/zorro", NULL); |
diff --git a/drivers/zorro/zorro.c b/drivers/zorro/zorro.c index d45fb34e2d2..6455f3a244c 100644 --- a/drivers/zorro/zorro.c +++ b/drivers/zorro/zorro.c | |||
@@ -15,6 +15,8 @@ | |||
15 | #include <linux/zorro.h> | 15 | #include <linux/zorro.h> |
16 | #include <linux/bitops.h> | 16 | #include <linux/bitops.h> |
17 | #include <linux/string.h> | 17 | #include <linux/string.h> |
18 | #include <linux/platform_device.h> | ||
19 | #include <linux/slab.h> | ||
18 | 20 | ||
19 | #include <asm/setup.h> | 21 | #include <asm/setup.h> |
20 | #include <asm/amigahw.h> | 22 | #include <asm/amigahw.h> |
@@ -26,24 +28,17 @@ | |||
26 | * Zorro Expansion Devices | 28 | * Zorro Expansion Devices |
27 | */ | 29 | */ |
28 | 30 | ||
29 | u_int zorro_num_autocon = 0; | 31 | unsigned int zorro_num_autocon; |
30 | struct zorro_dev zorro_autocon[ZORRO_NUM_AUTO]; | 32 | struct zorro_dev zorro_autocon[ZORRO_NUM_AUTO]; |
31 | 33 | ||
32 | 34 | ||
33 | /* | 35 | /* |
34 | * Single Zorro bus | 36 | * Zorro bus |
35 | */ | 37 | */ |
36 | 38 | ||
37 | struct zorro_bus zorro_bus = {\ | 39 | struct zorro_bus { |
38 | .resources = { | 40 | struct list_head devices; /* list of devices on this bus */ |
39 | /* Zorro II regions (on Zorro II/III) */ | 41 | struct device dev; |
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 } | ||
45 | }, | ||
46 | .name = "Zorro bus" | ||
47 | }; | 42 | }; |
48 | 43 | ||
49 | 44 | ||
@@ -53,18 +48,19 @@ struct zorro_bus zorro_bus = {\ | |||
53 | 48 | ||
54 | struct zorro_dev *zorro_find_device(zorro_id id, struct zorro_dev *from) | 49 | struct zorro_dev *zorro_find_device(zorro_id id, struct zorro_dev *from) |
55 | { | 50 | { |
56 | struct zorro_dev *z; | 51 | struct zorro_dev *z; |
57 | 52 | ||
58 | if (!MACH_IS_AMIGA || !AMIGAHW_PRESENT(ZORRO)) | 53 | if (!zorro_num_autocon) |
59 | return NULL; | 54 | return NULL; |
60 | 55 | ||
61 | for (z = from ? from+1 : &zorro_autocon[0]; | 56 | for (z = from ? from+1 : &zorro_autocon[0]; |
62 | z < zorro_autocon+zorro_num_autocon; | 57 | z < zorro_autocon+zorro_num_autocon; |
63 | z++) | 58 | z++) |
64 | if (id == ZORRO_WILDCARD || id == z->id) | 59 | if (id == ZORRO_WILDCARD || id == z->id) |
65 | return z; | 60 | return z; |
66 | return NULL; | 61 | return NULL; |
67 | } | 62 | } |
63 | EXPORT_SYMBOL(zorro_find_device); | ||
68 | 64 | ||
69 | 65 | ||
70 | /* | 66 | /* |
@@ -83,121 +79,138 @@ struct zorro_dev *zorro_find_device(zorro_id id, struct zorro_dev *from) | |||
83 | */ | 79 | */ |
84 | 80 | ||
85 | DECLARE_BITMAP(zorro_unused_z2ram, 128); | 81 | DECLARE_BITMAP(zorro_unused_z2ram, 128); |
82 | EXPORT_SYMBOL(zorro_unused_z2ram); | ||
86 | 83 | ||
87 | 84 | ||
88 | static void __init mark_region(unsigned long start, unsigned long end, | 85 | static void __init mark_region(unsigned long start, unsigned long end, |
89 | int flag) | 86 | int flag) |
90 | { | 87 | { |
91 | if (flag) | ||
92 | start += Z2RAM_CHUNKMASK; | ||
93 | else | ||
94 | end += Z2RAM_CHUNKMASK; | ||
95 | start &= ~Z2RAM_CHUNKMASK; | ||
96 | end &= ~Z2RAM_CHUNKMASK; | ||
97 | |||
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) | 88 | if (flag) |
105 | set_bit(chunk, zorro_unused_z2ram); | 89 | start += Z2RAM_CHUNKMASK; |
106 | else | 90 | else |
107 | clear_bit(chunk, zorro_unused_z2ram); | 91 | end += Z2RAM_CHUNKMASK; |
108 | start += Z2RAM_CHUNKSIZE; | 92 | start &= ~Z2RAM_CHUNKMASK; |
109 | } | 93 | end &= ~Z2RAM_CHUNKMASK; |
94 | |||
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; | ||
106 | } | ||
110 | } | 107 | } |
111 | 108 | ||
112 | 109 | ||
113 | static struct resource __init *zorro_find_parent_resource(struct zorro_dev *z) | 110 | static struct resource __init *zorro_find_parent_resource( |
111 | struct platform_device *bridge, struct zorro_dev *z) | ||
114 | { | 112 | { |
115 | int i; | 113 | int i; |
116 | 114 | ||
117 | for (i = 0; i < zorro_bus.num_resources; i++) | 115 | for (i = 0; i < bridge->num_resources; i++) { |
118 | if (zorro_resource_start(z) >= zorro_bus.resources[i].start && | 116 | struct resource *r = &bridge->resource[i]; |
119 | zorro_resource_end(z) <= zorro_bus.resources[i].end) | 117 | if (zorro_resource_start(z) >= r->start && |
120 | return &zorro_bus.resources[i]; | 118 | zorro_resource_end(z) <= r->end) |
121 | return &iomem_resource; | 119 | return r; |
120 | } | ||
121 | return &iomem_resource; | ||
122 | } | 122 | } |
123 | 123 | ||
124 | 124 | ||
125 | /* | ||
126 | * Initialization | ||
127 | */ | ||
128 | 125 | ||
129 | static int __init zorro_init(void) | 126 | static int __init amiga_zorro_probe(struct platform_device *pdev) |
130 | { | 127 | { |
131 | struct zorro_dev *z; | 128 | struct zorro_bus *bus; |
132 | unsigned int i; | 129 | struct zorro_dev *z; |
133 | int error; | 130 | struct resource *r; |
134 | 131 | unsigned int i; | |
135 | if (!MACH_IS_AMIGA || !AMIGAHW_PRESENT(ZORRO)) | 132 | int error; |
136 | return 0; | 133 | |
137 | 134 | /* Initialize the Zorro bus */ | |
138 | pr_info("Zorro: Probing AutoConfig expansion devices: %d device%s\n", | 135 | bus = kzalloc(sizeof(*bus), GFP_KERNEL); |
139 | zorro_num_autocon, zorro_num_autocon == 1 ? "" : "s"); | 136 | if (!bus) |
140 | 137 | return -ENOMEM; | |
141 | /* Initialize the Zorro bus */ | 138 | |
142 | INIT_LIST_HEAD(&zorro_bus.devices); | 139 | INIT_LIST_HEAD(&bus->devices); |
143 | dev_set_name(&zorro_bus.dev, "zorro"); | 140 | bus->dev.parent = &pdev->dev; |
144 | error = device_register(&zorro_bus.dev); | 141 | dev_set_name(&bus->dev, "zorro"); |
145 | if (error) { | 142 | error = device_register(&bus->dev); |
146 | pr_err("Zorro: Error registering zorro_bus\n"); | ||
147 | return error; | ||
148 | } | ||
149 | |||
150 | /* Request the resources */ | ||
151 | zorro_bus.num_resources = AMIGAHW_PRESENT(ZORRO3) ? 4 : 2; | ||
152 | for (i = 0; i < zorro_bus.num_resources; i++) | ||
153 | request_resource(&iomem_resource, &zorro_bus.resources[i]); | ||
154 | |||
155 | /* Register all devices */ | ||
156 | for (i = 0; i < zorro_num_autocon; i++) { | ||
157 | z = &zorro_autocon[i]; | ||
158 | z->id = (z->rom.er_Manufacturer<<16) | (z->rom.er_Product<<8); | ||
159 | if (z->id == ZORRO_PROD_GVP_EPC_BASE) { | ||
160 | /* GVP quirk */ | ||
161 | unsigned long magic = zorro_resource_start(z)+0x8000; | ||
162 | z->id |= *(u16 *)ZTWO_VADDR(magic) & GVP_PRODMASK; | ||
163 | } | ||
164 | sprintf(z->name, "Zorro device %08x", z->id); | ||
165 | zorro_name_device(z); | ||
166 | z->resource.name = z->name; | ||
167 | if (request_resource(zorro_find_parent_resource(z), &z->resource)) | ||
168 | pr_err("Zorro: Address space collision on device %s %pR\n", | ||
169 | z->name, &z->resource); | ||
170 | dev_set_name(&z->dev, "%02x", i); | ||
171 | z->dev.parent = &zorro_bus.dev; | ||
172 | z->dev.bus = &zorro_bus_type; | ||
173 | error = device_register(&z->dev); | ||
174 | if (error) { | 143 | if (error) { |
175 | pr_err("Zorro: Error registering device %s\n", z->name); | 144 | pr_err("Zorro: Error registering zorro_bus\n"); |
176 | continue; | 145 | kfree(bus); |
146 | return error; | ||
177 | } | 147 | } |
178 | error = zorro_create_sysfs_dev_files(z); | 148 | platform_set_drvdata(pdev, bus); |
179 | if (error) | 149 | |
180 | dev_err(&z->dev, "Error creating sysfs files\n"); | 150 | /* Register all devices */ |
181 | } | 151 | pr_info("Zorro: Probing AutoConfig expansion devices: %u device%s\n", |
182 | 152 | zorro_num_autocon, zorro_num_autocon == 1 ? "" : "s"); | |
183 | /* Mark all available Zorro II memory */ | 153 | |
184 | zorro_for_each_dev(z) { | 154 | for (i = 0; i < zorro_num_autocon; i++) { |
185 | if (z->rom.er_Type & ERTF_MEMLIST) | 155 | z = &zorro_autocon[i]; |
186 | mark_region(zorro_resource_start(z), zorro_resource_end(z)+1, 1); | 156 | z->id = (z->rom.er_Manufacturer<<16) | (z->rom.er_Product<<8); |
187 | } | 157 | if (z->id == ZORRO_PROD_GVP_EPC_BASE) { |
188 | 158 | /* GVP quirk */ | |
189 | /* Unmark all used Zorro II memory */ | 159 | unsigned long magic = zorro_resource_start(z)+0x8000; |
190 | for (i = 0; i < m68k_num_memory; i++) | 160 | z->id |= *(u16 *)ZTWO_VADDR(magic) & GVP_PRODMASK; |
191 | if (m68k_memory[i].addr < 16*1024*1024) | 161 | } |
192 | mark_region(m68k_memory[i].addr, | 162 | sprintf(z->name, "Zorro device %08x", z->id); |
193 | m68k_memory[i].addr+m68k_memory[i].size, 0); | 163 | zorro_name_device(z); |
194 | 164 | z->resource.name = z->name; | |
195 | return 0; | 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 | } | ||
184 | |||
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; | ||
196 | } | 200 | } |
197 | 201 | ||
198 | subsys_initcall(zorro_init); | 202 | static struct platform_driver amiga_zorro_driver = { |
203 | .driver = { | ||
204 | .name = "amiga-zorro", | ||
205 | .owner = THIS_MODULE, | ||
206 | }, | ||
207 | }; | ||
199 | 208 | ||
200 | EXPORT_SYMBOL(zorro_find_device); | 209 | static int __init amiga_zorro_init(void) |
201 | EXPORT_SYMBOL(zorro_unused_z2ram); | 210 | { |
211 | return platform_driver_probe(&amiga_zorro_driver, amiga_zorro_probe); | ||
212 | } | ||
213 | |||
214 | module_init(amiga_zorro_init); | ||
202 | 215 | ||
203 | MODULE_LICENSE("GPL"); | 216 | MODULE_LICENSE("GPL"); |