source: mainline/uspace/drv/audio/sb16/sb16.c@ 751d17a2

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

sb16: Play 'beep' sound on startup. Reove debug statements from interrupt routines.

  • Property mode set to 100644
File size: 4.2 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 };
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 return (irq_code_t*)&irq_code;
60}
61/*----------------------------------------------------------------------------*/
62int sb16_init_sb16(sb16_drv_t *drv, void *regs, size_t size)
63{
64 assert(drv);
65 /* Setup registers */
66 int ret = pio_enable(regs, size, (void**)&drv->regs);
67 if (ret != EOK)
68 return ret;
69 ddf_log_debug("PIO registers at %p accessible.\n", drv->regs);
70
71 /* Initialize DSP */
72 ret = sb_dsp_init(&drv->dsp, drv->regs);
73 if (ret != EOK) {
74 ddf_log_error("Failed to initialize SB DSP: %s.\n",
75 str_error(ret));
76 return ret;
77 }
78 ddf_log_note("Sound blaster DSP (%x.%x) initialized.\n",
79 drv->dsp.version.major, drv->dsp.version.minor);
80
81 /* Initialize mixer */
82 const sb_mixer_type_t mixer_type = sb_mixer_type_by_dsp_version(
83 drv->dsp.version.major, drv->dsp.version.minor);
84
85 ret = sb_mixer_init(&drv->mixer, drv->regs, mixer_type);
86 if (ret != EOK) {
87 ddf_log_error("Failed to initialize SB mixer: %s.\n",
88 str_error(ret));
89 return ret;
90 }
91 ddf_log_note("Initialized mixer: %s.\n",
92 sb_mixer_type_str(drv->mixer.type));
93
94 ddf_log_note("Playing startup sound.\n");
95 sb_dsp_play(&drv->dsp, beep, beep_size, 44100, 1, 8);
96
97 return EOK;
98}
99/*----------------------------------------------------------------------------*/
100int sb16_init_mpu(sb16_drv_t *drv, void *regs, size_t size)
101{
102 drv->mpu_regs = NULL;
103 return ENOTSUP;
104}
105/*----------------------------------------------------------------------------*/
106void sb16_interrupt(sb16_drv_t *drv)
107{
108 assert(drv);
109 /* The acknowledgment of interrupts on DSP version 4.xx is different;
110 * It can contain MPU-401 indicator and DMA16 transfers are acked
111 * differently */
112 if (drv->dsp.version.major >= 4) {
113 pio_write_8(&drv->regs->mixer_address, MIXER_IRQ_STATUS_ADDRESS);
114 const uint8_t irq_mask = pio_read_8(&drv->regs->mixer_data);
115 /* Third bit is MPU-401 interrupt */
116 if (irq_mask & 0x4) {
117 return;
118 }
119 } else {
120 ddf_log_debug("SB16 interrupt.\n");
121 }
122 sb_dsp_interrupt(&drv->dsp);
123}
Note: See TracBrowser for help on using the repository browser.