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

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

audio/sb16: Remove optical separators.

  • Property mode set to 100644
File size: 5.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#include <audio_pcm_buffer_iface.h>
33
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;
40extern audio_pcm_buffer_iface_t sb_pcm_iface;
41
42static ddf_dev_ops_t sb_mixer_ops = {
43 .interfaces[AUDIO_MIXER_IFACE] = &sb_mixer_iface,
44};
45
46static ddf_dev_ops_t sb_pcm_ops = {
47 .interfaces[AUDIO_PCM_BUFFER_IFACE] = &sb_pcm_iface,
48};
49
50/* ISA interrupts should be edge-triggered so there should be no need for
51 * irq code magic, but we still need to ack those interrupts ASAP. */
52static const irq_cmd_t irq_cmds[] = {
53 { .cmd = CMD_PIO_READ_8, .dstarg = 1 }, /* Address patched at runtime */
54 { .cmd = CMD_PIO_READ_8, .dstarg = 1 }, /* Address patched at runtime */
55 { .cmd = CMD_ACCEPT },
56};
57
58static inline sb_mixer_type_t sb_mixer_type_by_dsp_version(
59 unsigned major, unsigned minor)
60{
61 switch (major)
62 {
63 case 1: return SB_MIXER_NONE; /* SB 1.5 and early 2.0 = no mixer chip */
64 case 2: return (minor == 0) ? SB_MIXER_NONE : SB_MIXER_CT1335;
65 case 3: return SB_MIXER_CT1345; /* SB Pro */
66 case 4: return SB_MIXER_CT1745; /* SB 16 */
67 default: return SB_MIXER_UNKNOWN;
68 }
69}
70
71size_t sb16_irq_code_size(void)
72{
73 return sizeof(irq_cmds) / sizeof(irq_cmds[0]);
74}
75
76void sb16_irq_code(void *regs, int dma8, int dma16, irq_cmd_t cmds[], irq_pio_range_t ranges[])
77{
78 assert(regs);
79 assert(dma8 > 0 && dma8 < 4);
80 sb16_regs_t *registers = regs;
81 memcpy(cmds, irq_cmds, sizeof(irq_cmds));
82 cmds[0].addr = (void*)&registers->dsp_read_status;
83 ranges[0].base = (uintptr_t)registers;
84 ranges[0].size = sizeof(*registers);
85 if (dma16 > 4 && dma16 < 8) {
86 /* Valid dma16 */
87 cmds[1].addr = (void*)&registers->dma16_ack;
88 } else {
89 cmds[1].cmd = CMD_ACCEPT;
90 }
91}
92
93int sb16_init_sb16(sb16_t *sb, void *regs, size_t size,
94 ddf_dev_t *dev, int dma8, int dma16)
95{
96 assert(sb);
97 /* Setup registers */
98 int ret = pio_enable(regs, size, (void**)&sb->regs);
99 if (ret != EOK)
100 return ret;
101 ddf_log_debug("PIO registers at %p accessible.", sb->regs);
102
103 /* Initialize DSP */
104 ddf_fun_t *dsp_fun = ddf_fun_create(dev, fun_exposed, "dsp");
105 if (!dsp_fun) {
106 ddf_log_error("Failed to create dsp function.");
107 return ENOMEM;
108 }
109
110 ret = sb_dsp_init(&sb->dsp, sb->regs, dev, dma8, dma16);
111 if (ret != EOK) {
112 ddf_log_error("Failed to initialize SB DSP: %s.",
113 str_error(ret));
114 return ret;
115 }
116 dsp_fun->driver_data = &sb->dsp;
117 dsp_fun->ops = &sb_pcm_ops;
118 ddf_log_note("Sound blaster DSP (%x.%x) initialized.",
119 sb->dsp.version.major, sb->dsp.version.minor);
120
121 ret = ddf_fun_bind(dsp_fun);
122 if (ret != EOK) {
123 ddf_log_error(
124 "Failed to bind DSP function: %s.", str_error(ret));
125 dsp_fun->driver_data = NULL;
126 ddf_fun_destroy(dsp_fun);
127 return ret;
128 }
129
130 /* Initialize mixer */
131 const sb_mixer_type_t mixer_type = sb_mixer_type_by_dsp_version(
132 sb->dsp.version.major, sb->dsp.version.minor);
133
134 ddf_fun_t *mixer_fun = ddf_fun_create(dev, fun_exposed, "mixer");
135 if (!mixer_fun) {
136 ddf_log_error("Failed to create mixer function.");
137 ddf_fun_unbind(dsp_fun);
138 dsp_fun->driver_data = NULL;
139 ddf_fun_destroy(dsp_fun);
140 return ENOMEM;
141 }
142 ret = sb_mixer_init(&sb->mixer, sb->regs, mixer_type);
143 if (ret != EOK) {
144 ddf_log_error("Failed to initialize SB mixer: %s.",
145 str_error(ret));
146 ddf_fun_unbind(dsp_fun);
147 dsp_fun->driver_data = NULL;
148 ddf_fun_destroy(dsp_fun);
149 ddf_fun_destroy(mixer_fun);
150 return ret;
151 }
152
153 ddf_log_note("Initialized mixer: %s.",
154 sb_mixer_type_str(sb->mixer.type));
155 mixer_fun->driver_data = &sb->mixer;
156 mixer_fun->ops = &sb_mixer_ops;
157
158 ret = ddf_fun_bind(mixer_fun);
159 if (ret != EOK) {
160 ddf_log_error(
161 "Failed to bind mixer function: %s.", str_error(ret));
162 mixer_fun->driver_data = NULL;
163 ddf_fun_destroy(mixer_fun);
164
165 ddf_fun_unbind(dsp_fun);
166 dsp_fun->driver_data = NULL;
167 ddf_fun_destroy(dsp_fun);
168 return ret;
169 }
170
171 return EOK;
172}
173
174int sb16_init_mpu(sb16_t *sb, void *regs, size_t size)
175{
176 sb->mpu_regs = NULL;
177 return ENOTSUP;
178}
179
180void sb16_interrupt(sb16_t *sb)
181{
182 assert(sb);
183 /* The acknowledgment of interrupts on DSP version 4.xx is different;
184 * It can contain MPU-401 indicator and DMA16 transfers are acked
185 * differently */
186 if (sb->dsp.version.major >= 4) {
187 pio_write_8(&sb->regs->mixer_address, MIXER_IRQ_STATUS_ADDRESS);
188 const uint8_t irq_mask = pio_read_8(&sb->regs->mixer_data);
189 /* Third bit is MPU-401 interrupt */
190 if (irq_mask & 0x4) {
191 return;
192 }
193 } else {
194 ddf_log_debug("SB16 interrupt.");
195 }
196 sb_dsp_interrupt(&sb->dsp);
197}
Note: See TracBrowser for help on using the repository browser.