xref: /openbmc/linux/drivers/ata/pata_piccolo.c (revision 1ac731c529cd4d6adbce134754b51ff7d822b145)
18e182a90SAlan Cox /*
28e182a90SAlan Cox  *  pata_piccolo.c - Toshiba Piccolo PATA/SATA controller driver.
38e182a90SAlan Cox  *
48e182a90SAlan Cox  *  This is basically an update to ata_generic.c to add Toshiba Piccolo support
58e182a90SAlan Cox  *  then split out to keep ata_generic "clean".
68e182a90SAlan Cox  *
78e182a90SAlan Cox  *  Copyright 2005 Red Hat Inc, all rights reserved.
88e182a90SAlan Cox  *
98e182a90SAlan Cox  *  Elements from ide/pci/generic.c
108e182a90SAlan Cox  *	    Copyright (C) 2001-2002	Andre Hedrick <andre@linux-ide.org>
118e182a90SAlan Cox  *	    Portions (C) Copyright 2002  Red Hat Inc <alan@redhat.com>
128e182a90SAlan Cox  *
138e182a90SAlan Cox  *  May be copied or modified under the terms of the GNU General Public License
148e182a90SAlan Cox  *
158e182a90SAlan Cox  *  The timing data tables/programming info are courtesy of the NetBSD driver
168e182a90SAlan Cox  */
178e182a90SAlan Cox 
188e182a90SAlan Cox #include <linux/kernel.h>
198e182a90SAlan Cox #include <linux/module.h>
208e182a90SAlan Cox #include <linux/pci.h>
218e182a90SAlan Cox #include <linux/blkdev.h>
228e182a90SAlan Cox #include <linux/delay.h>
238e182a90SAlan Cox #include <scsi/scsi_host.h>
248e182a90SAlan Cox #include <linux/libata.h>
258e182a90SAlan Cox 
268e182a90SAlan Cox #define DRV_NAME "pata_piccolo"
278e182a90SAlan Cox #define DRV_VERSION "0.0.1"
288e182a90SAlan Cox 
298e182a90SAlan Cox 
308e182a90SAlan Cox 
tosh_set_piomode(struct ata_port * ap,struct ata_device * adev)318e182a90SAlan Cox static void tosh_set_piomode(struct ata_port *ap, struct ata_device *adev)
328e182a90SAlan Cox {
338e182a90SAlan Cox 	static const u16 pio[6] = {	/* For reg 0x50 low word & E088 */
348e182a90SAlan Cox 		0x0566, 0x0433, 0x0311, 0x0201, 0x0200, 0x0100
358e182a90SAlan Cox 	};
368e182a90SAlan Cox 	struct pci_dev *pdev = to_pci_dev(ap->host->dev);
378e182a90SAlan Cox 	u16 conf;
388e182a90SAlan Cox 	pci_read_config_word(pdev, 0x50, &conf);
398e182a90SAlan Cox 	conf &= 0xE088;
408e182a90SAlan Cox 	conf |= pio[adev->pio_mode - XFER_PIO_0];
418e182a90SAlan Cox 	pci_write_config_word(pdev, 0x50, conf);
428e182a90SAlan Cox }
438e182a90SAlan Cox 
tosh_set_dmamode(struct ata_port * ap,struct ata_device * adev)448e182a90SAlan Cox static void tosh_set_dmamode(struct ata_port *ap, struct ata_device *adev)
458e182a90SAlan Cox {
468e182a90SAlan Cox 	struct pci_dev *pdev = to_pci_dev(ap->host->dev);
478e182a90SAlan Cox 	u32 conf;
488e182a90SAlan Cox 	pci_read_config_dword(pdev, 0x5C, &conf);
498e182a90SAlan Cox 	conf &= 0x78FFE088;	/* Keep the other bits */
508e182a90SAlan Cox 	if (adev->dma_mode >= XFER_UDMA_0) {
518e182a90SAlan Cox 		int udma = adev->dma_mode - XFER_UDMA_0;
528e182a90SAlan Cox 		conf |= 0x80000000;
538e182a90SAlan Cox 		conf |= (udma + 2) << 28;
548e182a90SAlan Cox 		conf |= (2 - udma) * 0x111;	/* spread into three nibbles */
558e182a90SAlan Cox 	} else {
568e182a90SAlan Cox 		static const u32 mwdma[4] = {
578e182a90SAlan Cox 			0x0655, 0x0200, 0x0200, 0x0100
588e182a90SAlan Cox 		};
598e182a90SAlan Cox 		conf |= mwdma[adev->dma_mode - XFER_MW_DMA_0];
608e182a90SAlan Cox 	}
618e182a90SAlan Cox 	pci_write_config_dword(pdev, 0x5C, conf);
628e182a90SAlan Cox }
638e182a90SAlan Cox 
648e182a90SAlan Cox 
65*25df73d9SBart Van Assche static const struct scsi_host_template tosh_sht = {
668e182a90SAlan Cox 	ATA_BMDMA_SHT(DRV_NAME),
678e182a90SAlan Cox };
688e182a90SAlan Cox 
698e182a90SAlan Cox static struct ata_port_operations tosh_port_ops = {
708e182a90SAlan Cox 	.inherits	= &ata_bmdma_port_ops,
718e182a90SAlan Cox 	.cable_detect	= ata_cable_unknown,
728e182a90SAlan Cox 	.set_piomode	= tosh_set_piomode,
738e182a90SAlan Cox 	.set_dmamode	= tosh_set_dmamode
748e182a90SAlan Cox };
758e182a90SAlan Cox 
768e182a90SAlan Cox /**
7705f4226aSLee Jones  *	ata_tosh_init_one		-	attach generic IDE
788e182a90SAlan Cox  *	@dev: PCI device found
798e182a90SAlan Cox  *	@id: match entry
808e182a90SAlan Cox  *
818e182a90SAlan Cox  *	Called each time a matching IDE interface is found. We check if the
828e182a90SAlan Cox  *	interface is one we wish to claim and if so we perform any chip
838e182a90SAlan Cox  *	specific hacks then let the ATA layer do the heavy lifting.
848e182a90SAlan Cox  */
858e182a90SAlan Cox 
ata_tosh_init_one(struct pci_dev * dev,const struct pci_device_id * id)868e182a90SAlan Cox static int ata_tosh_init_one(struct pci_dev *dev, const struct pci_device_id *id)
878e182a90SAlan Cox {
888e182a90SAlan Cox 	static const struct ata_port_info info = {
898e182a90SAlan Cox 		.flags = ATA_FLAG_SLAVE_POSS,
908e182a90SAlan Cox 		.pio_mask = ATA_PIO5,
918e182a90SAlan Cox 		.mwdma_mask = ATA_MWDMA2,
928e182a90SAlan Cox 		.udma_mask = ATA_UDMA2,
938e182a90SAlan Cox 		.port_ops = &tosh_port_ops
948e182a90SAlan Cox 	};
958e182a90SAlan Cox 	const struct ata_port_info *ppi[] = { &info, &ata_dummy_port_info };
968e182a90SAlan Cox 	/* Just one port for the moment */
971c5afdf7STejun Heo 	return ata_pci_bmdma_init_one(dev, ppi, &tosh_sht, NULL, 0);
988e182a90SAlan Cox }
998e182a90SAlan Cox 
1008e182a90SAlan Cox static struct pci_device_id ata_tosh[] = {
1018e182a90SAlan Cox 	{ PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_1), },
1028e182a90SAlan Cox 	{ PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_2),  },
1038e182a90SAlan Cox 	{ PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_3),  },
1048e182a90SAlan Cox 	{ PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_5),  },
1058e182a90SAlan Cox 	{ 0, },
1068e182a90SAlan Cox };
1078e182a90SAlan Cox 
1088e182a90SAlan Cox static struct pci_driver ata_tosh_pci_driver = {
1098e182a90SAlan Cox 	.name 		= DRV_NAME,
1108e182a90SAlan Cox 	.id_table	= ata_tosh,
1118e182a90SAlan Cox 	.probe 		= ata_tosh_init_one,
1128e182a90SAlan Cox 	.remove		= ata_pci_remove_one,
11358eb8cd5SBartlomiej Zolnierkiewicz #ifdef CONFIG_PM_SLEEP
1148e182a90SAlan Cox 	.suspend	= ata_pci_device_suspend,
1158e182a90SAlan Cox 	.resume		= ata_pci_device_resume,
1168e182a90SAlan Cox #endif
1178e182a90SAlan Cox };
1188e182a90SAlan Cox 
1192fc75da0SAxel Lin module_pci_driver(ata_tosh_pci_driver);
1208e182a90SAlan Cox 
1218e182a90SAlan Cox MODULE_AUTHOR("Alan Cox");
1228e182a90SAlan Cox MODULE_DESCRIPTION("Low level driver for Toshiba Piccolo ATA");
1238e182a90SAlan Cox MODULE_LICENSE("GPL");
1248e182a90SAlan Cox MODULE_DEVICE_TABLE(pci, ata_tosh);
1258e182a90SAlan Cox MODULE_VERSION(DRV_VERSION);
126