pata_sis.c 27 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049
  1. /*
  2. * pata_sis.c - SiS ATA driver
  3. *
  4. * (C) 2005 Red Hat <alan@redhat.com>
  5. *
  6. * Based upon linux/drivers/ide/pci/sis5513.c
  7. * Copyright (C) 1999-2000 Andre Hedrick <andre@linux-ide.org>
  8. * Copyright (C) 2002 Lionel Bouton <Lionel.Bouton@inet6.fr>, Maintainer
  9. * Copyright (C) 2003 Vojtech Pavlik <vojtech@suse.cz>
  10. * SiS Taiwan : for direct support and hardware.
  11. * Daniela Engert : for initial ATA100 advices and numerous others.
  12. * John Fremlin, Manfred Spraul, Dave Morgan, Peter Kjellerstedt :
  13. * for checking code correctness, providing patches.
  14. * Original tests and design on the SiS620 chipset.
  15. * ATA100 tests and design on the SiS735 chipset.
  16. * ATA16/33 support from specs
  17. * ATA133 support for SiS961/962 by L.C. Chang <lcchang@sis.com.tw>
  18. *
  19. *
  20. * TODO
  21. * Check MWDMA on drives that don't support MWDMA speed pio cycles ?
  22. * More Testing
  23. */
  24. #include <linux/kernel.h>
  25. #include <linux/module.h>
  26. #include <linux/pci.h>
  27. #include <linux/init.h>
  28. #include <linux/blkdev.h>
  29. #include <linux/delay.h>
  30. #include <linux/device.h>
  31. #include <scsi/scsi_host.h>
  32. #include <linux/libata.h>
  33. #include <linux/ata.h>
  34. #include "sis.h"
  35. #define DRV_NAME "pata_sis"
  36. #define DRV_VERSION "0.5.1"
  37. struct sis_chipset {
  38. u16 device; /* PCI host ID */
  39. const struct ata_port_info *info; /* Info block */
  40. /* Probably add family, cable detect type etc here to clean
  41. up code later */
  42. };
  43. struct sis_laptop {
  44. u16 device;
  45. u16 subvendor;
  46. u16 subdevice;
  47. };
  48. static const struct sis_laptop sis_laptop[] = {
  49. /* devid, subvendor, subdev */
  50. { 0x5513, 0x1043, 0x1107 }, /* ASUS A6K */
  51. /* end marker */
  52. { 0, }
  53. };
  54. static int sis_short_ata40(struct pci_dev *dev)
  55. {
  56. const struct sis_laptop *lap = &sis_laptop[0];
  57. while (lap->device) {
  58. if (lap->device == dev->device &&
  59. lap->subvendor == dev->subsystem_vendor &&
  60. lap->subdevice == dev->subsystem_device)
  61. return 1;
  62. lap++;
  63. }
  64. return 0;
  65. }
  66. /**
  67. * sis_old_port_base - return PCI configuration base for dev
  68. * @adev: device
  69. *
  70. * Returns the base of the PCI configuration registers for this port
  71. * number.
  72. */
  73. static int sis_old_port_base(struct ata_device *adev)
  74. {
  75. return 0x40 + (4 * adev->ap->port_no) + (2 * adev->devno);
  76. }
  77. /**
  78. * sis_133_cable_detect - check for 40/80 pin
  79. * @ap: Port
  80. * @deadline: deadline jiffies for the operation
  81. *
  82. * Perform cable detection for the later UDMA133 capable
  83. * SiS chipset.
  84. */
  85. static int sis_133_cable_detect(struct ata_port *ap)
  86. {
  87. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  88. u16 tmp;
  89. /* The top bit of this register is the cable detect bit */
  90. pci_read_config_word(pdev, 0x50 + 2 * ap->port_no, &tmp);
  91. if ((tmp & 0x8000) && !sis_short_ata40(pdev))
  92. return ATA_CBL_PATA40;
  93. return ATA_CBL_PATA80;
  94. }
  95. /**
  96. * sis_66_cable_detect - check for 40/80 pin
  97. * @ap: Port
  98. * @deadline: deadline jiffies for the operation
  99. *
  100. * Perform cable detection on the UDMA66, UDMA100 and early UDMA133
  101. * SiS IDE controllers.
  102. */
  103. static int sis_66_cable_detect(struct ata_port *ap)
  104. {
  105. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  106. u8 tmp;
  107. /* Older chips keep cable detect in bits 4/5 of reg 0x48 */
  108. pci_read_config_byte(pdev, 0x48, &tmp);
  109. tmp >>= ap->port_no;
  110. if ((tmp & 0x10) && !sis_short_ata40(pdev))
  111. return ATA_CBL_PATA40;
  112. return ATA_CBL_PATA80;
  113. }
  114. /**
  115. * sis_pre_reset - probe begin
  116. * @ap: ATA port
  117. * @deadline: deadline jiffies for the operation
  118. *
  119. * Set up cable type and use generic probe init
  120. */
  121. static int sis_pre_reset(struct ata_port *ap, unsigned long deadline)
  122. {
  123. static const struct pci_bits sis_enable_bits[] = {
  124. { 0x4aU, 1U, 0x02UL, 0x02UL }, /* port 0 */
  125. { 0x4aU, 1U, 0x04UL, 0x04UL }, /* port 1 */
  126. };
  127. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  128. if (!pci_test_config_bits(pdev, &sis_enable_bits[ap->port_no]))
  129. return -ENOENT;
  130. 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_old_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_old_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_old_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_old_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 &= ~0xF000;
  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_old_port_base(adev);
  347. u8 timing;
  348. const u8 udma_bits[] = { 0x8B, 0x87, 0x85, 0x83, 0x82, 0x81};
  349. pci_read_config_byte(pdev, drive_pci + 1, &timing);
  350. if (adev->dma_mode < XFER_UDMA_0) {
  351. /* NOT SUPPORTED YET: NEED DATA SHEET. DITTO IN OLD DRIVER */
  352. } else {
  353. /* Bit 7 is UDMA on/off, bit 0-3 are cycle time */
  354. speed = adev->dma_mode - XFER_UDMA_0;
  355. timing &= ~0x8F;
  356. timing |= udma_bits[speed];
  357. }
  358. pci_write_config_byte(pdev, drive_pci + 1, 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_old_port_base(adev);
  377. u8 timing;
  378. /* Low 4 bits are timing */
  379. static const u8 udma_bits[] = { 0x8F, 0x8A, 0x87, 0x85, 0x83, 0x82, 0x81};
  380. pci_read_config_byte(pdev, drive_pci + 1, &timing);
  381. if (adev->dma_mode < XFER_UDMA_0) {
  382. /* NOT SUPPORTED YET: NEED DATA SHEET. DITTO IN OLD DRIVER */
  383. } else {
  384. /* Bit 7 is UDMA on/off, bit 0-3 are cycle time */
  385. speed = adev->dma_mode - XFER_UDMA_0;
  386. timing &= ~0x8F;
  387. timing |= udma_bits[speed];
  388. }
  389. pci_write_config_byte(pdev, drive_pci + 1, timing);
  390. }
  391. /**
  392. * sis_133_set_dmamode - Initialize host controller PATA DMA timings
  393. * @ap: Port whose timings we are configuring
  394. * @adev: Device to program
  395. *
  396. * Set UDMA/MWDMA mode for device, in host controller PCI config space.
  397. * Handles early SiS 961 bridges. Supports MWDMA as well unlike
  398. * the old ide/pci driver.
  399. *
  400. * LOCKING:
  401. * None (inherited from caller).
  402. */
  403. static void sis_133_set_dmamode (struct ata_port *ap, struct ata_device *adev)
  404. {
  405. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  406. int speed = adev->dma_mode - XFER_MW_DMA_0;
  407. int port = 0x40;
  408. u32 t1;
  409. u32 reg54;
  410. /* bits 4- cycle time 8 - cvs time */
  411. static const u32 timing_u100[] = { 0x6B0, 0x470, 0x350, 0x140, 0x120, 0x110, 0x000 };
  412. static const u32 timing_u133[] = { 0x9F0, 0x6A0, 0x470, 0x250, 0x230, 0x220, 0x210 };
  413. /* If bit 14 is set then the registers are mapped at 0x70 not 0x40 */
  414. pci_read_config_dword(pdev, 0x54, &reg54);
  415. if (reg54 & 0x40000000)
  416. port = 0x70;
  417. port += (8 * ap->port_no) + (4 * adev->devno);
  418. pci_read_config_dword(pdev, port, &t1);
  419. if (adev->dma_mode < XFER_UDMA_0) {
  420. t1 &= ~0x00000004;
  421. /* FIXME: need data sheet to add MWDMA here. Also lacking on
  422. ide/pci driver */
  423. } else {
  424. speed = adev->dma_mode - XFER_UDMA_0;
  425. /* if & 8 no UDMA133 - need info for ... */
  426. t1 &= ~0x00000FF0;
  427. t1 |= 0x00000004;
  428. if (t1 & 0x08)
  429. t1 |= timing_u133[speed];
  430. else
  431. t1 |= timing_u100[speed];
  432. }
  433. pci_write_config_dword(pdev, port, t1);
  434. }
  435. static struct scsi_host_template sis_sht = {
  436. .module = THIS_MODULE,
  437. .name = DRV_NAME,
  438. .ioctl = ata_scsi_ioctl,
  439. .queuecommand = ata_scsi_queuecmd,
  440. .can_queue = ATA_DEF_QUEUE,
  441. .this_id = ATA_SHT_THIS_ID,
  442. .sg_tablesize = LIBATA_MAX_PRD,
  443. .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
  444. .emulated = ATA_SHT_EMULATED,
  445. .use_clustering = ATA_SHT_USE_CLUSTERING,
  446. .proc_name = DRV_NAME,
  447. .dma_boundary = ATA_DMA_BOUNDARY,
  448. .slave_configure = ata_scsi_slave_config,
  449. .slave_destroy = ata_scsi_slave_destroy,
  450. .bios_param = ata_std_bios_param,
  451. };
  452. static const struct ata_port_operations sis_133_ops = {
  453. .port_disable = ata_port_disable,
  454. .set_piomode = sis_133_set_piomode,
  455. .set_dmamode = sis_133_set_dmamode,
  456. .mode_filter = ata_pci_default_filter,
  457. .tf_load = ata_tf_load,
  458. .tf_read = ata_tf_read,
  459. .check_status = ata_check_status,
  460. .exec_command = ata_exec_command,
  461. .dev_select = ata_std_dev_select,
  462. .freeze = ata_bmdma_freeze,
  463. .thaw = ata_bmdma_thaw,
  464. .error_handler = sis_error_handler,
  465. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  466. .cable_detect = sis_133_cable_detect,
  467. .bmdma_setup = ata_bmdma_setup,
  468. .bmdma_start = ata_bmdma_start,
  469. .bmdma_stop = ata_bmdma_stop,
  470. .bmdma_status = ata_bmdma_status,
  471. .qc_prep = ata_qc_prep,
  472. .qc_issue = ata_qc_issue_prot,
  473. .data_xfer = ata_data_xfer,
  474. .irq_handler = ata_interrupt,
  475. .irq_clear = ata_bmdma_irq_clear,
  476. .irq_on = ata_irq_on,
  477. .irq_ack = ata_irq_ack,
  478. .port_start = ata_port_start,
  479. };
  480. static const struct ata_port_operations sis_133_for_sata_ops = {
  481. .port_disable = ata_port_disable,
  482. .set_piomode = sis_133_set_piomode,
  483. .set_dmamode = sis_133_set_dmamode,
  484. .mode_filter = ata_pci_default_filter,
  485. .tf_load = ata_tf_load,
  486. .tf_read = ata_tf_read,
  487. .check_status = ata_check_status,
  488. .exec_command = ata_exec_command,
  489. .dev_select = ata_std_dev_select,
  490. .freeze = ata_bmdma_freeze,
  491. .thaw = ata_bmdma_thaw,
  492. .error_handler = ata_bmdma_error_handler,
  493. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  494. .cable_detect = sis_133_cable_detect,
  495. .bmdma_setup = ata_bmdma_setup,
  496. .bmdma_start = ata_bmdma_start,
  497. .bmdma_stop = ata_bmdma_stop,
  498. .bmdma_status = ata_bmdma_status,
  499. .qc_prep = ata_qc_prep,
  500. .qc_issue = ata_qc_issue_prot,
  501. .data_xfer = ata_data_xfer,
  502. .irq_handler = ata_interrupt,
  503. .irq_clear = ata_bmdma_irq_clear,
  504. .irq_on = ata_irq_on,
  505. .irq_ack = ata_irq_ack,
  506. .port_start = ata_port_start,
  507. };
  508. static const struct ata_port_operations sis_133_early_ops = {
  509. .port_disable = ata_port_disable,
  510. .set_piomode = sis_100_set_piomode,
  511. .set_dmamode = sis_133_early_set_dmamode,
  512. .mode_filter = ata_pci_default_filter,
  513. .tf_load = ata_tf_load,
  514. .tf_read = ata_tf_read,
  515. .check_status = ata_check_status,
  516. .exec_command = ata_exec_command,
  517. .dev_select = ata_std_dev_select,
  518. .freeze = ata_bmdma_freeze,
  519. .thaw = ata_bmdma_thaw,
  520. .error_handler = sis_error_handler,
  521. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  522. .cable_detect = sis_66_cable_detect,
  523. .bmdma_setup = ata_bmdma_setup,
  524. .bmdma_start = ata_bmdma_start,
  525. .bmdma_stop = ata_bmdma_stop,
  526. .bmdma_status = ata_bmdma_status,
  527. .qc_prep = ata_qc_prep,
  528. .qc_issue = ata_qc_issue_prot,
  529. .data_xfer = ata_data_xfer,
  530. .irq_handler = ata_interrupt,
  531. .irq_clear = ata_bmdma_irq_clear,
  532. .irq_on = ata_irq_on,
  533. .irq_ack = ata_irq_ack,
  534. .port_start = ata_port_start,
  535. };
  536. static const struct ata_port_operations sis_100_ops = {
  537. .port_disable = ata_port_disable,
  538. .set_piomode = sis_100_set_piomode,
  539. .set_dmamode = sis_100_set_dmamode,
  540. .mode_filter = ata_pci_default_filter,
  541. .tf_load = ata_tf_load,
  542. .tf_read = ata_tf_read,
  543. .check_status = ata_check_status,
  544. .exec_command = ata_exec_command,
  545. .dev_select = ata_std_dev_select,
  546. .freeze = ata_bmdma_freeze,
  547. .thaw = ata_bmdma_thaw,
  548. .error_handler = sis_error_handler,
  549. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  550. .cable_detect = sis_66_cable_detect,
  551. .bmdma_setup = ata_bmdma_setup,
  552. .bmdma_start = ata_bmdma_start,
  553. .bmdma_stop = ata_bmdma_stop,
  554. .bmdma_status = ata_bmdma_status,
  555. .qc_prep = ata_qc_prep,
  556. .qc_issue = ata_qc_issue_prot,
  557. .data_xfer = ata_data_xfer,
  558. .irq_handler = ata_interrupt,
  559. .irq_clear = ata_bmdma_irq_clear,
  560. .irq_on = ata_irq_on,
  561. .irq_ack = ata_irq_ack,
  562. .port_start = ata_port_start,
  563. };
  564. static const struct ata_port_operations sis_66_ops = {
  565. .port_disable = ata_port_disable,
  566. .set_piomode = sis_old_set_piomode,
  567. .set_dmamode = sis_66_set_dmamode,
  568. .mode_filter = ata_pci_default_filter,
  569. .tf_load = ata_tf_load,
  570. .tf_read = ata_tf_read,
  571. .check_status = ata_check_status,
  572. .exec_command = ata_exec_command,
  573. .dev_select = ata_std_dev_select,
  574. .cable_detect = sis_66_cable_detect,
  575. .freeze = ata_bmdma_freeze,
  576. .thaw = ata_bmdma_thaw,
  577. .error_handler = sis_error_handler,
  578. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  579. .bmdma_setup = ata_bmdma_setup,
  580. .bmdma_start = ata_bmdma_start,
  581. .bmdma_stop = ata_bmdma_stop,
  582. .bmdma_status = ata_bmdma_status,
  583. .qc_prep = ata_qc_prep,
  584. .qc_issue = ata_qc_issue_prot,
  585. .data_xfer = ata_data_xfer,
  586. .irq_handler = ata_interrupt,
  587. .irq_clear = ata_bmdma_irq_clear,
  588. .irq_on = ata_irq_on,
  589. .irq_ack = ata_irq_ack,
  590. .port_start = ata_port_start,
  591. };
  592. static const struct ata_port_operations sis_old_ops = {
  593. .port_disable = ata_port_disable,
  594. .set_piomode = sis_old_set_piomode,
  595. .set_dmamode = sis_old_set_dmamode,
  596. .mode_filter = ata_pci_default_filter,
  597. .tf_load = ata_tf_load,
  598. .tf_read = ata_tf_read,
  599. .check_status = ata_check_status,
  600. .exec_command = ata_exec_command,
  601. .dev_select = ata_std_dev_select,
  602. .freeze = ata_bmdma_freeze,
  603. .thaw = ata_bmdma_thaw,
  604. .error_handler = sis_error_handler,
  605. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  606. .cable_detect = ata_cable_40wire,
  607. .bmdma_setup = ata_bmdma_setup,
  608. .bmdma_start = ata_bmdma_start,
  609. .bmdma_stop = ata_bmdma_stop,
  610. .bmdma_status = ata_bmdma_status,
  611. .qc_prep = ata_qc_prep,
  612. .qc_issue = ata_qc_issue_prot,
  613. .data_xfer = ata_data_xfer,
  614. .irq_handler = ata_interrupt,
  615. .irq_clear = ata_bmdma_irq_clear,
  616. .irq_on = ata_irq_on,
  617. .irq_ack = ata_irq_ack,
  618. .port_start = ata_port_start,
  619. };
  620. static const struct ata_port_info sis_info = {
  621. .sht = &sis_sht,
  622. .flags = ATA_FLAG_SLAVE_POSS,
  623. .pio_mask = 0x1f, /* pio0-4 */
  624. .mwdma_mask = 0x07,
  625. .udma_mask = 0,
  626. .port_ops = &sis_old_ops,
  627. };
  628. static const struct ata_port_info sis_info33 = {
  629. .sht = &sis_sht,
  630. .flags = ATA_FLAG_SLAVE_POSS,
  631. .pio_mask = 0x1f, /* pio0-4 */
  632. .mwdma_mask = 0x07,
  633. .udma_mask = ATA_UDMA2, /* UDMA 33 */
  634. .port_ops = &sis_old_ops,
  635. };
  636. static const struct ata_port_info sis_info66 = {
  637. .sht = &sis_sht,
  638. .flags = ATA_FLAG_SLAVE_POSS,
  639. .pio_mask = 0x1f, /* pio0-4 */
  640. .udma_mask = ATA_UDMA4, /* UDMA 66 */
  641. .port_ops = &sis_66_ops,
  642. };
  643. static const struct ata_port_info sis_info100 = {
  644. .sht = &sis_sht,
  645. .flags = ATA_FLAG_SLAVE_POSS,
  646. .pio_mask = 0x1f, /* pio0-4 */
  647. .udma_mask = ATA_UDMA5,
  648. .port_ops = &sis_100_ops,
  649. };
  650. static const struct ata_port_info sis_info100_early = {
  651. .sht = &sis_sht,
  652. .flags = ATA_FLAG_SLAVE_POSS,
  653. .udma_mask = ATA_UDMA5,
  654. .pio_mask = 0x1f, /* pio0-4 */
  655. .port_ops = &sis_66_ops,
  656. };
  657. static const struct ata_port_info sis_info133 = {
  658. .sht = &sis_sht,
  659. .flags = ATA_FLAG_SLAVE_POSS,
  660. .pio_mask = 0x1f, /* pio0-4 */
  661. .udma_mask = ATA_UDMA6,
  662. .port_ops = &sis_133_ops,
  663. };
  664. const struct ata_port_info sis_info133_for_sata = {
  665. .sht = &sis_sht,
  666. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  667. .pio_mask = 0x1f, /* pio0-4 */
  668. .udma_mask = ATA_UDMA6,
  669. .port_ops = &sis_133_for_sata_ops,
  670. };
  671. static const struct ata_port_info sis_info133_early = {
  672. .sht = &sis_sht,
  673. .flags = ATA_FLAG_SLAVE_POSS,
  674. .pio_mask = 0x1f, /* pio0-4 */
  675. .udma_mask = ATA_UDMA6,
  676. .port_ops = &sis_133_early_ops,
  677. };
  678. /* Privately shared with the SiS180 SATA driver, not for use elsewhere */
  679. EXPORT_SYMBOL_GPL(sis_info133_for_sata);
  680. static void sis_fixup(struct pci_dev *pdev, struct sis_chipset *sis)
  681. {
  682. u16 regw;
  683. u8 reg;
  684. if (sis->info == &sis_info133) {
  685. pci_read_config_word(pdev, 0x50, &regw);
  686. if (regw & 0x08)
  687. pci_write_config_word(pdev, 0x50, regw & ~0x08);
  688. pci_read_config_word(pdev, 0x52, &regw);
  689. if (regw & 0x08)
  690. pci_write_config_word(pdev, 0x52, regw & ~0x08);
  691. return;
  692. }
  693. if (sis->info == &sis_info133_early || sis->info == &sis_info100) {
  694. /* Fix up latency */
  695. pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x80);
  696. /* Set compatibility bit */
  697. pci_read_config_byte(pdev, 0x49, &reg);
  698. if (!(reg & 0x01))
  699. pci_write_config_byte(pdev, 0x49, reg | 0x01);
  700. return;
  701. }
  702. if (sis->info == &sis_info66 || sis->info == &sis_info100_early) {
  703. /* Fix up latency */
  704. pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x80);
  705. /* Set compatibility bit */
  706. pci_read_config_byte(pdev, 0x52, &reg);
  707. if (!(reg & 0x04))
  708. pci_write_config_byte(pdev, 0x52, reg | 0x04);
  709. return;
  710. }
  711. if (sis->info == &sis_info33) {
  712. pci_read_config_byte(pdev, PCI_CLASS_PROG, &reg);
  713. if (( reg & 0x0F ) != 0x00)
  714. pci_write_config_byte(pdev, PCI_CLASS_PROG, reg & 0xF0);
  715. /* Fall through to ATA16 fixup below */
  716. }
  717. if (sis->info == &sis_info || sis->info == &sis_info33) {
  718. /* force per drive recovery and active timings
  719. needed on ATA_33 and below chips */
  720. pci_read_config_byte(pdev, 0x52, &reg);
  721. if (!(reg & 0x08))
  722. pci_write_config_byte(pdev, 0x52, reg|0x08);
  723. return;
  724. }
  725. BUG();
  726. }
  727. /**
  728. * sis_init_one - Register SiS ATA PCI device with kernel services
  729. * @pdev: PCI device to register
  730. * @ent: Entry in sis_pci_tbl matching with @pdev
  731. *
  732. * Called from kernel PCI layer. We probe for combined mode (sigh),
  733. * and then hand over control to libata, for it to do the rest.
  734. *
  735. * LOCKING:
  736. * Inherited from PCI layer (may sleep).
  737. *
  738. * RETURNS:
  739. * Zero on success, or -ERRNO value.
  740. */
  741. static int sis_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
  742. {
  743. static int printed_version;
  744. struct ata_port_info port;
  745. const struct ata_port_info *ppi[] = { &port, NULL };
  746. struct pci_dev *host = NULL;
  747. struct sis_chipset *chipset = NULL;
  748. struct sis_chipset *sets;
  749. static struct sis_chipset sis_chipsets[] = {
  750. { 0x0968, &sis_info133 },
  751. { 0x0966, &sis_info133 },
  752. { 0x0965, &sis_info133 },
  753. { 0x0745, &sis_info100 },
  754. { 0x0735, &sis_info100 },
  755. { 0x0733, &sis_info100 },
  756. { 0x0635, &sis_info100 },
  757. { 0x0633, &sis_info100 },
  758. { 0x0730, &sis_info100_early }, /* 100 with ATA 66 layout */
  759. { 0x0550, &sis_info100_early }, /* 100 with ATA 66 layout */
  760. { 0x0640, &sis_info66 },
  761. { 0x0630, &sis_info66 },
  762. { 0x0620, &sis_info66 },
  763. { 0x0540, &sis_info66 },
  764. { 0x0530, &sis_info66 },
  765. { 0x5600, &sis_info33 },
  766. { 0x5598, &sis_info33 },
  767. { 0x5597, &sis_info33 },
  768. { 0x5591, &sis_info33 },
  769. { 0x5582, &sis_info33 },
  770. { 0x5581, &sis_info33 },
  771. { 0x5596, &sis_info },
  772. { 0x5571, &sis_info },
  773. { 0x5517, &sis_info },
  774. { 0x5511, &sis_info },
  775. {0}
  776. };
  777. static struct sis_chipset sis133_early = {
  778. 0x0, &sis_info133_early
  779. };
  780. static struct sis_chipset sis133 = {
  781. 0x0, &sis_info133
  782. };
  783. static struct sis_chipset sis100_early = {
  784. 0x0, &sis_info100_early
  785. };
  786. static struct sis_chipset sis100 = {
  787. 0x0, &sis_info100
  788. };
  789. if (!printed_version++)
  790. dev_printk(KERN_DEBUG, &pdev->dev,
  791. "version " DRV_VERSION "\n");
  792. /* We have to find the bridge first */
  793. for (sets = &sis_chipsets[0]; sets->device; sets++) {
  794. host = pci_get_device(PCI_VENDOR_ID_SI, sets->device, NULL);
  795. if (host != NULL) {
  796. chipset = sets; /* Match found */
  797. if (sets->device == 0x630) { /* SIS630 */
  798. if (host->revision >= 0x30) /* 630 ET */
  799. chipset = &sis100_early;
  800. }
  801. break;
  802. }
  803. }
  804. /* Look for concealed bridges */
  805. if (chipset == NULL) {
  806. /* Second check */
  807. u32 idemisc;
  808. u16 trueid;
  809. /* Disable ID masking and register remapping then
  810. see what the real ID is */
  811. pci_read_config_dword(pdev, 0x54, &idemisc);
  812. pci_write_config_dword(pdev, 0x54, idemisc & 0x7fffffff);
  813. pci_read_config_word(pdev, PCI_DEVICE_ID, &trueid);
  814. pci_write_config_dword(pdev, 0x54, idemisc);
  815. switch(trueid) {
  816. case 0x5518: /* SIS 962/963 */
  817. chipset = &sis133;
  818. if ((idemisc & 0x40000000) == 0) {
  819. pci_write_config_dword(pdev, 0x54, idemisc | 0x40000000);
  820. printk(KERN_INFO "SIS5513: Switching to 5513 register mapping\n");
  821. }
  822. break;
  823. case 0x0180: /* SIS 965/965L */
  824. chipset = &sis133;
  825. break;
  826. case 0x1180: /* SIS 966/966L */
  827. chipset = &sis133;
  828. break;
  829. }
  830. }
  831. /* Further check */
  832. if (chipset == NULL) {
  833. struct pci_dev *lpc_bridge;
  834. u16 trueid;
  835. u8 prefctl;
  836. u8 idecfg;
  837. /* Try the second unmasking technique */
  838. pci_read_config_byte(pdev, 0x4a, &idecfg);
  839. pci_write_config_byte(pdev, 0x4a, idecfg | 0x10);
  840. pci_read_config_word(pdev, PCI_DEVICE_ID, &trueid);
  841. pci_write_config_byte(pdev, 0x4a, idecfg);
  842. switch(trueid) {
  843. case 0x5517:
  844. lpc_bridge = pci_get_slot(pdev->bus, 0x10); /* Bus 0 Dev 2 Fn 0 */
  845. if (lpc_bridge == NULL)
  846. break;
  847. pci_read_config_byte(pdev, 0x49, &prefctl);
  848. pci_dev_put(lpc_bridge);
  849. if (lpc_bridge->revision == 0x10 && (prefctl & 0x80)) {
  850. chipset = &sis133_early;
  851. break;
  852. }
  853. chipset = &sis100;
  854. break;
  855. }
  856. }
  857. pci_dev_put(host);
  858. /* No chipset info, no support */
  859. if (chipset == NULL)
  860. return -ENODEV;
  861. port = *chipset->info;
  862. port.private_data = chipset;
  863. sis_fixup(pdev, chipset);
  864. return ata_pci_init_one(pdev, ppi);
  865. }
  866. static const struct pci_device_id sis_pci_tbl[] = {
  867. { PCI_VDEVICE(SI, 0x5513), }, /* SiS 5513 */
  868. { PCI_VDEVICE(SI, 0x5518), }, /* SiS 5518 */
  869. { PCI_VDEVICE(SI, 0x1180), }, /* SiS 1180 */
  870. { }
  871. };
  872. static struct pci_driver sis_pci_driver = {
  873. .name = DRV_NAME,
  874. .id_table = sis_pci_tbl,
  875. .probe = sis_init_one,
  876. .remove = ata_pci_remove_one,
  877. #ifdef CONFIG_PM
  878. .suspend = ata_pci_device_suspend,
  879. .resume = ata_pci_device_resume,
  880. #endif
  881. };
  882. static int __init sis_init(void)
  883. {
  884. return pci_register_driver(&sis_pci_driver);
  885. }
  886. static void __exit sis_exit(void)
  887. {
  888. pci_unregister_driver(&sis_pci_driver);
  889. }
  890. module_init(sis_init);
  891. module_exit(sis_exit);
  892. MODULE_AUTHOR("Alan Cox");
  893. MODULE_DESCRIPTION("SCSI low-level driver for SiS ATA");
  894. MODULE_LICENSE("GPL");
  895. MODULE_DEVICE_TABLE(pci, sis_pci_tbl);
  896. MODULE_VERSION(DRV_VERSION);