source: mainline/uspace/drv/audio/sb16/sb16.c@ 0687e1b

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

sb16: Add mixer hw initialization and volume tables.

  • Property mode set to 100644
File size: 3.8 KB
Line 
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>
30#include <str_error.h>
31
32#include "ddf_log.h"
33#include "dsp_commands.h"
34#include "dsp.h"
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
43static mixer_type_t mixer_type_by_dsp_version(unsigned major, unsigned minor)
44{
45 switch (major)
46 {
47 case 1: return SB_MIXER_NONE; /* SB 1.5 and early 2.0 = no mixer chip */
48 case 2: return (minor == 0) ? SB_MIXER_NONE : SB_MIXER_CT1335;
49 case 3: return SB_MIXER_CT1345; /* SB Pro */
50 case 4: return SB_MIXER_CT1745; /* SB 16 */
51 default: return SB_MIXER_UNKNOWN;
52 }
53}
54/*----------------------------------------------------------------------------*/
55irq_code_t * sb16_irq_code(void)
56{
57 return (irq_code_t*)&irq_code;
58}
59/*----------------------------------------------------------------------------*/
60int sb16_init_sb16(sb16_drv_t *drv, void *regs, size_t size)
61{
62 assert(drv);
63 /* Setup registers */
64 int ret = pio_enable(regs, size, (void**)&drv->regs);
65 if (ret != EOK)
66 return ret;
67 ddf_log_debug("PIO registers at %p accessible.\n", drv->regs);
68
69 dsp_reset(drv->regs);
70 /* "DSP takes about 100 microseconds to initialize itself" */
71 udelay(100);
72
73 uint8_t response;
74 ret = dsp_read(drv->regs, &response);
75 if (ret != EOK) {
76 ddf_log_error("Failed to read DSP reset response value.\n");
77 return ret;
78 }
79
80 if (response != DSP_RESET_RESPONSE) {
81 ddf_log_error("Invalid DSP reset response: %x.\n", response);
82 return EIO;
83 }
84
85 /* Get DSP version number */
86 dsp_write(drv->regs, DSP_VERSION);
87 dsp_read(drv->regs, &drv->dsp_version.major);
88 dsp_read(drv->regs, &drv->dsp_version.minor);
89 ddf_log_note("Sound blaster DSP (%x.%x) Initialized.\n",
90 drv->dsp_version.major, drv->dsp_version.minor);
91
92 /* Initialize mixer */
93 drv->mixer = mixer_type_by_dsp_version(
94 drv->dsp_version.major, drv->dsp_version.minor);
95
96 ret = mixer_init(drv->regs, drv->mixer);
97 if (ret != EOK) {
98 ddf_log_error("Failed to initialize SB mixer: %s.\n",
99 str_error(ret));
100 return ret;
101 }
102 ddf_log_note("Initialized mixer: %s.\n", mixer_type_to_str(drv->mixer));
103
104 return EOK;
105}
106/*----------------------------------------------------------------------------*/
107int sb16_init_mpu(sb16_drv_t *drv, void *regs, size_t size)
108{
109 return ENOTSUP;
110}
Note: See TracBrowser for help on using the repository browser.