Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 1 | /* |
| 2 | * pata_qdi.c - QDI VLB ATA controllers |
| 3 | * (C) 2006 Red Hat <alan@redhat.com> |
| 4 | * |
| 5 | * This driver mostly exists as a proof of concept for non PCI devices under |
| 6 | * libata. While the QDI6580 was 'neat' in 1993 it is no longer terribly |
| 7 | * useful. |
| 8 | * |
| 9 | * Tuning code written from the documentation at |
| 10 | * http://www.ryston.cz/petr/vlb/qd6500.html |
| 11 | * http://www.ryston.cz/petr/vlb/qd6580.html |
| 12 | * |
| 13 | * Probe code based on drivers/ide/legacy/qd65xx.c |
| 14 | * Rewritten from the work of Colten Edwards <pje120@cs.usask.ca> by |
| 15 | * Samuel Thibault <samuel.thibault@fnac.net> |
| 16 | */ |
| 17 | |
| 18 | #include <linux/kernel.h> |
| 19 | #include <linux/module.h> |
| 20 | #include <linux/pci.h> |
| 21 | #include <linux/init.h> |
| 22 | #include <linux/blkdev.h> |
| 23 | #include <linux/delay.h> |
| 24 | #include <scsi/scsi_host.h> |
| 25 | #include <linux/libata.h> |
| 26 | #include <linux/platform_device.h> |
| 27 | |
| 28 | #define DRV_NAME "pata_qdi" |
Jeff Garzik | cb48cab | 2007-02-26 06:04:24 -0500 | [diff] [blame] | 29 | #define DRV_VERSION "0.3.0" |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 30 | |
| 31 | #define NR_HOST 4 /* Two 6580s */ |
| 32 | |
| 33 | struct qdi_data { |
| 34 | unsigned long timing; |
| 35 | u8 clock[2]; |
| 36 | u8 last; |
| 37 | int fast; |
| 38 | struct platform_device *platform_dev; |
Jeff Garzik | 85cd725 | 2006-08-31 00:03:49 -0400 | [diff] [blame] | 39 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 40 | }; |
| 41 | |
| 42 | static struct ata_host *qdi_host[NR_HOST]; |
| 43 | static struct qdi_data qdi_data[NR_HOST]; |
| 44 | static int nr_qdi_host; |
| 45 | |
| 46 | #ifdef MODULE |
| 47 | static int probe_qdi = 1; |
| 48 | #else |
| 49 | static int probe_qdi; |
| 50 | #endif |
| 51 | |
| 52 | static void qdi6500_set_piomode(struct ata_port *ap, struct ata_device *adev) |
| 53 | { |
| 54 | struct ata_timing t; |
| 55 | struct qdi_data *qdi = ap->host->private_data; |
| 56 | int active, recovery; |
| 57 | u8 timing; |
| 58 | |
| 59 | /* Get the timing data in cycles */ |
| 60 | ata_timing_compute(adev, adev->pio_mode, &t, 30303, 1000); |
Jeff Garzik | 85cd725 | 2006-08-31 00:03:49 -0400 | [diff] [blame] | 61 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 62 | if (qdi->fast) { |
| 63 | active = 8 - FIT(t.active, 1, 8); |
| 64 | recovery = 18 - FIT(t.recover, 3, 18); |
| 65 | } else { |
| 66 | active = 9 - FIT(t.active, 2, 9); |
| 67 | recovery = 15 - FIT(t.recover, 0, 15); |
| 68 | } |
| 69 | timing = (recovery << 4) | active | 0x08; |
Jeff Garzik | 85cd725 | 2006-08-31 00:03:49 -0400 | [diff] [blame] | 70 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 71 | qdi->clock[adev->devno] = timing; |
| 72 | |
Jeff Garzik | 85cd725 | 2006-08-31 00:03:49 -0400 | [diff] [blame] | 73 | outb(timing, qdi->timing); |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | static void qdi6580_set_piomode(struct ata_port *ap, struct ata_device *adev) |
| 77 | { |
| 78 | struct ata_timing t; |
| 79 | struct qdi_data *qdi = ap->host->private_data; |
| 80 | int active, recovery; |
| 81 | u8 timing; |
| 82 | |
| 83 | /* Get the timing data in cycles */ |
| 84 | ata_timing_compute(adev, adev->pio_mode, &t, 30303, 1000); |
Jeff Garzik | 85cd725 | 2006-08-31 00:03:49 -0400 | [diff] [blame] | 85 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 86 | if (qdi->fast) { |
| 87 | active = 8 - FIT(t.active, 1, 8); |
| 88 | recovery = 18 - FIT(t.recover, 3, 18); |
| 89 | } else { |
| 90 | active = 9 - FIT(t.active, 2, 9); |
| 91 | recovery = 15 - FIT(t.recover, 0, 15); |
| 92 | } |
| 93 | timing = (recovery << 4) | active | 0x08; |
Jeff Garzik | 85cd725 | 2006-08-31 00:03:49 -0400 | [diff] [blame] | 94 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 95 | qdi->clock[adev->devno] = timing; |
| 96 | |
| 97 | outb(timing, qdi->timing); |
Jeff Garzik | 85cd725 | 2006-08-31 00:03:49 -0400 | [diff] [blame] | 98 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 99 | /* Clear the FIFO */ |
| 100 | if (adev->class != ATA_DEV_ATA) |
| 101 | outb(0x5F, (qdi->timing & 0xFFF0) + 3); |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * qdi_qc_issue_prot - command issue |
| 106 | * @qc: command pending |
| 107 | * |
| 108 | * Called when the libata layer is about to issue a command. We wrap |
| 109 | * this interface so that we can load the correct ATA timings. |
| 110 | */ |
| 111 | |
| 112 | static unsigned int qdi_qc_issue_prot(struct ata_queued_cmd *qc) |
| 113 | { |
| 114 | struct ata_port *ap = qc->ap; |
| 115 | struct ata_device *adev = qc->dev; |
| 116 | struct qdi_data *qdi = ap->host->private_data; |
| 117 | |
| 118 | if (qdi->clock[adev->devno] != qdi->last) { |
| 119 | if (adev->pio_mode) { |
| 120 | qdi->last = qdi->clock[adev->devno]; |
| 121 | outb(qdi->clock[adev->devno], qdi->timing); |
| 122 | } |
| 123 | } |
| 124 | return ata_qc_issue_prot(qc); |
| 125 | } |
| 126 | |
| 127 | static void qdi_data_xfer(struct ata_device *adev, unsigned char *buf, unsigned int buflen, int write_data) |
| 128 | { |
| 129 | struct ata_port *ap = adev->ap; |
| 130 | int slop = buflen & 3; |
Jeff Garzik | 85cd725 | 2006-08-31 00:03:49 -0400 | [diff] [blame] | 131 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 132 | if (ata_id_has_dword_io(adev->id)) { |
| 133 | if (write_data) |
Tejun Heo | 0d5ff56 | 2007-02-01 15:06:36 +0900 | [diff] [blame] | 134 | iowrite32_rep(ap->ioaddr.data_addr, buf, buflen >> 2); |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 135 | else |
Tejun Heo | 0d5ff56 | 2007-02-01 15:06:36 +0900 | [diff] [blame] | 136 | ioread32_rep(ap->ioaddr.data_addr, buf, buflen >> 2); |
Jeff Garzik | 85cd725 | 2006-08-31 00:03:49 -0400 | [diff] [blame] | 137 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 138 | if (unlikely(slop)) { |
| 139 | u32 pad; |
| 140 | if (write_data) { |
| 141 | memcpy(&pad, buf + buflen - slop, slop); |
Tejun Heo | 0d5ff56 | 2007-02-01 15:06:36 +0900 | [diff] [blame] | 142 | pad = le32_to_cpu(pad); |
| 143 | iowrite32(pad, ap->ioaddr.data_addr); |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 144 | } else { |
Tejun Heo | 0d5ff56 | 2007-02-01 15:06:36 +0900 | [diff] [blame] | 145 | pad = ioread32(ap->ioaddr.data_addr); |
| 146 | pad = cpu_to_le32(pad); |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 147 | memcpy(buf + buflen - slop, &pad, slop); |
| 148 | } |
| 149 | } |
| 150 | } else |
Tejun Heo | 0d5ff56 | 2007-02-01 15:06:36 +0900 | [diff] [blame] | 151 | ata_data_xfer(adev, buf, buflen, write_data); |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | static struct scsi_host_template qdi_sht = { |
| 155 | .module = THIS_MODULE, |
| 156 | .name = DRV_NAME, |
| 157 | .ioctl = ata_scsi_ioctl, |
| 158 | .queuecommand = ata_scsi_queuecmd, |
| 159 | .can_queue = ATA_DEF_QUEUE, |
| 160 | .this_id = ATA_SHT_THIS_ID, |
| 161 | .sg_tablesize = LIBATA_MAX_PRD, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 162 | .cmd_per_lun = ATA_SHT_CMD_PER_LUN, |
| 163 | .emulated = ATA_SHT_EMULATED, |
| 164 | .use_clustering = ATA_SHT_USE_CLUSTERING, |
| 165 | .proc_name = DRV_NAME, |
| 166 | .dma_boundary = ATA_DMA_BOUNDARY, |
| 167 | .slave_configure = ata_scsi_slave_config, |
Tejun Heo | afdfe89 | 2006-11-29 11:26:47 +0900 | [diff] [blame] | 168 | .slave_destroy = ata_scsi_slave_destroy, |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 169 | .bios_param = ata_std_bios_param, |
| 170 | }; |
| 171 | |
| 172 | static struct ata_port_operations qdi6500_port_ops = { |
| 173 | .port_disable = ata_port_disable, |
| 174 | .set_piomode = qdi6500_set_piomode, |
| 175 | |
| 176 | .tf_load = ata_tf_load, |
| 177 | .tf_read = ata_tf_read, |
| 178 | .check_status = ata_check_status, |
| 179 | .exec_command = ata_exec_command, |
| 180 | .dev_select = ata_std_dev_select, |
| 181 | |
| 182 | .freeze = ata_bmdma_freeze, |
| 183 | .thaw = ata_bmdma_thaw, |
| 184 | .error_handler = ata_bmdma_error_handler, |
| 185 | .post_internal_cmd = ata_bmdma_post_internal_cmd, |
Alan Cox | 3be40d7 | 2007-03-26 21:43:40 -0800 | [diff] [blame] | 186 | .cable_detect = ata_cable_40wire, |
Jeff Garzik | 85cd725 | 2006-08-31 00:03:49 -0400 | [diff] [blame] | 187 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 188 | .qc_prep = ata_qc_prep, |
| 189 | .qc_issue = qdi_qc_issue_prot, |
Jeff Garzik | bda3028 | 2006-09-27 05:41:13 -0400 | [diff] [blame] | 190 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 191 | .data_xfer = qdi_data_xfer, |
| 192 | |
| 193 | .irq_handler = ata_interrupt, |
| 194 | .irq_clear = ata_bmdma_irq_clear, |
Akira Iguchi | 246ce3b | 2007-01-26 16:27:58 +0900 | [diff] [blame] | 195 | .irq_on = ata_irq_on, |
| 196 | .irq_ack = ata_irq_ack, |
Jeff Garzik | 85cd725 | 2006-08-31 00:03:49 -0400 | [diff] [blame] | 197 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 198 | .port_start = ata_port_start, |
Jeff Garzik | 85cd725 | 2006-08-31 00:03:49 -0400 | [diff] [blame] | 199 | }; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 200 | |
| 201 | static struct ata_port_operations qdi6580_port_ops = { |
| 202 | .port_disable = ata_port_disable, |
| 203 | .set_piomode = qdi6580_set_piomode, |
| 204 | |
| 205 | .tf_load = ata_tf_load, |
| 206 | .tf_read = ata_tf_read, |
| 207 | .check_status = ata_check_status, |
| 208 | .exec_command = ata_exec_command, |
| 209 | .dev_select = ata_std_dev_select, |
| 210 | |
| 211 | .freeze = ata_bmdma_freeze, |
| 212 | .thaw = ata_bmdma_thaw, |
| 213 | .error_handler = ata_bmdma_error_handler, |
| 214 | .post_internal_cmd = ata_bmdma_post_internal_cmd, |
Alan Cox | 3be40d7 | 2007-03-26 21:43:40 -0800 | [diff] [blame] | 215 | .cable_detect = ata_cable_40wire, |
Jeff Garzik | 85cd725 | 2006-08-31 00:03:49 -0400 | [diff] [blame] | 216 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 217 | .qc_prep = ata_qc_prep, |
| 218 | .qc_issue = qdi_qc_issue_prot, |
Jeff Garzik | bda3028 | 2006-09-27 05:41:13 -0400 | [diff] [blame] | 219 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 220 | .data_xfer = qdi_data_xfer, |
| 221 | |
| 222 | .irq_handler = ata_interrupt, |
| 223 | .irq_clear = ata_bmdma_irq_clear, |
Akira Iguchi | 246ce3b | 2007-01-26 16:27:58 +0900 | [diff] [blame] | 224 | .irq_on = ata_irq_on, |
| 225 | .irq_ack = ata_irq_ack, |
Jeff Garzik | 85cd725 | 2006-08-31 00:03:49 -0400 | [diff] [blame] | 226 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 227 | .port_start = ata_port_start, |
Jeff Garzik | 85cd725 | 2006-08-31 00:03:49 -0400 | [diff] [blame] | 228 | }; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 229 | |
| 230 | /** |
| 231 | * qdi_init_one - attach a qdi interface |
| 232 | * @type: Type to display |
| 233 | * @io: I/O port start |
| 234 | * @irq: interrupt line |
| 235 | * @fast: True if on a > 33Mhz VLB |
| 236 | * |
| 237 | * Register an ISA bus IDE interface. Such interfaces are PIO and we |
| 238 | * assume do not support IRQ sharing. |
| 239 | */ |
Jeff Garzik | 85cd725 | 2006-08-31 00:03:49 -0400 | [diff] [blame] | 240 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 241 | static __init int qdi_init_one(unsigned long port, int type, unsigned long io, int irq, int fast) |
| 242 | { |
| 243 | struct ata_probe_ent ae; |
| 244 | struct platform_device *pdev; |
Tejun Heo | 0d5ff56 | 2007-02-01 15:06:36 +0900 | [diff] [blame] | 245 | void __iomem *io_addr, *ctl_addr; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 246 | int ret; |
| 247 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 248 | /* |
| 249 | * Fill in a probe structure first of all |
| 250 | */ |
| 251 | |
| 252 | pdev = platform_device_register_simple(DRV_NAME, nr_qdi_host, NULL, 0); |
Akinobu Mita | 9825d73 | 2006-12-15 13:08:51 -0800 | [diff] [blame] | 253 | if (IS_ERR(pdev)) |
| 254 | return PTR_ERR(pdev); |
Jeff Garzik | 85cd725 | 2006-08-31 00:03:49 -0400 | [diff] [blame] | 255 | |
Tejun Heo | 0d5ff56 | 2007-02-01 15:06:36 +0900 | [diff] [blame] | 256 | ret = -ENOMEM; |
| 257 | io_addr = devm_ioport_map(&pdev->dev, io, 8); |
| 258 | ctl_addr = devm_ioport_map(&pdev->dev, io + 0x206, 1); |
| 259 | if (!io_addr || !ctl_addr) |
| 260 | goto fail; |
| 261 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 262 | memset(&ae, 0, sizeof(struct ata_probe_ent)); |
| 263 | INIT_LIST_HEAD(&ae.node); |
| 264 | ae.dev = &pdev->dev; |
Jeff Garzik | 85cd725 | 2006-08-31 00:03:49 -0400 | [diff] [blame] | 265 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 266 | if (type == 6580) { |
| 267 | ae.port_ops = &qdi6580_port_ops; |
| 268 | ae.pio_mask = 0x1F; |
Alan Cox | f834e49 | 2007-02-07 13:46:00 -0800 | [diff] [blame] | 269 | ae.port_flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 270 | } else { |
| 271 | ae.port_ops = &qdi6500_port_ops; |
| 272 | ae.pio_mask = 0x07; /* Actually PIO3 !IORDY is possible */ |
Alan Cox | f834e49 | 2007-02-07 13:46:00 -0800 | [diff] [blame] | 273 | ae.port_flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST | |
| 274 | ATA_FLAG_NO_IORDY; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 275 | } |
Jeff Garzik | 85cd725 | 2006-08-31 00:03:49 -0400 | [diff] [blame] | 276 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 277 | ae.sht = &qdi_sht; |
| 278 | ae.n_ports = 1; |
| 279 | ae.irq = irq; |
| 280 | ae.irq_flags = 0; |
Tejun Heo | 0d5ff56 | 2007-02-01 15:06:36 +0900 | [diff] [blame] | 281 | ae.port[0].cmd_addr = io_addr; |
| 282 | ae.port[0].altstatus_addr = ctl_addr; |
| 283 | ae.port[0].ctl_addr = ctl_addr; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 284 | ata_std_ports(&ae.port[0]); |
| 285 | |
| 286 | /* |
| 287 | * Hook in a private data structure per channel |
| 288 | */ |
| 289 | ae.private_data = &qdi_data[nr_qdi_host]; |
| 290 | |
| 291 | qdi_data[nr_qdi_host].timing = port; |
| 292 | qdi_data[nr_qdi_host].fast = fast; |
| 293 | qdi_data[nr_qdi_host].platform_dev = pdev; |
| 294 | |
| 295 | printk(KERN_INFO DRV_NAME": qd%d at 0x%lx.\n", type, io); |
Tejun Heo | 0d5ff56 | 2007-02-01 15:06:36 +0900 | [diff] [blame] | 296 | |
| 297 | ret = -ENODEV; |
| 298 | if (!ata_device_add(&ae)) |
| 299 | goto fail; |
Jeff Garzik | 85cd725 | 2006-08-31 00:03:49 -0400 | [diff] [blame] | 300 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 301 | qdi_host[nr_qdi_host++] = dev_get_drvdata(&pdev->dev); |
Jeff Garzik | 85cd725 | 2006-08-31 00:03:49 -0400 | [diff] [blame] | 302 | return 0; |
Tejun Heo | 0d5ff56 | 2007-02-01 15:06:36 +0900 | [diff] [blame] | 303 | |
| 304 | fail: |
| 305 | platform_device_unregister(pdev); |
| 306 | return ret; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | /** |
| 310 | * qdi_init - attach qdi interfaces |
| 311 | * |
| 312 | * Attach qdi IDE interfaces by scanning the ports it may occupy. |
| 313 | */ |
Jeff Garzik | 85cd725 | 2006-08-31 00:03:49 -0400 | [diff] [blame] | 314 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 315 | static __init int qdi_init(void) |
| 316 | { |
| 317 | unsigned long flags; |
| 318 | static const unsigned long qd_port[2] = { 0x30, 0xB0 }; |
| 319 | static const unsigned long ide_port[2] = { 0x170, 0x1F0 }; |
| 320 | static const int ide_irq[2] = { 14, 15 }; |
Jeff Garzik | 85cd725 | 2006-08-31 00:03:49 -0400 | [diff] [blame] | 321 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 322 | int ct = 0; |
| 323 | int i; |
Jeff Garzik | 85cd725 | 2006-08-31 00:03:49 -0400 | [diff] [blame] | 324 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 325 | if (probe_qdi == 0) |
| 326 | return -ENODEV; |
Jeff Garzik | 85cd725 | 2006-08-31 00:03:49 -0400 | [diff] [blame] | 327 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 328 | /* |
| 329 | * Check each possible QD65xx base address |
| 330 | */ |
Jeff Garzik | 85cd725 | 2006-08-31 00:03:49 -0400 | [diff] [blame] | 331 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 332 | for (i = 0; i < 2; i++) { |
| 333 | unsigned long port = qd_port[i]; |
| 334 | u8 r, res; |
Jeff Garzik | 85cd725 | 2006-08-31 00:03:49 -0400 | [diff] [blame] | 335 | |
| 336 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 337 | if (request_region(port, 2, "pata_qdi")) { |
| 338 | /* Check for a card */ |
| 339 | local_irq_save(flags); |
| 340 | r = inb_p(port); |
| 341 | outb_p(0x19, port); |
| 342 | res = inb_p(port); |
| 343 | outb_p(r, port); |
| 344 | local_irq_restore(flags); |
Jeff Garzik | 85cd725 | 2006-08-31 00:03:49 -0400 | [diff] [blame] | 345 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 346 | /* Fail */ |
| 347 | if (res == 0x19) |
| 348 | { |
| 349 | release_region(port, 2); |
| 350 | continue; |
| 351 | } |
Jeff Garzik | 85cd725 | 2006-08-31 00:03:49 -0400 | [diff] [blame] | 352 | |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 353 | /* Passes the presence test */ |
| 354 | r = inb_p(port + 1); /* Check port agrees with port set */ |
| 355 | if ((r & 2) >> 1 != i) { |
| 356 | release_region(port, 2); |
| 357 | continue; |
| 358 | } |
| 359 | |
Jeff Garzik | 85cd725 | 2006-08-31 00:03:49 -0400 | [diff] [blame] | 360 | /* Check card type */ |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 361 | if ((r & 0xF0) == 0xC0) { |
| 362 | /* QD6500: single channel */ |
| 363 | if (r & 8) { |
| 364 | /* Disabled ? */ |
| 365 | release_region(port, 2); |
| 366 | continue; |
| 367 | } |
Alan Cox | cc7c15e | 2007-03-02 14:56:35 +0000 | [diff] [blame] | 368 | if (qdi_init_one(port, 6500, ide_port[r & 0x01], ide_irq[r & 0x01], r & 0x04) == 0) |
| 369 | ct++; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 370 | } |
| 371 | if (((r & 0xF0) == 0xA0) || (r & 0xF0) == 0x50) { |
| 372 | /* QD6580: dual channel */ |
| 373 | if (!request_region(port + 2 , 2, "pata_qdi")) |
| 374 | { |
| 375 | release_region(port, 2); |
| 376 | continue; |
| 377 | } |
| 378 | res = inb(port + 3); |
| 379 | if (res & 1) { |
| 380 | /* Single channel mode */ |
Alan Cox | cc7c15e | 2007-03-02 14:56:35 +0000 | [diff] [blame] | 381 | if (qdi_init_one(port, 6580, ide_port[r & 0x01], ide_irq[r & 0x01], r & 0x04)) |
| 382 | ct++; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 383 | } else { |
| 384 | /* Dual channel mode */ |
Alan Cox | cc7c15e | 2007-03-02 14:56:35 +0000 | [diff] [blame] | 385 | if (qdi_init_one(port, 6580, 0x1F0, 14, r & 0x04) == 0) |
| 386 | ct++; |
| 387 | if (qdi_init_one(port + 2, 6580, 0x170, 15, r & 0x04) == 0) |
| 388 | ct++; |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 389 | } |
| 390 | } |
| 391 | } |
| 392 | } |
| 393 | if (ct != 0) |
| 394 | return 0; |
| 395 | return -ENODEV; |
| 396 | } |
| 397 | |
| 398 | static __exit void qdi_exit(void) |
| 399 | { |
| 400 | int i; |
| 401 | |
| 402 | for (i = 0; i < nr_qdi_host; i++) { |
Tejun Heo | 24dc5f3 | 2007-01-20 16:00:28 +0900 | [diff] [blame] | 403 | ata_host_detach(qdi_host[i]); |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 404 | /* Free the control resource. The 6580 dual channel has the resources |
| 405 | * claimed as a pair of 2 byte resources so we need no special cases... |
| 406 | */ |
| 407 | release_region(qdi_data[i].timing, 2); |
| 408 | platform_device_unregister(qdi_data[i].platform_dev); |
Jeff Garzik | 85cd725 | 2006-08-31 00:03:49 -0400 | [diff] [blame] | 409 | } |
Jeff Garzik | 669a5db | 2006-08-29 18:12:40 -0400 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | MODULE_AUTHOR("Alan Cox"); |
| 413 | MODULE_DESCRIPTION("low-level driver for qdi ATA"); |
| 414 | MODULE_LICENSE("GPL"); |
| 415 | MODULE_VERSION(DRV_VERSION); |
| 416 | |
| 417 | module_init(qdi_init); |
| 418 | module_exit(qdi_exit); |
| 419 | |
| 420 | module_param(probe_qdi, int, 0); |
| 421 | |