Nicolin Chen | 2a956ec | 2013-08-28 12:04:46 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 Freescale Semiconductor, Inc. |
| 3 | * |
| 4 | * The code contained herein is licensed under the GNU General Public |
| 5 | * License. You may obtain a copy of the GNU General Public License |
| 6 | * Version 2 or later at the following locations: |
| 7 | * |
| 8 | * http://www.opensource.org/licenses/gpl-license.html |
| 9 | * http://www.gnu.org/copyleft/gpl.html |
| 10 | */ |
| 11 | |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/of_platform.h> |
| 14 | #include <sound/soc.h> |
| 15 | |
| 16 | struct imx_spdif_data { |
Nicolin Chen | 14c3aa9 | 2013-12-23 17:28:53 +0800 | [diff] [blame] | 17 | struct snd_soc_dai_link dai; |
Nicolin Chen | 2a956ec | 2013-08-28 12:04:46 +0800 | [diff] [blame] | 18 | struct snd_soc_card card; |
Nicolin Chen | 2a956ec | 2013-08-28 12:04:46 +0800 | [diff] [blame] | 19 | }; |
| 20 | |
| 21 | static int imx_spdif_audio_probe(struct platform_device *pdev) |
| 22 | { |
| 23 | struct device_node *spdif_np, *np = pdev->dev.of_node; |
| 24 | struct imx_spdif_data *data; |
Nicolin Chen | 14c3aa9 | 2013-12-23 17:28:53 +0800 | [diff] [blame] | 25 | int ret = 0; |
Nicolin Chen | 2a956ec | 2013-08-28 12:04:46 +0800 | [diff] [blame] | 26 | |
| 27 | spdif_np = of_parse_phandle(np, "spdif-controller", 0); |
| 28 | if (!spdif_np) { |
| 29 | dev_err(&pdev->dev, "failed to find spdif-controller\n"); |
| 30 | ret = -EINVAL; |
| 31 | goto end; |
| 32 | } |
| 33 | |
| 34 | data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); |
| 35 | if (!data) { |
Nicolin Chen | 2a956ec | 2013-08-28 12:04:46 +0800 | [diff] [blame] | 36 | ret = -ENOMEM; |
| 37 | goto end; |
| 38 | } |
| 39 | |
Nicolin Chen | 14c3aa9 | 2013-12-23 17:28:53 +0800 | [diff] [blame] | 40 | data->dai.name = "S/PDIF PCM"; |
| 41 | data->dai.stream_name = "S/PDIF PCM"; |
| 42 | data->dai.codec_dai_name = "snd-soc-dummy-dai"; |
| 43 | data->dai.codec_name = "snd-soc-dummy"; |
| 44 | data->dai.cpu_of_node = spdif_np; |
| 45 | data->dai.platform_of_node = spdif_np; |
| 46 | data->dai.playback_only = true; |
| 47 | data->dai.capture_only = true; |
Nicolin Chen | 2a956ec | 2013-08-28 12:04:46 +0800 | [diff] [blame] | 48 | |
Nicolin Chen | 14c3aa9 | 2013-12-23 17:28:53 +0800 | [diff] [blame] | 49 | if (of_property_read_bool(np, "spdif-out")) |
| 50 | data->dai.capture_only = false; |
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-in")) |
| 53 | data->dai.playback_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 (data->dai.playback_only && data->dai.capture_only) { |
Nicolin Chen | 2a956ec | 2013-08-28 12:04:46 +0800 | [diff] [blame] | 56 | dev_err(&pdev->dev, "no enabled S/PDIF DAI link\n"); |
Nicolin Chen | 14c3aa9 | 2013-12-23 17:28:53 +0800 | [diff] [blame] | 57 | goto end; |
Nicolin Chen | 2a956ec | 2013-08-28 12:04:46 +0800 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | data->card.dev = &pdev->dev; |
Nicolin Chen | 14c3aa9 | 2013-12-23 17:28:53 +0800 | [diff] [blame] | 61 | data->card.dai_link = &data->dai; |
| 62 | data->card.num_links = 1; |
Fabio Estevam | 7a3a907 | 2015-01-14 16:39:15 -0200 | [diff] [blame] | 63 | data->card.owner = THIS_MODULE; |
Nicolin Chen | 2a956ec | 2013-08-28 12:04:46 +0800 | [diff] [blame] | 64 | |
| 65 | ret = snd_soc_of_parse_card_name(&data->card, "model"); |
| 66 | if (ret) |
Nicolin Chen | 14c3aa9 | 2013-12-23 17:28:53 +0800 | [diff] [blame] | 67 | goto end; |
Nicolin Chen | 2a956ec | 2013-08-28 12:04:46 +0800 | [diff] [blame] | 68 | |
Sachin Kamat | ff27d9b | 2013-09-17 09:42:47 +0530 | [diff] [blame] | 69 | ret = devm_snd_soc_register_card(&pdev->dev, &data->card); |
Nicolin Chen | 2a956ec | 2013-08-28 12:04:46 +0800 | [diff] [blame] | 70 | if (ret) { |
| 71 | dev_err(&pdev->dev, "snd_soc_register_card failed: %d\n", ret); |
Nicolin Chen | 14c3aa9 | 2013-12-23 17:28:53 +0800 | [diff] [blame] | 72 | goto end; |
Nicolin Chen | 2a956ec | 2013-08-28 12:04:46 +0800 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | platform_set_drvdata(pdev, data); |
| 76 | |
Nicolin Chen | 2a956ec | 2013-08-28 12:04:46 +0800 | [diff] [blame] | 77 | end: |
Fabio Estevam | aa4ac92 | 2014-10-07 15:29:56 -0300 | [diff] [blame] | 78 | of_node_put(spdif_np); |
Nicolin Chen | 2a956ec | 2013-08-28 12:04:46 +0800 | [diff] [blame] | 79 | |
| 80 | return ret; |
| 81 | } |
| 82 | |
Nicolin Chen | 2a956ec | 2013-08-28 12:04:46 +0800 | [diff] [blame] | 83 | static const struct of_device_id imx_spdif_dt_ids[] = { |
| 84 | { .compatible = "fsl,imx-audio-spdif", }, |
| 85 | { /* sentinel */ } |
| 86 | }; |
| 87 | MODULE_DEVICE_TABLE(of, imx_spdif_dt_ids); |
| 88 | |
| 89 | static struct platform_driver imx_spdif_driver = { |
| 90 | .driver = { |
| 91 | .name = "imx-spdif", |
Zidan Wang | 43ac946 | 2015-09-18 17:18:48 +0800 | [diff] [blame] | 92 | .pm = &snd_soc_pm_ops, |
Nicolin Chen | 2a956ec | 2013-08-28 12:04:46 +0800 | [diff] [blame] | 93 | .of_match_table = imx_spdif_dt_ids, |
| 94 | }, |
| 95 | .probe = imx_spdif_audio_probe, |
Nicolin Chen | 2a956ec | 2013-08-28 12:04:46 +0800 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | module_platform_driver(imx_spdif_driver); |
| 99 | |
| 100 | MODULE_AUTHOR("Freescale Semiconductor, Inc."); |
| 101 | MODULE_DESCRIPTION("Freescale i.MX S/PDIF machine driver"); |
| 102 | MODULE_LICENSE("GPL v2"); |
| 103 | MODULE_ALIAS("platform:imx-spdif"); |