Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 1 | /* |
| 2 | * ALSA SoC TLV320AIC3X codec driver |
| 3 | * |
Vladimir Barinov | d6b5203 | 2008-09-29 23:14:11 +0400 | [diff] [blame] | 4 | * Author: Vladimir Barinov, <vbarinov@embeddedalley.com> |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 5 | * Copyright: (C) 2007 MontaVista Software, Inc., <source@mvista.com> |
| 6 | * |
| 7 | * Based on sound/soc/codecs/wm8753.c by Liam Girdwood |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License version 2 as |
| 11 | * published by the Free Software Foundation. |
| 12 | * |
| 13 | * Notes: |
| 14 | * The AIC3X is a driver for a low power stereo audio |
Randolph Chung | 6184f10 | 2010-08-20 12:47:53 +0800 | [diff] [blame] | 15 | * codecs aic31, aic32, aic33, aic3007. |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 16 | * |
| 17 | * It supports full aic33 codec functionality. |
Randolph Chung | 6184f10 | 2010-08-20 12:47:53 +0800 | [diff] [blame] | 18 | * The compatibility with aic32, aic31 and aic3007 is as follows: |
| 19 | * aic32/aic3007 | aic31 |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 20 | * --------------------------------------- |
| 21 | * MONO_LOUT -> N/A | MONO_LOUT -> N/A |
| 22 | * | IN1L -> LINE1L |
| 23 | * | IN1R -> LINE1R |
| 24 | * | IN2L -> LINE2L |
| 25 | * | IN2R -> LINE2R |
| 26 | * | MIC3L/R -> N/A |
| 27 | * truncated internal functionality in |
| 28 | * accordance with documentation |
| 29 | * --------------------------------------- |
| 30 | * |
| 31 | * Hence the machine layer should disable unsupported inputs/outputs by |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 32 | * snd_soc_dapm_disable_pin(codec, "MONO_LOUT"), etc. |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 33 | */ |
| 34 | |
| 35 | #include <linux/module.h> |
| 36 | #include <linux/moduleparam.h> |
| 37 | #include <linux/init.h> |
| 38 | #include <linux/delay.h> |
| 39 | #include <linux/pm.h> |
| 40 | #include <linux/i2c.h> |
Jarkko Nikula | 5193d62 | 2010-05-05 13:02:03 +0300 | [diff] [blame] | 41 | #include <linux/gpio.h> |
Jarkko Nikula | 07779fd | 2010-04-26 15:49:14 +0300 | [diff] [blame] | 42 | #include <linux/regulator/consumer.h> |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 43 | #include <linux/platform_device.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 44 | #include <linux/slab.h> |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 45 | #include <sound/core.h> |
| 46 | #include <sound/pcm.h> |
| 47 | #include <sound/pcm_params.h> |
| 48 | #include <sound/soc.h> |
| 49 | #include <sound/soc-dapm.h> |
| 50 | #include <sound/initval.h> |
Jarkko Nikula | 7565fc3 | 2009-02-09 14:27:07 +0200 | [diff] [blame] | 51 | #include <sound/tlv.h> |
Jarkko Nikula | 5193d62 | 2010-05-05 13:02:03 +0300 | [diff] [blame] | 52 | #include <sound/tlv320aic3x.h> |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 53 | |
| 54 | #include "tlv320aic3x.h" |
| 55 | |
Jarkko Nikula | 07779fd | 2010-04-26 15:49:14 +0300 | [diff] [blame] | 56 | #define AIC3X_NUM_SUPPLIES 4 |
| 57 | static const char *aic3x_supply_names[AIC3X_NUM_SUPPLIES] = { |
| 58 | "IOVDD", /* I/O Voltage */ |
| 59 | "DVDD", /* Digital Core Voltage */ |
| 60 | "AVDD", /* Analog DAC Voltage */ |
| 61 | "DRVDD", /* ADC Analog and Output Driver Voltage */ |
| 62 | }; |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 63 | |
| 64 | /* codec private data */ |
| 65 | struct aic3x_priv { |
Jarkko Nikula | 07779fd | 2010-04-26 15:49:14 +0300 | [diff] [blame] | 66 | struct regulator_bulk_data supplies[AIC3X_NUM_SUPPLIES]; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 67 | enum snd_soc_control_type control_type; |
| 68 | struct aic3x_setup_data *setup; |
| 69 | void *control_data; |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 70 | unsigned int sysclk; |
| 71 | int master; |
Jarkko Nikula | 5193d62 | 2010-05-05 13:02:03 +0300 | [diff] [blame] | 72 | int gpio_reset; |
Randolph Chung | 6184f10 | 2010-08-20 12:47:53 +0800 | [diff] [blame] | 73 | #define AIC3X_MODEL_3X 0 |
| 74 | #define AIC3X_MODEL_33 1 |
| 75 | #define AIC3X_MODEL_3007 2 |
| 76 | u16 model; |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | /* |
| 80 | * AIC3X register cache |
| 81 | * We can't read the AIC3X register space when we are |
| 82 | * using 2 wire for device control, so we cache them instead. |
| 83 | * There is no point in caching the reset register |
| 84 | */ |
| 85 | static const u8 aic3x_reg[AIC3X_CACHEREGNUM] = { |
| 86 | 0x00, 0x00, 0x00, 0x10, /* 0 */ |
| 87 | 0x04, 0x00, 0x00, 0x00, /* 4 */ |
| 88 | 0x00, 0x00, 0x00, 0x01, /* 8 */ |
| 89 | 0x00, 0x00, 0x00, 0x80, /* 12 */ |
| 90 | 0x80, 0xff, 0xff, 0x78, /* 16 */ |
| 91 | 0x78, 0x78, 0x78, 0x78, /* 20 */ |
| 92 | 0x78, 0x00, 0x00, 0xfe, /* 24 */ |
| 93 | 0x00, 0x00, 0xfe, 0x00, /* 28 */ |
| 94 | 0x18, 0x18, 0x00, 0x00, /* 32 */ |
| 95 | 0x00, 0x00, 0x00, 0x00, /* 36 */ |
| 96 | 0x00, 0x00, 0x00, 0x80, /* 40 */ |
| 97 | 0x80, 0x00, 0x00, 0x00, /* 44 */ |
| 98 | 0x00, 0x00, 0x00, 0x04, /* 48 */ |
| 99 | 0x00, 0x00, 0x00, 0x00, /* 52 */ |
| 100 | 0x00, 0x00, 0x04, 0x00, /* 56 */ |
| 101 | 0x00, 0x00, 0x00, 0x00, /* 60 */ |
| 102 | 0x00, 0x04, 0x00, 0x00, /* 64 */ |
| 103 | 0x00, 0x00, 0x00, 0x00, /* 68 */ |
| 104 | 0x04, 0x00, 0x00, 0x00, /* 72 */ |
| 105 | 0x00, 0x00, 0x00, 0x00, /* 76 */ |
| 106 | 0x00, 0x00, 0x00, 0x00, /* 80 */ |
| 107 | 0x00, 0x00, 0x00, 0x00, /* 84 */ |
| 108 | 0x00, 0x00, 0x00, 0x00, /* 88 */ |
| 109 | 0x00, 0x00, 0x00, 0x00, /* 92 */ |
| 110 | 0x00, 0x00, 0x00, 0x00, /* 96 */ |
| 111 | 0x00, 0x00, 0x02, /* 100 */ |
| 112 | }; |
| 113 | |
| 114 | /* |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 115 | * write aic3x register cache |
| 116 | */ |
| 117 | static inline void aic3x_write_reg_cache(struct snd_soc_codec *codec, |
| 118 | u8 reg, u8 value) |
| 119 | { |
| 120 | u8 *cache = codec->reg_cache; |
| 121 | if (reg >= AIC3X_CACHEREGNUM) |
| 122 | return; |
| 123 | cache[reg] = value; |
| 124 | } |
| 125 | |
| 126 | /* |
Daniel Mack | 54e7e61 | 2008-04-30 16:20:52 +0200 | [diff] [blame] | 127 | * read from the aic3x register space |
| 128 | */ |
| 129 | static int aic3x_read(struct snd_soc_codec *codec, unsigned int reg, |
| 130 | u8 *value) |
| 131 | { |
| 132 | *value = reg & 0xff; |
Mark Brown | 5f34534 | 2009-07-05 17:35:28 +0100 | [diff] [blame] | 133 | |
| 134 | value[0] = i2c_smbus_read_byte_data(codec->control_data, value[0]); |
Daniel Mack | 54e7e61 | 2008-04-30 16:20:52 +0200 | [diff] [blame] | 135 | |
| 136 | aic3x_write_reg_cache(codec, reg, *value); |
| 137 | return 0; |
| 138 | } |
| 139 | |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 140 | #define SOC_DAPM_SINGLE_AIC3X(xname, reg, shift, mask, invert) \ |
| 141 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ |
| 142 | .info = snd_soc_info_volsw, \ |
| 143 | .get = snd_soc_dapm_get_volsw, .put = snd_soc_dapm_put_volsw_aic3x, \ |
| 144 | .private_value = SOC_SINGLE_VALUE(reg, shift, mask, invert) } |
| 145 | |
| 146 | /* |
| 147 | * All input lines are connected when !0xf and disconnected with 0xf bit field, |
| 148 | * so we have to use specific dapm_put call for input mixer |
| 149 | */ |
| 150 | static int snd_soc_dapm_put_volsw_aic3x(struct snd_kcontrol *kcontrol, |
| 151 | struct snd_ctl_elem_value *ucontrol) |
| 152 | { |
| 153 | struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol); |
Eero Nurkkala | 4453dba | 2009-02-06 12:01:04 +0200 | [diff] [blame] | 154 | struct soc_mixer_control *mc = |
| 155 | (struct soc_mixer_control *)kcontrol->private_value; |
| 156 | unsigned int reg = mc->reg; |
| 157 | unsigned int shift = mc->shift; |
| 158 | int max = mc->max; |
| 159 | unsigned int mask = (1 << fls(max)) - 1; |
| 160 | unsigned int invert = mc->invert; |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 161 | unsigned short val, val_mask; |
| 162 | int ret; |
| 163 | struct snd_soc_dapm_path *path; |
| 164 | int found = 0; |
| 165 | |
| 166 | val = (ucontrol->value.integer.value[0] & mask); |
| 167 | |
| 168 | mask = 0xf; |
| 169 | if (val) |
| 170 | val = mask; |
| 171 | |
| 172 | if (invert) |
| 173 | val = mask - val; |
| 174 | val_mask = mask << shift; |
| 175 | val = val << shift; |
| 176 | |
| 177 | mutex_lock(&widget->codec->mutex); |
| 178 | |
| 179 | if (snd_soc_test_bits(widget->codec, reg, val_mask, val)) { |
| 180 | /* find dapm widget path assoc with kcontrol */ |
| 181 | list_for_each_entry(path, &widget->codec->dapm_paths, list) { |
| 182 | if (path->kcontrol != kcontrol) |
| 183 | continue; |
| 184 | |
| 185 | /* found, now check type */ |
| 186 | found = 1; |
| 187 | if (val) |
| 188 | /* new connection */ |
| 189 | path->connect = invert ? 0 : 1; |
| 190 | else |
| 191 | /* old connection must be powered down */ |
| 192 | path->connect = invert ? 1 : 0; |
| 193 | break; |
| 194 | } |
| 195 | |
| 196 | if (found) |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 197 | snd_soc_dapm_sync(widget->codec); |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | ret = snd_soc_update_bits(widget->codec, reg, val_mask, val); |
| 201 | |
| 202 | mutex_unlock(&widget->codec->mutex); |
| 203 | return ret; |
| 204 | } |
| 205 | |
| 206 | static const char *aic3x_left_dac_mux[] = { "DAC_L1", "DAC_L3", "DAC_L2" }; |
| 207 | static const char *aic3x_right_dac_mux[] = { "DAC_R1", "DAC_R3", "DAC_R2" }; |
| 208 | static const char *aic3x_left_hpcom_mux[] = |
| 209 | { "differential of HPLOUT", "constant VCM", "single-ended" }; |
| 210 | static const char *aic3x_right_hpcom_mux[] = |
| 211 | { "differential of HPROUT", "constant VCM", "single-ended", |
| 212 | "differential of HPLCOM", "external feedback" }; |
| 213 | static const char *aic3x_linein_mode_mux[] = { "single-ended", "differential" }; |
Jarkko Nikula | 4d20f70 | 2008-06-27 14:07:57 +0300 | [diff] [blame] | 214 | static const char *aic3x_adc_hpf[] = |
| 215 | { "Disabled", "0.0045xFs", "0.0125xFs", "0.025xFs" }; |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 216 | |
| 217 | #define LDAC_ENUM 0 |
| 218 | #define RDAC_ENUM 1 |
| 219 | #define LHPCOM_ENUM 2 |
| 220 | #define RHPCOM_ENUM 3 |
| 221 | #define LINE1L_ENUM 4 |
| 222 | #define LINE1R_ENUM 5 |
| 223 | #define LINE2L_ENUM 6 |
| 224 | #define LINE2R_ENUM 7 |
Jarkko Nikula | 4d20f70 | 2008-06-27 14:07:57 +0300 | [diff] [blame] | 225 | #define ADC_HPF_ENUM 8 |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 226 | |
| 227 | static const struct soc_enum aic3x_enum[] = { |
| 228 | SOC_ENUM_SINGLE(DAC_LINE_MUX, 6, 3, aic3x_left_dac_mux), |
| 229 | SOC_ENUM_SINGLE(DAC_LINE_MUX, 4, 3, aic3x_right_dac_mux), |
| 230 | SOC_ENUM_SINGLE(HPLCOM_CFG, 4, 3, aic3x_left_hpcom_mux), |
| 231 | SOC_ENUM_SINGLE(HPRCOM_CFG, 3, 5, aic3x_right_hpcom_mux), |
| 232 | SOC_ENUM_SINGLE(LINE1L_2_LADC_CTRL, 7, 2, aic3x_linein_mode_mux), |
| 233 | SOC_ENUM_SINGLE(LINE1R_2_RADC_CTRL, 7, 2, aic3x_linein_mode_mux), |
| 234 | SOC_ENUM_SINGLE(LINE2L_2_LADC_CTRL, 7, 2, aic3x_linein_mode_mux), |
| 235 | SOC_ENUM_SINGLE(LINE2R_2_RADC_CTRL, 7, 2, aic3x_linein_mode_mux), |
Jarkko Nikula | 4d20f70 | 2008-06-27 14:07:57 +0300 | [diff] [blame] | 236 | SOC_ENUM_DOUBLE(AIC3X_CODEC_DFILT_CTRL, 6, 4, 4, aic3x_adc_hpf), |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 237 | }; |
| 238 | |
Jarkko Nikula | 7565fc3 | 2009-02-09 14:27:07 +0200 | [diff] [blame] | 239 | /* |
| 240 | * DAC digital volumes. From -63.5 to 0 dB in 0.5 dB steps |
| 241 | */ |
| 242 | static DECLARE_TLV_DB_SCALE(dac_tlv, -6350, 50, 0); |
| 243 | /* ADC PGA gain volumes. From 0 to 59.5 dB in 0.5 dB steps */ |
| 244 | static DECLARE_TLV_DB_SCALE(adc_tlv, 0, 50, 0); |
| 245 | /* |
| 246 | * Output stage volumes. From -78.3 to 0 dB. Muted below -78.3 dB. |
| 247 | * Step size is approximately 0.5 dB over most of the scale but increasing |
| 248 | * near the very low levels. |
| 249 | * Define dB scale so that it is mostly correct for range about -55 to 0 dB |
| 250 | * but having increasing dB difference below that (and where it doesn't count |
| 251 | * so much). This setting shows -50 dB (actual is -50.3 dB) for register |
| 252 | * value 100 and -58.5 dB (actual is -78.3 dB) for register value 117. |
| 253 | */ |
| 254 | static DECLARE_TLV_DB_SCALE(output_stage_tlv, -5900, 50, 1); |
| 255 | |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 256 | static const struct snd_kcontrol_new aic3x_snd_controls[] = { |
| 257 | /* Output */ |
Jarkko Nikula | 7565fc3 | 2009-02-09 14:27:07 +0200 | [diff] [blame] | 258 | SOC_DOUBLE_R_TLV("PCM Playback Volume", |
| 259 | LDAC_VOL, RDAC_VOL, 0, 0x7f, 1, dac_tlv), |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 260 | |
Jarkko Nikula | 098b171 | 2010-08-27 16:56:50 +0300 | [diff] [blame] | 261 | /* |
| 262 | * Output controls that map to output mixer switches. Note these are |
| 263 | * only for swapped L-to-R and R-to-L routes. See below stereo controls |
| 264 | * for direct L-to-L and R-to-R routes. |
| 265 | */ |
| 266 | SOC_SINGLE_TLV("Left Line Mixer Line2R Bypass Volume", |
| 267 | LINE2R_2_LLOPM_VOL, 0, 118, 1, output_stage_tlv), |
| 268 | SOC_SINGLE_TLV("Left Line Mixer PGAR Bypass Volume", |
| 269 | PGAR_2_LLOPM_VOL, 0, 118, 1, output_stage_tlv), |
| 270 | SOC_SINGLE_TLV("Left Line Mixer DACR1 Playback Volume", |
| 271 | DACR1_2_LLOPM_VOL, 0, 118, 1, output_stage_tlv), |
| 272 | |
| 273 | SOC_SINGLE_TLV("Right Line Mixer Line2L Bypass Volume", |
| 274 | LINE2L_2_RLOPM_VOL, 0, 118, 1, output_stage_tlv), |
| 275 | SOC_SINGLE_TLV("Right Line Mixer PGAL Bypass Volume", |
| 276 | PGAL_2_RLOPM_VOL, 0, 118, 1, output_stage_tlv), |
| 277 | SOC_SINGLE_TLV("Right Line Mixer DACL1 Playback Volume", |
| 278 | DACL1_2_RLOPM_VOL, 0, 118, 1, output_stage_tlv), |
| 279 | |
| 280 | SOC_SINGLE_TLV("Left HP Mixer Line2R Bypass Volume", |
| 281 | LINE2R_2_HPLOUT_VOL, 0, 118, 1, output_stage_tlv), |
| 282 | SOC_SINGLE_TLV("Left HP Mixer PGAR Bypass Volume", |
| 283 | PGAR_2_HPLOUT_VOL, 0, 118, 1, output_stage_tlv), |
| 284 | SOC_SINGLE_TLV("Left HP Mixer DACR1 Playback Volume", |
| 285 | DACR1_2_HPLOUT_VOL, 0, 118, 1, output_stage_tlv), |
| 286 | |
| 287 | SOC_SINGLE_TLV("Right HP Mixer Line2L Bypass Volume", |
| 288 | LINE2L_2_HPROUT_VOL, 0, 118, 1, output_stage_tlv), |
| 289 | SOC_SINGLE_TLV("Right HP Mixer PGAL Bypass Volume", |
| 290 | PGAL_2_HPROUT_VOL, 0, 118, 1, output_stage_tlv), |
| 291 | SOC_SINGLE_TLV("Right HP Mixer DACL1 Playback Volume", |
| 292 | DACL1_2_HPROUT_VOL, 0, 118, 1, output_stage_tlv), |
| 293 | |
| 294 | SOC_SINGLE_TLV("Left HPCOM Mixer Line2R Bypass Volume", |
| 295 | LINE2R_2_HPLCOM_VOL, 0, 118, 1, output_stage_tlv), |
| 296 | SOC_SINGLE_TLV("Left HPCOM Mixer PGAR Bypass Volume", |
| 297 | PGAR_2_HPLCOM_VOL, 0, 118, 1, output_stage_tlv), |
| 298 | SOC_SINGLE_TLV("Left HPCOM Mixer DACR1 Playback Volume", |
| 299 | DACR1_2_HPLCOM_VOL, 0, 118, 1, output_stage_tlv), |
| 300 | |
| 301 | SOC_SINGLE_TLV("Right HPCOM Mixer Line2L Bypass Volume", |
| 302 | LINE2L_2_HPRCOM_VOL, 0, 118, 1, output_stage_tlv), |
| 303 | SOC_SINGLE_TLV("Right HPCOM Mixer PGAL Bypass Volume", |
| 304 | PGAL_2_HPRCOM_VOL, 0, 118, 1, output_stage_tlv), |
| 305 | SOC_SINGLE_TLV("Right HPCOM Mixer DACL1 Playback Volume", |
| 306 | DACL1_2_HPRCOM_VOL, 0, 118, 1, output_stage_tlv), |
| 307 | |
| 308 | /* Stereo output controls for direct L-to-L and R-to-R routes */ |
| 309 | SOC_DOUBLE_R_TLV("Line Line2 Bypass Volume", |
| 310 | LINE2L_2_LLOPM_VOL, LINE2R_2_RLOPM_VOL, |
| 311 | 0, 118, 1, output_stage_tlv), |
| 312 | SOC_DOUBLE_R_TLV("Line PGA Bypass Volume", |
| 313 | PGAL_2_LLOPM_VOL, PGAR_2_RLOPM_VOL, |
| 314 | 0, 118, 1, output_stage_tlv), |
Jarkko Nikula | 7565fc3 | 2009-02-09 14:27:07 +0200 | [diff] [blame] | 315 | SOC_DOUBLE_R_TLV("Line DAC Playback Volume", |
| 316 | DACL1_2_LLOPM_VOL, DACR1_2_RLOPM_VOL, |
| 317 | 0, 118, 1, output_stage_tlv), |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 318 | |
Jarkko Nikula | 098b171 | 2010-08-27 16:56:50 +0300 | [diff] [blame] | 319 | SOC_DOUBLE_R_TLV("Mono Line2 Bypass Volume", |
| 320 | LINE2L_2_MONOLOPM_VOL, LINE2R_2_MONOLOPM_VOL, |
| 321 | 0, 118, 1, output_stage_tlv), |
| 322 | SOC_DOUBLE_R_TLV("Mono PGA Bypass Volume", |
| 323 | PGAL_2_MONOLOPM_VOL, PGAR_2_MONOLOPM_VOL, |
| 324 | 0, 118, 1, output_stage_tlv), |
Jarkko Nikula | 7565fc3 | 2009-02-09 14:27:07 +0200 | [diff] [blame] | 325 | SOC_DOUBLE_R_TLV("Mono DAC Playback Volume", |
| 326 | DACL1_2_MONOLOPM_VOL, DACR1_2_MONOLOPM_VOL, |
| 327 | 0, 118, 1, output_stage_tlv), |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 328 | |
Jarkko Nikula | 098b171 | 2010-08-27 16:56:50 +0300 | [diff] [blame] | 329 | SOC_DOUBLE_R_TLV("HP Line2 Bypass Volume", |
| 330 | LINE2L_2_HPLOUT_VOL, LINE2R_2_HPROUT_VOL, |
| 331 | 0, 118, 1, output_stage_tlv), |
| 332 | SOC_DOUBLE_R_TLV("HP PGA Bypass Volume", |
| 333 | PGAL_2_HPLOUT_VOL, PGAR_2_HPROUT_VOL, |
| 334 | 0, 118, 1, output_stage_tlv), |
Jarkko Nikula | 7565fc3 | 2009-02-09 14:27:07 +0200 | [diff] [blame] | 335 | SOC_DOUBLE_R_TLV("HP DAC Playback Volume", |
| 336 | DACL1_2_HPLOUT_VOL, DACR1_2_HPROUT_VOL, |
| 337 | 0, 118, 1, output_stage_tlv), |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 338 | |
Jarkko Nikula | 098b171 | 2010-08-27 16:56:50 +0300 | [diff] [blame] | 339 | SOC_DOUBLE_R_TLV("HPCOM Line2 Bypass Volume", |
| 340 | LINE2L_2_HPLCOM_VOL, LINE2R_2_HPRCOM_VOL, |
| 341 | 0, 118, 1, output_stage_tlv), |
| 342 | SOC_DOUBLE_R_TLV("HPCOM PGA Bypass Volume", |
| 343 | PGAL_2_HPLCOM_VOL, PGAR_2_HPRCOM_VOL, |
| 344 | 0, 118, 1, output_stage_tlv), |
Jarkko Nikula | 7565fc3 | 2009-02-09 14:27:07 +0200 | [diff] [blame] | 345 | SOC_DOUBLE_R_TLV("HPCOM DAC Playback Volume", |
| 346 | DACL1_2_HPLCOM_VOL, DACR1_2_HPRCOM_VOL, |
| 347 | 0, 118, 1, output_stage_tlv), |
Jarkko Nikula | 098b171 | 2010-08-27 16:56:50 +0300 | [diff] [blame] | 348 | |
| 349 | /* Output pin mute controls */ |
| 350 | SOC_DOUBLE_R("Line Playback Switch", LLOPM_CTRL, RLOPM_CTRL, 3, |
| 351 | 0x01, 0), |
| 352 | SOC_SINGLE("Mono Playback Switch", MONOLOPM_CTRL, 3, 0x01, 0), |
| 353 | SOC_DOUBLE_R("HP Playback Switch", HPLOUT_CTRL, HPROUT_CTRL, 3, |
| 354 | 0x01, 0), |
Jarkko Nikula | f9bc029 | 2010-08-27 16:56:47 +0300 | [diff] [blame] | 355 | SOC_DOUBLE_R("HPCOM Playback Switch", HPLCOM_CTRL, HPRCOM_CTRL, 3, |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 356 | 0x01, 0), |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 357 | |
| 358 | /* |
| 359 | * Note: enable Automatic input Gain Controller with care. It can |
| 360 | * adjust PGA to max value when ADC is on and will never go back. |
| 361 | */ |
| 362 | SOC_DOUBLE_R("AGC Switch", LAGC_CTRL_A, RAGC_CTRL_A, 7, 0x01, 0), |
| 363 | |
| 364 | /* Input */ |
Jarkko Nikula | 7565fc3 | 2009-02-09 14:27:07 +0200 | [diff] [blame] | 365 | SOC_DOUBLE_R_TLV("PGA Capture Volume", LADC_VOL, RADC_VOL, |
| 366 | 0, 119, 0, adc_tlv), |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 367 | SOC_DOUBLE_R("PGA Capture Switch", LADC_VOL, RADC_VOL, 7, 0x01, 1), |
Jarkko Nikula | 4d20f70 | 2008-06-27 14:07:57 +0300 | [diff] [blame] | 368 | |
| 369 | SOC_ENUM("ADC HPF Cut-off", aic3x_enum[ADC_HPF_ENUM]), |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 370 | }; |
| 371 | |
Randolph Chung | 6184f10 | 2010-08-20 12:47:53 +0800 | [diff] [blame] | 372 | /* |
| 373 | * Class-D amplifier gain. From 0 to 18 dB in 6 dB steps |
| 374 | */ |
| 375 | static DECLARE_TLV_DB_SCALE(classd_amp_tlv, 0, 600, 0); |
| 376 | |
| 377 | static const struct snd_kcontrol_new aic3x_classd_amp_gain_ctrl = |
| 378 | SOC_DOUBLE_TLV("Class-D Amplifier Gain", CLASSD_CTRL, 6, 4, 3, 0, classd_amp_tlv); |
| 379 | |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 380 | /* Left DAC Mux */ |
| 381 | static const struct snd_kcontrol_new aic3x_left_dac_mux_controls = |
| 382 | SOC_DAPM_ENUM("Route", aic3x_enum[LDAC_ENUM]); |
| 383 | |
| 384 | /* Right DAC Mux */ |
| 385 | static const struct snd_kcontrol_new aic3x_right_dac_mux_controls = |
| 386 | SOC_DAPM_ENUM("Route", aic3x_enum[RDAC_ENUM]); |
| 387 | |
| 388 | /* Left HPCOM Mux */ |
| 389 | static const struct snd_kcontrol_new aic3x_left_hpcom_mux_controls = |
| 390 | SOC_DAPM_ENUM("Route", aic3x_enum[LHPCOM_ENUM]); |
| 391 | |
| 392 | /* Right HPCOM Mux */ |
| 393 | static const struct snd_kcontrol_new aic3x_right_hpcom_mux_controls = |
| 394 | SOC_DAPM_ENUM("Route", aic3x_enum[RHPCOM_ENUM]); |
| 395 | |
Jarkko Nikula | c3b79e0 | 2010-08-27 16:56:49 +0300 | [diff] [blame] | 396 | /* Left Line Mixer */ |
| 397 | static const struct snd_kcontrol_new aic3x_left_line_mixer_controls[] = { |
| 398 | SOC_DAPM_SINGLE("Line2L Bypass Switch", LINE2L_2_LLOPM_VOL, 7, 1, 0), |
| 399 | SOC_DAPM_SINGLE("PGAL Bypass Switch", PGAL_2_LLOPM_VOL, 7, 1, 0), |
| 400 | SOC_DAPM_SINGLE("DACL1 Switch", DACL1_2_LLOPM_VOL, 7, 1, 0), |
| 401 | SOC_DAPM_SINGLE("Line2R Bypass Switch", LINE2R_2_LLOPM_VOL, 7, 1, 0), |
| 402 | SOC_DAPM_SINGLE("PGAR Bypass Switch", PGAR_2_LLOPM_VOL, 7, 1, 0), |
| 403 | SOC_DAPM_SINGLE("DACR1 Switch", DACR1_2_LLOPM_VOL, 7, 1, 0), |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 404 | }; |
| 405 | |
Jarkko Nikula | c3b79e0 | 2010-08-27 16:56:49 +0300 | [diff] [blame] | 406 | /* Right Line Mixer */ |
| 407 | static const struct snd_kcontrol_new aic3x_right_line_mixer_controls[] = { |
| 408 | SOC_DAPM_SINGLE("Line2L Bypass Switch", LINE2L_2_RLOPM_VOL, 7, 1, 0), |
| 409 | SOC_DAPM_SINGLE("PGAL Bypass Switch", PGAL_2_RLOPM_VOL, 7, 1, 0), |
| 410 | SOC_DAPM_SINGLE("DACL1 Switch", DACL1_2_RLOPM_VOL, 7, 1, 0), |
| 411 | SOC_DAPM_SINGLE("Line2R Bypass Switch", LINE2R_2_RLOPM_VOL, 7, 1, 0), |
| 412 | SOC_DAPM_SINGLE("PGAR Bypass Switch", PGAR_2_RLOPM_VOL, 7, 1, 0), |
| 413 | SOC_DAPM_SINGLE("DACR1 Switch", DACR1_2_RLOPM_VOL, 7, 1, 0), |
| 414 | }; |
| 415 | |
| 416 | /* Mono Mixer */ |
| 417 | static const struct snd_kcontrol_new aic3x_mono_mixer_controls[] = { |
| 418 | SOC_DAPM_SINGLE("Line2L Bypass Switch", LINE2L_2_MONOLOPM_VOL, 7, 1, 0), |
| 419 | SOC_DAPM_SINGLE("PGAL Bypass Switch", PGAL_2_MONOLOPM_VOL, 7, 1, 0), |
| 420 | SOC_DAPM_SINGLE("DACL1 Switch", DACL1_2_MONOLOPM_VOL, 7, 1, 0), |
| 421 | SOC_DAPM_SINGLE("Line2R Bypass Switch", LINE2R_2_MONOLOPM_VOL, 7, 1, 0), |
| 422 | SOC_DAPM_SINGLE("PGAR Bypass Switch", PGAR_2_MONOLOPM_VOL, 7, 1, 0), |
| 423 | SOC_DAPM_SINGLE("DACR1 Switch", DACR1_2_MONOLOPM_VOL, 7, 1, 0), |
| 424 | }; |
| 425 | |
| 426 | /* Left HP Mixer */ |
| 427 | static const struct snd_kcontrol_new aic3x_left_hp_mixer_controls[] = { |
| 428 | SOC_DAPM_SINGLE("Line2L Bypass Switch", LINE2L_2_HPLOUT_VOL, 7, 1, 0), |
| 429 | SOC_DAPM_SINGLE("PGAL Bypass Switch", PGAL_2_HPLOUT_VOL, 7, 1, 0), |
| 430 | SOC_DAPM_SINGLE("DACL1 Switch", DACL1_2_HPLOUT_VOL, 7, 1, 0), |
| 431 | SOC_DAPM_SINGLE("Line2R Bypass Switch", LINE2R_2_HPLOUT_VOL, 7, 1, 0), |
| 432 | SOC_DAPM_SINGLE("PGAR Bypass Switch", PGAR_2_HPLOUT_VOL, 7, 1, 0), |
| 433 | SOC_DAPM_SINGLE("DACR1 Switch", DACR1_2_HPLOUT_VOL, 7, 1, 0), |
| 434 | }; |
| 435 | |
| 436 | /* Right HP Mixer */ |
| 437 | static const struct snd_kcontrol_new aic3x_right_hp_mixer_controls[] = { |
| 438 | SOC_DAPM_SINGLE("Line2L Bypass Switch", LINE2L_2_HPROUT_VOL, 7, 1, 0), |
| 439 | SOC_DAPM_SINGLE("PGAL Bypass Switch", PGAL_2_HPROUT_VOL, 7, 1, 0), |
| 440 | SOC_DAPM_SINGLE("DACL1 Switch", DACL1_2_HPROUT_VOL, 7, 1, 0), |
| 441 | SOC_DAPM_SINGLE("Line2R Bypass Switch", LINE2R_2_HPROUT_VOL, 7, 1, 0), |
| 442 | SOC_DAPM_SINGLE("PGAR Bypass Switch", PGAR_2_HPROUT_VOL, 7, 1, 0), |
| 443 | SOC_DAPM_SINGLE("DACR1 Switch", DACR1_2_HPROUT_VOL, 7, 1, 0), |
| 444 | }; |
| 445 | |
| 446 | /* Left HPCOM Mixer */ |
| 447 | static const struct snd_kcontrol_new aic3x_left_hpcom_mixer_controls[] = { |
| 448 | SOC_DAPM_SINGLE("Line2L Bypass Switch", LINE2L_2_HPLCOM_VOL, 7, 1, 0), |
| 449 | SOC_DAPM_SINGLE("PGAL Bypass Switch", PGAL_2_HPLCOM_VOL, 7, 1, 0), |
| 450 | SOC_DAPM_SINGLE("DACL1 Switch", DACL1_2_HPLCOM_VOL, 7, 1, 0), |
| 451 | SOC_DAPM_SINGLE("Line2R Bypass Switch", LINE2R_2_HPLCOM_VOL, 7, 1, 0), |
| 452 | SOC_DAPM_SINGLE("PGAR Bypass Switch", PGAR_2_HPLCOM_VOL, 7, 1, 0), |
| 453 | SOC_DAPM_SINGLE("DACR1 Switch", DACR1_2_HPLCOM_VOL, 7, 1, 0), |
| 454 | }; |
| 455 | |
| 456 | /* Right HPCOM Mixer */ |
| 457 | static const struct snd_kcontrol_new aic3x_right_hpcom_mixer_controls[] = { |
| 458 | SOC_DAPM_SINGLE("Line2L Bypass Switch", LINE2L_2_HPRCOM_VOL, 7, 1, 0), |
| 459 | SOC_DAPM_SINGLE("PGAL Bypass Switch", PGAL_2_HPRCOM_VOL, 7, 1, 0), |
| 460 | SOC_DAPM_SINGLE("DACL1 Switch", DACL1_2_HPRCOM_VOL, 7, 1, 0), |
| 461 | SOC_DAPM_SINGLE("Line2R Bypass Switch", LINE2R_2_HPRCOM_VOL, 7, 1, 0), |
| 462 | SOC_DAPM_SINGLE("PGAR Bypass Switch", PGAR_2_HPRCOM_VOL, 7, 1, 0), |
| 463 | SOC_DAPM_SINGLE("DACR1 Switch", DACR1_2_HPRCOM_VOL, 7, 1, 0), |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 464 | }; |
| 465 | |
| 466 | /* Left PGA Mixer */ |
| 467 | static const struct snd_kcontrol_new aic3x_left_pga_mixer_controls[] = { |
| 468 | SOC_DAPM_SINGLE_AIC3X("Line1L Switch", LINE1L_2_LADC_CTRL, 3, 1, 1), |
Daniel Mack | 54f0191 | 2008-11-26 17:47:36 +0100 | [diff] [blame] | 469 | SOC_DAPM_SINGLE_AIC3X("Line1R Switch", LINE1R_2_LADC_CTRL, 3, 1, 1), |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 470 | SOC_DAPM_SINGLE_AIC3X("Line2L Switch", LINE2L_2_LADC_CTRL, 3, 1, 1), |
| 471 | SOC_DAPM_SINGLE_AIC3X("Mic3L Switch", MIC3LR_2_LADC_CTRL, 4, 1, 1), |
Daniel Mack | 54f0191 | 2008-11-26 17:47:36 +0100 | [diff] [blame] | 472 | SOC_DAPM_SINGLE_AIC3X("Mic3R Switch", MIC3LR_2_LADC_CTRL, 0, 1, 1), |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 473 | }; |
| 474 | |
| 475 | /* Right PGA Mixer */ |
| 476 | static const struct snd_kcontrol_new aic3x_right_pga_mixer_controls[] = { |
| 477 | SOC_DAPM_SINGLE_AIC3X("Line1R Switch", LINE1R_2_RADC_CTRL, 3, 1, 1), |
Daniel Mack | 54f0191 | 2008-11-26 17:47:36 +0100 | [diff] [blame] | 478 | SOC_DAPM_SINGLE_AIC3X("Line1L Switch", LINE1L_2_RADC_CTRL, 3, 1, 1), |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 479 | SOC_DAPM_SINGLE_AIC3X("Line2R Switch", LINE2R_2_RADC_CTRL, 3, 1, 1), |
Daniel Mack | 54f0191 | 2008-11-26 17:47:36 +0100 | [diff] [blame] | 480 | SOC_DAPM_SINGLE_AIC3X("Mic3L Switch", MIC3LR_2_RADC_CTRL, 4, 1, 1), |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 481 | SOC_DAPM_SINGLE_AIC3X("Mic3R Switch", MIC3LR_2_RADC_CTRL, 0, 1, 1), |
| 482 | }; |
| 483 | |
| 484 | /* Left Line1 Mux */ |
| 485 | static const struct snd_kcontrol_new aic3x_left_line1_mux_controls = |
| 486 | SOC_DAPM_ENUM("Route", aic3x_enum[LINE1L_ENUM]); |
| 487 | |
| 488 | /* Right Line1 Mux */ |
| 489 | static const struct snd_kcontrol_new aic3x_right_line1_mux_controls = |
| 490 | SOC_DAPM_ENUM("Route", aic3x_enum[LINE1R_ENUM]); |
| 491 | |
| 492 | /* Left Line2 Mux */ |
| 493 | static const struct snd_kcontrol_new aic3x_left_line2_mux_controls = |
| 494 | SOC_DAPM_ENUM("Route", aic3x_enum[LINE2L_ENUM]); |
| 495 | |
| 496 | /* Right Line2 Mux */ |
| 497 | static const struct snd_kcontrol_new aic3x_right_line2_mux_controls = |
| 498 | SOC_DAPM_ENUM("Route", aic3x_enum[LINE2R_ENUM]); |
| 499 | |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 500 | static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = { |
| 501 | /* Left DAC to Left Outputs */ |
| 502 | SND_SOC_DAPM_DAC("Left DAC", "Left Playback", DAC_PWR, 7, 0), |
| 503 | SND_SOC_DAPM_MUX("Left DAC Mux", SND_SOC_NOPM, 0, 0, |
| 504 | &aic3x_left_dac_mux_controls), |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 505 | SND_SOC_DAPM_MUX("Left HPCOM Mux", SND_SOC_NOPM, 0, 0, |
| 506 | &aic3x_left_hpcom_mux_controls), |
| 507 | SND_SOC_DAPM_PGA("Left Line Out", LLOPM_CTRL, 0, 0, NULL, 0), |
| 508 | SND_SOC_DAPM_PGA("Left HP Out", HPLOUT_CTRL, 0, 0, NULL, 0), |
| 509 | SND_SOC_DAPM_PGA("Left HP Com", HPLCOM_CTRL, 0, 0, NULL, 0), |
| 510 | |
| 511 | /* Right DAC to Right Outputs */ |
| 512 | SND_SOC_DAPM_DAC("Right DAC", "Right Playback", DAC_PWR, 6, 0), |
| 513 | SND_SOC_DAPM_MUX("Right DAC Mux", SND_SOC_NOPM, 0, 0, |
| 514 | &aic3x_right_dac_mux_controls), |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 515 | SND_SOC_DAPM_MUX("Right HPCOM Mux", SND_SOC_NOPM, 0, 0, |
| 516 | &aic3x_right_hpcom_mux_controls), |
| 517 | SND_SOC_DAPM_PGA("Right Line Out", RLOPM_CTRL, 0, 0, NULL, 0), |
| 518 | SND_SOC_DAPM_PGA("Right HP Out", HPROUT_CTRL, 0, 0, NULL, 0), |
| 519 | SND_SOC_DAPM_PGA("Right HP Com", HPRCOM_CTRL, 0, 0, NULL, 0), |
| 520 | |
| 521 | /* Mono Output */ |
| 522 | SND_SOC_DAPM_PGA("Mono Out", MONOLOPM_CTRL, 0, 0, NULL, 0), |
| 523 | |
Daniel Mack | 54f0191 | 2008-11-26 17:47:36 +0100 | [diff] [blame] | 524 | /* Inputs to Left ADC */ |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 525 | SND_SOC_DAPM_ADC("Left ADC", "Left Capture", LINE1L_2_LADC_CTRL, 2, 0), |
| 526 | SND_SOC_DAPM_MIXER("Left PGA Mixer", SND_SOC_NOPM, 0, 0, |
| 527 | &aic3x_left_pga_mixer_controls[0], |
| 528 | ARRAY_SIZE(aic3x_left_pga_mixer_controls)), |
| 529 | SND_SOC_DAPM_MUX("Left Line1L Mux", SND_SOC_NOPM, 0, 0, |
| 530 | &aic3x_left_line1_mux_controls), |
Daniel Mack | 54f0191 | 2008-11-26 17:47:36 +0100 | [diff] [blame] | 531 | SND_SOC_DAPM_MUX("Left Line1R Mux", SND_SOC_NOPM, 0, 0, |
| 532 | &aic3x_left_line1_mux_controls), |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 533 | SND_SOC_DAPM_MUX("Left Line2L Mux", SND_SOC_NOPM, 0, 0, |
| 534 | &aic3x_left_line2_mux_controls), |
| 535 | |
Daniel Mack | 54f0191 | 2008-11-26 17:47:36 +0100 | [diff] [blame] | 536 | /* Inputs to Right ADC */ |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 537 | SND_SOC_DAPM_ADC("Right ADC", "Right Capture", |
| 538 | LINE1R_2_RADC_CTRL, 2, 0), |
| 539 | SND_SOC_DAPM_MIXER("Right PGA Mixer", SND_SOC_NOPM, 0, 0, |
| 540 | &aic3x_right_pga_mixer_controls[0], |
| 541 | ARRAY_SIZE(aic3x_right_pga_mixer_controls)), |
Daniel Mack | 54f0191 | 2008-11-26 17:47:36 +0100 | [diff] [blame] | 542 | SND_SOC_DAPM_MUX("Right Line1L Mux", SND_SOC_NOPM, 0, 0, |
| 543 | &aic3x_right_line1_mux_controls), |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 544 | SND_SOC_DAPM_MUX("Right Line1R Mux", SND_SOC_NOPM, 0, 0, |
| 545 | &aic3x_right_line1_mux_controls), |
| 546 | SND_SOC_DAPM_MUX("Right Line2R Mux", SND_SOC_NOPM, 0, 0, |
| 547 | &aic3x_right_line2_mux_controls), |
| 548 | |
Jarkko Nikula | ee15ffd | 2008-06-25 14:58:46 +0300 | [diff] [blame] | 549 | /* |
| 550 | * Not a real mic bias widget but similar function. This is for dynamic |
| 551 | * control of GPIO1 digital mic modulator clock output function when |
| 552 | * using digital mic. |
| 553 | */ |
| 554 | SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "GPIO1 dmic modclk", |
| 555 | AIC3X_GPIO1_REG, 4, 0xf, |
| 556 | AIC3X_GPIO1_FUNC_DIGITAL_MIC_MODCLK, |
| 557 | AIC3X_GPIO1_FUNC_DISABLED), |
| 558 | |
| 559 | /* |
| 560 | * Also similar function like mic bias. Selects digital mic with |
| 561 | * configurable oversampling rate instead of ADC converter. |
| 562 | */ |
| 563 | SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "DMic Rate 128", |
| 564 | AIC3X_ASD_INTF_CTRLA, 0, 3, 1, 0), |
| 565 | SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "DMic Rate 64", |
| 566 | AIC3X_ASD_INTF_CTRLA, 0, 3, 2, 0), |
| 567 | SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "DMic Rate 32", |
| 568 | AIC3X_ASD_INTF_CTRLA, 0, 3, 3, 0), |
| 569 | |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 570 | /* Mic Bias */ |
Jarkko Nikula | 0bd72a3 | 2008-06-25 14:42:08 +0300 | [diff] [blame] | 571 | SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "Mic Bias 2V", |
| 572 | MICBIAS_CTRL, 6, 3, 1, 0), |
| 573 | SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "Mic Bias 2.5V", |
| 574 | MICBIAS_CTRL, 6, 3, 2, 0), |
| 575 | SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "Mic Bias AVDD", |
| 576 | MICBIAS_CTRL, 6, 3, 3, 0), |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 577 | |
Jarkko Nikula | c3b79e0 | 2010-08-27 16:56:49 +0300 | [diff] [blame] | 578 | /* Output mixers */ |
| 579 | SND_SOC_DAPM_MIXER("Left Line Mixer", SND_SOC_NOPM, 0, 0, |
| 580 | &aic3x_left_line_mixer_controls[0], |
| 581 | ARRAY_SIZE(aic3x_left_line_mixer_controls)), |
| 582 | SND_SOC_DAPM_MIXER("Right Line Mixer", SND_SOC_NOPM, 0, 0, |
| 583 | &aic3x_right_line_mixer_controls[0], |
| 584 | ARRAY_SIZE(aic3x_right_line_mixer_controls)), |
| 585 | SND_SOC_DAPM_MIXER("Mono Mixer", SND_SOC_NOPM, 0, 0, |
| 586 | &aic3x_mono_mixer_controls[0], |
| 587 | ARRAY_SIZE(aic3x_mono_mixer_controls)), |
| 588 | SND_SOC_DAPM_MIXER("Left HP Mixer", SND_SOC_NOPM, 0, 0, |
| 589 | &aic3x_left_hp_mixer_controls[0], |
| 590 | ARRAY_SIZE(aic3x_left_hp_mixer_controls)), |
| 591 | SND_SOC_DAPM_MIXER("Right HP Mixer", SND_SOC_NOPM, 0, 0, |
| 592 | &aic3x_right_hp_mixer_controls[0], |
| 593 | ARRAY_SIZE(aic3x_right_hp_mixer_controls)), |
| 594 | SND_SOC_DAPM_MIXER("Left HPCOM Mixer", SND_SOC_NOPM, 0, 0, |
| 595 | &aic3x_left_hpcom_mixer_controls[0], |
| 596 | ARRAY_SIZE(aic3x_left_hpcom_mixer_controls)), |
| 597 | SND_SOC_DAPM_MIXER("Right HPCOM Mixer", SND_SOC_NOPM, 0, 0, |
| 598 | &aic3x_right_hpcom_mixer_controls[0], |
| 599 | ARRAY_SIZE(aic3x_right_hpcom_mixer_controls)), |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 600 | |
| 601 | SND_SOC_DAPM_OUTPUT("LLOUT"), |
| 602 | SND_SOC_DAPM_OUTPUT("RLOUT"), |
| 603 | SND_SOC_DAPM_OUTPUT("MONO_LOUT"), |
| 604 | SND_SOC_DAPM_OUTPUT("HPLOUT"), |
| 605 | SND_SOC_DAPM_OUTPUT("HPROUT"), |
| 606 | SND_SOC_DAPM_OUTPUT("HPLCOM"), |
| 607 | SND_SOC_DAPM_OUTPUT("HPRCOM"), |
| 608 | |
| 609 | SND_SOC_DAPM_INPUT("MIC3L"), |
| 610 | SND_SOC_DAPM_INPUT("MIC3R"), |
| 611 | SND_SOC_DAPM_INPUT("LINE1L"), |
| 612 | SND_SOC_DAPM_INPUT("LINE1R"), |
| 613 | SND_SOC_DAPM_INPUT("LINE2L"), |
| 614 | SND_SOC_DAPM_INPUT("LINE2R"), |
| 615 | }; |
| 616 | |
Randolph Chung | 6184f10 | 2010-08-20 12:47:53 +0800 | [diff] [blame] | 617 | static const struct snd_soc_dapm_widget aic3007_dapm_widgets[] = { |
| 618 | /* Class-D outputs */ |
| 619 | SND_SOC_DAPM_PGA("Left Class-D Out", CLASSD_CTRL, 3, 0, NULL, 0), |
| 620 | SND_SOC_DAPM_PGA("Right Class-D Out", CLASSD_CTRL, 2, 0, NULL, 0), |
| 621 | |
| 622 | SND_SOC_DAPM_OUTPUT("SPOP"), |
| 623 | SND_SOC_DAPM_OUTPUT("SPOM"), |
| 624 | }; |
| 625 | |
Mark Brown | d0cc0d3 | 2008-05-13 14:55:22 +0200 | [diff] [blame] | 626 | static const struct snd_soc_dapm_route intercon[] = { |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 627 | /* Left Input */ |
| 628 | {"Left Line1L Mux", "single-ended", "LINE1L"}, |
| 629 | {"Left Line1L Mux", "differential", "LINE1L"}, |
| 630 | |
| 631 | {"Left Line2L Mux", "single-ended", "LINE2L"}, |
| 632 | {"Left Line2L Mux", "differential", "LINE2L"}, |
| 633 | |
| 634 | {"Left PGA Mixer", "Line1L Switch", "Left Line1L Mux"}, |
Daniel Mack | 54f0191 | 2008-11-26 17:47:36 +0100 | [diff] [blame] | 635 | {"Left PGA Mixer", "Line1R Switch", "Left Line1R Mux"}, |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 636 | {"Left PGA Mixer", "Line2L Switch", "Left Line2L Mux"}, |
| 637 | {"Left PGA Mixer", "Mic3L Switch", "MIC3L"}, |
Daniel Mack | 54f0191 | 2008-11-26 17:47:36 +0100 | [diff] [blame] | 638 | {"Left PGA Mixer", "Mic3R Switch", "MIC3R"}, |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 639 | |
| 640 | {"Left ADC", NULL, "Left PGA Mixer"}, |
Jarkko Nikula | ee15ffd | 2008-06-25 14:58:46 +0300 | [diff] [blame] | 641 | {"Left ADC", NULL, "GPIO1 dmic modclk"}, |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 642 | |
| 643 | /* Right Input */ |
| 644 | {"Right Line1R Mux", "single-ended", "LINE1R"}, |
| 645 | {"Right Line1R Mux", "differential", "LINE1R"}, |
| 646 | |
| 647 | {"Right Line2R Mux", "single-ended", "LINE2R"}, |
| 648 | {"Right Line2R Mux", "differential", "LINE2R"}, |
| 649 | |
Daniel Mack | 54f0191 | 2008-11-26 17:47:36 +0100 | [diff] [blame] | 650 | {"Right PGA Mixer", "Line1L Switch", "Right Line1L Mux"}, |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 651 | {"Right PGA Mixer", "Line1R Switch", "Right Line1R Mux"}, |
| 652 | {"Right PGA Mixer", "Line2R Switch", "Right Line2R Mux"}, |
Daniel Mack | 54f0191 | 2008-11-26 17:47:36 +0100 | [diff] [blame] | 653 | {"Right PGA Mixer", "Mic3L Switch", "MIC3L"}, |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 654 | {"Right PGA Mixer", "Mic3R Switch", "MIC3R"}, |
| 655 | |
| 656 | {"Right ADC", NULL, "Right PGA Mixer"}, |
Jarkko Nikula | ee15ffd | 2008-06-25 14:58:46 +0300 | [diff] [blame] | 657 | {"Right ADC", NULL, "GPIO1 dmic modclk"}, |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 658 | |
Jarkko Nikula | ee15ffd | 2008-06-25 14:58:46 +0300 | [diff] [blame] | 659 | /* |
| 660 | * Logical path between digital mic enable and GPIO1 modulator clock |
| 661 | * output function |
| 662 | */ |
| 663 | {"GPIO1 dmic modclk", NULL, "DMic Rate 128"}, |
| 664 | {"GPIO1 dmic modclk", NULL, "DMic Rate 64"}, |
| 665 | {"GPIO1 dmic modclk", NULL, "DMic Rate 32"}, |
Jarkko Nikula | c3b79e0 | 2010-08-27 16:56:49 +0300 | [diff] [blame] | 666 | |
| 667 | /* Left DAC Output */ |
| 668 | {"Left DAC Mux", "DAC_L1", "Left DAC"}, |
| 669 | {"Left DAC Mux", "DAC_L2", "Left DAC"}, |
| 670 | {"Left DAC Mux", "DAC_L3", "Left DAC"}, |
| 671 | |
| 672 | /* Right DAC Output */ |
| 673 | {"Right DAC Mux", "DAC_R1", "Right DAC"}, |
| 674 | {"Right DAC Mux", "DAC_R2", "Right DAC"}, |
| 675 | {"Right DAC Mux", "DAC_R3", "Right DAC"}, |
| 676 | |
| 677 | /* Left Line Output */ |
| 678 | {"Left Line Mixer", "Line2L Bypass Switch", "Left Line2L Mux"}, |
| 679 | {"Left Line Mixer", "PGAL Bypass Switch", "Left PGA Mixer"}, |
| 680 | {"Left Line Mixer", "DACL1 Switch", "Left DAC Mux"}, |
| 681 | {"Left Line Mixer", "Line2R Bypass Switch", "Right Line2R Mux"}, |
| 682 | {"Left Line Mixer", "PGAR Bypass Switch", "Right PGA Mixer"}, |
| 683 | {"Left Line Mixer", "DACR1 Switch", "Right DAC Mux"}, |
| 684 | |
| 685 | {"Left Line Out", NULL, "Left Line Mixer"}, |
| 686 | {"Left Line Out", NULL, "Left DAC Mux"}, |
| 687 | {"LLOUT", NULL, "Left Line Out"}, |
| 688 | |
| 689 | /* Right Line Output */ |
| 690 | {"Right Line Mixer", "Line2L Bypass Switch", "Left Line2L Mux"}, |
| 691 | {"Right Line Mixer", "PGAL Bypass Switch", "Left PGA Mixer"}, |
| 692 | {"Right Line Mixer", "DACL1 Switch", "Left DAC Mux"}, |
| 693 | {"Right Line Mixer", "Line2R Bypass Switch", "Right Line2R Mux"}, |
| 694 | {"Right Line Mixer", "PGAR Bypass Switch", "Right PGA Mixer"}, |
| 695 | {"Right Line Mixer", "DACR1 Switch", "Right DAC Mux"}, |
| 696 | |
| 697 | {"Right Line Out", NULL, "Right Line Mixer"}, |
| 698 | {"Right Line Out", NULL, "Right DAC Mux"}, |
| 699 | {"RLOUT", NULL, "Right Line Out"}, |
| 700 | |
| 701 | /* Mono Output */ |
| 702 | {"Mono Mixer", "Line2L Bypass Switch", "Left Line2L Mux"}, |
| 703 | {"Mono Mixer", "PGAL Bypass Switch", "Left PGA Mixer"}, |
| 704 | {"Mono Mixer", "DACL1 Switch", "Left DAC Mux"}, |
| 705 | {"Mono Mixer", "Line2R Bypass Switch", "Right Line2R Mux"}, |
| 706 | {"Mono Mixer", "PGAR Bypass Switch", "Right PGA Mixer"}, |
| 707 | {"Mono Mixer", "DACR1 Switch", "Right DAC Mux"}, |
| 708 | |
| 709 | {"Mono Out", NULL, "Mono Mixer"}, |
| 710 | {"MONO_LOUT", NULL, "Mono Out"}, |
| 711 | |
| 712 | /* Left HP Output */ |
| 713 | {"Left HP Mixer", "Line2L Bypass Switch", "Left Line2L Mux"}, |
| 714 | {"Left HP Mixer", "PGAL Bypass Switch", "Left PGA Mixer"}, |
| 715 | {"Left HP Mixer", "DACL1 Switch", "Left DAC Mux"}, |
| 716 | {"Left HP Mixer", "Line2R Bypass Switch", "Right Line2R Mux"}, |
| 717 | {"Left HP Mixer", "PGAR Bypass Switch", "Right PGA Mixer"}, |
| 718 | {"Left HP Mixer", "DACR1 Switch", "Right DAC Mux"}, |
| 719 | |
| 720 | {"Left HP Out", NULL, "Left HP Mixer"}, |
| 721 | {"Left HP Out", NULL, "Left DAC Mux"}, |
| 722 | {"HPLOUT", NULL, "Left HP Out"}, |
| 723 | |
| 724 | /* Right HP Output */ |
| 725 | {"Right HP Mixer", "Line2L Bypass Switch", "Left Line2L Mux"}, |
| 726 | {"Right HP Mixer", "PGAL Bypass Switch", "Left PGA Mixer"}, |
| 727 | {"Right HP Mixer", "DACL1 Switch", "Left DAC Mux"}, |
| 728 | {"Right HP Mixer", "Line2R Bypass Switch", "Right Line2R Mux"}, |
| 729 | {"Right HP Mixer", "PGAR Bypass Switch", "Right PGA Mixer"}, |
| 730 | {"Right HP Mixer", "DACR1 Switch", "Right DAC Mux"}, |
| 731 | |
| 732 | {"Right HP Out", NULL, "Right HP Mixer"}, |
| 733 | {"Right HP Out", NULL, "Right DAC Mux"}, |
| 734 | {"HPROUT", NULL, "Right HP Out"}, |
| 735 | |
| 736 | /* Left HPCOM Output */ |
| 737 | {"Left HPCOM Mixer", "Line2L Bypass Switch", "Left Line2L Mux"}, |
| 738 | {"Left HPCOM Mixer", "PGAL Bypass Switch", "Left PGA Mixer"}, |
| 739 | {"Left HPCOM Mixer", "DACL1 Switch", "Left DAC Mux"}, |
| 740 | {"Left HPCOM Mixer", "Line2R Bypass Switch", "Right Line2R Mux"}, |
| 741 | {"Left HPCOM Mixer", "PGAR Bypass Switch", "Right PGA Mixer"}, |
| 742 | {"Left HPCOM Mixer", "DACR1 Switch", "Right DAC Mux"}, |
| 743 | |
| 744 | {"Left HPCOM Mux", "differential of HPLOUT", "Left HP Mixer"}, |
| 745 | {"Left HPCOM Mux", "constant VCM", "Left HPCOM Mixer"}, |
| 746 | {"Left HPCOM Mux", "single-ended", "Left HPCOM Mixer"}, |
| 747 | {"Left HP Com", NULL, "Left HPCOM Mux"}, |
| 748 | {"HPLCOM", NULL, "Left HP Com"}, |
| 749 | |
| 750 | /* Right HPCOM Output */ |
| 751 | {"Right HPCOM Mixer", "Line2L Bypass Switch", "Left Line2L Mux"}, |
| 752 | {"Right HPCOM Mixer", "PGAL Bypass Switch", "Left PGA Mixer"}, |
| 753 | {"Right HPCOM Mixer", "DACL1 Switch", "Left DAC Mux"}, |
| 754 | {"Right HPCOM Mixer", "Line2R Bypass Switch", "Right Line2R Mux"}, |
| 755 | {"Right HPCOM Mixer", "PGAR Bypass Switch", "Right PGA Mixer"}, |
| 756 | {"Right HPCOM Mixer", "DACR1 Switch", "Right DAC Mux"}, |
| 757 | |
| 758 | {"Right HPCOM Mux", "differential of HPROUT", "Right HP Mixer"}, |
| 759 | {"Right HPCOM Mux", "constant VCM", "Right HPCOM Mixer"}, |
| 760 | {"Right HPCOM Mux", "single-ended", "Right HPCOM Mixer"}, |
| 761 | {"Right HPCOM Mux", "differential of HPLCOM", "Left HPCOM Mixer"}, |
| 762 | {"Right HPCOM Mux", "external feedback", "Right HPCOM Mixer"}, |
| 763 | {"Right HP Com", NULL, "Right HPCOM Mux"}, |
| 764 | {"HPRCOM", NULL, "Right HP Com"}, |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 765 | }; |
| 766 | |
Randolph Chung | 6184f10 | 2010-08-20 12:47:53 +0800 | [diff] [blame] | 767 | static const struct snd_soc_dapm_route intercon_3007[] = { |
| 768 | /* Class-D outputs */ |
| 769 | {"Left Class-D Out", NULL, "Left Line Out"}, |
| 770 | {"Right Class-D Out", NULL, "Left Line Out"}, |
| 771 | {"SPOP", NULL, "Left Class-D Out"}, |
| 772 | {"SPOM", NULL, "Right Class-D Out"}, |
| 773 | }; |
| 774 | |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 775 | static int aic3x_add_widgets(struct snd_soc_codec *codec) |
| 776 | { |
Randolph Chung | 6184f10 | 2010-08-20 12:47:53 +0800 | [diff] [blame] | 777 | struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec); |
| 778 | |
Mark Brown | d0cc0d3 | 2008-05-13 14:55:22 +0200 | [diff] [blame] | 779 | snd_soc_dapm_new_controls(codec, aic3x_dapm_widgets, |
| 780 | ARRAY_SIZE(aic3x_dapm_widgets)); |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 781 | |
| 782 | /* set up audio path interconnects */ |
Mark Brown | d0cc0d3 | 2008-05-13 14:55:22 +0200 | [diff] [blame] | 783 | snd_soc_dapm_add_routes(codec, intercon, ARRAY_SIZE(intercon)); |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 784 | |
Randolph Chung | 6184f10 | 2010-08-20 12:47:53 +0800 | [diff] [blame] | 785 | if (aic3x->model == AIC3X_MODEL_3007) { |
| 786 | snd_soc_dapm_new_controls(codec, aic3007_dapm_widgets, |
| 787 | ARRAY_SIZE(aic3007_dapm_widgets)); |
| 788 | snd_soc_dapm_add_routes(codec, intercon_3007, ARRAY_SIZE(intercon_3007)); |
| 789 | } |
| 790 | |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 791 | return 0; |
| 792 | } |
| 793 | |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 794 | static int aic3x_hw_params(struct snd_pcm_substream *substream, |
Mark Brown | dee89c4 | 2008-11-18 22:11:38 +0000 | [diff] [blame] | 795 | struct snd_pcm_hw_params *params, |
| 796 | struct snd_soc_dai *dai) |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 797 | { |
| 798 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 799 | struct snd_soc_codec *codec =rtd->codec; |
Mark Brown | b2c812e | 2010-04-14 15:35:19 +0900 | [diff] [blame] | 800 | struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec); |
Daniel Mack | 4f9c16c | 2008-04-30 16:20:19 +0200 | [diff] [blame] | 801 | int codec_clk = 0, bypass_pll = 0, fsref, last_clk = 0; |
Peter Meerwald | 255173b | 2009-12-14 14:44:56 +0100 | [diff] [blame] | 802 | u8 data, j, r, p, pll_q, pll_p = 1, pll_r = 1, pll_j = 1; |
| 803 | u16 d, pll_d = 1; |
Chaithrika U S | 06c7128 | 2009-07-22 07:45:04 -0400 | [diff] [blame] | 804 | u8 reg; |
Peter Meerwald | 255173b | 2009-12-14 14:44:56 +0100 | [diff] [blame] | 805 | int clk; |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 806 | |
| 807 | /* select data word length */ |
Jarkko Nikula | e18eca4 | 2010-09-14 14:54:47 +0300 | [diff] [blame] | 808 | data = snd_soc_read(codec, AIC3X_ASD_INTF_CTRLB) & (~(0x3 << 4)); |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 809 | switch (params_format(params)) { |
| 810 | case SNDRV_PCM_FORMAT_S16_LE: |
| 811 | break; |
| 812 | case SNDRV_PCM_FORMAT_S20_3LE: |
| 813 | data |= (0x01 << 4); |
| 814 | break; |
| 815 | case SNDRV_PCM_FORMAT_S24_LE: |
| 816 | data |= (0x02 << 4); |
| 817 | break; |
| 818 | case SNDRV_PCM_FORMAT_S32_LE: |
| 819 | data |= (0x03 << 4); |
| 820 | break; |
| 821 | } |
Jarkko Nikula | e18eca4 | 2010-09-14 14:54:47 +0300 | [diff] [blame] | 822 | snd_soc_write(codec, AIC3X_ASD_INTF_CTRLB, data); |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 823 | |
Daniel Mack | 4f9c16c | 2008-04-30 16:20:19 +0200 | [diff] [blame] | 824 | /* Fsref can be 44100 or 48000 */ |
| 825 | fsref = (params_rate(params) % 11025 == 0) ? 44100 : 48000; |
| 826 | |
| 827 | /* Try to find a value for Q which allows us to bypass the PLL and |
| 828 | * generate CODEC_CLK directly. */ |
| 829 | for (pll_q = 2; pll_q < 18; pll_q++) |
| 830 | if (aic3x->sysclk / (128 * pll_q) == fsref) { |
| 831 | bypass_pll = 1; |
| 832 | break; |
| 833 | } |
| 834 | |
| 835 | if (bypass_pll) { |
| 836 | pll_q &= 0xf; |
Jarkko Nikula | e18eca4 | 2010-09-14 14:54:47 +0300 | [diff] [blame] | 837 | snd_soc_write(codec, AIC3X_PLL_PROGA_REG, pll_q << PLLQ_SHIFT); |
| 838 | snd_soc_write(codec, AIC3X_GPIOB_REG, CODEC_CLKIN_CLKDIV); |
Chaithrika U S | 06c7128 | 2009-07-22 07:45:04 -0400 | [diff] [blame] | 839 | /* disable PLL if it is bypassed */ |
Jarkko Nikula | e18eca4 | 2010-09-14 14:54:47 +0300 | [diff] [blame] | 840 | reg = snd_soc_read(codec, AIC3X_PLL_PROGA_REG); |
| 841 | snd_soc_write(codec, AIC3X_PLL_PROGA_REG, reg & ~PLL_ENABLE); |
Chaithrika U S | 06c7128 | 2009-07-22 07:45:04 -0400 | [diff] [blame] | 842 | |
| 843 | } else { |
Jarkko Nikula | e18eca4 | 2010-09-14 14:54:47 +0300 | [diff] [blame] | 844 | snd_soc_write(codec, AIC3X_GPIOB_REG, CODEC_CLKIN_PLLDIV); |
Chaithrika U S | 06c7128 | 2009-07-22 07:45:04 -0400 | [diff] [blame] | 845 | /* enable PLL when it is used */ |
Jarkko Nikula | e18eca4 | 2010-09-14 14:54:47 +0300 | [diff] [blame] | 846 | reg = snd_soc_read(codec, AIC3X_PLL_PROGA_REG); |
| 847 | snd_soc_write(codec, AIC3X_PLL_PROGA_REG, reg | PLL_ENABLE); |
Chaithrika U S | 06c7128 | 2009-07-22 07:45:04 -0400 | [diff] [blame] | 848 | } |
Daniel Mack | 4f9c16c | 2008-04-30 16:20:19 +0200 | [diff] [blame] | 849 | |
| 850 | /* Route Left DAC to left channel input and |
| 851 | * right DAC to right channel input */ |
| 852 | data = (LDAC2LCH | RDAC2RCH); |
| 853 | data |= (fsref == 44100) ? FSREF_44100 : FSREF_48000; |
| 854 | if (params_rate(params) >= 64000) |
| 855 | data |= DUAL_RATE_MODE; |
Jarkko Nikula | e18eca4 | 2010-09-14 14:54:47 +0300 | [diff] [blame] | 856 | snd_soc_write(codec, AIC3X_CODEC_DATAPATH_REG, data); |
Daniel Mack | 4f9c16c | 2008-04-30 16:20:19 +0200 | [diff] [blame] | 857 | |
| 858 | /* codec sample rate select */ |
| 859 | data = (fsref * 20) / params_rate(params); |
| 860 | if (params_rate(params) < 64000) |
| 861 | data /= 2; |
| 862 | data /= 5; |
| 863 | data -= 2; |
| 864 | data |= (data << 4); |
Jarkko Nikula | e18eca4 | 2010-09-14 14:54:47 +0300 | [diff] [blame] | 865 | snd_soc_write(codec, AIC3X_SAMPLE_RATE_SEL_REG, data); |
Daniel Mack | 4f9c16c | 2008-04-30 16:20:19 +0200 | [diff] [blame] | 866 | |
| 867 | if (bypass_pll) |
| 868 | return 0; |
| 869 | |
Peter Meerwald | 255173b | 2009-12-14 14:44:56 +0100 | [diff] [blame] | 870 | /* Use PLL, compute apropriate setup for j, d, r and p, the closest |
| 871 | * one wins the game. Try with d==0 first, next with d!=0. |
| 872 | * Constraints for j are according to the datasheet. |
Daniel Mack | 4f9c16c | 2008-04-30 16:20:19 +0200 | [diff] [blame] | 873 | * The sysclk is divided by 1000 to prevent integer overflows. |
| 874 | */ |
Peter Meerwald | 255173b | 2009-12-14 14:44:56 +0100 | [diff] [blame] | 875 | |
Daniel Mack | 4f9c16c | 2008-04-30 16:20:19 +0200 | [diff] [blame] | 876 | codec_clk = (2048 * fsref) / (aic3x->sysclk / 1000); |
| 877 | |
| 878 | for (r = 1; r <= 16; r++) |
| 879 | for (p = 1; p <= 8; p++) { |
Peter Meerwald | 255173b | 2009-12-14 14:44:56 +0100 | [diff] [blame] | 880 | for (j = 4; j <= 55; j++) { |
| 881 | /* This is actually 1000*((j+(d/10000))*r)/p |
| 882 | * The term had to be converted to get |
| 883 | * rid of the division by 10000; d = 0 here |
| 884 | */ |
Mark Brown | 5baf831 | 2010-01-02 13:13:42 +0000 | [diff] [blame] | 885 | int tmp_clk = (1000 * j * r) / p; |
Daniel Mack | 4f9c16c | 2008-04-30 16:20:19 +0200 | [diff] [blame] | 886 | |
Peter Meerwald | 255173b | 2009-12-14 14:44:56 +0100 | [diff] [blame] | 887 | /* Check whether this values get closer than |
| 888 | * the best ones we had before |
| 889 | */ |
Mark Brown | 5baf831 | 2010-01-02 13:13:42 +0000 | [diff] [blame] | 890 | if (abs(codec_clk - tmp_clk) < |
Peter Meerwald | 255173b | 2009-12-14 14:44:56 +0100 | [diff] [blame] | 891 | abs(codec_clk - last_clk)) { |
| 892 | pll_j = j; pll_d = 0; |
| 893 | pll_r = r; pll_p = p; |
Mark Brown | 5baf831 | 2010-01-02 13:13:42 +0000 | [diff] [blame] | 894 | last_clk = tmp_clk; |
Peter Meerwald | 255173b | 2009-12-14 14:44:56 +0100 | [diff] [blame] | 895 | } |
Daniel Mack | 4f9c16c | 2008-04-30 16:20:19 +0200 | [diff] [blame] | 896 | |
Peter Meerwald | 255173b | 2009-12-14 14:44:56 +0100 | [diff] [blame] | 897 | /* Early exit for exact matches */ |
Mark Brown | 5baf831 | 2010-01-02 13:13:42 +0000 | [diff] [blame] | 898 | if (tmp_clk == codec_clk) |
Peter Meerwald | 255173b | 2009-12-14 14:44:56 +0100 | [diff] [blame] | 899 | goto found; |
Daniel Mack | 4f9c16c | 2008-04-30 16:20:19 +0200 | [diff] [blame] | 900 | } |
Daniel Mack | 4f9c16c | 2008-04-30 16:20:19 +0200 | [diff] [blame] | 901 | } |
| 902 | |
Peter Meerwald | 255173b | 2009-12-14 14:44:56 +0100 | [diff] [blame] | 903 | /* try with d != 0 */ |
| 904 | for (p = 1; p <= 8; p++) { |
| 905 | j = codec_clk * p / 1000; |
| 906 | |
| 907 | if (j < 4 || j > 11) |
| 908 | continue; |
| 909 | |
| 910 | /* do not use codec_clk here since we'd loose precision */ |
| 911 | d = ((2048 * p * fsref) - j * aic3x->sysclk) |
| 912 | * 100 / (aic3x->sysclk/100); |
| 913 | |
| 914 | clk = (10000 * j + d) / (10 * p); |
| 915 | |
| 916 | /* check whether this values get closer than the best |
| 917 | * ones we had before */ |
| 918 | if (abs(codec_clk - clk) < abs(codec_clk - last_clk)) { |
| 919 | pll_j = j; pll_d = d; pll_r = 1; pll_p = p; |
| 920 | last_clk = clk; |
| 921 | } |
| 922 | |
| 923 | /* Early exit for exact matches */ |
| 924 | if (clk == codec_clk) |
| 925 | goto found; |
| 926 | } |
| 927 | |
Daniel Mack | 4f9c16c | 2008-04-30 16:20:19 +0200 | [diff] [blame] | 928 | if (last_clk == 0) { |
| 929 | printk(KERN_ERR "%s(): unable to setup PLL\n", __func__); |
| 930 | return -EINVAL; |
| 931 | } |
| 932 | |
Peter Meerwald | 255173b | 2009-12-14 14:44:56 +0100 | [diff] [blame] | 933 | found: |
Jarkko Nikula | e18eca4 | 2010-09-14 14:54:47 +0300 | [diff] [blame] | 934 | data = snd_soc_read(codec, AIC3X_PLL_PROGA_REG); |
| 935 | snd_soc_write(codec, AIC3X_PLL_PROGA_REG, |
| 936 | data | (pll_p << PLLP_SHIFT)); |
| 937 | snd_soc_write(codec, AIC3X_OVRF_STATUS_AND_PLLR_REG, |
| 938 | pll_r << PLLR_SHIFT); |
| 939 | snd_soc_write(codec, AIC3X_PLL_PROGB_REG, pll_j << PLLJ_SHIFT); |
| 940 | snd_soc_write(codec, AIC3X_PLL_PROGC_REG, |
| 941 | (pll_d >> 6) << PLLD_MSB_SHIFT); |
| 942 | snd_soc_write(codec, AIC3X_PLL_PROGD_REG, |
| 943 | (pll_d & 0x3F) << PLLD_LSB_SHIFT); |
Daniel Mack | 4f9c16c | 2008-04-30 16:20:19 +0200 | [diff] [blame] | 944 | |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 945 | return 0; |
| 946 | } |
| 947 | |
Liam Girdwood | e550e17 | 2008-07-07 16:07:52 +0100 | [diff] [blame] | 948 | static int aic3x_mute(struct snd_soc_dai *dai, int mute) |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 949 | { |
| 950 | struct snd_soc_codec *codec = dai->codec; |
Jarkko Nikula | e18eca4 | 2010-09-14 14:54:47 +0300 | [diff] [blame] | 951 | u8 ldac_reg = snd_soc_read(codec, LDAC_VOL) & ~MUTE_ON; |
| 952 | u8 rdac_reg = snd_soc_read(codec, RDAC_VOL) & ~MUTE_ON; |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 953 | |
| 954 | if (mute) { |
Jarkko Nikula | e18eca4 | 2010-09-14 14:54:47 +0300 | [diff] [blame] | 955 | snd_soc_write(codec, LDAC_VOL, ldac_reg | MUTE_ON); |
| 956 | snd_soc_write(codec, RDAC_VOL, rdac_reg | MUTE_ON); |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 957 | } else { |
Jarkko Nikula | e18eca4 | 2010-09-14 14:54:47 +0300 | [diff] [blame] | 958 | snd_soc_write(codec, LDAC_VOL, ldac_reg); |
| 959 | snd_soc_write(codec, RDAC_VOL, rdac_reg); |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | return 0; |
| 963 | } |
| 964 | |
Liam Girdwood | e550e17 | 2008-07-07 16:07:52 +0100 | [diff] [blame] | 965 | static int aic3x_set_dai_sysclk(struct snd_soc_dai *codec_dai, |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 966 | int clk_id, unsigned int freq, int dir) |
| 967 | { |
| 968 | struct snd_soc_codec *codec = codec_dai->codec; |
Mark Brown | b2c812e | 2010-04-14 15:35:19 +0900 | [diff] [blame] | 969 | struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec); |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 970 | |
Daniel Mack | 4f9c16c | 2008-04-30 16:20:19 +0200 | [diff] [blame] | 971 | aic3x->sysclk = freq; |
| 972 | return 0; |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 973 | } |
| 974 | |
Liam Girdwood | e550e17 | 2008-07-07 16:07:52 +0100 | [diff] [blame] | 975 | static int aic3x_set_dai_fmt(struct snd_soc_dai *codec_dai, |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 976 | unsigned int fmt) |
| 977 | { |
| 978 | struct snd_soc_codec *codec = codec_dai->codec; |
Mark Brown | b2c812e | 2010-04-14 15:35:19 +0900 | [diff] [blame] | 979 | struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec); |
Jarkko Nikula | 81971a1 | 2008-06-25 14:58:45 +0300 | [diff] [blame] | 980 | u8 iface_areg, iface_breg; |
Troy Kisky | a24f4f6 | 2008-12-19 13:05:22 -0700 | [diff] [blame] | 981 | int delay = 0; |
Jarkko Nikula | 81971a1 | 2008-06-25 14:58:45 +0300 | [diff] [blame] | 982 | |
Jarkko Nikula | e18eca4 | 2010-09-14 14:54:47 +0300 | [diff] [blame] | 983 | iface_areg = snd_soc_read(codec, AIC3X_ASD_INTF_CTRLA) & 0x3f; |
| 984 | iface_breg = snd_soc_read(codec, AIC3X_ASD_INTF_CTRLB) & 0x3f; |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 985 | |
| 986 | /* set master/slave audio interface */ |
| 987 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 988 | case SND_SOC_DAIFMT_CBM_CFM: |
| 989 | aic3x->master = 1; |
| 990 | iface_areg |= BIT_CLK_MASTER | WORD_CLK_MASTER; |
| 991 | break; |
| 992 | case SND_SOC_DAIFMT_CBS_CFS: |
| 993 | aic3x->master = 0; |
| 994 | break; |
| 995 | default: |
| 996 | return -EINVAL; |
| 997 | } |
| 998 | |
Jarkko Nikula | 4b7d283 | 2008-10-23 14:27:03 +0300 | [diff] [blame] | 999 | /* |
| 1000 | * match both interface format and signal polarities since they |
| 1001 | * are fixed |
| 1002 | */ |
| 1003 | switch (fmt & (SND_SOC_DAIFMT_FORMAT_MASK | |
| 1004 | SND_SOC_DAIFMT_INV_MASK)) { |
| 1005 | case (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF): |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 1006 | break; |
Troy Kisky | a24f4f6 | 2008-12-19 13:05:22 -0700 | [diff] [blame] | 1007 | case (SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_IB_NF): |
| 1008 | delay = 1; |
Jarkko Nikula | 4b7d283 | 2008-10-23 14:27:03 +0300 | [diff] [blame] | 1009 | case (SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_IB_NF): |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 1010 | iface_breg |= (0x01 << 6); |
| 1011 | break; |
Jarkko Nikula | 4b7d283 | 2008-10-23 14:27:03 +0300 | [diff] [blame] | 1012 | case (SND_SOC_DAIFMT_RIGHT_J | SND_SOC_DAIFMT_NB_NF): |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 1013 | iface_breg |= (0x02 << 6); |
| 1014 | break; |
Jarkko Nikula | 4b7d283 | 2008-10-23 14:27:03 +0300 | [diff] [blame] | 1015 | case (SND_SOC_DAIFMT_LEFT_J | SND_SOC_DAIFMT_NB_NF): |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 1016 | iface_breg |= (0x03 << 6); |
| 1017 | break; |
| 1018 | default: |
| 1019 | return -EINVAL; |
| 1020 | } |
| 1021 | |
| 1022 | /* set iface */ |
Jarkko Nikula | e18eca4 | 2010-09-14 14:54:47 +0300 | [diff] [blame] | 1023 | snd_soc_write(codec, AIC3X_ASD_INTF_CTRLA, iface_areg); |
| 1024 | snd_soc_write(codec, AIC3X_ASD_INTF_CTRLB, iface_breg); |
| 1025 | snd_soc_write(codec, AIC3X_ASD_INTF_CTRLC, delay); |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 1026 | |
| 1027 | return 0; |
| 1028 | } |
| 1029 | |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1030 | static int aic3x_set_bias_level(struct snd_soc_codec *codec, |
| 1031 | enum snd_soc_bias_level level) |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 1032 | { |
Mark Brown | b2c812e | 2010-04-14 15:35:19 +0900 | [diff] [blame] | 1033 | struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec); |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 1034 | u8 reg; |
| 1035 | |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1036 | switch (level) { |
| 1037 | case SND_SOC_BIAS_ON: |
Jarkko Nikula | db13802 | 2010-04-26 15:49:13 +0300 | [diff] [blame] | 1038 | break; |
| 1039 | case SND_SOC_BIAS_PREPARE: |
Jarkko Nikula | c23fd75 | 2010-09-10 14:23:29 +0300 | [diff] [blame] | 1040 | if (codec->bias_level == SND_SOC_BIAS_STANDBY && |
| 1041 | aic3x->master) { |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 1042 | /* enable pll */ |
Jarkko Nikula | e18eca4 | 2010-09-14 14:54:47 +0300 | [diff] [blame] | 1043 | reg = snd_soc_read(codec, AIC3X_PLL_PROGA_REG); |
| 1044 | snd_soc_write(codec, AIC3X_PLL_PROGA_REG, |
| 1045 | reg | PLL_ENABLE); |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 1046 | } |
| 1047 | break; |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1048 | case SND_SOC_BIAS_STANDBY: |
Jarkko Nikula | c23fd75 | 2010-09-10 14:23:29 +0300 | [diff] [blame] | 1049 | if (codec->bias_level == SND_SOC_BIAS_PREPARE && |
| 1050 | aic3x->master) { |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 1051 | /* disable pll */ |
Jarkko Nikula | e18eca4 | 2010-09-14 14:54:47 +0300 | [diff] [blame] | 1052 | reg = snd_soc_read(codec, AIC3X_PLL_PROGA_REG); |
| 1053 | snd_soc_write(codec, AIC3X_PLL_PROGA_REG, |
| 1054 | reg & ~PLL_ENABLE); |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 1055 | } |
| 1056 | break; |
Jarkko Nikula | c23fd75 | 2010-09-10 14:23:29 +0300 | [diff] [blame] | 1057 | case SND_SOC_BIAS_OFF: |
| 1058 | break; |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 1059 | } |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1060 | codec->bias_level = level; |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 1061 | |
| 1062 | return 0; |
| 1063 | } |
| 1064 | |
Daniel Mack | 54e7e61 | 2008-04-30 16:20:52 +0200 | [diff] [blame] | 1065 | void aic3x_set_gpio(struct snd_soc_codec *codec, int gpio, int state) |
| 1066 | { |
| 1067 | u8 reg = gpio ? AIC3X_GPIO2_REG : AIC3X_GPIO1_REG; |
| 1068 | u8 bit = gpio ? 3: 0; |
Jarkko Nikula | e18eca4 | 2010-09-14 14:54:47 +0300 | [diff] [blame] | 1069 | u8 val = snd_soc_read(codec, reg) & ~(1 << bit); |
| 1070 | snd_soc_write(codec, reg, val | (!!state << bit)); |
Daniel Mack | 54e7e61 | 2008-04-30 16:20:52 +0200 | [diff] [blame] | 1071 | } |
| 1072 | EXPORT_SYMBOL_GPL(aic3x_set_gpio); |
| 1073 | |
| 1074 | int aic3x_get_gpio(struct snd_soc_codec *codec, int gpio) |
| 1075 | { |
| 1076 | u8 reg = gpio ? AIC3X_GPIO2_REG : AIC3X_GPIO1_REG; |
| 1077 | u8 val, bit = gpio ? 2: 1; |
| 1078 | |
| 1079 | aic3x_read(codec, reg, &val); |
| 1080 | return (val >> bit) & 1; |
| 1081 | } |
| 1082 | EXPORT_SYMBOL_GPL(aic3x_get_gpio); |
| 1083 | |
Daniel Mack | 6f2a974 | 2008-12-03 11:44:17 +0100 | [diff] [blame] | 1084 | void aic3x_set_headset_detection(struct snd_soc_codec *codec, int detect, |
| 1085 | int headset_debounce, int button_debounce) |
| 1086 | { |
| 1087 | u8 val; |
| 1088 | |
| 1089 | val = ((detect & AIC3X_HEADSET_DETECT_MASK) |
| 1090 | << AIC3X_HEADSET_DETECT_SHIFT) | |
| 1091 | ((headset_debounce & AIC3X_HEADSET_DEBOUNCE_MASK) |
| 1092 | << AIC3X_HEADSET_DEBOUNCE_SHIFT) | |
| 1093 | ((button_debounce & AIC3X_BUTTON_DEBOUNCE_MASK) |
| 1094 | << AIC3X_BUTTON_DEBOUNCE_SHIFT); |
| 1095 | |
| 1096 | if (detect & AIC3X_HEADSET_DETECT_MASK) |
| 1097 | val |= AIC3X_HEADSET_DETECT_ENABLED; |
| 1098 | |
Jarkko Nikula | e18eca4 | 2010-09-14 14:54:47 +0300 | [diff] [blame] | 1099 | snd_soc_write(codec, AIC3X_HEADSET_DETECT_CTRL_A, val); |
Daniel Mack | 6f2a974 | 2008-12-03 11:44:17 +0100 | [diff] [blame] | 1100 | } |
| 1101 | EXPORT_SYMBOL_GPL(aic3x_set_headset_detection); |
| 1102 | |
Daniel Mack | 54e7e61 | 2008-04-30 16:20:52 +0200 | [diff] [blame] | 1103 | int aic3x_headset_detected(struct snd_soc_codec *codec) |
| 1104 | { |
| 1105 | u8 val; |
Daniel Mack | 6f2a974 | 2008-12-03 11:44:17 +0100 | [diff] [blame] | 1106 | aic3x_read(codec, AIC3X_HEADSET_DETECT_CTRL_B, &val); |
| 1107 | return (val >> 4) & 1; |
Daniel Mack | 54e7e61 | 2008-04-30 16:20:52 +0200 | [diff] [blame] | 1108 | } |
| 1109 | EXPORT_SYMBOL_GPL(aic3x_headset_detected); |
| 1110 | |
Daniel Mack | 6f2a974 | 2008-12-03 11:44:17 +0100 | [diff] [blame] | 1111 | int aic3x_button_pressed(struct snd_soc_codec *codec) |
| 1112 | { |
| 1113 | u8 val; |
| 1114 | aic3x_read(codec, AIC3X_HEADSET_DETECT_CTRL_B, &val); |
| 1115 | return (val >> 5) & 1; |
| 1116 | } |
| 1117 | EXPORT_SYMBOL_GPL(aic3x_button_pressed); |
| 1118 | |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 1119 | #define AIC3X_RATES SNDRV_PCM_RATE_8000_96000 |
| 1120 | #define AIC3X_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \ |
| 1121 | SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE) |
| 1122 | |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 1123 | static struct snd_soc_dai_ops aic3x_dai_ops = { |
| 1124 | .hw_params = aic3x_hw_params, |
| 1125 | .digital_mute = aic3x_mute, |
| 1126 | .set_sysclk = aic3x_set_dai_sysclk, |
| 1127 | .set_fmt = aic3x_set_dai_fmt, |
| 1128 | }; |
| 1129 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1130 | static struct snd_soc_dai_driver aic3x_dai = { |
| 1131 | .name = "tlv320aic3x-hifi", |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 1132 | .playback = { |
| 1133 | .stream_name = "Playback", |
| 1134 | .channels_min = 1, |
| 1135 | .channels_max = 2, |
| 1136 | .rates = AIC3X_RATES, |
| 1137 | .formats = AIC3X_FORMATS,}, |
| 1138 | .capture = { |
| 1139 | .stream_name = "Capture", |
| 1140 | .channels_min = 1, |
| 1141 | .channels_max = 2, |
| 1142 | .rates = AIC3X_RATES, |
| 1143 | .formats = AIC3X_FORMATS,}, |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 1144 | .ops = &aic3x_dai_ops, |
Randolph Chung | 1401761 | 2010-08-19 12:06:17 +0100 | [diff] [blame] | 1145 | .symmetric_rates = 1, |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 1146 | }; |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 1147 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1148 | static int aic3x_suspend(struct snd_soc_codec *codec, pm_message_t state) |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 1149 | { |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1150 | aic3x_set_bias_level(codec, SND_SOC_BIAS_OFF); |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 1151 | |
| 1152 | return 0; |
| 1153 | } |
| 1154 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1155 | static int aic3x_resume(struct snd_soc_codec *codec) |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 1156 | { |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 1157 | int i; |
| 1158 | u8 data[2]; |
| 1159 | u8 *cache = codec->reg_cache; |
| 1160 | |
| 1161 | /* Sync reg_cache with the hardware */ |
| 1162 | for (i = 0; i < ARRAY_SIZE(aic3x_reg); i++) { |
| 1163 | data[0] = i; |
| 1164 | data[1] = cache[i]; |
| 1165 | codec->hw_write(codec->control_data, data, 2); |
| 1166 | } |
| 1167 | |
Mark Brown | 29e189c | 2010-05-07 20:30:00 +0100 | [diff] [blame] | 1168 | aic3x_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 1169 | |
| 1170 | return 0; |
| 1171 | } |
| 1172 | |
| 1173 | /* |
| 1174 | * initialise the AIC3X driver |
| 1175 | * register the mixer and dsp interfaces with the kernel |
| 1176 | */ |
Ben Dooks | cb3826f | 2009-08-20 22:50:41 +0100 | [diff] [blame] | 1177 | static int aic3x_init(struct snd_soc_codec *codec) |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 1178 | { |
Randolph Chung | 6184f10 | 2010-08-20 12:47:53 +0800 | [diff] [blame] | 1179 | struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec); |
Ben Dooks | cb3826f | 2009-08-20 22:50:41 +0100 | [diff] [blame] | 1180 | int reg; |
| 1181 | |
Jarkko Nikula | e18eca4 | 2010-09-14 14:54:47 +0300 | [diff] [blame] | 1182 | snd_soc_write(codec, AIC3X_PAGE_SELECT, PAGE0_SELECT); |
| 1183 | snd_soc_write(codec, AIC3X_RESET, SOFT_RESET); |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 1184 | |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 1185 | /* DAC default volume and mute */ |
Jarkko Nikula | e18eca4 | 2010-09-14 14:54:47 +0300 | [diff] [blame] | 1186 | snd_soc_write(codec, LDAC_VOL, DEFAULT_VOL | MUTE_ON); |
| 1187 | snd_soc_write(codec, RDAC_VOL, DEFAULT_VOL | MUTE_ON); |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 1188 | |
| 1189 | /* DAC to HP default volume and route to Output mixer */ |
Jarkko Nikula | e18eca4 | 2010-09-14 14:54:47 +0300 | [diff] [blame] | 1190 | snd_soc_write(codec, DACL1_2_HPLOUT_VOL, DEFAULT_VOL | ROUTE_ON); |
| 1191 | snd_soc_write(codec, DACR1_2_HPROUT_VOL, DEFAULT_VOL | ROUTE_ON); |
| 1192 | snd_soc_write(codec, DACL1_2_HPLCOM_VOL, DEFAULT_VOL | ROUTE_ON); |
| 1193 | snd_soc_write(codec, DACR1_2_HPRCOM_VOL, DEFAULT_VOL | ROUTE_ON); |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 1194 | /* DAC to Line Out default volume and route to Output mixer */ |
Jarkko Nikula | e18eca4 | 2010-09-14 14:54:47 +0300 | [diff] [blame] | 1195 | snd_soc_write(codec, DACL1_2_LLOPM_VOL, DEFAULT_VOL | ROUTE_ON); |
| 1196 | snd_soc_write(codec, DACR1_2_RLOPM_VOL, DEFAULT_VOL | ROUTE_ON); |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 1197 | /* DAC to Mono Line Out default volume and route to Output mixer */ |
Jarkko Nikula | e18eca4 | 2010-09-14 14:54:47 +0300 | [diff] [blame] | 1198 | snd_soc_write(codec, DACL1_2_MONOLOPM_VOL, DEFAULT_VOL | ROUTE_ON); |
| 1199 | snd_soc_write(codec, DACR1_2_MONOLOPM_VOL, DEFAULT_VOL | ROUTE_ON); |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 1200 | |
| 1201 | /* unmute all outputs */ |
Jarkko Nikula | e18eca4 | 2010-09-14 14:54:47 +0300 | [diff] [blame] | 1202 | reg = snd_soc_read(codec, LLOPM_CTRL); |
| 1203 | snd_soc_write(codec, LLOPM_CTRL, reg | UNMUTE); |
| 1204 | reg = snd_soc_read(codec, RLOPM_CTRL); |
| 1205 | snd_soc_write(codec, RLOPM_CTRL, reg | UNMUTE); |
| 1206 | reg = snd_soc_read(codec, MONOLOPM_CTRL); |
| 1207 | snd_soc_write(codec, MONOLOPM_CTRL, reg | UNMUTE); |
| 1208 | reg = snd_soc_read(codec, HPLOUT_CTRL); |
| 1209 | snd_soc_write(codec, HPLOUT_CTRL, reg | UNMUTE); |
| 1210 | reg = snd_soc_read(codec, HPROUT_CTRL); |
| 1211 | snd_soc_write(codec, HPROUT_CTRL, reg | UNMUTE); |
| 1212 | reg = snd_soc_read(codec, HPLCOM_CTRL); |
| 1213 | snd_soc_write(codec, HPLCOM_CTRL, reg | UNMUTE); |
| 1214 | reg = snd_soc_read(codec, HPRCOM_CTRL); |
| 1215 | snd_soc_write(codec, HPRCOM_CTRL, reg | UNMUTE); |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 1216 | |
| 1217 | /* ADC default volume and unmute */ |
Jarkko Nikula | e18eca4 | 2010-09-14 14:54:47 +0300 | [diff] [blame] | 1218 | snd_soc_write(codec, LADC_VOL, DEFAULT_GAIN); |
| 1219 | snd_soc_write(codec, RADC_VOL, DEFAULT_GAIN); |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 1220 | /* By default route Line1 to ADC PGA mixer */ |
Jarkko Nikula | e18eca4 | 2010-09-14 14:54:47 +0300 | [diff] [blame] | 1221 | snd_soc_write(codec, LINE1L_2_LADC_CTRL, 0x0); |
| 1222 | snd_soc_write(codec, LINE1R_2_RADC_CTRL, 0x0); |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 1223 | |
| 1224 | /* PGA to HP Bypass default volume, disconnect from Output Mixer */ |
Jarkko Nikula | e18eca4 | 2010-09-14 14:54:47 +0300 | [diff] [blame] | 1225 | snd_soc_write(codec, PGAL_2_HPLOUT_VOL, DEFAULT_VOL); |
| 1226 | snd_soc_write(codec, PGAR_2_HPROUT_VOL, DEFAULT_VOL); |
| 1227 | snd_soc_write(codec, PGAL_2_HPLCOM_VOL, DEFAULT_VOL); |
| 1228 | snd_soc_write(codec, PGAR_2_HPRCOM_VOL, DEFAULT_VOL); |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 1229 | /* PGA to Line Out default volume, disconnect from Output Mixer */ |
Jarkko Nikula | e18eca4 | 2010-09-14 14:54:47 +0300 | [diff] [blame] | 1230 | snd_soc_write(codec, PGAL_2_LLOPM_VOL, DEFAULT_VOL); |
| 1231 | snd_soc_write(codec, PGAR_2_RLOPM_VOL, DEFAULT_VOL); |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 1232 | /* PGA to Mono Line Out default volume, disconnect from Output Mixer */ |
Jarkko Nikula | e18eca4 | 2010-09-14 14:54:47 +0300 | [diff] [blame] | 1233 | snd_soc_write(codec, PGAL_2_MONOLOPM_VOL, DEFAULT_VOL); |
| 1234 | snd_soc_write(codec, PGAR_2_MONOLOPM_VOL, DEFAULT_VOL); |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 1235 | |
| 1236 | /* Line2 to HP Bypass default volume, disconnect from Output Mixer */ |
Jarkko Nikula | e18eca4 | 2010-09-14 14:54:47 +0300 | [diff] [blame] | 1237 | snd_soc_write(codec, LINE2L_2_HPLOUT_VOL, DEFAULT_VOL); |
| 1238 | snd_soc_write(codec, LINE2R_2_HPROUT_VOL, DEFAULT_VOL); |
| 1239 | snd_soc_write(codec, LINE2L_2_HPLCOM_VOL, DEFAULT_VOL); |
| 1240 | snd_soc_write(codec, LINE2R_2_HPRCOM_VOL, DEFAULT_VOL); |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 1241 | /* Line2 Line Out default volume, disconnect from Output Mixer */ |
Jarkko Nikula | e18eca4 | 2010-09-14 14:54:47 +0300 | [diff] [blame] | 1242 | snd_soc_write(codec, LINE2L_2_LLOPM_VOL, DEFAULT_VOL); |
| 1243 | snd_soc_write(codec, LINE2R_2_RLOPM_VOL, DEFAULT_VOL); |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 1244 | /* Line2 to Mono Out default volume, disconnect from Output Mixer */ |
Jarkko Nikula | e18eca4 | 2010-09-14 14:54:47 +0300 | [diff] [blame] | 1245 | snd_soc_write(codec, LINE2L_2_MONOLOPM_VOL, DEFAULT_VOL); |
| 1246 | snd_soc_write(codec, LINE2R_2_MONOLOPM_VOL, DEFAULT_VOL); |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 1247 | |
Randolph Chung | 6184f10 | 2010-08-20 12:47:53 +0800 | [diff] [blame] | 1248 | if (aic3x->model == AIC3X_MODEL_3007) { |
| 1249 | /* Class-D speaker driver init; datasheet p. 46 */ |
Jarkko Nikula | e18eca4 | 2010-09-14 14:54:47 +0300 | [diff] [blame] | 1250 | snd_soc_write(codec, AIC3X_PAGE_SELECT, 0x0D); |
| 1251 | snd_soc_write(codec, 0xD, 0x0D); |
| 1252 | snd_soc_write(codec, 0x8, 0x5C); |
| 1253 | snd_soc_write(codec, 0x8, 0x5D); |
| 1254 | snd_soc_write(codec, 0x8, 0x5C); |
| 1255 | snd_soc_write(codec, AIC3X_PAGE_SELECT, 0x00); |
| 1256 | snd_soc_write(codec, CLASSD_CTRL, 0); |
Randolph Chung | 6184f10 | 2010-08-20 12:47:53 +0800 | [diff] [blame] | 1257 | } |
| 1258 | |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 1259 | /* off, with power on */ |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1260 | aic3x_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 1261 | |
Ben Dooks | cb3826f | 2009-08-20 22:50:41 +0100 | [diff] [blame] | 1262 | return 0; |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 1263 | } |
| 1264 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1265 | static int aic3x_probe(struct snd_soc_codec *codec) |
Ben Dooks | cb3826f | 2009-08-20 22:50:41 +0100 | [diff] [blame] | 1266 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1267 | struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec); |
Jarkko Nikula | a84a441 | 2010-09-14 14:54:48 +0300 | [diff] [blame^] | 1268 | int ret; |
Ben Dooks | cb3826f | 2009-08-20 22:50:41 +0100 | [diff] [blame] | 1269 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1270 | codec->control_data = aic3x->control_data; |
| 1271 | |
Jarkko Nikula | a84a441 | 2010-09-14 14:54:48 +0300 | [diff] [blame^] | 1272 | ret = snd_soc_codec_set_cache_io(codec, 8, 8, aic3x->control_type); |
| 1273 | if (ret != 0) { |
| 1274 | dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); |
| 1275 | return ret; |
| 1276 | } |
| 1277 | |
Jarkko Nikula | 37b4765 | 2010-08-23 10:38:40 +0300 | [diff] [blame] | 1278 | aic3x_init(codec); |
| 1279 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1280 | if (aic3x->setup) { |
| 1281 | /* setup GPIO functions */ |
Jarkko Nikula | e18eca4 | 2010-09-14 14:54:47 +0300 | [diff] [blame] | 1282 | snd_soc_write(codec, AIC3X_GPIO1_REG, |
| 1283 | (aic3x->setup->gpio_func[0] & 0xf) << 4); |
| 1284 | snd_soc_write(codec, AIC3X_GPIO2_REG, |
| 1285 | (aic3x->setup->gpio_func[1] & 0xf) << 4); |
Ben Dooks | cb3826f | 2009-08-20 22:50:41 +0100 | [diff] [blame] | 1286 | } |
| 1287 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1288 | snd_soc_add_controls(codec, aic3x_snd_controls, |
| 1289 | ARRAY_SIZE(aic3x_snd_controls)); |
Randolph Chung | 6184f10 | 2010-08-20 12:47:53 +0800 | [diff] [blame] | 1290 | if (aic3x->model == AIC3X_MODEL_3007) |
| 1291 | snd_soc_add_controls(codec, &aic3x_classd_amp_gain_ctrl, 1); |
Ben Dooks | cb3826f | 2009-08-20 22:50:41 +0100 | [diff] [blame] | 1292 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1293 | aic3x_add_widgets(codec); |
Ben Dooks | cb3826f | 2009-08-20 22:50:41 +0100 | [diff] [blame] | 1294 | |
| 1295 | return 0; |
| 1296 | } |
| 1297 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1298 | static int aic3x_remove(struct snd_soc_codec *codec) |
Ben Dooks | cb3826f | 2009-08-20 22:50:41 +0100 | [diff] [blame] | 1299 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1300 | aic3x_set_bias_level(codec, SND_SOC_BIAS_OFF); |
Ben Dooks | cb3826f | 2009-08-20 22:50:41 +0100 | [diff] [blame] | 1301 | return 0; |
| 1302 | } |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 1303 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1304 | static struct snd_soc_codec_driver soc_codec_dev_aic3x = { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1305 | .set_bias_level = aic3x_set_bias_level, |
| 1306 | .reg_cache_size = ARRAY_SIZE(aic3x_reg), |
| 1307 | .reg_word_size = sizeof(u8), |
| 1308 | .reg_cache_default = aic3x_reg, |
| 1309 | .probe = aic3x_probe, |
| 1310 | .remove = aic3x_remove, |
| 1311 | .suspend = aic3x_suspend, |
| 1312 | .resume = aic3x_resume, |
| 1313 | }; |
| 1314 | |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 1315 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
| 1316 | /* |
| 1317 | * AIC3X 2 wire address can be up to 4 devices with device addresses |
| 1318 | * 0x18, 0x19, 0x1A, 0x1B |
| 1319 | */ |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 1320 | |
Randolph Chung | 6184f10 | 2010-08-20 12:47:53 +0800 | [diff] [blame] | 1321 | static const struct i2c_device_id aic3x_i2c_id[] = { |
| 1322 | [AIC3X_MODEL_3X] = { "tlv320aic3x", 0 }, |
| 1323 | [AIC3X_MODEL_33] = { "tlv320aic33", 0 }, |
| 1324 | [AIC3X_MODEL_3007] = { "tlv320aic3007", 0 }, |
| 1325 | { } |
| 1326 | }; |
| 1327 | MODULE_DEVICE_TABLE(i2c, aic3x_i2c_id); |
| 1328 | |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 1329 | /* |
| 1330 | * If the i2c layer weren't so broken, we could pass this kind of data |
| 1331 | * around |
| 1332 | */ |
Jean Delvare | ba8ed12 | 2008-09-22 14:15:53 +0200 | [diff] [blame] | 1333 | static int aic3x_i2c_probe(struct i2c_client *i2c, |
| 1334 | const struct i2c_device_id *id) |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 1335 | { |
Jarkko Nikula | 5193d62 | 2010-05-05 13:02:03 +0300 | [diff] [blame] | 1336 | struct aic3x_pdata *pdata = i2c->dev.platform_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1337 | struct aic3x_priv *aic3x; |
Jarkko Nikula | 07779fd | 2010-04-26 15:49:14 +0300 | [diff] [blame] | 1338 | int ret, i; |
Randolph Chung | 6184f10 | 2010-08-20 12:47:53 +0800 | [diff] [blame] | 1339 | const struct i2c_device_id *tbl; |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 1340 | |
Ben Dooks | cb3826f | 2009-08-20 22:50:41 +0100 | [diff] [blame] | 1341 | aic3x = kzalloc(sizeof(struct aic3x_priv), GFP_KERNEL); |
| 1342 | if (aic3x == NULL) { |
| 1343 | dev_err(&i2c->dev, "failed to create private data\n"); |
| 1344 | return -ENOMEM; |
| 1345 | } |
| 1346 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1347 | aic3x->control_data = i2c; |
Jarkko Nikula | a84a441 | 2010-09-14 14:54:48 +0300 | [diff] [blame^] | 1348 | aic3x->control_type = SND_SOC_I2C; |
| 1349 | |
Ben Dooks | cb3826f | 2009-08-20 22:50:41 +0100 | [diff] [blame] | 1350 | i2c_set_clientdata(i2c, aic3x); |
Jarkko Nikula | c776357 | 2010-09-05 19:10:22 +0300 | [diff] [blame] | 1351 | if (pdata) { |
| 1352 | aic3x->gpio_reset = pdata->gpio_reset; |
| 1353 | aic3x->setup = pdata->setup; |
| 1354 | } else { |
| 1355 | aic3x->gpio_reset = -1; |
| 1356 | } |
Ben Dooks | cb3826f | 2009-08-20 22:50:41 +0100 | [diff] [blame] | 1357 | |
Jarkko Nikula | c776357 | 2010-09-05 19:10:22 +0300 | [diff] [blame] | 1358 | if (aic3x->gpio_reset >= 0) { |
| 1359 | ret = gpio_request(aic3x->gpio_reset, "tlv320aic3x reset"); |
Jarkko Nikula | 5193d62 | 2010-05-05 13:02:03 +0300 | [diff] [blame] | 1360 | if (ret != 0) |
| 1361 | goto err_gpio; |
Jarkko Nikula | 5193d62 | 2010-05-05 13:02:03 +0300 | [diff] [blame] | 1362 | gpio_direction_output(aic3x->gpio_reset, 0); |
| 1363 | } |
| 1364 | |
Randolph Chung | 6184f10 | 2010-08-20 12:47:53 +0800 | [diff] [blame] | 1365 | for (tbl = aic3x_i2c_id; tbl->name[0]; tbl++) { |
| 1366 | if (!strcmp(tbl->name, id->name)) |
| 1367 | break; |
| 1368 | } |
| 1369 | aic3x->model = tbl - aic3x_i2c_id; |
| 1370 | |
Jarkko Nikula | 07779fd | 2010-04-26 15:49:14 +0300 | [diff] [blame] | 1371 | for (i = 0; i < ARRAY_SIZE(aic3x->supplies); i++) |
| 1372 | aic3x->supplies[i].supply = aic3x_supply_names[i]; |
| 1373 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1374 | ret = regulator_bulk_get(&i2c->dev, ARRAY_SIZE(aic3x->supplies), |
Jarkko Nikula | 07779fd | 2010-04-26 15:49:14 +0300 | [diff] [blame] | 1375 | aic3x->supplies); |
| 1376 | if (ret != 0) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1377 | dev_err(&i2c->dev, "Failed to request supplies: %d\n", ret); |
Jarkko Nikula | 07779fd | 2010-04-26 15:49:14 +0300 | [diff] [blame] | 1378 | goto err_get; |
| 1379 | } |
| 1380 | |
| 1381 | ret = regulator_bulk_enable(ARRAY_SIZE(aic3x->supplies), |
| 1382 | aic3x->supplies); |
| 1383 | if (ret != 0) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1384 | dev_err(&i2c->dev, "Failed to enable supplies: %d\n", ret); |
Jarkko Nikula | 07779fd | 2010-04-26 15:49:14 +0300 | [diff] [blame] | 1385 | goto err_enable; |
| 1386 | } |
| 1387 | |
Jarkko Nikula | 5193d62 | 2010-05-05 13:02:03 +0300 | [diff] [blame] | 1388 | if (aic3x->gpio_reset >= 0) { |
| 1389 | udelay(1); |
| 1390 | gpio_set_value(aic3x->gpio_reset, 1); |
| 1391 | } |
| 1392 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1393 | ret = snd_soc_register_codec(&i2c->dev, |
| 1394 | &soc_codec_dev_aic3x, &aic3x_dai, 1); |
| 1395 | if (ret < 0) |
| 1396 | goto err_enable; |
| 1397 | return ret; |
Jarkko Nikula | 07779fd | 2010-04-26 15:49:14 +0300 | [diff] [blame] | 1398 | |
| 1399 | err_enable: |
| 1400 | regulator_bulk_free(ARRAY_SIZE(aic3x->supplies), aic3x->supplies); |
| 1401 | err_get: |
Jarkko Nikula | 5193d62 | 2010-05-05 13:02:03 +0300 | [diff] [blame] | 1402 | if (aic3x->gpio_reset >= 0) |
| 1403 | gpio_free(aic3x->gpio_reset); |
| 1404 | err_gpio: |
Jarkko Nikula | 07779fd | 2010-04-26 15:49:14 +0300 | [diff] [blame] | 1405 | kfree(aic3x); |
| 1406 | return ret; |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 1407 | } |
| 1408 | |
Jean Delvare | ba8ed12 | 2008-09-22 14:15:53 +0200 | [diff] [blame] | 1409 | static int aic3x_i2c_remove(struct i2c_client *client) |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 1410 | { |
Ben Dooks | cb3826f | 2009-08-20 22:50:41 +0100 | [diff] [blame] | 1411 | struct aic3x_priv *aic3x = i2c_get_clientdata(client); |
| 1412 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1413 | if (aic3x->gpio_reset >= 0) { |
| 1414 | gpio_set_value(aic3x->gpio_reset, 0); |
| 1415 | gpio_free(aic3x->gpio_reset); |
| 1416 | } |
| 1417 | regulator_bulk_disable(ARRAY_SIZE(aic3x->supplies), aic3x->supplies); |
| 1418 | regulator_bulk_free(ARRAY_SIZE(aic3x->supplies), aic3x->supplies); |
| 1419 | |
| 1420 | snd_soc_unregister_codec(&client->dev); |
| 1421 | kfree(i2c_get_clientdata(client)); |
| 1422 | return 0; |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 1423 | } |
| 1424 | |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 1425 | /* machine i2c codec control layer */ |
| 1426 | static struct i2c_driver aic3x_i2c_driver = { |
| 1427 | .driver = { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1428 | .name = "tlv320aic3x-codec", |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 1429 | .owner = THIS_MODULE, |
| 1430 | }, |
Ben Dooks | cb3826f | 2009-08-20 22:50:41 +0100 | [diff] [blame] | 1431 | .probe = aic3x_i2c_probe, |
Jean Delvare | ba8ed12 | 2008-09-22 14:15:53 +0200 | [diff] [blame] | 1432 | .remove = aic3x_i2c_remove, |
| 1433 | .id_table = aic3x_i2c_id, |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 1434 | }; |
Daniel Mack | 54e7e61 | 2008-04-30 16:20:52 +0200 | [diff] [blame] | 1435 | |
Ben Dooks | cb3826f | 2009-08-20 22:50:41 +0100 | [diff] [blame] | 1436 | static inline void aic3x_i2c_init(void) |
Jean Delvare | ba8ed12 | 2008-09-22 14:15:53 +0200 | [diff] [blame] | 1437 | { |
Jean Delvare | ba8ed12 | 2008-09-22 14:15:53 +0200 | [diff] [blame] | 1438 | int ret; |
| 1439 | |
| 1440 | ret = i2c_add_driver(&aic3x_i2c_driver); |
Ben Dooks | cb3826f | 2009-08-20 22:50:41 +0100 | [diff] [blame] | 1441 | if (ret) |
| 1442 | printk(KERN_ERR "%s: error regsitering i2c driver, %d\n", |
| 1443 | __func__, ret); |
Jean Delvare | ba8ed12 | 2008-09-22 14:15:53 +0200 | [diff] [blame] | 1444 | } |
Ben Dooks | cb3826f | 2009-08-20 22:50:41 +0100 | [diff] [blame] | 1445 | |
| 1446 | static inline void aic3x_i2c_exit(void) |
| 1447 | { |
| 1448 | i2c_del_driver(&aic3x_i2c_driver); |
| 1449 | } |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 1450 | #endif |
| 1451 | |
Takashi Iwai | c9b3a40 | 2008-12-10 07:47:22 +0100 | [diff] [blame] | 1452 | static int __init aic3x_modinit(void) |
Mark Brown | 64089b8 | 2008-12-08 19:17:58 +0000 | [diff] [blame] | 1453 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1454 | int ret = 0; |
| 1455 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
| 1456 | ret = i2c_add_driver(&aic3x_i2c_driver); |
| 1457 | if (ret != 0) { |
| 1458 | printk(KERN_ERR "Failed to register TLV320AIC3x I2C driver: %d\n", |
| 1459 | ret); |
| 1460 | } |
| 1461 | #endif |
| 1462 | return ret; |
Mark Brown | 64089b8 | 2008-12-08 19:17:58 +0000 | [diff] [blame] | 1463 | } |
| 1464 | module_init(aic3x_modinit); |
| 1465 | |
| 1466 | static void __exit aic3x_exit(void) |
| 1467 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1468 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
| 1469 | i2c_del_driver(&aic3x_i2c_driver); |
| 1470 | #endif |
Mark Brown | 64089b8 | 2008-12-08 19:17:58 +0000 | [diff] [blame] | 1471 | } |
| 1472 | module_exit(aic3x_exit); |
| 1473 | |
Vladimir Barinov | 44d0a87 | 2007-11-14 17:07:17 +0100 | [diff] [blame] | 1474 | MODULE_DESCRIPTION("ASoC TLV320AIC3X codec driver"); |
| 1475 | MODULE_AUTHOR("Vladimir Barinov"); |
| 1476 | MODULE_LICENSE("GPL"); |