Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Copyright (C) ST-Ericsson SA 2012
0004  *
0005  * Author: Ola Lilja (ola.o.lilja@stericsson.com)
0006  *         for ST-Ericsson.
0007  */
0008 
0009 #include <asm/mach-types.h>
0010 
0011 #include <linux/module.h>
0012 #include <linux/io.h>
0013 #include <linux/spi/spi.h>
0014 #include <linux/of.h>
0015 
0016 #include <sound/soc.h>
0017 #include <sound/initval.h>
0018 
0019 #include "ux500_pcm.h"
0020 #include "ux500_msp_dai.h"
0021 
0022 #include "mop500_ab8500.h"
0023 
0024 /* Define the whole MOP500 soundcard, linking platform to the codec-drivers  */
0025 SND_SOC_DAILINK_DEFS(link1,
0026     DAILINK_COMP_ARRAY(COMP_CPU("ux500-msp-i2s.1")),
0027     DAILINK_COMP_ARRAY(COMP_CODEC("ab8500-codec.0", "ab8500-codec-dai.0")),
0028     DAILINK_COMP_ARRAY(COMP_PLATFORM("ux500-msp-i2s.1")));
0029 
0030 SND_SOC_DAILINK_DEFS(link2,
0031     DAILINK_COMP_ARRAY(COMP_CPU("ux500-msp-i2s.3")),
0032     DAILINK_COMP_ARRAY(COMP_CODEC("ab8500-codec.0", "ab8500-codec-dai.1")),
0033     DAILINK_COMP_ARRAY(COMP_PLATFORM("ux500-msp-i2s.3")));
0034 
0035 static struct snd_soc_dai_link mop500_dai_links[] = {
0036     {
0037         .name = "ab8500_0",
0038         .stream_name = "ab8500_0",
0039         .init = mop500_ab8500_machine_init,
0040         .ops = mop500_ab8500_ops,
0041         SND_SOC_DAILINK_REG(link1),
0042     },
0043     {
0044         .name = "ab8500_1",
0045         .stream_name = "ab8500_1",
0046         .init = NULL,
0047         .ops = mop500_ab8500_ops,
0048         SND_SOC_DAILINK_REG(link2),
0049     },
0050 };
0051 
0052 static struct snd_soc_card mop500_card = {
0053     .name = "MOP500-card",
0054     .owner = THIS_MODULE,
0055     .probe = NULL,
0056     .dai_link = mop500_dai_links,
0057     .num_links = ARRAY_SIZE(mop500_dai_links),
0058 };
0059 
0060 static void mop500_of_node_put(void)
0061 {
0062     int i;
0063 
0064     for (i = 0; i < 2; i++)
0065         of_node_put(mop500_dai_links[i].cpus->of_node);
0066 
0067     /* Both links use the same codec, which is refcounted only once */
0068     of_node_put(mop500_dai_links[0].codecs->of_node);
0069 }
0070 
0071 static int mop500_of_probe(struct platform_device *pdev,
0072                struct device_node *np)
0073 {
0074     struct device_node *codec_np, *msp_np[2];
0075     int i;
0076 
0077     msp_np[0] = of_parse_phandle(np, "stericsson,cpu-dai", 0);
0078     msp_np[1] = of_parse_phandle(np, "stericsson,cpu-dai", 1);
0079     codec_np  = of_parse_phandle(np, "stericsson,audio-codec", 0);
0080 
0081     if (!(msp_np[0] && msp_np[1] && codec_np)) {
0082         dev_err(&pdev->dev, "Phandle missing or invalid\n");
0083         for (i = 0; i < 2; i++)
0084             of_node_put(msp_np[i]);
0085         of_node_put(codec_np);
0086         return -EINVAL;
0087     }
0088 
0089     for (i = 0; i < 2; i++) {
0090         mop500_dai_links[i].cpus->of_node = msp_np[i];
0091         mop500_dai_links[i].cpus->dai_name = NULL;
0092         mop500_dai_links[i].platforms->of_node = msp_np[i];
0093         mop500_dai_links[i].platforms->name = NULL;
0094         mop500_dai_links[i].codecs->of_node = codec_np;
0095         mop500_dai_links[i].codecs->name = NULL;
0096     }
0097 
0098     snd_soc_of_parse_card_name(&mop500_card, "stericsson,card-name");
0099 
0100     return 0;
0101 }
0102 
0103 static int mop500_probe(struct platform_device *pdev)
0104 {
0105     struct device_node *np = pdev->dev.of_node;
0106     int ret;
0107 
0108     dev_dbg(&pdev->dev, "%s: Enter.\n", __func__);
0109 
0110     mop500_card.dev = &pdev->dev;
0111 
0112     if (np) {
0113         ret = mop500_of_probe(pdev, np);
0114         if (ret)
0115             return ret;
0116     }
0117 
0118     dev_dbg(&pdev->dev, "%s: Card %s: Set platform drvdata.\n",
0119         __func__, mop500_card.name);
0120 
0121     snd_soc_card_set_drvdata(&mop500_card, NULL);
0122 
0123     dev_dbg(&pdev->dev, "%s: Card %s: num_links = %d\n",
0124         __func__, mop500_card.name, mop500_card.num_links);
0125     dev_dbg(&pdev->dev, "%s: Card %s: DAI-link 0: name = %s\n",
0126         __func__, mop500_card.name, mop500_card.dai_link[0].name);
0127     dev_dbg(&pdev->dev, "%s: Card %s: DAI-link 0: stream_name = %s\n",
0128         __func__, mop500_card.name,
0129         mop500_card.dai_link[0].stream_name);
0130 
0131     ret = snd_soc_register_card(&mop500_card);
0132     if (ret)
0133         dev_err(&pdev->dev,
0134             "Error: snd_soc_register_card failed (%d)!\n", ret);
0135 
0136     return ret;
0137 }
0138 
0139 static int mop500_remove(struct platform_device *pdev)
0140 {
0141     struct snd_soc_card *card = platform_get_drvdata(pdev);
0142 
0143     pr_debug("%s: Enter.\n", __func__);
0144 
0145     snd_soc_unregister_card(card);
0146     mop500_ab8500_remove(card);
0147     mop500_of_node_put();
0148 
0149     return 0;
0150 }
0151 
0152 static const struct of_device_id snd_soc_mop500_match[] = {
0153     { .compatible = "stericsson,snd-soc-mop500", },
0154     {},
0155 };
0156 MODULE_DEVICE_TABLE(of, snd_soc_mop500_match);
0157 
0158 static struct platform_driver snd_soc_mop500_driver = {
0159     .driver = {
0160         .name = "snd-soc-mop500",
0161         .of_match_table = snd_soc_mop500_match,
0162     },
0163     .probe = mop500_probe,
0164     .remove = mop500_remove,
0165 };
0166 
0167 module_platform_driver(snd_soc_mop500_driver);
0168 
0169 MODULE_LICENSE("GPL v2");
0170 MODULE_DESCRIPTION("ASoC MOP500 board driver");
0171 MODULE_AUTHOR("Ola Lilja");