pata_sis.c 27 KB

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