pata_sis.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865
  1. /*
  2. * pata_sis.c - SiS ATA driver
  3. *
  4. * (C) 2005 Red Hat
  5. * (C) 2007 Bartlomiej Zolnierkiewicz
  6. *
  7. * Based upon linux/drivers/ide/pci/sis5513.c
  8. * Copyright (C) 1999-2000 Andre Hedrick <andre@linux-ide.org>
  9. * Copyright (C) 2002 Lionel Bouton <Lionel.Bouton@inet6.fr>, Maintainer
  10. * Copyright (C) 2003 Vojtech Pavlik <vojtech@suse.cz>
  11. * SiS Taiwan : for direct support and hardware.
  12. * Daniela Engert : for initial ATA100 advices and numerous others.
  13. * John Fremlin, Manfred Spraul, Dave Morgan, Peter Kjellerstedt :
  14. * for checking code correctness, providing patches.
  15. * Original tests and design on the SiS620 chipset.
  16. * ATA100 tests and design on the SiS735 chipset.
  17. * ATA16/33 support from specs
  18. * ATA133 support for SiS961/962 by L.C. Chang <lcchang@sis.com.tw>
  19. *
  20. *
  21. * TODO
  22. * Check MWDMA on drives that don't support MWDMA speed pio cycles ?
  23. * More Testing
  24. */
  25. #include <linux/kernel.h>
  26. #include <linux/module.h>
  27. #include <linux/pci.h>
  28. #include <linux/init.h>
  29. #include <linux/blkdev.h>
  30. #include <linux/delay.h>
  31. #include <linux/device.h>
  32. #include <scsi/scsi_host.h>
  33. #include <linux/libata.h>
  34. #include <linux/ata.h>
  35. #include "sis.h"
  36. #define DRV_NAME "pata_sis"
  37. #define DRV_VERSION "0.5.2"
  38. struct sis_chipset {
  39. u16 device; /* PCI host ID */
  40. const struct ata_port_info *info; /* Info block */
  41. /* Probably add family, cable detect type etc here to clean
  42. up code later */
  43. };
  44. struct sis_laptop {
  45. u16 device;
  46. u16 subvendor;
  47. u16 subdevice;
  48. };
  49. static const struct sis_laptop sis_laptop[] = {
  50. /* devid, subvendor, subdev */
  51. { 0x5513, 0x1043, 0x1107 }, /* ASUS A6K */
  52. { 0x5513, 0x1734, 0x105F }, /* FSC Amilo A1630 */
  53. { 0x5513, 0x1071, 0x8640 }, /* EasyNote K5305 */
  54. { 0x5513, 0x1039, 0x5513 }, /* Targa Visionary 1000 */
  55. /* end marker */
  56. { 0, }
  57. };
  58. static int sis_short_ata40(struct pci_dev *dev)
  59. {
  60. const struct sis_laptop *lap = &sis_laptop[0];
  61. while (lap->device) {
  62. if (lap->device == dev->device &&
  63. lap->subvendor == dev->subsystem_vendor &&
  64. lap->subdevice == dev->subsystem_device)
  65. return 1;
  66. lap++;
  67. }
  68. return 0;
  69. }
  70. /**
  71. * sis_old_port_base - return PCI configuration base for dev
  72. * @adev: device
  73. *
  74. * Returns the base of the PCI configuration registers for this port
  75. * number.
  76. */
  77. static int sis_old_port_base(struct ata_device *adev)
  78. {
  79. return 0x40 + (4 * adev->link->ap->port_no) + (2 * adev->devno);
  80. }
  81. /**
  82. * sis_133_cable_detect - check for 40/80 pin
  83. * @ap: Port
  84. * @deadline: deadline jiffies for the operation
  85. *
  86. * Perform cable detection for the later UDMA133 capable
  87. * SiS chipset.
  88. */
  89. static int sis_133_cable_detect(struct ata_port *ap)
  90. {
  91. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  92. u16 tmp;
  93. /* The top bit of this register is the cable detect bit */
  94. pci_read_config_word(pdev, 0x50 + 2 * ap->port_no, &tmp);
  95. if ((tmp & 0x8000) && !sis_short_ata40(pdev))
  96. return ATA_CBL_PATA40;
  97. return ATA_CBL_PATA80;
  98. }
  99. /**
  100. * sis_66_cable_detect - check for 40/80 pin
  101. * @ap: Port
  102. * @deadline: deadline jiffies for the operation
  103. *
  104. * Perform cable detection on the UDMA66, UDMA100 and early UDMA133
  105. * SiS IDE controllers.
  106. */
  107. static int sis_66_cable_detect(struct ata_port *ap)
  108. {
  109. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  110. u8 tmp;
  111. /* Older chips keep cable detect in bits 4/5 of reg 0x48 */
  112. pci_read_config_byte(pdev, 0x48, &tmp);
  113. tmp >>= ap->port_no;
  114. if ((tmp & 0x10) && !sis_short_ata40(pdev))
  115. return ATA_CBL_PATA40;
  116. return ATA_CBL_PATA80;
  117. }
  118. /**
  119. * sis_pre_reset - probe begin
  120. * @link: ATA link
  121. * @deadline: deadline jiffies for the operation
  122. *
  123. * Set up cable type and use generic probe init
  124. */
  125. static int sis_pre_reset(struct ata_link *link, unsigned long deadline)
  126. {
  127. static const struct pci_bits sis_enable_bits[] = {
  128. { 0x4aU, 1U, 0x02UL, 0x02UL }, /* port 0 */
  129. { 0x4aU, 1U, 0x04UL, 0x04UL }, /* port 1 */
  130. };
  131. struct ata_port *ap = link->ap;
  132. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  133. if (!pci_test_config_bits(pdev, &sis_enable_bits[ap->port_no]))
  134. return -ENOENT;
  135. /* Clear the FIFO settings. We can't enable the FIFO until
  136. we know we are poking at a disk */
  137. pci_write_config_byte(pdev, 0x4B, 0);
  138. return ata_sff_prereset(link, deadline);
  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_old_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_piomode - 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_old_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_piomode - 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_old_port_base(adev);
  277. u16 timing;
  278. const u16 mwdma_bits[] = { 0x008, 0x302, 0x301 };
  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 higher bits are dependant on the device */
  284. timing &= ~0x870F;
  285. timing |= mwdma_bits[speed];
  286. } else {
  287. /* Bit 15 is UDMA on/off, bit 13-14 are cycle time */
  288. speed = adev->dma_mode - XFER_UDMA_0;
  289. timing &= ~0x6000;
  290. timing |= udma_bits[speed];
  291. }
  292. pci_write_config_word(pdev, drive_pci, timing);
  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_old_port_base(adev);
  311. u16 timing;
  312. /* MWDMA 0-2 and UDMA 0-5 */
  313. const u16 mwdma_bits[] = { 0x008, 0x302, 0x301 };
  314. const u16 udma_bits[] = { 0xF000, 0xD000, 0xB000, 0xA000, 0x9000, 0x8000 };
  315. pci_read_config_word(pdev, drive_pci, &timing);
  316. if (adev->dma_mode < XFER_UDMA_0) {
  317. /* bits 3-0 hold recovery timing bits 8-10 active timing and
  318. the higher bits are dependant on the device, bit 15 udma */
  319. timing &= ~0x870F;
  320. timing |= mwdma_bits[speed];
  321. } else {
  322. /* Bit 15 is UDMA on/off, bit 12-14 are cycle time */
  323. speed = adev->dma_mode - XFER_UDMA_0;
  324. timing &= ~0xF000;
  325. timing |= udma_bits[speed];
  326. }
  327. pci_write_config_word(pdev, drive_pci, timing);
  328. }
  329. /**
  330. * sis_100_set_dmamode - Initialize host controller PATA DMA timings
  331. * @ap: Port whose timings we are configuring
  332. * @adev: Device to program
  333. *
  334. * Set UDMA/MWDMA mode for device, in host controller PCI config space.
  335. * Handles UDMA66 and early UDMA100 devices.
  336. *
  337. * LOCKING:
  338. * None (inherited from caller).
  339. */
  340. static void sis_100_set_dmamode (struct ata_port *ap, struct ata_device *adev)
  341. {
  342. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  343. int speed = adev->dma_mode - XFER_MW_DMA_0;
  344. int drive_pci = sis_old_port_base(adev);
  345. u8 timing;
  346. const u8 udma_bits[] = { 0x8B, 0x87, 0x85, 0x83, 0x82, 0x81};
  347. pci_read_config_byte(pdev, drive_pci + 1, &timing);
  348. if (adev->dma_mode < XFER_UDMA_0) {
  349. /* NOT SUPPORTED YET: NEED DATA SHEET. DITTO IN OLD DRIVER */
  350. } else {
  351. /* Bit 7 is UDMA on/off, bit 0-3 are cycle time */
  352. speed = adev->dma_mode - XFER_UDMA_0;
  353. timing &= ~0x8F;
  354. timing |= udma_bits[speed];
  355. }
  356. pci_write_config_byte(pdev, drive_pci + 1, timing);
  357. }
  358. /**
  359. * sis_133_early_set_dmamode - Initialize host controller PATA DMA timings
  360. * @ap: Port whose timings we are configuring
  361. * @adev: Device to program
  362. *
  363. * Set UDMA/MWDMA mode for device, in host controller PCI config space.
  364. * Handles early SiS 961 bridges.
  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_old_port_base(adev);
  374. u8 timing;
  375. /* Low 4 bits are timing */
  376. static const u8 udma_bits[] = { 0x8F, 0x8A, 0x87, 0x85, 0x83, 0x82, 0x81};
  377. pci_read_config_byte(pdev, drive_pci + 1, &timing);
  378. if (adev->dma_mode < XFER_UDMA_0) {
  379. /* NOT SUPPORTED YET: NEED DATA SHEET. DITTO IN OLD DRIVER */
  380. } else {
  381. /* Bit 7 is UDMA on/off, bit 0-3 are cycle time */
  382. speed = adev->dma_mode - XFER_UDMA_0;
  383. timing &= ~0x8F;
  384. timing |= udma_bits[speed];
  385. }
  386. pci_write_config_byte(pdev, drive_pci + 1, timing);
  387. }
  388. /**
  389. * sis_133_set_dmamode - Initialize host controller PATA DMA timings
  390. * @ap: Port whose timings we are configuring
  391. * @adev: Device to program
  392. *
  393. * Set UDMA/MWDMA mode for device, in host controller PCI config space.
  394. *
  395. * LOCKING:
  396. * None (inherited from caller).
  397. */
  398. static void sis_133_set_dmamode (struct ata_port *ap, struct ata_device *adev)
  399. {
  400. struct pci_dev *pdev = to_pci_dev(ap->host->dev);
  401. int speed = adev->dma_mode - XFER_MW_DMA_0;
  402. int port = 0x40;
  403. u32 t1;
  404. u32 reg54;
  405. /* bits 4- cycle time 8 - cvs time */
  406. static const u32 timing_u100[] = { 0x6B0, 0x470, 0x350, 0x140, 0x120, 0x110, 0x000 };
  407. static const u32 timing_u133[] = { 0x9F0, 0x6A0, 0x470, 0x250, 0x230, 0x220, 0x210 };
  408. /* If bit 14 is set then the registers are mapped at 0x70 not 0x40 */
  409. pci_read_config_dword(pdev, 0x54, &reg54);
  410. if (reg54 & 0x40000000)
  411. port = 0x70;
  412. port += (8 * ap->port_no) + (4 * adev->devno);
  413. pci_read_config_dword(pdev, port, &t1);
  414. if (adev->dma_mode < XFER_UDMA_0) {
  415. t1 &= ~0x00000004;
  416. /* FIXME: need data sheet to add MWDMA here. Also lacking on
  417. ide/pci driver */
  418. } else {
  419. speed = adev->dma_mode - XFER_UDMA_0;
  420. /* if & 8 no UDMA133 - need info for ... */
  421. t1 &= ~0x00000FF0;
  422. t1 |= 0x00000004;
  423. if (t1 & 0x08)
  424. t1 |= timing_u133[speed];
  425. else
  426. t1 |= timing_u100[speed];
  427. }
  428. pci_write_config_dword(pdev, port, t1);
  429. }
  430. static struct scsi_host_template sis_sht = {
  431. ATA_BMDMA_SHT(DRV_NAME),
  432. };
  433. static struct ata_port_operations sis_133_for_sata_ops = {
  434. .inherits = &ata_bmdma_port_ops,
  435. .set_piomode = sis_133_set_piomode,
  436. .set_dmamode = sis_133_set_dmamode,
  437. .cable_detect = sis_133_cable_detect,
  438. };
  439. static struct ata_port_operations sis_base_ops = {
  440. .inherits = &ata_bmdma_port_ops,
  441. .prereset = sis_pre_reset,
  442. };
  443. static struct ata_port_operations sis_133_ops = {
  444. .inherits = &sis_base_ops,
  445. .set_piomode = sis_133_set_piomode,
  446. .set_dmamode = sis_133_set_dmamode,
  447. .cable_detect = sis_133_cable_detect,
  448. };
  449. static struct ata_port_operations sis_133_early_ops = {
  450. .inherits = &sis_base_ops,
  451. .set_piomode = sis_100_set_piomode,
  452. .set_dmamode = sis_133_early_set_dmamode,
  453. .cable_detect = sis_66_cable_detect,
  454. };
  455. static struct ata_port_operations sis_100_ops = {
  456. .inherits = &sis_base_ops,
  457. .set_piomode = sis_100_set_piomode,
  458. .set_dmamode = sis_100_set_dmamode,
  459. .cable_detect = sis_66_cable_detect,
  460. };
  461. static struct ata_port_operations sis_66_ops = {
  462. .inherits = &sis_base_ops,
  463. .set_piomode = sis_old_set_piomode,
  464. .set_dmamode = sis_66_set_dmamode,
  465. .cable_detect = sis_66_cable_detect,
  466. };
  467. static struct ata_port_operations sis_old_ops = {
  468. .inherits = &sis_base_ops,
  469. .set_piomode = sis_old_set_piomode,
  470. .set_dmamode = sis_old_set_dmamode,
  471. .cable_detect = ata_cable_40wire,
  472. };
  473. static const struct ata_port_info sis_info = {
  474. .flags = ATA_FLAG_SLAVE_POSS,
  475. .pio_mask = 0x1f, /* pio0-4 */
  476. .mwdma_mask = 0x07,
  477. .udma_mask = 0,
  478. .port_ops = &sis_old_ops,
  479. };
  480. static const struct ata_port_info sis_info33 = {
  481. .flags = ATA_FLAG_SLAVE_POSS,
  482. .pio_mask = 0x1f, /* pio0-4 */
  483. .mwdma_mask = 0x07,
  484. .udma_mask = ATA_UDMA2, /* UDMA 33 */
  485. .port_ops = &sis_old_ops,
  486. };
  487. static const struct ata_port_info sis_info66 = {
  488. .flags = ATA_FLAG_SLAVE_POSS,
  489. .pio_mask = 0x1f, /* pio0-4 */
  490. .udma_mask = ATA_UDMA4, /* UDMA 66 */
  491. .port_ops = &sis_66_ops,
  492. };
  493. static const struct ata_port_info sis_info100 = {
  494. .flags = ATA_FLAG_SLAVE_POSS,
  495. .pio_mask = 0x1f, /* pio0-4 */
  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. .udma_mask = ATA_UDMA5,
  502. .pio_mask = 0x1f, /* pio0-4 */
  503. .port_ops = &sis_66_ops,
  504. };
  505. static const struct ata_port_info sis_info133 = {
  506. .flags = ATA_FLAG_SLAVE_POSS,
  507. .pio_mask = 0x1f, /* pio0-4 */
  508. .udma_mask = ATA_UDMA6,
  509. .port_ops = &sis_133_ops,
  510. };
  511. const struct ata_port_info sis_info133_for_sata = {
  512. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  513. .pio_mask = 0x1f, /* pio0-4 */
  514. .udma_mask = ATA_UDMA6,
  515. .port_ops = &sis_133_for_sata_ops,
  516. };
  517. static const struct ata_port_info sis_info133_early = {
  518. .flags = ATA_FLAG_SLAVE_POSS,
  519. .pio_mask = 0x1f, /* pio0-4 */
  520. .udma_mask = ATA_UDMA6,
  521. .port_ops = &sis_133_early_ops,
  522. };
  523. /* Privately shared with the SiS180 SATA driver, not for use elsewhere */
  524. EXPORT_SYMBOL_GPL(sis_info133_for_sata);
  525. static void sis_fixup(struct pci_dev *pdev, struct sis_chipset *sis)
  526. {
  527. u16 regw;
  528. u8 reg;
  529. if (sis->info == &sis_info133) {
  530. pci_read_config_word(pdev, 0x50, &regw);
  531. if (regw & 0x08)
  532. pci_write_config_word(pdev, 0x50, regw & ~0x08);
  533. pci_read_config_word(pdev, 0x52, &regw);
  534. if (regw & 0x08)
  535. pci_write_config_word(pdev, 0x52, regw & ~0x08);
  536. return;
  537. }
  538. if (sis->info == &sis_info133_early || sis->info == &sis_info100) {
  539. /* Fix up latency */
  540. pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x80);
  541. /* Set compatibility bit */
  542. pci_read_config_byte(pdev, 0x49, &reg);
  543. if (!(reg & 0x01))
  544. pci_write_config_byte(pdev, 0x49, reg | 0x01);
  545. return;
  546. }
  547. if (sis->info == &sis_info66 || sis->info == &sis_info100_early) {
  548. /* Fix up latency */
  549. pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x80);
  550. /* Set compatibility bit */
  551. pci_read_config_byte(pdev, 0x52, &reg);
  552. if (!(reg & 0x04))
  553. pci_write_config_byte(pdev, 0x52, reg | 0x04);
  554. return;
  555. }
  556. if (sis->info == &sis_info33) {
  557. pci_read_config_byte(pdev, PCI_CLASS_PROG, &reg);
  558. if (( reg & 0x0F ) != 0x00)
  559. pci_write_config_byte(pdev, PCI_CLASS_PROG, reg & 0xF0);
  560. /* Fall through to ATA16 fixup below */
  561. }
  562. if (sis->info == &sis_info || sis->info == &sis_info33) {
  563. /* force per drive recovery and active timings
  564. needed on ATA_33 and below chips */
  565. pci_read_config_byte(pdev, 0x52, &reg);
  566. if (!(reg & 0x08))
  567. pci_write_config_byte(pdev, 0x52, reg|0x08);
  568. return;
  569. }
  570. BUG();
  571. }
  572. /**
  573. * sis_init_one - Register SiS ATA PCI device with kernel services
  574. * @pdev: PCI device to register
  575. * @ent: Entry in sis_pci_tbl matching with @pdev
  576. *
  577. * Called from kernel PCI layer. We probe for combined mode (sigh),
  578. * and then hand over control to libata, for it to do the rest.
  579. *
  580. * LOCKING:
  581. * Inherited from PCI layer (may sleep).
  582. *
  583. * RETURNS:
  584. * Zero on success, or -ERRNO value.
  585. */
  586. static int sis_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
  587. {
  588. static int printed_version;
  589. const struct ata_port_info *ppi[] = { NULL, NULL };
  590. struct pci_dev *host = NULL;
  591. struct sis_chipset *chipset = NULL;
  592. struct sis_chipset *sets;
  593. int rc;
  594. static struct sis_chipset sis_chipsets[] = {
  595. { 0x0968, &sis_info133 },
  596. { 0x0966, &sis_info133 },
  597. { 0x0965, &sis_info133 },
  598. { 0x0745, &sis_info100 },
  599. { 0x0735, &sis_info100 },
  600. { 0x0733, &sis_info100 },
  601. { 0x0635, &sis_info100 },
  602. { 0x0633, &sis_info100 },
  603. { 0x0730, &sis_info100_early }, /* 100 with ATA 66 layout */
  604. { 0x0550, &sis_info100_early }, /* 100 with ATA 66 layout */
  605. { 0x0640, &sis_info66 },
  606. { 0x0630, &sis_info66 },
  607. { 0x0620, &sis_info66 },
  608. { 0x0540, &sis_info66 },
  609. { 0x0530, &sis_info66 },
  610. { 0x5600, &sis_info33 },
  611. { 0x5598, &sis_info33 },
  612. { 0x5597, &sis_info33 },
  613. { 0x5591, &sis_info33 },
  614. { 0x5582, &sis_info33 },
  615. { 0x5581, &sis_info33 },
  616. { 0x5596, &sis_info },
  617. { 0x5571, &sis_info },
  618. { 0x5517, &sis_info },
  619. { 0x5511, &sis_info },
  620. {0}
  621. };
  622. static struct sis_chipset sis133_early = {
  623. 0x0, &sis_info133_early
  624. };
  625. static struct sis_chipset sis133 = {
  626. 0x0, &sis_info133
  627. };
  628. static struct sis_chipset sis100_early = {
  629. 0x0, &sis_info100_early
  630. };
  631. static struct sis_chipset sis100 = {
  632. 0x0, &sis_info100
  633. };
  634. if (!printed_version++)
  635. dev_printk(KERN_DEBUG, &pdev->dev,
  636. "version " DRV_VERSION "\n");
  637. rc = pcim_enable_device(pdev);
  638. if (rc)
  639. return rc;
  640. /* We have to find the bridge first */
  641. for (sets = &sis_chipsets[0]; sets->device; sets++) {
  642. host = pci_get_device(PCI_VENDOR_ID_SI, sets->device, NULL);
  643. if (host != NULL) {
  644. chipset = sets; /* Match found */
  645. if (sets->device == 0x630) { /* SIS630 */
  646. if (host->revision >= 0x30) /* 630 ET */
  647. chipset = &sis100_early;
  648. }
  649. break;
  650. }
  651. }
  652. /* Look for concealed bridges */
  653. if (chipset == NULL) {
  654. /* Second check */
  655. u32 idemisc;
  656. u16 trueid;
  657. /* Disable ID masking and register remapping then
  658. see what the real ID is */
  659. pci_read_config_dword(pdev, 0x54, &idemisc);
  660. pci_write_config_dword(pdev, 0x54, idemisc & 0x7fffffff);
  661. pci_read_config_word(pdev, PCI_DEVICE_ID, &trueid);
  662. pci_write_config_dword(pdev, 0x54, idemisc);
  663. switch(trueid) {
  664. case 0x5518: /* SIS 962/963 */
  665. chipset = &sis133;
  666. if ((idemisc & 0x40000000) == 0) {
  667. pci_write_config_dword(pdev, 0x54, idemisc | 0x40000000);
  668. printk(KERN_INFO "SIS5513: Switching to 5513 register mapping\n");
  669. }
  670. break;
  671. case 0x0180: /* SIS 965/965L */
  672. chipset = &sis133;
  673. break;
  674. case 0x1180: /* SIS 966/966L */
  675. chipset = &sis133;
  676. break;
  677. }
  678. }
  679. /* Further check */
  680. if (chipset == NULL) {
  681. struct pci_dev *lpc_bridge;
  682. u16 trueid;
  683. u8 prefctl;
  684. u8 idecfg;
  685. /* Try the second unmasking technique */
  686. pci_read_config_byte(pdev, 0x4a, &idecfg);
  687. pci_write_config_byte(pdev, 0x4a, idecfg | 0x10);
  688. pci_read_config_word(pdev, PCI_DEVICE_ID, &trueid);
  689. pci_write_config_byte(pdev, 0x4a, idecfg);
  690. switch(trueid) {
  691. case 0x5517:
  692. lpc_bridge = pci_get_slot(pdev->bus, 0x10); /* Bus 0 Dev 2 Fn 0 */
  693. if (lpc_bridge == NULL)
  694. break;
  695. pci_read_config_byte(pdev, 0x49, &prefctl);
  696. pci_dev_put(lpc_bridge);
  697. if (lpc_bridge->revision == 0x10 && (prefctl & 0x80)) {
  698. chipset = &sis133_early;
  699. break;
  700. }
  701. chipset = &sis100;
  702. break;
  703. }
  704. }
  705. pci_dev_put(host);
  706. /* No chipset info, no support */
  707. if (chipset == NULL)
  708. return -ENODEV;
  709. ppi[0] = chipset->info;
  710. sis_fixup(pdev, chipset);
  711. return ata_pci_sff_init_one(pdev, ppi, &sis_sht, chipset);
  712. }
  713. static const struct pci_device_id sis_pci_tbl[] = {
  714. { PCI_VDEVICE(SI, 0x5513), }, /* SiS 5513 */
  715. { PCI_VDEVICE(SI, 0x5518), }, /* SiS 5518 */
  716. { PCI_VDEVICE(SI, 0x1180), }, /* SiS 1180 */
  717. { }
  718. };
  719. static struct pci_driver sis_pci_driver = {
  720. .name = DRV_NAME,
  721. .id_table = sis_pci_tbl,
  722. .probe = sis_init_one,
  723. .remove = ata_pci_remove_one,
  724. #ifdef CONFIG_PM
  725. .suspend = ata_pci_device_suspend,
  726. .resume = ata_pci_device_resume,
  727. #endif
  728. };
  729. static int __init sis_init(void)
  730. {
  731. return pci_register_driver(&sis_pci_driver);
  732. }
  733. static void __exit sis_exit(void)
  734. {
  735. pci_unregister_driver(&sis_pci_driver);
  736. }
  737. module_init(sis_init);
  738. module_exit(sis_exit);
  739. MODULE_AUTHOR("Alan Cox");
  740. MODULE_DESCRIPTION("SCSI low-level driver for SiS ATA");
  741. MODULE_LICENSE("GPL");
  742. MODULE_DEVICE_TABLE(pci, sis_pci_tbl);
  743. MODULE_VERSION(DRV_VERSION);