ASoC: amd: acp: Add support for splitting the codec specific code from the ACP driver
authorMarian Postevca <posteuca@mutex.one>
Tue, 29 Aug 2023 22:01:15 +0000 (01:01 +0300)
committerMark Brown <broonie@kernel.org>
Mon, 11 Sep 2023 00:24:10 +0000 (01:24 +0100)
This commit adds support for splitting more complicated machine
drivers, that need special handling, from the generic ACP code.

By adding support for callbacks to configure and handle codec
specific implementation details, we can split them in separate
files that don't clutter the ACP code.

Signed-off-by: Marian Postevca <posteuca@mutex.one>
Link: https://lore.kernel.org/r/20230829220116.1159-5-posteuca@mutex.one
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/amd/acp/acp-legacy-mach.c
sound/soc/amd/acp/acp-mach.h

index 6d57d17ddfd77096ff123f3ab7e872fbd20213ab..ba39b4dcdd6d37dfeba34b6cc31d4c8832d3b9d7 100644 (file)
@@ -75,6 +75,33 @@ static struct acp_card_drvdata rt5682s_rt1019_rmb_data = {
        .tdm_mode = false,
 };
 
+static bool acp_asoc_init_ops(struct acp_card_drvdata *priv)
+{
+       return false;
+}
+
+static int acp_asoc_suspend_pre(struct snd_soc_card *card)
+{
+       int ret;
+
+       ret = acp_ops_suspend_pre(card);
+       if (ret == 1)
+               return 0;
+       else
+               return ret;
+}
+
+static int acp_asoc_resume_post(struct snd_soc_card *card)
+{
+       int ret;
+
+       ret = acp_ops_resume_post(card);
+       if (ret == 1)
+               return 0;
+       else
+               return ret;
+}
+
 static int acp_asoc_probe(struct platform_device *pdev)
 {
        struct snd_soc_card *card = NULL;
@@ -83,35 +110,68 @@ static int acp_asoc_probe(struct platform_device *pdev)
        struct acp_card_drvdata *acp_card_drvdata;
        int ret;
 
-       if (!pdev->id_entry)
-               return -EINVAL;
+       if (!pdev->id_entry) {
+               ret = -EINVAL;
+               goto out;
+       }
 
        card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL);
-       if (!card)
-               return -ENOMEM;
+       if (!card) {
+               ret = -ENOMEM;
+               goto out;
+       }
 
+       card->drvdata = (struct acp_card_drvdata *)pdev->id_entry->driver_data;
+       acp_card_drvdata = card->drvdata;
+       acp_card_drvdata->acpi_mach = (struct snd_soc_acpi_mach *)pdev->dev.platform_data;
        card->dev = dev;
        card->owner = THIS_MODULE;
        card->name = pdev->id_entry->name;
-       card->drvdata = (struct acp_card_drvdata *)pdev->id_entry->driver_data;
-       /* Widgets and controls added per-codec in acp-mach-common.c */
 
-       acp_card_drvdata = card->drvdata;
+       acp_asoc_init_ops(card->drvdata);
+
+       /* If widgets and controls are not set in specific callback,
+        * they will be added per-codec in acp-mach-common.c
+        */
+       ret = acp_ops_configure_widgets(card);
+       if (ret < 0) {
+               dev_err(&pdev->dev,
+                       "Cannot configure widgets for card (%s): %d\n",
+                       card->name, ret);
+               goto out;
+       }
+       card->suspend_pre = acp_asoc_suspend_pre;
+       card->resume_post = acp_asoc_resume_post;
+
+       ret = acp_ops_probe(card);
+       if (ret < 0) {
+               dev_err(&pdev->dev,
+                       "Cannot probe card (%s): %d\n",
+                       card->name, ret);
+               goto out;
+       }
+
        dmi_id = dmi_first_match(acp_quirk_table);
        if (dmi_id && dmi_id->driver_data)
                acp_card_drvdata->tdm_mode = dmi_id->driver_data;
 
-       acp_legacy_dai_links_create(card);
+       ret = acp_legacy_dai_links_create(card);
+       if (ret) {
+               dev_err(&pdev->dev,
+                       "Cannot create dai links for card (%s): %d\n",
+                       card->name, ret);
+               goto out;
+       }
 
        ret = devm_snd_soc_register_card(&pdev->dev, card);
        if (ret) {
                dev_err(&pdev->dev,
                                "devm_snd_soc_register_card(%s) failed: %d\n",
                                card->name, ret);
-               return ret;
+               goto out;
        }
-
-       return 0;
+out:
+       return ret;
 }
 
 static const struct platform_device_id board_ids[] = {
index 2b3ec65940230d96255b6860671855b4986ddd0e..8cc33926e66b3749f959382315ee2b49a420d951 100644 (file)
 
 #define TDM_CHANNELS   8
 
+#define ACP_OPS(priv, cb)      ((priv)->ops.cb)
+
+#define acp_get_drvdata(card) ((struct acp_card_drvdata *)(card)->drvdata)
+
 enum be_id {
        HEADSET_BE_ID = 0,
        AMP_BE_ID,
@@ -50,6 +54,14 @@ enum platform_end_point {
        REMBRANDT,
 };
 
+struct acp_mach_ops {
+       int (*probe)(struct snd_soc_card *card);
+       int (*configure_link)(struct snd_soc_card *card, struct snd_soc_dai_link *dai_link);
+       int (*configure_widgets)(struct snd_soc_card *card);
+       int (*suspend_pre)(struct snd_soc_card *card);
+       int (*resume_post)(struct snd_soc_card *card);
+};
+
 struct acp_card_drvdata {
        unsigned int hs_cpu_id;
        unsigned int amp_cpu_id;
@@ -61,6 +73,9 @@ struct acp_card_drvdata {
        unsigned int platform;
        struct clk *wclk;
        struct clk *bclk;
+       struct acp_mach_ops ops;
+       struct snd_soc_acpi_mach *acpi_mach;
+       void *mach_priv;
        bool soc_mclk;
        bool tdm_mode;
 };
@@ -69,4 +84,55 @@ int acp_sofdsp_dai_links_create(struct snd_soc_card *card);
 int acp_legacy_dai_links_create(struct snd_soc_card *card);
 extern const struct dmi_system_id acp_quirk_table[];
 
+static inline int acp_ops_probe(struct snd_soc_card *card)
+{
+       int ret = 1;
+       struct acp_card_drvdata *priv = acp_get_drvdata(card);
+
+       if (ACP_OPS(priv, probe))
+               ret = ACP_OPS(priv, probe)(card);
+       return ret;
+}
+
+static inline int acp_ops_configure_link(struct snd_soc_card *card,
+                                        struct snd_soc_dai_link *dai_link)
+{
+       int ret = 1;
+       struct acp_card_drvdata *priv = acp_get_drvdata(card);
+
+       if (ACP_OPS(priv, configure_link))
+               ret = ACP_OPS(priv, configure_link)(card, dai_link);
+       return ret;
+}
+
+static inline int acp_ops_configure_widgets(struct snd_soc_card *card)
+{
+       int ret = 1;
+       struct acp_card_drvdata *priv = acp_get_drvdata(card);
+
+       if (ACP_OPS(priv, configure_widgets))
+               ret = ACP_OPS(priv, configure_widgets)(card);
+       return ret;
+}
+
+static inline int acp_ops_suspend_pre(struct snd_soc_card *card)
+{
+       int ret = 1;
+       struct acp_card_drvdata *priv = acp_get_drvdata(card);
+
+       if (ACP_OPS(priv, suspend_pre))
+               ret = ACP_OPS(priv, suspend_pre)(card);
+       return ret;
+}
+
+static inline int acp_ops_resume_post(struct snd_soc_card *card)
+{
+       int ret = 1;
+       struct acp_card_drvdata *priv = acp_get_drvdata(card);
+
+       if (ACP_OPS(priv, resume_post))
+               ret = ACP_OPS(priv, resume_post)(card);
+       return ret;
+}
+
 #endif