hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/sound/soc/rockchip/rockchip_pdm.c
....@@ -31,8 +31,10 @@
3131 #define PDM_FILTER_DELAY_MS_MIN (20)
3232 #define PDM_FILTER_DELAY_MS_MAX (1000)
3333 #define PDM_CLK_SHIFT_PPM_MAX (1000000) /* 1 ppm */
34
-#define CLK_PPM_MIN (-1000)
35
-#define CLK_PPM_MAX (1000)
34
+#define CLK_PPM_MIN (-1000)
35
+#define CLK_PPM_MAX (1000)
36
+
37
+#define QUIRK_ALWAYS_ON BIT(0)
3638
3739 enum rk_pdm_version {
3840 RK_PDM_RK3229,
....@@ -56,6 +58,7 @@
5658 enum rk_pdm_version version;
5759 unsigned int clk_root_rate;
5860 unsigned int clk_root_initial_rate;
61
+ unsigned int quirks;
5962 int clk_ppm;
6063 bool clk_calibrate;
6164 };
....@@ -95,6 +98,16 @@
9598 { 4, 12000 },
9699 { 4, 11025 },
97100 { 4, 8000 },
101
+};
102
+
103
+static const struct pdm_of_quirks {
104
+ char *quirk;
105
+ int id;
106
+} of_quirks[] = {
107
+ {
108
+ .quirk = "rockchip,always-on",
109
+ .id = QUIRK_ALWAYS_ON,
110
+ },
98111 };
99112
100113 static unsigned int get_pdm_clk(struct rk_pdm_dev *pdm, unsigned int sr,
....@@ -508,8 +521,8 @@
508521 static int rockchip_pdm_start_delay_get(struct snd_kcontrol *kcontrol,
509522 struct snd_ctl_elem_value *ucontrol)
510523 {
511
- struct snd_soc_dai *dai = snd_kcontrol_chip(kcontrol);
512
- struct rk_pdm_dev *pdm = snd_soc_dai_get_drvdata(dai);
524
+ struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
525
+ struct rk_pdm_dev *pdm = snd_soc_component_get_drvdata(component);
513526
514527 ucontrol->value.integer.value[0] = pdm->start_delay_ms;
515528
....@@ -519,8 +532,8 @@
519532 static int rockchip_pdm_start_delay_put(struct snd_kcontrol *kcontrol,
520533 struct snd_ctl_elem_value *ucontrol)
521534 {
522
- struct snd_soc_dai *dai = snd_kcontrol_chip(kcontrol);
523
- struct rk_pdm_dev *pdm = snd_soc_dai_get_drvdata(dai);
535
+ struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
536
+ struct rk_pdm_dev *pdm = snd_soc_component_get_drvdata(component);
524537
525538 if ((ucontrol->value.integer.value[0] < PDM_START_DELAY_MS_MIN) ||
526539 (ucontrol->value.integer.value[0] > PDM_START_DELAY_MS_MAX))
....@@ -546,8 +559,8 @@
546559 static int rockchip_pdm_filter_delay_get(struct snd_kcontrol *kcontrol,
547560 struct snd_ctl_elem_value *ucontrol)
548561 {
549
- struct snd_soc_dai *dai = snd_kcontrol_chip(kcontrol);
550
- struct rk_pdm_dev *pdm = snd_soc_dai_get_drvdata(dai);
562
+ struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
563
+ struct rk_pdm_dev *pdm = snd_soc_component_get_drvdata(component);
551564
552565 ucontrol->value.integer.value[0] = pdm->filter_delay_ms;
553566
....@@ -557,8 +570,8 @@
557570 static int rockchip_pdm_filter_delay_put(struct snd_kcontrol *kcontrol,
558571 struct snd_ctl_elem_value *ucontrol)
559572 {
560
- struct snd_soc_dai *dai = snd_kcontrol_chip(kcontrol);
561
- struct rk_pdm_dev *pdm = snd_soc_dai_get_drvdata(dai);
573
+ struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
574
+ struct rk_pdm_dev *pdm = snd_soc_component_get_drvdata(component);
562575
563576 if ((ucontrol->value.integer.value[0] < PDM_FILTER_DELAY_MS_MIN) ||
564577 (ucontrol->value.integer.value[0] > PDM_FILTER_DELAY_MS_MAX))
....@@ -577,11 +590,22 @@
577590 static SOC_ENUM_SINGLE_DECL(rpath1_enum, PDM_CLK_CTRL, 10, rpaths_text);
578591 static SOC_ENUM_SINGLE_DECL(rpath0_enum, PDM_CLK_CTRL, 8, rpaths_text);
579592
593
+static const char * const hpf_cutoff_text[] = {
594
+ "3.79Hz", "60Hz", "243Hz", "493Hz",
595
+};
596
+
597
+static SOC_ENUM_SINGLE_DECL(hpf_cutoff_enum, PDM_HPF_CTRL,
598
+ 0, hpf_cutoff_text);
599
+
580600 static const struct snd_kcontrol_new rockchip_pdm_controls[] = {
581601 SOC_ENUM("Receive PATH3 Source Select", rpath3_enum),
582602 SOC_ENUM("Receive PATH2 Source Select", rpath2_enum),
583603 SOC_ENUM("Receive PATH1 Source Select", rpath1_enum),
584604 SOC_ENUM("Receive PATH0 Source Select", rpath0_enum),
605
+
606
+ SOC_ENUM("HPF Cutoff", hpf_cutoff_enum),
607
+ SOC_SINGLE("HPFL Switch", PDM_HPF_CTRL, 3, 1, 0),
608
+ SOC_SINGLE("HPFR Switch", PDM_HPF_CTRL, 2, 1, 0),
585609
586610 {
587611 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
....@@ -616,8 +640,8 @@
616640 struct snd_ctl_elem_value *ucontrol)
617641
618642 {
619
- struct snd_soc_dai *dai = snd_kcontrol_chip(kcontrol);
620
- struct rk_pdm_dev *pdm = snd_soc_dai_get_drvdata(dai);
643
+ struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
644
+ struct rk_pdm_dev *pdm = snd_soc_component_get_drvdata(component);
621645
622646 ucontrol->value.integer.value[0] = pdm->clk_ppm;
623647
....@@ -627,8 +651,8 @@
627651 static int rockchip_pdm_clk_compensation_put(struct snd_kcontrol *kcontrol,
628652 struct snd_ctl_elem_value *ucontrol)
629653 {
630
- struct snd_soc_dai *dai = snd_kcontrol_chip(kcontrol);
631
- struct rk_pdm_dev *pdm = snd_soc_dai_get_drvdata(dai);
654
+ struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
655
+ struct rk_pdm_dev *pdm = snd_soc_component_get_drvdata(component);
632656
633657 int ppm = ucontrol->value.integer.value[0];
634658
....@@ -946,6 +970,29 @@
946970 return 0;
947971 }
948972
973
+static int rockchip_pdm_keep_clk_always_on(struct rk_pdm_dev *pdm)
974
+{
975
+ pm_runtime_forbid(pdm->dev);
976
+
977
+ dev_info(pdm->dev, "CLK-ALWAYS-ON: samplerate: %d\n", PDM_DEFAULT_RATE);
978
+
979
+ return 0;
980
+}
981
+
982
+static int rockchip_pdm_parse_quirks(struct rk_pdm_dev *pdm)
983
+{
984
+ int ret = 0, i = 0;
985
+
986
+ for (i = 0; i < ARRAY_SIZE(of_quirks); i++)
987
+ if (device_property_read_bool(pdm->dev, of_quirks[i].quirk))
988
+ pdm->quirks |= of_quirks[i].id;
989
+
990
+ if (pdm->quirks & QUIRK_ALWAYS_ON)
991
+ ret = rockchip_pdm_keep_clk_always_on(pdm);
992
+
993
+ return ret;
994
+}
995
+
949996 static int rockchip_pdm_probe(struct platform_device *pdev)
950997 {
951998 struct device_node *node = pdev->dev.of_node;
....@@ -1027,6 +1074,10 @@
10271074 if (ret != 0 && ret != -ENOENT)
10281075 goto err_clk;
10291076
1077
+ ret = rockchip_pdm_parse_quirks(pdm);
1078
+ if (ret)
1079
+ goto err_clk;
1080
+
10301081 /*
10311082 * MUST: after pm_runtime_enable step, any register R/W
10321083 * should be wrapped with pm_runtime_get_sync/put.