162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci *  pata_piccolo.c - Toshiba Piccolo PATA/SATA controller driver.
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci *  This is basically an update to ata_generic.c to add Toshiba Piccolo support
562306a36Sopenharmony_ci *  then split out to keep ata_generic "clean".
662306a36Sopenharmony_ci *
762306a36Sopenharmony_ci *  Copyright 2005 Red Hat Inc, all rights reserved.
862306a36Sopenharmony_ci *
962306a36Sopenharmony_ci *  Elements from ide/pci/generic.c
1062306a36Sopenharmony_ci *	    Copyright (C) 2001-2002	Andre Hedrick <andre@linux-ide.org>
1162306a36Sopenharmony_ci *	    Portions (C) Copyright 2002  Red Hat Inc <alan@redhat.com>
1262306a36Sopenharmony_ci *
1362306a36Sopenharmony_ci *  May be copied or modified under the terms of the GNU General Public License
1462306a36Sopenharmony_ci *
1562306a36Sopenharmony_ci *  The timing data tables/programming info are courtesy of the NetBSD driver
1662306a36Sopenharmony_ci */
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ci#include <linux/kernel.h>
1962306a36Sopenharmony_ci#include <linux/module.h>
2062306a36Sopenharmony_ci#include <linux/pci.h>
2162306a36Sopenharmony_ci#include <linux/blkdev.h>
2262306a36Sopenharmony_ci#include <linux/delay.h>
2362306a36Sopenharmony_ci#include <scsi/scsi_host.h>
2462306a36Sopenharmony_ci#include <linux/libata.h>
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ci#define DRV_NAME "pata_piccolo"
2762306a36Sopenharmony_ci#define DRV_VERSION "0.0.1"
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_ci
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_cistatic void tosh_set_piomode(struct ata_port *ap, struct ata_device *adev)
3262306a36Sopenharmony_ci{
3362306a36Sopenharmony_ci	static const u16 pio[6] = {	/* For reg 0x50 low word & E088 */
3462306a36Sopenharmony_ci		0x0566, 0x0433, 0x0311, 0x0201, 0x0200, 0x0100
3562306a36Sopenharmony_ci	};
3662306a36Sopenharmony_ci	struct pci_dev *pdev = to_pci_dev(ap->host->dev);
3762306a36Sopenharmony_ci	u16 conf;
3862306a36Sopenharmony_ci	pci_read_config_word(pdev, 0x50, &conf);
3962306a36Sopenharmony_ci	conf &= 0xE088;
4062306a36Sopenharmony_ci	conf |= pio[adev->pio_mode - XFER_PIO_0];
4162306a36Sopenharmony_ci	pci_write_config_word(pdev, 0x50, conf);
4262306a36Sopenharmony_ci}
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_cistatic void tosh_set_dmamode(struct ata_port *ap, struct ata_device *adev)
4562306a36Sopenharmony_ci{
4662306a36Sopenharmony_ci	struct pci_dev *pdev = to_pci_dev(ap->host->dev);
4762306a36Sopenharmony_ci	u32 conf;
4862306a36Sopenharmony_ci	pci_read_config_dword(pdev, 0x5C, &conf);
4962306a36Sopenharmony_ci	conf &= 0x78FFE088;	/* Keep the other bits */
5062306a36Sopenharmony_ci	if (adev->dma_mode >= XFER_UDMA_0) {
5162306a36Sopenharmony_ci		int udma = adev->dma_mode - XFER_UDMA_0;
5262306a36Sopenharmony_ci		conf |= 0x80000000;
5362306a36Sopenharmony_ci		conf |= (udma + 2) << 28;
5462306a36Sopenharmony_ci		conf |= (2 - udma) * 0x111;	/* spread into three nibbles */
5562306a36Sopenharmony_ci	} else {
5662306a36Sopenharmony_ci		static const u32 mwdma[4] = {
5762306a36Sopenharmony_ci			0x0655, 0x0200, 0x0200, 0x0100
5862306a36Sopenharmony_ci		};
5962306a36Sopenharmony_ci		conf |= mwdma[adev->dma_mode - XFER_MW_DMA_0];
6062306a36Sopenharmony_ci	}
6162306a36Sopenharmony_ci	pci_write_config_dword(pdev, 0x5C, conf);
6262306a36Sopenharmony_ci}
6362306a36Sopenharmony_ci
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_cistatic const struct scsi_host_template tosh_sht = {
6662306a36Sopenharmony_ci	ATA_BMDMA_SHT(DRV_NAME),
6762306a36Sopenharmony_ci};
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_cistatic struct ata_port_operations tosh_port_ops = {
7062306a36Sopenharmony_ci	.inherits	= &ata_bmdma_port_ops,
7162306a36Sopenharmony_ci	.cable_detect	= ata_cable_unknown,
7262306a36Sopenharmony_ci	.set_piomode	= tosh_set_piomode,
7362306a36Sopenharmony_ci	.set_dmamode	= tosh_set_dmamode
7462306a36Sopenharmony_ci};
7562306a36Sopenharmony_ci
7662306a36Sopenharmony_ci/**
7762306a36Sopenharmony_ci *	ata_tosh_init_one		-	attach generic IDE
7862306a36Sopenharmony_ci *	@dev: PCI device found
7962306a36Sopenharmony_ci *	@id: match entry
8062306a36Sopenharmony_ci *
8162306a36Sopenharmony_ci *	Called each time a matching IDE interface is found. We check if the
8262306a36Sopenharmony_ci *	interface is one we wish to claim and if so we perform any chip
8362306a36Sopenharmony_ci *	specific hacks then let the ATA layer do the heavy lifting.
8462306a36Sopenharmony_ci */
8562306a36Sopenharmony_ci
8662306a36Sopenharmony_cistatic int ata_tosh_init_one(struct pci_dev *dev, const struct pci_device_id *id)
8762306a36Sopenharmony_ci{
8862306a36Sopenharmony_ci	static const struct ata_port_info info = {
8962306a36Sopenharmony_ci		.flags = ATA_FLAG_SLAVE_POSS,
9062306a36Sopenharmony_ci		.pio_mask = ATA_PIO5,
9162306a36Sopenharmony_ci		.mwdma_mask = ATA_MWDMA2,
9262306a36Sopenharmony_ci		.udma_mask = ATA_UDMA2,
9362306a36Sopenharmony_ci		.port_ops = &tosh_port_ops
9462306a36Sopenharmony_ci	};
9562306a36Sopenharmony_ci	const struct ata_port_info *ppi[] = { &info, &ata_dummy_port_info };
9662306a36Sopenharmony_ci	/* Just one port for the moment */
9762306a36Sopenharmony_ci	return ata_pci_bmdma_init_one(dev, ppi, &tosh_sht, NULL, 0);
9862306a36Sopenharmony_ci}
9962306a36Sopenharmony_ci
10062306a36Sopenharmony_cistatic struct pci_device_id ata_tosh[] = {
10162306a36Sopenharmony_ci	{ PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_1), },
10262306a36Sopenharmony_ci	{ PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_2),  },
10362306a36Sopenharmony_ci	{ PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_3),  },
10462306a36Sopenharmony_ci	{ PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_5),  },
10562306a36Sopenharmony_ci	{ 0, },
10662306a36Sopenharmony_ci};
10762306a36Sopenharmony_ci
10862306a36Sopenharmony_cistatic struct pci_driver ata_tosh_pci_driver = {
10962306a36Sopenharmony_ci	.name 		= DRV_NAME,
11062306a36Sopenharmony_ci	.id_table	= ata_tosh,
11162306a36Sopenharmony_ci	.probe 		= ata_tosh_init_one,
11262306a36Sopenharmony_ci	.remove		= ata_pci_remove_one,
11362306a36Sopenharmony_ci#ifdef CONFIG_PM_SLEEP
11462306a36Sopenharmony_ci	.suspend	= ata_pci_device_suspend,
11562306a36Sopenharmony_ci	.resume		= ata_pci_device_resume,
11662306a36Sopenharmony_ci#endif
11762306a36Sopenharmony_ci};
11862306a36Sopenharmony_ci
11962306a36Sopenharmony_cimodule_pci_driver(ata_tosh_pci_driver);
12062306a36Sopenharmony_ci
12162306a36Sopenharmony_ciMODULE_AUTHOR("Alan Cox");
12262306a36Sopenharmony_ciMODULE_DESCRIPTION("Low level driver for Toshiba Piccolo ATA");
12362306a36Sopenharmony_ciMODULE_LICENSE("GPL");
12462306a36Sopenharmony_ciMODULE_DEVICE_TABLE(pci, ata_tosh);
12562306a36Sopenharmony_ciMODULE_VERSION(DRV_VERSION);
126