Christian Gmeiner | cdbf33a | 2007-05-22 15:56:05 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id: wm8975.c 13453 2007-05-20 23:10:15Z christian $ |
| 9 | * |
| 10 | * Driver for MAS35xx audio codec |
| 11 | * |
| 12 | * |
| 13 | * Copyright (c) 2007 by Christian Gmeiner |
| 14 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame^] | 15 | * This program is free software; you can redistribute it and/or |
| 16 | * modify it under the terms of the GNU General Public License |
| 17 | * as published by the Free Software Foundation; either version 2 |
| 18 | * of the License, or (at your option) any later version. |
Christian Gmeiner | cdbf33a | 2007-05-22 15:56:05 +0000 | [diff] [blame] | 19 | * |
| 20 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 21 | * KIND, either express or implied. |
| 22 | * |
| 23 | ****************************************************************************/ |
| 24 | |
| 25 | #include "config.h" |
Marcoen Hirschberg | 85f06b8 | 2007-05-22 20:39:50 +0000 | [diff] [blame] | 26 | #include "audiohw.h" |
Christian Gmeiner | b1806b2 | 2008-04-22 13:43:01 +0000 | [diff] [blame] | 27 | #include "mas.h" |
Christian Gmeiner | cdbf33a | 2007-05-22 15:56:05 +0000 | [diff] [blame] | 28 | |
| 29 | const struct sound_settings_info audiohw_settings[] = { |
| 30 | #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) |
| 31 | [SOUND_VOLUME] = {"dB", 0, 1,-100, 12, -25}, |
| 32 | [SOUND_BASS] = {"dB", 0, 1, -12, 12, 6}, |
| 33 | [SOUND_TREBLE] = {"dB", 0, 1, -12, 12, 6}, |
| 34 | #else /* MAS3507D */ |
| 35 | [SOUND_VOLUME] = {"dB", 0, 1, -78, 18, -18}, |
| 36 | [SOUND_BASS] = {"dB", 0, 1, -15, 15, 7}, |
| 37 | [SOUND_TREBLE] = {"dB", 0, 1, -15, 15, 7}, |
| 38 | #endif |
Marcoen Hirschberg | df31f5f | 2007-12-10 11:14:28 +0000 | [diff] [blame] | 39 | [SOUND_BALANCE] = {"%", 0, 1,-100, 100, 0}, |
Christian Gmeiner | cdbf33a | 2007-05-22 15:56:05 +0000 | [diff] [blame] | 40 | [SOUND_CHANNELS] = {"", 0, 1, 0, 5, 0}, |
Thom Johansen | 8f72192 | 2007-10-09 21:29:20 +0000 | [diff] [blame] | 41 | [SOUND_STEREO_WIDTH] = {"%", 0, 5, 0, 250, 100}, |
Christian Gmeiner | cdbf33a | 2007-05-22 15:56:05 +0000 | [diff] [blame] | 42 | #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) |
| 43 | [SOUND_LOUDNESS] = {"dB", 0, 1, 0, 17, 0}, |
| 44 | [SOUND_AVC] = {"", 0, 1, -1, 4, 0}, |
| 45 | [SOUND_MDB_STRENGTH] = {"dB", 0, 1, 0, 127, 48}, |
| 46 | [SOUND_MDB_HARMONICS] = {"%", 0, 1, 0, 100, 50}, |
| 47 | [SOUND_MDB_CENTER] = {"Hz", 0, 10, 20, 300, 60}, |
| 48 | [SOUND_MDB_SHAPE] = {"Hz", 0, 10, 50, 300, 90}, |
| 49 | [SOUND_MDB_ENABLE] = {"", 0, 1, 0, 1, 0}, |
| 50 | [SOUND_SUPERBASS] = {"", 0, 1, 0, 1, 0}, |
| 51 | #endif |
Peter D'Hoye | 825d89f | 2008-05-25 21:19:07 +0000 | [diff] [blame] | 52 | #if CONFIG_CODEC == MAS3587F && defined(HAVE_RECORDING) |
Christian Gmeiner | cdbf33a | 2007-05-22 15:56:05 +0000 | [diff] [blame] | 53 | [SOUND_LEFT_GAIN] = {"dB", 1, 1, 0, 15, 8}, |
| 54 | [SOUND_RIGHT_GAIN] = {"dB", 1, 1, 0, 15, 8}, |
| 55 | [SOUND_MIC_GAIN] = {"dB", 1, 1, 0, 15, 2}, |
| 56 | #endif |
| 57 | }; |
Christian Gmeiner | b1806b2 | 2008-04-22 13:43:01 +0000 | [diff] [blame] | 58 | |
| 59 | |
| 60 | int channel_configuration = SOUND_CHAN_STEREO; |
| 61 | int stereo_width = 100; |
| 62 | |
| 63 | |
| 64 | static void set_channel_config(void) |
| 65 | { |
| 66 | /* default values: stereo */ |
| 67 | unsigned long val_ll = 0x80000; |
| 68 | unsigned long val_lr = 0; |
| 69 | unsigned long val_rl = 0; |
| 70 | unsigned long val_rr = 0x80000; |
| 71 | |
| 72 | switch(channel_configuration) |
| 73 | { |
| 74 | /* case SOUND_CHAN_STEREO unnecessary */ |
| 75 | |
| 76 | case SOUND_CHAN_MONO: |
| 77 | val_ll = 0xc0000; |
| 78 | val_lr = 0xc0000; |
| 79 | val_rl = 0xc0000; |
| 80 | val_rr = 0xc0000; |
| 81 | break; |
| 82 | |
| 83 | case SOUND_CHAN_CUSTOM: |
| 84 | { |
| 85 | /* fixed point variables (matching MAS internal format) |
| 86 | integer part: upper 13 bits (inlcuding sign) |
| 87 | fractional part: lower 19 bits */ |
| 88 | long fp_width, fp_straight, fp_cross; |
| 89 | |
| 90 | fp_width = (stereo_width << 19) / 100; |
| 91 | if (stereo_width <= 100) |
| 92 | { |
| 93 | fp_straight = - ((1<<19) + fp_width) / 2; |
| 94 | fp_cross = fp_straight + fp_width; |
| 95 | } |
| 96 | else |
| 97 | { |
| 98 | /* straight = - (1 + width) / (2 * width) */ |
| 99 | fp_straight = - ((((1<<19) + fp_width) / (fp_width >> 9)) << 9); |
| 100 | fp_cross = (1<<19) + fp_straight; |
| 101 | } |
| 102 | val_ll = val_rr = fp_straight & 0xfffff; |
| 103 | val_lr = val_rl = fp_cross & 0xfffff; |
| 104 | } |
| 105 | break; |
| 106 | |
| 107 | case SOUND_CHAN_MONO_LEFT: |
| 108 | val_ll = 0x80000; |
| 109 | val_lr = 0x80000; |
| 110 | val_rl = 0; |
| 111 | val_rr = 0; |
| 112 | break; |
| 113 | |
| 114 | case SOUND_CHAN_MONO_RIGHT: |
| 115 | val_ll = 0; |
| 116 | val_lr = 0; |
| 117 | val_rl = 0x80000; |
| 118 | val_rr = 0x80000; |
| 119 | break; |
| 120 | |
| 121 | case SOUND_CHAN_KARAOKE: |
| 122 | val_ll = 0xc0000; |
| 123 | val_lr = 0x40000; |
| 124 | val_rl = 0x40000; |
| 125 | val_rr = 0xc0000; |
| 126 | break; |
| 127 | } |
| 128 | |
| 129 | #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) |
| 130 | mas_writemem(MAS_BANK_D0, MAS_D0_OUT_LL, &val_ll, 1); /* LL */ |
| 131 | mas_writemem(MAS_BANK_D0, MAS_D0_OUT_LR, &val_lr, 1); /* LR */ |
| 132 | mas_writemem(MAS_BANK_D0, MAS_D0_OUT_RL, &val_rl, 1); /* RL */ |
| 133 | mas_writemem(MAS_BANK_D0, MAS_D0_OUT_RR, &val_rr, 1); /* RR */ |
| 134 | #elif CONFIG_CODEC == MAS3507D |
| 135 | mas_writemem(MAS_BANK_D1, 0x7f8, &val_ll, 1); /* LL */ |
| 136 | mas_writemem(MAS_BANK_D1, 0x7f9, &val_lr, 1); /* LR */ |
| 137 | mas_writemem(MAS_BANK_D1, 0x7fa, &val_rl, 1); /* RL */ |
| 138 | mas_writemem(MAS_BANK_D1, 0x7fb, &val_rr, 1); /* RR */ |
| 139 | #endif |
| 140 | } |
| 141 | |
| 142 | void audiohw_set_channel(int val) |
| 143 | { |
| 144 | channel_configuration = val; |
| 145 | set_channel_config(); |
| 146 | } |
| 147 | |
| 148 | void audiohw_set_stereo_width(int val) |
| 149 | { |
| 150 | stereo_width = val; |
| 151 | if (channel_configuration == SOUND_CHAN_CUSTOM) { |
| 152 | set_channel_config(); |
| 153 | } |
| 154 | } |
Christian Gmeiner | 8391526 | 2008-04-28 08:37:18 +0000 | [diff] [blame] | 155 | |
| 156 | void audiohw_set_bass(int val) |
| 157 | { |
| 158 | #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) |
| 159 | unsigned tmp = ((unsigned)(val * 8) & 0xff) << 8; |
| 160 | mas_codec_writereg(0x14, tmp); |
| 161 | #elif CONFIG_CODEC == MAS3507D |
| 162 | mas_writereg(MAS_REG_KBASS, bass_table[val+15]); |
| 163 | #endif |
| 164 | } |
| 165 | |
Christian Gmeiner | 05e8488 | 2008-05-14 21:35:19 +0000 | [diff] [blame] | 166 | #if CONFIG_CODEC == MAS3507D |
| 167 | void audiohw_set_prescaler(int val) |
| 168 | { |
| 169 | mas_writereg(MAS_REG_KPRESCALE, prescale_table[val/10]); |
| 170 | } |
| 171 | #endif |
| 172 | |
Christian Gmeiner | 8391526 | 2008-04-28 08:37:18 +0000 | [diff] [blame] | 173 | void audiohw_set_treble(int val) |
| 174 | { |
| 175 | #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) |
| 176 | unsigned tmp = ((unsigned)(val * 8) & 0xff) << 8; |
| 177 | mas_codec_writereg(0x15, tmp); |
| 178 | #elif CONFIG_CODEC == MAS3507D |
| 179 | mas_writereg(MAS_REG_KTREBLE, treble_table[val+15]); |
| 180 | #endif |
| 181 | } |
Christian Gmeiner | 785e776 | 2008-05-13 06:19:16 +0000 | [diff] [blame] | 182 | |
| 183 | #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) |
| 184 | void audiohw_set_volume(int val) { |
| 185 | unsigned tmp = ((unsigned)(val + 115) & 0xff) << 8; |
| 186 | mas_codec_writereg(0x10, tmp); |
| 187 | } |
| 188 | |
| 189 | void audiohw_set_balance(int val) { |
| 190 | unsigned tmp = ((unsigned)(val * 127 / 100) & 0xff) << 8; |
| 191 | mas_codec_writereg(0x11, tmp); |
| 192 | } |
| 193 | #endif |