umc8672.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. {0xf, 0xb, 0x2, 0x2, 0x2, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1 },
  61. {0x3, 0x2, 0x2, 0x2, 0x2, 0x2, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1 },
  62. {0xff,0xcb,0xc0,0x58,0x36,0x33,0x23,0x22,0x21,0x11,0x10,0x0}};
  63. static void out_umc (char port,char wert)
  64. {
  65. outb_p(port,0x108);
  66. outb_p(wert,0x109);
  67. }
  68. static inline u8 in_umc (char port)
  69. {
  70. outb_p(port,0x108);
  71. return inb_p(0x109);
  72. }
  73. static void umc_set_speeds (u8 speeds[])
  74. {
  75. int i, tmp;
  76. outb_p(0x5A,0x108); /* enable umc */
  77. out_umc (0xd7,(speedtab[0][speeds[2]] | (speedtab[0][speeds[3]]<<4)));
  78. out_umc (0xd6,(speedtab[0][speeds[0]] | (speedtab[0][speeds[1]]<<4)));
  79. tmp = 0;
  80. for (i = 3; i >= 0; i--) {
  81. tmp = (tmp << 2) | speedtab[1][speeds[i]];
  82. }
  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. unsigned long flags;
  95. ide_hwgroup_t *hwgroup = ide_hwifs[HWIF(drive)->index^1].hwgroup;
  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 (hwgroup && hwgroup->handler != NULL) {
  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. unsigned long flags;
  115. static u8 idx[4] = { 0, 1, 0xff, 0xff };
  116. hw_regs_t hw[2];
  117. if (!request_region(0x108, 2, "umc8672")) {
  118. printk(KERN_ERR "umc8672: ports 0x108-0x109 already in use.\n");
  119. return 1;
  120. }
  121. local_irq_save(flags);
  122. outb_p(0x5A,0x108); /* enable umc */
  123. if (in_umc (0xd5) != 0xa0) {
  124. local_irq_restore(flags);
  125. printk(KERN_ERR "umc8672: not found\n");
  126. release_region(0x108, 2);
  127. return 1;
  128. }
  129. outb_p(0xa5,0x108); /* disable umc */
  130. umc_set_speeds (current_speeds);
  131. local_irq_restore(flags);
  132. memset(&hw, 0, sizeof(hw));
  133. ide_std_init_ports(&hw[0], 0x1f0, 0x3f6);
  134. hw[0].irq = 14;
  135. ide_std_init_ports(&hw[1], 0x170, 0x376);
  136. hw[1].irq = 15;
  137. ide_init_port_hw(&ide_hwifs[0], &hw[0]);
  138. ide_init_port_hw(&ide_hwifs[1], &hw[1]);
  139. ide_hwifs[0].set_pio_mode = &umc_set_pio_mode;
  140. ide_hwifs[1].set_pio_mode = &umc_set_pio_mode;
  141. ide_device_add(idx, &umc8672_port_info);
  142. return 0;
  143. }
  144. int probe_umc8672 = 0;
  145. module_param_named(probe, probe_umc8672, bool, 0);
  146. MODULE_PARM_DESC(probe, "probe for UMC8672 chipset");
  147. static int __init umc8672_init(void)
  148. {
  149. if (probe_umc8672 == 0)
  150. goto out;
  151. if (umc8672_probe() == 0)
  152. return 0;;
  153. out:
  154. return -ENODEV;;
  155. }
  156. module_init(umc8672_init);
  157. MODULE_AUTHOR("Wolfram Podien");
  158. MODULE_DESCRIPTION("Support for UMC 8672 IDE chipset");
  159. MODULE_LICENSE("GPL");