18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0+ 28c2ecf20Sopenharmony_ci// 38c2ecf20Sopenharmony_ci// imx-mc13783.c -- SoC audio for imx based boards with mc13783 codec 48c2ecf20Sopenharmony_ci// 58c2ecf20Sopenharmony_ci// Copyright 2012 Philippe Retornaz, <philippe.retornaz@epfl.ch> 68c2ecf20Sopenharmony_ci// 78c2ecf20Sopenharmony_ci// Heavly based on phycore-mc13783: 88c2ecf20Sopenharmony_ci// Copyright 2009 Sascha Hauer, Pengutronix <s.hauer@pengutronix.de> 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#include <linux/module.h> 118c2ecf20Sopenharmony_ci#include <linux/moduleparam.h> 128c2ecf20Sopenharmony_ci#include <linux/device.h> 138c2ecf20Sopenharmony_ci#include <sound/core.h> 148c2ecf20Sopenharmony_ci#include <sound/pcm.h> 158c2ecf20Sopenharmony_ci#include <sound/soc.h> 168c2ecf20Sopenharmony_ci#include <sound/soc-dapm.h> 178c2ecf20Sopenharmony_ci#include <asm/mach-types.h> 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci#include "../codecs/mc13783.h" 208c2ecf20Sopenharmony_ci#include "imx-ssi.h" 218c2ecf20Sopenharmony_ci#include "imx-audmux.h" 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci#define FMT_SSI (SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_NB_NF | \ 248c2ecf20Sopenharmony_ci SND_SOC_DAIFMT_CBM_CFM) 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_cistatic int imx_mc13783_hifi_hw_params(struct snd_pcm_substream *substream, 278c2ecf20Sopenharmony_ci struct snd_pcm_hw_params *params) 288c2ecf20Sopenharmony_ci{ 298c2ecf20Sopenharmony_ci struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); 308c2ecf20Sopenharmony_ci struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0); 318c2ecf20Sopenharmony_ci struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0); 328c2ecf20Sopenharmony_ci int ret; 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x3, 0x3, 4, 16); 358c2ecf20Sopenharmony_ci if (ret) 368c2ecf20Sopenharmony_ci return ret; 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci ret = snd_soc_dai_set_sysclk(codec_dai, MC13783_CLK_CLIA, 26000000, 0); 398c2ecf20Sopenharmony_ci if (ret) 408c2ecf20Sopenharmony_ci return ret; 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci return snd_soc_dai_set_tdm_slot(cpu_dai, 0x3, 0x3, 2, 16); 438c2ecf20Sopenharmony_ci} 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_cistatic const struct snd_soc_ops imx_mc13783_hifi_ops = { 468c2ecf20Sopenharmony_ci .hw_params = imx_mc13783_hifi_hw_params, 478c2ecf20Sopenharmony_ci}; 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ciSND_SOC_DAILINK_DEFS(hifi, 508c2ecf20Sopenharmony_ci DAILINK_COMP_ARRAY(COMP_CPU("imx-ssi.0")), 518c2ecf20Sopenharmony_ci DAILINK_COMP_ARRAY(COMP_CODEC("mc13783-codec", "mc13783-hifi")), 528c2ecf20Sopenharmony_ci DAILINK_COMP_ARRAY(COMP_PLATFORM("imx-ssi.0"))); 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_cistatic struct snd_soc_dai_link imx_mc13783_dai_mc13783[] = { 558c2ecf20Sopenharmony_ci { 568c2ecf20Sopenharmony_ci .name = "MC13783", 578c2ecf20Sopenharmony_ci .stream_name = "Sound", 588c2ecf20Sopenharmony_ci .ops = &imx_mc13783_hifi_ops, 598c2ecf20Sopenharmony_ci .symmetric_rates = 1, 608c2ecf20Sopenharmony_ci .dai_fmt = FMT_SSI, 618c2ecf20Sopenharmony_ci SND_SOC_DAILINK_REG(hifi), 628c2ecf20Sopenharmony_ci }, 638c2ecf20Sopenharmony_ci}; 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_cistatic const struct snd_soc_dapm_widget imx_mc13783_widget[] = { 668c2ecf20Sopenharmony_ci SND_SOC_DAPM_MIC("Mic", NULL), 678c2ecf20Sopenharmony_ci SND_SOC_DAPM_HP("Headphone", NULL), 688c2ecf20Sopenharmony_ci SND_SOC_DAPM_SPK("Speaker", NULL), 698c2ecf20Sopenharmony_ci}; 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_cistatic const struct snd_soc_dapm_route imx_mc13783_routes[] = { 728c2ecf20Sopenharmony_ci {"Speaker", NULL, "LSP"}, 738c2ecf20Sopenharmony_ci {"Headphone", NULL, "HSL"}, 748c2ecf20Sopenharmony_ci {"Headphone", NULL, "HSR"}, 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci {"MC1LIN", NULL, "MC1 Bias"}, 778c2ecf20Sopenharmony_ci {"MC2IN", NULL, "MC2 Bias"}, 788c2ecf20Sopenharmony_ci {"MC1 Bias", NULL, "Mic"}, 798c2ecf20Sopenharmony_ci {"MC2 Bias", NULL, "Mic"}, 808c2ecf20Sopenharmony_ci}; 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_cistatic struct snd_soc_card imx_mc13783 = { 838c2ecf20Sopenharmony_ci .name = "imx_mc13783", 848c2ecf20Sopenharmony_ci .owner = THIS_MODULE, 858c2ecf20Sopenharmony_ci .dai_link = imx_mc13783_dai_mc13783, 868c2ecf20Sopenharmony_ci .num_links = ARRAY_SIZE(imx_mc13783_dai_mc13783), 878c2ecf20Sopenharmony_ci .dapm_widgets = imx_mc13783_widget, 888c2ecf20Sopenharmony_ci .num_dapm_widgets = ARRAY_SIZE(imx_mc13783_widget), 898c2ecf20Sopenharmony_ci .dapm_routes = imx_mc13783_routes, 908c2ecf20Sopenharmony_ci .num_dapm_routes = ARRAY_SIZE(imx_mc13783_routes), 918c2ecf20Sopenharmony_ci}; 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_cistatic int imx_mc13783_probe(struct platform_device *pdev) 948c2ecf20Sopenharmony_ci{ 958c2ecf20Sopenharmony_ci int ret; 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_ci imx_mc13783.dev = &pdev->dev; 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ci ret = devm_snd_soc_register_card(&pdev->dev, &imx_mc13783); 1008c2ecf20Sopenharmony_ci if (ret) { 1018c2ecf20Sopenharmony_ci dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", 1028c2ecf20Sopenharmony_ci ret); 1038c2ecf20Sopenharmony_ci return ret; 1048c2ecf20Sopenharmony_ci } 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_ci if (machine_is_mx31_3ds() || machine_is_mx31moboard()) { 1078c2ecf20Sopenharmony_ci imx_audmux_v2_configure_port(MX31_AUDMUX_PORT4_SSI_PINS_4, 1088c2ecf20Sopenharmony_ci IMX_AUDMUX_V2_PTCR_SYN, 1098c2ecf20Sopenharmony_ci IMX_AUDMUX_V2_PDCR_RXDSEL(MX31_AUDMUX_PORT1_SSI0) | 1108c2ecf20Sopenharmony_ci IMX_AUDMUX_V2_PDCR_MODE(1) | 1118c2ecf20Sopenharmony_ci IMX_AUDMUX_V2_PDCR_INMMASK(0xfc)); 1128c2ecf20Sopenharmony_ci imx_audmux_v2_configure_port(MX31_AUDMUX_PORT1_SSI0, 1138c2ecf20Sopenharmony_ci IMX_AUDMUX_V2_PTCR_SYN | 1148c2ecf20Sopenharmony_ci IMX_AUDMUX_V2_PTCR_TFSDIR | 1158c2ecf20Sopenharmony_ci IMX_AUDMUX_V2_PTCR_TFSEL(MX31_AUDMUX_PORT4_SSI_PINS_4) | 1168c2ecf20Sopenharmony_ci IMX_AUDMUX_V2_PTCR_TCLKDIR | 1178c2ecf20Sopenharmony_ci IMX_AUDMUX_V2_PTCR_TCSEL(MX31_AUDMUX_PORT4_SSI_PINS_4) | 1188c2ecf20Sopenharmony_ci IMX_AUDMUX_V2_PTCR_RFSDIR | 1198c2ecf20Sopenharmony_ci IMX_AUDMUX_V2_PTCR_RFSEL(MX31_AUDMUX_PORT4_SSI_PINS_4) | 1208c2ecf20Sopenharmony_ci IMX_AUDMUX_V2_PTCR_RCLKDIR | 1218c2ecf20Sopenharmony_ci IMX_AUDMUX_V2_PTCR_RCSEL(MX31_AUDMUX_PORT4_SSI_PINS_4), 1228c2ecf20Sopenharmony_ci IMX_AUDMUX_V2_PDCR_RXDSEL(MX31_AUDMUX_PORT4_SSI_PINS_4)); 1238c2ecf20Sopenharmony_ci } else if (machine_is_mx27_3ds()) { 1248c2ecf20Sopenharmony_ci imx_audmux_v1_configure_port(MX27_AUDMUX_HPCR1_SSI0, 1258c2ecf20Sopenharmony_ci IMX_AUDMUX_V1_PCR_SYN | 1268c2ecf20Sopenharmony_ci IMX_AUDMUX_V1_PCR_TFSDIR | 1278c2ecf20Sopenharmony_ci IMX_AUDMUX_V1_PCR_TCLKDIR | 1288c2ecf20Sopenharmony_ci IMX_AUDMUX_V1_PCR_RFSDIR | 1298c2ecf20Sopenharmony_ci IMX_AUDMUX_V1_PCR_RCLKDIR | 1308c2ecf20Sopenharmony_ci IMX_AUDMUX_V1_PCR_TFCSEL(MX27_AUDMUX_HPCR3_SSI_PINS_4) | 1318c2ecf20Sopenharmony_ci IMX_AUDMUX_V1_PCR_RFCSEL(MX27_AUDMUX_HPCR3_SSI_PINS_4) | 1328c2ecf20Sopenharmony_ci IMX_AUDMUX_V1_PCR_RXDSEL(MX27_AUDMUX_HPCR3_SSI_PINS_4) 1338c2ecf20Sopenharmony_ci ); 1348c2ecf20Sopenharmony_ci imx_audmux_v1_configure_port(MX27_AUDMUX_HPCR3_SSI_PINS_4, 1358c2ecf20Sopenharmony_ci IMX_AUDMUX_V1_PCR_SYN | 1368c2ecf20Sopenharmony_ci IMX_AUDMUX_V1_PCR_RXDSEL(MX27_AUDMUX_HPCR1_SSI0) 1378c2ecf20Sopenharmony_ci ); 1388c2ecf20Sopenharmony_ci } 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_ci return ret; 1418c2ecf20Sopenharmony_ci} 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_cistatic struct platform_driver imx_mc13783_audio_driver = { 1448c2ecf20Sopenharmony_ci .driver = { 1458c2ecf20Sopenharmony_ci .name = "imx_mc13783", 1468c2ecf20Sopenharmony_ci }, 1478c2ecf20Sopenharmony_ci .probe = imx_mc13783_probe, 1488c2ecf20Sopenharmony_ci}; 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_cimodule_platform_driver(imx_mc13783_audio_driver); 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_ciMODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de>"); 1538c2ecf20Sopenharmony_ciMODULE_AUTHOR("Philippe Retornaz <philippe.retornaz@epfl.ch"); 1548c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("imx with mc13783 codec ALSA SoC driver"); 1558c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL"); 1568c2ecf20Sopenharmony_ciMODULE_ALIAS("platform:imx_mc13783"); 157