Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 2 | /* |
| 3 | * ALSA SoC TLV320AIC23 codec driver |
| 4 | * |
| 5 | * Author: Arun KS, <arunks@mistralsolutions.com> |
| 6 | * Copyright: (C) 2008 Mistral Solutions Pvt Ltd., |
| 7 | * |
| 8 | * Based on sound/soc/codecs/wm8731.c by Richard Purdie |
| 9 | * |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 10 | * Notes: |
| 11 | * The AIC23 is a driver for a low power stereo audio |
| 12 | * codec tlv320aic23 |
| 13 | * |
| 14 | * The machine layer should disable unsupported inputs/outputs by |
| 15 | * snd_soc_dapm_disable_pin(codec, "LHPOUT"), etc. |
| 16 | */ |
| 17 | |
| 18 | #include <linux/module.h> |
| 19 | #include <linux/moduleparam.h> |
| 20 | #include <linux/init.h> |
| 21 | #include <linux/delay.h> |
| 22 | #include <linux/pm.h> |
Mark Brown | 4aa11d6 | 2013-09-24 19:26:08 +0100 | [diff] [blame] | 23 | #include <linux/regmap.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 24 | #include <linux/slab.h> |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 25 | #include <sound/core.h> |
| 26 | #include <sound/pcm.h> |
| 27 | #include <sound/pcm_params.h> |
| 28 | #include <sound/soc.h> |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 29 | #include <sound/tlv.h> |
| 30 | #include <sound/initval.h> |
| 31 | |
| 32 | #include "tlv320aic23.h" |
| 33 | |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 34 | /* |
| 35 | * AIC23 register cache |
| 36 | */ |
Mark Brown | 4aa11d6 | 2013-09-24 19:26:08 +0100 | [diff] [blame] | 37 | static const struct reg_default tlv320aic23_reg[] = { |
| 38 | { 0, 0x0097 }, |
| 39 | { 1, 0x0097 }, |
| 40 | { 2, 0x00F9 }, |
| 41 | { 3, 0x00F9 }, |
| 42 | { 4, 0x001A }, |
| 43 | { 5, 0x0004 }, |
| 44 | { 6, 0x0007 }, |
| 45 | { 7, 0x0001 }, |
| 46 | { 8, 0x0020 }, |
| 47 | { 9, 0x0000 }, |
| 48 | }; |
| 49 | |
Max Filippov | b3fc572 | 2014-03-06 14:04:41 +0400 | [diff] [blame] | 50 | const struct regmap_config tlv320aic23_regmap = { |
Mark Brown | 4aa11d6 | 2013-09-24 19:26:08 +0100 | [diff] [blame] | 51 | .reg_bits = 7, |
| 52 | .val_bits = 9, |
| 53 | |
| 54 | .max_register = TLV320AIC23_RESET, |
| 55 | .reg_defaults = tlv320aic23_reg, |
| 56 | .num_reg_defaults = ARRAY_SIZE(tlv320aic23_reg), |
| 57 | .cache_type = REGCACHE_RBTREE, |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 58 | }; |
Max Filippov | 4042328 | 2014-03-08 13:31:06 +0400 | [diff] [blame] | 59 | EXPORT_SYMBOL(tlv320aic23_regmap); |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 60 | |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 61 | static const char *rec_src_text[] = { "Line", "Mic" }; |
| 62 | static const char *deemph_text[] = {"None", "32Khz", "44.1Khz", "48Khz"}; |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 63 | |
Takashi Iwai | 806057c | 2014-02-18 10:45:53 +0100 | [diff] [blame] | 64 | static SOC_ENUM_SINGLE_DECL(rec_src_enum, |
| 65 | TLV320AIC23_ANLG, 2, rec_src_text); |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 66 | |
| 67 | static const struct snd_kcontrol_new tlv320aic23_rec_src_mux_controls = |
| 68 | SOC_DAPM_ENUM("Input Select", rec_src_enum); |
| 69 | |
Takashi Iwai | 806057c | 2014-02-18 10:45:53 +0100 | [diff] [blame] | 70 | static SOC_ENUM_SINGLE_DECL(tlv320aic23_deemph, |
| 71 | TLV320AIC23_DIGT, 1, deemph_text); |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 72 | |
| 73 | static const DECLARE_TLV_DB_SCALE(out_gain_tlv, -12100, 100, 0); |
| 74 | static const DECLARE_TLV_DB_SCALE(input_gain_tlv, -1725, 75, 0); |
Arun KS | df91ddf | 2008-10-03 17:07:30 +0530 | [diff] [blame] | 75 | static const DECLARE_TLV_DB_SCALE(sidetone_vol_tlv, -1800, 300, 0); |
| 76 | |
| 77 | static int snd_soc_tlv320aic23_put_volsw(struct snd_kcontrol *kcontrol, |
| 78 | struct snd_ctl_elem_value *ucontrol) |
| 79 | { |
Kuninori Morimoto | ff06ac2 | 2018-01-29 04:12:48 +0000 | [diff] [blame] | 80 | struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol); |
Arun KS | df91ddf | 2008-10-03 17:07:30 +0530 | [diff] [blame] | 81 | u16 val, reg; |
| 82 | |
| 83 | val = (ucontrol->value.integer.value[0] & 0x07); |
| 84 | |
| 85 | /* linear conversion to userspace |
| 86 | * 000 = -6db |
| 87 | * 001 = -9db |
| 88 | * 010 = -12db |
| 89 | * 011 = -18db (Min) |
| 90 | * 100 = 0db (Max) |
| 91 | */ |
| 92 | val = (val >= 4) ? 4 : (3 - val); |
| 93 | |
Kuninori Morimoto | e348cf5 | 2020-06-16 14:20:46 +0900 | [diff] [blame] | 94 | reg = snd_soc_component_read(component, TLV320AIC23_ANLG) & (~0x1C0); |
Kuninori Morimoto | ff06ac2 | 2018-01-29 04:12:48 +0000 | [diff] [blame] | 95 | snd_soc_component_write(component, TLV320AIC23_ANLG, reg | (val << 6)); |
Arun KS | df91ddf | 2008-10-03 17:07:30 +0530 | [diff] [blame] | 96 | |
| 97 | return 0; |
| 98 | } |
| 99 | |
| 100 | static int snd_soc_tlv320aic23_get_volsw(struct snd_kcontrol *kcontrol, |
| 101 | struct snd_ctl_elem_value *ucontrol) |
| 102 | { |
Kuninori Morimoto | ff06ac2 | 2018-01-29 04:12:48 +0000 | [diff] [blame] | 103 | struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol); |
Arun KS | df91ddf | 2008-10-03 17:07:30 +0530 | [diff] [blame] | 104 | u16 val; |
| 105 | |
Kuninori Morimoto | e348cf5 | 2020-06-16 14:20:46 +0900 | [diff] [blame] | 106 | val = snd_soc_component_read(component, TLV320AIC23_ANLG) & (0x1C0); |
Arun KS | df91ddf | 2008-10-03 17:07:30 +0530 | [diff] [blame] | 107 | val = val >> 6; |
| 108 | val = (val >= 4) ? 4 : (3 - val); |
| 109 | ucontrol->value.integer.value[0] = val; |
| 110 | return 0; |
| 111 | |
| 112 | } |
| 113 | |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 114 | static const struct snd_kcontrol_new tlv320aic23_snd_controls[] = { |
| 115 | SOC_DOUBLE_R_TLV("Digital Playback Volume", TLV320AIC23_LCHNVOL, |
| 116 | TLV320AIC23_RCHNVOL, 0, 127, 0, out_gain_tlv), |
| 117 | SOC_SINGLE("Digital Playback Switch", TLV320AIC23_DIGT, 3, 1, 1), |
| 118 | SOC_DOUBLE_R("Line Input Switch", TLV320AIC23_LINVOL, |
| 119 | TLV320AIC23_RINVOL, 7, 1, 0), |
| 120 | SOC_DOUBLE_R_TLV("Line Input Volume", TLV320AIC23_LINVOL, |
| 121 | TLV320AIC23_RINVOL, 0, 31, 0, input_gain_tlv), |
| 122 | SOC_SINGLE("Mic Input Switch", TLV320AIC23_ANLG, 1, 1, 1), |
| 123 | SOC_SINGLE("Mic Booster Switch", TLV320AIC23_ANLG, 0, 1, 0), |
Peter Ujfalusi | 0f9887d | 2011-10-05 10:29:19 +0300 | [diff] [blame] | 124 | SOC_SINGLE_EXT_TLV("Sidetone Volume", TLV320AIC23_ANLG, 6, 4, 0, |
| 125 | snd_soc_tlv320aic23_get_volsw, |
| 126 | snd_soc_tlv320aic23_put_volsw, sidetone_vol_tlv), |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 127 | SOC_ENUM("Playback De-emphasis", tlv320aic23_deemph), |
| 128 | }; |
| 129 | |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 130 | /* PGA Mixer controls for Line and Mic switch */ |
| 131 | static const struct snd_kcontrol_new tlv320aic23_output_mixer_controls[] = { |
| 132 | SOC_DAPM_SINGLE("Line Bypass Switch", TLV320AIC23_ANLG, 3, 1, 0), |
| 133 | SOC_DAPM_SINGLE("Mic Sidetone Switch", TLV320AIC23_ANLG, 5, 1, 0), |
| 134 | SOC_DAPM_SINGLE("Playback Switch", TLV320AIC23_ANLG, 4, 1, 0), |
| 135 | }; |
| 136 | |
| 137 | static const struct snd_soc_dapm_widget tlv320aic23_dapm_widgets[] = { |
| 138 | SND_SOC_DAPM_DAC("DAC", "Playback", TLV320AIC23_PWR, 3, 1), |
| 139 | SND_SOC_DAPM_ADC("ADC", "Capture", TLV320AIC23_PWR, 2, 1), |
| 140 | SND_SOC_DAPM_MUX("Capture Source", SND_SOC_NOPM, 0, 0, |
| 141 | &tlv320aic23_rec_src_mux_controls), |
| 142 | SND_SOC_DAPM_MIXER("Output Mixer", TLV320AIC23_PWR, 4, 1, |
| 143 | &tlv320aic23_output_mixer_controls[0], |
| 144 | ARRAY_SIZE(tlv320aic23_output_mixer_controls)), |
| 145 | SND_SOC_DAPM_PGA("Line Input", TLV320AIC23_PWR, 0, 1, NULL, 0), |
| 146 | SND_SOC_DAPM_PGA("Mic Input", TLV320AIC23_PWR, 1, 1, NULL, 0), |
| 147 | |
| 148 | SND_SOC_DAPM_OUTPUT("LHPOUT"), |
| 149 | SND_SOC_DAPM_OUTPUT("RHPOUT"), |
| 150 | SND_SOC_DAPM_OUTPUT("LOUT"), |
| 151 | SND_SOC_DAPM_OUTPUT("ROUT"), |
| 152 | |
| 153 | SND_SOC_DAPM_INPUT("LLINEIN"), |
| 154 | SND_SOC_DAPM_INPUT("RLINEIN"), |
| 155 | |
| 156 | SND_SOC_DAPM_INPUT("MICIN"), |
| 157 | }; |
| 158 | |
Lu Guanqun | a7dca70 | 2011-03-30 21:53:16 +0800 | [diff] [blame] | 159 | static const struct snd_soc_dapm_route tlv320aic23_intercon[] = { |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 160 | /* Output Mixer */ |
| 161 | {"Output Mixer", "Line Bypass Switch", "Line Input"}, |
| 162 | {"Output Mixer", "Playback Switch", "DAC"}, |
| 163 | {"Output Mixer", "Mic Sidetone Switch", "Mic Input"}, |
| 164 | |
| 165 | /* Outputs */ |
| 166 | {"RHPOUT", NULL, "Output Mixer"}, |
| 167 | {"LHPOUT", NULL, "Output Mixer"}, |
| 168 | {"LOUT", NULL, "Output Mixer"}, |
| 169 | {"ROUT", NULL, "Output Mixer"}, |
| 170 | |
| 171 | /* Inputs */ |
Liviu Dudau | a03faba | 2017-03-01 12:26:28 +0000 | [diff] [blame] | 172 | {"Line Input", NULL, "LLINEIN"}, |
| 173 | {"Line Input", NULL, "RLINEIN"}, |
| 174 | {"Mic Input", NULL, "MICIN"}, |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 175 | |
| 176 | /* input mux */ |
| 177 | {"Capture Source", "Line", "Line Input"}, |
| 178 | {"Capture Source", "Mic", "Mic Input"}, |
| 179 | {"ADC", NULL, "Capture Source"}, |
| 180 | |
| 181 | }; |
| 182 | |
Troy Kisky | 26df91c | 2008-11-05 18:53:28 +0000 | [diff] [blame] | 183 | /* AIC23 driver data */ |
| 184 | struct aic23 { |
Mark Brown | 4aa11d6 | 2013-09-24 19:26:08 +0100 | [diff] [blame] | 185 | struct regmap *regmap; |
Troy Kisky | 26df91c | 2008-11-05 18:53:28 +0000 | [diff] [blame] | 186 | int mclk; |
| 187 | int requested_adc; |
| 188 | int requested_dac; |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 189 | }; |
| 190 | |
Troy Kisky | 26df91c | 2008-11-05 18:53:28 +0000 | [diff] [blame] | 191 | /* |
| 192 | * Common Crystals used |
| 193 | * 11.2896 Mhz /128 = *88.2k /192 = 58.8k |
| 194 | * 12.0000 Mhz /125 = *96k /136 = 88.235K |
| 195 | * 12.2880 Mhz /128 = *96k /192 = 64k |
| 196 | * 16.9344 Mhz /128 = 132.3k /192 = *88.2k |
| 197 | * 18.4320 Mhz /128 = 144k /192 = *96k |
| 198 | */ |
| 199 | |
| 200 | /* |
| 201 | * Normal BOSR 0-256/2 = 128, 1-384/2 = 192 |
| 202 | * USB BOSR 0-250/2 = 125, 1-272/2 = 136 |
| 203 | */ |
| 204 | static const int bosr_usb_divisor_table[] = { |
| 205 | 128, 125, 192, 136 |
| 206 | }; |
| 207 | #define LOWER_GROUP ((1<<0) | (1<<1) | (1<<2) | (1<<3) | (1<<6) | (1<<7)) |
| 208 | #define UPPER_GROUP ((1<<8) | (1<<9) | (1<<10) | (1<<11) | (1<<15)) |
| 209 | static const unsigned short sr_valid_mask[] = { |
| 210 | LOWER_GROUP|UPPER_GROUP, /* Normal, bosr - 0*/ |
Troy Kisky | 26df91c | 2008-11-05 18:53:28 +0000 | [diff] [blame] | 211 | LOWER_GROUP, /* Usb, bosr - 0*/ |
Troy Kisky | bab0212 | 2009-11-17 13:51:01 -0700 | [diff] [blame] | 212 | LOWER_GROUP|UPPER_GROUP, /* Normal, bosr - 1*/ |
Troy Kisky | 26df91c | 2008-11-05 18:53:28 +0000 | [diff] [blame] | 213 | UPPER_GROUP, /* Usb, bosr - 1*/ |
| 214 | }; |
| 215 | /* |
| 216 | * Every divisor is a factor of 11*12 |
| 217 | */ |
| 218 | #define SR_MULT (11*12) |
Troy Kisky | ccff4b1 | 2009-06-05 19:15:58 -0700 | [diff] [blame] | 219 | #define A(x) (SR_MULT/x) |
Troy Kisky | 26df91c | 2008-11-05 18:53:28 +0000 | [diff] [blame] | 220 | static const unsigned char sr_adc_mult_table[] = { |
Troy Kisky | ccff4b1 | 2009-06-05 19:15:58 -0700 | [diff] [blame] | 221 | A(2), A(2), A(12), A(12), 0, 0, A(3), A(1), |
| 222 | A(2), A(2), A(11), A(11), 0, 0, 0, A(1) |
Troy Kisky | 26df91c | 2008-11-05 18:53:28 +0000 | [diff] [blame] | 223 | }; |
| 224 | static const unsigned char sr_dac_mult_table[] = { |
Troy Kisky | ccff4b1 | 2009-06-05 19:15:58 -0700 | [diff] [blame] | 225 | A(2), A(12), A(2), A(12), 0, 0, A(3), A(1), |
| 226 | A(2), A(11), A(2), A(11), 0, 0, 0, A(1) |
Troy Kisky | 26df91c | 2008-11-05 18:53:28 +0000 | [diff] [blame] | 227 | }; |
| 228 | |
| 229 | static unsigned get_score(int adc, int adc_l, int adc_h, int need_adc, |
| 230 | int dac, int dac_l, int dac_h, int need_dac) |
| 231 | { |
| 232 | if ((adc >= adc_l) && (adc <= adc_h) && |
| 233 | (dac >= dac_l) && (dac <= dac_h)) { |
| 234 | int diff_adc = need_adc - adc; |
| 235 | int diff_dac = need_dac - dac; |
| 236 | return abs(diff_adc) + abs(diff_dac); |
| 237 | } |
| 238 | return UINT_MAX; |
| 239 | } |
| 240 | |
| 241 | static int find_rate(int mclk, u32 need_adc, u32 need_dac) |
| 242 | { |
| 243 | int i, j; |
| 244 | int best_i = -1; |
| 245 | int best_j = -1; |
| 246 | int best_div = 0; |
| 247 | unsigned best_score = UINT_MAX; |
| 248 | int adc_l, adc_h, dac_l, dac_h; |
| 249 | |
| 250 | need_adc *= SR_MULT; |
| 251 | need_dac *= SR_MULT; |
| 252 | /* |
| 253 | * rates given are +/- 1/32 |
| 254 | */ |
| 255 | adc_l = need_adc - (need_adc >> 5); |
| 256 | adc_h = need_adc + (need_adc >> 5); |
| 257 | dac_l = need_dac - (need_dac >> 5); |
| 258 | dac_h = need_dac + (need_dac >> 5); |
Mark Brown | 8d702f2 | 2008-11-17 21:42:01 +0000 | [diff] [blame] | 259 | for (i = 0; i < ARRAY_SIZE(bosr_usb_divisor_table); i++) { |
Troy Kisky | 26df91c | 2008-11-05 18:53:28 +0000 | [diff] [blame] | 260 | int base = mclk / bosr_usb_divisor_table[i]; |
| 261 | int mask = sr_valid_mask[i]; |
Mark Brown | 8d702f2 | 2008-11-17 21:42:01 +0000 | [diff] [blame] | 262 | for (j = 0; j < ARRAY_SIZE(sr_adc_mult_table); |
| 263 | j++, mask >>= 1) { |
Troy Kisky | 26df91c | 2008-11-05 18:53:28 +0000 | [diff] [blame] | 264 | int adc; |
| 265 | int dac; |
| 266 | int score; |
| 267 | if ((mask & 1) == 0) |
| 268 | continue; |
| 269 | adc = base * sr_adc_mult_table[j]; |
| 270 | dac = base * sr_dac_mult_table[j]; |
| 271 | score = get_score(adc, adc_l, adc_h, need_adc, |
| 272 | dac, dac_l, dac_h, need_dac); |
| 273 | if (best_score > score) { |
| 274 | best_score = score; |
| 275 | best_i = i; |
| 276 | best_j = j; |
| 277 | best_div = 0; |
| 278 | } |
| 279 | score = get_score((adc >> 1), adc_l, adc_h, need_adc, |
| 280 | (dac >> 1), dac_l, dac_h, need_dac); |
| 281 | /* prefer to have a /2 */ |
| 282 | if ((score != UINT_MAX) && (best_score >= score)) { |
| 283 | best_score = score; |
| 284 | best_i = i; |
| 285 | best_j = j; |
| 286 | best_div = 1; |
| 287 | } |
| 288 | } |
| 289 | } |
| 290 | return (best_j << 2) | best_i | (best_div << TLV320AIC23_CLKIN_SHIFT); |
| 291 | } |
| 292 | |
Mark Brown | 8d702f2 | 2008-11-17 21:42:01 +0000 | [diff] [blame] | 293 | #ifdef DEBUG |
Kuninori Morimoto | ff06ac2 | 2018-01-29 04:12:48 +0000 | [diff] [blame] | 294 | static void get_current_sample_rates(struct snd_soc_component *component, int mclk, |
Troy Kisky | 26df91c | 2008-11-05 18:53:28 +0000 | [diff] [blame] | 295 | u32 *sample_rate_adc, u32 *sample_rate_dac) |
| 296 | { |
Kuninori Morimoto | e348cf5 | 2020-06-16 14:20:46 +0900 | [diff] [blame] | 297 | int src = snd_soc_component_read(component, TLV320AIC23_SRATE); |
Troy Kisky | 26df91c | 2008-11-05 18:53:28 +0000 | [diff] [blame] | 298 | int sr = (src >> 2) & 0x0f; |
| 299 | int val = (mclk / bosr_usb_divisor_table[src & 3]); |
| 300 | int adc = (val * sr_adc_mult_table[sr]) / SR_MULT; |
| 301 | int dac = (val * sr_dac_mult_table[sr]) / SR_MULT; |
| 302 | if (src & TLV320AIC23_CLKIN_HALF) { |
| 303 | adc >>= 1; |
| 304 | dac >>= 1; |
| 305 | } |
| 306 | *sample_rate_adc = adc; |
| 307 | *sample_rate_dac = dac; |
| 308 | } |
Mark Brown | 8d702f2 | 2008-11-17 21:42:01 +0000 | [diff] [blame] | 309 | #endif |
Troy Kisky | 26df91c | 2008-11-05 18:53:28 +0000 | [diff] [blame] | 310 | |
Kuninori Morimoto | ff06ac2 | 2018-01-29 04:12:48 +0000 | [diff] [blame] | 311 | static int set_sample_rate_control(struct snd_soc_component *component, int mclk, |
Troy Kisky | 26df91c | 2008-11-05 18:53:28 +0000 | [diff] [blame] | 312 | u32 sample_rate_adc, u32 sample_rate_dac) |
| 313 | { |
| 314 | /* Search for the right sample rate */ |
| 315 | int data = find_rate(mclk, sample_rate_adc, sample_rate_dac); |
| 316 | if (data < 0) { |
| 317 | printk(KERN_ERR "%s:Invalid rate %u,%u requested\n", |
| 318 | __func__, sample_rate_adc, sample_rate_dac); |
| 319 | return -EINVAL; |
| 320 | } |
Kuninori Morimoto | ff06ac2 | 2018-01-29 04:12:48 +0000 | [diff] [blame] | 321 | snd_soc_component_write(component, TLV320AIC23_SRATE, data); |
Mark Brown | 8d702f2 | 2008-11-17 21:42:01 +0000 | [diff] [blame] | 322 | #ifdef DEBUG |
| 323 | { |
| 324 | u32 adc, dac; |
Kuninori Morimoto | ff06ac2 | 2018-01-29 04:12:48 +0000 | [diff] [blame] | 325 | get_current_sample_rates(component, mclk, &adc, &dac); |
Troy Kisky | 26df91c | 2008-11-05 18:53:28 +0000 | [diff] [blame] | 326 | printk(KERN_DEBUG "actual samplerate = %u,%u reg=%x\n", |
| 327 | adc, dac, data); |
| 328 | } |
Mark Brown | 8d702f2 | 2008-11-17 21:42:01 +0000 | [diff] [blame] | 329 | #endif |
Troy Kisky | 26df91c | 2008-11-05 18:53:28 +0000 | [diff] [blame] | 330 | return 0; |
| 331 | } |
| 332 | |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 333 | static int tlv320aic23_hw_params(struct snd_pcm_substream *substream, |
Mark Brown | dee89c4 | 2008-11-18 22:11:38 +0000 | [diff] [blame] | 334 | struct snd_pcm_hw_params *params, |
| 335 | struct snd_soc_dai *dai) |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 336 | { |
Kuninori Morimoto | ff06ac2 | 2018-01-29 04:12:48 +0000 | [diff] [blame] | 337 | struct snd_soc_component *component = dai->component; |
Troy Kisky | 26df91c | 2008-11-05 18:53:28 +0000 | [diff] [blame] | 338 | u16 iface_reg; |
| 339 | int ret; |
Kuninori Morimoto | ff06ac2 | 2018-01-29 04:12:48 +0000 | [diff] [blame] | 340 | struct aic23 *aic23 = snd_soc_component_get_drvdata(component); |
Troy Kisky | 26df91c | 2008-11-05 18:53:28 +0000 | [diff] [blame] | 341 | u32 sample_rate_adc = aic23->requested_adc; |
| 342 | u32 sample_rate_dac = aic23->requested_dac; |
| 343 | u32 sample_rate = params_rate(params); |
| 344 | |
| 345 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 346 | aic23->requested_dac = sample_rate_dac = sample_rate; |
| 347 | if (!sample_rate_adc) |
| 348 | sample_rate_adc = sample_rate; |
| 349 | } else { |
| 350 | aic23->requested_adc = sample_rate_adc = sample_rate; |
| 351 | if (!sample_rate_dac) |
| 352 | sample_rate_dac = sample_rate; |
| 353 | } |
Kuninori Morimoto | ff06ac2 | 2018-01-29 04:12:48 +0000 | [diff] [blame] | 354 | ret = set_sample_rate_control(component, aic23->mclk, sample_rate_adc, |
Troy Kisky | 26df91c | 2008-11-05 18:53:28 +0000 | [diff] [blame] | 355 | sample_rate_dac); |
| 356 | if (ret < 0) |
| 357 | return ret; |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 358 | |
Kuninori Morimoto | e348cf5 | 2020-06-16 14:20:46 +0900 | [diff] [blame] | 359 | iface_reg = snd_soc_component_read(component, TLV320AIC23_DIGT_FMT) & ~(0x03 << 2); |
Axel Lin | f9dfbf9 | 2011-10-13 15:06:43 +0800 | [diff] [blame] | 360 | |
Mark Brown | 08074dc | 2014-07-29 20:13:00 +0100 | [diff] [blame] | 361 | switch (params_width(params)) { |
| 362 | case 16: |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 363 | break; |
Mark Brown | 08074dc | 2014-07-29 20:13:00 +0100 | [diff] [blame] | 364 | case 20: |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 365 | iface_reg |= (0x01 << 2); |
| 366 | break; |
Mark Brown | 08074dc | 2014-07-29 20:13:00 +0100 | [diff] [blame] | 367 | case 24: |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 368 | iface_reg |= (0x02 << 2); |
| 369 | break; |
Mark Brown | 08074dc | 2014-07-29 20:13:00 +0100 | [diff] [blame] | 370 | case 32: |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 371 | iface_reg |= (0x03 << 2); |
| 372 | break; |
| 373 | } |
Kuninori Morimoto | ff06ac2 | 2018-01-29 04:12:48 +0000 | [diff] [blame] | 374 | snd_soc_component_write(component, TLV320AIC23_DIGT_FMT, iface_reg); |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 375 | |
| 376 | return 0; |
| 377 | } |
| 378 | |
Mark Brown | dee89c4 | 2008-11-18 22:11:38 +0000 | [diff] [blame] | 379 | static int tlv320aic23_pcm_prepare(struct snd_pcm_substream *substream, |
| 380 | struct snd_soc_dai *dai) |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 381 | { |
Kuninori Morimoto | ff06ac2 | 2018-01-29 04:12:48 +0000 | [diff] [blame] | 382 | struct snd_soc_component *component = dai->component; |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 383 | |
| 384 | /* set active */ |
Kuninori Morimoto | ff06ac2 | 2018-01-29 04:12:48 +0000 | [diff] [blame] | 385 | snd_soc_component_write(component, TLV320AIC23_ACTIVE, 0x0001); |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 386 | |
| 387 | return 0; |
| 388 | } |
| 389 | |
Mark Brown | dee89c4 | 2008-11-18 22:11:38 +0000 | [diff] [blame] | 390 | static void tlv320aic23_shutdown(struct snd_pcm_substream *substream, |
| 391 | struct snd_soc_dai *dai) |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 392 | { |
Kuninori Morimoto | ff06ac2 | 2018-01-29 04:12:48 +0000 | [diff] [blame] | 393 | struct snd_soc_component *component = dai->component; |
| 394 | struct aic23 *aic23 = snd_soc_component_get_drvdata(component); |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 395 | |
| 396 | /* deactivate */ |
Kuninori Morimoto | 5e518ed | 2020-05-15 09:47:11 +0900 | [diff] [blame] | 397 | if (!snd_soc_component_active(component)) { |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 398 | udelay(50); |
Kuninori Morimoto | ff06ac2 | 2018-01-29 04:12:48 +0000 | [diff] [blame] | 399 | snd_soc_component_write(component, TLV320AIC23_ACTIVE, 0x0); |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 400 | } |
Troy Kisky | 26df91c | 2008-11-05 18:53:28 +0000 | [diff] [blame] | 401 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 402 | aic23->requested_dac = 0; |
| 403 | else |
| 404 | aic23->requested_adc = 0; |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 405 | } |
| 406 | |
Kuninori Morimoto | 960af79 | 2020-07-09 10:56:25 +0900 | [diff] [blame] | 407 | static int tlv320aic23_mute(struct snd_soc_dai *dai, int mute, int direction) |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 408 | { |
Kuninori Morimoto | ff06ac2 | 2018-01-29 04:12:48 +0000 | [diff] [blame] | 409 | struct snd_soc_component *component = dai->component; |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 410 | u16 reg; |
| 411 | |
Kuninori Morimoto | e348cf5 | 2020-06-16 14:20:46 +0900 | [diff] [blame] | 412 | reg = snd_soc_component_read(component, TLV320AIC23_DIGT); |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 413 | if (mute) |
| 414 | reg |= TLV320AIC23_DACM_MUTE; |
| 415 | |
| 416 | else |
| 417 | reg &= ~TLV320AIC23_DACM_MUTE; |
| 418 | |
Kuninori Morimoto | ff06ac2 | 2018-01-29 04:12:48 +0000 | [diff] [blame] | 419 | snd_soc_component_write(component, TLV320AIC23_DIGT, reg); |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 420 | |
| 421 | return 0; |
| 422 | } |
| 423 | |
| 424 | static int tlv320aic23_set_dai_fmt(struct snd_soc_dai *codec_dai, |
| 425 | unsigned int fmt) |
| 426 | { |
Kuninori Morimoto | ff06ac2 | 2018-01-29 04:12:48 +0000 | [diff] [blame] | 427 | struct snd_soc_component *component = codec_dai->component; |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 428 | u16 iface_reg; |
| 429 | |
Kuninori Morimoto | e348cf5 | 2020-06-16 14:20:46 +0900 | [diff] [blame] | 430 | iface_reg = snd_soc_component_read(component, TLV320AIC23_DIGT_FMT) & (~0x03); |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 431 | |
| 432 | /* set master/slave audio interface */ |
| 433 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 434 | case SND_SOC_DAIFMT_CBM_CFM: |
| 435 | iface_reg |= TLV320AIC23_MS_MASTER; |
| 436 | break; |
| 437 | case SND_SOC_DAIFMT_CBS_CFS: |
Axel Lin | b01a3d6 | 2011-10-27 16:35:49 +0800 | [diff] [blame] | 438 | iface_reg &= ~TLV320AIC23_MS_MASTER; |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 439 | break; |
| 440 | default: |
| 441 | return -EINVAL; |
| 442 | |
| 443 | } |
| 444 | |
| 445 | /* interface format */ |
| 446 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
| 447 | case SND_SOC_DAIFMT_I2S: |
| 448 | iface_reg |= TLV320AIC23_FOR_I2S; |
| 449 | break; |
Peter Ujfalusi | 894bf92 | 2009-04-09 12:34:40 +0300 | [diff] [blame] | 450 | case SND_SOC_DAIFMT_DSP_A: |
| 451 | iface_reg |= TLV320AIC23_LRP_ON; |
Gustavo A. R. Silva | 3e146b5 | 2020-07-08 20:03:59 -0500 | [diff] [blame] | 452 | fallthrough; |
Jarkko Nikula | bd25867 | 2008-12-22 10:21:36 +0200 | [diff] [blame] | 453 | case SND_SOC_DAIFMT_DSP_B: |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 454 | iface_reg |= TLV320AIC23_FOR_DSP; |
| 455 | break; |
| 456 | case SND_SOC_DAIFMT_RIGHT_J: |
| 457 | break; |
| 458 | case SND_SOC_DAIFMT_LEFT_J: |
| 459 | iface_reg |= TLV320AIC23_FOR_LJUST; |
| 460 | break; |
| 461 | default: |
| 462 | return -EINVAL; |
| 463 | |
| 464 | } |
| 465 | |
Kuninori Morimoto | ff06ac2 | 2018-01-29 04:12:48 +0000 | [diff] [blame] | 466 | snd_soc_component_write(component, TLV320AIC23_DIGT_FMT, iface_reg); |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 467 | |
| 468 | return 0; |
| 469 | } |
| 470 | |
| 471 | static int tlv320aic23_set_dai_sysclk(struct snd_soc_dai *codec_dai, |
| 472 | int clk_id, unsigned int freq, int dir) |
| 473 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 474 | struct aic23 *aic23 = snd_soc_dai_get_drvdata(codec_dai); |
Troy Kisky | 26df91c | 2008-11-05 18:53:28 +0000 | [diff] [blame] | 475 | aic23->mclk = freq; |
| 476 | return 0; |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 477 | } |
| 478 | |
Kuninori Morimoto | ff06ac2 | 2018-01-29 04:12:48 +0000 | [diff] [blame] | 479 | static int tlv320aic23_set_bias_level(struct snd_soc_component *component, |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 480 | enum snd_soc_bias_level level) |
| 481 | { |
Kuninori Morimoto | e348cf5 | 2020-06-16 14:20:46 +0900 | [diff] [blame] | 482 | u16 reg = snd_soc_component_read(component, TLV320AIC23_PWR) & 0x17f; |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 483 | |
| 484 | switch (level) { |
| 485 | case SND_SOC_BIAS_ON: |
| 486 | /* vref/mid, osc on, dac unmute */ |
Eric Bénard | 3d5a451 | 2010-06-19 19:33:39 +0200 | [diff] [blame] | 487 | reg &= ~(TLV320AIC23_DEVICE_PWR_OFF | TLV320AIC23_OSC_OFF | \ |
| 488 | TLV320AIC23_DAC_OFF); |
Kuninori Morimoto | ff06ac2 | 2018-01-29 04:12:48 +0000 | [diff] [blame] | 489 | snd_soc_component_write(component, TLV320AIC23_PWR, reg); |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 490 | break; |
| 491 | case SND_SOC_BIAS_PREPARE: |
| 492 | break; |
| 493 | case SND_SOC_BIAS_STANDBY: |
| 494 | /* everything off except vref/vmid, */ |
Kuninori Morimoto | ff06ac2 | 2018-01-29 04:12:48 +0000 | [diff] [blame] | 495 | snd_soc_component_write(component, TLV320AIC23_PWR, |
Axel Lin | f9dfbf9 | 2011-10-13 15:06:43 +0800 | [diff] [blame] | 496 | reg | TLV320AIC23_CLK_OFF); |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 497 | break; |
| 498 | case SND_SOC_BIAS_OFF: |
| 499 | /* everything off, dac mute, inactive */ |
Kuninori Morimoto | ff06ac2 | 2018-01-29 04:12:48 +0000 | [diff] [blame] | 500 | snd_soc_component_write(component, TLV320AIC23_ACTIVE, 0x0); |
| 501 | snd_soc_component_write(component, TLV320AIC23_PWR, 0x1ff); |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 502 | break; |
| 503 | } |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 504 | return 0; |
| 505 | } |
| 506 | |
| 507 | #define AIC23_RATES SNDRV_PCM_RATE_8000_96000 |
| 508 | #define AIC23_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \ |
| 509 | SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE) |
| 510 | |
Lars-Peter Clausen | 85e7652 | 2011-11-23 11:40:40 +0100 | [diff] [blame] | 511 | static const struct snd_soc_dai_ops tlv320aic23_dai_ops = { |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 512 | .prepare = tlv320aic23_pcm_prepare, |
| 513 | .hw_params = tlv320aic23_hw_params, |
| 514 | .shutdown = tlv320aic23_shutdown, |
Kuninori Morimoto | 960af79 | 2020-07-09 10:56:25 +0900 | [diff] [blame] | 515 | .mute_stream = tlv320aic23_mute, |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 516 | .set_fmt = tlv320aic23_set_dai_fmt, |
| 517 | .set_sysclk = tlv320aic23_set_dai_sysclk, |
Kuninori Morimoto | 960af79 | 2020-07-09 10:56:25 +0900 | [diff] [blame] | 518 | .no_capture_mute = 1, |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 519 | }; |
| 520 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 521 | static struct snd_soc_dai_driver tlv320aic23_dai = { |
| 522 | .name = "tlv320aic23-hifi", |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 523 | .playback = { |
| 524 | .stream_name = "Playback", |
| 525 | .channels_min = 2, |
| 526 | .channels_max = 2, |
| 527 | .rates = AIC23_RATES, |
| 528 | .formats = AIC23_FORMATS,}, |
| 529 | .capture = { |
| 530 | .stream_name = "Capture", |
| 531 | .channels_min = 2, |
| 532 | .channels_max = 2, |
| 533 | .rates = AIC23_RATES, |
| 534 | .formats = AIC23_FORMATS,}, |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 535 | .ops = &tlv320aic23_dai_ops, |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 536 | }; |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 537 | |
Kuninori Morimoto | ff06ac2 | 2018-01-29 04:12:48 +0000 | [diff] [blame] | 538 | static int tlv320aic23_resume(struct snd_soc_component *component) |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 539 | { |
Kuninori Morimoto | ff06ac2 | 2018-01-29 04:12:48 +0000 | [diff] [blame] | 540 | struct aic23 *aic23 = snd_soc_component_get_drvdata(component); |
Mark Brown | 4aa11d6 | 2013-09-24 19:26:08 +0100 | [diff] [blame] | 541 | regcache_mark_dirty(aic23->regmap); |
| 542 | regcache_sync(aic23->regmap); |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 543 | |
| 544 | return 0; |
| 545 | } |
| 546 | |
Kuninori Morimoto | ff06ac2 | 2018-01-29 04:12:48 +0000 | [diff] [blame] | 547 | static int tlv320aic23_component_probe(struct snd_soc_component *component) |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 548 | { |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 549 | /* Reset codec */ |
Kuninori Morimoto | ff06ac2 | 2018-01-29 04:12:48 +0000 | [diff] [blame] | 550 | snd_soc_component_write(component, TLV320AIC23_RESET, 0); |
Axel Lin | f9dfbf9 | 2011-10-13 15:06:43 +0800 | [diff] [blame] | 551 | |
Kuninori Morimoto | ff06ac2 | 2018-01-29 04:12:48 +0000 | [diff] [blame] | 552 | snd_soc_component_write(component, TLV320AIC23_DIGT, TLV320AIC23_DEEMP_44K); |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 553 | |
| 554 | /* Unmute input */ |
Kuninori Morimoto | ff06ac2 | 2018-01-29 04:12:48 +0000 | [diff] [blame] | 555 | snd_soc_component_update_bits(component, TLV320AIC23_LINVOL, |
Axel Lin | f9dfbf9 | 2011-10-13 15:06:43 +0800 | [diff] [blame] | 556 | TLV320AIC23_LIM_MUTED, TLV320AIC23_LRS_ENABLED); |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 557 | |
Kuninori Morimoto | ff06ac2 | 2018-01-29 04:12:48 +0000 | [diff] [blame] | 558 | snd_soc_component_update_bits(component, TLV320AIC23_RINVOL, |
Axel Lin | f9dfbf9 | 2011-10-13 15:06:43 +0800 | [diff] [blame] | 559 | TLV320AIC23_LIM_MUTED, TLV320AIC23_LRS_ENABLED); |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 560 | |
Kuninori Morimoto | ff06ac2 | 2018-01-29 04:12:48 +0000 | [diff] [blame] | 561 | snd_soc_component_update_bits(component, TLV320AIC23_ANLG, |
Axel Lin | f9dfbf9 | 2011-10-13 15:06:43 +0800 | [diff] [blame] | 562 | TLV320AIC23_BYPASS_ON | TLV320AIC23_MICM_MUTED, |
| 563 | 0); |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 564 | |
| 565 | /* Default output volume */ |
Kuninori Morimoto | ff06ac2 | 2018-01-29 04:12:48 +0000 | [diff] [blame] | 566 | snd_soc_component_write(component, TLV320AIC23_LCHNVOL, |
Axel Lin | f9dfbf9 | 2011-10-13 15:06:43 +0800 | [diff] [blame] | 567 | TLV320AIC23_DEFAULT_OUT_VOL & TLV320AIC23_OUT_VOL_MASK); |
Kuninori Morimoto | ff06ac2 | 2018-01-29 04:12:48 +0000 | [diff] [blame] | 568 | snd_soc_component_write(component, TLV320AIC23_RCHNVOL, |
Axel Lin | f9dfbf9 | 2011-10-13 15:06:43 +0800 | [diff] [blame] | 569 | TLV320AIC23_DEFAULT_OUT_VOL & TLV320AIC23_OUT_VOL_MASK); |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 570 | |
Kuninori Morimoto | ff06ac2 | 2018-01-29 04:12:48 +0000 | [diff] [blame] | 571 | snd_soc_component_write(component, TLV320AIC23_ACTIVE, 0x1); |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 572 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 573 | return 0; |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 574 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 575 | |
Kuninori Morimoto | ff06ac2 | 2018-01-29 04:12:48 +0000 | [diff] [blame] | 576 | static const struct snd_soc_component_driver soc_component_dev_tlv320aic23 = { |
| 577 | .probe = tlv320aic23_component_probe, |
| 578 | .resume = tlv320aic23_resume, |
| 579 | .set_bias_level = tlv320aic23_set_bias_level, |
| 580 | .controls = tlv320aic23_snd_controls, |
| 581 | .num_controls = ARRAY_SIZE(tlv320aic23_snd_controls), |
| 582 | .dapm_widgets = tlv320aic23_dapm_widgets, |
| 583 | .num_dapm_widgets = ARRAY_SIZE(tlv320aic23_dapm_widgets), |
| 584 | .dapm_routes = tlv320aic23_intercon, |
| 585 | .num_dapm_routes = ARRAY_SIZE(tlv320aic23_intercon), |
| 586 | .suspend_bias_off = 1, |
| 587 | .idle_bias_on = 1, |
| 588 | .use_pmdown_time = 1, |
| 589 | .endianness = 1, |
| 590 | .non_legacy_dai_naming = 1, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 591 | }; |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 592 | |
Max Filippov | b3fc572 | 2014-03-06 14:04:41 +0400 | [diff] [blame] | 593 | int tlv320aic23_probe(struct device *dev, struct regmap *regmap) |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 594 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 595 | struct aic23 *aic23; |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 596 | |
Max Filippov | b3fc572 | 2014-03-06 14:04:41 +0400 | [diff] [blame] | 597 | if (IS_ERR(regmap)) |
| 598 | return PTR_ERR(regmap); |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 599 | |
Max Filippov | b3fc572 | 2014-03-06 14:04:41 +0400 | [diff] [blame] | 600 | aic23 = devm_kzalloc(dev, sizeof(struct aic23), GFP_KERNEL); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 601 | if (aic23 == NULL) |
| 602 | return -ENOMEM; |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 603 | |
Max Filippov | b3fc572 | 2014-03-06 14:04:41 +0400 | [diff] [blame] | 604 | aic23->regmap = regmap; |
Mark Brown | 4aa11d6 | 2013-09-24 19:26:08 +0100 | [diff] [blame] | 605 | |
Max Filippov | b3fc572 | 2014-03-06 14:04:41 +0400 | [diff] [blame] | 606 | dev_set_drvdata(dev, aic23); |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 607 | |
Kuninori Morimoto | ff06ac2 | 2018-01-29 04:12:48 +0000 | [diff] [blame] | 608 | return devm_snd_soc_register_component(dev, |
| 609 | &soc_component_dev_tlv320aic23, |
Max Filippov | b3fc572 | 2014-03-06 14:04:41 +0400 | [diff] [blame] | 610 | &tlv320aic23_dai, 1); |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 611 | } |
Max Filippov | 4042328 | 2014-03-08 13:31:06 +0400 | [diff] [blame] | 612 | EXPORT_SYMBOL(tlv320aic23_probe); |
Mark Brown | 64089b8 | 2008-12-08 19:17:58 +0000 | [diff] [blame] | 613 | |
Arun KS | c1f2719 | 2008-10-02 14:45:49 +0530 | [diff] [blame] | 614 | MODULE_DESCRIPTION("ASoC TLV320AIC23 codec driver"); |
| 615 | MODULE_AUTHOR("Arun KS <arunks@mistralsolutions.com>"); |
| 616 | MODULE_LICENSE("GPL"); |