pata_sis.c 27 KB

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