Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0+
0002 //
0003 // Copyright (C) 2013 Freescale Semiconductor, Inc.
0004 
0005 #include <linux/module.h>
0006 #include <linux/of_platform.h>
0007 #include <sound/soc.h>
0008 
0009 struct imx_spdif_data {
0010     struct snd_soc_dai_link dai;
0011     struct snd_soc_card card;
0012 };
0013 
0014 static int imx_spdif_audio_probe(struct platform_device *pdev)
0015 {
0016     struct device_node *spdif_np, *np = pdev->dev.of_node;
0017     struct imx_spdif_data *data;
0018     struct snd_soc_dai_link_component *comp;
0019     int ret = 0;
0020 
0021     spdif_np = of_parse_phandle(np, "spdif-controller", 0);
0022     if (!spdif_np) {
0023         dev_err(&pdev->dev, "failed to find spdif-controller\n");
0024         ret = -EINVAL;
0025         goto end;
0026     }
0027 
0028     data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
0029     comp = devm_kzalloc(&pdev->dev, 3 * sizeof(*comp), GFP_KERNEL);
0030     if (!data || !comp) {
0031         ret = -ENOMEM;
0032         goto end;
0033     }
0034 
0035     data->dai.cpus      = &comp[0];
0036     data->dai.codecs    = &comp[1];
0037     data->dai.platforms = &comp[2];
0038 
0039     data->dai.num_cpus  = 1;
0040     data->dai.num_codecs    = 1;
0041     data->dai.num_platforms = 1;
0042 
0043     data->dai.name = "S/PDIF PCM";
0044     data->dai.stream_name = "S/PDIF PCM";
0045     data->dai.codecs->dai_name = "snd-soc-dummy-dai";
0046     data->dai.codecs->name = "snd-soc-dummy";
0047     data->dai.cpus->of_node = spdif_np;
0048     data->dai.platforms->of_node = spdif_np;
0049     data->dai.playback_only = true;
0050     data->dai.capture_only = true;
0051 
0052     if (of_property_read_bool(np, "spdif-out"))
0053         data->dai.capture_only = false;
0054 
0055     if (of_property_read_bool(np, "spdif-in"))
0056         data->dai.playback_only = false;
0057 
0058     if (data->dai.playback_only && data->dai.capture_only) {
0059         dev_err(&pdev->dev, "no enabled S/PDIF DAI link\n");
0060         goto end;
0061     }
0062 
0063     data->card.dev = &pdev->dev;
0064     data->card.dai_link = &data->dai;
0065     data->card.num_links = 1;
0066     data->card.owner = THIS_MODULE;
0067 
0068     ret = snd_soc_of_parse_card_name(&data->card, "model");
0069     if (ret)
0070         goto end;
0071 
0072     ret = devm_snd_soc_register_card(&pdev->dev, &data->card);
0073     if (ret)
0074         dev_err_probe(&pdev->dev, ret, "snd_soc_register_card failed\n");
0075 
0076 end:
0077     of_node_put(spdif_np);
0078 
0079     return ret;
0080 }
0081 
0082 static const struct of_device_id imx_spdif_dt_ids[] = {
0083     { .compatible = "fsl,imx-audio-spdif", },
0084     { /* sentinel */ }
0085 };
0086 MODULE_DEVICE_TABLE(of, imx_spdif_dt_ids);
0087 
0088 static struct platform_driver imx_spdif_driver = {
0089     .driver = {
0090         .name = "imx-spdif",
0091         .pm = &snd_soc_pm_ops,
0092         .of_match_table = imx_spdif_dt_ids,
0093     },
0094     .probe = imx_spdif_audio_probe,
0095 };
0096 
0097 module_platform_driver(imx_spdif_driver);
0098 
0099 MODULE_AUTHOR("Freescale Semiconductor, Inc.");
0100 MODULE_DESCRIPTION("Freescale i.MX S/PDIF machine driver");
0101 MODULE_LICENSE("GPL v2");
0102 MODULE_ALIAS("platform:imx-spdif");