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