Remove all inclusions of <linux/config.h>
[pandora-kernel.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  *      jmicron_ratemask        -       Compute available modes
26  *      @drive: IDE drive
27  *
28  *      Compute the available speeds for the devices on the interface. This
29  *      is all modes to ATA133 clipped by drive cable setup.
30  */
31
32 static u8 jmicron_ratemask(ide_drive_t *drive)
33 {
34         u8 mode = 4;
35         if (!eighty_ninty_three(drive))
36                 mode = min(mode, (u8)1);
37         return mode;
38 }
39
40 /**
41  *      ata66_jmicron           -       Cable check
42  *      @hwif: IDE port
43  *
44  *      Return 1 if the cable is 80pin
45  */
46
47 static int __devinit ata66_jmicron(ide_hwif_t *hwif)
48 {
49         struct pci_dev *pdev = hwif->pci_dev;
50
51         u32 control;
52         u32 control5;
53
54         int port = hwif->channel;
55         port_type port_map[2];
56
57         pci_read_config_dword(pdev, 0x40, &control);
58
59         /* There are two basic mappings. One has the two SATA ports merged
60            as master/slave and the secondary as PATA, the other has only the
61            SATA port mapped */
62         if (control & (1 << 23)) {
63                 port_map[0] = PORT_SATA;
64                 port_map[1] = PORT_PATA0;
65         } else {
66                 port_map[0] = PORT_SATA;
67                 port_map[1] = PORT_SATA;
68         }
69
70         /* The 365/366 may have this bit set to map the second PATA port
71            as the internal primary channel */
72         pci_read_config_dword(pdev, 0x80, &control5);
73         if (control5 & (1<<24))
74                 port_map[0] = PORT_PATA1;
75
76         /* The two ports may then be logically swapped by the firmware */
77         if (control & (1 << 22))
78                 port = port ^ 1;
79
80         /*
81          *      Now we know which physical port we are talking about we can
82          *      actually do our cable checking etc. Thankfully we don't need
83          *      to do the plumbing for other cases.
84          */
85         switch (port_map[port])
86         {
87         case PORT_PATA0:
88                 if (control & (1 << 3)) /* 40/80 pin primary */
89                         return 1;
90                 return 0;
91         case PORT_PATA1:
92                 if (control5 & (1 << 19))       /* 40/80 pin secondary */
93                         return 0;
94                 return 1;
95         case PORT_SATA:
96                 return 1;
97         }
98 }
99
100 static void jmicron_tuneproc (ide_drive_t *drive, byte mode_wanted)
101 {
102         return;
103 }
104
105 /**
106  *      config_jmicron_chipset_for_pio  -       set drive timings
107  *      @drive: drive to tune
108  *      @speed we want
109  *
110  */
111
112 static void config_jmicron_chipset_for_pio (ide_drive_t *drive, byte set_speed)
113 {
114         u8 speed = XFER_PIO_0 + ide_get_best_pio_mode(drive, 255, 5, NULL);
115         if (set_speed)
116                 (void) ide_config_drive_speed(drive, speed);
117 }
118
119 /**
120  *      jmicron_tune_chipset    -       set controller timings
121  *      @drive: Drive to set up
122  *      @xferspeed: speed we want to achieve
123  *
124  *      As the JMicron snoops for timings all we actually need to do is
125  *      make sure we don't set an invalid mode. We do need to honour
126  *      the cable detect here.
127  */
128
129 static int jmicron_tune_chipset (ide_drive_t *drive, byte xferspeed)
130 {
131
132         u8 speed                = ide_rate_filter(jmicron_ratemask(drive), xferspeed);
133
134         return ide_config_drive_speed(drive, speed);
135 }
136
137 /**
138  *      config_chipset_for_dma  -       configure for DMA
139  *      @drive: drive to configure
140  *
141  *      As the JMicron snoops for timings all we actually need to do is
142  *      make sure we don't set an invalid mode.
143  */
144
145 static int config_chipset_for_dma (ide_drive_t *drive)
146 {
147         u8 speed        = ide_dma_speed(drive, jmicron_ratemask(drive));
148
149         config_jmicron_chipset_for_pio(drive, !speed);
150         jmicron_tune_chipset(drive, speed);
151         return ide_dma_enable(drive);
152 }
153
154 /**
155  *      jmicron_configure_drive_for_dma -       set up for DMA transfers
156  *      @drive: drive we are going to set up
157  *
158  *      As the JMicron snoops for timings all we actually need to do is
159  *      make sure we don't set an invalid mode.
160  */
161
162 static int jmicron_config_drive_for_dma (ide_drive_t *drive)
163 {
164         ide_hwif_t *hwif        = drive->hwif;
165
166         if (ide_use_dma(drive)) {
167                 if (config_chipset_for_dma(drive))
168                         return hwif->ide_dma_on(drive);
169         }
170         config_jmicron_chipset_for_pio(drive, 1);
171         return hwif->ide_dma_off_quietly(drive);
172 }
173
174 /**
175  *      init_hwif_jmicron       -       set up hwif structs
176  *      @hwif: interface to set up
177  *
178  *      Minimal set up is required for the Jmicron hardware.
179  */
180
181 static void __devinit init_hwif_jmicron(ide_hwif_t *hwif)
182 {
183         hwif->speedproc = &jmicron_tune_chipset;
184         hwif->tuneproc  = &jmicron_tuneproc;
185
186         hwif->drives[0].autotune = 1;
187         hwif->drives[1].autotune = 1;
188
189         if (!hwif->dma_base)
190                 goto fallback;
191
192         hwif->atapi_dma = 1;
193         hwif->ultra_mask = 0x7f;
194         hwif->mwdma_mask = 0x07;
195
196         hwif->ide_dma_check = &jmicron_config_drive_for_dma;
197         if (!(hwif->udma_four))
198                 hwif->udma_four = ata66_jmicron(hwif);
199
200         hwif->autodma = 1;
201         hwif->drives[0].autodma = hwif->autodma;
202         hwif->drives[1].autodma = hwif->autodma;
203         return;
204 fallback:
205         hwif->autodma = 0;
206         return;
207 }
208
209 #define DECLARE_JMB_DEV(name_str)                       \
210         {                                               \
211                 .name           = name_str,             \
212                 .init_hwif      = init_hwif_jmicron,    \
213                 .channels       = 2,                    \
214                 .autodma        = AUTODMA,              \
215                 .bootable       = ON_BOARD,             \
216                 .enablebits     = { {0x40, 1, 1}, {0x40, 0x10, 0x10} }, \
217         }
218
219 static ide_pci_device_t jmicron_chipsets[] __devinitdata = {
220         /* 0 */ DECLARE_JMB_DEV("JMB361"),
221         /* 1 */ DECLARE_JMB_DEV("JMB363"),
222         /* 2 */ DECLARE_JMB_DEV("JMB365"),
223         /* 3 */ DECLARE_JMB_DEV("JMB366"),
224         /* 4 */ DECLARE_JMB_DEV("JMB368"),
225 };
226
227 /**
228  *      jmicron_init_one        -       pci layer discovery entry
229  *      @dev: PCI device
230  *      @id: ident table entry
231  *
232  *      Called by the PCI code when it finds a Jmicron controller.
233  *      We then use the IDE PCI generic helper to do most of the work.
234  */
235
236 static int __devinit jmicron_init_one(struct pci_dev *dev, const struct pci_device_id *id)
237 {
238         ide_setup_pci_device(dev, &jmicron_chipsets[id->driver_data]);
239         return 0;
240 }
241
242 static struct pci_device_id jmicron_pci_tbl[] = {
243         { PCI_DEVICE(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB361), 0},
244         { PCI_DEVICE(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB363), 1},
245         { PCI_DEVICE(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB365), 2},
246         { PCI_DEVICE(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB366), 3},
247         { PCI_DEVICE(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB368), 4},
248         { 0, },
249 };
250
251 MODULE_DEVICE_TABLE(pci, jmicron_pci_tbl);
252
253 static struct pci_driver driver = {
254         .name           = "JMicron IDE",
255         .id_table       = jmicron_pci_tbl,
256         .probe          = jmicron_init_one,
257 };
258
259 static int __init jmicron_ide_init(void)
260 {
261         return ide_pci_register_driver(&driver);
262 }
263
264 module_init(jmicron_ide_init);
265
266 MODULE_AUTHOR("Alan Cox");
267 MODULE_DESCRIPTION("PCI driver module for the JMicron in legacy modes");
268 MODULE_LICENSE("GPL");