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/sb8.c

Version: -  FREEBSD  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * Copyright (c) 1999 Cameron Grant <cg@freebsd.org>
    3  * Copyright 1997,1998 Luigi Rizzo.
    4  *
    5  * Derived from files in the Voxware 3.5 distribution,
    6  * Copyright by Hannu Savolainen 1994, under the same copyright
    7  * conditions.
    8  * All rights reserved.
    9  *
   10  * Redistribution and use in source and binary forms, with or without
   11  * modification, are permitted provided that the following conditions
   12  * are met:
   13  * 1. Redistributions of source code must retain the above copyright
   14  *    notice, this list of conditions and the following disclaimer.
   15  * 2. Redistributions in binary form must reproduce the above copyright
   16  *    notice, this list of conditions and the following disclaimer in the
   17  *    documentation and/or other materials provided with the distribution.
   18  *
   19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   29  * SUCH DAMAGE.
   30  */
   31 
   32 #include <dev/sound/pcm/sound.h>
   33 
   34 #include  <dev/sound/isa/sb.h>
   35 #include  <dev/sound/chip.h>
   36 
   37 #include <isa/isavar.h>
   38 
   39 #include "mixer_if.h"
   40 
   41 SND_DECLARE_FILE("$FreeBSD: releng/5.4/sys/dev/sound/isa/sb8.c 141016 2005-01-30 01:00:13Z imp $");
   42 
   43 #define SB_DEFAULT_BUFSZ        4096
   44 
   45 static u_int32_t sb_fmt[] = {
   46         AFMT_U8,
   47         0
   48 };
   49 static struct pcmchan_caps sb200_playcaps = {4000, 23000, sb_fmt, 0};
   50 static struct pcmchan_caps sb200_reccaps = {4000, 13000, sb_fmt, 0};
   51 static struct pcmchan_caps sb201_playcaps = {4000, 44100, sb_fmt, 0};
   52 static struct pcmchan_caps sb201_reccaps = {4000, 15000, sb_fmt, 0};
   53 
   54 static u_int32_t sbpro_fmt[] = {
   55         AFMT_U8,
   56         AFMT_STEREO | AFMT_U8,
   57         0
   58 };
   59 static struct pcmchan_caps sbpro_playcaps = {4000, 44100, sbpro_fmt, 0};
   60 static struct pcmchan_caps sbpro_reccaps = {4000, 44100, sbpro_fmt, 0};
   61 
   62 struct sb_info;
   63 
   64 struct sb_chinfo {
   65         struct sb_info *parent;
   66         struct pcm_channel *channel;
   67         struct snd_dbuf *buffer;
   68         int dir;
   69         u_int32_t fmt, spd, blksz;
   70 };
   71 
   72 struct sb_info {
   73         device_t parent_dev;
   74         struct resource *io_base;       /* I/O address for the board */
   75         struct resource *irq;
   76         struct resource *drq;
   77         void *ih;
   78         bus_dma_tag_t parent_dmat;
   79 
   80         unsigned int bufsize;
   81         int bd_id;
   82         u_long bd_flags;       /* board-specific flags */
   83         struct sb_chinfo pch, rch;
   84 };
   85 
   86 static int sb_rd(struct sb_info *sb, int reg);
   87 static void sb_wr(struct sb_info *sb, int reg, u_int8_t val);
   88 static int sb_dspready(struct sb_info *sb);
   89 static int sb_cmd(struct sb_info *sb, u_char val);
   90 static int sb_cmd1(struct sb_info *sb, u_char cmd, int val);
   91 static int sb_cmd2(struct sb_info *sb, u_char cmd, int val);
   92 static u_int sb_get_byte(struct sb_info *sb);
   93 static void sb_setmixer(struct sb_info *sb, u_int port, u_int value);
   94 static int sb_getmixer(struct sb_info *sb, u_int port);
   95 static int sb_reset_dsp(struct sb_info *sb);
   96 
   97 static void sb_intr(void *arg);
   98 static int sb_speed(struct sb_chinfo *ch);
   99 static int sb_start(struct sb_chinfo *ch);
  100 static int sb_stop(struct sb_chinfo *ch);
  101 
  102 /*
  103  * Common code for the midi and pcm functions
  104  *
  105  * sb_cmd write a single byte to the CMD port.
  106  * sb_cmd1 write a CMD + 1 byte arg
  107  * sb_cmd2 write a CMD + 2 byte arg
  108  * sb_get_byte returns a single byte from the DSP data port
  109  */
  110 
  111 static void
  112 sb_lock(struct sb_info *sb) {
  113 
  114         sbc_lock(device_get_softc(sb->parent_dev));
  115 }
  116 
  117 static void
  118 sb_unlock(struct sb_info *sb) {
  119 
  120         sbc_unlock(device_get_softc(sb->parent_dev));
  121 }
  122 
  123 static int
  124 port_rd(struct resource *port, int off)
  125 {
  126         return bus_space_read_1(rman_get_bustag(port), rman_get_bushandle(port), off);
  127 }
  128 
  129 static void
  130 port_wr(struct resource *port, int off, u_int8_t data)
  131 {
  132         bus_space_write_1(rman_get_bustag(port), rman_get_bushandle(port), off, data);
  133 }
  134 
  135 static int
  136 sb_rd(struct sb_info *sb, int reg)
  137 {
  138         return port_rd(sb->io_base, reg);
  139 }
  140 
  141 static void
  142 sb_wr(struct sb_info *sb, int reg, u_int8_t val)
  143 {
  144         port_wr(sb->io_base, reg, val);
  145 }
  146 
  147 static int
  148 sb_dspready(struct sb_info *sb)
  149 {
  150         return ((sb_rd(sb, SBDSP_STATUS) & 0x80) == 0);
  151 }
  152 
  153 static int
  154 sb_dspwr(struct sb_info *sb, u_char val)
  155 {
  156         int  i;
  157 
  158         for (i = 0; i < 1000; i++) {
  159                 if (sb_dspready(sb)) {
  160                         sb_wr(sb, SBDSP_CMD, val);
  161                         return 1;
  162                 }
  163                 if (i > 10) DELAY((i > 100)? 1000 : 10);
  164         }
  165         printf("sb_dspwr(0x%02x) timed out.\n", val);
  166         return 0;
  167 }
  168 
  169 static int
  170 sb_cmd(struct sb_info *sb, u_char val)
  171 {
  172 #if 0
  173         printf("sb_cmd: %x\n", val);
  174 #endif
  175         return sb_dspwr(sb, val);
  176 }
  177 
  178 static int
  179 sb_cmd1(struct sb_info *sb, u_char cmd, int val)
  180 {
  181 #if 0
  182         printf("sb_cmd1: %x, %x\n", cmd, val);
  183 #endif
  184         if (sb_dspwr(sb, cmd)) {
  185                 return sb_dspwr(sb, val & 0xff);
  186         } else return 0;
  187 }
  188 
  189 static int
  190 sb_cmd2(struct sb_info *sb, u_char cmd, int val)
  191 {
  192 #if 0
  193         printf("sb_cmd2: %x, %x\n", cmd, val);
  194 #endif
  195         if (sb_dspwr(sb, cmd)) {
  196                 return sb_dspwr(sb, val & 0xff) &&
  197                        sb_dspwr(sb, (val >> 8) & 0xff);
  198         } else return 0;
  199 }
  200 
  201 /*
  202  * in the SB, there is a set of indirect "mixer" registers with
  203  * address at offset 4, data at offset 5
  204  *
  205  * we don't need to interlock these, the mixer lock will suffice.
  206  */
  207 static void
  208 sb_setmixer(struct sb_info *sb, u_int port, u_int value)
  209 {
  210         sb_wr(sb, SB_MIX_ADDR, (u_char) (port & 0xff)); /* Select register */
  211         DELAY(10);
  212         sb_wr(sb, SB_MIX_DATA, (u_char) (value & 0xff));
  213         DELAY(10);
  214 }
  215 
  216 static int
  217 sb_getmixer(struct sb_info *sb, u_int port)
  218 {
  219         int val;
  220 
  221         sb_wr(sb, SB_MIX_ADDR, (u_char) (port & 0xff)); /* Select register */
  222         DELAY(10);
  223         val = sb_rd(sb, SB_MIX_DATA);
  224         DELAY(10);
  225 
  226         return val;
  227 }
  228 
  229 static u_int
  230 sb_get_byte(struct sb_info *sb)
  231 {
  232         int i;
  233 
  234         for (i = 1000; i > 0; i--) {
  235                 if (sb_rd(sb, DSP_DATA_AVAIL) & 0x80)
  236                         return sb_rd(sb, DSP_READ);
  237                 else
  238                         DELAY(20);
  239         }
  240         return 0xffff;
  241 }
  242 
  243 static int
  244 sb_reset_dsp(struct sb_info *sb)
  245 {
  246         sb_wr(sb, SBDSP_RST, 3);
  247         DELAY(100);
  248         sb_wr(sb, SBDSP_RST, 0);
  249         if (sb_get_byte(sb) != 0xAA) {
  250                 DEB(printf("sb_reset_dsp 0x%lx failed\n",
  251                            rman_get_start(sb->io_base)));
  252                 return ENXIO;   /* Sorry */
  253         }
  254         return 0;
  255 }
  256 
  257 static void
  258 sb_release_resources(struct sb_info *sb, device_t dev)
  259 {
  260         if (sb->irq) {
  261                 if (sb->ih)
  262                         bus_teardown_intr(dev, sb->irq, sb->ih);
  263                 bus_release_resource(dev, SYS_RES_IRQ, 0, sb->irq);
  264                 sb->irq = 0;
  265         }
  266         if (sb->drq) {
  267                 isa_dma_release(rman_get_start(sb->drq));
  268                 bus_release_resource(dev, SYS_RES_DRQ, 0, sb->drq);
  269                 sb->drq = 0;
  270         }
  271         if (sb->io_base) {
  272                 bus_release_resource(dev, SYS_RES_IOPORT, 0, sb->io_base);
  273                 sb->io_base = 0;
  274         }
  275         if (sb->parent_dmat) {
  276                 bus_dma_tag_destroy(sb->parent_dmat);
  277                 sb->parent_dmat = 0;
  278         }
  279         free(sb, M_DEVBUF);
  280 }
  281 
  282 static int
  283 sb_alloc_resources(struct sb_info *sb, device_t dev)
  284 {
  285         int rid;
  286 
  287         rid = 0;
  288         if (!sb->io_base)
  289                 sb->io_base = bus_alloc_resource_any(dev, SYS_RES_IOPORT,
  290                         &rid, RF_ACTIVE);
  291         rid = 0;
  292         if (!sb->irq)
  293                 sb->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ,
  294                         &rid, RF_ACTIVE);
  295         rid = 0;
  296         if (!sb->drq)
  297                 sb->drq = bus_alloc_resource_any(dev, SYS_RES_DRQ,
  298                         &rid, RF_ACTIVE);
  299 
  300         if (sb->io_base && sb->drq && sb->irq) {
  301                 isa_dma_acquire(rman_get_start(sb->drq));
  302                 isa_dmainit(rman_get_start(sb->drq), sb->bufsize);
  303 
  304                 return 0;
  305         } else return ENXIO;
  306 }
  307 
  308 /************************************************************/
  309 
  310 static int
  311 sbpromix_init(struct snd_mixer *m)
  312 {
  313         struct sb_info *sb = mix_getdevinfo(m);
  314 
  315         mix_setdevs(m, SOUND_MASK_SYNTH | SOUND_MASK_PCM | SOUND_MASK_LINE |
  316                        SOUND_MASK_MIC | SOUND_MASK_CD | SOUND_MASK_VOLUME);
  317 
  318         mix_setrecdevs(m, SOUND_MASK_LINE | SOUND_MASK_MIC | SOUND_MASK_CD);
  319 
  320         sb_setmixer(sb, 0, 1); /* reset mixer */
  321 
  322         return 0;
  323 }
  324 
  325 static int
  326 sbpromix_set(struct snd_mixer *m, unsigned dev, unsigned left, unsigned right)
  327 {
  328         struct sb_info *sb = mix_getdevinfo(m);
  329         int reg, max;
  330         u_char val;
  331 
  332         max = 7;
  333         switch (dev) {
  334         case SOUND_MIXER_PCM:
  335                 reg = 0x04;
  336                 break;
  337 
  338         case SOUND_MIXER_MIC:
  339                 reg = 0x0a;
  340                 max = 3;
  341                 break;
  342 
  343         case SOUND_MIXER_VOLUME:
  344                 reg = 0x22;
  345                 break;
  346 
  347         case SOUND_MIXER_SYNTH:
  348                 reg = 0x26;
  349                 break;
  350 
  351         case SOUND_MIXER_CD:
  352                 reg = 0x28;
  353                 break;
  354 
  355         case SOUND_MIXER_LINE:
  356                 reg = 0x2e;
  357                 break;
  358 
  359         default:
  360                 return -1;
  361         }
  362 
  363         left = (left * max) / 100;
  364         right = (dev == SOUND_MIXER_MIC)? left : ((right * max) / 100);
  365 
  366         val = (dev == SOUND_MIXER_MIC)? (left << 1) : (left << 5 | right << 1);
  367         sb_setmixer(sb, reg, val);
  368 
  369         left = (left * 100) / max;
  370         right = (right * 100) / max;
  371 
  372         return left | (right << 8);
  373 }
  374 
  375 static int
  376 sbpromix_setrecsrc(struct snd_mixer *m, u_int32_t src)
  377 {
  378         struct sb_info *sb = mix_getdevinfo(m);
  379         u_char recdev;
  380 
  381         if      (src == SOUND_MASK_LINE)
  382                 recdev = 0x06;
  383         else if (src == SOUND_MASK_CD)
  384                 recdev = 0x02;
  385         else { /* default: mic */
  386                 src = SOUND_MASK_MIC;
  387                 recdev = 0;
  388         }
  389         sb_setmixer(sb, RECORD_SRC, recdev | (sb_getmixer(sb, RECORD_SRC) & ~0x07));
  390 
  391         return src;
  392 }
  393 
  394 static kobj_method_t sbpromix_mixer_methods[] = {
  395         KOBJMETHOD(mixer_init,          sbpromix_init),
  396         KOBJMETHOD(mixer_set,           sbpromix_set),
  397         KOBJMETHOD(mixer_setrecsrc,     sbpromix_setrecsrc),
  398         { 0, 0 }
  399 };
  400 MIXER_DECLARE(sbpromix_mixer);
  401 
  402 /************************************************************/
  403 
  404 static int
  405 sbmix_init(struct snd_mixer *m)
  406 {
  407         struct sb_info *sb = mix_getdevinfo(m);
  408 
  409         mix_setdevs(m, SOUND_MASK_SYNTH | SOUND_MASK_PCM | SOUND_MASK_CD | SOUND_MASK_VOLUME);
  410 
  411         mix_setrecdevs(m, 0);
  412 
  413         sb_setmixer(sb, 0, 1); /* reset mixer */
  414 
  415         return 0;
  416 }
  417 
  418 static int
  419 sbmix_set(struct snd_mixer *m, unsigned dev, unsigned left, unsigned right)
  420 {
  421         struct sb_info *sb = mix_getdevinfo(m);
  422         int reg, max;
  423 
  424         max = 7;
  425         switch (dev) {
  426         case SOUND_MIXER_VOLUME:
  427                 reg = 0x2;
  428                 break;
  429 
  430         case SOUND_MIXER_SYNTH:
  431                 reg = 0x6;
  432                 break;
  433 
  434         case SOUND_MIXER_CD:
  435                 reg = 0x8;
  436                 break;
  437 
  438         case SOUND_MIXER_PCM:
  439                 reg = 0x0a;
  440                 max = 3;
  441                 break;
  442 
  443         default:
  444                 return -1;
  445         }
  446 
  447         left = (left * max) / 100;
  448 
  449         sb_setmixer(sb, reg, left << 1);
  450 
  451         left = (left * 100) / max;
  452 
  453         return left | (left << 8);
  454 }
  455 
  456 static int
  457 sbmix_setrecsrc(struct snd_mixer *m, u_int32_t src)
  458 {
  459         return 0;
  460 }
  461 
  462 static kobj_method_t sbmix_mixer_methods[] = {
  463         KOBJMETHOD(mixer_init,          sbmix_init),
  464         KOBJMETHOD(mixer_set,           sbmix_set),
  465         KOBJMETHOD(mixer_setrecsrc,     sbmix_setrecsrc),
  466         { 0, 0 }
  467 };
  468 MIXER_DECLARE(sbmix_mixer);
  469 
  470 /************************************************************/
  471 
  472 static void
  473 sb_intr(void *arg)
  474 {
  475         struct sb_info *sb = (struct sb_info *)arg;
  476 
  477         sb_lock(sb);
  478         if (sndbuf_runsz(sb->pch.buffer) > 0)
  479                 chn_intr(sb->pch.channel);
  480 
  481         if (sndbuf_runsz(sb->rch.buffer) > 0)
  482                 chn_intr(sb->rch.channel);
  483 
  484         sb_rd(sb, DSP_DATA_AVAIL); /* int ack */
  485         sb_unlock(sb);
  486 }
  487 
  488 static int
  489 sb_speed(struct sb_chinfo *ch)
  490 {
  491         struct sb_info *sb = ch->parent;
  492         int play = (ch->dir == PCMDIR_PLAY)? 1 : 0;
  493         int stereo = (ch->fmt & AFMT_STEREO)? 1 : 0;
  494         int speed, tmp, thresh, max;
  495         u_char tconst;
  496 
  497         if (sb->bd_id >= 0x300) {
  498                 thresh = stereo? 11025 : 23000;
  499                 max = stereo? 22050 : 44100;
  500         } else if (sb->bd_id > 0x200) {
  501                 thresh = play? 23000 : 13000;
  502                 max = play? 44100 : 15000;
  503         } else {
  504                 thresh = 999999;
  505                 max = play? 23000 : 13000;
  506         }
  507 
  508         speed = ch->spd;
  509         if (speed > max)
  510                 speed = max;
  511 
  512         sb_lock(sb);
  513         sb->bd_flags &= ~BD_F_HISPEED;
  514         if (speed > thresh)
  515                 sb->bd_flags |= BD_F_HISPEED;
  516 
  517         tmp = 65536 - (256000000 / (speed << stereo));
  518         tconst = tmp >> 8;
  519 
  520         sb_cmd1(sb, 0x40, tconst); /* set time constant */
  521 
  522         speed = (256000000 / (65536 - tmp)) >> stereo;
  523 
  524         ch->spd = speed;
  525         sb_unlock(sb);
  526         return speed;
  527 }
  528 
  529 static int
  530 sb_start(struct sb_chinfo *ch)
  531 {
  532         struct sb_info *sb = ch->parent;
  533         int play = (ch->dir == PCMDIR_PLAY)? 1 : 0;
  534         int stereo = (ch->fmt & AFMT_STEREO)? 1 : 0;
  535         int l = ch->blksz;
  536         u_char i;
  537 
  538         l--;
  539 
  540         sb_lock(sb);
  541         if (play)
  542                 sb_cmd(sb, DSP_CMD_SPKON);
  543 
  544         if (sb->bd_flags & BD_F_HISPEED)
  545                 i = play? 0x90 : 0x98;
  546         else
  547                 i = play? 0x1c : 0x2c;
  548 
  549         sb_setmixer(sb, 0x0e, stereo? 2 : 0);
  550         sb_cmd2(sb, 0x48, l);
  551         sb_cmd(sb, i);
  552 
  553         sb->bd_flags |= BD_F_DMARUN;
  554         sb_unlock(sb);
  555         return 0;
  556 }
  557 
  558 static int
  559 sb_stop(struct sb_chinfo *ch)
  560 {
  561         struct sb_info *sb = ch->parent;
  562         int play = (ch->dir == PCMDIR_PLAY)? 1 : 0;
  563 
  564         sb_lock(sb);
  565         if (sb->bd_flags & BD_F_HISPEED)
  566                 sb_reset_dsp(sb);
  567         else
  568                 sb_cmd(sb, DSP_CMD_DMAEXIT_8);
  569 
  570         if (play)
  571                 sb_cmd(sb, DSP_CMD_SPKOFF); /* speaker off */
  572         sb_unlock(sb);
  573         sb->bd_flags &= ~BD_F_DMARUN;
  574         return 0;
  575 }
  576 
  577 /* channel interface */
  578 static void *
  579 sbchan_init(kobj_t obj, void *devinfo, struct snd_dbuf *b, struct pcm_channel *c, int dir)
  580 {
  581         struct sb_info *sb = devinfo;
  582         struct sb_chinfo *ch = (dir == PCMDIR_PLAY)? &sb->pch : &sb->rch;
  583 
  584         ch->parent = sb;
  585         ch->channel = c;
  586         ch->dir = dir;
  587         ch->buffer = b;
  588         if (sndbuf_alloc(ch->buffer, sb->parent_dmat, sb->bufsize) != 0)
  589                 return NULL;
  590         sndbuf_dmasetup(ch->buffer, sb->drq);
  591         return ch;
  592 }
  593 
  594 static int
  595 sbchan_setformat(kobj_t obj, void *data, u_int32_t format)
  596 {
  597         struct sb_chinfo *ch = data;
  598 
  599         ch->fmt = format;
  600         return 0;
  601 }
  602 
  603 static int
  604 sbchan_setspeed(kobj_t obj, void *data, u_int32_t speed)
  605 {
  606         struct sb_chinfo *ch = data;
  607 
  608         ch->spd = speed;
  609         return sb_speed(ch);
  610 }
  611 
  612 static int
  613 sbchan_setblocksize(kobj_t obj, void *data, u_int32_t blocksize)
  614 {
  615         struct sb_chinfo *ch = data;
  616 
  617         ch->blksz = blocksize;
  618         return ch->blksz;
  619 }
  620 
  621 static int
  622 sbchan_trigger(kobj_t obj, void *data, int go)
  623 {
  624         struct sb_chinfo *ch = data;
  625 
  626         if (go == PCMTRIG_EMLDMAWR || go == PCMTRIG_EMLDMARD)
  627                 return 0;
  628 
  629         sndbuf_dma(ch->buffer, go);
  630         if (go == PCMTRIG_START)
  631                 sb_start(ch);
  632         else
  633                 sb_stop(ch);
  634         return 0;
  635 }
  636 
  637 static int
  638 sbchan_getptr(kobj_t obj, void *data)
  639 {
  640         struct sb_chinfo *ch = data;
  641 
  642         return sndbuf_dmaptr(ch->buffer);
  643 }
  644 
  645 static struct pcmchan_caps *
  646 sbchan_getcaps(kobj_t obj, void *data)
  647 {
  648         struct sb_chinfo *ch = data;
  649         int p = (ch->dir == PCMDIR_PLAY)? 1 : 0;
  650 
  651         if (ch->parent->bd_id == 0x200)
  652                 return p? &sb200_playcaps : &sb200_reccaps;
  653         if (ch->parent->bd_id < 0x300)
  654                 return p? &sb201_playcaps : &sb201_reccaps;
  655         return p? &sbpro_playcaps : &sbpro_reccaps;
  656 }
  657 
  658 static kobj_method_t sbchan_methods[] = {
  659         KOBJMETHOD(channel_init,                sbchan_init),
  660         KOBJMETHOD(channel_setformat,           sbchan_setformat),
  661         KOBJMETHOD(channel_setspeed,            sbchan_setspeed),
  662         KOBJMETHOD(channel_setblocksize,        sbchan_setblocksize),
  663         KOBJMETHOD(channel_trigger,             sbchan_trigger),
  664         KOBJMETHOD(channel_getptr,              sbchan_getptr),
  665         KOBJMETHOD(channel_getcaps,             sbchan_getcaps),
  666         { 0, 0 }
  667 };
  668 CHANNEL_DECLARE(sbchan);
  669 
  670 /************************************************************/
  671 
  672 static int
  673 sb_probe(device_t dev)
  674 {
  675         char buf[64];
  676         uintptr_t func, ver, r, f;
  677 
  678         /* The parent device has already been probed. */
  679         r = BUS_READ_IVAR(device_get_parent(dev), dev, 0, &func);
  680         if (func != SCF_PCM)
  681                 return (ENXIO);
  682 
  683         r = BUS_READ_IVAR(device_get_parent(dev), dev, 1, &ver);
  684         f = (ver & 0xffff0000) >> 16;
  685         ver &= 0x0000ffff;
  686         if ((f & BD_F_ESS) || (ver >= 0x400))
  687                 return (ENXIO);
  688 
  689         snprintf(buf, sizeof buf, "SB DSP %d.%02d", (int) ver >> 8, (int) ver & 0xff);
  690 
  691         device_set_desc_copy(dev, buf);
  692 
  693         return 0;
  694 }
  695 
  696 static int
  697 sb_attach(device_t dev)
  698 {
  699         struct sb_info *sb;
  700         char status[SND_STATUSLEN];
  701         uintptr_t ver;
  702 
  703         sb = (struct sb_info *)malloc(sizeof *sb, M_DEVBUF, M_NOWAIT | M_ZERO);
  704         if (!sb)
  705                 return ENXIO;
  706 
  707         sb->parent_dev = device_get_parent(dev);
  708         BUS_READ_IVAR(device_get_parent(dev), dev, 1, &ver);
  709         sb->bd_id = ver & 0x0000ffff;
  710         sb->bd_flags = (ver & 0xffff0000) >> 16;
  711         sb->bufsize = pcm_getbuffersize(dev, 4096, SB_DEFAULT_BUFSZ, 65536);
  712 
  713         if (sb_alloc_resources(sb, dev))
  714                 goto no;
  715         if (sb_reset_dsp(sb))
  716                 goto no;
  717         if (mixer_init(dev, (sb->bd_id < 0x300)? &sbmix_mixer_class : &sbpromix_mixer_class, sb))
  718                 goto no;
  719         if (snd_setup_intr(dev, sb->irq, 0, sb_intr, sb, &sb->ih))
  720                 goto no;
  721 
  722         pcm_setflags(dev, pcm_getflags(dev) | SD_F_SIMPLEX);
  723 
  724         if (bus_dma_tag_create(/*parent*/NULL, /*alignment*/2, /*boundary*/0,
  725                         /*lowaddr*/BUS_SPACE_MAXADDR_24BIT,
  726                         /*highaddr*/BUS_SPACE_MAXADDR,
  727                         /*filter*/NULL, /*filterarg*/NULL,
  728                         /*maxsize*/sb->bufsize, /*nsegments*/1,
  729                         /*maxsegz*/0x3ffff, /*flags*/0,
  730                         /*lockfunc*/busdma_lock_mutex, /*lockarg*/&Giant,
  731                         &sb->parent_dmat) != 0) {
  732                 device_printf(dev, "unable to create dma tag\n");
  733                 goto no;
  734         }
  735 
  736         snprintf(status, SND_STATUSLEN, "at io 0x%lx irq %ld drq %ld bufsz %u %s",
  737                 rman_get_start(sb->io_base), rman_get_start(sb->irq),
  738                 rman_get_start(sb->drq), sb->bufsize, PCM_KLDSTRING(snd_sb8));
  739 
  740         if (pcm_register(dev, sb, 1, 1))
  741                 goto no;
  742         pcm_addchan(dev, PCMDIR_REC, &sbchan_class, sb);
  743         pcm_addchan(dev, PCMDIR_PLAY, &sbchan_class, sb);
  744 
  745         pcm_setstatus(dev, status);
  746 
  747         return 0;
  748 
  749 no:
  750         sb_release_resources(sb, dev);
  751         return ENXIO;
  752 }
  753 
  754 static int
  755 sb_detach(device_t dev)
  756 {
  757         int r;
  758         struct sb_info *sb;
  759 
  760         r = pcm_unregister(dev);
  761         if (r)
  762                 return r;
  763 
  764         sb = pcm_getdevinfo(dev);
  765         sb_release_resources(sb, dev);
  766         return 0;
  767 }
  768 
  769 static device_method_t sb_methods[] = {
  770         /* Device interface */
  771         DEVMETHOD(device_probe,         sb_probe),
  772         DEVMETHOD(device_attach,        sb_attach),
  773         DEVMETHOD(device_detach,        sb_detach),
  774 
  775         { 0, 0 }
  776 };
  777 
  778 static driver_t sb_driver = {
  779         "pcm",
  780         sb_methods,
  781         PCM_SOFTC_SIZE,
  782 };
  783 
  784 DRIVER_MODULE(snd_sb8, sbc, sb_driver, pcm_devclass, 0, 0);
  785 MODULE_DEPEND(snd_sb8, sound, SOUND_MINVER, SOUND_PREFVER, SOUND_MAXVER);
  786 MODULE_DEPEND(snd_sb8, snd_sbc, 1, 1, 1);
  787 MODULE_VERSION(snd_sb8, 1);
  788 
  789 
  790 
  791 

Cache object: 614c98d9670d5eb0174793de621bdf71


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