blob: a590089b9397b3fedc619dd83f7bc91285e03065 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Generic Macintosh NCR5380 driver
3 *
4 * Copyright 1998, Michael Schmitz <mschmitz@lbl.gov>
5 *
6 * derived in part from:
7 */
8/*
9 * Generic Generic NCR5380 driver
10 *
11 * Copyright 1995, Russell King
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 */
13
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/ioport.h>
17#include <linux/init.h>
18#include <linux/blkdev.h>
19#include <linux/interrupt.h>
Finn Thaincbad48d2014-11-12 16:12:07 +110020#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
Finn Thaincbad48d2014-11-12 16:12:07 +110022#include <asm/hwtest.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <asm/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <asm/macints.h>
Finn Thaincbad48d2014-11-12 16:12:07 +110025#include <asm/setup.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <scsi/scsi_host.h>
Finn Thain92de3832014-11-12 16:12:04 +110028
29/* Definitions for the core NCR5380 driver. */
Boaz Harroshe744fde2007-10-16 10:25:01 +020030
Finn Thain3a0f64b2016-03-23 21:10:31 +110031#define NCR5380_implementation_fields unsigned char *pdma_base; \
32 int pdma_residual
Finn Thain92de3832014-11-12 16:12:04 +110033
Finn Thain54d8fe42016-01-03 16:05:06 +110034#define NCR5380_read(reg) macscsi_read(instance, reg)
35#define NCR5380_write(reg, value) macscsi_write(instance, reg, value)
Finn Thain92de3832014-11-12 16:12:04 +110036
Finn Thain7e9ec8d2016-03-23 21:10:11 +110037#define NCR5380_dma_xfer_len(instance, cmd, phase) \
38 macscsi_dma_xfer_len(instance, cmd)
Finn Thain6c4b88c2016-03-23 21:10:17 +110039#define NCR5380_dma_recv_setup macscsi_pread
40#define NCR5380_dma_send_setup macscsi_pwrite
Finn Thain3a0f64b2016-03-23 21:10:31 +110041#define NCR5380_dma_residual(instance) (hostdata->pdma_residual)
Finn Thain92de3832014-11-12 16:12:04 +110042
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
Finn Thain92de3832014-11-12 16:12:04 +110048
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include "NCR5380.h"
50
Linus Torvalds1da177e2005-04-16 15:20:36 -070051static int setup_can_queue = -1;
Finn Thain6e9ae6d2014-11-12 16:12:05 +110052module_param(setup_can_queue, int, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070053static int setup_cmd_per_lun = -1;
Finn Thain6e9ae6d2014-11-12 16:12:05 +110054module_param(setup_cmd_per_lun, int, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070055static int setup_sg_tablesize = -1;
Finn Thain6e9ae6d2014-11-12 16:12:05 +110056module_param(setup_sg_tablesize, int, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070057static int setup_use_pdma = -1;
Finn Thain6e9ae6d2014-11-12 16:12:05 +110058module_param(setup_use_pdma, int, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070059static int setup_hostid = -1;
Finn Thain6e9ae6d2014-11-12 16:12:05 +110060module_param(setup_hostid, int, 0);
Finn Thain9c3f0e22016-01-03 16:05:11 +110061static int setup_toshiba_delay = -1;
62module_param(setup_toshiba_delay, int, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
Linus Torvalds1da177e2005-04-16 15:20:36 -070064/*
65 * NCR 5380 register access functions
66 */
67
Finn Thaincbad48d2014-11-12 16:12:07 +110068static inline char macscsi_read(struct Scsi_Host *instance, int reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -070069{
Finn Thaincbad48d2014-11-12 16:12:07 +110070 return in_8(instance->base + (reg << 4));
Linus Torvalds1da177e2005-04-16 15:20:36 -070071}
72
Finn Thaincbad48d2014-11-12 16:12:07 +110073static inline void macscsi_write(struct Scsi_Host *instance, int reg, int value)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074{
Finn Thaincbad48d2014-11-12 16:12:07 +110075 out_8(instance->base + (reg << 4), value);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076}
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
Finn Thain6e9ae6d2014-11-12 16:12:05 +110078#ifndef MODULE
79static int __init mac_scsi_setup(char *str)
80{
Finn Thain9c3f0e22016-01-03 16:05:11 +110081 int ints[8];
Finn Thain6e9ae6d2014-11-12 16:12:05 +110082
83 (void)get_options(str, ARRAY_SIZE(ints), ints);
84
Finn Thain9c3f0e22016-01-03 16:05:11 +110085 if (ints[0] < 1) {
86 pr_err("Usage: mac5380=<can_queue>[,<cmd_per_lun>[,<sg_tablesize>[,<hostid>[,<use_tags>[,<use_pdma>[,<toshiba_delay>]]]]]]\n");
Finn Thain6e9ae6d2014-11-12 16:12:05 +110087 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 }
Finn Thain6e9ae6d2014-11-12 16:12:05 +110089 if (ints[0] >= 1)
90 setup_can_queue = ints[1];
91 if (ints[0] >= 2)
92 setup_cmd_per_lun = ints[2];
93 if (ints[0] >= 3)
94 setup_sg_tablesize = ints[3];
95 if (ints[0] >= 4)
96 setup_hostid = ints[4];
Finn Thainc4ec6f92016-03-23 21:10:22 +110097 /* ints[5] (use_tagged_queuing) is ignored */
Finn Thain6e9ae6d2014-11-12 16:12:05 +110098 if (ints[0] >= 6)
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 setup_use_pdma = ints[6];
Finn Thain9c3f0e22016-01-03 16:05:11 +1100100 if (ints[0] >= 7)
101 setup_toshiba_delay = ints[7];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 return 1;
103}
104
105__setup("mac5380=", mac_scsi_setup);
Finn Thain6e9ae6d2014-11-12 16:12:05 +1100106#endif /* !MODULE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
Finn Thain3a0f64b2016-03-23 21:10:31 +1100108/* Pseudo DMA asm originally by Ove Edlund */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
Finn Thain3a0f64b2016-03-23 21:10:31 +1100110#define CP_IO_TO_MEM(s,d,n) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111__asm__ __volatile__ \
112 (" cmp.w #4,%2\n" \
113 " bls 8f\n" \
114 " move.w %1,%%d0\n" \
115 " neg.b %%d0\n" \
116 " and.w #3,%%d0\n" \
117 " sub.w %%d0,%2\n" \
118 " bra 2f\n" \
119 " 1: move.b (%0),(%1)+\n" \
120 " 2: dbf %%d0,1b\n" \
121 " move.w %2,%%d0\n" \
122 " lsr.w #5,%%d0\n" \
123 " bra 4f\n" \
124 " 3: move.l (%0),(%1)+\n" \
125 "31: move.l (%0),(%1)+\n" \
126 "32: move.l (%0),(%1)+\n" \
127 "33: move.l (%0),(%1)+\n" \
128 "34: move.l (%0),(%1)+\n" \
129 "35: move.l (%0),(%1)+\n" \
130 "36: move.l (%0),(%1)+\n" \
131 "37: move.l (%0),(%1)+\n" \
132 " 4: dbf %%d0,3b\n" \
133 " move.w %2,%%d0\n" \
134 " lsr.w #2,%%d0\n" \
135 " and.w #7,%%d0\n" \
136 " bra 6f\n" \
137 " 5: move.l (%0),(%1)+\n" \
138 " 6: dbf %%d0,5b\n" \
139 " and.w #3,%2\n" \
140 " bra 8f\n" \
141 " 7: move.b (%0),(%1)+\n" \
142 " 8: dbf %2,7b\n" \
143 " moveq.l #0, %2\n" \
144 " 9: \n" \
145 ".section .fixup,\"ax\"\n" \
146 " .even\n" \
Finn Thain3a0f64b2016-03-23 21:10:31 +1100147 "91: moveq.l #1, %2\n" \
148 " jra 9b\n" \
149 "94: moveq.l #4, %2\n" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 " jra 9b\n" \
151 ".previous\n" \
152 ".section __ex_table,\"a\"\n" \
153 " .align 4\n" \
Finn Thain3a0f64b2016-03-23 21:10:31 +1100154 " .long 1b,91b\n" \
155 " .long 3b,94b\n" \
156 " .long 31b,94b\n" \
157 " .long 32b,94b\n" \
158 " .long 33b,94b\n" \
159 " .long 34b,94b\n" \
160 " .long 35b,94b\n" \
161 " .long 36b,94b\n" \
162 " .long 37b,94b\n" \
163 " .long 5b,94b\n" \
164 " .long 7b,91b\n" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 ".previous" \
Finn Thain3a0f64b2016-03-23 21:10:31 +1100166 : "=a"(s), "=a"(d), "=d"(n) \
167 : "0"(s), "1"(d), "2"(n) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 : "d0")
169
Finn Thainffdede62014-11-12 16:12:06 +1100170static int macscsi_pread(struct Scsi_Host *instance,
171 unsigned char *dst, int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172{
Finn Thaincbad48d2014-11-12 16:12:07 +1100173 struct NCR5380_hostdata *hostdata = shost_priv(instance);
Finn Thain3a0f64b2016-03-23 21:10:31 +1100174 unsigned char *s = hostdata->pdma_base + (INPUT_DATA_REG << 4);
175 unsigned char *d = dst;
176 int n = len;
177 int transferred;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178
Finn Thain3a0f64b2016-03-23 21:10:31 +1100179 while (!NCR5380_poll_politely(instance, BUS_AND_STATUS_REG,
180 BASR_DRQ | BASR_PHASE_MATCH,
181 BASR_DRQ | BASR_PHASE_MATCH, HZ / 64)) {
182 CP_IO_TO_MEM(s, d, n);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183
Finn Thain3a0f64b2016-03-23 21:10:31 +1100184 transferred = d - dst - n;
185 hostdata->pdma_residual = len - transferred;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186
Finn Thain3a0f64b2016-03-23 21:10:31 +1100187 /* No bus error. */
188 if (n == 0)
189 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
Finn Thain3a0f64b2016-03-23 21:10:31 +1100191 /* Target changed phase early? */
192 if (NCR5380_poll_politely2(instance, STATUS_REG, SR_REQ, SR_REQ,
193 BUS_AND_STATUS_REG, BASR_ACK, BASR_ACK, HZ / 64) < 0)
194 scmd_printk(KERN_ERR, hostdata->connected,
195 "%s: !REQ and !ACK\n", __func__);
196 if (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_PHASE_MATCH))
197 return 0;
198
199 dsprintk(NDEBUG_PSEUDO_DMA, instance,
200 "%s: bus error (%d/%d)\n", __func__, transferred, len);
201 NCR5380_dprint(NDEBUG_PSEUDO_DMA, instance);
202 d = dst + transferred;
203 n = len - transferred;
Finn Thainffdede62014-11-12 16:12:06 +1100204 }
205
Finn Thain3a0f64b2016-03-23 21:10:31 +1100206 scmd_printk(KERN_ERR, hostdata->connected,
207 "%s: phase mismatch or !DRQ\n", __func__);
208 NCR5380_dprint(NDEBUG_PSEUDO_DMA, instance);
209 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210}
211
212
Finn Thain3a0f64b2016-03-23 21:10:31 +1100213#define CP_MEM_TO_IO(s,d,n) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214__asm__ __volatile__ \
215 (" cmp.w #4,%2\n" \
216 " bls 8f\n" \
217 " move.w %0,%%d0\n" \
218 " neg.b %%d0\n" \
219 " and.w #3,%%d0\n" \
220 " sub.w %%d0,%2\n" \
221 " bra 2f\n" \
222 " 1: move.b (%0)+,(%1)\n" \
223 " 2: dbf %%d0,1b\n" \
224 " move.w %2,%%d0\n" \
225 " lsr.w #5,%%d0\n" \
226 " bra 4f\n" \
227 " 3: move.l (%0)+,(%1)\n" \
228 "31: move.l (%0)+,(%1)\n" \
229 "32: move.l (%0)+,(%1)\n" \
230 "33: move.l (%0)+,(%1)\n" \
231 "34: move.l (%0)+,(%1)\n" \
232 "35: move.l (%0)+,(%1)\n" \
233 "36: move.l (%0)+,(%1)\n" \
234 "37: move.l (%0)+,(%1)\n" \
235 " 4: dbf %%d0,3b\n" \
236 " move.w %2,%%d0\n" \
237 " lsr.w #2,%%d0\n" \
238 " and.w #7,%%d0\n" \
239 " bra 6f\n" \
240 " 5: move.l (%0)+,(%1)\n" \
241 " 6: dbf %%d0,5b\n" \
242 " and.w #3,%2\n" \
243 " bra 8f\n" \
244 " 7: move.b (%0)+,(%1)\n" \
245 " 8: dbf %2,7b\n" \
246 " moveq.l #0, %2\n" \
247 " 9: \n" \
248 ".section .fixup,\"ax\"\n" \
249 " .even\n" \
Finn Thain3a0f64b2016-03-23 21:10:31 +1100250 "91: moveq.l #1, %2\n" \
251 " jra 9b\n" \
252 "94: moveq.l #4, %2\n" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 " jra 9b\n" \
254 ".previous\n" \
255 ".section __ex_table,\"a\"\n" \
256 " .align 4\n" \
Finn Thain3a0f64b2016-03-23 21:10:31 +1100257 " .long 1b,91b\n" \
258 " .long 3b,94b\n" \
259 " .long 31b,94b\n" \
260 " .long 32b,94b\n" \
261 " .long 33b,94b\n" \
262 " .long 34b,94b\n" \
263 " .long 35b,94b\n" \
264 " .long 36b,94b\n" \
265 " .long 37b,94b\n" \
266 " .long 5b,94b\n" \
267 " .long 7b,91b\n" \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 ".previous" \
Finn Thain3a0f64b2016-03-23 21:10:31 +1100269 : "=a"(s), "=a"(d), "=d"(n) \
270 : "0"(s), "1"(d), "2"(n) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 : "d0")
272
Finn Thainffdede62014-11-12 16:12:06 +1100273static int macscsi_pwrite(struct Scsi_Host *instance,
274 unsigned char *src, int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275{
Finn Thaincbad48d2014-11-12 16:12:07 +1100276 struct NCR5380_hostdata *hostdata = shost_priv(instance);
Finn Thain3a0f64b2016-03-23 21:10:31 +1100277 unsigned char *s = src;
278 unsigned char *d = hostdata->pdma_base + (OUTPUT_DATA_REG << 4);
279 int n = len;
280 int transferred;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281
Finn Thain3a0f64b2016-03-23 21:10:31 +1100282 while (!NCR5380_poll_politely(instance, BUS_AND_STATUS_REG,
283 BASR_DRQ | BASR_PHASE_MATCH,
284 BASR_DRQ | BASR_PHASE_MATCH, HZ / 64)) {
285 CP_MEM_TO_IO(s, d, n);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286
Finn Thain3a0f64b2016-03-23 21:10:31 +1100287 transferred = s - src - n;
288 hostdata->pdma_residual = len - transferred;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289
Finn Thain3a0f64b2016-03-23 21:10:31 +1100290 /* Target changed phase early? */
291 if (NCR5380_poll_politely2(instance, STATUS_REG, SR_REQ, SR_REQ,
292 BUS_AND_STATUS_REG, BASR_ACK, BASR_ACK, HZ / 64) < 0)
293 scmd_printk(KERN_ERR, hostdata->connected,
294 "%s: !REQ and !ACK\n", __func__);
295 if (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_PHASE_MATCH))
296 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297
Finn Thain3a0f64b2016-03-23 21:10:31 +1100298 /* No bus error. */
299 if (n == 0) {
300 if (NCR5380_poll_politely(instance, TARGET_COMMAND_REG,
301 TCR_LAST_BYTE_SENT,
302 TCR_LAST_BYTE_SENT, HZ / 64) < 0)
303 scmd_printk(KERN_ERR, hostdata->connected,
304 "%s: Last Byte Sent timeout\n", __func__);
305 return 0;
306 }
307
308 dsprintk(NDEBUG_PSEUDO_DMA, instance,
309 "%s: bus error (%d/%d)\n", __func__, transferred, len);
310 NCR5380_dprint(NDEBUG_PSEUDO_DMA, instance);
311 s = src + transferred;
312 n = len - transferred;
Finn Thainffdede62014-11-12 16:12:06 +1100313 }
314
Finn Thain3a0f64b2016-03-23 21:10:31 +1100315 scmd_printk(KERN_ERR, hostdata->connected,
316 "%s: phase mismatch or !DRQ\n", __func__);
317 NCR5380_dprint(NDEBUG_PSEUDO_DMA, instance);
Finn Thainffdede62014-11-12 16:12:06 +1100318
Finn Thain3a0f64b2016-03-23 21:10:31 +1100319 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321
Finn Thain7e9ec8d2016-03-23 21:10:11 +1100322static int macscsi_dma_xfer_len(struct Scsi_Host *instance,
323 struct scsi_cmnd *cmd)
324{
325 struct NCR5380_hostdata *hostdata = shost_priv(instance);
326
Finn Thain3a0f64b2016-03-23 21:10:31 +1100327 if (hostdata->flags & FLAG_NO_PSEUDO_DMA ||
328 cmd->SCp.this_residual < 16)
Finn Thain7e9ec8d2016-03-23 21:10:11 +1100329 return 0;
330
Finn Thain3a0f64b2016-03-23 21:10:31 +1100331 return cmd->SCp.this_residual;
Finn Thain7e9ec8d2016-03-23 21:10:11 +1100332}
333
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334#include "NCR5380.c"
335
Finn Thaincbad48d2014-11-12 16:12:07 +1100336#define DRV_MODULE_NAME "mac_scsi"
337#define PFX DRV_MODULE_NAME ": "
338
339static struct scsi_host_template mac_scsi_template = {
Finn Thainaa2e2cb2016-01-03 16:05:48 +1100340 .module = THIS_MODULE,
341 .proc_name = DRV_MODULE_NAME,
Finn Thainaa2e2cb2016-01-03 16:05:48 +1100342 .name = "Macintosh NCR5380 SCSI",
343 .info = macscsi_info,
344 .queuecommand = macscsi_queue_command,
345 .eh_abort_handler = macscsi_abort,
346 .eh_bus_reset_handler = macscsi_bus_reset,
347 .can_queue = 16,
348 .this_id = 7,
Finn Thain3a0f64b2016-03-23 21:10:31 +1100349 .sg_tablesize = 1,
Finn Thainaa2e2cb2016-01-03 16:05:48 +1100350 .cmd_per_lun = 2,
351 .use_clustering = DISABLE_CLUSTERING,
Finn Thain32b26a12016-01-03 16:05:58 +1100352 .cmd_size = NCR5380_CMD_SIZE,
Finn Thain0a4e3612016-01-03 16:06:07 +1100353 .max_sectors = 128,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354};
355
Finn Thaincbad48d2014-11-12 16:12:07 +1100356static int __init mac_scsi_probe(struct platform_device *pdev)
357{
358 struct Scsi_Host *instance;
359 int error;
360 int host_flags = 0;
361 struct resource *irq, *pio_mem, *pdma_mem = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362
Finn Thaincbad48d2014-11-12 16:12:07 +1100363 pio_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
364 if (!pio_mem)
365 return -ENODEV;
Finn Thain6e9ae6d2014-11-12 16:12:05 +1100366
Finn Thaincbad48d2014-11-12 16:12:07 +1100367 pdma_mem = platform_get_resource(pdev, IORESOURCE_MEM, 1);
Finn Thaincbad48d2014-11-12 16:12:07 +1100368
369 irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
370
371 if (!hwreg_present((unsigned char *)pio_mem->start +
372 (STATUS_REG << 4))) {
373 pr_info(PFX "no device detected at %pap\n", &pio_mem->start);
374 return -ENODEV;
375 }
376
377 if (setup_can_queue > 0)
378 mac_scsi_template.can_queue = setup_can_queue;
379 if (setup_cmd_per_lun > 0)
380 mac_scsi_template.cmd_per_lun = setup_cmd_per_lun;
381 if (setup_sg_tablesize >= 0)
382 mac_scsi_template.sg_tablesize = setup_sg_tablesize;
383 if (setup_hostid >= 0)
384 mac_scsi_template.this_id = setup_hostid & 7;
Finn Thaincbad48d2014-11-12 16:12:07 +1100385
386 instance = scsi_host_alloc(&mac_scsi_template,
387 sizeof(struct NCR5380_hostdata));
388 if (!instance)
389 return -ENOMEM;
390
391 instance->base = pio_mem->start;
392 if (irq)
393 instance->irq = irq->start;
394 else
395 instance->irq = NO_IRQ;
396
397 if (pdma_mem && setup_use_pdma) {
398 struct NCR5380_hostdata *hostdata = shost_priv(instance);
399
400 hostdata->pdma_base = (unsigned char *)pdma_mem->start;
401 } else
402 host_flags |= FLAG_NO_PSEUDO_DMA;
403
Finn Thain9c3f0e22016-01-03 16:05:11 +1100404 host_flags |= setup_toshiba_delay > 0 ? FLAG_TOSHIBA_DELAY : 0;
Finn Thainca513fc2014-11-12 16:12:19 +1100405
Finn Thain8053b0e2016-03-23 21:10:19 +1100406 error = NCR5380_init(instance, host_flags | FLAG_LATE_DMA_SETUP);
Finn Thain0ad0eff2016-01-03 16:05:21 +1100407 if (error)
408 goto fail_init;
Finn Thaincbad48d2014-11-12 16:12:07 +1100409
410 if (instance->irq != NO_IRQ) {
411 error = request_irq(instance->irq, macscsi_intr, IRQF_SHARED,
412 "NCR5380", instance);
413 if (error)
414 goto fail_irq;
415 }
416
Finn Thain9c3f0e22016-01-03 16:05:11 +1100417 NCR5380_maybe_reset_bus(instance);
418
Finn Thaincbad48d2014-11-12 16:12:07 +1100419 error = scsi_add_host(instance, NULL);
420 if (error)
421 goto fail_host;
422
423 platform_set_drvdata(pdev, instance);
424
425 scsi_scan_host(instance);
426 return 0;
427
428fail_host:
429 if (instance->irq != NO_IRQ)
430 free_irq(instance->irq, instance);
431fail_irq:
432 NCR5380_exit(instance);
Finn Thain0ad0eff2016-01-03 16:05:21 +1100433fail_init:
Finn Thaincbad48d2014-11-12 16:12:07 +1100434 scsi_host_put(instance);
435 return error;
436}
437
438static int __exit mac_scsi_remove(struct platform_device *pdev)
439{
440 struct Scsi_Host *instance = platform_get_drvdata(pdev);
441
442 scsi_remove_host(instance);
443 if (instance->irq != NO_IRQ)
444 free_irq(instance->irq, instance);
445 NCR5380_exit(instance);
446 scsi_host_put(instance);
447 return 0;
448}
449
450static struct platform_driver mac_scsi_driver = {
451 .remove = __exit_p(mac_scsi_remove),
452 .driver = {
453 .name = DRV_MODULE_NAME,
Finn Thaincbad48d2014-11-12 16:12:07 +1100454 },
455};
456
457module_platform_driver_probe(mac_scsi_driver, mac_scsi_probe);
458
459MODULE_ALIAS("platform:" DRV_MODULE_NAME);
Finn Thain6e9ae6d2014-11-12 16:12:05 +1100460MODULE_LICENSE("GPL");