pata_sis.c 27 KB

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