1 #include <linux/types.h>
2 #include <linux/init.h>
3 #include <linux/interrupt.h>
5 #include <linux/slab.h>
6 #include <linux/spinlock.h>
7 #include <linux/zorro.h>
10 #include <asm/pgtable.h>
11 #include <asm/amigaints.h>
12 #include <asm/amigahw.h>
21 static irqreturn_t gvp11_intr(int irq, void *data)
23 struct Scsi_Host *instance = data;
24 struct gvp11_scsiregs *regs = (struct gvp11_scsiregs *)(instance->base);
25 unsigned int status = regs->CNTR;
28 if (!(status & GVP11_DMAC_INT_PENDING))
31 spin_lock_irqsave(instance->host_lock, flags);
32 wd33c93_intr(instance);
33 spin_unlock_irqrestore(instance->host_lock, flags);
37 static int gvp11_xfer_mask = 0;
39 void gvp11_setup(char *str, int *ints)
41 gvp11_xfer_mask = ints[1];
44 static int dma_setup(struct scsi_cmnd *cmd, int dir_in)
46 struct Scsi_Host *instance = cmd->device->host;
47 struct WD33C93_hostdata *hdata = shost_priv(instance);
48 struct gvp11_scsiregs *regs = (struct gvp11_scsiregs *)(instance->base);
49 unsigned short cntr = GVP11_DMAC_INT_ENABLE;
50 unsigned long addr = virt_to_bus(cmd->SCp.ptr);
52 static int scsi_alloc_out_of_range = 0;
54 /* use bounce buffer if the physical address is bad */
55 if (addr & hdata->dma_xfer_mask) {
56 hdata->dma_bounce_len = (cmd->SCp.this_residual + 511) & ~0x1ff;
58 if (!scsi_alloc_out_of_range) {
59 hdata->dma_bounce_buffer =
60 kmalloc(hdata->dma_bounce_len, GFP_KERNEL);
61 hdata->dma_buffer_pool = BUF_SCSI_ALLOCED;
64 if (scsi_alloc_out_of_range ||
65 !hdata->dma_bounce_buffer) {
66 hdata->dma_bounce_buffer =
67 amiga_chip_alloc(hdata->dma_bounce_len,
68 "GVP II SCSI Bounce Buffer");
70 if (!hdata->dma_bounce_buffer) {
71 hdata->dma_bounce_len = 0;
75 hdata->dma_buffer_pool = BUF_CHIP_ALLOCED;
78 /* check if the address of the bounce buffer is OK */
79 addr = virt_to_bus(hdata->dma_bounce_buffer);
81 if (addr & hdata->dma_xfer_mask) {
82 /* fall back to Chip RAM if address out of range */
83 if (hdata->dma_buffer_pool == BUF_SCSI_ALLOCED) {
84 kfree(hdata->dma_bounce_buffer);
85 scsi_alloc_out_of_range = 1;
87 amiga_chip_free(hdata->dma_bounce_buffer);
90 hdata->dma_bounce_buffer =
91 amiga_chip_alloc(hdata->dma_bounce_len,
92 "GVP II SCSI Bounce Buffer");
94 if (!hdata->dma_bounce_buffer) {
95 hdata->dma_bounce_len = 0;
99 addr = virt_to_bus(hdata->dma_bounce_buffer);
100 hdata->dma_buffer_pool = BUF_CHIP_ALLOCED;
104 /* copy to bounce buffer for a write */
105 memcpy(hdata->dma_bounce_buffer, cmd->SCp.ptr,
106 cmd->SCp.this_residual);
110 /* setup dma direction */
112 cntr |= GVP11_DMAC_DIR_WRITE;
114 hdata->dma_dir = dir_in;
117 /* setup DMA *physical* address */
121 /* invalidate any cache */
122 cache_clear(addr, cmd->SCp.this_residual);
124 /* push any dirty cache */
125 cache_push(addr, cmd->SCp.this_residual);
128 bank_mask = (~hdata->dma_xfer_mask >> 18) & 0x01c0;
130 regs->BANK = bank_mask & (addr >> 18);
139 static void dma_stop(struct Scsi_Host *instance, struct scsi_cmnd *SCpnt,
142 struct gvp11_scsiregs *regs = (struct gvp11_scsiregs *)(instance->base);
143 struct WD33C93_hostdata *hdata = shost_priv(instance);
147 /* remove write bit from CONTROL bits */
148 regs->CNTR = GVP11_DMAC_INT_ENABLE;
150 /* copy from a bounce buffer, if necessary */
151 if (status && hdata->dma_bounce_buffer) {
152 if (hdata->dma_dir && SCpnt)
153 memcpy(SCpnt->SCp.ptr, hdata->dma_bounce_buffer,
154 SCpnt->SCp.this_residual);
156 if (hdata->dma_buffer_pool == BUF_SCSI_ALLOCED)
157 kfree(hdata->dma_bounce_buffer);
159 amiga_chip_free(hdata->dma_bounce_buffer);
161 hdata->dma_bounce_buffer = NULL;
162 hdata->dma_bounce_len = 0;
166 static int gvp11_bus_reset(struct scsi_cmnd *cmd)
168 struct Scsi_Host *instance = cmd->device->host;
170 /* FIXME perform bus-specific reset */
172 /* FIXME 2: shouldn't we no-op this function (return
173 FAILED), and fall back to host reset function,
174 wd33c93_host_reset ? */
176 spin_lock_irq(instance->host_lock);
177 wd33c93_host_reset(cmd);
178 spin_unlock_irq(instance->host_lock);
183 static struct scsi_host_template gvp11_scsi_template = {
184 .module = THIS_MODULE,
185 .name = "GVP Series II SCSI",
186 .proc_info = wd33c93_proc_info,
187 .proc_name = "GVP11",
188 .queuecommand = wd33c93_queuecommand,
189 .eh_abort_handler = wd33c93_abort,
190 .eh_bus_reset_handler = gvp11_bus_reset,
191 .eh_host_reset_handler = wd33c93_host_reset,
192 .can_queue = CAN_QUEUE,
194 .sg_tablesize = SG_ALL,
195 .cmd_per_lun = CMD_PER_LUN,
196 .use_clustering = DISABLE_CLUSTERING
199 static int __devinit check_wd33c93(struct gvp11_scsiregs *regs)
202 volatile unsigned char *sasr_3393, *scmd_3393;
203 unsigned char save_sasr;
207 * These darn GVP boards are a problem - it can be tough to tell
208 * whether or not they include a SCSI controller. This is the
209 * ultimate Yet-Another-GVP-Detection-Hack in that it actually
210 * probes for a WD33c93 chip: If we find one, it's extremely
211 * likely that this card supports SCSI, regardless of Product_
212 * Code, Board_Size, etc.
215 /* Get pointers to the presumed register locations and save contents */
217 sasr_3393 = ®s->SASR;
218 scmd_3393 = ®s->SCMD;
219 save_sasr = *sasr_3393;
221 /* First test the AuxStatus Reg */
223 q = *sasr_3393; /* read it */
224 if (q & 0x08) /* bit 3 should always be clear */
226 *sasr_3393 = WD_AUXILIARY_STATUS; /* setup indirect address */
227 if (*sasr_3393 == WD_AUXILIARY_STATUS) { /* shouldn't retain the write */
228 *sasr_3393 = save_sasr; /* Oops - restore this byte */
231 if (*sasr_3393 != q) { /* should still read the same */
232 *sasr_3393 = save_sasr; /* Oops - restore this byte */
235 if (*scmd_3393 != q) /* and so should the image at 0x1f */
239 * Ok, we probably have a wd33c93, but let's check a few other places
240 * for good measure. Make sure that this works for both 'A and 'B
244 *sasr_3393 = WD_SCSI_STATUS;
246 *sasr_3393 = WD_SCSI_STATUS;
248 *sasr_3393 = WD_SCSI_STATUS;
250 *sasr_3393 = WD_SCSI_STATUS;
252 if (qq != q) /* should be read only */
254 *sasr_3393 = 0x1e; /* this register is unimplemented */
262 if (qq != q || qq != 0xff) /* should be read only, all 1's */
264 *sasr_3393 = WD_TIMEOUT_PERIOD;
266 *sasr_3393 = WD_TIMEOUT_PERIOD;
268 *sasr_3393 = WD_TIMEOUT_PERIOD;
270 *sasr_3393 = WD_TIMEOUT_PERIOD;
272 if (qq != (~q & 0xff)) /* should be read/write */
274 #endif /* CHECK_WD33C93 */
279 static int __devinit gvp11_probe(struct zorro_dev *z,
280 const struct zorro_device_id *ent)
282 struct Scsi_Host *instance;
283 unsigned long address;
286 unsigned int default_dma_xfer_mask;
287 struct WD33C93_hostdata *hdata;
288 struct gvp11_scsiregs *regs;
291 default_dma_xfer_mask = ent->driver_data;
294 * Rumors state that some GVP ram boards use the same product
295 * code as the SCSI controllers. Therefore if the board-size
296 * is not 64KB we asume it is a ram board and bail out.
298 if (zorro_resource_len(z) != 0x10000)
301 address = z->resource.start;
302 if (!request_mem_region(address, 256, "wd33c93"))
305 regs = (struct gvp11_scsiregs *)(ZTWO_VADDR(address));
307 error = check_wd33c93(regs);
309 goto fail_check_or_alloc;
311 instance = scsi_host_alloc(&gvp11_scsi_template,
312 sizeof(struct WD33C93_hostdata));
315 goto fail_check_or_alloc;
318 instance->base = (unsigned long)regs;
319 instance->irq = IRQ_AMIGA_PORTS;
320 instance->unique_id = z->slotaddr;
325 while (regs->CNTR & GVP11_DMAC_BUSY)
330 wdregs.SASR = ®s->SASR;
331 wdregs.SCMD = ®s->SCMD;
333 hdata = shost_priv(instance);
335 hdata->dma_xfer_mask = gvp11_xfer_mask;
337 hdata->dma_xfer_mask = default_dma_xfer_mask;
339 hdata->no_sync = 0xff;
341 hdata->dma_mode = CTRL_DMA;
344 * Check for 14MHz SCSI clock
346 epc = *(unsigned short *)(ZTWO_VADDR(address) + 0x8000);
347 wd33c93_init(instance, wdregs, dma_setup, dma_stop,
348 (epc & GVP_SCSICLKMASK) ? WD33C93_FS_8_10
351 error = request_irq(IRQ_AMIGA_PORTS, gvp11_intr, IRQF_SHARED,
352 "GVP11 SCSI", instance);
356 regs->CNTR = GVP11_DMAC_INT_ENABLE;
358 error = scsi_add_host(instance, NULL);
362 zorro_set_drvdata(z, instance);
363 scsi_scan_host(instance);
367 free_irq(IRQ_AMIGA_PORTS, instance);
369 scsi_host_put(instance);
371 release_mem_region(address, 256);
375 static void __devexit gvp11_remove(struct zorro_dev *z)
377 struct Scsi_Host *instance = zorro_get_drvdata(z);
378 struct gvp11_scsiregs *regs = (struct gvp11_scsiregs *)(instance->base);
381 scsi_remove_host(instance);
382 free_irq(IRQ_AMIGA_PORTS, instance);
383 scsi_host_put(instance);
384 release_mem_region(z->resource.start, 256);
388 * This should (hopefully) be the correct way to identify
389 * all the different GVP SCSI controllers (except for the
393 static struct zorro_device_id gvp11_zorro_tbl[] __devinitdata = {
394 { ZORRO_PROD_GVP_COMBO_030_R3_SCSI, ~0x00ffffff },
395 { ZORRO_PROD_GVP_SERIES_II, ~0x00ffffff },
396 { ZORRO_PROD_GVP_GFORCE_030_SCSI, ~0x01ffffff },
397 { ZORRO_PROD_GVP_A530_SCSI, ~0x01ffffff },
398 { ZORRO_PROD_GVP_COMBO_030_R4_SCSI, ~0x01ffffff },
399 { ZORRO_PROD_GVP_A1291, ~0x07ffffff },
400 { ZORRO_PROD_GVP_GFORCE_040_SCSI_1, ~0x07ffffff },
403 MODULE_DEVICE_TABLE(zorro, gvp11_zorro_tbl);
405 static struct zorro_driver gvp11_driver = {
407 .id_table = gvp11_zorro_tbl,
408 .probe = gvp11_probe,
409 .remove = __devexit_p(gvp11_remove),
412 static int __init gvp11_init(void)
414 return zorro_register_driver(&gvp11_driver);
416 module_init(gvp11_init);
418 static void __exit gvp11_exit(void)
420 zorro_unregister_driver(&gvp11_driver);
422 module_exit(gvp11_exit);
424 MODULE_DESCRIPTION("GVP Series II SCSI");
425 MODULE_LICENSE("GPL");