d1e2a97b36
Hi Mark Many ASoC drivers are getting rtd from substream by rtd = substream->private_data OTOH, we have snd_pcm_substream_chip() macro for it. #define snd_pcm_substream_chip(substream) ((substream)->private_data) But, both are not understandable for reader. This patch adds new asoc_substream_to_rtd() which is easy to understand. These are not important, but for readable code. Kuninori Morimoto (29): ASoC: soc-xxx: add asoc_substream_to_rtd() ASoC: ux500: use asoc_substream_to_rtd() ASoC: ti: use asoc_substream_to_rtd() ASoC: tegra: use asoc_substream_to_rtd() ASoC: sunxi: use asoc_substream_to_rtd() ASoC: stm: use asoc_substream_to_rtd() ASoC: sof: use asoc_substream_to_rtd() ASoC: sh: use asoc_substream_to_rtd() ASoC: samsung: use asoc_substream_to_rtd() ASoC: pxa: use asoc_substream_to_rtd() ASoC: cirrus: use asoc_substream_to_rtd() ASoC: rockchip: use asoc_substream_to_rtd() ASoC: amd: use asoc_substream_to_rtd() ASoC: fsl: use asoc_substream_to_rtd() ASoC: mediatek: use asoc_substream_to_rtd() ASoC: atmel: use asoc_substream_to_rtd() ASoC: qcom: use asoc_substream_to_rtd() ASoC: dwc: use asoc_substream_to_rtd() ASoC: intel: use asoc_substream_to_rtd() ASoC: meson: use asoc_substream_to_rtd() ASoC: au1x: use asoc_substream_to_rtd() ASoC: bcm: use asoc_substream_to_rtd() ASoC: codecs: use asoc_substream_to_rtd() ASoC: generic: use asoc_substream_to_rtd() ASoC: sprd: use asoc_substream_to_rtd() ASoC: kirkwood: use asoc_substream_to_rtd() ASoC: xtensa: use asoc_substream_to_rtd() ASoC: mxs: use asoc_substream_to_rtd() ASoC: uniphier: use asoc_substream_to_rtd() include/sound/soc.h | 2 + sound/soc/amd/acp-da7219-max98357a.c | 12 ++-- sound/soc/amd/acp-pcm-dma.c | 2 +- sound/soc/amd/acp-rt5645.c | 2 +- sound/soc/amd/acp3x-rt5682-max9836.c | 8 +-- sound/soc/amd/raven/acp3x-i2s.c | 2 +- sound/soc/amd/raven/acp3x-pcm-dma.c | 6 +- sound/soc/atmel/atmel-classd.c | 8 +-- sound/soc/atmel/atmel-pcm-dma.c | 4 +- sound/soc/atmel/atmel-pcm-pdc.c | 2 +- sound/soc/atmel/atmel-pdmic.c | 10 +-- sound/soc/atmel/atmel_wm8904.c | 2 +- sound/soc/au1x/db1200.c | 2 +- sound/soc/au1x/dbdma2.c | 2 +- sound/soc/au1x/dma.c | 2 +- sound/soc/bcm/bcm63xx-pcm-whistler.c | 12 ++-- sound/soc/bcm/cygnus-pcm.c | 16 ++--- sound/soc/cirrus/edb93xx.c | 2 +- sound/soc/cirrus/snappercl15.c | 2 +- sound/soc/codecs/rt5677-spi.c | 4 +- sound/soc/dwc/dwc-pcm.c | 2 +- sound/soc/fsl/eukrea-tlv320.c | 2 +- sound/soc/fsl/fsl-asoc-card.c | 2 +- sound/soc/fsl/fsl_asrc_dma.c | 4 +- sound/soc/fsl/fsl_dma.c | 2 +- sound/soc/fsl/fsl_spdif.c | 10 +-- sound/soc/fsl/fsl_ssi.c | 8 +-- sound/soc/fsl/imx-audmix.c | 6 +- sound/soc/fsl/imx-mc13783.c | 2 +- sound/soc/fsl/mpc5200_dma.c | 8 +-- sound/soc/fsl/mpc5200_psc_i2s.c | 2 +- sound/soc/fsl/mpc8610_hpcd.c | 2 +- sound/soc/fsl/mx27vis-aic32x4.c | 2 +- sound/soc/fsl/p1022_ds.c | 2 +- sound/soc/fsl/p1022_rdk.c | 2 +- sound/soc/fsl/wm1133-ev1.c | 2 +- sound/soc/generic/simple-card-utils.c | 6 +- sound/soc/intel/atom/sst-mfld-platform-pcm.c | 6 +- sound/soc/intel/baytrail/sst-baytrail-pcm.c | 16 ++--- sound/soc/intel/boards/bdw-rt5650.c | 2 +- sound/soc/intel/boards/bdw-rt5677.c | 4 +- sound/soc/intel/boards/broadwell.c | 2 +- sound/soc/intel/boards/bxt_rt298.c | 2 +- sound/soc/intel/boards/byt-rt5640.c | 2 +- sound/soc/intel/boards/bytcht_da7213.c | 4 +- sound/soc/intel/boards/bytcr_rt5640.c | 2 +- sound/soc/intel/boards/bytcr_rt5651.c | 2 +- sound/soc/intel/boards/cht_bsw_max98090_ti.c | 2 +- sound/soc/intel/boards/cht_bsw_nau8824.c | 2 +- sound/soc/intel/boards/cht_bsw_rt5645.c | 2 +- sound/soc/intel/boards/cht_bsw_rt5672.c | 2 +- sound/soc/intel/boards/cml_rt1011_rt5682.c | 4 +- sound/soc/intel/boards/ehl_rt5660.c | 2 +- sound/soc/intel/boards/glk_rt5682_max98357a.c | 2 +- sound/soc/intel/boards/haswell.c | 2 +- sound/soc/intel/boards/kbl_da7219_max98927.c | 8 +-- sound/soc/intel/boards/kbl_rt5660.c | 2 +- sound/soc/intel/boards/kbl_rt5663_max98927.c | 4 +- .../intel/boards/kbl_rt5663_rt5514_max98927.c | 4 +- .../soc/intel/boards/skl_nau88l25_max98357a.c | 2 +- sound/soc/intel/boards/skl_nau88l25_ssm4567.c | 2 +- sound/soc/intel/boards/skl_rt286.c | 2 +- sound/soc/intel/boards/sof_da7219_max98373.c | 2 +- sound/soc/intel/boards/sof_maxim_common.c | 4 +- sound/soc/intel/boards/sof_pcm512x.c | 4 +- sound/soc/intel/boards/sof_rt5682.c | 4 +- sound/soc/intel/boards/sof_sdw_rt1308.c | 2 +- sound/soc/intel/boards/sof_wm8804.c | 2 +- sound/soc/intel/haswell/sst-haswell-pcm.c | 12 ++-- sound/soc/intel/keembay/kmb_platform.c | 2 +- sound/soc/intel/skylake/skl-pcm.c | 8 +-- sound/soc/kirkwood/armada-370-db.c | 2 +- sound/soc/mediatek/common/mtk-afe-fe-dai.c | 12 ++-- .../mediatek/common/mtk-afe-platform-driver.c | 2 +- sound/soc/mediatek/mt2701/mt2701-afe-pcm.c | 2 +- sound/soc/mediatek/mt2701/mt2701-cs42448.c | 2 +- sound/soc/mediatek/mt2701/mt2701-wm8960.c | 2 +- sound/soc/mediatek/mt6797/mt6797-afe-pcm.c | 4 +- sound/soc/mediatek/mt8173/mt8173-afe-pcm.c | 2 +- sound/soc/mediatek/mt8173/mt8173-max98090.c | 2 +- .../mediatek/mt8173/mt8173-rt5650-rt5514.c | 2 +- .../mediatek/mt8173/mt8173-rt5650-rt5676.c | 2 +- sound/soc/mediatek/mt8173/mt8173-rt5650.c | 2 +- sound/soc/mediatek/mt8183/mt8183-afe-pcm.c | 4 +- .../mediatek/mt8183/mt8183-da7219-max98357.c | 8 +-- .../mt8183/mt8183-mt6358-ts3a227-max98357.c | 12 ++-- sound/soc/meson/axg-card.c | 2 +- sound/soc/meson/gx-card.c | 2 +- sound/soc/meson/meson-card-utils.c | 2 +- sound/soc/meson/meson-codec-glue.c | 2 +- sound/soc/mxs/mxs-sgtl5000.c | 2 +- sound/soc/pxa/brownstone.c | 2 +- sound/soc/pxa/corgi.c | 4 +- sound/soc/pxa/hx4700.c | 2 +- sound/soc/pxa/imote2.c | 2 +- sound/soc/pxa/magician.c | 6 +- sound/soc/pxa/mmp-pcm.c | 2 +- sound/soc/pxa/poodle.c | 4 +- sound/soc/pxa/pxa2xx-i2s.c | 2 +- sound/soc/pxa/spitz.c | 4 +- sound/soc/pxa/tosa.c | 2 +- sound/soc/pxa/z2.c | 2 +- sound/soc/pxa/zylonite.c | 2 +- sound/soc/qcom/apq8096.c | 2 +- sound/soc/qcom/lpass-platform.c | 14 ++--- sound/soc/qcom/qdsp6/q6asm-dai.c | 6 +- sound/soc/qcom/qdsp6/q6routing.c | 2 +- sound/soc/qcom/sdm845.c | 14 ++--- sound/soc/qcom/storm.c | 2 +- sound/soc/rockchip/rk3288_hdmi_analog.c | 2 +- sound/soc/rockchip/rk3399_gru_sound.c | 8 +-- sound/soc/rockchip/rockchip_i2s.c | 2 +- sound/soc/rockchip/rockchip_max98090.c | 2 +- sound/soc/rockchip/rockchip_rt5645.c | 2 +- sound/soc/samsung/aries_wm8994.c | 4 +- sound/soc/samsung/arndale.c | 4 +- sound/soc/samsung/h1940_uda1380.c | 2 +- sound/soc/samsung/i2s.c | 2 +- sound/soc/samsung/jive_wm8750.c | 2 +- sound/soc/samsung/littlemill.c | 2 +- sound/soc/samsung/neo1973_wm8753.c | 8 +-- sound/soc/samsung/odroid.c | 6 +- sound/soc/samsung/pcm.c | 4 +- sound/soc/samsung/rx1950_uda1380.c | 2 +- sound/soc/samsung/s3c-i2s-v2.c | 2 +- sound/soc/samsung/s3c24xx_simtec.c | 2 +- sound/soc/samsung/s3c24xx_uda134x.c | 6 +- sound/soc/samsung/smartq_wm8987.c | 2 +- sound/soc/samsung/smdk_spdif.c | 2 +- sound/soc/samsung/smdk_wm8580.c | 2 +- sound/soc/samsung/smdk_wm8994.c | 2 +- sound/soc/samsung/smdk_wm8994pcm.c | 2 +- sound/soc/samsung/snow.c | 2 +- sound/soc/samsung/spdif.c | 6 +- sound/soc/samsung/tm2_wm5110.c | 8 +-- sound/soc/sh/dma-sh7760.c | 12 ++-- sound/soc/sh/fsi.c | 2 +- sound/soc/sh/migor.c | 4 +- sound/soc/sh/rcar/core.c | 4 +- sound/soc/soc-component.c | 20 +++--- sound/soc/soc-dai.c | 8 +-- sound/soc/soc-dapm.c | 6 +- sound/soc/soc-generic-dmaengine-pcm.c | 4 +- sound/soc/soc-link.c | 12 ++-- sound/soc/soc-pcm.c | 62 +++++++++---------- sound/soc/soc-utils.c | 2 +- sound/soc/sof/intel/hda-dai.c | 10 +-- sound/soc/sof/intel/hda-dsp.c | 2 +- sound/soc/sof/intel/hda-pcm.c | 2 +- sound/soc/sof/pcm.c | 18 +++--- sound/soc/sprd/sprd-pcm-dma.c | 2 +- sound/soc/stm/stm32_adfsdm.c | 12 ++-- sound/soc/stm/stm32_sai_sub.c | 2 +- sound/soc/sunxi/sun4i-codec.c | 12 ++-- sound/soc/sunxi/sun4i-spdif.c | 2 +- sound/soc/tegra/tegra_alc5632.c | 2 +- sound/soc/tegra/tegra_max98090.c | 2 +- sound/soc/tegra/tegra_rt5640.c | 2 +- sound/soc/tegra/tegra_rt5677.c | 2 +- sound/soc/tegra/tegra_sgtl5000.c | 2 +- sound/soc/tegra/tegra_wm8753.c | 2 +- sound/soc/tegra/tegra_wm8903.c | 2 +- sound/soc/tegra/trimslice.c | 2 +- sound/soc/ti/davinci-evm.c | 6 +- sound/soc/ti/davinci-vcif.c | 4 +- sound/soc/ti/j721e-evm.c | 6 +- sound/soc/ti/n810.c | 4 +- sound/soc/ti/omap-abe-twl6040.c | 4 +- sound/soc/ti/omap-mcbsp.c | 4 +- sound/soc/ti/omap-twl4030.c | 2 +- sound/soc/ti/omap3pandora.c | 2 +- sound/soc/ti/osk5912.c | 2 +- sound/soc/ti/rx51.c | 4 +- sound/soc/uniphier/aio-dma.c | 6 +- sound/soc/ux500/mop500_ab8500.c | 8 +-- sound/soc/ux500/ux500_pcm.c | 2 +- sound/soc/xtensa/xtfpga-i2s.c | 2 +- 177 files changed, 397 insertions(+), 395 deletions(-) -- 2.25.1
889 lines
25 KiB
C
889 lines
25 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
//
|
|
// Freescale Generic ASoC Sound Card driver with ASRC
|
|
//
|
|
// Copyright (C) 2014 Freescale Semiconductor, Inc.
|
|
//
|
|
// Author: Nicolin Chen <nicoleotsuka@gmail.com>
|
|
|
|
#include <linux/clk.h>
|
|
#include <linux/i2c.h>
|
|
#include <linux/module.h>
|
|
#include <linux/of_platform.h>
|
|
#if IS_ENABLED(CONFIG_SND_AC97_CODEC)
|
|
#include <sound/ac97_codec.h>
|
|
#endif
|
|
#include <sound/pcm_params.h>
|
|
#include <sound/soc.h>
|
|
#include <sound/jack.h>
|
|
#include <sound/simple_card_utils.h>
|
|
|
|
#include "fsl_esai.h"
|
|
#include "fsl_sai.h"
|
|
#include "imx-audmux.h"
|
|
|
|
#include "../codecs/sgtl5000.h"
|
|
#include "../codecs/wm8962.h"
|
|
#include "../codecs/wm8960.h"
|
|
|
|
#define CS427x_SYSCLK_MCLK 0
|
|
|
|
#define RX 0
|
|
#define TX 1
|
|
|
|
/* Default DAI format without Master and Slave flag */
|
|
#define DAI_FMT_BASE (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF)
|
|
|
|
/**
|
|
* struct codec_priv - CODEC private data
|
|
* @mclk_freq: Clock rate of MCLK
|
|
* @mclk_id: MCLK (or main clock) id for set_sysclk()
|
|
* @fll_id: FLL (or secordary clock) id for set_sysclk()
|
|
* @pll_id: PLL id for set_pll()
|
|
*/
|
|
struct codec_priv {
|
|
unsigned long mclk_freq;
|
|
u32 mclk_id;
|
|
u32 fll_id;
|
|
u32 pll_id;
|
|
};
|
|
|
|
/**
|
|
* struct cpu_priv - CPU private data
|
|
* @sysclk_freq: SYSCLK rates for set_sysclk()
|
|
* @sysclk_dir: SYSCLK directions for set_sysclk()
|
|
* @sysclk_id: SYSCLK ids for set_sysclk()
|
|
* @slot_width: Slot width of each frame
|
|
*
|
|
* Note: [1] for tx and [0] for rx
|
|
*/
|
|
struct cpu_priv {
|
|
unsigned long sysclk_freq[2];
|
|
u32 sysclk_dir[2];
|
|
u32 sysclk_id[2];
|
|
u32 slot_width;
|
|
};
|
|
|
|
/**
|
|
* struct fsl_asoc_card_priv - Freescale Generic ASOC card private data
|
|
* @dai_link: DAI link structure including normal one and DPCM link
|
|
* @hp_jack: Headphone Jack structure
|
|
* @mic_jack: Microphone Jack structure
|
|
* @pdev: platform device pointer
|
|
* @codec_priv: CODEC private data
|
|
* @cpu_priv: CPU private data
|
|
* @card: ASoC card structure
|
|
* @sample_rate: Current sample rate
|
|
* @sample_format: Current sample format
|
|
* @asrc_rate: ASRC sample rate used by Back-Ends
|
|
* @asrc_format: ASRC sample format used by Back-Ends
|
|
* @dai_fmt: DAI format between CPU and CODEC
|
|
* @name: Card name
|
|
*/
|
|
|
|
struct fsl_asoc_card_priv {
|
|
struct snd_soc_dai_link dai_link[3];
|
|
struct asoc_simple_jack hp_jack;
|
|
struct asoc_simple_jack mic_jack;
|
|
struct platform_device *pdev;
|
|
struct codec_priv codec_priv;
|
|
struct cpu_priv cpu_priv;
|
|
struct snd_soc_card card;
|
|
u32 sample_rate;
|
|
snd_pcm_format_t sample_format;
|
|
u32 asrc_rate;
|
|
snd_pcm_format_t asrc_format;
|
|
u32 dai_fmt;
|
|
char name[32];
|
|
};
|
|
|
|
/*
|
|
* This dapm route map exists for DPCM link only.
|
|
* The other routes shall go through Device Tree.
|
|
*
|
|
* Note: keep all ASRC routes in the second half
|
|
* to drop them easily for non-ASRC cases.
|
|
*/
|
|
static const struct snd_soc_dapm_route audio_map[] = {
|
|
/* 1st half -- Normal DAPM routes */
|
|
{"Playback", NULL, "CPU-Playback"},
|
|
{"CPU-Capture", NULL, "Capture"},
|
|
/* 2nd half -- ASRC DAPM routes */
|
|
{"CPU-Playback", NULL, "ASRC-Playback"},
|
|
{"ASRC-Capture", NULL, "CPU-Capture"},
|
|
};
|
|
|
|
static const struct snd_soc_dapm_route audio_map_ac97[] = {
|
|
/* 1st half -- Normal DAPM routes */
|
|
{"Playback", NULL, "AC97 Playback"},
|
|
{"AC97 Capture", NULL, "Capture"},
|
|
/* 2nd half -- ASRC DAPM routes */
|
|
{"AC97 Playback", NULL, "ASRC-Playback"},
|
|
{"ASRC-Capture", NULL, "AC97 Capture"},
|
|
};
|
|
|
|
static const struct snd_soc_dapm_route audio_map_tx[] = {
|
|
/* 1st half -- Normal DAPM routes */
|
|
{"Playback", NULL, "CPU-Playback"},
|
|
/* 2nd half -- ASRC DAPM routes */
|
|
{"CPU-Playback", NULL, "ASRC-Playback"},
|
|
};
|
|
|
|
/* Add all possible widgets into here without being redundant */
|
|
static const struct snd_soc_dapm_widget fsl_asoc_card_dapm_widgets[] = {
|
|
SND_SOC_DAPM_LINE("Line Out Jack", NULL),
|
|
SND_SOC_DAPM_LINE("Line In Jack", NULL),
|
|
SND_SOC_DAPM_HP("Headphone Jack", NULL),
|
|
SND_SOC_DAPM_SPK("Ext Spk", NULL),
|
|
SND_SOC_DAPM_MIC("Mic Jack", NULL),
|
|
SND_SOC_DAPM_MIC("AMIC", NULL),
|
|
SND_SOC_DAPM_MIC("DMIC", NULL),
|
|
};
|
|
|
|
static bool fsl_asoc_card_is_ac97(struct fsl_asoc_card_priv *priv)
|
|
{
|
|
return priv->dai_fmt == SND_SOC_DAIFMT_AC97;
|
|
}
|
|
|
|
static int fsl_asoc_card_hw_params(struct snd_pcm_substream *substream,
|
|
struct snd_pcm_hw_params *params)
|
|
{
|
|
struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
|
|
struct fsl_asoc_card_priv *priv = snd_soc_card_get_drvdata(rtd->card);
|
|
bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
|
|
struct cpu_priv *cpu_priv = &priv->cpu_priv;
|
|
struct device *dev = rtd->card->dev;
|
|
int ret;
|
|
|
|
priv->sample_rate = params_rate(params);
|
|
priv->sample_format = params_format(params);
|
|
|
|
/*
|
|
* If codec-dai is DAI Master and all configurations are already in the
|
|
* set_bias_level(), bypass the remaining settings in hw_params().
|
|
* Note: (dai_fmt & CBM_CFM) includes CBM_CFM and CBM_CFS.
|
|
*/
|
|
if ((priv->card.set_bias_level &&
|
|
priv->dai_fmt & SND_SOC_DAIFMT_CBM_CFM) ||
|
|
fsl_asoc_card_is_ac97(priv))
|
|
return 0;
|
|
|
|
/* Specific configurations of DAIs starts from here */
|
|
ret = snd_soc_dai_set_sysclk(asoc_rtd_to_cpu(rtd, 0), cpu_priv->sysclk_id[tx],
|
|
cpu_priv->sysclk_freq[tx],
|
|
cpu_priv->sysclk_dir[tx]);
|
|
if (ret && ret != -ENOTSUPP) {
|
|
dev_err(dev, "failed to set sysclk for cpu dai\n");
|
|
return ret;
|
|
}
|
|
|
|
if (cpu_priv->slot_width) {
|
|
ret = snd_soc_dai_set_tdm_slot(asoc_rtd_to_cpu(rtd, 0), 0x3, 0x3, 2,
|
|
cpu_priv->slot_width);
|
|
if (ret && ret != -ENOTSUPP) {
|
|
dev_err(dev, "failed to set TDM slot for cpu dai\n");
|
|
return ret;
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static const struct snd_soc_ops fsl_asoc_card_ops = {
|
|
.hw_params = fsl_asoc_card_hw_params,
|
|
};
|
|
|
|
static int be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
|
|
struct snd_pcm_hw_params *params)
|
|
{
|
|
struct fsl_asoc_card_priv *priv = snd_soc_card_get_drvdata(rtd->card);
|
|
struct snd_interval *rate;
|
|
struct snd_mask *mask;
|
|
|
|
rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
|
|
rate->max = rate->min = priv->asrc_rate;
|
|
|
|
mask = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
|
|
snd_mask_none(mask);
|
|
snd_mask_set_format(mask, priv->asrc_format);
|
|
|
|
return 0;
|
|
}
|
|
|
|
SND_SOC_DAILINK_DEFS(hifi,
|
|
DAILINK_COMP_ARRAY(COMP_EMPTY()),
|
|
DAILINK_COMP_ARRAY(COMP_EMPTY()),
|
|
DAILINK_COMP_ARRAY(COMP_EMPTY()));
|
|
|
|
SND_SOC_DAILINK_DEFS(hifi_fe,
|
|
DAILINK_COMP_ARRAY(COMP_EMPTY()),
|
|
DAILINK_COMP_ARRAY(COMP_DUMMY()),
|
|
DAILINK_COMP_ARRAY(COMP_EMPTY()));
|
|
|
|
SND_SOC_DAILINK_DEFS(hifi_be,
|
|
DAILINK_COMP_ARRAY(COMP_EMPTY()),
|
|
DAILINK_COMP_ARRAY(COMP_EMPTY()),
|
|
DAILINK_COMP_ARRAY(COMP_DUMMY()));
|
|
|
|
static struct snd_soc_dai_link fsl_asoc_card_dai[] = {
|
|
/* Default ASoC DAI Link*/
|
|
{
|
|
.name = "HiFi",
|
|
.stream_name = "HiFi",
|
|
.ops = &fsl_asoc_card_ops,
|
|
SND_SOC_DAILINK_REG(hifi),
|
|
},
|
|
/* DPCM Link between Front-End and Back-End (Optional) */
|
|
{
|
|
.name = "HiFi-ASRC-FE",
|
|
.stream_name = "HiFi-ASRC-FE",
|
|
.dpcm_playback = 1,
|
|
.dpcm_capture = 1,
|
|
.dynamic = 1,
|
|
SND_SOC_DAILINK_REG(hifi_fe),
|
|
},
|
|
{
|
|
.name = "HiFi-ASRC-BE",
|
|
.stream_name = "HiFi-ASRC-BE",
|
|
.be_hw_params_fixup = be_hw_params_fixup,
|
|
.ops = &fsl_asoc_card_ops,
|
|
.dpcm_playback = 1,
|
|
.dpcm_capture = 1,
|
|
.no_pcm = 1,
|
|
SND_SOC_DAILINK_REG(hifi_be),
|
|
},
|
|
};
|
|
|
|
static int fsl_asoc_card_set_bias_level(struct snd_soc_card *card,
|
|
struct snd_soc_dapm_context *dapm,
|
|
enum snd_soc_bias_level level)
|
|
{
|
|
struct fsl_asoc_card_priv *priv = snd_soc_card_get_drvdata(card);
|
|
struct snd_soc_pcm_runtime *rtd;
|
|
struct snd_soc_dai *codec_dai;
|
|
struct codec_priv *codec_priv = &priv->codec_priv;
|
|
struct device *dev = card->dev;
|
|
unsigned int pll_out;
|
|
int ret;
|
|
|
|
rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
|
|
codec_dai = asoc_rtd_to_codec(rtd, 0);
|
|
if (dapm->dev != codec_dai->dev)
|
|
return 0;
|
|
|
|
switch (level) {
|
|
case SND_SOC_BIAS_PREPARE:
|
|
if (dapm->bias_level != SND_SOC_BIAS_STANDBY)
|
|
break;
|
|
|
|
if (priv->sample_format == SNDRV_PCM_FORMAT_S24_LE)
|
|
pll_out = priv->sample_rate * 384;
|
|
else
|
|
pll_out = priv->sample_rate * 256;
|
|
|
|
ret = snd_soc_dai_set_pll(codec_dai, codec_priv->pll_id,
|
|
codec_priv->mclk_id,
|
|
codec_priv->mclk_freq, pll_out);
|
|
if (ret) {
|
|
dev_err(dev, "failed to start FLL: %d\n", ret);
|
|
return ret;
|
|
}
|
|
|
|
ret = snd_soc_dai_set_sysclk(codec_dai, codec_priv->fll_id,
|
|
pll_out, SND_SOC_CLOCK_IN);
|
|
if (ret && ret != -ENOTSUPP) {
|
|
dev_err(dev, "failed to set SYSCLK: %d\n", ret);
|
|
return ret;
|
|
}
|
|
break;
|
|
|
|
case SND_SOC_BIAS_STANDBY:
|
|
if (dapm->bias_level != SND_SOC_BIAS_PREPARE)
|
|
break;
|
|
|
|
ret = snd_soc_dai_set_sysclk(codec_dai, codec_priv->mclk_id,
|
|
codec_priv->mclk_freq,
|
|
SND_SOC_CLOCK_IN);
|
|
if (ret && ret != -ENOTSUPP) {
|
|
dev_err(dev, "failed to switch away from FLL: %d\n", ret);
|
|
return ret;
|
|
}
|
|
|
|
ret = snd_soc_dai_set_pll(codec_dai, codec_priv->pll_id, 0, 0, 0);
|
|
if (ret) {
|
|
dev_err(dev, "failed to stop FLL: %d\n", ret);
|
|
return ret;
|
|
}
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int fsl_asoc_card_audmux_init(struct device_node *np,
|
|
struct fsl_asoc_card_priv *priv)
|
|
{
|
|
struct device *dev = &priv->pdev->dev;
|
|
u32 int_ptcr = 0, ext_ptcr = 0;
|
|
int int_port, ext_port;
|
|
int ret;
|
|
|
|
ret = of_property_read_u32(np, "mux-int-port", &int_port);
|
|
if (ret) {
|
|
dev_err(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(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--;
|
|
|
|
/*
|
|
* Use asynchronous mode (6 wires) for all cases except AC97.
|
|
* If only 4 wires are needed, just set SSI into
|
|
* synchronous mode and enable 4 PADs in IOMUX.
|
|
*/
|
|
switch (priv->dai_fmt & SND_SOC_DAIFMT_MASTER_MASK) {
|
|
case SND_SOC_DAIFMT_CBM_CFM:
|
|
int_ptcr = IMX_AUDMUX_V2_PTCR_RFSEL(8 | ext_port) |
|
|
IMX_AUDMUX_V2_PTCR_RCSEL(8 | ext_port) |
|
|
IMX_AUDMUX_V2_PTCR_TFSEL(ext_port) |
|
|
IMX_AUDMUX_V2_PTCR_TCSEL(ext_port) |
|
|
IMX_AUDMUX_V2_PTCR_RFSDIR |
|
|
IMX_AUDMUX_V2_PTCR_RCLKDIR |
|
|
IMX_AUDMUX_V2_PTCR_TFSDIR |
|
|
IMX_AUDMUX_V2_PTCR_TCLKDIR;
|
|
break;
|
|
case SND_SOC_DAIFMT_CBM_CFS:
|
|
int_ptcr = IMX_AUDMUX_V2_PTCR_RCSEL(8 | ext_port) |
|
|
IMX_AUDMUX_V2_PTCR_TCSEL(ext_port) |
|
|
IMX_AUDMUX_V2_PTCR_RCLKDIR |
|
|
IMX_AUDMUX_V2_PTCR_TCLKDIR;
|
|
ext_ptcr = IMX_AUDMUX_V2_PTCR_RFSEL(8 | int_port) |
|
|
IMX_AUDMUX_V2_PTCR_TFSEL(int_port) |
|
|
IMX_AUDMUX_V2_PTCR_RFSDIR |
|
|
IMX_AUDMUX_V2_PTCR_TFSDIR;
|
|
break;
|
|
case SND_SOC_DAIFMT_CBS_CFM:
|
|
int_ptcr = IMX_AUDMUX_V2_PTCR_RFSEL(8 | ext_port) |
|
|
IMX_AUDMUX_V2_PTCR_TFSEL(ext_port) |
|
|
IMX_AUDMUX_V2_PTCR_RFSDIR |
|
|
IMX_AUDMUX_V2_PTCR_TFSDIR;
|
|
ext_ptcr = IMX_AUDMUX_V2_PTCR_RCSEL(8 | int_port) |
|
|
IMX_AUDMUX_V2_PTCR_TCSEL(int_port) |
|
|
IMX_AUDMUX_V2_PTCR_RCLKDIR |
|
|
IMX_AUDMUX_V2_PTCR_TCLKDIR;
|
|
break;
|
|
case SND_SOC_DAIFMT_CBS_CFS:
|
|
ext_ptcr = IMX_AUDMUX_V2_PTCR_RFSEL(8 | int_port) |
|
|
IMX_AUDMUX_V2_PTCR_RCSEL(8 | int_port) |
|
|
IMX_AUDMUX_V2_PTCR_TFSEL(int_port) |
|
|
IMX_AUDMUX_V2_PTCR_TCSEL(int_port) |
|
|
IMX_AUDMUX_V2_PTCR_RFSDIR |
|
|
IMX_AUDMUX_V2_PTCR_RCLKDIR |
|
|
IMX_AUDMUX_V2_PTCR_TFSDIR |
|
|
IMX_AUDMUX_V2_PTCR_TCLKDIR;
|
|
break;
|
|
default:
|
|
if (!fsl_asoc_card_is_ac97(priv))
|
|
return -EINVAL;
|
|
}
|
|
|
|
if (fsl_asoc_card_is_ac97(priv)) {
|
|
int_ptcr = IMX_AUDMUX_V2_PTCR_SYN |
|
|
IMX_AUDMUX_V2_PTCR_TCSEL(ext_port) |
|
|
IMX_AUDMUX_V2_PTCR_TCLKDIR;
|
|
ext_ptcr = IMX_AUDMUX_V2_PTCR_SYN |
|
|
IMX_AUDMUX_V2_PTCR_TFSEL(int_port) |
|
|
IMX_AUDMUX_V2_PTCR_TFSDIR;
|
|
}
|
|
|
|
/* Asynchronous mode can not be set along with RCLKDIR */
|
|
if (!fsl_asoc_card_is_ac97(priv)) {
|
|
unsigned int pdcr =
|
|
IMX_AUDMUX_V2_PDCR_RXDSEL(ext_port);
|
|
|
|
ret = imx_audmux_v2_configure_port(int_port, 0,
|
|
pdcr);
|
|
if (ret) {
|
|
dev_err(dev, "audmux internal port setup failed\n");
|
|
return ret;
|
|
}
|
|
}
|
|
|
|
ret = imx_audmux_v2_configure_port(int_port, int_ptcr,
|
|
IMX_AUDMUX_V2_PDCR_RXDSEL(ext_port));
|
|
if (ret) {
|
|
dev_err(dev, "audmux internal port setup failed\n");
|
|
return ret;
|
|
}
|
|
|
|
if (!fsl_asoc_card_is_ac97(priv)) {
|
|
unsigned int pdcr =
|
|
IMX_AUDMUX_V2_PDCR_RXDSEL(int_port);
|
|
|
|
ret = imx_audmux_v2_configure_port(ext_port, 0,
|
|
pdcr);
|
|
if (ret) {
|
|
dev_err(dev, "audmux external port setup failed\n");
|
|
return ret;
|
|
}
|
|
}
|
|
|
|
ret = imx_audmux_v2_configure_port(ext_port, ext_ptcr,
|
|
IMX_AUDMUX_V2_PDCR_RXDSEL(int_port));
|
|
if (ret) {
|
|
dev_err(dev, "audmux external port setup failed\n");
|
|
return ret;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int hp_jack_event(struct notifier_block *nb, unsigned long event,
|
|
void *data)
|
|
{
|
|
struct snd_soc_jack *jack = (struct snd_soc_jack *)data;
|
|
struct snd_soc_dapm_context *dapm = &jack->card->dapm;
|
|
|
|
if (event & SND_JACK_HEADPHONE)
|
|
/* Disable speaker if headphone is plugged in */
|
|
snd_soc_dapm_disable_pin(dapm, "Ext Spk");
|
|
else
|
|
snd_soc_dapm_enable_pin(dapm, "Ext Spk");
|
|
|
|
return 0;
|
|
}
|
|
|
|
static struct notifier_block hp_jack_nb = {
|
|
.notifier_call = hp_jack_event,
|
|
};
|
|
|
|
static int mic_jack_event(struct notifier_block *nb, unsigned long event,
|
|
void *data)
|
|
{
|
|
struct snd_soc_jack *jack = (struct snd_soc_jack *)data;
|
|
struct snd_soc_dapm_context *dapm = &jack->card->dapm;
|
|
|
|
if (event & SND_JACK_MICROPHONE)
|
|
/* Disable dmic if microphone is plugged in */
|
|
snd_soc_dapm_disable_pin(dapm, "DMIC");
|
|
else
|
|
snd_soc_dapm_enable_pin(dapm, "DMIC");
|
|
|
|
return 0;
|
|
}
|
|
|
|
static struct notifier_block mic_jack_nb = {
|
|
.notifier_call = mic_jack_event,
|
|
};
|
|
|
|
static int fsl_asoc_card_late_probe(struct snd_soc_card *card)
|
|
{
|
|
struct fsl_asoc_card_priv *priv = snd_soc_card_get_drvdata(card);
|
|
struct snd_soc_pcm_runtime *rtd = list_first_entry(
|
|
&card->rtd_list, struct snd_soc_pcm_runtime, list);
|
|
struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
|
|
struct codec_priv *codec_priv = &priv->codec_priv;
|
|
struct device *dev = card->dev;
|
|
int ret;
|
|
|
|
if (fsl_asoc_card_is_ac97(priv)) {
|
|
#if IS_ENABLED(CONFIG_SND_AC97_CODEC)
|
|
struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
|
|
struct snd_ac97 *ac97 = snd_soc_component_get_drvdata(component);
|
|
|
|
/*
|
|
* Use slots 3/4 for S/PDIF so SSI won't try to enable
|
|
* other slots and send some samples there
|
|
* due to SLOTREQ bits for S/PDIF received from codec
|
|
*/
|
|
snd_ac97_update_bits(ac97, AC97_EXTENDED_STATUS,
|
|
AC97_EA_SPSA_SLOT_MASK, AC97_EA_SPSA_3_4);
|
|
#endif
|
|
|
|
return 0;
|
|
}
|
|
|
|
ret = snd_soc_dai_set_sysclk(codec_dai, codec_priv->mclk_id,
|
|
codec_priv->mclk_freq, SND_SOC_CLOCK_IN);
|
|
if (ret && ret != -ENOTSUPP) {
|
|
dev_err(dev, "failed to set sysclk in %s\n", __func__);
|
|
return ret;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int fsl_asoc_card_probe(struct platform_device *pdev)
|
|
{
|
|
struct device_node *cpu_np, *codec_np, *asrc_np;
|
|
struct device_node *np = pdev->dev.of_node;
|
|
struct platform_device *asrc_pdev = NULL;
|
|
struct device_node *bitclkmaster = NULL;
|
|
struct device_node *framemaster = NULL;
|
|
struct platform_device *cpu_pdev;
|
|
struct fsl_asoc_card_priv *priv;
|
|
struct device *codec_dev = NULL;
|
|
const char *codec_dai_name;
|
|
const char *codec_dev_name;
|
|
unsigned int daifmt;
|
|
u32 width;
|
|
int ret;
|
|
|
|
priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
|
|
if (!priv)
|
|
return -ENOMEM;
|
|
|
|
cpu_np = of_parse_phandle(np, "audio-cpu", 0);
|
|
/* Give a chance to old DT binding */
|
|
if (!cpu_np)
|
|
cpu_np = of_parse_phandle(np, "ssi-controller", 0);
|
|
if (!cpu_np) {
|
|
dev_err(&pdev->dev, "CPU phandle missing or invalid\n");
|
|
ret = -EINVAL;
|
|
goto fail;
|
|
}
|
|
|
|
cpu_pdev = of_find_device_by_node(cpu_np);
|
|
if (!cpu_pdev) {
|
|
dev_err(&pdev->dev, "failed to find CPU DAI device\n");
|
|
ret = -EINVAL;
|
|
goto fail;
|
|
}
|
|
|
|
codec_np = of_parse_phandle(np, "audio-codec", 0);
|
|
if (codec_np) {
|
|
struct platform_device *codec_pdev;
|
|
struct i2c_client *codec_i2c;
|
|
|
|
codec_i2c = of_find_i2c_device_by_node(codec_np);
|
|
if (codec_i2c) {
|
|
codec_dev = &codec_i2c->dev;
|
|
codec_dev_name = codec_i2c->name;
|
|
}
|
|
if (!codec_dev) {
|
|
codec_pdev = of_find_device_by_node(codec_np);
|
|
if (codec_pdev) {
|
|
codec_dev = &codec_pdev->dev;
|
|
codec_dev_name = codec_pdev->name;
|
|
}
|
|
}
|
|
}
|
|
|
|
asrc_np = of_parse_phandle(np, "audio-asrc", 0);
|
|
if (asrc_np)
|
|
asrc_pdev = of_find_device_by_node(asrc_np);
|
|
|
|
/* Get the MCLK rate only, and leave it controlled by CODEC drivers */
|
|
if (codec_dev) {
|
|
struct clk *codec_clk = clk_get(codec_dev, NULL);
|
|
|
|
if (!IS_ERR(codec_clk)) {
|
|
priv->codec_priv.mclk_freq = clk_get_rate(codec_clk);
|
|
clk_put(codec_clk);
|
|
}
|
|
}
|
|
|
|
/* Default sample rate and format, will be updated in hw_params() */
|
|
priv->sample_rate = 44100;
|
|
priv->sample_format = SNDRV_PCM_FORMAT_S16_LE;
|
|
|
|
/* Assign a default DAI format, and allow each card to overwrite it */
|
|
priv->dai_fmt = DAI_FMT_BASE;
|
|
|
|
memcpy(priv->dai_link, fsl_asoc_card_dai,
|
|
sizeof(struct snd_soc_dai_link) * ARRAY_SIZE(priv->dai_link));
|
|
|
|
priv->card.dapm_routes = audio_map;
|
|
priv->card.num_dapm_routes = ARRAY_SIZE(audio_map);
|
|
/* Diversify the card configurations */
|
|
if (of_device_is_compatible(np, "fsl,imx-audio-cs42888")) {
|
|
codec_dai_name = "cs42888";
|
|
priv->card.set_bias_level = NULL;
|
|
priv->cpu_priv.sysclk_freq[TX] = priv->codec_priv.mclk_freq;
|
|
priv->cpu_priv.sysclk_freq[RX] = priv->codec_priv.mclk_freq;
|
|
priv->cpu_priv.sysclk_dir[TX] = SND_SOC_CLOCK_OUT;
|
|
priv->cpu_priv.sysclk_dir[RX] = SND_SOC_CLOCK_OUT;
|
|
priv->cpu_priv.slot_width = 32;
|
|
priv->dai_fmt |= SND_SOC_DAIFMT_CBS_CFS;
|
|
} else if (of_device_is_compatible(np, "fsl,imx-audio-cs427x")) {
|
|
codec_dai_name = "cs4271-hifi";
|
|
priv->codec_priv.mclk_id = CS427x_SYSCLK_MCLK;
|
|
priv->dai_fmt |= SND_SOC_DAIFMT_CBM_CFM;
|
|
} else if (of_device_is_compatible(np, "fsl,imx-audio-sgtl5000")) {
|
|
codec_dai_name = "sgtl5000";
|
|
priv->codec_priv.mclk_id = SGTL5000_SYSCLK;
|
|
priv->dai_fmt |= SND_SOC_DAIFMT_CBM_CFM;
|
|
} else if (of_device_is_compatible(np, "fsl,imx-audio-wm8962")) {
|
|
codec_dai_name = "wm8962";
|
|
priv->card.set_bias_level = fsl_asoc_card_set_bias_level;
|
|
priv->codec_priv.mclk_id = WM8962_SYSCLK_MCLK;
|
|
priv->codec_priv.fll_id = WM8962_SYSCLK_FLL;
|
|
priv->codec_priv.pll_id = WM8962_FLL;
|
|
priv->dai_fmt |= SND_SOC_DAIFMT_CBM_CFM;
|
|
} else if (of_device_is_compatible(np, "fsl,imx-audio-wm8960")) {
|
|
codec_dai_name = "wm8960-hifi";
|
|
priv->card.set_bias_level = fsl_asoc_card_set_bias_level;
|
|
priv->codec_priv.fll_id = WM8960_SYSCLK_AUTO;
|
|
priv->codec_priv.pll_id = WM8960_SYSCLK_AUTO;
|
|
priv->dai_fmt |= SND_SOC_DAIFMT_CBM_CFM;
|
|
} else if (of_device_is_compatible(np, "fsl,imx-audio-ac97")) {
|
|
codec_dai_name = "ac97-hifi";
|
|
priv->card.set_bias_level = NULL;
|
|
priv->dai_fmt = SND_SOC_DAIFMT_AC97;
|
|
priv->card.dapm_routes = audio_map_ac97;
|
|
priv->card.num_dapm_routes = ARRAY_SIZE(audio_map_ac97);
|
|
} else if (of_device_is_compatible(np, "fsl,imx-audio-mqs")) {
|
|
codec_dai_name = "fsl-mqs-dai";
|
|
priv->card.set_bias_level = NULL;
|
|
priv->dai_fmt = SND_SOC_DAIFMT_LEFT_J |
|
|
SND_SOC_DAIFMT_CBS_CFS |
|
|
SND_SOC_DAIFMT_NB_NF;
|
|
priv->dai_link[1].dpcm_capture = 0;
|
|
priv->dai_link[2].dpcm_capture = 0;
|
|
priv->card.dapm_routes = audio_map_tx;
|
|
priv->card.num_dapm_routes = ARRAY_SIZE(audio_map_tx);
|
|
} else if (of_device_is_compatible(np, "fsl,imx-audio-wm8524")) {
|
|
codec_dai_name = "wm8524-hifi";
|
|
priv->card.set_bias_level = NULL;
|
|
priv->dai_fmt |= SND_SOC_DAIFMT_CBS_CFS;
|
|
priv->dai_link[1].dpcm_capture = 0;
|
|
priv->dai_link[2].dpcm_capture = 0;
|
|
priv->cpu_priv.slot_width = 32;
|
|
priv->card.dapm_routes = audio_map_tx;
|
|
priv->card.num_dapm_routes = ARRAY_SIZE(audio_map_tx);
|
|
} else {
|
|
dev_err(&pdev->dev, "unknown Device Tree compatible\n");
|
|
ret = -EINVAL;
|
|
goto asrc_fail;
|
|
}
|
|
|
|
/* Format info from DT is optional. */
|
|
daifmt = snd_soc_of_parse_daifmt(np, NULL,
|
|
&bitclkmaster, &framemaster);
|
|
daifmt &= ~SND_SOC_DAIFMT_MASTER_MASK;
|
|
if (bitclkmaster || framemaster) {
|
|
if (codec_np == bitclkmaster)
|
|
daifmt |= (codec_np == framemaster) ?
|
|
SND_SOC_DAIFMT_CBM_CFM : SND_SOC_DAIFMT_CBM_CFS;
|
|
else
|
|
daifmt |= (codec_np == framemaster) ?
|
|
SND_SOC_DAIFMT_CBS_CFM : SND_SOC_DAIFMT_CBS_CFS;
|
|
|
|
/* Override dai_fmt with value from DT */
|
|
priv->dai_fmt = daifmt;
|
|
}
|
|
|
|
/* Change direction according to format */
|
|
if (priv->dai_fmt & SND_SOC_DAIFMT_CBM_CFM) {
|
|
priv->cpu_priv.sysclk_dir[TX] = SND_SOC_CLOCK_IN;
|
|
priv->cpu_priv.sysclk_dir[RX] = SND_SOC_CLOCK_IN;
|
|
}
|
|
|
|
of_node_put(bitclkmaster);
|
|
of_node_put(framemaster);
|
|
|
|
if (!fsl_asoc_card_is_ac97(priv) && !codec_dev) {
|
|
dev_err(&pdev->dev, "failed to find codec device\n");
|
|
ret = -EPROBE_DEFER;
|
|
goto asrc_fail;
|
|
}
|
|
|
|
/* Common settings for corresponding Freescale CPU DAI driver */
|
|
if (of_node_name_eq(cpu_np, "ssi")) {
|
|
/* Only SSI needs to configure AUDMUX */
|
|
ret = fsl_asoc_card_audmux_init(np, priv);
|
|
if (ret) {
|
|
dev_err(&pdev->dev, "failed to init audmux\n");
|
|
goto asrc_fail;
|
|
}
|
|
} else if (of_node_name_eq(cpu_np, "esai")) {
|
|
priv->cpu_priv.sysclk_id[1] = ESAI_HCKT_EXTAL;
|
|
priv->cpu_priv.sysclk_id[0] = ESAI_HCKR_EXTAL;
|
|
} else if (of_node_name_eq(cpu_np, "sai")) {
|
|
priv->cpu_priv.sysclk_id[1] = FSL_SAI_CLK_MAST1;
|
|
priv->cpu_priv.sysclk_id[0] = FSL_SAI_CLK_MAST1;
|
|
}
|
|
|
|
/* Initialize sound card */
|
|
priv->pdev = pdev;
|
|
priv->card.dev = &pdev->dev;
|
|
ret = snd_soc_of_parse_card_name(&priv->card, "model");
|
|
if (ret) {
|
|
snprintf(priv->name, sizeof(priv->name), "%s-audio",
|
|
fsl_asoc_card_is_ac97(priv) ? "ac97" : codec_dev_name);
|
|
priv->card.name = priv->name;
|
|
}
|
|
priv->card.dai_link = priv->dai_link;
|
|
priv->card.late_probe = fsl_asoc_card_late_probe;
|
|
priv->card.dapm_widgets = fsl_asoc_card_dapm_widgets;
|
|
priv->card.num_dapm_widgets = ARRAY_SIZE(fsl_asoc_card_dapm_widgets);
|
|
|
|
/* Drop the second half of DAPM routes -- ASRC */
|
|
if (!asrc_pdev)
|
|
priv->card.num_dapm_routes /= 2;
|
|
|
|
if (of_property_read_bool(np, "audio-routing")) {
|
|
ret = snd_soc_of_parse_audio_routing(&priv->card, "audio-routing");
|
|
if (ret) {
|
|
dev_err(&pdev->dev, "failed to parse audio-routing: %d\n", ret);
|
|
goto asrc_fail;
|
|
}
|
|
}
|
|
|
|
/* Normal DAI Link */
|
|
priv->dai_link[0].cpus->of_node = cpu_np;
|
|
priv->dai_link[0].codecs->dai_name = codec_dai_name;
|
|
|
|
if (!fsl_asoc_card_is_ac97(priv))
|
|
priv->dai_link[0].codecs->of_node = codec_np;
|
|
else {
|
|
u32 idx;
|
|
|
|
ret = of_property_read_u32(cpu_np, "cell-index", &idx);
|
|
if (ret) {
|
|
dev_err(&pdev->dev,
|
|
"cannot get CPU index property\n");
|
|
goto asrc_fail;
|
|
}
|
|
|
|
priv->dai_link[0].codecs->name =
|
|
devm_kasprintf(&pdev->dev, GFP_KERNEL,
|
|
"ac97-codec.%u",
|
|
(unsigned int)idx);
|
|
if (!priv->dai_link[0].codecs->name) {
|
|
ret = -ENOMEM;
|
|
goto asrc_fail;
|
|
}
|
|
}
|
|
|
|
priv->dai_link[0].platforms->of_node = cpu_np;
|
|
priv->dai_link[0].dai_fmt = priv->dai_fmt;
|
|
priv->card.num_links = 1;
|
|
|
|
if (asrc_pdev) {
|
|
/* DPCM DAI Links only if ASRC exsits */
|
|
priv->dai_link[1].cpus->of_node = asrc_np;
|
|
priv->dai_link[1].platforms->of_node = asrc_np;
|
|
priv->dai_link[2].codecs->dai_name = codec_dai_name;
|
|
priv->dai_link[2].codecs->of_node = codec_np;
|
|
priv->dai_link[2].codecs->name =
|
|
priv->dai_link[0].codecs->name;
|
|
priv->dai_link[2].cpus->of_node = cpu_np;
|
|
priv->dai_link[2].dai_fmt = priv->dai_fmt;
|
|
priv->card.num_links = 3;
|
|
|
|
ret = of_property_read_u32(asrc_np, "fsl,asrc-rate",
|
|
&priv->asrc_rate);
|
|
if (ret) {
|
|
dev_err(&pdev->dev, "failed to get output rate\n");
|
|
ret = -EINVAL;
|
|
goto asrc_fail;
|
|
}
|
|
|
|
ret = of_property_read_u32(asrc_np, "fsl,asrc-format",
|
|
&priv->asrc_format);
|
|
if (ret) {
|
|
/* Fallback to old binding; translate to asrc_format */
|
|
ret = of_property_read_u32(asrc_np, "fsl,asrc-width",
|
|
&width);
|
|
if (ret) {
|
|
dev_err(&pdev->dev,
|
|
"failed to decide output format\n");
|
|
goto asrc_fail;
|
|
}
|
|
|
|
if (width == 24)
|
|
priv->asrc_format = SNDRV_PCM_FORMAT_S24_LE;
|
|
else
|
|
priv->asrc_format = SNDRV_PCM_FORMAT_S16_LE;
|
|
}
|
|
}
|
|
|
|
/* Finish card registering */
|
|
platform_set_drvdata(pdev, priv);
|
|
snd_soc_card_set_drvdata(&priv->card, priv);
|
|
|
|
ret = devm_snd_soc_register_card(&pdev->dev, &priv->card);
|
|
if (ret) {
|
|
if (ret != -EPROBE_DEFER)
|
|
dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
|
|
goto asrc_fail;
|
|
}
|
|
|
|
/*
|
|
* Properties "hp-det-gpio" and "mic-det-gpio" are optional, and
|
|
* asoc_simple_init_jack uses these properties for creating
|
|
* Headphone Jack and Microphone Jack.
|
|
*
|
|
* The notifier is initialized in snd_soc_card_jack_new(), then
|
|
* snd_soc_jack_notifier_register can be called.
|
|
*/
|
|
if (of_property_read_bool(np, "hp-det-gpio")) {
|
|
ret = asoc_simple_init_jack(&priv->card, &priv->hp_jack,
|
|
1, NULL, "Headphone Jack");
|
|
if (ret)
|
|
goto asrc_fail;
|
|
|
|
snd_soc_jack_notifier_register(&priv->hp_jack.jack, &hp_jack_nb);
|
|
}
|
|
|
|
if (of_property_read_bool(np, "mic-det-gpio")) {
|
|
ret = asoc_simple_init_jack(&priv->card, &priv->mic_jack,
|
|
0, NULL, "Mic Jack");
|
|
if (ret)
|
|
goto asrc_fail;
|
|
|
|
snd_soc_jack_notifier_register(&priv->mic_jack.jack, &mic_jack_nb);
|
|
}
|
|
|
|
asrc_fail:
|
|
of_node_put(asrc_np);
|
|
of_node_put(codec_np);
|
|
put_device(&cpu_pdev->dev);
|
|
fail:
|
|
of_node_put(cpu_np);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static const struct of_device_id fsl_asoc_card_dt_ids[] = {
|
|
{ .compatible = "fsl,imx-audio-ac97", },
|
|
{ .compatible = "fsl,imx-audio-cs42888", },
|
|
{ .compatible = "fsl,imx-audio-cs427x", },
|
|
{ .compatible = "fsl,imx-audio-sgtl5000", },
|
|
{ .compatible = "fsl,imx-audio-wm8962", },
|
|
{ .compatible = "fsl,imx-audio-wm8960", },
|
|
{ .compatible = "fsl,imx-audio-mqs", },
|
|
{ .compatible = "fsl,imx-audio-wm8524", },
|
|
{}
|
|
};
|
|
MODULE_DEVICE_TABLE(of, fsl_asoc_card_dt_ids);
|
|
|
|
static struct platform_driver fsl_asoc_card_driver = {
|
|
.probe = fsl_asoc_card_probe,
|
|
.driver = {
|
|
.name = "fsl-asoc-card",
|
|
.pm = &snd_soc_pm_ops,
|
|
.of_match_table = fsl_asoc_card_dt_ids,
|
|
},
|
|
};
|
|
module_platform_driver(fsl_asoc_card_driver);
|
|
|
|
MODULE_DESCRIPTION("Freescale Generic ASoC Sound Card driver with ASRC");
|
|
MODULE_AUTHOR("Nicolin Chen <nicoleotsuka@gmail.com>");
|
|
MODULE_ALIAS("platform:fsl-asoc-card");
|
|
MODULE_LICENSE("GPL");
|