pata_sis.c 26 KB

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