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