2 * Generic Macintosh NCR5380 driver
4 * Copyright 1998, Michael Schmitz <mschmitz@lbl.gov>
6 * derived in part from:
9 * Generic Generic NCR5380 driver
11 * Copyright 1995, Russell King
14 #include <linux/types.h>
15 #include <linux/delay.h>
16 #include <linux/module.h>
17 #include <linux/ioport.h>
18 #include <linux/init.h>
19 #include <linux/blkdev.h>
20 #include <linux/interrupt.h>
21 #include <linux/platform_device.h>
23 #include <asm/hwtest.h>
25 #include <asm/macints.h>
26 #include <asm/setup.h>
28 #include <scsi/scsi_host.h>
30 /* Definitions for the core NCR5380 driver. */
34 #define NCR5380_implementation_fields unsigned char *pdma_base
36 #define NCR5380_read(reg) macscsi_read(instance, reg)
37 #define NCR5380_write(reg, value) macscsi_write(instance, reg, value)
39 #define NCR5380_pread macscsi_pread
40 #define NCR5380_pwrite macscsi_pwrite
41 #define NCR5380_dma_xfer_len(instance, cmd, phase) (cmd->transfersize)
43 #define NCR5380_intr macscsi_intr
44 #define NCR5380_queue_command macscsi_queue_command
45 #define NCR5380_abort macscsi_abort
46 #define NCR5380_bus_reset macscsi_bus_reset
47 #define NCR5380_info macscsi_info
48 #define NCR5380_show_info macscsi_show_info
49 #define NCR5380_write_info macscsi_write_info
53 static int setup_can_queue = -1;
54 module_param(setup_can_queue, int, 0);
55 static int setup_cmd_per_lun = -1;
56 module_param(setup_cmd_per_lun, int, 0);
57 static int setup_sg_tablesize = -1;
58 module_param(setup_sg_tablesize, int, 0);
59 static int setup_use_pdma = -1;
60 module_param(setup_use_pdma, int, 0);
61 static int setup_use_tagged_queuing = -1;
62 module_param(setup_use_tagged_queuing, int, 0);
63 static int setup_hostid = -1;
64 module_param(setup_hostid, int, 0);
65 static int setup_toshiba_delay = -1;
66 module_param(setup_toshiba_delay, int, 0);
69 * NCR 5380 register access functions
72 static inline char macscsi_read(struct Scsi_Host *instance, int reg)
74 return in_8(instance->base + (reg << 4));
77 static inline void macscsi_write(struct Scsi_Host *instance, int reg, int value)
79 out_8(instance->base + (reg << 4), value);
83 static int __init mac_scsi_setup(char *str)
87 (void)get_options(str, ARRAY_SIZE(ints), ints);
90 pr_err("Usage: mac5380=<can_queue>[,<cmd_per_lun>[,<sg_tablesize>[,<hostid>[,<use_tags>[,<use_pdma>[,<toshiba_delay>]]]]]]\n");
94 setup_can_queue = ints[1];
96 setup_cmd_per_lun = ints[2];
98 setup_sg_tablesize = ints[3];
100 setup_hostid = ints[4];
102 setup_use_tagged_queuing = ints[5];
104 setup_use_pdma = ints[6];
106 setup_toshiba_delay = ints[7];
110 __setup("mac5380=", mac_scsi_setup);
115 Pseudo-DMA: (Ove Edlund)
116 The code attempts to catch bus errors that occur if one for example
117 "trips over the cable".
118 XXX: Since bus errors in the PDMA routines never happen on my
119 computer, the bus error code is untested.
120 If the code works as intended, a bus error results in Pseudo-DMA
121 being disabled, meaning that the driver switches to slow handshake.
122 If bus errors are NOT extremely rare, this has to be changed.
125 #define CP_IO_TO_MEM(s,d,len) \
126 __asm__ __volatile__ \
129 " move.w %1,%%d0\n" \
134 " 1: move.b (%0),(%1)+\n" \
135 " 2: dbf %%d0,1b\n" \
136 " move.w %2,%%d0\n" \
139 " 3: move.l (%0),(%1)+\n" \
140 "31: move.l (%0),(%1)+\n" \
141 "32: move.l (%0),(%1)+\n" \
142 "33: move.l (%0),(%1)+\n" \
143 "34: move.l (%0),(%1)+\n" \
144 "35: move.l (%0),(%1)+\n" \
145 "36: move.l (%0),(%1)+\n" \
146 "37: move.l (%0),(%1)+\n" \
147 " 4: dbf %%d0,3b\n" \
148 " move.w %2,%%d0\n" \
152 " 5: move.l (%0),(%1)+\n" \
153 " 6: dbf %%d0,5b\n" \
156 " 7: move.b (%0),(%1)+\n" \
158 " moveq.l #0, %2\n" \
160 ".section .fixup,\"ax\"\n" \
162 "90: moveq.l #1, %2\n" \
165 ".section __ex_table,\"a\"\n" \
179 : "=a"(s), "=a"(d), "=d"(len) \
180 : "0"(s), "1"(d), "2"(len) \
183 static int macscsi_pread(struct Scsi_Host *instance,
184 unsigned char *dst, int len)
186 struct NCR5380_hostdata *hostdata = shost_priv(instance);
190 s = hostdata->pdma_base + (INPUT_DATA_REG << 4);
193 /* These conditions are derived from MacOS */
195 while (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_DRQ) &&
196 !(NCR5380_read(STATUS_REG) & SR_REQ))
199 if (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_DRQ) &&
200 (NCR5380_read(BUS_AND_STATUS_REG) & BASR_PHASE_MATCH)) {
201 pr_err("Error in macscsi_pread\n");
205 CP_IO_TO_MEM(s, d, len);
208 pr_notice("Bus error in macscsi_pread\n");
216 #define CP_MEM_TO_IO(s,d,len) \
217 __asm__ __volatile__ \
220 " move.w %0,%%d0\n" \
225 " 1: move.b (%0)+,(%1)\n" \
226 " 2: dbf %%d0,1b\n" \
227 " move.w %2,%%d0\n" \
230 " 3: move.l (%0)+,(%1)\n" \
231 "31: move.l (%0)+,(%1)\n" \
232 "32: move.l (%0)+,(%1)\n" \
233 "33: move.l (%0)+,(%1)\n" \
234 "34: move.l (%0)+,(%1)\n" \
235 "35: move.l (%0)+,(%1)\n" \
236 "36: move.l (%0)+,(%1)\n" \
237 "37: move.l (%0)+,(%1)\n" \
238 " 4: dbf %%d0,3b\n" \
239 " move.w %2,%%d0\n" \
243 " 5: move.l (%0)+,(%1)\n" \
244 " 6: dbf %%d0,5b\n" \
247 " 7: move.b (%0)+,(%1)\n" \
249 " moveq.l #0, %2\n" \
251 ".section .fixup,\"ax\"\n" \
253 "90: moveq.l #1, %2\n" \
256 ".section __ex_table,\"a\"\n" \
270 : "=a"(s), "=a"(d), "=d"(len) \
271 : "0"(s), "1"(d), "2"(len) \
274 static int macscsi_pwrite(struct Scsi_Host *instance,
275 unsigned char *src, int len)
277 struct NCR5380_hostdata *hostdata = shost_priv(instance);
282 d = hostdata->pdma_base + (OUTPUT_DATA_REG << 4);
284 /* These conditions are derived from MacOS */
286 while (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_DRQ) &&
287 (!(NCR5380_read(STATUS_REG) & SR_REQ) ||
288 (NCR5380_read(BUS_AND_STATUS_REG) & BASR_PHASE_MATCH)))
291 if (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_DRQ)) {
292 pr_err("Error in macscsi_pwrite\n");
296 CP_MEM_TO_IO(s, d, len);
299 pr_notice("Bus error in macscsi_pwrite\n");
309 #define DRV_MODULE_NAME "mac_scsi"
310 #define PFX DRV_MODULE_NAME ": "
312 static struct scsi_host_template mac_scsi_template = {
313 .module = THIS_MODULE,
314 .proc_name = DRV_MODULE_NAME,
315 .show_info = macscsi_show_info,
316 .write_info = macscsi_write_info,
317 .name = "Macintosh NCR5380 SCSI",
318 .info = macscsi_info,
319 .queuecommand = macscsi_queue_command,
320 .eh_abort_handler = macscsi_abort,
321 .eh_bus_reset_handler = macscsi_bus_reset,
324 .sg_tablesize = SG_ALL,
326 .use_clustering = DISABLE_CLUSTERING
329 static int __init mac_scsi_probe(struct platform_device *pdev)
331 struct Scsi_Host *instance;
334 struct resource *irq, *pio_mem, *pdma_mem = NULL;
336 pio_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
341 pdma_mem = platform_get_resource(pdev, IORESOURCE_MEM, 1);
344 irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
346 if (!hwreg_present((unsigned char *)pio_mem->start +
347 (STATUS_REG << 4))) {
348 pr_info(PFX "no device detected at %pap\n", &pio_mem->start);
352 if (setup_can_queue > 0)
353 mac_scsi_template.can_queue = setup_can_queue;
354 if (setup_cmd_per_lun > 0)
355 mac_scsi_template.cmd_per_lun = setup_cmd_per_lun;
356 if (setup_sg_tablesize >= 0)
357 mac_scsi_template.sg_tablesize = setup_sg_tablesize;
358 if (setup_hostid >= 0)
359 mac_scsi_template.this_id = setup_hostid & 7;
360 if (setup_use_pdma < 0)
363 instance = scsi_host_alloc(&mac_scsi_template,
364 sizeof(struct NCR5380_hostdata));
368 instance->base = pio_mem->start;
370 instance->irq = irq->start;
372 instance->irq = NO_IRQ;
374 if (pdma_mem && setup_use_pdma) {
375 struct NCR5380_hostdata *hostdata = shost_priv(instance);
377 hostdata->pdma_base = (unsigned char *)pdma_mem->start;
379 host_flags |= FLAG_NO_PSEUDO_DMA;
382 host_flags |= setup_use_tagged_queuing > 0 ? FLAG_TAGGED_QUEUING : 0;
384 host_flags |= setup_toshiba_delay > 0 ? FLAG_TOSHIBA_DELAY : 0;
386 error = NCR5380_init(instance, host_flags);
390 if (instance->irq != NO_IRQ) {
391 error = request_irq(instance->irq, macscsi_intr, IRQF_SHARED,
392 "NCR5380", instance);
397 NCR5380_maybe_reset_bus(instance);
399 error = scsi_add_host(instance, NULL);
403 platform_set_drvdata(pdev, instance);
405 scsi_scan_host(instance);
409 if (instance->irq != NO_IRQ)
410 free_irq(instance->irq, instance);
412 NCR5380_exit(instance);
414 scsi_host_put(instance);
418 static int __exit mac_scsi_remove(struct platform_device *pdev)
420 struct Scsi_Host *instance = platform_get_drvdata(pdev);
422 scsi_remove_host(instance);
423 if (instance->irq != NO_IRQ)
424 free_irq(instance->irq, instance);
425 NCR5380_exit(instance);
426 scsi_host_put(instance);
430 static struct platform_driver mac_scsi_driver = {
431 .remove = __exit_p(mac_scsi_remove),
433 .name = DRV_MODULE_NAME,
437 module_platform_driver_probe(mac_scsi_driver, mac_scsi_probe);
439 MODULE_ALIAS("platform:" DRV_MODULE_NAME);
440 MODULE_LICENSE("GPL");