pata_sis.c 27 KB

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