/* * pata_artop.c - ARTOP ATA controller driver * * (C) 2006 Red Hat * (C) 2007,2011 Bartlomiej Zolnierkiewicz * * Based in part on drivers/ide/pci/aec62xx.c * Copyright (C) 1999-2002 Andre Hedrick * 865/865R fixes for Macintosh card version from a patch to the old * driver by Thibaut VARENE * When setting the PCI latency we must set 0x80 or higher for burst * performance Alessandro Zummo * * TODO * Investigate no_dsc on 850R * Clock detect */ #include #include #include #include #include #include #include #include #include #define DRV_NAME "pata_artop" #define DRV_VERSION "0.4.6" /* * The ARTOP has 33 Mhz and "over clocked" timing tables. Until we * get PCI bus speed functionality we leave this as 0. Its a variable * for when we get the functionality and also for folks wanting to * test stuff. */ static int clock = 0; /** * artop62x0_pre_reset - probe begin * @link: link * @deadline: deadline jiffies for the operation * * Nothing complicated needed here. */ static int artop62x0_pre_reset(struct ata_link *link, unsigned long deadline) { static const struct pci_bits artop_enable_bits[] = { { 0x4AU, 1U, 0x02UL, 0x02UL }, /* port 0 */ { 0x4AU, 1U, 0x04UL, 0x04UL }, /* port 1 */ }; struct ata_port *ap = link->ap; struct pci_dev *pdev = to_pci_dev(ap->host->dev); /* Odd numbered device ids are the units with enable bits. */ if ((pdev->device & 1) && !pci_test_config_bits(pdev, &artop_enable_bits[ap->port_no])) return -ENOENT; return ata_sff_prereset(link, deadline); } /** * artop6260_cable_detect - identify cable type * @ap: Port * * Identify the cable type for the ARTOP interface in question */ static int artop6260_cable_detect(struct ata_port *ap) { struct pci_dev *pdev = to_pci_dev(ap->host->dev); u8 tmp; pci_read_config_byte(pdev, 0x49, &tmp); if (tmp & (1 << ap->port_no)) return ATA_CBL_PATA40; return ATA_CBL_PATA80; } /** * artop6210_load_piomode - Load a set of PATA PIO timings * @ap: Port whose timings we are configuring * @adev: Device * @pio: PIO mode * * Set PIO mode for device, in host controller PCI config space. This * is used both to set PIO timings in PIO mode and also to set the * matching PIO clocking for UDMA, as well as the MWDMA timings. * * LOCKING: * None (inherited from caller). */ static void artop6210_load_piomode(struct ata_port *ap, struct ata_device *adev, unsigned int pio) { struct pci_dev *pdev = to_pci_dev(ap->host->dev); int dn = adev->devno + 2 * ap->port_no; const u16 timing[2][5] = { { 0x0000, 0x000A, 0x0008, 0x0303, 0x0301 }, { 0x0700, 0x070A, 0x0708, 0x0403, 0x0401 } }; /* Load the PIO timing active/recovery bits */ pci_write_config_word(pdev, 0x40 + 2 * dn, timing[clock][pio]); } /** * artop6210_set_piomode - Initialize host controller PATA PIO timings * @ap: Port whose timings we are configuring * @adev: Device we are configuring * * Set PIO mode for device, in host controller PCI config space. For * ARTOP we must also clear the UDMA bits if we are not doing UDMA. In * the event UDMA is used the later call to set_dmamode will set the * bits as required. * * LOCKING: * None (inherited from caller). */ static void artop6210_set_piomode(struct ata_port *ap, struct ata_device *adev) { struct pci_dev *pdev = to_pci_dev(ap->host->dev); int dn = adev->devno + 2 * ap->port_no; u8 ultra; artop6210_load_piomode(ap, adev, adev->pio_mode - XFER_PIO_0); /* Clear the UDMA mode bits (set_dmamode will redo this if needed) */ pci_read_config_byte(pdev, 0x54, &ultra); ultra &= ~(3 << (2 * dn)); pci_write_config_byte(pdev, 0x54, ultra); } /** * artop6260_load_piomode - Initialize host controller PATA PIO timings * @ap: Port whose timings we are configuring * @adev: Device we are configuring * @pio: PIO mode * * Set PIO mode for device, in host controller PCI config space. The * ARTOP6260 and relatives store the timing data differently. * * LOCKING: * None (inherited from caller). */ static void artop6260_load_piomode (struct ata_port *ap, struct ata_device *adev, unsigned int pio) { struct pci_dev *pdev = to_pci_dev(ap->host->dev); int dn = adev->devno + 2 * ap->port_no; const u8 timing[2][5] = { { 0x00, 0x0A, 0x08, 0x33, 0x31 }, { 0x70, 0x7A, 0x78, 0x43, 0x41 } }; /* Load the PIO timing active/recovery bits */ pci_write_config_byte(pdev, 0x40 + dn, timing[clock][pio]); } /** * artop6260_set_piomode - Initialize host controller PATA PIO timings * @ap: Port whose timings we are configuring * @adev: Device we are configuring * * Set PIO mode for device, in host controller PCI config space. For * ARTOP we must also clear the UDMA bits if we are not doing UDMA. In * the event UDMA is used the later call to set_dmamode will set the * bits as required. * * LOCKING: * None (inherited from caller). */ static void artop6260_set_piomode(struct ata_port *ap, struct ata_device *adev) { struct pci_dev *pdev = to_pci_dev(ap->host->dev); u8 ultra; artop6260_load_piomode(ap, adev, adev->pio_mode - XFER_PIO_0); /* Clear the UDMA mode bits (set_dmamode will redo this if needed) */ pci_read_config_byte(pdev, 0x44 + ap->port_no, &ultra); ultra &= ~(7 << (4 * adev->devno)); /* One nibble per drive */ pci_write_config_byte(pdev, 0x44 + ap->port_no, ultra); } /** * artop6210_set_dmamode - Initialize host controller PATA PIO timings * @ap: Port whose timings we ar