~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Linux/drivers/ide/ht6560b.c

Version: ~ [ 2.2.5 ] ~ [ 2.4.1 ] ~ [ 2.4.9 ] ~ [ 2.6.17.10 ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  *  linux/drivers/ide/ht6560b.c         Version 0.07    Feb  1, 2000
  3  *
  4  *  Copyright (C) 1995-2000  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  *  Version 0.05        PIO mode cycle timings auto-tune using bus-speed
 16  *
 17  *  Version 0.06        Prefetch mode now defaults no OFF. To set
 18  *                      prefetch mode OFF/ON use "hdparm -p8/-p9".
 19  *                      Unmask irq is disabled when prefetch mode
 20  *                      is enabled.
 21  *
 22  *  Version 0.07        Trying to fix CD-ROM detection problem.
 23  *                      "Prefetch" mode bit OFF for ide disks and
 24  *                      ON for anything else.
 25  *
 26  *
 27  *  HT-6560B EIDE-controller support
 28  *  To activate controller support use kernel parameter "ide0=ht6560b".
 29  *  Use hdparm utility to enable PIO mode support.
 30  *
 31  *  Author:    Mikko Ala-Fossi            <maf@iki.fi>
 32  *             Jan Evert van Grootheest   <janevert@iae.nl>
 33  *
 34  *  Try:  http://www.maf.iki.fi/~maf/ht6560b/
 35  */
 36 
 37 #define HT6560B_VERSION "v0.07"
 38 
 39 #undef REALLY_SLOW_IO           /* most systems can safely undef this */
 40 
 41 #include <linux/types.h>
 42 #include <linux/kernel.h>
 43 #include <linux/delay.h>
 44 #include <linux/timer.h>
 45 #include <linux/mm.h>
 46 #include <linux/ioport.h>
 47 #include <linux/blkdev.h>
 48 #include <linux/hdreg.h>
 49 #include <linux/ide.h>
 50 #include <linux/init.h>
 51 
 52 #include <asm/io.h>
 53 
 54 #include "ide_modes.h"
 55 
 56 /* #define DEBUG */  /* remove comments for DEBUG messages */
 57 
 58 /*
 59  * The special i/o-port that HT-6560B uses to configuration:
 60  *    bit0 (0x01): "1" selects secondary interface
 61  *    bit2 (0x04): "1" enables FIFO function
 62  *    bit5 (0x20): "1" enables prefetched data read function  (???)
 63  *
 64  * The special i/o-port that HT-6560A uses to configuration:
 65  *    bit0 (0x01): "1" selects secondary interface
 66  *    bit1 (0x02): "1" enables prefetched data read function
 67  *    bit2 (0x04): "" enables multi-master system            (?)
 68  *    bit3 (0x08): "1" 3 cycle time, "" 2 cycle time         (?)
 69  */
 70 #define HT_CONFIG_PORT    0x3e6
 71 #define HT_CONFIG(drivea) (byte)(((drivea)->drive_data & 0xff00) >> 8)
 72 /*
 73  * FIFO + PREFETCH (both a/b-model)
 74  */
 75 #define HT_CONFIG_DEFAULT 0x1c /* no prefetch */
 76 /* #define HT_CONFIG_DEFAULT 0x3c */ /* with prefetch */
 77 #define HT_SECONDARY_IF   0x01
 78 #define HT_PREFETCH_MODE  0x20
 79 
 80 /*
 81  * ht6560b Timing values:
 82  *
 83  * I reviewed some assembler source listings of htide drivers and found
 84  * out how they setup those cycle time interfacing values, as they at Holtek
 85  * call them. IDESETUP.COM that is supplied with the drivers figures out
 86  * optimal values and fetches those values to drivers. I found out that
 87  * they use IDE_SELECT_REG to fetch timings to the ide board right after
 88  * interface switching. After that it was quite easy to add code to
 89  * ht6560b.c.
 90  *
 91  * IDESETUP.COM gave me values 0x24, 0x45, 0xaa, 0xff that worked fine
 92  * for hda and hdc. But hdb needed higher values to work, so I guess
 93  * that sometimes it is necessary to give higher value than IDESETUP
 94  * gives.   [see cmd640.c for an extreme example of this. -ml]
 95  *
 96  * Perhaps I should explain something about these timing values:
 97  * The higher nibble of value is the Recovery Time  (rt) and the lower nibble
 98  * of the value is the Active Time  (at). Minimum value 2 is the fastest and
 99  * the maximum value 15 is the slowest. Default values should be 15 for both.
100  * So 0x24 means 2 for rt and 4 for at. Each of the drives should have
101  * both values, and IDESETUP gives automatically rt=15 st=15 for CDROMs or
102  * similar. If value is too small there will be all sorts of failures.
103  *
104  * Timing byte consists of
105  *      High nibble:  Recovery Cycle Time  (rt)
106  *           The valid values range from 2 to 15. The default is 15.
107  *
108  *      Low nibble:   Active Cycle Time    (at)
109  *           The valid values range from 2 to 15. The default is 15.
110  *
111  * You can obtain optimized timing values by running Holtek IDESETUP.COM
112  * for DOS. DOS drivers get their timing values from command line, where
113  * the first value is the Recovery Time and the second value is the
114  * Active Time for each drive. Smaller value gives higher speed.
115  * In case of failures you should probably fall back to a higher value.
116  */
117 #define HT_TIMING(drivea) (byte)((drivea)->drive_data & 0x00ff)
118 #define HT_TIMING_DEFAULT 0xff
119 
120 /*
121  * This routine handles interface switching for the peculiar hardware design
122  * on the F.G.I./Holtek HT-6560B VLB IDE interface.
123  * The HT-6560B can only enable one IDE port at a time, and requires a
124  * silly sequence (below) whenever we switch between primary and secondary.
125  */
126 
127 /*
128  * This routine is invoked from ide.c to prepare for access to a given drive.
129  */
130 static void ht6560b_selectproc (ide_drive_t *drive)
131 {
132         unsigned long flags;
133         static byte current_select = 0;
134         static byte current_timing = 0;
135         byte select, timing;
136         
137         __save_flags (flags);   /* local CPU only */
138         __cli();                /* local CPU only */
139         
140         select = HT_CONFIG(drive);
141         timing = HT_TIMING(drive);
142         
143         if (select != current_select || timing != current_timing) {
144                 current_select = select;
145                 current_timing = timing;
146                 if (drive->media != ide_disk || !drive->present)
147                         select |= HT_PREFETCH_MODE;
148                 (void) inb(HT_CONFIG_PORT);
149                 (void) inb(HT_CONFIG_PORT);
150                 (void) inb(HT_CONFIG_PORT);
151                 (void) inb(HT_CONFIG_PORT);
152                 outb(select, HT_CONFIG_PORT);
153                 /*
154                  * Set timing for this drive:
155                  */
156                 outb(timing, IDE_SELECT_REG);
157                 (void) inb(IDE_STATUS_REG);
158 #ifdef DEBUG
159                 printk("ht6560b: %s: select=%#x timing=%#x\n", drive->name, select, timing);
160 #endif
161         }
162         __restore_flags (flags);        /* local CPU only */
163 }
164 
165 /*
166  * Autodetection and initialization of ht6560b
167  */
168 static int __init try_to_init_ht6560b(void)
169 {
170         byte orig_value;
171         int i;
172         
173         /* Autodetect ht6560b */
174         if ((orig_value=inb(HT_CONFIG_PORT)) == 0xff)
175                 return 0;
176         
177         for (i=3;i>0;i--) {
178                 outb(0x00, HT_CONFIG_PORT);
179                 if (!( (~inb(HT_CONFIG_PORT)) & 0x3f )) {
180                         outb(orig_value, HT_CONFIG_PORT);
181                         return 0;
182                 }
183         }
184         outb(0x00, HT_CONFIG_PORT);
185         if ((~inb(HT_CONFIG_PORT))& 0x3f) {
186                 outb(orig_value, HT_CONFIG_PORT);
187                 return 0;
188         }
189         /*
190          * Ht6560b autodetected
191          */
192         outb(HT_CONFIG_DEFAULT, HT_CONFIG_PORT);
193         outb(HT_TIMING_DEFAULT, 0x1f6);  /* IDE_SELECT_REG */
194         (void) inb(0x1f7);               /* IDE_STATUS_REG */
195         
196         printk("\nht6560b " HT6560B_VERSION
197                ": chipset detected and initialized"
198 #ifdef DEBUG
199                " with debug enabled"
200 #endif
201                 );
202         return 1;
203 }
204 
205 static byte ht_pio2timings(ide_drive_t *drive, byte pio)
206 {
207         int active_time, recovery_time;
208         int active_cycles, recovery_cycles;
209         ide_pio_data_t d;
210         int bus_speed = system_bus_clock();
211         
212         if (pio) {
213                 pio = ide_get_best_pio_mode(drive, pio, 5, &d);
214                 
215                 /*
216                  *  Just like opti621.c we try to calculate the
217                  *  actual cycle time for recovery and activity
218                  *  according system bus speed.
219                  */
220                 active_time = ide_pio_timings[pio].active_time;
221                 recovery_time = d.cycle_time 
222                         - active_time
223                         - ide_pio_timings[pio].setup_time;
224                 /*
225                  *  Cycle times should be Vesa bus cycles
226                  */
227                 active_cycles   = (active_time   * bus_speed + 999) / 1000;
228                 recovery_cycles = (recovery_time * bus_speed + 999) / 1000;
229                 /*
230                  *  Upper and lower limits
231                  */
232                 if (active_cycles   < 2)  active_cycles   = 2;
233                 if (recovery_cycles < 2)  recovery_cycles = 2;
234                 if (active_cycles   > 15) active_cycles   = 15;
235                 if (recovery_cycles > 15) recovery_cycles = 0;  /* 0==16 */
236                 
237 #ifdef DEBUG
238                 printk("ht6560b: drive %s setting pio=%d recovery=%d (%dns) active=%d (%dns)\n", drive->name, pio, recovery_cycles, recovery_time, active_cycles, active_time);
239 #endif
240                 
241                 return (byte)((recovery_cycles << 4) | active_cycles);
242         } else {
243                 
244 #ifdef DEBUG
245                 printk("ht6560b: drive %s setting pio=0\n", drive->name);
246 #endif
247                 
248                 return HT_TIMING_DEFAULT;    /* default setting */
249         }
250 }
251 
252 /*
253  *  Enable/Disable so called prefetch mode
254  */
255 static void ht_set_prefetch(ide_drive_t *drive, byte state)
256 {
257         unsigned long flags;
258         int t = HT_PREFETCH_MODE << 8;
259         
260         save_flags (flags);     /* all CPUs */
261         cli();                  /* all CPUs */
262         
263         /*
264          *  Prefetch mode and unmask irq seems to conflict
265          */
266         if (state) {
267                 drive->drive_data |= t;   /* enable prefetch mode */
268                 drive->no_unmask = 1;
269                 drive->unmask = 0;
270         } else {
271                 drive->drive_data &= ~t;  /* disable prefetch mode */
272                 drive->no_unmask = 0;
273         }
274         
275         restore_flags (flags);  /* all CPUs */
276         
277 #ifdef DEBUG
278         printk("ht6560b: drive %s prefetch mode %sabled\n", drive->name, (state ? "en" : "dis"));
279 #endif
280 }
281 
282 static void tune_ht6560b (ide_drive_t *drive, byte pio)
283 {
284         unsigned long flags;
285         byte timing;
286         
287         switch (pio) {
288         case 8:         /* set prefetch off */
289         case 9:         /* set prefetch on */
290                 ht_set_prefetch(drive, pio & 1);
291                 return;
292         }
293         
294         timing = ht_pio2timings(drive, pio);
295         
296         save_flags (flags);     /* all CPUs */
297         cli();                  /* all CPUs */
298         
299         drive->drive_data &= 0xff00;
300         drive->drive_data |= timing;
301         
302         restore_flags (flags);  /* all CPUs */
303         
304 #ifdef DEBUG
305         printk("ht6560b: drive %s tuned to pio mode %#x timing=%#x\n", drive->name, pio, timing);
306 #endif
307 }
308 
309 void __init init_ht6560b (void)
310 {
311         int t;
312         
313         if (check_region(HT_CONFIG_PORT,1)) {
314                 printk(KERN_ERR "ht6560b: PORT %#x ALREADY IN USE\n", HT_CONFIG_PORT);
315         } else {
316                 if (try_to_init_ht6560b()) {
317                         request_region(HT_CONFIG_PORT, 1, ide_hwifs[0].name);
318                         ide_hwifs[0].chipset = ide_ht6560b;
319                         ide_hwifs[1].chipset = ide_ht6560b;
320                         ide_hwifs[0].selectproc = &ht6560b_selectproc;
321                         ide_hwifs[1].selectproc = &ht6560b_selectproc;
322                         ide_hwifs[0].tuneproc = &tune_ht6560b;
323                         ide_hwifs[1].tuneproc = &tune_ht6560b;
324                         ide_hwifs[0].serialized = 1;  /* is this needed? */
325                         ide_hwifs[1].serialized = 1;  /* is this needed? */
326                         ide_hwifs[0].mate = &ide_hwifs[1];
327                         ide_hwifs[1].mate = &ide_hwifs[0];
328                         ide_hwifs[1].channel = 1;
329                         
330                         /*
331                          * Setting default configurations for drives
332                          */
333                         t = (HT_CONFIG_DEFAULT << 8);
334                         t |= HT_TIMING_DEFAULT;
335                         ide_hwifs[0].drives[0].drive_data = t;
336                         ide_hwifs[0].drives[1].drive_data = t;
337                         t |= (HT_SECONDARY_IF << 8);
338                         ide_hwifs[1].drives[0].drive_data = t;
339                         ide_hwifs[1].drives[1].drive_data = t;
340                 } else
341                         printk(KERN_ERR "ht6560b: not found\n");
342         }
343 }
344 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.