source: mainline/uspace/drv/audio/sb16/sb16.c@ bf38143

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since bf38143 was bf38143, checked in by Jan Vesely <jano.vesely@…>, 14 years ago

sb16: Use new sb_dsp_t structure.

  • Property mode set to 100644
File size: 3.5 KB
RevLine 
[7a69340]1/*
2 * Copyright (c) 2011 Jan Vesely
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <errno.h>
[01282fc]30#include <str_error.h>
[7a69340]31
[9dd79bc7]32#include "ddf_log.h"
33#include "dsp_commands.h"
[cf083e8]34#include "dsp.h"
[7a69340]35#include "sb16.h"
36
37/* ISA interrupts should be edge-triggered so there should be no need for
38 * irq code magic */
39static const irq_cmd_t irq_cmds[] = {{ .cmd = CMD_ACCEPT }};
40static const irq_code_t irq_code =
41 { .cmdcount = 1, .cmds = (irq_cmd_t*)irq_cmds };
42
[bde691c]43static inline sb_mixer_type_t sb_mixer_type_by_dsp_version(
44 unsigned major, unsigned minor)
[01282fc]45{
[7a0a0f5]46 switch (major)
47 {
48 case 1: return SB_MIXER_NONE; /* SB 1.5 and early 2.0 = no mixer chip */
49 case 2: return (minor == 0) ? SB_MIXER_NONE : SB_MIXER_CT1335;
50 case 3: return SB_MIXER_CT1345; /* SB Pro */
51 case 4: return SB_MIXER_CT1745; /* SB 16 */
52 default: return SB_MIXER_UNKNOWN;
53 }
[01282fc]54}
[7a69340]55/*----------------------------------------------------------------------------*/
56irq_code_t * sb16_irq_code(void)
57{
58 return (irq_code_t*)&irq_code;
59}
60/*----------------------------------------------------------------------------*/
61int sb16_init_sb16(sb16_drv_t *drv, void *regs, size_t size)
62{
[9dd79bc7]63 assert(drv);
64 /* Setup registers */
65 int ret = pio_enable(regs, size, (void**)&drv->regs);
66 if (ret != EOK)
67 return ret;
68 ddf_log_debug("PIO registers at %p accessible.\n", drv->regs);
69
[bf38143]70 /* Initialize DSP */
71 ret = sb_dsp_init(&drv->dsp, drv->regs);
[cf083e8]72 if (ret != EOK) {
[bf38143]73 ddf_log_error("Failed to initialize SB DSP: %s.\n",
74 str_error(ret));
[cf083e8]75 return ret;
76 }
[763444e]77 ddf_log_note("Sound blaster DSP (%x.%x) initialized.\n",
[bf38143]78 drv->dsp.version.major, drv->dsp.version.minor);
[9dd79bc7]79
[01282fc]80 /* Initialize mixer */
[bde691c]81 const sb_mixer_type_t mixer_type = sb_mixer_type_by_dsp_version(
[bf38143]82 drv->dsp.version.major, drv->dsp.version.minor);
[01282fc]83
[bde691c]84 ret = sb_mixer_init(&drv->mixer, drv->regs, mixer_type);
[01282fc]85 if (ret != EOK) {
86 ddf_log_error("Failed to initialize SB mixer: %s.\n",
87 str_error(ret));
88 return ret;
89 }
[050d4fa]90 ddf_log_note("Initialized mixer: %s.\n",
[bde691c]91 sb_mixer_type_str(drv->mixer.type));
[9dd79bc7]92
[7a69340]93 return EOK;
94}
95/*----------------------------------------------------------------------------*/
96int sb16_init_mpu(sb16_drv_t *drv, void *regs, size_t size)
97{
98 return ENOTSUP;
99}
Note: See TracBrowser for help on using the repository browser.