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

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

sb16: Switch to new ISA bus provided DMA controller access.

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