pata_sis.c 26 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016
  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. 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_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_old_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. return ata_std_prereset(ap, deadline);
  131. }
  132. /**
  133. * sis_error_handler - Probe specified port on PATA host controller
  134. * @ap: Port to probe
  135. *
  136. * LOCKING:
  137. * None (inherited from caller).
  138. */
  139. static void sis_error_handler(struct ata_port *ap)
  140. {
  141. ata_bmdma_drive_eh(ap, sis_pre_reset, ata_std_softreset, NULL, ata_std_postreset);
  142. }
  143. /**
  144. * sis_set_fifo - Set RWP fifo bits for this device
  145. * @ap: Port
  146. * @adev: Device
  147. *
  148. * SIS chipsets implement prefetch/postwrite bits for each device
  149. * on both channels. This functionality is not ATAPI compatible and
  150. * must be configured according to the class of device present
  151. */
  152. static void sis_set_fifo(struct ata_port *ap, struct ata_device *adev)
  153. {
  154. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  155. u8 fifoctrl;
  156. u8 mask = 0x11;
  157. mask <<= (2 * ap->port_no);
  158. mask <<= adev->devno;
  159. /* This holds various bits including the FIFO control */
  160. pci_read_config_byte(pdev, 0x4B, &fifoctrl);
  161. fifoctrl &= ~mask;
  162. /* Enable for ATA (disk) only */
  163. if (adev->class == ATA_DEV_ATA)
  164. fifoctrl |= mask;
  165. pci_write_config_byte(pdev, 0x4B, fifoctrl);
  166. }
  167. /**
  168. * sis_old_set_piomode - Initialize host controller PATA PIO timings
  169. * @ap: Port whose timings we are configuring
  170. * @adev: Device we are configuring for.
  171. *
  172. * Set PIO mode for device, in host controller PCI config space. This
  173. * function handles PIO set up for all chips that are pre ATA100 and
  174. * also early ATA100 devices.
  175. *
  176. * LOCKING:
  177. * None (inherited from caller).
  178. */
  179. static void sis_old_set_piomode (struct ata_port *ap, struct ata_device *adev)
  180. {
  181. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  182. int port = sis_port_base(adev);
  183. u8 t1, t2;
  184. int speed = adev->pio_mode - XFER_PIO_0;
  185. const u8 active[] = { 0x00, 0x07, 0x04, 0x03, 0x01 };
  186. const u8 recovery[] = { 0x00, 0x06, 0x04, 0x03, 0x03 };
  187. sis_set_fifo(ap, adev);
  188. pci_read_config_byte(pdev, port, &t1);
  189. pci_read_config_byte(pdev, port + 1, &t2);
  190. t1 &= ~0x0F; /* Clear active/recovery timings */
  191. t2 &= ~0x07;
  192. t1 |= active[speed];
  193. t2 |= recovery[speed];
  194. pci_write_config_byte(pdev, port, t1);
  195. pci_write_config_byte(pdev, port + 1, t2);
  196. }
  197. /**
  198. * sis_100_set_pioode - Initialize host controller PATA PIO timings
  199. * @ap: Port whose timings we are configuring
  200. * @adev: Device we are configuring for.
  201. *
  202. * Set PIO mode for device, in host controller PCI config space. This
  203. * function handles PIO set up for ATA100 devices and early ATA133.
  204. *
  205. * LOCKING:
  206. * None (inherited from caller).
  207. */
  208. static void sis_100_set_piomode (struct ata_port *ap, struct ata_device *adev)
  209. {
  210. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  211. int port = sis_port_base(adev);
  212. int speed = adev->pio_mode - XFER_PIO_0;
  213. const u8 actrec[] = { 0x00, 0x67, 0x44, 0x33, 0x31 };
  214. sis_set_fifo(ap, adev);
  215. pci_write_config_byte(pdev, port, actrec[speed]);
  216. }
  217. /**
  218. * sis_133_set_pioode - Initialize host controller PATA PIO timings
  219. * @ap: Port whose timings we are configuring
  220. * @adev: Device we are configuring for.
  221. *
  222. * Set PIO mode for device, in host controller PCI config space. This
  223. * function handles PIO set up for the later ATA133 devices.
  224. *
  225. * LOCKING:
  226. * None (inherited from caller).
  227. */
  228. static void sis_133_set_piomode (struct ata_port *ap, struct ata_device *adev)
  229. {
  230. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  231. int port = 0x40;
  232. u32 t1;
  233. u32 reg54;
  234. int speed = adev->pio_mode - XFER_PIO_0;
  235. const u32 timing133[] = {
  236. 0x28269000, /* Recovery << 24 | Act << 16 | Ini << 12 */
  237. 0x0C266000,
  238. 0x04263000,
  239. 0x0C0A3000,
  240. 0x05093000
  241. };
  242. const u32 timing100[] = {
  243. 0x1E1C6000, /* Recovery << 24 | Act << 16 | Ini << 12 */
  244. 0x091C4000,
  245. 0x031C2000,
  246. 0x09072000,
  247. 0x04062000
  248. };
  249. sis_set_fifo(ap, adev);
  250. /* If bit 14 is set then the registers are mapped at 0x70 not 0x40 */
  251. pci_read_config_dword(pdev, 0x54, &reg54);
  252. if (reg54 & 0x40000000)
  253. port = 0x70;
  254. port += 8 * ap->port_no + 4 * adev->devno;
  255. pci_read_config_dword(pdev, port, &t1);
  256. t1 &= 0xC0C00FFF; /* Mask out timing */
  257. if (t1 & 0x08) /* 100 or 133 ? */
  258. t1 |= timing133[speed];
  259. else
  260. t1 |= timing100[speed];
  261. pci_write_config_byte(pdev, port, t1);
  262. }
  263. /**
  264. * sis_old_set_dmamode - Initialize host controller PATA DMA timings
  265. * @ap: Port whose timings we are configuring
  266. * @adev: Device to program
  267. *
  268. * Set UDMA/MWDMA mode for device, in host controller PCI config space.
  269. * Handles pre UDMA and UDMA33 devices. Supports MWDMA as well unlike
  270. * the old ide/pci driver.
  271. *
  272. * LOCKING:
  273. * None (inherited from caller).
  274. */
  275. static void sis_old_set_dmamode (struct ata_port *ap, struct ata_device *adev)
  276. {
  277. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  278. int speed = adev->dma_mode - XFER_MW_DMA_0;
  279. int drive_pci = sis_port_base(adev);
  280. u16 timing;
  281. const u16 mwdma_bits[] = { 0x707, 0x202, 0x202 };
  282. const u16 udma_bits[] = { 0xE000, 0xC000, 0xA000 };
  283. pci_read_config_word(pdev, drive_pci, &timing);
  284. if (adev->dma_mode < XFER_UDMA_0) {
  285. /* bits 3-0 hold recovery timing bits 8-10 active timing and
  286. the higer bits are dependant on the device */
  287. timing &= ~ 0x870F;
  288. timing |= mwdma_bits[speed];
  289. pci_write_config_word(pdev, drive_pci, timing);
  290. } else {
  291. /* Bit 15 is UDMA on/off, bit 13-14 are cycle time */
  292. speed = adev->dma_mode - XFER_UDMA_0;
  293. timing &= ~0x6000;
  294. timing |= udma_bits[speed];
  295. }
  296. }
  297. /**
  298. * sis_66_set_dmamode - Initialize host controller PATA DMA timings
  299. * @ap: Port whose timings we are configuring
  300. * @adev: Device to program
  301. *
  302. * Set UDMA/MWDMA mode for device, in host controller PCI config space.
  303. * Handles UDMA66 and early UDMA100 devices. Supports MWDMA as well unlike
  304. * the old ide/pci driver.
  305. *
  306. * LOCKING:
  307. * None (inherited from caller).
  308. */
  309. static void sis_66_set_dmamode (struct ata_port *ap, struct ata_device *adev)
  310. {
  311. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  312. int speed = adev->dma_mode - XFER_MW_DMA_0;
  313. int drive_pci = sis_port_base(adev);
  314. u16 timing;
  315. const u16 mwdma_bits[] = { 0x707, 0x202, 0x202 };
  316. const u16 udma_bits[] = { 0xF000, 0xD000, 0xB000, 0xA000, 0x9000};
  317. pci_read_config_word(pdev, drive_pci, &timing);
  318. if (adev->dma_mode < XFER_UDMA_0) {
  319. /* bits 3-0 hold recovery timing bits 8-10 active timing and
  320. the higer bits are dependant on the device, bit 15 udma */
  321. timing &= ~ 0x870F;
  322. timing |= mwdma_bits[speed];
  323. } else {
  324. /* Bit 15 is UDMA on/off, bit 12-14 are cycle time */
  325. speed = adev->dma_mode - XFER_UDMA_0;
  326. timing &= ~0x6000;
  327. timing |= udma_bits[speed];
  328. }
  329. pci_write_config_word(pdev, drive_pci, timing);
  330. }
  331. /**
  332. * sis_100_set_dmamode - Initialize host controller PATA DMA timings
  333. * @ap: Port whose timings we are configuring
  334. * @adev: Device to program
  335. *
  336. * Set UDMA/MWDMA mode for device, in host controller PCI config space.
  337. * Handles UDMA66 and early UDMA100 devices.
  338. *
  339. * LOCKING:
  340. * None (inherited from caller).
  341. */
  342. static void sis_100_set_dmamode (struct ata_port *ap, struct ata_device *adev)
  343. {
  344. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  345. int speed = adev->dma_mode - XFER_MW_DMA_0;
  346. int drive_pci = sis_port_base(adev);
  347. u16 timing;
  348. const u16 udma_bits[] = { 0x8B00, 0x8700, 0x8500, 0x8300, 0x8200, 0x8100};
  349. pci_read_config_word(pdev, drive_pci, &timing);
  350. if (adev->dma_mode < XFER_UDMA_0) {
  351. /* NOT SUPPORTED YET: NEED DATA SHEET. DITTO IN OLD DRIVER */
  352. } else {
  353. /* Bit 15 is UDMA on/off, bit 12-14 are cycle time */
  354. speed = adev->dma_mode - XFER_UDMA_0;
  355. timing &= ~0x0F00;
  356. timing |= udma_bits[speed];
  357. }
  358. pci_write_config_word(pdev, drive_pci, timing);
  359. }
  360. /**
  361. * sis_133_early_set_dmamode - Initialize host controller PATA DMA timings
  362. * @ap: Port whose timings we are configuring
  363. * @adev: Device to program
  364. *
  365. * Set UDMA/MWDMA mode for device, in host controller PCI config space.
  366. * Handles early SiS 961 bridges. Supports MWDMA as well unlike
  367. * the old ide/pci driver.
  368. *
  369. * LOCKING:
  370. * None (inherited from caller).
  371. */
  372. static void sis_133_early_set_dmamode (struct ata_port *ap, struct ata_device *adev)
  373. {
  374. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  375. int speed = adev->dma_mode - XFER_MW_DMA_0;
  376. int drive_pci = sis_port_base(adev);
  377. u16 timing;
  378. static const u16 udma_bits[] = { 0x8F00, 0x8A00, 0x8700, 0x8500, 0x8300, 0x8200, 0x8100};
  379. pci_read_config_word(pdev, drive_pci, &timing);
  380. if (adev->dma_mode < XFER_UDMA_0) {
  381. /* NOT SUPPORTED YET: NEED DATA SHEET. DITTO IN OLD DRIVER */
  382. } else {
  383. /* Bit 15 is UDMA on/off, bit 12-14 are cycle time */
  384. speed = adev->dma_mode - XFER_UDMA_0;
  385. timing &= ~0x0F00;
  386. timing |= udma_bits[speed];
  387. }
  388. pci_write_config_word(pdev, drive_pci, timing);
  389. }
  390. /**
  391. * sis_133_set_dmamode - Initialize host controller PATA DMA timings
  392. * @ap: Port whose timings we are configuring
  393. * @adev: Device to program
  394. *
  395. * Set UDMA/MWDMA mode for device, in host controller PCI config space.
  396. * Handles early SiS 961 bridges. Supports MWDMA as well unlike
  397. * the old ide/pci driver.
  398. *
  399. * LOCKING:
  400. * None (inherited from caller).
  401. */
  402. static void sis_133_set_dmamode (struct ata_port *ap, struct ata_device *adev)
  403. {
  404. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  405. int speed = adev->dma_mode - XFER_MW_DMA_0;
  406. int port = 0x40;
  407. u32 t1;
  408. u32 reg54;
  409. /* bits 4- cycle time 8 - cvs time */
  410. static const u32 timing_u100[] = { 0x6B0, 0x470, 0x350, 0x140, 0x120, 0x110, 0x000 };
  411. static const u32 timing_u133[] = { 0x9F0, 0x6A0, 0x470, 0x250, 0x230, 0x220, 0x210 };
  412. /* If bit 14 is set then the registers are mapped at 0x70 not 0x40 */
  413. pci_read_config_dword(pdev, 0x54, &reg54);
  414. if (reg54 & 0x40000000)
  415. port = 0x70;
  416. port += (8 * ap->port_no) + (4 * adev->devno);
  417. pci_read_config_dword(pdev, port, &t1);
  418. if (adev->dma_mode < XFER_UDMA_0) {
  419. t1 &= ~0x00000004;
  420. /* FIXME: need data sheet to add MWDMA here. Also lacking on
  421. ide/pci driver */
  422. } else {
  423. speed = adev->dma_mode - XFER_UDMA_0;
  424. /* if & 8 no UDMA133 - need info for ... */
  425. t1 &= ~0x00000FF0;
  426. t1 |= 0x00000004;
  427. if (t1 & 0x08)
  428. t1 |= timing_u133[speed];
  429. else
  430. t1 |= timing_u100[speed];
  431. }
  432. pci_write_config_dword(pdev, port, t1);
  433. }
  434. static struct scsi_host_template sis_sht = {
  435. .module = THIS_MODULE,
  436. .name = DRV_NAME,
  437. .ioctl = ata_scsi_ioctl,
  438. .queuecommand = ata_scsi_queuecmd,
  439. .can_queue = ATA_DEF_QUEUE,
  440. .this_id = ATA_SHT_THIS_ID,
  441. .sg_tablesize = LIBATA_MAX_PRD,
  442. .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
  443. .emulated = ATA_SHT_EMULATED,
  444. .use_clustering = ATA_SHT_USE_CLUSTERING,
  445. .proc_name = DRV_NAME,
  446. .dma_boundary = ATA_DMA_BOUNDARY,
  447. .slave_configure = ata_scsi_slave_config,
  448. .slave_destroy = ata_scsi_slave_destroy,
  449. .bios_param = ata_std_bios_param,
  450. #ifdef CONFIG_PM
  451. .resume = ata_scsi_device_resume,
  452. .suspend = ata_scsi_device_suspend,
  453. #endif
  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_early_ops = {
  484. .port_disable = ata_port_disable,
  485. .set_piomode = sis_100_set_piomode,
  486. .set_dmamode = sis_133_early_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 = sis_error_handler,
  496. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  497. .cable_detect = sis_66_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_100_ops = {
  512. .port_disable = ata_port_disable,
  513. .set_piomode = sis_100_set_piomode,
  514. .set_dmamode = sis_100_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_66_ops = {
  540. .port_disable = ata_port_disable,
  541. .set_piomode = sis_old_set_piomode,
  542. .set_dmamode = sis_66_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. .cable_detect = sis_66_cable_detect,
  550. .freeze = ata_bmdma_freeze,
  551. .thaw = ata_bmdma_thaw,
  552. .error_handler = sis_error_handler,
  553. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  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_old_ops = {
  568. .port_disable = ata_port_disable,
  569. .set_piomode = sis_old_set_piomode,
  570. .set_dmamode = sis_old_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. .freeze = ata_bmdma_freeze,
  578. .thaw = ata_bmdma_thaw,
  579. .error_handler = sis_error_handler,
  580. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  581. .cable_detect = ata_cable_40wire,
  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 struct ata_port_info sis_info = {
  596. .sht = &sis_sht,
  597. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  598. .pio_mask = 0x1f, /* pio0-4 */
  599. .mwdma_mask = 0x07,
  600. .udma_mask = 0,
  601. .port_ops = &sis_old_ops,
  602. };
  603. static struct ata_port_info sis_info33 = {
  604. .sht = &sis_sht,
  605. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  606. .pio_mask = 0x1f, /* pio0-4 */
  607. .mwdma_mask = 0x07,
  608. .udma_mask = ATA_UDMA2, /* UDMA 33 */
  609. .port_ops = &sis_old_ops,
  610. };
  611. static struct ata_port_info sis_info66 = {
  612. .sht = &sis_sht,
  613. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  614. .pio_mask = 0x1f, /* pio0-4 */
  615. .udma_mask = ATA_UDMA4, /* UDMA 66 */
  616. .port_ops = &sis_66_ops,
  617. };
  618. static struct ata_port_info sis_info100 = {
  619. .sht = &sis_sht,
  620. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  621. .pio_mask = 0x1f, /* pio0-4 */
  622. .udma_mask = ATA_UDMA5,
  623. .port_ops = &sis_100_ops,
  624. };
  625. static struct ata_port_info sis_info100_early = {
  626. .sht = &sis_sht,
  627. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  628. .udma_mask = ATA_UDMA5,
  629. .pio_mask = 0x1f, /* pio0-4 */
  630. .port_ops = &sis_66_ops,
  631. };
  632. struct ata_port_info sis_info133 = {
  633. .sht = &sis_sht,
  634. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  635. .pio_mask = 0x1f, /* pio0-4 */
  636. .udma_mask = ATA_UDMA6,
  637. .port_ops = &sis_133_ops,
  638. };
  639. static struct ata_port_info sis_info133_early = {
  640. .sht = &sis_sht,
  641. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  642. .pio_mask = 0x1f, /* pio0-4 */
  643. .udma_mask = ATA_UDMA6,
  644. .port_ops = &sis_133_early_ops,
  645. };
  646. /* Privately shared with the SiS180 SATA driver, not for use elsewhere */
  647. EXPORT_SYMBOL_GPL(sis_info133);
  648. static void sis_fixup(struct pci_dev *pdev, struct sis_chipset *sis)
  649. {
  650. u16 regw;
  651. u8 reg;
  652. if (sis->info == &sis_info133) {
  653. pci_read_config_word(pdev, 0x50, &regw);
  654. if (regw & 0x08)
  655. pci_write_config_word(pdev, 0x50, regw & ~0x08);
  656. pci_read_config_word(pdev, 0x52, &regw);
  657. if (regw & 0x08)
  658. pci_write_config_word(pdev, 0x52, regw & ~0x08);
  659. return;
  660. }
  661. if (sis->info == &sis_info133_early || sis->info == &sis_info100) {
  662. /* Fix up latency */
  663. pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x80);
  664. /* Set compatibility bit */
  665. pci_read_config_byte(pdev, 0x49, &reg);
  666. if (!(reg & 0x01))
  667. pci_write_config_byte(pdev, 0x49, reg | 0x01);
  668. return;
  669. }
  670. if (sis->info == &sis_info66 || sis->info == &sis_info100_early) {
  671. /* Fix up latency */
  672. pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x80);
  673. /* Set compatibility bit */
  674. pci_read_config_byte(pdev, 0x52, &reg);
  675. if (!(reg & 0x04))
  676. pci_write_config_byte(pdev, 0x52, reg | 0x04);
  677. return;
  678. }
  679. if (sis->info == &sis_info33) {
  680. pci_read_config_byte(pdev, PCI_CLASS_PROG, &reg);
  681. if (( reg & 0x0F ) != 0x00)
  682. pci_write_config_byte(pdev, PCI_CLASS_PROG, reg & 0xF0);
  683. /* Fall through to ATA16 fixup below */
  684. }
  685. if (sis->info == &sis_info || sis->info == &sis_info33) {
  686. /* force per drive recovery and active timings
  687. needed on ATA_33 and below chips */
  688. pci_read_config_byte(pdev, 0x52, &reg);
  689. if (!(reg & 0x08))
  690. pci_write_config_byte(pdev, 0x52, reg|0x08);
  691. return;
  692. }
  693. BUG();
  694. }
  695. /**
  696. * sis_init_one - Register SiS ATA PCI device with kernel services
  697. * @pdev: PCI device to register
  698. * @ent: Entry in sis_pci_tbl matching with @pdev
  699. *
  700. * Called from kernel PCI layer. We probe for combined mode (sigh),
  701. * and then hand over control to libata, for it to do the rest.
  702. *
  703. * LOCKING:
  704. * Inherited from PCI layer (may sleep).
  705. *
  706. * RETURNS:
  707. * Zero on success, or -ERRNO value.
  708. */
  709. static int sis_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
  710. {
  711. static int printed_version;
  712. static struct ata_port_info *port_info[2];
  713. struct ata_port_info *port;
  714. struct pci_dev *host = NULL;
  715. struct sis_chipset *chipset = NULL;
  716. struct sis_chipset *sets;
  717. static struct sis_chipset sis_chipsets[] = {
  718. { 0x0968, &sis_info133 },
  719. { 0x0966, &sis_info133 },
  720. { 0x0965, &sis_info133 },
  721. { 0x0745, &sis_info100 },
  722. { 0x0735, &sis_info100 },
  723. { 0x0733, &sis_info100 },
  724. { 0x0635, &sis_info100 },
  725. { 0x0633, &sis_info100 },
  726. { 0x0730, &sis_info100_early }, /* 100 with ATA 66 layout */
  727. { 0x0550, &sis_info100_early }, /* 100 with ATA 66 layout */
  728. { 0x0640, &sis_info66 },
  729. { 0x0630, &sis_info66 },
  730. { 0x0620, &sis_info66 },
  731. { 0x0540, &sis_info66 },
  732. { 0x0530, &sis_info66 },
  733. { 0x5600, &sis_info33 },
  734. { 0x5598, &sis_info33 },
  735. { 0x5597, &sis_info33 },
  736. { 0x5591, &sis_info33 },
  737. { 0x5582, &sis_info33 },
  738. { 0x5581, &sis_info33 },
  739. { 0x5596, &sis_info },
  740. { 0x5571, &sis_info },
  741. { 0x5517, &sis_info },
  742. { 0x5511, &sis_info },
  743. {0}
  744. };
  745. static struct sis_chipset sis133_early = {
  746. 0x0, &sis_info133_early
  747. };
  748. static struct sis_chipset sis133 = {
  749. 0x0, &sis_info133
  750. };
  751. static struct sis_chipset sis100_early = {
  752. 0x0, &sis_info100_early
  753. };
  754. static struct sis_chipset sis100 = {
  755. 0x0, &sis_info100
  756. };
  757. if (!printed_version++)
  758. dev_printk(KERN_DEBUG, &pdev->dev,
  759. "version " DRV_VERSION "\n");
  760. /* We have to find the bridge first */
  761. for (sets = &sis_chipsets[0]; sets->device; sets++) {
  762. host = pci_get_device(PCI_VENDOR_ID_SI, sets->device, NULL);
  763. if (host != NULL) {
  764. chipset = sets; /* Match found */
  765. if (sets->device == 0x630) { /* SIS630 */
  766. u8 host_rev;
  767. pci_read_config_byte(host, PCI_REVISION_ID, &host_rev);
  768. if (host_rev >= 0x30) /* 630 ET */
  769. chipset = &sis100_early;
  770. }
  771. break;
  772. }
  773. }
  774. /* Look for concealed bridges */
  775. if (chipset == NULL) {
  776. /* Second check */
  777. u32 idemisc;
  778. u16 trueid;
  779. /* Disable ID masking and register remapping then
  780. see what the real ID is */
  781. pci_read_config_dword(pdev, 0x54, &idemisc);
  782. pci_write_config_dword(pdev, 0x54, idemisc & 0x7fffffff);
  783. pci_read_config_word(pdev, PCI_DEVICE_ID, &trueid);
  784. pci_write_config_dword(pdev, 0x54, idemisc);
  785. switch(trueid) {
  786. case 0x5518: /* SIS 962/963 */
  787. chipset = &sis133;
  788. if ((idemisc & 0x40000000) == 0) {
  789. pci_write_config_dword(pdev, 0x54, idemisc | 0x40000000);
  790. printk(KERN_INFO "SIS5513: Switching to 5513 register mapping\n");
  791. }
  792. break;
  793. case 0x0180: /* SIS 965/965L */
  794. chipset = &sis133;
  795. break;
  796. case 0x1180: /* SIS 966/966L */
  797. chipset = &sis133;
  798. break;
  799. }
  800. }
  801. /* Further check */
  802. if (chipset == NULL) {
  803. struct pci_dev *lpc_bridge;
  804. u16 trueid;
  805. u8 prefctl;
  806. u8 idecfg;
  807. u8 sbrev;
  808. /* Try the second unmasking technique */
  809. pci_read_config_byte(pdev, 0x4a, &idecfg);
  810. pci_write_config_byte(pdev, 0x4a, idecfg | 0x10);
  811. pci_read_config_word(pdev, PCI_DEVICE_ID, &trueid);
  812. pci_write_config_byte(pdev, 0x4a, idecfg);
  813. switch(trueid) {
  814. case 0x5517:
  815. lpc_bridge = pci_get_slot(pdev->bus, 0x10); /* Bus 0 Dev 2 Fn 0 */
  816. if (lpc_bridge == NULL)
  817. break;
  818. pci_read_config_byte(lpc_bridge, PCI_REVISION_ID, &sbrev);
  819. pci_read_config_byte(pdev, 0x49, &prefctl);
  820. pci_dev_put(lpc_bridge);
  821. if (sbrev == 0x10 && (prefctl & 0x80)) {
  822. chipset = &sis133_early;
  823. break;
  824. }
  825. chipset = &sis100;
  826. break;
  827. }
  828. }
  829. pci_dev_put(host);
  830. /* No chipset info, no support */
  831. if (chipset == NULL)
  832. return -ENODEV;
  833. port = chipset->info;
  834. port->private_data = chipset;
  835. sis_fixup(pdev, chipset);
  836. port_info[0] = port_info[1] = port;
  837. return ata_pci_init_one(pdev, port_info, 2);
  838. }
  839. static const struct pci_device_id sis_pci_tbl[] = {
  840. { PCI_VDEVICE(SI, 0x5513), }, /* SiS 5513 */
  841. { PCI_VDEVICE(SI, 0x5518), }, /* SiS 5518 */
  842. { }
  843. };
  844. static struct pci_driver sis_pci_driver = {
  845. .name = DRV_NAME,
  846. .id_table = sis_pci_tbl,
  847. .probe = sis_init_one,
  848. .remove = ata_pci_remove_one,
  849. #ifdef CONFIG_PM
  850. .suspend = ata_pci_device_suspend,
  851. .resume = ata_pci_device_resume,
  852. #endif
  853. };
  854. static int __init sis_init(void)
  855. {
  856. return pci_register_driver(&sis_pci_driver);
  857. }
  858. static void __exit sis_exit(void)
  859. {
  860. pci_unregister_driver(&sis_pci_driver);
  861. }
  862. module_init(sis_init);
  863. module_exit(sis_exit);
  864. MODULE_AUTHOR("Alan Cox");
  865. MODULE_DESCRIPTION("SCSI low-level driver for SiS ATA");
  866. MODULE_LICENSE("GPL");
  867. MODULE_DEVICE_TABLE(pci, sis_pci_tbl);
  868. MODULE_VERSION(DRV_VERSION);