root/drivers/block/ht6560b.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. ht6560b_selectproc
  2. try_to_init_ht6560b
  3. tune_ht6560b
  4. init_ht6560b

   1 /*
   2  *  linux/drivers/block/ht6580.c       Version 0.03  Feb 09, 1996
   3  *
   4  *  Copyright (C) 1995-1996  Linus Torvalds & author (see below)
   5  */
   6 
   7 /*
   8  *
   9  *  Version 0.01        Initial version hacked out of ide.c
  10  *
  11  *  Version 0.02        Added support for PIO modes, auto-tune
  12  *
  13  *  Version 0.03        Some cleanups
  14  *
  15  * I reviewed some assembler sourcer listings of htide drivers and found
  16  * out how they setup those cycle time interfacing values, as they at Holtek
  17  * call them. IDESETUP.COM that is supplied with the drivers figures out
  18  * optimal values and fetches those values to drivers. I found out that
  19  * they use IDE_SELECT_REG to fetch timings to the ide board right after
  20  * interface switching. After that it was quite easy to add code to
  21  * ht6560b.c.
  22  *
  23  * IDESETUP.COM gave me values 0x24, 0x45, 0xaa, 0xff that worked fine
  24  * for hda and hdc. But hdb needed higher values to work, so I guess
  25  * that sometimes it is necessary to give higher value than IDESETUP
  26  * gives.   [see cmd640.c for an extreme example of this. -ml]
  27  *
  28  * Perhaps I should explain something about these timing values:
  29  * The higher nibble of value is the Recovery Time  (rt) and the lower nibble
  30  * of the value is the Active Time  (at). Minimum value 2 is the fastest and
  31  * the maximum value 15 is the slowest. Default values should be 15 for both.
  32  * So 0x24 means 2 for rt and 4 for at. Each of the drives should have
  33  * both values, and IDESETUP gives automatically rt=15 st=15 for cdroms or
  34  * similar. If value is too small there will be all sorts of failures.
  35  *
  36  * Port 0x3e6 bit 0x20 sets these timings on/off. If 0x20 bit is set
  37  * these timings are disabled.
  38  *
  39  * Mikko Ala-Fossi
  40  *
  41  * More notes:
  42  *
  43  * There's something still missing from the initialization code, though.
  44  * If I have booted to dos sometime after power on, I can get smaller
  45  * timing values working. Perhaps I could soft-ice the initialization.
  46  *
  47  * OS/2 driver seems to use some kind of DMA. But that code is really
  48  * messy to me to found out how.
  49  *
  50  * -=- malafoss@snakemail.hut.fi -=- searching the marvels of universe -=-
  51  */
  52 
  53 #undef REALLY_SLOW_IO           /* most systems can safely undef this */
  54 
  55 #include <linux/types.h>
  56 #include <linux/kernel.h>
  57 #include <linux/delay.h>
  58 #include <linux/timer.h>
  59 #include <linux/mm.h>
  60 #include <linux/ioport.h>
  61 #include <linux/blkdev.h>
  62 #include <linux/hdreg.h>
  63 #include <asm/io.h>
  64 #include "ide.h"
  65 #include "ide_modes.h"
  66 
  67 /*
  68  * This routine handles interface switching for the peculiar hardware design
  69  * on the F.G.I./Holtek HT-6560B VLB IDE interface.
  70  * The HT-6560B can only enable one IDE port at a time, and requires a
  71  * silly sequence (below) whenever we switch between primary and secondary.
  72  *
  73  * This stuff is courtesy of malafoss@snakemail.hut.fi
  74  *
  75  * At least one user has reported that this code can confuse the floppy
  76  * controller and/or driver -- perhaps this should be changed to use
  77  * a read-modify-write sequence, so as not to disturb other bits in the reg?
  78  */
  79 
  80 /*
  81  * The special i/o-port that HT-6560B uses to select interfaces:
  82  */
  83 #define HT_SELECT_PORT     0x3e6
  84 
  85 /*
  86  * We don't know what all of the bits are for, but we *do* know about these:
  87  *      bit5 (0x20): "1" selects slower speed by disabling use of timing values
  88  *      bit0 (0x01): "1" selects second interface
  89  */
  90 static byte ht6560b_selects [2][MAX_DRIVES] = {{0x3c,0x3c}, {0x3d,0x3d}};
  91 
  92 /*
  93  * VLB ht6560b Timing values:
  94  *
  95  * Timing byte consists of
  96  *      High nibble:  Recovery Time  (rt)
  97  *           The valid values range from 2 to 15. The default is 15.
  98  *
  99  *      Low nibble:   Active Time    (at)
 100  *           The valid values range from 2 to 15. The default is 15.
 101  *
 102  * You can obtain optimized timing values by running Holtek IDESETUP.COM
 103  * for DOS. DOS drivers get their timing values from command line, where
 104  * the first value is the Recovery Time and the second value is the
 105  * Active Time for each drive. Smaller value gives higher speed.
 106  * In case of failures you should probably fall back to a higher value.
 107  *
 108  * Hopefully this example will make it clearer:
 109  *
 110  * DOS:    DEVICE=C:\bin\HTIDE\HTIDE.SYS /D0=2,4 /D1=4,5 /D2=10,10 /D3=15,15
 111  * Linux:  byte ht6560b_timings [][] = {{0x24, 0x45}, {0xaa, 0xff}};
 112  *
 113  * Note: There are no ioctls to change these values directly,
 114  * but settings can be approximated as PIO modes, using "hdparm":
 115  *
 116  * rc.local:  hdparm -p3 /dev/hda -p2 /dev/hdb -p1 /dev/hdc -p0 /dev/hdd
 117  */
 118 
 119 static byte ht6560b_timings [2][MAX_DRIVES] = {{0xff,0xff}, {0xff,0xff}};
 120 
 121 static byte pio_to_timings[6] = {0xff, 0xaa, 0x45, 0x24, 0x13, 0x12};
 122 
 123 /*
 124  * This routine is invoked from ide.c to prepare for access to a given drive.
 125  */
 126 static void ht6560b_selectproc (ide_drive_t *drive)
     /* [previous][next][first][last][top][bottom][index][help] */
 127 {
 128         byte t;
 129         unsigned long flags;
 130         static byte current_select = 0;
 131         static byte current_timing = 0;
 132         byte select = ht6560b_selects[HWIF(drive)->index][drive->select.b.unit];
 133         byte timing = ht6560b_timings[HWIF(drive)->index][drive->select.b.unit];
 134 
 135         if (select != current_select || timing != current_timing) {
 136                 current_select = select;
 137                 current_timing = timing;
 138                 save_flags (flags);
 139                 cli();
 140                 (void) inb(HT_SELECT_PORT);
 141                 (void) inb(HT_SELECT_PORT);
 142                 (void) inb(HT_SELECT_PORT);
 143                 /*
 144                  * Note: input bits are reversed to output bits!!
 145                  */
 146                 t = inb(HT_SELECT_PORT) ^ 0x3f;
 147                 t &= (~0x21);
 148                 t |= (current_select & 0x21);
 149                 outb(t, HT_SELECT_PORT);
 150                 /*
 151                  * Set timing for this drive:
 152                  */
 153                 outb (timing, IDE_SELECT_REG);
 154                 (void) inb (IDE_STATUS_REG);
 155                 restore_flags (flags);
 156         }
 157 }
 158 
 159 /*
 160  * Autodetection and initialization of ht6560b
 161  */
 162 int try_to_init_ht6560b(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 163 {
 164         byte orig_value;
 165         int i;
 166 
 167         /* Autodetect ht6560b */
 168         if ((orig_value=inb(HT_SELECT_PORT)) == 0xff)
 169                 return 0;
 170 
 171         for (i=3;i>0;i--) {
 172                 outb(0x00, HT_SELECT_PORT);
 173                 if (!( (~inb(HT_SELECT_PORT)) & 0x3f )) {
 174                           outb(orig_value, HT_SELECT_PORT);
 175                           return 0;
 176                 }
 177         }
 178         outb(0x00, HT_SELECT_PORT);
 179         if ((~inb(HT_SELECT_PORT))& 0x3f) {
 180                 outb(orig_value, HT_SELECT_PORT);
 181                 return 0;
 182         }
 183         /*
 184          * Ht6560b autodetected:
 185          *     reverse input bits to output bits
 186          *     initialize bit1 to 0
 187          */
 188         outb((orig_value ^ 0x3f) & 0xfd, HT_SELECT_PORT);
 189 
 190         printk("\nht6560b: detected and initialized");
 191         return 1;
 192 }
 193 
 194 static void tune_ht6560b (ide_drive_t *drive, byte pio)
     /* [previous][next][first][last][top][bottom][index][help] */
 195 {
 196         unsigned int hwif, unit;
 197 
 198         if (pio == 255)  {      /* auto-tune */
 199                 if (drive->media != ide_disk)
 200                         pio = 0; /* some cdroms don't like fast modes (?) */
 201                 else
 202                         pio = ide_get_best_pio_mode (drive);
 203         }
 204         if (pio > 5)
 205                 pio = 5;
 206         unit = drive->select.b.unit;
 207         hwif = HWIF(drive)->index;
 208         ht6560b_timings[hwif][unit] = pio_to_timings[pio];
 209         if (pio == 0)
 210                 ht6560b_selects[hwif][unit] |= 0x20;
 211         else
 212                 ht6560b_selects[hwif][unit] &= ~0x20;
 213 }
 214 
 215 void init_ht6560b (void)
     /* [previous][next][first][last][top][bottom][index][help] */
 216 {
 217         if (check_region(HT_SELECT_PORT,1)) {
 218                 printk("\nht6560b: PORT 0x3e6 ALREADY IN USE\n");
 219         } else {
 220                 if (try_to_init_ht6560b()) {
 221                         request_region(HT_SELECT_PORT, 1, ide_hwifs[0].name);
 222                         ide_hwifs[0].chipset = ide_ht6560b;
 223                         ide_hwifs[1].chipset = ide_ht6560b;
 224                         ide_hwifs[0].selectproc = &ht6560b_selectproc;
 225                         ide_hwifs[1].selectproc = &ht6560b_selectproc;
 226                         ide_hwifs[0].tuneproc = &tune_ht6560b;
 227                         ide_hwifs[1].tuneproc = &tune_ht6560b;
 228                         ide_hwifs[0].serialized = 1;
 229                 } else
 230                         printk("ht6560b: not found\n");
 231         }
 232 }

/* [previous][next][first][last][top][bottom][index][help] */