47 #include <linux/types.h>
48 #include <linux/module.h>
49 #include <linux/kernel.h>
50 #include <linux/pci.h>
54 #define DRV_NAME "sis5513"
66 static u8 chipset_family;
76 } SiSHostChipInfo[] = {
113 static u8 cycle_time_offset[] = { 0, 0, 5, 4, 4, 0, 0 };
114 static u8 cycle_time_range[] = { 0, 0, 2, 3, 3, 4, 4 };
116 { 0, 0, 0, 0, 0, 0, 0 },
117 { 0, 0, 0, 0, 0, 0, 0 },
118 { 3, 2, 1, 0, 0, 0, 0 },
119 { 7, 5, 3, 2, 1, 0, 0 },
120 { 7, 5, 3, 2, 1, 0, 0 },
122 { 11, 7, 5, 4, 2, 1, 0 },
123 { 15, 10, 7, 5, 3, 2, 1 },
124 { 15, 10, 7, 5, 3, 2, 1 },
129 { 0, 0, 0, 0, 0, 0, 0 },
130 { 0, 0, 0, 0, 0, 0, 0 },
131 { 2, 1, 1, 0, 0, 0, 0 },
132 { 4, 3, 2, 1, 0, 0, 0 },
133 { 4, 3, 2, 1, 0, 0, 0 },
134 { 6, 4, 3, 1, 1, 1, 0 },
135 { 9, 6, 4, 2, 2, 2, 2 },
136 { 9, 6, 4, 2, 2, 2, 2 },
141 static u8 ini_time_value[][8] = {
142 { 0, 0, 0, 0, 0, 0, 0, 0 },
143 { 0, 0, 0, 0, 0, 0, 0, 0 },
144 { 2, 1, 0, 0, 0, 1, 0, 0 },
145 { 4, 3, 1, 1, 1, 3, 1, 1 },
146 { 4, 3, 1, 1, 1, 3, 1, 1 },
147 { 6, 4, 2, 2, 2, 4, 2, 2 },
148 { 9, 6, 3, 3, 3, 6, 3, 3 },
149 { 9, 6, 3, 3, 3, 6, 3, 3 },
151 static u8 act_time_value[][8] = {
152 { 0, 0, 0, 0, 0, 0, 0, 0 },
153 { 0, 0, 0, 0, 0, 0, 0, 0 },
154 { 9, 9, 9, 2, 2, 7, 2, 2 },
155 { 19, 19, 19, 5, 4, 14, 5, 4 },
156 { 19, 19, 19, 5, 4, 14, 5, 4 },
157 { 28, 28, 28, 7, 6, 21, 7, 6 },
158 { 38, 38, 38, 10, 9, 28, 10, 9 },
159 { 38, 38, 38, 10, 9, 28, 10, 9 },
161 static u8 rco_time_value[][8] = {
162 { 0, 0, 0, 0, 0, 0, 0, 0 },
163 { 0, 0, 0, 0, 0, 0, 0, 0 },
164 { 9, 2, 0, 2, 0, 7, 1, 1 },
165 { 19, 5, 1, 5, 2, 16, 3, 2 },
166 { 19, 5, 1, 5, 2, 16, 3, 2 },
167 { 30, 9, 3, 9, 4, 25, 6, 4 },
168 { 40, 12, 4, 12, 5, 34, 12, 5 },
169 { 40, 12, 4, 12, 5, 34, 12, 5 },
176 static char *chipset_capability[] = {
179 "ATA 100 (1st gen)",
"ATA 100 (2nd gen)",
180 "ATA 133 (1st gen)",
"ATA 133 (2nd gen)"
192 pci_read_config_dword(dev, 0x54, ®54);
194 return ((reg54 & 0x40000000) ? 0x70 : 0x40) + drive->
dn * 4;
201 u8 drive_pci = 0x40 + drive->
dn * 2;
203 const u16 pio_timings[] = { 0x000, 0x607, 0x404, 0x303, 0x301 };
204 const u16 mwdma_timings[] = { 0x008, 0x302, 0x301 };
206 pci_read_config_word(dev, drive_pci, &t1);
211 if (chipset_family >
ATA_16)
217 pci_write_config_word(dev, drive_pci, t1);
220 static void sis_ata100_program_timings(
ide_drive_t *drive,
const u8 mode)
223 u8 t1, drive_pci = 0x40 + drive->
dn * 2;
226 const u8 pio_timings[] = { 0x00, 0x67, 0x44, 0x33, 0x31 };
227 const u8 mwdma_timings[] = { 0x08, 0x32, 0x31 };
232 pci_read_config_byte(dev, drive_pci, &t2);
234 pci_write_config_byte(dev, drive_pci, t2);
240 pci_write_config_byte(dev, drive_pci + 1, t1);
243 static void sis_ata133_program_timings(
ide_drive_t *drive,
const u8 mode)
247 u8 drive_pci = sis_ata133_get_base(drive),
clk,
idx;
249 pci_read_config_dword(dev, drive_pci, &t1);
258 t1 |= ini_time_value[
clk][
idx] << 12;
259 t1 |= act_time_value[
clk][
idx] << 16;
260 t1 |= rco_time_value[
clk][
idx] << 24;
262 pci_write_config_dword(dev, drive_pci, t1);
265 static void sis_program_timings(
ide_drive_t *drive,
const u8 mode)
268 sis_ata16_program_timings(drive, mode);
269 else if (chipset_family <
ATA_133)
270 sis_ata100_program_timings(drive, mode);
272 sis_ata133_program_timings(drive, mode);
275 static void config_drive_art_rwp(
ide_drive_t *drive)
282 pci_read_config_byte(dev, 0x4b, ®4bh);
284 rw_prefetch = reg4bh & ~(0x11 << drive->
dn);
287 rw_prefetch |= 0x11 << drive->
dn;
289 if (reg4bh != rw_prefetch)
290 pci_write_config_byte(dev, 0x4b, rw_prefetch);
295 config_drive_art_rwp(drive);
296 sis_program_timings(drive, drive->
pio_mode);
299 static void sis_ata133_program_udma_timings(
ide_drive_t *drive,
const u8 mode)
303 u8 drive_pci = sis_ata133_get_base(drive),
clk,
idx;
305 pci_read_config_dword(dev, drive_pci, ®dw);
312 regdw |= cycle_time_value[
clk][
idx] << 4;
313 regdw |= cvs_time_value[
clk][
idx] << 8;
315 pci_write_config_dword(dev, drive_pci, regdw);
318 static void sis_ata33_program_udma_timings(
ide_drive_t *drive,
const u8 mode)
321 u8 drive_pci = 0x40 + drive->
dn * 2,
reg = 0,
i = chipset_family;
323 pci_read_config_byte(dev, drive_pci + 1, &
reg);
328 reg &= ~((0xff >> (8 - cycle_time_range[
i])) << cycle_time_offset[
i]);
332 pci_write_config_byte(dev, drive_pci + 1,
reg);
335 static void sis_program_udma_timings(
ide_drive_t *drive,
const u8 mode)
338 sis_ata133_program_udma_timings(drive, mode);
340 sis_ata33_program_udma_timings(drive, mode);
348 sis_program_udma_timings(drive, speed);
350 sis_program_timings(drive, speed);
357 u8 drive_pci = sis_ata133_get_base(drive);
359 pci_read_config_dword(dev, drive_pci, ®dw);
372 for (i = 0; i <
ARRAY_SIZE(SiSHostChipInfo) && !chipset_family; i++) {
379 chipset_family = SiSHostChipInfo[
i].chipset_family;
389 pci_name(dev), SiSHostChipInfo[i].
name,
390 chipset_capability[chipset_family]);
393 if (!chipset_family) {
399 pci_read_config_dword(dev, 0x54, &idemisc);
400 pci_write_config_dword(dev, 0x54, (idemisc & 0x7fffffff));
402 pci_write_config_dword(dev, 0x54, idemisc);
404 if (trueid == 0x5518) {
413 if ((idemisc & 0x40000000) == 0) {
414 pci_write_config_dword(dev, 0x54, idemisc | 0x40000000);
421 if (!chipset_family) {
428 pci_read_config_byte(dev, 0x4a, &idecfg);
429 pci_write_config_byte(dev, 0x4a, idecfg | 0x10);
431 pci_write_config_byte(dev, 0x4a, idecfg);
433 if (trueid == 0x5517) {
436 pci_read_config_byte(dev, 0x49, &prefctl);
439 if (lpc_bridge->
revision == 0x10 && (prefctl & 0x80)) {
440 printk(
KERN_INFO DRV_NAME
" %s: SiS 961B MuTIOL IDE UDMA133 controller\n",
444 printk(
KERN_INFO DRV_NAME
" %s: SiS 961 MuTIOL IDE UDMA100 controller\n",
451 return chipset_family;
454 static int init_chipset_sis5513(
struct pci_dev *dev)
463 switch (chipset_family) {
466 pci_read_config_word(dev, 0x50, ®w);
468 pci_write_config_word(dev, 0x50, regw&0xfff7);
469 pci_read_config_word(dev, 0x52, ®w);
471 pci_write_config_word(dev, 0x52, regw&0xfff7);
478 pci_read_config_byte(dev, 0x49, ®);
480 pci_write_config_byte(dev, 0x49, reg|0x01);
488 pci_read_config_byte(dev, 0x52, ®);
490 pci_write_config_byte(dev, 0x52, reg|0x04);
494 pci_read_config_byte(dev, 0x09, ®);
495 if ((reg & 0x0f) != 0x00)
496 pci_write_config_byte(dev, 0x09, reg&0xf0);
500 pci_read_config_byte(dev, 0x52, ®);
502 pci_write_config_byte(dev, 0x52, reg|0x08);
517 { 0x5513, 0x1043, 0x1107 },
518 { 0x5513, 0x1734, 0x105f },
519 { 0x5513, 0x1071, 0x8640 },
527 const struct sis_laptop *lap = &sis_laptop[0];
538 if (chipset_family >=
ATA_133) {
541 pci_read_config_word(pdev, reg_addr, ®w);
542 ata66 = (regw & 0x8000) ? 0 : 1;
543 }
else if (chipset_family >=
ATA_66) {
546 pci_read_config_byte(pdev, 0x48, ®48h);
547 ata66 = (reg48h &
mask) ? 0 : 1;
554 .set_pio_mode = sis_set_pio_mode,
555 .set_dma_mode = sis_set_dma_mode,
556 .cable_detect = sis_cable_detect,
559 static const struct ide_port_ops sis_ata133_port_ops = {
560 .set_pio_mode = sis_set_pio_mode,
561 .set_dma_mode = sis_set_dma_mode,
562 .udma_filter = sis_ata133_udma_filter,
563 .cable_detect = sis_cable_detect,
568 .init_chipset = init_chipset_sis5513,
569 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
578 u8 udma_rates[] = { 0x00, 0x00, 0x07, 0x1f, 0x3f, 0x3f, 0x7f, 0x7f };
585 if (sis_find_family(dev) == 0)
593 d.
udma_mask = udma_rates[chipset_family];
612 static struct pci_driver sis5513_pci_driver = {
614 .id_table = sis5513_pci_tbl,
615 .probe = sis5513_init_one,
621 static int __init sis5513_ide_init(
void)
626 static void __exit sis5513_ide_exit(
void)
634 MODULE_AUTHOR(
"Lionel Bouton, L C Chang, Andre Hedrick, Vojtech Pavlik");