Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #include <linux/types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | #include <linux/init.h> |
| 3 | #include <linux/interrupt.h> |
Geert Uytterhoeven | c1d288a | 2009-08-16 11:17:35 +0200 | [diff] [blame] | 4 | #include <linux/mm.h> |
| 5 | #include <linux/slab.h> |
| 6 | #include <linux/spinlock.h> |
| 7 | #include <linux/zorro.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | #include <asm/page.h> |
| 10 | #include <asm/pgtable.h> |
| 11 | #include <asm/amigaints.h> |
| 12 | #include <asm/amigahw.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | |
| 14 | #include "scsi.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include "wd33c93.h" |
| 16 | #include "gvp11.h" |
| 17 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | |
Geert Uytterhoeven | 11ca46e | 2009-05-17 20:44:16 +0200 | [diff] [blame] | 19 | #define CHECK_WD33C93 |
| 20 | |
Geert Uytterhoeven | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 21 | struct gvp11_hostdata { |
| 22 | struct WD33C93_hostdata wh; |
| 23 | struct gvp11_scsiregs *regs; |
| 24 | }; |
| 25 | |
Geert Uytterhoeven | 6869b15 | 2009-05-17 12:17:28 +0200 | [diff] [blame] | 26 | static irqreturn_t gvp11_intr(int irq, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | { |
Geert Uytterhoeven | 6869b15 | 2009-05-17 12:17:28 +0200 | [diff] [blame] | 28 | struct Scsi_Host *instance = data; |
Geert Uytterhoeven | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 29 | struct gvp11_hostdata *hdata = shost_priv(instance); |
| 30 | unsigned int status = hdata->regs->CNTR; |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 31 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 33 | if (!(status & GVP11_DMAC_INT_PENDING)) |
| 34 | return IRQ_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 36 | spin_lock_irqsave(instance->host_lock, flags); |
| 37 | wd33c93_intr(instance); |
| 38 | spin_unlock_irqrestore(instance->host_lock, flags); |
| 39 | return IRQ_HANDLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | static int gvp11_xfer_mask = 0; |
| 43 | |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 44 | void gvp11_setup(char *str, int *ints) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | { |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 46 | gvp11_xfer_mask = ints[1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | } |
| 48 | |
Henrik Kretzschmar | 6539641 | 2006-09-12 23:49:33 +0200 | [diff] [blame] | 49 | static int dma_setup(struct scsi_cmnd *cmd, int dir_in) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | { |
Geert Uytterhoeven | 52c3d8a | 2010-04-04 11:00:37 +0200 | [diff] [blame] | 51 | struct Scsi_Host *instance = cmd->device->host; |
Geert Uytterhoeven | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 52 | struct gvp11_hostdata *hdata = shost_priv(instance); |
| 53 | struct WD33C93_hostdata *wh = &hdata->wh; |
| 54 | struct gvp11_scsiregs *regs = hdata->regs; |
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 | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 61 | if (addr & wh->dma_xfer_mask) { |
| 62 | wh->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 | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 65 | wh->dma_bounce_buffer = |
| 66 | kmalloc(wh->dma_bounce_len, GFP_KERNEL); |
| 67 | wh->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 | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 71 | !wh->dma_bounce_buffer) { |
| 72 | wh->dma_bounce_buffer = |
| 73 | amiga_chip_alloc(wh->dma_bounce_len, |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 74 | "GVP II SCSI Bounce Buffer"); |
| 75 | |
Geert Uytterhoeven | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 76 | if (!wh->dma_bounce_buffer) { |
| 77 | wh->dma_bounce_len = 0; |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 78 | return 1; |
| 79 | } |
| 80 | |
Geert Uytterhoeven | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 81 | wh->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 | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 85 | addr = virt_to_bus(wh->dma_bounce_buffer); |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 86 | |
Geert Uytterhoeven | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 87 | if (addr & wh->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 | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 89 | if (wh->dma_buffer_pool == BUF_SCSI_ALLOCED) { |
| 90 | kfree(wh->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 | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 93 | amiga_chip_free(wh->dma_bounce_buffer); |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 94 | } |
| 95 | |
Geert Uytterhoeven | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 96 | wh->dma_bounce_buffer = |
| 97 | amiga_chip_alloc(wh->dma_bounce_len, |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 98 | "GVP II SCSI Bounce Buffer"); |
| 99 | |
Geert Uytterhoeven | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 100 | if (!wh->dma_bounce_buffer) { |
| 101 | wh->dma_bounce_len = 0; |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 102 | return 1; |
| 103 | } |
| 104 | |
Geert Uytterhoeven | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 105 | addr = virt_to_bus(wh->dma_bounce_buffer); |
| 106 | wh->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 | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 111 | memcpy(wh->dma_bounce_buffer, cmd->SCp.ptr, |
Geert Uytterhoeven | 52c3d8a | 2010-04-04 11:00:37 +0200 | [diff] [blame] | 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 | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 120 | wh->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 | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 134 | bank_mask = (~wh->dma_xfer_mask >> 18) & 0x01c0; |
Geert Uytterhoeven | 52c3d8a | 2010-04-04 11:00:37 +0200 | [diff] [blame] | 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 | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 148 | struct gvp11_hostdata *hdata = shost_priv(instance); |
| 149 | struct WD33C93_hostdata *wh = &hdata->wh; |
| 150 | struct gvp11_scsiregs *regs = hdata->regs; |
Geert Uytterhoeven | 52c3d8a | 2010-04-04 11:00:37 +0200 | [diff] [blame] | 151 | |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 152 | /* stop DMA */ |
Geert Uytterhoeven | 6869b15 | 2009-05-17 12:17:28 +0200 | [diff] [blame] | 153 | regs->SP_DMA = 1; |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 154 | /* remove write bit from CONTROL bits */ |
Geert Uytterhoeven | 6869b15 | 2009-05-17 12:17:28 +0200 | [diff] [blame] | 155 | regs->CNTR = GVP11_DMAC_INT_ENABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 157 | /* copy from a bounce buffer, if necessary */ |
Geert Uytterhoeven | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 158 | if (status && wh->dma_bounce_buffer) { |
| 159 | if (wh->dma_dir && SCpnt) |
| 160 | memcpy(SCpnt->SCp.ptr, wh->dma_bounce_buffer, |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 161 | SCpnt->SCp.this_residual); |
| 162 | |
Geert Uytterhoeven | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 163 | if (wh->dma_buffer_pool == BUF_SCSI_ALLOCED) |
| 164 | kfree(wh->dma_bounce_buffer); |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 165 | else |
Geert Uytterhoeven | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 166 | amiga_chip_free(wh->dma_bounce_buffer); |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 167 | |
Geert Uytterhoeven | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 168 | wh->dma_bounce_buffer = NULL; |
| 169 | wh->dma_bounce_len = 0; |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 170 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | } |
| 172 | |
Geert Uytterhoeven | c1d288a | 2009-08-16 11:17:35 +0200 | [diff] [blame] | 173 | static int gvp11_bus_reset(struct scsi_cmnd *cmd) |
| 174 | { |
| 175 | struct Scsi_Host *instance = cmd->device->host; |
| 176 | |
| 177 | /* FIXME perform bus-specific reset */ |
| 178 | |
| 179 | /* FIXME 2: shouldn't we no-op this function (return |
| 180 | FAILED), and fall back to host reset function, |
| 181 | wd33c93_host_reset ? */ |
| 182 | |
| 183 | spin_lock_irq(instance->host_lock); |
| 184 | wd33c93_host_reset(cmd); |
| 185 | spin_unlock_irq(instance->host_lock); |
| 186 | |
| 187 | return SUCCESS; |
| 188 | } |
| 189 | |
| 190 | static struct scsi_host_template gvp11_scsi_template = { |
| 191 | .module = THIS_MODULE, |
| 192 | .name = "GVP Series II SCSI", |
| 193 | .proc_info = wd33c93_proc_info, |
| 194 | .proc_name = "GVP11", |
| 195 | .queuecommand = wd33c93_queuecommand, |
| 196 | .eh_abort_handler = wd33c93_abort, |
| 197 | .eh_bus_reset_handler = gvp11_bus_reset, |
| 198 | .eh_host_reset_handler = wd33c93_host_reset, |
| 199 | .can_queue = CAN_QUEUE, |
| 200 | .this_id = 7, |
| 201 | .sg_tablesize = SG_ALL, |
| 202 | .cmd_per_lun = CMD_PER_LUN, |
| 203 | .use_clustering = DISABLE_CLUSTERING |
| 204 | }; |
| 205 | |
| 206 | static int __devinit check_wd33c93(struct gvp11_scsiregs *regs) |
Geert Uytterhoeven | 11ca46e | 2009-05-17 20:44:16 +0200 | [diff] [blame] | 207 | { |
| 208 | #ifdef CHECK_WD33C93 |
| 209 | volatile unsigned char *sasr_3393, *scmd_3393; |
| 210 | unsigned char save_sasr; |
| 211 | unsigned char q, qq; |
| 212 | |
| 213 | /* |
| 214 | * These darn GVP boards are a problem - it can be tough to tell |
| 215 | * whether or not they include a SCSI controller. This is the |
| 216 | * ultimate Yet-Another-GVP-Detection-Hack in that it actually |
| 217 | * probes for a WD33c93 chip: If we find one, it's extremely |
| 218 | * likely that this card supports SCSI, regardless of Product_ |
| 219 | * Code, Board_Size, etc. |
| 220 | */ |
| 221 | |
| 222 | /* Get pointers to the presumed register locations and save contents */ |
| 223 | |
| 224 | sasr_3393 = ®s->SASR; |
| 225 | scmd_3393 = ®s->SCMD; |
| 226 | save_sasr = *sasr_3393; |
| 227 | |
| 228 | /* First test the AuxStatus Reg */ |
| 229 | |
| 230 | q = *sasr_3393; /* read it */ |
| 231 | if (q & 0x08) /* bit 3 should always be clear */ |
| 232 | return -ENODEV; |
| 233 | *sasr_3393 = WD_AUXILIARY_STATUS; /* setup indirect address */ |
| 234 | if (*sasr_3393 == WD_AUXILIARY_STATUS) { /* shouldn't retain the write */ |
| 235 | *sasr_3393 = save_sasr; /* Oops - restore this byte */ |
| 236 | return -ENODEV; |
| 237 | } |
| 238 | if (*sasr_3393 != q) { /* should still read the same */ |
| 239 | *sasr_3393 = save_sasr; /* Oops - restore this byte */ |
| 240 | return -ENODEV; |
| 241 | } |
| 242 | if (*scmd_3393 != q) /* and so should the image at 0x1f */ |
| 243 | return -ENODEV; |
| 244 | |
| 245 | /* |
| 246 | * Ok, we probably have a wd33c93, but let's check a few other places |
| 247 | * for good measure. Make sure that this works for both 'A and 'B |
| 248 | * chip versions. |
| 249 | */ |
| 250 | |
| 251 | *sasr_3393 = WD_SCSI_STATUS; |
| 252 | q = *scmd_3393; |
| 253 | *sasr_3393 = WD_SCSI_STATUS; |
| 254 | *scmd_3393 = ~q; |
| 255 | *sasr_3393 = WD_SCSI_STATUS; |
| 256 | qq = *scmd_3393; |
| 257 | *sasr_3393 = WD_SCSI_STATUS; |
| 258 | *scmd_3393 = q; |
| 259 | if (qq != q) /* should be read only */ |
| 260 | return -ENODEV; |
| 261 | *sasr_3393 = 0x1e; /* this register is unimplemented */ |
| 262 | q = *scmd_3393; |
| 263 | *sasr_3393 = 0x1e; |
| 264 | *scmd_3393 = ~q; |
| 265 | *sasr_3393 = 0x1e; |
| 266 | qq = *scmd_3393; |
| 267 | *sasr_3393 = 0x1e; |
| 268 | *scmd_3393 = q; |
| 269 | if (qq != q || qq != 0xff) /* should be read only, all 1's */ |
| 270 | return -ENODEV; |
| 271 | *sasr_3393 = WD_TIMEOUT_PERIOD; |
| 272 | q = *scmd_3393; |
| 273 | *sasr_3393 = WD_TIMEOUT_PERIOD; |
| 274 | *scmd_3393 = ~q; |
| 275 | *sasr_3393 = WD_TIMEOUT_PERIOD; |
| 276 | qq = *scmd_3393; |
| 277 | *sasr_3393 = WD_TIMEOUT_PERIOD; |
| 278 | *scmd_3393 = q; |
| 279 | if (qq != (~q & 0xff)) /* should be read/write */ |
| 280 | return -ENODEV; |
| 281 | #endif /* CHECK_WD33C93 */ |
| 282 | |
| 283 | return 0; |
| 284 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | |
Geert Uytterhoeven | c1d288a | 2009-08-16 11:17:35 +0200 | [diff] [blame] | 286 | static int __devinit gvp11_probe(struct zorro_dev *z, |
| 287 | const struct zorro_device_id *ent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | { |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 289 | struct Scsi_Host *instance; |
| 290 | unsigned long address; |
Geert Uytterhoeven | c1d288a | 2009-08-16 11:17:35 +0200 | [diff] [blame] | 291 | int error; |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 292 | unsigned int epc; |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 293 | unsigned int default_dma_xfer_mask; |
Geert Uytterhoeven | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 294 | struct gvp11_hostdata *hdata; |
Geert Uytterhoeven | 349d65f | 2009-05-17 21:05:55 +0200 | [diff] [blame] | 295 | struct gvp11_scsiregs *regs; |
Geert Uytterhoeven | 6869b15 | 2009-05-17 12:17:28 +0200 | [diff] [blame] | 296 | wd33c93_regs wdregs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | |
Geert Uytterhoeven | c1d288a | 2009-08-16 11:17:35 +0200 | [diff] [blame] | 298 | default_dma_xfer_mask = ent->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | |
Geert Uytterhoeven | c1d288a | 2009-08-16 11:17:35 +0200 | [diff] [blame] | 300 | /* |
| 301 | * Rumors state that some GVP ram boards use the same product |
| 302 | * code as the SCSI controllers. Therefore if the board-size |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 303 | * is not 64KB we assume it is a ram board and bail out. |
Geert Uytterhoeven | c1d288a | 2009-08-16 11:17:35 +0200 | [diff] [blame] | 304 | */ |
| 305 | if (zorro_resource_len(z) != 0x10000) |
| 306 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | |
Geert Uytterhoeven | c1d288a | 2009-08-16 11:17:35 +0200 | [diff] [blame] | 308 | address = z->resource.start; |
| 309 | if (!request_mem_region(address, 256, "wd33c93")) |
| 310 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | |
Geert Uytterhoeven | c1d288a | 2009-08-16 11:17:35 +0200 | [diff] [blame] | 312 | regs = (struct gvp11_scsiregs *)(ZTWO_VADDR(address)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | |
Geert Uytterhoeven | c1d288a | 2009-08-16 11:17:35 +0200 | [diff] [blame] | 314 | error = check_wd33c93(regs); |
| 315 | if (error) |
| 316 | goto fail_check_or_alloc; |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 317 | |
Geert Uytterhoeven | c1d288a | 2009-08-16 11:17:35 +0200 | [diff] [blame] | 318 | instance = scsi_host_alloc(&gvp11_scsi_template, |
Geert Uytterhoeven | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 319 | sizeof(struct gvp11_hostdata)); |
Geert Uytterhoeven | c1d288a | 2009-08-16 11:17:35 +0200 | [diff] [blame] | 320 | if (!instance) { |
| 321 | error = -ENOMEM; |
| 322 | goto fail_check_or_alloc; |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 323 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | |
Geert Uytterhoeven | c1d288a | 2009-08-16 11:17:35 +0200 | [diff] [blame] | 325 | instance->irq = IRQ_AMIGA_PORTS; |
| 326 | instance->unique_id = z->slotaddr; |
| 327 | |
| 328 | regs->secret2 = 1; |
| 329 | regs->secret1 = 0; |
| 330 | regs->secret3 = 15; |
| 331 | while (regs->CNTR & GVP11_DMAC_BUSY) |
| 332 | ; |
| 333 | regs->CNTR = 0; |
| 334 | regs->BANK = 0; |
| 335 | |
| 336 | wdregs.SASR = ®s->SASR; |
| 337 | wdregs.SCMD = ®s->SCMD; |
| 338 | |
| 339 | hdata = shost_priv(instance); |
| 340 | if (gvp11_xfer_mask) |
Geert Uytterhoeven | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 341 | hdata->wh.dma_xfer_mask = gvp11_xfer_mask; |
Geert Uytterhoeven | c1d288a | 2009-08-16 11:17:35 +0200 | [diff] [blame] | 342 | else |
Geert Uytterhoeven | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 343 | hdata->wh.dma_xfer_mask = default_dma_xfer_mask; |
Geert Uytterhoeven | c1d288a | 2009-08-16 11:17:35 +0200 | [diff] [blame] | 344 | |
Geert Uytterhoeven | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 345 | hdata->wh.no_sync = 0xff; |
| 346 | hdata->wh.fast = 0; |
| 347 | hdata->wh.dma_mode = CTRL_DMA; |
| 348 | hdata->regs = regs; |
Geert Uytterhoeven | c1d288a | 2009-08-16 11:17:35 +0200 | [diff] [blame] | 349 | |
| 350 | /* |
| 351 | * Check for 14MHz SCSI clock |
| 352 | */ |
| 353 | epc = *(unsigned short *)(ZTWO_VADDR(address) + 0x8000); |
| 354 | wd33c93_init(instance, wdregs, dma_setup, dma_stop, |
| 355 | (epc & GVP_SCSICLKMASK) ? WD33C93_FS_8_10 |
| 356 | : WD33C93_FS_12_15); |
| 357 | |
| 358 | error = request_irq(IRQ_AMIGA_PORTS, gvp11_intr, IRQF_SHARED, |
| 359 | "GVP11 SCSI", instance); |
| 360 | if (error) |
| 361 | goto fail_irq; |
| 362 | |
| 363 | regs->CNTR = GVP11_DMAC_INT_ENABLE; |
| 364 | |
| 365 | error = scsi_add_host(instance, NULL); |
| 366 | if (error) |
| 367 | goto fail_host; |
| 368 | |
| 369 | zorro_set_drvdata(z, instance); |
| 370 | scsi_scan_host(instance); |
| 371 | return 0; |
| 372 | |
| 373 | fail_host: |
| 374 | free_irq(IRQ_AMIGA_PORTS, instance); |
| 375 | fail_irq: |
| 376 | scsi_host_put(instance); |
| 377 | fail_check_or_alloc: |
| 378 | release_mem_region(address, 256); |
| 379 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | } |
| 381 | |
Geert Uytterhoeven | c1d288a | 2009-08-16 11:17:35 +0200 | [diff] [blame] | 382 | static void __devexit gvp11_remove(struct zorro_dev *z) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | { |
Geert Uytterhoeven | c1d288a | 2009-08-16 11:17:35 +0200 | [diff] [blame] | 384 | struct Scsi_Host *instance = zorro_get_drvdata(z); |
Geert Uytterhoeven | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 385 | struct gvp11_hostdata *hdata = shost_priv(instance); |
Geert Uytterhoeven | 6869b15 | 2009-05-17 12:17:28 +0200 | [diff] [blame] | 386 | |
Geert Uytterhoeven | cf2ed27 | 2010-04-12 21:55:25 +0200 | [diff] [blame] | 387 | hdata->regs->CNTR = 0; |
Geert Uytterhoeven | c1d288a | 2009-08-16 11:17:35 +0200 | [diff] [blame] | 388 | scsi_remove_host(instance); |
Geert Uytterhoeven | bb17b78 | 2010-04-04 11:00:33 +0200 | [diff] [blame] | 389 | free_irq(IRQ_AMIGA_PORTS, instance); |
Geert Uytterhoeven | c1d288a | 2009-08-16 11:17:35 +0200 | [diff] [blame] | 390 | scsi_host_put(instance); |
| 391 | release_mem_region(z->resource.start, 256); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | } |
| 393 | |
Geert Uytterhoeven | c1d288a | 2009-08-16 11:17:35 +0200 | [diff] [blame] | 394 | /* |
| 395 | * This should (hopefully) be the correct way to identify |
| 396 | * all the different GVP SCSI controllers (except for the |
| 397 | * SERIES I though). |
| 398 | */ |
| 399 | |
| 400 | static struct zorro_device_id gvp11_zorro_tbl[] __devinitdata = { |
| 401 | { ZORRO_PROD_GVP_COMBO_030_R3_SCSI, ~0x00ffffff }, |
| 402 | { ZORRO_PROD_GVP_SERIES_II, ~0x00ffffff }, |
| 403 | { ZORRO_PROD_GVP_GFORCE_030_SCSI, ~0x01ffffff }, |
| 404 | { ZORRO_PROD_GVP_A530_SCSI, ~0x01ffffff }, |
| 405 | { ZORRO_PROD_GVP_COMBO_030_R4_SCSI, ~0x01ffffff }, |
| 406 | { ZORRO_PROD_GVP_A1291, ~0x07ffffff }, |
| 407 | { ZORRO_PROD_GVP_GFORCE_040_SCSI_1, ~0x07ffffff }, |
| 408 | { 0 } |
| 409 | }; |
| 410 | MODULE_DEVICE_TABLE(zorro, gvp11_zorro_tbl); |
| 411 | |
| 412 | static struct zorro_driver gvp11_driver = { |
| 413 | .name = "gvp11", |
| 414 | .id_table = gvp11_zorro_tbl, |
| 415 | .probe = gvp11_probe, |
| 416 | .remove = __devexit_p(gvp11_remove), |
| 417 | }; |
| 418 | |
| 419 | static int __init gvp11_init(void) |
| 420 | { |
| 421 | return zorro_register_driver(&gvp11_driver); |
| 422 | } |
| 423 | module_init(gvp11_init); |
| 424 | |
| 425 | static void __exit gvp11_exit(void) |
| 426 | { |
| 427 | zorro_unregister_driver(&gvp11_driver); |
| 428 | } |
| 429 | module_exit(gvp11_exit); |
| 430 | |
| 431 | MODULE_DESCRIPTION("GVP Series II SCSI"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | MODULE_LICENSE("GPL"); |