libata: implement and use SHT initializers
[deliverable/linux.git] / drivers / ata / pata_jmicron.c
CommitLineData
669a5db4
JG
1/*
2 * pata_jmicron.c - JMicron ATA driver for non AHCI mode. This drives the
3 * PATA port of the controller. The SATA ports are
4 * driven by AHCI in the usual configuration although
5 * this driver can handle other setups if we need it.
6 *
7 * (c) 2006 Red Hat <alan@redhat.com>
8 */
9
10#include <linux/kernel.h>
11#include <linux/module.h>
12#include <linux/pci.h>
13#include <linux/init.h>
14#include <linux/blkdev.h>
15#include <linux/delay.h>
16#include <linux/device.h>
17#include <scsi/scsi_host.h>
18#include <linux/libata.h>
19#include <linux/ata.h>
20
21#define DRV_NAME "pata_jmicron"
8bc3fc47 22#define DRV_VERSION "0.1.5"
669a5db4
JG
23
24typedef enum {
25 PORT_PATA0 = 0,
26 PORT_PATA1 = 1,
27 PORT_SATA = 2,
28} port_type;
29
30/**
31 * jmicron_pre_reset - check for 40/80 pin
cc0680a5 32 * @link: ATA link
d4b2bab4 33 * @deadline: deadline jiffies for the operation
669a5db4
JG
34 *
35 * Perform the PATA port setup we need.
d4b2bab4 36 *
669a5db4
JG
37 * On the Jmicron 361/363 there is a single PATA port that can be mapped
38 * either as primary or secondary (or neither). We don't do any policy
39 * and setup here. We assume that has been done by init_one and the
40 * BIOS.
41 */
cc0680a5 42static int jmicron_pre_reset(struct ata_link *link, unsigned long deadline)
669a5db4 43{
cc0680a5 44 struct ata_port *ap = link->ap;
669a5db4
JG
45 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
46 u32 control;
47 u32 control5;
48 int port_mask = 1<< (4 * ap->port_no);
49 int port = ap->port_no;
50 port_type port_map[2];
51
52 /* Check if our port is enabled */
53 pci_read_config_dword(pdev, 0x40, &control);
54 if ((control & port_mask) == 0)
c961922b 55 return -ENOENT;
669a5db4
JG
56
57 /* There are two basic mappings. One has the two SATA ports merged
58 as master/slave and the secondary as PATA, the other has only the
59 SATA port mapped */
60 if (control & (1 << 23)) {
61 port_map[0] = PORT_SATA;
62 port_map[1] = PORT_PATA0;
63 } else {
64 port_map[0] = PORT_SATA;
65 port_map[1] = PORT_SATA;
66 }
67
68 /* The 365/366 may have this bit set to map the second PATA port
69 as the internal primary channel */
70 pci_read_config_dword(pdev, 0x80, &control5);
71 if (control5 & (1<<24))
72 port_map[0] = PORT_PATA1;
73
74 /* The two ports may then be logically swapped by the firmware */
75 if (control & (1 << 22))
76 port = port ^ 1;
77
78 /*
79 * Now we know which physical port we are talking about we can
80 * actually do our cable checking etc. Thankfully we don't need
81 * to do the plumbing for other cases.
82 */
0706efd6 83 switch (port_map[port]) {
669a5db4 84 case PORT_PATA0:
0706efd6
TH
85 if ((control & (1 << 5)) == 0)
86 return -ENOENT;
669a5db4
JG
87 if (control & (1 << 3)) /* 40/80 pin primary */
88 ap->cbl = ATA_CBL_PATA40;
89 else
90 ap->cbl = ATA_CBL_PATA80;
91 break;
92 case PORT_PATA1:
93 /* Bit 21 is set if the port is enabled */
94 if ((control5 & (1 << 21)) == 0)
0706efd6 95 return -ENOENT;
669a5db4
JG
96 if (control5 & (1 << 19)) /* 40/80 pin secondary */
97 ap->cbl = ATA_CBL_PATA40;
98 else
99 ap->cbl = ATA_CBL_PATA80;
100 break;
101 case PORT_SATA:
102 ap->cbl = ATA_CBL_SATA;
103 break;
104 }
cc0680a5 105 return ata_std_prereset(link, deadline);
669a5db4
JG
106}
107
108/**
109 * jmicron_error_handler - Setup and error handler
110 * @ap: Port to handle
111 *
112 * LOCKING:
113 * None (inherited from caller).
114 */
115
116static void jmicron_error_handler(struct ata_port *ap)
117{
ef2f2e49
HH
118 ata_bmdma_drive_eh(ap, jmicron_pre_reset, ata_std_softreset, NULL,
119 ata_std_postreset);
669a5db4
JG
120}
121
122/* No PIO or DMA methods needed for this device */
123
124static struct scsi_host_template jmicron_sht = {
68d1d07b 125 ATA_BMDMA_SHT(DRV_NAME),
669a5db4
JG
126};
127
128static const struct ata_port_operations jmicron_ops = {
669a5db4
JG
129 /* Task file is PCI ATA format, use helpers */
130 .tf_load = ata_tf_load,
131 .tf_read = ata_tf_read,
132 .check_status = ata_check_status,
133 .exec_command = ata_exec_command,
134 .dev_select = ata_std_dev_select,
135
6bd99b4e 136 .mode_filter = ata_pci_default_filter,
669a5db4
JG
137 .freeze = ata_bmdma_freeze,
138 .thaw = ata_bmdma_thaw,
139 .error_handler = jmicron_error_handler,
140 .post_internal_cmd = ata_bmdma_post_internal_cmd,
141
142 /* BMDMA handling is PCI ATA format, use helpers */
143 .bmdma_setup = ata_bmdma_setup,
144 .bmdma_start = ata_bmdma_start,
145 .bmdma_stop = ata_bmdma_stop,
146 .bmdma_status = ata_bmdma_status,
147 .qc_prep = ata_qc_prep,
148 .qc_issue = ata_qc_issue_prot,
0d5ff566 149 .data_xfer = ata_data_xfer,
669a5db4 150
bda30288 151 /* IRQ-related hooks */
669a5db4
JG
152 .irq_handler = ata_interrupt,
153 .irq_clear = ata_bmdma_irq_clear,
246ce3b6 154 .irq_on = ata_irq_on,
669a5db4
JG
155
156 /* Generic PATA PCI ATA helpers */
6bd99b4e 157 .port_start = ata_sff_port_start,
669a5db4
JG
158};
159
160
161/**
162 * jmicron_init_one - Register Jmicron ATA PCI device with kernel services
163 * @pdev: PCI device to register
164 * @ent: Entry in jmicron_pci_tbl matching with @pdev
165 *
166 * Called from kernel PCI layer.
167 *
168 * LOCKING:
169 * Inherited from PCI layer (may sleep).
170 *
171 * RETURNS:
172 * Zero on success, or -ERRNO value.
173 */
174
175static int jmicron_init_one (struct pci_dev *pdev, const struct pci_device_id *id)
176{
1626aeb8 177 static const struct ata_port_info info = {
669a5db4 178 .sht = &jmicron_sht,
1d2808fd 179 .flags = ATA_FLAG_SLAVE_POSS,
669a5db4
JG
180
181 .pio_mask = 0x1f,
182 .mwdma_mask = 0x07,
bf6263a8 183 .udma_mask = ATA_UDMA5,
669a5db4
JG
184
185 .port_ops = &jmicron_ops,
186 };
1626aeb8 187 const struct ata_port_info *ppi[] = { &info, NULL };
669a5db4 188
1626aeb8 189 return ata_pci_init_one(pdev, ppi);
669a5db4
JG
190}
191
192static const struct pci_device_id jmicron_pci_tbl[] = {
a01f48b8
TH
193 { PCI_VENDOR_ID_JMICRON, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
194 PCI_CLASS_STORAGE_IDE << 8, 0xffff00, 0 },
669a5db4
JG
195 { } /* terminate list */
196};
197
198static struct pci_driver jmicron_pci_driver = {
199 .name = DRV_NAME,
200 .id_table = jmicron_pci_tbl,
201 .probe = jmicron_init_one,
202 .remove = ata_pci_remove_one,
438ac6d5 203#ifdef CONFIG_PM
d39ca896 204 .suspend = ata_pci_device_suspend,
960627b7 205 .resume = ata_pci_device_resume,
438ac6d5 206#endif
669a5db4
JG
207};
208
209static int __init jmicron_init(void)
210{
211 return pci_register_driver(&jmicron_pci_driver);
212}
213
214static void __exit jmicron_exit(void)
215{
216 pci_unregister_driver(&jmicron_pci_driver);
217}
218
219module_init(jmicron_init);
220module_exit(jmicron_exit);
221
222MODULE_AUTHOR("Alan Cox");
223MODULE_DESCRIPTION("SCSI low-level driver for Jmicron PATA ports");
224MODULE_LICENSE("GPL");
225MODULE_DEVICE_TABLE(pci, jmicron_pci_tbl);
226MODULE_VERSION(DRV_VERSION);
227
This page took 0.306801 seconds and 5 git commands to generate.