0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include <linux/module.h>
0012 #include <linux/init.h>
0013 #include <linux/delay.h>
0014 #include <linux/gpio.h>
0015 #include <linux/pm.h>
0016 #include <linux/i2c.h>
0017 #include <linux/regmap.h>
0018 #include <linux/slab.h>
0019 #include <sound/core.h>
0020 #include <sound/pcm.h>
0021 #include <sound/pcm_params.h>
0022 #include <sound/soc.h>
0023 #include <sound/initval.h>
0024 #include <sound/tlv.h>
0025 #include <sound/ak4641.h>
0026
0027
0028 #define AK4641_PM1 0x00
0029 #define AK4641_PM2 0x01
0030 #define AK4641_SIG1 0x02
0031 #define AK4641_SIG2 0x03
0032 #define AK4641_MODE1 0x04
0033 #define AK4641_MODE2 0x05
0034 #define AK4641_DAC 0x06
0035 #define AK4641_MIC 0x07
0036 #define AK4641_TIMER 0x08
0037 #define AK4641_ALC1 0x09
0038 #define AK4641_ALC2 0x0a
0039 #define AK4641_PGA 0x0b
0040 #define AK4641_LATT 0x0c
0041 #define AK4641_RATT 0x0d
0042 #define AK4641_VOL 0x0e
0043 #define AK4641_STATUS 0x0f
0044 #define AK4641_EQLO 0x10
0045 #define AK4641_EQMID 0x11
0046 #define AK4641_EQHI 0x12
0047 #define AK4641_BTIF 0x13
0048
0049
0050 struct ak4641_priv {
0051 struct regmap *regmap;
0052 unsigned int sysclk;
0053 int deemph;
0054 int playback_fs;
0055 };
0056
0057
0058
0059
0060 static const struct reg_default ak4641_reg_defaults[] = {
0061 { 0, 0x00 }, { 1, 0x80 }, { 2, 0x00 }, { 3, 0x80 },
0062 { 4, 0x02 }, { 5, 0x00 }, { 6, 0x11 }, { 7, 0x05 },
0063 { 8, 0x00 }, { 9, 0x00 }, { 10, 0x36 }, { 11, 0x10 },
0064 { 12, 0x00 }, { 13, 0x00 }, { 14, 0x57 }, { 15, 0x00 },
0065 { 16, 0x88 }, { 17, 0x88 }, { 18, 0x08 }, { 19, 0x08 }
0066 };
0067
0068 static const int deemph_settings[] = {44100, 0, 48000, 32000};
0069
0070 static int ak4641_set_deemph(struct snd_soc_component *component)
0071 {
0072 struct ak4641_priv *ak4641 = snd_soc_component_get_drvdata(component);
0073 int i, best = 0;
0074
0075 for (i = 0 ; i < ARRAY_SIZE(deemph_settings); i++) {
0076
0077 if (ak4641->deemph && deemph_settings[i] != 0 &&
0078 abs(deemph_settings[i] - ak4641->playback_fs) <
0079 abs(deemph_settings[best] - ak4641->playback_fs))
0080 best = i;
0081
0082 if (!ak4641->deemph && deemph_settings[i] == 0)
0083 best = i;
0084 }
0085
0086 dev_dbg(component->dev, "Set deemphasis %d\n", best);
0087
0088 return snd_soc_component_update_bits(component, AK4641_DAC, 0x3, best);
0089 }
0090
0091 static int ak4641_put_deemph(struct snd_kcontrol *kcontrol,
0092 struct snd_ctl_elem_value *ucontrol)
0093 {
0094 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
0095 struct ak4641_priv *ak4641 = snd_soc_component_get_drvdata(component);
0096 int deemph = ucontrol->value.integer.value[0];
0097
0098 if (deemph > 1)
0099 return -EINVAL;
0100
0101 ak4641->deemph = deemph;
0102
0103 return ak4641_set_deemph(component);
0104 }
0105
0106 static int ak4641_get_deemph(struct snd_kcontrol *kcontrol,
0107 struct snd_ctl_elem_value *ucontrol)
0108 {
0109 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
0110 struct ak4641_priv *ak4641 = snd_soc_component_get_drvdata(component);
0111
0112 ucontrol->value.integer.value[0] = ak4641->deemph;
0113 return 0;
0114 };
0115
0116 static const char *ak4641_mono_out[] = {"(L + R)/2", "Hi-Z"};
0117 static const char *ak4641_hp_out[] = {"Stereo", "Mono"};
0118 static const char *ak4641_mic_select[] = {"Internal", "External"};
0119 static const char *ak4641_mic_or_dac[] = {"Microphone", "Voice DAC"};
0120
0121
0122 static const DECLARE_TLV_DB_SCALE(mono_gain_tlv, -1700, 2300, 0);
0123 static const DECLARE_TLV_DB_SCALE(mic_boost_tlv, 0, 2000, 0);
0124 static const DECLARE_TLV_DB_SCALE(eq_tlv, -1050, 150, 0);
0125 static const DECLARE_TLV_DB_SCALE(master_tlv, -12750, 50, 0);
0126 static const DECLARE_TLV_DB_SCALE(mic_stereo_sidetone_tlv, -2700, 300, 0);
0127 static const DECLARE_TLV_DB_SCALE(mic_mono_sidetone_tlv, -400, 400, 0);
0128 static const DECLARE_TLV_DB_SCALE(capture_tlv, -800, 50, 0);
0129 static const DECLARE_TLV_DB_SCALE(alc_tlv, -800, 50, 0);
0130 static const DECLARE_TLV_DB_SCALE(aux_in_tlv, -2100, 300, 0);
0131
0132
0133 static SOC_ENUM_SINGLE_DECL(ak4641_mono_out_enum,
0134 AK4641_SIG1, 6, ak4641_mono_out);
0135 static SOC_ENUM_SINGLE_DECL(ak4641_hp_out_enum,
0136 AK4641_MODE2, 2, ak4641_hp_out);
0137 static SOC_ENUM_SINGLE_DECL(ak4641_mic_select_enum,
0138 AK4641_MIC, 1, ak4641_mic_select);
0139 static SOC_ENUM_SINGLE_DECL(ak4641_mic_or_dac_enum,
0140 AK4641_BTIF, 4, ak4641_mic_or_dac);
0141
0142 static const struct snd_kcontrol_new ak4641_snd_controls[] = {
0143 SOC_ENUM("Mono 1 Output", ak4641_mono_out_enum),
0144 SOC_SINGLE_TLV("Mono 1 Gain Volume", AK4641_SIG1, 7, 1, 1,
0145 mono_gain_tlv),
0146 SOC_ENUM("Headphone Output", ak4641_hp_out_enum),
0147 SOC_SINGLE_BOOL_EXT("Playback Deemphasis Switch", 0,
0148 ak4641_get_deemph, ak4641_put_deemph),
0149
0150 SOC_SINGLE_TLV("Mic Boost Volume", AK4641_MIC, 0, 1, 0, mic_boost_tlv),
0151
0152 SOC_SINGLE("ALC Operation Time", AK4641_TIMER, 0, 3, 0),
0153 SOC_SINGLE("ALC Recovery Time", AK4641_TIMER, 2, 3, 0),
0154 SOC_SINGLE("ALC ZC Time", AK4641_TIMER, 4, 3, 0),
0155
0156 SOC_SINGLE("ALC 1 Switch", AK4641_ALC1, 5, 1, 0),
0157
0158 SOC_SINGLE_TLV("ALC Volume", AK4641_ALC2, 0, 71, 0, alc_tlv),
0159 SOC_SINGLE("Left Out Enable Switch", AK4641_SIG2, 1, 1, 0),
0160 SOC_SINGLE("Right Out Enable Switch", AK4641_SIG2, 0, 1, 0),
0161
0162 SOC_SINGLE_TLV("Capture Volume", AK4641_PGA, 0, 71, 0, capture_tlv),
0163
0164 SOC_DOUBLE_R_TLV("Master Playback Volume", AK4641_LATT,
0165 AK4641_RATT, 0, 255, 1, master_tlv),
0166
0167 SOC_SINGLE_TLV("AUX In Volume", AK4641_VOL, 0, 15, 0, aux_in_tlv),
0168
0169 SOC_SINGLE("Equalizer Switch", AK4641_DAC, 2, 1, 0),
0170 SOC_SINGLE_TLV("EQ1 100 Hz Volume", AK4641_EQLO, 0, 15, 1, eq_tlv),
0171 SOC_SINGLE_TLV("EQ2 250 Hz Volume", AK4641_EQLO, 4, 15, 1, eq_tlv),
0172 SOC_SINGLE_TLV("EQ3 1 kHz Volume", AK4641_EQMID, 0, 15, 1, eq_tlv),
0173 SOC_SINGLE_TLV("EQ4 3.5 kHz Volume", AK4641_EQMID, 4, 15, 1, eq_tlv),
0174 SOC_SINGLE_TLV("EQ5 10 kHz Volume", AK4641_EQHI, 0, 15, 1, eq_tlv),
0175 };
0176
0177
0178 static const struct snd_kcontrol_new ak4641_mono1_mixer_controls[] = {
0179 SOC_DAPM_SINGLE_TLV("Mic Mono Sidetone Volume", AK4641_VOL, 7, 1, 0,
0180 mic_mono_sidetone_tlv),
0181 SOC_DAPM_SINGLE("Mic Mono Sidetone Switch", AK4641_SIG1, 4, 1, 0),
0182 SOC_DAPM_SINGLE("Mono Playback Switch", AK4641_SIG1, 5, 1, 0),
0183 };
0184
0185
0186 static const struct snd_kcontrol_new ak4641_stereo_mixer_controls[] = {
0187 SOC_DAPM_SINGLE_TLV("Mic Sidetone Volume", AK4641_VOL, 4, 7, 0,
0188 mic_stereo_sidetone_tlv),
0189 SOC_DAPM_SINGLE("Mic Sidetone Switch", AK4641_SIG2, 4, 1, 0),
0190 SOC_DAPM_SINGLE("Playback Switch", AK4641_SIG2, 7, 1, 0),
0191 SOC_DAPM_SINGLE("Aux Bypass Switch", AK4641_SIG2, 5, 1, 0),
0192 };
0193
0194
0195 static const struct snd_kcontrol_new ak4641_input_mixer_controls[] = {
0196 SOC_DAPM_SINGLE("Mic Capture Switch", AK4641_MIC, 2, 1, 0),
0197 SOC_DAPM_SINGLE("Aux Capture Switch", AK4641_MIC, 5, 1, 0),
0198 };
0199
0200
0201 static const struct snd_kcontrol_new ak4641_mic_mux_control =
0202 SOC_DAPM_ENUM("Mic Select", ak4641_mic_select_enum);
0203
0204
0205 static const struct snd_kcontrol_new ak4641_input_mux_control =
0206 SOC_DAPM_ENUM("Input Select", ak4641_mic_or_dac_enum);
0207
0208
0209 static const struct snd_kcontrol_new ak4641_mono2_control =
0210 SOC_DAPM_SINGLE("Switch", AK4641_SIG1, 0, 1, 0);
0211
0212
0213 static const struct snd_soc_dapm_widget ak4641_dapm_widgets[] = {
0214 SND_SOC_DAPM_MIXER("Stereo Mixer", SND_SOC_NOPM, 0, 0,
0215 &ak4641_stereo_mixer_controls[0],
0216 ARRAY_SIZE(ak4641_stereo_mixer_controls)),
0217 SND_SOC_DAPM_MIXER("Mono1 Mixer", SND_SOC_NOPM, 0, 0,
0218 &ak4641_mono1_mixer_controls[0],
0219 ARRAY_SIZE(ak4641_mono1_mixer_controls)),
0220 SND_SOC_DAPM_MIXER("Input Mixer", SND_SOC_NOPM, 0, 0,
0221 &ak4641_input_mixer_controls[0],
0222 ARRAY_SIZE(ak4641_input_mixer_controls)),
0223 SND_SOC_DAPM_MUX("Mic Mux", SND_SOC_NOPM, 0, 0,
0224 &ak4641_mic_mux_control),
0225 SND_SOC_DAPM_MUX("Input Mux", SND_SOC_NOPM, 0, 0,
0226 &ak4641_input_mux_control),
0227 SND_SOC_DAPM_SWITCH("Mono 2 Enable", SND_SOC_NOPM, 0, 0,
0228 &ak4641_mono2_control),
0229
0230 SND_SOC_DAPM_OUTPUT("LOUT"),
0231 SND_SOC_DAPM_OUTPUT("ROUT"),
0232 SND_SOC_DAPM_OUTPUT("MOUT1"),
0233 SND_SOC_DAPM_OUTPUT("MOUT2"),
0234 SND_SOC_DAPM_OUTPUT("MICOUT"),
0235
0236 SND_SOC_DAPM_ADC("ADC", "HiFi Capture", AK4641_PM1, 0, 0),
0237 SND_SOC_DAPM_PGA("Mic", AK4641_PM1, 1, 0, NULL, 0),
0238 SND_SOC_DAPM_PGA("AUX In", AK4641_PM1, 2, 0, NULL, 0),
0239 SND_SOC_DAPM_PGA("Mono Out", AK4641_PM1, 3, 0, NULL, 0),
0240 SND_SOC_DAPM_PGA("Line Out", AK4641_PM1, 4, 0, NULL, 0),
0241
0242 SND_SOC_DAPM_DAC("DAC", "HiFi Playback", AK4641_PM2, 0, 0),
0243 SND_SOC_DAPM_PGA("Mono Out 2", AK4641_PM2, 3, 0, NULL, 0),
0244
0245 SND_SOC_DAPM_ADC("Voice ADC", "Voice Capture", AK4641_BTIF, 0, 0),
0246 SND_SOC_DAPM_DAC("Voice DAC", "Voice Playback", AK4641_BTIF, 1, 0),
0247
0248 SND_SOC_DAPM_MICBIAS("Mic Int Bias", AK4641_MIC, 3, 0),
0249 SND_SOC_DAPM_MICBIAS("Mic Ext Bias", AK4641_MIC, 4, 0),
0250
0251 SND_SOC_DAPM_INPUT("MICIN"),
0252 SND_SOC_DAPM_INPUT("MICEXT"),
0253 SND_SOC_DAPM_INPUT("AUX"),
0254 SND_SOC_DAPM_INPUT("AIN"),
0255 };
0256
0257 static const struct snd_soc_dapm_route ak4641_audio_map[] = {
0258
0259 {"Stereo Mixer", "Playback Switch", "DAC"},
0260 {"Stereo Mixer", "Mic Sidetone Switch", "Input Mux"},
0261 {"Stereo Mixer", "Aux Bypass Switch", "AUX In"},
0262
0263
0264 {"Mono1 Mixer", "Mic Mono Sidetone Switch", "Input Mux"},
0265 {"Mono1 Mixer", "Mono Playback Switch", "DAC"},
0266
0267
0268 {"Mic", NULL, "AIN"},
0269 {"Mic Mux", "Internal", "Mic Int Bias"},
0270 {"Mic Mux", "External", "Mic Ext Bias"},
0271 {"Mic Int Bias", NULL, "MICIN"},
0272 {"Mic Ext Bias", NULL, "MICEXT"},
0273 {"MICOUT", NULL, "Mic Mux"},
0274
0275
0276 {"Input Mux", "Microphone", "Mic"},
0277 {"Input Mux", "Voice DAC", "Voice DAC"},
0278
0279
0280 {"LOUT", NULL, "Line Out"},
0281 {"ROUT", NULL, "Line Out"},
0282 {"Line Out", NULL, "Stereo Mixer"},
0283
0284
0285 {"MOUT1", NULL, "Mono Out"},
0286 {"Mono Out", NULL, "Mono1 Mixer"},
0287
0288
0289 {"MOUT2", NULL, "Mono 2 Enable"},
0290 {"Mono 2 Enable", "Switch", "Mono Out 2"},
0291 {"Mono Out 2", NULL, "Stereo Mixer"},
0292
0293 {"Voice ADC", NULL, "Mono 2 Enable"},
0294
0295
0296 {"AUX In", NULL, "AUX"},
0297
0298
0299 {"ADC", NULL, "Input Mixer"},
0300 {"Input Mixer", "Mic Capture Switch", "Mic"},
0301 {"Input Mixer", "Aux Capture Switch", "AUX In"},
0302 };
0303
0304 static int ak4641_set_dai_sysclk(struct snd_soc_dai *codec_dai,
0305 int clk_id, unsigned int freq, int dir)
0306 {
0307 struct snd_soc_component *component = codec_dai->component;
0308 struct ak4641_priv *ak4641 = snd_soc_component_get_drvdata(component);
0309
0310 ak4641->sysclk = freq;
0311 return 0;
0312 }
0313
0314 static int ak4641_i2s_hw_params(struct snd_pcm_substream *substream,
0315 struct snd_pcm_hw_params *params,
0316 struct snd_soc_dai *dai)
0317 {
0318 struct snd_soc_component *component = dai->component;
0319 struct ak4641_priv *ak4641 = snd_soc_component_get_drvdata(component);
0320 int rate = params_rate(params), fs = 256;
0321 u8 mode2;
0322
0323 if (rate)
0324 fs = ak4641->sysclk / rate;
0325 else
0326 return -EINVAL;
0327
0328
0329 switch (fs) {
0330 case 1024:
0331 mode2 = (0x2 << 5);
0332 break;
0333 case 512:
0334 mode2 = (0x1 << 5);
0335 break;
0336 case 256:
0337 mode2 = (0x0 << 5);
0338 break;
0339 default:
0340 dev_err(component->dev, "Error: unsupported fs=%d\n", fs);
0341 return -EINVAL;
0342 }
0343
0344 snd_soc_component_update_bits(component, AK4641_MODE2, (0x3 << 5), mode2);
0345
0346
0347 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
0348 ak4641->playback_fs = rate;
0349 ak4641_set_deemph(component);
0350 }
0351
0352 return 0;
0353 }
0354
0355 static int ak4641_pcm_set_dai_fmt(struct snd_soc_dai *codec_dai,
0356 unsigned int fmt)
0357 {
0358 struct snd_soc_component *component = codec_dai->component;
0359 u8 btif;
0360 int ret;
0361
0362
0363 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
0364 case SND_SOC_DAIFMT_I2S:
0365 btif = (0x3 << 5);
0366 break;
0367 case SND_SOC_DAIFMT_LEFT_J:
0368 btif = (0x2 << 5);
0369 break;
0370 case SND_SOC_DAIFMT_DSP_A:
0371 btif = (0x0 << 5);
0372 break;
0373 case SND_SOC_DAIFMT_DSP_B:
0374 btif = (0x1 << 5);
0375 break;
0376 default:
0377 return -EINVAL;
0378 }
0379
0380 ret = snd_soc_component_update_bits(component, AK4641_BTIF, (0x3 << 5), btif);
0381 if (ret < 0)
0382 return ret;
0383
0384 return 0;
0385 }
0386
0387 static int ak4641_i2s_set_dai_fmt(struct snd_soc_dai *codec_dai,
0388 unsigned int fmt)
0389 {
0390 struct snd_soc_component *component = codec_dai->component;
0391 u8 mode1 = 0;
0392
0393
0394 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
0395 case SND_SOC_DAIFMT_I2S:
0396 mode1 = 0x02;
0397 break;
0398 case SND_SOC_DAIFMT_LEFT_J:
0399 mode1 = 0x01;
0400 break;
0401 default:
0402 return -EINVAL;
0403 }
0404
0405 return snd_soc_component_write(component, AK4641_MODE1, mode1);
0406 }
0407
0408 static int ak4641_mute(struct snd_soc_dai *dai, int mute, int direction)
0409 {
0410 struct snd_soc_component *component = dai->component;
0411
0412 return snd_soc_component_update_bits(component, AK4641_DAC, 0x20, mute ? 0x20 : 0);
0413 }
0414
0415 static int ak4641_set_bias_level(struct snd_soc_component *component,
0416 enum snd_soc_bias_level level)
0417 {
0418 struct ak4641_priv *ak4641 = snd_soc_component_get_drvdata(component);
0419 struct ak4641_platform_data *pdata = component->dev->platform_data;
0420 int ret;
0421
0422 switch (level) {
0423 case SND_SOC_BIAS_ON:
0424
0425 snd_soc_component_update_bits(component, AK4641_DAC, 0x20, 0);
0426 break;
0427 case SND_SOC_BIAS_PREPARE:
0428
0429 snd_soc_component_update_bits(component, AK4641_DAC, 0x20, 0x20);
0430 break;
0431 case SND_SOC_BIAS_STANDBY:
0432 if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_OFF) {
0433 if (pdata && gpio_is_valid(pdata->gpio_power))
0434 gpio_set_value(pdata->gpio_power, 1);
0435 mdelay(1);
0436 if (pdata && gpio_is_valid(pdata->gpio_npdn))
0437 gpio_set_value(pdata->gpio_npdn, 1);
0438 mdelay(1);
0439
0440 ret = regcache_sync(ak4641->regmap);
0441 if (ret) {
0442 dev_err(component->dev,
0443 "Failed to sync cache: %d\n", ret);
0444 return ret;
0445 }
0446 }
0447 snd_soc_component_update_bits(component, AK4641_PM1, 0x80, 0x80);
0448 snd_soc_component_update_bits(component, AK4641_PM2, 0x80, 0);
0449 break;
0450 case SND_SOC_BIAS_OFF:
0451 snd_soc_component_update_bits(component, AK4641_PM1, 0x80, 0);
0452 if (pdata && gpio_is_valid(pdata->gpio_npdn))
0453 gpio_set_value(pdata->gpio_npdn, 0);
0454 if (pdata && gpio_is_valid(pdata->gpio_power))
0455 gpio_set_value(pdata->gpio_power, 0);
0456 regcache_mark_dirty(ak4641->regmap);
0457 break;
0458 }
0459 return 0;
0460 }
0461
0462 #define AK4641_RATES (SNDRV_PCM_RATE_8000_48000)
0463 #define AK4641_RATES_BT (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
0464 SNDRV_PCM_RATE_16000)
0465 #define AK4641_FORMATS (SNDRV_PCM_FMTBIT_S16_LE)
0466
0467 static const struct snd_soc_dai_ops ak4641_i2s_dai_ops = {
0468 .hw_params = ak4641_i2s_hw_params,
0469 .set_fmt = ak4641_i2s_set_dai_fmt,
0470 .mute_stream = ak4641_mute,
0471 .set_sysclk = ak4641_set_dai_sysclk,
0472 .no_capture_mute = 1,
0473 };
0474
0475 static const struct snd_soc_dai_ops ak4641_pcm_dai_ops = {
0476 .hw_params = NULL,
0477 .set_fmt = ak4641_pcm_set_dai_fmt,
0478 .mute_stream = ak4641_mute,
0479 .set_sysclk = ak4641_set_dai_sysclk,
0480 .no_capture_mute = 1,
0481 };
0482
0483 static struct snd_soc_dai_driver ak4641_dai[] = {
0484 {
0485 .name = "ak4641-hifi",
0486 .id = 1,
0487 .playback = {
0488 .stream_name = "HiFi Playback",
0489 .channels_min = 1,
0490 .channels_max = 2,
0491 .rates = AK4641_RATES,
0492 .formats = AK4641_FORMATS,
0493 },
0494 .capture = {
0495 .stream_name = "HiFi Capture",
0496 .channels_min = 1,
0497 .channels_max = 2,
0498 .rates = AK4641_RATES,
0499 .formats = AK4641_FORMATS,
0500 },
0501 .ops = &ak4641_i2s_dai_ops,
0502 .symmetric_rate = 1,
0503 },
0504 {
0505 .name = "ak4641-voice",
0506 .id = 1,
0507 .playback = {
0508 .stream_name = "Voice Playback",
0509 .channels_min = 1,
0510 .channels_max = 1,
0511 .rates = AK4641_RATES_BT,
0512 .formats = AK4641_FORMATS,
0513 },
0514 .capture = {
0515 .stream_name = "Voice Capture",
0516 .channels_min = 1,
0517 .channels_max = 1,
0518 .rates = AK4641_RATES_BT,
0519 .formats = AK4641_FORMATS,
0520 },
0521 .ops = &ak4641_pcm_dai_ops,
0522 .symmetric_rate = 1,
0523 },
0524 };
0525
0526 static const struct snd_soc_component_driver soc_component_dev_ak4641 = {
0527 .controls = ak4641_snd_controls,
0528 .num_controls = ARRAY_SIZE(ak4641_snd_controls),
0529 .dapm_widgets = ak4641_dapm_widgets,
0530 .num_dapm_widgets = ARRAY_SIZE(ak4641_dapm_widgets),
0531 .dapm_routes = ak4641_audio_map,
0532 .num_dapm_routes = ARRAY_SIZE(ak4641_audio_map),
0533 .set_bias_level = ak4641_set_bias_level,
0534 .suspend_bias_off = 1,
0535 .idle_bias_on = 1,
0536 .use_pmdown_time = 1,
0537 .endianness = 1,
0538 };
0539
0540 static const struct regmap_config ak4641_regmap = {
0541 .reg_bits = 8,
0542 .val_bits = 8,
0543
0544 .max_register = AK4641_BTIF,
0545 .reg_defaults = ak4641_reg_defaults,
0546 .num_reg_defaults = ARRAY_SIZE(ak4641_reg_defaults),
0547 .cache_type = REGCACHE_RBTREE,
0548 };
0549
0550 static int ak4641_i2c_probe(struct i2c_client *i2c)
0551 {
0552 struct ak4641_platform_data *pdata = i2c->dev.platform_data;
0553 struct ak4641_priv *ak4641;
0554 int ret;
0555
0556 ak4641 = devm_kzalloc(&i2c->dev, sizeof(struct ak4641_priv),
0557 GFP_KERNEL);
0558 if (!ak4641)
0559 return -ENOMEM;
0560
0561 ak4641->regmap = devm_regmap_init_i2c(i2c, &ak4641_regmap);
0562 if (IS_ERR(ak4641->regmap))
0563 return PTR_ERR(ak4641->regmap);
0564
0565 if (pdata) {
0566 if (gpio_is_valid(pdata->gpio_power)) {
0567 ret = gpio_request_one(pdata->gpio_power,
0568 GPIOF_OUT_INIT_LOW, "ak4641 power");
0569 if (ret)
0570 goto err_out;
0571 }
0572 if (gpio_is_valid(pdata->gpio_npdn)) {
0573 ret = gpio_request_one(pdata->gpio_npdn,
0574 GPIOF_OUT_INIT_LOW, "ak4641 npdn");
0575 if (ret)
0576 goto err_gpio;
0577
0578 udelay(1);
0579 gpio_set_value(pdata->gpio_npdn, 1);
0580 }
0581 }
0582
0583 i2c_set_clientdata(i2c, ak4641);
0584
0585 ret = devm_snd_soc_register_component(&i2c->dev,
0586 &soc_component_dev_ak4641,
0587 ak4641_dai, ARRAY_SIZE(ak4641_dai));
0588 if (ret != 0)
0589 goto err_gpio2;
0590
0591 return 0;
0592
0593 err_gpio2:
0594 if (pdata) {
0595 if (gpio_is_valid(pdata->gpio_power))
0596 gpio_set_value(pdata->gpio_power, 0);
0597 if (gpio_is_valid(pdata->gpio_npdn))
0598 gpio_free(pdata->gpio_npdn);
0599 }
0600 err_gpio:
0601 if (pdata && gpio_is_valid(pdata->gpio_power))
0602 gpio_free(pdata->gpio_power);
0603 err_out:
0604 return ret;
0605 }
0606
0607 static int ak4641_i2c_remove(struct i2c_client *i2c)
0608 {
0609 struct ak4641_platform_data *pdata = i2c->dev.platform_data;
0610
0611 if (pdata) {
0612 if (gpio_is_valid(pdata->gpio_power)) {
0613 gpio_set_value(pdata->gpio_power, 0);
0614 gpio_free(pdata->gpio_power);
0615 }
0616 if (gpio_is_valid(pdata->gpio_npdn))
0617 gpio_free(pdata->gpio_npdn);
0618 }
0619
0620 return 0;
0621 }
0622
0623 static const struct i2c_device_id ak4641_i2c_id[] = {
0624 { "ak4641", 0 },
0625 { }
0626 };
0627 MODULE_DEVICE_TABLE(i2c, ak4641_i2c_id);
0628
0629 static struct i2c_driver ak4641_i2c_driver = {
0630 .driver = {
0631 .name = "ak4641",
0632 },
0633 .probe_new = ak4641_i2c_probe,
0634 .remove = ak4641_i2c_remove,
0635 .id_table = ak4641_i2c_id,
0636 };
0637
0638 module_i2c_driver(ak4641_i2c_driver);
0639
0640 MODULE_DESCRIPTION("SoC AK4641 driver");
0641 MODULE_AUTHOR("Harald Welte <laforge@gnufiish.org>");
0642 MODULE_LICENSE("GPL");