]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/ata/pata_ns87410.c
[libata] Add a bunch of PATA drivers.
[mirror_ubuntu-bionic-kernel.git] / drivers / ata / pata_ns87410.c
CommitLineData
669a5db4
JG
1/*
2 * pata_ns87410.c - National Semiconductor 87410 PATA for new ATA layer
3 * (C) 2006 Red Hat Inc
4 * Alan Cox <alan@redhat.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; see the file COPYING. If not, write to
18 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21#include <linux/kernel.h>
22#include <linux/module.h>
23#include <linux/pci.h>
24#include <linux/init.h>
25#include <linux/blkdev.h>
26#include <linux/delay.h>
27#include <scsi/scsi_host.h>
28#include <linux/libata.h>
29
30#define DRV_NAME "pata_ns87410"
31#define DRV_VERSION "0.4.2"
32
33/**
34 * ns87410_pre_reset - probe begin
35 * @ap: ATA port
36 *
37 * Set up cable type and use generic probe init
38 */
39
40static int ns87410_pre_reset(struct ata_port *ap)
41{
42 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
43 static const struct pci_bits ns87410_enable_bits[] = {
44 { 0x43, 1, 0x08, 0x08 },
45 { 0x47, 1, 0x08, 0x08 }
46 };
47
48 if (!pci_test_config_bits(pdev, &ns87410_enable_bits[ap->port_no])) {
49 ata_port_disable(ap);
50 printk(KERN_INFO "ata%u: port disabled. ignoring.\n", ap->id);
51 return 0;
52 }
53 ap->cbl = ATA_CBL_PATA40;
54 return ata_std_prereset(ap);
55}
56
57/**
58 * ns87410_error_handler - probe reset
59 * @ap: ATA port
60 *
61 * Perform the ATA probe and bus reset sequence plus specific handling
62 * for this hardware. The MPIIX has the enable bits in a different place
63 * to PIIX4 and friends. As a pure PIO device it has no cable detect
64 */
65
66static void ns87410_error_handler(struct ata_port *ap)
67{
68 ata_bmdma_drive_eh(ap, ns87410_pre_reset, ata_std_softreset, NULL, ata_std_postreset);
69}
70
71/**
72 * ns87410_set_piomode - set initial PIO mode data
73 * @ap: ATA interface
74 * @adev: ATA device
75 *
76 * Program timing data. This is kept per channel not per device,
77 * and only affects the data port.
78 */
79
80static void ns87410_set_piomode(struct ata_port *ap, struct ata_device *adev)
81{
82 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
83 int port = 0x40 + 4 * ap->port_no;
84 u8 idetcr, idefr;
85 struct ata_timing at;
86
87 static const u8 activebits[15] = {
88 0, 1, 2, 3, 4,
89 5, 5, 6, 6, 6,
90 6, 7, 7, 7, 7
91 };
92
93 static const u8 recoverbits[12] = {
94 0, 1, 2, 3, 4, 5, 6, 6, 7, 7, 7, 7
95 };
96
97 pci_read_config_byte(pdev, port + 3, &idefr);
98
99 if (ata_pio_need_iordy(adev))
100 idefr |= 0x04; /* IORDY enable */
101 else
102 idefr &= ~0x04;
103
104 if (ata_timing_compute(adev, adev->pio_mode, &at, 30303, 1) < 0) {
105 dev_printk(KERN_ERR, &pdev->dev, "unknown mode %d.\n", adev->pio_mode);
106 return;
107 }
108
109 at.active = FIT(at.active, 2, 16) - 2;
110 at.setup = FIT(at.setup, 1, 4) - 1;
111 at.recover = FIT(at.recover, 1, 12) - 1;
112
113 idetcr = (at.setup << 6) | (recoverbits[at.recover] << 3) | activebits[at.active];
114
115 pci_write_config_byte(pdev, port, idetcr);
116 pci_write_config_byte(pdev, port + 3, idefr);
117 /* We use ap->private_data as a pointer to the device currently
118 loaded for timing */
119 ap->private_data = adev;
120}
121
122/**
123 * ns87410_qc_issue_prot - command issue
124 * @qc: command pending
125 *
126 * Called when the libata layer is about to issue a command. We wrap
127 * this interface so that we can load the correct ATA timings if
128 * neccessary.
129 */
130
131static unsigned int ns87410_qc_issue_prot(struct ata_queued_cmd *qc)
132{
133 struct ata_port *ap = qc->ap;
134 struct ata_device *adev = qc->dev;
135
136 /* If modes have been configured and the channel data is not loaded
137 then load it. We have to check if pio_mode is set as the core code
138 does not set adev->pio_mode to XFER_PIO_0 while probing as would be
139 logical */
140
141 if (adev->pio_mode && adev != ap->private_data)
142 ns87410_set_piomode(ap, adev);
143
144 return ata_qc_issue_prot(qc);
145}
146
147static struct scsi_host_template ns87410_sht = {
148 .module = THIS_MODULE,
149 .name = DRV_NAME,
150 .ioctl = ata_scsi_ioctl,
151 .queuecommand = ata_scsi_queuecmd,
152 .can_queue = ATA_DEF_QUEUE,
153 .this_id = ATA_SHT_THIS_ID,
154 .sg_tablesize = LIBATA_MAX_PRD,
155 .max_sectors = ATA_MAX_SECTORS,
156 .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
157 .emulated = ATA_SHT_EMULATED,
158 .use_clustering = ATA_SHT_USE_CLUSTERING,
159 .proc_name = DRV_NAME,
160 .dma_boundary = ATA_DMA_BOUNDARY,
161 .slave_configure = ata_scsi_slave_config,
162 .bios_param = ata_std_bios_param,
163};
164
165static struct ata_port_operations ns87410_port_ops = {
166 .port_disable = ata_port_disable,
167 .set_piomode = ns87410_set_piomode,
168
169 .tf_load = ata_tf_load,
170 .tf_read = ata_tf_read,
171 .check_status = ata_check_status,
172 .exec_command = ata_exec_command,
173 .dev_select = ata_std_dev_select,
174
175 .freeze = ata_bmdma_freeze,
176 .thaw = ata_bmdma_thaw,
177 .error_handler = ns87410_error_handler,
178 .post_internal_cmd = ata_bmdma_post_internal_cmd,
179
180 .qc_prep = ata_qc_prep,
181 .qc_issue = ns87410_qc_issue_prot,
182 .eng_timeout = ata_eng_timeout,
183 .data_xfer = ata_pio_data_xfer,
184
185 .irq_handler = ata_interrupt,
186 .irq_clear = ata_bmdma_irq_clear,
187
188 .port_start = ata_port_start,
189 .port_stop = ata_port_stop,
190 .host_stop = ata_host_stop
191};
192
193static int ns87410_init_one(struct pci_dev *dev, const struct pci_device_id *id)
194{
195 static struct ata_port_info info = {
196 .sht = &ns87410_sht,
197 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
198 .pio_mask = 0x0F,
199 .port_ops = &ns87410_port_ops
200 };
201 static struct ata_port_info *port_info[2] = {&info, &info};
202 return ata_pci_init_one(dev, port_info, 2);
203}
204
205static const struct pci_device_id ns87410[] = {
206 { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_87410), },
207 { 0, },
208};
209
210static struct pci_driver ns87410_pci_driver = {
211 .name = DRV_NAME,
212 .id_table = ns87410,
213 .probe = ns87410_init_one,
214 .remove = ata_pci_remove_one
215};
216
217static int __init ns87410_init(void)
218{
219 return pci_register_driver(&ns87410_pci_driver);
220}
221
222
223static void __exit ns87410_exit(void)
224{
225 pci_unregister_driver(&ns87410_pci_driver);
226}
227
228
229MODULE_AUTHOR("Alan Cox");
230MODULE_DESCRIPTION("low-level driver for Nat Semi 87410");
231MODULE_LICENSE("GPL");
232MODULE_DEVICE_TABLE(pci, ns87410);
233MODULE_VERSION(DRV_VERSION);
234
235module_init(ns87410_init);
236module_exit(ns87410_exit);