blob: a7e3c14f7b07b978a5b7903b3f18339765bb5304 [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>
Alan Coxbbb3bbd2006-10-03 01:14:12 -070011#include <linux/hdreg.h>
12#include <linux/ide.h>
13#include <linux/init.h>
14
Alan Coxbbb3bbd2006-10-03 01:14:12 -070015typedef enum {
16 PORT_PATA0 = 0,
17 PORT_PATA1 = 1,
18 PORT_SATA = 2,
19} port_type;
20
21/**
Bartlomiej Zolnierkiewiczac95bee2008-04-26 22:25:14 +020022 * jmicron_cable_detect - cable detection
Alan Coxbbb3bbd2006-10-03 01:14:12 -070023 * @hwif: IDE port
24 *
Bartlomiej Zolnierkiewicz49521f92007-07-09 23:17:58 +020025 * Returns the cable type.
Alan Coxbbb3bbd2006-10-03 01:14:12 -070026 */
27
Bartlomiej Zolnierkiewiczac95bee2008-04-26 22:25:14 +020028static u8 __devinit jmicron_cable_detect(ide_hwif_t *hwif)
Alan Coxbbb3bbd2006-10-03 01:14:12 -070029{
Bartlomiej Zolnierkiewicz36501652008-02-01 23:09:31 +010030 struct pci_dev *pdev = to_pci_dev(hwif->dev);
Alan Coxbbb3bbd2006-10-03 01:14:12 -070031
32 u32 control;
33 u32 control5;
34
35 int port = hwif->channel;
36 port_type port_map[2];
37
38 pci_read_config_dword(pdev, 0x40, &control);
39
40 /* There are two basic mappings. One has the two SATA ports merged
41 as master/slave and the secondary as PATA, the other has only the
42 SATA port mapped */
43 if (control & (1 << 23)) {
44 port_map[0] = PORT_SATA;
45 port_map[1] = PORT_PATA0;
46 } else {
47 port_map[0] = PORT_SATA;
48 port_map[1] = PORT_SATA;
49 }
50
51 /* The 365/366 may have this bit set to map the second PATA port
52 as the internal primary channel */
53 pci_read_config_dword(pdev, 0x80, &control5);
54 if (control5 & (1<<24))
55 port_map[0] = PORT_PATA1;
56
57 /* The two ports may then be logically swapped by the firmware */
58 if (control & (1 << 22))
59 port = port ^ 1;
60
61 /*
62 * Now we know which physical port we are talking about we can
63 * actually do our cable checking etc. Thankfully we don't need
64 * to do the plumbing for other cases.
65 */
Paolo Ciarrocchi740694f2008-04-26 17:36:40 +020066 switch (port_map[port]) {
Alan Coxbbb3bbd2006-10-03 01:14:12 -070067 case PORT_PATA0:
68 if (control & (1 << 3)) /* 40/80 pin primary */
Bartlomiej Zolnierkiewicz49521f92007-07-09 23:17:58 +020069 return ATA_CBL_PATA40;
70 return ATA_CBL_PATA80;
Alan Coxbbb3bbd2006-10-03 01:14:12 -070071 case PORT_PATA1:
72 if (control5 & (1 << 19)) /* 40/80 pin secondary */
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_SATA:
Andrew Mortona51545a2007-01-27 13:46:21 +010076 break;
Alan Coxbbb3bbd2006-10-03 01:14:12 -070077 }
Bartlomiej Zolnierkiewicz49521f92007-07-09 23:17:58 +020078 /* Avoid bogus "control reaches end of non-void function" */
79 return ATA_CBL_PATA80;
Alan Coxbbb3bbd2006-10-03 01:14:12 -070080}
81
Bartlomiej Zolnierkiewicz26bcb872007-10-11 23:54:00 +020082static void jmicron_set_pio_mode(ide_drive_t *drive, const u8 pio)
Alan Coxbbb3bbd2006-10-03 01:14:12 -070083{
Alan Coxbbb3bbd2006-10-03 01:14:12 -070084}
85
86/**
Bartlomiej Zolnierkiewicz88b2b322007-10-13 17:47:51 +020087 * jmicron_set_dma_mode - set host controller for DMA mode
88 * @drive: drive
89 * @mode: DMA mode
Alan Coxbbb3bbd2006-10-03 01:14:12 -070090 *
Bartlomiej Zolnierkiewicz88b2b322007-10-13 17:47:51 +020091 * As the JMicron snoops for timings we don't need to do anything here.
Alan Coxbbb3bbd2006-10-03 01:14:12 -070092 */
93
Bartlomiej Zolnierkiewicz88b2b322007-10-13 17:47:51 +020094static void jmicron_set_dma_mode(ide_drive_t *drive, const u8 mode)
Alan Coxbbb3bbd2006-10-03 01:14:12 -070095{
Alan Coxbbb3bbd2006-10-03 01:14:12 -070096}
97
Bartlomiej Zolnierkiewiczac95bee2008-04-26 22:25:14 +020098static const struct ide_port_ops jmicron_port_ops = {
99 .set_pio_mode = jmicron_set_pio_mode,
100 .set_dma_mode = jmicron_set_dma_mode,
101 .cable_detect = jmicron_cable_detect,
102};
Alan Coxbbb3bbd2006-10-03 01:14:12 -0700103
Bartlomiej Zolnierkiewicz85620432007-10-20 00:32:34 +0200104static const struct ide_port_info jmicron_chipset __devinitdata = {
Tejun Heobda79702007-10-11 23:53:59 +0200105 .name = "JMB",
Tejun Heobda79702007-10-11 23:53:59 +0200106 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
Bartlomiej Zolnierkiewiczac95bee2008-04-26 22:25:14 +0200107 .port_ops = &jmicron_port_ops,
Tejun Heobda79702007-10-11 23:53:59 +0200108 .pio_mask = ATA_PIO5,
Bartlomiej Zolnierkiewicz5f8b6c32007-10-19 00:30:07 +0200109 .mwdma_mask = ATA_MWDMA2,
110 .udma_mask = ATA_UDMA6,
Alan Coxbbb3bbd2006-10-03 01:14:12 -0700111};
112
113/**
114 * jmicron_init_one - pci layer discovery entry
115 * @dev: PCI device
116 * @id: ident table entry
117 *
118 * Called by the PCI code when it finds a Jmicron controller.
119 * We then use the IDE PCI generic helper to do most of the work.
120 */
121
122static int __devinit jmicron_init_one(struct pci_dev *dev, const struct pci_device_id *id)
123{
Bartlomiej Zolnierkiewicz6cdf6eb2008-07-24 22:53:14 +0200124 return ide_pci_init_one(dev, &jmicron_chipset, NULL);
Alan Coxbbb3bbd2006-10-03 01:14:12 -0700125}
126
Tejun Heobda79702007-10-11 23:53:59 +0200127/* All JMB PATA controllers have and will continue to have the same
128 * interface. Matching vendor and device class is enough for all
129 * current and future controllers if the controller is programmed
130 * properly.
131 *
132 * If libata is configured, jmicron PCI quirk programs the controller
133 * into the correct mode. If libata isn't configured, match known
134 * device IDs too to maintain backward compatibility.
Tejun Heoebbc2032007-03-17 21:57:25 +0100135 */
Alan Coxbbb3bbd2006-10-03 01:14:12 -0700136static struct pci_device_id jmicron_pci_tbl[] = {
Tejun Heobda79702007-10-11 23:53:59 +0200137#if !defined(CONFIG_ATA) && !defined(CONFIG_ATA_MODULE)
138 { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB361) },
139 { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB363) },
140 { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB365) },
141 { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB366) },
142 { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB368) },
143#endif
144 { PCI_VENDOR_ID_JMICRON, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
145 PCI_CLASS_STORAGE_IDE << 8, 0xffff00, 0 },
Alan Coxbbb3bbd2006-10-03 01:14:12 -0700146 { 0, },
147};
148
149MODULE_DEVICE_TABLE(pci, jmicron_pci_tbl);
150
151static struct pci_driver driver = {
152 .name = "JMicron IDE",
153 .id_table = jmicron_pci_tbl,
154 .probe = jmicron_init_one,
155};
156
157static int __init jmicron_ide_init(void)
158{
159 return ide_pci_register_driver(&driver);
160}
161
162module_init(jmicron_ide_init);
163
164MODULE_AUTHOR("Alan Cox");
165MODULE_DESCRIPTION("PCI driver module for the JMicron in legacy modes");
166MODULE_LICENSE("GPL");