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>
19 static irqreturn_t a2091_intr(int irq, void *data)
21 struct Scsi_Host *instance = data;
22 struct a2091_scsiregs *regs = (struct a2091_scsiregs *)(instance->base);
23 unsigned int status = regs->ISTR;
26 if (!(status & (ISTR_INT_F | ISTR_INT_P)) || !(status & ISTR_INTS))
29 spin_lock_irqsave(instance->host_lock, flags);
30 wd33c93_intr(instance);
31 spin_unlock_irqrestore(instance->host_lock, flags);
35 static int dma_setup(struct scsi_cmnd *cmd, int dir_in)
37 struct Scsi_Host *instance = cmd->device->host;
38 struct WD33C93_hostdata *hdata = shost_priv(instance);
39 struct a2091_scsiregs *regs = (struct a2091_scsiregs *)(instance->base);
40 unsigned short cntr = CNTR_PDMD | CNTR_INTEN;
41 unsigned long addr = virt_to_bus(cmd->SCp.ptr);
43 /* don't allow DMA if the physical address is bad */
44 if (addr & A2091_XFER_MASK) {
45 hdata->dma_bounce_len = (cmd->SCp.this_residual + 511) & ~0x1ff;
46 hdata->dma_bounce_buffer = kmalloc(hdata->dma_bounce_len,
49 /* can't allocate memory; use PIO */
50 if (!hdata->dma_bounce_buffer) {
51 hdata->dma_bounce_len = 0;
55 /* get the physical address of the bounce buffer */
56 addr = virt_to_bus(hdata->dma_bounce_buffer);
58 /* the bounce buffer may not be in the first 16M of physmem */
59 if (addr & A2091_XFER_MASK) {
60 /* we could use chipmem... maybe later */
61 kfree(hdata->dma_bounce_buffer);
62 hdata->dma_bounce_buffer = NULL;
63 hdata->dma_bounce_len = 0;
68 /* copy to bounce buffer for a write */
69 memcpy(hdata->dma_bounce_buffer, cmd->SCp.ptr,
70 cmd->SCp.this_residual);
74 /* setup dma direction */
78 /* remember direction */
79 hdata->dma_dir = dir_in;
83 /* setup DMA *physical* address */
87 /* invalidate any cache */
88 cache_clear(addr, cmd->SCp.this_residual);
90 /* push any dirty cache */
91 cache_push(addr, cmd->SCp.this_residual);
100 static void dma_stop(struct Scsi_Host *instance, struct scsi_cmnd *SCpnt,
103 struct WD33C93_hostdata *hdata = shost_priv(instance);
104 struct a2091_scsiregs *regs = (struct a2091_scsiregs *)(instance->base);
106 /* disable SCSI interrupts */
107 unsigned short cntr = CNTR_PDMD;
112 /* disable SCSI interrupts */
115 /* flush if we were reading */
116 if (hdata->dma_dir) {
118 while (!(regs->ISTR & ISTR_FE_FLG))
122 /* clear a possible interrupt */
128 /* restore the CONTROL bits (minus the direction flag) */
129 regs->CNTR = CNTR_PDMD | CNTR_INTEN;
131 /* copy from a bounce buffer, if necessary */
132 if (status && hdata->dma_bounce_buffer) {
134 memcpy(SCpnt->SCp.ptr, hdata->dma_bounce_buffer,
135 SCpnt->SCp.this_residual);
136 kfree(hdata->dma_bounce_buffer);
137 hdata->dma_bounce_buffer = NULL;
138 hdata->dma_bounce_len = 0;
142 static int a2091_bus_reset(struct scsi_cmnd *cmd)
144 struct Scsi_Host *instance = cmd->device->host;
146 /* FIXME perform bus-specific reset */
148 /* FIXME 2: kill this function, and let midlayer fall back
149 to the same action, calling wd33c93_host_reset() */
151 spin_lock_irq(instance->host_lock);
152 wd33c93_host_reset(cmd);
153 spin_unlock_irq(instance->host_lock);
158 static struct scsi_host_template a2091_scsi_template = {
159 .module = THIS_MODULE,
160 .name = "Commodore A2091/A590 SCSI",
161 .proc_info = wd33c93_proc_info,
162 .proc_name = "A2901",
163 .queuecommand = wd33c93_queuecommand,
164 .eh_abort_handler = wd33c93_abort,
165 .eh_bus_reset_handler = a2091_bus_reset,
166 .eh_host_reset_handler = wd33c93_host_reset,
167 .can_queue = CAN_QUEUE,
169 .sg_tablesize = SG_ALL,
170 .cmd_per_lun = CMD_PER_LUN,
171 .use_clustering = DISABLE_CLUSTERING
174 static int __devinit a2091_probe(struct zorro_dev *z,
175 const struct zorro_device_id *ent)
177 struct Scsi_Host *instance;
179 struct a2091_scsiregs *regs;
181 struct WD33C93_hostdata *hdata;
183 if (!request_mem_region(z->resource.start, 256, "wd33c93"))
186 instance = scsi_host_alloc(&a2091_scsi_template,
187 sizeof(struct WD33C93_hostdata));
193 instance->base = ZTWO_VADDR(z->resource.start);
194 instance->irq = IRQ_AMIGA_PORTS;
195 instance->unique_id = z->slotaddr;
197 regs = (struct a2091_scsiregs *)(instance->base);
198 regs->DAWR = DAWR_A2091;
200 wdregs.SASR = ®s->SASR;
201 wdregs.SCMD = ®s->SCMD;
203 hdata = shost_priv(instance);
204 hdata->no_sync = 0xff;
206 hdata->dma_mode = CTRL_DMA;
208 wd33c93_init(instance, wdregs, dma_setup, dma_stop, WD33C93_FS_8_10);
209 error = request_irq(IRQ_AMIGA_PORTS, a2091_intr, IRQF_SHARED,
210 "A2091 SCSI", instance);
214 regs->CNTR = CNTR_PDMD | CNTR_INTEN;
216 error = scsi_add_host(instance, NULL);
220 zorro_set_drvdata(z, instance);
222 scsi_scan_host(instance);
226 free_irq(IRQ_AMIGA_PORTS, instance);
228 scsi_host_put(instance);
230 release_mem_region(z->resource.start, 256);
234 static void __devexit a2091_remove(struct zorro_dev *z)
236 struct Scsi_Host *instance = zorro_get_drvdata(z);
237 struct a2091_scsiregs *regs = (struct a2091_scsiregs *)(instance->base);
240 scsi_remove_host(instance);
241 free_irq(IRQ_AMIGA_PORTS, instance);
242 scsi_host_put(instance);
243 release_mem_region(z->resource.start, 256);
246 static struct zorro_device_id a2091_zorro_tbl[] __devinitdata = {
247 { ZORRO_PROD_CBM_A590_A2091_1 },
248 { ZORRO_PROD_CBM_A590_A2091_2 },
251 MODULE_DEVICE_TABLE(zorro, a2091_zorro_tbl);
253 static struct zorro_driver a2091_driver = {
255 .id_table = a2091_zorro_tbl,
256 .probe = a2091_probe,
257 .remove = __devexit_p(a2091_remove),
260 static int __init a2091_init(void)
262 return zorro_register_driver(&a2091_driver);
264 module_init(a2091_init);
266 static void __exit a2091_exit(void)
268 zorro_unregister_driver(&a2091_driver);
270 module_exit(a2091_exit);
272 MODULE_DESCRIPTION("Commodore A2091/A590 SCSI");
273 MODULE_LICENSE("GPL");