ide: remove ->ide_dma_check (take 2)
[deliverable/linux.git] / drivers / ide / pci / jmicron.c
CommitLineData
bbb3bbdb
AC
1
2/*
3 * Copyright (C) 2006 Red Hat <alan@redhat.com>
4 *
5 * May be copied or modified under the terms of the GNU General Public License
6 */
7
bbb3bbdb
AC
8#include <linux/types.h>
9#include <linux/module.h>
10#include <linux/pci.h>
11#include <linux/delay.h>
12#include <linux/hdreg.h>
13#include <linux/ide.h>
14#include <linux/init.h>
15
16#include <asm/io.h>
17
18typedef enum {
19 PORT_PATA0 = 0,
20 PORT_PATA1 = 1,
21 PORT_SATA = 2,
22} port_type;
23
bbb3bbdb
AC
24/**
25 * ata66_jmicron - Cable check
26 * @hwif: IDE port
27 *
49521f97 28 * Returns the cable type.
bbb3bbdb
AC
29 */
30
49521f97 31static u8 __devinit ata66_jmicron(ide_hwif_t *hwif)
bbb3bbdb
AC
32{
33 struct pci_dev *pdev = hwif->pci_dev;
34
35 u32 control;
36 u32 control5;
37
38 int port = hwif->channel;
39 port_type port_map[2];
40
41 pci_read_config_dword(pdev, 0x40, &control);
42
43 /* There are two basic mappings. One has the two SATA ports merged
44 as master/slave and the secondary as PATA, the other has only the
45 SATA port mapped */
46 if (control & (1 << 23)) {
47 port_map[0] = PORT_SATA;
48 port_map[1] = PORT_PATA0;
49 } else {
50 port_map[0] = PORT_SATA;
51 port_map[1] = PORT_SATA;
52 }
53
54 /* The 365/366 may have this bit set to map the second PATA port
55 as the internal primary channel */
56 pci_read_config_dword(pdev, 0x80, &control5);
57 if (control5 & (1<<24))
58 port_map[0] = PORT_PATA1;
59
60 /* The two ports may then be logically swapped by the firmware */
61 if (control & (1 << 22))
62 port = port ^ 1;
63
64 /*
65 * Now we know which physical port we are talking about we can
66 * actually do our cable checking etc. Thankfully we don't need
67 * to do the plumbing for other cases.
68 */
69 switch (port_map[port])
70 {
71 case PORT_PATA0:
72 if (control & (1 << 3)) /* 40/80 pin primary */
49521f97
BZ
73 return ATA_CBL_PATA40;
74 return ATA_CBL_PATA80;
bbb3bbdb
AC
75 case PORT_PATA1:
76 if (control5 & (1 << 19)) /* 40/80 pin secondary */
49521f97
BZ
77 return ATA_CBL_PATA40;
78 return ATA_CBL_PATA80;
bbb3bbdb 79 case PORT_SATA:
a51545ab 80 break;
bbb3bbdb 81 }
49521f97
BZ
82 /* Avoid bogus "control reaches end of non-void function" */
83 return ATA_CBL_PATA80;
bbb3bbdb
AC
84}
85
26bcb879 86static void jmicron_set_pio_mode(ide_drive_t *drive, const u8 pio)
bbb3bbdb 87{
bbb3bbdb
AC
88}
89
90/**
88b2b32b
BZ
91 * jmicron_set_dma_mode - set host controller for DMA mode
92 * @drive: drive
93 * @mode: DMA mode
bbb3bbdb 94 *
88b2b32b 95 * As the JMicron snoops for timings we don't need to do anything here.
bbb3bbdb
AC
96 */
97
88b2b32b 98static void jmicron_set_dma_mode(ide_drive_t *drive, const u8 mode)
bbb3bbdb 99{
bbb3bbdb
AC
100}
101
bbb3bbdb
AC
102/**
103 * init_hwif_jmicron - set up hwif structs
104 * @hwif: interface to set up
105 *
106 * Minimal set up is required for the Jmicron hardware.
107 */
108
109static void __devinit init_hwif_jmicron(ide_hwif_t *hwif)
110{
26bcb879 111 hwif->set_pio_mode = &jmicron_set_pio_mode;
88b2b32b 112 hwif->set_dma_mode = &jmicron_set_dma_mode;
bbb3bbdb
AC
113
114 hwif->drives[0].autotune = 1;
115 hwif->drives[1].autotune = 1;
116
117 if (!hwif->dma_base)
118 goto fallback;
119
120 hwif->atapi_dma = 1;
121 hwif->ultra_mask = 0x7f;
122 hwif->mwdma_mask = 0x07;
123
49521f97
BZ
124 if (hwif->cbl != ATA_CBL_PATA40_SHORT)
125 hwif->cbl = ata66_jmicron(hwif);
bbb3bbdb
AC
126
127 hwif->autodma = 1;
128 hwif->drives[0].autodma = hwif->autodma;
129 hwif->drives[1].autodma = hwif->autodma;
130 return;
131fallback:
132 hwif->autodma = 0;
133 return;
134}
135
bda7970c
TH
136static ide_pci_device_t jmicron_chipset __devinitdata = {
137 .name = "JMB",
138 .init_hwif = init_hwif_jmicron,
139 .autodma = AUTODMA,
140 .bootable = ON_BOARD,
141 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
142 .pio_mask = ATA_PIO5,
bbb3bbdb
AC
143};
144
145/**
146 * jmicron_init_one - pci layer discovery entry
147 * @dev: PCI device
148 * @id: ident table entry
149 *
150 * Called by the PCI code when it finds a Jmicron controller.
151 * We then use the IDE PCI generic helper to do most of the work.
152 */
153
154static int __devinit jmicron_init_one(struct pci_dev *dev, const struct pci_device_id *id)
155{
bda7970c 156 ide_setup_pci_device(dev, &jmicron_chipset);
bbb3bbdb
AC
157 return 0;
158}
159
bda7970c
TH
160/* All JMB PATA controllers have and will continue to have the same
161 * interface. Matching vendor and device class is enough for all
162 * current and future controllers if the controller is programmed
163 * properly.
164 *
165 * If libata is configured, jmicron PCI quirk programs the controller
166 * into the correct mode. If libata isn't configured, match known
167 * device IDs too to maintain backward compatibility.
ebbc2031 168 */
bbb3bbdb 169static struct pci_device_id jmicron_pci_tbl[] = {
bda7970c
TH
170#if !defined(CONFIG_ATA) && !defined(CONFIG_ATA_MODULE)
171 { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB361) },
172 { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB363) },
173 { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB365) },
174 { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB366) },
175 { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB368) },
176#endif
177 { PCI_VENDOR_ID_JMICRON, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
178 PCI_CLASS_STORAGE_IDE << 8, 0xffff00, 0 },
bbb3bbdb
AC
179 { 0, },
180};
181
182MODULE_DEVICE_TABLE(pci, jmicron_pci_tbl);
183
184static struct pci_driver driver = {
185 .name = "JMicron IDE",
186 .id_table = jmicron_pci_tbl,
187 .probe = jmicron_init_one,
188};
189
190static int __init jmicron_ide_init(void)
191{
192 return ide_pci_register_driver(&driver);
193}
194
195module_init(jmicron_ide_init);
196
197MODULE_AUTHOR("Alan Cox");
198MODULE_DESCRIPTION("PCI driver module for the JMicron in legacy modes");
199MODULE_LICENSE("GPL");
This page took 0.137883 seconds and 5 git commands to generate.