pdc202xx_old.c 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. /*
  2. * Copyright (C) 1998-2002 Andre Hedrick <andre@linux-ide.org>
  3. * Copyright (C) 2006-2007, 2009 MontaVista Software, Inc.
  4. * Copyright (C) 2007 Bartlomiej Zolnierkiewicz
  5. *
  6. * Portions Copyright (C) 1999 Promise Technology, Inc.
  7. * Author: Frank Tiernan (frankt@promise.com)
  8. * Released under terms of General Public License
  9. */
  10. #include <linux/types.h>
  11. #include <linux/module.h>
  12. #include <linux/kernel.h>
  13. #include <linux/delay.h>
  14. #include <linux/blkdev.h>
  15. #include <linux/pci.h>
  16. #include <linux/init.h>
  17. #include <linux/ide.h>
  18. #include <asm/io.h>
  19. #define DRV_NAME "pdc202xx_old"
  20. #define PDC202XX_DEBUG_DRIVE_INFO 0
  21. static void pdc_old_disable_66MHz_clock(ide_hwif_t *);
  22. static void pdc202xx_set_mode(ide_drive_t *drive, const u8 speed)
  23. {
  24. ide_hwif_t *hwif = drive->hwif;
  25. struct pci_dev *dev = to_pci_dev(hwif->dev);
  26. u8 drive_pci = 0x60 + (drive->dn << 2);
  27. u8 AP = 0, BP = 0, CP = 0;
  28. u8 TA = 0, TB = 0, TC = 0;
  29. #if PDC202XX_DEBUG_DRIVE_INFO
  30. u32 drive_conf = 0;
  31. pci_read_config_dword(dev, drive_pci, &drive_conf);
  32. #endif
  33. /*
  34. * TODO: do this once per channel
  35. */
  36. if (dev->device != PCI_DEVICE_ID_PROMISE_20246)
  37. pdc_old_disable_66MHz_clock(hwif);
  38. pci_read_config_byte(dev, drive_pci, &AP);
  39. pci_read_config_byte(dev, drive_pci + 1, &BP);
  40. pci_read_config_byte(dev, drive_pci + 2, &CP);
  41. switch(speed) {
  42. case XFER_UDMA_5:
  43. case XFER_UDMA_4: TB = 0x20; TC = 0x01; break;
  44. case XFER_UDMA_2: TB = 0x20; TC = 0x01; break;
  45. case XFER_UDMA_3:
  46. case XFER_UDMA_1: TB = 0x40; TC = 0x02; break;
  47. case XFER_UDMA_0:
  48. case XFER_MW_DMA_2: TB = 0x60; TC = 0x03; break;
  49. case XFER_MW_DMA_1: TB = 0x60; TC = 0x04; break;
  50. case XFER_MW_DMA_0: TB = 0xE0; TC = 0x0F; break;
  51. case XFER_PIO_4: TA = 0x01; TB = 0x04; break;
  52. case XFER_PIO_3: TA = 0x02; TB = 0x06; break;
  53. case XFER_PIO_2: TA = 0x03; TB = 0x08; break;
  54. case XFER_PIO_1: TA = 0x05; TB = 0x0C; break;
  55. case XFER_PIO_0:
  56. default: TA = 0x09; TB = 0x13; break;
  57. }
  58. if (speed < XFER_SW_DMA_0) {
  59. /*
  60. * preserve SYNC_INT / ERDDY_EN bits while clearing
  61. * Prefetch_EN / IORDY_EN / PA[3:0] bits of register A
  62. */
  63. AP &= ~0x3f;
  64. if (ata_id_iordy_disable(drive->id))
  65. AP |= 0x20; /* set IORDY_EN bit */
  66. if (drive->media == ide_disk)
  67. AP |= 0x10; /* set Prefetch_EN bit */
  68. /* clear PB[4:0] bits of register B */
  69. BP &= ~0x1f;
  70. pci_write_config_byte(dev, drive_pci, AP | TA);
  71. pci_write_config_byte(dev, drive_pci + 1, BP | TB);
  72. } else {
  73. /* clear MB[2:0] bits of register B */
  74. BP &= ~0xe0;
  75. /* clear MC[3:0] bits of register C */
  76. CP &= ~0x0f;
  77. pci_write_config_byte(dev, drive_pci + 1, BP | TB);
  78. pci_write_config_byte(dev, drive_pci + 2, CP | TC);
  79. }
  80. #if PDC202XX_DEBUG_DRIVE_INFO
  81. printk(KERN_DEBUG "%s: %s drive%d 0x%08x ",
  82. drive->name, ide_xfer_verbose(speed),
  83. drive->dn, drive_conf);
  84. pci_read_config_dword(dev, drive_pci, &drive_conf);
  85. printk("0x%08x\n", drive_conf);
  86. #endif
  87. }
  88. static void pdc202xx_set_pio_mode(ide_drive_t *drive, const u8 pio)
  89. {
  90. pdc202xx_set_mode(drive, XFER_PIO_0 + pio);
  91. }
  92. static u8 pdc2026x_cable_detect(ide_hwif_t *hwif)
  93. {
  94. struct pci_dev *dev = to_pci_dev(hwif->dev);
  95. u16 CIS, mask = hwif->channel ? (1 << 11) : (1 << 10);
  96. pci_read_config_word(dev, 0x50, &CIS);
  97. return (CIS & mask) ? ATA_CBL_PATA40 : ATA_CBL_PATA80;
  98. }
  99. /*
  100. * Set the control register to use the 66MHz system
  101. * clock for UDMA 3/4/5 mode operation when necessary.
  102. *
  103. * FIXME: this register is shared by both channels, some locking is needed
  104. *
  105. * It may also be possible to leave the 66MHz clock on
  106. * and readjust the timing parameters.
  107. */
  108. static void pdc_old_enable_66MHz_clock(ide_hwif_t *hwif)
  109. {
  110. unsigned long clock_reg = hwif->extra_base + 0x01;
  111. u8 clock = inb(clock_reg);
  112. outb(clock | (hwif->channel ? 0x08 : 0x02), clock_reg);
  113. }
  114. static void pdc_old_disable_66MHz_clock(ide_hwif_t *hwif)
  115. {
  116. unsigned long clock_reg = hwif->extra_base + 0x01;
  117. u8 clock = inb(clock_reg);
  118. outb(clock & ~(hwif->channel ? 0x08 : 0x02), clock_reg);
  119. }
  120. static void pdc202xx_dma_start(ide_drive_t *drive)
  121. {
  122. if (drive->current_speed > XFER_UDMA_2)
  123. pdc_old_enable_66MHz_clock(drive->hwif);
  124. if (drive->media != ide_disk || (drive->dev_flags & IDE_DFLAG_LBA48)) {
  125. ide_hwif_t *hwif = drive->hwif;
  126. struct request *rq = hwif->rq;
  127. unsigned long high_16 = hwif->extra_base - 16;
  128. unsigned long atapi_reg = high_16 + (hwif->channel ? 0x24 : 0x20);
  129. u32 word_count = 0;
  130. u8 clock = inb(high_16 + 0x11);
  131. outb(clock | (hwif->channel ? 0x08 : 0x02), high_16 + 0x11);
  132. word_count = (blk_rq_sectors(rq) << 8);
  133. word_count = (rq_data_dir(rq) == READ) ?
  134. word_count | 0x05000000 :
  135. word_count | 0x06000000;
  136. outl(word_count, atapi_reg);
  137. }
  138. ide_dma_start(drive);
  139. }
  140. static int pdc202xx_dma_end(ide_drive_t *drive)
  141. {
  142. if (drive->media != ide_disk || (drive->dev_flags & IDE_DFLAG_LBA48)) {
  143. ide_hwif_t *hwif = drive->hwif;
  144. unsigned long high_16 = hwif->extra_base - 16;
  145. unsigned long atapi_reg = high_16 + (hwif->channel ? 0x24 : 0x20);
  146. u8 clock = 0;
  147. outl(0, atapi_reg); /* zero out extra */
  148. clock = inb(high_16 + 0x11);
  149. outb(clock & ~(hwif->channel ? 0x08:0x02), high_16 + 0x11);
  150. }
  151. if (drive->current_speed > XFER_UDMA_2)
  152. pdc_old_disable_66MHz_clock(drive->hwif);
  153. return ide_dma_end(drive);
  154. }
  155. static int init_chipset_pdc202xx(struct pci_dev *dev)
  156. {
  157. unsigned long dmabase = pci_resource_start(dev, 4);
  158. u8 udma_speed_flag = 0, primary_mode = 0, secondary_mode = 0;
  159. if (dmabase == 0)
  160. goto out;
  161. udma_speed_flag = inb(dmabase | 0x1f);
  162. primary_mode = inb(dmabase | 0x1a);
  163. secondary_mode = inb(dmabase | 0x1b);
  164. printk(KERN_INFO "%s: (U)DMA Burst Bit %sABLED " \
  165. "Primary %s Mode " \
  166. "Secondary %s Mode.\n", pci_name(dev),
  167. (udma_speed_flag & 1) ? "EN" : "DIS",
  168. (primary_mode & 1) ? "MASTER" : "PCI",
  169. (secondary_mode & 1) ? "MASTER" : "PCI" );
  170. if (!(udma_speed_flag & 1)) {
  171. printk(KERN_INFO "%s: FORCING BURST BIT 0x%02x->0x%02x ",
  172. pci_name(dev), udma_speed_flag,
  173. (udma_speed_flag|1));
  174. outb(udma_speed_flag | 1, dmabase | 0x1f);
  175. printk("%sACTIVE\n", (inb(dmabase | 0x1f) & 1) ? "" : "IN");
  176. }
  177. out:
  178. return 0;
  179. }
  180. static void __devinit pdc202ata4_fixup_irq(struct pci_dev *dev,
  181. const char *name)
  182. {
  183. if ((dev->class >> 8) != PCI_CLASS_STORAGE_IDE) {
  184. u8 irq = 0, irq2 = 0;
  185. pci_read_config_byte(dev, PCI_INTERRUPT_LINE, &irq);
  186. /* 0xbc */
  187. pci_read_config_byte(dev, (PCI_INTERRUPT_LINE)|0x80, &irq2);
  188. if (irq != irq2) {
  189. pci_write_config_byte(dev,
  190. (PCI_INTERRUPT_LINE)|0x80, irq); /* 0xbc */
  191. printk(KERN_INFO "%s %s: PCI config space interrupt "
  192. "mirror fixed\n", name, pci_name(dev));
  193. }
  194. }
  195. }
  196. #define IDE_HFLAGS_PDC202XX \
  197. (IDE_HFLAG_ERROR_STOPS_FIFO | \
  198. IDE_HFLAG_OFF_BOARD)
  199. static const struct ide_port_ops pdc20246_port_ops = {
  200. .set_pio_mode = pdc202xx_set_pio_mode,
  201. .set_dma_mode = pdc202xx_set_mode,
  202. };
  203. static const struct ide_port_ops pdc2026x_port_ops = {
  204. .set_pio_mode = pdc202xx_set_pio_mode,
  205. .set_dma_mode = pdc202xx_set_mode,
  206. .cable_detect = pdc2026x_cable_detect,
  207. };
  208. static const struct ide_dma_ops pdc2026x_dma_ops = {
  209. .dma_host_set = ide_dma_host_set,
  210. .dma_setup = ide_dma_setup,
  211. .dma_start = pdc202xx_dma_start,
  212. .dma_end = pdc202xx_dma_end,
  213. .dma_test_irq = ide_dma_test_irq,
  214. .dma_lost_irq = ide_dma_lost_irq,
  215. .dma_timer_expiry = ide_dma_sff_timer_expiry,
  216. .dma_sff_read_status = ide_dma_sff_read_status,
  217. };
  218. #define DECLARE_PDC2026X_DEV(udma, sectors) \
  219. { \
  220. .name = DRV_NAME, \
  221. .init_chipset = init_chipset_pdc202xx, \
  222. .port_ops = &pdc2026x_port_ops, \
  223. .dma_ops = &pdc2026x_dma_ops, \
  224. .host_flags = IDE_HFLAGS_PDC202XX, \
  225. .pio_mask = ATA_PIO4, \
  226. .mwdma_mask = ATA_MWDMA2, \
  227. .udma_mask = udma, \
  228. .max_sectors = sectors, \
  229. }
  230. static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
  231. { /* 0: PDC20246 */
  232. .name = DRV_NAME,
  233. .init_chipset = init_chipset_pdc202xx,
  234. .port_ops = &pdc20246_port_ops,
  235. .dma_ops = &sff_dma_ops,
  236. .host_flags = IDE_HFLAGS_PDC202XX,
  237. .pio_mask = ATA_PIO4,
  238. .mwdma_mask = ATA_MWDMA2,
  239. .udma_mask = ATA_UDMA2,
  240. },
  241. /* 1: PDC2026{2,3} */
  242. DECLARE_PDC2026X_DEV(ATA_UDMA4, 0),
  243. /* 2: PDC2026{5,7}: UDMA5, limit LBA48 requests to 256 sectors */
  244. DECLARE_PDC2026X_DEV(ATA_UDMA5, 256),
  245. };
  246. /**
  247. * pdc202xx_init_one - called when a PDC202xx is found
  248. * @dev: the pdc202xx device
  249. * @id: the matching pci id
  250. *
  251. * Called when the PCI registration layer (or the IDE initialization)
  252. * finds a device matching our IDE device tables.
  253. */
  254. static int __devinit pdc202xx_init_one(struct pci_dev *dev, const struct pci_device_id *id)
  255. {
  256. const struct ide_port_info *d;
  257. u8 idx = id->driver_data;
  258. d = &pdc202xx_chipsets[idx];
  259. if (idx < 2)
  260. pdc202ata4_fixup_irq(dev, d->name);
  261. if (dev->vendor == PCI_DEVICE_ID_PROMISE_20265) {
  262. struct pci_dev *bridge = dev->bus->self;
  263. if (bridge &&
  264. bridge->vendor == PCI_VENDOR_ID_INTEL &&
  265. (bridge->device == PCI_DEVICE_ID_INTEL_I960 ||
  266. bridge->device == PCI_DEVICE_ID_INTEL_I960RM)) {
  267. printk(KERN_INFO DRV_NAME " %s: skipping Promise "
  268. "PDC20265 attached to I2O RAID controller\n",
  269. pci_name(dev));
  270. return -ENODEV;
  271. }
  272. }
  273. return ide_pci_init_one(dev, d, NULL);
  274. }
  275. static const struct pci_device_id pdc202xx_pci_tbl[] = {
  276. { PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20246), 0 },
  277. { PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20262), 1 },
  278. { PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20263), 1 },
  279. { PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20265), 2 },
  280. { PCI_VDEVICE(PROMISE, PCI_DEVICE_ID_PROMISE_20267), 2 },
  281. { 0, },
  282. };
  283. MODULE_DEVICE_TABLE(pci, pdc202xx_pci_tbl);
  284. static struct pci_driver pdc202xx_pci_driver = {
  285. .name = "Promise_Old_IDE",
  286. .id_table = pdc202xx_pci_tbl,
  287. .probe = pdc202xx_init_one,
  288. .remove = ide_pci_remove,
  289. .suspend = ide_pci_suspend,
  290. .resume = ide_pci_resume,
  291. };
  292. static int __init pdc202xx_ide_init(void)
  293. {
  294. return ide_pci_register_driver(&pdc202xx_pci_driver);
  295. }
  296. static void __exit pdc202xx_ide_exit(void)
  297. {
  298. pci_unregister_driver(&pdc202xx_pci_driver);
  299. }
  300. module_init(pdc202xx_ide_init);
  301. module_exit(pdc202xx_ide_exit);
  302. MODULE_AUTHOR("Andre Hedrick, Frank Tiernan");
  303. MODULE_DESCRIPTION("PCI driver module for older Promise IDE");
  304. MODULE_LICENSE("GPL");