siimage.c 23 KB

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