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/module.h>
16 #include <linux/ioport.h>
17 #include <linux/init.h>
18 #include <linux/blkdev.h>
19 #include <linux/interrupt.h>
20 #include <linux/platform_device.h>
22 #include <asm/hwtest.h>
24 #include <asm/macints.h>
25 #include <asm/setup.h>
27 #include <scsi/scsi_host.h>
29 /* Definitions for the core NCR5380 driver. */
33 #define NCR5380_implementation_fields unsigned char *pdma_base
35 #define NCR5380_read(reg) macscsi_read(instance, reg)
36 #define NCR5380_write(reg, value) macscsi_write(instance, reg, value)
38 #define NCR5380_pread macscsi_pread
39 #define NCR5380_pwrite macscsi_pwrite
40 #define NCR5380_dma_xfer_len(instance, cmd, phase) (cmd->transfersize)
42 #define NCR5380_intr macscsi_intr
43 #define NCR5380_queue_command macscsi_queue_command
44 #define NCR5380_abort macscsi_abort
45 #define NCR5380_bus_reset macscsi_bus_reset
46 #define NCR5380_info macscsi_info
47 #define NCR5380_show_info macscsi_show_info
48 #define NCR5380_write_info macscsi_write_info
52 static int setup_can_queue
= -1;
53 module_param(setup_can_queue
, int, 0);
54 static int setup_cmd_per_lun
= -1;
55 module_param(setup_cmd_per_lun
, int, 0);
56 static int setup_sg_tablesize
= -1;
57 module_param(setup_sg_tablesize
, int, 0);
58 static int setup_use_pdma
= -1;
59 module_param(setup_use_pdma
, int, 0);
60 static int setup_use_tagged_queuing
= -1;
61 module_param(setup_use_tagged_queuing
, int, 0);
62 static int setup_hostid
= -1;
63 module_param(setup_hostid
, int, 0);
64 static int setup_toshiba_delay
= -1;
65 module_param(setup_toshiba_delay
, int, 0);
68 * NCR 5380 register access functions
71 static inline char macscsi_read(struct Scsi_Host
*instance
, int reg
)
73 return in_8(instance
->base
+ (reg
<< 4));
76 static inline void macscsi_write(struct Scsi_Host
*instance
, int reg
, int value
)
78 out_8(instance
->base
+ (reg
<< 4), value
);
82 static int __init
mac_scsi_setup(char *str
)
86 (void)get_options(str
, ARRAY_SIZE(ints
), ints
);
89 pr_err("Usage: mac5380=<can_queue>[,<cmd_per_lun>[,<sg_tablesize>[,<hostid>[,<use_tags>[,<use_pdma>[,<toshiba_delay>]]]]]]\n");
93 setup_can_queue
= ints
[1];
95 setup_cmd_per_lun
= ints
[2];
97 setup_sg_tablesize
= ints
[3];
99 setup_hostid
= ints
[4];
101 setup_use_tagged_queuing
= ints
[5];
103 setup_use_pdma
= ints
[6];
105 setup_toshiba_delay
= ints
[7];
109 __setup("mac5380=", mac_scsi_setup
);
114 Pseudo-DMA: (Ove Edlund)
115 The code attempts to catch bus errors that occur if one for example
116 "trips over the cable".
117 XXX: Since bus errors in the PDMA routines never happen on my
118 computer, the bus error code is untested.
119 If the code works as intended, a bus error results in Pseudo-DMA
120 being disabled, meaning that the driver switches to slow handshake.
121 If bus errors are NOT extremely rare, this has to be changed.
124 #define CP_IO_TO_MEM(s,d,len) \
125 __asm__ __volatile__ \
128 " move.w %1,%%d0\n" \
133 " 1: move.b (%0),(%1)+\n" \
134 " 2: dbf %%d0,1b\n" \
135 " move.w %2,%%d0\n" \
138 " 3: move.l (%0),(%1)+\n" \
139 "31: move.l (%0),(%1)+\n" \
140 "32: move.l (%0),(%1)+\n" \
141 "33: move.l (%0),(%1)+\n" \
142 "34: move.l (%0),(%1)+\n" \
143 "35: move.l (%0),(%1)+\n" \
144 "36: move.l (%0),(%1)+\n" \
145 "37: move.l (%0),(%1)+\n" \
146 " 4: dbf %%d0,3b\n" \
147 " move.w %2,%%d0\n" \
151 " 5: move.l (%0),(%1)+\n" \
152 " 6: dbf %%d0,5b\n" \
155 " 7: move.b (%0),(%1)+\n" \
157 " moveq.l #0, %2\n" \
159 ".section .fixup,\"ax\"\n" \
161 "90: moveq.l #1, %2\n" \
164 ".section __ex_table,\"a\"\n" \
178 : "=a"(s), "=a"(d), "=d"(len) \
179 : "0"(s), "1"(d), "2"(len) \
182 static int macscsi_pread(struct Scsi_Host
*instance
,
183 unsigned char *dst
, int len
)
185 struct NCR5380_hostdata
*hostdata
= shost_priv(instance
);
189 s
= hostdata
->pdma_base
+ (INPUT_DATA_REG
<< 4);
192 /* These conditions are derived from MacOS */
194 while (!(NCR5380_read(BUS_AND_STATUS_REG
) & BASR_DRQ
) &&
195 !(NCR5380_read(STATUS_REG
) & SR_REQ
))
198 if (!(NCR5380_read(BUS_AND_STATUS_REG
) & BASR_DRQ
) &&
199 (NCR5380_read(BUS_AND_STATUS_REG
) & BASR_PHASE_MATCH
)) {
200 pr_err("Error in macscsi_pread\n");
204 CP_IO_TO_MEM(s
, d
, len
);
207 pr_notice("Bus error in macscsi_pread\n");
215 #define CP_MEM_TO_IO(s,d,len) \
216 __asm__ __volatile__ \
219 " move.w %0,%%d0\n" \
224 " 1: move.b (%0)+,(%1)\n" \
225 " 2: dbf %%d0,1b\n" \
226 " move.w %2,%%d0\n" \
229 " 3: move.l (%0)+,(%1)\n" \
230 "31: move.l (%0)+,(%1)\n" \
231 "32: move.l (%0)+,(%1)\n" \
232 "33: move.l (%0)+,(%1)\n" \
233 "34: move.l (%0)+,(%1)\n" \
234 "35: move.l (%0)+,(%1)\n" \
235 "36: move.l (%0)+,(%1)\n" \
236 "37: move.l (%0)+,(%1)\n" \
237 " 4: dbf %%d0,3b\n" \
238 " move.w %2,%%d0\n" \
242 " 5: move.l (%0)+,(%1)\n" \
243 " 6: dbf %%d0,5b\n" \
246 " 7: move.b (%0)+,(%1)\n" \
248 " moveq.l #0, %2\n" \
250 ".section .fixup,\"ax\"\n" \
252 "90: moveq.l #1, %2\n" \
255 ".section __ex_table,\"a\"\n" \
269 : "=a"(s), "=a"(d), "=d"(len) \
270 : "0"(s), "1"(d), "2"(len) \
273 static int macscsi_pwrite(struct Scsi_Host
*instance
,
274 unsigned char *src
, int len
)
276 struct NCR5380_hostdata
*hostdata
= shost_priv(instance
);
281 d
= hostdata
->pdma_base
+ (OUTPUT_DATA_REG
<< 4);
283 /* These conditions are derived from MacOS */
285 while (!(NCR5380_read(BUS_AND_STATUS_REG
) & BASR_DRQ
) &&
286 (!(NCR5380_read(STATUS_REG
) & SR_REQ
) ||
287 (NCR5380_read(BUS_AND_STATUS_REG
) & BASR_PHASE_MATCH
)))
290 if (!(NCR5380_read(BUS_AND_STATUS_REG
) & BASR_DRQ
)) {
291 pr_err("Error in macscsi_pwrite\n");
295 CP_MEM_TO_IO(s
, d
, len
);
298 pr_notice("Bus error in macscsi_pwrite\n");
308 #define DRV_MODULE_NAME "mac_scsi"
309 #define PFX DRV_MODULE_NAME ": "
311 static struct scsi_host_template mac_scsi_template
= {
312 .module
= THIS_MODULE
,
313 .proc_name
= DRV_MODULE_NAME
,
314 .show_info
= macscsi_show_info
,
315 .write_info
= macscsi_write_info
,
316 .name
= "Macintosh NCR5380 SCSI",
317 .info
= macscsi_info
,
318 .queuecommand
= macscsi_queue_command
,
319 .eh_abort_handler
= macscsi_abort
,
320 .eh_bus_reset_handler
= macscsi_bus_reset
,
323 .sg_tablesize
= SG_ALL
,
325 .use_clustering
= DISABLE_CLUSTERING
,
326 .cmd_size
= NCR5380_CMD_SIZE
,
330 static int __init
mac_scsi_probe(struct platform_device
*pdev
)
332 struct Scsi_Host
*instance
;
335 struct resource
*irq
, *pio_mem
, *pdma_mem
= NULL
;
337 pio_mem
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
342 pdma_mem
= platform_get_resource(pdev
, IORESOURCE_MEM
, 1);
345 irq
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 0);
347 if (!hwreg_present((unsigned char *)pio_mem
->start
+
348 (STATUS_REG
<< 4))) {
349 pr_info(PFX
"no device detected at %pap\n", &pio_mem
->start
);
353 if (setup_can_queue
> 0)
354 mac_scsi_template
.can_queue
= setup_can_queue
;
355 if (setup_cmd_per_lun
> 0)
356 mac_scsi_template
.cmd_per_lun
= setup_cmd_per_lun
;
357 if (setup_sg_tablesize
>= 0)
358 mac_scsi_template
.sg_tablesize
= setup_sg_tablesize
;
359 if (setup_hostid
>= 0)
360 mac_scsi_template
.this_id
= setup_hostid
& 7;
361 if (setup_use_pdma
< 0)
364 instance
= scsi_host_alloc(&mac_scsi_template
,
365 sizeof(struct NCR5380_hostdata
));
369 instance
->base
= pio_mem
->start
;
371 instance
->irq
= irq
->start
;
373 instance
->irq
= NO_IRQ
;
375 if (pdma_mem
&& setup_use_pdma
) {
376 struct NCR5380_hostdata
*hostdata
= shost_priv(instance
);
378 hostdata
->pdma_base
= (unsigned char *)pdma_mem
->start
;
380 host_flags
|= FLAG_NO_PSEUDO_DMA
;
383 host_flags
|= setup_use_tagged_queuing
> 0 ? FLAG_TAGGED_QUEUING
: 0;
385 host_flags
|= setup_toshiba_delay
> 0 ? FLAG_TOSHIBA_DELAY
: 0;
387 error
= NCR5380_init(instance
, host_flags
);
391 if (instance
->irq
!= NO_IRQ
) {
392 error
= request_irq(instance
->irq
, macscsi_intr
, IRQF_SHARED
,
393 "NCR5380", instance
);
398 NCR5380_maybe_reset_bus(instance
);
400 error
= scsi_add_host(instance
, NULL
);
404 platform_set_drvdata(pdev
, instance
);
406 scsi_scan_host(instance
);
410 if (instance
->irq
!= NO_IRQ
)
411 free_irq(instance
->irq
, instance
);
413 NCR5380_exit(instance
);
415 scsi_host_put(instance
);
419 static int __exit
mac_scsi_remove(struct platform_device
*pdev
)
421 struct Scsi_Host
*instance
= platform_get_drvdata(pdev
);
423 scsi_remove_host(instance
);
424 if (instance
->irq
!= NO_IRQ
)
425 free_irq(instance
->irq
, instance
);
426 NCR5380_exit(instance
);
427 scsi_host_put(instance
);
431 static struct platform_driver mac_scsi_driver
= {
432 .remove
= __exit_p(mac_scsi_remove
),
434 .name
= DRV_MODULE_NAME
,
438 module_platform_driver_probe(mac_scsi_driver
, mac_scsi_probe
);
440 MODULE_ALIAS("platform:" DRV_MODULE_NAME
);
441 MODULE_LICENSE("GPL");