pata_sis.c 23 KB

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