^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * pata_piccolo.c - Toshiba Piccolo PATA/SATA controller driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * This is basically an update to ata_generic.c to add Toshiba Piccolo support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * then split out to keep ata_generic "clean".
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright 2005 Red Hat Inc, all rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Elements from ide/pci/generic.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Copyright (C) 2001-2002 Andre Hedrick <andre@linux-ide.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Portions (C) Copyright 2002 Red Hat Inc <alan@redhat.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * May be copied or modified under the terms of the GNU General Public License
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * The timing data tables/programming info are courtesy of the NetBSD driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/blkdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <scsi/scsi_host.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/libata.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define DRV_NAME "pata_piccolo"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define DRV_VERSION "0.0.1"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) static void tosh_set_piomode(struct ata_port *ap, struct ata_device *adev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) static const u16 pio[6] = { /* For reg 0x50 low word & E088 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) 0x0566, 0x0433, 0x0311, 0x0201, 0x0200, 0x0100
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) struct pci_dev *pdev = to_pci_dev(ap->host->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) u16 conf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) pci_read_config_word(pdev, 0x50, &conf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) conf &= 0xE088;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) conf |= pio[adev->pio_mode - XFER_PIO_0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) pci_write_config_word(pdev, 0x50, conf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) static void tosh_set_dmamode(struct ata_port *ap, struct ata_device *adev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) struct pci_dev *pdev = to_pci_dev(ap->host->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) u32 conf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) pci_read_config_dword(pdev, 0x5C, &conf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) conf &= 0x78FFE088; /* Keep the other bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) if (adev->dma_mode >= XFER_UDMA_0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) int udma = adev->dma_mode - XFER_UDMA_0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) conf |= 0x80000000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) conf |= (udma + 2) << 28;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) conf |= (2 - udma) * 0x111; /* spread into three nibbles */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) static const u32 mwdma[4] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) 0x0655, 0x0200, 0x0200, 0x0100
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) conf |= mwdma[adev->dma_mode - XFER_MW_DMA_0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) pci_write_config_dword(pdev, 0x5C, conf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) static struct scsi_host_template tosh_sht = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) ATA_BMDMA_SHT(DRV_NAME),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) static struct ata_port_operations tosh_port_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) .inherits = &ata_bmdma_port_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) .cable_detect = ata_cable_unknown,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) .set_piomode = tosh_set_piomode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) .set_dmamode = tosh_set_dmamode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * ata_tosh_init - attach generic IDE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * @dev: PCI device found
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * @id: match entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) * Called each time a matching IDE interface is found. We check if the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) * interface is one we wish to claim and if so we perform any chip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) * specific hacks then let the ATA layer do the heavy lifting.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) static int ata_tosh_init_one(struct pci_dev *dev, const struct pci_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) static const struct ata_port_info info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) .flags = ATA_FLAG_SLAVE_POSS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) .pio_mask = ATA_PIO5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) .mwdma_mask = ATA_MWDMA2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) .udma_mask = ATA_UDMA2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) .port_ops = &tosh_port_ops
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) const struct ata_port_info *ppi[] = { &info, &ata_dummy_port_info };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) /* Just one port for the moment */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) return ata_pci_bmdma_init_one(dev, ppi, &tosh_sht, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) static struct pci_device_id ata_tosh[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) { PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_1), },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) { PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_2), },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) { PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_3), },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) { PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_5), },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) { 0, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) static struct pci_driver ata_tosh_pci_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) .name = DRV_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) .id_table = ata_tosh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) .probe = ata_tosh_init_one,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) .remove = ata_pci_remove_one,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) #ifdef CONFIG_PM_SLEEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) .suspend = ata_pci_device_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) .resume = ata_pci_device_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) module_pci_driver(ata_tosh_pci_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) MODULE_AUTHOR("Alan Cox");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) MODULE_DESCRIPTION("Low level driver for Toshiba Piccolo ATA");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) MODULE_DEVICE_TABLE(pci, ata_tosh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) MODULE_VERSION(DRV_VERSION);