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