]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/i386/isa/alog.c
eliminated a previously unnoticde compile warning about use of
[FreeBSD/FreeBSD.git] / sys / i386 / isa / alog.c
1 /*
2  * Copyright (c) 1997 Jamil J. Weatherbee
3  * All rights reserved.
4  *
5  * 
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer
11  *    in this position and unchanged.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. The name of the author may not be used to endorse or promote products
16  *    derived from this software without specific prior written permission
17  * 
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  *
29  * Industrial Computer Source model AIO8-P
30  * 8 channel, moderate speed analog to digital converter board with
31  * 128 channel MUX capability via daisy chained AT-16P units
32  * alog.c, character device driver, last revised December 9 1997
33  * See http://www.indcompsrc.com/products/data/html/aio8g-p.html
34  *     http://www.indcompsrc.com/products/data/html/at16-p.html
35  *
36  * Written by: Jamil J. Weatherbee <jamil@freebsd.org>
37  *
38  */
39
40
41 /* Include Files */
42
43 #include "alog.h"
44 #if NALOG > 0
45
46 #include <sys/param.h> 
47 #include <sys/systm.h>
48 #include <sys/proc.h>
49 #include <sys/kernel.h>
50 #include <sys/conf.h>
51 #include <sys/fcntl.h>
52 #include <sys/malloc.h>
53 #include <sys/buf.h> 
54 #include <sys/poll.h>
55 #include <sys/vnode.h>
56 #include <sys/filio.h>
57 #include <machine/clock.h>
58 #include <i386/isa/isa.h>
59 #include <i386/isa/isa_device.h>
60 #include <sys/alogio.h>
61 #include <sys/dataacq.h>
62
63 #ifdef DEVFS
64 #include <sys/devfsext.h>
65 #endif 
66
67 /* Local Defines */
68
69 /* Tests have shown that increasing the fifo size 
70  * beyond 64 entries for this particular piece of hardware is
71  * unproductive */
72
73 #ifdef ALOG_FIFOSIZE
74 #define FIFOSIZE ALOG_FIFOSIZE
75 #else
76 #define FIFOSIZE 64
77 #endif
78
79 #ifdef ALOG_FIFO_TRIGGER
80 #define DEFAULT_FIFO_TRIGGER ALOG_FIFO_TRIGGER
81 #else
82 #define DEFAULT_FIFO_TRIGGER 1
83 #endif
84
85 #ifdef ALOG_CHANNELS 
86 #define NUMCHANNELS ALOG_CHANNELS
87 #else
88 #define NUMCHANNELS 128
89 #endif
90
91 #ifdef ALOG_TIMO
92 #define READTIMO ALOG_TIMO
93 #else
94 #define READTIMO (MAX_MICRO_PERIOD*NUMCHANNELS/500000*hz)
95 #endif
96
97 #define CDEV_MAJOR 86
98 #define NUMPORTS 8
99 #define MAXUNITS 2
100 #define NUMIMUXES 8
101
102 #define ADLOW 0x0
103 #define ADHIGH 0x1
104 #define STATUS 0x2
105 #define CNTR0 0x4
106 #define CNTR1 0x5
107 #define CNTR2 0x6
108 #define CNTRCNTRL 0x7
109
110 #define DEVFORMAT "alog%d%c%d"
111 #define CLOCK2FREQ 4.165
112 #define MIN_MICRO_PERIOD 25  
113 #define MAX_MICRO_PERIOD (65535/CLOCK2FREQ*PRIMARY_STATES)
114 #define DEFAULT_MICRO_PERIOD MAX_MICRO_PERIOD
115 #define READMAXTRIG 0.75*FIFOSIZE
116 #define ALOGPRI PRIBIO
117 #define ALOGMSG "alogio"
118
119 #define PRIMARY_STATES 2  /* Setup and conversion are clock tick consuming */
120 #define STATE_SETUP 0
121 #define STATE_CONVERT 1
122 #define STATE_READ 2
123
124 /* Notes on interrupt driven A/D conversion:
125  * On the AIO8-P, interrupt driven conversion (the only type supported by this
126  * driver) is facilitated through 8253 timer #2.  In order for interrrupts to
127  * be generated you must connect line 6 to line 24 (counter 2 output to 
128  * interrupt input) and line 23 to line 29 (counter 2 gate to +5VDC). 
129  * Due to the design of the AIO8-P this precludes the use of programmable 
130  * gain control.
131  */
132
133 /* mode bits for the status register */
134
135 #define EOC 0x80 
136 #define IEN 0x08  
137 #define IMUXMASK 0x07
138 #define EMUXMASK 0xf0
139
140 /* mode bits for counter controller */
141
142 #define LD2MODE4 0xb8
143
144 /* Minor allocations:
145  * UCCCCMMM
146  * U: board unit (0-1)
147  * CCCC: external multiplexer channel (0-15) (on AT-16P units)
148  * MMM: internal multiplexer channel (0-7) (on AIO8-P card)
149  */
150
151 #define UNIT(dev) ((minor(dev) & 0x80) >> 7)
152 #define CHANNEL(dev) (minor(dev) & 0x7f) 
153 #define EMUX(chan) ((chan & 0x78) >> 3)
154 #define EMUXMAKE(chan) ((chan & 0x78) << 1)
155 #define IMUX(chan) (chan & 0x07)
156 #define LMINOR(unit, chan) ((unit << 7)+chan)
157
158 /* port statuses */
159
160 #define STATUS_UNUSED 0 
161 #define STATUS_INUSE 1
162 #define STATUS_STOPPED 2
163 #define STATUS_INIT 3
164
165 /* Type definitions */
166
167 typedef struct
168 {
169   short status; /* the status of this chan */
170   struct selinfo readpoll; /* the poll() info */
171   u_short fifo[FIFOSIZE]; /* fifo for this chan */
172   int fifostart, fifoend; /* the ptrs showing where info is stored in fifo */
173   int fifosize, fifotrig; /* the current and trigger size of the fifo */
174   void *devfs_token; /* the devfs token for this chan */
175   int nextchan;  
176 } talog_chan;
177
178 typedef struct 
179
180   struct isa_device *isaunit; /* ptr to isa device information */     
181   talog_chan chan[NUMCHANNELS]; /* the device nodes */
182   int curchan; /* the current chan being intr handled */
183   int firstchan; /* the first chan to go to in list */
184   int state; /* is the node in setup or convert mode */ 
185   long microperiod; /* current microsecond period setting */ 
186   u_char perlo, perhi; /* current values to send to clock 2 after every intr */
187    
188 } talog_unit;
189
190 /* Function Prototypes */
191
192 static int alog_probe (struct isa_device *idp);  /* Check for alog board */
193 static int alog_attach (struct isa_device *idp);  /* Take alog board */
194 static int sync_clock2 (int unit, long period); /* setup clock 2 period */
195 static int putfifo (talog_chan *pchan, u_short fifoent);
196 static int alog_open (dev_t dev, int oflags, int devtype, struct proc *p);
197 static int alog_close (dev_t dev, int fflag, int devtype, struct proc *p);
198 static int alog_ioctl (dev_t dev, int cmd, caddr_t data,
199                         int fflag, struct proc *p);
200 static int alog_read (dev_t dev, struct uio *uio, int ioflag);
201 static int alog_poll (dev_t dev, int events, struct proc *p);
202
203 /* Global Data */
204
205 static int alog_devsw_installed = 0;  /* Protect against reinit multiunit */
206 static talog_unit *alog_unit[NALOG]; /* data structs for each unit */ 
207
208 /* Character device switching structure */
209 static struct cdevsw alog_cdevsw = { alog_open, alog_close, alog_read,
210                                      nowrite, alog_ioctl, nostop, noreset,
211                                      nodevtotty, alog_poll, nommap,
212                                      nostrategy, "alog", NULL, -1 };
213
214 /* Structure expected to tell how to probe and attach the driver
215  * Must be published externally (cannot be static) */
216 struct isa_driver alogdriver = { alog_probe, alog_attach, "alog", 0 };
217
218
219 /* handle the ioctls */
220 static int alog_ioctl (dev_t dev, int cmd, caddr_t data,
221                         int fflag, struct proc *p)
222 {
223   int unit = UNIT(dev);
224   int chan = CHANNEL(dev);
225   talog_unit *info = alog_unit[unit];
226   int s;
227    
228   switch (cmd)
229    {  
230     case FIONBIO: return 0; /* this allows for non-blocking ioctls */ 
231
232     case AD_NCHANS_GET: *(int *)data = NUMCHANNELS;
233                         return 0;
234     case AD_FIFOSIZE_GET: *(int *)data = FIFOSIZE;
235                           return 0;
236       
237     case AD_FIFO_TRIGGER_GET: s = spltty();
238                               *(int *)data = info->chan[chan].fifotrig;
239                               splx(s);
240                               return 0;
241       
242     case AD_FIFO_TRIGGER_SET: 
243                   s = spltty();
244                   if ((*(int *)data < 1) || (*(int *)data > FIFOSIZE))
245                    {   
246                      splx(s);
247                      return EPERM; 
248                    }
249                   info->chan[chan].fifotrig = *(int *)data;
250                   splx(s);
251                   return 0;
252       
253     case AD_STOP: s = spltty();
254                   info->chan[chan].status = STATUS_STOPPED;              
255                   splx(s);
256                   return 0;
257       
258     case AD_START: s = spltty();
259                    info->chan[chan].status = STATUS_INUSE;
260                    splx(s);
261                    return 0;
262
263     case AD_MICRO_PERIOD_SET: 
264                    s = spltty();
265                    if (sync_clock2 (unit, *(long *) data))
266                     {          
267                       splx(s);
268                       return EPERM;
269                     }
270                    splx(s);
271                    return 0;
272       
273     case AD_MICRO_PERIOD_GET: s = spltty();
274                               *(long *)data = info->microperiod;
275                               splx(s);
276                               return 0;    
277                               
278    }
279    
280   return ENOTTY;  
281 }
282
283
284 /* handle poll() based read polling */
285 static int alog_poll (dev_t dev, int events, struct proc *p)
286 {
287   int unit = UNIT(dev);
288   int chan = CHANNEL(dev);
289   talog_unit *info = alog_unit[unit];
290   int s;
291    
292   s = spltty();
293   if (events & (POLLIN | POLLRDNORM)) /* if polling for any/normal data */
294    if (info->chan[chan].fifosize >= info->chan[chan].fifotrig)
295     { 
296       splx(s);
297        
298       return events & (POLLIN | POLLRDNORM); /* ready for any/read */
299     }
300    else    
301     {
302       /* record this request */
303       selrecord (p, &(info->chan[chan].readpoll));
304       splx(s);
305       return 0; /* not ready, yet */
306     }
307      
308   splx(s);
309   return 0; /* not ready (any I never will be) */
310 }
311
312
313 /* how to read from the board */
314 static int alog_read (dev_t dev, struct uio *uio, int ioflag)
315 {
316   int unit = UNIT(dev);
317   int chan = CHANNEL(dev);
318   talog_unit *info = alog_unit[unit];
319   int s, oldtrig, toread, err = 0;
320
321   s = spltty();
322       
323   oldtrig = info->chan[chan].fifotrig; /* save official trigger value */   
324   while (uio->uio_resid >= sizeof(u_short)) /* while uio has space */
325    {
326      if (!info->chan[chan].fifosize) /* if we have an empty fifo */
327       {
328         if (ioflag & IO_NDELAY) /* exit if we are non-blocking */
329            { err = EWOULDBLOCK;
330              break; 
331            }
332         /* Start filling fifo on first blocking read */
333         if (info->chan[chan].status == STATUS_INIT)
334              info->chan[chan].status = STATUS_INUSE;     
335         /* temporarily adjust the fifo trigger to be optimal size */
336         info->chan[chan].fifotrig = 
337           min (READMAXTRIG, uio->uio_resid / sizeof(u_short));
338         /* lets sleep until we have some io available or timeout */
339         err = tsleep (&(info->chan[chan].fifo), ALOGPRI | PCATCH, ALOGMSG,
340                          info->chan[chan].fifotrig*READTIMO);
341         if (err == EWOULDBLOCK)
342          {    printf (DEVFORMAT ": read timeout\n", unit,
343                        'a'+EMUX(chan), IMUX(chan));         
344          }
345         if (err == ERESTART) err = EINTR; /* don't know how to restart */
346         if (err) break; /* exit if any kind of error or signal */
347       }
348          
349      /* ok, now if we got here there is something to read from the fifo */
350      
351      /* calculate how many entries we can read out from the fifostart
352       * pointer */ 
353      toread = min (uio->uio_resid / sizeof(u_short), 
354                    min (info->chan[chan].fifosize, 
355                          FIFOSIZE - info->chan[chan].fifostart));
356      /* perform the move, if there is an error then exit */
357      if (err = uiomove((caddr_t)
358                         &(info->chan[chan].fifo[info->chan[chan].fifostart]), 
359                            toread * sizeof(u_short), uio)) break;
360      info->chan[chan].fifosize -= toread; /* fifo this much smaller */ 
361      info->chan[chan].fifostart += toread; /* we got this many more */
362      if (info->chan[chan].fifostart == FIFOSIZE)
363        info->chan[chan].fifostart = 0; /* wrap around fifostart */
364       
365    }
366   info->chan[chan].fifotrig = oldtrig; /* restore trigger changes */
367   splx(s);                     
368   return err;
369 }
370
371    
372 /* open a channel */
373 static int alog_open (dev_t dev, int oflags, int devtype, struct proc *p)
374 {
375   int unit = UNIT(dev); /* get unit no */
376   int chan = CHANNEL(dev); /* get channel no */
377   talog_unit *info; 
378   int s; /* priority */
379   int cur;
380    
381   if ((unit >= NALOG) || (unit >= MAXUNITS) || (chan >= NUMCHANNELS))
382       return ENXIO; /* unit and channel no ok ? */
383   if (!alog_unit[unit]) return ENXIO; /* unit attached */
384   info = alog_unit[unit]; /* ok, this is valid now */
385   
386   if (info->chan[chan].status) return EBUSY; /* channel busy */
387   if (oflags & FREAD)
388    {
389      s=spltty();
390      info->chan[chan].status = STATUS_INIT; /* channel open, read waiting */
391      info->chan[chan].fifostart = info->chan[chan].fifoend =
392         info->chan[chan].fifosize = 0;/* fifo empty */
393      info->chan[chan].fifotrig = DEFAULT_FIFO_TRIGGER;
394      if (info->firstchan < 0) /* if empty chain */
395       {
396         info->firstchan = info->curchan = chan; /* rev up the list */
397         info->chan[chan].nextchan = -1; /* end of the list */
398       }
399      else /* non empty list must insert */
400       {  
401         if (chan < info->firstchan) /* this one must become first in list */
402          {
403            info->chan[chan].nextchan = info->firstchan;
404            info->firstchan = chan;  
405          }
406         else /* insert this one as second - last in chan list */
407          {
408            cur = info->firstchan;
409             
410            /* traverse list as long as cur is less than chan and cur is
411             * not last in list */
412            while ((info->chan[cur].nextchan < chan) && 
413                    (info->chan[cur].nextchan >= 0))
414              cur = info->chan[cur].nextchan; 
415            
416            /* now cur should point to the entry right before yours */
417            info->chan[chan].nextchan = info->chan[cur].nextchan;
418            info->chan[cur].nextchan = chan; /* insert yours in */
419          }
420       }
421      splx(s); 
422      return 0; /* open successful */  
423    }
424   return EPERM; /* this is a read only device */ 
425 }
426
427
428 /* close a channel */
429 static int alog_close (dev_t dev, int fflag, int devtype, struct proc *p)
430 {
431   int unit = UNIT(dev);
432   int chan = CHANNEL(dev);
433   talog_unit *info = alog_unit[unit];
434   int s;
435   int cur; 
436    
437   s = spltty();
438   info->chan[chan].status = STATUS_UNUSED; 
439   
440   /* what if we are in the middle of a conversion ?
441    * then smoothly get us out of it: */
442   if (info->curchan == chan)
443    { /* if we are last in list set curchan to first in list */
444      if ((info->curchan = info->chan[chan].nextchan) < 0)
445       info->curchan = info->firstchan;
446
447      info->state = STATE_SETUP;
448    }
449    
450   /* if this is the first channel, then make the second channel the first
451    * channel (note that if this is also the only channel firstchan becomes
452    * -1 and so the list is marked as empty */
453    
454   if (chan == info->firstchan) 
455    info->firstchan = info->chan[chan].nextchan;
456   else /* ok, so there must be at least 2 channels (and it is not the first) */
457    {  
458      cur = info->firstchan;
459
460      /* find the entry before it (which must exist if you are closing) */ 
461      while (info->chan[cur].nextchan < chan) 
462         cur = info->chan[cur].nextchan;
463      /* at this point we must have the entry before ours */
464      info->chan[cur].nextchan = info->chan[chan].nextchan; /* give our link */       
465    
466    }
467   
468   splx(s);
469    
470   return 0; /* close always successful */
471 }
472
473
474 /* The probing routine - returns number of bytes needed */
475 static int alog_probe (struct isa_device *idp)
476 {
477   int unit = idp->id_unit;  /* this device unit number */
478   int iobase = idp->id_iobase; /* the base address of the unit */
479   int addr; 
480    
481   if ((unit < 0) || (unit >= NALOG) || (unit >= MAXUNITS))
482    { 
483      printf ("alog: invalid unit number (%d)\n", unit);
484      return 0;
485    }
486    
487   /* the unit number is ok, lets check if used */
488   if (alog_unit[unit]) 
489    {
490      printf ("alog: unit (%d) already attached\n", unit);
491      return 0;
492    }
493
494   if (inb (iobase+STATUS) & EOC) return 0; /* End of conv bit should be 0 */
495   for (addr=0; addr<NUMIMUXES; addr++)
496    {
497      outb (iobase+STATUS, EMUXMASK|addr);/* output ones to upper nibbl+addr */ 
498      /* get back a zero in MSB and the addr where you put it */
499      if ((inb (iobase+STATUS) & (EOC|IMUXMASK)) != addr) return 0;
500    }
501  
502   return NUMPORTS; /* this device needs this many ports */ 
503 }
504
505
506 /* setup the info structure correctly for reloading clock 2 after interrupt */
507 static int sync_clock2 (int unit, long period)
508 {
509   int clockper;
510   talog_unit *info = alog_unit[unit];
511    
512   if ((period > MAX_MICRO_PERIOD) || (period < MIN_MICRO_PERIOD))
513      return -1; /* error period too long */
514   info->microperiod = period; /* record the period */   
515   clockper = (CLOCK2FREQ * period) / PRIMARY_STATES;
516   info->perlo = clockper & 0xff; /* least sig byte of clock period */
517   info->perhi = ((clockper & 0xff00) >> 8); /* most sig byte of clock period */
518   return 0;
519 }
520
521
522 /* The attachment routine - returns true on success */
523 static int alog_attach (struct isa_device *idp)
524 {
525   int unit = idp->id_unit;  /* this device unit number */   
526   int iobase = idp->id_iobase; /* the base address of the unit */ 
527   talog_unit *info; /* pointer to driver specific info for unit */
528   int chan; /* the channel used for creating devfs nodes */
529    
530   if (!(info = malloc(sizeof(*info), M_DEVBUF, M_NOWAIT)))
531    {
532      printf ("alog%d: cannot allocate driver storage\n", unit);
533      return 0;
534    }
535   alog_unit[unit] = info; /* make sure to save the pointer */
536   bzero (info, sizeof(*info)); /* clear info structure to all false */
537   info->isaunit = idp;  /* store ptr to isa device information */
538   sync_clock2 (unit, DEFAULT_MICRO_PERIOD); /* setup perlo and perhi */ 
539   info->firstchan = -1; /* channel lists are empty */
540    
541   /* insert devfs nodes */
542   
543 #ifdef DEVFS   
544   for (chan=0; chan<NUMCHANNELS; chan++)
545     info->chan[chan].devfs_token = 
546      devfs_add_devswf(&alog_cdevsw, LMINOR(unit, chan), DV_CHR,
547                       UID_ROOT, GID_WHEEL, 0400, DEVFORMAT,
548                         unit, 'a'+EMUX(chan), IMUX(chan));
549 #endif   
550
551   printf ("alog%d: %d channels, %d bytes/FIFO, %d entry trigger\n",
552             unit, NUMCHANNELS, FIFOSIZE*sizeof(u_short), 
553             DEFAULT_FIFO_TRIGGER);
554   alogintr (unit); /* start the periodic interrupting process */    
555   return 1; /* obviously successful */
556 }
557
558
559 /* Unit interrupt handling routine (interrupts generated by clock 2) */
560 void alogintr (int unit)
561 {
562   talog_unit *info = alog_unit[unit];
563   int iobase = info->isaunit->id_iobase;
564   u_short fifoent;
565    
566    
567   if (info->firstchan >= 0) /* ? is there even a chan list to traverse */
568    switch (info->state)
569     {  
570       case STATE_READ: 
571        if (info->chan[info->curchan].status == STATUS_INUSE)
572         { 
573          if (inb (iobase+STATUS) & EOC) /* check that conversion finished */
574           printf (DEVFORMAT ": incomplete conversion\n", unit,
575                    'a'+EMUX(info->curchan), IMUX(info->curchan));           
576          else /* conversion is finished (should always be) */
577           {   
578            fifoent = (inb (iobase+ADHIGH) << 8) +
579                        inb (iobase+ADLOW);
580            if (putfifo(&(info->chan[info->curchan]), fifoent))
581             {
582                printf (DEVFORMAT ": fifo overflow\n", unit,
583                        'a'+EMUX(info->curchan), IMUX(info->curchan));       
584             }
585            if (info->chan[info->curchan].fifosize >=
586                 info->chan[info->curchan].fifotrig)
587             {
588               /* if we've reached trigger levels */
589               selwakeup (&(info->chan[info->curchan].readpoll));
590               wakeup (&(info->chan[info->curchan].fifo));
591             }
592           }
593          }
594        /* goto setup state for next channel on list */
595        if ((info->curchan = info->chan[info->curchan].nextchan) < 0)
596         info->curchan = info->firstchan;  
597        /* notice lack of break here this implys a STATE_SETUP */ 
598       case STATE_SETUP: /* set the muxes and let them settle */
599 #if NUMCHANNELS > NUMIMUXES    /* only do this if using external muxes */
600        outb (iobase+STATUS, 
601               EMUXMAKE(info->curchan) | IMUX(info->curchan) | IEN);
602        info->state = STATE_CONVERT;
603        break;
604 #endif
605       case STATE_CONVERT: 
606        outb (iobase+STATUS, 
607               EMUXMAKE(info->curchan) | IMUX(info->curchan) | IEN);
608        outb (iobase+ADHIGH, 0); /* start the conversion */
609        info->state = STATE_READ;
610        break;
611     }
612   else /* this is kind of like an idle mode */ 
613    {
614       outb (iobase+STATUS, IEN); /* no list keep getting interrupts though */
615       /* since we have no open channels spin clock rate down to 
616        * minimum to save interrupt overhead */
617       outb (iobase+CNTRCNTRL, LD2MODE4); /* counter 2 to mode 4 strobe */
618       outb (iobase+CNTR2, 0xff); /* longest period we can generate */
619       outb (iobase+CNTR2, 0xff); 
620       return;   
621    }
622   outb (iobase+CNTRCNTRL, LD2MODE4); /* counter 2 to mode 4 strobe */
623   outb (iobase+CNTR2, info->perlo); /* low part of the period count */
624   outb (iobase+CNTR2, info->perhi); /* high part of the period count */
625 }
626
627    
628 /* this will put an entry in fifo, returns 1 if the first item in 
629  * fifo was wiped (overflow) or 0 if everything went fine */
630 static int putfifo (talog_chan *pchan, u_short fifoent)
631 {   
632    pchan->fifo[pchan->fifoend] = fifoent; /* insert the entry in */
633    pchan->fifoend++; /* one more in fifo */
634    if (pchan->fifoend == FIFOSIZE) pchan->fifoend = 0; /* wrap around */ 
635    /* note: I did intend to write over the oldest entry on overflow */
636    if (pchan->fifosize == FIFOSIZE) /* overflowing state already */
637     {
638        pchan->fifostart++;
639        if (pchan->fifostart == FIFOSIZE) pchan->fifostart = 0;
640        return 1; /* we overflowed */
641     }
642    pchan->fifosize++; /* actually one bigger, else same size */
643    return 0; /* went in just fine */ 
644 }
645    
646
647 /* Driver initialization */
648 static void alog_drvinit (void *unused)
649 {
650   dev_t dev;  /* Type for holding device major/minor numbers (int) */
651
652   if (!alog_devsw_installed)
653    {
654      dev = makedev (CDEV_MAJOR, 0);  /* description of device major */
655      cdevsw_add (&dev, &alog_cdevsw, NULL);  /* put driver in cdev table */
656      alog_devsw_installed=1;
657    }
658 }
659
660 /* System initialization call instance */
661
662 SYSINIT (alogdev, SI_SUB_DRIVERS, SI_ORDER_MIDDLE+CDEV_MAJOR,
663          alog_drvinit,NULL);
664
665 #endif