blob: 545b6e172d9bcc74b712789edc375d6fd31f6195 [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
Bartlomiej Zolnierkiewiczced3ec82008-07-24 22:53:32 +020015#define DRV_NAME "jmicron"
16
Alan Coxbbb3bbd2006-10-03 01:14:12 -070017typedef enum {
18 PORT_PATA0 = 0,
19 PORT_PATA1 = 1,
20 PORT_SATA = 2,
21} port_type;
22
23/**
Bartlomiej Zolnierkiewiczac95bee2008-04-26 22:25:14 +020024 * jmicron_cable_detect - cable detection
Alan Coxbbb3bbd2006-10-03 01:14:12 -070025 * @hwif: IDE port
26 *
Bartlomiej Zolnierkiewicz49521f92007-07-09 23:17:58 +020027 * Returns the cable type.
Alan Coxbbb3bbd2006-10-03 01:14:12 -070028 */
29
Bartlomiej Zolnierkiewiczac95bee2008-04-26 22:25:14 +020030static u8 __devinit jmicron_cable_detect(ide_hwif_t *hwif)
Alan Coxbbb3bbd2006-10-03 01:14:12 -070031{
Bartlomiej Zolnierkiewicz36501652008-02-01 23:09:31 +010032 struct pci_dev *pdev = to_pci_dev(hwif->dev);
Alan Coxbbb3bbd2006-10-03 01:14:12 -070033
34 u32 control;
35 u32 control5;
36
37 int port = hwif->channel;
38 port_type port_map[2];
39
40 pci_read_config_dword(pdev, 0x40, &control);
41
42 /* There are two basic mappings. One has the two SATA ports merged
43 as master/slave and the secondary as PATA, the other has only the
44 SATA port mapped */
45 if (control & (1 << 23)) {
46 port_map[0] = PORT_SATA;
47 port_map[1] = PORT_PATA0;
48 } else {
49 port_map[0] = PORT_SATA;
50 port_map[1] = PORT_SATA;
51 }
52
53 /* The 365/366 may have this bit set to map the second PATA port
54 as the internal primary channel */
55 pci_read_config_dword(pdev, 0x80, &control5);
56 if (control5 & (1<<24))
57 port_map[0] = PORT_PATA1;
58
59 /* The two ports may then be logically swapped by the firmware */
60 if (control & (1 << 22))
61 port = port ^ 1;
62
63 /*
64 * Now we know which physical port we are talking about we can
65 * actually do our cable checking etc. Thankfully we don't need
66 * to do the plumbing for other cases.
67 */
Paolo Ciarrocchi740694f2008-04-26 17:36:40 +020068 switch (port_map[port]) {
Alan Coxbbb3bbd2006-10-03 01:14:12 -070069 case PORT_PATA0:
70 if (control & (1 << 3)) /* 40/80 pin primary */
Bartlomiej Zolnierkiewicz49521f92007-07-09 23:17:58 +020071 return ATA_CBL_PATA40;
72 return ATA_CBL_PATA80;
Alan Coxbbb3bbd2006-10-03 01:14:12 -070073 case PORT_PATA1:
74 if (control5 & (1 << 19)) /* 40/80 pin secondary */
Bartlomiej Zolnierkiewicz49521f92007-07-09 23:17:58 +020075 return ATA_CBL_PATA40;
76 return ATA_CBL_PATA80;
Alan Coxbbb3bbd2006-10-03 01:14:12 -070077 case PORT_SATA:
Andrew Mortona51545a2007-01-27 13:46:21 +010078 break;
Alan Coxbbb3bbd2006-10-03 01:14:12 -070079 }
Bartlomiej Zolnierkiewicz49521f92007-07-09 23:17:58 +020080 /* Avoid bogus "control reaches end of non-void function" */
81 return ATA_CBL_PATA80;
Alan Coxbbb3bbd2006-10-03 01:14:12 -070082}
83
Bartlomiej Zolnierkiewicz26bcb872007-10-11 23:54:00 +020084static void jmicron_set_pio_mode(ide_drive_t *drive, const u8 pio)
Alan Coxbbb3bbd2006-10-03 01:14:12 -070085{
Alan Coxbbb3bbd2006-10-03 01:14:12 -070086}
87
88/**
Bartlomiej Zolnierkiewicz88b2b322007-10-13 17:47:51 +020089 * jmicron_set_dma_mode - set host controller for DMA mode
90 * @drive: drive
91 * @mode: DMA mode
Alan Coxbbb3bbd2006-10-03 01:14:12 -070092 *
Bartlomiej Zolnierkiewicz88b2b322007-10-13 17:47:51 +020093 * As the JMicron snoops for timings we don't need to do anything here.
Alan Coxbbb3bbd2006-10-03 01:14:12 -070094 */
95
Bartlomiej Zolnierkiewicz88b2b322007-10-13 17:47:51 +020096static void jmicron_set_dma_mode(ide_drive_t *drive, const u8 mode)
Alan Coxbbb3bbd2006-10-03 01:14:12 -070097{
Alan Coxbbb3bbd2006-10-03 01:14:12 -070098}
99
Bartlomiej Zolnierkiewiczac95bee2008-04-26 22:25:14 +0200100static const struct ide_port_ops jmicron_port_ops = {
101 .set_pio_mode = jmicron_set_pio_mode,
102 .set_dma_mode = jmicron_set_dma_mode,
103 .cable_detect = jmicron_cable_detect,
104};
Alan Coxbbb3bbd2006-10-03 01:14:12 -0700105
Bartlomiej Zolnierkiewicz85620432007-10-20 00:32:34 +0200106static const struct ide_port_info jmicron_chipset __devinitdata = {
Bartlomiej Zolnierkiewiczced3ec82008-07-24 22:53:32 +0200107 .name = DRV_NAME,
Tejun Heobda79702007-10-11 23:53:59 +0200108 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
Bartlomiej Zolnierkiewiczac95bee2008-04-26 22:25:14 +0200109 .port_ops = &jmicron_port_ops,
Tejun Heobda79702007-10-11 23:53:59 +0200110 .pio_mask = ATA_PIO5,
Bartlomiej Zolnierkiewicz5f8b6c32007-10-19 00:30:07 +0200111 .mwdma_mask = ATA_MWDMA2,
112 .udma_mask = ATA_UDMA6,
Alan Coxbbb3bbd2006-10-03 01:14:12 -0700113};
114
115/**
116 * jmicron_init_one - pci layer discovery entry
117 * @dev: PCI device
118 * @id: ident table entry
119 *
120 * Called by the PCI code when it finds a Jmicron controller.
121 * We then use the IDE PCI generic helper to do most of the work.
122 */
123
124static int __devinit jmicron_init_one(struct pci_dev *dev, const struct pci_device_id *id)
125{
Bartlomiej Zolnierkiewicz6cdf6eb2008-07-24 22:53:14 +0200126 return ide_pci_init_one(dev, &jmicron_chipset, NULL);
Alan Coxbbb3bbd2006-10-03 01:14:12 -0700127}
128
Tejun Heobda79702007-10-11 23:53:59 +0200129/* All JMB PATA controllers have and will continue to have the same
130 * interface. Matching vendor and device class is enough for all
131 * current and future controllers if the controller is programmed
132 * properly.
133 *
134 * If libata is configured, jmicron PCI quirk programs the controller
135 * into the correct mode. If libata isn't configured, match known
136 * device IDs too to maintain backward compatibility.
Tejun Heoebbc2032007-03-17 21:57:25 +0100137 */
Alan Coxbbb3bbd2006-10-03 01:14:12 -0700138static struct pci_device_id jmicron_pci_tbl[] = {
Tejun Heobda79702007-10-11 23:53:59 +0200139#if !defined(CONFIG_ATA) && !defined(CONFIG_ATA_MODULE)
140 { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB361) },
141 { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB363) },
142 { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB365) },
143 { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB366) },
144 { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB368) },
145#endif
146 { PCI_VENDOR_ID_JMICRON, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
147 PCI_CLASS_STORAGE_IDE << 8, 0xffff00, 0 },
Alan Coxbbb3bbd2006-10-03 01:14:12 -0700148 { 0, },
149};
150
151MODULE_DEVICE_TABLE(pci, jmicron_pci_tbl);
152
153static struct pci_driver driver = {
154 .name = "JMicron IDE",
155 .id_table = jmicron_pci_tbl,
156 .probe = jmicron_init_one,
Bartlomiej Zolnierkiewicz1bcaaba2008-07-24 22:53:22 +0200157 .remove = ide_pci_remove,
Alan Coxbbb3bbd2006-10-03 01:14:12 -0700158};
159
160static int __init jmicron_ide_init(void)
161{
162 return ide_pci_register_driver(&driver);
163}
164
Bartlomiej Zolnierkiewicz1bcaaba2008-07-24 22:53:22 +0200165static void __exit jmicron_ide_exit(void)
166{
167 pci_unregister_driver(&driver);
168}
169
Alan Coxbbb3bbd2006-10-03 01:14:12 -0700170module_init(jmicron_ide_init);
Bartlomiej Zolnierkiewicz1bcaaba2008-07-24 22:53:22 +0200171module_exit(jmicron_ide_exit);
Alan Coxbbb3bbd2006-10-03 01:14:12 -0700172
173MODULE_AUTHOR("Alan Cox");
174MODULE_DESCRIPTION("PCI driver module for the JMicron in legacy modes");
175MODULE_LICENSE("GPL");