]>
Commit | Line | Data |
---|---|---|
1da177e4 | 1 | #include <linux/types.h> |
1da177e4 LT |
2 | #include <linux/init.h> |
3 | #include <linux/interrupt.h> | |
c737e22c GU |
4 | #include <linux/mm.h> |
5 | #include <linux/slab.h> | |
6 | #include <linux/spinlock.h> | |
7 | #include <linux/zorro.h> | |
acf3368f | 8 | #include <linux/module.h> |
1da177e4 | 9 | |
1da177e4 LT |
10 | #include <asm/page.h> |
11 | #include <asm/pgtable.h> | |
12 | #include <asm/amigaints.h> | |
13 | #include <asm/amigahw.h> | |
1da177e4 LT |
14 | |
15 | #include "scsi.h" | |
1da177e4 LT |
16 | #include "wd33c93.h" |
17 | #include "a2091.h" | |
18 | ||
5880f486 | 19 | |
65c2784a GU |
20 | struct a2091_hostdata { |
21 | struct WD33C93_hostdata wh; | |
22 | struct a2091_scsiregs *regs; | |
23 | }; | |
24 | ||
b1de6ab7 | 25 | static irqreturn_t a2091_intr(int irq, void *data) |
1da177e4 | 26 | { |
b1de6ab7 | 27 | struct Scsi_Host *instance = data; |
65c2784a GU |
28 | struct a2091_hostdata *hdata = shost_priv(instance); |
29 | unsigned int status = hdata->regs->ISTR; | |
09bc85b0 | 30 | unsigned long flags; |
09bc85b0 | 31 | |
09bc85b0 GU |
32 | if (!(status & (ISTR_INT_F | ISTR_INT_P)) || !(status & ISTR_INTS)) |
33 | return IRQ_NONE; | |
34 | ||
35 | spin_lock_irqsave(instance->host_lock, flags); | |
36 | wd33c93_intr(instance); | |
37 | spin_unlock_irqrestore(instance->host_lock, flags); | |
38 | return IRQ_HANDLED; | |
1da177e4 LT |
39 | } |
40 | ||
65396410 | 41 | static int dma_setup(struct scsi_cmnd *cmd, int dir_in) |
1da177e4 | 42 | { |
6d1d5d43 | 43 | struct Scsi_Host *instance = cmd->device->host; |
65c2784a GU |
44 | struct a2091_hostdata *hdata = shost_priv(instance); |
45 | struct WD33C93_hostdata *wh = &hdata->wh; | |
46 | struct a2091_scsiregs *regs = hdata->regs; | |
09bc85b0 GU |
47 | unsigned short cntr = CNTR_PDMD | CNTR_INTEN; |
48 | unsigned long addr = virt_to_bus(cmd->SCp.ptr); | |
1da177e4 | 49 | |
09bc85b0 | 50 | /* don't allow DMA if the physical address is bad */ |
1da177e4 | 51 | if (addr & A2091_XFER_MASK) { |
65c2784a GU |
52 | wh->dma_bounce_len = (cmd->SCp.this_residual + 511) & ~0x1ff; |
53 | wh->dma_bounce_buffer = kmalloc(wh->dma_bounce_len, | |
54 | GFP_KERNEL); | |
09bc85b0 GU |
55 | |
56 | /* can't allocate memory; use PIO */ | |
65c2784a GU |
57 | if (!wh->dma_bounce_buffer) { |
58 | wh->dma_bounce_len = 0; | |
09bc85b0 GU |
59 | return 1; |
60 | } | |
61 | ||
62 | /* get the physical address of the bounce buffer */ | |
65c2784a | 63 | addr = virt_to_bus(wh->dma_bounce_buffer); |
09bc85b0 GU |
64 | |
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 */ | |
65c2784a GU |
68 | kfree(wh->dma_bounce_buffer); |
69 | wh->dma_bounce_buffer = NULL; | |
70 | wh->dma_bounce_len = 0; | |
09bc85b0 GU |
71 | return 1; |
72 | } | |
73 | ||
74 | if (!dir_in) { | |
75 | /* copy to bounce buffer for a write */ | |
65c2784a | 76 | memcpy(wh->dma_bounce_buffer, cmd->SCp.ptr, |
6d1d5d43 | 77 | cmd->SCp.this_residual); |
09bc85b0 | 78 | } |
1da177e4 | 79 | } |
1da177e4 | 80 | |
09bc85b0 GU |
81 | /* setup dma direction */ |
82 | if (!dir_in) | |
83 | cntr |= CNTR_DDIR; | |
1da177e4 | 84 | |
09bc85b0 | 85 | /* remember direction */ |
65c2784a | 86 | wh->dma_dir = dir_in; |
1da177e4 | 87 | |
b1de6ab7 | 88 | regs->CNTR = cntr; |
1da177e4 | 89 | |
09bc85b0 | 90 | /* setup DMA *physical* address */ |
b1de6ab7 | 91 | regs->ACR = addr; |
1da177e4 | 92 | |
09bc85b0 GU |
93 | if (dir_in) { |
94 | /* invalidate any cache */ | |
95 | cache_clear(addr, cmd->SCp.this_residual); | |
96 | } else { | |
97 | /* push any dirty cache */ | |
98 | cache_push(addr, cmd->SCp.this_residual); | |
99 | } | |
100 | /* start DMA */ | |
b1de6ab7 | 101 | regs->ST_DMA = 1; |
1da177e4 | 102 | |
09bc85b0 GU |
103 | /* return success */ |
104 | return 0; | |
1da177e4 LT |
105 | } |
106 | ||
65396410 | 107 | static void dma_stop(struct Scsi_Host *instance, struct scsi_cmnd *SCpnt, |
09bc85b0 | 108 | int status) |
1da177e4 | 109 | { |
65c2784a GU |
110 | struct a2091_hostdata *hdata = shost_priv(instance); |
111 | struct WD33C93_hostdata *wh = &hdata->wh; | |
112 | struct a2091_scsiregs *regs = hdata->regs; | |
6d1d5d43 | 113 | |
09bc85b0 GU |
114 | /* disable SCSI interrupts */ |
115 | unsigned short cntr = CNTR_PDMD; | |
116 | ||
65c2784a | 117 | if (!wh->dma_dir) |
09bc85b0 GU |
118 | cntr |= CNTR_DDIR; |
119 | ||
120 | /* disable SCSI interrupts */ | |
b1de6ab7 | 121 | regs->CNTR = cntr; |
09bc85b0 GU |
122 | |
123 | /* flush if we were reading */ | |
65c2784a | 124 | if (wh->dma_dir) { |
b1de6ab7 GU |
125 | regs->FLUSH = 1; |
126 | while (!(regs->ISTR & ISTR_FE_FLG)) | |
09bc85b0 GU |
127 | ; |
128 | } | |
129 | ||
130 | /* clear a possible interrupt */ | |
b1de6ab7 | 131 | regs->CINT = 1; |
09bc85b0 GU |
132 | |
133 | /* stop DMA */ | |
b1de6ab7 | 134 | regs->SP_DMA = 1; |
09bc85b0 GU |
135 | |
136 | /* restore the CONTROL bits (minus the direction flag) */ | |
b1de6ab7 | 137 | regs->CNTR = CNTR_PDMD | CNTR_INTEN; |
09bc85b0 GU |
138 | |
139 | /* copy from a bounce buffer, if necessary */ | |
65c2784a GU |
140 | if (status && wh->dma_bounce_buffer) { |
141 | if (wh->dma_dir) | |
142 | memcpy(SCpnt->SCp.ptr, wh->dma_bounce_buffer, | |
09bc85b0 | 143 | SCpnt->SCp.this_residual); |
65c2784a GU |
144 | kfree(wh->dma_bounce_buffer); |
145 | wh->dma_bounce_buffer = NULL; | |
146 | wh->dma_bounce_len = 0; | |
09bc85b0 | 147 | } |
1da177e4 LT |
148 | } |
149 | ||
c737e22c GU |
150 | static struct scsi_host_template a2091_scsi_template = { |
151 | .module = THIS_MODULE, | |
1da177e4 | 152 | .name = "Commodore A2091/A590 SCSI", |
408bb25b AV |
153 | .show_info = wd33c93_show_info, |
154 | .write_info = wd33c93_write_info, | |
c737e22c | 155 | .proc_name = "A2901", |
1da177e4 LT |
156 | .queuecommand = wd33c93_queuecommand, |
157 | .eh_abort_handler = wd33c93_abort, | |
1da177e4 LT |
158 | .eh_host_reset_handler = wd33c93_host_reset, |
159 | .can_queue = CAN_QUEUE, | |
160 | .this_id = 7, | |
161 | .sg_tablesize = SG_ALL, | |
162 | .cmd_per_lun = CMD_PER_LUN, | |
163 | .use_clustering = DISABLE_CLUSTERING | |
164 | }; | |
165 | ||
6f039790 | 166 | static int a2091_probe(struct zorro_dev *z, const struct zorro_device_id *ent) |
c737e22c GU |
167 | { |
168 | struct Scsi_Host *instance; | |
169 | int error; | |
170 | struct a2091_scsiregs *regs; | |
171 | wd33c93_regs wdregs; | |
65c2784a | 172 | struct a2091_hostdata *hdata; |
c737e22c GU |
173 | |
174 | if (!request_mem_region(z->resource.start, 256, "wd33c93")) | |
175 | return -EBUSY; | |
176 | ||
177 | instance = scsi_host_alloc(&a2091_scsi_template, | |
65c2784a | 178 | sizeof(struct a2091_hostdata)); |
c737e22c GU |
179 | if (!instance) { |
180 | error = -ENOMEM; | |
181 | goto fail_alloc; | |
182 | } | |
183 | ||
c737e22c GU |
184 | instance->irq = IRQ_AMIGA_PORTS; |
185 | instance->unique_id = z->slotaddr; | |
186 | ||
6112ea08 | 187 | regs = ZTWO_VADDR(z->resource.start); |
c737e22c GU |
188 | regs->DAWR = DAWR_A2091; |
189 | ||
190 | wdregs.SASR = ®s->SASR; | |
191 | wdregs.SCMD = ®s->SCMD; | |
1da177e4 | 192 | |
c737e22c | 193 | hdata = shost_priv(instance); |
65c2784a GU |
194 | hdata->wh.no_sync = 0xff; |
195 | hdata->wh.fast = 0; | |
196 | hdata->wh.dma_mode = CTRL_DMA; | |
197 | hdata->regs = regs; | |
c737e22c GU |
198 | |
199 | wd33c93_init(instance, wdregs, dma_setup, dma_stop, WD33C93_FS_8_10); | |
200 | error = request_irq(IRQ_AMIGA_PORTS, a2091_intr, IRQF_SHARED, | |
201 | "A2091 SCSI", instance); | |
202 | if (error) | |
203 | goto fail_irq; | |
204 | ||
205 | regs->CNTR = CNTR_PDMD | CNTR_INTEN; | |
206 | ||
207 | error = scsi_add_host(instance, NULL); | |
208 | if (error) | |
209 | goto fail_host; | |
210 | ||
211 | zorro_set_drvdata(z, instance); | |
212 | ||
213 | scsi_scan_host(instance); | |
214 | return 0; | |
1da177e4 | 215 | |
c737e22c GU |
216 | fail_host: |
217 | free_irq(IRQ_AMIGA_PORTS, instance); | |
218 | fail_irq: | |
219 | scsi_host_put(instance); | |
220 | fail_alloc: | |
221 | release_mem_region(z->resource.start, 256); | |
222 | return error; | |
223 | } | |
224 | ||
6f039790 | 225 | static void a2091_remove(struct zorro_dev *z) |
1da177e4 | 226 | { |
c737e22c | 227 | struct Scsi_Host *instance = zorro_get_drvdata(z); |
65c2784a | 228 | struct a2091_hostdata *hdata = shost_priv(instance); |
b1de6ab7 | 229 | |
65c2784a | 230 | hdata->regs->CNTR = 0; |
c737e22c | 231 | scsi_remove_host(instance); |
1da177e4 | 232 | free_irq(IRQ_AMIGA_PORTS, instance); |
c737e22c GU |
233 | scsi_host_put(instance); |
234 | release_mem_region(z->resource.start, 256); | |
235 | } | |
236 | ||
6f039790 | 237 | static struct zorro_device_id a2091_zorro_tbl[] = { |
c737e22c GU |
238 | { ZORRO_PROD_CBM_A590_A2091_1 }, |
239 | { ZORRO_PROD_CBM_A590_A2091_2 }, | |
240 | { 0 } | |
241 | }; | |
242 | MODULE_DEVICE_TABLE(zorro, a2091_zorro_tbl); | |
243 | ||
244 | static struct zorro_driver a2091_driver = { | |
245 | .name = "a2091", | |
246 | .id_table = a2091_zorro_tbl, | |
247 | .probe = a2091_probe, | |
6f039790 | 248 | .remove = a2091_remove, |
c737e22c GU |
249 | }; |
250 | ||
251 | static int __init a2091_init(void) | |
252 | { | |
253 | return zorro_register_driver(&a2091_driver); | |
254 | } | |
255 | module_init(a2091_init); | |
256 | ||
257 | static void __exit a2091_exit(void) | |
258 | { | |
259 | zorro_unregister_driver(&a2091_driver); | |
1da177e4 | 260 | } |
c737e22c | 261 | module_exit(a2091_exit); |
1da177e4 | 262 | |
c737e22c | 263 | MODULE_DESCRIPTION("Commodore A2091/A590 SCSI"); |
1da177e4 | 264 | MODULE_LICENSE("GPL"); |