source: mainline/uspace/drv/audio/sb16/sb16.c@ 485a496

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

sb16: Implement audio mixer interface.

Move mixer fun creation and initialization to sb_init.

  • Property mode set to 100644
File size: 4.9 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#include <audio_mixer_iface.h>
32
33#include "beep.h"
34#include "ddf_log.h"
35#include "dsp_commands.h"
36#include "dsp.h"
37#include "sb16.h"
38
39extern audio_mixer_iface_t sb_mixer_iface;
40
41static ddf_dev_ops_t sb_mixer_ops = {
42 .interfaces[AUDIO_MIXER_IFACE] = &sb_mixer_iface,
43};
44
45/* ISA interrupts should be edge-triggered so there should be no need for
46 * irq code magic */
47static const irq_cmd_t irq_cmds[] = {{ .cmd = CMD_ACCEPT }};
48static const irq_code_t irq_code =
49 { .cmdcount = 1, .cmds = (irq_cmd_t*)irq_cmds }; // FIXME: Remove cast
50
51static inline sb_mixer_type_t sb_mixer_type_by_dsp_version(
52 unsigned major, unsigned minor)
53{
54 switch (major)
55 {
56 case 1: return SB_MIXER_NONE; /* SB 1.5 and early 2.0 = no mixer chip */
57 case 2: return (minor == 0) ? SB_MIXER_NONE : SB_MIXER_CT1335;
58 case 3: return SB_MIXER_CT1345; /* SB Pro */
59 case 4: return SB_MIXER_CT1745; /* SB 16 */
60 default: return SB_MIXER_UNKNOWN;
61 }
62}
63/*----------------------------------------------------------------------------*/
64irq_code_t * sb16_irq_code(void)
65{
66 // FIXME: Remove this cast
67 return (irq_code_t*)&irq_code;
68}
69/*----------------------------------------------------------------------------*/
70int sb16_init_sb16(sb16_t *sb, void *regs, size_t size,
71 ddf_dev_t *dev, int dma8, int dma16)
72{
73 assert(sb);
74 /* Setup registers */
75 int ret = pio_enable(regs, size, (void**)&sb->regs);
76 if (ret != EOK)
77 return ret;
78 ddf_log_debug("PIO registers at %p accessible.\n", sb->regs);
79
80 /* Initialize DSP */
81 ret = sb_dsp_init(&sb->dsp, sb->regs, dev, dma8, dma16);
82 if (ret != EOK) {
83 ddf_log_error("Failed to initialize SB DSP: %s.\n",
84 str_error(ret));
85 return ret;
86 }
87 ddf_log_note("Sound blaster DSP (%x.%x) initialized.\n",
88 sb->dsp.version.major, sb->dsp.version.minor);
89
90 /* Initialize mixer */
91 const sb_mixer_type_t mixer_type = sb_mixer_type_by_dsp_version(
92 sb->dsp.version.major, sb->dsp.version.minor);
93
94 ddf_fun_t *mixer_fun = ddf_fun_create(dev, fun_exposed, "mixer");
95 if (!mixer_fun) {
96 ddf_log_error("Failed to create mixer function.\n");
97 return ENOMEM;
98 }
99 ret = sb_mixer_init(&sb->mixer, sb->regs, mixer_type);
100 if (ret != EOK) {
101 ddf_log_error("Failed to initialize SB mixer: %s.\n",
102 str_error(ret));
103 return ret;
104 }
105
106 ddf_log_note("Initialized mixer: %s.\n",
107 sb_mixer_type_str(sb->mixer.type));
108 mixer_fun->driver_data = &sb->mixer;
109 mixer_fun->ops = &sb_mixer_ops;
110
111 ret = ddf_fun_bind(mixer_fun);
112 if (ret != EOK) {
113 ddf_log_error(
114 "Failed to bind mixer function: %s.\n", str_error(ret));
115 mixer_fun->driver_data = NULL;
116 ddf_fun_destroy(mixer_fun);
117 return ret;
118 }
119
120 ddf_log_note("Playing startup sound.\n");
121 sb_dsp_play(&sb->dsp, beep, beep_size, 44100, 1, 8);
122
123 return EOK;
124}
125/*----------------------------------------------------------------------------*/
126int sb16_init_mpu(sb16_t *sb, void *regs, size_t size)
127{
128 sb->mpu_regs = NULL;
129 return ENOTSUP;
130}
131/*----------------------------------------------------------------------------*/
132void sb16_interrupt(sb16_t *sb)
133{
134 assert(sb);
135 /* The acknowledgment of interrupts on DSP version 4.xx is different;
136 * It can contain MPU-401 indicator and DMA16 transfers are acked
137 * differently */
138 if (sb->dsp.version.major >= 4) {
139 pio_write_8(&sb->regs->mixer_address, MIXER_IRQ_STATUS_ADDRESS);
140 const uint8_t irq_mask = pio_read_8(&sb->regs->mixer_data);
141 /* Third bit is MPU-401 interrupt */
142 if (irq_mask & 0x4) {
143 return;
144 }
145 } else {
146 ddf_log_debug("SB16 interrupt.\n");
147 }
148 sb_dsp_interrupt(&sb->dsp);
149}
Note: See TracBrowser for help on using the repository browser.