]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - drivers/ide/pci/jmicron.c
ide: ->quirkproc method cannot be marked __devinit
[mirror_ubuntu-zesty-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
ced3ec8a
BZ
15#define DRV_NAME "jmicron"
16
bbb3bbdb
AC
17typedef enum {
18 PORT_PATA0 = 0,
19 PORT_PATA1 = 1,
20 PORT_SATA = 2,
21} port_type;
22
bbb3bbdb 23/**
ac95beed 24 * jmicron_cable_detect - cable detection
bbb3bbdb
AC
25 * @hwif: IDE port
26 *
49521f97 27 * Returns the cable type.
bbb3bbdb
AC
28 */
29
ac95beed 30static u8 __devinit jmicron_cable_detect(ide_hwif_t *hwif)
bbb3bbdb 31{
36501650 32 struct pci_dev *pdev = to_pci_dev(hwif->dev);
bbb3bbdb
AC
33
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 */
740694f5 68 switch (port_map[port]) {
bbb3bbdb
AC
69 case PORT_PATA0:
70 if (control & (1 << 3)) /* 40/80 pin primary */
49521f97
BZ
71 return ATA_CBL_PATA40;
72 return ATA_CBL_PATA80;
bbb3bbdb
AC
73 case PORT_PATA1:
74 if (control5 & (1 << 19)) /* 40/80 pin secondary */
49521f97
BZ
75 return ATA_CBL_PATA40;
76 return ATA_CBL_PATA80;
bbb3bbdb 77 case PORT_SATA:
a51545ab 78 break;
bbb3bbdb 79 }
49521f97
BZ
80 /* Avoid bogus "control reaches end of non-void function" */
81 return ATA_CBL_PATA80;
bbb3bbdb
AC
82}
83
26bcb879 84static void jmicron_set_pio_mode(ide_drive_t *drive, const u8 pio)
bbb3bbdb 85{
bbb3bbdb
AC
86}
87
88/**
88b2b32b
BZ
89 * jmicron_set_dma_mode - set host controller for DMA mode
90 * @drive: drive
91 * @mode: DMA mode
bbb3bbdb 92 *
88b2b32b 93 * As the JMicron snoops for timings we don't need to do anything here.
bbb3bbdb
AC
94 */
95
88b2b32b 96static void jmicron_set_dma_mode(ide_drive_t *drive, const u8 mode)
bbb3bbdb 97{
bbb3bbdb
AC
98}
99
ac95beed
BZ
100static 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};
bbb3bbdb 105
85620436 106static const struct ide_port_info jmicron_chipset __devinitdata = {
ced3ec8a 107 .name = DRV_NAME,
bda7970c 108 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
ac95beed 109 .port_ops = &jmicron_port_ops,
bda7970c 110 .pio_mask = ATA_PIO5,
5f8b6c34
BZ
111 .mwdma_mask = ATA_MWDMA2,
112 .udma_mask = ATA_UDMA6,
bbb3bbdb
AC
113};
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{
6cdf6eb3 126 return ide_pci_init_one(dev, &jmicron_chipset, NULL);
bbb3bbdb
AC
127}
128
bda7970c
TH
129/* 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.
ebbc2031 137 */
bbb3bbdb 138static struct pci_device_id jmicron_pci_tbl[] = {
bda7970c
TH
139#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 },
bbb3bbdb
AC
148 { 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,
1bcaaba7 157 .remove = ide_pci_remove,
bbb3bbdb
AC
158};
159
160static int __init jmicron_ide_init(void)
161{
162 return ide_pci_register_driver(&driver);
163}
164
1bcaaba7
BZ
165static void __exit jmicron_ide_exit(void)
166{
167 pci_unregister_driver(&driver);
168}
169
bbb3bbdb 170module_init(jmicron_ide_init);
1bcaaba7 171module_exit(jmicron_ide_exit);
bbb3bbdb
AC
172
173MODULE_AUTHOR("Alan Cox");
174MODULE_DESCRIPTION("PCI driver module for the JMicron in legacy modes");
175MODULE_LICENSE("GPL");