1 #include <linux/types.h>
3 #include <linux/blkdev.h>
4 #include <linux/init.h>
5 #include <linux/interrupt.h>
9 #include <asm/pgtable.h>
10 #include <asm/amigaints.h>
11 #include <asm/amigahw.h>
12 #include <linux/zorro.h>
14 #include <linux/spinlock.h>
17 #include <scsi/scsi_host.h>
21 #include<linux/stat.h>
23 #define DMA(ptr) ((a2091_scsiregs *)((ptr)->base))
24 #define HDATA(ptr) ((struct WD33C93_hostdata *)((ptr)->hostdata))
26 static irqreturn_t a2091_intr (int irq, void *_instance)
30 struct Scsi_Host *instance = (struct Scsi_Host *)_instance;
32 status = DMA(instance)->ISTR;
33 if (!(status & (ISTR_INT_F|ISTR_INT_P)) || !(status & ISTR_INTS))
36 spin_lock_irqsave(instance->host_lock, flags);
37 wd33c93_intr(instance);
38 spin_unlock_irqrestore(instance->host_lock, flags);
42 static int dma_setup(struct scsi_cmnd *cmd, int dir_in)
44 unsigned short cntr = CNTR_PDMD | CNTR_INTEN;
45 unsigned long addr = virt_to_bus(cmd->SCp.ptr);
46 struct Scsi_Host *instance = cmd->device->host;
48 /* don't allow DMA if the physical address is bad */
49 if (addr & A2091_XFER_MASK)
51 HDATA(instance)->dma_bounce_len = (cmd->SCp.this_residual + 511)
53 HDATA(instance)->dma_bounce_buffer =
54 kmalloc (HDATA(instance)->dma_bounce_len, GFP_KERNEL);
56 /* can't allocate memory; use PIO */
57 if (!HDATA(instance)->dma_bounce_buffer) {
58 HDATA(instance)->dma_bounce_len = 0;
62 /* get the physical address of the bounce buffer */
63 addr = virt_to_bus(HDATA(instance)->dma_bounce_buffer);
65 /* the bounce buffer may not be in the first 16M of physmem */
66 if (addr & A2091_XFER_MASK) {
67 /* we could use chipmem... maybe later */
68 kfree (HDATA(instance)->dma_bounce_buffer);
69 HDATA(instance)->dma_bounce_buffer = NULL;
70 HDATA(instance)->dma_bounce_len = 0;
75 /* copy to bounce buffer for a write */
76 memcpy (HDATA(instance)->dma_bounce_buffer,
77 cmd->SCp.ptr, cmd->SCp.this_residual);
81 /* setup dma direction */
85 /* remember direction */
86 HDATA(cmd->device->host)->dma_dir = dir_in;
88 DMA(cmd->device->host)->CNTR = cntr;
90 /* setup DMA *physical* address */
91 DMA(cmd->device->host)->ACR = addr;
94 /* invalidate any cache */
95 cache_clear (addr, cmd->SCp.this_residual);
97 /* push any dirty cache */
98 cache_push (addr, cmd->SCp.this_residual);
101 DMA(cmd->device->host)->ST_DMA = 1;
107 static void dma_stop(struct Scsi_Host *instance, struct scsi_cmnd *SCpnt,
110 /* disable SCSI interrupts */
111 unsigned short cntr = CNTR_PDMD;
113 if (!HDATA(instance)->dma_dir)
116 /* disable SCSI interrupts */
117 DMA(instance)->CNTR = cntr;
119 /* flush if we were reading */
120 if (HDATA(instance)->dma_dir) {
121 DMA(instance)->FLUSH = 1;
122 while (!(DMA(instance)->ISTR & ISTR_FE_FLG))
126 /* clear a possible interrupt */
127 DMA(instance)->CINT = 1;
130 DMA(instance)->SP_DMA = 1;
132 /* restore the CONTROL bits (minus the direction flag) */
133 DMA(instance)->CNTR = CNTR_PDMD | CNTR_INTEN;
135 /* copy from a bounce buffer, if necessary */
136 if (status && HDATA(instance)->dma_bounce_buffer) {
137 if( HDATA(instance)->dma_dir )
138 memcpy (SCpnt->SCp.ptr,
139 HDATA(instance)->dma_bounce_buffer,
140 SCpnt->SCp.this_residual);
141 kfree (HDATA(instance)->dma_bounce_buffer);
142 HDATA(instance)->dma_bounce_buffer = NULL;
143 HDATA(instance)->dma_bounce_len = 0;
147 int __init a2091_detect(struct scsi_host_template *tpnt)
149 static unsigned char called = 0;
150 struct Scsi_Host *instance;
151 unsigned long address;
152 struct zorro_dev *z = NULL;
156 if (!MACH_IS_AMIGA || called)
160 tpnt->proc_name = "A2091";
161 tpnt->proc_info = &wd33c93_proc_info;
163 while ((z = zorro_find_device(ZORRO_WILDCARD, z))) {
164 if (z->id != ZORRO_PROD_CBM_A590_A2091_1 &&
165 z->id != ZORRO_PROD_CBM_A590_A2091_2)
167 address = z->resource.start;
168 if (!request_mem_region(address, 256, "wd33c93"))
171 instance = scsi_register (tpnt, sizeof (struct WD33C93_hostdata));
172 if (instance == NULL) {
173 release_mem_region(address, 256);
176 instance->base = ZTWO_VADDR(address);
177 instance->irq = IRQ_AMIGA_PORTS;
178 instance->unique_id = z->slotaddr;
179 DMA(instance)->DAWR = DAWR_A2091;
180 regs.SASR = &(DMA(instance)->SASR);
181 regs.SCMD = &(DMA(instance)->SCMD);
182 wd33c93_init(instance, regs, dma_setup, dma_stop, WD33C93_FS_8_10);
183 request_irq(IRQ_AMIGA_PORTS, a2091_intr, IRQF_SHARED, "A2091 SCSI",
185 DMA(instance)->CNTR = CNTR_PDMD | CNTR_INTEN;
192 static int a2091_bus_reset(struct scsi_cmnd *cmd)
194 /* FIXME perform bus-specific reset */
196 /* FIXME 2: kill this function, and let midlayer fall back
197 to the same action, calling wd33c93_host_reset() */
199 spin_lock_irq(cmd->device->host->host_lock);
200 wd33c93_host_reset(cmd);
201 spin_unlock_irq(cmd->device->host->host_lock);
208 static struct scsi_host_template driver_template = {
209 .proc_name = "A2901",
210 .name = "Commodore A2091/A590 SCSI",
211 .detect = a2091_detect,
212 .release = a2091_release,
213 .queuecommand = wd33c93_queuecommand,
214 .eh_abort_handler = wd33c93_abort,
215 .eh_bus_reset_handler = a2091_bus_reset,
216 .eh_host_reset_handler = wd33c93_host_reset,
217 .can_queue = CAN_QUEUE,
219 .sg_tablesize = SG_ALL,
220 .cmd_per_lun = CMD_PER_LUN,
221 .use_clustering = DISABLE_CLUSTERING
225 #include "scsi_module.c"
227 int a2091_release(struct Scsi_Host *instance)
230 DMA(instance)->CNTR = 0;
231 release_mem_region(ZTWO_PADDR(instance->base), 256);
232 free_irq(IRQ_AMIGA_PORTS, instance);
238 MODULE_LICENSE("GPL");