forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-31 f70575805708cabdedea7498aaa3f710fde4d920
kernel/sound/soc/codecs/wm8960.c
....@@ -1,13 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * wm8960.c -- WM8960 ALSA SoC Audio driver
34 *
45 * Copyright 2007-11 Wolfson Microelectronics, plc
56 *
67 * Author: Liam Girdwood
7
- *
8
- * This program is free software; you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License version 2 as
10
- * published by the Free Software Foundation.
118 */
129
1310 #include <linux/module.h>
....@@ -611,11 +608,7 @@
611608 * - lrclk = sysclk / dac_divs
612609 * - 10 * bclk = sysclk / bclk_divs
613610 *
614
- * If we cannot find an exact match for (sysclk, lrclk, bclk)
615
- * triplet, we relax the bclk such that bclk is chosen as the
616
- * closest available frequency greater than expected bclk.
617
- *
618
- * @wm8960_priv: wm8960 codec private data
611
+ * @wm8960: codec private data
619612 * @mclk: MCLK used to derive sysclk
620613 * @sysclk_idx: sysclk_divs index for found sysclk
621614 * @dac_idx: dac_divs index for found lrclk
....@@ -632,7 +625,7 @@
632625 {
633626 int sysclk, bclk, lrclk;
634627 int i, j, k;
635
- int diff, closest = mclk;
628
+ int diff;
636629
637630 /* marker for no match */
638631 *bclk_idx = -1;
....@@ -655,12 +648,6 @@
655648 *dac_idx = j;
656649 *bclk_idx = k;
657650 break;
658
- }
659
- if (diff > 0 && closest > diff) {
660
- *sysclk_idx = i;
661
- *dac_idx = j;
662
- *bclk_idx = k;
663
- closest = diff;
664651 }
665652 }
666653 if (k != ARRAY_SIZE(bclk_divs))
....@@ -751,7 +738,7 @@
751738 {
752739 struct wm8960_priv *wm8960 = snd_soc_component_get_drvdata(component);
753740 int freq_out, freq_in;
754
- u16 iface1 = snd_soc_component_read32(component, WM8960_IFACE1);
741
+ u16 iface1 = snd_soc_component_read(component, WM8960_IFACE1);
755742 int i, j, k;
756743 int ret;
757744
....@@ -828,7 +815,7 @@
828815 {
829816 struct snd_soc_component *component = dai->component;
830817 struct wm8960_priv *wm8960 = snd_soc_component_get_drvdata(component);
831
- u16 iface = snd_soc_component_read32(component, WM8960_IFACE1) & 0xfff3;
818
+ u16 iface = snd_soc_component_read(component, WM8960_IFACE1) & 0xfff3;
832819 bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
833820 int i;
834821
....@@ -852,7 +839,7 @@
852839 iface |= 0x000c;
853840 break;
854841 }
855
- /* fall through */
842
+ fallthrough;
856843 default:
857844 dev_err(component->dev, "unsupported width %d\n",
858845 params_width(params));
....@@ -894,7 +881,7 @@
894881 return 0;
895882 }
896883
897
-static int wm8960_mute(struct snd_soc_dai *dai, int mute)
884
+static int wm8960_mute(struct snd_soc_dai *dai, int mute, int direction)
898885 {
899886 struct snd_soc_component *component = dai->component;
900887
....@@ -909,7 +896,7 @@
909896 enum snd_soc_bias_level level)
910897 {
911898 struct wm8960_priv *wm8960 = snd_soc_component_get_drvdata(component);
912
- u16 pm2 = snd_soc_component_read32(component, WM8960_POWER2);
899
+ u16 pm2 = snd_soc_component_read(component, WM8960_POWER2);
913900 int ret;
914901
915902 switch (level) {
....@@ -999,7 +986,7 @@
999986 enum snd_soc_bias_level level)
1000987 {
1001988 struct wm8960_priv *wm8960 = snd_soc_component_get_drvdata(component);
1002
- u16 pm2 = snd_soc_component_read32(component, WM8960_POWER2);
989
+ u16 pm2 = snd_soc_component_read(component, WM8960_POWER2);
1003990 int reg, ret;
1004991
1005992 switch (level) {
....@@ -1218,7 +1205,7 @@
12181205 if (!freq_in || !freq_out)
12191206 return 0;
12201207
1221
- reg = snd_soc_component_read32(component, WM8960_PLL1) & ~0x3f;
1208
+ reg = snd_soc_component_read(component, WM8960_PLL1) & ~0x3f;
12221209 reg |= pll_div.pre_div << 4;
12231210 reg |= pll_div.n;
12241211
....@@ -1261,23 +1248,23 @@
12611248
12621249 switch (div_id) {
12631250 case WM8960_SYSCLKDIV:
1264
- reg = snd_soc_component_read32(component, WM8960_CLOCK1) & 0x1f9;
1251
+ reg = snd_soc_component_read(component, WM8960_CLOCK1) & 0x1f9;
12651252 snd_soc_component_write(component, WM8960_CLOCK1, reg | div);
12661253 break;
12671254 case WM8960_DACDIV:
1268
- reg = snd_soc_component_read32(component, WM8960_CLOCK1) & 0x1c7;
1255
+ reg = snd_soc_component_read(component, WM8960_CLOCK1) & 0x1c7;
12691256 snd_soc_component_write(component, WM8960_CLOCK1, reg | div);
12701257 break;
12711258 case WM8960_OPCLKDIV:
1272
- reg = snd_soc_component_read32(component, WM8960_PLL1) & 0x03f;
1259
+ reg = snd_soc_component_read(component, WM8960_PLL1) & 0x03f;
12731260 snd_soc_component_write(component, WM8960_PLL1, reg | div);
12741261 break;
12751262 case WM8960_DCLKDIV:
1276
- reg = snd_soc_component_read32(component, WM8960_CLOCK2) & 0x03f;
1263
+ reg = snd_soc_component_read(component, WM8960_CLOCK2) & 0x03f;
12771264 snd_soc_component_write(component, WM8960_CLOCK2, reg | div);
12781265 break;
12791266 case WM8960_TOCLKSEL:
1280
- reg = snd_soc_component_read32(component, WM8960_ADDCTL1) & 0x1fd;
1267
+ reg = snd_soc_component_read(component, WM8960_ADDCTL1) & 0x1fd;
12811268 snd_soc_component_write(component, WM8960_ADDCTL1, reg | div);
12821269 break;
12831270 default:
....@@ -1331,11 +1318,12 @@
13311318 static const struct snd_soc_dai_ops wm8960_dai_ops = {
13321319 .hw_params = wm8960_hw_params,
13331320 .hw_free = wm8960_hw_free,
1334
- .digital_mute = wm8960_mute,
1321
+ .mute_stream = wm8960_mute,
13351322 .set_fmt = wm8960_set_dai_fmt,
13361323 .set_clkdiv = wm8960_set_dai_clkdiv,
13371324 .set_pll = wm8960_set_dai_pll,
13381325 .set_sysclk = wm8960_set_dai_sysclk,
1326
+ .no_capture_mute = 1,
13391327 };
13401328
13411329 static struct snd_soc_dai_driver wm8960_dai = {
....@@ -1405,6 +1393,12 @@
14051393
14061394 if (of_property_read_bool(np, "wlf,shared-lrclk"))
14071395 pdata->shared_lrclk = true;
1396
+
1397
+ of_property_read_u32_array(np, "wlf,gpio-cfg", pdata->gpio_cfg,
1398
+ ARRAY_SIZE(pdata->gpio_cfg));
1399
+
1400
+ of_property_read_u32_array(np, "wlf,hp-cfg", pdata->hp_cfg,
1401
+ ARRAY_SIZE(pdata->hp_cfg));
14081402 }
14091403
14101404 static int wm8960_i2c_probe(struct i2c_client *i2c,
....@@ -1462,6 +1456,20 @@
14621456 regmap_update_bits(wm8960->regmap, WM8960_LOUT2, 0x100, 0x100);
14631457 regmap_update_bits(wm8960->regmap, WM8960_ROUT2, 0x100, 0x100);
14641458
1459
+ /* ADCLRC pin configured as GPIO. */
1460
+ regmap_update_bits(wm8960->regmap, WM8960_IFACE2, 1 << 6,
1461
+ wm8960->pdata.gpio_cfg[0] << 6);
1462
+ regmap_update_bits(wm8960->regmap, WM8960_ADDCTL4, 0xF << 4,
1463
+ wm8960->pdata.gpio_cfg[1] << 4);
1464
+
1465
+ /* Enable headphone jack detect */
1466
+ regmap_update_bits(wm8960->regmap, WM8960_ADDCTL4, 3 << 2,
1467
+ wm8960->pdata.hp_cfg[0] << 2);
1468
+ regmap_update_bits(wm8960->regmap, WM8960_ADDCTL2, 3 << 5,
1469
+ wm8960->pdata.hp_cfg[1] << 5);
1470
+ regmap_update_bits(wm8960->regmap, WM8960_ADDCTL1, 3,
1471
+ wm8960->pdata.hp_cfg[2]);
1472
+
14651473 i2c_set_clientdata(i2c, wm8960);
14661474
14671475 ret = devm_snd_soc_register_component(&i2c->dev,