sis5513.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. /*
  2. * linux/drivers/ide/pci/sis5513.c Version 0.31 Aug 9, 2007
  3. *
  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>
  7. * Copyright (C) 2007 Bartlomiej Zolnierkiewicz
  8. *
  9. * 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. * The original SiS5513 comes from a SiS5511/55112/5513 chipset. The original
  32. * SiS5513 was also used in the SiS5596/5513 chipset. Thus if we see a SiS5511
  33. * or SiS5596, we can assume we see the first MWDMA-16 capable SiS5513 chip.
  34. *
  35. * Later SiS chipsets integrated the 5513 functionality into the NorthBridge,
  36. * starting with SiS5571 and up to SiS745. The PCI ID didn't change, though. We
  37. * can figure out that we have a more modern and more capable 5513 by looking
  38. * for the respective NorthBridge IDs.
  39. *
  40. * Even later (96x family) SiS chipsets use the MuTIOL link and place the 5513
  41. * into the SouthBrige. Here we cannot rely on looking up the NorthBridge PCI
  42. * ID, while the now ATA-133 capable 5513 still has the same PCI ID.
  43. * Fortunately the 5513 can be 'unmasked' by fiddling with some config space
  44. * bits, changing its device id to the true one - 5517 for 961 and 5518 for
  45. * 962/963.
  46. */
  47. #include <linux/types.h>
  48. #include <linux/module.h>
  49. #include <linux/kernel.h>
  50. #include <linux/delay.h>
  51. #include <linux/timer.h>
  52. #include <linux/mm.h>
  53. #include <linux/ioport.h>
  54. #include <linux/blkdev.h>
  55. #include <linux/hdreg.h>
  56. #include <linux/interrupt.h>
  57. #include <linux/pci.h>
  58. #include <linux/init.h>
  59. #include <linux/ide.h>
  60. #include <asm/irq.h>
  61. #include "ide-timing.h"
  62. /* registers layout and init values are chipset family dependant */
  63. #define ATA_16 0x01
  64. #define ATA_33 0x02
  65. #define ATA_66 0x03
  66. #define ATA_100a 0x04 // SiS730/SiS550 is ATA100 with ATA66 layout
  67. #define ATA_100 0x05
  68. #define ATA_133a 0x06 // SiS961b with 133 support
  69. #define ATA_133 0x07 // SiS962/963
  70. static u8 chipset_family;
  71. /*
  72. * Devices supported
  73. */
  74. static const struct {
  75. const char *name;
  76. u16 host_id;
  77. u8 chipset_family;
  78. u8 flags;
  79. } SiSHostChipInfo[] = {
  80. { "SiS968", PCI_DEVICE_ID_SI_968, ATA_133 },
  81. { "SiS966", PCI_DEVICE_ID_SI_966, ATA_133 },
  82. { "SiS965", PCI_DEVICE_ID_SI_965, ATA_133 },
  83. { "SiS745", PCI_DEVICE_ID_SI_745, ATA_100 },
  84. { "SiS735", PCI_DEVICE_ID_SI_735, ATA_100 },
  85. { "SiS733", PCI_DEVICE_ID_SI_733, ATA_100 },
  86. { "SiS635", PCI_DEVICE_ID_SI_635, ATA_100 },
  87. { "SiS633", PCI_DEVICE_ID_SI_633, ATA_100 },
  88. { "SiS730", PCI_DEVICE_ID_SI_730, ATA_100a },
  89. { "SiS550", PCI_DEVICE_ID_SI_550, ATA_100a },
  90. { "SiS640", PCI_DEVICE_ID_SI_640, ATA_66 },
  91. { "SiS630", PCI_DEVICE_ID_SI_630, ATA_66 },
  92. { "SiS620", PCI_DEVICE_ID_SI_620, ATA_66 },
  93. { "SiS540", PCI_DEVICE_ID_SI_540, ATA_66 },
  94. { "SiS530", PCI_DEVICE_ID_SI_530, ATA_66 },
  95. { "SiS5600", PCI_DEVICE_ID_SI_5600, ATA_33 },
  96. { "SiS5598", PCI_DEVICE_ID_SI_5598, ATA_33 },
  97. { "SiS5597", PCI_DEVICE_ID_SI_5597, ATA_33 },
  98. { "SiS5591/2", PCI_DEVICE_ID_SI_5591, ATA_33 },
  99. { "SiS5582", PCI_DEVICE_ID_SI_5582, ATA_33 },
  100. { "SiS5581", PCI_DEVICE_ID_SI_5581, ATA_33 },
  101. { "SiS5596", PCI_DEVICE_ID_SI_5596, ATA_16 },
  102. { "SiS5571", PCI_DEVICE_ID_SI_5571, ATA_16 },
  103. { "SiS5517", PCI_DEVICE_ID_SI_5517, ATA_16 },
  104. { "SiS551x", PCI_DEVICE_ID_SI_5511, ATA_16 },
  105. };
  106. /* Cycle time bits and values vary across chip dma capabilities
  107. These three arrays hold the register layout and the values to set.
  108. Indexed by chipset_family and (dma_mode - XFER_UDMA_0) */
  109. /* {0, ATA_16, ATA_33, ATA_66, ATA_100a, ATA_100, ATA_133} */
  110. static u8 cycle_time_offset[] = {0,0,5,4,4,0,0};
  111. static u8 cycle_time_range[] = {0,0,2,3,3,4,4};
  112. static u8 cycle_time_value[][XFER_UDMA_6 - XFER_UDMA_0 + 1] = {
  113. {0,0,0,0,0,0,0}, /* no udma */
  114. {0,0,0,0,0,0,0}, /* no udma */
  115. {3,2,1,0,0,0,0}, /* ATA_33 */
  116. {7,5,3,2,1,0,0}, /* ATA_66 */
  117. {7,5,3,2,1,0,0}, /* ATA_100a (730 specific), differences are on cycle_time range and offset */
  118. {11,7,5,4,2,1,0}, /* ATA_100 */
  119. {15,10,7,5,3,2,1}, /* ATA_133a (earliest 691 southbridges) */
  120. {15,10,7,5,3,2,1}, /* ATA_133 */
  121. };
  122. /* CRC Valid Setup Time vary across IDE clock setting 33/66/100/133
  123. See SiS962 data sheet for more detail */
  124. static u8 cvs_time_value[][XFER_UDMA_6 - XFER_UDMA_0 + 1] = {
  125. {0,0,0,0,0,0,0}, /* no udma */
  126. {0,0,0,0,0,0,0}, /* no udma */
  127. {2,1,1,0,0,0,0},
  128. {4,3,2,1,0,0,0},
  129. {4,3,2,1,0,0,0},
  130. {6,4,3,1,1,1,0},
  131. {9,6,4,2,2,2,2},
  132. {9,6,4,2,2,2,2},
  133. };
  134. /* Initialize time, Active time, Recovery time vary across
  135. IDE clock settings. These 3 arrays hold the register value
  136. for PIO0/1/2/3/4 and DMA0/1/2 mode in order */
  137. static u8 ini_time_value[][8] = {
  138. {0,0,0,0,0,0,0,0},
  139. {0,0,0,0,0,0,0,0},
  140. {2,1,0,0,0,1,0,0},
  141. {4,3,1,1,1,3,1,1},
  142. {4,3,1,1,1,3,1,1},
  143. {6,4,2,2,2,4,2,2},
  144. {9,6,3,3,3,6,3,3},
  145. {9,6,3,3,3,6,3,3},
  146. };
  147. static u8 act_time_value[][8] = {
  148. {0,0,0,0,0,0,0,0},
  149. {0,0,0,0,0,0,0,0},
  150. {9,9,9,2,2,7,2,2},
  151. {19,19,19,5,4,14,5,4},
  152. {19,19,19,5,4,14,5,4},
  153. {28,28,28,7,6,21,7,6},
  154. {38,38,38,10,9,28,10,9},
  155. {38,38,38,10,9,28,10,9},
  156. };
  157. static u8 rco_time_value[][8] = {
  158. {0,0,0,0,0,0,0,0},
  159. {0,0,0,0,0,0,0,0},
  160. {9,2,0,2,0,7,1,1},
  161. {19,5,1,5,2,16,3,2},
  162. {19,5,1,5,2,16,3,2},
  163. {30,9,3,9,4,25,6,4},
  164. {40,12,4,12,5,34,12,5},
  165. {40,12,4,12,5,34,12,5},
  166. };
  167. /*
  168. * Printing configuration
  169. */
  170. /* Used for chipset type printing at boot time */
  171. static char* chipset_capability[] = {
  172. "ATA", "ATA 16",
  173. "ATA 33", "ATA 66",
  174. "ATA 100 (1st gen)", "ATA 100 (2nd gen)",
  175. "ATA 133 (1st gen)", "ATA 133 (2nd gen)"
  176. };
  177. /*
  178. * Configuration functions
  179. */
  180. static u8 sis_ata133_get_base(ide_drive_t *drive)
  181. {
  182. struct pci_dev *dev = drive->hwif->pci_dev;
  183. u32 reg54 = 0;
  184. pci_read_config_dword(dev, 0x54, &reg54);
  185. return ((reg54 & 0x40000000) ? 0x70 : 0x40) + drive->dn * 4;
  186. }
  187. static void sis_ata16_program_timings(ide_drive_t *drive, const u8 mode)
  188. {
  189. struct pci_dev *dev = drive->hwif->pci_dev;
  190. u16 t1 = 0;
  191. u8 drive_pci = 0x40 + drive->dn * 2;
  192. const u16 pio_timings[] = { 0x000, 0x607, 0x404, 0x303, 0x301 };
  193. const u16 mwdma_timings[] = { 0x008, 0x302, 0x301 };
  194. pci_read_config_word(dev, drive_pci, &t1);
  195. /* clear active/recovery timings */
  196. t1 &= ~0x070f;
  197. if (mode >= XFER_MW_DMA_0) {
  198. if (chipset_family > ATA_16)
  199. t1 &= ~0x8000; /* disable UDMA */
  200. t1 |= mwdma_timings[mode - XFER_MW_DMA_0];
  201. } else
  202. t1 |= pio_timings[mode - XFER_PIO_0];
  203. pci_write_config_word(dev, drive_pci, t1);
  204. }
  205. static void sis_ata100_program_timings(ide_drive_t *drive, const u8 mode)
  206. {
  207. struct pci_dev *dev = drive->hwif->pci_dev;
  208. u8 t1, drive_pci = 0x40 + drive->dn * 2;
  209. /* timing bits: 7:4 active 3:0 recovery */
  210. const u8 pio_timings[] = { 0x00, 0x67, 0x44, 0x33, 0x31 };
  211. const u8 mwdma_timings[] = { 0x08, 0x32, 0x31 };
  212. if (mode >= XFER_MW_DMA_0) {
  213. u8 t2 = 0;
  214. pci_read_config_byte(dev, drive_pci, &t2);
  215. t2 &= ~0x80; /* disable UDMA */
  216. pci_write_config_byte(dev, drive_pci, t2);
  217. t1 = mwdma_timings[mode - XFER_MW_DMA_0];
  218. } else
  219. t1 = pio_timings[mode - XFER_PIO_0];
  220. pci_write_config_byte(dev, drive_pci + 1, t1);
  221. }
  222. static void sis_ata133_program_timings(ide_drive_t *drive, const u8 mode)
  223. {
  224. struct pci_dev *dev = drive->hwif->pci_dev;
  225. u32 t1 = 0;
  226. u8 drive_pci = sis_ata133_get_base(drive), clk, idx;
  227. pci_read_config_dword(dev, drive_pci, &t1);
  228. t1 &= 0xc0c00fff;
  229. clk = (t1 & 0x08) ? ATA_133 : ATA_100;
  230. if (mode >= XFER_MW_DMA_0) {
  231. t1 &= ~0x04; /* disable UDMA */
  232. idx = mode - XFER_MW_DMA_0 + 5;
  233. } else
  234. idx = mode - XFER_PIO_0;
  235. t1 |= ini_time_value[clk][idx] << 12;
  236. t1 |= act_time_value[clk][idx] << 16;
  237. t1 |= rco_time_value[clk][idx] << 24;
  238. pci_write_config_dword(dev, drive_pci, t1);
  239. }
  240. static void sis_program_timings(ide_drive_t *drive, const u8 mode)
  241. {
  242. if (chipset_family < ATA_100) /* ATA_16/33/66/100a */
  243. sis_ata16_program_timings(drive, mode);
  244. else if (chipset_family < ATA_133) /* ATA_100/133a */
  245. sis_ata100_program_timings(drive, mode);
  246. else /* ATA_133 */
  247. sis_ata133_program_timings(drive, mode);
  248. }
  249. static void config_drive_art_rwp (ide_drive_t *drive)
  250. {
  251. ide_hwif_t *hwif = HWIF(drive);
  252. struct pci_dev *dev = hwif->pci_dev;
  253. u8 reg4bh = 0;
  254. u8 rw_prefetch = 0;
  255. pci_read_config_byte(dev, 0x4b, &reg4bh);
  256. if (drive->media == ide_disk)
  257. rw_prefetch = 0x11 << drive->dn;
  258. if ((reg4bh & (0x11 << drive->dn)) != rw_prefetch)
  259. pci_write_config_byte(dev, 0x4b, reg4bh|rw_prefetch);
  260. }
  261. static void sis_set_pio_mode(ide_drive_t *drive, const u8 pio)
  262. {
  263. config_drive_art_rwp(drive);
  264. sis_program_timings(drive, XFER_PIO_0 + pio);
  265. }
  266. static void sis_set_dma_mode(ide_drive_t *drive, const u8 speed)
  267. {
  268. ide_hwif_t *hwif = HWIF(drive);
  269. struct pci_dev *dev = hwif->pci_dev;
  270. /* Config chip for mode */
  271. switch(speed) {
  272. case XFER_UDMA_6:
  273. case XFER_UDMA_5:
  274. case XFER_UDMA_4:
  275. case XFER_UDMA_3:
  276. case XFER_UDMA_2:
  277. case XFER_UDMA_1:
  278. case XFER_UDMA_0:
  279. if (chipset_family >= ATA_133) {
  280. u32 regdw = 0;
  281. u8 drive_pci = sis_ata133_get_base(drive);
  282. pci_read_config_dword(dev, drive_pci, &regdw);
  283. regdw |= 0x04;
  284. regdw &= 0xfffff00f;
  285. /* check if ATA133 enable */
  286. if (regdw & 0x08) {
  287. regdw |= (unsigned long)cycle_time_value[ATA_133][speed-XFER_UDMA_0] << 4;
  288. regdw |= (unsigned long)cvs_time_value[ATA_133][speed-XFER_UDMA_0] << 8;
  289. } else {
  290. regdw |= (unsigned long)cycle_time_value[ATA_100][speed-XFER_UDMA_0] << 4;
  291. regdw |= (unsigned long)cvs_time_value[ATA_100][speed-XFER_UDMA_0] << 8;
  292. }
  293. pci_write_config_dword(dev, (unsigned long)drive_pci, regdw);
  294. } else {
  295. u8 drive_pci = 0x40 + drive->dn * 2, reg = 0;
  296. pci_read_config_byte(dev, drive_pci+1, &reg);
  297. /* Force the UDMA bit on if we want to use UDMA */
  298. reg |= 0x80;
  299. /* clean reg cycle time bits */
  300. reg &= ~((0xFF >> (8 - cycle_time_range[chipset_family]))
  301. << cycle_time_offset[chipset_family]);
  302. /* set reg cycle time bits */
  303. reg |= cycle_time_value[chipset_family][speed-XFER_UDMA_0]
  304. << cycle_time_offset[chipset_family];
  305. pci_write_config_byte(dev, drive_pci+1, reg);
  306. }
  307. break;
  308. case XFER_MW_DMA_2:
  309. case XFER_MW_DMA_1:
  310. case XFER_MW_DMA_0:
  311. sis_program_timings(drive, speed);
  312. break;
  313. default:
  314. BUG();
  315. break;
  316. }
  317. }
  318. static u8 sis5513_ata133_udma_filter(ide_drive_t *drive)
  319. {
  320. struct pci_dev *dev = drive->hwif->pci_dev;
  321. u32 regdw = 0;
  322. u8 drive_pci = sis_ata133_get_base(drive);
  323. pci_read_config_dword(dev, drive_pci, &regdw);
  324. /* if ATA133 disable, we should not set speed above UDMA5 */
  325. return (regdw & 0x08) ? ATA_UDMA6 : ATA_UDMA5;
  326. }
  327. /* Chip detection and general config */
  328. static unsigned int __devinit init_chipset_sis5513 (struct pci_dev *dev, const char *name)
  329. {
  330. struct pci_dev *host;
  331. int i = 0;
  332. chipset_family = 0;
  333. for (i = 0; i < ARRAY_SIZE(SiSHostChipInfo) && !chipset_family; i++) {
  334. host = pci_get_device(PCI_VENDOR_ID_SI, SiSHostChipInfo[i].host_id, NULL);
  335. if (!host)
  336. continue;
  337. chipset_family = SiSHostChipInfo[i].chipset_family;
  338. /* Special case for SiS630 : 630S/ET is ATA_100a */
  339. if (SiSHostChipInfo[i].host_id == PCI_DEVICE_ID_SI_630) {
  340. if (host->revision >= 0x30)
  341. chipset_family = ATA_100a;
  342. }
  343. pci_dev_put(host);
  344. printk(KERN_INFO "SIS5513: %s %s controller\n",
  345. SiSHostChipInfo[i].name, chipset_capability[chipset_family]);
  346. }
  347. if (!chipset_family) { /* Belongs to pci-quirks */
  348. u32 idemisc;
  349. u16 trueid;
  350. /* Disable ID masking and register remapping */
  351. pci_read_config_dword(dev, 0x54, &idemisc);
  352. pci_write_config_dword(dev, 0x54, (idemisc & 0x7fffffff));
  353. pci_read_config_word(dev, PCI_DEVICE_ID, &trueid);
  354. pci_write_config_dword(dev, 0x54, idemisc);
  355. if (trueid == 0x5518) {
  356. printk(KERN_INFO "SIS5513: SiS 962/963 MuTIOL IDE UDMA133 controller\n");
  357. chipset_family = ATA_133;
  358. /* Check for 5513 compability mapping
  359. * We must use this, else the port enabled code will fail,
  360. * as it expects the enablebits at 0x4a.
  361. */
  362. if ((idemisc & 0x40000000) == 0) {
  363. pci_write_config_dword(dev, 0x54, idemisc | 0x40000000);
  364. printk(KERN_INFO "SIS5513: Switching to 5513 register mapping\n");
  365. }
  366. }
  367. }
  368. if (!chipset_family) { /* Belongs to pci-quirks */
  369. struct pci_dev *lpc_bridge;
  370. u16 trueid;
  371. u8 prefctl;
  372. u8 idecfg;
  373. pci_read_config_byte(dev, 0x4a, &idecfg);
  374. pci_write_config_byte(dev, 0x4a, idecfg | 0x10);
  375. pci_read_config_word(dev, PCI_DEVICE_ID, &trueid);
  376. pci_write_config_byte(dev, 0x4a, idecfg);
  377. if (trueid == 0x5517) { /* SiS 961/961B */
  378. lpc_bridge = pci_get_slot(dev->bus, 0x10); /* Bus 0, Dev 2, Fn 0 */
  379. pci_read_config_byte(dev, 0x49, &prefctl);
  380. pci_dev_put(lpc_bridge);
  381. if (lpc_bridge->revision == 0x10 && (prefctl & 0x80)) {
  382. printk(KERN_INFO "SIS5513: SiS 961B MuTIOL IDE UDMA133 controller\n");
  383. chipset_family = ATA_133a;
  384. } else {
  385. printk(KERN_INFO "SIS5513: SiS 961 MuTIOL IDE UDMA100 controller\n");
  386. chipset_family = ATA_100;
  387. }
  388. }
  389. }
  390. if (!chipset_family)
  391. return -1;
  392. /* Make general config ops here
  393. 1/ tell IDE channels to operate in Compatibility mode only
  394. 2/ tell old chips to allow per drive IDE timings */
  395. {
  396. u8 reg;
  397. u16 regw;
  398. switch(chipset_family) {
  399. case ATA_133:
  400. /* SiS962 operation mode */
  401. pci_read_config_word(dev, 0x50, &regw);
  402. if (regw & 0x08)
  403. pci_write_config_word(dev, 0x50, regw&0xfff7);
  404. pci_read_config_word(dev, 0x52, &regw);
  405. if (regw & 0x08)
  406. pci_write_config_word(dev, 0x52, regw&0xfff7);
  407. break;
  408. case ATA_133a:
  409. case ATA_100:
  410. /* Fixup latency */
  411. pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x80);
  412. /* Set compatibility bit */
  413. pci_read_config_byte(dev, 0x49, &reg);
  414. if (!(reg & 0x01)) {
  415. pci_write_config_byte(dev, 0x49, reg|0x01);
  416. }
  417. break;
  418. case ATA_100a:
  419. case ATA_66:
  420. /* Fixup latency */
  421. pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x10);
  422. /* On ATA_66 chips the bit was elsewhere */
  423. pci_read_config_byte(dev, 0x52, &reg);
  424. if (!(reg & 0x04)) {
  425. pci_write_config_byte(dev, 0x52, reg|0x04);
  426. }
  427. break;
  428. case ATA_33:
  429. /* On ATA_33 we didn't have a single bit to set */
  430. pci_read_config_byte(dev, 0x09, &reg);
  431. if ((reg & 0x0f) != 0x00) {
  432. pci_write_config_byte(dev, 0x09, reg&0xf0);
  433. }
  434. case ATA_16:
  435. /* force per drive recovery and active timings
  436. needed on ATA_33 and below chips */
  437. pci_read_config_byte(dev, 0x52, &reg);
  438. if (!(reg & 0x08)) {
  439. pci_write_config_byte(dev, 0x52, reg|0x08);
  440. }
  441. break;
  442. }
  443. }
  444. return 0;
  445. }
  446. struct sis_laptop {
  447. u16 device;
  448. u16 subvendor;
  449. u16 subdevice;
  450. };
  451. static const struct sis_laptop sis_laptop[] = {
  452. /* devid, subvendor, subdev */
  453. { 0x5513, 0x1043, 0x1107 }, /* ASUS A6K */
  454. { 0x5513, 0x1734, 0x105f }, /* FSC Amilo A1630 */
  455. /* end marker */
  456. { 0, }
  457. };
  458. static u8 __devinit ata66_sis5513(ide_hwif_t *hwif)
  459. {
  460. struct pci_dev *pdev = hwif->pci_dev;
  461. const struct sis_laptop *lap = &sis_laptop[0];
  462. u8 ata66 = 0;
  463. while (lap->device) {
  464. if (lap->device == pdev->device &&
  465. lap->subvendor == pdev->subsystem_vendor &&
  466. lap->subdevice == pdev->subsystem_device)
  467. return ATA_CBL_PATA40_SHORT;
  468. lap++;
  469. }
  470. if (chipset_family >= ATA_133) {
  471. u16 regw = 0;
  472. u16 reg_addr = hwif->channel ? 0x52: 0x50;
  473. pci_read_config_word(hwif->pci_dev, reg_addr, &regw);
  474. ata66 = (regw & 0x8000) ? 0 : 1;
  475. } else if (chipset_family >= ATA_66) {
  476. u8 reg48h = 0;
  477. u8 mask = hwif->channel ? 0x20 : 0x10;
  478. pci_read_config_byte(hwif->pci_dev, 0x48, &reg48h);
  479. ata66 = (reg48h & mask) ? 0 : 1;
  480. }
  481. return ata66 ? ATA_CBL_PATA80 : ATA_CBL_PATA40;
  482. }
  483. static void __devinit init_hwif_sis5513 (ide_hwif_t *hwif)
  484. {
  485. u8 udma_rates[] = { 0x00, 0x00, 0x07, 0x1f, 0x3f, 0x3f, 0x7f, 0x7f };
  486. hwif->set_pio_mode = &sis_set_pio_mode;
  487. hwif->set_dma_mode = &sis_set_dma_mode;
  488. if (chipset_family >= ATA_133)
  489. hwif->udma_filter = sis5513_ata133_udma_filter;
  490. if (hwif->dma_base == 0)
  491. return;
  492. hwif->ultra_mask = udma_rates[chipset_family];
  493. if (hwif->cbl != ATA_CBL_PATA40_SHORT)
  494. hwif->cbl = ata66_sis5513(hwif);
  495. }
  496. static const struct ide_port_info sis5513_chipset __devinitdata = {
  497. .name = "SIS5513",
  498. .init_chipset = init_chipset_sis5513,
  499. .init_hwif = init_hwif_sis5513,
  500. .enablebits = {{0x4a,0x02,0x02}, {0x4a,0x04,0x04}},
  501. .host_flags = IDE_HFLAG_LEGACY_IRQS | IDE_HFLAG_NO_AUTODMA |
  502. IDE_HFLAG_BOOTABLE,
  503. .pio_mask = ATA_PIO4,
  504. .mwdma_mask = ATA_MWDMA2,
  505. };
  506. static int __devinit sis5513_init_one(struct pci_dev *dev, const struct pci_device_id *id)
  507. {
  508. return ide_setup_pci_device(dev, &sis5513_chipset);
  509. }
  510. static const struct pci_device_id sis5513_pci_tbl[] = {
  511. { PCI_VDEVICE(SI, PCI_DEVICE_ID_SI_5513), 0 },
  512. { PCI_VDEVICE(SI, PCI_DEVICE_ID_SI_5518), 0 },
  513. { PCI_VDEVICE(SI, PCI_DEVICE_ID_SI_1180), 0 },
  514. { 0, },
  515. };
  516. MODULE_DEVICE_TABLE(pci, sis5513_pci_tbl);
  517. static struct pci_driver driver = {
  518. .name = "SIS_IDE",
  519. .id_table = sis5513_pci_tbl,
  520. .probe = sis5513_init_one,
  521. };
  522. static int __init sis5513_ide_init(void)
  523. {
  524. return ide_pci_register_driver(&driver);
  525. }
  526. module_init(sis5513_ide_init);
  527. MODULE_AUTHOR("Lionel Bouton, L C Chang, Andre Hedrick, Vojtech Pavlik");
  528. MODULE_DESCRIPTION("PCI driver module for SIS IDE");
  529. MODULE_LICENSE("GPL");
  530. /*
  531. * TODO:
  532. * - CLEANUP
  533. * - Use drivers/ide/ide-timing.h !
  534. * - More checks in the config registers (force values instead of
  535. * relying on the BIOS setting them correctly).
  536. * - Further optimisations ?
  537. * . for example ATA66+ regs 0x48 & 0x4A
  538. */