libata: dev_config does not need ap and adev passing
[linux-2.6/mini2440.git] / drivers / ata / pata_pdc202xx_old.c
bloba764ce8252aaff75584030a56a1f541a096cb7a0
1 /*
2 * pata_pdc202xx_old.c - Promise PDC202xx PATA for new ATA layer
3 * (C) 2005 Red Hat Inc
4 * Alan Cox <alan@redhat.com>
5 * (C) 2007 Bartlomiej Zolnierkiewicz
7 * Based in part on linux/drivers/ide/pci/pdc202xx_old.c
9 * First cut with LBA48/ATAPI
11 * TODO:
12 * Channel interlock/reset on both required
15 #include <linux/kernel.h>
16 #include <linux/module.h>
17 #include <linux/pci.h>
18 #include <linux/init.h>
19 #include <linux/blkdev.h>
20 #include <linux/delay.h>
21 #include <scsi/scsi_host.h>
22 #include <linux/libata.h>
24 #define DRV_NAME "pata_pdc202xx_old"
25 #define DRV_VERSION "0.4.0"
27 /**
28 * pdc2024x_pre_reset - probe begin
29 * @ap: ATA port
31 * Set up cable type and use generic probe init
34 static int pdc2024x_pre_reset(struct ata_port *ap)
36 ap->cbl = ATA_CBL_PATA40;
37 return ata_std_prereset(ap);
41 static void pdc2024x_error_handler(struct ata_port *ap)
43 ata_bmdma_drive_eh(ap, pdc2024x_pre_reset, ata_std_softreset, NULL, ata_std_postreset);
47 static int pdc2026x_pre_reset(struct ata_port *ap)
49 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
50 u16 cis;
52 pci_read_config_word(pdev, 0x50, &cis);
53 if (cis & (1 << (10 + ap->port_no)))
54 ap->cbl = ATA_CBL_PATA80;
55 else
56 ap->cbl = ATA_CBL_PATA40;
58 return ata_std_prereset(ap);
61 static void pdc2026x_error_handler(struct ata_port *ap)
63 ata_bmdma_drive_eh(ap, pdc2026x_pre_reset, ata_std_softreset, NULL, ata_std_postreset);
66 /**
67 * pdc202xx_configure_piomode - set chip PIO timing
68 * @ap: ATA interface
69 * @adev: ATA device
70 * @pio: PIO mode
72 * Called to do the PIO mode setup. Our timing registers are shared
73 * so a configure_dmamode call will undo any work we do here and vice
74 * versa
77 static void pdc202xx_configure_piomode(struct ata_port *ap, struct ata_device *adev, int pio)
79 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
80 int port = 0x60 + 8 * ap->port_no + 4 * adev->devno;
81 static u16 pio_timing[5] = {
82 0x0913, 0x050C , 0x0308, 0x0206, 0x0104
84 u8 r_ap, r_bp;
86 pci_read_config_byte(pdev, port, &r_ap);
87 pci_read_config_byte(pdev, port + 1, &r_bp);
88 r_ap &= ~0x3F; /* Preserve ERRDY_EN, SYNC_IN */
89 r_bp &= ~0x1F;
90 r_ap |= (pio_timing[pio] >> 8);
91 r_bp |= (pio_timing[pio] & 0xFF);
93 if (ata_pio_need_iordy(adev))
94 r_ap |= 0x20; /* IORDY enable */
95 if (adev->class == ATA_DEV_ATA)
96 r_ap |= 0x10; /* FIFO enable */
97 pci_write_config_byte(pdev, port, r_ap);
98 pci_write_config_byte(pdev, port + 1, r_bp);
102 * pdc202xx_set_piomode - set initial PIO mode data
103 * @ap: ATA interface
104 * @adev: ATA device
106 * Called to do the PIO mode setup. Our timing registers are shared
107 * but we want to set the PIO timing by default.
110 static void pdc202xx_set_piomode(struct ata_port *ap, struct ata_device *adev)
112 pdc202xx_configure_piomode(ap, adev, adev->pio_mode - XFER_PIO_0);
116 * pdc202xx_configure_dmamode - set DMA mode in chip
117 * @ap: ATA interface
118 * @adev: ATA device
120 * Load DMA cycle times into the chip ready for a DMA transfer
121 * to occur.
124 static void pdc202xx_set_dmamode(struct ata_port *ap, struct ata_device *adev)
126 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
127 int port = 0x60 + 8 * ap->port_no + 4 * adev->devno;
128 static u8 udma_timing[6][2] = {
129 { 0x60, 0x03 }, /* 33 Mhz Clock */
130 { 0x40, 0x02 },
131 { 0x20, 0x01 },
132 { 0x40, 0x02 }, /* 66 Mhz Clock */
133 { 0x20, 0x01 },
134 { 0x20, 0x01 }
136 static u8 mdma_timing[3][2] = {
137 { 0x60, 0x03 },
138 { 0x60, 0x04 },
139 { 0xe0, 0x0f },
141 u8 r_bp, r_cp;
143 pci_read_config_byte(pdev, port + 1, &r_bp);
144 pci_read_config_byte(pdev, port + 2, &r_cp);
146 r_bp &= ~0xE0;
147 r_cp &= ~0x0F;
149 if (adev->dma_mode >= XFER_UDMA_0) {
150 int speed = adev->dma_mode - XFER_UDMA_0;
151 r_bp |= udma_timing[speed][0];
152 r_cp |= udma_timing[speed][1];
154 } else {
155 int speed = adev->dma_mode - XFER_MW_DMA_0;
156 r_bp |= mdma_timing[speed][0];
157 r_cp |= mdma_timing[speed][1];
159 pci_write_config_byte(pdev, port + 1, r_bp);
160 pci_write_config_byte(pdev, port + 2, r_cp);
165 * pdc2026x_bmdma_start - DMA engine begin
166 * @qc: ATA command
168 * In UDMA3 or higher we have to clock switch for the duration of the
169 * DMA transfer sequence.
172 static void pdc2026x_bmdma_start(struct ata_queued_cmd *qc)
174 struct ata_port *ap = qc->ap;
175 struct ata_device *adev = qc->dev;
176 struct ata_taskfile *tf = &qc->tf;
177 int sel66 = ap->port_no ? 0x08: 0x02;
179 void __iomem *master = ap->host->ports[0]->ioaddr.bmdma_addr;
180 void __iomem *clock = master + 0x11;
181 void __iomem *atapi_reg = master + 0x20 + (4 * ap->port_no);
183 u32 len;
185 /* Check we keep host level locking here */
186 if (adev->dma_mode >= XFER_UDMA_2)
187 iowrite8(ioread8(clock) | sel66, clock);
188 else
189 iowrite8(ioread8(clock) & ~sel66, clock);
191 /* The DMA clocks may have been trashed by a reset. FIXME: make conditional
192 and move to qc_issue ? */
193 pdc202xx_set_dmamode(ap, qc->dev);
195 /* Cases the state machine will not complete correctly without help */
196 if ((tf->flags & ATA_TFLAG_LBA48) || tf->protocol == ATA_PROT_ATAPI_DMA)
198 len = qc->nbytes / 2;
200 if (tf->flags & ATA_TFLAG_WRITE)
201 len |= 0x06000000;
202 else
203 len |= 0x05000000;
205 iowrite32(len, atapi_reg);
208 /* Activate DMA */
209 ata_bmdma_start(qc);
213 * pdc2026x_bmdma_end - DMA engine stop
214 * @qc: ATA command
216 * After a DMA completes we need to put the clock back to 33MHz for
217 * PIO timings.
220 static void pdc2026x_bmdma_stop(struct ata_queued_cmd *qc)
222 struct ata_port *ap = qc->ap;
223 struct ata_device *adev = qc->dev;
224 struct ata_taskfile *tf = &qc->tf;
226 int sel66 = ap->port_no ? 0x08: 0x02;
227 /* The clock bits are in the same register for both channels */
228 void __iomem *master = ap->host->ports[0]->ioaddr.bmdma_addr;
229 void __iomem *clock = master + 0x11;
230 void __iomem *atapi_reg = master + 0x20 + (4 * ap->port_no);
232 /* Cases the state machine will not complete correctly */
233 if (tf->protocol == ATA_PROT_ATAPI_DMA || ( tf->flags & ATA_TFLAG_LBA48)) {
234 iowrite32(0, atapi_reg);
235 iowrite8(ioread8(clock) & ~sel66, clock);
237 /* Check we keep host level locking here */
238 /* Flip back to 33Mhz for PIO */
239 if (adev->dma_mode >= XFER_UDMA_2)
240 iowrite8(ioread8(clock) & ~sel66, clock);
242 ata_bmdma_stop(qc);
246 * pdc2026x_dev_config - device setup hook
247 * @adev: newly found device
249 * Perform chip specific early setup. We need to lock the transfer
250 * sizes to 8bit to avoid making the state engine on the 2026x cards
251 * barf.
254 static void pdc2026x_dev_config(struct ata_device *adev)
256 adev->max_sectors = 256;
259 static struct scsi_host_template pdc202xx_sht = {
260 .module = THIS_MODULE,
261 .name = DRV_NAME,
262 .ioctl = ata_scsi_ioctl,
263 .queuecommand = ata_scsi_queuecmd,
264 .can_queue = ATA_DEF_QUEUE,
265 .this_id = ATA_SHT_THIS_ID,
266 .sg_tablesize = LIBATA_MAX_PRD,
267 .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
268 .emulated = ATA_SHT_EMULATED,
269 .use_clustering = ATA_SHT_USE_CLUSTERING,
270 .proc_name = DRV_NAME,
271 .dma_boundary = ATA_DMA_BOUNDARY,
272 .slave_configure = ata_scsi_slave_config,
273 .slave_destroy = ata_scsi_slave_destroy,
274 .bios_param = ata_std_bios_param,
275 #ifdef CONFIG_PM
276 .resume = ata_scsi_device_resume,
277 .suspend = ata_scsi_device_suspend,
278 #endif
281 static struct ata_port_operations pdc2024x_port_ops = {
282 .port_disable = ata_port_disable,
283 .set_piomode = pdc202xx_set_piomode,
284 .set_dmamode = pdc202xx_set_dmamode,
285 .mode_filter = ata_pci_default_filter,
286 .tf_load = ata_tf_load,
287 .tf_read = ata_tf_read,
288 .check_status = ata_check_status,
289 .exec_command = ata_exec_command,
290 .dev_select = ata_std_dev_select,
292 .freeze = ata_bmdma_freeze,
293 .thaw = ata_bmdma_thaw,
294 .error_handler = pdc2024x_error_handler,
295 .post_internal_cmd = ata_bmdma_post_internal_cmd,
297 .bmdma_setup = ata_bmdma_setup,
298 .bmdma_start = ata_bmdma_start,
299 .bmdma_stop = ata_bmdma_stop,
300 .bmdma_status = ata_bmdma_status,
302 .qc_prep = ata_qc_prep,
303 .qc_issue = ata_qc_issue_prot,
304 .data_xfer = ata_data_xfer,
306 .irq_handler = ata_interrupt,
307 .irq_clear = ata_bmdma_irq_clear,
308 .irq_on = ata_irq_on,
309 .irq_ack = ata_irq_ack,
311 .port_start = ata_port_start,
314 static struct ata_port_operations pdc2026x_port_ops = {
315 .port_disable = ata_port_disable,
316 .set_piomode = pdc202xx_set_piomode,
317 .set_dmamode = pdc202xx_set_dmamode,
318 .mode_filter = ata_pci_default_filter,
319 .tf_load = ata_tf_load,
320 .tf_read = ata_tf_read,
321 .check_status = ata_check_status,
322 .exec_command = ata_exec_command,
323 .dev_select = ata_std_dev_select,
324 .dev_config = pdc2026x_dev_config,
326 .freeze = ata_bmdma_freeze,
327 .thaw = ata_bmdma_thaw,
328 .error_handler = pdc2026x_error_handler,
329 .post_internal_cmd = ata_bmdma_post_internal_cmd,
331 .bmdma_setup = ata_bmdma_setup,
332 .bmdma_start = pdc2026x_bmdma_start,
333 .bmdma_stop = pdc2026x_bmdma_stop,
334 .bmdma_status = ata_bmdma_status,
336 .qc_prep = ata_qc_prep,
337 .qc_issue = ata_qc_issue_prot,
338 .data_xfer = ata_data_xfer,
340 .irq_handler = ata_interrupt,
341 .irq_clear = ata_bmdma_irq_clear,
342 .irq_on = ata_irq_on,
343 .irq_ack = ata_irq_ack,
345 .port_start = ata_port_start,
348 static int pdc202xx_init_one(struct pci_dev *dev, const struct pci_device_id *id)
350 static struct ata_port_info info[3] = {
352 .sht = &pdc202xx_sht,
353 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
354 .pio_mask = 0x1f,
355 .mwdma_mask = 0x07,
356 .udma_mask = ATA_UDMA2,
357 .port_ops = &pdc2024x_port_ops
360 .sht = &pdc202xx_sht,
361 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
362 .pio_mask = 0x1f,
363 .mwdma_mask = 0x07,
364 .udma_mask = ATA_UDMA4,
365 .port_ops = &pdc2026x_port_ops
368 .sht = &pdc202xx_sht,
369 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
370 .pio_mask = 0x1f,
371 .mwdma_mask = 0x07,
372 .udma_mask = ATA_UDMA5,
373 .port_ops = &pdc2026x_port_ops
377 static struct ata_port_info *port_info[2];
379 port_info[0] = port_info[1] = &info[id->driver_data];
381 if (dev->device == PCI_DEVICE_ID_PROMISE_20265) {
382 struct pci_dev *bridge = dev->bus->self;
383 /* Don't grab anything behind a Promise I2O RAID */
384 if (bridge && bridge->vendor == PCI_VENDOR_ID_INTEL) {
385 if( bridge->device == PCI_DEVICE_ID_INTEL_I960)
386 return -ENODEV;
387 if( bridge->device == PCI_DEVICE_ID_INTEL_I960RM)
388 return -ENODEV;
391 return ata_pci_init_one(dev, port_info, 2);
394 static const struct pci_device_id pdc202xx[] = {
395 { PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20246), 0 },
396 { PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20262), 1 },
397 { PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20263), 1 },
398 { PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20265), 2 },
399 { PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20267), 2 },
401 { },
404 static struct pci_driver pdc202xx_pci_driver = {
405 .name = DRV_NAME,
406 .id_table = pdc202xx,
407 .probe = pdc202xx_init_one,
408 .remove = ata_pci_remove_one,
409 #ifdef CONFIG_PM
410 .suspend = ata_pci_device_suspend,
411 .resume = ata_pci_device_resume,
412 #endif
415 static int __init pdc202xx_init(void)
417 return pci_register_driver(&pdc202xx_pci_driver);
420 static void __exit pdc202xx_exit(void)
422 pci_unregister_driver(&pdc202xx_pci_driver);
425 MODULE_AUTHOR("Alan Cox");
426 MODULE_DESCRIPTION("low-level driver for Promise 2024x and 20262-20267");
427 MODULE_LICENSE("GPL");
428 MODULE_DEVICE_TABLE(pci, pdc202xx);
429 MODULE_VERSION(DRV_VERSION);
431 module_init(pdc202xx_init);
432 module_exit(pdc202xx_exit);