The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/dev/sound/isa/ad1816.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * Copyright (c) 1999 Cameron Grant <cg@freebsd.org>
    3  * Copyright Luigi Rizzo, 1997,1998
    4  * Copyright by Hannu Savolainen 1994, 1995
    5  * All rights reserved.
    6  *
    7  * Redistribution and use in source and binary forms, with or without
    8  * modification, are permitted provided that the following conditions
    9  * are met:
   10  * 1. Redistributions of source code must retain the above copyright
   11  *    notice, this list of conditions and the following disclaimer.
   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  *
   16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   26  * SUCH DAMAGE.
   27  */
   28 
   29 #include <dev/sound/pcm/sound.h>
   30 #include <dev/sound/isa/ad1816.h>
   31 
   32 #include <isa/isavar.h>
   33 
   34 #include "mixer_if.h"
   35 
   36 SND_DECLARE_FILE("$FreeBSD: releng/6.3/sys/dev/sound/isa/ad1816.c 157484 2006-04-04 17:23:24Z ariff $");
   37 
   38 struct ad1816_info;
   39 
   40 struct ad1816_chinfo {
   41         struct ad1816_info *parent;
   42         struct pcm_channel *channel;
   43         struct snd_dbuf *buffer;
   44         int dir, blksz;
   45 };
   46 
   47 struct ad1816_info {
   48         struct resource *io_base;       /* primary I/O address for the board */
   49         int io_rid;
   50         struct resource *irq;
   51         int irq_rid;
   52         struct resource *drq1;          /* play */
   53         int drq1_rid;
   54         struct resource *drq2;          /* rec */
   55         int drq2_rid;
   56         void *ih;
   57         bus_dma_tag_t parent_dmat;
   58         struct mtx *lock;
   59 
   60         unsigned int bufsize;
   61         struct ad1816_chinfo pch, rch;
   62 };
   63 
   64 static u_int32_t ad1816_fmt[] = {
   65         AFMT_U8,
   66         AFMT_STEREO | AFMT_U8,
   67         AFMT_S16_LE,
   68         AFMT_STEREO | AFMT_S16_LE,
   69         AFMT_MU_LAW,
   70         AFMT_STEREO | AFMT_MU_LAW,
   71         AFMT_A_LAW,
   72         AFMT_STEREO | AFMT_A_LAW,
   73         0
   74 };
   75 
   76 static struct pcmchan_caps ad1816_caps = {4000, 55200, ad1816_fmt, 0};
   77 
   78 #define AD1816_MUTE 31          /* value for mute */
   79 
   80 static void
   81 ad1816_lock(struct ad1816_info *ad1816)
   82 {
   83         snd_mtxlock(ad1816->lock);
   84 }
   85 
   86 static void
   87 ad1816_unlock(struct ad1816_info *ad1816)
   88 {
   89         snd_mtxunlock(ad1816->lock);
   90 }
   91 
   92 static int
   93 port_rd(struct resource *port, int off)
   94 {
   95         if (port)
   96                 return bus_space_read_1(rman_get_bustag(port),
   97                                         rman_get_bushandle(port),
   98                                         off);
   99         else
  100                 return -1;
  101 }
  102 
  103 static void
  104 port_wr(struct resource *port, int off, u_int8_t data)
  105 {
  106         if (port)
  107                 bus_space_write_1(rman_get_bustag(port),
  108                                   rman_get_bushandle(port),
  109                                   off, data);
  110 }
  111 
  112 static int
  113 io_rd(struct ad1816_info *ad1816, int reg)
  114 {
  115         return port_rd(ad1816->io_base, reg);
  116 }
  117 
  118 static void
  119 io_wr(struct ad1816_info *ad1816, int reg, u_int8_t data)
  120 {
  121         port_wr(ad1816->io_base, reg, data);
  122 }
  123 
  124 static void
  125 ad1816_intr(void *arg)
  126 {
  127         struct ad1816_info *ad1816 = (struct ad1816_info *)arg;
  128         unsigned char   c, served = 0;
  129 
  130         ad1816_lock(ad1816);
  131         /* get interupt status */
  132         c = io_rd(ad1816, AD1816_INT);
  133 
  134         /* check for stray interupts */
  135         if (c & ~(AD1816_INTRCI | AD1816_INTRPI)) {
  136                 printf("pcm: stray int (%x)\n", c);
  137                 c &= AD1816_INTRCI | AD1816_INTRPI;
  138         }
  139         /* check for capture interupt */
  140         if (sndbuf_runsz(ad1816->rch.buffer) && (c & AD1816_INTRCI)) {
  141                 ad1816_unlock(ad1816);
  142                 chn_intr(ad1816->rch.channel);
  143                 ad1816_lock(ad1816);
  144                 served |= AD1816_INTRCI;                /* cp served */
  145         }
  146         /* check for playback interupt */
  147         if (sndbuf_runsz(ad1816->pch.buffer) && (c & AD1816_INTRPI)) {
  148                 ad1816_unlock(ad1816);
  149                 chn_intr(ad1816->pch.channel);
  150                 ad1816_lock(ad1816);
  151                 served |= AD1816_INTRPI;                /* pb served */
  152         }
  153         if (served == 0) {
  154                 /* this probably means this is not a (working) ad1816 chip, */
  155                 /* or an error in dma handling                              */
  156                 printf("pcm: int without reason (%x)\n", c);
  157                 c = 0;
  158         } else c &= ~served;
  159         io_wr(ad1816, AD1816_INT, c);
  160         c = io_rd(ad1816, AD1816_INT);
  161         if (c != 0) printf("pcm: int clear failed (%x)\n", c);
  162         ad1816_unlock(ad1816);
  163 }
  164 
  165 static int
  166 ad1816_wait_init(struct ad1816_info *ad1816, int x)
  167 {
  168         int             n = 0;  /* to shut up the compiler... */
  169 
  170         for (; x--;)
  171                 if ((n = (io_rd(ad1816, AD1816_ALE) & AD1816_BUSY)) == 0) DELAY(10);
  172                 else return n;
  173         printf("ad1816_wait_init failed 0x%02x.\n", n);
  174         return -1;
  175 }
  176 
  177 static unsigned short
  178 ad1816_read(struct ad1816_info *ad1816, unsigned int reg)
  179 {
  180         u_short         x = 0;
  181 
  182         if (ad1816_wait_init(ad1816, 100) == -1) return 0;
  183         io_wr(ad1816, AD1816_ALE, 0);
  184         io_wr(ad1816, AD1816_ALE, (reg & AD1816_ALEMASK));
  185         if (ad1816_wait_init(ad1816, 100) == -1) return 0;
  186         x = (io_rd(ad1816, AD1816_HIGH) << 8) | io_rd(ad1816, AD1816_LOW);
  187         return x;
  188 }
  189 
  190 static void
  191 ad1816_write(struct ad1816_info *ad1816, unsigned int reg, unsigned short data)
  192 {
  193         if (ad1816_wait_init(ad1816, 100) == -1) return;
  194         io_wr(ad1816, AD1816_ALE, (reg & AD1816_ALEMASK));
  195         io_wr(ad1816, AD1816_LOW,  (data & 0x000000ff));
  196         io_wr(ad1816, AD1816_HIGH, (data & 0x0000ff00) >> 8);
  197 }
  198 
  199 /* -------------------------------------------------------------------- */
  200 
  201 static int
  202 ad1816mix_init(struct snd_mixer *m)
  203 {
  204         mix_setdevs(m, AD1816_MIXER_DEVICES);
  205         mix_setrecdevs(m, AD1816_REC_DEVICES);
  206         return 0;
  207 }
  208 
  209 static int
  210 ad1816mix_set(struct snd_mixer *m, unsigned dev, unsigned left, unsigned right)
  211 {
  212         struct ad1816_info *ad1816 = mix_getdevinfo(m);
  213         u_short reg = 0;
  214 
  215         /* Scale volumes */
  216         left = AD1816_MUTE - (AD1816_MUTE * left) / 100;
  217         right = AD1816_MUTE - (AD1816_MUTE * right) / 100;
  218 
  219         reg = (left << 8) | right;
  220 
  221         /* do channel selective muting if volume is zero */
  222         if (left == AD1816_MUTE)        reg |= 0x8000;
  223         if (right == AD1816_MUTE)       reg |= 0x0080;
  224 
  225         ad1816_lock(ad1816);
  226         switch (dev) {
  227         case SOUND_MIXER_VOLUME:        /* Register 14 master volume */
  228                 ad1816_write(ad1816, 14, reg);
  229                 break;
  230 
  231         case SOUND_MIXER_CD:    /* Register 15 cd */
  232         case SOUND_MIXER_LINE1:
  233                 ad1816_write(ad1816, 15, reg);
  234                 break;
  235 
  236         case SOUND_MIXER_SYNTH: /* Register 16 synth */
  237                 ad1816_write(ad1816, 16, reg);
  238                 break;
  239 
  240         case SOUND_MIXER_PCM:   /* Register 4 pcm */
  241                 ad1816_write(ad1816, 4, reg);
  242                 break;
  243 
  244         case SOUND_MIXER_LINE:
  245         case SOUND_MIXER_LINE3: /* Register 18 line in */
  246                 ad1816_write(ad1816, 18, reg);
  247                 break;
  248 
  249         case SOUND_MIXER_MIC:   /* Register 19 mic volume */
  250                 ad1816_write(ad1816, 19, reg & ~0xff);  /* mic is mono */
  251                 break;
  252 
  253         case SOUND_MIXER_IGAIN:
  254                 /* and now to something completely different ... */
  255                 ad1816_write(ad1816, 20, ((ad1816_read(ad1816, 20) & ~0x0f0f)
  256                 | (((AD1816_MUTE - left) / 2) << 8) /* four bits of adc gain */
  257                 | ((AD1816_MUTE - right) / 2)));
  258                 break;
  259 
  260         default:
  261                 printf("ad1816_mixer_set(): unknown device.\n");
  262                 break;
  263         }
  264         ad1816_unlock(ad1816);
  265 
  266         left = ((AD1816_MUTE - left) * 100) / AD1816_MUTE;
  267         right = ((AD1816_MUTE - right) * 100) / AD1816_MUTE;
  268 
  269         return left | (right << 8);
  270 }
  271 
  272 static int
  273 ad1816mix_setrecsrc(struct snd_mixer *m, u_int32_t src)
  274 {
  275         struct ad1816_info *ad1816 = mix_getdevinfo(m);
  276         int dev;
  277 
  278         switch (src) {
  279         case SOUND_MASK_LINE:
  280         case SOUND_MASK_LINE3:
  281                 dev = 0x00;
  282                 break;
  283 
  284         case SOUND_MASK_CD:
  285         case SOUND_MASK_LINE1:
  286                 dev = 0x20;
  287                 break;
  288 
  289         case SOUND_MASK_MIC:
  290         default:
  291                 dev = 0x50;
  292                 src = SOUND_MASK_MIC;
  293         }
  294 
  295         dev |= dev << 8;
  296         ad1816_lock(ad1816);
  297         ad1816_write(ad1816, 20, (ad1816_read(ad1816, 20) & ~0x7070) | dev);
  298         ad1816_unlock(ad1816);
  299         return src;
  300 }
  301 
  302 static kobj_method_t ad1816mixer_methods[] = {
  303         KOBJMETHOD(mixer_init,          ad1816mix_init),
  304         KOBJMETHOD(mixer_set,           ad1816mix_set),
  305         KOBJMETHOD(mixer_setrecsrc,     ad1816mix_setrecsrc),
  306         { 0, 0 }
  307 };
  308 MIXER_DECLARE(ad1816mixer);
  309 
  310 /* -------------------------------------------------------------------- */
  311 /* channel interface */
  312 static void *
  313 ad1816chan_init(kobj_t obj, void *devinfo, struct snd_dbuf *b, struct pcm_channel *c, int dir)
  314 {
  315         struct ad1816_info *ad1816 = devinfo;
  316         struct ad1816_chinfo *ch = (dir == PCMDIR_PLAY)? &ad1816->pch : &ad1816->rch;
  317 
  318         ch->parent = ad1816;
  319         ch->channel = c;
  320         ch->buffer = b;
  321         if (sndbuf_alloc(ch->buffer, ad1816->parent_dmat, ad1816->bufsize) != 0)
  322                 return NULL;
  323         return ch;
  324 }
  325 
  326 static int
  327 ad1816chan_setdir(kobj_t obj, void *data, int dir)
  328 {
  329         struct ad1816_chinfo *ch = data;
  330         struct ad1816_info *ad1816 = ch->parent;
  331 
  332         sndbuf_dmasetup(ch->buffer, (dir == PCMDIR_PLAY)? ad1816->drq1 : ad1816->drq2);
  333         ch->dir = dir;
  334         return 0;
  335 }
  336 
  337 static int
  338 ad1816chan_setformat(kobj_t obj, void *data, u_int32_t format)
  339 {
  340         struct ad1816_chinfo *ch = data;
  341         struct ad1816_info *ad1816 = ch->parent;
  342         int fmt = AD1816_U8, reg;
  343 
  344         ad1816_lock(ad1816);
  345         if (ch->dir == PCMDIR_PLAY) {
  346                 reg = AD1816_PLAY;
  347                 ad1816_write(ad1816, 8, 0x0000);        /* reset base and current counter */
  348                 ad1816_write(ad1816, 9, 0x0000);        /* for playback and capture */
  349         } else {
  350                 reg = AD1816_CAPT;
  351                 ad1816_write(ad1816, 10, 0x0000);
  352                 ad1816_write(ad1816, 11, 0x0000);
  353         }
  354         switch (format & ~AFMT_STEREO) {
  355         case AFMT_A_LAW:
  356                 fmt = AD1816_ALAW;
  357                 break;
  358 
  359         case AFMT_MU_LAW:
  360                 fmt = AD1816_MULAW;
  361                 break;
  362 
  363         case AFMT_S16_LE:
  364                 fmt = AD1816_S16LE;
  365                 break;
  366 
  367         case AFMT_S16_BE:
  368                 fmt = AD1816_S16BE;
  369                 break;
  370 
  371         case AFMT_U8:
  372                 fmt = AD1816_U8;
  373                 break;
  374         }
  375         if (format & AFMT_STEREO) fmt |= AD1816_STEREO;
  376         io_wr(ad1816, reg, fmt);
  377         ad1816_unlock(ad1816);
  378 #if 0
  379         return format;
  380 #else
  381         return 0;
  382 #endif
  383 }
  384 
  385 static int
  386 ad1816chan_setspeed(kobj_t obj, void *data, u_int32_t speed)
  387 {
  388         struct ad1816_chinfo *ch = data;
  389         struct ad1816_info *ad1816 = ch->parent;
  390 
  391         RANGE(speed, 4000, 55200);
  392         ad1816_lock(ad1816);
  393         ad1816_write(ad1816, (ch->dir == PCMDIR_PLAY)? 2 : 3, speed);
  394         ad1816_unlock(ad1816);
  395         return speed;
  396 }
  397 
  398 static int
  399 ad1816chan_setblocksize(kobj_t obj, void *data, u_int32_t blocksize)
  400 {
  401         struct ad1816_chinfo *ch = data;
  402 
  403         ch->blksz = blocksize;
  404         return ch->blksz;
  405 }
  406 
  407 static int
  408 ad1816chan_trigger(kobj_t obj, void *data, int go)
  409 {
  410         struct ad1816_chinfo *ch = data;
  411         struct ad1816_info *ad1816 = ch->parent;
  412         int wr, reg;
  413 
  414         if (go == PCMTRIG_EMLDMAWR || go == PCMTRIG_EMLDMARD)
  415                 return 0;
  416 
  417         sndbuf_dma(ch->buffer, go);
  418         wr = (ch->dir == PCMDIR_PLAY);
  419         reg = wr? AD1816_PLAY : AD1816_CAPT;
  420         ad1816_lock(ad1816);
  421         switch (go) {
  422         case PCMTRIG_START:
  423                 /* start only if not already running */
  424                 if (!(io_rd(ad1816, reg) & AD1816_ENABLE)) {
  425                         int cnt = ((ch->blksz) >> 2) - 1;
  426                         ad1816_write(ad1816, wr? 8 : 10, cnt); /* count */
  427                         ad1816_write(ad1816, wr? 9 : 11, 0); /* reset cur cnt */
  428                         ad1816_write(ad1816, 1, ad1816_read(ad1816, 1) |
  429                                      (wr? 0x8000 : 0x4000)); /* enable int */
  430                         /* enable playback */
  431                         io_wr(ad1816, reg, io_rd(ad1816, reg) | AD1816_ENABLE);
  432                         if (!(io_rd(ad1816, reg) & AD1816_ENABLE))
  433                                 printf("ad1816: failed to start %s DMA!\n",
  434                                        wr? "play" : "rec");
  435                 }
  436                 break;
  437 
  438         case PCMTRIG_STOP:
  439         case PCMTRIG_ABORT:             /* XXX check this... */
  440                 /* we don't test here if it is running... */
  441                 if (wr) {
  442                         ad1816_write(ad1816, 1, ad1816_read(ad1816, 1) &
  443                                      ~(wr? 0x8000 : 0x4000));
  444                         /* disable int */
  445                         io_wr(ad1816, reg, io_rd(ad1816, reg) & ~AD1816_ENABLE);
  446                         /* disable playback */
  447                         if (io_rd(ad1816, reg) & AD1816_ENABLE)
  448                                 printf("ad1816: failed to stop %s DMA!\n",
  449                                        wr? "play" : "rec");
  450                         ad1816_write(ad1816, wr? 8 : 10, 0); /* reset base cnt */
  451                         ad1816_write(ad1816, wr? 9 : 11, 0); /* reset cur cnt */
  452                 }
  453                 break;
  454         }
  455         ad1816_unlock(ad1816);
  456         return 0;
  457 }
  458 
  459 static int
  460 ad1816chan_getptr(kobj_t obj, void *data)
  461 {
  462         struct ad1816_chinfo *ch = data;
  463         return sndbuf_dmaptr(ch->buffer);
  464 }
  465 
  466 static struct pcmchan_caps *
  467 ad1816chan_getcaps(kobj_t obj, void *data)
  468 {
  469         return &ad1816_caps;
  470 }
  471 
  472 static kobj_method_t ad1816chan_methods[] = {
  473         KOBJMETHOD(channel_init,                ad1816chan_init),
  474         KOBJMETHOD(channel_setdir,              ad1816chan_setdir),
  475         KOBJMETHOD(channel_setformat,           ad1816chan_setformat),
  476         KOBJMETHOD(channel_setspeed,            ad1816chan_setspeed),
  477         KOBJMETHOD(channel_setblocksize,        ad1816chan_setblocksize),
  478         KOBJMETHOD(channel_trigger,             ad1816chan_trigger),
  479         KOBJMETHOD(channel_getptr,              ad1816chan_getptr),
  480         KOBJMETHOD(channel_getcaps,             ad1816chan_getcaps),
  481         { 0, 0 }
  482 };
  483 CHANNEL_DECLARE(ad1816chan);
  484 
  485 /* -------------------------------------------------------------------- */
  486 
  487 static void
  488 ad1816_release_resources(struct ad1816_info *ad1816, device_t dev)
  489 {
  490         if (ad1816->irq) {
  491                 if (ad1816->ih)
  492                         bus_teardown_intr(dev, ad1816->irq, ad1816->ih);
  493                 bus_release_resource(dev, SYS_RES_IRQ, ad1816->irq_rid, ad1816->irq);
  494                 ad1816->irq = 0;
  495         }
  496         if (ad1816->drq1) {
  497                 isa_dma_release(rman_get_start(ad1816->drq1));
  498                 bus_release_resource(dev, SYS_RES_DRQ, ad1816->drq1_rid, ad1816->drq1);
  499                 ad1816->drq1 = 0;
  500         }
  501         if (ad1816->drq2) {
  502                 isa_dma_release(rman_get_start(ad1816->drq2));
  503                 bus_release_resource(dev, SYS_RES_DRQ, ad1816->drq2_rid, ad1816->drq2);
  504                 ad1816->drq2 = 0;
  505         }
  506         if (ad1816->io_base) {
  507                 bus_release_resource(dev, SYS_RES_IOPORT, ad1816->io_rid, ad1816->io_base);
  508                 ad1816->io_base = 0;
  509         }
  510         if (ad1816->parent_dmat) {
  511                 bus_dma_tag_destroy(ad1816->parent_dmat);
  512                 ad1816->parent_dmat = 0;
  513         }
  514         if (ad1816->lock)
  515                 snd_mtxfree(ad1816->lock);
  516 
  517         free(ad1816, M_DEVBUF);
  518 }
  519 
  520 static int
  521 ad1816_alloc_resources(struct ad1816_info *ad1816, device_t dev)
  522 {
  523         int ok = 1, pdma, rdma;
  524 
  525         if (!ad1816->io_base)
  526                 ad1816->io_base = bus_alloc_resource_any(dev, 
  527                         SYS_RES_IOPORT, &ad1816->io_rid, RF_ACTIVE);
  528         if (!ad1816->irq)
  529                 ad1816->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ,
  530                         &ad1816->irq_rid, RF_ACTIVE);
  531         if (!ad1816->drq1)
  532                 ad1816->drq1 = bus_alloc_resource_any(dev, SYS_RES_DRQ,
  533                         &ad1816->drq1_rid, RF_ACTIVE);
  534         if (!ad1816->drq2)
  535                 ad1816->drq2 = bus_alloc_resource_any(dev, SYS_RES_DRQ, 
  536                         &ad1816->drq2_rid, RF_ACTIVE);
  537 
  538         if (!ad1816->io_base || !ad1816->drq1 || !ad1816->irq) ok = 0;
  539 
  540         if (ok) {
  541                 pdma = rman_get_start(ad1816->drq1);
  542                 isa_dma_acquire(pdma);
  543                 isa_dmainit(pdma, ad1816->bufsize);
  544                 if (ad1816->drq2) {
  545                         rdma = rman_get_start(ad1816->drq2);
  546                         isa_dma_acquire(rdma);
  547                         isa_dmainit(rdma, ad1816->bufsize);
  548                 } else
  549                         rdma = pdma;
  550                 if (pdma == rdma)
  551                         pcm_setflags(dev, pcm_getflags(dev) | SD_F_SIMPLEX);
  552         }
  553 
  554         return ok;
  555 }
  556 
  557 static int
  558 ad1816_init(struct ad1816_info *ad1816, device_t dev)
  559 {
  560         ad1816_write(ad1816, 1, 0x2);   /* disable interrupts */
  561         ad1816_write(ad1816, 32, 0x90F0);       /* SoundSys Mode, split fmt */
  562 
  563         ad1816_write(ad1816, 5, 0x8080);        /* FM volume mute */
  564         ad1816_write(ad1816, 6, 0x8080);        /* I2S1 volume mute */
  565         ad1816_write(ad1816, 7, 0x8080);        /* I2S0 volume mute */
  566         ad1816_write(ad1816, 17, 0x8888);       /* VID Volume mute */
  567         ad1816_write(ad1816, 20, 0x5050);       /* recsrc mic, agc off */
  568         /* adc gain is set to 0 */
  569 
  570         return 0;
  571 }
  572 
  573 static int
  574 ad1816_probe(device_t dev)
  575 {
  576         char *s = NULL;
  577         u_int32_t logical_id = isa_get_logicalid(dev);
  578 
  579         switch (logical_id) {
  580         case 0x80719304: /* ADS7180 */
  581                 s = "AD1816";
  582                 break;
  583         case 0x50719304: /* ADS7150 */
  584                 s = "AD1815";
  585                 break;
  586         }
  587 
  588         if (s) {
  589                 device_set_desc(dev, s);
  590                 return BUS_PROBE_DEFAULT;
  591         }
  592         return ENXIO;
  593 }
  594 
  595 static int
  596 ad1816_attach(device_t dev)
  597 {
  598         struct ad1816_info *ad1816;
  599         char status[SND_STATUSLEN], status2[SND_STATUSLEN];
  600 
  601         ad1816 = (struct ad1816_info *)malloc(sizeof *ad1816, M_DEVBUF, M_NOWAIT | M_ZERO);
  602         if (!ad1816) return ENXIO;
  603 
  604         ad1816->lock = snd_mtxcreate(device_get_nameunit(dev), "sound softc");
  605         ad1816->io_rid = 2;
  606         ad1816->irq_rid = 0;
  607         ad1816->drq1_rid = 0;
  608         ad1816->drq2_rid = 1;
  609         ad1816->bufsize = pcm_getbuffersize(dev, 4096, DSP_BUFFSIZE, 65536);
  610 
  611         if (!ad1816_alloc_resources(ad1816, dev)) goto no;
  612         ad1816_init(ad1816, dev);
  613         if (mixer_init(dev, &ad1816mixer_class, ad1816)) goto no;
  614 
  615         snd_setup_intr(dev, ad1816->irq, 0, ad1816_intr, ad1816, &ad1816->ih);
  616         if (bus_dma_tag_create(/*parent*/NULL, /*alignment*/2, /*boundary*/0,
  617                         /*lowaddr*/BUS_SPACE_MAXADDR_24BIT,
  618                         /*highaddr*/BUS_SPACE_MAXADDR,
  619                         /*filter*/NULL, /*filterarg*/NULL,
  620                         /*maxsize*/ad1816->bufsize, /*nsegments*/1,
  621                         /*maxsegz*/0x3ffff,
  622                         /*flags*/0, /*lockfunc*/busdma_lock_mutex,
  623                         /*lockarg*/ &Giant, &ad1816->parent_dmat) != 0) {
  624                 device_printf(dev, "unable to create dma tag\n");
  625                 goto no;
  626         }
  627         if (ad1816->drq2)
  628                 snprintf(status2, SND_STATUSLEN, ":%ld", rman_get_start(ad1816->drq2));
  629         else
  630                 status2[0] = '\0';
  631 
  632         snprintf(status, SND_STATUSLEN, "at io 0x%lx irq %ld drq %ld%s bufsz %u %s",
  633                 rman_get_start(ad1816->io_base),
  634                 rman_get_start(ad1816->irq),
  635                 rman_get_start(ad1816->drq1),
  636                 status2,
  637                 ad1816->bufsize,
  638                 PCM_KLDSTRING(snd_ad1816));
  639 
  640         if (pcm_register(dev, ad1816, 1, 1)) goto no;
  641         pcm_addchan(dev, PCMDIR_REC, &ad1816chan_class, ad1816);
  642         pcm_addchan(dev, PCMDIR_PLAY, &ad1816chan_class, ad1816);
  643         pcm_setstatus(dev, status);
  644 
  645         return 0;
  646 no:
  647         ad1816_release_resources(ad1816, dev);
  648 
  649         return ENXIO;
  650 
  651 }
  652 
  653 static int
  654 ad1816_detach(device_t dev)
  655 {
  656         int r;
  657         struct ad1816_info *ad1816;
  658 
  659         r = pcm_unregister(dev);
  660         if (r)
  661                 return r;
  662 
  663         ad1816 = pcm_getdevinfo(dev);
  664         ad1816_release_resources(ad1816, dev);
  665         return 0;
  666 }
  667 
  668 static device_method_t ad1816_methods[] = {
  669         /* Device interface */
  670         DEVMETHOD(device_probe,         ad1816_probe),
  671         DEVMETHOD(device_attach,        ad1816_attach),
  672         DEVMETHOD(device_detach,        ad1816_detach),
  673 
  674         { 0, 0 }
  675 };
  676 
  677 static driver_t ad1816_driver = {
  678         "pcm",
  679         ad1816_methods,
  680         PCM_SOFTC_SIZE,
  681 };
  682 
  683 DRIVER_MODULE(snd_ad1816, isa, ad1816_driver, pcm_devclass, 0, 0);
  684 DRIVER_MODULE(snd_ad1816, acpi, ad1816_driver, pcm_devclass, 0, 0);
  685 MODULE_DEPEND(snd_ad1816, sound, SOUND_MINVER, SOUND_PREFVER, SOUND_MAXVER);
  686 MODULE_VERSION(snd_ad1816, 1);
  687 
  688 

Cache object: 214f52a53d0d8d205f7db31492a27412


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.