pata_sis.c 27 KB

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