siimage.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833
  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. * @drive: drive
  200. * @pio: PIO mode number
  201. *
  202. * Load the timing settings for this device mode into the
  203. * controller.
  204. */
  205. static void sil_set_pio_mode(ide_drive_t *drive, u8 pio)
  206. {
  207. static const u16 tf_speed[] = { 0x328a, 0x2283, 0x1281, 0x10c3, 0x10c1 };
  208. static const u16 data_speed[] = { 0x328a, 0x2283, 0x1104, 0x10c3, 0x10c1 };
  209. ide_hwif_t *hwif = drive->hwif;
  210. struct pci_dev *dev = to_pci_dev(hwif->dev);
  211. ide_drive_t *pair = ide_get_pair_dev(drive);
  212. u32 speedt = 0;
  213. u16 speedp = 0;
  214. unsigned long addr = siimage_seldev(drive, 0x04);
  215. unsigned long tfaddr = siimage_selreg(hwif, 0x02);
  216. unsigned long base = (unsigned long)hwif->hwif_data;
  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 = ide_get_best_pio_mode(pair, 255, 4);
  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. * @drive: drive
  249. * @speed: DMA mode
  250. *
  251. * Tune the SiI chipset for the desired DMA mode.
  252. */
  253. static void sil_set_dma_mode(ide_drive_t *drive, const u8 speed)
  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. ide_hwif_t *hwif = drive->hwif;
  259. struct pci_dev *dev = to_pci_dev(hwif->dev);
  260. unsigned long base = (unsigned long)hwif->hwif_data;
  261. u16 ultra = 0, multi = 0;
  262. u8 mode = 0, unit = drive->dn & 1;
  263. u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
  264. u8 scsc = 0, addr_mask = hwif->channel ? (mmio ? 0xF4 : 0x84)
  265. : (mmio ? 0xB4 : 0x80);
  266. unsigned long ma = siimage_seldev(drive, 0x08);
  267. unsigned long ua = siimage_seldev(drive, 0x0C);
  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. /**
  290. * siimage_mmio_dma_test_irq - check we caused an IRQ
  291. * @drive: drive we are testing
  292. *
  293. * Check if we caused an IDE DMA interrupt. We may also have caused
  294. * SATA status interrupts, if so we clean them up and continue.
  295. */
  296. static int siimage_mmio_dma_test_irq(ide_drive_t *drive)
  297. {
  298. ide_hwif_t *hwif = drive->hwif;
  299. void __iomem *sata_error_addr
  300. = (void __iomem *)hwif->sata_scr[SATA_ERROR_OFFSET];
  301. if (sata_error_addr) {
  302. unsigned long base = (unsigned long)hwif->hwif_data;
  303. u32 ext_stat = readl((void __iomem *)(base + 0x10));
  304. u8 watchdog = 0;
  305. if (ext_stat & ((hwif->channel) ? 0x40 : 0x10)) {
  306. u32 sata_error = readl(sata_error_addr);
  307. writel(sata_error, sata_error_addr);
  308. watchdog = (sata_error & 0x00680000) ? 1 : 0;
  309. printk(KERN_WARNING "%s: sata_error = 0x%08x, "
  310. "watchdog = %d, %s\n",
  311. drive->name, sata_error, watchdog, __func__);
  312. } else
  313. watchdog = (ext_stat & 0x8000) ? 1 : 0;
  314. ext_stat >>= 16;
  315. if (!(ext_stat & 0x0404) && !watchdog)
  316. return 0;
  317. }
  318. /* return 1 if INTR asserted */
  319. if (readb((void __iomem *)(hwif->dma_base + ATA_DMA_STATUS)) & 4)
  320. return 1;
  321. return 0;
  322. }
  323. static int siimage_dma_test_irq(ide_drive_t *drive)
  324. {
  325. if (drive->hwif->host_flags & IDE_HFLAG_MMIO)
  326. return siimage_mmio_dma_test_irq(drive);
  327. else
  328. return ide_dma_test_irq(drive);
  329. }
  330. /**
  331. * sil_sata_reset_poll - wait for SATA reset
  332. * @drive: drive we are resetting
  333. *
  334. * Poll the SATA phy and see whether it has come back from the dead
  335. * yet.
  336. */
  337. static int sil_sata_reset_poll(ide_drive_t *drive)
  338. {
  339. ide_hwif_t *hwif = drive->hwif;
  340. void __iomem *sata_status_addr
  341. = (void __iomem *)hwif->sata_scr[SATA_STATUS_OFFSET];
  342. if (sata_status_addr) {
  343. /* SATA Status is available only when in MMIO mode */
  344. u32 sata_stat = readl(sata_status_addr);
  345. if ((sata_stat & 0x03) != 0x03) {
  346. printk(KERN_WARNING "%s: reset phy dead, status=0x%08x\n",
  347. hwif->name, sata_stat);
  348. return -ENXIO;
  349. }
  350. }
  351. return 0;
  352. }
  353. /**
  354. * sil_sata_pre_reset - reset hook
  355. * @drive: IDE device being reset
  356. *
  357. * For the SATA devices we need to handle recalibration/geometry
  358. * differently
  359. */
  360. static void sil_sata_pre_reset(ide_drive_t *drive)
  361. {
  362. if (drive->media == ide_disk) {
  363. drive->special_flags &=
  364. ~(IDE_SFLAG_SET_GEOMETRY | IDE_SFLAG_RECALIBRATE);
  365. }
  366. }
  367. /**
  368. * init_chipset_siimage - set up an SI device
  369. * @dev: PCI device
  370. *
  371. * Perform the initial PCI set up for this device. Attempt to switch
  372. * to 133 MHz clocking if the system isn't already set up to do it.
  373. */
  374. static int init_chipset_siimage(struct pci_dev *dev)
  375. {
  376. struct ide_host *host = pci_get_drvdata(dev);
  377. void __iomem *ioaddr = host->host_priv;
  378. unsigned long base, scsc_addr;
  379. u8 rev = dev->revision, tmp;
  380. pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, rev ? 1 : 255);
  381. if (ioaddr)
  382. pci_set_master(dev);
  383. base = (unsigned long)ioaddr;
  384. if (ioaddr && pdev_is_sata(dev)) {
  385. u32 tmp32, irq_mask;
  386. /* make sure IDE0/1 interrupts are not masked */
  387. irq_mask = (1 << 22) | (1 << 23);
  388. tmp32 = readl(ioaddr + 0x48);
  389. if (tmp32 & irq_mask) {
  390. tmp32 &= ~irq_mask;
  391. writel(tmp32, ioaddr + 0x48);
  392. readl(ioaddr + 0x48); /* flush */
  393. }
  394. writel(0, ioaddr + 0x148);
  395. writel(0, ioaddr + 0x1C8);
  396. }
  397. sil_iowrite8(dev, 0, base ? (base + 0xB4) : 0x80);
  398. sil_iowrite8(dev, 0, base ? (base + 0xF4) : 0x84);
  399. scsc_addr = base ? (base + 0x4A) : 0x8A;
  400. tmp = sil_ioread8(dev, scsc_addr);
  401. switch (tmp & 0x30) {
  402. case 0x00:
  403. /* On 100 MHz clocking, try and switch to 133 MHz */
  404. sil_iowrite8(dev, tmp | 0x10, scsc_addr);
  405. break;
  406. case 0x30:
  407. /* Clocking is disabled, attempt to force 133MHz clocking. */
  408. sil_iowrite8(dev, tmp & ~0x20, scsc_addr);
  409. case 0x10:
  410. /* On 133Mhz clocking. */
  411. break;
  412. case 0x20:
  413. /* On PCIx2 clocking. */
  414. break;
  415. }
  416. tmp = sil_ioread8(dev, scsc_addr);
  417. sil_iowrite8 (dev, 0x72, base + 0xA1);
  418. sil_iowrite16(dev, 0x328A, base + 0xA2);
  419. sil_iowrite32(dev, 0x62DD62DD, base + 0xA4);
  420. sil_iowrite32(dev, 0x43924392, base + 0xA8);
  421. sil_iowrite32(dev, 0x40094009, base + 0xAC);
  422. sil_iowrite8 (dev, 0x72, base ? (base + 0xE1) : 0xB1);
  423. sil_iowrite16(dev, 0x328A, base ? (base + 0xE2) : 0xB2);
  424. sil_iowrite32(dev, 0x62DD62DD, base ? (base + 0xE4) : 0xB4);
  425. sil_iowrite32(dev, 0x43924392, base ? (base + 0xE8) : 0xB8);
  426. sil_iowrite32(dev, 0x40094009, base ? (base + 0xEC) : 0xBC);
  427. if (base && pdev_is_sata(dev)) {
  428. writel(0xFFFF0000, ioaddr + 0x108);
  429. writel(0xFFFF0000, ioaddr + 0x188);
  430. writel(0x00680000, ioaddr + 0x148);
  431. writel(0x00680000, ioaddr + 0x1C8);
  432. }
  433. /* report the clocking mode of the controller */
  434. if (!pdev_is_sata(dev)) {
  435. static const char *clk_str[] =
  436. { "== 100", "== 133", "== 2X PCI", "DISABLED!" };
  437. tmp >>= 4;
  438. printk(KERN_INFO DRV_NAME " %s: BASE CLOCK %s\n",
  439. pci_name(dev), clk_str[tmp & 3]);
  440. }
  441. return 0;
  442. }
  443. /**
  444. * init_mmio_iops_siimage - set up the iops for MMIO
  445. * @hwif: interface to set up
  446. *
  447. * The basic setup here is fairly simple, we can use standard MMIO
  448. * operations. However we do have to set the taskfile register offsets
  449. * by hand as there isn't a standard defined layout for them this time.
  450. *
  451. * The hardware supports buffered taskfiles and also some rather nice
  452. * extended PRD tables. For better SI3112 support use the libata driver
  453. */
  454. static void __devinit init_mmio_iops_siimage(ide_hwif_t *hwif)
  455. {
  456. struct pci_dev *dev = to_pci_dev(hwif->dev);
  457. struct ide_host *host = pci_get_drvdata(dev);
  458. void *addr = host->host_priv;
  459. u8 ch = hwif->channel;
  460. struct ide_io_ports *io_ports = &hwif->io_ports;
  461. unsigned long base;
  462. /*
  463. * Fill in the basic hwif bits
  464. */
  465. hwif->host_flags |= IDE_HFLAG_MMIO;
  466. hwif->hwif_data = addr;
  467. /*
  468. * Now set up the hw. We have to do this ourselves as the
  469. * MMIO layout isn't the same as the standard port based I/O.
  470. */
  471. memset(io_ports, 0, sizeof(*io_ports));
  472. base = (unsigned long)addr;
  473. if (ch)
  474. base += 0xC0;
  475. else
  476. base += 0x80;
  477. /*
  478. * The buffered task file doesn't have status/control, so we
  479. * can't currently use it sanely since we want to use LBA48 mode.
  480. */
  481. io_ports->data_addr = base;
  482. io_ports->error_addr = base + 1;
  483. io_ports->nsect_addr = base + 2;
  484. io_ports->lbal_addr = base + 3;
  485. io_ports->lbam_addr = base + 4;
  486. io_ports->lbah_addr = base + 5;
  487. io_ports->device_addr = base + 6;
  488. io_ports->status_addr = base + 7;
  489. io_ports->ctl_addr = base + 10;
  490. if (pdev_is_sata(dev)) {
  491. base = (unsigned long)addr;
  492. if (ch)
  493. base += 0x80;
  494. hwif->sata_scr[SATA_STATUS_OFFSET] = base + 0x104;
  495. hwif->sata_scr[SATA_ERROR_OFFSET] = base + 0x108;
  496. hwif->sata_scr[SATA_CONTROL_OFFSET] = base + 0x100;
  497. }
  498. hwif->irq = dev->irq;
  499. hwif->dma_base = (unsigned long)addr + (ch ? 0x08 : 0x00);
  500. }
  501. static int is_dev_seagate_sata(ide_drive_t *drive)
  502. {
  503. const char *s = (const char *)&drive->id[ATA_ID_PROD];
  504. unsigned len = strnlen(s, ATA_ID_PROD_LEN);
  505. if ((len > 4) && (!memcmp(s, "ST", 2)))
  506. if ((!memcmp(s + len - 2, "AS", 2)) ||
  507. (!memcmp(s + len - 3, "ASL", 3))) {
  508. printk(KERN_INFO "%s: applying pessimistic Seagate "
  509. "errata fix\n", drive->name);
  510. return 1;
  511. }
  512. return 0;
  513. }
  514. /**
  515. * sil_quirkproc - post probe fixups
  516. * @drive: drive
  517. *
  518. * Called after drive probe we use this to decide whether the
  519. * Seagate fixup must be applied. This used to be in init_iops but
  520. * that can occur before we know what drives are present.
  521. */
  522. static void sil_quirkproc(ide_drive_t *drive)
  523. {
  524. ide_hwif_t *hwif = drive->hwif;
  525. /* Try and rise the rqsize */
  526. if (!is_sata(hwif) || !is_dev_seagate_sata(drive))
  527. hwif->rqsize = 128;
  528. }
  529. /**
  530. * init_iops_siimage - set up iops
  531. * @hwif: interface to set up
  532. *
  533. * Do the basic setup for the SIIMAGE hardware interface
  534. * and then do the MMIO setup if we can. This is the first
  535. * look in we get for setting up the hwif so that we
  536. * can get the iops right before using them.
  537. */
  538. static void __devinit init_iops_siimage(ide_hwif_t *hwif)
  539. {
  540. struct pci_dev *dev = to_pci_dev(hwif->dev);
  541. struct ide_host *host = pci_get_drvdata(dev);
  542. hwif->hwif_data = NULL;
  543. /* Pessimal until we finish probing */
  544. hwif->rqsize = 15;
  545. if (host->host_priv)
  546. init_mmio_iops_siimage(hwif);
  547. }
  548. /**
  549. * sil_cable_detect - cable detection
  550. * @hwif: interface to check
  551. *
  552. * Check for the presence of an ATA66 capable cable on the interface.
  553. */
  554. static u8 sil_cable_detect(ide_hwif_t *hwif)
  555. {
  556. struct pci_dev *dev = to_pci_dev(hwif->dev);
  557. unsigned long addr = siimage_selreg(hwif, 0);
  558. u8 ata66 = sil_ioread8(dev, addr);
  559. return (ata66 & 0x01) ? ATA_CBL_PATA80 : ATA_CBL_PATA40;
  560. }
  561. static const struct ide_port_ops sil_pata_port_ops = {
  562. .set_pio_mode = sil_set_pio_mode,
  563. .set_dma_mode = sil_set_dma_mode,
  564. .quirkproc = sil_quirkproc,
  565. .udma_filter = sil_pata_udma_filter,
  566. .cable_detect = sil_cable_detect,
  567. };
  568. static const struct ide_port_ops sil_sata_port_ops = {
  569. .set_pio_mode = sil_set_pio_mode,
  570. .set_dma_mode = sil_set_dma_mode,
  571. .reset_poll = sil_sata_reset_poll,
  572. .pre_reset = sil_sata_pre_reset,
  573. .quirkproc = sil_quirkproc,
  574. .udma_filter = sil_sata_udma_filter,
  575. .cable_detect = sil_cable_detect,
  576. };
  577. static const struct ide_dma_ops sil_dma_ops = {
  578. .dma_host_set = ide_dma_host_set,
  579. .dma_setup = ide_dma_setup,
  580. .dma_start = ide_dma_start,
  581. .dma_end = ide_dma_end,
  582. .dma_test_irq = siimage_dma_test_irq,
  583. .dma_timer_expiry = ide_dma_sff_timer_expiry,
  584. .dma_lost_irq = ide_dma_lost_irq,
  585. .dma_sff_read_status = ide_dma_sff_read_status,
  586. };
  587. #define DECLARE_SII_DEV(p_ops) \
  588. { \
  589. .name = DRV_NAME, \
  590. .init_chipset = init_chipset_siimage, \
  591. .init_iops = init_iops_siimage, \
  592. .port_ops = p_ops, \
  593. .dma_ops = &sil_dma_ops, \
  594. .pio_mask = ATA_PIO4, \
  595. .mwdma_mask = ATA_MWDMA2, \
  596. .udma_mask = ATA_UDMA6, \
  597. }
  598. static const struct ide_port_info siimage_chipsets[] __devinitdata = {
  599. /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
  600. /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
  601. };
  602. /**
  603. * siimage_init_one - PCI layer discovery entry
  604. * @dev: PCI device
  605. * @id: ident table entry
  606. *
  607. * Called by the PCI code when it finds an SiI680 or SiI3112 controller.
  608. * We then use the IDE PCI generic helper to do most of the work.
  609. */
  610. static int __devinit siimage_init_one(struct pci_dev *dev,
  611. const struct pci_device_id *id)
  612. {
  613. void __iomem *ioaddr = NULL;
  614. resource_size_t bar5 = pci_resource_start(dev, 5);
  615. unsigned long barsize = pci_resource_len(dev, 5);
  616. int rc;
  617. struct ide_port_info d;
  618. u8 idx = id->driver_data;
  619. u8 BA5_EN;
  620. d = siimage_chipsets[idx];
  621. if (idx) {
  622. static int first = 1;
  623. if (first) {
  624. printk(KERN_INFO DRV_NAME ": For full SATA support you "
  625. "should use the libata sata_sil module.\n");
  626. first = 0;
  627. }
  628. d.host_flags |= IDE_HFLAG_NO_ATAPI_DMA;
  629. }
  630. rc = pci_enable_device(dev);
  631. if (rc)
  632. return rc;
  633. pci_read_config_byte(dev, 0x8A, &BA5_EN);
  634. if ((BA5_EN & 0x01) || bar5) {
  635. /*
  636. * Drop back to PIO if we can't map the MMIO. Some systems
  637. * seem to get terminally confused in the PCI spaces.
  638. */
  639. if (!request_mem_region(bar5, barsize, d.name)) {
  640. printk(KERN_WARNING DRV_NAME " %s: MMIO ports not "
  641. "available\n", pci_name(dev));
  642. } else {
  643. ioaddr = pci_ioremap_bar(dev, 5);
  644. if (ioaddr == NULL)
  645. release_mem_region(bar5, barsize);
  646. }
  647. }
  648. rc = ide_pci_init_one(dev, &d, ioaddr);
  649. if (rc) {
  650. if (ioaddr) {
  651. iounmap(ioaddr);
  652. release_mem_region(bar5, barsize);
  653. }
  654. pci_disable_device(dev);
  655. }
  656. return rc;
  657. }
  658. static void __devexit siimage_remove(struct pci_dev *dev)
  659. {
  660. struct ide_host *host = pci_get_drvdata(dev);
  661. void __iomem *ioaddr = host->host_priv;
  662. ide_pci_remove(dev);
  663. if (ioaddr) {
  664. resource_size_t bar5 = pci_resource_start(dev, 5);
  665. unsigned long barsize = pci_resource_len(dev, 5);
  666. iounmap(ioaddr);
  667. release_mem_region(bar5, barsize);
  668. }
  669. pci_disable_device(dev);
  670. }
  671. static const struct pci_device_id siimage_pci_tbl[] = {
  672. { PCI_VDEVICE(CMD, PCI_DEVICE_ID_SII_680), 0 },
  673. #ifdef CONFIG_BLK_DEV_IDE_SATA
  674. { PCI_VDEVICE(CMD, PCI_DEVICE_ID_SII_3112), 1 },
  675. { PCI_VDEVICE(CMD, PCI_DEVICE_ID_SII_1210SA), 1 },
  676. #endif
  677. { 0, },
  678. };
  679. MODULE_DEVICE_TABLE(pci, siimage_pci_tbl);
  680. static struct pci_driver siimage_pci_driver = {
  681. .name = "SiI_IDE",
  682. .id_table = siimage_pci_tbl,
  683. .probe = siimage_init_one,
  684. .remove = __devexit_p(siimage_remove),
  685. .suspend = ide_pci_suspend,
  686. .resume = ide_pci_resume,
  687. };
  688. static int __init siimage_ide_init(void)
  689. {
  690. return ide_pci_register_driver(&siimage_pci_driver);
  691. }
  692. static void __exit siimage_ide_exit(void)
  693. {
  694. pci_unregister_driver(&siimage_pci_driver);
  695. }
  696. module_init(siimage_ide_init);
  697. module_exit(siimage_ide_exit);
  698. MODULE_AUTHOR("Andre Hedrick, Alan Cox");
  699. MODULE_DESCRIPTION("PCI driver module for SiI IDE");
  700. MODULE_LICENSE("GPL");