Commit 0d305464aefff342c85b4db8b3d7a4345246e5a1

Authored by Geert Uytterhoeven
1 parent bf54a2b3c0

m68k: amiga - Zorro host bridge platform device conversion

Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>

Showing 5 changed files with 190 additions and 128 deletions Side-by-side Diff

arch/m68k/amiga/Makefile
... ... @@ -2,7 +2,7 @@
2 2 # Makefile for Linux arch/m68k/amiga source directory
3 3 #
4 4  
5   -obj-y := config.o amiints.o cia.o chipram.o amisound.o
  5 +obj-y := config.o amiints.o cia.o chipram.o amisound.o platform.o
6 6  
7 7 obj-$(CONFIG_AMIGA_PCMCIA) += pcmcia.o
arch/m68k/amiga/platform.c
  1 +/*
  2 + * Copyright (C) 2007-2009 Geert Uytterhoeven
  3 + *
  4 + * This file is subject to the terms and conditions of the GNU General Public
  5 + * License. See the file COPYING in the main directory of this archive
  6 + * for more details.
  7 + */
  8 +
  9 +#include <linux/init.h>
  10 +#include <linux/platform_device.h>
  11 +#include <linux/zorro.h>
  12 +
  13 +#include <asm/amigahw.h>
  14 +
  15 +
  16 +#ifdef CONFIG_ZORRO
  17 +
  18 +static const struct resource zorro_resources[] __initconst = {
  19 + /* Zorro II regions (on Zorro II/III) */
  20 + {
  21 + .name = "Zorro II exp",
  22 + .start = 0x00e80000,
  23 + .end = 0x00efffff,
  24 + .flags = IORESOURCE_MEM,
  25 + }, {
  26 + .name = "Zorro II mem",
  27 + .start = 0x00200000,
  28 + .end = 0x009fffff,
  29 + .flags = IORESOURCE_MEM,
  30 + },
  31 + /* Zorro III regions (on Zorro III only) */
  32 + {
  33 + .name = "Zorro III exp",
  34 + .start = 0xff000000,
  35 + .end = 0xffffffff,
  36 + .flags = IORESOURCE_MEM,
  37 + }, {
  38 + .name = "Zorro III cfg",
  39 + .start = 0x40000000,
  40 + .end = 0x7fffffff,
  41 + .flags = IORESOURCE_MEM,
  42 + }
  43 +};
  44 +
  45 +
  46 +static int __init amiga_init_bus(void)
  47 +{
  48 + if (!MACH_IS_AMIGA || !AMIGAHW_PRESENT(ZORRO))
  49 + return -ENODEV;
  50 +
  51 + platform_device_register_simple("amiga-zorro", -1, zorro_resources,
  52 + AMIGAHW_PRESENT(ZORRO3) ? 4 : 2);
  53 + return 0;
  54 +}
  55 +
  56 +subsys_initcall(amiga_init_bus);
  57 +
  58 +#endif /* CONFIG_ZORRO */
drivers/zorro/proc.c
... ... @@ -97,7 +97,7 @@
97 97  
98 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 101 struct zorro_dev *z = &zorro_autocon[slot];
102 102  
103 103 seq_printf(m, "%02x\t%08x\t%08lx\t%08lx\t%02x\n", slot, z->id,
... ... @@ -129,7 +129,7 @@
129 129  
130 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 134 struct proc_dir_entry *entry;
135 135 char name[4];
... ... @@ -146,7 +146,7 @@
146 146  
147 147 static int __init zorro_proc_init(void)
148 148 {
149   - u_int slot;
  149 + unsigned int slot;
150 150  
151 151 if (MACH_IS_AMIGA && AMIGAHW_PRESENT(ZORRO)) {
152 152 proc_bus_zorro_dir = proc_mkdir("bus/zorro", NULL);
drivers/zorro/zorro.c
... ... @@ -15,6 +15,8 @@
15 15 #include <linux/zorro.h>
16 16 #include <linux/bitops.h>
17 17 #include <linux/string.h>
  18 +#include <linux/platform_device.h>
  19 +#include <linux/slab.h>
18 20  
19 21 #include <asm/setup.h>
20 22 #include <asm/amigahw.h>
21 23  
22 24  
... ... @@ -26,24 +28,17 @@
26 28 * Zorro Expansion Devices
27 29 */
28 30  
29   -u_int zorro_num_autocon = 0;
  31 +unsigned int zorro_num_autocon;
30 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 = {\
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 }
45   - },
46   - .name = "Zorro bus"
  39 +struct zorro_bus {
  40 + struct list_head devices; /* list of devices on this bus */
  41 + struct device dev;
47 42 };
48 43  
49 44  
50 45  
51 46  
52 47  
... ... @@ -53,18 +48,19 @@
53 48  
54 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))
59   - return NULL;
  53 + if (!zorro_num_autocon)
  54 + return NULL;
60 55  
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;
  56 + for (z = from ? from+1 : &zorro_autocon[0];
  57 + z < zorro_autocon+zorro_num_autocon;
  58 + z++)
  59 + if (id == ZORRO_WILDCARD || id == z->id)
  60 + return z;
  61 + return NULL;
67 62 }
  63 +EXPORT_SYMBOL(zorro_find_device);
68 64  
69 65  
70 66 /*
71 67  
72 68  
73 69  
74 70  
75 71  
76 72  
77 73  
78 74  
79 75  
80 76  
81 77  
82 78  
83 79  
84 80  
85 81  
86 82  
87 83  
88 84  
89 85  
... ... @@ -83,122 +79,139 @@
83 79 */
84 80  
85 81 DECLARE_BITMAP(zorro_unused_z2ram, 128);
  82 +EXPORT_SYMBOL(zorro_unused_z2ram);
86 83  
87 84  
88 85 static void __init mark_region(unsigned long start, unsigned long end,
89 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 88 if (flag)
105   - set_bit(chunk, zorro_unused_z2ram);
  89 + start += Z2RAM_CHUNKMASK;
106 90 else
107   - clear_bit(chunk, zorro_unused_z2ram);
108   - start += Z2RAM_CHUNKSIZE;
109   - }
  91 + end += Z2RAM_CHUNKMASK;
  92 + start &= ~Z2RAM_CHUNKMASK;
  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++)
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;
  115 + for (i = 0; i < bridge->num_resources; i++) {
  116 + struct resource *r = &bridge->resource[i];
  117 + if (zorro_resource_start(z) >= r->start &&
  118 + zorro_resource_end(z) <= r->end)
  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;
132   - unsigned int i;
133   - int error;
  128 + struct zorro_bus *bus;
  129 + struct zorro_dev *z;
  130 + struct resource *r;
  131 + unsigned int i;
  132 + int error;
134 133  
135   - if (!MACH_IS_AMIGA || !AMIGAHW_PRESENT(ZORRO))
136   - return 0;
  134 + /* Initialize the Zorro bus */
  135 + bus = kzalloc(sizeof(*bus), GFP_KERNEL);
  136 + if (!bus)
  137 + return -ENOMEM;
137 138  
138   - pr_info("Zorro: Probing AutoConfig expansion devices: %d device%s\n",
139   - zorro_num_autocon, zorro_num_autocon == 1 ? "" : "s");
  139 + INIT_LIST_HEAD(&bus->devices);
  140 + bus->dev.parent = &pdev->dev;
  141 + dev_set_name(&bus->dev, "zorro");
  142 + error = device_register(&bus->dev);
  143 + if (error) {
  144 + pr_err("Zorro: Error registering zorro_bus\n");
  145 + kfree(bus);
  146 + return error;
  147 + }
  148 + platform_set_drvdata(pdev, bus);
140 149  
141   - /* Initialize the Zorro bus */
142   - INIT_LIST_HEAD(&zorro_bus.devices);
143   - dev_set_name(&zorro_bus.dev, "zorro");
144   - error = device_register(&zorro_bus.dev);
145   - if (error) {
146   - pr_err("Zorro: Error registering zorro_bus\n");
147   - return error;
148   - }
  150 + /* Register all devices */
  151 + pr_info("Zorro: Probing AutoConfig expansion devices: %u device%s\n",
  152 + zorro_num_autocon, zorro_num_autocon == 1 ? "" : "s");
149 153  
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 + for (i = 0; i < zorro_num_autocon; i++) {
  155 + z = &zorro_autocon[i];
  156 + z->id = (z->rom.er_Manufacturer<<16) | (z->rom.er_Product<<8);
  157 + if (z->id == ZORRO_PROD_GVP_EPC_BASE) {
  158 + /* GVP quirk */
  159 + unsigned long magic = zorro_resource_start(z)+0x8000;
  160 + z->id |= *(u16 *)ZTWO_VADDR(magic) & GVP_PRODMASK;
  161 + }
  162 + sprintf(z->name, "Zorro device %08x", z->id);
  163 + zorro_name_device(z);
  164 + z->resource.name = z->name;
  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 + }
154 184  
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;
  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);
163 190 }
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) {
175   - pr_err("Zorro: Error registering device %s\n", z->name);
176   - continue;
177   - }
178   - error = zorro_create_sysfs_dev_files(z);
179   - if (error)
180   - dev_err(&z->dev, "Error creating sysfs files\n");
181   - }
182 191  
183   - /* Mark all available Zorro II memory */
184   - zorro_for_each_dev(z) {
185   - if (z->rom.er_Type & ERTF_MEMLIST)
186   - mark_region(zorro_resource_start(z), zorro_resource_end(z)+1, 1);
187   - }
  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);
188 198  
189   - /* Unmark all used Zorro II memory */
190   - for (i = 0; i < m68k_num_memory; i++)
191   - if (m68k_memory[i].addr < 16*1024*1024)
192   - mark_region(m68k_memory[i].addr,
193   - m68k_memory[i].addr+m68k_memory[i].size, 0);
194   -
195   - return 0;
  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);
201   -EXPORT_SYMBOL(zorro_unused_z2ram);
  209 +static int __init amiga_zorro_init(void)
  210 +{
  211 + return platform_driver_probe(&amiga_zorro_driver, amiga_zorro_probe);
  212 +}
  213 +
  214 +module_init(amiga_zorro_init);
202 215  
203 216 MODULE_LICENSE("GPL");
include/linux/zorro.h
... ... @@ -141,15 +141,6 @@
141 141 * Zorro bus
142 142 */
143 143  
144   -struct zorro_bus {
145   - struct list_head devices; /* list of devices on this bus */
146   - unsigned int num_resources; /* number of resources */
147   - struct resource resources[4]; /* address space routed to this bus */
148   - struct device dev;
149   - char name[10];
150   -};
151   -
152   -extern struct zorro_bus zorro_bus; /* single Zorro bus */
153 144 extern struct bus_type zorro_bus_type;
154 145  
155 146