pata_marvell.c 4.2 KB
Newer Older
1 2 3 4 5 6 7
/*
 *	Marvell PATA driver.
 *
 *	For the moment we drive the PATA port in legacy mode. That
 *	isn't making full use of the device functionality but it is
 *	easy to get working.
 *
8
 *	(c) 2006 Red Hat
9 10 11 12 13 14 15 16 17 18 19 20 21
 */

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

#define DRV_NAME	"pata_marvell"
22
#define DRV_VERSION	"0.1.6"
23 24

/**
25 26
 *	marvell_pata_active	-	check if PATA is active
 *	@pdev: PCI device
27
 *
28 29
 *	Returns 1 if the PATA port may be active. We know how to check this
 *	for the 6145 but not the other devices
30 31
 */

32
static int marvell_pata_active(struct pci_dev *pdev)
33
{
34
	int i;
35 36 37
	u32 devices;
	void __iomem *barp;

38 39
	/* We don't yet know how to do this for other devices */
	if (pdev->device != 0x6145)
40
		return 1;
41

42
	barp = pci_iomap(pdev, 5, 0x10);
43 44
	if (barp == NULL)
		return -ENOMEM;
45

46 47
	printk("BAR5:");
	for(i = 0; i <= 0x0F; i++)
48
		printk("%02X:%02X ", i, ioread8(barp + i));
49
	printk("\n");
J
Jeff Garzik 已提交
50

51
	devices = ioread32(barp + 0x0C);
52
	pci_iounmap(pdev, barp);
J
Jeff Garzik 已提交
53

54 55 56 57 58 59
	if (devices & 0x10)
		return 1;
	return 0;
}

/**
60
 *	marvell_pre_reset	-	probe begin
61 62 63 64 65 66 67 68 69 70 71 72 73 74
 *	@link: link
 *	@deadline: deadline jiffies for the operation
 *
 *	Perform the PATA port setup we need.
 */

static int marvell_pre_reset(struct ata_link *link, unsigned long deadline)
{
	struct ata_port *ap = link->ap;
	struct pci_dev *pdev = to_pci_dev(ap->host->dev);

	if (pdev->device == 0x6145 && ap->port_no == 0 &&
		!marvell_pata_active(pdev))	/* PATA enable ? */
			return -ENOENT;
75

T
Tejun Heo 已提交
76
	return ata_sff_prereset(link, deadline);
A
Alan Cox 已提交
77
}
78

A
Alan Cox 已提交
79 80
static int marvell_cable_detect(struct ata_port *ap)
{
81 82 83
	/* Cable type */
	switch(ap->port_no)
	{
84
	case 0:
T
Tejun Heo 已提交
85
		if (ioread8(ap->ioaddr.bmdma_addr + 1) & 1)
A
Alan Cox 已提交
86 87
			return ATA_CBL_PATA40;
		return ATA_CBL_PATA80;
88
	case 1: /* Legacy SATA port */
A
Alan Cox 已提交
89
		return ATA_CBL_SATA;
90
	}
91

A
Alan Cox 已提交
92 93
	BUG();
	return 0;	/* Our BUG macro needs the right markup */
94 95 96 97 98
}

/* No PIO or DMA methods needed for this device */

static struct scsi_host_template marvell_sht = {
99
	ATA_BMDMA_SHT(DRV_NAME),
100 101
};

102 103
static struct ata_port_operations marvell_ops = {
	.inherits		= &ata_bmdma_port_ops,
A
Alan Cox 已提交
104
	.cable_detect		= marvell_cable_detect,
105
	.prereset		= marvell_pre_reset,
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
};


/**
 *	marvell_init_one - Register Marvell ATA PCI device with kernel services
 *	@pdev: PCI device to register
 *	@ent: Entry in marvell_pci_tbl matching with @pdev
 *
 *	Called from kernel PCI layer.
 *
 *	LOCKING:
 *	Inherited from PCI layer (may sleep).
 *
 *	RETURNS:
 *	Zero on success, or -ERRNO value.
 */

static int marvell_init_one (struct pci_dev *pdev, const struct pci_device_id *id)
{
T
Tejun Heo 已提交
125
	static const struct ata_port_info info = {
126
		.flags		= ATA_FLAG_SLAVE_POSS,
127

128 129
		.pio_mask	= ATA_PIO4,
		.mwdma_mask	= ATA_MWDMA2,
130
		.udma_mask 	= ATA_UDMA5,
131 132 133

		.port_ops	= &marvell_ops,
	};
T
Tejun Heo 已提交
134
	static const struct ata_port_info info_sata = {
135
		/* Slave possible as its magically mapped not real */
136
		.flags		= ATA_FLAG_SLAVE_POSS,
137

138 139
		.pio_mask	= ATA_PIO4,
		.mwdma_mask	= ATA_MWDMA2,
140
		.udma_mask 	= ATA_UDMA6,
141 142 143

		.port_ops	= &marvell_ops,
	};
T
Tejun Heo 已提交
144
	const struct ata_port_info *ppi[] = { &info, &info_sata };
145

146
	if (pdev->device == 0x6101)
T
Tejun Heo 已提交
147
		ppi[1] = &ata_dummy_port_info;
148

149
#if defined(CONFIG_SATA_AHCI) || defined(CONFIG_SATA_AHCI_MODULE)
150 151 152 153 154
	if (!marvell_pata_active(pdev)) {
		printk(KERN_INFO DRV_NAME ": PATA port not active, deferring to AHCI driver.\n");
		return -ENODEV;
	}
#endif
T
Tejun Heo 已提交
155
	return ata_pci_bmdma_init_one(pdev, ppi, &marvell_sht, NULL, 0);
156 157 158 159
}

static const struct pci_device_id marvell_pci_tbl[] = {
	{ PCI_DEVICE(0x11AB, 0x6101), },
A
Alan Cox 已提交
160 161
	{ PCI_DEVICE(0x11AB, 0x6121), },
	{ PCI_DEVICE(0x11AB, 0x6123), },
162
	{ PCI_DEVICE(0x11AB, 0x6145), },
163 164 165
	{ PCI_DEVICE(0x1B4B, 0x91A0), },
	{ PCI_DEVICE(0x1B4B, 0x91A4), },

166 167 168 169 170 171 172 173
	{ }	/* terminate list */
};

static struct pci_driver marvell_pci_driver = {
	.name			= DRV_NAME,
	.id_table		= marvell_pci_tbl,
	.probe			= marvell_init_one,
	.remove			= ata_pci_remove_one,
174
#ifdef CONFIG_PM
175 176
	.suspend		= ata_pci_device_suspend,
	.resume			= ata_pci_device_resume,
177
#endif
178 179
};

A
Axel Lin 已提交
180
module_pci_driver(marvell_pci_driver);
181 182 183 184 185 186

MODULE_AUTHOR("Alan Cox");
MODULE_DESCRIPTION("SCSI low-level driver for Marvell ATA in legacy mode");
MODULE_LICENSE("GPL");
MODULE_DEVICE_TABLE(pci, marvell_pci_tbl);
MODULE_VERSION(DRV_VERSION);