umc8672.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. * Copyright (C) 1995-1996 Linus Torvalds & author (see below)
  3. */
  4. /*
  5. * Principal Author/Maintainer: PODIEN@hml2.atlas.de (Wolfram Podien)
  6. *
  7. * This file provides support for the advanced features
  8. * of the UMC 8672 IDE interface.
  9. *
  10. * Version 0.01 Initial version, hacked out of ide.c,
  11. * and #include'd rather than compiled separately.
  12. * This will get cleaned up in a subsequent release.
  13. *
  14. * Version 0.02 now configs/compiles separate from ide.c -ml
  15. * Version 0.03 enhanced auto-tune, fix display bug
  16. * Version 0.05 replace sti() with restore_flags() -ml
  17. * add detection of possible race condition -ml
  18. */
  19. /*
  20. * VLB Controller Support from
  21. * Wolfram Podien
  22. * Rohoefe 3
  23. * D28832 Achim
  24. * Germany
  25. *
  26. * To enable UMC8672 support there must a lilo line like
  27. * append="ide0=umc8672"...
  28. * To set the speed according to the abilities of the hardware there must be a
  29. * line like
  30. * #define UMC_DRIVE0 11
  31. * in the beginning of the driver, which sets the speed of drive 0 to 11 (there
  32. * are some lines present). 0 - 11 are allowed speed values. These values are
  33. * the results from the DOS speed test program supplied from UMC. 11 is the
  34. * highest speed (about PIO mode 3)
  35. */
  36. #define REALLY_SLOW_IO /* some systems can safely undef this */
  37. #include <linux/module.h>
  38. #include <linux/types.h>
  39. #include <linux/kernel.h>
  40. #include <linux/delay.h>
  41. #include <linux/timer.h>
  42. #include <linux/mm.h>
  43. #include <linux/ioport.h>
  44. #include <linux/blkdev.h>
  45. #include <linux/hdreg.h>
  46. #include <linux/ide.h>
  47. #include <linux/init.h>
  48. #include <asm/io.h>
  49. /*
  50. * Default speeds. These can be changed with "auto-tune" and/or hdparm.
  51. */
  52. #define UMC_DRIVE0 1 /* DOS measured drive speeds */
  53. #define UMC_DRIVE1 1 /* 0 to 11 allowed */
  54. #define UMC_DRIVE2 1 /* 11 = Fastest Speed */
  55. #define UMC_DRIVE3 1 /* In case of crash reduce speed */
  56. static u8 current_speeds[4] = {UMC_DRIVE0, UMC_DRIVE1, UMC_DRIVE2, UMC_DRIVE3};
  57. static const u8 pio_to_umc [5] = {0, 3, 7, 10, 11}; /* rough guesses */
  58. /* 0 1 2 3 4 5 6 7 8 9 10 11 */
  59. static const u8 speedtab [3][12] = {
  60. {0x0f, 0x0b, 0x02, 0x02, 0x02, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1},
  61. {0x03, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1},
  62. {0xff, 0xcb, 0xc0, 0x58, 0x36, 0x33, 0x23, 0x22, 0x21, 0x11, 0x10, 0x0}
  63. };
  64. static void out_umc(char port, char wert)
  65. {
  66. outb_p(port, 0x108);
  67. outb_p(wert, 0x109);
  68. }
  69. static inline u8 in_umc(char port)
  70. {
  71. outb_p(port, 0x108);
  72. return inb_p(0x109);
  73. }
  74. static void umc_set_speeds(u8 speeds[])
  75. {
  76. int i, tmp;
  77. outb_p(0x5A, 0x108); /* enable umc */
  78. out_umc(0xd7, (speedtab[0][speeds[2]] | (speedtab[0][speeds[3]]<<4)));
  79. out_umc(0xd6, (speedtab[0][speeds[0]] | (speedtab[0][speeds[1]]<<4)));
  80. tmp = 0;
  81. for (i = 3; i >= 0; i--)
  82. tmp = (tmp << 2) | speedtab[1][speeds[i]];
  83. out_umc(0xdc, tmp);
  84. for (i = 0; i < 4; i++) {
  85. out_umc(0xd0 + i, speedtab[2][speeds[i]]);
  86. out_umc(0xd8 + i, speedtab[2][speeds[i]]);
  87. }
  88. outb_p(0xa5, 0x108); /* disable umc */
  89. printk("umc8672: drive speeds [0 to 11]: %d %d %d %d\n",
  90. speeds[0], speeds[1], speeds[2], speeds[3]);
  91. }
  92. static void umc_set_pio_mode(ide_drive_t *drive, const u8 pio)
  93. {
  94. ide_hwif_t *hwif = drive->hwif;
  95. unsigned long flags;
  96. printk("%s: setting umc8672 to PIO mode%d (speed %d)\n",
  97. drive->name, pio, pio_to_umc[pio]);
  98. spin_lock_irqsave(&ide_lock, flags);
  99. if (hwif->mate && hwif->mate->hwgroup->handler) {
  100. printk(KERN_ERR "umc8672: other interface is busy: exiting tune_umc()\n");
  101. } else {
  102. current_speeds[drive->name[2] - 'a'] = pio_to_umc[pio];
  103. umc_set_speeds(current_speeds);
  104. }
  105. spin_unlock_irqrestore(&ide_lock, flags);
  106. }
  107. static const struct ide_port_info umc8672_port_info __initdata = {
  108. .chipset = ide_umc8672,
  109. .host_flags = IDE_HFLAG_NO_DMA | IDE_HFLAG_NO_AUTOTUNE,
  110. .pio_mask = ATA_PIO4,
  111. };
  112. static int __init umc8672_probe(void)
  113. {
  114. ide_hwif_t *hwif, *mate;
  115. unsigned long flags;
  116. static u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
  117. hw_regs_t hw[2];
  118. if (!request_region(0x108, 2, "umc8672")) {
  119. printk(KERN_ERR "umc8672: ports 0x108-0x109 already in use.\n");
  120. return 1;
  121. }
  122. local_irq_save(flags);
  123. outb_p(0x5A, 0x108); /* enable umc */
  124. if (in_umc (0xd5) != 0xa0) {
  125. local_irq_restore(flags);
  126. printk(KERN_ERR "umc8672: not found\n");
  127. release_region(0x108, 2);
  128. return 1;
  129. }
  130. outb_p(0xa5, 0x108); /* disable umc */
  131. umc_set_speeds(current_speeds);
  132. local_irq_restore(flags);
  133. memset(&hw, 0, sizeof(hw));
  134. ide_std_init_ports(&hw[0], 0x1f0, 0x3f6);
  135. hw[0].irq = 14;
  136. ide_std_init_ports(&hw[1], 0x170, 0x376);
  137. hw[1].irq = 15;
  138. hwif = ide_find_port();
  139. if (hwif) {
  140. ide_init_port_hw(hwif, &hw[0]);
  141. hwif->set_pio_mode = umc_set_pio_mode;
  142. idx[0] = hwif->index;
  143. }
  144. mate = ide_find_port();
  145. if (mate) {
  146. ide_init_port_hw(mate, &hw[1]);
  147. mate->set_pio_mode = umc_set_pio_mode;
  148. idx[1] = mate->index;
  149. }
  150. ide_device_add(idx, &umc8672_port_info);
  151. return 0;
  152. }
  153. int probe_umc8672;
  154. module_param_named(probe, probe_umc8672, bool, 0);
  155. MODULE_PARM_DESC(probe, "probe for UMC8672 chipset");
  156. static int __init umc8672_init(void)
  157. {
  158. if (probe_umc8672 == 0)
  159. goto out;
  160. if (umc8672_probe() == 0)
  161. return 0;;
  162. out:
  163. return -ENODEV;;
  164. }
  165. module_init(umc8672_init);
  166. MODULE_AUTHOR("Wolfram Podien");
  167. MODULE_DESCRIPTION("Support for UMC 8672 IDE chipset");
  168. MODULE_LICENSE("GPL");