Russell King | 73b6a2b | 2007-05-03 09:55:52 +0100 | [diff] [blame] | 1 | #include <linux/kernel.h> |
| 2 | #include <linux/module.h> |
| 3 | #include <linux/init.h> |
| 4 | #include <linux/blkdev.h> |
| 5 | #include <scsi/scsi_host.h> |
| 6 | #include <linux/ata.h> |
| 7 | #include <linux/libata.h> |
| 8 | |
| 9 | #include <asm/dma.h> |
| 10 | #include <asm/ecard.h> |
| 11 | |
| 12 | #define DRV_NAME "pata_icside" |
| 13 | |
| 14 | #define ICS_IDENT_OFFSET 0x2280 |
| 15 | |
| 16 | #define ICS_ARCIN_V5_INTRSTAT 0x0000 |
| 17 | #define ICS_ARCIN_V5_INTROFFSET 0x0004 |
| 18 | |
| 19 | #define ICS_ARCIN_V6_INTROFFSET_1 0x2200 |
| 20 | #define ICS_ARCIN_V6_INTRSTAT_1 0x2290 |
| 21 | #define ICS_ARCIN_V6_INTROFFSET_2 0x3200 |
| 22 | #define ICS_ARCIN_V6_INTRSTAT_2 0x3290 |
| 23 | |
| 24 | struct portinfo { |
| 25 | unsigned int dataoffset; |
| 26 | unsigned int ctrloffset; |
| 27 | unsigned int stepping; |
| 28 | }; |
| 29 | |
| 30 | static const struct portinfo pata_icside_portinfo_v5 = { |
| 31 | .dataoffset = 0x2800, |
| 32 | .ctrloffset = 0x2b80, |
| 33 | .stepping = 6, |
| 34 | }; |
| 35 | |
| 36 | static const struct portinfo pata_icside_portinfo_v6_1 = { |
| 37 | .dataoffset = 0x2000, |
| 38 | .ctrloffset = 0x2380, |
| 39 | .stepping = 6, |
| 40 | }; |
| 41 | |
| 42 | static const struct portinfo pata_icside_portinfo_v6_2 = { |
| 43 | .dataoffset = 0x3000, |
| 44 | .ctrloffset = 0x3380, |
| 45 | .stepping = 6, |
| 46 | }; |
| 47 | |
| 48 | #define PATA_ICSIDE_MAX_SG 128 |
| 49 | |
| 50 | struct pata_icside_state { |
| 51 | void __iomem *irq_port; |
| 52 | void __iomem *ioc_base; |
| 53 | unsigned int type; |
| 54 | unsigned int dma; |
| 55 | struct { |
| 56 | u8 port_sel; |
| 57 | u8 disabled; |
| 58 | unsigned int speed[ATA_MAX_DEVICES]; |
| 59 | } port[2]; |
| 60 | struct scatterlist sg[PATA_ICSIDE_MAX_SG]; |
| 61 | }; |
| 62 | |
Russell King | f95637d | 2007-05-10 19:32:36 +0100 | [diff] [blame] | 63 | struct pata_icside_info { |
| 64 | struct pata_icside_state *state; |
| 65 | struct expansion_card *ec; |
| 66 | void __iomem *base; |
| 67 | void __iomem *irqaddr; |
| 68 | unsigned int irqmask; |
| 69 | const expansioncard_ops_t *irqops; |
| 70 | unsigned int mwdma_mask; |
| 71 | unsigned int nr_ports; |
| 72 | const struct portinfo *port[2]; |
Tejun Heo | cbcdd87 | 2007-08-18 13:14:55 +0900 | [diff] [blame] | 73 | unsigned long raw_base; |
| 74 | unsigned long raw_ioc_base; |
Russell King | f95637d | 2007-05-10 19:32:36 +0100 | [diff] [blame] | 75 | }; |
| 76 | |
Russell King | 73b6a2b | 2007-05-03 09:55:52 +0100 | [diff] [blame] | 77 | #define ICS_TYPE_A3IN 0 |
| 78 | #define ICS_TYPE_A3USER 1 |
| 79 | #define ICS_TYPE_V6 3 |
| 80 | #define ICS_TYPE_V5 15 |
| 81 | #define ICS_TYPE_NOTYPE ((unsigned int)-1) |
| 82 | |
| 83 | /* ---------------- Version 5 PCB Support Functions --------------------- */ |
| 84 | /* Prototype: pata_icside_irqenable_arcin_v5 (struct expansion_card *ec, int irqnr) |
| 85 | * Purpose : enable interrupts from card |
| 86 | */ |
| 87 | static void pata_icside_irqenable_arcin_v5 (struct expansion_card *ec, int irqnr) |
| 88 | { |
| 89 | struct pata_icside_state *state = ec->irq_data; |
| 90 | |
| 91 | writeb(0, state->irq_port + ICS_ARCIN_V5_INTROFFSET); |
| 92 | } |
| 93 | |
| 94 | /* Prototype: pata_icside_irqdisable_arcin_v5 (struct expansion_card *ec, int irqnr) |
| 95 | * Purpose : disable interrupts from card |
| 96 | */ |
| 97 | static void pata_icside_irqdisable_arcin_v5 (struct expansion_card *ec, int irqnr) |
| 98 | { |
| 99 | struct pata_icside_state *state = ec->irq_data; |
| 100 | |
| 101 | readb(state->irq_port + ICS_ARCIN_V5_INTROFFSET); |
| 102 | } |
| 103 | |
| 104 | static const expansioncard_ops_t pata_icside_ops_arcin_v5 = { |
| 105 | .irqenable = pata_icside_irqenable_arcin_v5, |
| 106 | .irqdisable = pata_icside_irqdisable_arcin_v5, |
| 107 | }; |
| 108 | |
| 109 | |
| 110 | /* ---------------- Version 6 PCB Support Functions --------------------- */ |
| 111 | /* Prototype: pata_icside_irqenable_arcin_v6 (struct expansion_card *ec, int irqnr) |
| 112 | * Purpose : enable interrupts from card |
| 113 | */ |
| 114 | static void pata_icside_irqenable_arcin_v6 (struct expansion_card *ec, int irqnr) |
| 115 | { |
| 116 | struct pata_icside_state *state = ec->irq_data; |
| 117 | void __iomem *base = state->irq_port; |
| 118 | |
| 119 | if (!state->port[0].disabled) |
| 120 | writeb(0, base + ICS_ARCIN_V6_INTROFFSET_1); |
| 121 | if (!state->port[1].disabled) |
| 122 | writeb(0, base + ICS_ARCIN_V6_INTROFFSET_2); |
| 123 | } |
| 124 | |
| 125 | /* Prototype: pata_icside_irqdisable_arcin_v6 (struct expansion_card *ec, int irqnr) |
| 126 | * Purpose : disable interrupts from card |
| 127 | */ |
| 128 | static void pata_icside_irqdisable_arcin_v6 (struct expansion_card *ec, int irqnr) |
| 129 | { |
| 130 | struct pata_icside_state *state = ec->irq_data; |
| 131 | |
| 132 | readb(state->irq_port + ICS_ARCIN_V6_INTROFFSET_1); |
| 133 | readb(state->irq_port + ICS_ARCIN_V6_INTROFFSET_2); |
| 134 | } |
| 135 | |
| 136 | /* Prototype: pata_icside_irqprobe(struct expansion_card *ec) |
| 137 | * Purpose : detect an active interrupt from card |
| 138 | */ |
| 139 | static int pata_icside_irqpending_arcin_v6(struct expansion_card *ec) |
| 140 | { |
| 141 | struct pata_icside_state *state = ec->irq_data; |
| 142 | |
| 143 | return readb(state->irq_port + ICS_ARCIN_V6_INTRSTAT_1) & 1 || |
| 144 | readb(state->irq_port + ICS_ARCIN_V6_INTRSTAT_2) & 1; |
| 145 | } |
| 146 | |
| 147 | static const expansioncard_ops_t pata_icside_ops_arcin_v6 = { |
| 148 | .irqenable = pata_icside_irqenable_arcin_v6, |
| 149 | .irqdisable = pata_icside_irqdisable_arcin_v6, |
| 150 | .irqpending = pata_icside_irqpending_arcin_v6, |
| 151 | }; |
| 152 | |
| 153 | |
| 154 | /* |
| 155 | * SG-DMA support. |
| 156 | * |
| 157 | * Similar to the BM-DMA, but we use the RiscPCs IOMD DMA controllers. |
| 158 | * There is only one DMA controller per card, which means that only |
| 159 | * one drive can be accessed at one time. NOTE! We do not enforce that |
| 160 | * here, but we rely on the main IDE driver spotting that both |
| 161 | * interfaces use the same IRQ, which should guarantee this. |
| 162 | */ |
| 163 | |
| 164 | /* |
| 165 | * Configure the IOMD to give the appropriate timings for the transfer |
| 166 | * mode being requested. We take the advice of the ATA standards, and |
| 167 | * calculate the cycle time based on the transfer mode, and the EIDE |
| 168 | * MW DMA specs that the drive provides in the IDENTIFY command. |
| 169 | * |
| 170 | * We have the following IOMD DMA modes to choose from: |
| 171 | * |
| 172 | * Type Active Recovery Cycle |
| 173 | * A 250 (250) 312 (550) 562 (800) |
| 174 | * B 187 (200) 250 (550) 437 (750) |
| 175 | * C 125 (125) 125 (375) 250 (500) |
| 176 | * D 62 (50) 125 (375) 187 (425) |
| 177 | * |
| 178 | * (figures in brackets are actual measured timings on DIOR/DIOW) |
| 179 | * |
| 180 | * However, we also need to take care of the read/write active and |
| 181 | * recovery timings: |
| 182 | * |
| 183 | * Read Write |
| 184 | * Mode Active -- Recovery -- Cycle IOMD type |
| 185 | * MW0 215 50 215 480 A |
| 186 | * MW1 80 50 50 150 C |
| 187 | * MW2 70 25 25 120 C |
| 188 | */ |
| 189 | static void pata_icside_set_dmamode(struct ata_port *ap, struct ata_device *adev) |
| 190 | { |
| 191 | struct pata_icside_state *state = ap->host->private_data; |
| 192 | struct ata_timing t; |
| 193 | unsigned int cycle; |
| 194 | char iomd_type; |
| 195 | |
| 196 | /* |
| 197 | * DMA is based on a 16MHz clock |
| 198 | */ |
| 199 | if (ata_timing_compute(adev, adev->dma_mode, &t, 1000, 1)) |
| 200 | return; |
| 201 | |
| 202 | /* |
| 203 | * Choose the IOMD cycle timing which ensure that the interface |
| 204 | * satisfies the measured active, recovery and cycle times. |
| 205 | */ |
| 206 | if (t.active <= 50 && t.recover <= 375 && t.cycle <= 425) |
| 207 | iomd_type = 'D', cycle = 187; |
| 208 | else if (t.active <= 125 && t.recover <= 375 && t.cycle <= 500) |
| 209 | iomd_type = 'C', cycle = 250; |
| 210 | else if (t.active <= 200 && t.recover <= 550 && t.cycle <= 750) |
| 211 | iomd_type = 'B', cycle = 437; |
| 212 | else |
| 213 | iomd_type = 'A', cycle = 562; |
| 214 | |
| 215 | ata_dev_printk(adev, KERN_INFO, "timings: act %dns rec %dns cyc %dns (%c)\n", |
| 216 | t.active, t.recover, t.cycle, iomd_type); |
| 217 | |
| 218 | state->port[ap->port_no].speed[adev->devno] = cycle; |
| 219 | } |
| 220 | |
| 221 | static void pata_icside_bmdma_setup(struct ata_queued_cmd *qc) |
| 222 | { |
| 223 | struct ata_port *ap = qc->ap; |
| 224 | struct pata_icside_state *state = ap->host->private_data; |
| 225 | struct scatterlist *sg, *rsg = state->sg; |
| 226 | unsigned int write = qc->tf.flags & ATA_TFLAG_WRITE; |
Tejun Heo | ff2aeb1 | 2007-12-05 16:43:11 +0900 | [diff] [blame] | 227 | unsigned int si; |
Russell King | 73b6a2b | 2007-05-03 09:55:52 +0100 | [diff] [blame] | 228 | |
| 229 | /* |
| 230 | * We are simplex; BUG if we try to fiddle with DMA |
| 231 | * while it's active. |
| 232 | */ |
| 233 | BUG_ON(dma_channel_active(state->dma)); |
| 234 | |
| 235 | /* |
| 236 | * Copy ATAs scattered sg list into a contiguous array of sg |
| 237 | */ |
Tejun Heo | ff2aeb1 | 2007-12-05 16:43:11 +0900 | [diff] [blame] | 238 | for_each_sg(qc->sg, sg, qc->n_elem, si) { |
Russell King | 73b6a2b | 2007-05-03 09:55:52 +0100 | [diff] [blame] | 239 | memcpy(rsg, sg, sizeof(*sg)); |
| 240 | rsg++; |
| 241 | } |
| 242 | |
| 243 | /* |
| 244 | * Route the DMA signals to the correct interface |
| 245 | */ |
| 246 | writeb(state->port[ap->port_no].port_sel, state->ioc_base); |
| 247 | |
| 248 | set_dma_speed(state->dma, state->port[ap->port_no].speed[qc->dev->devno]); |
| 249 | set_dma_sg(state->dma, state->sg, rsg - state->sg); |
| 250 | set_dma_mode(state->dma, write ? DMA_MODE_WRITE : DMA_MODE_READ); |
| 251 | |
| 252 | /* issue r/w command */ |
| 253 | ap->ops->exec_command(ap, &qc->tf); |
| 254 | } |
| 255 | |
| 256 | static void pata_icside_bmdma_start(struct ata_queued_cmd *qc) |
| 257 | { |
| 258 | struct ata_port *ap = qc->ap; |
| 259 | struct pata_icside_state *state = ap->host->private_data; |
| 260 | |
| 261 | BUG_ON(dma_channel_active(state->dma)); |
| 262 | enable_dma(state->dma); |
| 263 | } |
| 264 | |
| 265 | static void pata_icside_bmdma_stop(struct ata_queued_cmd *qc) |
| 266 | { |
| 267 | struct ata_port *ap = qc->ap; |
| 268 | struct pata_icside_state *state = ap->host->private_data; |
| 269 | |
| 270 | disable_dma(state->dma); |
| 271 | |
| 272 | /* see ata_bmdma_stop */ |
| 273 | ata_altstatus(ap); |
| 274 | } |
| 275 | |
| 276 | static u8 pata_icside_bmdma_status(struct ata_port *ap) |
| 277 | { |
| 278 | struct pata_icside_state *state = ap->host->private_data; |
| 279 | void __iomem *irq_port; |
| 280 | |
| 281 | irq_port = state->irq_port + (ap->port_no ? ICS_ARCIN_V6_INTRSTAT_2 : |
| 282 | ICS_ARCIN_V6_INTRSTAT_1); |
| 283 | |
| 284 | return readb(irq_port) & 1 ? ATA_DMA_INTR : 0; |
| 285 | } |
| 286 | |
Russell King | f95637d | 2007-05-10 19:32:36 +0100 | [diff] [blame] | 287 | static int icside_dma_init(struct pata_icside_info *info) |
Russell King | 73b6a2b | 2007-05-03 09:55:52 +0100 | [diff] [blame] | 288 | { |
Russell King | f95637d | 2007-05-10 19:32:36 +0100 | [diff] [blame] | 289 | struct pata_icside_state *state = info->state; |
| 290 | struct expansion_card *ec = info->ec; |
Russell King | 73b6a2b | 2007-05-03 09:55:52 +0100 | [diff] [blame] | 291 | int i; |
| 292 | |
| 293 | for (i = 0; i < ATA_MAX_DEVICES; i++) { |
| 294 | state->port[0].speed[i] = 480; |
| 295 | state->port[1].speed[i] = 480; |
| 296 | } |
| 297 | |
| 298 | if (ec->dma != NO_DMA && !request_dma(ec->dma, DRV_NAME)) { |
| 299 | state->dma = ec->dma; |
Russell King | f95637d | 2007-05-10 19:32:36 +0100 | [diff] [blame] | 300 | info->mwdma_mask = 0x07; /* MW0..2 */ |
Russell King | 73b6a2b | 2007-05-03 09:55:52 +0100 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | return 0; |
| 304 | } |
| 305 | |
| 306 | |
| 307 | static int pata_icside_port_start(struct ata_port *ap) |
| 308 | { |
| 309 | /* No PRD to alloc */ |
| 310 | return ata_pad_alloc(ap, ap->dev); |
| 311 | } |
| 312 | |
| 313 | static struct scsi_host_template pata_icside_sht = { |
| 314 | .module = THIS_MODULE, |
| 315 | .name = DRV_NAME, |
| 316 | .ioctl = ata_scsi_ioctl, |
| 317 | .queuecommand = ata_scsi_queuecmd, |
| 318 | .can_queue = ATA_DEF_QUEUE, |
| 319 | .this_id = ATA_SHT_THIS_ID, |
| 320 | .sg_tablesize = PATA_ICSIDE_MAX_SG, |
| 321 | .cmd_per_lun = ATA_SHT_CMD_PER_LUN, |
| 322 | .emulated = ATA_SHT_EMULATED, |
| 323 | .use_clustering = ATA_SHT_USE_CLUSTERING, |
| 324 | .proc_name = DRV_NAME, |
| 325 | .dma_boundary = ~0, /* no dma boundaries */ |
| 326 | .slave_configure = ata_scsi_slave_config, |
| 327 | .slave_destroy = ata_scsi_slave_destroy, |
| 328 | .bios_param = ata_std_bios_param, |
| 329 | }; |
| 330 | |
| 331 | /* wish this was exported from libata-core */ |
| 332 | static void ata_dummy_noret(struct ata_port *port) |
| 333 | { |
| 334 | } |
| 335 | |
Al Viro | c15fcaf | 2007-10-14 01:12:39 +0100 | [diff] [blame] | 336 | static void pata_icside_postreset(struct ata_link *link, unsigned int *classes) |
Russell King | 73b6a2b | 2007-05-03 09:55:52 +0100 | [diff] [blame] | 337 | { |
Al Viro | c15fcaf | 2007-10-14 01:12:39 +0100 | [diff] [blame] | 338 | struct ata_port *ap = link->ap; |
Russell King | 73b6a2b | 2007-05-03 09:55:52 +0100 | [diff] [blame] | 339 | struct pata_icside_state *state = ap->host->private_data; |
| 340 | |
Russell King | eba8448 | 2007-08-06 16:10:54 +0100 | [diff] [blame] | 341 | if (classes[0] != ATA_DEV_NONE || classes[1] != ATA_DEV_NONE) |
Al Viro | c15fcaf | 2007-10-14 01:12:39 +0100 | [diff] [blame] | 342 | return ata_std_postreset(link, classes); |
Russell King | 73b6a2b | 2007-05-03 09:55:52 +0100 | [diff] [blame] | 343 | |
| 344 | state->port[ap->port_no].disabled = 1; |
| 345 | |
| 346 | if (state->type == ICS_TYPE_V6) { |
| 347 | /* |
| 348 | * Disable interrupts from this port, otherwise we |
| 349 | * receive spurious interrupts from the floating |
| 350 | * interrupt line. |
| 351 | */ |
| 352 | void __iomem *irq_port = state->irq_port + |
| 353 | (ap->port_no ? ICS_ARCIN_V6_INTROFFSET_2 : ICS_ARCIN_V6_INTROFFSET_1); |
| 354 | readb(irq_port); |
| 355 | } |
| 356 | } |
| 357 | |
Russell King | eba8448 | 2007-08-06 16:10:54 +0100 | [diff] [blame] | 358 | static void pata_icside_error_handler(struct ata_port *ap) |
| 359 | { |
| 360 | ata_bmdma_drive_eh(ap, ata_std_prereset, ata_std_softreset, NULL, |
| 361 | pata_icside_postreset); |
| 362 | } |
| 363 | |
Russell King | 73b6a2b | 2007-05-03 09:55:52 +0100 | [diff] [blame] | 364 | static struct ata_port_operations pata_icside_port_ops = { |
Russell King | 73b6a2b | 2007-05-03 09:55:52 +0100 | [diff] [blame] | 365 | .set_dmamode = pata_icside_set_dmamode, |
| 366 | |
| 367 | .tf_load = ata_tf_load, |
| 368 | .tf_read = ata_tf_read, |
| 369 | .exec_command = ata_exec_command, |
| 370 | .check_status = ata_check_status, |
| 371 | .dev_select = ata_std_dev_select, |
| 372 | |
Russell King | f95637d | 2007-05-10 19:32:36 +0100 | [diff] [blame] | 373 | .cable_detect = ata_cable_40wire, |
| 374 | |
Russell King | 73b6a2b | 2007-05-03 09:55:52 +0100 | [diff] [blame] | 375 | .bmdma_setup = pata_icside_bmdma_setup, |
| 376 | .bmdma_start = pata_icside_bmdma_start, |
| 377 | |
| 378 | .data_xfer = ata_data_xfer_noirq, |
| 379 | |
| 380 | /* no need to build any PRD tables for DMA */ |
| 381 | .qc_prep = ata_noop_qc_prep, |
| 382 | .qc_issue = ata_qc_issue_prot, |
| 383 | |
| 384 | .freeze = ata_bmdma_freeze, |
| 385 | .thaw = ata_bmdma_thaw, |
Russell King | eba8448 | 2007-08-06 16:10:54 +0100 | [diff] [blame] | 386 | .error_handler = pata_icside_error_handler, |
Russell King | 73b6a2b | 2007-05-03 09:55:52 +0100 | [diff] [blame] | 387 | .post_internal_cmd = pata_icside_bmdma_stop, |
| 388 | |
Russell King | 73b6a2b | 2007-05-03 09:55:52 +0100 | [diff] [blame] | 389 | .irq_clear = ata_dummy_noret, |
| 390 | .irq_on = ata_irq_on, |
Russell King | 73b6a2b | 2007-05-03 09:55:52 +0100 | [diff] [blame] | 391 | |
| 392 | .port_start = pata_icside_port_start, |
| 393 | |
| 394 | .bmdma_stop = pata_icside_bmdma_stop, |
| 395 | .bmdma_status = pata_icside_bmdma_status, |
| 396 | }; |
| 397 | |
Russell King | f95637d | 2007-05-10 19:32:36 +0100 | [diff] [blame] | 398 | static void __devinit |
Tejun Heo | cbcdd87 | 2007-08-18 13:14:55 +0900 | [diff] [blame] | 399 | pata_icside_setup_ioaddr(struct ata_port *ap, void __iomem *base, |
Al Viro | c15fcaf | 2007-10-14 01:12:39 +0100 | [diff] [blame] | 400 | struct pata_icside_info *info, |
| 401 | const struct portinfo *port) |
Russell King | 73b6a2b | 2007-05-03 09:55:52 +0100 | [diff] [blame] | 402 | { |
Tejun Heo | cbcdd87 | 2007-08-18 13:14:55 +0900 | [diff] [blame] | 403 | struct ata_ioports *ioaddr = &ap->ioaddr; |
Al Viro | c15fcaf | 2007-10-14 01:12:39 +0100 | [diff] [blame] | 404 | void __iomem *cmd = base + port->dataoffset; |
Russell King | 73b6a2b | 2007-05-03 09:55:52 +0100 | [diff] [blame] | 405 | |
| 406 | ioaddr->cmd_addr = cmd; |
Al Viro | c15fcaf | 2007-10-14 01:12:39 +0100 | [diff] [blame] | 407 | ioaddr->data_addr = cmd + (ATA_REG_DATA << port->stepping); |
| 408 | ioaddr->error_addr = cmd + (ATA_REG_ERR << port->stepping); |
| 409 | ioaddr->feature_addr = cmd + (ATA_REG_FEATURE << port->stepping); |
| 410 | ioaddr->nsect_addr = cmd + (ATA_REG_NSECT << port->stepping); |
| 411 | ioaddr->lbal_addr = cmd + (ATA_REG_LBAL << port->stepping); |
| 412 | ioaddr->lbam_addr = cmd + (ATA_REG_LBAM << port->stepping); |
| 413 | ioaddr->lbah_addr = cmd + (ATA_REG_LBAH << port->stepping); |
| 414 | ioaddr->device_addr = cmd + (ATA_REG_DEVICE << port->stepping); |
| 415 | ioaddr->status_addr = cmd + (ATA_REG_STATUS << port->stepping); |
| 416 | ioaddr->command_addr = cmd + (ATA_REG_CMD << port->stepping); |
Russell King | 73b6a2b | 2007-05-03 09:55:52 +0100 | [diff] [blame] | 417 | |
Al Viro | c15fcaf | 2007-10-14 01:12:39 +0100 | [diff] [blame] | 418 | ioaddr->ctl_addr = base + port->ctrloffset; |
Russell King | 73b6a2b | 2007-05-03 09:55:52 +0100 | [diff] [blame] | 419 | ioaddr->altstatus_addr = ioaddr->ctl_addr; |
Tejun Heo | cbcdd87 | 2007-08-18 13:14:55 +0900 | [diff] [blame] | 420 | |
| 421 | ata_port_desc(ap, "cmd 0x%lx ctl 0x%lx", |
Al Viro | c15fcaf | 2007-10-14 01:12:39 +0100 | [diff] [blame] | 422 | info->raw_base + port->dataoffset, |
| 423 | info->raw_base + port->ctrloffset); |
Tejun Heo | cbcdd87 | 2007-08-18 13:14:55 +0900 | [diff] [blame] | 424 | |
| 425 | if (info->raw_ioc_base) |
| 426 | ata_port_desc(ap, "iocbase 0x%lx", info->raw_ioc_base); |
Russell King | 73b6a2b | 2007-05-03 09:55:52 +0100 | [diff] [blame] | 427 | } |
| 428 | |
Russell King | f95637d | 2007-05-10 19:32:36 +0100 | [diff] [blame] | 429 | static int __devinit pata_icside_register_v5(struct pata_icside_info *info) |
Russell King | 73b6a2b | 2007-05-03 09:55:52 +0100 | [diff] [blame] | 430 | { |
Russell King | f95637d | 2007-05-10 19:32:36 +0100 | [diff] [blame] | 431 | struct pata_icside_state *state = info->state; |
Russell King | 73b6a2b | 2007-05-03 09:55:52 +0100 | [diff] [blame] | 432 | void __iomem *base; |
| 433 | |
Russell King | 10bdaaa | 2007-05-10 18:40:51 +0100 | [diff] [blame] | 434 | base = ecardm_iomap(info->ec, ECARD_RES_MEMC, 0, 0); |
Russell King | 73b6a2b | 2007-05-03 09:55:52 +0100 | [diff] [blame] | 435 | if (!base) |
| 436 | return -ENOMEM; |
| 437 | |
| 438 | state->irq_port = base; |
| 439 | |
Russell King | f95637d | 2007-05-10 19:32:36 +0100 | [diff] [blame] | 440 | info->base = base; |
| 441 | info->irqaddr = base + ICS_ARCIN_V5_INTRSTAT; |
| 442 | info->irqmask = 1; |
| 443 | info->irqops = &pata_icside_ops_arcin_v5; |
| 444 | info->nr_ports = 1; |
| 445 | info->port[0] = &pata_icside_portinfo_v5; |
Russell King | 73b6a2b | 2007-05-03 09:55:52 +0100 | [diff] [blame] | 446 | |
Al Viro | c15fcaf | 2007-10-14 01:12:39 +0100 | [diff] [blame] | 447 | info->raw_base = ecard_resource_start(info->ec, ECARD_RES_MEMC); |
Tejun Heo | cbcdd87 | 2007-08-18 13:14:55 +0900 | [diff] [blame] | 448 | |
Russell King | 73b6a2b | 2007-05-03 09:55:52 +0100 | [diff] [blame] | 449 | return 0; |
| 450 | } |
| 451 | |
Russell King | f95637d | 2007-05-10 19:32:36 +0100 | [diff] [blame] | 452 | static int __devinit pata_icside_register_v6(struct pata_icside_info *info) |
Russell King | 73b6a2b | 2007-05-03 09:55:52 +0100 | [diff] [blame] | 453 | { |
Russell King | f95637d | 2007-05-10 19:32:36 +0100 | [diff] [blame] | 454 | struct pata_icside_state *state = info->state; |
| 455 | struct expansion_card *ec = info->ec; |
Russell King | 73b6a2b | 2007-05-03 09:55:52 +0100 | [diff] [blame] | 456 | void __iomem *ioc_base, *easi_base; |
| 457 | unsigned int sel = 0; |
Russell King | 73b6a2b | 2007-05-03 09:55:52 +0100 | [diff] [blame] | 458 | |
Russell King | 10bdaaa | 2007-05-10 18:40:51 +0100 | [diff] [blame] | 459 | ioc_base = ecardm_iomap(ec, ECARD_RES_IOCFAST, 0, 0); |
| 460 | if (!ioc_base) |
| 461 | return -ENOMEM; |
Russell King | 73b6a2b | 2007-05-03 09:55:52 +0100 | [diff] [blame] | 462 | |
| 463 | easi_base = ioc_base; |
| 464 | |
| 465 | if (ecard_resource_flags(ec, ECARD_RES_EASI)) { |
Russell King | 10bdaaa | 2007-05-10 18:40:51 +0100 | [diff] [blame] | 466 | easi_base = ecardm_iomap(ec, ECARD_RES_EASI, 0, 0); |
| 467 | if (!easi_base) |
| 468 | return -ENOMEM; |
Russell King | 73b6a2b | 2007-05-03 09:55:52 +0100 | [diff] [blame] | 469 | |
| 470 | /* |
| 471 | * Enable access to the EASI region. |
| 472 | */ |
| 473 | sel = 1 << 5; |
| 474 | } |
| 475 | |
| 476 | writeb(sel, ioc_base); |
| 477 | |
Russell King | 73b6a2b | 2007-05-03 09:55:52 +0100 | [diff] [blame] | 478 | state->irq_port = easi_base; |
| 479 | state->ioc_base = ioc_base; |
| 480 | state->port[0].port_sel = sel; |
| 481 | state->port[1].port_sel = sel | 1; |
| 482 | |
Russell King | f95637d | 2007-05-10 19:32:36 +0100 | [diff] [blame] | 483 | info->base = easi_base; |
| 484 | info->irqops = &pata_icside_ops_arcin_v6; |
| 485 | info->nr_ports = 2; |
| 486 | info->port[0] = &pata_icside_portinfo_v6_1; |
| 487 | info->port[1] = &pata_icside_portinfo_v6_2; |
Russell King | 73b6a2b | 2007-05-03 09:55:52 +0100 | [diff] [blame] | 488 | |
Tejun Heo | cbcdd87 | 2007-08-18 13:14:55 +0900 | [diff] [blame] | 489 | info->raw_base = ecard_resource_start(ec, ECARD_RES_EASI); |
| 490 | info->raw_ioc_base = ecard_resource_start(ec, ECARD_RES_IOCFAST); |
| 491 | |
Russell King | f95637d | 2007-05-10 19:32:36 +0100 | [diff] [blame] | 492 | return icside_dma_init(info); |
| 493 | } |
| 494 | |
| 495 | static int __devinit pata_icside_add_ports(struct pata_icside_info *info) |
| 496 | { |
| 497 | struct expansion_card *ec = info->ec; |
| 498 | struct ata_host *host; |
| 499 | int i; |
| 500 | |
| 501 | if (info->irqaddr) { |
| 502 | ec->irqaddr = info->irqaddr; |
| 503 | ec->irqmask = info->irqmask; |
| 504 | } |
| 505 | if (info->irqops) |
| 506 | ecard_setirq(ec, info->irqops, info->state); |
| 507 | |
| 508 | /* |
| 509 | * Be on the safe side - disable interrupts |
| 510 | */ |
| 511 | ec->ops->irqdisable(ec, ec->irq); |
| 512 | |
| 513 | host = ata_host_alloc(&ec->dev, info->nr_ports); |
| 514 | if (!host) |
| 515 | return -ENOMEM; |
| 516 | |
| 517 | host->private_data = info->state; |
| 518 | host->flags = ATA_HOST_SIMPLEX; |
| 519 | |
| 520 | for (i = 0; i < info->nr_ports; i++) { |
| 521 | struct ata_port *ap = host->ports[i]; |
| 522 | |
| 523 | ap->pio_mask = 0x1f; |
| 524 | ap->mwdma_mask = info->mwdma_mask; |
Jeff Garzik | 1d2808f | 2007-05-28 06:59:48 -0400 | [diff] [blame] | 525 | ap->flags |= ATA_FLAG_SLAVE_POSS; |
Russell King | f95637d | 2007-05-10 19:32:36 +0100 | [diff] [blame] | 526 | ap->ops = &pata_icside_port_ops; |
| 527 | |
Al Viro | c15fcaf | 2007-10-14 01:12:39 +0100 | [diff] [blame] | 528 | pata_icside_setup_ioaddr(ap, info->base, info, info->port[i]); |
Russell King | f95637d | 2007-05-10 19:32:36 +0100 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | return ata_host_activate(host, ec->irq, ata_interrupt, 0, |
| 532 | &pata_icside_sht); |
Russell King | 73b6a2b | 2007-05-03 09:55:52 +0100 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | static int __devinit |
| 536 | pata_icside_probe(struct expansion_card *ec, const struct ecard_id *id) |
| 537 | { |
| 538 | struct pata_icside_state *state; |
Russell King | f95637d | 2007-05-10 19:32:36 +0100 | [diff] [blame] | 539 | struct pata_icside_info info; |
Russell King | 73b6a2b | 2007-05-03 09:55:52 +0100 | [diff] [blame] | 540 | void __iomem *idmem; |
| 541 | int ret; |
| 542 | |
| 543 | ret = ecard_request_resources(ec); |
| 544 | if (ret) |
| 545 | goto out; |
| 546 | |
Russell King | f95637d | 2007-05-10 19:32:36 +0100 | [diff] [blame] | 547 | state = devm_kzalloc(&ec->dev, sizeof(*state), GFP_KERNEL); |
Russell King | 73b6a2b | 2007-05-03 09:55:52 +0100 | [diff] [blame] | 548 | if (!state) { |
| 549 | ret = -ENOMEM; |
| 550 | goto release; |
| 551 | } |
| 552 | |
| 553 | state->type = ICS_TYPE_NOTYPE; |
| 554 | state->dma = NO_DMA; |
| 555 | |
Russell King | 10bdaaa | 2007-05-10 18:40:51 +0100 | [diff] [blame] | 556 | idmem = ecardm_iomap(ec, ECARD_RES_IOCFAST, 0, 0); |
Russell King | 73b6a2b | 2007-05-03 09:55:52 +0100 | [diff] [blame] | 557 | if (idmem) { |
| 558 | unsigned int type; |
| 559 | |
| 560 | type = readb(idmem + ICS_IDENT_OFFSET) & 1; |
| 561 | type |= (readb(idmem + ICS_IDENT_OFFSET + 4) & 1) << 1; |
| 562 | type |= (readb(idmem + ICS_IDENT_OFFSET + 8) & 1) << 2; |
| 563 | type |= (readb(idmem + ICS_IDENT_OFFSET + 12) & 1) << 3; |
Russell King | 10bdaaa | 2007-05-10 18:40:51 +0100 | [diff] [blame] | 564 | ecardm_iounmap(ec, idmem); |
Russell King | 73b6a2b | 2007-05-03 09:55:52 +0100 | [diff] [blame] | 565 | |
| 566 | state->type = type; |
| 567 | } |
| 568 | |
Russell King | f95637d | 2007-05-10 19:32:36 +0100 | [diff] [blame] | 569 | memset(&info, 0, sizeof(info)); |
| 570 | info.state = state; |
| 571 | info.ec = ec; |
Russell King | 73b6a2b | 2007-05-03 09:55:52 +0100 | [diff] [blame] | 572 | |
| 573 | switch (state->type) { |
| 574 | case ICS_TYPE_A3IN: |
| 575 | dev_warn(&ec->dev, "A3IN unsupported\n"); |
| 576 | ret = -ENODEV; |
| 577 | break; |
| 578 | |
| 579 | case ICS_TYPE_A3USER: |
| 580 | dev_warn(&ec->dev, "A3USER unsupported\n"); |
| 581 | ret = -ENODEV; |
| 582 | break; |
| 583 | |
| 584 | case ICS_TYPE_V5: |
Russell King | f95637d | 2007-05-10 19:32:36 +0100 | [diff] [blame] | 585 | ret = pata_icside_register_v5(&info); |
Russell King | 73b6a2b | 2007-05-03 09:55:52 +0100 | [diff] [blame] | 586 | break; |
| 587 | |
| 588 | case ICS_TYPE_V6: |
Russell King | f95637d | 2007-05-10 19:32:36 +0100 | [diff] [blame] | 589 | ret = pata_icside_register_v6(&info); |
Russell King | 73b6a2b | 2007-05-03 09:55:52 +0100 | [diff] [blame] | 590 | break; |
| 591 | |
| 592 | default: |
| 593 | dev_warn(&ec->dev, "unknown interface type\n"); |
| 594 | ret = -ENODEV; |
| 595 | break; |
| 596 | } |
| 597 | |
| 598 | if (ret == 0) |
Russell King | f95637d | 2007-05-10 19:32:36 +0100 | [diff] [blame] | 599 | ret = pata_icside_add_ports(&info); |
Russell King | 73b6a2b | 2007-05-03 09:55:52 +0100 | [diff] [blame] | 600 | |
| 601 | if (ret == 0) |
| 602 | goto out; |
| 603 | |
Russell King | 73b6a2b | 2007-05-03 09:55:52 +0100 | [diff] [blame] | 604 | release: |
| 605 | ecard_release_resources(ec); |
| 606 | out: |
| 607 | return ret; |
| 608 | } |
| 609 | |
| 610 | static void pata_icside_shutdown(struct expansion_card *ec) |
| 611 | { |
| 612 | struct ata_host *host = ecard_get_drvdata(ec); |
| 613 | unsigned long flags; |
| 614 | |
| 615 | /* |
| 616 | * Disable interrupts from this card. We need to do |
| 617 | * this before disabling EASI since we may be accessing |
| 618 | * this register via that region. |
| 619 | */ |
| 620 | local_irq_save(flags); |
Russell King | c7b87f3 | 2007-05-10 16:46:13 +0100 | [diff] [blame] | 621 | ec->ops->irqdisable(ec, ec->irq); |
Russell King | 73b6a2b | 2007-05-03 09:55:52 +0100 | [diff] [blame] | 622 | local_irq_restore(flags); |
| 623 | |
| 624 | /* |
| 625 | * Reset the ROM pointer so that we can read the ROM |
| 626 | * after a soft reboot. This also disables access to |
| 627 | * the IDE taskfile via the EASI region. |
| 628 | */ |
| 629 | if (host) { |
| 630 | struct pata_icside_state *state = host->private_data; |
| 631 | if (state->ioc_base) |
| 632 | writeb(0, state->ioc_base); |
| 633 | } |
| 634 | } |
| 635 | |
| 636 | static void __devexit pata_icside_remove(struct expansion_card *ec) |
| 637 | { |
| 638 | struct ata_host *host = ecard_get_drvdata(ec); |
| 639 | struct pata_icside_state *state = host->private_data; |
| 640 | |
| 641 | ata_host_detach(host); |
| 642 | |
| 643 | pata_icside_shutdown(ec); |
| 644 | |
| 645 | /* |
| 646 | * don't NULL out the drvdata - devres/libata wants it |
| 647 | * to free the ata_host structure. |
| 648 | */ |
Russell King | 73b6a2b | 2007-05-03 09:55:52 +0100 | [diff] [blame] | 649 | if (state->dma != NO_DMA) |
| 650 | free_dma(state->dma); |
Russell King | 73b6a2b | 2007-05-03 09:55:52 +0100 | [diff] [blame] | 651 | |
Russell King | 73b6a2b | 2007-05-03 09:55:52 +0100 | [diff] [blame] | 652 | ecard_release_resources(ec); |
| 653 | } |
| 654 | |
| 655 | static const struct ecard_id pata_icside_ids[] = { |
| 656 | { MANU_ICS, PROD_ICS_IDE }, |
| 657 | { MANU_ICS2, PROD_ICS2_IDE }, |
| 658 | { 0xffff, 0xffff } |
| 659 | }; |
| 660 | |
| 661 | static struct ecard_driver pata_icside_driver = { |
| 662 | .probe = pata_icside_probe, |
| 663 | .remove = __devexit_p(pata_icside_remove), |
| 664 | .shutdown = pata_icside_shutdown, |
| 665 | .id_table = pata_icside_ids, |
| 666 | .drv = { |
| 667 | .name = DRV_NAME, |
| 668 | }, |
| 669 | }; |
| 670 | |
| 671 | static int __init pata_icside_init(void) |
| 672 | { |
| 673 | return ecard_register_driver(&pata_icside_driver); |
| 674 | } |
| 675 | |
| 676 | static void __exit pata_icside_exit(void) |
| 677 | { |
| 678 | ecard_remove_driver(&pata_icside_driver); |
| 679 | } |
| 680 | |
| 681 | MODULE_AUTHOR("Russell King <rmk@arm.linux.org.uk>"); |
| 682 | MODULE_LICENSE("GPL"); |
| 683 | MODULE_DESCRIPTION("ICS PATA driver"); |
| 684 | |
| 685 | module_init(pata_icside_init); |
| 686 | module_exit(pata_icside_exit); |