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