1 // SPDX-License-Identifier: GPL-2.0-only
2 #include <linux/types.h>
3 #include <linux/init.h>
4 #include <linux/interrupt.h>
6 #include <linux/slab.h>
7 #include <linux/spinlock.h>
8 #include <linux/zorro.h>
9 #include <linux/module.h>
12 #include <asm/pgtable.h>
13 #include <asm/amigaints.h>
14 #include <asm/amigahw.h>
21 struct a2091_hostdata
{
22 struct WD33C93_hostdata wh
;
23 struct a2091_scsiregs
*regs
;
26 static irqreturn_t
a2091_intr(int irq
, void *data
)
28 struct Scsi_Host
*instance
= data
;
29 struct a2091_hostdata
*hdata
= shost_priv(instance
);
30 unsigned int status
= hdata
->regs
->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 struct Scsi_Host
*instance
= cmd
->device
->host
;
45 struct a2091_hostdata
*hdata
= shost_priv(instance
);
46 struct WD33C93_hostdata
*wh
= &hdata
->wh
;
47 struct a2091_scsiregs
*regs
= hdata
->regs
;
48 unsigned short cntr
= CNTR_PDMD
| CNTR_INTEN
;
49 unsigned long addr
= virt_to_bus(cmd
->SCp
.ptr
);
51 /* don't allow DMA if the physical address is bad */
52 if (addr
& A2091_XFER_MASK
) {
53 wh
->dma_bounce_len
= (cmd
->SCp
.this_residual
+ 511) & ~0x1ff;
54 wh
->dma_bounce_buffer
= kmalloc(wh
->dma_bounce_len
,
57 /* can't allocate memory; use PIO */
58 if (!wh
->dma_bounce_buffer
) {
59 wh
->dma_bounce_len
= 0;
63 /* get the physical address of the bounce buffer */
64 addr
= virt_to_bus(wh
->dma_bounce_buffer
);
66 /* the bounce buffer may not be in the first 16M of physmem */
67 if (addr
& A2091_XFER_MASK
) {
68 /* we could use chipmem... maybe later */
69 kfree(wh
->dma_bounce_buffer
);
70 wh
->dma_bounce_buffer
= NULL
;
71 wh
->dma_bounce_len
= 0;
76 /* copy to bounce buffer for a write */
77 memcpy(wh
->dma_bounce_buffer
, cmd
->SCp
.ptr
,
78 cmd
->SCp
.this_residual
);
82 /* setup dma direction */
86 /* remember direction */
91 /* setup DMA *physical* address */
95 /* invalidate any cache */
96 cache_clear(addr
, cmd
->SCp
.this_residual
);
98 /* push any dirty cache */
99 cache_push(addr
, cmd
->SCp
.this_residual
);
108 static void dma_stop(struct Scsi_Host
*instance
, struct scsi_cmnd
*SCpnt
,
111 struct a2091_hostdata
*hdata
= shost_priv(instance
);
112 struct WD33C93_hostdata
*wh
= &hdata
->wh
;
113 struct a2091_scsiregs
*regs
= hdata
->regs
;
115 /* disable SCSI interrupts */
116 unsigned short cntr
= CNTR_PDMD
;
121 /* disable SCSI interrupts */
124 /* flush if we were reading */
127 while (!(regs
->ISTR
& ISTR_FE_FLG
))
131 /* clear a possible interrupt */
137 /* restore the CONTROL bits (minus the direction flag) */
138 regs
->CNTR
= CNTR_PDMD
| CNTR_INTEN
;
140 /* copy from a bounce buffer, if necessary */
141 if (status
&& wh
->dma_bounce_buffer
) {
143 memcpy(SCpnt
->SCp
.ptr
, wh
->dma_bounce_buffer
,
144 SCpnt
->SCp
.this_residual
);
145 kfree(wh
->dma_bounce_buffer
);
146 wh
->dma_bounce_buffer
= NULL
;
147 wh
->dma_bounce_len
= 0;
151 static struct scsi_host_template a2091_scsi_template
= {
152 .module
= THIS_MODULE
,
153 .name
= "Commodore A2091/A590 SCSI",
154 .show_info
= wd33c93_show_info
,
155 .write_info
= wd33c93_write_info
,
156 .proc_name
= "A2901",
157 .queuecommand
= wd33c93_queuecommand
,
158 .eh_abort_handler
= wd33c93_abort
,
159 .eh_host_reset_handler
= wd33c93_host_reset
,
160 .can_queue
= CAN_QUEUE
,
162 .sg_tablesize
= SG_ALL
,
163 .cmd_per_lun
= CMD_PER_LUN
,
164 .dma_boundary
= PAGE_SIZE
- 1,
167 static int a2091_probe(struct zorro_dev
*z
, const struct zorro_device_id
*ent
)
169 struct Scsi_Host
*instance
;
171 struct a2091_scsiregs
*regs
;
173 struct a2091_hostdata
*hdata
;
175 if (!request_mem_region(z
->resource
.start
, 256, "wd33c93"))
178 instance
= scsi_host_alloc(&a2091_scsi_template
,
179 sizeof(struct a2091_hostdata
));
185 instance
->irq
= IRQ_AMIGA_PORTS
;
186 instance
->unique_id
= z
->slotaddr
;
188 regs
= ZTWO_VADDR(z
->resource
.start
);
189 regs
->DAWR
= DAWR_A2091
;
191 wdregs
.SASR
= ®s
->SASR
;
192 wdregs
.SCMD
= ®s
->SCMD
;
194 hdata
= shost_priv(instance
);
195 hdata
->wh
.no_sync
= 0xff;
197 hdata
->wh
.dma_mode
= CTRL_DMA
;
200 wd33c93_init(instance
, wdregs
, dma_setup
, dma_stop
, WD33C93_FS_8_10
);
201 error
= request_irq(IRQ_AMIGA_PORTS
, a2091_intr
, IRQF_SHARED
,
202 "A2091 SCSI", instance
);
206 regs
->CNTR
= CNTR_PDMD
| CNTR_INTEN
;
208 error
= scsi_add_host(instance
, NULL
);
212 zorro_set_drvdata(z
, instance
);
214 scsi_scan_host(instance
);
218 free_irq(IRQ_AMIGA_PORTS
, instance
);
220 scsi_host_put(instance
);
222 release_mem_region(z
->resource
.start
, 256);
226 static void a2091_remove(struct zorro_dev
*z
)
228 struct Scsi_Host
*instance
= zorro_get_drvdata(z
);
229 struct a2091_hostdata
*hdata
= shost_priv(instance
);
231 hdata
->regs
->CNTR
= 0;
232 scsi_remove_host(instance
);
233 free_irq(IRQ_AMIGA_PORTS
, instance
);
234 scsi_host_put(instance
);
235 release_mem_region(z
->resource
.start
, 256);
238 static struct zorro_device_id a2091_zorro_tbl
[] = {
239 { ZORRO_PROD_CBM_A590_A2091_1
},
240 { ZORRO_PROD_CBM_A590_A2091_2
},
243 MODULE_DEVICE_TABLE(zorro
, a2091_zorro_tbl
);
245 static struct zorro_driver a2091_driver
= {
247 .id_table
= a2091_zorro_tbl
,
248 .probe
= a2091_probe
,
249 .remove
= a2091_remove
,
252 static int __init
a2091_init(void)
254 return zorro_register_driver(&a2091_driver
);
256 module_init(a2091_init
);
258 static void __exit
a2091_exit(void)
260 zorro_unregister_driver(&a2091_driver
);
262 module_exit(a2091_exit
);
264 MODULE_DESCRIPTION("Commodore A2091/A590 SCSI");
265 MODULE_LICENSE("GPL");