File Index
Files and directories
Sign in
FILE

fsl-asoc-card.c

File preview with syntax highlighting.

linux-6.19.14/sound/soc/fsl/fsl-asoc-card.c C
   1// SPDX-License-Identifier: GPL-2.0
   2//
   3// Freescale Generic ASoC Sound Card driver with ASRC
   4//
   5// Copyright (C) 2014 Freescale Semiconductor, Inc.
   6//
   7// Author: Nicolin Chen <nicoleotsuka@gmail.com>
   8
   9#include <linux/clk.h>
  10#include <linux/i2c.h>
  11#include <linux/module.h>
  12#include <linux/of_platform.h>
  13#if IS_ENABLED(CONFIG_SND_AC97_CODEC)
  14#include <sound/ac97_codec.h>
  15#endif
  16#include <sound/pcm_params.h>
  17#include <sound/soc.h>
  18#include <sound/jack.h>
  19#include <sound/simple_card_utils.h>
  20
  21#include "fsl_esai.h"
  22#include "fsl_sai.h"
  23#include "imx-audmux.h"
  24
  25#include "../codecs/sgtl5000.h"
  26#include "../codecs/wm8962.h"
  27#include "../codecs/wm8960.h"
  28#include "../codecs/wm8994.h"
  29#include "../codecs/tlv320aic31xx.h"
  30#include "../codecs/nau8822.h"
  31#include "../codecs/wm8904.h"
  32
  33#define DRIVER_NAME "fsl-asoc-card"
  34
  35#define CS427x_SYSCLK_MCLK 0
  36
  37#define RX 0
  38#define TX 1
  39
  40/* Default DAI format without Master and Slave flag */
  41#define DAI_FMT_BASE (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF)
  42
  43/**
  44 * struct codec_priv - CODEC private data
  45 * @mclk: Main clock of the CODEC
  46 * @mclk_freq: Clock rate of MCLK
  47 * @free_freq: Clock rate of MCLK for hw_free()
  48 * @mclk_id: MCLK (or main clock) id for set_sysclk()
  49 * @fll_id: FLL (or secordary clock) id for set_sysclk()
  50 * @pll_id: PLL id for set_pll()
  51 */
  52struct codec_priv {
  53	struct clk *mclk;
  54	unsigned long mclk_freq;
  55	unsigned long free_freq;
  56	u32 mclk_id;
  57	int fll_id;
  58	int pll_id;
  59};
  60
  61/**
  62 * struct cpu_priv - CPU private data
  63 * @sysclk_freq: SYSCLK rates for set_sysclk()
  64 * @sysclk_dir: SYSCLK directions for set_sysclk()
  65 * @sysclk_id: SYSCLK ids for set_sysclk()
  66 * @sysclk_ratio: SYSCLK ratio on sample rate
  67 * @slot_width: Slot width of each frame
  68 * @slot_num: Number of slots of each frame
  69 *
  70 * Note: [1] for tx and [0] for rx
  71 */
  72struct cpu_priv {
  73	unsigned long sysclk_freq[2];
  74	u32 sysclk_dir[2];
  75	u32 sysclk_id[2];
  76	u32 sysclk_ratio[2];
  77	u32 slot_width;
  78	u32 slot_num;
  79};
  80
  81/**
  82 * struct fsl_asoc_card_priv - Freescale Generic ASOC card private data
  83 * @dai_link: DAI link structure including normal one and DPCM link
  84 * @hp_jack: Headphone Jack structure
  85 * @mic_jack: Microphone Jack structure
  86 * @pdev: platform device pointer
  87 * @codec_priv: CODEC private data
  88 * @cpu_priv: CPU private data
  89 * @card: ASoC card structure
  90 * @streams: Mask of current active streams
  91 * @sample_rate: Current sample rate
  92 * @sample_format: Current sample format
  93 * @asrc_rate: ASRC sample rate used by Back-Ends
  94 * @asrc_format: ASRC sample format used by Back-Ends
  95 * @dai_fmt: DAI format between CPU and CODEC
  96 * @name: Card name
  97 */
  98
  99struct fsl_asoc_card_priv {
 100	struct snd_soc_dai_link dai_link[3];
 101	struct simple_util_jack hp_jack;
 102	struct simple_util_jack mic_jack;
 103	struct platform_device *pdev;
 104	struct codec_priv codec_priv[2];
 105	struct cpu_priv cpu_priv;
 106	struct snd_soc_card card;
 107	u8 streams;
 108	u32 sample_rate;
 109	snd_pcm_format_t sample_format;
 110	u32 asrc_rate;
 111	snd_pcm_format_t asrc_format;
 112	u32 dai_fmt;
 113	char name[32];
 114};
 115
 116/*
 117 * This dapm route map exists for DPCM link only.
 118 * The other routes shall go through Device Tree.
 119 *
 120 * Note: keep all ASRC routes in the second half
 121 *	 to drop them easily for non-ASRC cases.
 122 */
 123static const struct snd_soc_dapm_route audio_map[] = {
 124	/* 1st half -- Normal DAPM routes */
 125	{"Playback",  NULL, "CPU-Playback"},
 126	{"CPU-Capture",  NULL, "Capture"},
 127	/* 2nd half -- ASRC DAPM routes */
 128	{"CPU-Playback",  NULL, "ASRC-Playback"},
 129	{"ASRC-Capture",  NULL, "CPU-Capture"},
 130};
 131
 132static const struct snd_soc_dapm_route audio_map_ac97[] = {
 133	/* 1st half -- Normal DAPM routes */
 134	{"AC97 Playback",  NULL, "CPU AC97 Playback"},
 135	{"CPU AC97 Capture",  NULL, "AC97 Capture"},
 136	/* 2nd half -- ASRC DAPM routes */
 137	{"CPU AC97 Playback",  NULL, "ASRC-Playback"},
 138	{"ASRC-Capture",  NULL, "CPU AC97 Capture"},
 139};
 140
 141static const struct snd_soc_dapm_route audio_map_tx[] = {
 142	/* 1st half -- Normal DAPM routes */
 143	{"Playback",  NULL, "CPU-Playback"},
 144	/* 2nd half -- ASRC DAPM routes */
 145	{"CPU-Playback",  NULL, "ASRC-Playback"},
 146};
 147
 148static const struct snd_soc_dapm_route audio_map_rx[] = {
 149	/* 1st half -- Normal DAPM routes */
 150	{"CPU-Capture",  NULL, "Capture"},
 151	/* 2nd half -- ASRC DAPM routes */
 152	{"ASRC-Capture",  NULL, "CPU-Capture"},
 153};
 154
 155/* Add all possible widgets into here without being redundant */
 156static const struct snd_soc_dapm_widget fsl_asoc_card_dapm_widgets[] = {
 157	SND_SOC_DAPM_LINE("Line Out Jack", NULL),
 158	SND_SOC_DAPM_LINE("Line In Jack", NULL),
 159	SND_SOC_DAPM_HP("Headphone Jack", NULL),
 160	SND_SOC_DAPM_SPK("Ext Spk", NULL),
 161	SND_SOC_DAPM_MIC("Mic Jack", NULL),
 162	SND_SOC_DAPM_MIC("AMIC", NULL),
 163	SND_SOC_DAPM_MIC("DMIC", NULL),
 164};
 165
 166static bool fsl_asoc_card_is_ac97(struct fsl_asoc_card_priv *priv)
 167{
 168	return priv->dai_fmt == SND_SOC_DAIFMT_AC97;
 169}
 170
 171static int fsl_asoc_card_hw_params(struct snd_pcm_substream *substream,
 172				   struct snd_pcm_hw_params *params)
 173{
 174	struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
 175	struct fsl_asoc_card_priv *priv = snd_soc_card_get_drvdata(rtd->card);
 176	bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
 177	struct codec_priv *codec_priv;
 178	struct snd_soc_dai *codec_dai;
 179	struct cpu_priv *cpu_priv = &priv->cpu_priv;
 180	struct device *dev = rtd->card->dev;
 181	unsigned int pll_out, sysclk_freq;
 182	int codec_idx;
 183	int ret;
 184
 185	priv->sample_rate = params_rate(params);
 186	priv->sample_format = params_format(params);
 187	priv->streams |= BIT(substream->stream);
 188
 189	if (fsl_asoc_card_is_ac97(priv))
 190		return 0;
 191
 192	if (!cpu_priv->sysclk_freq[tx] && cpu_priv->sysclk_ratio[tx])
 193		sysclk_freq = priv->sample_rate * cpu_priv->sysclk_ratio[tx];
 194	else
 195		sysclk_freq = cpu_priv->sysclk_freq[tx];
 196
 197	/* Specific configurations of DAIs starts from here */
 198	ret = snd_soc_dai_set_sysclk(snd_soc_rtd_to_cpu(rtd, 0), cpu_priv->sysclk_id[tx],
 199				     sysclk_freq,
 200				     cpu_priv->sysclk_dir[tx]);
 201	if (ret && ret != -ENOTSUPP) {
 202		dev_err(dev, "failed to set sysclk for cpu dai\n");
 203		goto fail;
 204	}
 205
 206	if (cpu_priv->slot_width) {
 207		if (!cpu_priv->slot_num)
 208			cpu_priv->slot_num = 2;
 209
 210		ret = snd_soc_dai_set_tdm_slot(snd_soc_rtd_to_cpu(rtd, 0), 0x3, 0x3,
 211					       cpu_priv->slot_num,
 212					       cpu_priv->slot_width);
 213		if (ret && ret != -ENOTSUPP) {
 214			dev_err(dev, "failed to set TDM slot for cpu dai\n");
 215			goto fail;
 216		}
 217	}
 218
 219	/* Specific configuration for PLL */
 220	for_each_rtd_codec_dais(rtd, codec_idx, codec_dai) {
 221		codec_priv = &priv->codec_priv[codec_idx];
 222
 223		if (codec_priv->pll_id >= 0 && codec_priv->fll_id >= 0) {
 224			if (priv->sample_format == SNDRV_PCM_FORMAT_S24_LE)
 225				pll_out = priv->sample_rate * 384;
 226			else
 227				pll_out = priv->sample_rate * 256;
 228
 229			ret = snd_soc_dai_set_pll(codec_dai,
 230						codec_priv->pll_id,
 231						codec_priv->mclk_id,
 232						codec_priv->mclk_freq, pll_out);
 233			if (ret) {
 234				dev_err(dev, "failed to start FLL: %d\n", ret);
 235				goto fail;
 236			}
 237
 238			ret = snd_soc_dai_set_sysclk(codec_dai,
 239						codec_priv->fll_id,
 240						pll_out, SND_SOC_CLOCK_IN);
 241
 242			if (ret && ret != -ENOTSUPP) {
 243				dev_err(dev, "failed to set SYSCLK: %d\n", ret);
 244				goto fail;
 245			}
 246		}
 247	}
 248
 249	return 0;
 250
 251fail:
 252	priv->streams &= ~BIT(substream->stream);
 253	return ret;
 254}
 255
 256static int fsl_asoc_card_hw_free(struct snd_pcm_substream *substream)
 257{
 258	struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
 259	struct fsl_asoc_card_priv *priv = snd_soc_card_get_drvdata(rtd->card);
 260	struct codec_priv *codec_priv;
 261	struct snd_soc_dai *codec_dai;
 262	struct device *dev = rtd->card->dev;
 263	int codec_idx;
 264	int ret;
 265
 266	priv->streams &= ~BIT(substream->stream);
 267
 268	for_each_rtd_codec_dais(rtd, codec_idx, codec_dai) {
 269		codec_priv = &priv->codec_priv[codec_idx];
 270
 271		if (!priv->streams && codec_priv->pll_id >= 0 && codec_priv->fll_id >= 0) {
 272			/* Force freq to be free_freq to avoid error message in codec */
 273			ret = snd_soc_dai_set_sysclk(codec_dai,
 274						codec_priv->mclk_id,
 275						codec_priv->free_freq,
 276						SND_SOC_CLOCK_IN);
 277			if (ret) {
 278				dev_err(dev, "failed to switch away from FLL: %d\n", ret);
 279				return ret;
 280			}
 281
 282			ret = snd_soc_dai_set_pll(codec_dai,
 283						codec_priv->pll_id, 0, 0, 0);
 284			if (ret && ret != -ENOTSUPP) {
 285				dev_err(dev, "failed to stop FLL: %d\n", ret);
 286				return ret;
 287			}
 288		}
 289	}
 290
 291	return 0;
 292}
 293
 294static const struct snd_soc_ops fsl_asoc_card_ops = {
 295	.hw_params = fsl_asoc_card_hw_params,
 296	.hw_free = fsl_asoc_card_hw_free,
 297};
 298
 299static int be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
 300			      struct snd_pcm_hw_params *params)
 301{
 302	struct fsl_asoc_card_priv *priv = snd_soc_card_get_drvdata(rtd->card);
 303	struct snd_interval *rate;
 304	struct snd_mask *mask;
 305
 306	rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
 307	rate->max = rate->min = priv->asrc_rate;
 308
 309	mask = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
 310	snd_mask_none(mask);
 311	snd_mask_set_format(mask, priv->asrc_format);
 312
 313	return 0;
 314}
 315
 316static const struct snd_soc_dai_link fsl_asoc_card_dai[] = {
 317	/* Default ASoC DAI Link*/
 318	{
 319		.name = "HiFi",
 320		.stream_name = "HiFi",
 321		.ops = &fsl_asoc_card_ops,
 322	},
 323	/* DPCM Link between Front-End and Back-End (Optional) */
 324	{
 325		.name = "HiFi-ASRC-FE",
 326		.stream_name = "HiFi-ASRC-FE",
 327		.dynamic = 1,
 328	},
 329	{
 330		.name = "HiFi-ASRC-BE",
 331		.stream_name = "HiFi-ASRC-BE",
 332		.be_hw_params_fixup = be_hw_params_fixup,
 333		.ops = &fsl_asoc_card_ops,
 334		.no_pcm = 1,
 335	},
 336};
 337
 338static int fsl_asoc_card_audmux_init(struct device_node *np,
 339				     struct fsl_asoc_card_priv *priv)
 340{
 341	struct device *dev = &priv->pdev->dev;
 342	u32 int_ptcr = 0, ext_ptcr = 0;
 343	int int_port, ext_port;
 344	int ret;
 345
 346	ret = of_property_read_u32(np, "mux-int-port", &int_port);
 347	if (ret) {
 348		dev_err(dev, "mux-int-port missing or invalid\n");
 349		return ret;
 350	}
 351	ret = of_property_read_u32(np, "mux-ext-port", &ext_port);
 352	if (ret) {
 353		dev_err(dev, "mux-ext-port missing or invalid\n");
 354		return ret;
 355	}
 356
 357	/*
 358	 * The port numbering in the hardware manual starts at 1, while
 359	 * the AUDMUX API expects it starts at 0.
 360	 */
 361	int_port--;
 362	ext_port--;
 363
 364	/*
 365	 * Use asynchronous mode (6 wires) for all cases except AC97.
 366	 * If only 4 wires are needed, just set SSI into
 367	 * synchronous mode and enable 4 PADs in IOMUX.
 368	 */
 369	switch (priv->dai_fmt & SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK) {
 370	case SND_SOC_DAIFMT_CBP_CFP:
 371		int_ptcr = IMX_AUDMUX_V2_PTCR_RFSEL(8 | ext_port) |
 372			   IMX_AUDMUX_V2_PTCR_RCSEL(8 | ext_port) |
 373			   IMX_AUDMUX_V2_PTCR_TFSEL(ext_port) |
 374			   IMX_AUDMUX_V2_PTCR_TCSEL(ext_port) |
 375			   IMX_AUDMUX_V2_PTCR_RFSDIR |
 376			   IMX_AUDMUX_V2_PTCR_RCLKDIR |
 377			   IMX_AUDMUX_V2_PTCR_TFSDIR |
 378			   IMX_AUDMUX_V2_PTCR_TCLKDIR;
 379		break;
 380	case SND_SOC_DAIFMT_CBP_CFC:
 381		int_ptcr = IMX_AUDMUX_V2_PTCR_RCSEL(8 | ext_port) |
 382			   IMX_AUDMUX_V2_PTCR_TCSEL(ext_port) |
 383			   IMX_AUDMUX_V2_PTCR_RCLKDIR |
 384			   IMX_AUDMUX_V2_PTCR_TCLKDIR;
 385		ext_ptcr = IMX_AUDMUX_V2_PTCR_RFSEL(8 | int_port) |
 386			   IMX_AUDMUX_V2_PTCR_TFSEL(int_port) |
 387			   IMX_AUDMUX_V2_PTCR_RFSDIR |
 388			   IMX_AUDMUX_V2_PTCR_TFSDIR;
 389		break;
 390	case SND_SOC_DAIFMT_CBC_CFP:
 391		int_ptcr = IMX_AUDMUX_V2_PTCR_RFSEL(8 | ext_port) |
 392			   IMX_AUDMUX_V2_PTCR_TFSEL(ext_port) |
 393			   IMX_AUDMUX_V2_PTCR_RFSDIR |
 394			   IMX_AUDMUX_V2_PTCR_TFSDIR;
 395		ext_ptcr = IMX_AUDMUX_V2_PTCR_RCSEL(8 | int_port) |
 396			   IMX_AUDMUX_V2_PTCR_TCSEL(int_port) |
 397			   IMX_AUDMUX_V2_PTCR_RCLKDIR |
 398			   IMX_AUDMUX_V2_PTCR_TCLKDIR;
 399		break;
 400	case SND_SOC_DAIFMT_CBC_CFC:
 401		ext_ptcr = IMX_AUDMUX_V2_PTCR_RFSEL(8 | int_port) |
 402			   IMX_AUDMUX_V2_PTCR_RCSEL(8 | int_port) |
 403			   IMX_AUDMUX_V2_PTCR_TFSEL(int_port) |
 404			   IMX_AUDMUX_V2_PTCR_TCSEL(int_port) |
 405			   IMX_AUDMUX_V2_PTCR_RFSDIR |
 406			   IMX_AUDMUX_V2_PTCR_RCLKDIR |
 407			   IMX_AUDMUX_V2_PTCR_TFSDIR |
 408			   IMX_AUDMUX_V2_PTCR_TCLKDIR;
 409		break;
 410	default:
 411		if (!fsl_asoc_card_is_ac97(priv))
 412			return -EINVAL;
 413	}
 414
 415	if (fsl_asoc_card_is_ac97(priv)) {
 416		int_ptcr = IMX_AUDMUX_V2_PTCR_SYN |
 417			   IMX_AUDMUX_V2_PTCR_TCSEL(ext_port) |
 418			   IMX_AUDMUX_V2_PTCR_TCLKDIR;
 419		ext_ptcr = IMX_AUDMUX_V2_PTCR_SYN |
 420			   IMX_AUDMUX_V2_PTCR_TFSEL(int_port) |
 421			   IMX_AUDMUX_V2_PTCR_TFSDIR;
 422	}
 423
 424	/* Asynchronous mode can not be set along with RCLKDIR */
 425	if (!fsl_asoc_card_is_ac97(priv)) {
 426		unsigned int pdcr =
 427				IMX_AUDMUX_V2_PDCR_RXDSEL(ext_port);
 428
 429		ret = imx_audmux_v2_configure_port(int_port, 0,
 430						   pdcr);
 431		if (ret) {
 432			dev_err(dev, "audmux internal port setup failed\n");
 433			return ret;
 434		}
 435	}
 436
 437	ret = imx_audmux_v2_configure_port(int_port, int_ptcr,
 438					   IMX_AUDMUX_V2_PDCR_RXDSEL(ext_port));
 439	if (ret) {
 440		dev_err(dev, "audmux internal port setup failed\n");
 441		return ret;
 442	}
 443
 444	if (!fsl_asoc_card_is_ac97(priv)) {
 445		unsigned int pdcr =
 446				IMX_AUDMUX_V2_PDCR_RXDSEL(int_port);
 447
 448		ret = imx_audmux_v2_configure_port(ext_port, 0,
 449						   pdcr);
 450		if (ret) {
 451			dev_err(dev, "audmux external port setup failed\n");
 452			return ret;
 453		}
 454	}
 455
 456	ret = imx_audmux_v2_configure_port(ext_port, ext_ptcr,
 457					   IMX_AUDMUX_V2_PDCR_RXDSEL(int_port));
 458	if (ret) {
 459		dev_err(dev, "audmux external port setup failed\n");
 460		return ret;
 461	}
 462
 463	return 0;
 464}
 465
 466static int fsl_asoc_card_spdif_init(struct device_node *codec_np[],
 467				    struct device_node *cpu_np,
 468				    const char *codec_dai_name[],
 469				    struct fsl_asoc_card_priv *priv)
 470{
 471	struct device *dev = &priv->pdev->dev;
 472	struct device_node *np = dev->of_node;
 473
 474	if (!of_node_name_eq(cpu_np, "spdif")) {
 475		dev_err(dev, "CPU phandle invalid, should be an SPDIF device\n");
 476		return -EINVAL;
 477	}
 478
 479	priv->dai_link[0].playback_only = true;
 480	priv->dai_link[0].capture_only = true;
 481
 482	for (int i = 0; i < 2; i++) {
 483		if (!codec_np[i])
 484			break;
 485
 486		if (of_device_is_compatible(codec_np[i], "linux,spdif-dit")) {
 487			priv->dai_link[0].capture_only = false;
 488			codec_dai_name[i] = "dit-hifi";
 489		} else if (of_device_is_compatible(codec_np[i], "linux,spdif-dir")) {
 490			priv->dai_link[0].playback_only = false;
 491			codec_dai_name[i] = "dir-hifi";
 492		}
 493	}
 494
 495	// Old SPDIF DT binding
 496	if (!codec_np[0]) {
 497		codec_dai_name[0] = snd_soc_dummy_dlc.dai_name;
 498		if (of_property_read_bool(np, "spdif-out"))
 499			priv->dai_link[0].capture_only = false;
 500		if (of_property_read_bool(np, "spdif-in"))
 501			priv->dai_link[0].playback_only = false;
 502	}
 503
 504	if (priv->dai_link[0].playback_only && priv->dai_link[0].capture_only) {
 505		dev_err(dev, "no enabled S/PDIF DAI link\n");
 506		return -EINVAL;
 507	}
 508
 509	if (priv->dai_link[0].playback_only) {
 510		priv->dai_link[1].playback_only = true;
 511		priv->dai_link[2].playback_only = true;
 512		priv->card.dapm_routes = audio_map_tx;
 513		priv->card.num_dapm_routes = ARRAY_SIZE(audio_map_tx);
 514	} else if (priv->dai_link[0].capture_only) {
 515		priv->dai_link[1].capture_only = true;
 516		priv->dai_link[2].capture_only = true;
 517		priv->card.dapm_routes = audio_map_rx;
 518		priv->card.num_dapm_routes = ARRAY_SIZE(audio_map_rx);
 519	}
 520
 521	// No DAPM routes with old bindings and dummy codec
 522	if (!codec_np[0]) {
 523		priv->card.dapm_routes = NULL;
 524		priv->card.num_dapm_routes = 0;
 525	}
 526
 527	if (codec_np[0] && codec_np[1]) {
 528		priv->dai_link[0].num_codecs = 2;
 529		priv->dai_link[2].num_codecs = 2;
 530	}
 531
 532	return 0;
 533}
 534
 535static int hp_jack_event(struct notifier_block *nb, unsigned long event,
 536			 void *data)
 537{
 538	struct snd_soc_jack *jack = (struct snd_soc_jack *)data;
 539	struct snd_soc_dapm_context *dapm = snd_soc_card_to_dapm(jack->card);
 540
 541	if (event & SND_JACK_HEADPHONE)
 542		/* Disable speaker if headphone is plugged in */
 543		return snd_soc_dapm_disable_pin(dapm, "Ext Spk");
 544	else
 545		return snd_soc_dapm_enable_pin(dapm, "Ext Spk");
 546}
 547
 548static struct notifier_block hp_jack_nb = {
 549	.notifier_call = hp_jack_event,
 550};
 551
 552static int mic_jack_event(struct notifier_block *nb, unsigned long event,
 553			  void *data)
 554{
 555	struct snd_soc_jack *jack = (struct snd_soc_jack *)data;
 556	struct snd_soc_dapm_context *dapm = snd_soc_card_to_dapm(jack->card);
 557
 558	if (event & SND_JACK_MICROPHONE)
 559		/* Disable dmic if microphone is plugged in */
 560		return snd_soc_dapm_disable_pin(dapm, "DMIC");
 561	else
 562		return snd_soc_dapm_enable_pin(dapm, "DMIC");
 563}
 564
 565static struct notifier_block mic_jack_nb = {
 566	.notifier_call = mic_jack_event,
 567};
 568
 569static int fsl_asoc_card_late_probe(struct snd_soc_card *card)
 570{
 571	struct fsl_asoc_card_priv *priv = snd_soc_card_get_drvdata(card);
 572	struct snd_soc_pcm_runtime *rtd = list_first_entry(
 573			&card->rtd_list, struct snd_soc_pcm_runtime, list);
 574	struct snd_soc_dai *codec_dai;
 575	struct codec_priv *codec_priv;
 576	struct device *dev = card->dev;
 577	int codec_idx;
 578	int ret;
 579
 580	if (fsl_asoc_card_is_ac97(priv)) {
 581#if IS_ENABLED(CONFIG_SND_AC97_CODEC)
 582		struct snd_soc_component *component = snd_soc_rtd_to_codec(rtd, 0)->component;
 583		struct snd_ac97 *ac97 = snd_soc_component_get_drvdata(component);
 584
 585		/*
 586		 * Use slots 3/4 for S/PDIF so SSI won't try to enable
 587		 * other slots and send some samples there
 588		 * due to SLOTREQ bits for S/PDIF received from codec
 589		 */
 590		snd_ac97_update_bits(ac97, AC97_EXTENDED_STATUS,
 591				     AC97_EA_SPSA_SLOT_MASK, AC97_EA_SPSA_3_4);
 592#endif
 593
 594		return 0;
 595	}
 596
 597	for_each_rtd_codec_dais(rtd, codec_idx, codec_dai) {
 598		codec_priv = &priv->codec_priv[codec_idx];
 599
 600		ret = snd_soc_dai_set_sysclk(codec_dai, codec_priv->mclk_id,
 601					codec_priv->mclk_freq, SND_SOC_CLOCK_IN);
 602		if (ret && ret != -ENOTSUPP) {
 603			dev_err(dev, "failed to set sysclk in %s\n", __func__);
 604			return ret;
 605		}
 606
 607		if (!IS_ERR_OR_NULL(codec_priv->mclk))
 608			clk_prepare_enable(codec_priv->mclk);
 609	}
 610
 611	return 0;
 612}
 613
 614static int fsl_asoc_card_probe(struct platform_device *pdev)
 615{
 616	struct device_node *cpu_np, *asrc_np;
 617	struct snd_soc_dai_link_component *codec_comp;
 618	struct device_node *codec_np[2];
 619	struct device_node *np = pdev->dev.of_node;
 620	struct platform_device *asrc_pdev = NULL;
 621	struct device_node *bitclkprovider = NULL;
 622	struct device_node *frameprovider = NULL;
 623	struct platform_device *cpu_pdev;
 624	struct fsl_asoc_card_priv *priv;
 625	struct device *codec_dev[2] = { NULL, NULL };
 626	struct snd_soc_dai_link_component *dlc;
 627	const char *codec_dai_name[2];
 628	const char *codec_dev_name[2];
 629	u32 asrc_fmt = 0;
 630	int codec_idx;
 631	u32 width;
 632	int ret;
 633
 634	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
 635	if (!priv)
 636		return -ENOMEM;
 637
 638	priv->pdev = pdev;
 639
 640	cpu_np = of_parse_phandle(np, "audio-cpu", 0);
 641	/* Give a chance to old DT bindings */
 642	if (!cpu_np)
 643		cpu_np = of_parse_phandle(np, "ssi-controller", 0);
 644	if (!cpu_np)
 645		cpu_np = of_parse_phandle(np, "spdif-controller", 0);
 646	if (!cpu_np) {
 647		dev_err(&pdev->dev, "CPU phandle missing or invalid\n");
 648		ret = -EINVAL;
 649		goto fail;
 650	}
 651
 652	cpu_pdev = of_find_device_by_node(cpu_np);
 653	if (!cpu_pdev) {
 654		dev_err(&pdev->dev, "failed to find CPU DAI device\n");
 655		ret = -EINVAL;
 656		goto fail;
 657	}
 658
 659	codec_np[0] = of_parse_phandle(np, "audio-codec", 0);
 660	codec_np[1] = of_parse_phandle(np, "audio-codec", 1);
 661
 662	for (codec_idx = 0; codec_idx < 2; codec_idx++) {
 663		if (codec_np[codec_idx]) {
 664			struct platform_device *codec_pdev;
 665			struct i2c_client *codec_i2c;
 666
 667			codec_i2c = of_find_i2c_device_by_node(codec_np[codec_idx]);
 668			if (codec_i2c) {
 669				codec_dev[codec_idx] = &codec_i2c->dev;
 670				codec_dev_name[codec_idx] = codec_i2c->name;
 671			}
 672			if (!codec_dev[codec_idx]) {
 673				codec_pdev = of_find_device_by_node(codec_np[codec_idx]);
 674				if (codec_pdev) {
 675					codec_dev[codec_idx] = &codec_pdev->dev;
 676					codec_dev_name[codec_idx] = codec_pdev->name;
 677				}
 678			}
 679		}
 680	}
 681
 682	asrc_np = of_parse_phandle(np, "audio-asrc", 0);
 683	if (asrc_np)
 684		asrc_pdev = of_find_device_by_node(asrc_np);
 685
 686	/* Get the MCLK rate only, and leave it controlled by CODEC drivers */
 687	for (codec_idx = 0; codec_idx < 2; codec_idx++) {
 688		if (codec_dev[codec_idx]) {
 689			struct clk *codec_clk = clk_get(codec_dev[codec_idx], NULL);
 690
 691			if (!IS_ERR(codec_clk)) {
 692				priv->codec_priv[codec_idx].mclk_freq = clk_get_rate(codec_clk);
 693				clk_put(codec_clk);
 694			}
 695		}
 696	}
 697
 698	/* Default sample rate and format, will be updated in hw_params() */
 699	priv->sample_rate = 44100;
 700	priv->sample_format = SNDRV_PCM_FORMAT_S16_LE;
 701
 702	/* Assign a default DAI format, and allow each card to overwrite it */
 703	priv->dai_fmt = DAI_FMT_BASE;
 704
 705	memcpy(priv->dai_link, fsl_asoc_card_dai,
 706	       sizeof(struct snd_soc_dai_link) * ARRAY_SIZE(priv->dai_link));
 707	/*
 708	 * "Default ASoC DAI Link": 1 cpus, 2 codecs, 1 platforms
 709	 * "DPCM Link Front-End":  1 cpus, 1 codecs (dummy), 1 platforms
 710	 * "DPCM Link Back-End": 1 cpus, 2 codecs
 711	 * totally 10 components
 712	 */
 713	dlc = devm_kcalloc(&pdev->dev, 10, sizeof(*dlc), GFP_KERNEL);
 714	if (!dlc) {
 715		ret = -ENOMEM;
 716		goto asrc_fail;
 717	}
 718
 719	priv->dai_link[0].cpus = &dlc[0];
 720	priv->dai_link[0].num_cpus = 1;
 721	priv->dai_link[0].codecs = &dlc[1];
 722	priv->dai_link[0].num_codecs = 1;
 723	priv->dai_link[0].platforms = &dlc[3];
 724	priv->dai_link[0].num_platforms = 1;
 725
 726	priv->dai_link[1].cpus = &dlc[4];
 727	priv->dai_link[1].num_cpus = 1;
 728	priv->dai_link[1].codecs = &dlc[5];
 729	priv->dai_link[1].num_codecs = 0; /* dummy */
 730	priv->dai_link[1].platforms = &dlc[6];
 731	priv->dai_link[1].num_platforms = 1;
 732
 733	priv->dai_link[2].cpus = &dlc[7];
 734	priv->dai_link[2].num_cpus = 1;
 735	priv->dai_link[2].codecs = &dlc[8];
 736	priv->dai_link[2].num_codecs = 1;
 737
 738	priv->card.dapm_routes = audio_map;
 739	priv->card.num_dapm_routes = ARRAY_SIZE(audio_map);
 740	priv->card.driver_name = DRIVER_NAME;
 741
 742	for (codec_idx = 0; codec_idx < 2; codec_idx++) {
 743		priv->codec_priv[codec_idx].fll_id = -1;
 744		priv->codec_priv[codec_idx].pll_id = -1;
 745	}
 746
 747	/* Diversify the card configurations */
 748	if (of_device_is_compatible(np, "fsl,imx-audio-cs42888")) {
 749		codec_dai_name[0] = "cs42888";
 750		priv->cpu_priv.sysclk_freq[TX] = priv->codec_priv[0].mclk_freq;
 751		priv->cpu_priv.sysclk_freq[RX] = priv->codec_priv[0].mclk_freq;
 752		priv->cpu_priv.sysclk_dir[TX] = SND_SOC_CLOCK_OUT;
 753		priv->cpu_priv.sysclk_dir[RX] = SND_SOC_CLOCK_OUT;
 754		priv->cpu_priv.slot_width = 32;
 755		priv->dai_fmt |= SND_SOC_DAIFMT_CBC_CFC;
 756	} else if (of_device_is_compatible(np, "fsl,imx-audio-cs427x")) {
 757		codec_dai_name[0] = "cs4271-hifi";
 758		priv->codec_priv[0].mclk_id = CS427x_SYSCLK_MCLK;
 759		priv->dai_fmt |= SND_SOC_DAIFMT_CBP_CFP;
 760	} else if (of_device_is_compatible(np, "fsl,imx-audio-sgtl5000")) {
 761		codec_dai_name[0] = "sgtl5000";
 762		priv->codec_priv[0].mclk_id = SGTL5000_SYSCLK;
 763		priv->dai_fmt |= SND_SOC_DAIFMT_CBP_CFP;
 764	} else if (of_device_is_compatible(np, "fsl,imx-audio-tlv320aic32x4")) {
 765		codec_dai_name[0] = "tlv320aic32x4-hifi";
 766		priv->dai_fmt |= SND_SOC_DAIFMT_CBP_CFP;
 767	} else if (of_device_is_compatible(np, "fsl,imx-audio-tlv320aic31xx")) {
 768		codec_dai_name[0] = "tlv320dac31xx-hifi";
 769		priv->dai_fmt |= SND_SOC_DAIFMT_CBC_CFC;
 770		priv->dai_link[1].playback_only = 1;
 771		priv->dai_link[2].playback_only = 1;
 772		priv->cpu_priv.sysclk_dir[TX] = SND_SOC_CLOCK_OUT;
 773		priv->cpu_priv.sysclk_dir[RX] = SND_SOC_CLOCK_OUT;
 774		priv->card.dapm_routes = audio_map_tx;
 775		priv->card.num_dapm_routes = ARRAY_SIZE(audio_map_tx);
 776	} else if (of_device_is_compatible(np, "fsl,imx-audio-wm8962")) {
 777		codec_dai_name[0] = "wm8962";
 778		priv->codec_priv[0].mclk_id = WM8962_SYSCLK_MCLK;
 779		priv->codec_priv[0].fll_id = WM8962_SYSCLK_FLL;
 780		priv->codec_priv[0].pll_id = WM8962_FLL;
 781		priv->dai_fmt |= SND_SOC_DAIFMT_CBP_CFP;
 782	} else if (of_device_is_compatible(np, "fsl,imx-audio-wm8960")) {
 783		codec_dai_name[0] = "wm8960-hifi";
 784		priv->codec_priv[0].fll_id = WM8960_SYSCLK_AUTO;
 785		priv->codec_priv[0].pll_id = WM8960_SYSCLK_AUTO;
 786		priv->dai_fmt |= SND_SOC_DAIFMT_CBP_CFP;
 787	} else if (of_device_is_compatible(np, "fsl,imx-audio-ac97")) {
 788		codec_dai_name[0] = "ac97-hifi";
 789		priv->dai_fmt = SND_SOC_DAIFMT_AC97;
 790		priv->card.dapm_routes = audio_map_ac97;
 791		priv->card.num_dapm_routes = ARRAY_SIZE(audio_map_ac97);
 792	} else if (of_device_is_compatible(np, "fsl,imx-audio-mqs")) {
 793		codec_dai_name[0] = "fsl-mqs-dai";
 794		priv->dai_fmt = SND_SOC_DAIFMT_LEFT_J |
 795				SND_SOC_DAIFMT_CBC_CFC |
 796				SND_SOC_DAIFMT_NB_NF;
 797		priv->dai_link[1].playback_only = 1;
 798		priv->dai_link[2].playback_only = 1;
 799		priv->card.dapm_routes = audio_map_tx;
 800		priv->card.num_dapm_routes = ARRAY_SIZE(audio_map_tx);
 801	} else if (of_device_is_compatible(np, "fsl,imx-audio-wm8524")) {
 802		codec_dai_name[0] = "wm8524-hifi";
 803		priv->dai_fmt |= SND_SOC_DAIFMT_CBC_CFC;
 804		priv->dai_link[1].playback_only = 1;
 805		priv->dai_link[2].playback_only = 1;
 806		priv->cpu_priv.slot_width = 32;
 807		priv->card.dapm_routes = audio_map_tx;
 808		priv->card.num_dapm_routes = ARRAY_SIZE(audio_map_tx);
 809		priv->cpu_priv.sysclk_dir[TX] = SND_SOC_CLOCK_OUT;
 810		priv->cpu_priv.sysclk_ratio[TX] = 256;
 811	} else if (of_device_is_compatible(np, "fsl,imx-audio-si476x")) {
 812		codec_dai_name[0] = "si476x-codec";
 813		priv->dai_fmt |= SND_SOC_DAIFMT_CBC_CFC;
 814		priv->card.dapm_routes = audio_map_rx;
 815		priv->card.num_dapm_routes = ARRAY_SIZE(audio_map_rx);
 816	} else if (of_device_is_compatible(np, "fsl,imx-audio-wm8958")) {
 817		codec_dai_name[0] = "wm8994-aif1";
 818		priv->dai_fmt |= SND_SOC_DAIFMT_CBP_CFP;
 819		priv->codec_priv[0].mclk_id = WM8994_FLL_SRC_MCLK1;
 820		priv->codec_priv[0].fll_id = WM8994_SYSCLK_FLL1;
 821		priv->codec_priv[0].pll_id = WM8994_FLL1;
 822		priv->codec_priv[0].free_freq = priv->codec_priv[0].mclk_freq;
 823		priv->card.dapm_routes = NULL;
 824		priv->card.num_dapm_routes = 0;
 825	} else if (of_device_is_compatible(np, "fsl,imx-audio-nau8822")) {
 826		codec_dai_name[0] = "nau8822-hifi";
 827		priv->codec_priv[0].mclk_id = NAU8822_CLK_MCLK;
 828		priv->codec_priv[0].fll_id = NAU8822_CLK_PLL;
 829		priv->codec_priv[0].pll_id = NAU8822_CLK_PLL;
 830		priv->dai_fmt |= SND_SOC_DAIFMT_CBP_CFP;
 831		if (codec_dev[0])
 832			priv->codec_priv[0].mclk = devm_clk_get(codec_dev[0], NULL);
 833	} else if (of_device_is_compatible(np, "fsl,imx-audio-wm8904")) {
 834		codec_dai_name[0] = "wm8904-hifi";
 835		priv->codec_priv[0].mclk_id = WM8904_FLL_MCLK;
 836		priv->codec_priv[0].fll_id = WM8904_CLK_FLL;
 837		priv->codec_priv[0].pll_id = WM8904_FLL_MCLK;
 838		priv->dai_fmt |= SND_SOC_DAIFMT_CBP_CFP;
 839	} else if (of_device_is_compatible(np, "fsl,imx-audio-spdif")) {
 840		ret = fsl_asoc_card_spdif_init(codec_np, cpu_np, codec_dai_name, priv);
 841		if (ret)
 842			goto asrc_fail;
 843	} else {
 844		dev_err(&pdev->dev, "unknown Device Tree compatible\n");
 845		ret = -EINVAL;
 846		goto asrc_fail;
 847	}
 848
 849	/*
 850	 * Allow setting mclk-id from the device-tree node. Otherwise, the
 851	 * default value for each card configuration is used.
 852	 */
 853	for_each_link_codecs((&(priv->dai_link[0])), codec_idx, codec_comp) {
 854		of_property_read_u32_index(np, "mclk-id", codec_idx,
 855					&priv->codec_priv[codec_idx].mclk_id);
 856	}
 857
 858	/* Format info from DT is optional. */
 859	snd_soc_daifmt_parse_clock_provider_as_phandle(np, NULL, &bitclkprovider, &frameprovider);
 860	if (bitclkprovider || frameprovider) {
 861		unsigned int daifmt = snd_soc_daifmt_parse_format(np, NULL);
 862		bool codec_bitclkprovider = false;
 863		bool codec_frameprovider = false;
 864
 865		for_each_link_codecs((&(priv->dai_link[0])), codec_idx, codec_comp) {
 866			if (bitclkprovider && codec_np[codec_idx] == bitclkprovider)
 867				codec_bitclkprovider = true;
 868			if (frameprovider && codec_np[codec_idx] == frameprovider)
 869				codec_frameprovider = true;
 870		}
 871
 872		if (codec_bitclkprovider)
 873			daifmt |= (codec_frameprovider) ?
 874				SND_SOC_DAIFMT_CBP_CFP : SND_SOC_DAIFMT_CBP_CFC;
 875		else
 876			daifmt |= (codec_frameprovider) ?
 877				SND_SOC_DAIFMT_CBC_CFP : SND_SOC_DAIFMT_CBC_CFC;
 878
 879		/* Override dai_fmt with value from DT */
 880		priv->dai_fmt = daifmt;
 881	}
 882
 883	/* Change direction according to format */
 884	if (priv->dai_fmt & SND_SOC_DAIFMT_CBP_CFP) {
 885		priv->cpu_priv.sysclk_dir[TX] = SND_SOC_CLOCK_IN;
 886		priv->cpu_priv.sysclk_dir[RX] = SND_SOC_CLOCK_IN;
 887	}
 888
 889	of_node_put(bitclkprovider);
 890	of_node_put(frameprovider);
 891
 892	if (!fsl_asoc_card_is_ac97(priv) && !codec_dev[0]
 893	    && codec_dai_name[0] != snd_soc_dummy_dlc.dai_name) {
 894		dev_dbg(&pdev->dev, "failed to find codec device\n");
 895		ret = -EPROBE_DEFER;
 896		goto asrc_fail;
 897	}
 898
 899	/* Common settings for corresponding Freescale CPU DAI driver */
 900	if (of_node_name_eq(cpu_np, "ssi")) {
 901		/* Only SSI needs to configure AUDMUX */
 902		ret = fsl_asoc_card_audmux_init(np, priv);
 903		if (ret) {
 904			dev_err(&pdev->dev, "failed to init audmux\n");
 905			goto asrc_fail;
 906		}
 907	} else if (of_node_name_eq(cpu_np, "esai")) {
 908		struct clk *esai_clk = clk_get(&cpu_pdev->dev, "extal");
 909
 910		if (!IS_ERR(esai_clk)) {
 911			priv->cpu_priv.sysclk_freq[TX] = clk_get_rate(esai_clk);
 912			priv->cpu_priv.sysclk_freq[RX] = clk_get_rate(esai_clk);
 913			clk_put(esai_clk);
 914		} else if (PTR_ERR(esai_clk) == -EPROBE_DEFER) {
 915			ret = -EPROBE_DEFER;
 916			goto asrc_fail;
 917		}
 918
 919		priv->cpu_priv.sysclk_id[1] = ESAI_HCKT_EXTAL;
 920		priv->cpu_priv.sysclk_id[0] = ESAI_HCKR_EXTAL;
 921	} else if (of_node_name_eq(cpu_np, "sai")) {
 922		priv->cpu_priv.sysclk_id[1] = FSL_SAI_CLK_MAST1;
 923		priv->cpu_priv.sysclk_id[0] = FSL_SAI_CLK_MAST1;
 924	}
 925
 926	/* Initialize sound card */
 927	priv->card.dev = &pdev->dev;
 928	priv->card.owner = THIS_MODULE;
 929	ret = snd_soc_of_parse_card_name(&priv->card, "model");
 930	if (ret) {
 931		snprintf(priv->name, sizeof(priv->name), "%s-audio",
 932			 fsl_asoc_card_is_ac97(priv) ? "ac97" : codec_dev_name[0]);
 933		priv->card.name = priv->name;
 934	}
 935	priv->card.dai_link = priv->dai_link;
 936	priv->card.late_probe = fsl_asoc_card_late_probe;
 937	priv->card.dapm_widgets = fsl_asoc_card_dapm_widgets;
 938	priv->card.num_dapm_widgets = ARRAY_SIZE(fsl_asoc_card_dapm_widgets);
 939
 940	/* Drop the second half of DAPM routes -- ASRC */
 941	if (!asrc_pdev)
 942		priv->card.num_dapm_routes /= 2;
 943
 944	if (of_property_present(np, "audio-routing")) {
 945		ret = snd_soc_of_parse_audio_routing(&priv->card, "audio-routing");
 946		if (ret) {
 947			dev_err(&pdev->dev, "failed to parse audio-routing: %d\n", ret);
 948			goto asrc_fail;
 949		}
 950	}
 951
 952	/* Normal DAI Link */
 953	priv->dai_link[0].cpus->of_node = cpu_np;
 954	for_each_link_codecs((&(priv->dai_link[0])), codec_idx, codec_comp) {
 955		codec_comp->dai_name = codec_dai_name[codec_idx];
 956	}
 957
 958	// Old SPDIF DT binding support
 959	if (codec_dai_name[0] == snd_soc_dummy_dlc.dai_name)
 960		priv->dai_link[0].codecs[0].name = snd_soc_dummy_dlc.name;
 961
 962	if (!fsl_asoc_card_is_ac97(priv)) {
 963		for_each_link_codecs((&(priv->dai_link[0])), codec_idx, codec_comp) {
 964			codec_comp->of_node = codec_np[codec_idx];
 965		}
 966	} else {
 967		u32 idx;
 968
 969		ret = of_property_read_u32(cpu_np, "cell-index", &idx);
 970		if (ret) {
 971			dev_err(&pdev->dev,
 972				"cannot get CPU index property\n");
 973			goto asrc_fail;
 974		}
 975
 976		priv->dai_link[0].codecs[0].name =
 977				devm_kasprintf(&pdev->dev, GFP_KERNEL,
 978					       "ac97-codec.%u",
 979					       (unsigned int)idx);
 980		if (!priv->dai_link[0].codecs[0].name) {
 981			ret = -ENOMEM;
 982			goto asrc_fail;
 983		}
 984	}
 985
 986	priv->dai_link[0].platforms->of_node = cpu_np;
 987	priv->dai_link[0].dai_fmt = priv->dai_fmt;
 988	priv->card.num_links = 1;
 989
 990	if (asrc_pdev) {
 991		/* DPCM DAI Links only if ASRC exists */
 992		priv->dai_link[1].cpus->of_node = asrc_np;
 993		priv->dai_link[1].platforms->of_node = asrc_np;
 994		for_each_link_codecs((&(priv->dai_link[2])), codec_idx, codec_comp) {
 995			codec_comp->dai_name = priv->dai_link[0].codecs[codec_idx].dai_name;
 996			codec_comp->of_node = priv->dai_link[0].codecs[codec_idx].of_node;
 997			codec_comp->name = priv->dai_link[0].codecs[codec_idx].name;
 998		}
 999		priv->dai_link[2].cpus->of_node = cpu_np;
1000		priv->dai_link[2].dai_fmt = priv->dai_fmt;
1001		priv->card.num_links = 3;
1002
1003		ret = of_property_read_u32(asrc_np, "fsl,asrc-rate",
1004					   &priv->asrc_rate);
1005		if (ret) {
1006			dev_err(&pdev->dev, "failed to get output rate\n");
1007			ret = -EINVAL;
1008			goto asrc_fail;
1009		}
1010
1011		ret = of_property_read_u32(asrc_np, "fsl,asrc-format", &asrc_fmt);
1012		priv->asrc_format = (__force snd_pcm_format_t)asrc_fmt;
1013		if (ret) {
1014			/* Fallback to old binding; translate to asrc_format */
1015			ret = of_property_read_u32(asrc_np, "fsl,asrc-width",
1016						   &width);
1017			if (ret) {
1018				dev_err(&pdev->dev,
1019					"failed to decide output format\n");
1020				goto asrc_fail;
1021			}
1022
1023			if (width == 24)
1024				priv->asrc_format = SNDRV_PCM_FORMAT_S24_LE;
1025			else
1026				priv->asrc_format = SNDRV_PCM_FORMAT_S16_LE;
1027		}
1028	}
1029
1030	/* Finish card registering */
1031	platform_set_drvdata(pdev, priv);
1032	snd_soc_card_set_drvdata(&priv->card, priv);
1033
1034	ret = devm_snd_soc_register_card(&pdev->dev, &priv->card);
1035	if (ret) {
1036		dev_err_probe(&pdev->dev, ret, "snd_soc_register_card failed\n");
1037		goto asrc_fail;
1038	}
1039
1040	/*
1041	 * Properties "hp-det-gpios" and "mic-det-gpios" are optional, and
1042	 * simple_util_init_jack() uses these properties for creating
1043	 * Headphone Jack and Microphone Jack.
1044	 *
1045	 * The notifier is initialized in snd_soc_card_jack_new(), then
1046	 * snd_soc_jack_notifier_register can be called.
1047	 */
1048	if (of_property_present(np, "hp-det-gpios") ||
1049	    of_property_present(np, "hp-det-gpio") /* deprecated */) {
1050		ret = simple_util_init_jack(&priv->card, &priv->hp_jack,
1051					    1, NULL, "Headphone Jack");
1052		if (ret)
1053			goto asrc_fail;
1054
1055		snd_soc_jack_notifier_register(&priv->hp_jack.jack, &hp_jack_nb);
1056	}
1057
1058	if (of_property_present(np, "mic-det-gpios") ||
1059	    of_property_present(np, "mic-det-gpio") /* deprecated */) {
1060		ret = simple_util_init_jack(&priv->card, &priv->mic_jack,
1061					    0, NULL, "Mic Jack");
1062		if (ret)
1063			goto asrc_fail;
1064
1065		snd_soc_jack_notifier_register(&priv->mic_jack.jack, &mic_jack_nb);
1066	}
1067
1068asrc_fail:
1069	of_node_put(asrc_np);
1070	of_node_put(codec_np[0]);
1071	of_node_put(codec_np[1]);
1072	put_device(&cpu_pdev->dev);
1073fail:
1074	of_node_put(cpu_np);
1075
1076	return ret;
1077}
1078
1079static const struct of_device_id fsl_asoc_card_dt_ids[] = {
1080	{ .compatible = "fsl,imx-audio-ac97", },
1081	{ .compatible = "fsl,imx-audio-cs42888", },
1082	{ .compatible = "fsl,imx-audio-cs427x", },
1083	{ .compatible = "fsl,imx-audio-tlv320aic32x4", },
1084	{ .compatible = "fsl,imx-audio-tlv320aic31xx", },
1085	{ .compatible = "fsl,imx-audio-sgtl5000", },
1086	{ .compatible = "fsl,imx-audio-wm8962", },
1087	{ .compatible = "fsl,imx-audio-wm8960", },
1088	{ .compatible = "fsl,imx-audio-mqs", },
1089	{ .compatible = "fsl,imx-audio-wm8524", },
1090	{ .compatible = "fsl,imx-audio-si476x", },
1091	{ .compatible = "fsl,imx-audio-wm8958", },
1092	{ .compatible = "fsl,imx-audio-nau8822", },
1093	{ .compatible = "fsl,imx-audio-wm8904", },
1094	{ .compatible = "fsl,imx-audio-spdif", },
1095	{}
1096};
1097MODULE_DEVICE_TABLE(of, fsl_asoc_card_dt_ids);
1098
1099static struct platform_driver fsl_asoc_card_driver = {
1100	.probe = fsl_asoc_card_probe,
1101	.driver = {
1102		.name = DRIVER_NAME,
1103		.pm = &snd_soc_pm_ops,
1104		.of_match_table = fsl_asoc_card_dt_ids,
1105	},
1106};
1107module_platform_driver(fsl_asoc_card_driver);
1108
1109MODULE_DESCRIPTION("Freescale Generic ASoC Sound Card driver with ASRC");
1110MODULE_AUTHOR("Nicolin Chen <nicoleotsuka@gmail.com>");
1111MODULE_ALIAS("platform:" DRIVER_NAME);
1112MODULE_LICENSE("GPL");
~/ Read-only file preview.