pata_sis.c 27 KB

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