siimage.c 21 KB

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