pata_sis.c 26 KB

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