Andra Danciu | 58dbd10 | 2019-04-05 14:49:59 +0300 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | // |
| 3 | // Copyright (C) 2013 Freescale Semiconductor, Inc. |
Nicolin Chen | 2a956ec | 2013-08-28 12:04:46 +0800 | [diff] [blame] | 4 | |
| 5 | #include <linux/module.h> |
| 6 | #include <linux/of_platform.h> |
| 7 | #include <sound/soc.h> |
| 8 | |
| 9 | struct imx_spdif_data { |
Nicolin Chen | 14c3aa9 | 2013-12-23 17:28:53 +0800 | [diff] [blame] | 10 | struct snd_soc_dai_link dai; |
Nicolin Chen | 2a956ec | 2013-08-28 12:04:46 +0800 | [diff] [blame] | 11 | struct snd_soc_card card; |
Nicolin Chen | 2a956ec | 2013-08-28 12:04:46 +0800 | [diff] [blame] | 12 | }; |
| 13 | |
| 14 | static int imx_spdif_audio_probe(struct platform_device *pdev) |
| 15 | { |
| 16 | struct device_node *spdif_np, *np = pdev->dev.of_node; |
| 17 | struct imx_spdif_data *data; |
Kuninori Morimoto | 8337ef4 | 2019-06-06 13:14:38 +0900 | [diff] [blame] | 18 | struct snd_soc_dai_link_component *comp; |
Nicolin Chen | 14c3aa9 | 2013-12-23 17:28:53 +0800 | [diff] [blame] | 19 | int ret = 0; |
Nicolin Chen | 2a956ec | 2013-08-28 12:04:46 +0800 | [diff] [blame] | 20 | |
| 21 | spdif_np = of_parse_phandle(np, "spdif-controller", 0); |
| 22 | if (!spdif_np) { |
| 23 | dev_err(&pdev->dev, "failed to find spdif-controller\n"); |
| 24 | ret = -EINVAL; |
| 25 | goto end; |
| 26 | } |
| 27 | |
| 28 | data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); |
Kuninori Morimoto | 9e8f529 | 2019-06-28 10:47:30 +0900 | [diff] [blame] | 29 | comp = devm_kzalloc(&pdev->dev, 3 * sizeof(*comp), GFP_KERNEL); |
Kuninori Morimoto | 8337ef4 | 2019-06-06 13:14:38 +0900 | [diff] [blame] | 30 | if (!data || !comp) { |
Nicolin Chen | 2a956ec | 2013-08-28 12:04:46 +0800 | [diff] [blame] | 31 | ret = -ENOMEM; |
| 32 | goto end; |
| 33 | } |
| 34 | |
Kuninori Morimoto | 8337ef4 | 2019-06-06 13:14:38 +0900 | [diff] [blame] | 35 | data->dai.cpus = &comp[0]; |
| 36 | data->dai.codecs = &comp[1]; |
Kuninori Morimoto | 9e8f529 | 2019-06-28 10:47:30 +0900 | [diff] [blame] | 37 | data->dai.platforms = &comp[2]; |
Kuninori Morimoto | 8337ef4 | 2019-06-06 13:14:38 +0900 | [diff] [blame] | 38 | |
| 39 | data->dai.num_cpus = 1; |
| 40 | data->dai.num_codecs = 1; |
Kuninori Morimoto | 9e8f529 | 2019-06-28 10:47:30 +0900 | [diff] [blame] | 41 | data->dai.num_platforms = 1; |
Kuninori Morimoto | 8337ef4 | 2019-06-06 13:14:38 +0900 | [diff] [blame] | 42 | |
Nicolin Chen | 14c3aa9 | 2013-12-23 17:28:53 +0800 | [diff] [blame] | 43 | data->dai.name = "S/PDIF PCM"; |
| 44 | data->dai.stream_name = "S/PDIF PCM"; |
Kuninori Morimoto | 8337ef4 | 2019-06-06 13:14:38 +0900 | [diff] [blame] | 45 | data->dai.codecs->dai_name = "snd-soc-dummy-dai"; |
| 46 | data->dai.codecs->name = "snd-soc-dummy"; |
| 47 | data->dai.cpus->of_node = spdif_np; |
Kuninori Morimoto | 9e8f529 | 2019-06-28 10:47:30 +0900 | [diff] [blame] | 48 | data->dai.platforms->of_node = spdif_np; |
Nicolin Chen | 14c3aa9 | 2013-12-23 17:28:53 +0800 | [diff] [blame] | 49 | data->dai.playback_only = true; |
| 50 | data->dai.capture_only = true; |
Nicolin Chen | 2a956ec | 2013-08-28 12:04:46 +0800 | [diff] [blame] | 51 | |
Nicolin Chen | 14c3aa9 | 2013-12-23 17:28:53 +0800 | [diff] [blame] | 52 | if (of_property_read_bool(np, "spdif-out")) |
| 53 | data->dai.capture_only = false; |
Nicolin Chen | 2a956ec | 2013-08-28 12:04:46 +0800 | [diff] [blame] | 54 | |
Nicolin Chen | 14c3aa9 | 2013-12-23 17:28:53 +0800 | [diff] [blame] | 55 | if (of_property_read_bool(np, "spdif-in")) |
| 56 | data->dai.playback_only = false; |
Nicolin Chen | 2a956ec | 2013-08-28 12:04:46 +0800 | [diff] [blame] | 57 | |
Nicolin Chen | 14c3aa9 | 2013-12-23 17:28:53 +0800 | [diff] [blame] | 58 | if (data->dai.playback_only && data->dai.capture_only) { |
Nicolin Chen | 2a956ec | 2013-08-28 12:04:46 +0800 | [diff] [blame] | 59 | dev_err(&pdev->dev, "no enabled S/PDIF DAI link\n"); |
Nicolin Chen | 14c3aa9 | 2013-12-23 17:28:53 +0800 | [diff] [blame] | 60 | goto end; |
Nicolin Chen | 2a956ec | 2013-08-28 12:04:46 +0800 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | data->card.dev = &pdev->dev; |
Nicolin Chen | 14c3aa9 | 2013-12-23 17:28:53 +0800 | [diff] [blame] | 64 | data->card.dai_link = &data->dai; |
| 65 | data->card.num_links = 1; |
Fabio Estevam | 7a3a907 | 2015-01-14 16:39:15 -0200 | [diff] [blame] | 66 | data->card.owner = THIS_MODULE; |
Nicolin Chen | 2a956ec | 2013-08-28 12:04:46 +0800 | [diff] [blame] | 67 | |
| 68 | ret = snd_soc_of_parse_card_name(&data->card, "model"); |
| 69 | if (ret) |
Nicolin Chen | 14c3aa9 | 2013-12-23 17:28:53 +0800 | [diff] [blame] | 70 | goto end; |
Nicolin Chen | 2a956ec | 2013-08-28 12:04:46 +0800 | [diff] [blame] | 71 | |
Sachin Kamat | ff27d9b | 2013-09-17 09:42:47 +0530 | [diff] [blame] | 72 | ret = devm_snd_soc_register_card(&pdev->dev, &data->card); |
Kuninori Morimoto | 2e6f557 | 2021-12-14 11:08:34 +0900 | [diff] [blame] | 73 | if (ret) |
| 74 | dev_err_probe(&pdev->dev, ret, "snd_soc_register_card failed\n"); |
Nicolin Chen | 2a956ec | 2013-08-28 12:04:46 +0800 | [diff] [blame] | 75 | |
Nicolin Chen | 2a956ec | 2013-08-28 12:04:46 +0800 | [diff] [blame] | 76 | end: |
Fabio Estevam | aa4ac92 | 2014-10-07 15:29:56 -0300 | [diff] [blame] | 77 | of_node_put(spdif_np); |
Nicolin Chen | 2a956ec | 2013-08-28 12:04:46 +0800 | [diff] [blame] | 78 | |
| 79 | return ret; |
| 80 | } |
| 81 | |
Nicolin Chen | 2a956ec | 2013-08-28 12:04:46 +0800 | [diff] [blame] | 82 | static const struct of_device_id imx_spdif_dt_ids[] = { |
| 83 | { .compatible = "fsl,imx-audio-spdif", }, |
| 84 | { /* sentinel */ } |
| 85 | }; |
| 86 | MODULE_DEVICE_TABLE(of, imx_spdif_dt_ids); |
| 87 | |
| 88 | static struct platform_driver imx_spdif_driver = { |
| 89 | .driver = { |
| 90 | .name = "imx-spdif", |
Zidan Wang | 43ac946 | 2015-09-18 17:18:48 +0800 | [diff] [blame] | 91 | .pm = &snd_soc_pm_ops, |
Nicolin Chen | 2a956ec | 2013-08-28 12:04:46 +0800 | [diff] [blame] | 92 | .of_match_table = imx_spdif_dt_ids, |
| 93 | }, |
| 94 | .probe = imx_spdif_audio_probe, |
Nicolin Chen | 2a956ec | 2013-08-28 12:04:46 +0800 | [diff] [blame] | 95 | }; |
| 96 | |
| 97 | module_platform_driver(imx_spdif_driver); |
| 98 | |
| 99 | MODULE_AUTHOR("Freescale Semiconductor, Inc."); |
| 100 | MODULE_DESCRIPTION("Freescale i.MX S/PDIF machine driver"); |
| 101 | MODULE_LICENSE("GPL v2"); |
| 102 | MODULE_ALIAS("platform:imx-spdif"); |