dtc2278.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /*
  2. * Copyright (C) 1996 Linus Torvalds & author (see below)
  3. */
  4. #include <linux/module.h>
  5. #include <linux/types.h>
  6. #include <linux/kernel.h>
  7. #include <linux/delay.h>
  8. #include <linux/timer.h>
  9. #include <linux/mm.h>
  10. #include <linux/ioport.h>
  11. #include <linux/blkdev.h>
  12. #include <linux/hdreg.h>
  13. #include <linux/ide.h>
  14. #include <linux/init.h>
  15. #include <asm/io.h>
  16. /*
  17. * Changing this #undef to #define may solve start up problems in some systems.
  18. */
  19. #undef ALWAYS_SET_DTC2278_PIO_MODE
  20. /*
  21. * From: andy@cercle.cts.com (Dyan Wile)
  22. *
  23. * Below is a patch for DTC-2278 - alike software-programmable controllers
  24. * The code enables the secondary IDE controller and the PIO4 (3?) timings on
  25. * the primary (EIDE). You may probably have to enable the 32-bit support to
  26. * get the full speed. You better get the disk interrupts disabled ( hdparm -u0
  27. * /dev/hd.. ) for the drives connected to the EIDE interface. (I get my
  28. * filesystem corrupted with -u1, but under heavy disk load only :-)
  29. *
  30. * This card is now forced to use the "serialize" feature,
  31. * and irq-unmasking is disallowed. If io_32bit is enabled,
  32. * it must be done for BOTH drives on each interface.
  33. *
  34. * This code was written for the DTC2278E, but might work with any of these:
  35. *
  36. * DTC2278S has only a single IDE interface.
  37. * DTC2278D has two IDE interfaces and is otherwise identical to the S version.
  38. * DTC2278E also has serial ports and a printer port
  39. * DTC2278EB: has onboard BIOS, and "works like a charm" -- Kent Bradford <kent@theory.caltech.edu>
  40. *
  41. * There may be a fourth controller type. The S and D versions use the
  42. * Winbond chip, and I think the E version does also.
  43. *
  44. */
  45. static void sub22 (char b, char c)
  46. {
  47. int i;
  48. for(i = 0; i < 3; ++i) {
  49. inb(0x3f6);
  50. outb_p(b,0xb0);
  51. inb(0x3f6);
  52. outb_p(c,0xb4);
  53. inb(0x3f6);
  54. if(inb(0xb4) == c) {
  55. outb_p(7,0xb0);
  56. inb(0x3f6);
  57. return; /* success */
  58. }
  59. }
  60. }
  61. static DEFINE_SPINLOCK(dtc2278_lock);
  62. static void dtc2278_set_pio_mode(ide_drive_t *drive, const u8 pio)
  63. {
  64. unsigned long flags;
  65. if (pio >= 3) {
  66. spin_lock_irqsave(&dtc2278_lock, flags);
  67. /*
  68. * This enables PIO mode4 (3?) on the first interface
  69. */
  70. sub22(1,0xc3);
  71. sub22(0,0xa0);
  72. spin_unlock_irqrestore(&dtc2278_lock, flags);
  73. } else {
  74. /* we don't know how to set it back again.. */
  75. /* Actually we do - there is a data sheet available for the
  76. Winbond but does anyone actually care */
  77. }
  78. }
  79. static const struct ide_port_info dtc2278_port_info __initdata = {
  80. .chipset = ide_dtc2278,
  81. .host_flags = IDE_HFLAG_SERIALIZE |
  82. IDE_HFLAG_NO_UNMASK_IRQS |
  83. IDE_HFLAG_IO_32BIT |
  84. /* disallow ->io_32bit changes */
  85. IDE_HFLAG_NO_IO_32BIT |
  86. IDE_HFLAG_NO_DMA |
  87. IDE_HFLAG_NO_AUTOTUNE,
  88. .pio_mask = ATA_PIO4,
  89. };
  90. static int __init dtc2278_probe(void)
  91. {
  92. unsigned long flags;
  93. ide_hwif_t *hwif, *mate;
  94. static u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
  95. hw_regs_t hw[2];
  96. local_irq_save(flags);
  97. /*
  98. * This enables the second interface
  99. */
  100. outb_p(4,0xb0);
  101. inb(0x3f6);
  102. outb_p(0x20,0xb4);
  103. inb(0x3f6);
  104. #ifdef ALWAYS_SET_DTC2278_PIO_MODE
  105. /*
  106. * This enables PIO mode4 (3?) on the first interface
  107. * and may solve start-up problems for some people.
  108. */
  109. sub22(1,0xc3);
  110. sub22(0,0xa0);
  111. #endif
  112. local_irq_restore(flags);
  113. memset(&hw, 0, sizeof(hw));
  114. ide_std_init_ports(&hw[0], 0x1f0, 0x3f6);
  115. hw[0].irq = 14;
  116. ide_std_init_ports(&hw[1], 0x170, 0x376);
  117. hw[1].irq = 15;
  118. hwif = ide_find_port();
  119. if (hwif) {
  120. ide_init_port_hw(hwif, &hw[0]);
  121. hwif->set_pio_mode = dtc2278_set_pio_mode;
  122. idx[0] = hwif->index;
  123. }
  124. mate = ide_find_port();
  125. if (mate) {
  126. ide_init_port_hw(mate, &hw[1]);
  127. idx[1] = mate->index;
  128. }
  129. ide_device_add(idx, &dtc2278_port_info);
  130. return 0;
  131. }
  132. int probe_dtc2278 = 0;
  133. module_param_named(probe, probe_dtc2278, bool, 0);
  134. MODULE_PARM_DESC(probe, "probe for DTC2278xx chipsets");
  135. static int __init dtc2278_init(void)
  136. {
  137. if (probe_dtc2278 == 0)
  138. return -ENODEV;
  139. if (dtc2278_probe()) {
  140. printk(KERN_ERR "dtc2278: ide interfaces already in use!\n");
  141. return -EBUSY;
  142. }
  143. return 0;
  144. }
  145. module_init(dtc2278_init);
  146. MODULE_AUTHOR("See Local File");
  147. MODULE_DESCRIPTION("support of DTC-2278 VLB IDE chipsets");
  148. MODULE_LICENSE("GPL");