pata_sis.c 27 KB

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