]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/ide/pci/jmicron.c
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/x86/linux...
[mirror_ubuntu-artful-kernel.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>
bbb3bbdb
AC
11#include <linux/hdreg.h>
12#include <linux/ide.h>
13#include <linux/init.h>
14
bbb3bbdb
AC
15typedef enum {
16 PORT_PATA0 = 0,
17 PORT_PATA1 = 1,
18 PORT_SATA = 2,
19} port_type;
20
bbb3bbdb
AC
21/**
22 * ata66_jmicron - Cable check
23 * @hwif: IDE port
24 *
49521f97 25 * Returns the cable type.
bbb3bbdb
AC
26 */
27
49521f97 28static u8 __devinit ata66_jmicron(ide_hwif_t *hwif)
bbb3bbdb 29{
36501650 30 struct pci_dev *pdev = to_pci_dev(hwif->dev);
bbb3bbdb
AC
31
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 */
740694f5 66 switch (port_map[port]) {
bbb3bbdb
AC
67 case PORT_PATA0:
68 if (control & (1 << 3)) /* 40/80 pin primary */
49521f97
BZ
69 return ATA_CBL_PATA40;
70 return ATA_CBL_PATA80;
bbb3bbdb
AC
71 case PORT_PATA1:
72 if (control5 & (1 << 19)) /* 40/80 pin secondary */
49521f97
BZ
73 return ATA_CBL_PATA40;
74 return ATA_CBL_PATA80;
bbb3bbdb 75 case PORT_SATA:
a51545ab 76 break;
bbb3bbdb 77 }
49521f97
BZ
78 /* Avoid bogus "control reaches end of non-void function" */
79 return ATA_CBL_PATA80;
bbb3bbdb
AC
80}
81
26bcb879 82static void jmicron_set_pio_mode(ide_drive_t *drive, const u8 pio)
bbb3bbdb 83{
bbb3bbdb
AC
84}
85
86/**
88b2b32b
BZ
87 * jmicron_set_dma_mode - set host controller for DMA mode
88 * @drive: drive
89 * @mode: DMA mode
bbb3bbdb 90 *
88b2b32b 91 * As the JMicron snoops for timings we don't need to do anything here.
bbb3bbdb
AC
92 */
93
88b2b32b 94static void jmicron_set_dma_mode(ide_drive_t *drive, const u8 mode)
bbb3bbdb 95{
bbb3bbdb
AC
96}
97
bbb3bbdb
AC
98/**
99 * init_hwif_jmicron - set up hwif structs
100 * @hwif: interface to set up
101 *
102 * Minimal set up is required for the Jmicron hardware.
103 */
104
105static void __devinit init_hwif_jmicron(ide_hwif_t *hwif)
106{
26bcb879 107 hwif->set_pio_mode = &jmicron_set_pio_mode;
88b2b32b 108 hwif->set_dma_mode = &jmicron_set_dma_mode;
bbb3bbdb 109
bfa14b42 110 hwif->cable_detect = ata66_jmicron;
bbb3bbdb
AC
111}
112
85620436 113static const struct ide_port_info jmicron_chipset __devinitdata = {
bda7970c
TH
114 .name = "JMB",
115 .init_hwif = init_hwif_jmicron,
bda7970c
TH
116 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
117 .pio_mask = ATA_PIO5,
5f8b6c34
BZ
118 .mwdma_mask = ATA_MWDMA2,
119 .udma_mask = ATA_UDMA6,
bbb3bbdb
AC
120};
121
122/**
123 * jmicron_init_one - pci layer discovery entry
124 * @dev: PCI device
125 * @id: ident table entry
126 *
127 * Called by the PCI code when it finds a Jmicron controller.
128 * We then use the IDE PCI generic helper to do most of the work.
129 */
130
131static int __devinit jmicron_init_one(struct pci_dev *dev, const struct pci_device_id *id)
132{
24ffbd62 133 return ide_setup_pci_device(dev, &jmicron_chipset);
bbb3bbdb
AC
134}
135
bda7970c
TH
136/* All JMB PATA controllers have and will continue to have the same
137 * interface. Matching vendor and device class is enough for all
138 * current and future controllers if the controller is programmed
139 * properly.
140 *
141 * If libata is configured, jmicron PCI quirk programs the controller
142 * into the correct mode. If libata isn't configured, match known
143 * device IDs too to maintain backward compatibility.
ebbc2031 144 */
bbb3bbdb 145static struct pci_device_id jmicron_pci_tbl[] = {
bda7970c
TH
146#if !defined(CONFIG_ATA) && !defined(CONFIG_ATA_MODULE)
147 { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB361) },
148 { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB363) },
149 { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB365) },
150 { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB366) },
151 { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB368) },
152#endif
153 { PCI_VENDOR_ID_JMICRON, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
154 PCI_CLASS_STORAGE_IDE << 8, 0xffff00, 0 },
bbb3bbdb
AC
155 { 0, },
156};
157
158MODULE_DEVICE_TABLE(pci, jmicron_pci_tbl);
159
160static struct pci_driver driver = {
161 .name = "JMicron IDE",
162 .id_table = jmicron_pci_tbl,
163 .probe = jmicron_init_one,
164};
165
166static int __init jmicron_ide_init(void)
167{
168 return ide_pci_register_driver(&driver);
169}
170
171module_init(jmicron_ide_init);
172
173MODULE_AUTHOR("Alan Cox");
174MODULE_DESCRIPTION("PCI driver module for the JMicron in legacy modes");
175MODULE_LICENSE("GPL");