sis5513.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917
  1. /*
  2. * linux/drivers/ide/pci/sis5513.c Version 0.27 Jul 14, 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. #define DISPLAY_SIS_TIMINGS
  63. /* registers layout and init values are chipset family dependant */
  64. #define ATA_16 0x01
  65. #define ATA_33 0x02
  66. #define ATA_66 0x03
  67. #define ATA_100a 0x04 // SiS730/SiS550 is ATA100 with ATA66 layout
  68. #define ATA_100 0x05
  69. #define ATA_133a 0x06 // SiS961b with 133 support
  70. #define ATA_133 0x07 // SiS962/963
  71. static u8 chipset_family;
  72. /*
  73. * Devices supported
  74. */
  75. static const struct {
  76. const char *name;
  77. u16 host_id;
  78. u8 chipset_family;
  79. u8 flags;
  80. } SiSHostChipInfo[] = {
  81. { "SiS968", PCI_DEVICE_ID_SI_968, ATA_133 },
  82. { "SiS966", PCI_DEVICE_ID_SI_966, ATA_133 },
  83. { "SiS965", PCI_DEVICE_ID_SI_965, ATA_133 },
  84. { "SiS745", PCI_DEVICE_ID_SI_745, ATA_100 },
  85. { "SiS735", PCI_DEVICE_ID_SI_735, ATA_100 },
  86. { "SiS733", PCI_DEVICE_ID_SI_733, ATA_100 },
  87. { "SiS635", PCI_DEVICE_ID_SI_635, ATA_100 },
  88. { "SiS633", PCI_DEVICE_ID_SI_633, ATA_100 },
  89. { "SiS730", PCI_DEVICE_ID_SI_730, ATA_100a },
  90. { "SiS550", PCI_DEVICE_ID_SI_550, ATA_100a },
  91. { "SiS640", PCI_DEVICE_ID_SI_640, ATA_66 },
  92. { "SiS630", PCI_DEVICE_ID_SI_630, ATA_66 },
  93. { "SiS620", PCI_DEVICE_ID_SI_620, ATA_66 },
  94. { "SiS540", PCI_DEVICE_ID_SI_540, ATA_66 },
  95. { "SiS530", PCI_DEVICE_ID_SI_530, ATA_66 },
  96. { "SiS5600", PCI_DEVICE_ID_SI_5600, ATA_33 },
  97. { "SiS5598", PCI_DEVICE_ID_SI_5598, ATA_33 },
  98. { "SiS5597", PCI_DEVICE_ID_SI_5597, ATA_33 },
  99. { "SiS5591/2", PCI_DEVICE_ID_SI_5591, ATA_33 },
  100. { "SiS5582", PCI_DEVICE_ID_SI_5582, ATA_33 },
  101. { "SiS5581", PCI_DEVICE_ID_SI_5581, ATA_33 },
  102. { "SiS5596", PCI_DEVICE_ID_SI_5596, ATA_16 },
  103. { "SiS5571", PCI_DEVICE_ID_SI_5571, ATA_16 },
  104. { "SiS5517", PCI_DEVICE_ID_SI_5517, ATA_16 },
  105. { "SiS551x", PCI_DEVICE_ID_SI_5511, ATA_16 },
  106. };
  107. /* Cycle time bits and values vary across chip dma capabilities
  108. These three arrays hold the register layout and the values to set.
  109. Indexed by chipset_family and (dma_mode - XFER_UDMA_0) */
  110. /* {0, ATA_16, ATA_33, ATA_66, ATA_100a, ATA_100, ATA_133} */
  111. static u8 cycle_time_offset[] = {0,0,5,4,4,0,0};
  112. static u8 cycle_time_range[] = {0,0,2,3,3,4,4};
  113. static u8 cycle_time_value[][XFER_UDMA_6 - XFER_UDMA_0 + 1] = {
  114. {0,0,0,0,0,0,0}, /* no udma */
  115. {0,0,0,0,0,0,0}, /* no udma */
  116. {3,2,1,0,0,0,0}, /* ATA_33 */
  117. {7,5,3,2,1,0,0}, /* ATA_66 */
  118. {7,5,3,2,1,0,0}, /* ATA_100a (730 specific), differences are on cycle_time range and offset */
  119. {11,7,5,4,2,1,0}, /* ATA_100 */
  120. {15,10,7,5,3,2,1}, /* ATA_133a (earliest 691 southbridges) */
  121. {15,10,7,5,3,2,1}, /* ATA_133 */
  122. };
  123. /* CRC Valid Setup Time vary across IDE clock setting 33/66/100/133
  124. See SiS962 data sheet for more detail */
  125. static u8 cvs_time_value[][XFER_UDMA_6 - XFER_UDMA_0 + 1] = {
  126. {0,0,0,0,0,0,0}, /* no udma */
  127. {0,0,0,0,0,0,0}, /* no udma */
  128. {2,1,1,0,0,0,0},
  129. {4,3,2,1,0,0,0},
  130. {4,3,2,1,0,0,0},
  131. {6,4,3,1,1,1,0},
  132. {9,6,4,2,2,2,2},
  133. {9,6,4,2,2,2,2},
  134. };
  135. /* Initialize time, Active time, Recovery time vary across
  136. IDE clock settings. These 3 arrays hold the register value
  137. for PIO0/1/2/3/4 and DMA0/1/2 mode in order */
  138. static u8 ini_time_value[][8] = {
  139. {0,0,0,0,0,0,0,0},
  140. {0,0,0,0,0,0,0,0},
  141. {2,1,0,0,0,1,0,0},
  142. {4,3,1,1,1,3,1,1},
  143. {4,3,1,1,1,3,1,1},
  144. {6,4,2,2,2,4,2,2},
  145. {9,6,3,3,3,6,3,3},
  146. {9,6,3,3,3,6,3,3},
  147. };
  148. static u8 act_time_value[][8] = {
  149. {0,0,0,0,0,0,0,0},
  150. {0,0,0,0,0,0,0,0},
  151. {9,9,9,2,2,7,2,2},
  152. {19,19,19,5,4,14,5,4},
  153. {19,19,19,5,4,14,5,4},
  154. {28,28,28,7,6,21,7,6},
  155. {38,38,38,10,9,28,10,9},
  156. {38,38,38,10,9,28,10,9},
  157. };
  158. static u8 rco_time_value[][8] = {
  159. {0,0,0,0,0,0,0,0},
  160. {0,0,0,0,0,0,0,0},
  161. {9,2,0,2,0,7,1,1},
  162. {19,5,1,5,2,16,3,2},
  163. {19,5,1,5,2,16,3,2},
  164. {30,9,3,9,4,25,6,4},
  165. {40,12,4,12,5,34,12,5},
  166. {40,12,4,12,5,34,12,5},
  167. };
  168. /*
  169. * Printing configuration
  170. */
  171. /* Used for chipset type printing at boot time */
  172. static char* chipset_capability[] = {
  173. "ATA", "ATA 16",
  174. "ATA 33", "ATA 66",
  175. "ATA 100 (1st gen)", "ATA 100 (2nd gen)",
  176. "ATA 133 (1st gen)", "ATA 133 (2nd gen)"
  177. };
  178. #if defined(DISPLAY_SIS_TIMINGS) && defined(CONFIG_IDE_PROC_FS)
  179. #include <linux/stat.h>
  180. #include <linux/proc_fs.h>
  181. static u8 sis_proc = 0;
  182. static struct pci_dev *bmide_dev;
  183. static char* cable_type[] = {
  184. "80 pins",
  185. "40 pins"
  186. };
  187. static char* recovery_time[] ={
  188. "12 PCICLK", "1 PCICLK",
  189. "2 PCICLK", "3 PCICLK",
  190. "4 PCICLK", "5 PCICLCK",
  191. "6 PCICLK", "7 PCICLCK",
  192. "8 PCICLK", "9 PCICLCK",
  193. "10 PCICLK", "11 PCICLK",
  194. "13 PCICLK", "14 PCICLK",
  195. "15 PCICLK", "15 PCICLK"
  196. };
  197. static char* active_time[] = {
  198. "8 PCICLK", "1 PCICLCK",
  199. "2 PCICLK", "3 PCICLK",
  200. "4 PCICLK", "5 PCICLK",
  201. "6 PCICLK", "12 PCICLK"
  202. };
  203. static char* cycle_time[] = {
  204. "Reserved", "2 CLK",
  205. "3 CLK", "4 CLK",
  206. "5 CLK", "6 CLK",
  207. "7 CLK", "8 CLK",
  208. "9 CLK", "10 CLK",
  209. "11 CLK", "12 CLK",
  210. "13 CLK", "14 CLK",
  211. "15 CLK", "16 CLK"
  212. };
  213. /* Generic add master or slave info function */
  214. static char* get_drives_info (char *buffer, u8 pos)
  215. {
  216. u8 reg00, reg01, reg10, reg11; /* timing registers */
  217. u32 regdw0, regdw1;
  218. char* p = buffer;
  219. /* Postwrite/Prefetch */
  220. if (chipset_family < ATA_133) {
  221. pci_read_config_byte(bmide_dev, 0x4b, &reg00);
  222. p += sprintf(p, "Drive %d: Postwrite %s \t \t Postwrite %s\n",
  223. pos, (reg00 & (0x10 << pos)) ? "Enabled" : "Disabled",
  224. (reg00 & (0x40 << pos)) ? "Enabled" : "Disabled");
  225. p += sprintf(p, " Prefetch %s \t \t Prefetch %s\n",
  226. (reg00 & (0x01 << pos)) ? "Enabled" : "Disabled",
  227. (reg00 & (0x04 << pos)) ? "Enabled" : "Disabled");
  228. pci_read_config_byte(bmide_dev, 0x40+2*pos, &reg00);
  229. pci_read_config_byte(bmide_dev, 0x41+2*pos, &reg01);
  230. pci_read_config_byte(bmide_dev, 0x44+2*pos, &reg10);
  231. pci_read_config_byte(bmide_dev, 0x45+2*pos, &reg11);
  232. } else {
  233. u32 reg54h;
  234. u8 drive_pci = 0x40;
  235. pci_read_config_dword(bmide_dev, 0x54, &reg54h);
  236. if (reg54h & 0x40000000) {
  237. // Configuration space remapped to 0x70
  238. drive_pci = 0x70;
  239. }
  240. pci_read_config_dword(bmide_dev, (unsigned long)drive_pci+4*pos, &regdw0);
  241. pci_read_config_dword(bmide_dev, (unsigned long)drive_pci+4*pos+8, &regdw1);
  242. p += sprintf(p, "Drive %d:\n", pos);
  243. }
  244. /* UDMA */
  245. if (chipset_family >= ATA_133) {
  246. p += sprintf(p, " UDMA %s \t \t \t UDMA %s\n",
  247. (regdw0 & 0x04) ? "Enabled" : "Disabled",
  248. (regdw1 & 0x04) ? "Enabled" : "Disabled");
  249. p += sprintf(p, " UDMA Cycle Time %s \t UDMA Cycle Time %s\n",
  250. cycle_time[(regdw0 & 0xF0) >> 4],
  251. cycle_time[(regdw1 & 0xF0) >> 4]);
  252. } else if (chipset_family >= ATA_33) {
  253. p += sprintf(p, " UDMA %s \t \t \t UDMA %s\n",
  254. (reg01 & 0x80) ? "Enabled" : "Disabled",
  255. (reg11 & 0x80) ? "Enabled" : "Disabled");
  256. p += sprintf(p, " UDMA Cycle Time ");
  257. switch(chipset_family) {
  258. case ATA_33: p += sprintf(p, cycle_time[(reg01 & 0x60) >> 5]); break;
  259. case ATA_66:
  260. case ATA_100a: p += sprintf(p, cycle_time[(reg01 & 0x70) >> 4]); break;
  261. case ATA_100:
  262. case ATA_133a: p += sprintf(p, cycle_time[reg01 & 0x0F]); break;
  263. default: p += sprintf(p, "?"); break;
  264. }
  265. p += sprintf(p, " \t UDMA Cycle Time ");
  266. switch(chipset_family) {
  267. case ATA_33: p += sprintf(p, cycle_time[(reg11 & 0x60) >> 5]); break;
  268. case ATA_66:
  269. case ATA_100a: p += sprintf(p, cycle_time[(reg11 & 0x70) >> 4]); break;
  270. case ATA_100:
  271. case ATA_133a: p += sprintf(p, cycle_time[reg11 & 0x0F]); break;
  272. default: p += sprintf(p, "?"); break;
  273. }
  274. p += sprintf(p, "\n");
  275. }
  276. if (chipset_family < ATA_133) { /* else case TODO */
  277. /* Data Active */
  278. p += sprintf(p, " Data Active Time ");
  279. switch(chipset_family) {
  280. case ATA_16: /* confirmed */
  281. case ATA_33:
  282. case ATA_66:
  283. case ATA_100a: p += sprintf(p, active_time[reg01 & 0x07]); break;
  284. case ATA_100:
  285. case ATA_133a: p += sprintf(p, active_time[(reg00 & 0x70) >> 4]); break;
  286. default: p += sprintf(p, "?"); break;
  287. }
  288. p += sprintf(p, " \t Data Active Time ");
  289. switch(chipset_family) {
  290. case ATA_16:
  291. case ATA_33:
  292. case ATA_66:
  293. case ATA_100a: p += sprintf(p, active_time[reg11 & 0x07]); break;
  294. case ATA_100:
  295. case ATA_133a: p += sprintf(p, active_time[(reg10 & 0x70) >> 4]); break;
  296. default: p += sprintf(p, "?"); break;
  297. }
  298. p += sprintf(p, "\n");
  299. /* Data Recovery */
  300. /* warning: may need (reg&0x07) for pre ATA66 chips */
  301. p += sprintf(p, " Data Recovery Time %s \t Data Recovery Time %s\n",
  302. recovery_time[reg00 & 0x0f], recovery_time[reg10 & 0x0f]);
  303. }
  304. return p;
  305. }
  306. static char* get_masters_info(char* buffer)
  307. {
  308. return get_drives_info(buffer, 0);
  309. }
  310. static char* get_slaves_info(char* buffer)
  311. {
  312. return get_drives_info(buffer, 1);
  313. }
  314. /* Main get_info, called on /proc/ide/sis reads */
  315. static int sis_get_info (char *buffer, char **addr, off_t offset, int count)
  316. {
  317. char *p = buffer;
  318. int len;
  319. u8 reg;
  320. u16 reg2, reg3;
  321. p += sprintf(p, "\nSiS 5513 ");
  322. switch(chipset_family) {
  323. case ATA_16: p += sprintf(p, "DMA 16"); break;
  324. case ATA_33: p += sprintf(p, "Ultra 33"); break;
  325. case ATA_66: p += sprintf(p, "Ultra 66"); break;
  326. case ATA_100a:
  327. case ATA_100: p += sprintf(p, "Ultra 100"); break;
  328. case ATA_133a:
  329. case ATA_133: p += sprintf(p, "Ultra 133"); break;
  330. default: p+= sprintf(p, "Unknown???"); break;
  331. }
  332. p += sprintf(p, " chipset\n");
  333. p += sprintf(p, "--------------- Primary Channel "
  334. "---------------- Secondary Channel "
  335. "-------------\n");
  336. /* Status */
  337. pci_read_config_byte(bmide_dev, 0x4a, &reg);
  338. if (chipset_family == ATA_133) {
  339. pci_read_config_word(bmide_dev, 0x50, &reg2);
  340. pci_read_config_word(bmide_dev, 0x52, &reg3);
  341. }
  342. p += sprintf(p, "Channel Status: ");
  343. if (chipset_family < ATA_66) {
  344. p += sprintf(p, "%s \t \t \t \t %s\n",
  345. (reg & 0x04) ? "On" : "Off",
  346. (reg & 0x02) ? "On" : "Off");
  347. } else if (chipset_family < ATA_133) {
  348. p += sprintf(p, "%s \t \t \t \t %s \n",
  349. (reg & 0x02) ? "On" : "Off",
  350. (reg & 0x04) ? "On" : "Off");
  351. } else { /* ATA_133 */
  352. p += sprintf(p, "%s \t \t \t \t %s \n",
  353. (reg2 & 0x02) ? "On" : "Off",
  354. (reg3 & 0x02) ? "On" : "Off");
  355. }
  356. /* Operation Mode */
  357. pci_read_config_byte(bmide_dev, 0x09, &reg);
  358. p += sprintf(p, "Operation Mode: %s \t \t \t %s \n",
  359. (reg & 0x01) ? "Native" : "Compatible",
  360. (reg & 0x04) ? "Native" : "Compatible");
  361. /* 80-pin cable ? */
  362. if (chipset_family >= ATA_133) {
  363. p += sprintf(p, "Cable Type: %s \t \t \t %s\n",
  364. (reg2 & 0x01) ? cable_type[1] : cable_type[0],
  365. (reg3 & 0x01) ? cable_type[1] : cable_type[0]);
  366. } else if (chipset_family > ATA_33) {
  367. pci_read_config_byte(bmide_dev, 0x48, &reg);
  368. p += sprintf(p, "Cable Type: %s \t \t \t %s\n",
  369. (reg & 0x10) ? cable_type[1] : cable_type[0],
  370. (reg & 0x20) ? cable_type[1] : cable_type[0]);
  371. }
  372. /* Prefetch Count */
  373. if (chipset_family < ATA_133) {
  374. pci_read_config_word(bmide_dev, 0x4c, &reg2);
  375. pci_read_config_word(bmide_dev, 0x4e, &reg3);
  376. p += sprintf(p, "Prefetch Count: %d \t \t \t \t %d\n",
  377. reg2, reg3);
  378. }
  379. p = get_masters_info(p);
  380. p = get_slaves_info(p);
  381. len = (p - buffer) - offset;
  382. *addr = buffer + offset;
  383. return len > count ? count : len;
  384. }
  385. #endif /* defined(DISPLAY_SIS_TIMINGS) && defined(CONFIG_IDE_PROC_FS) */
  386. /*
  387. * Configuration functions
  388. */
  389. /* Enables per-drive prefetch and postwrite */
  390. static void config_drive_art_rwp (ide_drive_t *drive)
  391. {
  392. ide_hwif_t *hwif = HWIF(drive);
  393. struct pci_dev *dev = hwif->pci_dev;
  394. u8 reg4bh = 0;
  395. u8 rw_prefetch = (0x11 << drive->dn);
  396. if (drive->media != ide_disk)
  397. return;
  398. pci_read_config_byte(dev, 0x4b, &reg4bh);
  399. if ((reg4bh & rw_prefetch) != rw_prefetch)
  400. pci_write_config_byte(dev, 0x4b, reg4bh|rw_prefetch);
  401. }
  402. /* Set per-drive active and recovery time */
  403. static void sis_set_pio_mode(ide_drive_t *drive, const u8 pio)
  404. {
  405. ide_hwif_t *hwif = HWIF(drive);
  406. struct pci_dev *dev = hwif->pci_dev;
  407. u8 drive_pci, test1, test2;
  408. config_drive_art_rwp(drive);
  409. /* In pre ATA_133 case, drives sit at 0x40 + 4*drive->dn */
  410. drive_pci = 0x40;
  411. /* In SiS962 case drives sit at (0x40 or 0x70) + 8*drive->dn) */
  412. if (chipset_family >= ATA_133) {
  413. u32 reg54h;
  414. pci_read_config_dword(dev, 0x54, &reg54h);
  415. if (reg54h & 0x40000000) drive_pci = 0x70;
  416. drive_pci += ((drive->dn)*0x4);
  417. } else {
  418. drive_pci += ((drive->dn)*0x2);
  419. }
  420. /* register layout changed with newer ATA100 chips */
  421. if (chipset_family < ATA_100) {
  422. pci_read_config_byte(dev, drive_pci, &test1);
  423. pci_read_config_byte(dev, drive_pci+1, &test2);
  424. /* Clear active and recovery timings */
  425. test1 &= ~0x0F;
  426. test2 &= ~0x07;
  427. switch(pio) {
  428. case 4: test1 |= 0x01; test2 |= 0x03; break;
  429. case 3: test1 |= 0x03; test2 |= 0x03; break;
  430. case 2: test1 |= 0x04; test2 |= 0x04; break;
  431. case 1: test1 |= 0x07; test2 |= 0x06; break;
  432. case 0: /* PIO0: register setting == X000 */
  433. default: break;
  434. }
  435. pci_write_config_byte(dev, drive_pci, test1);
  436. pci_write_config_byte(dev, drive_pci+1, test2);
  437. } else if (chipset_family < ATA_133) {
  438. switch(pio) { /* active recovery
  439. v v */
  440. case 4: test1 = 0x30|0x01; break;
  441. case 3: test1 = 0x30|0x03; break;
  442. case 2: test1 = 0x40|0x04; break;
  443. case 1: test1 = 0x60|0x07; break;
  444. case 0: test1 = 0x00; break;
  445. default: break;
  446. }
  447. pci_write_config_byte(dev, drive_pci, test1);
  448. } else { /* ATA_133 */
  449. u32 test3;
  450. pci_read_config_dword(dev, drive_pci, &test3);
  451. test3 &= 0xc0c00fff;
  452. if (test3 & 0x08) {
  453. test3 |= ini_time_value[ATA_133][pio] << 12;
  454. test3 |= act_time_value[ATA_133][pio] << 16;
  455. test3 |= rco_time_value[ATA_133][pio] << 24;
  456. } else {
  457. test3 |= ini_time_value[ATA_100][pio] << 12;
  458. test3 |= act_time_value[ATA_100][pio] << 16;
  459. test3 |= rco_time_value[ATA_100][pio] << 24;
  460. }
  461. pci_write_config_dword(dev, drive_pci, test3);
  462. }
  463. }
  464. static void sis_set_dma_mode(ide_drive_t *drive, const u8 speed)
  465. {
  466. ide_hwif_t *hwif = HWIF(drive);
  467. struct pci_dev *dev = hwif->pci_dev;
  468. u32 regdw;
  469. u8 drive_pci, reg;
  470. /* See sis_set_pio_mode() for drive PCI config registers */
  471. drive_pci = 0x40;
  472. if (chipset_family >= ATA_133) {
  473. u32 reg54h;
  474. pci_read_config_dword(dev, 0x54, &reg54h);
  475. if (reg54h & 0x40000000) drive_pci = 0x70;
  476. drive_pci += ((drive->dn)*0x4);
  477. pci_read_config_dword(dev, (unsigned long)drive_pci, &regdw);
  478. /* Disable UDMA bit for non UDMA modes on UDMA chips */
  479. if (speed < XFER_UDMA_0) {
  480. regdw &= 0xfffffffb;
  481. pci_write_config_dword(dev, (unsigned long)drive_pci, regdw);
  482. }
  483. } else {
  484. drive_pci += ((drive->dn)*0x2);
  485. pci_read_config_byte(dev, drive_pci+1, &reg);
  486. /* Disable UDMA bit for non UDMA modes on UDMA chips */
  487. if ((speed < XFER_UDMA_0) && (chipset_family > ATA_16)) {
  488. reg &= 0x7F;
  489. pci_write_config_byte(dev, drive_pci+1, reg);
  490. }
  491. }
  492. /* Config chip for mode */
  493. switch(speed) {
  494. case XFER_UDMA_6:
  495. case XFER_UDMA_5:
  496. case XFER_UDMA_4:
  497. case XFER_UDMA_3:
  498. case XFER_UDMA_2:
  499. case XFER_UDMA_1:
  500. case XFER_UDMA_0:
  501. if (chipset_family >= ATA_133) {
  502. regdw |= 0x04;
  503. regdw &= 0xfffff00f;
  504. /* check if ATA133 enable */
  505. if (regdw & 0x08) {
  506. regdw |= (unsigned long)cycle_time_value[ATA_133][speed-XFER_UDMA_0] << 4;
  507. regdw |= (unsigned long)cvs_time_value[ATA_133][speed-XFER_UDMA_0] << 8;
  508. } else {
  509. regdw |= (unsigned long)cycle_time_value[ATA_100][speed-XFER_UDMA_0] << 4;
  510. regdw |= (unsigned long)cvs_time_value[ATA_100][speed-XFER_UDMA_0] << 8;
  511. }
  512. pci_write_config_dword(dev, (unsigned long)drive_pci, regdw);
  513. } else {
  514. /* Force the UDMA bit on if we want to use UDMA */
  515. reg |= 0x80;
  516. /* clean reg cycle time bits */
  517. reg &= ~((0xFF >> (8 - cycle_time_range[chipset_family]))
  518. << cycle_time_offset[chipset_family]);
  519. /* set reg cycle time bits */
  520. reg |= cycle_time_value[chipset_family][speed-XFER_UDMA_0]
  521. << cycle_time_offset[chipset_family];
  522. pci_write_config_byte(dev, drive_pci+1, reg);
  523. }
  524. break;
  525. case XFER_MW_DMA_2:
  526. case XFER_MW_DMA_1:
  527. case XFER_MW_DMA_0:
  528. case XFER_SW_DMA_2:
  529. case XFER_SW_DMA_1:
  530. case XFER_SW_DMA_0:
  531. break;
  532. default:
  533. BUG();
  534. break;
  535. }
  536. }
  537. static int sis5513_config_xfer_rate(ide_drive_t *drive)
  538. {
  539. /*
  540. * TODO: always set PIO mode and remove this
  541. */
  542. ide_set_max_pio(drive);
  543. drive->init_speed = 0;
  544. if (ide_tune_dma(drive))
  545. return 0;
  546. if (ide_use_fast_pio(drive))
  547. ide_set_max_pio(drive);
  548. return -1;
  549. }
  550. static u8 sis5513_ata133_udma_filter(ide_drive_t *drive)
  551. {
  552. struct pci_dev *dev = drive->hwif->pci_dev;
  553. int drive_pci;
  554. u32 reg54 = 0, regdw = 0;
  555. pci_read_config_dword(dev, 0x54, &reg54);
  556. drive_pci = ((reg54 & 0x40000000) ? 0x70 : 0x40) + drive->dn * 4;
  557. pci_read_config_dword(dev, drive_pci, &regdw);
  558. /* if ATA133 disable, we should not set speed above UDMA5 */
  559. return (regdw & 0x08) ? ATA_UDMA6 : ATA_UDMA5;
  560. }
  561. /* Chip detection and general config */
  562. static unsigned int __devinit init_chipset_sis5513 (struct pci_dev *dev, const char *name)
  563. {
  564. struct pci_dev *host;
  565. int i = 0;
  566. chipset_family = 0;
  567. for (i = 0; i < ARRAY_SIZE(SiSHostChipInfo) && !chipset_family; i++) {
  568. host = pci_get_device(PCI_VENDOR_ID_SI, SiSHostChipInfo[i].host_id, NULL);
  569. if (!host)
  570. continue;
  571. chipset_family = SiSHostChipInfo[i].chipset_family;
  572. /* Special case for SiS630 : 630S/ET is ATA_100a */
  573. if (SiSHostChipInfo[i].host_id == PCI_DEVICE_ID_SI_630) {
  574. if (host->revision >= 0x30)
  575. chipset_family = ATA_100a;
  576. }
  577. pci_dev_put(host);
  578. printk(KERN_INFO "SIS5513: %s %s controller\n",
  579. SiSHostChipInfo[i].name, chipset_capability[chipset_family]);
  580. }
  581. if (!chipset_family) { /* Belongs to pci-quirks */
  582. u32 idemisc;
  583. u16 trueid;
  584. /* Disable ID masking and register remapping */
  585. pci_read_config_dword(dev, 0x54, &idemisc);
  586. pci_write_config_dword(dev, 0x54, (idemisc & 0x7fffffff));
  587. pci_read_config_word(dev, PCI_DEVICE_ID, &trueid);
  588. pci_write_config_dword(dev, 0x54, idemisc);
  589. if (trueid == 0x5518) {
  590. printk(KERN_INFO "SIS5513: SiS 962/963 MuTIOL IDE UDMA133 controller\n");
  591. chipset_family = ATA_133;
  592. /* Check for 5513 compability mapping
  593. * We must use this, else the port enabled code will fail,
  594. * as it expects the enablebits at 0x4a.
  595. */
  596. if ((idemisc & 0x40000000) == 0) {
  597. pci_write_config_dword(dev, 0x54, idemisc | 0x40000000);
  598. printk(KERN_INFO "SIS5513: Switching to 5513 register mapping\n");
  599. }
  600. }
  601. }
  602. if (!chipset_family) { /* Belongs to pci-quirks */
  603. struct pci_dev *lpc_bridge;
  604. u16 trueid;
  605. u8 prefctl;
  606. u8 idecfg;
  607. pci_read_config_byte(dev, 0x4a, &idecfg);
  608. pci_write_config_byte(dev, 0x4a, idecfg | 0x10);
  609. pci_read_config_word(dev, PCI_DEVICE_ID, &trueid);
  610. pci_write_config_byte(dev, 0x4a, idecfg);
  611. if (trueid == 0x5517) { /* SiS 961/961B */
  612. lpc_bridge = pci_get_slot(dev->bus, 0x10); /* Bus 0, Dev 2, Fn 0 */
  613. pci_read_config_byte(dev, 0x49, &prefctl);
  614. pci_dev_put(lpc_bridge);
  615. if (lpc_bridge->revision == 0x10 && (prefctl & 0x80)) {
  616. printk(KERN_INFO "SIS5513: SiS 961B MuTIOL IDE UDMA133 controller\n");
  617. chipset_family = ATA_133a;
  618. } else {
  619. printk(KERN_INFO "SIS5513: SiS 961 MuTIOL IDE UDMA100 controller\n");
  620. chipset_family = ATA_100;
  621. }
  622. }
  623. }
  624. if (!chipset_family)
  625. return -1;
  626. /* Make general config ops here
  627. 1/ tell IDE channels to operate in Compatibility mode only
  628. 2/ tell old chips to allow per drive IDE timings */
  629. {
  630. u8 reg;
  631. u16 regw;
  632. switch(chipset_family) {
  633. case ATA_133:
  634. /* SiS962 operation mode */
  635. pci_read_config_word(dev, 0x50, &regw);
  636. if (regw & 0x08)
  637. pci_write_config_word(dev, 0x50, regw&0xfff7);
  638. pci_read_config_word(dev, 0x52, &regw);
  639. if (regw & 0x08)
  640. pci_write_config_word(dev, 0x52, regw&0xfff7);
  641. break;
  642. case ATA_133a:
  643. case ATA_100:
  644. /* Fixup latency */
  645. pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x80);
  646. /* Set compatibility bit */
  647. pci_read_config_byte(dev, 0x49, &reg);
  648. if (!(reg & 0x01)) {
  649. pci_write_config_byte(dev, 0x49, reg|0x01);
  650. }
  651. break;
  652. case ATA_100a:
  653. case ATA_66:
  654. /* Fixup latency */
  655. pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x10);
  656. /* On ATA_66 chips the bit was elsewhere */
  657. pci_read_config_byte(dev, 0x52, &reg);
  658. if (!(reg & 0x04)) {
  659. pci_write_config_byte(dev, 0x52, reg|0x04);
  660. }
  661. break;
  662. case ATA_33:
  663. /* On ATA_33 we didn't have a single bit to set */
  664. pci_read_config_byte(dev, 0x09, &reg);
  665. if ((reg & 0x0f) != 0x00) {
  666. pci_write_config_byte(dev, 0x09, reg&0xf0);
  667. }
  668. case ATA_16:
  669. /* force per drive recovery and active timings
  670. needed on ATA_33 and below chips */
  671. pci_read_config_byte(dev, 0x52, &reg);
  672. if (!(reg & 0x08)) {
  673. pci_write_config_byte(dev, 0x52, reg|0x08);
  674. }
  675. break;
  676. }
  677. #if defined(DISPLAY_SIS_TIMINGS) && defined(CONFIG_IDE_PROC_FS)
  678. if (!sis_proc) {
  679. sis_proc = 1;
  680. bmide_dev = dev;
  681. ide_pci_create_host_proc("sis", sis_get_info);
  682. }
  683. #endif
  684. }
  685. return 0;
  686. }
  687. struct sis_laptop {
  688. u16 device;
  689. u16 subvendor;
  690. u16 subdevice;
  691. };
  692. static const struct sis_laptop sis_laptop[] = {
  693. /* devid, subvendor, subdev */
  694. { 0x5513, 0x1043, 0x1107 }, /* ASUS A6K */
  695. { 0x5513, 0x1734, 0x105f }, /* FSC Amilo A1630 */
  696. /* end marker */
  697. { 0, }
  698. };
  699. static u8 __devinit ata66_sis5513(ide_hwif_t *hwif)
  700. {
  701. struct pci_dev *pdev = hwif->pci_dev;
  702. const struct sis_laptop *lap = &sis_laptop[0];
  703. u8 ata66 = 0;
  704. while (lap->device) {
  705. if (lap->device == pdev->device &&
  706. lap->subvendor == pdev->subsystem_vendor &&
  707. lap->subdevice == pdev->subsystem_device)
  708. return ATA_CBL_PATA40_SHORT;
  709. lap++;
  710. }
  711. if (chipset_family >= ATA_133) {
  712. u16 regw = 0;
  713. u16 reg_addr = hwif->channel ? 0x52: 0x50;
  714. pci_read_config_word(hwif->pci_dev, reg_addr, &regw);
  715. ata66 = (regw & 0x8000) ? 0 : 1;
  716. } else if (chipset_family >= ATA_66) {
  717. u8 reg48h = 0;
  718. u8 mask = hwif->channel ? 0x20 : 0x10;
  719. pci_read_config_byte(hwif->pci_dev, 0x48, &reg48h);
  720. ata66 = (reg48h & mask) ? 0 : 1;
  721. }
  722. return ata66 ? ATA_CBL_PATA80 : ATA_CBL_PATA40;
  723. }
  724. static void __devinit init_hwif_sis5513 (ide_hwif_t *hwif)
  725. {
  726. u8 udma_rates[] = { 0x00, 0x00, 0x07, 0x1f, 0x3f, 0x3f, 0x7f, 0x7f };
  727. hwif->autodma = 0;
  728. if (!hwif->irq)
  729. hwif->irq = hwif->channel ? 15 : 14;
  730. hwif->set_pio_mode = &sis_set_pio_mode;
  731. hwif->set_dma_mode = &sis_set_dma_mode;
  732. if (chipset_family >= ATA_133)
  733. hwif->udma_filter = sis5513_ata133_udma_filter;
  734. if (!(hwif->dma_base)) {
  735. hwif->drives[0].autotune = 1;
  736. hwif->drives[1].autotune = 1;
  737. return;
  738. }
  739. hwif->atapi_dma = 1;
  740. hwif->ultra_mask = udma_rates[chipset_family];
  741. hwif->mwdma_mask = 0x07;
  742. hwif->swdma_mask = 0x07;
  743. if (!chipset_family)
  744. return;
  745. if (hwif->cbl != ATA_CBL_PATA40_SHORT)
  746. hwif->cbl = ata66_sis5513(hwif);
  747. if (chipset_family > ATA_16) {
  748. hwif->ide_dma_check = &sis5513_config_xfer_rate;
  749. if (!noautodma)
  750. hwif->autodma = 1;
  751. }
  752. hwif->drives[0].autodma = hwif->autodma;
  753. hwif->drives[1].autodma = hwif->autodma;
  754. return;
  755. }
  756. static ide_pci_device_t sis5513_chipset __devinitdata = {
  757. .name = "SIS5513",
  758. .init_chipset = init_chipset_sis5513,
  759. .init_hwif = init_hwif_sis5513,
  760. .autodma = NOAUTODMA,
  761. .enablebits = {{0x4a,0x02,0x02}, {0x4a,0x04,0x04}},
  762. .bootable = ON_BOARD,
  763. .pio_mask = ATA_PIO4,
  764. };
  765. static int __devinit sis5513_init_one(struct pci_dev *dev, const struct pci_device_id *id)
  766. {
  767. return ide_setup_pci_device(dev, &sis5513_chipset);
  768. }
  769. static struct pci_device_id sis5513_pci_tbl[] = {
  770. { PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_5513, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  771. { PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_5518, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  772. { PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_1180, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  773. { 0, },
  774. };
  775. MODULE_DEVICE_TABLE(pci, sis5513_pci_tbl);
  776. static struct pci_driver driver = {
  777. .name = "SIS_IDE",
  778. .id_table = sis5513_pci_tbl,
  779. .probe = sis5513_init_one,
  780. };
  781. static int __init sis5513_ide_init(void)
  782. {
  783. return ide_pci_register_driver(&driver);
  784. }
  785. module_init(sis5513_ide_init);
  786. MODULE_AUTHOR("Lionel Bouton, L C Chang, Andre Hedrick, Vojtech Pavlik");
  787. MODULE_DESCRIPTION("PCI driver module for SIS IDE");
  788. MODULE_LICENSE("GPL");
  789. /*
  790. * TODO:
  791. * - CLEANUP
  792. * - Use drivers/ide/ide-timing.h !
  793. * - More checks in the config registers (force values instead of
  794. * relying on the BIOS setting them correctly).
  795. * - Further optimisations ?
  796. * . for example ATA66+ regs 0x48 & 0x4A
  797. */