blob: b058b3a01b30463396970de5302e12997d6f4787 [file] [log] [blame]
Alan Coxbbb3bbd2006-10-03 01:14:12 -07001
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
Alan Coxbbb3bbd2006-10-03 01:14:12 -07008#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
24/**
Alan Coxbbb3bbd2006-10-03 01:14:12 -070025 * ata66_jmicron - Cable check
26 * @hwif: IDE port
27 *
Bartlomiej Zolnierkiewicz49521f92007-07-09 23:17:58 +020028 * Returns the cable type.
Alan Coxbbb3bbd2006-10-03 01:14:12 -070029 */
30
Bartlomiej Zolnierkiewicz49521f92007-07-09 23:17:58 +020031static u8 __devinit ata66_jmicron(ide_hwif_t *hwif)
Alan Coxbbb3bbd2006-10-03 01:14:12 -070032{
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 */
Bartlomiej Zolnierkiewicz49521f92007-07-09 23:17:58 +020073 return ATA_CBL_PATA40;
74 return ATA_CBL_PATA80;
Alan Coxbbb3bbd2006-10-03 01:14:12 -070075 case PORT_PATA1:
76 if (control5 & (1 << 19)) /* 40/80 pin secondary */
Bartlomiej Zolnierkiewicz49521f92007-07-09 23:17:58 +020077 return ATA_CBL_PATA40;
78 return ATA_CBL_PATA80;
Alan Coxbbb3bbd2006-10-03 01:14:12 -070079 case PORT_SATA:
Andrew Mortona51545a2007-01-27 13:46:21 +010080 break;
Alan Coxbbb3bbd2006-10-03 01:14:12 -070081 }
Bartlomiej Zolnierkiewicz49521f92007-07-09 23:17:58 +020082 /* Avoid bogus "control reaches end of non-void function" */
83 return ATA_CBL_PATA80;
Alan Coxbbb3bbd2006-10-03 01:14:12 -070084}
85
Bartlomiej Zolnierkiewicz26bcb872007-10-11 23:54:00 +020086static void jmicron_set_pio_mode(ide_drive_t *drive, const u8 pio)
Alan Coxbbb3bbd2006-10-03 01:14:12 -070087{
Alan Coxbbb3bbd2006-10-03 01:14:12 -070088}
89
90/**
Bartlomiej Zolnierkiewicz88b2b322007-10-13 17:47:51 +020091 * jmicron_set_dma_mode - set host controller for DMA mode
92 * @drive: drive
93 * @mode: DMA mode
Alan Coxbbb3bbd2006-10-03 01:14:12 -070094 *
Bartlomiej Zolnierkiewicz88b2b322007-10-13 17:47:51 +020095 * As the JMicron snoops for timings we don't need to do anything here.
Alan Coxbbb3bbd2006-10-03 01:14:12 -070096 */
97
Bartlomiej Zolnierkiewicz88b2b322007-10-13 17:47:51 +020098static void jmicron_set_dma_mode(ide_drive_t *drive, const u8 mode)
Alan Coxbbb3bbd2006-10-03 01:14:12 -070099{
Alan Coxbbb3bbd2006-10-03 01:14:12 -0700100}
101
102/**
Alan Coxbbb3bbd2006-10-03 01:14:12 -0700103 * 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{
Bartlomiej Zolnierkiewicz26bcb872007-10-11 23:54:00 +0200111 hwif->set_pio_mode = &jmicron_set_pio_mode;
Bartlomiej Zolnierkiewicz88b2b322007-10-13 17:47:51 +0200112 hwif->set_dma_mode = &jmicron_set_dma_mode;
Alan Coxbbb3bbd2006-10-03 01:14:12 -0700113
114 hwif->drives[0].autotune = 1;
115 hwif->drives[1].autotune = 1;
116
Bartlomiej Zolnierkiewicz9ff6f722007-10-16 22:29:58 +0200117 if (hwif->dma_base == 0)
118 return;
Alan Coxbbb3bbd2006-10-03 01:14:12 -0700119
Bartlomiej Zolnierkiewicz49521f92007-07-09 23:17:58 +0200120 if (hwif->cbl != ATA_CBL_PATA40_SHORT)
121 hwif->cbl = ata66_jmicron(hwif);
Alan Coxbbb3bbd2006-10-03 01:14:12 -0700122}
123
Tejun Heobda79702007-10-11 23:53:59 +0200124static ide_pci_device_t jmicron_chipset __devinitdata = {
125 .name = "JMB",
126 .init_hwif = init_hwif_jmicron,
Bartlomiej Zolnierkiewicz7cab14a2007-10-19 00:30:06 +0200127 .host_flags = IDE_HFLAG_BOOTABLE,
Tejun Heobda79702007-10-11 23:53:59 +0200128 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
129 .pio_mask = ATA_PIO5,
Bartlomiej Zolnierkiewicz5f8b6c32007-10-19 00:30:07 +0200130 .mwdma_mask = ATA_MWDMA2,
131 .udma_mask = ATA_UDMA6,
Alan Coxbbb3bbd2006-10-03 01:14:12 -0700132};
133
134/**
135 * jmicron_init_one - pci layer discovery entry
136 * @dev: PCI device
137 * @id: ident table entry
138 *
139 * Called by the PCI code when it finds a Jmicron controller.
140 * We then use the IDE PCI generic helper to do most of the work.
141 */
142
143static int __devinit jmicron_init_one(struct pci_dev *dev, const struct pci_device_id *id)
144{
Tejun Heobda79702007-10-11 23:53:59 +0200145 ide_setup_pci_device(dev, &jmicron_chipset);
Alan Coxbbb3bbd2006-10-03 01:14:12 -0700146 return 0;
147}
148
Tejun Heobda79702007-10-11 23:53:59 +0200149/* All JMB PATA controllers have and will continue to have the same
150 * interface. Matching vendor and device class is enough for all
151 * current and future controllers if the controller is programmed
152 * properly.
153 *
154 * If libata is configured, jmicron PCI quirk programs the controller
155 * into the correct mode. If libata isn't configured, match known
156 * device IDs too to maintain backward compatibility.
Tejun Heoebbc2032007-03-17 21:57:25 +0100157 */
Alan Coxbbb3bbd2006-10-03 01:14:12 -0700158static struct pci_device_id jmicron_pci_tbl[] = {
Tejun Heobda79702007-10-11 23:53:59 +0200159#if !defined(CONFIG_ATA) && !defined(CONFIG_ATA_MODULE)
160 { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB361) },
161 { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB363) },
162 { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB365) },
163 { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB366) },
164 { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB368) },
165#endif
166 { PCI_VENDOR_ID_JMICRON, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
167 PCI_CLASS_STORAGE_IDE << 8, 0xffff00, 0 },
Alan Coxbbb3bbd2006-10-03 01:14:12 -0700168 { 0, },
169};
170
171MODULE_DEVICE_TABLE(pci, jmicron_pci_tbl);
172
173static struct pci_driver driver = {
174 .name = "JMicron IDE",
175 .id_table = jmicron_pci_tbl,
176 .probe = jmicron_init_one,
177};
178
179static int __init jmicron_ide_init(void)
180{
181 return ide_pci_register_driver(&driver);
182}
183
184module_init(jmicron_ide_init);
185
186MODULE_AUTHOR("Alan Cox");
187MODULE_DESCRIPTION("PCI driver module for the JMicron in legacy modes");
188MODULE_LICENSE("GPL");