pata_sis: extract a sis_port_base() method
[deliverable/linux.git] / drivers / ata / pata_sis.c
CommitLineData
669a5db4
JG
1/*
2 * pata_sis.c - SiS ATA driver
3 *
ab771630 4 * (C) 2005 Red Hat
750c7136 5 * (C) 2007,2009 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
023a0175
DM
91/**
92 * sis_port_base - return PCI configuration base for dev
93 * @adev: device
94 *
95 * Returns the base of the PCI configuration registers for this port
96 * number.
97 */
98
99static int sis_port_base(struct ata_device *adev)
100{
101 struct ata_port *ap = adev->link->ap;
102 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
103 int port = 0x40;
104 u32 reg54;
105
106 /* If bit 30 is set then the registers are mapped at 0x70 not 0x40 */
107 pci_read_config_dword(pdev, 0x54, &reg54);
108 if (reg54 & 0x40000000)
109 port = 0x70;
110
111 return port + (8 * ap->port_no) + (4 * adev->devno);
112}
113
669a5db4 114/**
2e413f51 115 * sis_133_cable_detect - check for 40/80 pin
669a5db4 116 * @ap: Port
d4b2bab4 117 * @deadline: deadline jiffies for the operation
669a5db4
JG
118 *
119 * Perform cable detection for the later UDMA133 capable
120 * SiS chipset.
121 */
122
2e413f51 123static int sis_133_cable_detect(struct ata_port *ap)
669a5db4 124{
669a5db4
JG
125 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
126 u16 tmp;
127
669a5db4
JG
128 /* The top bit of this register is the cable detect bit */
129 pci_read_config_word(pdev, 0x50 + 2 * ap->port_no, &tmp);
7dcbc1f2 130 if ((tmp & 0x8000) && !sis_short_ata40(pdev))
2e413f51
AC
131 return ATA_CBL_PATA40;
132 return ATA_CBL_PATA80;
669a5db4
JG
133}
134
135/**
2e413f51 136 * sis_66_cable_detect - check for 40/80 pin
669a5db4
JG
137 * @ap: Port
138 *
139 * Perform cable detection on the UDMA66, UDMA100 and early UDMA133
140 * SiS IDE controllers.
141 */
142
2e413f51 143static int sis_66_cable_detect(struct ata_port *ap)
669a5db4 144{
669a5db4
JG
145 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
146 u8 tmp;
147
669a5db4
JG
148 /* Older chips keep cable detect in bits 4/5 of reg 0x48 */
149 pci_read_config_byte(pdev, 0x48, &tmp);
150 tmp >>= ap->port_no;
7dcbc1f2 151 if ((tmp & 0x10) && !sis_short_ata40(pdev))
2e413f51
AC
152 return ATA_CBL_PATA40;
153 return ATA_CBL_PATA80;
669a5db4
JG
154}
155
669a5db4
JG
156
157/**
2e413f51 158 * sis_pre_reset - probe begin
cc0680a5 159 * @link: ATA link
d4b2bab4 160 * @deadline: deadline jiffies for the operation
669a5db4
JG
161 *
162 * Set up cable type and use generic probe init
163 */
164
cc0680a5 165static int sis_pre_reset(struct ata_link *link, unsigned long deadline)
669a5db4
JG
166{
167 static const struct pci_bits sis_enable_bits[] = {
168 { 0x4aU, 1U, 0x02UL, 0x02UL }, /* port 0 */
169 { 0x4aU, 1U, 0x04UL, 0x04UL }, /* port 1 */
170 };
85cd7251 171
cc0680a5 172 struct ata_port *ap = link->ap;
669a5db4
JG
173 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
174
2e413f51
AC
175 if (!pci_test_config_bits(pdev, &sis_enable_bits[ap->port_no]))
176 return -ENOENT;
d4b2bab4 177
15ce0943
AC
178 /* Clear the FIFO settings. We can't enable the FIFO until
179 we know we are poking at a disk */
180 pci_write_config_byte(pdev, 0x4B, 0);
9363c382 181 return ata_sff_prereset(link, deadline);
669a5db4
JG
182}
183
184
669a5db4
JG
185/**
186 * sis_set_fifo - Set RWP fifo bits for this device
187 * @ap: Port
188 * @adev: Device
189 *
190 * SIS chipsets implement prefetch/postwrite bits for each device
191 * on both channels. This functionality is not ATAPI compatible and
192 * must be configured according to the class of device present
193 */
194
195static void sis_set_fifo(struct ata_port *ap, struct ata_device *adev)
196{
197 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
198 u8 fifoctrl;
199 u8 mask = 0x11;
200
201 mask <<= (2 * ap->port_no);
202 mask <<= adev->devno;
203
204 /* This holds various bits including the FIFO control */
205 pci_read_config_byte(pdev, 0x4B, &fifoctrl);
206 fifoctrl &= ~mask;
207
208 /* Enable for ATA (disk) only */
209 if (adev->class == ATA_DEV_ATA)
210 fifoctrl |= mask;
211 pci_write_config_byte(pdev, 0x4B, fifoctrl);
212}
213
214/**
215 * sis_old_set_piomode - Initialize host controller PATA PIO timings
216 * @ap: Port whose timings we are configuring
217 * @adev: Device we are configuring for.
218 *
219 * Set PIO mode for device, in host controller PCI config space. This
220 * function handles PIO set up for all chips that are pre ATA100 and
221 * also early ATA100 devices.
222 *
223 * LOCKING:
224 * None (inherited from caller).
225 */
226
227static void sis_old_set_piomode (struct ata_port *ap, struct ata_device *adev)
228{
229 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
dd668d15 230 int port = sis_old_port_base(adev);
669a5db4
JG
231 u8 t1, t2;
232 int speed = adev->pio_mode - XFER_PIO_0;
233
234 const u8 active[] = { 0x00, 0x07, 0x04, 0x03, 0x01 };
235 const u8 recovery[] = { 0x00, 0x06, 0x04, 0x03, 0x03 };
236
237 sis_set_fifo(ap, adev);
238
239 pci_read_config_byte(pdev, port, &t1);
240 pci_read_config_byte(pdev, port + 1, &t2);
241
242 t1 &= ~0x0F; /* Clear active/recovery timings */
243 t2 &= ~0x07;
244
245 t1 |= active[speed];
246 t2 |= recovery[speed];
247
248 pci_write_config_byte(pdev, port, t1);
249 pci_write_config_byte(pdev, port + 1, t2);
250}
251
252/**
4761c06c 253 * sis_100_set_piomode - Initialize host controller PATA PIO timings
669a5db4
JG
254 * @ap: Port whose timings we are configuring
255 * @adev: Device we are configuring for.
256 *
257 * Set PIO mode for device, in host controller PCI config space. This
258 * function handles PIO set up for ATA100 devices and early ATA133.
259 *
260 * LOCKING:
261 * None (inherited from caller).
262 */
263
264static void sis_100_set_piomode (struct ata_port *ap, struct ata_device *adev)
265{
266 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
dd668d15 267 int port = sis_old_port_base(adev);
669a5db4
JG
268 int speed = adev->pio_mode - XFER_PIO_0;
269
270 const u8 actrec[] = { 0x00, 0x67, 0x44, 0x33, 0x31 };
271
272 sis_set_fifo(ap, adev);
273
274 pci_write_config_byte(pdev, port, actrec[speed]);
275}
276
277/**
1b52f2a4 278 * sis_133_set_piomode - Initialize host controller PATA PIO timings
669a5db4
JG
279 * @ap: Port whose timings we are configuring
280 * @adev: Device we are configuring for.
281 *
282 * Set PIO mode for device, in host controller PCI config space. This
1b52f2a4 283 * function handles PIO set up for the later ATA133 devices.
669a5db4
JG
284 *
285 * LOCKING:
286 * None (inherited from caller).
287 */
288
1b52f2a4 289static void sis_133_set_piomode (struct ata_port *ap, struct ata_device *adev)
669a5db4
JG
290{
291 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
023a0175 292 int port;
669a5db4 293 u32 t1;
1b52f2a4 294 int speed = adev->pio_mode - XFER_PIO_0;
669a5db4
JG
295
296 const u32 timing133[] = {
297 0x28269000, /* Recovery << 24 | Act << 16 | Ini << 12 */
298 0x0C266000,
299 0x04263000,
300 0x0C0A3000,
301 0x05093000
302 };
303 const u32 timing100[] = {
304 0x1E1C6000, /* Recovery << 24 | Act << 16 | Ini << 12 */
305 0x091C4000,
306 0x031C2000,
307 0x09072000,
308 0x04062000
309 };
310
311 sis_set_fifo(ap, adev);
312
023a0175 313 port = sis_port_base(adev);
669a5db4
JG
314 pci_read_config_dword(pdev, port, &t1);
315 t1 &= 0xC0C00FFF; /* Mask out timing */
316
317 if (t1 & 0x08) /* 100 or 133 ? */
318 t1 |= timing133[speed];
319 else
320 t1 |= timing100[speed];
321 pci_write_config_byte(pdev, port, t1);
322}
323
324/**
325 * sis_old_set_dmamode - Initialize host controller PATA DMA timings
326 * @ap: Port whose timings we are configuring
327 * @adev: Device to program
328 *
329 * Set UDMA/MWDMA mode for device, in host controller PCI config space.
330 * Handles pre UDMA and UDMA33 devices. Supports MWDMA as well unlike
331 * the old ide/pci driver.
332 *
333 * LOCKING:
334 * None (inherited from caller).
335 */
336
337static void sis_old_set_dmamode (struct ata_port *ap, struct ata_device *adev)
338{
339 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
340 int speed = adev->dma_mode - XFER_MW_DMA_0;
dd668d15 341 int drive_pci = sis_old_port_base(adev);
669a5db4
JG
342 u16 timing;
343
4761c06c 344 const u16 mwdma_bits[] = { 0x008, 0x302, 0x301 };
669a5db4
JG
345 const u16 udma_bits[] = { 0xE000, 0xC000, 0xA000 };
346
347 pci_read_config_word(pdev, drive_pci, &timing);
348
349 if (adev->dma_mode < XFER_UDMA_0) {
350 /* bits 3-0 hold recovery timing bits 8-10 active timing and
25985edc 351 the higher bits are dependent on the device */
4761c06c 352 timing &= ~0x870F;
669a5db4 353 timing |= mwdma_bits[speed];
669a5db4
JG
354 } else {
355 /* Bit 15 is UDMA on/off, bit 13-14 are cycle time */
356 speed = adev->dma_mode - XFER_UDMA_0;
357 timing &= ~0x6000;
358 timing |= udma_bits[speed];
359 }
4761c06c 360 pci_write_config_word(pdev, drive_pci, timing);
669a5db4
JG
361}
362
363/**
364 * sis_66_set_dmamode - Initialize host controller PATA DMA timings
365 * @ap: Port whose timings we are configuring
366 * @adev: Device to program
367 *
368 * Set UDMA/MWDMA mode for device, in host controller PCI config space.
369 * Handles UDMA66 and early UDMA100 devices. Supports MWDMA as well unlike
370 * the old ide/pci driver.
371 *
372 * LOCKING:
373 * None (inherited from caller).
374 */
375
376static void sis_66_set_dmamode (struct ata_port *ap, struct ata_device *adev)
377{
378 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
379 int speed = adev->dma_mode - XFER_MW_DMA_0;
dd668d15 380 int drive_pci = sis_old_port_base(adev);
669a5db4
JG
381 u16 timing;
382
edeb614c 383 /* MWDMA 0-2 and UDMA 0-5 */
4761c06c 384 const u16 mwdma_bits[] = { 0x008, 0x302, 0x301 };
edeb614c 385 const u16 udma_bits[] = { 0xF000, 0xD000, 0xB000, 0xA000, 0x9000, 0x8000 };
669a5db4
JG
386
387 pci_read_config_word(pdev, drive_pci, &timing);
388
389 if (adev->dma_mode < XFER_UDMA_0) {
390 /* bits 3-0 hold recovery timing bits 8-10 active timing and
25985edc 391 the higher bits are dependent on the device, bit 15 udma */
dd668d15 392 timing &= ~0x870F;
669a5db4
JG
393 timing |= mwdma_bits[speed];
394 } else {
395 /* Bit 15 is UDMA on/off, bit 12-14 are cycle time */
396 speed = adev->dma_mode - XFER_UDMA_0;
dd668d15 397 timing &= ~0xF000;
669a5db4
JG
398 timing |= udma_bits[speed];
399 }
400 pci_write_config_word(pdev, drive_pci, timing);
401}
402
403/**
404 * sis_100_set_dmamode - Initialize host controller PATA DMA timings
405 * @ap: Port whose timings we are configuring
406 * @adev: Device to program
407 *
408 * Set UDMA/MWDMA mode for device, in host controller PCI config space.
1b52f2a4 409 * Handles UDMA66 and early UDMA100 devices.
669a5db4
JG
410 *
411 * LOCKING:
412 * None (inherited from caller).
413 */
414
415static void sis_100_set_dmamode (struct ata_port *ap, struct ata_device *adev)
416{
417 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
418 int speed = adev->dma_mode - XFER_MW_DMA_0;
dd668d15 419 int drive_pci = sis_old_port_base(adev);
1b52f2a4 420 u8 timing;
669a5db4 421
1b52f2a4 422 const u8 udma_bits[] = { 0x8B, 0x87, 0x85, 0x83, 0x82, 0x81};
669a5db4 423
1b52f2a4 424 pci_read_config_byte(pdev, drive_pci + 1, &timing);
669a5db4
JG
425
426 if (adev->dma_mode < XFER_UDMA_0) {
1b52f2a4 427 /* NOT SUPPORTED YET: NEED DATA SHEET. DITTO IN OLD DRIVER */
669a5db4 428 } else {
dd668d15 429 /* Bit 7 is UDMA on/off, bit 0-3 are cycle time */
669a5db4 430 speed = adev->dma_mode - XFER_UDMA_0;
1b52f2a4 431 timing &= ~0x8F;
669a5db4
JG
432 timing |= udma_bits[speed];
433 }
1b52f2a4 434 pci_write_config_byte(pdev, drive_pci + 1, timing);
669a5db4
JG
435}
436
437/**
438 * sis_133_early_set_dmamode - Initialize host controller PATA DMA timings
439 * @ap: Port whose timings we are configuring
440 * @adev: Device to program
441 *
442 * Set UDMA/MWDMA mode for device, in host controller PCI config space.
4761c06c 443 * Handles early SiS 961 bridges.
669a5db4
JG
444 *
445 * LOCKING:
446 * None (inherited from caller).
447 */
448
449static void sis_133_early_set_dmamode (struct ata_port *ap, struct ata_device *adev)
450{
451 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
452 int speed = adev->dma_mode - XFER_MW_DMA_0;
dd668d15 453 int drive_pci = sis_old_port_base(adev);
1b52f2a4
JG
454 u8 timing;
455 /* Low 4 bits are timing */
456 static const u8 udma_bits[] = { 0x8F, 0x8A, 0x87, 0x85, 0x83, 0x82, 0x81};
669a5db4 457
1b52f2a4 458 pci_read_config_byte(pdev, drive_pci + 1, &timing);
669a5db4
JG
459
460 if (adev->dma_mode < XFER_UDMA_0) {
1b52f2a4 461 /* NOT SUPPORTED YET: NEED DATA SHEET. DITTO IN OLD DRIVER */
669a5db4 462 } else {
dd668d15 463 /* Bit 7 is UDMA on/off, bit 0-3 are cycle time */
669a5db4 464 speed = adev->dma_mode - XFER_UDMA_0;
1b52f2a4 465 timing &= ~0x8F;
669a5db4
JG
466 timing |= udma_bits[speed];
467 }
1b52f2a4 468 pci_write_config_byte(pdev, drive_pci + 1, timing);
669a5db4
JG
469}
470
471/**
472 * sis_133_set_dmamode - Initialize host controller PATA DMA timings
473 * @ap: Port whose timings we are configuring
474 * @adev: Device to program
475 *
476 * Set UDMA/MWDMA mode for device, in host controller PCI config space.
669a5db4
JG
477 *
478 * LOCKING:
479 * None (inherited from caller).
480 */
481
482static void sis_133_set_dmamode (struct ata_port *ap, struct ata_device *adev)
483{
484 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
023a0175 485 int port;
669a5db4 486 u32 t1;
669a5db4
JG
487
488 /* bits 4- cycle time 8 - cvs time */
2e413f51
AC
489 static const u32 timing_u100[] = { 0x6B0, 0x470, 0x350, 0x140, 0x120, 0x110, 0x000 };
490 static const u32 timing_u133[] = { 0x9F0, 0x6A0, 0x470, 0x250, 0x230, 0x220, 0x210 };
669a5db4 491
023a0175 492 port = sis_port_base(adev);
669a5db4
JG
493 pci_read_config_dword(pdev, port, &t1);
494
495 if (adev->dma_mode < XFER_UDMA_0) {
1b52f2a4
JG
496 t1 &= ~0x00000004;
497 /* FIXME: need data sheet to add MWDMA here. Also lacking on
498 ide/pci driver */
669a5db4 499 } else {
023a0175 500 int speed = adev->dma_mode - XFER_UDMA_0;
669a5db4
JG
501 /* if & 8 no UDMA133 - need info for ... */
502 t1 &= ~0x00000FF0;
503 t1 |= 0x00000004;
504 if (t1 & 0x08)
505 t1 |= timing_u133[speed];
506 else
507 t1 |= timing_u100[speed];
508 }
509 pci_write_config_dword(pdev, port, t1);
510}
511
512static struct scsi_host_template sis_sht = {
68d1d07b 513 ATA_BMDMA_SHT(DRV_NAME),
669a5db4
JG
514};
515
029cfd6b
TH
516static struct ata_port_operations sis_133_for_sata_ops = {
517 .inherits = &ata_bmdma_port_ops,
669a5db4
JG
518 .set_piomode = sis_133_set_piomode,
519 .set_dmamode = sis_133_set_dmamode,
2e413f51 520 .cable_detect = sis_133_cable_detect,
029cfd6b 521};
669a5db4 522
029cfd6b
TH
523static struct ata_port_operations sis_base_ops = {
524 .inherits = &ata_bmdma_port_ops,
a1efdaba 525 .prereset = sis_pre_reset,
669a5db4
JG
526};
527
029cfd6b
TH
528static struct ata_port_operations sis_133_ops = {
529 .inherits = &sis_base_ops,
a3cabb27
UK
530 .set_piomode = sis_133_set_piomode,
531 .set_dmamode = sis_133_set_dmamode,
a3cabb27 532 .cable_detect = sis_133_cable_detect,
a3cabb27
UK
533};
534
029cfd6b
TH
535static struct ata_port_operations sis_133_early_ops = {
536 .inherits = &sis_base_ops,
669a5db4
JG
537 .set_piomode = sis_100_set_piomode,
538 .set_dmamode = sis_133_early_set_dmamode,
2e413f51 539 .cable_detect = sis_66_cable_detect,
669a5db4
JG
540};
541
029cfd6b
TH
542static struct ata_port_operations sis_100_ops = {
543 .inherits = &sis_base_ops,
669a5db4
JG
544 .set_piomode = sis_100_set_piomode,
545 .set_dmamode = sis_100_set_dmamode,
2e413f51 546 .cable_detect = sis_66_cable_detect,
669a5db4
JG
547};
548
029cfd6b
TH
549static struct ata_port_operations sis_66_ops = {
550 .inherits = &sis_base_ops,
669a5db4
JG
551 .set_piomode = sis_old_set_piomode,
552 .set_dmamode = sis_66_set_dmamode,
2e413f51 553 .cable_detect = sis_66_cable_detect,
669a5db4
JG
554};
555
029cfd6b
TH
556static struct ata_port_operations sis_old_ops = {
557 .inherits = &sis_base_ops,
669a5db4
JG
558 .set_piomode = sis_old_set_piomode,
559 .set_dmamode = sis_old_set_dmamode,
2e413f51 560 .cable_detect = ata_cable_40wire,
669a5db4
JG
561};
562
1626aeb8 563static const struct ata_port_info sis_info = {
1d2808fd 564 .flags = ATA_FLAG_SLAVE_POSS,
14bdef98
EIB
565 .pio_mask = ATA_PIO4,
566 .mwdma_mask = ATA_MWDMA2,
567 /* No UDMA */
669a5db4
JG
568 .port_ops = &sis_old_ops,
569};
1626aeb8 570static const struct ata_port_info sis_info33 = {
1d2808fd 571 .flags = ATA_FLAG_SLAVE_POSS,
14bdef98
EIB
572 .pio_mask = ATA_PIO4,
573 .mwdma_mask = ATA_MWDMA2,
574 .udma_mask = ATA_UDMA2,
669a5db4
JG
575 .port_ops = &sis_old_ops,
576};
1626aeb8 577static const struct ata_port_info sis_info66 = {
1d2808fd 578 .flags = ATA_FLAG_SLAVE_POSS,
14bdef98
EIB
579 .pio_mask = ATA_PIO4,
580 /* No MWDMA */
581 .udma_mask = ATA_UDMA4,
669a5db4
JG
582 .port_ops = &sis_66_ops,
583};
1626aeb8 584static const struct ata_port_info sis_info100 = {
1d2808fd 585 .flags = ATA_FLAG_SLAVE_POSS,
14bdef98
EIB
586 .pio_mask = ATA_PIO4,
587 /* No MWDMA */
669a5db4
JG
588 .udma_mask = ATA_UDMA5,
589 .port_ops = &sis_100_ops,
590};
1626aeb8 591static const struct ata_port_info sis_info100_early = {
1d2808fd 592 .flags = ATA_FLAG_SLAVE_POSS,
14bdef98
EIB
593 .pio_mask = ATA_PIO4,
594 /* No MWDMA */
669a5db4 595 .udma_mask = ATA_UDMA5,
669a5db4
JG
596 .port_ops = &sis_66_ops,
597};
a3cabb27 598static const struct ata_port_info sis_info133 = {
1d2808fd 599 .flags = ATA_FLAG_SLAVE_POSS,
14bdef98
EIB
600 .pio_mask = ATA_PIO4,
601 /* No MWDMA */
669a5db4
JG
602 .udma_mask = ATA_UDMA6,
603 .port_ops = &sis_133_ops,
604};
a3cabb27 605const struct ata_port_info sis_info133_for_sata = {
c10f97b9 606 .flags = ATA_FLAG_SLAVE_POSS,
14bdef98
EIB
607 .pio_mask = ATA_PIO4,
608 /* No MWDMA */
a3cabb27
UK
609 .udma_mask = ATA_UDMA6,
610 .port_ops = &sis_133_for_sata_ops,
611};
1626aeb8 612static const struct ata_port_info sis_info133_early = {
1d2808fd 613 .flags = ATA_FLAG_SLAVE_POSS,
14bdef98
EIB
614 .pio_mask = ATA_PIO4,
615 /* No MWDMA */
669a5db4
JG
616 .udma_mask = ATA_UDMA6,
617 .port_ops = &sis_133_early_ops,
618};
619
9b14dec5 620/* Privately shared with the SiS180 SATA driver, not for use elsewhere */
a3cabb27 621EXPORT_SYMBOL_GPL(sis_info133_for_sata);
669a5db4
JG
622
623static void sis_fixup(struct pci_dev *pdev, struct sis_chipset *sis)
624{
625 u16 regw;
626 u8 reg;
627
628 if (sis->info == &sis_info133) {
629 pci_read_config_word(pdev, 0x50, &regw);
630 if (regw & 0x08)
631 pci_write_config_word(pdev, 0x50, regw & ~0x08);
632 pci_read_config_word(pdev, 0x52, &regw);
633 if (regw & 0x08)
634 pci_write_config_word(pdev, 0x52, regw & ~0x08);
635 return;
636 }
637
638 if (sis->info == &sis_info133_early || sis->info == &sis_info100) {
639 /* Fix up latency */
640 pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x80);
641 /* Set compatibility bit */
642 pci_read_config_byte(pdev, 0x49, &reg);
643 if (!(reg & 0x01))
644 pci_write_config_byte(pdev, 0x49, reg | 0x01);
645 return;
646 }
647
648 if (sis->info == &sis_info66 || sis->info == &sis_info100_early) {
649 /* Fix up latency */
650 pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x80);
651 /* Set compatibility bit */
652 pci_read_config_byte(pdev, 0x52, &reg);
653 if (!(reg & 0x04))
654 pci_write_config_byte(pdev, 0x52, reg | 0x04);
655 return;
656 }
657
658 if (sis->info == &sis_info33) {
659 pci_read_config_byte(pdev, PCI_CLASS_PROG, &reg);
660 if (( reg & 0x0F ) != 0x00)
661 pci_write_config_byte(pdev, PCI_CLASS_PROG, reg & 0xF0);
662 /* Fall through to ATA16 fixup below */
663 }
664
665 if (sis->info == &sis_info || sis->info == &sis_info33) {
666 /* force per drive recovery and active timings
667 needed on ATA_33 and below chips */
668 pci_read_config_byte(pdev, 0x52, &reg);
669 if (!(reg & 0x08))
670 pci_write_config_byte(pdev, 0x52, reg|0x08);
671 return;
672 }
673
674 BUG();
675}
676
677/**
678 * sis_init_one - Register SiS ATA PCI device with kernel services
679 * @pdev: PCI device to register
680 * @ent: Entry in sis_pci_tbl matching with @pdev
681 *
682 * Called from kernel PCI layer. We probe for combined mode (sigh),
683 * and then hand over control to libata, for it to do the rest.
684 *
685 * LOCKING:
686 * Inherited from PCI layer (may sleep).
687 *
688 * RETURNS:
689 * Zero on success, or -ERRNO value.
690 */
691
692static int sis_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
693{
887125e3 694 const struct ata_port_info *ppi[] = { NULL, 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
06296a1e 747 ata_print_version_once(&pdev->dev, DRV_VERSION);
669a5db4 748
f08048e9
TH
749 rc = pcim_enable_device(pdev);
750 if (rc)
751 return rc;
669a5db4 752
f08048e9 753 /* We have to find the bridge first */
f3769e9d
AC
754 for (sets = &sis_chipsets[0]; sets->device; sets++) {
755 host = pci_get_device(PCI_VENDOR_ID_SI, sets->device, NULL);
669a5db4 756 if (host != NULL) {
f3769e9d
AC
757 chipset = sets; /* Match found */
758 if (sets->device == 0x630) { /* SIS630 */
44c10138 759 if (host->revision >= 0x30) /* 630 ET */
669a5db4
JG
760 chipset = &sis100_early;
761 }
762 break;
763 }
764 }
765
766 /* Look for concealed bridges */
f3769e9d 767 if (chipset == NULL) {
669a5db4
JG
768 /* Second check */
769 u32 idemisc;
770 u16 trueid;
771
772 /* Disable ID masking and register remapping then
773 see what the real ID is */
774
775 pci_read_config_dword(pdev, 0x54, &idemisc);
776 pci_write_config_dword(pdev, 0x54, idemisc & 0x7fffffff);
777 pci_read_config_word(pdev, PCI_DEVICE_ID, &trueid);
778 pci_write_config_dword(pdev, 0x54, idemisc);
779
780 switch(trueid) {
781 case 0x5518: /* SIS 962/963 */
782 chipset = &sis133;
783 if ((idemisc & 0x40000000) == 0) {
784 pci_write_config_dword(pdev, 0x54, idemisc | 0x40000000);
785 printk(KERN_INFO "SIS5513: Switching to 5513 register mapping\n");
786 }
787 break;
788 case 0x0180: /* SIS 965/965L */
789 chipset = &sis133;
790 break;
791 case 0x1180: /* SIS 966/966L */
792 chipset = &sis133;
793 break;
794 }
795 }
796
797 /* Further check */
798 if (chipset == NULL) {
799 struct pci_dev *lpc_bridge;
800 u16 trueid;
801 u8 prefctl;
802 u8 idecfg;
669a5db4
JG
803
804 /* Try the second unmasking technique */
805 pci_read_config_byte(pdev, 0x4a, &idecfg);
806 pci_write_config_byte(pdev, 0x4a, idecfg | 0x10);
807 pci_read_config_word(pdev, PCI_DEVICE_ID, &trueid);
808 pci_write_config_byte(pdev, 0x4a, idecfg);
809
810 switch(trueid) {
811 case 0x5517:
812 lpc_bridge = pci_get_slot(pdev->bus, 0x10); /* Bus 0 Dev 2 Fn 0 */
813 if (lpc_bridge == NULL)
814 break;
669a5db4
JG
815 pci_read_config_byte(pdev, 0x49, &prefctl);
816 pci_dev_put(lpc_bridge);
817
44c10138 818 if (lpc_bridge->revision == 0x10 && (prefctl & 0x80)) {
669a5db4
JG
819 chipset = &sis133_early;
820 break;
821 }
822 chipset = &sis100;
823 break;
824 }
825 }
826 pci_dev_put(host);
827
828 /* No chipset info, no support */
829 if (chipset == NULL)
830 return -ENODEV;
831
887125e3 832 ppi[0] = chipset->info;
669a5db4
JG
833
834 sis_fixup(pdev, chipset);
835
1c5afdf7 836 return ata_pci_bmdma_init_one(pdev, ppi, &sis_sht, chipset, 0);
669a5db4
JG
837}
838
750c7136
BZ
839#ifdef CONFIG_PM
840static int sis_reinit_one(struct pci_dev *pdev)
841{
842 struct ata_host *host = dev_get_drvdata(&pdev->dev);
843 int rc;
844
845 rc = ata_pci_device_do_resume(pdev);
846 if (rc)
847 return rc;
848
849 sis_fixup(pdev, host->private_data);
850
851 ata_host_resume(host);
852 return 0;
853}
854#endif
855
669a5db4 856static const struct pci_device_id sis_pci_tbl[] = {
2d2744fc
JG
857 { PCI_VDEVICE(SI, 0x5513), }, /* SiS 5513 */
858 { PCI_VDEVICE(SI, 0x5518), }, /* SiS 5518 */
a3cabb27 859 { PCI_VDEVICE(SI, 0x1180), }, /* SiS 1180 */
2d2744fc 860
669a5db4
JG
861 { }
862};
863
864static struct pci_driver sis_pci_driver = {
865 .name = DRV_NAME,
866 .id_table = sis_pci_tbl,
867 .probe = sis_init_one,
868 .remove = ata_pci_remove_one,
438ac6d5 869#ifdef CONFIG_PM
62d64ae0 870 .suspend = ata_pci_device_suspend,
750c7136 871 .resume = sis_reinit_one,
438ac6d5 872#endif
669a5db4
JG
873};
874
875static int __init sis_init(void)
876{
877 return pci_register_driver(&sis_pci_driver);
878}
879
880static void __exit sis_exit(void)
881{
882 pci_unregister_driver(&sis_pci_driver);
883}
884
669a5db4
JG
885module_init(sis_init);
886module_exit(sis_exit);
887
888MODULE_AUTHOR("Alan Cox");
889MODULE_DESCRIPTION("SCSI low-level driver for SiS ATA");
890MODULE_LICENSE("GPL");
891MODULE_DEVICE_TABLE(pci, sis_pci_tbl);
892MODULE_VERSION(DRV_VERSION);
893
This page took 0.486751 seconds and 5 git commands to generate.