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