pata_marvell.c 4.24 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 22
 */

#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 <linux/device.h>
#include <scsi/scsi_host.h>
#include <linux/libata.h>
#include <linux/ata.h>

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

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

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

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

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

47 48
	printk("BAR5:");
	for(i = 0; i <= 0x0F; i++)
49
		printk("%02X:%02X ", i, ioread8(barp + i));
50
	printk("\n");
51

52
	devices = ioread32(barp + 0x0C);
53
	pci_iounmap(pdev, barp);
54

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

/**
61
 *	marvell_pre_reset	-	probe begin
62 63 64 65 66 67 68 69 70 71 72 73 74 75
 *	@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;
76

Tejun Heo's avatar
Tejun Heo committed
77
	return ata_sff_prereset(link, deadline);
78
}
79

80 81
static int marvell_cable_detect(struct ata_port *ap)
{
82 83 84
	/* Cable type */
	switch(ap->port_no)
	{
85
	case 0:
Tejun Heo's avatar
Tejun Heo committed
86
		if (ioread8(ap->ioaddr.bmdma_addr + 1) & 1)
87 88
			return ATA_CBL_PATA40;
		return ATA_CBL_PATA80;
89
	case 1: /* Legacy SATA port */
90
		return ATA_CBL_SATA;
91
	}
92

93 94
	BUG();
	return 0;	/* Our BUG macro needs the right markup */
95 96 97 98 99
}

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

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

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


/**
 *	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)
{
126
	static const struct ata_port_info info = {
127
		.flags		= ATA_FLAG_SLAVE_POSS,
128

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

		.port_ops	= &marvell_ops,
	};
135
	static const struct ata_port_info info_sata = {
136
		/* Slave possible as its magically mapped not real */
137
		.flags		= ATA_FLAG_SLAVE_POSS,
138

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

		.port_ops	= &marvell_ops,
	};
145
	const struct ata_port_info *ppi[] = { &info, &info_sata };
146

147
	if (pdev->device == 0x6101)
148
		ppi[1] = &ata_dummy_port_info;
149

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

static const struct pci_device_id marvell_pci_tbl[] = {
	{ PCI_DEVICE(0x11AB, 0x6101), },
161 162
	{ PCI_DEVICE(0x11AB, 0x6121), },
	{ PCI_DEVICE(0x11AB, 0x6123), },
163
	{ PCI_DEVICE(0x11AB, 0x6145), },
164 165 166
	{ PCI_DEVICE(0x1B4B, 0x91A0), },
	{ PCI_DEVICE(0x1B4B, 0x91A4), },

167 168 169 170 171 172 173 174
	{ }	/* 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,
175
#ifdef CONFIG_PM
176 177
	.suspend		= ata_pci_device_suspend,
	.resume			= ata_pci_device_resume,
178
#endif
179 180
};

Axel Lin's avatar
Axel Lin committed
181
module_pci_driver(marvell_pci_driver);
182 183 184 185 186 187

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);