source: mainline/uspace/drv/audio/sb16/mixer.c@ a4a4e47

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

sb16: Simplify direct mode sound IO.

(Follow hw design guide)

  • Property mode set to 100644
File size: 5.0 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 <bool.h>
30#include <errno.h>
31#include <libarch/ddi.h>
32
33#include "ddf_log.h"
34#include "mixer.h"
35
36#define CT_MIXER_RESET_ADDRESS 0x00
37
38typedef struct volume_item {
39 uint8_t address;
40 uint8_t channels;
41 const char *description;
42 unsigned min_value;
43 unsigned max_value;
44 unsigned shift;
45 bool same_reg;
46} volume_item_t;
47
48static const volume_item_t volume_ct1335[] = {
49 { 0x02, 1, "Master", 0, 7, 1, true },
50 { 0x06, 1, "MIDI", 0, 7, 1, true },
51 { 0x08, 1, "CD", 0, 7, 1, true },
52 { 0x0a, 1, "Voice", 0, 3, 1, true },
53};
54
55static const volume_item_t volume_ct1345[] = {
56 { 0x04, 2, "Voice", 0, 7, 1, true },
57 { 0x0a, 1, "Mic", 0, 3, 1, true },
58 { 0x22, 2, "Master", 0, 7, 1, true },
59 { 0x26, 2, "MIDI", 0, 7, 1, true },
60 { 0x28, 2, "CD", 0, 7, 1, true },
61 { 0x2e, 2, "Line", 0, 7, 1, true },
62};
63
64static const volume_item_t volume_ct1745[] = {
65 { 0x30, 2, "Master", 0, 31, 3, false },
66 { 0x32, 2, "Voice", 0, 31, 3, false },
67 { 0x34, 2, "MIDI", 0, 31, 3, false },
68 { 0x36, 2, "CD", 0, 31, 3, false },
69 { 0x38, 2, "Line", 0, 31, 3, false },
70 { 0x3a, 1, "Mic", 0, 31, 3, false },
71 { 0x3b, 1, "PC Speaker", 0, 3, 6, false },
72 { 0x3f, 2, "Input Gain", 0, 3, 6, false },
73 { 0x41, 2, "Output Gain", 0, 3, 6, false },
74 { 0x44, 2, "Treble", 0, 15, 4, false },
75 { 0x46, 2, "Bass", 0, 15, 4, false },
76};
77
78static const struct {
79 size_t count;
80 const volume_item_t *table;
81} volume_table[] = {
82 [SB_MIXER_NONE] = { 0, NULL },
83 [SB_MIXER_UNKNOWN] = { 0, NULL },
84 [SB_MIXER_CT1335] = {
85 sizeof(volume_ct1335) / sizeof(volume_item_t), volume_ct1335 },
86 [SB_MIXER_CT1345] = {
87 sizeof(volume_ct1345) / sizeof(volume_item_t), volume_ct1345 },
88 [SB_MIXER_CT1745] = {
89 sizeof(volume_ct1745) / sizeof(volume_item_t), volume_ct1745 },
90};
91
92const char * mixer_type_to_str(mixer_type_t type)
93{
94 static const char * names[] = {
95 [SB_MIXER_CT1335] = "CT 1335",
96 [SB_MIXER_CT1345] = "CT 1345",
97 [SB_MIXER_CT1745] = "CT 1745",
98 [SB_MIXER_UNKNOWN] = "Unknown mixer",
99 };
100 return names[type];
101}
102/*----------------------------------------------------------------------------*/
103int mixer_init(sb16_regs_t *regs, mixer_type_t type)
104{
105 if (type == SB_MIXER_UNKNOWN)
106 return ENOTSUP;
107
108 if (type != SB_MIXER_NONE) {
109 pio_write_8(&regs->mixer_address, CT_MIXER_RESET_ADDRESS);
110 pio_write_8(&regs->mixer_data, 1);
111 }
112 return EOK;
113}
114/*----------------------------------------------------------------------------*/
115void mixer_load_volume_levels(sb16_regs_t *regs, mixer_type_t type)
116{
117 /* Default values are ok for now */
118}
119/*----------------------------------------------------------------------------*/
120void mixer_store_volume_levels(sb16_regs_t *regs, mixer_type_t type)
121{
122 /* Default values are ok for now */
123}
124/*----------------------------------------------------------------------------*/
125int mixer_get_control_item_count(mixer_type_t type)
126{
127 return volume_table[type].count;
128}
129/*----------------------------------------------------------------------------*/
130int mixer_get_control_item_info(mixer_type_t type, unsigned index,
131 const char** name, unsigned *channels)
132{
133 if (index > volume_table[type].count)
134 return ENOENT;
135
136 if (name)
137 *name = volume_table[type].table[index].description;
138 if (channels)
139 *channels = volume_table[type].table[index].channels;
140 return EOK;
141}
142/*----------------------------------------------------------------------------*/
143int mixer_set_volume_level(sb16_regs_t *regs, mixer_type_t type,
144 unsigned item, unsigned channel, unsigned level)
145{
146 return ENOTSUP;
147}
148/*----------------------------------------------------------------------------*/
149unsigned mixer_get_volume_level(sb16_regs_t *regs, mixer_type_t type,
150 unsigned item, unsigned channel)
151{
152 return 0;
153}
Note: See TracBrowser for help on using the repository browser.