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