]> pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/ide/pci/jmicron.c
Merge branch 'upstream' of git://ftp.linux-mips.org/pub/scm/upstream-linus
[linux-2.6-omap-h63xx.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/delay.h>
12 #include <linux/hdreg.h>
13 #include <linux/ide.h>
14 #include <linux/init.h>
15
16 #include <asm/io.h>
17
18 typedef enum {
19         PORT_PATA0 = 0,
20         PORT_PATA1 = 1,
21         PORT_SATA = 2,
22 } port_type;
23
24 /**
25  *      ata66_jmicron           -       Cable check
26  *      @hwif: IDE port
27  *
28  *      Returns the cable type.
29  */
30
31 static u8 __devinit ata66_jmicron(ide_hwif_t *hwif)
32 {
33         struct pci_dev *pdev = hwif->pci_dev;
34
35         u32 control;
36         u32 control5;
37
38         int port = hwif->channel;
39         port_type port_map[2];
40
41         pci_read_config_dword(pdev, 0x40, &control);
42
43         /* There are two basic mappings. One has the two SATA ports merged
44            as master/slave and the secondary as PATA, the other has only the
45            SATA port mapped */
46         if (control & (1 << 23)) {
47                 port_map[0] = PORT_SATA;
48                 port_map[1] = PORT_PATA0;
49         } else {
50                 port_map[0] = PORT_SATA;
51                 port_map[1] = PORT_SATA;
52         }
53
54         /* The 365/366 may have this bit set to map the second PATA port
55            as the internal primary channel */
56         pci_read_config_dword(pdev, 0x80, &control5);
57         if (control5 & (1<<24))
58                 port_map[0] = PORT_PATA1;
59
60         /* The two ports may then be logically swapped by the firmware */
61         if (control & (1 << 22))
62                 port = port ^ 1;
63
64         /*
65          *      Now we know which physical port we are talking about we can
66          *      actually do our cable checking etc. Thankfully we don't need
67          *      to do the plumbing for other cases.
68          */
69         switch (port_map[port])
70         {
71         case PORT_PATA0:
72                 if (control & (1 << 3)) /* 40/80 pin primary */
73                         return ATA_CBL_PATA40;
74                 return ATA_CBL_PATA80;
75         case PORT_PATA1:
76                 if (control5 & (1 << 19))       /* 40/80 pin secondary */
77                         return ATA_CBL_PATA40;
78                 return ATA_CBL_PATA80;
79         case PORT_SATA:
80                 break;
81         }
82         /* Avoid bogus "control reaches end of non-void function" */
83         return ATA_CBL_PATA80;
84 }
85
86 static void jmicron_set_pio_mode(ide_drive_t *drive, const u8 pio)
87 {
88         ide_config_drive_speed(drive, XFER_PIO_0 + pio);
89 }
90
91 /**
92  *      jmicron_tune_chipset    -       set controller timings
93  *      @drive: Drive to set up
94  *      @speed: speed we want to achieve
95  *
96  *      As the JMicron snoops for timings all we actually need to do is
97  *      set the transfer mode on the device.
98  */
99
100 static int jmicron_tune_chipset(ide_drive_t *drive, const u8 speed)
101 {
102         return ide_config_drive_speed(drive, speed);
103 }
104
105 /**
106  *      jmicron_configure_drive_for_dma -       set up for DMA transfers
107  *      @drive: drive we are going to set up
108  *
109  *      As the JMicron snoops for timings all we actually need to do is
110  *      make sure we don't set an invalid mode.
111  */
112
113 static int jmicron_config_drive_for_dma (ide_drive_t *drive)
114 {
115         if (ide_tune_dma(drive))
116                 return 0;
117
118         ide_set_max_pio(drive);
119
120         return -1;
121 }
122
123 /**
124  *      init_hwif_jmicron       -       set up hwif structs
125  *      @hwif: interface to set up
126  *
127  *      Minimal set up is required for the Jmicron hardware.
128  */
129
130 static void __devinit init_hwif_jmicron(ide_hwif_t *hwif)
131 {
132         hwif->speedproc = &jmicron_tune_chipset;
133         hwif->set_pio_mode = &jmicron_set_pio_mode;
134
135         hwif->drives[0].autotune = 1;
136         hwif->drives[1].autotune = 1;
137
138         if (!hwif->dma_base)
139                 goto fallback;
140
141         hwif->atapi_dma = 1;
142         hwif->ultra_mask = 0x7f;
143         hwif->mwdma_mask = 0x07;
144
145         hwif->ide_dma_check = &jmicron_config_drive_for_dma;
146
147         if (hwif->cbl != ATA_CBL_PATA40_SHORT)
148                 hwif->cbl = ata66_jmicron(hwif);
149
150         hwif->autodma = 1;
151         hwif->drives[0].autodma = hwif->autodma;
152         hwif->drives[1].autodma = hwif->autodma;
153         return;
154 fallback:
155         hwif->autodma = 0;
156         return;
157 }
158
159 static ide_pci_device_t jmicron_chipset __devinitdata = {
160         .name           = "JMB",
161         .init_hwif      = init_hwif_jmicron,
162         .autodma        = AUTODMA,
163         .bootable       = ON_BOARD,
164         .enablebits     = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
165         .pio_mask       = ATA_PIO5,
166 };
167
168 /**
169  *      jmicron_init_one        -       pci layer discovery entry
170  *      @dev: PCI device
171  *      @id: ident table entry
172  *
173  *      Called by the PCI code when it finds a Jmicron controller.
174  *      We then use the IDE PCI generic helper to do most of the work.
175  */
176
177 static int __devinit jmicron_init_one(struct pci_dev *dev, const struct pci_device_id *id)
178 {
179         ide_setup_pci_device(dev, &jmicron_chipset);
180         return 0;
181 }
182
183 /* All JMB PATA controllers have and will continue to have the same
184  * interface.  Matching vendor and device class is enough for all
185  * current and future controllers if the controller is programmed
186  * properly.
187  *
188  * If libata is configured, jmicron PCI quirk programs the controller
189  * into the correct mode.  If libata isn't configured, match known
190  * device IDs too to maintain backward compatibility.
191  */
192 static struct pci_device_id jmicron_pci_tbl[] = {
193 #if !defined(CONFIG_ATA) && !defined(CONFIG_ATA_MODULE)
194         { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB361) },
195         { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB363) },
196         { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB365) },
197         { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB366) },
198         { PCI_VDEVICE(JMICRON, PCI_DEVICE_ID_JMICRON_JMB368) },
199 #endif
200         { PCI_VENDOR_ID_JMICRON, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
201           PCI_CLASS_STORAGE_IDE << 8, 0xffff00, 0 },
202         { 0, },
203 };
204
205 MODULE_DEVICE_TABLE(pci, jmicron_pci_tbl);
206
207 static struct pci_driver driver = {
208         .name           = "JMicron IDE",
209         .id_table       = jmicron_pci_tbl,
210         .probe          = jmicron_init_one,
211 };
212
213 static int __init jmicron_ide_init(void)
214 {
215         return ide_pci_register_driver(&driver);
216 }
217
218 module_init(jmicron_ide_init);
219
220 MODULE_AUTHOR("Alan Cox");
221 MODULE_DESCRIPTION("PCI driver module for the JMicron in legacy modes");
222 MODULE_LICENSE("GPL");