[GITLAB] - UPGRADE TO v12 on Wednesday the 18th of December at 11.30AM

pata_ns87410.c 4.73 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
/*
 * pata_ns87410.c 	- National Semiconductor 87410 PATA for new ATA layer
 *			  (C) 2006 Red Hat Inc
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2, or (at your option)
 *  any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; see the file COPYING.  If not, write to
 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#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 "pata_ns87410"
30
#define DRV_VERSION "0.4.6"
31 32 33

/**
 *	ns87410_pre_reset		-	probe begin
Tejun Heo's avatar
Tejun Heo committed
34
 *	@link: ATA link
35
 *	@deadline: deadline jiffies for the operation
36
 *
37
 *	Check enabled ports
38 39
 */

Tejun Heo's avatar
Tejun Heo committed
40
static int ns87410_pre_reset(struct ata_link *link, unsigned long deadline)
41
{
Tejun Heo's avatar
Tejun Heo committed
42
	struct ata_port *ap = link->ap;
43 44 45 46 47 48
	struct pci_dev *pdev = to_pci_dev(ap->host->dev);
	static const struct pci_bits ns87410_enable_bits[] = {
		{ 0x43, 1, 0x08, 0x08 },
		{ 0x47, 1, 0x08, 0x08 }
	};

49 50
	if (!pci_test_config_bits(pdev, &ns87410_enable_bits[ap->port_no]))
		return -ENOENT;
51

Tejun Heo's avatar
Tejun Heo committed
52
	return ata_sff_prereset(link, deadline);
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
}

/**
 *	ns87410_set_piomode	-	set initial PIO mode data
 *	@ap: ATA interface
 *	@adev: ATA device
 *
 *	Program timing data. This is kept per channel not per device,
 *	and only affects the data port.
 */

static void ns87410_set_piomode(struct ata_port *ap, struct ata_device *adev)
{
	struct pci_dev *pdev = to_pci_dev(ap->host->dev);
	int port = 0x40 + 4 * ap->port_no;
	u8 idetcr, idefr;
	struct ata_timing at;

	static const u8 activebits[15] = {
		0, 1, 2, 3, 4,
		5, 5, 6, 6, 6,
		6, 7, 7, 7, 7
	};

	static const u8 recoverbits[12] = {
		0, 1, 2, 3, 4, 5, 6, 6, 7, 7, 7, 7
	};

	pci_read_config_byte(pdev, port + 3, &idefr);

	if (ata_pio_need_iordy(adev))
		idefr |= 0x04;	/* IORDY enable */
	else
		idefr &= ~0x04;

	if (ata_timing_compute(adev, adev->pio_mode, &at, 30303, 1) < 0) {
89
		dev_err(&pdev->dev, "unknown mode %d\n", adev->pio_mode);
90 91 92
		return;
	}

93 94 95
	at.active = clamp_val(at.active, 2, 16) - 2;
	at.setup = clamp_val(at.setup, 1, 4) - 1;
	at.recover = clamp_val(at.recover, 1, 12) - 1;
96 97 98 99 100 101 102 103 104 105 106

	idetcr = (at.setup << 6) | (recoverbits[at.recover] << 3) | activebits[at.active];

	pci_write_config_byte(pdev, port, idetcr);
	pci_write_config_byte(pdev, port + 3, idefr);
	/* We use ap->private_data as a pointer to the device currently
	   loaded for timing */
	ap->private_data = adev;
}

/**
Tejun Heo's avatar
Tejun Heo committed
107
 *	ns87410_qc_issue	-	command issue
108 109 110 111
 *	@qc: command pending
 *
 *	Called when the libata layer is about to issue a command. We wrap
 *	this interface so that we can load the correct ATA timings if
112
 *	necessary.
113 114
 */

Tejun Heo's avatar
Tejun Heo committed
115
static unsigned int ns87410_qc_issue(struct ata_queued_cmd *qc)
116 117 118 119 120 121 122 123 124 125 126 127
{
	struct ata_port *ap = qc->ap;
	struct ata_device *adev = qc->dev;

	/* If modes have been configured and the channel data is not loaded
	   then load it. We have to check if pio_mode is set as the core code
	   does not set adev->pio_mode to XFER_PIO_0 while probing as would be
	   logical */

	if (adev->pio_mode && adev != ap->private_data)
		ns87410_set_piomode(ap, adev);

Tejun Heo's avatar
Tejun Heo committed
128
	return ata_sff_qc_issue(qc);
129 130 131
}

static struct scsi_host_template ns87410_sht = {
132
	ATA_PIO_SHT(DRV_NAME),
133 134 135
};

static struct ata_port_operations ns87410_port_ops = {
136
	.inherits	= &ata_sff_port_ops,
Tejun Heo's avatar
Tejun Heo committed
137
	.qc_issue	= ns87410_qc_issue,
138
	.cable_detect	= ata_cable_40wire,
139
	.set_piomode	= ns87410_set_piomode,
140
	.prereset	= ns87410_pre_reset,
141 142 143 144
};

static int ns87410_init_one(struct pci_dev *dev, const struct pci_device_id *id)
{
145
	static const struct ata_port_info info = {
146
		.flags = ATA_FLAG_SLAVE_POSS,
147
		.pio_mask = ATA_PIO3,
148 149
		.port_ops = &ns87410_port_ops
	};
150
	const struct ata_port_info *ppi[] = { &info, NULL };
151
	return ata_pci_sff_init_one(dev, ppi, &ns87410_sht, NULL, 0);
152 153 154
}

static const struct pci_device_id ns87410[] = {
155 156 157
	{ PCI_VDEVICE(NS, PCI_DEVICE_ID_NS_87410), },

	{ },
158 159 160
};

static struct pci_driver ns87410_pci_driver = {
161
	.name 		= DRV_NAME,
162 163
	.id_table	= ns87410,
	.probe 		= ns87410_init_one,
164
	.remove		= ata_pci_remove_one,
165
#ifdef CONFIG_PM
166 167
	.suspend	= ata_pci_device_suspend,
	.resume		= ata_pci_device_resume,
168
#endif
169 170
};

Axel Lin's avatar
Axel Lin committed
171
module_pci_driver(ns87410_pci_driver);
172 173 174 175 176 177

MODULE_AUTHOR("Alan Cox");
MODULE_DESCRIPTION("low-level driver for Nat Semi 87410");
MODULE_LICENSE("GPL");
MODULE_DEVICE_TABLE(pci, ns87410);
MODULE_VERSION(DRV_VERSION);