pata_sis.c 28 KB

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