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