hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/sound/soc/codecs/rk_codec_digital.c
....@@ -24,6 +24,8 @@
2424 #include "rk_codec_digital.h"
2525
2626 #define RK3568_GRF_SOC_CON2 (0x0508)
27
+#define RK3588_GRF_SOC_CON6 (0x0318)
28
+#define RV1106_GRF_SOC_CON1 (0x0004)
2729 #define RV1126_GRF_SOC_CON2 (0x0008)
2830
2931 struct rk_codec_digital_soc_data {
....@@ -80,8 +82,8 @@
8082 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
8183 struct soc_mixer_control *mc =
8284 (struct soc_mixer_control *)kcontrol->private_value;
83
- unsigned int val = snd_soc_component_read32(component, mc->reg);
84
- unsigned int sign = snd_soc_component_read32(component, ADCVOGP);
85
+ unsigned int val = snd_soc_component_read(component, mc->reg);
86
+ unsigned int sign = snd_soc_component_read(component, ADCVOGP);
8587 unsigned int mask = (1 << fls(mc->max)) - 1;
8688 unsigned int shift = mc->shift;
8789 int mid = mc->max / 2;
....@@ -162,8 +164,8 @@
162164 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
163165 struct soc_mixer_control *mc =
164166 (struct soc_mixer_control *)kcontrol->private_value;
165
- unsigned int val = snd_soc_component_read32(component, mc->reg);
166
- unsigned int sign = snd_soc_component_read32(component, DACVOGP);
167
+ unsigned int val = snd_soc_component_read(component, mc->reg);
168
+ unsigned int sign = snd_soc_component_read(component, DACVOGP);
167169 unsigned int mask = (1 << fls(mc->max)) - 1;
168170 unsigned int shift = mc->shift;
169171 int mid = mc->max / 2;
....@@ -221,7 +223,7 @@
221223 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
222224 struct rk_codec_digital_priv *rcd = snd_soc_component_get_drvdata(component);
223225
224
- if (!rcd || !rcd->pa_ctl)
226
+ if (!rcd->pa_ctl)
225227 return -EINVAL;
226228
227229 ucontrol->value.enumerated.item[0] = gpiod_get_value(rcd->pa_ctl);
....@@ -235,7 +237,7 @@
235237 struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
236238 struct rk_codec_digital_priv *rcd = snd_soc_component_get_drvdata(component);
237239
238
- if (!rcd || !rcd->pa_ctl)
240
+ if (!rcd->pa_ctl)
239241 return -EINVAL;
240242
241243 gpiod_set_value(rcd->pa_ctl, ucontrol->value.enumerated.item[0]);
....@@ -405,13 +407,13 @@
405407 ACDCDIG_DACSCLKRXINT_DIV_SCKRXDIV(div_bclk));
406408 regmap_update_bits(rcd->regmap, I2S_CKR0,
407409 ACDCDIG_I2S_CKR0_RSD_MASK,
408
- ACDCDIG_I2S_CKR0_RSD(64));
410
+ ACDCDIG_I2S_CKR0_RSD_64);
409411 regmap_update_bits(rcd->regmap, ADCSCLKTXINT_DIV,
410412 ACDCDIG_ADCSCLKTXINT_DIV_SCKTXDIV_MASK,
411413 ACDCDIG_ADCSCLKTXINT_DIV_SCKTXDIV(div_bclk));
412414 regmap_update_bits(rcd->regmap, I2S_CKR0,
413415 ACDCDIG_I2S_CKR0_TSD_MASK,
414
- ACDCDIG_I2S_CKR0_TSD(64));
416
+ ACDCDIG_I2S_CKR0_TSD_64);
415417
416418 return 0;
417419 }
....@@ -448,7 +450,7 @@
448450 ACDCDIG_DACSCLKRXINT_DIV_SCKRXDIV(div_bclk));
449451 regmap_update_bits(rcd->regmap, I2S_CKR0,
450452 ACDCDIG_I2S_CKR0_RSD_MASK,
451
- ACDCDIG_I2S_CKR0_RSD(64));
453
+ ACDCDIG_I2S_CKR0_RSD_64);
452454 } else {
453455 clk_set_rate(rcd->clk_adc, mclk);
454456
....@@ -462,7 +464,7 @@
462464 ACDCDIG_ADCSCLKTXINT_DIV_SCKTXDIV(div_bclk));
463465 regmap_update_bits(rcd->regmap, I2S_CKR0,
464466 ACDCDIG_I2S_CKR0_TSD_MASK,
465
- ACDCDIG_I2S_CKR0_TSD(64));
467
+ ACDCDIG_I2S_CKR0_TSD_64);
466468 }
467469
468470 return 0;
....@@ -746,7 +748,7 @@
746748 struct rk_codec_digital_priv *rcd =
747749 snd_soc_component_get_drvdata(dai->component);
748750
749
- if (rcd && rcd->pa_ctl) {
751
+ if (rcd->pa_ctl) {
750752 gpiod_set_value_cansleep(rcd->pa_ctl, 1);
751753 if (rcd->pa_ctl_delay_ms)
752754 msleep(rcd->pa_ctl_delay_ms);
....@@ -761,11 +763,11 @@
761763 struct rk_codec_digital_priv *rcd =
762764 snd_soc_component_get_drvdata(dai->component);
763765
764
- if (rcd && rcd->pa_ctl)
766
+ if (rcd->pa_ctl)
765767 gpiod_set_value_cansleep(rcd->pa_ctl, 0);
766768
767769 if (rcd->sync) {
768
- if (!snd_soc_component_is_active(dai->component)) {
770
+ if (!snd_soc_component_active(dai->component)) {
769771 rk_codec_digital_disable_sync(rcd);
770772 rk_codec_digital_reset(rcd);
771773 }
....@@ -882,6 +884,60 @@
882884 .deinit = rk3568_soc_deinit,
883885 };
884886
887
+static int rk3588_soc_init(struct device *dev)
888
+{
889
+ struct rk_codec_digital_priv *rcd = dev_get_drvdata(dev);
890
+
891
+ if (IS_ERR(rcd->grf))
892
+ return PTR_ERR(rcd->grf);
893
+
894
+ /* enable internal codec to i2s3 */
895
+ return regmap_write(rcd->grf, RK3588_GRF_SOC_CON6,
896
+ (BIT(11) << 16 | BIT(11)));
897
+}
898
+
899
+static void rk3588_soc_deinit(struct device *dev)
900
+{
901
+ struct rk_codec_digital_priv *rcd = dev_get_drvdata(dev);
902
+
903
+ if (IS_ERR(rcd->grf))
904
+ return;
905
+
906
+ regmap_write(rcd->grf, RK3588_GRF_SOC_CON6, (BIT(11) << 16));
907
+}
908
+
909
+static const struct rk_codec_digital_soc_data rk3588_data = {
910
+ .init = rk3588_soc_init,
911
+ .deinit = rk3588_soc_deinit,
912
+};
913
+
914
+static int rv1106_soc_init(struct device *dev)
915
+{
916
+ struct rk_codec_digital_priv *rcd = dev_get_drvdata(dev);
917
+
918
+ if (IS_ERR(rcd->grf))
919
+ return PTR_ERR(rcd->grf);
920
+
921
+ /* enable internal codec to i2s0 */
922
+ return regmap_write(rcd->grf, RV1106_GRF_SOC_CON1,
923
+ (BIT(8) << 16 | BIT(8)));
924
+}
925
+
926
+static void rv1106_soc_deinit(struct device *dev)
927
+{
928
+ struct rk_codec_digital_priv *rcd = dev_get_drvdata(dev);
929
+
930
+ if (IS_ERR(rcd->grf))
931
+ return;
932
+
933
+ regmap_write(rcd->grf, RV1106_GRF_SOC_CON1, (BIT(8) << 16));
934
+}
935
+
936
+static const struct rk_codec_digital_soc_data rv1106_data = {
937
+ .init = rv1106_soc_init,
938
+ .deinit = rv1106_soc_deinit,
939
+};
940
+
885941 static int rv1126_soc_init(struct device *dev)
886942 {
887943 struct rk_codec_digital_priv *rcd = dev_get_drvdata(dev);
....@@ -912,8 +968,18 @@
912968 #ifdef CONFIG_OF
913969 static const struct of_device_id rcd_of_match[] = {
914970 { .compatible = "rockchip,codec-digital-v1", },
971
+#ifdef CONFIG_CPU_RK3568
915972 { .compatible = "rockchip,rk3568-codec-digital", .data = &rk3568_data },
973
+#endif
974
+#ifdef CONFIG_CPU_RK3588
975
+ { .compatible = "rockchip,rk3588-codec-digital", .data = &rk3588_data },
976
+#endif
977
+#ifdef CONFIG_CPU_RV1106
978
+ { .compatible = "rockchip,rv1106-codec-digital", .data = &rv1106_data },
979
+#endif
980
+#ifdef CONFIG_CPU_RV1126
916981 { .compatible = "rockchip,rv1126-codec-digital", .data = &rv1126_data },
982
+#endif
917983 {},
918984 };
919985 MODULE_DEVICE_TABLE(of, rcd_of_match);
....@@ -995,7 +1061,8 @@
9951061
9961062 rcd->rc = devm_reset_control_get(&pdev->dev, "reset");
9971063
998
- rcd->clk_adc = devm_clk_get(&pdev->dev, "adc");
1064
+ /* optional on some platform */
1065
+ rcd->clk_adc = devm_clk_get_optional(&pdev->dev, "adc");
9991066 if (IS_ERR(rcd->clk_adc))
10001067 return PTR_ERR(rcd->clk_adc);
10011068