/* * SoC audio for i.MX boards with tda1997x HDMI receiver * based off sound/soc/fsl/imx-sgtl5000.c * * Copyright 2013 Tim Harvey, Gateworks Corporation * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #include #include #include #include #include #include #include #include #include "imx-audmux.h" #define DAI_NAME_SIZE 32 struct imx_tda1997x_data { struct snd_soc_dai_link dai; struct snd_soc_card card; char codec_dai_name[DAI_NAME_SIZE]; char platform_name[DAI_NAME_SIZE]; }; static int imx_tda1997x_dai_init(struct snd_soc_pcm_runtime *rtd) { return 0; } static int imx_tda1997x_audmux_config(struct platform_device *pdev) { struct device_node *np = pdev->dev.of_node; int int_port, ext_port; int ret; ret = of_property_read_u32(np, "mux-int-port", &int_port); if (ret) { dev_err(&pdev->dev, "mux-int-port missing or invalid\n"); return ret; } ret = of_property_read_u32(np, "mux-ext-port", &ext_port); if (ret) { dev_err(&pdev->dev, "mux-ext-port missing or invalid\n"); return ret; } /* * The port numbering in the hardware manual starts at 1, while * the audmux API expects it starts at 0. */ int_port--; ext_port--; ret = imx_audmux_v2_configure_port(int_port, IMX_AUDMUX_V2_PTCR_SYN | IMX_AUDMUX_V2_PTCR_TFSEL(ext_port) | IMX_AUDMUX_V2_PTCR_TCSEL(ext_port) | IMX_AUDMUX_V2_PTCR_TFSDIR | IMX_AUDMUX_V2_PTCR_TCLKDIR | (1<<30) | /* use RXFS from port instead of TXFS */ (1<<25), /* use RXC from port instead of TXC */ IMX_AUDMUX_V2_PDCR_RXDSEL(ext_port)); if (ret) { dev_err(&pdev->dev, "audmux internal port setup failed\n"); return ret; } ret = imx_audmux_v2_configure_port(ext_port, IMX_AUDMUX_V2_PTCR_SYN, IMX_AUDMUX_V2_PDCR_RXDSEL(int_port)); if (ret) { dev_err(&pdev->dev, "audmux external port setup failed\n"); return ret; } return 0; } static int imx_tda1997x_probe(struct platform_device *pdev) { struct device_node *cpu_np, *codec_np; struct platform_device *cpu_pdev; struct imx_tda1997x_data *data; int ret; cpu_np = of_parse_phandle(pdev->dev.of_node, "cpu-dai", 0); codec_np = of_parse_phandle(pdev->dev.of_node, "audio-codec", 0); if (!cpu_np || !codec_np) { dev_err(&pdev->dev, "phandle missing or invalid\n"); ret = -EINVAL; goto fail; } if (strstr(cpu_np->name, "ssi")) { ret = imx_tda1997x_audmux_config(pdev); if (ret) goto fail; } cpu_pdev = of_find_device_by_node(cpu_np); if (!cpu_pdev) { dev_err(&pdev->dev, "failed to find SSI platform device\n"); ret = -EINVAL; goto fail; } data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); if (!data) { ret = -ENOMEM; goto fail; } data->dai.name = "i.MX HDMI Audio Rx"; data->dai.stream_name = "i.MX HDMI Audio Rx"; data->dai.codec_dai_name = "tda1997x"; data->dai.codec_of_node = codec_np; data->dai.cpu_of_node = cpu_np; data->dai.platform_of_node = cpu_np; data->dai.init = &imx_tda1997x_dai_init; data->dai.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM; data->card.dev = &pdev->dev; ret = snd_soc_of_parse_card_name(&data->card, "model"); if (ret) goto fail; data->card.num_links = 1; data->card.owner = THIS_MODULE; data->card.dai_link = &data->dai; /* register card with ASoC core */ ret = snd_soc_register_card(&data->card); if (ret) { dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret); goto fail; } platform_set_drvdata(pdev, data); fail: if (cpu_np) of_node_put(cpu_np); if (codec_np) of_node_put(codec_np); return ret; } static int imx_tda1997x_remove(struct platform_device *pdev) { struct imx_tda1997x_data *data = platform_get_drvdata(pdev); snd_soc_unregister_card(&data->card); return 0; } static const struct of_device_id imx_tda1997x_dt_ids[] = { { .compatible = "fsl,imx-audio-tda1997x", }, { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, imx_tda1997x_dt_ids); static struct platform_driver imx_tda1997x_audio_driver = { .driver = { .name = "imx-tda1997x-audio", .owner = THIS_MODULE, .of_match_table = imx_tda1997x_dt_ids, }, .probe = imx_tda1997x_probe, .remove = imx_tda1997x_remove, }; module_platform_driver(imx_tda1997x_audio_driver); MODULE_AUTHOR("Tim Harvey "); MODULE_DESCRIPTION("Freescale i.MX TDA1997X RX ASoC machine driver"); MODULE_LICENSE("GPL v2"); MODULE_ALIAS("platform:imx-tda1997x-audio");