pata_sis.c 27 KB

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