hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/sound/soc/codecs/rk817_codec.c
....@@ -67,7 +67,10 @@
6767 struct regmap *regmap;
6868 struct rk808 *rk817;
6969 struct clk *mclk;
70
+ struct mutex clk_lock;
7071
72
+ unsigned int clk_capture;
73
+ unsigned int clk_playback;
7174 unsigned int stereo_sysclk;
7275 unsigned int rate;
7376
....@@ -79,6 +82,7 @@
7982 bool pdmdata_out_enable;
8083 bool use_ext_amplifier;
8184 bool adc_for_loopback;
85
+ bool resume_path;
8286
8387 bool out_l2spk_r2hp;
8488 long int playback_path;
....@@ -282,10 +286,10 @@
282286 {RK817_CODEC_AREF_RTCFG1, 0x40},
283287 {RK817_CODEC_DDAC_POPD_DACST, 0x02},
284288 /* APLL */
285
- {RK817_CODEC_APLL_CFG0, 0x04},
289
+ /* {RK817_CODEC_APLL_CFG0, 0x04}, */
286290 {RK817_CODEC_APLL_CFG1, 0x58},
287291 {RK817_CODEC_APLL_CFG2, 0x2d},
288
- {RK817_CODEC_APLL_CFG4, 0xa5},
292
+ /* {RK817_CODEC_APLL_CFG4, 0xa5}, */
289293 {RK817_CODEC_APLL_CFG5, 0x00},
290294
291295 {RK817_CODEC_DI2S_RXCMD_TSD, 0x00},
....@@ -320,10 +324,10 @@
320324 {RK817_CODEC_AREF_RTCFG1, 0x40},
321325 {RK817_CODEC_DADC_SR_ACL0, 0x02},
322326 /* {RK817_CODEC_DTOP_DIGEN_CLKE, 0xff}, */
323
- {RK817_CODEC_APLL_CFG0, 0x04},
327
+ /* {RK817_CODEC_APLL_CFG0, 0x04}, */
324328 {RK817_CODEC_APLL_CFG1, 0x58},
325329 {RK817_CODEC_APLL_CFG2, 0x2d},
326
- {RK817_CODEC_APLL_CFG4, 0xa5},
330
+ /* {RK817_CODEC_APLL_CFG4, 0xa5}, */
327331 {RK817_CODEC_APLL_CFG5, 0x00},
328332
329333 /*{RK817_CODEC_DI2S_RXCMD_TSD, 0x00},*/
....@@ -374,12 +378,16 @@
374378 playback_power_up_list[i].value);
375379 }
376380
377
- /* Re-configure APLL CFG0/4 if (chip_ver <= 0x4) */
381
+ /* configure APLL CFG0/4 */
378382 if (rk817->chip_ver <= 0x4) {
379383 DBG("%s (%d): SMIC TudorAG and previous versions\n",
380384 __func__, __LINE__);
381385 snd_soc_component_write(component, RK817_CODEC_APLL_CFG0, 0x0c);
382386 snd_soc_component_write(component, RK817_CODEC_APLL_CFG4, 0x95);
387
+ } else {
388
+ DBG("%s: SMIC TudorAG version later\n", __func__);
389
+ snd_soc_component_write(component, RK817_CODEC_APLL_CFG0, 0x04);
390
+ snd_soc_component_write(component, RK817_CODEC_APLL_CFG4, 0xa5);
383391 }
384392
385393 snd_soc_component_update_bits(component, RK817_CODEC_DTOP_DIGEN_CLKE,
....@@ -401,16 +409,20 @@
401409 capture_power_up_list[i].value);
402410 }
403411
404
- /* Re-configure APLL CFG0/4 if (chip_ver <= 0x4) */
412
+ /* configure APLL CFG0/4 */
405413 if (rk817->chip_ver <= 0x4) {
406414 DBG("%s (%d): SMIC TudorAG and previous versions\n",
407415 __func__, __LINE__);
408416 snd_soc_component_write(component, RK817_CODEC_APLL_CFG0, 0x0c);
409417 snd_soc_component_write(component, RK817_CODEC_APLL_CFG4, 0x95);
418
+ } else {
419
+ DBG("%s: SMIC TudorAG version later\n", __func__);
420
+ snd_soc_component_write(component, RK817_CODEC_APLL_CFG0, 0x04);
421
+ snd_soc_component_write(component, RK817_CODEC_APLL_CFG4, 0xa5);
410422 }
411423
412424 snd_soc_component_update_bits(component, RK817_CODEC_DTOP_DIGEN_CLKE,
413
- ADC_DIG_CLK_MASK, DAC_DIG_CLK_DIS);
425
+ ADC_DIG_CLK_MASK, ADC_DIG_CLK_DIS);
414426 usleep_range(2000, 2500);
415427 snd_soc_component_update_bits(component, RK817_CODEC_DTOP_DIGEN_CLKE,
416428 ADC_DIG_CLK_MASK, ADC_DIG_CLK_EN);
....@@ -506,10 +518,7 @@
506518 static const char * const rk817_capture_path_mode[] = {
507519 "MIC OFF", "Main Mic", "Hands Free Mic", "BT Sco Mic"};
508520
509
-static const char * const rk817_call_path_mode[] = {
510
- "OFF", "RCV", "SPK", "HP", "HP_NO_MIC", "BT"}; /* 0-5 */
511
-
512
-static const char * const rk817_modem_input_mode[] = {"OFF", "ON"};
521
+static const char * const rk817_binary_mode[] = {"OFF", "ON"};
513522
514523 static SOC_ENUM_SINGLE_DECL(rk817_playback_path_type,
515524 0, 0, rk817_playback_path_mode);
....@@ -517,11 +526,8 @@
517526 static SOC_ENUM_SINGLE_DECL(rk817_capture_path_type,
518527 0, 0, rk817_capture_path_mode);
519528
520
-static SOC_ENUM_SINGLE_DECL(rk817_call_path_type,
521
- 0, 0, rk817_call_path_mode);
522
-
523
-static SOC_ENUM_SINGLE_DECL(rk817_modem_input_type,
524
- 0, 0, rk817_modem_input_mode);
529
+static SOC_ENUM_SINGLE_DECL(rk817_resume_path_type,
530
+ 0, 0, rk817_binary_mode);
525531
526532 static int rk817_playback_path_config(struct snd_soc_component *component,
527533 long pre_path, long target_path)
....@@ -533,10 +539,19 @@
533539 DBG("%s : set playback_path %ld, pre_path %ld\n",
534540 __func__, rk817->playback_path, pre_path);
535541
536
- if (rk817->playback_path != OFF)
537
- clk_prepare_enable(rk817->mclk);
538
- else
539
- clk_disable_unprepare(rk817->mclk);
542
+ mutex_lock(&rk817->clk_lock);
543
+ if (rk817->playback_path != OFF) {
544
+ if (rk817->clk_playback == 0) {
545
+ clk_prepare_enable(rk817->mclk);
546
+ rk817->clk_playback++;
547
+ }
548
+ } else {
549
+ if (rk817->clk_playback > 0) {
550
+ clk_disable_unprepare(rk817->mclk);
551
+ rk817->clk_playback--;
552
+ }
553
+ }
554
+ mutex_unlock(&rk817->clk_lock);
540555
541556 switch (rk817->playback_path) {
542557 case OFF:
....@@ -720,10 +735,19 @@
720735 DBG("%s : set capture_path %ld, pre_path %ld\n", __func__,
721736 rk817->capture_path, pre_path);
722737
723
- if (rk817->capture_path != MIC_OFF)
724
- clk_prepare_enable(rk817->mclk);
725
- else
726
- clk_disable_unprepare(rk817->mclk);
738
+ mutex_lock(&rk817->clk_lock);
739
+ if (rk817->capture_path != MIC_OFF) {
740
+ if (rk817->clk_capture == 0) {
741
+ clk_prepare_enable(rk817->mclk);
742
+ rk817->clk_capture++;
743
+ }
744
+ } else {
745
+ if (rk817->clk_capture > 0) {
746
+ clk_disable_unprepare(rk817->mclk);
747
+ rk817->clk_capture--;
748
+ }
749
+ }
750
+ mutex_unlock(&rk817->clk_lock);
727751
728752 switch (rk817->capture_path) {
729753 case MIC_OFF:
....@@ -842,12 +866,39 @@
842866 ucontrol->value.integer.value[0]);
843867 }
844868
869
+static int rk817_resume_path_get(struct snd_kcontrol *kcontrol,
870
+ struct snd_ctl_elem_value *ucontrol)
871
+{
872
+ struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
873
+ struct rk817_codec_priv *rk817 = snd_soc_component_get_drvdata(component);
874
+
875
+ DBG("%s : resume_path %ld\n", __func__, rk817->resume_path);
876
+
877
+ ucontrol->value.integer.value[0] = rk817->resume_path;
878
+
879
+ return 0;
880
+}
881
+
882
+static int rk817_resume_path_put(struct snd_kcontrol *kcontrol,
883
+ struct snd_ctl_elem_value *ucontrol)
884
+{
885
+ struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
886
+ struct rk817_codec_priv *rk817 = snd_soc_component_get_drvdata(component);
887
+
888
+ rk817->resume_path = ucontrol->value.integer.value[0];
889
+
890
+ return 0;
891
+}
892
+
845893 static struct snd_kcontrol_new rk817_snd_path_controls[] = {
846894 SOC_ENUM_EXT("Playback Path", rk817_playback_path_type,
847895 rk817_playback_path_get, rk817_playback_path_put),
848896
849897 SOC_ENUM_EXT("Capture MIC Path", rk817_capture_path_type,
850898 rk817_capture_path_get, rk817_capture_path_put),
899
+
900
+ SOC_ENUM_EXT("Resume Path", rk817_resume_path_type,
901
+ rk817_resume_path_get, rk817_resume_path_put),
851902 };
852903
853904 static int rk817_set_dai_sysclk(struct snd_soc_dai *codec_dai,
....@@ -892,8 +943,7 @@
892943 struct snd_pcm_hw_params *params,
893944 struct snd_soc_dai *dai)
894945 {
895
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
896
- struct snd_soc_component *component = rtd->codec_dai->component;
946
+ struct snd_soc_component *component = dai->component;
897947 struct rk817_codec_priv *rk817 = snd_soc_component_get_drvdata(component);
898948 unsigned int rate = params_rate(params);
899949 unsigned char apll_cfg3_val;
....@@ -946,14 +996,22 @@
946996 * is before playback/capture_path_put, therefore, we need to configure
947997 * APLL_CFG3/DTOP_DIGEN_CLKE/DDAC_SR_LMT0 for different sample rates.
948998 */
949
- snd_soc_component_write(component, RK817_CODEC_APLL_CFG3, apll_cfg3_val);
950
- /* The 0x00 contains ADC_DIG_CLK_DIS and DAC_DIG_CLK_DIS */
951
- snd_soc_component_update_bits(component, RK817_CODEC_DTOP_DIGEN_CLKE,
952
- dtop_digen_clke, 0x00);
953
- snd_soc_component_update_bits(component, RK817_CODEC_DDAC_SR_LMT0,
954
- DACSRT_MASK, dtop_digen_sr_lmt0);
955
- snd_soc_component_update_bits(component, RK817_CODEC_DTOP_DIGEN_CLKE,
956
- dtop_digen_clke, dtop_digen_clke);
999
+ if (!((substream->stream == SNDRV_PCM_STREAM_CAPTURE) && rk817->pdmdata_out_enable)) {
1000
+ snd_soc_component_write(component, RK817_CODEC_APLL_CFG3, apll_cfg3_val);
1001
+ /* The 0x00 contains ADC_DIG_CLK_DIS and DAC_DIG_CLK_DIS */
1002
+ snd_soc_component_update_bits(component, RK817_CODEC_DTOP_DIGEN_CLKE,
1003
+ dtop_digen_clke, 0x00);
1004
+ snd_soc_component_update_bits(component, RK817_CODEC_DDAC_SR_LMT0,
1005
+ DACSRT_MASK, dtop_digen_sr_lmt0);
1006
+ snd_soc_component_update_bits(component, RK817_CODEC_DTOP_DIGEN_CLKE,
1007
+ dtop_digen_clke, dtop_digen_clke);
1008
+ snd_soc_component_update_bits(component, RK817_CODEC_APLL_CFG5,
1009
+ PLL_PW_DOWN, PLL_PW_DOWN);
1010
+ usleep_range(50, 60);
1011
+ snd_soc_component_update_bits(component, RK817_CODEC_APLL_CFG5,
1012
+ PLL_PW_DOWN, PLL_PW_UP);
1013
+ usleep_range(500, 600);
1014
+ }
9571015
9581016 switch (params_format(params)) {
9591017 case SNDRV_PCM_FORMAT_S16_LE:
....@@ -976,7 +1034,7 @@
9761034 return 0;
9771035 }
9781036
979
-static int rk817_digital_mute(struct snd_soc_dai *dai, int mute)
1037
+static int rk817_digital_mute_dac(struct snd_soc_dai *dai, int mute, int stream)
9801038 {
9811039 struct snd_soc_component *component = dai->component;
9821040 struct rk817_codec_priv *rk817 = snd_soc_component_get_drvdata(component);
....@@ -998,7 +1056,11 @@
9981056 DAC_DIG_CLK_EN, DAC_DIG_CLK_DIS);
9991057 snd_soc_component_update_bits(component, RK817_CODEC_DTOP_DIGEN_CLKE,
10001058 DAC_DIG_CLK_EN, DAC_DIG_CLK_EN);
1059
+ snd_soc_component_update_bits(component, RK817_CODEC_DTOP_DIGEN_CLKE,
1060
+ I2SRX_EN_MASK, I2SRX_DIS);
10011061 } else {
1062
+ snd_soc_component_update_bits(component, RK817_CODEC_DTOP_DIGEN_CLKE,
1063
+ I2SRX_EN_MASK, I2SRX_EN);
10021064 snd_soc_component_update_bits(component,
10031065 RK817_CODEC_DDAC_MUTE_MIXCTL,
10041066 DACMT_ENABLE, DACMT_DISABLE);
....@@ -1048,6 +1110,28 @@
10481110 return 0;
10491111 }
10501112
1113
+static int rk817_digital_mute_adc(struct snd_soc_dai *dai, int mute, int stream)
1114
+{
1115
+ struct snd_soc_component *component = dai->component;
1116
+
1117
+ if (mute)
1118
+ snd_soc_component_update_bits(component, RK817_CODEC_DTOP_DIGEN_CLKE,
1119
+ I2STX_EN_MASK, I2STX_DIS);
1120
+ else
1121
+ snd_soc_component_update_bits(component, RK817_CODEC_DTOP_DIGEN_CLKE,
1122
+ I2STX_EN_MASK, I2STX_EN);
1123
+
1124
+ return 0;
1125
+}
1126
+
1127
+static int rk817_digital_mute(struct snd_soc_dai *dai, int mute, int stream)
1128
+{
1129
+ if (stream == SNDRV_PCM_STREAM_PLAYBACK)
1130
+ return rk817_digital_mute_dac(dai, mute, stream);
1131
+ else
1132
+ return rk817_digital_mute_adc(dai, mute, stream);
1133
+}
1134
+
10511135 #define RK817_PLAYBACK_RATES (SNDRV_PCM_RATE_8000 |\
10521136 SNDRV_PCM_RATE_16000 | \
10531137 SNDRV_PCM_RATE_32000 | \
....@@ -1090,7 +1174,7 @@
10901174 .hw_params = rk817_hw_params,
10911175 .set_fmt = rk817_set_dai_fmt,
10921176 .set_sysclk = rk817_set_dai_sysclk,
1093
- .digital_mute = rk817_digital_mute,
1177
+ .mute_stream = rk817_digital_mute,
10941178 .shutdown = rk817_codec_shutdown,
10951179 };
10961180
....@@ -1144,6 +1228,15 @@
11441228
11451229 static int rk817_resume(struct snd_soc_component *component)
11461230 {
1231
+ struct rk817_codec_priv *rk817 = snd_soc_component_get_drvdata(component);
1232
+
1233
+ if (rk817->resume_path) {
1234
+ if (rk817->capture_path != MIC_OFF)
1235
+ rk817_capture_path_config(component, OFF, rk817->capture_path);
1236
+ if (rk817->playback_path != OFF)
1237
+ rk817_playback_path_config(component, OFF, rk817->playback_path);
1238
+ }
1239
+
11471240 return 0;
11481241 }
11491242
....@@ -1165,14 +1258,17 @@
11651258 rk817->playback_path = OFF;
11661259 rk817->capture_path = MIC_OFF;
11671260
1168
- chip_name = snd_soc_component_read32(component, RK817_PMIC_CHIP_NAME);
1169
- chip_ver = snd_soc_component_read32(component, RK817_PMIC_CHIP_VER);
1261
+ chip_name = snd_soc_component_read(component, RK817_PMIC_CHIP_NAME);
1262
+ chip_ver = snd_soc_component_read(component, RK817_PMIC_CHIP_VER);
11701263 rk817->chip_ver = (chip_ver & 0x0f);
11711264 dev_info(component->dev, "%s: chip_name:0x%x, chip_ver:0x%x\n", __func__, chip_name, chip_ver);
11721265
1266
+ /* always enable mclk, and will disable mclk in rk817_remove */
11731267 clk_prepare_enable(rk817->mclk);
11741268 rk817_reset(component);
1175
- clk_disable_unprepare(rk817->mclk);
1269
+ mutex_init(&rk817->clk_lock);
1270
+ rk817->clk_capture = 0;
1271
+ rk817->clk_playback = 0;
11761272
11771273 snd_soc_add_component_controls(component, rk817_snd_path_controls,
11781274 ARRAY_SIZE(rk817_snd_path_controls));
....@@ -1193,6 +1289,8 @@
11931289
11941290 rk817_codec_power_down(component, RK817_CODEC_ALL);
11951291 snd_soc_component_exit_regmap(component);
1292
+ mutex_destroy(&rk817->clk_lock);
1293
+ clk_disable_unprepare(rk817->mclk);
11961294 mdelay(10);
11971295
11981296 }