pata_sis.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914
  1. /*
  2. * pata_sis.c - SiS ATA driver
  3. *
  4. * (C) 2005 Red Hat
  5. * (C) 2007,2009 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/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.2"
  37. struct sis_chipset {
  38. u16 device; /* PCI host ID */
  39. const 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. { 0x5513, 0x1734, 0x105F }, /* FSC Amilo A1630 */
  52. { 0x5513, 0x1071, 0x8640 }, /* EasyNote K5305 */
  53. /* end marker */
  54. { 0, }
  55. };
  56. static int sis_short_ata40(struct pci_dev *dev)
  57. {
  58. const struct sis_laptop *lap = &sis_laptop[0];
  59. while (lap->device) {
  60. if (lap->device == dev->device &&
  61. lap->subvendor == dev->subsystem_vendor &&
  62. lap->subdevice == dev->subsystem_device)
  63. return 1;
  64. lap++;
  65. }
  66. return 0;
  67. }
  68. /**
  69. * sis_old_port_base - return PCI configuration base for dev
  70. * @adev: device
  71. *
  72. * Returns the base of the PCI configuration registers for this port
  73. * number.
  74. */
  75. static int sis_old_port_base(struct ata_device *adev)
  76. {
  77. return 0x40 + (4 * adev->link->ap->port_no) + (2 * adev->devno);
  78. }
  79. /**
  80. * sis_port_base - return PCI configuration base for dev
  81. * @adev: device
  82. *
  83. * Returns the base of the PCI configuration registers for this port
  84. * number.
  85. */
  86. static int sis_port_base(struct ata_device *adev)
  87. {
  88. struct ata_port *ap = adev->link->ap;
  89. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  90. int port = 0x40;
  91. u32 reg54;
  92. /* If bit 30 is set then the registers are mapped at 0x70 not 0x40 */
  93. pci_read_config_dword(pdev, 0x54, &reg54);
  94. if (reg54 & 0x40000000)
  95. port = 0x70;
  96. return port + (8 * ap->port_no) + (4 * adev->devno);
  97. }
  98. /**
  99. * sis_133_cable_detect - check for 40/80 pin
  100. * @ap: Port
  101. * @deadline: deadline jiffies for the operation
  102. *
  103. * Perform cable detection for the later UDMA133 capable
  104. * SiS chipset.
  105. */
  106. static int sis_133_cable_detect(struct ata_port *ap)
  107. {
  108. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  109. u16 tmp;
  110. /* The top bit of this register is the cable detect bit */
  111. pci_read_config_word(pdev, 0x50 + 2 * ap->port_no, &tmp);
  112. if ((tmp & 0x8000) && !sis_short_ata40(pdev))
  113. return ATA_CBL_PATA40;
  114. return ATA_CBL_PATA80;
  115. }
  116. /**
  117. * sis_66_cable_detect - check for 40/80 pin
  118. * @ap: Port
  119. *
  120. * Perform cable detection on the UDMA66, UDMA100 and early UDMA133
  121. * SiS IDE controllers.
  122. */
  123. static int sis_66_cable_detect(struct ata_port *ap)
  124. {
  125. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  126. u8 tmp;
  127. /* Older chips keep cable detect in bits 4/5 of reg 0x48 */
  128. pci_read_config_byte(pdev, 0x48, &tmp);
  129. tmp >>= ap->port_no;
  130. if ((tmp & 0x10) && !sis_short_ata40(pdev))
  131. return ATA_CBL_PATA40;
  132. return ATA_CBL_PATA80;
  133. }
  134. /**
  135. * sis_pre_reset - probe begin
  136. * @link: ATA link
  137. * @deadline: deadline jiffies for the operation
  138. *
  139. * Set up cable type and use generic probe init
  140. */
  141. static int sis_pre_reset(struct ata_link *link, unsigned long deadline)
  142. {
  143. static const struct pci_bits sis_enable_bits[] = {
  144. { 0x4aU, 1U, 0x02UL, 0x02UL }, /* port 0 */
  145. { 0x4aU, 1U, 0x04UL, 0x04UL }, /* port 1 */
  146. };
  147. struct ata_port *ap = link->ap;
  148. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  149. if (!pci_test_config_bits(pdev, &sis_enable_bits[ap->port_no]))
  150. return -ENOENT;
  151. /* Clear the FIFO settings. We can't enable the FIFO until
  152. we know we are poking at a disk */
  153. pci_write_config_byte(pdev, 0x4B, 0);
  154. return ata_sff_prereset(link, deadline);
  155. }
  156. /**
  157. * sis_set_fifo - Set RWP fifo bits for this device
  158. * @ap: Port
  159. * @adev: Device
  160. *
  161. * SIS chipsets implement prefetch/postwrite bits for each device
  162. * on both channels. This functionality is not ATAPI compatible and
  163. * must be configured according to the class of device present
  164. */
  165. static void sis_set_fifo(struct ata_port *ap, struct ata_device *adev)
  166. {
  167. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  168. u8 fifoctrl;
  169. u8 mask = 0x11;
  170. mask <<= (2 * ap->port_no);
  171. mask <<= adev->devno;
  172. /* This holds various bits including the FIFO control */
  173. pci_read_config_byte(pdev, 0x4B, &fifoctrl);
  174. fifoctrl &= ~mask;
  175. /* Enable for ATA (disk) only */
  176. if (adev->class == ATA_DEV_ATA)
  177. fifoctrl |= mask;
  178. pci_write_config_byte(pdev, 0x4B, fifoctrl);
  179. }
  180. /**
  181. * sis_old_set_piomode - Initialize host controller PATA PIO timings
  182. * @ap: Port whose timings we are configuring
  183. * @adev: Device we are configuring for.
  184. *
  185. * Set PIO mode for device, in host controller PCI config space. This
  186. * function handles PIO set up for all chips that are pre ATA100 and
  187. * also early ATA100 devices.
  188. *
  189. * LOCKING:
  190. * None (inherited from caller).
  191. */
  192. static void sis_old_set_piomode (struct ata_port *ap, struct ata_device *adev)
  193. {
  194. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  195. int port = sis_old_port_base(adev);
  196. u8 t1, t2;
  197. int speed = adev->pio_mode - XFER_PIO_0;
  198. static const u8 active[] = { 0x00, 0x07, 0x04, 0x03, 0x01 };
  199. static const u8 recovery[] = { 0x00, 0x06, 0x04, 0x03, 0x03 };
  200. sis_set_fifo(ap, adev);
  201. pci_read_config_byte(pdev, port, &t1);
  202. pci_read_config_byte(pdev, port + 1, &t2);
  203. t1 &= ~0x0F; /* Clear active/recovery timings */
  204. t2 &= ~0x07;
  205. t1 |= active[speed];
  206. t2 |= recovery[speed];
  207. pci_write_config_byte(pdev, port, t1);
  208. pci_write_config_byte(pdev, port + 1, t2);
  209. }
  210. /**
  211. * sis_100_set_piomode - Initialize host controller PATA PIO timings
  212. * @ap: Port whose timings we are configuring
  213. * @adev: Device we are configuring for.
  214. *
  215. * Set PIO mode for device, in host controller PCI config space. This
  216. * function handles PIO set up for ATA100 devices and early ATA133.
  217. *
  218. * LOCKING:
  219. * None (inherited from caller).
  220. */
  221. static void sis_100_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_old_port_base(adev);
  225. int speed = adev->pio_mode - XFER_PIO_0;
  226. static const u8 actrec[] = { 0x00, 0x67, 0x44, 0x33, 0x31 };
  227. sis_set_fifo(ap, adev);
  228. pci_write_config_byte(pdev, port, actrec[speed]);
  229. }
  230. /**
  231. * sis_133_set_piomode - Initialize host controller PATA PIO timings
  232. * @ap: Port whose timings we are configuring
  233. * @adev: Device we are configuring for.
  234. *
  235. * Set PIO mode for device, in host controller PCI config space. This
  236. * function handles PIO set up for the later ATA133 devices.
  237. *
  238. * LOCKING:
  239. * None (inherited from caller).
  240. */
  241. static void sis_133_set_piomode (struct ata_port *ap, struct ata_device *adev)
  242. {
  243. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  244. int port;
  245. u32 t1;
  246. int speed = adev->pio_mode - XFER_PIO_0;
  247. static const u32 timing133[] = {
  248. 0x28269000, /* Recovery << 24 | Act << 16 | Ini << 12 */
  249. 0x0C266000,
  250. 0x04263000,
  251. 0x0C0A3000,
  252. 0x05093000
  253. };
  254. static const u32 timing100[] = {
  255. 0x1E1C6000, /* Recovery << 24 | Act << 16 | Ini << 12 */
  256. 0x091C4000,
  257. 0x031C2000,
  258. 0x09072000,
  259. 0x04062000
  260. };
  261. sis_set_fifo(ap, adev);
  262. port = sis_port_base(adev);
  263. pci_read_config_dword(pdev, port, &t1);
  264. t1 &= 0xC0C00FFF; /* Mask out timing */
  265. if (t1 & 0x08) /* 100 or 133 ? */
  266. t1 |= timing133[speed];
  267. else
  268. t1 |= timing100[speed];
  269. pci_write_config_byte(pdev, port, t1);
  270. }
  271. /**
  272. * sis_old_set_dmamode - Initialize host controller PATA DMA timings
  273. * @ap: Port whose timings we are configuring
  274. * @adev: Device to program
  275. *
  276. * Set UDMA/MWDMA mode for device, in host controller PCI config space.
  277. * Handles pre UDMA and UDMA33 devices. Supports MWDMA as well unlike
  278. * the old ide/pci driver.
  279. *
  280. * LOCKING:
  281. * None (inherited from caller).
  282. */
  283. static void sis_old_set_dmamode (struct ata_port *ap, struct ata_device *adev)
  284. {
  285. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  286. int speed = adev->dma_mode - XFER_MW_DMA_0;
  287. int drive_pci = sis_old_port_base(adev);
  288. u16 timing;
  289. static const u16 mwdma_bits[] = { 0x008, 0x302, 0x301 };
  290. static const u16 udma_bits[] = { 0xE000, 0xC000, 0xA000 };
  291. pci_read_config_word(pdev, drive_pci, &timing);
  292. if (adev->dma_mode < XFER_UDMA_0) {
  293. /* bits 3-0 hold recovery timing bits 8-10 active timing and
  294. the higher bits are dependent on the device */
  295. timing &= ~0x870F;
  296. timing |= mwdma_bits[speed];
  297. } else {
  298. /* Bit 15 is UDMA on/off, bit 13-14 are cycle time */
  299. speed = adev->dma_mode - XFER_UDMA_0;
  300. timing &= ~0x6000;
  301. timing |= udma_bits[speed];
  302. }
  303. pci_write_config_word(pdev, drive_pci, timing);
  304. }
  305. /**
  306. * sis_66_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 UDMA66 and early UDMA100 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_66_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_old_port_base(adev);
  322. u16 timing;
  323. /* MWDMA 0-2 and UDMA 0-5 */
  324. static const u16 mwdma_bits[] = { 0x008, 0x302, 0x301 };
  325. static const u16 udma_bits[] = { 0xF000, 0xD000, 0xB000, 0xA000, 0x9000, 0x8000 };
  326. pci_read_config_word(pdev, drive_pci, &timing);
  327. if (adev->dma_mode < XFER_UDMA_0) {
  328. /* bits 3-0 hold recovery timing bits 8-10 active timing and
  329. the higher bits are dependent on the device, bit 15 udma */
  330. timing &= ~0x870F;
  331. timing |= mwdma_bits[speed];
  332. } else {
  333. /* Bit 15 is UDMA on/off, bit 12-14 are cycle time */
  334. speed = adev->dma_mode - XFER_UDMA_0;
  335. timing &= ~0xF000;
  336. timing |= udma_bits[speed];
  337. }
  338. pci_write_config_word(pdev, drive_pci, timing);
  339. }
  340. /**
  341. * sis_100_set_dmamode - Initialize host controller PATA DMA timings
  342. * @ap: Port whose timings we are configuring
  343. * @adev: Device to program
  344. *
  345. * Set UDMA/MWDMA mode for device, in host controller PCI config space.
  346. * Handles UDMA66 and early UDMA100 devices.
  347. *
  348. * LOCKING:
  349. * None (inherited from caller).
  350. */
  351. static void sis_100_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_old_port_base(adev);
  356. u8 timing;
  357. static const u8 udma_bits[] = { 0x8B, 0x87, 0x85, 0x83, 0x82, 0x81};
  358. pci_read_config_byte(pdev, drive_pci + 1, &timing);
  359. if (adev->dma_mode < XFER_UDMA_0) {
  360. /* NOT SUPPORTED YET: NEED DATA SHEET. DITTO IN OLD DRIVER */
  361. } else {
  362. /* Bit 7 is UDMA on/off, bit 0-3 are cycle time */
  363. speed = adev->dma_mode - XFER_UDMA_0;
  364. timing &= ~0x8F;
  365. timing |= udma_bits[speed];
  366. }
  367. pci_write_config_byte(pdev, drive_pci + 1, timing);
  368. }
  369. /**
  370. * sis_133_early_set_dmamode - Initialize host controller PATA DMA timings
  371. * @ap: Port whose timings we are configuring
  372. * @adev: Device to program
  373. *
  374. * Set UDMA/MWDMA mode for device, in host controller PCI config space.
  375. * Handles early SiS 961 bridges.
  376. *
  377. * LOCKING:
  378. * None (inherited from caller).
  379. */
  380. static void sis_133_early_set_dmamode (struct ata_port *ap, struct ata_device *adev)
  381. {
  382. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  383. int speed = adev->dma_mode - XFER_MW_DMA_0;
  384. int drive_pci = sis_old_port_base(adev);
  385. u8 timing;
  386. /* Low 4 bits are timing */
  387. static const u8 udma_bits[] = { 0x8F, 0x8A, 0x87, 0x85, 0x83, 0x82, 0x81};
  388. pci_read_config_byte(pdev, drive_pci + 1, &timing);
  389. if (adev->dma_mode < XFER_UDMA_0) {
  390. /* NOT SUPPORTED YET: NEED DATA SHEET. DITTO IN OLD DRIVER */
  391. } else {
  392. /* Bit 7 is UDMA on/off, bit 0-3 are cycle time */
  393. speed = adev->dma_mode - XFER_UDMA_0;
  394. timing &= ~0x8F;
  395. timing |= udma_bits[speed];
  396. }
  397. pci_write_config_byte(pdev, drive_pci + 1, timing);
  398. }
  399. /**
  400. * sis_133_set_dmamode - Initialize host controller PATA DMA timings
  401. * @ap: Port whose timings we are configuring
  402. * @adev: Device to program
  403. *
  404. * Set UDMA/MWDMA mode for device, in host controller PCI config space.
  405. *
  406. * LOCKING:
  407. * None (inherited from caller).
  408. */
  409. static void sis_133_set_dmamode (struct ata_port *ap, struct ata_device *adev)
  410. {
  411. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  412. int port;
  413. u32 t1;
  414. port = sis_port_base(adev);
  415. pci_read_config_dword(pdev, port, &t1);
  416. if (adev->dma_mode < XFER_UDMA_0) {
  417. /* Recovery << 24 | Act << 16 | Ini << 12, like PIO modes */
  418. static const u32 timing_u100[] = { 0x19154000, 0x06072000, 0x04062000 };
  419. static const u32 timing_u133[] = { 0x221C6000, 0x0C0A3000, 0x05093000 };
  420. int speed = adev->dma_mode - XFER_MW_DMA_0;
  421. t1 &= 0xC0C00FFF;
  422. /* disable UDMA */
  423. t1 &= ~0x00000004;
  424. if (t1 & 0x08)
  425. t1 |= timing_u133[speed];
  426. else
  427. t1 |= timing_u100[speed];
  428. } else {
  429. /* bits 4- cycle time 8 - cvs time */
  430. static const u32 timing_u100[] = { 0x6B0, 0x470, 0x350, 0x140, 0x120, 0x110, 0x000 };
  431. static const u32 timing_u133[] = { 0x9F0, 0x6A0, 0x470, 0x250, 0x230, 0x220, 0x210 };
  432. int speed = adev->dma_mode - XFER_UDMA_0;
  433. t1 &= ~0x00000FF0;
  434. /* enable UDMA */
  435. t1 |= 0x00000004;
  436. if (t1 & 0x08)
  437. t1 |= timing_u133[speed];
  438. else
  439. t1 |= timing_u100[speed];
  440. }
  441. pci_write_config_dword(pdev, port, t1);
  442. }
  443. /**
  444. * sis_133_mode_filter - mode selection filter
  445. * @adev: ATA device
  446. *
  447. * Block UDMA6 on devices that do not support it.
  448. */
  449. static unsigned long sis_133_mode_filter(struct ata_device *adev, unsigned long mask)
  450. {
  451. struct ata_port *ap = adev->link->ap;
  452. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  453. int port = sis_port_base(adev);
  454. u32 t1;
  455. pci_read_config_dword(pdev, port, &t1);
  456. /* if ATA133 is disabled, mask it out */
  457. if (!(t1 & 0x08))
  458. mask &= ~(0xC0 << ATA_SHIFT_UDMA);
  459. return mask;
  460. }
  461. static struct scsi_host_template sis_sht = {
  462. ATA_BMDMA_SHT(DRV_NAME),
  463. };
  464. static struct ata_port_operations sis_133_for_sata_ops = {
  465. .inherits = &ata_bmdma_port_ops,
  466. .set_piomode = sis_133_set_piomode,
  467. .set_dmamode = sis_133_set_dmamode,
  468. .cable_detect = sis_133_cable_detect,
  469. };
  470. static struct ata_port_operations sis_base_ops = {
  471. .inherits = &ata_bmdma_port_ops,
  472. .prereset = sis_pre_reset,
  473. };
  474. static struct ata_port_operations sis_133_ops = {
  475. .inherits = &sis_base_ops,
  476. .set_piomode = sis_133_set_piomode,
  477. .set_dmamode = sis_133_set_dmamode,
  478. .cable_detect = sis_133_cable_detect,
  479. .mode_filter = sis_133_mode_filter,
  480. };
  481. static struct ata_port_operations sis_133_early_ops = {
  482. .inherits = &sis_base_ops,
  483. .set_piomode = sis_100_set_piomode,
  484. .set_dmamode = sis_133_early_set_dmamode,
  485. .cable_detect = sis_66_cable_detect,
  486. };
  487. static struct ata_port_operations sis_100_ops = {
  488. .inherits = &sis_base_ops,
  489. .set_piomode = sis_100_set_piomode,
  490. .set_dmamode = sis_100_set_dmamode,
  491. .cable_detect = sis_66_cable_detect,
  492. };
  493. static struct ata_port_operations sis_66_ops = {
  494. .inherits = &sis_base_ops,
  495. .set_piomode = sis_old_set_piomode,
  496. .set_dmamode = sis_66_set_dmamode,
  497. .cable_detect = sis_66_cable_detect,
  498. };
  499. static struct ata_port_operations sis_old_ops = {
  500. .inherits = &sis_base_ops,
  501. .set_piomode = sis_old_set_piomode,
  502. .set_dmamode = sis_old_set_dmamode,
  503. .cable_detect = ata_cable_40wire,
  504. };
  505. static const struct ata_port_info sis_info = {
  506. .flags = ATA_FLAG_SLAVE_POSS,
  507. .pio_mask = ATA_PIO4,
  508. .mwdma_mask = ATA_MWDMA2,
  509. /* No UDMA */
  510. .port_ops = &sis_old_ops,
  511. };
  512. static const struct ata_port_info sis_info33 = {
  513. .flags = ATA_FLAG_SLAVE_POSS,
  514. .pio_mask = ATA_PIO4,
  515. .mwdma_mask = ATA_MWDMA2,
  516. .udma_mask = ATA_UDMA2,
  517. .port_ops = &sis_old_ops,
  518. };
  519. static const struct ata_port_info sis_info66 = {
  520. .flags = ATA_FLAG_SLAVE_POSS,
  521. .pio_mask = ATA_PIO4,
  522. /* No MWDMA */
  523. .udma_mask = ATA_UDMA4,
  524. .port_ops = &sis_66_ops,
  525. };
  526. static const struct ata_port_info sis_info100 = {
  527. .flags = ATA_FLAG_SLAVE_POSS,
  528. .pio_mask = ATA_PIO4,
  529. /* No MWDMA */
  530. .udma_mask = ATA_UDMA5,
  531. .port_ops = &sis_100_ops,
  532. };
  533. static const struct ata_port_info sis_info100_early = {
  534. .flags = ATA_FLAG_SLAVE_POSS,
  535. .pio_mask = ATA_PIO4,
  536. /* No MWDMA */
  537. .udma_mask = ATA_UDMA5,
  538. .port_ops = &sis_66_ops,
  539. };
  540. static const struct ata_port_info sis_info133 = {
  541. .flags = ATA_FLAG_SLAVE_POSS,
  542. .pio_mask = ATA_PIO4,
  543. .mwdma_mask = ATA_MWDMA2,
  544. .udma_mask = ATA_UDMA6,
  545. .port_ops = &sis_133_ops,
  546. };
  547. const struct ata_port_info sis_info133_for_sata = {
  548. .flags = ATA_FLAG_SLAVE_POSS,
  549. .pio_mask = ATA_PIO4,
  550. /* No MWDMA */
  551. .udma_mask = ATA_UDMA6,
  552. .port_ops = &sis_133_for_sata_ops,
  553. };
  554. static const struct ata_port_info sis_info133_early = {
  555. .flags = ATA_FLAG_SLAVE_POSS,
  556. .pio_mask = ATA_PIO4,
  557. /* No MWDMA */
  558. .udma_mask = ATA_UDMA6,
  559. .port_ops = &sis_133_early_ops,
  560. };
  561. /* Privately shared with the SiS180 SATA driver, not for use elsewhere */
  562. EXPORT_SYMBOL_GPL(sis_info133_for_sata);
  563. static void sis_fixup(struct pci_dev *pdev, struct sis_chipset *sis)
  564. {
  565. u16 regw;
  566. u8 reg;
  567. if (sis->info == &sis_info133) {
  568. pci_read_config_word(pdev, 0x50, &regw);
  569. if (regw & 0x08)
  570. pci_write_config_word(pdev, 0x50, regw & ~0x08);
  571. pci_read_config_word(pdev, 0x52, &regw);
  572. if (regw & 0x08)
  573. pci_write_config_word(pdev, 0x52, regw & ~0x08);
  574. return;
  575. }
  576. if (sis->info == &sis_info133_early || sis->info == &sis_info100) {
  577. /* Fix up latency */
  578. pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x80);
  579. /* Set compatibility bit */
  580. pci_read_config_byte(pdev, 0x49, &reg);
  581. if (!(reg & 0x01))
  582. pci_write_config_byte(pdev, 0x49, reg | 0x01);
  583. return;
  584. }
  585. if (sis->info == &sis_info66 || sis->info == &sis_info100_early) {
  586. /* Fix up latency */
  587. pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x80);
  588. /* Set compatibility bit */
  589. pci_read_config_byte(pdev, 0x52, &reg);
  590. if (!(reg & 0x04))
  591. pci_write_config_byte(pdev, 0x52, reg | 0x04);
  592. return;
  593. }
  594. if (sis->info == &sis_info33) {
  595. pci_read_config_byte(pdev, PCI_CLASS_PROG, &reg);
  596. if (( reg & 0x0F ) != 0x00)
  597. pci_write_config_byte(pdev, PCI_CLASS_PROG, reg & 0xF0);
  598. /* Fall through to ATA16 fixup below */
  599. }
  600. if (sis->info == &sis_info || sis->info == &sis_info33) {
  601. /* force per drive recovery and active timings
  602. needed on ATA_33 and below chips */
  603. pci_read_config_byte(pdev, 0x52, &reg);
  604. if (!(reg & 0x08))
  605. pci_write_config_byte(pdev, 0x52, reg|0x08);
  606. return;
  607. }
  608. BUG();
  609. }
  610. /**
  611. * sis_init_one - Register SiS ATA PCI device with kernel services
  612. * @pdev: PCI device to register
  613. * @ent: Entry in sis_pci_tbl matching with @pdev
  614. *
  615. * Called from kernel PCI layer. We probe for combined mode (sigh),
  616. * and then hand over control to libata, for it to do the rest.
  617. *
  618. * LOCKING:
  619. * Inherited from PCI layer (may sleep).
  620. *
  621. * RETURNS:
  622. * Zero on success, or -ERRNO value.
  623. */
  624. static int sis_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
  625. {
  626. const struct ata_port_info *ppi[] = { NULL, NULL };
  627. struct pci_dev *host = NULL;
  628. struct sis_chipset *chipset = NULL;
  629. struct sis_chipset *sets;
  630. int rc;
  631. static struct sis_chipset sis_chipsets[] = {
  632. { 0x0968, &sis_info133 },
  633. { 0x0966, &sis_info133 },
  634. { 0x0965, &sis_info133 },
  635. { 0x0745, &sis_info100 },
  636. { 0x0735, &sis_info100 },
  637. { 0x0733, &sis_info100 },
  638. { 0x0635, &sis_info100 },
  639. { 0x0633, &sis_info100 },
  640. { 0x0730, &sis_info100_early }, /* 100 with ATA 66 layout */
  641. { 0x0550, &sis_info100_early }, /* 100 with ATA 66 layout */
  642. { 0x0640, &sis_info66 },
  643. { 0x0630, &sis_info66 },
  644. { 0x0620, &sis_info66 },
  645. { 0x0540, &sis_info66 },
  646. { 0x0530, &sis_info66 },
  647. { 0x5600, &sis_info33 },
  648. { 0x5598, &sis_info33 },
  649. { 0x5597, &sis_info33 },
  650. { 0x5591, &sis_info33 },
  651. { 0x5582, &sis_info33 },
  652. { 0x5581, &sis_info33 },
  653. { 0x5596, &sis_info },
  654. { 0x5571, &sis_info },
  655. { 0x5517, &sis_info },
  656. { 0x5511, &sis_info },
  657. {0}
  658. };
  659. static struct sis_chipset sis133_early = {
  660. 0x0, &sis_info133_early
  661. };
  662. static struct sis_chipset sis133 = {
  663. 0x0, &sis_info133
  664. };
  665. static struct sis_chipset sis100_early = {
  666. 0x0, &sis_info100_early
  667. };
  668. static struct sis_chipset sis100 = {
  669. 0x0, &sis_info100
  670. };
  671. ata_print_version_once(&pdev->dev, DRV_VERSION);
  672. rc = pcim_enable_device(pdev);
  673. if (rc)
  674. return rc;
  675. /* We have to find the bridge first */
  676. for (sets = &sis_chipsets[0]; sets->device; sets++) {
  677. host = pci_get_device(PCI_VENDOR_ID_SI, sets->device, NULL);
  678. if (host != NULL) {
  679. chipset = sets; /* Match found */
  680. if (sets->device == 0x630) { /* SIS630 */
  681. if (host->revision >= 0x30) /* 630 ET */
  682. chipset = &sis100_early;
  683. }
  684. break;
  685. }
  686. }
  687. /* Look for concealed bridges */
  688. if (chipset == NULL) {
  689. /* Second check */
  690. u32 idemisc;
  691. u16 trueid;
  692. /* Disable ID masking and register remapping then
  693. see what the real ID is */
  694. pci_read_config_dword(pdev, 0x54, &idemisc);
  695. pci_write_config_dword(pdev, 0x54, idemisc & 0x7fffffff);
  696. pci_read_config_word(pdev, PCI_DEVICE_ID, &trueid);
  697. pci_write_config_dword(pdev, 0x54, idemisc);
  698. switch(trueid) {
  699. case 0x5518: /* SIS 962/963 */
  700. dev_info(&pdev->dev,
  701. "SiS 962/963 MuTIOL IDE UDMA133 controller\n");
  702. chipset = &sis133;
  703. if ((idemisc & 0x40000000) == 0) {
  704. pci_write_config_dword(pdev, 0x54, idemisc | 0x40000000);
  705. dev_info(&pdev->dev,
  706. "Switching to 5513 register mapping\n");
  707. }
  708. break;
  709. case 0x0180: /* SIS 965/965L */
  710. chipset = &sis133;
  711. break;
  712. case 0x1180: /* SIS 966/966L */
  713. chipset = &sis133;
  714. break;
  715. }
  716. }
  717. /* Further check */
  718. if (chipset == NULL) {
  719. struct pci_dev *lpc_bridge;
  720. u16 trueid;
  721. u8 prefctl;
  722. u8 idecfg;
  723. /* Try the second unmasking technique */
  724. pci_read_config_byte(pdev, 0x4a, &idecfg);
  725. pci_write_config_byte(pdev, 0x4a, idecfg | 0x10);
  726. pci_read_config_word(pdev, PCI_DEVICE_ID, &trueid);
  727. pci_write_config_byte(pdev, 0x4a, idecfg);
  728. switch(trueid) {
  729. case 0x5517:
  730. lpc_bridge = pci_get_slot(pdev->bus, 0x10); /* Bus 0 Dev 2 Fn 0 */
  731. if (lpc_bridge == NULL)
  732. break;
  733. pci_read_config_byte(pdev, 0x49, &prefctl);
  734. pci_dev_put(lpc_bridge);
  735. if (lpc_bridge->revision == 0x10 && (prefctl & 0x80)) {
  736. chipset = &sis133_early;
  737. break;
  738. }
  739. chipset = &sis100;
  740. break;
  741. }
  742. }
  743. pci_dev_put(host);
  744. /* No chipset info, no support */
  745. if (chipset == NULL)
  746. return -ENODEV;
  747. ppi[0] = chipset->info;
  748. sis_fixup(pdev, chipset);
  749. return ata_pci_bmdma_init_one(pdev, ppi, &sis_sht, chipset, 0);
  750. }
  751. #ifdef CONFIG_PM_SLEEP
  752. static int sis_reinit_one(struct pci_dev *pdev)
  753. {
  754. struct ata_host *host = pci_get_drvdata(pdev);
  755. int rc;
  756. rc = ata_pci_device_do_resume(pdev);
  757. if (rc)
  758. return rc;
  759. sis_fixup(pdev, host->private_data);
  760. ata_host_resume(host);
  761. return 0;
  762. }
  763. #endif
  764. static const struct pci_device_id sis_pci_tbl[] = {
  765. { PCI_VDEVICE(SI, 0x5513), }, /* SiS 5513 */
  766. { PCI_VDEVICE(SI, 0x5518), }, /* SiS 5518 */
  767. { PCI_VDEVICE(SI, 0x1180), }, /* SiS 1180 */
  768. { }
  769. };
  770. static struct pci_driver sis_pci_driver = {
  771. .name = DRV_NAME,
  772. .id_table = sis_pci_tbl,
  773. .probe = sis_init_one,
  774. .remove = ata_pci_remove_one,
  775. #ifdef CONFIG_PM_SLEEP
  776. .suspend = ata_pci_device_suspend,
  777. .resume = sis_reinit_one,
  778. #endif
  779. };
  780. module_pci_driver(sis_pci_driver);
  781. MODULE_AUTHOR("Alan Cox");
  782. MODULE_DESCRIPTION("SCSI low-level driver for SiS ATA");
  783. MODULE_LICENSE("GPL");
  784. MODULE_DEVICE_TABLE(pci, sis_pci_tbl);
  785. MODULE_VERSION(DRV_VERSION);