hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/sound/soc/mediatek/mt8173/mt8173-afe-pcm.c
....@@ -297,7 +297,7 @@
297297 {
298298 struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai);
299299
300
- if (dai->active)
300
+ if (snd_soc_dai_active(dai))
301301 return 0;
302302
303303 regmap_update_bits(afe->regmap, AUDIO_TOP_CON0,
....@@ -310,7 +310,7 @@
310310 {
311311 struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai);
312312
313
- if (dai->active)
313
+ if (snd_soc_dai_active(dai))
314314 return;
315315
316316 mt8173_afe_set_i2s_enable(afe, false);
....@@ -347,7 +347,7 @@
347347 struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai);
348348 struct mt8173_afe_private *afe_priv = afe->platform_priv;
349349
350
- if (dai->active)
350
+ if (snd_soc_dai_active(dai))
351351 return 0;
352352
353353 mt8173_afe_dais_enable_clks(afe, afe_priv->clocks[MT8173_CLK_I2S3_M],
....@@ -361,7 +361,7 @@
361361 struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai);
362362 struct mt8173_afe_private *afe_priv = afe->platform_priv;
363363
364
- if (dai->active)
364
+ if (snd_soc_dai_active(dai))
365365 return;
366366
367367 mt8173_afe_dais_disable_clks(afe, afe_priv->clocks[MT8173_CLK_I2S3_M],
....@@ -482,10 +482,10 @@
482482 static int mt8173_memif_fs(struct snd_pcm_substream *substream,
483483 unsigned int rate)
484484 {
485
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
485
+ struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
486486 struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
487487 struct mtk_base_afe *afe = snd_soc_component_get_drvdata(component);
488
- struct mtk_base_afe_memif *memif = &afe->memif[rtd->cpu_dai->id];
488
+ struct mtk_base_afe_memif *memif = &afe->memif[asoc_rtd_to_cpu(rtd, 0)->id];
489489 int fs;
490490
491491 if (memif->data->id == MT8173_AFE_MEMIF_DAI ||
....@@ -533,8 +533,6 @@
533533 {
534534 .name = "DL1", /* downlink 1 */
535535 .id = MT8173_AFE_MEMIF_DL1,
536
- .suspend = mtk_afe_dai_suspend,
537
- .resume = mtk_afe_dai_resume,
538536 .playback = {
539537 .stream_name = "DL1",
540538 .channels_min = 1,
....@@ -546,8 +544,6 @@
546544 }, {
547545 .name = "VUL", /* voice uplink */
548546 .id = MT8173_AFE_MEMIF_VUL,
549
- .suspend = mtk_afe_dai_suspend,
550
- .resume = mtk_afe_dai_resume,
551547 .capture = {
552548 .stream_name = "VUL",
553549 .channels_min = 1,
....@@ -584,8 +580,6 @@
584580 {
585581 .name = "HDMI",
586582 .id = MT8173_AFE_MEMIF_HDMI,
587
- .suspend = mtk_afe_dai_suspend,
588
- .resume = mtk_afe_dai_resume,
589583 .playback = {
590584 .stream_name = "HDMI",
591585 .channels_min = 2,
....@@ -681,12 +675,16 @@
681675 .num_dapm_widgets = ARRAY_SIZE(mt8173_afe_pcm_widgets),
682676 .dapm_routes = mt8173_afe_pcm_routes,
683677 .num_dapm_routes = ARRAY_SIZE(mt8173_afe_pcm_routes),
678
+ .suspend = mtk_afe_suspend,
679
+ .resume = mtk_afe_resume,
684680 };
685681
686682 static const struct snd_soc_component_driver mt8173_afe_hdmi_dai_component = {
687683 .name = "mt8173-afe-hdmi-dai",
688684 .dapm_routes = mt8173_afe_hdmi_routes,
689685 .num_dapm_routes = ARRAY_SIZE(mt8173_afe_hdmi_routes),
686
+ .suspend = mtk_afe_suspend,
687
+ .resume = mtk_afe_resume,
690688 };
691689
692690 static const char *aud_clks[MT8173_CLK_NUM] = {
....@@ -714,13 +712,11 @@
714712 .mono_reg = AFE_DAC_CON1,
715713 .mono_shift = 21,
716714 .hd_reg = -1,
717
- .hd_shift = -1,
718715 .enable_reg = AFE_DAC_CON0,
719716 .enable_shift = 1,
720717 .msb_reg = AFE_MEMIF_MSB,
721718 .msb_shift = 0,
722719 .agent_disable_reg = -1,
723
- .agent_disable_shift = -1,
724720 }, {
725721 .name = "DL2",
726722 .id = MT8173_AFE_MEMIF_DL2,
....@@ -732,13 +728,11 @@
732728 .mono_reg = AFE_DAC_CON1,
733729 .mono_shift = 22,
734730 .hd_reg = -1,
735
- .hd_shift = -1,
736731 .enable_reg = AFE_DAC_CON0,
737732 .enable_shift = 2,
738733 .msb_reg = AFE_MEMIF_MSB,
739734 .msb_shift = 1,
740735 .agent_disable_reg = -1,
741
- .agent_disable_shift = -1,
742736 }, {
743737 .name = "VUL",
744738 .id = MT8173_AFE_MEMIF_VUL,
....@@ -750,13 +744,11 @@
750744 .mono_reg = AFE_DAC_CON1,
751745 .mono_shift = 27,
752746 .hd_reg = -1,
753
- .hd_shift = -1,
754747 .enable_reg = AFE_DAC_CON0,
755748 .enable_shift = 3,
756749 .msb_reg = AFE_MEMIF_MSB,
757750 .msb_shift = 6,
758751 .agent_disable_reg = -1,
759
- .agent_disable_shift = -1,
760752 }, {
761753 .name = "DAI",
762754 .id = MT8173_AFE_MEMIF_DAI,
....@@ -768,13 +760,11 @@
768760 .mono_reg = -1,
769761 .mono_shift = -1,
770762 .hd_reg = -1,
771
- .hd_shift = -1,
772763 .enable_reg = AFE_DAC_CON0,
773764 .enable_shift = 4,
774765 .msb_reg = AFE_MEMIF_MSB,
775766 .msb_shift = 5,
776767 .agent_disable_reg = -1,
777
- .agent_disable_shift = -1,
778768 }, {
779769 .name = "AWB",
780770 .id = MT8173_AFE_MEMIF_AWB,
....@@ -786,13 +776,11 @@
786776 .mono_reg = AFE_DAC_CON1,
787777 .mono_shift = 24,
788778 .hd_reg = -1,
789
- .hd_shift = -1,
790779 .enable_reg = AFE_DAC_CON0,
791780 .enable_shift = 6,
792781 .msb_reg = AFE_MEMIF_MSB,
793782 .msb_shift = 3,
794783 .agent_disable_reg = -1,
795
- .agent_disable_shift = -1,
796784 }, {
797785 .name = "MOD_DAI",
798786 .id = MT8173_AFE_MEMIF_MOD_DAI,
....@@ -804,13 +792,11 @@
804792 .mono_reg = AFE_DAC_CON1,
805793 .mono_shift = 30,
806794 .hd_reg = -1,
807
- .hd_shift = -1,
808795 .enable_reg = AFE_DAC_CON0,
809796 .enable_shift = 7,
810797 .msb_reg = AFE_MEMIF_MSB,
811798 .msb_shift = 4,
812799 .agent_disable_reg = -1,
813
- .agent_disable_shift = -1,
814800 }, {
815801 .name = "HDMI",
816802 .id = MT8173_AFE_MEMIF_HDMI,
....@@ -822,13 +808,10 @@
822808 .mono_reg = -1,
823809 .mono_shift = -1,
824810 .hd_reg = -1,
825
- .hd_shift = -1,
826811 .enable_reg = -1,
827
- .enable_shift = -1,
828812 .msb_reg = AFE_MEMIF_MSB,
829813 .msb_shift = 8,
830814 .agent_disable_reg = -1,
831
- .agent_disable_shift = -1,
832815 },
833816 };
834817
....@@ -914,7 +897,6 @@
914897 .irq_en_reg = AFE_IRQ_MCU_CON,
915898 .irq_en_shift = 12,
916899 .irq_fs_reg = -1,
917
- .irq_fs_shift = -1,
918900 .irq_fs_maskbit = -1,
919901 .irq_clr_reg = AFE_IRQ_CLR,
920902 .irq_clr_shift = 4,
....@@ -1072,7 +1054,7 @@
10721054 int irq_id;
10731055 struct mtk_base_afe *afe;
10741056 struct mt8173_afe_private *afe_priv;
1075
- struct resource *res;
1057
+ struct snd_soc_component *comp_pcm, *comp_hdmi;
10761058
10771059 ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(33));
10781060 if (ret)
....@@ -1091,19 +1073,10 @@
10911073 afe->dev = &pdev->dev;
10921074
10931075 irq_id = platform_get_irq(pdev, 0);
1094
- if (irq_id <= 0) {
1095
- dev_err(afe->dev, "np %s no irq\n", afe->dev->of_node->name);
1076
+ if (irq_id <= 0)
10961077 return irq_id < 0 ? irq_id : -ENXIO;
1097
- }
1098
- ret = devm_request_irq(afe->dev, irq_id, mt8173_afe_irq_handler,
1099
- 0, "Afe_ISR_Handle", (void *)afe);
1100
- if (ret) {
1101
- dev_err(afe->dev, "could not request_irq\n");
1102
- return ret;
1103
- }
11041078
1105
- res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1106
- afe->base_addr = devm_ioremap_resource(&pdev->dev, res);
1079
+ afe->base_addr = devm_platform_ioremap_resource(pdev, 0);
11071080 if (IS_ERR(afe->base_addr))
11081081 return PTR_ERR(afe->base_addr);
11091082
....@@ -1164,23 +1137,62 @@
11641137 if (ret)
11651138 goto err_pm_disable;
11661139
1167
- ret = devm_snd_soc_register_component(&pdev->dev,
1168
- &mt8173_afe_pcm_dai_component,
1169
- mt8173_afe_pcm_dais,
1170
- ARRAY_SIZE(mt8173_afe_pcm_dais));
1140
+ comp_pcm = devm_kzalloc(&pdev->dev, sizeof(*comp_pcm), GFP_KERNEL);
1141
+ if (!comp_pcm) {
1142
+ ret = -ENOMEM;
1143
+ goto err_pm_disable;
1144
+ }
1145
+
1146
+ ret = snd_soc_component_initialize(comp_pcm,
1147
+ &mt8173_afe_pcm_dai_component,
1148
+ &pdev->dev);
11711149 if (ret)
11721150 goto err_pm_disable;
11731151
1174
- ret = devm_snd_soc_register_component(&pdev->dev,
1175
- &mt8173_afe_hdmi_dai_component,
1176
- mt8173_afe_hdmi_dais,
1177
- ARRAY_SIZE(mt8173_afe_hdmi_dais));
1152
+#ifdef CONFIG_DEBUG_FS
1153
+ comp_pcm->debugfs_prefix = "pcm";
1154
+#endif
1155
+
1156
+ ret = snd_soc_add_component(comp_pcm,
1157
+ mt8173_afe_pcm_dais,
1158
+ ARRAY_SIZE(mt8173_afe_pcm_dais));
11781159 if (ret)
11791160 goto err_pm_disable;
1161
+
1162
+ comp_hdmi = devm_kzalloc(&pdev->dev, sizeof(*comp_hdmi), GFP_KERNEL);
1163
+ if (!comp_hdmi) {
1164
+ ret = -ENOMEM;
1165
+ goto err_cleanup_components;
1166
+ }
1167
+
1168
+ ret = snd_soc_component_initialize(comp_hdmi,
1169
+ &mt8173_afe_hdmi_dai_component,
1170
+ &pdev->dev);
1171
+ if (ret)
1172
+ goto err_cleanup_components;
1173
+
1174
+#ifdef CONFIG_DEBUG_FS
1175
+ comp_hdmi->debugfs_prefix = "hdmi";
1176
+#endif
1177
+
1178
+ ret = snd_soc_add_component(comp_hdmi,
1179
+ mt8173_afe_hdmi_dais,
1180
+ ARRAY_SIZE(mt8173_afe_hdmi_dais));
1181
+ if (ret)
1182
+ goto err_cleanup_components;
1183
+
1184
+ ret = devm_request_irq(afe->dev, irq_id, mt8173_afe_irq_handler,
1185
+ 0, "Afe_ISR_Handle", (void *)afe);
1186
+ if (ret) {
1187
+ dev_err(afe->dev, "could not request_irq\n");
1188
+ goto err_cleanup_components;
1189
+ }
11801190
11811191 dev_info(&pdev->dev, "MT8173 AFE driver initialized.\n");
11821192 return 0;
11831193
1194
+err_cleanup_components:
1195
+ snd_soc_unregister_component(&pdev->dev);
11841196 err_pm_disable:
11851197 pm_runtime_disable(&pdev->dev);
11861198 return ret;
....@@ -1188,6 +1200,8 @@
11881200
11891201 static int mt8173_afe_pcm_dev_remove(struct platform_device *pdev)
11901202 {
1203
+ snd_soc_unregister_component(&pdev->dev);
1204
+
11911205 pm_runtime_disable(&pdev->dev);
11921206 if (!pm_runtime_status_suspended(&pdev->dev))
11931207 mt8173_afe_runtime_suspend(&pdev->dev);