pata_sis.c 28 KB

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