pata_sis.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023
  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.4"
  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. .max_sectors = ATA_MAX_SECTORS,
  462. .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
  463. .emulated = ATA_SHT_EMULATED,
  464. .use_clustering = ATA_SHT_USE_CLUSTERING,
  465. .proc_name = DRV_NAME,
  466. .dma_boundary = ATA_DMA_BOUNDARY,
  467. .slave_configure = ata_scsi_slave_config,
  468. .slave_destroy = ata_scsi_slave_destroy,
  469. .bios_param = ata_std_bios_param,
  470. };
  471. static const struct ata_port_operations sis_133_ops = {
  472. .port_disable = ata_port_disable,
  473. .set_piomode = sis_133_set_piomode,
  474. .set_dmamode = sis_133_set_dmamode,
  475. .mode_filter = ata_pci_default_filter,
  476. .tf_load = ata_tf_load,
  477. .tf_read = ata_tf_read,
  478. .check_status = ata_check_status,
  479. .exec_command = ata_exec_command,
  480. .dev_select = ata_std_dev_select,
  481. .freeze = ata_bmdma_freeze,
  482. .thaw = ata_bmdma_thaw,
  483. .error_handler = sis_133_error_handler,
  484. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  485. .bmdma_setup = ata_bmdma_setup,
  486. .bmdma_start = ata_bmdma_start,
  487. .bmdma_stop = ata_bmdma_stop,
  488. .bmdma_status = ata_bmdma_status,
  489. .qc_prep = ata_qc_prep,
  490. .qc_issue = ata_qc_issue_prot,
  491. .data_xfer = ata_pio_data_xfer,
  492. .irq_handler = ata_interrupt,
  493. .irq_clear = ata_bmdma_irq_clear,
  494. .port_start = ata_port_start,
  495. .port_stop = ata_port_stop,
  496. .host_stop = ata_host_stop,
  497. };
  498. static const struct ata_port_operations sis_133_early_ops = {
  499. .port_disable = ata_port_disable,
  500. .set_piomode = sis_100_set_piomode,
  501. .set_dmamode = sis_133_early_set_dmamode,
  502. .mode_filter = ata_pci_default_filter,
  503. .tf_load = ata_tf_load,
  504. .tf_read = ata_tf_read,
  505. .check_status = ata_check_status,
  506. .exec_command = ata_exec_command,
  507. .dev_select = ata_std_dev_select,
  508. .freeze = ata_bmdma_freeze,
  509. .thaw = ata_bmdma_thaw,
  510. .error_handler = sis_66_error_handler,
  511. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  512. .bmdma_setup = ata_bmdma_setup,
  513. .bmdma_start = ata_bmdma_start,
  514. .bmdma_stop = ata_bmdma_stop,
  515. .bmdma_status = ata_bmdma_status,
  516. .qc_prep = ata_qc_prep,
  517. .qc_issue = ata_qc_issue_prot,
  518. .data_xfer = ata_pio_data_xfer,
  519. .irq_handler = ata_interrupt,
  520. .irq_clear = ata_bmdma_irq_clear,
  521. .port_start = ata_port_start,
  522. .port_stop = ata_port_stop,
  523. .host_stop = ata_host_stop,
  524. };
  525. static const struct ata_port_operations sis_100_ops = {
  526. .port_disable = ata_port_disable,
  527. .set_piomode = sis_100_set_piomode,
  528. .set_dmamode = sis_100_set_dmamode,
  529. .mode_filter = ata_pci_default_filter,
  530. .tf_load = ata_tf_load,
  531. .tf_read = ata_tf_read,
  532. .check_status = ata_check_status,
  533. .exec_command = ata_exec_command,
  534. .dev_select = ata_std_dev_select,
  535. .freeze = ata_bmdma_freeze,
  536. .thaw = ata_bmdma_thaw,
  537. .error_handler = sis_66_error_handler,
  538. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  539. .bmdma_setup = ata_bmdma_setup,
  540. .bmdma_start = ata_bmdma_start,
  541. .bmdma_stop = ata_bmdma_stop,
  542. .bmdma_status = ata_bmdma_status,
  543. .qc_prep = ata_qc_prep,
  544. .qc_issue = ata_qc_issue_prot,
  545. .data_xfer = ata_pio_data_xfer,
  546. .irq_handler = ata_interrupt,
  547. .irq_clear = ata_bmdma_irq_clear,
  548. .port_start = ata_port_start,
  549. .port_stop = ata_port_stop,
  550. .host_stop = ata_host_stop,
  551. };
  552. static const struct ata_port_operations sis_66_ops = {
  553. .port_disable = ata_port_disable,
  554. .set_piomode = sis_old_set_piomode,
  555. .set_dmamode = sis_66_set_dmamode,
  556. .mode_filter = ata_pci_default_filter,
  557. .tf_load = ata_tf_load,
  558. .tf_read = ata_tf_read,
  559. .check_status = ata_check_status,
  560. .exec_command = ata_exec_command,
  561. .dev_select = ata_std_dev_select,
  562. .freeze = ata_bmdma_freeze,
  563. .thaw = ata_bmdma_thaw,
  564. .error_handler = sis_66_error_handler,
  565. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  566. .bmdma_setup = ata_bmdma_setup,
  567. .bmdma_start = ata_bmdma_start,
  568. .bmdma_stop = ata_bmdma_stop,
  569. .bmdma_status = ata_bmdma_status,
  570. .qc_prep = ata_qc_prep,
  571. .qc_issue = ata_qc_issue_prot,
  572. .data_xfer = ata_pio_data_xfer,
  573. .irq_handler = ata_interrupt,
  574. .irq_clear = ata_bmdma_irq_clear,
  575. .port_start = ata_port_start,
  576. .port_stop = ata_port_stop,
  577. .host_stop = ata_host_stop,
  578. };
  579. static const struct ata_port_operations sis_old_ops = {
  580. .port_disable = ata_port_disable,
  581. .set_piomode = sis_old_set_piomode,
  582. .set_dmamode = sis_old_set_dmamode,
  583. .mode_filter = ata_pci_default_filter,
  584. .tf_load = ata_tf_load,
  585. .tf_read = ata_tf_read,
  586. .check_status = ata_check_status,
  587. .exec_command = ata_exec_command,
  588. .dev_select = ata_std_dev_select,
  589. .freeze = ata_bmdma_freeze,
  590. .thaw = ata_bmdma_thaw,
  591. .error_handler = sis_old_error_handler,
  592. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  593. .bmdma_setup = ata_bmdma_setup,
  594. .bmdma_start = ata_bmdma_start,
  595. .bmdma_stop = ata_bmdma_stop,
  596. .bmdma_status = ata_bmdma_status,
  597. .qc_prep = ata_qc_prep,
  598. .qc_issue = ata_qc_issue_prot,
  599. .data_xfer = ata_pio_data_xfer,
  600. .irq_handler = ata_interrupt,
  601. .irq_clear = ata_bmdma_irq_clear,
  602. .port_start = ata_port_start,
  603. .port_stop = ata_port_stop,
  604. .host_stop = ata_host_stop,
  605. };
  606. static struct ata_port_info sis_info = {
  607. .sht = &sis_sht,
  608. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  609. .pio_mask = 0x1f, /* pio0-4 */
  610. .mwdma_mask = 0x07,
  611. .udma_mask = 0,
  612. .port_ops = &sis_old_ops,
  613. };
  614. static struct ata_port_info sis_info33 = {
  615. .sht = &sis_sht,
  616. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  617. .pio_mask = 0x1f, /* pio0-4 */
  618. .mwdma_mask = 0x07,
  619. .udma_mask = ATA_UDMA2, /* UDMA 33 */
  620. .port_ops = &sis_old_ops,
  621. };
  622. static struct ata_port_info sis_info66 = {
  623. .sht = &sis_sht,
  624. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  625. .pio_mask = 0x1f, /* pio0-4 */
  626. .udma_mask = ATA_UDMA4, /* UDMA 66 */
  627. .port_ops = &sis_66_ops,
  628. };
  629. static struct ata_port_info sis_info100 = {
  630. .sht = &sis_sht,
  631. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  632. .pio_mask = 0x1f, /* pio0-4 */
  633. .udma_mask = ATA_UDMA5,
  634. .port_ops = &sis_100_ops,
  635. };
  636. static struct ata_port_info sis_info100_early = {
  637. .sht = &sis_sht,
  638. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  639. .udma_mask = ATA_UDMA5,
  640. .pio_mask = 0x1f, /* pio0-4 */
  641. .port_ops = &sis_66_ops,
  642. };
  643. static struct ata_port_info sis_info133 = {
  644. .sht = &sis_sht,
  645. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  646. .pio_mask = 0x1f, /* pio0-4 */
  647. .udma_mask = ATA_UDMA6,
  648. .port_ops = &sis_133_ops,
  649. };
  650. static struct ata_port_info sis_info133_early = {
  651. .sht = &sis_sht,
  652. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  653. .pio_mask = 0x1f, /* pio0-4 */
  654. .udma_mask = ATA_UDMA6,
  655. .port_ops = &sis_133_early_ops,
  656. };
  657. static void sis_fixup(struct pci_dev *pdev, struct sis_chipset *sis)
  658. {
  659. u16 regw;
  660. u8 reg;
  661. if (sis->info == &sis_info133) {
  662. pci_read_config_word(pdev, 0x50, &regw);
  663. if (regw & 0x08)
  664. pci_write_config_word(pdev, 0x50, regw & ~0x08);
  665. pci_read_config_word(pdev, 0x52, &regw);
  666. if (regw & 0x08)
  667. pci_write_config_word(pdev, 0x52, regw & ~0x08);
  668. return;
  669. }
  670. if (sis->info == &sis_info133_early || sis->info == &sis_info100) {
  671. /* Fix up latency */
  672. pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x80);
  673. /* Set compatibility bit */
  674. pci_read_config_byte(pdev, 0x49, &reg);
  675. if (!(reg & 0x01))
  676. pci_write_config_byte(pdev, 0x49, reg | 0x01);
  677. return;
  678. }
  679. if (sis->info == &sis_info66 || sis->info == &sis_info100_early) {
  680. /* Fix up latency */
  681. pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x80);
  682. /* Set compatibility bit */
  683. pci_read_config_byte(pdev, 0x52, &reg);
  684. if (!(reg & 0x04))
  685. pci_write_config_byte(pdev, 0x52, reg | 0x04);
  686. return;
  687. }
  688. if (sis->info == &sis_info33) {
  689. pci_read_config_byte(pdev, PCI_CLASS_PROG, &reg);
  690. if (( reg & 0x0F ) != 0x00)
  691. pci_write_config_byte(pdev, PCI_CLASS_PROG, reg & 0xF0);
  692. /* Fall through to ATA16 fixup below */
  693. }
  694. if (sis->info == &sis_info || sis->info == &sis_info33) {
  695. /* force per drive recovery and active timings
  696. needed on ATA_33 and below chips */
  697. pci_read_config_byte(pdev, 0x52, &reg);
  698. if (!(reg & 0x08))
  699. pci_write_config_byte(pdev, 0x52, reg|0x08);
  700. return;
  701. }
  702. BUG();
  703. }
  704. /**
  705. * sis_init_one - Register SiS ATA PCI device with kernel services
  706. * @pdev: PCI device to register
  707. * @ent: Entry in sis_pci_tbl matching with @pdev
  708. *
  709. * Called from kernel PCI layer. We probe for combined mode (sigh),
  710. * and then hand over control to libata, for it to do the rest.
  711. *
  712. * LOCKING:
  713. * Inherited from PCI layer (may sleep).
  714. *
  715. * RETURNS:
  716. * Zero on success, or -ERRNO value.
  717. */
  718. static int sis_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
  719. {
  720. static int printed_version;
  721. static struct ata_port_info *port_info[2];
  722. struct ata_port_info *port;
  723. struct pci_dev *host = NULL;
  724. struct sis_chipset *chipset = NULL;
  725. static struct sis_chipset sis_chipsets[] = {
  726. { 0x0968, &sis_info133 },
  727. { 0x0966, &sis_info133 },
  728. { 0x0965, &sis_info133 },
  729. { 0x0745, &sis_info100 },
  730. { 0x0735, &sis_info100 },
  731. { 0x0733, &sis_info100 },
  732. { 0x0635, &sis_info100 },
  733. { 0x0633, &sis_info100 },
  734. { 0x0730, &sis_info100_early }, /* 100 with ATA 66 layout */
  735. { 0x0550, &sis_info100_early }, /* 100 with ATA 66 layout */
  736. { 0x0640, &sis_info66 },
  737. { 0x0630, &sis_info66 },
  738. { 0x0620, &sis_info66 },
  739. { 0x0540, &sis_info66 },
  740. { 0x0530, &sis_info66 },
  741. { 0x5600, &sis_info33 },
  742. { 0x5598, &sis_info33 },
  743. { 0x5597, &sis_info33 },
  744. { 0x5591, &sis_info33 },
  745. { 0x5582, &sis_info33 },
  746. { 0x5581, &sis_info33 },
  747. { 0x5596, &sis_info },
  748. { 0x5571, &sis_info },
  749. { 0x5517, &sis_info },
  750. { 0x5511, &sis_info },
  751. {0}
  752. };
  753. static struct sis_chipset sis133_early = {
  754. 0x0, &sis_info133_early
  755. };
  756. static struct sis_chipset sis133 = {
  757. 0x0, &sis_info133
  758. };
  759. static struct sis_chipset sis100_early = {
  760. 0x0, &sis_info100_early
  761. };
  762. static struct sis_chipset sis100 = {
  763. 0x0, &sis_info100
  764. };
  765. if (!printed_version++)
  766. dev_printk(KERN_DEBUG, &pdev->dev,
  767. "version " DRV_VERSION "\n");
  768. /* We have to find the bridge first */
  769. for (chipset = &sis_chipsets[0]; chipset->device; chipset++) {
  770. host = pci_get_device(PCI_VENDOR_ID_SI, chipset->device, NULL);
  771. if (host != NULL) {
  772. if (chipset->device == 0x630) { /* SIS630 */
  773. u8 host_rev;
  774. pci_read_config_byte(host, PCI_REVISION_ID, &host_rev);
  775. if (host_rev >= 0x30) /* 630 ET */
  776. chipset = &sis100_early;
  777. }
  778. break;
  779. }
  780. }
  781. /* Look for concealed bridges */
  782. if (host == NULL) {
  783. /* Second check */
  784. u32 idemisc;
  785. u16 trueid;
  786. /* Disable ID masking and register remapping then
  787. see what the real ID is */
  788. pci_read_config_dword(pdev, 0x54, &idemisc);
  789. pci_write_config_dword(pdev, 0x54, idemisc & 0x7fffffff);
  790. pci_read_config_word(pdev, PCI_DEVICE_ID, &trueid);
  791. pci_write_config_dword(pdev, 0x54, idemisc);
  792. switch(trueid) {
  793. case 0x5518: /* SIS 962/963 */
  794. chipset = &sis133;
  795. if ((idemisc & 0x40000000) == 0) {
  796. pci_write_config_dword(pdev, 0x54, idemisc | 0x40000000);
  797. printk(KERN_INFO "SIS5513: Switching to 5513 register mapping\n");
  798. }
  799. break;
  800. case 0x0180: /* SIS 965/965L */
  801. chipset = &sis133;
  802. break;
  803. case 0x1180: /* SIS 966/966L */
  804. chipset = &sis133;
  805. break;
  806. }
  807. }
  808. /* Further check */
  809. if (chipset == NULL) {
  810. struct pci_dev *lpc_bridge;
  811. u16 trueid;
  812. u8 prefctl;
  813. u8 idecfg;
  814. u8 sbrev;
  815. /* Try the second unmasking technique */
  816. pci_read_config_byte(pdev, 0x4a, &idecfg);
  817. pci_write_config_byte(pdev, 0x4a, idecfg | 0x10);
  818. pci_read_config_word(pdev, PCI_DEVICE_ID, &trueid);
  819. pci_write_config_byte(pdev, 0x4a, idecfg);
  820. switch(trueid) {
  821. case 0x5517:
  822. lpc_bridge = pci_get_slot(pdev->bus, 0x10); /* Bus 0 Dev 2 Fn 0 */
  823. if (lpc_bridge == NULL)
  824. break;
  825. pci_read_config_byte(lpc_bridge, PCI_REVISION_ID, &sbrev);
  826. pci_read_config_byte(pdev, 0x49, &prefctl);
  827. pci_dev_put(lpc_bridge);
  828. if (sbrev == 0x10 && (prefctl & 0x80)) {
  829. chipset = &sis133_early;
  830. break;
  831. }
  832. chipset = &sis100;
  833. break;
  834. }
  835. }
  836. pci_dev_put(host);
  837. /* No chipset info, no support */
  838. if (chipset == NULL)
  839. return -ENODEV;
  840. port = chipset->info;
  841. port->private_data = chipset;
  842. sis_fixup(pdev, chipset);
  843. port_info[0] = port_info[1] = port;
  844. return ata_pci_init_one(pdev, port_info, 2);
  845. }
  846. static const struct pci_device_id sis_pci_tbl[] = {
  847. { PCI_VDEVICE(SI, 0x5513), }, /* SiS 5513 */
  848. { PCI_VDEVICE(SI, 0x5518), }, /* SiS 5518 */
  849. { }
  850. };
  851. static struct pci_driver sis_pci_driver = {
  852. .name = DRV_NAME,
  853. .id_table = sis_pci_tbl,
  854. .probe = sis_init_one,
  855. .remove = ata_pci_remove_one,
  856. };
  857. static int __init sis_init(void)
  858. {
  859. return pci_register_driver(&sis_pci_driver);
  860. }
  861. static void __exit sis_exit(void)
  862. {
  863. pci_unregister_driver(&sis_pci_driver);
  864. }
  865. module_init(sis_init);
  866. module_exit(sis_exit);
  867. MODULE_AUTHOR("Alan Cox");
  868. MODULE_DESCRIPTION("SCSI low-level driver for SiS ATA");
  869. MODULE_LICENSE("GPL");
  870. MODULE_DEVICE_TABLE(pci, sis_pci_tbl);
  871. MODULE_VERSION(DRV_VERSION);