pata_sis.c 27 KB

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