| .. | .. |
|---|
| 297 | 297 | { |
|---|
| 298 | 298 | struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai); |
|---|
| 299 | 299 | |
|---|
| 300 | | - if (dai->active) |
|---|
| 300 | + if (snd_soc_dai_active(dai)) |
|---|
| 301 | 301 | return 0; |
|---|
| 302 | 302 | |
|---|
| 303 | 303 | regmap_update_bits(afe->regmap, AUDIO_TOP_CON0, |
|---|
| .. | .. |
|---|
| 310 | 310 | { |
|---|
| 311 | 311 | struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai); |
|---|
| 312 | 312 | |
|---|
| 313 | | - if (dai->active) |
|---|
| 313 | + if (snd_soc_dai_active(dai)) |
|---|
| 314 | 314 | return; |
|---|
| 315 | 315 | |
|---|
| 316 | 316 | mt8173_afe_set_i2s_enable(afe, false); |
|---|
| .. | .. |
|---|
| 347 | 347 | struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai); |
|---|
| 348 | 348 | struct mt8173_afe_private *afe_priv = afe->platform_priv; |
|---|
| 349 | 349 | |
|---|
| 350 | | - if (dai->active) |
|---|
| 350 | + if (snd_soc_dai_active(dai)) |
|---|
| 351 | 351 | return 0; |
|---|
| 352 | 352 | |
|---|
| 353 | 353 | mt8173_afe_dais_enable_clks(afe, afe_priv->clocks[MT8173_CLK_I2S3_M], |
|---|
| .. | .. |
|---|
| 361 | 361 | struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai); |
|---|
| 362 | 362 | struct mt8173_afe_private *afe_priv = afe->platform_priv; |
|---|
| 363 | 363 | |
|---|
| 364 | | - if (dai->active) |
|---|
| 364 | + if (snd_soc_dai_active(dai)) |
|---|
| 365 | 365 | return; |
|---|
| 366 | 366 | |
|---|
| 367 | 367 | mt8173_afe_dais_disable_clks(afe, afe_priv->clocks[MT8173_CLK_I2S3_M], |
|---|
| .. | .. |
|---|
| 482 | 482 | static int mt8173_memif_fs(struct snd_pcm_substream *substream, |
|---|
| 483 | 483 | unsigned int rate) |
|---|
| 484 | 484 | { |
|---|
| 485 | | - struct snd_soc_pcm_runtime *rtd = substream->private_data; |
|---|
| 485 | + struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
|---|
| 486 | 486 | struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME); |
|---|
| 487 | 487 | 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]; |
|---|
| 489 | 489 | int fs; |
|---|
| 490 | 490 | |
|---|
| 491 | 491 | if (memif->data->id == MT8173_AFE_MEMIF_DAI || |
|---|
| .. | .. |
|---|
| 533 | 533 | { |
|---|
| 534 | 534 | .name = "DL1", /* downlink 1 */ |
|---|
| 535 | 535 | .id = MT8173_AFE_MEMIF_DL1, |
|---|
| 536 | | - .suspend = mtk_afe_dai_suspend, |
|---|
| 537 | | - .resume = mtk_afe_dai_resume, |
|---|
| 538 | 536 | .playback = { |
|---|
| 539 | 537 | .stream_name = "DL1", |
|---|
| 540 | 538 | .channels_min = 1, |
|---|
| .. | .. |
|---|
| 546 | 544 | }, { |
|---|
| 547 | 545 | .name = "VUL", /* voice uplink */ |
|---|
| 548 | 546 | .id = MT8173_AFE_MEMIF_VUL, |
|---|
| 549 | | - .suspend = mtk_afe_dai_suspend, |
|---|
| 550 | | - .resume = mtk_afe_dai_resume, |
|---|
| 551 | 547 | .capture = { |
|---|
| 552 | 548 | .stream_name = "VUL", |
|---|
| 553 | 549 | .channels_min = 1, |
|---|
| .. | .. |
|---|
| 584 | 580 | { |
|---|
| 585 | 581 | .name = "HDMI", |
|---|
| 586 | 582 | .id = MT8173_AFE_MEMIF_HDMI, |
|---|
| 587 | | - .suspend = mtk_afe_dai_suspend, |
|---|
| 588 | | - .resume = mtk_afe_dai_resume, |
|---|
| 589 | 583 | .playback = { |
|---|
| 590 | 584 | .stream_name = "HDMI", |
|---|
| 591 | 585 | .channels_min = 2, |
|---|
| .. | .. |
|---|
| 681 | 675 | .num_dapm_widgets = ARRAY_SIZE(mt8173_afe_pcm_widgets), |
|---|
| 682 | 676 | .dapm_routes = mt8173_afe_pcm_routes, |
|---|
| 683 | 677 | .num_dapm_routes = ARRAY_SIZE(mt8173_afe_pcm_routes), |
|---|
| 678 | + .suspend = mtk_afe_suspend, |
|---|
| 679 | + .resume = mtk_afe_resume, |
|---|
| 684 | 680 | }; |
|---|
| 685 | 681 | |
|---|
| 686 | 682 | static const struct snd_soc_component_driver mt8173_afe_hdmi_dai_component = { |
|---|
| 687 | 683 | .name = "mt8173-afe-hdmi-dai", |
|---|
| 688 | 684 | .dapm_routes = mt8173_afe_hdmi_routes, |
|---|
| 689 | 685 | .num_dapm_routes = ARRAY_SIZE(mt8173_afe_hdmi_routes), |
|---|
| 686 | + .suspend = mtk_afe_suspend, |
|---|
| 687 | + .resume = mtk_afe_resume, |
|---|
| 690 | 688 | }; |
|---|
| 691 | 689 | |
|---|
| 692 | 690 | static const char *aud_clks[MT8173_CLK_NUM] = { |
|---|
| .. | .. |
|---|
| 714 | 712 | .mono_reg = AFE_DAC_CON1, |
|---|
| 715 | 713 | .mono_shift = 21, |
|---|
| 716 | 714 | .hd_reg = -1, |
|---|
| 717 | | - .hd_shift = -1, |
|---|
| 718 | 715 | .enable_reg = AFE_DAC_CON0, |
|---|
| 719 | 716 | .enable_shift = 1, |
|---|
| 720 | 717 | .msb_reg = AFE_MEMIF_MSB, |
|---|
| 721 | 718 | .msb_shift = 0, |
|---|
| 722 | 719 | .agent_disable_reg = -1, |
|---|
| 723 | | - .agent_disable_shift = -1, |
|---|
| 724 | 720 | }, { |
|---|
| 725 | 721 | .name = "DL2", |
|---|
| 726 | 722 | .id = MT8173_AFE_MEMIF_DL2, |
|---|
| .. | .. |
|---|
| 732 | 728 | .mono_reg = AFE_DAC_CON1, |
|---|
| 733 | 729 | .mono_shift = 22, |
|---|
| 734 | 730 | .hd_reg = -1, |
|---|
| 735 | | - .hd_shift = -1, |
|---|
| 736 | 731 | .enable_reg = AFE_DAC_CON0, |
|---|
| 737 | 732 | .enable_shift = 2, |
|---|
| 738 | 733 | .msb_reg = AFE_MEMIF_MSB, |
|---|
| 739 | 734 | .msb_shift = 1, |
|---|
| 740 | 735 | .agent_disable_reg = -1, |
|---|
| 741 | | - .agent_disable_shift = -1, |
|---|
| 742 | 736 | }, { |
|---|
| 743 | 737 | .name = "VUL", |
|---|
| 744 | 738 | .id = MT8173_AFE_MEMIF_VUL, |
|---|
| .. | .. |
|---|
| 750 | 744 | .mono_reg = AFE_DAC_CON1, |
|---|
| 751 | 745 | .mono_shift = 27, |
|---|
| 752 | 746 | .hd_reg = -1, |
|---|
| 753 | | - .hd_shift = -1, |
|---|
| 754 | 747 | .enable_reg = AFE_DAC_CON0, |
|---|
| 755 | 748 | .enable_shift = 3, |
|---|
| 756 | 749 | .msb_reg = AFE_MEMIF_MSB, |
|---|
| 757 | 750 | .msb_shift = 6, |
|---|
| 758 | 751 | .agent_disable_reg = -1, |
|---|
| 759 | | - .agent_disable_shift = -1, |
|---|
| 760 | 752 | }, { |
|---|
| 761 | 753 | .name = "DAI", |
|---|
| 762 | 754 | .id = MT8173_AFE_MEMIF_DAI, |
|---|
| .. | .. |
|---|
| 768 | 760 | .mono_reg = -1, |
|---|
| 769 | 761 | .mono_shift = -1, |
|---|
| 770 | 762 | .hd_reg = -1, |
|---|
| 771 | | - .hd_shift = -1, |
|---|
| 772 | 763 | .enable_reg = AFE_DAC_CON0, |
|---|
| 773 | 764 | .enable_shift = 4, |
|---|
| 774 | 765 | .msb_reg = AFE_MEMIF_MSB, |
|---|
| 775 | 766 | .msb_shift = 5, |
|---|
| 776 | 767 | .agent_disable_reg = -1, |
|---|
| 777 | | - .agent_disable_shift = -1, |
|---|
| 778 | 768 | }, { |
|---|
| 779 | 769 | .name = "AWB", |
|---|
| 780 | 770 | .id = MT8173_AFE_MEMIF_AWB, |
|---|
| .. | .. |
|---|
| 786 | 776 | .mono_reg = AFE_DAC_CON1, |
|---|
| 787 | 777 | .mono_shift = 24, |
|---|
| 788 | 778 | .hd_reg = -1, |
|---|
| 789 | | - .hd_shift = -1, |
|---|
| 790 | 779 | .enable_reg = AFE_DAC_CON0, |
|---|
| 791 | 780 | .enable_shift = 6, |
|---|
| 792 | 781 | .msb_reg = AFE_MEMIF_MSB, |
|---|
| 793 | 782 | .msb_shift = 3, |
|---|
| 794 | 783 | .agent_disable_reg = -1, |
|---|
| 795 | | - .agent_disable_shift = -1, |
|---|
| 796 | 784 | }, { |
|---|
| 797 | 785 | .name = "MOD_DAI", |
|---|
| 798 | 786 | .id = MT8173_AFE_MEMIF_MOD_DAI, |
|---|
| .. | .. |
|---|
| 804 | 792 | .mono_reg = AFE_DAC_CON1, |
|---|
| 805 | 793 | .mono_shift = 30, |
|---|
| 806 | 794 | .hd_reg = -1, |
|---|
| 807 | | - .hd_shift = -1, |
|---|
| 808 | 795 | .enable_reg = AFE_DAC_CON0, |
|---|
| 809 | 796 | .enable_shift = 7, |
|---|
| 810 | 797 | .msb_reg = AFE_MEMIF_MSB, |
|---|
| 811 | 798 | .msb_shift = 4, |
|---|
| 812 | 799 | .agent_disable_reg = -1, |
|---|
| 813 | | - .agent_disable_shift = -1, |
|---|
| 814 | 800 | }, { |
|---|
| 815 | 801 | .name = "HDMI", |
|---|
| 816 | 802 | .id = MT8173_AFE_MEMIF_HDMI, |
|---|
| .. | .. |
|---|
| 822 | 808 | .mono_reg = -1, |
|---|
| 823 | 809 | .mono_shift = -1, |
|---|
| 824 | 810 | .hd_reg = -1, |
|---|
| 825 | | - .hd_shift = -1, |
|---|
| 826 | 811 | .enable_reg = -1, |
|---|
| 827 | | - .enable_shift = -1, |
|---|
| 828 | 812 | .msb_reg = AFE_MEMIF_MSB, |
|---|
| 829 | 813 | .msb_shift = 8, |
|---|
| 830 | 814 | .agent_disable_reg = -1, |
|---|
| 831 | | - .agent_disable_shift = -1, |
|---|
| 832 | 815 | }, |
|---|
| 833 | 816 | }; |
|---|
| 834 | 817 | |
|---|
| .. | .. |
|---|
| 914 | 897 | .irq_en_reg = AFE_IRQ_MCU_CON, |
|---|
| 915 | 898 | .irq_en_shift = 12, |
|---|
| 916 | 899 | .irq_fs_reg = -1, |
|---|
| 917 | | - .irq_fs_shift = -1, |
|---|
| 918 | 900 | .irq_fs_maskbit = -1, |
|---|
| 919 | 901 | .irq_clr_reg = AFE_IRQ_CLR, |
|---|
| 920 | 902 | .irq_clr_shift = 4, |
|---|
| .. | .. |
|---|
| 1072 | 1054 | int irq_id; |
|---|
| 1073 | 1055 | struct mtk_base_afe *afe; |
|---|
| 1074 | 1056 | struct mt8173_afe_private *afe_priv; |
|---|
| 1075 | | - struct resource *res; |
|---|
| 1057 | + struct snd_soc_component *comp_pcm, *comp_hdmi; |
|---|
| 1076 | 1058 | |
|---|
| 1077 | 1059 | ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(33)); |
|---|
| 1078 | 1060 | if (ret) |
|---|
| .. | .. |
|---|
| 1091 | 1073 | afe->dev = &pdev->dev; |
|---|
| 1092 | 1074 | |
|---|
| 1093 | 1075 | 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) |
|---|
| 1096 | 1077 | 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 | | - } |
|---|
| 1104 | 1078 | |
|---|
| 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); |
|---|
| 1107 | 1080 | if (IS_ERR(afe->base_addr)) |
|---|
| 1108 | 1081 | return PTR_ERR(afe->base_addr); |
|---|
| 1109 | 1082 | |
|---|
| .. | .. |
|---|
| 1164 | 1137 | if (ret) |
|---|
| 1165 | 1138 | goto err_pm_disable; |
|---|
| 1166 | 1139 | |
|---|
| 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); |
|---|
| 1171 | 1149 | if (ret) |
|---|
| 1172 | 1150 | goto err_pm_disable; |
|---|
| 1173 | 1151 | |
|---|
| 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)); |
|---|
| 1178 | 1159 | if (ret) |
|---|
| 1179 | 1160 | 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 | + } |
|---|
| 1180 | 1190 | |
|---|
| 1181 | 1191 | dev_info(&pdev->dev, "MT8173 AFE driver initialized.\n"); |
|---|
| 1182 | 1192 | return 0; |
|---|
| 1183 | 1193 | |
|---|
| 1194 | +err_cleanup_components: |
|---|
| 1195 | + snd_soc_unregister_component(&pdev->dev); |
|---|
| 1184 | 1196 | err_pm_disable: |
|---|
| 1185 | 1197 | pm_runtime_disable(&pdev->dev); |
|---|
| 1186 | 1198 | return ret; |
|---|
| .. | .. |
|---|
| 1188 | 1200 | |
|---|
| 1189 | 1201 | static int mt8173_afe_pcm_dev_remove(struct platform_device *pdev) |
|---|
| 1190 | 1202 | { |
|---|
| 1203 | + snd_soc_unregister_component(&pdev->dev); |
|---|
| 1204 | + |
|---|
| 1191 | 1205 | pm_runtime_disable(&pdev->dev); |
|---|
| 1192 | 1206 | if (!pm_runtime_status_suspended(&pdev->dev)) |
|---|
| 1193 | 1207 | mt8173_afe_runtime_suspend(&pdev->dev); |
|---|