pata_sis.c 27 KB

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