blob: 3f35386d9cad720402b6c56311a41b8c3d56870d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Bartlomiej Zolnierkiewicza7181222007-10-16 22:29:58 +02002 * linux/drivers/ide/pci/sis5513.c Version 0.31 Aug 9, 2007
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
4 * Copyright (C) 1999-2000 Andre Hedrick <andre@linux-ide.org>
5 * Copyright (C) 2002 Lionel Bouton <Lionel.Bouton@inet6.fr>, Maintainer
6 * Copyright (C) 2003 Vojtech Pavlik <vojtech@suse.cz>
Bartlomiej Zolnierkiewicz6b8cf772007-05-16 00:51:42 +02007 * Copyright (C) 2007 Bartlomiej Zolnierkiewicz
8 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * May be copied or modified under the terms of the GNU General Public License
10 *
11 *
12 * Thanks :
13 *
14 * SiS Taiwan : for direct support and hardware.
15 * Daniela Engert : for initial ATA100 advices and numerous others.
16 * John Fremlin, Manfred Spraul, Dave Morgan, Peter Kjellerstedt :
17 * for checking code correctness, providing patches.
18 *
19 *
20 * Original tests and design on the SiS620 chipset.
21 * ATA100 tests and design on the SiS735 chipset.
22 * ATA16/33 support from specs
23 * ATA133 support for SiS961/962 by L.C. Chang <lcchang@sis.com.tw>
24 * ATA133 961/962/963 fixes by Vojtech Pavlik <vojtech@suse.cz>
25 *
26 * Documentation:
27 * SiS chipset documentation available under NDA to companies only
28 * (not to individuals).
29 */
30
31/*
32 * The original SiS5513 comes from a SiS5511/55112/5513 chipset. The original
33 * SiS5513 was also used in the SiS5596/5513 chipset. Thus if we see a SiS5511
34 * or SiS5596, we can assume we see the first MWDMA-16 capable SiS5513 chip.
35 *
36 * Later SiS chipsets integrated the 5513 functionality into the NorthBridge,
37 * starting with SiS5571 and up to SiS745. The PCI ID didn't change, though. We
38 * can figure out that we have a more modern and more capable 5513 by looking
39 * for the respective NorthBridge IDs.
40 *
41 * Even later (96x family) SiS chipsets use the MuTIOL link and place the 5513
42 * into the SouthBrige. Here we cannot rely on looking up the NorthBridge PCI
43 * ID, while the now ATA-133 capable 5513 still has the same PCI ID.
44 * Fortunately the 5513 can be 'unmasked' by fiddling with some config space
45 * bits, changing its device id to the true one - 5517 for 961 and 5518 for
46 * 962/963.
47 */
48
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include <linux/types.h>
50#include <linux/module.h>
51#include <linux/kernel.h>
52#include <linux/delay.h>
53#include <linux/timer.h>
54#include <linux/mm.h>
55#include <linux/ioport.h>
56#include <linux/blkdev.h>
57#include <linux/hdreg.h>
58
59#include <linux/interrupt.h>
60#include <linux/pci.h>
61#include <linux/init.h>
62#include <linux/ide.h>
63
64#include <asm/irq.h>
65
66#include "ide-timing.h"
67
Linus Torvalds1da177e2005-04-16 15:20:36 -070068/* registers layout and init values are chipset family dependant */
69
70#define ATA_16 0x01
71#define ATA_33 0x02
72#define ATA_66 0x03
73#define ATA_100a 0x04 // SiS730/SiS550 is ATA100 with ATA66 layout
74#define ATA_100 0x05
75#define ATA_133a 0x06 // SiS961b with 133 support
76#define ATA_133 0x07 // SiS962/963
77
78static u8 chipset_family;
79
80/*
81 * Devices supported
82 */
83static const struct {
84 const char *name;
85 u16 host_id;
86 u8 chipset_family;
87 u8 flags;
88} SiSHostChipInfo[] = {
David Wang47d4b902006-09-08 09:47:51 -070089 { "SiS968", PCI_DEVICE_ID_SI_968, ATA_133 },
90 { "SiS966", PCI_DEVICE_ID_SI_966, ATA_133 },
Aurelien Jarno14351f82005-11-19 21:43:45 +010091 { "SiS965", PCI_DEVICE_ID_SI_965, ATA_133 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 { "SiS745", PCI_DEVICE_ID_SI_745, ATA_100 },
93 { "SiS735", PCI_DEVICE_ID_SI_735, ATA_100 },
94 { "SiS733", PCI_DEVICE_ID_SI_733, ATA_100 },
95 { "SiS635", PCI_DEVICE_ID_SI_635, ATA_100 },
96 { "SiS633", PCI_DEVICE_ID_SI_633, ATA_100 },
97
98 { "SiS730", PCI_DEVICE_ID_SI_730, ATA_100a },
99 { "SiS550", PCI_DEVICE_ID_SI_550, ATA_100a },
100
101 { "SiS640", PCI_DEVICE_ID_SI_640, ATA_66 },
102 { "SiS630", PCI_DEVICE_ID_SI_630, ATA_66 },
103 { "SiS620", PCI_DEVICE_ID_SI_620, ATA_66 },
104 { "SiS540", PCI_DEVICE_ID_SI_540, ATA_66 },
105 { "SiS530", PCI_DEVICE_ID_SI_530, ATA_66 },
106
107 { "SiS5600", PCI_DEVICE_ID_SI_5600, ATA_33 },
108 { "SiS5598", PCI_DEVICE_ID_SI_5598, ATA_33 },
109 { "SiS5597", PCI_DEVICE_ID_SI_5597, ATA_33 },
110 { "SiS5591/2", PCI_DEVICE_ID_SI_5591, ATA_33 },
111 { "SiS5582", PCI_DEVICE_ID_SI_5582, ATA_33 },
112 { "SiS5581", PCI_DEVICE_ID_SI_5581, ATA_33 },
113
114 { "SiS5596", PCI_DEVICE_ID_SI_5596, ATA_16 },
115 { "SiS5571", PCI_DEVICE_ID_SI_5571, ATA_16 },
Alan Coxd266ab82006-03-28 01:56:31 -0800116 { "SiS5517", PCI_DEVICE_ID_SI_5517, ATA_16 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 { "SiS551x", PCI_DEVICE_ID_SI_5511, ATA_16 },
118};
119
120/* Cycle time bits and values vary across chip dma capabilities
121 These three arrays hold the register layout and the values to set.
122 Indexed by chipset_family and (dma_mode - XFER_UDMA_0) */
123
124/* {0, ATA_16, ATA_33, ATA_66, ATA_100a, ATA_100, ATA_133} */
125static u8 cycle_time_offset[] = {0,0,5,4,4,0,0};
126static u8 cycle_time_range[] = {0,0,2,3,3,4,4};
127static u8 cycle_time_value[][XFER_UDMA_6 - XFER_UDMA_0 + 1] = {
128 {0,0,0,0,0,0,0}, /* no udma */
129 {0,0,0,0,0,0,0}, /* no udma */
130 {3,2,1,0,0,0,0}, /* ATA_33 */
131 {7,5,3,2,1,0,0}, /* ATA_66 */
132 {7,5,3,2,1,0,0}, /* ATA_100a (730 specific), differences are on cycle_time range and offset */
133 {11,7,5,4,2,1,0}, /* ATA_100 */
134 {15,10,7,5,3,2,1}, /* ATA_133a (earliest 691 southbridges) */
135 {15,10,7,5,3,2,1}, /* ATA_133 */
136};
137/* CRC Valid Setup Time vary across IDE clock setting 33/66/100/133
138 See SiS962 data sheet for more detail */
139static u8 cvs_time_value[][XFER_UDMA_6 - XFER_UDMA_0 + 1] = {
140 {0,0,0,0,0,0,0}, /* no udma */
141 {0,0,0,0,0,0,0}, /* no udma */
142 {2,1,1,0,0,0,0},
143 {4,3,2,1,0,0,0},
144 {4,3,2,1,0,0,0},
145 {6,4,3,1,1,1,0},
146 {9,6,4,2,2,2,2},
147 {9,6,4,2,2,2,2},
148};
149/* Initialize time, Active time, Recovery time vary across
150 IDE clock settings. These 3 arrays hold the register value
151 for PIO0/1/2/3/4 and DMA0/1/2 mode in order */
152static u8 ini_time_value[][8] = {
153 {0,0,0,0,0,0,0,0},
154 {0,0,0,0,0,0,0,0},
155 {2,1,0,0,0,1,0,0},
156 {4,3,1,1,1,3,1,1},
157 {4,3,1,1,1,3,1,1},
158 {6,4,2,2,2,4,2,2},
159 {9,6,3,3,3,6,3,3},
160 {9,6,3,3,3,6,3,3},
161};
162static u8 act_time_value[][8] = {
163 {0,0,0,0,0,0,0,0},
164 {0,0,0,0,0,0,0,0},
165 {9,9,9,2,2,7,2,2},
166 {19,19,19,5,4,14,5,4},
167 {19,19,19,5,4,14,5,4},
168 {28,28,28,7,6,21,7,6},
169 {38,38,38,10,9,28,10,9},
170 {38,38,38,10,9,28,10,9},
171};
172static u8 rco_time_value[][8] = {
173 {0,0,0,0,0,0,0,0},
174 {0,0,0,0,0,0,0,0},
175 {9,2,0,2,0,7,1,1},
176 {19,5,1,5,2,16,3,2},
177 {19,5,1,5,2,16,3,2},
178 {30,9,3,9,4,25,6,4},
179 {40,12,4,12,5,34,12,5},
180 {40,12,4,12,5,34,12,5},
181};
182
183/*
184 * Printing configuration
185 */
186/* Used for chipset type printing at boot time */
187static char* chipset_capability[] = {
188 "ATA", "ATA 16",
189 "ATA 33", "ATA 66",
190 "ATA 100 (1st gen)", "ATA 100 (2nd gen)",
191 "ATA 133 (1st gen)", "ATA 133 (2nd gen)"
192};
193
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194/*
195 * Configuration functions
196 */
Bartlomiej Zolnierkiewiczc77a89c2007-10-16 22:29:52 +0200197
198static u8 sis_ata133_get_base(ide_drive_t *drive)
199{
200 struct pci_dev *dev = drive->hwif->pci_dev;
201 u32 reg54 = 0;
202
203 pci_read_config_dword(dev, 0x54, &reg54);
204
205 return ((reg54 & 0x40000000) ? 0x70 : 0x40) + drive->dn * 4;
206}
207
208static void sis_ata16_program_timings(ide_drive_t *drive, const u8 mode)
209{
210 struct pci_dev *dev = drive->hwif->pci_dev;
211 u16 t1 = 0;
212 u8 drive_pci = 0x40 + drive->dn * 2;
213
214 const u16 pio_timings[] = { 0x000, 0x607, 0x404, 0x303, 0x301 };
215 const u16 mwdma_timings[] = { 0x008, 0x302, 0x301 };
216
217 pci_read_config_word(dev, drive_pci, &t1);
218
219 /* clear active/recovery timings */
220 t1 &= ~0x070f;
221 if (mode >= XFER_MW_DMA_0) {
222 if (chipset_family > ATA_16)
223 t1 &= ~0x8000; /* disable UDMA */
224 t1 |= mwdma_timings[mode - XFER_MW_DMA_0];
225 } else
226 t1 |= pio_timings[mode - XFER_PIO_0];
227
228 pci_write_config_word(dev, drive_pci, t1);
229}
230
231static void sis_ata100_program_timings(ide_drive_t *drive, const u8 mode)
232{
233 struct pci_dev *dev = drive->hwif->pci_dev;
234 u8 t1, drive_pci = 0x40 + drive->dn * 2;
235
236 /* timing bits: 7:4 active 3:0 recovery */
237 const u8 pio_timings[] = { 0x00, 0x67, 0x44, 0x33, 0x31 };
238 const u8 mwdma_timings[] = { 0x08, 0x32, 0x31 };
239
240 if (mode >= XFER_MW_DMA_0) {
241 u8 t2 = 0;
242
243 pci_read_config_byte(dev, drive_pci, &t2);
244 t2 &= ~0x80; /* disable UDMA */
245 pci_write_config_byte(dev, drive_pci, t2);
246
247 t1 = mwdma_timings[mode - XFER_MW_DMA_0];
248 } else
249 t1 = pio_timings[mode - XFER_PIO_0];
250
251 pci_write_config_byte(dev, drive_pci + 1, t1);
252}
253
254static void sis_ata133_program_timings(ide_drive_t *drive, const u8 mode)
255{
256 struct pci_dev *dev = drive->hwif->pci_dev;
257 u32 t1 = 0;
258 u8 drive_pci = sis_ata133_get_base(drive), clk, idx;
259
260 pci_read_config_dword(dev, drive_pci, &t1);
261
262 t1 &= 0xc0c00fff;
263 clk = (t1 & 0x08) ? ATA_133 : ATA_100;
264 if (mode >= XFER_MW_DMA_0) {
265 t1 &= ~0x04; /* disable UDMA */
266 idx = mode - XFER_MW_DMA_0 + 5;
Adrian Bunk3dfd6432007-10-20 00:32:29 +0200267 } else
Bartlomiej Zolnierkiewiczc77a89c2007-10-16 22:29:52 +0200268 idx = mode - XFER_PIO_0;
269 t1 |= ini_time_value[clk][idx] << 12;
270 t1 |= act_time_value[clk][idx] << 16;
271 t1 |= rco_time_value[clk][idx] << 24;
272
273 pci_write_config_dword(dev, drive_pci, t1);
274}
275
276static void sis_program_timings(ide_drive_t *drive, const u8 mode)
277{
278 if (chipset_family < ATA_100) /* ATA_16/33/66/100a */
279 sis_ata16_program_timings(drive, mode);
280 else if (chipset_family < ATA_133) /* ATA_100/133a */
281 sis_ata100_program_timings(drive, mode);
282 else /* ATA_133 */
283 sis_ata133_program_timings(drive, mode);
284}
285
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286static void config_drive_art_rwp (ide_drive_t *drive)
287{
288 ide_hwif_t *hwif = HWIF(drive);
289 struct pci_dev *dev = hwif->pci_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 u8 reg4bh = 0;
Bartlomiej Zolnierkiewiczd83fca52007-10-16 22:29:56 +0200291 u8 rw_prefetch = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 pci_read_config_byte(dev, 0x4b, &reg4bh);
294
Bartlomiej Zolnierkiewiczd83fca52007-10-16 22:29:56 +0200295 if (drive->media == ide_disk)
296 rw_prefetch = 0x11 << drive->dn;
297
298 if ((reg4bh & (0x11 << drive->dn)) != rw_prefetch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 pci_write_config_byte(dev, 0x4b, reg4bh|rw_prefetch);
300}
301
Bartlomiej Zolnierkiewicz88b2b322007-10-13 17:47:51 +0200302static void sis_set_pio_mode(ide_drive_t *drive, const u8 pio)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 config_drive_art_rwp(drive);
Bartlomiej Zolnierkiewiczc77a89c2007-10-16 22:29:52 +0200305 sis_program_timings(drive, XFER_PIO_0 + pio);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306}
307
Bartlomiej Zolnierkiewicz428c6442008-01-25 22:17:18 +0100308static void sis_ata133_program_udma_timings(ide_drive_t *drive, const u8 mode)
309{
310 struct pci_dev *dev = drive->hwif->pci_dev;
311 u32 regdw = 0;
312 u8 drive_pci = sis_ata133_get_base(drive), clk, idx;
313
314 pci_read_config_dword(dev, drive_pci, &regdw);
315
316 regdw |= 0x04;
317 regdw &= 0xfffff00f;
318 /* check if ATA133 enable */
319 clk = (regdw & 0x08) ? ATA_133 : ATA_100;
320 idx = mode - XFER_UDMA_0;
321 regdw |= cycle_time_value[clk][idx] << 4;
322 regdw |= cvs_time_value[clk][idx] << 8;
323
324 pci_write_config_dword(dev, drive_pci, regdw);
325}
326
327static void sis_ata33_program_udma_timings(ide_drive_t *drive, const u8 mode)
328{
329 struct pci_dev *dev = drive->hwif->pci_dev;
330 u8 drive_pci = 0x40 + drive->dn * 2, reg = 0, i = chipset_family;
331
332 pci_read_config_byte(dev, drive_pci + 1, &reg);
333
334 /* force the UDMA bit on if we want to use UDMA */
335 reg |= 0x80;
336 /* clean reg cycle time bits */
337 reg &= ~((0xff >> (8 - cycle_time_range[i])) << cycle_time_offset[i]);
338 /* set reg cycle time bits */
339 reg |= cycle_time_value[i][mode - XFER_UDMA_0] << cycle_time_offset[i];
340
341 pci_write_config_byte(dev, drive_pci + 1, reg);
342}
343
344static void sis_program_udma_timings(ide_drive_t *drive, const u8 mode)
345{
346 if (chipset_family >= ATA_133) /* ATA_133 */
347 sis_ata133_program_udma_timings(drive, mode);
348 else /* ATA_33/66/100a/100/133a */
349 sis_ata33_program_udma_timings(drive, mode);
350}
351
Bartlomiej Zolnierkiewicz88b2b322007-10-13 17:47:51 +0200352static void sis_set_dma_mode(ide_drive_t *drive, const u8 speed)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 /* Config chip for mode */
355 switch(speed) {
356 case XFER_UDMA_6:
357 case XFER_UDMA_5:
358 case XFER_UDMA_4:
359 case XFER_UDMA_3:
360 case XFER_UDMA_2:
361 case XFER_UDMA_1:
362 case XFER_UDMA_0:
Bartlomiej Zolnierkiewicz428c6442008-01-25 22:17:18 +0100363 sis_program_udma_timings(drive, speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 break;
365 case XFER_MW_DMA_2:
366 case XFER_MW_DMA_1:
367 case XFER_MW_DMA_0:
Bartlomiej Zolnierkiewiczc77a89c2007-10-16 22:29:52 +0200368 sis_program_timings(drive, speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 break;
Bartlomiej Zolnierkiewicz6b8cf772007-05-16 00:51:42 +0200370 default:
Bartlomiej Zolnierkiewicz6b8cf772007-05-16 00:51:42 +0200371 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373}
374
Bartlomiej Zolnierkiewicz3160d542007-10-11 23:53:59 +0200375static u8 sis5513_ata133_udma_filter(ide_drive_t *drive)
376{
377 struct pci_dev *dev = drive->hwif->pci_dev;
Bartlomiej Zolnierkiewiczc77a89c2007-10-16 22:29:52 +0200378 u32 regdw = 0;
379 u8 drive_pci = sis_ata133_get_base(drive);
Bartlomiej Zolnierkiewicz3160d542007-10-11 23:53:59 +0200380
Bartlomiej Zolnierkiewicz3160d542007-10-11 23:53:59 +0200381 pci_read_config_dword(dev, drive_pci, &regdw);
382
383 /* if ATA133 disable, we should not set speed above UDMA5 */
384 return (regdw & 0x08) ? ATA_UDMA6 : ATA_UDMA5;
385}
386
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387/* Chip detection and general config */
Adrian Bunk2b0c4be2005-05-05 16:15:49 -0700388static unsigned int __devinit init_chipset_sis5513 (struct pci_dev *dev, const char *name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389{
390 struct pci_dev *host;
391 int i = 0;
392
393 chipset_family = 0;
394
395 for (i = 0; i < ARRAY_SIZE(SiSHostChipInfo) && !chipset_family; i++) {
396
Alan Cox40cddf22006-09-30 23:27:30 -0700397 host = pci_get_device(PCI_VENDOR_ID_SI, SiSHostChipInfo[i].host_id, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398
399 if (!host)
400 continue;
401
402 chipset_family = SiSHostChipInfo[i].chipset_family;
403
404 /* Special case for SiS630 : 630S/ET is ATA_100a */
405 if (SiSHostChipInfo[i].host_id == PCI_DEVICE_ID_SI_630) {
Auke Kok44c10132007-06-08 15:46:36 -0700406 if (host->revision >= 0x30)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 chipset_family = ATA_100a;
408 }
Alan Cox40cddf22006-09-30 23:27:30 -0700409 pci_dev_put(host);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410
411 printk(KERN_INFO "SIS5513: %s %s controller\n",
412 SiSHostChipInfo[i].name, chipset_capability[chipset_family]);
413 }
414
415 if (!chipset_family) { /* Belongs to pci-quirks */
416
417 u32 idemisc;
418 u16 trueid;
419
420 /* Disable ID masking and register remapping */
421 pci_read_config_dword(dev, 0x54, &idemisc);
422 pci_write_config_dword(dev, 0x54, (idemisc & 0x7fffffff));
423 pci_read_config_word(dev, PCI_DEVICE_ID, &trueid);
424 pci_write_config_dword(dev, 0x54, idemisc);
425
426 if (trueid == 0x5518) {
427 printk(KERN_INFO "SIS5513: SiS 962/963 MuTIOL IDE UDMA133 controller\n");
428 chipset_family = ATA_133;
429
430 /* Check for 5513 compability mapping
431 * We must use this, else the port enabled code will fail,
432 * as it expects the enablebits at 0x4a.
433 */
434 if ((idemisc & 0x40000000) == 0) {
435 pci_write_config_dword(dev, 0x54, idemisc | 0x40000000);
436 printk(KERN_INFO "SIS5513: Switching to 5513 register mapping\n");
437 }
438 }
439 }
440
441 if (!chipset_family) { /* Belongs to pci-quirks */
442
443 struct pci_dev *lpc_bridge;
444 u16 trueid;
445 u8 prefctl;
446 u8 idecfg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
448 pci_read_config_byte(dev, 0x4a, &idecfg);
449 pci_write_config_byte(dev, 0x4a, idecfg | 0x10);
450 pci_read_config_word(dev, PCI_DEVICE_ID, &trueid);
451 pci_write_config_byte(dev, 0x4a, idecfg);
452
453 if (trueid == 0x5517) { /* SiS 961/961B */
454
Alan Coxb1489002006-12-08 02:39:58 -0800455 lpc_bridge = pci_get_slot(dev->bus, 0x10); /* Bus 0, Dev 2, Fn 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 pci_read_config_byte(dev, 0x49, &prefctl);
Alan Coxb1489002006-12-08 02:39:58 -0800457 pci_dev_put(lpc_bridge);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458
Auke Kok44c10132007-06-08 15:46:36 -0700459 if (lpc_bridge->revision == 0x10 && (prefctl & 0x80)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 printk(KERN_INFO "SIS5513: SiS 961B MuTIOL IDE UDMA133 controller\n");
461 chipset_family = ATA_133a;
462 } else {
463 printk(KERN_INFO "SIS5513: SiS 961 MuTIOL IDE UDMA100 controller\n");
464 chipset_family = ATA_100;
465 }
466 }
467 }
468
469 if (!chipset_family)
470 return -1;
471
472 /* Make general config ops here
473 1/ tell IDE channels to operate in Compatibility mode only
474 2/ tell old chips to allow per drive IDE timings */
475
476 {
477 u8 reg;
478 u16 regw;
479
480 switch(chipset_family) {
481 case ATA_133:
482 /* SiS962 operation mode */
483 pci_read_config_word(dev, 0x50, &regw);
484 if (regw & 0x08)
485 pci_write_config_word(dev, 0x50, regw&0xfff7);
486 pci_read_config_word(dev, 0x52, &regw);
487 if (regw & 0x08)
488 pci_write_config_word(dev, 0x52, regw&0xfff7);
489 break;
490 case ATA_133a:
491 case ATA_100:
492 /* Fixup latency */
493 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x80);
494 /* Set compatibility bit */
495 pci_read_config_byte(dev, 0x49, &reg);
496 if (!(reg & 0x01)) {
497 pci_write_config_byte(dev, 0x49, reg|0x01);
498 }
499 break;
500 case ATA_100a:
501 case ATA_66:
502 /* Fixup latency */
503 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x10);
504
505 /* On ATA_66 chips the bit was elsewhere */
506 pci_read_config_byte(dev, 0x52, &reg);
507 if (!(reg & 0x04)) {
508 pci_write_config_byte(dev, 0x52, reg|0x04);
509 }
510 break;
511 case ATA_33:
512 /* On ATA_33 we didn't have a single bit to set */
513 pci_read_config_byte(dev, 0x09, &reg);
514 if ((reg & 0x0f) != 0x00) {
515 pci_write_config_byte(dev, 0x09, reg&0xf0);
516 }
517 case ATA_16:
518 /* force per drive recovery and active timings
519 needed on ATA_33 and below chips */
520 pci_read_config_byte(dev, 0x52, &reg);
521 if (!(reg & 0x08)) {
522 pci_write_config_byte(dev, 0x52, reg|0x08);
523 }
524 break;
525 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 }
527
528 return 0;
529}
530
Bartlomiej Zolnierkiewiczf2befd92007-07-09 23:17:58 +0200531struct sis_laptop {
532 u16 device;
533 u16 subvendor;
534 u16 subdevice;
535};
536
537static const struct sis_laptop sis_laptop[] = {
538 /* devid, subvendor, subdev */
539 { 0x5513, 0x1043, 0x1107 }, /* ASUS A6K */
David Lamparter1955f682007-08-01 23:46:44 +0200540 { 0x5513, 0x1734, 0x105f }, /* FSC Amilo A1630 */
Gabriel Craciunescua1d85862007-11-27 21:35:52 +0100541 { 0x5513, 0x1071, 0x8640 }, /* EasyNote K5305 */
Bartlomiej Zolnierkiewiczf2befd92007-07-09 23:17:58 +0200542 /* end marker */
543 { 0, }
544};
545
Bartlomiej Zolnierkiewicz49521f92007-07-09 23:17:58 +0200546static u8 __devinit ata66_sis5513(ide_hwif_t *hwif)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547{
Bartlomiej Zolnierkiewiczf2befd92007-07-09 23:17:58 +0200548 struct pci_dev *pdev = hwif->pci_dev;
549 const struct sis_laptop *lap = &sis_laptop[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 u8 ata66 = 0;
551
Bartlomiej Zolnierkiewiczf2befd92007-07-09 23:17:58 +0200552 while (lap->device) {
553 if (lap->device == pdev->device &&
554 lap->subvendor == pdev->subsystem_vendor &&
555 lap->subdevice == pdev->subsystem_device)
556 return ATA_CBL_PATA40_SHORT;
557 lap++;
558 }
559
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 if (chipset_family >= ATA_133) {
561 u16 regw = 0;
562 u16 reg_addr = hwif->channel ? 0x52: 0x50;
563 pci_read_config_word(hwif->pci_dev, reg_addr, &regw);
564 ata66 = (regw & 0x8000) ? 0 : 1;
565 } else if (chipset_family >= ATA_66) {
566 u8 reg48h = 0;
567 u8 mask = hwif->channel ? 0x20 : 0x10;
568 pci_read_config_byte(hwif->pci_dev, 0x48, &reg48h);
569 ata66 = (reg48h & mask) ? 0 : 1;
570 }
Bartlomiej Zolnierkiewicz49521f92007-07-09 23:17:58 +0200571
572 return ata66 ? ATA_CBL_PATA80 : ATA_CBL_PATA40;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573}
574
Adrian Bunk2b0c4be2005-05-05 16:15:49 -0700575static void __devinit init_hwif_sis5513 (ide_hwif_t *hwif)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576{
Bartlomiej Zolnierkiewicz18137202007-05-10 00:01:07 +0200577 u8 udma_rates[] = { 0x00, 0x00, 0x07, 0x1f, 0x3f, 0x3f, 0x7f, 0x7f };
578
Bartlomiej Zolnierkiewicz26bcb872007-10-11 23:54:00 +0200579 hwif->set_pio_mode = &sis_set_pio_mode;
Bartlomiej Zolnierkiewicz88b2b322007-10-13 17:47:51 +0200580 hwif->set_dma_mode = &sis_set_dma_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581
Bartlomiej Zolnierkiewicz3160d542007-10-11 23:53:59 +0200582 if (chipset_family >= ATA_133)
583 hwif->udma_filter = sis5513_ata133_udma_filter;
584
Bartlomiej Zolnierkiewicz4960ab72007-10-16 22:29:53 +0200585 if (hwif->dma_base == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587
Bartlomiej Zolnierkiewicz18137202007-05-10 00:01:07 +0200588 hwif->ultra_mask = udma_rates[chipset_family];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589
Bartlomiej Zolnierkiewicz49521f92007-07-09 23:17:58 +0200590 if (hwif->cbl != ATA_CBL_PATA40_SHORT)
591 hwif->cbl = ata66_sis5513(hwif);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592}
593
Bartlomiej Zolnierkiewicz85620432007-10-20 00:32:34 +0200594static const struct ide_port_info sis5513_chipset __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 .name = "SIS5513",
596 .init_chipset = init_chipset_sis5513,
597 .init_hwif = init_hwif_sis5513,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 .enablebits = {{0x4a,0x02,0x02}, {0x4a,0x04,0x04}},
Bartlomiej Zolnierkiewicz3985ee32007-10-19 00:30:11 +0200599 .host_flags = IDE_HFLAG_LEGACY_IRQS | IDE_HFLAG_NO_AUTODMA |
600 IDE_HFLAG_BOOTABLE,
Bartlomiej Zolnierkiewicz4099d142007-07-20 01:11:59 +0200601 .pio_mask = ATA_PIO4,
Bartlomiej Zolnierkiewicz5f8b6c32007-10-19 00:30:07 +0200602 .mwdma_mask = ATA_MWDMA2,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603};
604
605static int __devinit sis5513_init_one(struct pci_dev *dev, const struct pci_device_id *id)
606{
607 return ide_setup_pci_device(dev, &sis5513_chipset);
608}
609
Bartlomiej Zolnierkiewicz9cbcc5e2007-10-16 22:29:56 +0200610static const struct pci_device_id sis5513_pci_tbl[] = {
611 { PCI_VDEVICE(SI, PCI_DEVICE_ID_SI_5513), 0 },
612 { PCI_VDEVICE(SI, PCI_DEVICE_ID_SI_5518), 0 },
613 { PCI_VDEVICE(SI, PCI_DEVICE_ID_SI_1180), 0 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 { 0, },
615};
616MODULE_DEVICE_TABLE(pci, sis5513_pci_tbl);
617
618static struct pci_driver driver = {
619 .name = "SIS_IDE",
620 .id_table = sis5513_pci_tbl,
621 .probe = sis5513_init_one,
622};
623
Bartlomiej Zolnierkiewicz82ab1ee2007-01-27 13:46:56 +0100624static int __init sis5513_ide_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625{
626 return ide_pci_register_driver(&driver);
627}
628
629module_init(sis5513_ide_init);
630
631MODULE_AUTHOR("Lionel Bouton, L C Chang, Andre Hedrick, Vojtech Pavlik");
632MODULE_DESCRIPTION("PCI driver module for SIS IDE");
633MODULE_LICENSE("GPL");
634
635/*
636 * TODO:
637 * - CLEANUP
638 * - Use drivers/ide/ide-timing.h !
639 * - More checks in the config registers (force values instead of
640 * relying on the BIOS setting them correctly).
641 * - Further optimisations ?
642 * . for example ATA66+ regs 0x48 & 0x4A
643 */