umc8672.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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/ide.h>
  46. #include <linux/init.h>
  47. #include <asm/io.h>
  48. #define DRV_NAME "umc8672"
  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_hwif_t *hwif, ide_drive_t *drive)
  93. {
  94. ide_hwif_t *mate = hwif->mate;
  95. unsigned long uninitialized_var(flags);
  96. const u8 pio = drive->pio_mode - XFER_PIO_0;
  97. printk("%s: setting umc8672 to PIO mode%d (speed %d)\n",
  98. drive->name, pio, pio_to_umc[pio]);
  99. if (mate)
  100. spin_lock_irqsave(&mate->lock, flags);
  101. if (mate && mate->handler) {
  102. printk(KERN_ERR "umc8672: other interface is busy: exiting tune_umc()\n");
  103. } else {
  104. current_speeds[drive->name[2] - 'a'] = pio_to_umc[pio];
  105. umc_set_speeds(current_speeds);
  106. }
  107. if (mate)
  108. spin_unlock_irqrestore(&mate->lock, flags);
  109. }
  110. static const struct ide_port_ops umc8672_port_ops = {
  111. .set_pio_mode = umc_set_pio_mode,
  112. };
  113. static const struct ide_port_info umc8672_port_info __initconst = {
  114. .name = DRV_NAME,
  115. .chipset = ide_umc8672,
  116. .port_ops = &umc8672_port_ops,
  117. .host_flags = IDE_HFLAG_NO_DMA,
  118. .pio_mask = ATA_PIO4,
  119. };
  120. static int __init umc8672_probe(void)
  121. {
  122. unsigned long flags;
  123. if (!request_region(0x108, 2, "umc8672")) {
  124. printk(KERN_ERR "umc8672: ports 0x108-0x109 already in use.\n");
  125. return 1;
  126. }
  127. local_irq_save(flags);
  128. outb_p(0x5A, 0x108); /* enable umc */
  129. if (in_umc (0xd5) != 0xa0) {
  130. local_irq_restore(flags);
  131. printk(KERN_ERR "umc8672: not found\n");
  132. release_region(0x108, 2);
  133. return 1;
  134. }
  135. outb_p(0xa5, 0x108); /* disable umc */
  136. umc_set_speeds(current_speeds);
  137. local_irq_restore(flags);
  138. return ide_legacy_device_add(&umc8672_port_info, 0);
  139. }
  140. static bool probe_umc8672;
  141. module_param_named(probe, probe_umc8672, bool, 0);
  142. MODULE_PARM_DESC(probe, "probe for UMC8672 chipset");
  143. static int __init umc8672_init(void)
  144. {
  145. if (probe_umc8672 == 0)
  146. goto out;
  147. if (umc8672_probe() == 0)
  148. return 0;
  149. out:
  150. return -ENODEV;
  151. }
  152. module_init(umc8672_init);
  153. MODULE_AUTHOR("Wolfram Podien");
  154. MODULE_DESCRIPTION("Support for UMC 8672 IDE chipset");
  155. MODULE_LICENSE("GPL");