pata_sis.c 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052
  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. #include "sis.h"
  35. #define DRV_NAME "pata_sis"
  36. #define DRV_VERSION "0.5.1"
  37. struct sis_chipset {
  38. u16 device; /* PCI host ID */
  39. const struct ata_port_info *info; /* Info block */
  40. /* Probably add family, cable detect type etc here to clean
  41. up code later */
  42. };
  43. struct sis_laptop {
  44. u16 device;
  45. u16 subvendor;
  46. u16 subdevice;
  47. };
  48. static const struct sis_laptop sis_laptop[] = {
  49. /* devid, subvendor, subdev */
  50. { 0x5513, 0x1043, 0x1107 }, /* ASUS A6K */
  51. /* end marker */
  52. { 0, }
  53. };
  54. static int sis_short_ata40(struct pci_dev *dev)
  55. {
  56. const struct sis_laptop *lap = &sis_laptop[0];
  57. while (lap->device) {
  58. if (lap->device == dev->device &&
  59. lap->subvendor == dev->subsystem_vendor &&
  60. lap->subdevice == dev->subsystem_device)
  61. return 1;
  62. lap++;
  63. }
  64. return 0;
  65. }
  66. /**
  67. * sis_old_port_base - return PCI configuration base for dev
  68. * @adev: device
  69. *
  70. * Returns the base of the PCI configuration registers for this port
  71. * number.
  72. */
  73. static int sis_old_port_base(struct ata_device *adev)
  74. {
  75. return 0x40 + (4 * adev->ap->port_no) + (2 * adev->devno);
  76. }
  77. /**
  78. * sis_133_cable_detect - check for 40/80 pin
  79. * @ap: Port
  80. * @deadline: deadline jiffies for the operation
  81. *
  82. * Perform cable detection for the later UDMA133 capable
  83. * SiS chipset.
  84. */
  85. static int sis_133_cable_detect(struct ata_port *ap)
  86. {
  87. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  88. u16 tmp;
  89. /* The top bit of this register is the cable detect bit */
  90. pci_read_config_word(pdev, 0x50 + 2 * ap->port_no, &tmp);
  91. if ((tmp & 0x8000) && !sis_short_ata40(pdev))
  92. return ATA_CBL_PATA40;
  93. return ATA_CBL_PATA80;
  94. }
  95. /**
  96. * sis_66_cable_detect - check for 40/80 pin
  97. * @ap: Port
  98. * @deadline: deadline jiffies for the operation
  99. *
  100. * Perform cable detection on the UDMA66, UDMA100 and early UDMA133
  101. * SiS IDE controllers.
  102. */
  103. static int sis_66_cable_detect(struct ata_port *ap)
  104. {
  105. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  106. u8 tmp;
  107. /* Older chips keep cable detect in bits 4/5 of reg 0x48 */
  108. pci_read_config_byte(pdev, 0x48, &tmp);
  109. tmp >>= ap->port_no;
  110. if ((tmp & 0x10) && !sis_short_ata40(pdev))
  111. return ATA_CBL_PATA40;
  112. return ATA_CBL_PATA80;
  113. }
  114. /**
  115. * sis_pre_reset - probe begin
  116. * @ap: ATA port
  117. * @deadline: deadline jiffies for the operation
  118. *
  119. * Set up cable type and use generic probe init
  120. */
  121. static int sis_pre_reset(struct ata_port *ap, unsigned long deadline)
  122. {
  123. static const struct pci_bits sis_enable_bits[] = {
  124. { 0x4aU, 1U, 0x02UL, 0x02UL }, /* port 0 */
  125. { 0x4aU, 1U, 0x04UL, 0x04UL }, /* port 1 */
  126. };
  127. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  128. if (!pci_test_config_bits(pdev, &sis_enable_bits[ap->port_no]))
  129. return -ENOENT;
  130. /* Clear the FIFO settings. We can't enable the FIFO until
  131. we know we are poking at a disk */
  132. pci_write_config_byte(pdev, 0x4B, 0);
  133. return ata_std_prereset(ap, deadline);
  134. }
  135. /**
  136. * sis_error_handler - Probe specified port on PATA host controller
  137. * @ap: Port to probe
  138. *
  139. * LOCKING:
  140. * None (inherited from caller).
  141. */
  142. static void sis_error_handler(struct ata_port *ap)
  143. {
  144. ata_bmdma_drive_eh(ap, sis_pre_reset, ata_std_softreset, NULL, ata_std_postreset);
  145. }
  146. /**
  147. * sis_set_fifo - Set RWP fifo bits for this device
  148. * @ap: Port
  149. * @adev: Device
  150. *
  151. * SIS chipsets implement prefetch/postwrite bits for each device
  152. * on both channels. This functionality is not ATAPI compatible and
  153. * must be configured according to the class of device present
  154. */
  155. static void sis_set_fifo(struct ata_port *ap, struct ata_device *adev)
  156. {
  157. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  158. u8 fifoctrl;
  159. u8 mask = 0x11;
  160. mask <<= (2 * ap->port_no);
  161. mask <<= adev->devno;
  162. /* This holds various bits including the FIFO control */
  163. pci_read_config_byte(pdev, 0x4B, &fifoctrl);
  164. fifoctrl &= ~mask;
  165. /* Enable for ATA (disk) only */
  166. if (adev->class == ATA_DEV_ATA)
  167. fifoctrl |= mask;
  168. pci_write_config_byte(pdev, 0x4B, fifoctrl);
  169. }
  170. /**
  171. * sis_old_set_piomode - Initialize host controller PATA PIO timings
  172. * @ap: Port whose timings we are configuring
  173. * @adev: Device we are configuring for.
  174. *
  175. * Set PIO mode for device, in host controller PCI config space. This
  176. * function handles PIO set up for all chips that are pre ATA100 and
  177. * also early ATA100 devices.
  178. *
  179. * LOCKING:
  180. * None (inherited from caller).
  181. */
  182. static void sis_old_set_piomode (struct ata_port *ap, struct ata_device *adev)
  183. {
  184. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  185. int port = sis_old_port_base(adev);
  186. u8 t1, t2;
  187. int speed = adev->pio_mode - XFER_PIO_0;
  188. const u8 active[] = { 0x00, 0x07, 0x04, 0x03, 0x01 };
  189. const u8 recovery[] = { 0x00, 0x06, 0x04, 0x03, 0x03 };
  190. sis_set_fifo(ap, adev);
  191. pci_read_config_byte(pdev, port, &t1);
  192. pci_read_config_byte(pdev, port + 1, &t2);
  193. t1 &= ~0x0F; /* Clear active/recovery timings */
  194. t2 &= ~0x07;
  195. t1 |= active[speed];
  196. t2 |= recovery[speed];
  197. pci_write_config_byte(pdev, port, t1);
  198. pci_write_config_byte(pdev, port + 1, t2);
  199. }
  200. /**
  201. * sis_100_set_pioode - Initialize host controller PATA PIO timings
  202. * @ap: Port whose timings we are configuring
  203. * @adev: Device we are configuring for.
  204. *
  205. * Set PIO mode for device, in host controller PCI config space. This
  206. * function handles PIO set up for ATA100 devices and early ATA133.
  207. *
  208. * LOCKING:
  209. * None (inherited from caller).
  210. */
  211. static void sis_100_set_piomode (struct ata_port *ap, struct ata_device *adev)
  212. {
  213. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  214. int port = sis_old_port_base(adev);
  215. int speed = adev->pio_mode - XFER_PIO_0;
  216. const u8 actrec[] = { 0x00, 0x67, 0x44, 0x33, 0x31 };
  217. sis_set_fifo(ap, adev);
  218. pci_write_config_byte(pdev, port, actrec[speed]);
  219. }
  220. /**
  221. * sis_133_set_pioode - Initialize host controller PATA PIO timings
  222. * @ap: Port whose timings we are configuring
  223. * @adev: Device we are configuring for.
  224. *
  225. * Set PIO mode for device, in host controller PCI config space. This
  226. * function handles PIO set up for the later ATA133 devices.
  227. *
  228. * LOCKING:
  229. * None (inherited from caller).
  230. */
  231. static void sis_133_set_piomode (struct ata_port *ap, struct ata_device *adev)
  232. {
  233. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  234. int port = 0x40;
  235. u32 t1;
  236. u32 reg54;
  237. int speed = adev->pio_mode - XFER_PIO_0;
  238. const u32 timing133[] = {
  239. 0x28269000, /* Recovery << 24 | Act << 16 | Ini << 12 */
  240. 0x0C266000,
  241. 0x04263000,
  242. 0x0C0A3000,
  243. 0x05093000
  244. };
  245. const u32 timing100[] = {
  246. 0x1E1C6000, /* Recovery << 24 | Act << 16 | Ini << 12 */
  247. 0x091C4000,
  248. 0x031C2000,
  249. 0x09072000,
  250. 0x04062000
  251. };
  252. sis_set_fifo(ap, adev);
  253. /* If bit 14 is set then the registers are mapped at 0x70 not 0x40 */
  254. pci_read_config_dword(pdev, 0x54, &reg54);
  255. if (reg54 & 0x40000000)
  256. port = 0x70;
  257. port += 8 * ap->port_no + 4 * adev->devno;
  258. pci_read_config_dword(pdev, port, &t1);
  259. t1 &= 0xC0C00FFF; /* Mask out timing */
  260. if (t1 & 0x08) /* 100 or 133 ? */
  261. t1 |= timing133[speed];
  262. else
  263. t1 |= timing100[speed];
  264. pci_write_config_byte(pdev, port, t1);
  265. }
  266. /**
  267. * sis_old_set_dmamode - Initialize host controller PATA DMA timings
  268. * @ap: Port whose timings we are configuring
  269. * @adev: Device to program
  270. *
  271. * Set UDMA/MWDMA mode for device, in host controller PCI config space.
  272. * Handles pre UDMA and UDMA33 devices. Supports MWDMA as well unlike
  273. * the old ide/pci driver.
  274. *
  275. * LOCKING:
  276. * None (inherited from caller).
  277. */
  278. static void sis_old_set_dmamode (struct ata_port *ap, struct ata_device *adev)
  279. {
  280. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  281. int speed = adev->dma_mode - XFER_MW_DMA_0;
  282. int drive_pci = sis_old_port_base(adev);
  283. u16 timing;
  284. const u16 mwdma_bits[] = { 0x707, 0x202, 0x202 };
  285. const u16 udma_bits[] = { 0xE000, 0xC000, 0xA000 };
  286. pci_read_config_word(pdev, drive_pci, &timing);
  287. if (adev->dma_mode < XFER_UDMA_0) {
  288. /* bits 3-0 hold recovery timing bits 8-10 active timing and
  289. the higer bits are dependant on the device */
  290. timing &= ~ 0x870F;
  291. timing |= mwdma_bits[speed];
  292. pci_write_config_word(pdev, drive_pci, timing);
  293. } else {
  294. /* Bit 15 is UDMA on/off, bit 13-14 are cycle time */
  295. speed = adev->dma_mode - XFER_UDMA_0;
  296. timing &= ~0x6000;
  297. timing |= udma_bits[speed];
  298. }
  299. }
  300. /**
  301. * sis_66_set_dmamode - Initialize host controller PATA DMA timings
  302. * @ap: Port whose timings we are configuring
  303. * @adev: Device to program
  304. *
  305. * Set UDMA/MWDMA mode for device, in host controller PCI config space.
  306. * Handles UDMA66 and early UDMA100 devices. Supports MWDMA as well unlike
  307. * the old ide/pci driver.
  308. *
  309. * LOCKING:
  310. * None (inherited from caller).
  311. */
  312. static void sis_66_set_dmamode (struct ata_port *ap, struct ata_device *adev)
  313. {
  314. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  315. int speed = adev->dma_mode - XFER_MW_DMA_0;
  316. int drive_pci = sis_old_port_base(adev);
  317. u16 timing;
  318. const u16 mwdma_bits[] = { 0x707, 0x202, 0x202 };
  319. const u16 udma_bits[] = { 0xF000, 0xD000, 0xB000, 0xA000, 0x9000};
  320. pci_read_config_word(pdev, drive_pci, &timing);
  321. if (adev->dma_mode < XFER_UDMA_0) {
  322. /* bits 3-0 hold recovery timing bits 8-10 active timing and
  323. the higer bits are dependant on the device, bit 15 udma */
  324. timing &= ~0x870F;
  325. timing |= mwdma_bits[speed];
  326. } else {
  327. /* Bit 15 is UDMA on/off, bit 12-14 are cycle time */
  328. speed = adev->dma_mode - XFER_UDMA_0;
  329. timing &= ~0xF000;
  330. timing |= udma_bits[speed];
  331. }
  332. pci_write_config_word(pdev, drive_pci, timing);
  333. }
  334. /**
  335. * sis_100_set_dmamode - Initialize host controller PATA DMA timings
  336. * @ap: Port whose timings we are configuring
  337. * @adev: Device to program
  338. *
  339. * Set UDMA/MWDMA mode for device, in host controller PCI config space.
  340. * Handles UDMA66 and early UDMA100 devices.
  341. *
  342. * LOCKING:
  343. * None (inherited from caller).
  344. */
  345. static void sis_100_set_dmamode (struct ata_port *ap, struct ata_device *adev)
  346. {
  347. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  348. int speed = adev->dma_mode - XFER_MW_DMA_0;
  349. int drive_pci = sis_old_port_base(adev);
  350. u8 timing;
  351. const u8 udma_bits[] = { 0x8B, 0x87, 0x85, 0x83, 0x82, 0x81};
  352. pci_read_config_byte(pdev, drive_pci + 1, &timing);
  353. if (adev->dma_mode < XFER_UDMA_0) {
  354. /* NOT SUPPORTED YET: NEED DATA SHEET. DITTO IN OLD DRIVER */
  355. } else {
  356. /* Bit 7 is UDMA on/off, bit 0-3 are cycle time */
  357. speed = adev->dma_mode - XFER_UDMA_0;
  358. timing &= ~0x8F;
  359. timing |= udma_bits[speed];
  360. }
  361. pci_write_config_byte(pdev, drive_pci + 1, timing);
  362. }
  363. /**
  364. * sis_133_early_set_dmamode - Initialize host controller PATA DMA timings
  365. * @ap: Port whose timings we are configuring
  366. * @adev: Device to program
  367. *
  368. * Set UDMA/MWDMA mode for device, in host controller PCI config space.
  369. * Handles early SiS 961 bridges. Supports MWDMA as well unlike
  370. * the old ide/pci driver.
  371. *
  372. * LOCKING:
  373. * None (inherited from caller).
  374. */
  375. static void sis_133_early_set_dmamode (struct ata_port *ap, struct ata_device *adev)
  376. {
  377. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  378. int speed = adev->dma_mode - XFER_MW_DMA_0;
  379. int drive_pci = sis_old_port_base(adev);
  380. u8 timing;
  381. /* Low 4 bits are timing */
  382. static const u8 udma_bits[] = { 0x8F, 0x8A, 0x87, 0x85, 0x83, 0x82, 0x81};
  383. pci_read_config_byte(pdev, drive_pci + 1, &timing);
  384. if (adev->dma_mode < XFER_UDMA_0) {
  385. /* NOT SUPPORTED YET: NEED DATA SHEET. DITTO IN OLD DRIVER */
  386. } else {
  387. /* Bit 7 is UDMA on/off, bit 0-3 are cycle time */
  388. speed = adev->dma_mode - XFER_UDMA_0;
  389. timing &= ~0x8F;
  390. timing |= udma_bits[speed];
  391. }
  392. pci_write_config_byte(pdev, drive_pci + 1, timing);
  393. }
  394. /**
  395. * sis_133_set_dmamode - Initialize host controller PATA DMA timings
  396. * @ap: Port whose timings we are configuring
  397. * @adev: Device to program
  398. *
  399. * Set UDMA/MWDMA mode for device, in host controller PCI config space.
  400. * Handles early SiS 961 bridges. Supports MWDMA as well unlike
  401. * the old ide/pci driver.
  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);