summaryrefslogtreecommitdiffstats
path: root/drivers/ata
diff options
context:
space:
mode:
authorMax Staudt <max@enpas.org>2019-08-23 06:49:11 -0400
committerJens Axboe <axboe@kernel.dk>2019-08-23 08:58:50 -0400
commit12ce6b0d21c2038ddae9da418aab198e284ad922 (patch)
treeb806bcaedb12eab3f4acc68e13620ab4d6f8e2ea /drivers/ata
parente21a712a9685488f5ce80495b37b9fdbe96c230d (diff)
ata/pata_buddha: Probe via modalias instead of initcall
Up until now, the pata_buddha driver would only check for cards on initcall time. Now, the kernel will call its probe function as soon as a compatible card is detected. v7: Removed suppress_bind_attrs that slipped in v6: Only do the drvdata workaround for X-Surf (remove breaks otherwise) Style v5: Remove module_exit(): There's no good way to handle the X-Surf hack. Also include a workaround to save X-Surf's drvdata in case zorro8390 is active. v4: Clean up pata_buddha_probe() by using ent->driver_data. Support X-Surf via late_initcall() v3: Clean up devm_*, implement device removal. v2: Rename 'zdev' to 'z' to make the patch easy to analyse with git diff --ignore-space-change Signed-off-by: Max Staudt <max@enpas.org> Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'drivers/ata')
-rw-r--r--drivers/ata/pata_buddha.c228
1 files changed, 135 insertions, 93 deletions
diff --git a/drivers/ata/pata_buddha.c b/drivers/ata/pata_buddha.c
index 11a8044ff633..27d4c417fc60 100644
--- a/drivers/ata/pata_buddha.c
+++ b/drivers/ata/pata_buddha.c
@@ -18,7 +18,9 @@
18#include <linux/kernel.h> 18#include <linux/kernel.h>
19#include <linux/libata.h> 19#include <linux/libata.h>
20#include <linux/mm.h> 20#include <linux/mm.h>
21#include <linux/mod_devicetable.h>
21#include <linux/module.h> 22#include <linux/module.h>
23#include <linux/types.h>
22#include <linux/zorro.h> 24#include <linux/zorro.h>
23#include <scsi/scsi_cmnd.h> 25#include <scsi/scsi_cmnd.h>
24#include <scsi/scsi_host.h> 26#include <scsi/scsi_host.h>
@@ -29,7 +31,7 @@
29#include <asm/setup.h> 31#include <asm/setup.h>
30 32
31#define DRV_NAME "pata_buddha" 33#define DRV_NAME "pata_buddha"
32#define DRV_VERSION "0.1.0" 34#define DRV_VERSION "0.1.1"
33 35
34#define BUDDHA_BASE1 0x800 36#define BUDDHA_BASE1 0x800
35#define BUDDHA_BASE2 0xa00 37#define BUDDHA_BASE2 0xa00
@@ -47,11 +49,11 @@ enum {
47 BOARD_XSURF 49 BOARD_XSURF
48}; 50};
49 51
50static unsigned int buddha_bases[3] __initdata = { 52static unsigned int buddha_bases[3] = {
51 BUDDHA_BASE1, BUDDHA_BASE2, BUDDHA_BASE3 53 BUDDHA_BASE1, BUDDHA_BASE2, BUDDHA_BASE3
52}; 54};
53 55
54static unsigned int xsurf_bases[2] __initdata = { 56static unsigned int xsurf_bases[2] = {
55 XSURF_BASE1, XSURF_BASE2 57 XSURF_BASE1, XSURF_BASE2
56}; 58};
57 59
@@ -145,111 +147,151 @@ static struct ata_port_operations pata_xsurf_ops = {
145 .set_mode = pata_buddha_set_mode, 147 .set_mode = pata_buddha_set_mode,
146}; 148};
147 149
148static int __init pata_buddha_init_one(void) 150static int pata_buddha_probe(struct zorro_dev *z,
151 const struct zorro_device_id *ent)
149{ 152{
150 struct zorro_dev *z = NULL; 153 static const char * const board_name[] = {
154 "Buddha", "Catweasel", "X-Surf"
155 };
156 struct ata_host *host;
157 void __iomem *buddha_board;
158 unsigned long board;
159 unsigned int type = ent->driver_data;
160 unsigned int nr_ports = (type == BOARD_CATWEASEL) ? 3 : 2;
161 void *old_drvdata;
162 int i;
163
164 dev_info(&z->dev, "%s IDE controller\n", board_name[type]);
165
166 board = z->resource.start;
167
168 if (type != BOARD_XSURF) {
169 if (!devm_request_mem_region(&z->dev,
170 board + BUDDHA_BASE1,
171 0x800, DRV_NAME))
172 return -ENXIO;
173 } else {
174 if (!devm_request_mem_region(&z->dev,
175 board + XSURF_BASE1,
176 0x1000, DRV_NAME))
177 return -ENXIO;
178 if (!devm_request_mem_region(&z->dev,
179 board + XSURF_BASE2,
180 0x1000, DRV_NAME)) {
181 }
182 }
183
184 /* Workaround for X-Surf: Save drvdata in case zorro8390 has set it */
185 if (type == BOARD_XSURF)
186 old_drvdata = dev_get_drvdata(&z->dev);
187
188 /* allocate host */
189 host = ata_host_alloc(&z->dev, nr_ports);
190 if (type == BOARD_XSURF)
191 dev_set_drvdata(&z->dev, old_drvdata);
192 if (!host)
193 return -ENXIO;
194
195 buddha_board = ZTWO_VADDR(board);
196
197 /* enable the board IRQ on Buddha/Catweasel */
198 if (type != BOARD_XSURF)
199 z_writeb(0, buddha_board + BUDDHA_IRQ_MR);
151 200
152 while ((z = zorro_find_device(ZORRO_WILDCARD, z))) { 201 for (i = 0; i < nr_ports; i++) {
153 static const char *board_name[] 202 struct ata_port *ap = host->ports[i];
154 = { "Buddha", "Catweasel", "X-Surf" }; 203 void __iomem *base, *irqport;
155 struct ata_host *host; 204 unsigned long ctl = 0;
156 void __iomem *buddha_board;
157 unsigned long board;
158 unsigned int type, nr_ports = 2;
159 int i;
160
161 if (z->id == ZORRO_PROD_INDIVIDUAL_COMPUTERS_BUDDHA) {
162 type = BOARD_BUDDHA;
163 } else if (z->id == ZORRO_PROD_INDIVIDUAL_COMPUTERS_CATWEASEL) {
164 type = BOARD_CATWEASEL;
165 nr_ports++;
166 } else if (z->id == ZORRO_PROD_INDIVIDUAL_COMPUTERS_X_SURF) {
167 type = BOARD_XSURF;
168 } else
169 continue;
170
171 dev_info(&z->dev, "%s IDE controller\n", board_name[type]);
172
173 board = z->resource.start;
174 205
175 if (type != BOARD_XSURF) { 206 if (type != BOARD_XSURF) {
176 if (!devm_request_mem_region(&z->dev, 207 ap->ops = &pata_buddha_ops;
177 board + BUDDHA_BASE1, 208 base = buddha_board + buddha_bases[i];
178 0x800, DRV_NAME)) 209 ctl = BUDDHA_CONTROL;
179 continue; 210 irqport = buddha_board + BUDDHA_IRQ + i * 0x40;
180 } else { 211 } else {
181 if (!devm_request_mem_region(&z->dev, 212 ap->ops = &pata_xsurf_ops;
182 board + XSURF_BASE1, 213 base = buddha_board + xsurf_bases[i];
183 0x1000, DRV_NAME)) 214 /* X-Surf has no CS1* (Control/AltStat) */
184 continue; 215 irqport = buddha_board + XSURF_IRQ;
185 if (!devm_request_mem_region(&z->dev,
186 board + XSURF_BASE2,
187 0x1000, DRV_NAME))
188 continue;
189 } 216 }
190 217
191 /* allocate host */ 218 ap->pio_mask = ATA_PIO4;
192 host = ata_host_alloc(&z->dev, nr_ports); 219 ap->flags |= ATA_FLAG_SLAVE_POSS | ATA_FLAG_NO_IORDY;
193 if (!host) 220
194 continue; 221 ap->ioaddr.data_addr = base;
195 222 ap->ioaddr.error_addr = base + 2 + 1 * 4;
196 buddha_board = ZTWO_VADDR(board); 223 ap->ioaddr.feature_addr = base + 2 + 1 * 4;
197 224 ap->ioaddr.nsect_addr = base + 2 + 2 * 4;
198 /* enable the board IRQ on Buddha/Catweasel */ 225 ap->ioaddr.lbal_addr = base + 2 + 3 * 4;
199 if (type != BOARD_XSURF) 226 ap->ioaddr.lbam_addr = base + 2 + 4 * 4;
200 z_writeb(0, buddha_board + BUDDHA_IRQ_MR); 227 ap->ioaddr.lbah_addr = base + 2 + 5 * 4;
201 228 ap->ioaddr.device_addr = base + 2 + 6 * 4;
202 for (i = 0; i < nr_ports; i++) { 229 ap->ioaddr.status_addr = base + 2 + 7 * 4;
203 struct ata_port *ap = host->ports[i]; 230 ap->ioaddr.command_addr = base + 2 + 7 * 4;
204 void __iomem *base, *irqport; 231
205 unsigned long ctl = 0; 232 if (ctl) {
206 233 ap->ioaddr.altstatus_addr = base + ctl;
207 if (type != BOARD_XSURF) { 234 ap->ioaddr.ctl_addr = base + ctl;
208 ap->ops = &pata_buddha_ops;
209 base = buddha_board + buddha_bases[i];
210 ctl = BUDDHA_CONTROL;
211 irqport = buddha_board + BUDDHA_IRQ + i * 0x40;
212 } else {
213 ap->ops = &pata_xsurf_ops;
214 base = buddha_board + xsurf_bases[i];
215 /* X-Surf has no CS1* (Control/AltStat) */
216 irqport = buddha_board + XSURF_IRQ;
217 }
218
219 ap->pio_mask = ATA_PIO4;
220 ap->flags |= ATA_FLAG_SLAVE_POSS | ATA_FLAG_NO_IORDY;
221
222 ap->ioaddr.data_addr = base;
223 ap->ioaddr.error_addr = base + 2 + 1 * 4;
224 ap->ioaddr.feature_addr = base + 2 + 1 * 4;
225 ap->ioaddr.nsect_addr = base + 2 + 2 * 4;
226 ap->ioaddr.lbal_addr = base + 2 + 3 * 4;
227 ap->ioaddr.lbam_addr = base + 2 + 4 * 4;
228 ap->ioaddr.lbah_addr = base + 2 + 5 * 4;
229 ap->ioaddr.device_addr = base + 2 + 6 * 4;
230 ap->ioaddr.status_addr = base + 2 + 7 * 4;
231 ap->ioaddr.command_addr = base + 2 + 7 * 4;
232
233 if (ctl) {
234 ap->ioaddr.altstatus_addr = base + ctl;
235 ap->ioaddr.ctl_addr = base + ctl;
236 }
237
238 ap->private_data = (void *)irqport;
239
240 ata_port_desc(ap, "cmd 0x%lx ctl 0x%lx", board,
241 ctl ? board + buddha_bases[i] + ctl : 0);
242 } 235 }
243 236
244 ata_host_activate(host, IRQ_AMIGA_PORTS, ata_sff_interrupt, 237 ap->private_data = (void *)irqport;
245 IRQF_SHARED, &pata_buddha_sht);
246 238
239 ata_port_desc(ap, "cmd 0x%lx ctl 0x%lx", board,
240 ctl ? board + buddha_bases[i] + ctl : 0);
247 } 241 }
248 242
243 ata_host_activate(host, IRQ_AMIGA_PORTS, ata_sff_interrupt,
244 IRQF_SHARED, &pata_buddha_sht);
245
249 return 0; 246 return 0;
250} 247}
251 248
252module_init(pata_buddha_init_one); 249static void pata_buddha_remove(struct zorro_dev *z)
250{
251 struct ata_host *host = dev_get_drvdata(&z->dev);
252
253 ata_host_detach(host);
254}
255
256static const struct zorro_device_id pata_buddha_zorro_tbl[] = {
257 { ZORRO_PROD_INDIVIDUAL_COMPUTERS_BUDDHA, BOARD_BUDDHA},
258 { ZORRO_PROD_INDIVIDUAL_COMPUTERS_CATWEASEL, BOARD_CATWEASEL},
259 { 0 }
260};
261MODULE_DEVICE_TABLE(zorro, pata_buddha_zorro_tbl);
262
263static struct zorro_driver pata_buddha_driver = {
264 .name = "pata_buddha",
265 .id_table = pata_buddha_zorro_tbl,
266 .probe = pata_buddha_probe,
267 .remove = pata_buddha_remove,
268};
269
270/*
271 * We cannot have a modalias for X-Surf boards, as it competes with the
272 * zorro8390 network driver. As a stopgap measure until we have proper
273 * MFD support for this board, we manually attach to it late after Zorro
274 * has enumerated its boards.
275 */
276static int __init pata_buddha_late_init(void)
277{
278 struct zorro_dev *z = NULL;
279
280 /* Auto-bind to regular boards */
281 zorro_register_driver(&pata_buddha_driver);
282
283 /* Manually bind to all X-Surf boards */
284 while ((z = zorro_find_device(ZORRO_PROD_INDIVIDUAL_COMPUTERS_X_SURF, z))) {
285 static struct zorro_device_id xsurf_ent = {
286 ZORRO_PROD_INDIVIDUAL_COMPUTERS_X_SURF, BOARD_XSURF
287 };
288
289 pata_buddha_probe(z, &xsurf_ent);
290 }
291
292 return 0;
293}
294late_initcall(pata_buddha_late_init);
253 295
254MODULE_AUTHOR("Bartlomiej Zolnierkiewicz"); 296MODULE_AUTHOR("Bartlomiej Zolnierkiewicz");
255MODULE_DESCRIPTION("low-level driver for Buddha/Catweasel/X-Surf PATA"); 297MODULE_DESCRIPTION("low-level driver for Buddha/Catweasel/X-Surf PATA");