siimage.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845
  1. /*
  2. * Copyright (C) 2001-2002 Andre Hedrick <andre@linux-ide.org>
  3. * Copyright (C) 2003 Red Hat
  4. * Copyright (C) 2007-2008 MontaVista Software, Inc.
  5. * Copyright (C) 2007-2008 Bartlomiej Zolnierkiewicz
  6. *
  7. * May be copied or modified under the terms of the GNU General Public License
  8. *
  9. * Documentation for CMD680:
  10. * http://gkernel.sourceforge.net/specs/sii/sii-0680a-v1.31.pdf.bz2
  11. *
  12. * Documentation for SiI 3112:
  13. * http://gkernel.sourceforge.net/specs/sii/3112A_SiI-DS-0095-B2.pdf.bz2
  14. *
  15. * Errata and other documentation only available under NDA.
  16. *
  17. *
  18. * FAQ Items:
  19. * If you are using Marvell SATA-IDE adapters with Maxtor drives
  20. * ensure the system is set up for ATA100/UDMA5, not UDMA6.
  21. *
  22. * If you are using WD drives with SATA bridges you must set the
  23. * drive to "Single". "Master" will hang.
  24. *
  25. * If you have strange problems with nVidia chipset systems please
  26. * see the SI support documentation and update your system BIOS
  27. * if necessary
  28. *
  29. * The Dell DRAC4 has some interesting features including effectively hot
  30. * unplugging/replugging the virtual CD interface when the DRAC is reset.
  31. * This often causes drivers/ide/siimage to panic but is ok with the rather
  32. * smarter code in libata.
  33. *
  34. * TODO:
  35. * - VDMA support
  36. */
  37. #include <linux/types.h>
  38. #include <linux/module.h>
  39. #include <linux/pci.h>
  40. #include <linux/ide.h>
  41. #include <linux/init.h>
  42. #include <linux/io.h>
  43. #define DRV_NAME "siimage"
  44. /**
  45. * pdev_is_sata - check if device is SATA
  46. * @pdev: PCI device to check
  47. *
  48. * Returns true if this is a SATA controller
  49. */
  50. static int pdev_is_sata(struct pci_dev *pdev)
  51. {
  52. #ifdef CONFIG_BLK_DEV_IDE_SATA
  53. switch (pdev->device) {
  54. case PCI_DEVICE_ID_SII_3112:
  55. case PCI_DEVICE_ID_SII_1210SA:
  56. return 1;
  57. case PCI_DEVICE_ID_SII_680:
  58. return 0;
  59. }
  60. BUG();
  61. #endif
  62. return 0;
  63. }
  64. /**
  65. * is_sata - check if hwif is SATA
  66. * @hwif: interface to check
  67. *
  68. * Returns true if this is a SATA controller
  69. */
  70. static inline int is_sata(ide_hwif_t *hwif)
  71. {
  72. return pdev_is_sata(to_pci_dev(hwif->dev));
  73. }
  74. /**
  75. * siimage_selreg - return register base
  76. * @hwif: interface
  77. * @r: config offset
  78. *
  79. * Turn a config register offset into the right address in either
  80. * PCI space or MMIO space to access the control register in question
  81. * Thankfully this is a configuration operation, so isn't performance
  82. * critical.
  83. */
  84. static unsigned long siimage_selreg(ide_hwif_t *hwif, int r)
  85. {
  86. unsigned long base = (unsigned long)hwif->hwif_data;
  87. base += 0xA0 + r;
  88. if (hwif->host_flags & IDE_HFLAG_MMIO)
  89. base += hwif->channel << 6;
  90. else
  91. base += hwif->channel << 4;
  92. return base;
  93. }
  94. /**
  95. * siimage_seldev - return register base
  96. * @hwif: interface
  97. * @r: config offset
  98. *
  99. * Turn a config register offset into the right address in either
  100. * PCI space or MMIO space to access the control register in question
  101. * including accounting for the unit shift.
  102. */
  103. static inline unsigned long siimage_seldev(ide_drive_t *drive, int r)
  104. {
  105. ide_hwif_t *hwif = drive->hwif;
  106. unsigned long base = (unsigned long)hwif->hwif_data;
  107. u8 unit = drive->dn & 1;
  108. base += 0xA0 + r;
  109. if (hwif->host_flags & IDE_HFLAG_MMIO)
  110. base += hwif->channel << 6;
  111. else
  112. base += hwif->channel << 4;
  113. base |= unit << unit;
  114. return base;
  115. }
  116. static u8 sil_ioread8(struct pci_dev *dev, unsigned long addr)
  117. {
  118. struct ide_host *host = pci_get_drvdata(dev);
  119. u8 tmp = 0;
  120. if (host->host_priv)
  121. tmp = readb((void __iomem *)addr);
  122. else
  123. pci_read_config_byte(dev, addr, &tmp);
  124. return tmp;
  125. }
  126. static u16 sil_ioread16(struct pci_dev *dev, unsigned long addr)
  127. {
  128. struct ide_host *host = pci_get_drvdata(dev);
  129. u16 tmp = 0;
  130. if (host->host_priv)
  131. tmp = readw((void __iomem *)addr);
  132. else
  133. pci_read_config_word(dev, addr, &tmp);
  134. return tmp;
  135. }
  136. static void sil_iowrite8(struct pci_dev *dev, u8 val, unsigned long addr)
  137. {
  138. struct ide_host *host = pci_get_drvdata(dev);
  139. if (host->host_priv)
  140. writeb(val, (void __iomem *)addr);
  141. else
  142. pci_write_config_byte(dev, addr, val);
  143. }
  144. static void sil_iowrite16(struct pci_dev *dev, u16 val, unsigned long addr)
  145. {
  146. struct ide_host *host = pci_get_drvdata(dev);
  147. if (host->host_priv)
  148. writew(val, (void __iomem *)addr);
  149. else
  150. pci_write_config_word(dev, addr, val);
  151. }
  152. static void sil_iowrite32(struct pci_dev *dev, u32 val, unsigned long addr)
  153. {
  154. struct ide_host *host = pci_get_drvdata(dev);
  155. if (host->host_priv)
  156. writel(val, (void __iomem *)addr);
  157. else
  158. pci_write_config_dword(dev, addr, val);
  159. }
  160. /**
  161. * sil_udma_filter - compute UDMA mask
  162. * @drive: IDE device
  163. *
  164. * Compute the available UDMA speeds for the device on the interface.
  165. *
  166. * For the CMD680 this depends on the clocking mode (scsc), for the
  167. * SI3112 SATA controller life is a bit simpler.
  168. */
  169. static u8 sil_pata_udma_filter(ide_drive_t *drive)
  170. {
  171. ide_hwif_t *hwif = drive->hwif;
  172. struct pci_dev *dev = to_pci_dev(hwif->dev);
  173. unsigned long base = (unsigned long)hwif->hwif_data;
  174. u8 scsc, mask = 0;
  175. base += (hwif->host_flags & IDE_HFLAG_MMIO) ? 0x4A : 0x8A;
  176. scsc = sil_ioread8(dev, base);
  177. switch (scsc & 0x30) {
  178. case 0x10: /* 133 */
  179. mask = ATA_UDMA6;
  180. break;
  181. case 0x20: /* 2xPCI */
  182. mask = ATA_UDMA6;
  183. break;
  184. case 0x00: /* 100 */
  185. mask = ATA_UDMA5;
  186. break;
  187. default: /* Disabled ? */
  188. BUG();
  189. }
  190. return mask;
  191. }
  192. static u8 sil_sata_udma_filter(ide_drive_t *drive)
  193. {
  194. char *m = (char *)&drive->id[ATA_ID_PROD];
  195. return strstr(m, "Maxtor") ? ATA_UDMA5 : ATA_UDMA6;
  196. }
  197. /**
  198. * sil_set_pio_mode - set host controller for PIO mode
  199. * @hwif: port
  200. * @drive: drive
  201. *
  202. * Load the timing settings for this device mode into the
  203. * controller.
  204. */
  205. static void sil_set_pio_mode(ide_hwif_t *hwif, ide_drive_t *drive)
  206. {
  207. static const u16 tf_speed[] = { 0x328a, 0x2283, 0x1281, 0x10c3, 0x10c1 };
  208. static const u16 data_speed[] = { 0x328a, 0x2283, 0x1104, 0x10c3, 0x10c1 };
  209. struct pci_dev *dev = to_pci_dev(hwif->dev);
  210. ide_drive_t *pair = ide_get_pair_dev(drive);
  211. u32 speedt = 0;
  212. u16 speedp = 0;
  213. unsigned long addr = siimage_seldev(drive, 0x04);
  214. unsigned long tfaddr = siimage_selreg(hwif, 0x02);
  215. unsigned long base = (unsigned long)hwif->hwif_data;
  216. const u8 pio = drive->pio_mode - XFER_PIO_0;
  217. u8 tf_pio = pio;
  218. u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
  219. u8 addr_mask = hwif->channel ? (mmio ? 0xF4 : 0x84)
  220. : (mmio ? 0xB4 : 0x80);
  221. u8 mode = 0;
  222. u8 unit = drive->dn & 1;
  223. /* trim *taskfile* PIO to the slowest of the master/slave */
  224. if (pair) {
  225. u8 pair_pio = pair->pio_mode - XFER_PIO_0;
  226. if (pair_pio < tf_pio)
  227. tf_pio = pair_pio;
  228. }
  229. /* cheat for now and use the docs */
  230. speedp = data_speed[pio];
  231. speedt = tf_speed[tf_pio];
  232. sil_iowrite16(dev, speedp, addr);
  233. sil_iowrite16(dev, speedt, tfaddr);
  234. /* now set up IORDY */
  235. speedp = sil_ioread16(dev, tfaddr - 2);
  236. speedp &= ~0x200;
  237. mode = sil_ioread8(dev, base + addr_mask);
  238. mode &= ~(unit ? 0x30 : 0x03);
  239. if (ide_pio_need_iordy(drive, pio)) {
  240. speedp |= 0x200;
  241. mode |= unit ? 0x10 : 0x01;
  242. }
  243. sil_iowrite16(dev, speedp, tfaddr - 2);
  244. sil_iowrite8(dev, mode, base + addr_mask);
  245. }
  246. /**
  247. * sil_set_dma_mode - set host controller for DMA mode
  248. * @hwif: port
  249. * @drive: drive
  250. *
  251. * Tune the SiI chipset for the desired DMA mode.
  252. */
  253. static void sil_set_dma_mode(ide_hwif_t *hwif, ide_drive_t *drive)
  254. {
  255. static const u8 ultra6[] = { 0x0F, 0x0B, 0x07, 0x05, 0x03, 0x02, 0x01 };
  256. static const u8 ultra5[] = { 0x0C, 0x07, 0x05, 0x04, 0x02, 0x01 };
  257. static const u16 dma[] = { 0x2208, 0x10C2, 0x10C1 };
  258. struct pci_dev *dev = to_pci_dev(hwif->dev);
  259. unsigned long base = (unsigned long)hwif->hwif_data;
  260. u16 ultra = 0, multi = 0;
  261. u8 mode = 0, unit = drive->dn & 1;
  262. u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
  263. u8 scsc = 0, addr_mask = hwif->channel ? (mmio ? 0xF4 : 0x84)
  264. : (mmio ? 0xB4 : 0x80);
  265. unsigned long ma = siimage_seldev(drive, 0x08);
  266. unsigned long ua = siimage_seldev(drive, 0x0C);
  267. const u8 speed = drive->dma_mode;
  268. scsc = sil_ioread8 (dev, base + (mmio ? 0x4A : 0x8A));
  269. mode = sil_ioread8 (dev, base + addr_mask);
  270. multi = sil_ioread16(dev, ma);
  271. ultra = sil_ioread16(dev, ua);
  272. mode &= ~(unit ? 0x30 : 0x03);
  273. ultra &= ~0x3F;
  274. scsc = ((scsc & 0x30) == 0x00) ? 0 : 1;
  275. scsc = is_sata(hwif) ? 1 : scsc;
  276. if (speed >= XFER_UDMA_0) {
  277. multi = dma[2];
  278. ultra |= scsc ? ultra6[speed - XFER_UDMA_0] :
  279. ultra5[speed - XFER_UDMA_0];
  280. mode |= unit ? 0x30 : 0x03;
  281. } else {
  282. multi = dma[speed - XFER_MW_DMA_0];
  283. mode |= unit ? 0x20 : 0x02;
  284. }
  285. sil_iowrite8 (dev, mode, base + addr_mask);
  286. sil_iowrite16(dev, multi, ma);
  287. sil_iowrite16(dev, ultra, ua);
  288. }
  289. static int sil_test_irq(ide_hwif_t *hwif)
  290. {
  291. struct pci_dev *dev = to_pci_dev(hwif->dev);
  292. unsigned long addr = siimage_selreg(hwif, 1);
  293. u8 val = sil_ioread8(dev, addr);
  294. /* Return 1 if INTRQ asserted */
  295. return (val & 8) ? 1 : 0;
  296. }
  297. /**
  298. * siimage_mmio_dma_test_irq - check we caused an IRQ
  299. * @drive: drive we are testing
  300. *
  301. * Check if we caused an IDE DMA interrupt. We may also have caused
  302. * SATA status interrupts, if so we clean them up and continue.
  303. */
  304. static int siimage_mmio_dma_test_irq(ide_drive_t *drive)
  305. {
  306. ide_hwif_t *hwif = drive->hwif;
  307. void __iomem *sata_error_addr
  308. = (void __iomem *)hwif->sata_scr[SATA_ERROR_OFFSET];
  309. if (sata_error_addr) {
  310. unsigned long base = (unsigned long)hwif->hwif_data;
  311. u32 ext_stat = readl((void __iomem *)(base + 0x10));
  312. u8 watchdog = 0;
  313. if (ext_stat & ((hwif->channel) ? 0x40 : 0x10)) {
  314. u32 sata_error = readl(sata_error_addr);
  315. writel(sata_error, sata_error_addr);
  316. watchdog = (sata_error & 0x00680000) ? 1 : 0;
  317. printk(KERN_WARNING "%s: sata_error = 0x%08x, "
  318. "watchdog = %d, %s\n",
  319. drive->name, sata_error, watchdog, __func__);
  320. } else
  321. watchdog = (ext_stat & 0x8000) ? 1 : 0;
  322. ext_stat >>= 16;
  323. if (!(ext_stat & 0x0404) && !watchdog)
  324. return 0;
  325. }
  326. /* return 1 if INTR asserted */
  327. if (readb((void __iomem *)(hwif->dma_base + ATA_DMA_STATUS)) & 4)
  328. return 1;
  329. return 0;
  330. }
  331. static int siimage_dma_test_irq(ide_drive_t *drive)
  332. {
  333. if (drive->hwif->host_flags & IDE_HFLAG_MMIO)
  334. return siimage_mmio_dma_test_irq(drive);
  335. else
  336. return ide_dma_test_irq(drive);
  337. }
  338. /**
  339. * sil_sata_reset_poll - wait for SATA reset
  340. * @drive: drive we are resetting
  341. *
  342. * Poll the SATA phy and see whether it has come back from the dead
  343. * yet.
  344. */
  345. static int sil_sata_reset_poll(ide_drive_t *drive)
  346. {
  347. ide_hwif_t *hwif = drive->hwif;
  348. void __iomem *sata_status_addr
  349. = (void __iomem *)hwif->sata_scr[SATA_STATUS_OFFSET];
  350. if (sata_status_addr) {
  351. /* SATA Status is available only when in MMIO mode */
  352. u32 sata_stat = readl(sata_status_addr);
  353. if ((sata_stat & 0x03) != 0x03) {
  354. printk(KERN_WARNING "%s: reset phy dead, status=0x%08x\n",
  355. hwif->name, sata_stat);
  356. return -ENXIO;
  357. }
  358. }
  359. return 0;
  360. }
  361. /**
  362. * sil_sata_pre_reset - reset hook
  363. * @drive: IDE device being reset
  364. *
  365. * For the SATA devices we need to handle recalibration/geometry
  366. * differently
  367. */
  368. static void sil_sata_pre_reset(ide_drive_t *drive)
  369. {
  370. if (drive->media == ide_disk) {
  371. drive->special_flags &=
  372. ~(IDE_SFLAG_SET_GEOMETRY | IDE_SFLAG_RECALIBRATE);
  373. }
  374. }
  375. /**
  376. * init_chipset_siimage - set up an SI device
  377. * @dev: PCI device
  378. *
  379. * Perform the initial PCI set up for this device. Attempt to switch
  380. * to 133 MHz clocking if the system isn't already set up to do it.
  381. */
  382. static int init_chipset_siimage(struct pci_dev *dev)
  383. {
  384. struct ide_host *host = pci_get_drvdata(dev);
  385. void __iomem *ioaddr = host->host_priv;
  386. unsigned long base, scsc_addr;
  387. u8 rev = dev->revision, tmp;
  388. pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, rev ? 1 : 255);
  389. if (ioaddr)
  390. pci_set_master(dev);
  391. base = (unsigned long)ioaddr;
  392. if (ioaddr && pdev_is_sata(dev)) {
  393. u32 tmp32, irq_mask;
  394. /* make sure IDE0/1 interrupts are not masked */
  395. irq_mask = (1 << 22) | (1 << 23);
  396. tmp32 = readl(ioaddr + 0x48);
  397. if (tmp32 & irq_mask) {
  398. tmp32 &= ~irq_mask;
  399. writel(tmp32, ioaddr + 0x48);
  400. readl(ioaddr + 0x48); /* flush */
  401. }
  402. writel(0, ioaddr + 0x148);
  403. writel(0, ioaddr + 0x1C8);
  404. }
  405. sil_iowrite8(dev, 0, base ? (base + 0xB4) : 0x80);
  406. sil_iowrite8(dev, 0, base ? (base + 0xF4) : 0x84);
  407. scsc_addr = base ? (base + 0x4A) : 0x8A;
  408. tmp = sil_ioread8(dev, scsc_addr);
  409. switch (tmp & 0x30) {
  410. case 0x00:
  411. /* On 100 MHz clocking, try and switch to 133 MHz */
  412. sil_iowrite8(dev, tmp | 0x10, scsc_addr);
  413. break;
  414. case 0x30:
  415. /* Clocking is disabled, attempt to force 133MHz clocking. */
  416. sil_iowrite8(dev, tmp & ~0x20, scsc_addr);
  417. case 0x10:
  418. /* On 133Mhz clocking. */
  419. break;
  420. case 0x20:
  421. /* On PCIx2 clocking. */
  422. break;
  423. }
  424. tmp = sil_ioread8(dev, scsc_addr);
  425. sil_iowrite8 (dev, 0x72, base + 0xA1);
  426. sil_iowrite16(dev, 0x328A, base + 0xA2);
  427. sil_iowrite32(dev, 0x62DD62DD, base + 0xA4);
  428. sil_iowrite32(dev, 0x43924392, base + 0xA8);
  429. sil_iowrite32(dev, 0x40094009, base + 0xAC);
  430. sil_iowrite8 (dev, 0x72, base ? (base + 0xE1) : 0xB1);
  431. sil_iowrite16(dev, 0x328A, base ? (base + 0xE2) : 0xB2);
  432. sil_iowrite32(dev, 0x62DD62DD, base ? (base + 0xE4) : 0xB4);
  433. sil_iowrite32(dev, 0x43924392, base ? (base + 0xE8) : 0xB8);
  434. sil_iowrite32(dev, 0x40094009, base ? (base + 0xEC) : 0xBC);
  435. if (base && pdev_is_sata(dev)) {
  436. writel(0xFFFF0000, ioaddr + 0x108);
  437. writel(0xFFFF0000, ioaddr + 0x188);
  438. writel(0x00680000, ioaddr + 0x148);
  439. writel(0x00680000, ioaddr + 0x1C8);
  440. }
  441. /* report the clocking mode of the controller */
  442. if (!pdev_is_sata(dev)) {
  443. static const char *clk_str[] =
  444. { "== 100", "== 133", "== 2X PCI", "DISABLED!" };
  445. tmp >>= 4;
  446. printk(KERN_INFO DRV_NAME " %s: BASE CLOCK %s\n",
  447. pci_name(dev), clk_str[tmp & 3]);
  448. }
  449. return 0;
  450. }
  451. /**
  452. * init_mmio_iops_siimage - set up the iops for MMIO
  453. * @hwif: interface to set up
  454. *
  455. * The basic setup here is fairly simple, we can use standard MMIO
  456. * operations. However we do have to set the taskfile register offsets
  457. * by hand as there isn't a standard defined layout for them this time.
  458. *
  459. * The hardware supports buffered taskfiles and also some rather nice
  460. * extended PRD tables. For better SI3112 support use the libata driver
  461. */
  462. static void init_mmio_iops_siimage(ide_hwif_t *hwif)
  463. {
  464. struct pci_dev *dev = to_pci_dev(hwif->dev);
  465. struct ide_host *host = pci_get_drvdata(dev);
  466. void *addr = host->host_priv;
  467. u8 ch = hwif->channel;
  468. struct ide_io_ports *io_ports = &hwif->io_ports;
  469. unsigned long base;
  470. /*
  471. * Fill in the basic hwif bits
  472. */
  473. hwif->host_flags |= IDE_HFLAG_MMIO;
  474. hwif->hwif_data = addr;
  475. /*
  476. * Now set up the hw. We have to do this ourselves as the
  477. * MMIO layout isn't the same as the standard port based I/O.
  478. */
  479. memset(io_ports, 0, sizeof(*io_ports));
  480. base = (unsigned long)addr;
  481. if (ch)
  482. base += 0xC0;
  483. else
  484. base += 0x80;
  485. /*
  486. * The buffered task file doesn't have status/control, so we
  487. * can't currently use it sanely since we want to use LBA48 mode.
  488. */
  489. io_ports->data_addr = base;
  490. io_ports->error_addr = base + 1;
  491. io_ports->nsect_addr = base + 2;
  492. io_ports->lbal_addr = base + 3;
  493. io_ports->lbam_addr = base + 4;
  494. io_ports->lbah_addr = base + 5;
  495. io_ports->device_addr = base + 6;
  496. io_ports->status_addr = base + 7;
  497. io_ports->ctl_addr = base + 10;
  498. if (pdev_is_sata(dev)) {
  499. base = (unsigned long)addr;
  500. if (ch)
  501. base += 0x80;
  502. hwif->sata_scr[SATA_STATUS_OFFSET] = base + 0x104;
  503. hwif->sata_scr[SATA_ERROR_OFFSET] = base + 0x108;
  504. hwif->sata_scr[SATA_CONTROL_OFFSET] = base + 0x100;
  505. }
  506. hwif->irq = dev->irq;
  507. hwif->dma_base = (unsigned long)addr + (ch ? 0x08 : 0x00);
  508. }
  509. static int is_dev_seagate_sata(ide_drive_t *drive)
  510. {
  511. const char *s = (const char *)&drive->id[ATA_ID_PROD];
  512. unsigned len = strnlen(s, ATA_ID_PROD_LEN);
  513. if ((len > 4) && (!memcmp(s, "ST", 2)))
  514. if ((!memcmp(s + len - 2, "AS", 2)) ||
  515. (!memcmp(s + len - 3, "ASL", 3))) {
  516. printk(KERN_INFO "%s: applying pessimistic Seagate "
  517. "errata fix\n", drive->name);
  518. return 1;
  519. }
  520. return 0;
  521. }
  522. /**
  523. * sil_quirkproc - post probe fixups
  524. * @drive: drive
  525. *
  526. * Called after drive probe we use this to decide whether the
  527. * Seagate fixup must be applied. This used to be in init_iops but
  528. * that can occur before we know what drives are present.
  529. */
  530. static void sil_quirkproc(ide_drive_t *drive)
  531. {
  532. ide_hwif_t *hwif = drive->hwif;
  533. /* Try and rise the rqsize */
  534. if (!is_sata(hwif) || !is_dev_seagate_sata(drive))
  535. hwif->rqsize = 128;
  536. }
  537. /**
  538. * init_iops_siimage - set up iops
  539. * @hwif: interface to set up
  540. *
  541. * Do the basic setup for the SIIMAGE hardware interface
  542. * and then do the MMIO setup if we can. This is the first
  543. * look in we get for setting up the hwif so that we
  544. * can get the iops right before using them.
  545. */
  546. static void init_iops_siimage(ide_hwif_t *hwif)
  547. {
  548. struct pci_dev *dev = to_pci_dev(hwif->dev);
  549. struct ide_host *host = pci_get_drvdata(dev);
  550. hwif->hwif_data = NULL;
  551. /* Pessimal until we finish probing */
  552. hwif->rqsize = 15;
  553. if (host->host_priv)
  554. init_mmio_iops_siimage(hwif);
  555. }
  556. /**
  557. * sil_cable_detect - cable detection
  558. * @hwif: interface to check
  559. *
  560. * Check for the presence of an ATA66 capable cable on the interface.
  561. */
  562. static u8 sil_cable_detect(ide_hwif_t *hwif)
  563. {
  564. struct pci_dev *dev = to_pci_dev(hwif->dev);
  565. unsigned long addr = siimage_selreg(hwif, 0);
  566. u8 ata66 = sil_ioread8(dev, addr);
  567. return (ata66 & 0x01) ? ATA_CBL_PATA80 : ATA_CBL_PATA40;
  568. }
  569. static const struct ide_port_ops sil_pata_port_ops = {
  570. .set_pio_mode = sil_set_pio_mode,
  571. .set_dma_mode = sil_set_dma_mode,
  572. .quirkproc = sil_quirkproc,
  573. .test_irq = sil_test_irq,
  574. .udma_filter = sil_pata_udma_filter,
  575. .cable_detect = sil_cable_detect,
  576. };
  577. static const struct ide_port_ops sil_sata_port_ops = {
  578. .set_pio_mode = sil_set_pio_mode,
  579. .set_dma_mode = sil_set_dma_mode,
  580. .reset_poll = sil_sata_reset_poll,
  581. .pre_reset = sil_sata_pre_reset,
  582. .quirkproc = sil_quirkproc,
  583. .test_irq = sil_test_irq,
  584. .udma_filter = sil_sata_udma_filter,
  585. .cable_detect = sil_cable_detect,
  586. };
  587. static const struct ide_dma_ops sil_dma_ops = {
  588. .dma_host_set = ide_dma_host_set,
  589. .dma_setup = ide_dma_setup,
  590. .dma_start = ide_dma_start,
  591. .dma_end = ide_dma_end,
  592. .dma_test_irq = siimage_dma_test_irq,
  593. .dma_timer_expiry = ide_dma_sff_timer_expiry,
  594. .dma_lost_irq = ide_dma_lost_irq,
  595. .dma_sff_read_status = ide_dma_sff_read_status,
  596. };
  597. #define DECLARE_SII_DEV(p_ops) \
  598. { \
  599. .name = DRV_NAME, \
  600. .init_chipset = init_chipset_siimage, \
  601. .init_iops = init_iops_siimage, \
  602. .port_ops = p_ops, \
  603. .dma_ops = &sil_dma_ops, \
  604. .pio_mask = ATA_PIO4, \
  605. .mwdma_mask = ATA_MWDMA2, \
  606. .udma_mask = ATA_UDMA6, \
  607. }
  608. static const struct ide_port_info siimage_chipsets[] = {
  609. /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
  610. /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
  611. };
  612. /**
  613. * siimage_init_one - PCI layer discovery entry
  614. * @dev: PCI device
  615. * @id: ident table entry
  616. *
  617. * Called by the PCI code when it finds an SiI680 or SiI3112 controller.
  618. * We then use the IDE PCI generic helper to do most of the work.
  619. */
  620. static int siimage_init_one(struct pci_dev *dev, const struct pci_device_id *id)
  621. {
  622. void __iomem *ioaddr = NULL;
  623. resource_size_t bar5 = pci_resource_start(dev, 5);
  624. unsigned long barsize = pci_resource_len(dev, 5);
  625. int rc;
  626. struct ide_port_info d;
  627. u8 idx = id->driver_data;
  628. u8 BA5_EN;
  629. d = siimage_chipsets[idx];
  630. if (idx) {
  631. static int first = 1;
  632. if (first) {
  633. printk(KERN_INFO DRV_NAME ": For full SATA support you "
  634. "should use the libata sata_sil module.\n");
  635. first = 0;
  636. }
  637. d.host_flags |= IDE_HFLAG_NO_ATAPI_DMA;
  638. }
  639. rc = pci_enable_device(dev);
  640. if (rc)
  641. return rc;
  642. pci_read_config_byte(dev, 0x8A, &BA5_EN);
  643. if ((BA5_EN & 0x01) || bar5) {
  644. /*
  645. * Drop back to PIO if we can't map the MMIO. Some systems
  646. * seem to get terminally confused in the PCI spaces.
  647. */
  648. if (!request_mem_region(bar5, barsize, d.name)) {
  649. printk(KERN_WARNING DRV_NAME " %s: MMIO ports not "
  650. "available\n", pci_name(dev));
  651. } else {
  652. ioaddr = pci_ioremap_bar(dev, 5);
  653. if (ioaddr == NULL)
  654. release_mem_region(bar5, barsize);
  655. }
  656. }
  657. rc = ide_pci_init_one(dev, &d, ioaddr);
  658. if (rc) {
  659. if (ioaddr) {
  660. iounmap(ioaddr);
  661. release_mem_region(bar5, barsize);
  662. }
  663. pci_disable_device(dev);
  664. }
  665. return rc;
  666. }
  667. static void siimage_remove(struct pci_dev *dev)
  668. {
  669. struct ide_host *host = pci_get_drvdata(dev);
  670. void __iomem *ioaddr = host->host_priv;
  671. ide_pci_remove(dev);
  672. if (ioaddr) {
  673. resource_size_t bar5 = pci_resource_start(dev, 5);
  674. unsigned long barsize = pci_resource_len(dev, 5);
  675. iounmap(ioaddr);
  676. release_mem_region(bar5, barsize);
  677. }
  678. pci_disable_device(dev);
  679. }
  680. static const struct pci_device_id siimage_pci_tbl[] = {
  681. { PCI_VDEVICE(CMD, PCI_DEVICE_ID_SII_680), 0 },
  682. #ifdef CONFIG_BLK_DEV_IDE_SATA
  683. { PCI_VDEVICE(CMD, PCI_DEVICE_ID_SII_3112), 1 },
  684. { PCI_VDEVICE(CMD, PCI_DEVICE_ID_SII_1210SA), 1 },
  685. #endif
  686. { 0, },
  687. };
  688. MODULE_DEVICE_TABLE(pci, siimage_pci_tbl);
  689. static struct pci_driver siimage_pci_driver = {
  690. .name = "SiI_IDE",
  691. .id_table = siimage_pci_tbl,
  692. .probe = siimage_init_one,
  693. .remove = siimage_remove,
  694. .suspend = ide_pci_suspend,
  695. .resume = ide_pci_resume,
  696. };
  697. static int __init siimage_ide_init(void)
  698. {
  699. return ide_pci_register_driver(&siimage_pci_driver);
  700. }
  701. static void __exit siimage_ide_exit(void)
  702. {
  703. pci_unregister_driver(&siimage_pci_driver);
  704. }
  705. module_init(siimage_ide_init);
  706. module_exit(siimage_ide_exit);
  707. MODULE_AUTHOR("Andre Hedrick, Alan Cox");
  708. MODULE_DESCRIPTION("PCI driver module for SiI IDE");
  709. MODULE_LICENSE("GPL");