pata_sis.c 27 KB

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