ata_generic.c 8.24 KB
Newer Older
1 2
/*
 *  ata_generic.c - Generic PATA/SATA controller driver.
3
 *  Copyright 2005 Red Hat Inc, all rights reserved.
4
 *
5
 *  Elements from ide/pci/generic.c
6 7 8 9
 *	    Copyright (C) 2001-2002	Andre Hedrick <andre@linux-ide.org>
 *	    Portions (C) Copyright 2002  Red Hat Inc <alan@redhat.com>
 *
 *  May be copied or modified under the terms of the GNU General Public License
10
 *
11 12 13 14 15
 *  Driver for PCI IDE interfaces implementing the standard bus mastering
 *  interface functionality. This assumes the BIOS did the drive set up and
 *  tuning for us. By default we do not grab all IDE class devices as they
 *  may have other drivers or need fixups to avoid problems. Instead we keep
 *  a default list of stuff without documentation/driver that appears to
16
 *  work.
17 18 19 20 21 22 23 24 25 26 27 28
 */

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/pci.h>
#include <linux/init.h>
#include <linux/blkdev.h>
#include <linux/delay.h>
#include <scsi/scsi_host.h>
#include <linux/libata.h>

#define DRV_NAME "ata_generic"
Alan Cox's avatar
Alan Cox committed
29
#define DRV_VERSION "0.2.15"
30 31 32 33 34

/*
 *	A generic parallel ATA driver using libata
 */

35 36 37
enum {
	ATA_GEN_CLASS_MATCH		= (1 << 0),
	ATA_GEN_FORCE_DMA		= (1 << 1),
Alan Cox's avatar
Alan Cox committed
38
	ATA_GEN_INTEL_IDER		= (1 << 2),
39 40
};

41 42
/**
 *	generic_set_mode	-	mode setting
43
 *	@link: link to set up
Alan's avatar
Alan committed
44
 *	@unused: returned device on error
45 46 47 48
 *
 *	Use a non standard set_mode function. We don't want to be tuned.
 *	The BIOS configured everything. Our job is not to fiddle. We
 *	read the dma enabled bits from the PCI configuration of the device
49
 *	and respect them.
50
 */
51

52
static int generic_set_mode(struct ata_link *link, struct ata_device **unused)
53
{
54
	struct ata_port *ap = link->ap;
55
	const struct pci_device_id *id = ap->host->private_data;
56
	int dma_enabled = 0;
57
	struct ata_device *dev;
58

59 60 61 62
	if (id->driver_data & ATA_GEN_FORCE_DMA) {
		dma_enabled = 0xff;
	} else if (ap->ioaddr.bmdma_addr) {
		/* Bits 5 and 6 indicate if DMA is active on master/slave */
63
		dma_enabled = ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_STATUS);
64
	}
65

Tejun Heo's avatar
Tejun Heo committed
66
	ata_for_each_dev(dev, link, ENABLED) {
67 68 69 70 71 72
		/* We don't really care */
		dev->pio_mode = XFER_PIO_0;
		dev->dma_mode = XFER_MW_DMA_0;
		/* We do need the right mode information for DMA or PIO
		   and this comes from the current configuration flags */
		if (dma_enabled & (1 << (5 + dev->devno))) {
73 74 75 76 77 78 79 80 81 82 83
			unsigned int xfer_mask = ata_id_xfermask(dev->id);
			const char *name;

			if (xfer_mask & (ATA_MASK_MWDMA | ATA_MASK_UDMA))
				name = ata_mode_string(xfer_mask);
			else {
				/* SWDMA perhaps? */
				name = "DMA";
				xfer_mask |= ata_xfer_mode2mask(XFER_MW_DMA_0);
			}

84
			ata_dev_info(dev, "configured for %s\n", name);
85 86 87

			dev->xfer_mode = ata_xfer_mask2mode(xfer_mask);
			dev->xfer_shift = ata_xfer_mode2shift(dev->xfer_mode);
88 89
			dev->flags &= ~ATA_DFLAG_PIO;
		} else {
90
			ata_dev_info(dev, "configured for PIO\n");
91 92 93
			dev->xfer_mode = XFER_PIO_0;
			dev->xfer_shift = ATA_SHIFT_PIO;
			dev->flags |= ATA_DFLAG_PIO;
94 95
		}
	}
Alan's avatar
Alan committed
96
	return 0;
97 98 99
}

static struct scsi_host_template generic_sht = {
100
	ATA_BMDMA_SHT(DRV_NAME),
101 102 103
};

static struct ata_port_operations generic_port_ops = {
104
	.inherits	= &ata_bmdma_port_ops,
Alan Cox's avatar
Alan Cox committed
105
	.cable_detect	= ata_cable_unknown,
106
	.set_mode	= generic_set_mode,
107 108
};

109 110
static int all_generic_ide;		/* Set to claim all devices */

Alan Cox's avatar
Alan Cox committed
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
/**
 *	is_intel_ider		-	identify intel IDE-R devices
 *	@dev: PCI device
 *
 *	Distinguish Intel IDE-R controller devices from other Intel IDE
 *	devices. IDE-R devices have no timing registers and are in
 *	most respects virtual. They should be driven by the ata_generic
 *	driver.
 *
 *	IDE-R devices have PCI offset 0xF8.L as zero, later Intel ATA has
 *	it non zero. All Intel ATA has 0x40 writable (timing), but it is
 *	not writable on IDE-R devices (this is guaranteed).
 */

static int is_intel_ider(struct pci_dev *dev)
{
	/* For Intel IDE the value at 0xF8 is only zero on IDE-R
	   interfaces */
	u32 r;
	u16 t;

	/* Check the manufacturing ID, it will be zero for IDE-R */
	pci_read_config_dword(dev, 0xF8, &r);
	/* Not IDE-R: punt so that ata_(old)piix gets it */
	if (r != 0)
		return 0;
	/* 0xF8 will also be zero on some early Intel IDE devices
	   but they will have a sane timing register */
	pci_read_config_word(dev, 0x40, &t);
	if (t != 0)
		return 0;
	/* Finally check if the timing register is writable so that
	   we eliminate any early devices hot-docked in a docking
	   station */
	pci_write_config_word(dev, 0x40, 1);
	pci_read_config_word(dev, 0x40, &t);
	if (t) {
		pci_write_config_word(dev, 0x40, 0);
		return 0;
	}
	return 1;
}

154 155 156 157 158 159
/**
 *	ata_generic_init		-	attach generic IDE
 *	@dev: PCI device found
 *	@id: match entry
 *
 *	Called each time a matching IDE interface is found. We check if the
160
 *	interface is one we wish to claim and if so we perform any chip
161 162
 *	specific hacks then let the ATA layer do the heavy lifting.
 */
163

164 165 166
static int ata_generic_init_one(struct pci_dev *dev, const struct pci_device_id *id)
{
	u16 command;
167
	static const struct ata_port_info info = {
168
		.flags = ATA_FLAG_SLAVE_POSS,
169 170
		.pio_mask = ATA_PIO4,
		.mwdma_mask = ATA_MWDMA2,
171
		.udma_mask = ATA_UDMA5,
172 173
		.port_ops = &generic_port_ops
	};
174
	const struct ata_port_info *ppi[] = { &info, NULL };
175

176
	/* Don't use the generic entry unless instructed to do so */
177
	if ((id->driver_data & ATA_GEN_CLASS_MATCH) && all_generic_ide == 0)
178 179
		return -ENODEV;

180
	if ((id->driver_data & ATA_GEN_INTEL_IDER) && !all_generic_ide)
Alan Cox's avatar
Alan Cox committed
181 182 183
		if (!is_intel_ider(dev))
			return -ENODEV;

184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
	/* Devices that need care */
	if (dev->vendor == PCI_VENDOR_ID_UMC &&
	    dev->device == PCI_DEVICE_ID_UMC_UM8886A &&
	    (!(PCI_FUNC(dev->devfn) & 1)))
		return -ENODEV;

	if (dev->vendor == PCI_VENDOR_ID_OPTI &&
	    dev->device == PCI_DEVICE_ID_OPTI_82C558 &&
	    (!(PCI_FUNC(dev->devfn) & 1)))
		return -ENODEV;

	/* Don't re-enable devices in generic mode or we will break some
	   motherboards with disabled and unused IDE controllers */
	pci_read_config_word(dev, PCI_COMMAND, &command);
	if (!(command & PCI_COMMAND_IO))
		return -ENODEV;
200

201
	if (dev->vendor == PCI_VENDOR_ID_AL)
Tejun Heo's avatar
Tejun Heo committed
202
		ata_pci_bmdma_clear_simplex(dev);
203

Alan Cox's avatar
Alan Cox committed
204 205 206 207 208 209
	if (dev->vendor == PCI_VENDOR_ID_ATI) {
		int rc = pcim_enable_device(dev);
		if (rc < 0)
			return rc;
		pcim_pin_device(dev);
	}
210
	return ata_pci_bmdma_init_one(dev, ppi, &generic_sht, (void *)id, 0);
211 212 213 214 215
}

static struct pci_device_id ata_generic[] = {
	{ PCI_DEVICE(PCI_VENDOR_ID_PCTECH, PCI_DEVICE_ID_PCTECH_SAMURAI_IDE), },
	{ PCI_DEVICE(PCI_VENDOR_ID_HOLTEK, PCI_DEVICE_ID_HOLTEK_6565), },
216
	{ PCI_DEVICE(PCI_VENDOR_ID_UMC,    PCI_DEVICE_ID_UMC_UM8673F), },
217 218 219 220 221
	{ PCI_DEVICE(PCI_VENDOR_ID_UMC,    PCI_DEVICE_ID_UMC_UM8886A), },
	{ PCI_DEVICE(PCI_VENDOR_ID_UMC,    PCI_DEVICE_ID_UMC_UM8886BF), },
	{ PCI_DEVICE(PCI_VENDOR_ID_HINT,   PCI_DEVICE_ID_HINT_VXPROII_IDE), },
	{ PCI_DEVICE(PCI_VENDOR_ID_VIA,    PCI_DEVICE_ID_VIA_82C561), },
	{ PCI_DEVICE(PCI_VENDOR_ID_OPTI,   PCI_DEVICE_ID_OPTI_82C558), },
222 223
	{ PCI_DEVICE(PCI_VENDOR_ID_CENATEK,PCI_DEVICE_ID_CENATEK_IDE),
	  .driver_data = ATA_GEN_FORCE_DMA },
224 225 226 227 228
	/*
	 * For some reason, MCP89 on MacBook 7,1 doesn't work with
	 * ahci, use ata_generic instead.
	 */
	{ PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP89_SATA,
229 230
	  PCI_VENDOR_ID_APPLE, 0xcb89,
	  .driver_data = ATA_GEN_FORCE_DMA },
231
#if !defined(CONFIG_PATA_TOSHIBA) && !defined(CONFIG_PATA_TOSHIBA_MODULE)
232 233
	{ PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_1), },
	{ PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_2),  },
234 235
	{ PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_3),  },
	{ PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_5),  },
Alan Cox's avatar
Alan Cox committed
236 237 238
#endif
	/* Intel, IDE class device */
	{ PCI_VENDOR_ID_INTEL, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
239
	  PCI_CLASS_STORAGE_IDE << 8, 0xFFFFFF00UL,
Alan Cox's avatar
Alan Cox committed
240
	  .driver_data = ATA_GEN_INTEL_IDER },
241
	/* Must come last. If you add entries adjust this table appropriately */
242 243
	{ PCI_DEVICE_CLASS(PCI_CLASS_STORAGE_IDE << 8, 0xFFFFFF00UL),
	  .driver_data = ATA_GEN_CLASS_MATCH },
244 245 246 247 248 249 250
	{ 0, },
};

static struct pci_driver ata_generic_pci_driver = {
	.name 		= DRV_NAME,
	.id_table	= ata_generic,
	.probe 		= ata_generic_init_one,
251
	.remove		= ata_pci_remove_one,
252
#ifdef CONFIG_PM
253 254
	.suspend	= ata_pci_device_suspend,
	.resume		= ata_pci_device_resume,
255
#endif
256 257
};

Axel Lin's avatar
Axel Lin committed
258
module_pci_driver(ata_generic_pci_driver);
259 260 261 262 263 264 265 266

MODULE_AUTHOR("Alan Cox");
MODULE_DESCRIPTION("low-level driver for generic ATA");
MODULE_LICENSE("GPL");
MODULE_DEVICE_TABLE(pci, ata_generic);
MODULE_VERSION(DRV_VERSION);

module_param(all_generic_ide, int, 0);