Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #include <linux/types.h> |
| 2 | #include <linux/mm.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 3 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | #include <linux/blkdev.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | #include <linux/init.h> |
| 6 | #include <linux/interrupt.h> |
| 7 | |
| 8 | #include <asm/setup.h> |
| 9 | #include <asm/page.h> |
| 10 | #include <asm/pgtable.h> |
| 11 | #include <asm/amigaints.h> |
| 12 | #include <asm/amigahw.h> |
| 13 | #include <linux/zorro.h> |
| 14 | #include <asm/irq.h> |
| 15 | #include <linux/spinlock.h> |
| 16 | |
| 17 | #include "scsi.h" |
| 18 | #include <scsi/scsi_host.h> |
| 19 | #include "wd33c93.h" |
| 20 | #include "gvp11.h" |
| 21 | |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 22 | #include <linux/stat.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | |
Geert Uytterhoeven | 11ca46e | 2009-05-17 20:44:16 +0200 | [diff] [blame] | 25 | #define CHECK_WD33C93 |
| 26 | |
Geert Uytterhoeven | 6869b15 | 2009-05-17 12:17:28 +0200 | [diff] [blame] | 27 | static irqreturn_t gvp11_intr(int irq, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | { |
Geert Uytterhoeven | 6869b15 | 2009-05-17 12:17:28 +0200 | [diff] [blame] | 29 | struct Scsi_Host *instance = data; |
Geert Uytterhoeven | 349d65f | 2009-05-17 21:05:55 +0200 | [diff] [blame] | 30 | struct gvp11_scsiregs *regs = (struct gvp11_scsiregs *)(instance->base); |
Geert Uytterhoeven | 6869b15 | 2009-05-17 12:17:28 +0200 | [diff] [blame] | 31 | unsigned int status = regs->CNTR; |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 32 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 34 | if (!(status & GVP11_DMAC_INT_PENDING)) |
| 35 | return IRQ_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 37 | spin_lock_irqsave(instance->host_lock, flags); |
| 38 | wd33c93_intr(instance); |
| 39 | spin_unlock_irqrestore(instance->host_lock, flags); |
| 40 | return IRQ_HANDLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | static int gvp11_xfer_mask = 0; |
| 44 | |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 45 | void gvp11_setup(char *str, int *ints) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | { |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 47 | gvp11_xfer_mask = ints[1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | } |
| 49 | |
Henrik Kretzschmar | 6539641 | 2006-09-12 23:49:33 +0200 | [diff] [blame] | 50 | static int dma_setup(struct scsi_cmnd *cmd, int dir_in) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | { |
Geert Uytterhoeven | 52c3d8a | 2010-04-04 11:00:37 +0200 | [diff] [blame] | 52 | struct Scsi_Host *instance = cmd->device->host; |
| 53 | struct WD33C93_hostdata *hdata = shost_priv(instance); |
Geert Uytterhoeven | 349d65f | 2009-05-17 21:05:55 +0200 | [diff] [blame] | 54 | struct gvp11_scsiregs *regs = (struct gvp11_scsiregs *)(instance->base); |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 55 | unsigned short cntr = GVP11_DMAC_INT_ENABLE; |
| 56 | unsigned long addr = virt_to_bus(cmd->SCp.ptr); |
| 57 | int bank_mask; |
| 58 | static int scsi_alloc_out_of_range = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 60 | /* use bounce buffer if the physical address is bad */ |
Geert Uytterhoeven | 52c3d8a | 2010-04-04 11:00:37 +0200 | [diff] [blame] | 61 | if (addr & hdata->dma_xfer_mask) { |
| 62 | hdata->dma_bounce_len = (cmd->SCp.this_residual + 511) & ~0x1ff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 64 | if (!scsi_alloc_out_of_range) { |
Geert Uytterhoeven | 52c3d8a | 2010-04-04 11:00:37 +0200 | [diff] [blame] | 65 | hdata->dma_bounce_buffer = |
| 66 | kmalloc(hdata->dma_bounce_len, GFP_KERNEL); |
| 67 | hdata->dma_buffer_pool = BUF_SCSI_ALLOCED; |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 68 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 70 | if (scsi_alloc_out_of_range || |
Geert Uytterhoeven | 52c3d8a | 2010-04-04 11:00:37 +0200 | [diff] [blame] | 71 | !hdata->dma_bounce_buffer) { |
| 72 | hdata->dma_bounce_buffer = |
| 73 | amiga_chip_alloc(hdata->dma_bounce_len, |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 74 | "GVP II SCSI Bounce Buffer"); |
| 75 | |
Geert Uytterhoeven | 52c3d8a | 2010-04-04 11:00:37 +0200 | [diff] [blame] | 76 | if (!hdata->dma_bounce_buffer) { |
| 77 | hdata->dma_bounce_len = 0; |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 78 | return 1; |
| 79 | } |
| 80 | |
Geert Uytterhoeven | 52c3d8a | 2010-04-04 11:00:37 +0200 | [diff] [blame] | 81 | hdata->dma_buffer_pool = BUF_CHIP_ALLOCED; |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | /* check if the address of the bounce buffer is OK */ |
Geert Uytterhoeven | 52c3d8a | 2010-04-04 11:00:37 +0200 | [diff] [blame] | 85 | addr = virt_to_bus(hdata->dma_bounce_buffer); |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 86 | |
Geert Uytterhoeven | 52c3d8a | 2010-04-04 11:00:37 +0200 | [diff] [blame] | 87 | if (addr & hdata->dma_xfer_mask) { |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 88 | /* fall back to Chip RAM if address out of range */ |
Geert Uytterhoeven | 52c3d8a | 2010-04-04 11:00:37 +0200 | [diff] [blame] | 89 | if (hdata->dma_buffer_pool == BUF_SCSI_ALLOCED) { |
| 90 | kfree(hdata->dma_bounce_buffer); |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 91 | scsi_alloc_out_of_range = 1; |
| 92 | } else { |
Geert Uytterhoeven | 52c3d8a | 2010-04-04 11:00:37 +0200 | [diff] [blame] | 93 | amiga_chip_free(hdata->dma_bounce_buffer); |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 94 | } |
| 95 | |
Geert Uytterhoeven | 52c3d8a | 2010-04-04 11:00:37 +0200 | [diff] [blame] | 96 | hdata->dma_bounce_buffer = |
| 97 | amiga_chip_alloc(hdata->dma_bounce_len, |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 98 | "GVP II SCSI Bounce Buffer"); |
| 99 | |
Geert Uytterhoeven | 52c3d8a | 2010-04-04 11:00:37 +0200 | [diff] [blame] | 100 | if (!hdata->dma_bounce_buffer) { |
| 101 | hdata->dma_bounce_len = 0; |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 102 | return 1; |
| 103 | } |
| 104 | |
Geert Uytterhoeven | 52c3d8a | 2010-04-04 11:00:37 +0200 | [diff] [blame] | 105 | addr = virt_to_bus(hdata->dma_bounce_buffer); |
| 106 | hdata->dma_buffer_pool = BUF_CHIP_ALLOCED; |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | if (!dir_in) { |
| 110 | /* copy to bounce buffer for a write */ |
Geert Uytterhoeven | 52c3d8a | 2010-04-04 11:00:37 +0200 | [diff] [blame] | 111 | memcpy(hdata->dma_bounce_buffer, cmd->SCp.ptr, |
| 112 | cmd->SCp.this_residual); |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 113 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | } |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 115 | |
| 116 | /* setup dma direction */ |
| 117 | if (!dir_in) |
| 118 | cntr |= GVP11_DMAC_DIR_WRITE; |
| 119 | |
Geert Uytterhoeven | 52c3d8a | 2010-04-04 11:00:37 +0200 | [diff] [blame] | 120 | hdata->dma_dir = dir_in; |
Geert Uytterhoeven | 6869b15 | 2009-05-17 12:17:28 +0200 | [diff] [blame] | 121 | regs->CNTR = cntr; |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 122 | |
| 123 | /* setup DMA *physical* address */ |
Geert Uytterhoeven | 6869b15 | 2009-05-17 12:17:28 +0200 | [diff] [blame] | 124 | regs->ACR = addr; |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 125 | |
| 126 | if (dir_in) { |
| 127 | /* invalidate any cache */ |
| 128 | cache_clear(addr, cmd->SCp.this_residual); |
| 129 | } else { |
| 130 | /* push any dirty cache */ |
| 131 | cache_push(addr, cmd->SCp.this_residual); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | |
Geert Uytterhoeven | 52c3d8a | 2010-04-04 11:00:37 +0200 | [diff] [blame] | 134 | bank_mask = (~hdata->dma_xfer_mask >> 18) & 0x01c0; |
| 135 | if (bank_mask) |
Geert Uytterhoeven | 6869b15 | 2009-05-17 12:17:28 +0200 | [diff] [blame] | 136 | regs->BANK = bank_mask & (addr >> 18); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 138 | /* start DMA */ |
Geert Uytterhoeven | 6869b15 | 2009-05-17 12:17:28 +0200 | [diff] [blame] | 139 | regs->ST_DMA = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 141 | /* return success */ |
| 142 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | } |
| 144 | |
Henrik Kretzschmar | 6539641 | 2006-09-12 23:49:33 +0200 | [diff] [blame] | 145 | static void dma_stop(struct Scsi_Host *instance, struct scsi_cmnd *SCpnt, |
| 146 | int status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | { |
Geert Uytterhoeven | 349d65f | 2009-05-17 21:05:55 +0200 | [diff] [blame] | 148 | struct gvp11_scsiregs *regs = (struct gvp11_scsiregs *)(instance->base); |
Geert Uytterhoeven | 52c3d8a | 2010-04-04 11:00:37 +0200 | [diff] [blame] | 149 | struct WD33C93_hostdata *hdata = shost_priv(instance); |
| 150 | |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 151 | /* stop DMA */ |
Geert Uytterhoeven | 6869b15 | 2009-05-17 12:17:28 +0200 | [diff] [blame] | 152 | regs->SP_DMA = 1; |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 153 | /* remove write bit from CONTROL bits */ |
Geert Uytterhoeven | 6869b15 | 2009-05-17 12:17:28 +0200 | [diff] [blame] | 154 | regs->CNTR = GVP11_DMAC_INT_ENABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 156 | /* copy from a bounce buffer, if necessary */ |
Geert Uytterhoeven | 52c3d8a | 2010-04-04 11:00:37 +0200 | [diff] [blame] | 157 | if (status && hdata->dma_bounce_buffer) { |
| 158 | if (hdata->dma_dir && SCpnt) |
| 159 | memcpy(SCpnt->SCp.ptr, hdata->dma_bounce_buffer, |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 160 | SCpnt->SCp.this_residual); |
| 161 | |
Geert Uytterhoeven | 52c3d8a | 2010-04-04 11:00:37 +0200 | [diff] [blame] | 162 | if (hdata->dma_buffer_pool == BUF_SCSI_ALLOCED) |
| 163 | kfree(hdata->dma_bounce_buffer); |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 164 | else |
Geert Uytterhoeven | 52c3d8a | 2010-04-04 11:00:37 +0200 | [diff] [blame] | 165 | amiga_chip_free(hdata->dma_bounce_buffer); |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 166 | |
Geert Uytterhoeven | 52c3d8a | 2010-04-04 11:00:37 +0200 | [diff] [blame] | 167 | hdata->dma_bounce_buffer = NULL; |
| 168 | hdata->dma_bounce_len = 0; |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 169 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | } |
| 171 | |
Geert Uytterhoeven | 349d65f | 2009-05-17 21:05:55 +0200 | [diff] [blame] | 172 | static int __init check_wd33c93(struct gvp11_scsiregs *regs) |
Geert Uytterhoeven | 11ca46e | 2009-05-17 20:44:16 +0200 | [diff] [blame] | 173 | { |
| 174 | #ifdef CHECK_WD33C93 |
| 175 | volatile unsigned char *sasr_3393, *scmd_3393; |
| 176 | unsigned char save_sasr; |
| 177 | unsigned char q, qq; |
| 178 | |
| 179 | /* |
| 180 | * These darn GVP boards are a problem - it can be tough to tell |
| 181 | * whether or not they include a SCSI controller. This is the |
| 182 | * ultimate Yet-Another-GVP-Detection-Hack in that it actually |
| 183 | * probes for a WD33c93 chip: If we find one, it's extremely |
| 184 | * likely that this card supports SCSI, regardless of Product_ |
| 185 | * Code, Board_Size, etc. |
| 186 | */ |
| 187 | |
| 188 | /* Get pointers to the presumed register locations and save contents */ |
| 189 | |
| 190 | sasr_3393 = ®s->SASR; |
| 191 | scmd_3393 = ®s->SCMD; |
| 192 | save_sasr = *sasr_3393; |
| 193 | |
| 194 | /* First test the AuxStatus Reg */ |
| 195 | |
| 196 | q = *sasr_3393; /* read it */ |
| 197 | if (q & 0x08) /* bit 3 should always be clear */ |
| 198 | return -ENODEV; |
| 199 | *sasr_3393 = WD_AUXILIARY_STATUS; /* setup indirect address */ |
| 200 | if (*sasr_3393 == WD_AUXILIARY_STATUS) { /* shouldn't retain the write */ |
| 201 | *sasr_3393 = save_sasr; /* Oops - restore this byte */ |
| 202 | return -ENODEV; |
| 203 | } |
| 204 | if (*sasr_3393 != q) { /* should still read the same */ |
| 205 | *sasr_3393 = save_sasr; /* Oops - restore this byte */ |
| 206 | return -ENODEV; |
| 207 | } |
| 208 | if (*scmd_3393 != q) /* and so should the image at 0x1f */ |
| 209 | return -ENODEV; |
| 210 | |
| 211 | /* |
| 212 | * Ok, we probably have a wd33c93, but let's check a few other places |
| 213 | * for good measure. Make sure that this works for both 'A and 'B |
| 214 | * chip versions. |
| 215 | */ |
| 216 | |
| 217 | *sasr_3393 = WD_SCSI_STATUS; |
| 218 | q = *scmd_3393; |
| 219 | *sasr_3393 = WD_SCSI_STATUS; |
| 220 | *scmd_3393 = ~q; |
| 221 | *sasr_3393 = WD_SCSI_STATUS; |
| 222 | qq = *scmd_3393; |
| 223 | *sasr_3393 = WD_SCSI_STATUS; |
| 224 | *scmd_3393 = q; |
| 225 | if (qq != q) /* should be read only */ |
| 226 | return -ENODEV; |
| 227 | *sasr_3393 = 0x1e; /* this register is unimplemented */ |
| 228 | q = *scmd_3393; |
| 229 | *sasr_3393 = 0x1e; |
| 230 | *scmd_3393 = ~q; |
| 231 | *sasr_3393 = 0x1e; |
| 232 | qq = *scmd_3393; |
| 233 | *sasr_3393 = 0x1e; |
| 234 | *scmd_3393 = q; |
| 235 | if (qq != q || qq != 0xff) /* should be read only, all 1's */ |
| 236 | return -ENODEV; |
| 237 | *sasr_3393 = WD_TIMEOUT_PERIOD; |
| 238 | q = *scmd_3393; |
| 239 | *sasr_3393 = WD_TIMEOUT_PERIOD; |
| 240 | *scmd_3393 = ~q; |
| 241 | *sasr_3393 = WD_TIMEOUT_PERIOD; |
| 242 | qq = *scmd_3393; |
| 243 | *sasr_3393 = WD_TIMEOUT_PERIOD; |
| 244 | *scmd_3393 = q; |
| 245 | if (qq != (~q & 0xff)) /* should be read/write */ |
| 246 | return -ENODEV; |
| 247 | #endif /* CHECK_WD33C93 */ |
| 248 | |
| 249 | return 0; |
| 250 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | |
Christoph Hellwig | d0be4a7d | 2005-10-31 18:31:40 +0100 | [diff] [blame] | 252 | int __init gvp11_detect(struct scsi_host_template *tpnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | { |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 254 | static unsigned char called = 0; |
| 255 | struct Scsi_Host *instance; |
| 256 | unsigned long address; |
| 257 | unsigned int epc; |
| 258 | struct zorro_dev *z = NULL; |
| 259 | unsigned int default_dma_xfer_mask; |
Geert Uytterhoeven | 52c3d8a | 2010-04-04 11:00:37 +0200 | [diff] [blame] | 260 | struct WD33C93_hostdata *hdata; |
Geert Uytterhoeven | 349d65f | 2009-05-17 21:05:55 +0200 | [diff] [blame] | 261 | struct gvp11_scsiregs *regs; |
Geert Uytterhoeven | 6869b15 | 2009-05-17 12:17:28 +0200 | [diff] [blame] | 262 | wd33c93_regs wdregs; |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 263 | int num_gvp11 = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 265 | if (!MACH_IS_AMIGA || called) |
| 266 | return 0; |
| 267 | called = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 269 | tpnt->proc_name = "GVP11"; |
| 270 | tpnt->proc_info = &wd33c93_proc_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 272 | while ((z = zorro_find_device(ZORRO_WILDCARD, z))) { |
| 273 | /* |
| 274 | * This should (hopefully) be the correct way to identify |
| 275 | * all the different GVP SCSI controllers (except for the |
| 276 | * SERIES I though). |
| 277 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 279 | if (z->id == ZORRO_PROD_GVP_COMBO_030_R3_SCSI || |
| 280 | z->id == ZORRO_PROD_GVP_SERIES_II) |
| 281 | default_dma_xfer_mask = ~0x00ffffff; |
| 282 | else if (z->id == ZORRO_PROD_GVP_GFORCE_030_SCSI || |
| 283 | z->id == ZORRO_PROD_GVP_A530_SCSI || |
| 284 | z->id == ZORRO_PROD_GVP_COMBO_030_R4_SCSI) |
| 285 | default_dma_xfer_mask = ~0x01ffffff; |
| 286 | else if (z->id == ZORRO_PROD_GVP_A1291 || |
| 287 | z->id == ZORRO_PROD_GVP_GFORCE_040_SCSI_1) |
| 288 | default_dma_xfer_mask = ~0x07ffffff; |
| 289 | else |
| 290 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 292 | /* |
| 293 | * Rumors state that some GVP ram boards use the same product |
| 294 | * code as the SCSI controllers. Therefore if the board-size |
| 295 | * is not 64KB we asume it is a ram board and bail out. |
| 296 | */ |
| 297 | if (z->resource.end - z->resource.start != 0xffff) |
| 298 | continue; |
| 299 | |
| 300 | address = z->resource.start; |
| 301 | if (!request_mem_region(address, 256, "wd33c93")) |
| 302 | continue; |
| 303 | |
Geert Uytterhoeven | 349d65f | 2009-05-17 21:05:55 +0200 | [diff] [blame] | 304 | regs = (struct gvp11_scsiregs *)(ZTWO_VADDR(address)); |
Geert Uytterhoeven | 11ca46e | 2009-05-17 20:44:16 +0200 | [diff] [blame] | 305 | if (check_wd33c93(regs)) |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 306 | goto release; |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 307 | |
| 308 | instance = scsi_register(tpnt, sizeof(struct WD33C93_hostdata)); |
| 309 | if (instance == NULL) |
| 310 | goto release; |
| 311 | instance->base = ZTWO_VADDR(address); |
| 312 | instance->irq = IRQ_AMIGA_PORTS; |
| 313 | instance->unique_id = z->slotaddr; |
| 314 | |
Geert Uytterhoeven | 52c3d8a | 2010-04-04 11:00:37 +0200 | [diff] [blame] | 315 | hdata = shost_priv(instance); |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 316 | if (gvp11_xfer_mask) |
Geert Uytterhoeven | 52c3d8a | 2010-04-04 11:00:37 +0200 | [diff] [blame] | 317 | hdata->dma_xfer_mask = gvp11_xfer_mask; |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 318 | else |
Geert Uytterhoeven | 52c3d8a | 2010-04-04 11:00:37 +0200 | [diff] [blame] | 319 | hdata->dma_xfer_mask = default_dma_xfer_mask; |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 320 | |
Geert Uytterhoeven | 6869b15 | 2009-05-17 12:17:28 +0200 | [diff] [blame] | 321 | regs->secret2 = 1; |
| 322 | regs->secret1 = 0; |
| 323 | regs->secret3 = 15; |
| 324 | while (regs->CNTR & GVP11_DMAC_BUSY) |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 325 | ; |
Geert Uytterhoeven | 6869b15 | 2009-05-17 12:17:28 +0200 | [diff] [blame] | 326 | regs->CNTR = 0; |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 327 | |
Geert Uytterhoeven | 6869b15 | 2009-05-17 12:17:28 +0200 | [diff] [blame] | 328 | regs->BANK = 0; |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 329 | |
| 330 | epc = *(unsigned short *)(ZTWO_VADDR(address) + 0x8000); |
| 331 | |
| 332 | /* |
| 333 | * Check for 14MHz SCSI clock |
| 334 | */ |
Geert Uytterhoeven | 6869b15 | 2009-05-17 12:17:28 +0200 | [diff] [blame] | 335 | wdregs.SASR = ®s->SASR; |
| 336 | wdregs.SCMD = ®s->SCMD; |
Geert Uytterhoeven | 52c3d8a | 2010-04-04 11:00:37 +0200 | [diff] [blame] | 337 | hdata->no_sync = 0xff; |
| 338 | hdata->fast = 0; |
| 339 | hdata->dma_mode = CTRL_DMA; |
Geert Uytterhoeven | 6869b15 | 2009-05-17 12:17:28 +0200 | [diff] [blame] | 340 | wd33c93_init(instance, wdregs, dma_setup, dma_stop, |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 341 | (epc & GVP_SCSICLKMASK) ? WD33C93_FS_8_10 |
| 342 | : WD33C93_FS_12_15); |
| 343 | |
| 344 | if (request_irq(IRQ_AMIGA_PORTS, gvp11_intr, IRQF_SHARED, |
| 345 | "GVP11 SCSI", instance)) |
| 346 | goto unregister; |
Geert Uytterhoeven | 6869b15 | 2009-05-17 12:17:28 +0200 | [diff] [blame] | 347 | regs->CNTR = GVP11_DMAC_INT_ENABLE; |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 348 | num_gvp11++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | continue; |
| 350 | |
Geert Uytterhoeven | d38f47a | 2009-01-02 11:41:24 +0100 | [diff] [blame] | 351 | unregister: |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 352 | scsi_unregister(instance); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | release: |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 354 | release_mem_region(address, 256); |
| 355 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 357 | return num_gvp11; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | } |
| 359 | |
Henrik Kretzschmar | 6539641 | 2006-09-12 23:49:33 +0200 | [diff] [blame] | 360 | static int gvp11_bus_reset(struct scsi_cmnd *cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | { |
| 362 | /* FIXME perform bus-specific reset */ |
Jeff Garzik | 68b3aa7 | 2005-05-28 07:56:31 -0400 | [diff] [blame] | 363 | |
Jeff Garzik | df0ae24 | 2005-05-28 07:57:14 -0400 | [diff] [blame] | 364 | /* FIXME 2: shouldn't we no-op this function (return |
| 365 | FAILED), and fall back to host reset function, |
| 366 | wd33c93_host_reset ? */ |
| 367 | |
Jeff Garzik | 68b3aa7 | 2005-05-28 07:56:31 -0400 | [diff] [blame] | 368 | spin_lock_irq(cmd->device->host->host_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | wd33c93_host_reset(cmd); |
Jeff Garzik | 68b3aa7 | 2005-05-28 07:56:31 -0400 | [diff] [blame] | 370 | spin_unlock_irq(cmd->device->host->host_lock); |
| 371 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | return SUCCESS; |
| 373 | } |
| 374 | |
| 375 | |
| 376 | #define HOSTS_C |
| 377 | |
| 378 | #include "gvp11.h" |
| 379 | |
Christoph Hellwig | d0be4a7d | 2005-10-31 18:31:40 +0100 | [diff] [blame] | 380 | static struct scsi_host_template driver_template = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | .proc_name = "GVP11", |
| 382 | .name = "GVP Series II SCSI", |
| 383 | .detect = gvp11_detect, |
| 384 | .release = gvp11_release, |
| 385 | .queuecommand = wd33c93_queuecommand, |
| 386 | .eh_abort_handler = wd33c93_abort, |
| 387 | .eh_bus_reset_handler = gvp11_bus_reset, |
| 388 | .eh_host_reset_handler = wd33c93_host_reset, |
| 389 | .can_queue = CAN_QUEUE, |
| 390 | .this_id = 7, |
| 391 | .sg_tablesize = SG_ALL, |
| 392 | .cmd_per_lun = CMD_PER_LUN, |
| 393 | .use_clustering = DISABLE_CLUSTERING |
| 394 | }; |
| 395 | |
| 396 | |
| 397 | #include "scsi_module.c" |
| 398 | |
| 399 | int gvp11_release(struct Scsi_Host *instance) |
| 400 | { |
| 401 | #ifdef MODULE |
Geert Uytterhoeven | 349d65f | 2009-05-17 21:05:55 +0200 | [diff] [blame] | 402 | struct gvp11_scsiregs *regs = (struct gvp11_scsiregs *)(instance->base); |
Geert Uytterhoeven | 6869b15 | 2009-05-17 12:17:28 +0200 | [diff] [blame] | 403 | |
| 404 | regs->CNTR = 0; |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 405 | release_mem_region(ZTWO_PADDR(instance->base), 256); |
| 406 | free_irq(IRQ_AMIGA_PORTS, instance); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | #endif |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 408 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | MODULE_LICENSE("GPL"); |