pata_sis.c 27 KB

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