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$");
   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                 chn_intr(ad1816->rch.channel);
  142                 served |= AD1816_INTRCI;                /* cp served */
  143         }
  144         /* check for playback interupt */
  145         if (sndbuf_runsz(ad1816->pch.buffer) && (c & AD1816_INTRPI)) {
  146                 chn_intr(ad1816->pch.channel);
  147                 served |= AD1816_INTRPI;                /* pb served */
  148         }
  149         if (served == 0) {
  150                 /* this probably means this is not a (working) ad1816 chip, */
  151                 /* or an error in dma handling                              */
  152                 printf("pcm: int without reason (%x)\n", c);
  153                 c = 0;
  154         } else c &= ~served;
  155         io_wr(ad1816, AD1816_INT, c);
  156         c = io_rd(ad1816, AD1816_INT);
  157         if (c != 0) printf("pcm: int clear failed (%x)\n", c);
  158         ad1816_unlock(ad1816);
  159 }
  160 
  161 static int
  162 ad1816_wait_init(struct ad1816_info *ad1816, int x)
  163 {
  164         int             n = 0;  /* to shut up the compiler... */
  165 
  166         for (; x--;)
  167                 if ((n = (io_rd(ad1816, AD1816_ALE) & AD1816_BUSY)) == 0) DELAY(10);
  168                 else return n;
  169         printf("ad1816_wait_init failed 0x%02x.\n", n);
  170         return -1;
  171 }
  172 
  173 static unsigned short
  174 ad1816_read(struct ad1816_info *ad1816, unsigned int reg)
  175 {
  176         u_short         x = 0;
  177 
  178         if (ad1816_wait_init(ad1816, 100) == -1) return 0;
  179         io_wr(ad1816, AD1816_ALE, 0);
  180         io_wr(ad1816, AD1816_ALE, (reg & AD1816_ALEMASK));
  181         if (ad1816_wait_init(ad1816, 100) == -1) return 0;
  182         x = (io_rd(ad1816, AD1816_HIGH) << 8) | io_rd(ad1816, AD1816_LOW);
  183         return x;
  184 }
  185 
  186 static void
  187 ad1816_write(struct ad1816_info *ad1816, unsigned int reg, unsigned short data)
  188 {
  189         if (ad1816_wait_init(ad1816, 100) == -1) return;
  190         io_wr(ad1816, AD1816_ALE, (reg & AD1816_ALEMASK));
  191         io_wr(ad1816, AD1816_LOW,  (data & 0x000000ff));
  192         io_wr(ad1816, AD1816_HIGH, (data & 0x0000ff00) >> 8);
  193 }
  194 
  195 /* -------------------------------------------------------------------- */
  196 
  197 static int
  198 ad1816mix_init(struct snd_mixer *m)
  199 {
  200         mix_setdevs(m, AD1816_MIXER_DEVICES);
  201         mix_setrecdevs(m, AD1816_REC_DEVICES);
  202         return 0;
  203 }
  204 
  205 static int
  206 ad1816mix_set(struct snd_mixer *m, unsigned dev, unsigned left, unsigned right)
  207 {
  208         struct ad1816_info *ad1816 = mix_getdevinfo(m);
  209         u_short reg = 0;
  210 
  211         /* Scale volumes */
  212         left = AD1816_MUTE - (AD1816_MUTE * left) / 100;
  213         right = AD1816_MUTE - (AD1816_MUTE * right) / 100;
  214 
  215         reg = (left << 8) | right;
  216 
  217         /* do channel selective muting if volume is zero */
  218         if (left == AD1816_MUTE)        reg |= 0x8000;
  219         if (right == AD1816_MUTE)       reg |= 0x0080;
  220 
  221         ad1816_lock(ad1816);
  222         switch (dev) {
  223         case SOUND_MIXER_VOLUME:        /* Register 14 master volume */
  224                 ad1816_write(ad1816, 14, reg);
  225                 break;
  226 
  227         case SOUND_MIXER_CD:    /* Register 15 cd */
  228         case SOUND_MIXER_LINE1:
  229                 ad1816_write(ad1816, 15, reg);
  230                 break;
  231 
  232         case SOUND_MIXER_SYNTH: /* Register 16 synth */
  233                 ad1816_write(ad1816, 16, reg);
  234                 break;
  235 
  236         case SOUND_MIXER_PCM:   /* Register 4 pcm */
  237                 ad1816_write(ad1816, 4, reg);
  238                 break;
  239 
  240         case SOUND_MIXER_LINE:
  241         case SOUND_MIXER_LINE3: /* Register 18 line in */
  242                 ad1816_write(ad1816, 18, reg);
  243                 break;
  244 
  245         case SOUND_MIXER_MIC:   /* Register 19 mic volume */
  246                 ad1816_write(ad1816, 19, reg & ~0xff);  /* mic is mono */
  247                 break;
  248 
  249         case SOUND_MIXER_IGAIN:
  250                 /* and now to something completely different ... */
  251                 ad1816_write(ad1816, 20, ((ad1816_read(ad1816, 20) & ~0x0f0f)
  252                 | (((AD1816_MUTE - left) / 2) << 8) /* four bits of adc gain */
  253                 | ((AD1816_MUTE - right) / 2)));
  254                 break;
  255 
  256         default:
  257                 printf("ad1816_mixer_set(): unknown device.\n");
  258                 break;
  259         }
  260         ad1816_unlock(ad1816);
  261 
  262         left = ((AD1816_MUTE - left) * 100) / AD1816_MUTE;
  263         right = ((AD1816_MUTE - right) * 100) / AD1816_MUTE;
  264 
  265         return left | (right << 8);
  266 }
  267 
  268 static int
  269 ad1816mix_setrecsrc(struct snd_mixer *m, u_int32_t src)
  270 {
  271         struct ad1816_info *ad1816 = mix_getdevinfo(m);
  272         int dev;
  273 
  274         switch (src) {
  275         case SOUND_MASK_LINE:
  276         case SOUND_MASK_LINE3:
  277                 dev = 0x00;
  278                 break;
  279 
  280         case SOUND_MASK_CD:
  281         case SOUND_MASK_LINE1:
  282                 dev = 0x20;
  283                 break;
  284 
  285         case SOUND_MASK_MIC:
  286         default:
  287                 dev = 0x50;
  288                 src = SOUND_MASK_MIC;
  289         }
  290 
  291         dev |= dev << 8;
  292         ad1816_lock(ad1816);
  293         ad1816_write(ad1816, 20, (ad1816_read(ad1816, 20) & ~0x7070) | dev);
  294         ad1816_unlock(ad1816);
  295         return src;
  296 }
  297 
  298 static kobj_method_t ad1816mixer_methods[] = {
  299         KOBJMETHOD(mixer_init,          ad1816mix_init),
  300         KOBJMETHOD(mixer_set,           ad1816mix_set),
  301         KOBJMETHOD(mixer_setrecsrc,     ad1816mix_setrecsrc),
  302         { 0, 0 }
  303 };
  304 MIXER_DECLARE(ad1816mixer);
  305 
  306 /* -------------------------------------------------------------------- */
  307 /* channel interface */
  308 static void *
  309 ad1816chan_init(kobj_t obj, void *devinfo, struct snd_dbuf *b, struct pcm_channel *c, int dir)
  310 {
  311         struct ad1816_info *ad1816 = devinfo;
  312         struct ad1816_chinfo *ch = (dir == PCMDIR_PLAY)? &ad1816->pch : &ad1816->rch;
  313 
  314         ch->parent = ad1816;
  315         ch->channel = c;
  316         ch->buffer = b;
  317         if (sndbuf_alloc(ch->buffer, ad1816->parent_dmat, ad1816->bufsize) != 0)
  318                 return NULL;
  319         return ch;
  320 }
  321 
  322 static int
  323 ad1816chan_setdir(kobj_t obj, void *data, int dir)
  324 {
  325         struct ad1816_chinfo *ch = data;
  326         struct ad1816_info *ad1816 = ch->parent;
  327 
  328         sndbuf_dmasetup(ch->buffer, (dir == PCMDIR_PLAY)? ad1816->drq1 : ad1816->drq2);
  329         ch->dir = dir;
  330         return 0;
  331 }
  332 
  333 static int
  334 ad1816chan_setformat(kobj_t obj, void *data, u_int32_t format)
  335 {
  336         struct ad1816_chinfo *ch = data;
  337         struct ad1816_info *ad1816 = ch->parent;
  338         int fmt = AD1816_U8, reg;
  339 
  340         ad1816_lock(ad1816);
  341         if (ch->dir == PCMDIR_PLAY) {
  342                 reg = AD1816_PLAY;
  343                 ad1816_write(ad1816, 8, 0x0000);        /* reset base and current counter */
  344                 ad1816_write(ad1816, 9, 0x0000);        /* for playback and capture */
  345         } else {
  346                 reg = AD1816_CAPT;
  347                 ad1816_write(ad1816, 10, 0x0000);
  348                 ad1816_write(ad1816, 11, 0x0000);
  349         }
  350         switch (format & ~AFMT_STEREO) {
  351         case AFMT_A_LAW:
  352                 fmt = AD1816_ALAW;
  353                 break;
  354 
  355         case AFMT_MU_LAW:
  356                 fmt = AD1816_MULAW;
  357                 break;
  358 
  359         case AFMT_S16_LE:
  360                 fmt = AD1816_S16LE;
  361                 break;
  362 
  363         case AFMT_S16_BE:
  364                 fmt = AD1816_S16BE;
  365                 break;
  366 
  367         case AFMT_U8:
  368                 fmt = AD1816_U8;
  369                 break;
  370         }
  371         if (format & AFMT_STEREO) fmt |= AD1816_STEREO;
  372         io_wr(ad1816, reg, fmt);
  373         ad1816_unlock(ad1816);
  374 #if 0
  375         return format;
  376 #else
  377         return 0;
  378 #endif
  379 }
  380 
  381 static int
  382 ad1816chan_setspeed(kobj_t obj, void *data, u_int32_t speed)
  383 {
  384         struct ad1816_chinfo *ch = data;
  385         struct ad1816_info *ad1816 = ch->parent;
  386 
  387         RANGE(speed, 4000, 55200);
  388         ad1816_lock(ad1816);
  389         ad1816_write(ad1816, (ch->dir == PCMDIR_PLAY)? 2 : 3, speed);
  390         ad1816_unlock(ad1816);
  391         return speed;
  392 }
  393 
  394 static int
  395 ad1816chan_setblocksize(kobj_t obj, void *data, u_int32_t blocksize)
  396 {
  397         struct ad1816_chinfo *ch = data;
  398 
  399         ch->blksz = blocksize;
  400         return ch->blksz;
  401 }
  402 
  403 static int
  404 ad1816chan_trigger(kobj_t obj, void *data, int go)
  405 {
  406         struct ad1816_chinfo *ch = data;
  407         struct ad1816_info *ad1816 = ch->parent;
  408         int wr, reg;
  409 
  410         if (go == PCMTRIG_EMLDMAWR || go == PCMTRIG_EMLDMARD)
  411                 return 0;
  412 
  413         sndbuf_dma(ch->buffer, go);
  414         wr = (ch->dir == PCMDIR_PLAY);
  415         reg = wr? AD1816_PLAY : AD1816_CAPT;
  416         ad1816_lock(ad1816);
  417         switch (go) {
  418         case PCMTRIG_START:
  419                 /* start only if not already running */
  420                 if (!(io_rd(ad1816, reg) & AD1816_ENABLE)) {
  421                         int cnt = ((ch->blksz) >> 2) - 1;
  422                         ad1816_write(ad1816, wr? 8 : 10, cnt); /* count */
  423                         ad1816_write(ad1816, wr? 9 : 11, 0); /* reset cur cnt */
  424                         ad1816_write(ad1816, 1, ad1816_read(ad1816, 1) |
  425                                      (wr? 0x8000 : 0x4000)); /* enable int */
  426                         /* enable playback */
  427                         io_wr(ad1816, reg, io_rd(ad1816, reg) | AD1816_ENABLE);
  428                         if (!(io_rd(ad1816, reg) & AD1816_ENABLE))
  429                                 printf("ad1816: failed to start %s DMA!\n",
  430                                        wr? "play" : "rec");
  431                 }
  432                 break;
  433 
  434         case PCMTRIG_STOP:
  435         case PCMTRIG_ABORT:             /* XXX check this... */
  436                 /* we don't test here if it is running... */
  437                 if (wr) {
  438                         ad1816_write(ad1816, 1, ad1816_read(ad1816, 1) &
  439                                      ~(wr? 0x8000 : 0x4000));
  440                         /* disable int */
  441                         io_wr(ad1816, reg, io_rd(ad1816, reg) & ~AD1816_ENABLE);
  442                         /* disable playback */
  443                         if (io_rd(ad1816, reg) & AD1816_ENABLE)
  444                                 printf("ad1816: failed to stop %s DMA!\n",
  445                                        wr? "play" : "rec");
  446                         ad1816_write(ad1816, wr? 8 : 10, 0); /* reset base cnt */
  447                         ad1816_write(ad1816, wr? 9 : 11, 0); /* reset cur cnt */
  448                 }
  449                 break;
  450         }
  451         ad1816_unlock(ad1816);
  452         return 0;
  453 }
  454 
  455 static int
  456 ad1816chan_getptr(kobj_t obj, void *data)
  457 {
  458         struct ad1816_chinfo *ch = data;
  459         return sndbuf_dmaptr(ch->buffer);
  460 }
  461 
  462 static struct pcmchan_caps *
  463 ad1816chan_getcaps(kobj_t obj, void *data)
  464 {
  465         return &ad1816_caps;
  466 }
  467 
  468 static kobj_method_t ad1816chan_methods[] = {
  469         KOBJMETHOD(channel_init,                ad1816chan_init),
  470         KOBJMETHOD(channel_setdir,              ad1816chan_setdir),
  471         KOBJMETHOD(channel_setformat,           ad1816chan_setformat),
  472         KOBJMETHOD(channel_setspeed,            ad1816chan_setspeed),
  473         KOBJMETHOD(channel_setblocksize,        ad1816chan_setblocksize),
  474         KOBJMETHOD(channel_trigger,             ad1816chan_trigger),
  475         KOBJMETHOD(channel_getptr,              ad1816chan_getptr),
  476         KOBJMETHOD(channel_getcaps,             ad1816chan_getcaps),
  477         { 0, 0 }
  478 };
  479 CHANNEL_DECLARE(ad1816chan);
  480 
  481 /* -------------------------------------------------------------------- */
  482 
  483 static void
  484 ad1816_release_resources(struct ad1816_info *ad1816, device_t dev)
  485 {
  486         if (ad1816->irq) {
  487                 if (ad1816->ih)
  488                         bus_teardown_intr(dev, ad1816->irq, ad1816->ih);
  489                 bus_release_resource(dev, SYS_RES_IRQ, ad1816->irq_rid, ad1816->irq);
  490                 ad1816->irq = 0;
  491         }
  492         if (ad1816->drq1) {
  493                 isa_dma_release(rman_get_start(ad1816->drq1));
  494                 bus_release_resource(dev, SYS_RES_DRQ, ad1816->drq1_rid, ad1816->drq1);
  495                 ad1816->drq1 = 0;
  496         }
  497         if (ad1816->drq2) {
  498                 isa_dma_release(rman_get_start(ad1816->drq2));
  499                 bus_release_resource(dev, SYS_RES_DRQ, ad1816->drq2_rid, ad1816->drq2);
  500                 ad1816->drq2 = 0;
  501         }
  502         if (ad1816->io_base) {
  503                 bus_release_resource(dev, SYS_RES_IOPORT, ad1816->io_rid, ad1816->io_base);
  504                 ad1816->io_base = 0;
  505         }
  506         if (ad1816->parent_dmat) {
  507                 bus_dma_tag_destroy(ad1816->parent_dmat);
  508                 ad1816->parent_dmat = 0;
  509         }
  510         if (ad1816->lock)
  511                 snd_mtxfree(ad1816->lock);
  512 
  513         free(ad1816, M_DEVBUF);
  514 }
  515 
  516 static int
  517 ad1816_alloc_resources(struct ad1816_info *ad1816, device_t dev)
  518 {
  519         int ok = 1, pdma, rdma;
  520 
  521         if (!ad1816->io_base)
  522                 ad1816->io_base = bus_alloc_resource_any(dev, 
  523                         SYS_RES_IOPORT, &ad1816->io_rid, RF_ACTIVE);
  524         if (!ad1816->irq)
  525                 ad1816->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ,
  526                         &ad1816->irq_rid, RF_ACTIVE);
  527         if (!ad1816->drq1)
  528                 ad1816->drq1 = bus_alloc_resource_any(dev, SYS_RES_DRQ,
  529                         &ad1816->drq1_rid, RF_ACTIVE);
  530         if (!ad1816->drq2)
  531                 ad1816->drq2 = bus_alloc_resource_any(dev, SYS_RES_DRQ, 
  532                         &ad1816->drq2_rid, RF_ACTIVE);
  533 
  534         if (!ad1816->io_base || !ad1816->drq1 || !ad1816->irq) ok = 0;
  535 
  536         if (ok) {
  537                 pdma = rman_get_start(ad1816->drq1);
  538                 isa_dma_acquire(pdma);
  539                 isa_dmainit(pdma, ad1816->bufsize);
  540                 if (ad1816->drq2) {
  541                         rdma = rman_get_start(ad1816->drq2);
  542                         isa_dma_acquire(rdma);
  543                         isa_dmainit(rdma, ad1816->bufsize);
  544                 } else
  545                         rdma = pdma;
  546                 if (pdma == rdma)
  547                         pcm_setflags(dev, pcm_getflags(dev) | SD_F_SIMPLEX);
  548         }
  549 
  550         return ok;
  551 }
  552 
  553 static int
  554 ad1816_init(struct ad1816_info *ad1816, device_t dev)
  555 {
  556         ad1816_write(ad1816, 1, 0x2);   /* disable interrupts */
  557         ad1816_write(ad1816, 32, 0x90F0);       /* SoundSys Mode, split fmt */
  558 
  559         ad1816_write(ad1816, 5, 0x8080);        /* FM volume mute */
  560         ad1816_write(ad1816, 6, 0x8080);        /* I2S1 volume mute */
  561         ad1816_write(ad1816, 7, 0x8080);        /* I2S0 volume mute */
  562         ad1816_write(ad1816, 17, 0x8888);       /* VID Volume mute */
  563         ad1816_write(ad1816, 20, 0x5050);       /* recsrc mic, agc off */
  564         /* adc gain is set to 0 */
  565 
  566         return 0;
  567 }
  568 
  569 static int
  570 ad1816_probe(device_t dev)
  571 {
  572         char *s = NULL;
  573         u_int32_t logical_id = isa_get_logicalid(dev);
  574 
  575         switch (logical_id) {
  576         case 0x80719304: /* ADS7180 */
  577                 s = "AD1816";
  578                 break;
  579         }
  580 
  581         if (s) {
  582                 device_set_desc(dev, s);
  583                 return 0;
  584         }
  585         return ENXIO;
  586 }
  587 
  588 static int
  589 ad1816_attach(device_t dev)
  590 {
  591         struct ad1816_info *ad1816;
  592         char status[SND_STATUSLEN], status2[SND_STATUSLEN];
  593 
  594         ad1816 = (struct ad1816_info *)malloc(sizeof *ad1816, M_DEVBUF, M_NOWAIT | M_ZERO);
  595         if (!ad1816) return ENXIO;
  596 
  597         ad1816->lock = snd_mtxcreate(device_get_nameunit(dev), "sound softc");
  598         ad1816->io_rid = 2;
  599         ad1816->irq_rid = 0;
  600         ad1816->drq1_rid = 0;
  601         ad1816->drq2_rid = 1;
  602         ad1816->bufsize = pcm_getbuffersize(dev, 4096, DSP_BUFFSIZE, 65536);
  603 
  604         if (!ad1816_alloc_resources(ad1816, dev)) goto no;
  605         ad1816_init(ad1816, dev);
  606         if (mixer_init(dev, &ad1816mixer_class, ad1816)) goto no;
  607 
  608         snd_setup_intr(dev, ad1816->irq, 0, ad1816_intr, ad1816, &ad1816->ih);
  609         if (bus_dma_tag_create(/*parent*/NULL, /*alignment*/2, /*boundary*/0,
  610                         /*lowaddr*/BUS_SPACE_MAXADDR_24BIT,
  611                         /*highaddr*/BUS_SPACE_MAXADDR,
  612                         /*filter*/NULL, /*filterarg*/NULL,
  613                         /*maxsize*/ad1816->bufsize, /*nsegments*/1,
  614                         /*maxsegz*/0x3ffff,
  615                         /*flags*/0, /*lockfunc*/busdma_lock_mutex,
  616                         /*lockarg*/ &Giant, &ad1816->parent_dmat) != 0) {
  617                 device_printf(dev, "unable to create dma tag\n");
  618                 goto no;
  619         }
  620         if (ad1816->drq2)
  621                 snprintf(status2, SND_STATUSLEN, ":%ld", rman_get_start(ad1816->drq2));
  622         else
  623                 status2[0] = '\0';
  624 
  625         snprintf(status, SND_STATUSLEN, "at io 0x%lx irq %ld drq %ld%s bufsz %u %s",
  626                 rman_get_start(ad1816->io_base),
  627                 rman_get_start(ad1816->irq),
  628                 rman_get_start(ad1816->drq1),
  629                 status2,
  630                 ad1816->bufsize,
  631                 PCM_KLDSTRING(snd_ad1816));
  632 
  633         if (pcm_register(dev, ad1816, 1, 1)) goto no;
  634         pcm_addchan(dev, PCMDIR_REC, &ad1816chan_class, ad1816);
  635         pcm_addchan(dev, PCMDIR_PLAY, &ad1816chan_class, ad1816);
  636         pcm_setstatus(dev, status);
  637 
  638         return 0;
  639 no:
  640         ad1816_release_resources(ad1816, dev);
  641 
  642         return ENXIO;
  643 
  644 }
  645 
  646 static int
  647 ad1816_detach(device_t dev)
  648 {
  649         int r;
  650         struct ad1816_info *ad1816;
  651 
  652         r = pcm_unregister(dev);
  653         if (r)
  654                 return r;
  655 
  656         ad1816 = pcm_getdevinfo(dev);
  657         ad1816_release_resources(ad1816, dev);
  658         return 0;
  659 }
  660 
  661 static device_method_t ad1816_methods[] = {
  662         /* Device interface */
  663         DEVMETHOD(device_probe,         ad1816_probe),
  664         DEVMETHOD(device_attach,        ad1816_attach),
  665         DEVMETHOD(device_detach,        ad1816_detach),
  666 
  667         { 0, 0 }
  668 };
  669 
  670 static driver_t ad1816_driver = {
  671         "pcm",
  672         ad1816_methods,
  673         PCM_SOFTC_SIZE,
  674 };
  675 
  676 DRIVER_MODULE(snd_ad1816, isa, ad1816_driver, pcm_devclass, 0, 0);
  677 DRIVER_MODULE(snd_ad1816, acpi, ad1816_driver, pcm_devclass, 0, 0);
  678 MODULE_DEPEND(snd_ad1816, sound, SOUND_MINVER, SOUND_PREFVER, SOUND_MAXVER);
  679 MODULE_VERSION(snd_ad1816, 1);
  680 
  681 

Cache object: e0bb7c5f288ce231064b7fc9525f5564


[ 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.