]> bbs.cooldavid.org Git - net-next-2.6.git/blame - drivers/ata/pata_sis.c
libata: make ata_pci_init_one() not use ops->irq_handler and pi->sht
[net-next-2.6.git] / drivers / ata / pata_sis.c
CommitLineData
669a5db4
JG
1/*
2 * pata_sis.c - SiS ATA driver
3 *
4 * (C) 2005 Red Hat <alan@redhat.com>
4761c06c 5 * (C) 2007 Bartlomiej Zolnierkiewicz
669a5db4
JG
6 *
7 * Based upon linux/drivers/ide/pci/sis5513.c
8 * Copyright (C) 1999-2000 Andre Hedrick <andre@linux-ide.org>
9 * Copyright (C) 2002 Lionel Bouton <Lionel.Bouton@inet6.fr>, Maintainer
10 * Copyright (C) 2003 Vojtech Pavlik <vojtech@suse.cz>
11 * SiS Taiwan : for direct support and hardware.
12 * Daniela Engert : for initial ATA100 advices and numerous others.
13 * John Fremlin, Manfred Spraul, Dave Morgan, Peter Kjellerstedt :
14 * for checking code correctness, providing patches.
15 * Original tests and design on the SiS620 chipset.
16 * ATA100 tests and design on the SiS735 chipset.
17 * ATA16/33 support from specs
18 * ATA133 support for SiS961/962 by L.C. Chang <lcchang@sis.com.tw>
19 *
20 *
21 * TODO
22 * Check MWDMA on drives that don't support MWDMA speed pio cycles ?
23 * More Testing
24 */
25
26#include <linux/kernel.h>
27#include <linux/module.h>
28#include <linux/pci.h>
29#include <linux/init.h>
30#include <linux/blkdev.h>
31#include <linux/delay.h>
32#include <linux/device.h>
33#include <scsi/scsi_host.h>
34#include <linux/libata.h>
35#include <linux/ata.h>
4bb64fb9 36#include "sis.h"
669a5db4
JG
37
38#define DRV_NAME "pata_sis"
4761c06c 39#define DRV_VERSION "0.5.2"
669a5db4
JG
40
41struct sis_chipset {
1626aeb8
TH
42 u16 device; /* PCI host ID */
43 const struct ata_port_info *info; /* Info block */
669a5db4
JG
44 /* Probably add family, cable detect type etc here to clean
45 up code later */
46};
47
7dcbc1f2
JJ
48struct sis_laptop {
49 u16 device;
50 u16 subvendor;
51 u16 subdevice;
52};
53
54static const struct sis_laptop sis_laptop[] = {
55 /* devid, subvendor, subdev */
56 { 0x5513, 0x1043, 0x1107 }, /* ASUS A6K */
4f2d47cf 57 { 0x5513, 0x1734, 0x105F }, /* FSC Amilo A1630 */
1f71d067 58 { 0x5513, 0x1071, 0x8640 }, /* EasyNote K5305 */
7dcbc1f2
JJ
59 /* end marker */
60 { 0, }
61};
62
63static int sis_short_ata40(struct pci_dev *dev)
64{
65 const struct sis_laptop *lap = &sis_laptop[0];
66
67 while (lap->device) {
68 if (lap->device == dev->device &&
69 lap->subvendor == dev->subsystem_vendor &&
70 lap->subdevice == dev->subsystem_device)
71 return 1;
72 lap++;
73 }
74
75 return 0;
76}
77
669a5db4 78/**
dd668d15 79 * sis_old_port_base - return PCI configuration base for dev
669a5db4
JG
80 * @adev: device
81 *
82 * Returns the base of the PCI configuration registers for this port
83 * number.
84 */
85
dd668d15 86static int sis_old_port_base(struct ata_device *adev)
669a5db4 87{
9af5c9c9 88 return 0x40 + (4 * adev->link->ap->port_no) + (2 * adev->devno);
669a5db4
JG
89}
90
91/**
2e413f51 92 * sis_133_cable_detect - check for 40/80 pin
669a5db4 93 * @ap: Port
d4b2bab4 94 * @deadline: deadline jiffies for the operation
669a5db4
JG
95 *
96 * Perform cable detection for the later UDMA133 capable
97 * SiS chipset.
98 */
99
2e413f51 100static int sis_133_cable_detect(struct ata_port *ap)
669a5db4 101{
669a5db4
JG
102 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
103 u16 tmp;
104
669a5db4
JG
105 /* The top bit of this register is the cable detect bit */
106 pci_read_config_word(pdev, 0x50 + 2 * ap->port_no, &tmp);
7dcbc1f2 107 if ((tmp & 0x8000) && !sis_short_ata40(pdev))
2e413f51
AC
108 return ATA_CBL_PATA40;
109 return ATA_CBL_PATA80;
669a5db4
JG
110}
111
112/**
2e413f51 113 * sis_66_cable_detect - check for 40/80 pin
669a5db4 114 * @ap: Port
d4b2bab4 115 * @deadline: deadline jiffies for the operation
669a5db4
JG
116 *
117 * Perform cable detection on the UDMA66, UDMA100 and early UDMA133
118 * SiS IDE controllers.
119 */
120
2e413f51 121static int sis_66_cable_detect(struct ata_port *ap)
669a5db4 122{
669a5db4
JG
123 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
124 u8 tmp;
125
669a5db4
JG
126 /* Older chips keep cable detect in bits 4/5 of reg 0x48 */
127 pci_read_config_byte(pdev, 0x48, &tmp);
128 tmp >>= ap->port_no;
7dcbc1f2 129 if ((tmp & 0x10) && !sis_short_ata40(pdev))
2e413f51
AC
130 return ATA_CBL_PATA40;
131 return ATA_CBL_PATA80;
669a5db4
JG
132}
133
669a5db4
JG
134
135/**
2e413f51 136 * sis_pre_reset - probe begin
cc0680a5 137 * @link: ATA link
d4b2bab4 138 * @deadline: deadline jiffies for the operation
669a5db4
JG
139 *
140 * Set up cable type and use generic probe init
141 */
142
cc0680a5 143static int sis_pre_reset(struct ata_link *link, unsigned long deadline)
669a5db4
JG
144{
145 static const struct pci_bits sis_enable_bits[] = {
146 { 0x4aU, 1U, 0x02UL, 0x02UL }, /* port 0 */
147 { 0x4aU, 1U, 0x04UL, 0x04UL }, /* port 1 */
148 };
85cd7251 149
cc0680a5 150 struct ata_port *ap = link->ap;
669a5db4
JG
151 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
152
2e413f51
AC
153 if (!pci_test_config_bits(pdev, &sis_enable_bits[ap->port_no]))
154 return -ENOENT;
d4b2bab4 155
15ce0943
AC
156 /* Clear the FIFO settings. We can't enable the FIFO until
157 we know we are poking at a disk */
158 pci_write_config_byte(pdev, 0x4B, 0);
cc0680a5 159 return ata_std_prereset(link, deadline);
669a5db4
JG
160}
161
162
163/**
2e413f51 164 * sis_error_handler - Probe specified port on PATA host controller
669a5db4
JG
165 * @ap: Port to probe
166 *
167 * LOCKING:
168 * None (inherited from caller).
169 */
170
2e413f51 171static void sis_error_handler(struct ata_port *ap)
669a5db4 172{
2e413f51 173 ata_bmdma_drive_eh(ap, sis_pre_reset, ata_std_softreset, NULL, ata_std_postreset);
669a5db4
JG
174}
175
176/**
177 * sis_set_fifo - Set RWP fifo bits for this device
178 * @ap: Port
179 * @adev: Device
180 *
181 * SIS chipsets implement prefetch/postwrite bits for each device
182 * on both channels. This functionality is not ATAPI compatible and
183 * must be configured according to the class of device present
184 */
185
186static void sis_set_fifo(struct ata_port *ap, struct ata_device *adev)
187{
188 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
189 u8 fifoctrl;
190 u8 mask = 0x11;
191
192 mask <<= (2 * ap->port_no);
193 mask <<= adev->devno;
194
195 /* This holds various bits including the FIFO control */
196 pci_read_config_byte(pdev, 0x4B, &fifoctrl);
197 fifoctrl &= ~mask;
198
199 /* Enable for ATA (disk) only */
200 if (adev->class == ATA_DEV_ATA)
201 fifoctrl |= mask;
202 pci_write_config_byte(pdev, 0x4B, fifoctrl);
203}
204
205/**
206 * sis_old_set_piomode - Initialize host controller PATA PIO timings
207 * @ap: Port whose timings we are configuring
208 * @adev: Device we are configuring for.
209 *
210 * Set PIO mode for device, in host controller PCI config space. This
211 * function handles PIO set up for all chips that are pre ATA100 and
212 * also early ATA100 devices.
213 *
214 * LOCKING:
215 * None (inherited from caller).
216 */
217
218static void sis_old_set_piomode (struct ata_port *ap, struct ata_device *adev)
219{
220 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
dd668d15 221 int port = sis_old_port_base(adev);
669a5db4
JG
222 u8 t1, t2;
223 int speed = adev->pio_mode - XFER_PIO_0;
224
225 const u8 active[] = { 0x00, 0x07, 0x04, 0x03, 0x01 };
226 const u8 recovery[] = { 0x00, 0x06, 0x04, 0x03, 0x03 };
227
228 sis_set_fifo(ap, adev);
229
230 pci_read_config_byte(pdev, port, &t1);
231 pci_read_config_byte(pdev, port + 1, &t2);
232
233 t1 &= ~0x0F; /* Clear active/recovery timings */
234 t2 &= ~0x07;
235
236 t1 |= active[speed];
237 t2 |= recovery[speed];
238
239 pci_write_config_byte(pdev, port, t1);
240 pci_write_config_byte(pdev, port + 1, t2);
241}
242
243/**
4761c06c 244 * sis_100_set_piomode - Initialize host controller PATA PIO timings
669a5db4
JG
245 * @ap: Port whose timings we are configuring
246 * @adev: Device we are configuring for.
247 *
248 * Set PIO mode for device, in host controller PCI config space. This
249 * function handles PIO set up for ATA100 devices and early ATA133.
250 *
251 * LOCKING:
252 * None (inherited from caller).
253 */
254
255static void sis_100_set_piomode (struct ata_port *ap, struct ata_device *adev)
256{
257 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
dd668d15 258 int port = sis_old_port_base(adev);
669a5db4
JG
259 int speed = adev->pio_mode - XFER_PIO_0;
260
261 const u8 actrec[] = { 0x00, 0x67, 0x44, 0x33, 0x31 };
262
263 sis_set_fifo(ap, adev);
264
265 pci_write_config_byte(pdev, port, actrec[speed]);
266}
267
268/**
4761c06c 269 * sis_133_set_piomode - Initialize host controller PATA PIO timings
669a5db4
JG
270 * @ap: Port whose timings we are configuring
271 * @adev: Device we are configuring for.
272 *
273 * Set PIO mode for device, in host controller PCI config space. This
274 * function handles PIO set up for the later ATA133 devices.
275 *
276 * LOCKING:
277 * None (inherited from caller).
278 */
279
280static void sis_133_set_piomode (struct ata_port *ap, struct ata_device *adev)
281{
282 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
283 int port = 0x40;
284 u32 t1;
285 u32 reg54;
286 int speed = adev->pio_mode - XFER_PIO_0;
287
288 const u32 timing133[] = {
289 0x28269000, /* Recovery << 24 | Act << 16 | Ini << 12 */
290 0x0C266000,
291 0x04263000,
292 0x0C0A3000,
293 0x05093000
294 };
295 const u32 timing100[] = {
296 0x1E1C6000, /* Recovery << 24 | Act << 16 | Ini << 12 */
297 0x091C4000,
298 0x031C2000,
299 0x09072000,
300 0x04062000
301 };
302
303 sis_set_fifo(ap, adev);
304
305 /* If bit 14 is set then the registers are mapped at 0x70 not 0x40 */
306 pci_read_config_dword(pdev, 0x54, &reg54);
307 if (reg54 & 0x40000000)
308 port = 0x70;
309 port += 8 * ap->port_no + 4 * adev->devno;
310
311 pci_read_config_dword(pdev, port, &t1);
312 t1 &= 0xC0C00FFF; /* Mask out timing */
313
314 if (t1 & 0x08) /* 100 or 133 ? */
315 t1 |= timing133[speed];
316 else
317 t1 |= timing100[speed];
318 pci_write_config_byte(pdev, port, t1);
319}
320
321/**
322 * sis_old_set_dmamode - Initialize host controller PATA DMA timings
323 * @ap: Port whose timings we are configuring
324 * @adev: Device to program
325 *
326 * Set UDMA/MWDMA mode for device, in host controller PCI config space.
327 * Handles pre UDMA and UDMA33 devices. Supports MWDMA as well unlike
328 * the old ide/pci driver.
329 *
330 * LOCKING:
331 * None (inherited from caller).
332 */
333
334static void sis_old_set_dmamode (struct ata_port *ap, struct ata_device *adev)
335{
336 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
337 int speed = adev->dma_mode - XFER_MW_DMA_0;
dd668d15 338 int drive_pci = sis_old_port_base(adev);
669a5db4
JG
339 u16 timing;
340
4761c06c 341 const u16 mwdma_bits[] = { 0x008, 0x302, 0x301 };
669a5db4
JG
342 const u16 udma_bits[] = { 0xE000, 0xC000, 0xA000 };
343
344 pci_read_config_word(pdev, drive_pci, &timing);
345
346 if (adev->dma_mode < XFER_UDMA_0) {
347 /* bits 3-0 hold recovery timing bits 8-10 active timing and
1967b7ff 348 the higher bits are dependant on the device */
4761c06c 349 timing &= ~0x870F;
669a5db4 350 timing |= mwdma_bits[speed];
669a5db4
JG
351 } else {
352 /* Bit 15 is UDMA on/off, bit 13-14 are cycle time */
353 speed = adev->dma_mode - XFER_UDMA_0;
354 timing &= ~0x6000;
355 timing |= udma_bits[speed];
356 }
4761c06c 357 pci_write_config_word(pdev, drive_pci, timing);
669a5db4
JG
358}
359
360/**
361 * sis_66_set_dmamode - Initialize host controller PATA DMA timings
362 * @ap: Port whose timings we are configuring
363 * @adev: Device to program
364 *
365 * Set UDMA/MWDMA mode for device, in host controller PCI config space.
366 * Handles UDMA66 and early UDMA100 devices. Supports MWDMA as well unlike
367 * the old ide/pci driver.
368 *
369 * LOCKING:
370 * None (inherited from caller).
371 */
372
373static void sis_66_set_dmamode (struct ata_port *ap, struct ata_device *adev)
374{
375 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
376 int speed = adev->dma_mode - XFER_MW_DMA_0;
dd668d15 377 int drive_pci = sis_old_port_base(adev);
669a5db4
JG
378 u16 timing;
379
edeb614c 380 /* MWDMA 0-2 and UDMA 0-5 */
4761c06c 381 const u16 mwdma_bits[] = { 0x008, 0x302, 0x301 };
edeb614c 382 const u16 udma_bits[] = { 0xF000, 0xD000, 0xB000, 0xA000, 0x9000, 0x8000 };
669a5db4
JG
383
384 pci_read_config_word(pdev, drive_pci, &timing);
385
386 if (adev->dma_mode < XFER_UDMA_0) {
387 /* bits 3-0 hold recovery timing bits 8-10 active timing and
1967b7ff 388 the higher bits are dependant on the device, bit 15 udma */
dd668d15 389 timing &= ~0x870F;
669a5db4
JG
390 timing |= mwdma_bits[speed];
391 } else {
392 /* Bit 15 is UDMA on/off, bit 12-14 are cycle time */
393 speed = adev->dma_mode - XFER_UDMA_0;
dd668d15 394 timing &= ~0xF000;
669a5db4
JG
395 timing |= udma_bits[speed];
396 }
397 pci_write_config_word(pdev, drive_pci, timing);
398}
399
400/**
401 * sis_100_set_dmamode - Initialize host controller PATA DMA timings
402 * @ap: Port whose timings we are configuring
403 * @adev: Device to program
404 *
405 * Set UDMA/MWDMA mode for device, in host controller PCI config space.
406 * Handles UDMA66 and early UDMA100 devices.
407 *
408 * LOCKING:
409 * None (inherited from caller).
410 */
411
412static void sis_100_set_dmamode (struct ata_port *ap, struct ata_device *adev)
413{
414 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
415 int speed = adev->dma_mode - XFER_MW_DMA_0;
dd668d15
AC
416 int drive_pci = sis_old_port_base(adev);
417 u8 timing;
669a5db4 418
dd668d15 419 const u8 udma_bits[] = { 0x8B, 0x87, 0x85, 0x83, 0x82, 0x81};
669a5db4 420
dd668d15 421 pci_read_config_byte(pdev, drive_pci + 1, &timing);
669a5db4
JG
422
423 if (adev->dma_mode < XFER_UDMA_0) {
424 /* NOT SUPPORTED YET: NEED DATA SHEET. DITTO IN OLD DRIVER */
425 } else {
dd668d15 426 /* Bit 7 is UDMA on/off, bit 0-3 are cycle time */
669a5db4 427 speed = adev->dma_mode - XFER_UDMA_0;
dd668d15 428 timing &= ~0x8F;
669a5db4
JG
429 timing |= udma_bits[speed];
430 }
dd668d15 431 pci_write_config_byte(pdev, drive_pci + 1, timing);
669a5db4
JG
432}
433
434/**
435 * sis_133_early_set_dmamode - Initialize host controller PATA DMA timings
436 * @ap: Port whose timings we are configuring
437 * @adev: Device to program
438 *
439 * Set UDMA/MWDMA mode for device, in host controller PCI config space.
4761c06c 440 * Handles early SiS 961 bridges.
669a5db4
JG
441 *
442 * LOCKING:
443 * None (inherited from caller).
444 */
445
446static void sis_133_early_set_dmamode (struct ata_port *ap, struct ata_device *adev)
447{
448 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
449 int speed = adev->dma_mode - XFER_MW_DMA_0;
dd668d15
AC
450 int drive_pci = sis_old_port_base(adev);
451 u8 timing;
452 /* Low 4 bits are timing */
453 static const u8 udma_bits[] = { 0x8F, 0x8A, 0x87, 0x85, 0x83, 0x82, 0x81};
669a5db4 454
dd668d15 455 pci_read_config_byte(pdev, drive_pci + 1, &timing);
669a5db4
JG
456
457 if (adev->dma_mode < XFER_UDMA_0) {
458 /* NOT SUPPORTED YET: NEED DATA SHEET. DITTO IN OLD DRIVER */
459 } else {
dd668d15 460 /* Bit 7 is UDMA on/off, bit 0-3 are cycle time */
669a5db4 461 speed = adev->dma_mode - XFER_UDMA_0;
dd668d15 462 timing &= ~0x8F;
669a5db4
JG
463 timing |= udma_bits[speed];
464 }
dd668d15 465 pci_write_config_byte(pdev, drive_pci + 1, timing);
669a5db4
JG
466}
467
468/**
469 * sis_133_set_dmamode - Initialize host controller PATA DMA timings
470 * @ap: Port whose timings we are configuring
471 * @adev: Device to program
472 *
473 * Set UDMA/MWDMA mode for device, in host controller PCI config space.
669a5db4
JG
474 *
475 * LOCKING:
476 * None (inherited from caller).
477 */
478
479static void sis_133_set_dmamode (struct ata_port *ap, struct ata_device *adev)
480{
481 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
482 int speed = adev->dma_mode - XFER_MW_DMA_0;
483 int port = 0x40;
484 u32 t1;
485 u32 reg54;
486
487 /* bits 4- cycle time 8 - cvs time */
2e413f51
AC
488 static const u32 timing_u100[] = { 0x6B0, 0x470, 0x350, 0x140, 0x120, 0x110, 0x000 };
489 static const u32 timing_u133[] = { 0x9F0, 0x6A0, 0x470, 0x250, 0x230, 0x220, 0x210 };
669a5db4
JG
490
491 /* If bit 14 is set then the registers are mapped at 0x70 not 0x40 */
492 pci_read_config_dword(pdev, 0x54, &reg54);
493 if (reg54 & 0x40000000)
494 port = 0x70;
495 port += (8 * ap->port_no) + (4 * adev->devno);
496
497 pci_read_config_dword(pdev, port, &t1);
498
499 if (adev->dma_mode < XFER_UDMA_0) {
500 t1 &= ~0x00000004;
501 /* FIXME: need data sheet to add MWDMA here. Also lacking on
502 ide/pci driver */
503 } else {
504 speed = adev->dma_mode - XFER_UDMA_0;
505 /* if & 8 no UDMA133 - need info for ... */
506 t1 &= ~0x00000FF0;
507 t1 |= 0x00000004;
508 if (t1 & 0x08)
509 t1 |= timing_u133[speed];
510 else
511 t1 |= timing_u100[speed];
512 }
513 pci_write_config_dword(pdev, port, t1);
514}
515
516static struct scsi_host_template sis_sht = {
68d1d07b 517 ATA_BMDMA_SHT(DRV_NAME),
669a5db4
JG
518};
519
029cfd6b
TH
520static struct ata_port_operations sis_133_for_sata_ops = {
521 .inherits = &ata_bmdma_port_ops,
669a5db4
JG
522 .set_piomode = sis_133_set_piomode,
523 .set_dmamode = sis_133_set_dmamode,
2e413f51 524 .cable_detect = sis_133_cable_detect,
029cfd6b 525};
669a5db4 526
029cfd6b
TH
527static struct ata_port_operations sis_base_ops = {
528 .inherits = &ata_bmdma_port_ops,
529 .error_handler = sis_error_handler,
669a5db4
JG
530};
531
029cfd6b
TH
532static struct ata_port_operations sis_133_ops = {
533 .inherits = &sis_base_ops,
a3cabb27
UK
534 .set_piomode = sis_133_set_piomode,
535 .set_dmamode = sis_133_set_dmamode,
a3cabb27 536 .cable_detect = sis_133_cable_detect,
a3cabb27
UK
537};
538
029cfd6b
TH
539static struct ata_port_operations sis_133_early_ops = {
540 .inherits = &sis_base_ops,
669a5db4
JG
541 .set_piomode = sis_100_set_piomode,
542 .set_dmamode = sis_133_early_set_dmamode,
2e413f51 543 .cable_detect = sis_66_cable_detect,
669a5db4
JG
544};
545
029cfd6b
TH
546static struct ata_port_operations sis_100_ops = {
547 .inherits = &sis_base_ops,
669a5db4
JG
548 .set_piomode = sis_100_set_piomode,
549 .set_dmamode = sis_100_set_dmamode,
2e413f51 550 .cable_detect = sis_66_cable_detect,
669a5db4
JG
551};
552
029cfd6b
TH
553static struct ata_port_operations sis_66_ops = {
554 .inherits = &sis_base_ops,
669a5db4
JG
555 .set_piomode = sis_old_set_piomode,
556 .set_dmamode = sis_66_set_dmamode,
2e413f51 557 .cable_detect = sis_66_cable_detect,
669a5db4
JG
558};
559
029cfd6b
TH
560static struct ata_port_operations sis_old_ops = {
561 .inherits = &sis_base_ops,
669a5db4
JG
562 .set_piomode = sis_old_set_piomode,
563 .set_dmamode = sis_old_set_dmamode,
2e413f51 564 .cable_detect = ata_cable_40wire,
669a5db4
JG
565};
566
1626aeb8 567static const struct ata_port_info sis_info = {
1d2808fd 568 .flags = ATA_FLAG_SLAVE_POSS,
669a5db4
JG
569 .pio_mask = 0x1f, /* pio0-4 */
570 .mwdma_mask = 0x07,
571 .udma_mask = 0,
572 .port_ops = &sis_old_ops,
573};
1626aeb8 574static const struct ata_port_info sis_info33 = {
1d2808fd 575 .flags = ATA_FLAG_SLAVE_POSS,
669a5db4
JG
576 .pio_mask = 0x1f, /* pio0-4 */
577 .mwdma_mask = 0x07,
578 .udma_mask = ATA_UDMA2, /* UDMA 33 */
579 .port_ops = &sis_old_ops,
580};
1626aeb8 581static const struct ata_port_info sis_info66 = {
1d2808fd 582 .flags = ATA_FLAG_SLAVE_POSS,
669a5db4
JG
583 .pio_mask = 0x1f, /* pio0-4 */
584 .udma_mask = ATA_UDMA4, /* UDMA 66 */
585 .port_ops = &sis_66_ops,
586};
1626aeb8 587static const struct ata_port_info sis_info100 = {
1d2808fd 588 .flags = ATA_FLAG_SLAVE_POSS,
669a5db4
JG
589 .pio_mask = 0x1f, /* pio0-4 */
590 .udma_mask = ATA_UDMA5,
591 .port_ops = &sis_100_ops,
592};
1626aeb8 593static const struct ata_port_info sis_info100_early = {
1d2808fd 594 .flags = ATA_FLAG_SLAVE_POSS,
669a5db4
JG
595 .udma_mask = ATA_UDMA5,
596 .pio_mask = 0x1f, /* pio0-4 */
597 .port_ops = &sis_66_ops,
598};
a3cabb27 599static const struct ata_port_info sis_info133 = {
1d2808fd 600 .flags = ATA_FLAG_SLAVE_POSS,
669a5db4
JG
601 .pio_mask = 0x1f, /* pio0-4 */
602 .udma_mask = ATA_UDMA6,
603 .port_ops = &sis_133_ops,
604};
a3cabb27 605const struct ata_port_info sis_info133_for_sata = {
a3cabb27
UK
606 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
607 .pio_mask = 0x1f, /* pio0-4 */
608 .udma_mask = ATA_UDMA6,
609 .port_ops = &sis_133_for_sata_ops,
610};
1626aeb8 611static const struct ata_port_info sis_info133_early = {
1d2808fd 612 .flags = ATA_FLAG_SLAVE_POSS,
669a5db4
JG
613 .pio_mask = 0x1f, /* pio0-4 */
614 .udma_mask = ATA_UDMA6,
615 .port_ops = &sis_133_early_ops,
616};
617
9b14dec5 618/* Privately shared with the SiS180 SATA driver, not for use elsewhere */
a3cabb27 619EXPORT_SYMBOL_GPL(sis_info133_for_sata);
669a5db4
JG
620
621static void sis_fixup(struct pci_dev *pdev, struct sis_chipset *sis)
622{
623 u16 regw;
624 u8 reg;
625
626 if (sis->info == &sis_info133) {
627 pci_read_config_word(pdev, 0x50, &regw);
628 if (regw & 0x08)
629 pci_write_config_word(pdev, 0x50, regw & ~0x08);
630 pci_read_config_word(pdev, 0x52, &regw);
631 if (regw & 0x08)
632 pci_write_config_word(pdev, 0x52, regw & ~0x08);
633 return;
634 }
635
636 if (sis->info == &sis_info133_early || sis->info == &sis_info100) {
637 /* Fix up latency */
638 pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x80);
639 /* Set compatibility bit */
640 pci_read_config_byte(pdev, 0x49, &reg);
641 if (!(reg & 0x01))
642 pci_write_config_byte(pdev, 0x49, reg | 0x01);
643 return;
644 }
645
646 if (sis->info == &sis_info66 || sis->info == &sis_info100_early) {
647 /* Fix up latency */
648 pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x80);
649 /* Set compatibility bit */
650 pci_read_config_byte(pdev, 0x52, &reg);
651 if (!(reg & 0x04))
652 pci_write_config_byte(pdev, 0x52, reg | 0x04);
653 return;
654 }
655
656 if (sis->info == &sis_info33) {
657 pci_read_config_byte(pdev, PCI_CLASS_PROG, &reg);
658 if (( reg & 0x0F ) != 0x00)
659 pci_write_config_byte(pdev, PCI_CLASS_PROG, reg & 0xF0);
660 /* Fall through to ATA16 fixup below */
661 }
662
663 if (sis->info == &sis_info || sis->info == &sis_info33) {
664 /* force per drive recovery and active timings
665 needed on ATA_33 and below chips */
666 pci_read_config_byte(pdev, 0x52, &reg);
667 if (!(reg & 0x08))
668 pci_write_config_byte(pdev, 0x52, reg|0x08);
669 return;
670 }
671
672 BUG();
673}
674
675/**
676 * sis_init_one - Register SiS ATA PCI device with kernel services
677 * @pdev: PCI device to register
678 * @ent: Entry in sis_pci_tbl matching with @pdev
679 *
680 * Called from kernel PCI layer. We probe for combined mode (sigh),
681 * and then hand over control to libata, for it to do the rest.
682 *
683 * LOCKING:
684 * Inherited from PCI layer (may sleep).
685 *
686 * RETURNS:
687 * Zero on success, or -ERRNO value.
688 */
689
690static int sis_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
691{
692 static int printed_version;
1626aeb8
TH
693 struct ata_port_info port;
694 const struct ata_port_info *ppi[] = { &port, NULL };
669a5db4
JG
695 struct pci_dev *host = NULL;
696 struct sis_chipset *chipset = NULL;
f3769e9d 697 struct sis_chipset *sets;
f08048e9 698 int rc;
669a5db4
JG
699
700 static struct sis_chipset sis_chipsets[] = {
f20b16ff 701
af323a2f
AC
702 { 0x0968, &sis_info133 },
703 { 0x0966, &sis_info133 },
704 { 0x0965, &sis_info133 },
669a5db4
JG
705 { 0x0745, &sis_info100 },
706 { 0x0735, &sis_info100 },
707 { 0x0733, &sis_info100 },
708 { 0x0635, &sis_info100 },
709 { 0x0633, &sis_info100 },
710
711 { 0x0730, &sis_info100_early }, /* 100 with ATA 66 layout */
712 { 0x0550, &sis_info100_early }, /* 100 with ATA 66 layout */
713
714 { 0x0640, &sis_info66 },
715 { 0x0630, &sis_info66 },
716 { 0x0620, &sis_info66 },
717 { 0x0540, &sis_info66 },
718 { 0x0530, &sis_info66 },
719
720 { 0x5600, &sis_info33 },
721 { 0x5598, &sis_info33 },
722 { 0x5597, &sis_info33 },
723 { 0x5591, &sis_info33 },
724 { 0x5582, &sis_info33 },
725 { 0x5581, &sis_info33 },
726
727 { 0x5596, &sis_info },
728 { 0x5571, &sis_info },
729 { 0x5517, &sis_info },
730 { 0x5511, &sis_info },
731
732 {0}
733 };
734 static struct sis_chipset sis133_early = {
735 0x0, &sis_info133_early
736 };
737 static struct sis_chipset sis133 = {
738 0x0, &sis_info133
739 };
740 static struct sis_chipset sis100_early = {
741 0x0, &sis_info100_early
742 };
743 static struct sis_chipset sis100 = {
744 0x0, &sis_info100
745 };
746
747 if (!printed_version++)
748 dev_printk(KERN_DEBUG, &pdev->dev,
749 "version " DRV_VERSION "\n");
750
f08048e9
TH
751 rc = pcim_enable_device(pdev);
752 if (rc)
753 return rc;
669a5db4 754
f08048e9 755 /* We have to find the bridge first */
f3769e9d
AC
756 for (sets = &sis_chipsets[0]; sets->device; sets++) {
757 host = pci_get_device(PCI_VENDOR_ID_SI, sets->device, NULL);
669a5db4 758 if (host != NULL) {
f3769e9d
AC
759 chipset = sets; /* Match found */
760 if (sets->device == 0x630) { /* SIS630 */
44c10138 761 if (host->revision >= 0x30) /* 630 ET */
669a5db4
JG
762 chipset = &sis100_early;
763 }
764 break;
765 }
766 }
767
768 /* Look for concealed bridges */
f3769e9d 769 if (chipset == NULL) {
669a5db4
JG
770 /* Second check */
771 u32 idemisc;
772 u16 trueid;
773
774 /* Disable ID masking and register remapping then
775 see what the real ID is */
776
777 pci_read_config_dword(pdev, 0x54, &idemisc);
778 pci_write_config_dword(pdev, 0x54, idemisc & 0x7fffffff);
779 pci_read_config_word(pdev, PCI_DEVICE_ID, &trueid);
780 pci_write_config_dword(pdev, 0x54, idemisc);
781
782 switch(trueid) {
783 case 0x5518: /* SIS 962/963 */
784 chipset = &sis133;
785 if ((idemisc & 0x40000000) == 0) {
786 pci_write_config_dword(pdev, 0x54, idemisc | 0x40000000);
787 printk(KERN_INFO "SIS5513: Switching to 5513 register mapping\n");
788 }
789 break;
790 case 0x0180: /* SIS 965/965L */
791 chipset = &sis133;
792 break;
793 case 0x1180: /* SIS 966/966L */
794 chipset = &sis133;
795 break;
796 }
797 }
798
799 /* Further check */
800 if (chipset == NULL) {
801 struct pci_dev *lpc_bridge;
802 u16 trueid;
803 u8 prefctl;
804 u8 idecfg;
669a5db4
JG
805
806 /* Try the second unmasking technique */
807 pci_read_config_byte(pdev, 0x4a, &idecfg);
808 pci_write_config_byte(pdev, 0x4a, idecfg | 0x10);
809 pci_read_config_word(pdev, PCI_DEVICE_ID, &trueid);
810 pci_write_config_byte(pdev, 0x4a, idecfg);
811
812 switch(trueid) {
813 case 0x5517:
814 lpc_bridge = pci_get_slot(pdev->bus, 0x10); /* Bus 0 Dev 2 Fn 0 */
815 if (lpc_bridge == NULL)
816 break;
669a5db4
JG
817 pci_read_config_byte(pdev, 0x49, &prefctl);
818 pci_dev_put(lpc_bridge);
819
44c10138 820 if (lpc_bridge->revision == 0x10 && (prefctl & 0x80)) {
669a5db4
JG
821 chipset = &sis133_early;
822 break;
823 }
824 chipset = &sis100;
825 break;
826 }
827 }
828 pci_dev_put(host);
829
830 /* No chipset info, no support */
831 if (chipset == NULL)
832 return -ENODEV;
833
1626aeb8
TH
834 port = *chipset->info;
835 port.private_data = chipset;
669a5db4
JG
836
837 sis_fixup(pdev, chipset);
838
1bd5b715 839 return ata_pci_init_one(pdev, ppi, &sis_sht);
669a5db4
JG
840}
841
842static const struct pci_device_id sis_pci_tbl[] = {
2d2744fc
JG
843 { PCI_VDEVICE(SI, 0x5513), }, /* SiS 5513 */
844 { PCI_VDEVICE(SI, 0x5518), }, /* SiS 5518 */
a3cabb27 845 { PCI_VDEVICE(SI, 0x1180), }, /* SiS 1180 */
2d2744fc 846
669a5db4
JG
847 { }
848};
849
850static struct pci_driver sis_pci_driver = {
851 .name = DRV_NAME,
852 .id_table = sis_pci_tbl,
853 .probe = sis_init_one,
854 .remove = ata_pci_remove_one,
438ac6d5 855#ifdef CONFIG_PM
62d64ae0
AC
856 .suspend = ata_pci_device_suspend,
857 .resume = ata_pci_device_resume,
438ac6d5 858#endif
669a5db4
JG
859};
860
861static int __init sis_init(void)
862{
863 return pci_register_driver(&sis_pci_driver);
864}
865
866static void __exit sis_exit(void)
867{
868 pci_unregister_driver(&sis_pci_driver);
869}
870
669a5db4
JG
871module_init(sis_init);
872module_exit(sis_exit);
873
874MODULE_AUTHOR("Alan Cox");
875MODULE_DESCRIPTION("SCSI low-level driver for SiS ATA");
876MODULE_LICENSE("GPL");
877MODULE_DEVICE_TABLE(pci, sis_pci_tbl);
878MODULE_VERSION(DRV_VERSION);
879