Fabio Estevam | aa624a0 | 2018-07-24 09:48:30 -0300 | [diff] [blame] | 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> |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 8 | |
| 9 | #include <linux/clk.h> |
| 10 | #include <linux/i2c.h> |
| 11 | #include <linux/module.h> |
| 12 | #include <linux/of_platform.h> |
Maciej S. Szmigiero | 50760ca | 2015-09-19 02:00:25 +0200 | [diff] [blame] | 13 | #if IS_ENABLED(CONFIG_SND_AC97_CODEC) |
| 14 | #include <sound/ac97_codec.h> |
| 15 | #endif |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 16 | #include <sound/pcm_params.h> |
| 17 | #include <sound/soc.h> |
Shengjiu Wang | 3b17119 | 2020-07-15 22:09:39 +0800 | [diff] [blame] | 18 | #include <sound/jack.h> |
| 19 | #include <sound/simple_card_utils.h> |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 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" |
Zidan Wang | 50e0ee0 | 2015-08-14 19:11:09 +0800 | [diff] [blame] | 27 | #include "../codecs/wm8960.h" |
Shengjiu Wang | efd0b16 | 2021-03-17 21:05:02 +0800 | [diff] [blame] | 28 | #include "../codecs/wm8994.h" |
Ariel D'Alessandro | 8c9b9cfb | 2021-11-19 12:32:48 -0300 | [diff] [blame] | 29 | #include "../codecs/tlv320aic31xx.h" |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 30 | |
Felipe F. Tonello | 57e756d | 2016-01-29 11:01:00 +0000 | [diff] [blame] | 31 | #define CS427x_SYSCLK_MCLK 0 |
| 32 | |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 33 | #define RX 0 |
| 34 | #define TX 1 |
| 35 | |
| 36 | /* Default DAI format without Master and Slave flag */ |
| 37 | #define DAI_FMT_BASE (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF) |
| 38 | |
| 39 | /** |
Pierre-Louis Bossart | 31deacf | 2020-07-02 14:21:38 -0500 | [diff] [blame] | 40 | * struct codec_priv - CODEC private data |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 41 | * @mclk_freq: Clock rate of MCLK |
Shengjiu Wang | efd0b16 | 2021-03-17 21:05:02 +0800 | [diff] [blame] | 42 | * @free_freq: Clock rate of MCLK for hw_free() |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 43 | * @mclk_id: MCLK (or main clock) id for set_sysclk() |
| 44 | * @fll_id: FLL (or secordary clock) id for set_sysclk() |
| 45 | * @pll_id: PLL id for set_pll() |
| 46 | */ |
| 47 | struct codec_priv { |
| 48 | unsigned long mclk_freq; |
Shengjiu Wang | efd0b16 | 2021-03-17 21:05:02 +0800 | [diff] [blame] | 49 | unsigned long free_freq; |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 50 | u32 mclk_id; |
| 51 | u32 fll_id; |
| 52 | u32 pll_id; |
| 53 | }; |
| 54 | |
| 55 | /** |
Pierre-Louis Bossart | 31deacf | 2020-07-02 14:21:38 -0500 | [diff] [blame] | 56 | * struct cpu_priv - CPU private data |
| 57 | * @sysclk_freq: SYSCLK rates for set_sysclk() |
| 58 | * @sysclk_dir: SYSCLK directions for set_sysclk() |
| 59 | * @sysclk_id: SYSCLK ids for set_sysclk() |
Nicolin Chen | cb3fc1f | 2014-10-24 16:48:13 -0700 | [diff] [blame] | 60 | * @slot_width: Slot width of each frame |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 61 | * |
| 62 | * Note: [1] for tx and [0] for rx |
| 63 | */ |
| 64 | struct cpu_priv { |
| 65 | unsigned long sysclk_freq[2]; |
| 66 | u32 sysclk_dir[2]; |
| 67 | u32 sysclk_id[2]; |
Nicolin Chen | cb3fc1f | 2014-10-24 16:48:13 -0700 | [diff] [blame] | 68 | u32 slot_width; |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | /** |
Pierre-Louis Bossart | 31deacf | 2020-07-02 14:21:38 -0500 | [diff] [blame] | 72 | * struct fsl_asoc_card_priv - Freescale Generic ASOC card private data |
| 73 | * @dai_link: DAI link structure including normal one and DPCM link |
Shengjiu Wang | 3b17119 | 2020-07-15 22:09:39 +0800 | [diff] [blame] | 74 | * @hp_jack: Headphone Jack structure |
| 75 | * @mic_jack: Microphone Jack structure |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 76 | * @pdev: platform device pointer |
| 77 | * @codec_priv: CODEC private data |
| 78 | * @cpu_priv: CPU private data |
| 79 | * @card: ASoC card structure |
Shengjiu Wang | f36e8ed | 2020-08-03 10:13:31 +0800 | [diff] [blame] | 80 | * @streams: Mask of current active streams |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 81 | * @sample_rate: Current sample rate |
| 82 | * @sample_format: Current sample format |
| 83 | * @asrc_rate: ASRC sample rate used by Back-Ends |
| 84 | * @asrc_format: ASRC sample format used by Back-Ends |
| 85 | * @dai_fmt: DAI format between CPU and CODEC |
| 86 | * @name: Card name |
| 87 | */ |
| 88 | |
| 89 | struct fsl_asoc_card_priv { |
| 90 | struct snd_soc_dai_link dai_link[3]; |
Shengjiu Wang | 3b17119 | 2020-07-15 22:09:39 +0800 | [diff] [blame] | 91 | struct asoc_simple_jack hp_jack; |
| 92 | struct asoc_simple_jack mic_jack; |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 93 | struct platform_device *pdev; |
| 94 | struct codec_priv codec_priv; |
| 95 | struct cpu_priv cpu_priv; |
| 96 | struct snd_soc_card card; |
Shengjiu Wang | f36e8ed | 2020-08-03 10:13:31 +0800 | [diff] [blame] | 97 | u8 streams; |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 98 | u32 sample_rate; |
Fabio Estevam | fc734c24 | 2018-02-11 19:53:18 -0200 | [diff] [blame] | 99 | snd_pcm_format_t sample_format; |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 100 | u32 asrc_rate; |
Fabio Estevam | fc734c24 | 2018-02-11 19:53:18 -0200 | [diff] [blame] | 101 | snd_pcm_format_t asrc_format; |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 102 | u32 dai_fmt; |
| 103 | char name[32]; |
| 104 | }; |
| 105 | |
Pierre-Louis Bossart | 31deacf | 2020-07-02 14:21:38 -0500 | [diff] [blame] | 106 | /* |
Lee Jones | 1b58214 | 2020-07-15 16:00:09 +0100 | [diff] [blame] | 107 | * This dapm route map exists for DPCM link only. |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 108 | * The other routes shall go through Device Tree. |
Nicolin Chen | 089dfaf | 2016-01-30 23:07:00 -0800 | [diff] [blame] | 109 | * |
| 110 | * Note: keep all ASRC routes in the second half |
| 111 | * to drop them easily for non-ASRC cases. |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 112 | */ |
| 113 | static const struct snd_soc_dapm_route audio_map[] = { |
Nicolin Chen | 089dfaf | 2016-01-30 23:07:00 -0800 | [diff] [blame] | 114 | /* 1st half -- Normal DAPM routes */ |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 115 | {"Playback", NULL, "CPU-Playback"}, |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 116 | {"CPU-Capture", NULL, "Capture"}, |
Nicolin Chen | 089dfaf | 2016-01-30 23:07:00 -0800 | [diff] [blame] | 117 | /* 2nd half -- ASRC DAPM routes */ |
| 118 | {"CPU-Playback", NULL, "ASRC-Playback"}, |
| 119 | {"ASRC-Capture", NULL, "CPU-Capture"}, |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 120 | }; |
| 121 | |
Maciej S. Szmigiero | 25e5ef9 | 2015-12-20 21:34:29 +0100 | [diff] [blame] | 122 | static const struct snd_soc_dapm_route audio_map_ac97[] = { |
Nicolin Chen | 089dfaf | 2016-01-30 23:07:00 -0800 | [diff] [blame] | 123 | /* 1st half -- Normal DAPM routes */ |
Maciej S. Szmigiero | 25e5ef9 | 2015-12-20 21:34:29 +0100 | [diff] [blame] | 124 | {"Playback", NULL, "AC97 Playback"}, |
Maciej S. Szmigiero | 25e5ef9 | 2015-12-20 21:34:29 +0100 | [diff] [blame] | 125 | {"AC97 Capture", NULL, "Capture"}, |
Nicolin Chen | 089dfaf | 2016-01-30 23:07:00 -0800 | [diff] [blame] | 126 | /* 2nd half -- ASRC DAPM routes */ |
| 127 | {"AC97 Playback", NULL, "ASRC-Playback"}, |
| 128 | {"ASRC-Capture", NULL, "AC97 Capture"}, |
Maciej S. Szmigiero | 25e5ef9 | 2015-12-20 21:34:29 +0100 | [diff] [blame] | 129 | }; |
| 130 | |
Shengjiu Wang | 039652a | 2020-06-17 12:48:25 +0800 | [diff] [blame] | 131 | static const struct snd_soc_dapm_route audio_map_tx[] = { |
| 132 | /* 1st half -- Normal DAPM routes */ |
| 133 | {"Playback", NULL, "CPU-Playback"}, |
| 134 | /* 2nd half -- ASRC DAPM routes */ |
| 135 | {"CPU-Playback", NULL, "ASRC-Playback"}, |
| 136 | }; |
| 137 | |
Shengjiu Wang | 77f1ff75 | 2020-11-30 11:57:47 +0800 | [diff] [blame] | 138 | static const struct snd_soc_dapm_route audio_map_rx[] = { |
| 139 | /* 1st half -- Normal DAPM routes */ |
| 140 | {"CPU-Capture", NULL, "Capture"}, |
| 141 | /* 2nd half -- ASRC DAPM routes */ |
| 142 | {"ASRC-Capture", NULL, "CPU-Capture"}, |
| 143 | }; |
| 144 | |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 145 | /* Add all possible widgets into here without being redundant */ |
| 146 | static const struct snd_soc_dapm_widget fsl_asoc_card_dapm_widgets[] = { |
| 147 | SND_SOC_DAPM_LINE("Line Out Jack", NULL), |
| 148 | SND_SOC_DAPM_LINE("Line In Jack", NULL), |
| 149 | SND_SOC_DAPM_HP("Headphone Jack", NULL), |
| 150 | SND_SOC_DAPM_SPK("Ext Spk", NULL), |
| 151 | SND_SOC_DAPM_MIC("Mic Jack", NULL), |
| 152 | SND_SOC_DAPM_MIC("AMIC", NULL), |
| 153 | SND_SOC_DAPM_MIC("DMIC", NULL), |
| 154 | }; |
| 155 | |
Maciej S. Szmigiero | 50760ca | 2015-09-19 02:00:25 +0200 | [diff] [blame] | 156 | static bool fsl_asoc_card_is_ac97(struct fsl_asoc_card_priv *priv) |
| 157 | { |
| 158 | return priv->dai_fmt == SND_SOC_DAIFMT_AC97; |
| 159 | } |
| 160 | |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 161 | static int fsl_asoc_card_hw_params(struct snd_pcm_substream *substream, |
| 162 | struct snd_pcm_hw_params *params) |
| 163 | { |
Kuninori Morimoto | 9f5f078 | 2020-07-20 10:18:38 +0900 | [diff] [blame] | 164 | struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 165 | struct fsl_asoc_card_priv *priv = snd_soc_card_get_drvdata(rtd->card); |
| 166 | bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK; |
Shengjiu Wang | f36e8ed | 2020-08-03 10:13:31 +0800 | [diff] [blame] | 167 | struct codec_priv *codec_priv = &priv->codec_priv; |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 168 | struct cpu_priv *cpu_priv = &priv->cpu_priv; |
| 169 | struct device *dev = rtd->card->dev; |
Shengjiu Wang | f36e8ed | 2020-08-03 10:13:31 +0800 | [diff] [blame] | 170 | unsigned int pll_out; |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 171 | int ret; |
| 172 | |
| 173 | priv->sample_rate = params_rate(params); |
| 174 | priv->sample_format = params_format(params); |
Shengjiu Wang | f36e8ed | 2020-08-03 10:13:31 +0800 | [diff] [blame] | 175 | priv->streams |= BIT(substream->stream); |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 176 | |
Shengjiu Wang | f36e8ed | 2020-08-03 10:13:31 +0800 | [diff] [blame] | 177 | if (fsl_asoc_card_is_ac97(priv)) |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 178 | return 0; |
| 179 | |
| 180 | /* Specific configurations of DAIs starts from here */ |
Kuninori Morimoto | 17198ae | 2020-03-23 14:18:30 +0900 | [diff] [blame] | 181 | ret = snd_soc_dai_set_sysclk(asoc_rtd_to_cpu(rtd, 0), cpu_priv->sysclk_id[tx], |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 182 | cpu_priv->sysclk_freq[tx], |
| 183 | cpu_priv->sysclk_dir[tx]); |
Nicolin Chen | 758a3b0 | 2017-09-07 22:27:33 -0700 | [diff] [blame] | 184 | if (ret && ret != -ENOTSUPP) { |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 185 | dev_err(dev, "failed to set sysclk for cpu dai\n"); |
Shengjiu Wang | f36e8ed | 2020-08-03 10:13:31 +0800 | [diff] [blame] | 186 | goto fail; |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 187 | } |
| 188 | |
Nicolin Chen | cb3fc1f | 2014-10-24 16:48:13 -0700 | [diff] [blame] | 189 | if (cpu_priv->slot_width) { |
Kuninori Morimoto | 17198ae | 2020-03-23 14:18:30 +0900 | [diff] [blame] | 190 | ret = snd_soc_dai_set_tdm_slot(asoc_rtd_to_cpu(rtd, 0), 0x3, 0x3, 2, |
Nicolin Chen | cb3fc1f | 2014-10-24 16:48:13 -0700 | [diff] [blame] | 191 | cpu_priv->slot_width); |
Nicolin Chen | 758a3b0 | 2017-09-07 22:27:33 -0700 | [diff] [blame] | 192 | if (ret && ret != -ENOTSUPP) { |
Nicolin Chen | cb3fc1f | 2014-10-24 16:48:13 -0700 | [diff] [blame] | 193 | dev_err(dev, "failed to set TDM slot for cpu dai\n"); |
Shengjiu Wang | f36e8ed | 2020-08-03 10:13:31 +0800 | [diff] [blame] | 194 | goto fail; |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | /* Specific configuration for PLL */ |
| 199 | if (codec_priv->pll_id && codec_priv->fll_id) { |
| 200 | if (priv->sample_format == SNDRV_PCM_FORMAT_S24_LE) |
| 201 | pll_out = priv->sample_rate * 384; |
| 202 | else |
| 203 | pll_out = priv->sample_rate * 256; |
| 204 | |
| 205 | ret = snd_soc_dai_set_pll(asoc_rtd_to_codec(rtd, 0), |
| 206 | codec_priv->pll_id, |
| 207 | codec_priv->mclk_id, |
| 208 | codec_priv->mclk_freq, pll_out); |
| 209 | if (ret) { |
| 210 | dev_err(dev, "failed to start FLL: %d\n", ret); |
| 211 | goto fail; |
| 212 | } |
| 213 | |
| 214 | ret = snd_soc_dai_set_sysclk(asoc_rtd_to_codec(rtd, 0), |
| 215 | codec_priv->fll_id, |
| 216 | pll_out, SND_SOC_CLOCK_IN); |
| 217 | |
| 218 | if (ret && ret != -ENOTSUPP) { |
| 219 | dev_err(dev, "failed to set SYSCLK: %d\n", ret); |
| 220 | goto fail; |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | return 0; |
| 225 | |
| 226 | fail: |
| 227 | priv->streams &= ~BIT(substream->stream); |
| 228 | return ret; |
| 229 | } |
| 230 | |
| 231 | static int fsl_asoc_card_hw_free(struct snd_pcm_substream *substream) |
| 232 | { |
| 233 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 234 | struct fsl_asoc_card_priv *priv = snd_soc_card_get_drvdata(rtd->card); |
| 235 | struct codec_priv *codec_priv = &priv->codec_priv; |
| 236 | struct device *dev = rtd->card->dev; |
| 237 | int ret; |
| 238 | |
| 239 | priv->streams &= ~BIT(substream->stream); |
| 240 | |
| 241 | if (!priv->streams && codec_priv->pll_id && codec_priv->fll_id) { |
Shengjiu Wang | efd0b16 | 2021-03-17 21:05:02 +0800 | [diff] [blame] | 242 | /* Force freq to be free_freq to avoid error message in codec */ |
Shengjiu Wang | f36e8ed | 2020-08-03 10:13:31 +0800 | [diff] [blame] | 243 | ret = snd_soc_dai_set_sysclk(asoc_rtd_to_codec(rtd, 0), |
| 244 | codec_priv->mclk_id, |
Shengjiu Wang | efd0b16 | 2021-03-17 21:05:02 +0800 | [diff] [blame] | 245 | codec_priv->free_freq, |
Shengjiu Wang | f36e8ed | 2020-08-03 10:13:31 +0800 | [diff] [blame] | 246 | SND_SOC_CLOCK_IN); |
| 247 | if (ret) { |
| 248 | dev_err(dev, "failed to switch away from FLL: %d\n", ret); |
| 249 | return ret; |
| 250 | } |
| 251 | |
| 252 | ret = snd_soc_dai_set_pll(asoc_rtd_to_codec(rtd, 0), |
| 253 | codec_priv->pll_id, 0, 0, 0); |
| 254 | if (ret && ret != -ENOTSUPP) { |
| 255 | dev_err(dev, "failed to stop FLL: %d\n", ret); |
Nicolin Chen | cb3fc1f | 2014-10-24 16:48:13 -0700 | [diff] [blame] | 256 | return ret; |
| 257 | } |
| 258 | } |
| 259 | |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 260 | return 0; |
| 261 | } |
| 262 | |
Julia Lawall | ddba7fa | 2016-10-15 16:55:50 +0200 | [diff] [blame] | 263 | static const struct snd_soc_ops fsl_asoc_card_ops = { |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 264 | .hw_params = fsl_asoc_card_hw_params, |
Shengjiu Wang | f36e8ed | 2020-08-03 10:13:31 +0800 | [diff] [blame] | 265 | .hw_free = fsl_asoc_card_hw_free, |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 266 | }; |
| 267 | |
| 268 | static int be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, |
| 269 | struct snd_pcm_hw_params *params) |
| 270 | { |
| 271 | struct fsl_asoc_card_priv *priv = snd_soc_card_get_drvdata(rtd->card); |
| 272 | struct snd_interval *rate; |
| 273 | struct snd_mask *mask; |
| 274 | |
| 275 | rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); |
| 276 | rate->max = rate->min = priv->asrc_rate; |
| 277 | |
| 278 | mask = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT); |
| 279 | snd_mask_none(mask); |
Takashi Iwai | ebc22af | 2018-07-25 23:17:20 +0200 | [diff] [blame] | 280 | snd_mask_set_format(mask, priv->asrc_format); |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 281 | |
| 282 | return 0; |
| 283 | } |
| 284 | |
Kuninori Morimoto | 893f195 | 2019-06-06 13:15:11 +0900 | [diff] [blame] | 285 | SND_SOC_DAILINK_DEFS(hifi, |
| 286 | DAILINK_COMP_ARRAY(COMP_EMPTY()), |
Kuninori Morimoto | 9998d3e | 2019-06-28 10:47:18 +0900 | [diff] [blame] | 287 | DAILINK_COMP_ARRAY(COMP_EMPTY()), |
Kuninori Morimoto | 893f195 | 2019-06-06 13:15:11 +0900 | [diff] [blame] | 288 | DAILINK_COMP_ARRAY(COMP_EMPTY())); |
| 289 | |
| 290 | SND_SOC_DAILINK_DEFS(hifi_fe, |
| 291 | DAILINK_COMP_ARRAY(COMP_EMPTY()), |
Kuninori Morimoto | 9998d3e | 2019-06-28 10:47:18 +0900 | [diff] [blame] | 292 | DAILINK_COMP_ARRAY(COMP_DUMMY()), |
| 293 | DAILINK_COMP_ARRAY(COMP_EMPTY())); |
Kuninori Morimoto | 893f195 | 2019-06-06 13:15:11 +0900 | [diff] [blame] | 294 | |
| 295 | SND_SOC_DAILINK_DEFS(hifi_be, |
| 296 | DAILINK_COMP_ARRAY(COMP_EMPTY()), |
| 297 | DAILINK_COMP_ARRAY(COMP_EMPTY()), |
| 298 | DAILINK_COMP_ARRAY(COMP_DUMMY())); |
| 299 | |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 300 | static struct snd_soc_dai_link fsl_asoc_card_dai[] = { |
| 301 | /* Default ASoC DAI Link*/ |
| 302 | { |
| 303 | .name = "HiFi", |
| 304 | .stream_name = "HiFi", |
| 305 | .ops = &fsl_asoc_card_ops, |
Kuninori Morimoto | 893f195 | 2019-06-06 13:15:11 +0900 | [diff] [blame] | 306 | SND_SOC_DAILINK_REG(hifi), |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 307 | }, |
| 308 | /* DPCM Link between Front-End and Back-End (Optional) */ |
| 309 | { |
| 310 | .name = "HiFi-ASRC-FE", |
| 311 | .stream_name = "HiFi-ASRC-FE", |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 312 | .dpcm_playback = 1, |
| 313 | .dpcm_capture = 1, |
| 314 | .dynamic = 1, |
Kuninori Morimoto | 893f195 | 2019-06-06 13:15:11 +0900 | [diff] [blame] | 315 | SND_SOC_DAILINK_REG(hifi_fe), |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 316 | }, |
| 317 | { |
| 318 | .name = "HiFi-ASRC-BE", |
| 319 | .stream_name = "HiFi-ASRC-BE", |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 320 | .be_hw_params_fixup = be_hw_params_fixup, |
| 321 | .ops = &fsl_asoc_card_ops, |
| 322 | .dpcm_playback = 1, |
| 323 | .dpcm_capture = 1, |
| 324 | .no_pcm = 1, |
Kuninori Morimoto | 893f195 | 2019-06-06 13:15:11 +0900 | [diff] [blame] | 325 | SND_SOC_DAILINK_REG(hifi_be), |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 326 | }, |
| 327 | }; |
| 328 | |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 329 | static int fsl_asoc_card_audmux_init(struct device_node *np, |
| 330 | struct fsl_asoc_card_priv *priv) |
| 331 | { |
| 332 | struct device *dev = &priv->pdev->dev; |
| 333 | u32 int_ptcr = 0, ext_ptcr = 0; |
| 334 | int int_port, ext_port; |
| 335 | int ret; |
| 336 | |
| 337 | ret = of_property_read_u32(np, "mux-int-port", &int_port); |
| 338 | if (ret) { |
| 339 | dev_err(dev, "mux-int-port missing or invalid\n"); |
| 340 | return ret; |
| 341 | } |
| 342 | ret = of_property_read_u32(np, "mux-ext-port", &ext_port); |
| 343 | if (ret) { |
| 344 | dev_err(dev, "mux-ext-port missing or invalid\n"); |
| 345 | return ret; |
| 346 | } |
| 347 | |
| 348 | /* |
| 349 | * The port numbering in the hardware manual starts at 1, while |
| 350 | * the AUDMUX API expects it starts at 0. |
| 351 | */ |
| 352 | int_port--; |
| 353 | ext_port--; |
| 354 | |
| 355 | /* |
Maciej S. Szmigiero | 50760ca | 2015-09-19 02:00:25 +0200 | [diff] [blame] | 356 | * Use asynchronous mode (6 wires) for all cases except AC97. |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 357 | * If only 4 wires are needed, just set SSI into |
| 358 | * synchronous mode and enable 4 PADs in IOMUX. |
| 359 | */ |
Mark Brown | 8fcfd34 | 2021-09-21 22:35:28 +0100 | [diff] [blame] | 360 | switch (priv->dai_fmt & SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK) { |
| 361 | case SND_SOC_DAIFMT_CBP_CFP: |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 362 | int_ptcr = IMX_AUDMUX_V2_PTCR_RFSEL(8 | ext_port) | |
| 363 | IMX_AUDMUX_V2_PTCR_RCSEL(8 | ext_port) | |
| 364 | IMX_AUDMUX_V2_PTCR_TFSEL(ext_port) | |
| 365 | IMX_AUDMUX_V2_PTCR_TCSEL(ext_port) | |
| 366 | IMX_AUDMUX_V2_PTCR_RFSDIR | |
| 367 | IMX_AUDMUX_V2_PTCR_RCLKDIR | |
| 368 | IMX_AUDMUX_V2_PTCR_TFSDIR | |
| 369 | IMX_AUDMUX_V2_PTCR_TCLKDIR; |
| 370 | break; |
Mark Brown | 8fcfd34 | 2021-09-21 22:35:28 +0100 | [diff] [blame] | 371 | case SND_SOC_DAIFMT_CBP_CFC: |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 372 | int_ptcr = IMX_AUDMUX_V2_PTCR_RCSEL(8 | ext_port) | |
| 373 | IMX_AUDMUX_V2_PTCR_TCSEL(ext_port) | |
| 374 | IMX_AUDMUX_V2_PTCR_RCLKDIR | |
| 375 | IMX_AUDMUX_V2_PTCR_TCLKDIR; |
| 376 | ext_ptcr = IMX_AUDMUX_V2_PTCR_RFSEL(8 | int_port) | |
| 377 | IMX_AUDMUX_V2_PTCR_TFSEL(int_port) | |
| 378 | IMX_AUDMUX_V2_PTCR_RFSDIR | |
| 379 | IMX_AUDMUX_V2_PTCR_TFSDIR; |
| 380 | break; |
Mark Brown | 8fcfd34 | 2021-09-21 22:35:28 +0100 | [diff] [blame] | 381 | case SND_SOC_DAIFMT_CBC_CFP: |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 382 | int_ptcr = IMX_AUDMUX_V2_PTCR_RFSEL(8 | ext_port) | |
| 383 | IMX_AUDMUX_V2_PTCR_TFSEL(ext_port) | |
| 384 | IMX_AUDMUX_V2_PTCR_RFSDIR | |
| 385 | IMX_AUDMUX_V2_PTCR_TFSDIR; |
| 386 | ext_ptcr = IMX_AUDMUX_V2_PTCR_RCSEL(8 | int_port) | |
| 387 | IMX_AUDMUX_V2_PTCR_TCSEL(int_port) | |
| 388 | IMX_AUDMUX_V2_PTCR_RCLKDIR | |
| 389 | IMX_AUDMUX_V2_PTCR_TCLKDIR; |
| 390 | break; |
Mark Brown | 8fcfd34 | 2021-09-21 22:35:28 +0100 | [diff] [blame] | 391 | case SND_SOC_DAIFMT_CBC_CFC: |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 392 | ext_ptcr = IMX_AUDMUX_V2_PTCR_RFSEL(8 | int_port) | |
| 393 | IMX_AUDMUX_V2_PTCR_RCSEL(8 | int_port) | |
| 394 | IMX_AUDMUX_V2_PTCR_TFSEL(int_port) | |
| 395 | IMX_AUDMUX_V2_PTCR_TCSEL(int_port) | |
| 396 | IMX_AUDMUX_V2_PTCR_RFSDIR | |
| 397 | IMX_AUDMUX_V2_PTCR_RCLKDIR | |
| 398 | IMX_AUDMUX_V2_PTCR_TFSDIR | |
| 399 | IMX_AUDMUX_V2_PTCR_TCLKDIR; |
| 400 | break; |
| 401 | default: |
Maciej S. Szmigiero | 50760ca | 2015-09-19 02:00:25 +0200 | [diff] [blame] | 402 | if (!fsl_asoc_card_is_ac97(priv)) |
| 403 | return -EINVAL; |
| 404 | } |
| 405 | |
| 406 | if (fsl_asoc_card_is_ac97(priv)) { |
| 407 | int_ptcr = IMX_AUDMUX_V2_PTCR_SYN | |
| 408 | IMX_AUDMUX_V2_PTCR_TCSEL(ext_port) | |
| 409 | IMX_AUDMUX_V2_PTCR_TCLKDIR; |
| 410 | ext_ptcr = IMX_AUDMUX_V2_PTCR_SYN | |
| 411 | IMX_AUDMUX_V2_PTCR_TFSEL(int_port) | |
| 412 | IMX_AUDMUX_V2_PTCR_TFSDIR; |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | /* Asynchronous mode can not be set along with RCLKDIR */ |
Maciej S. Szmigiero | 50760ca | 2015-09-19 02:00:25 +0200 | [diff] [blame] | 416 | if (!fsl_asoc_card_is_ac97(priv)) { |
| 417 | unsigned int pdcr = |
| 418 | IMX_AUDMUX_V2_PDCR_RXDSEL(ext_port); |
| 419 | |
| 420 | ret = imx_audmux_v2_configure_port(int_port, 0, |
| 421 | pdcr); |
| 422 | if (ret) { |
| 423 | dev_err(dev, "audmux internal port setup failed\n"); |
| 424 | return ret; |
| 425 | } |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | ret = imx_audmux_v2_configure_port(int_port, int_ptcr, |
| 429 | IMX_AUDMUX_V2_PDCR_RXDSEL(ext_port)); |
| 430 | if (ret) { |
| 431 | dev_err(dev, "audmux internal port setup failed\n"); |
| 432 | return ret; |
| 433 | } |
| 434 | |
Maciej S. Szmigiero | 50760ca | 2015-09-19 02:00:25 +0200 | [diff] [blame] | 435 | if (!fsl_asoc_card_is_ac97(priv)) { |
| 436 | unsigned int pdcr = |
| 437 | IMX_AUDMUX_V2_PDCR_RXDSEL(int_port); |
| 438 | |
| 439 | ret = imx_audmux_v2_configure_port(ext_port, 0, |
| 440 | pdcr); |
| 441 | if (ret) { |
| 442 | dev_err(dev, "audmux external port setup failed\n"); |
| 443 | return ret; |
| 444 | } |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | ret = imx_audmux_v2_configure_port(ext_port, ext_ptcr, |
| 448 | IMX_AUDMUX_V2_PDCR_RXDSEL(int_port)); |
| 449 | if (ret) { |
| 450 | dev_err(dev, "audmux external port setup failed\n"); |
| 451 | return ret; |
| 452 | } |
| 453 | |
| 454 | return 0; |
| 455 | } |
| 456 | |
Shengjiu Wang | 3b17119 | 2020-07-15 22:09:39 +0800 | [diff] [blame] | 457 | static int hp_jack_event(struct notifier_block *nb, unsigned long event, |
| 458 | void *data) |
| 459 | { |
| 460 | struct snd_soc_jack *jack = (struct snd_soc_jack *)data; |
| 461 | struct snd_soc_dapm_context *dapm = &jack->card->dapm; |
| 462 | |
| 463 | if (event & SND_JACK_HEADPHONE) |
| 464 | /* Disable speaker if headphone is plugged in */ |
| 465 | snd_soc_dapm_disable_pin(dapm, "Ext Spk"); |
| 466 | else |
| 467 | snd_soc_dapm_enable_pin(dapm, "Ext Spk"); |
| 468 | |
| 469 | return 0; |
| 470 | } |
| 471 | |
| 472 | static struct notifier_block hp_jack_nb = { |
| 473 | .notifier_call = hp_jack_event, |
| 474 | }; |
| 475 | |
| 476 | static int mic_jack_event(struct notifier_block *nb, unsigned long event, |
| 477 | void *data) |
| 478 | { |
| 479 | struct snd_soc_jack *jack = (struct snd_soc_jack *)data; |
| 480 | struct snd_soc_dapm_context *dapm = &jack->card->dapm; |
| 481 | |
| 482 | if (event & SND_JACK_MICROPHONE) |
| 483 | /* Disable dmic if microphone is plugged in */ |
| 484 | snd_soc_dapm_disable_pin(dapm, "DMIC"); |
| 485 | else |
| 486 | snd_soc_dapm_enable_pin(dapm, "DMIC"); |
| 487 | |
| 488 | return 0; |
| 489 | } |
| 490 | |
| 491 | static struct notifier_block mic_jack_nb = { |
| 492 | .notifier_call = mic_jack_event, |
| 493 | }; |
| 494 | |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 495 | static int fsl_asoc_card_late_probe(struct snd_soc_card *card) |
| 496 | { |
| 497 | struct fsl_asoc_card_priv *priv = snd_soc_card_get_drvdata(card); |
Vinod Koul | abd657b | 2015-11-20 22:45:20 +0530 | [diff] [blame] | 498 | struct snd_soc_pcm_runtime *rtd = list_first_entry( |
| 499 | &card->rtd_list, struct snd_soc_pcm_runtime, list); |
Kuninori Morimoto | 17198ae | 2020-03-23 14:18:30 +0900 | [diff] [blame] | 500 | struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0); |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 501 | struct codec_priv *codec_priv = &priv->codec_priv; |
| 502 | struct device *dev = card->dev; |
| 503 | int ret; |
| 504 | |
Maciej S. Szmigiero | 50760ca | 2015-09-19 02:00:25 +0200 | [diff] [blame] | 505 | if (fsl_asoc_card_is_ac97(priv)) { |
| 506 | #if IS_ENABLED(CONFIG_SND_AC97_CODEC) |
Kuninori Morimoto | 17198ae | 2020-03-23 14:18:30 +0900 | [diff] [blame] | 507 | struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component; |
Kuninori Morimoto | 845f80c | 2017-12-05 04:23:21 +0000 | [diff] [blame] | 508 | struct snd_ac97 *ac97 = snd_soc_component_get_drvdata(component); |
Maciej S. Szmigiero | 50760ca | 2015-09-19 02:00:25 +0200 | [diff] [blame] | 509 | |
| 510 | /* |
| 511 | * Use slots 3/4 for S/PDIF so SSI won't try to enable |
| 512 | * other slots and send some samples there |
| 513 | * due to SLOTREQ bits for S/PDIF received from codec |
| 514 | */ |
| 515 | snd_ac97_update_bits(ac97, AC97_EXTENDED_STATUS, |
| 516 | AC97_EA_SPSA_SLOT_MASK, AC97_EA_SPSA_3_4); |
| 517 | #endif |
| 518 | |
| 519 | return 0; |
| 520 | } |
| 521 | |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 522 | ret = snd_soc_dai_set_sysclk(codec_dai, codec_priv->mclk_id, |
| 523 | codec_priv->mclk_freq, SND_SOC_CLOCK_IN); |
Nicolin Chen | 758a3b0 | 2017-09-07 22:27:33 -0700 | [diff] [blame] | 524 | if (ret && ret != -ENOTSUPP) { |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 525 | dev_err(dev, "failed to set sysclk in %s\n", __func__); |
| 526 | return ret; |
| 527 | } |
| 528 | |
| 529 | return 0; |
| 530 | } |
| 531 | |
| 532 | static int fsl_asoc_card_probe(struct platform_device *pdev) |
| 533 | { |
| 534 | struct device_node *cpu_np, *codec_np, *asrc_np; |
| 535 | struct device_node *np = pdev->dev.of_node; |
| 536 | struct platform_device *asrc_pdev = NULL; |
Mark Brown | 8fcfd34 | 2021-09-21 22:35:28 +0100 | [diff] [blame] | 537 | struct device_node *bitclkprovider = NULL; |
| 538 | struct device_node *frameprovider = NULL; |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 539 | struct platform_device *cpu_pdev; |
| 540 | struct fsl_asoc_card_priv *priv; |
Shengjiu Wang | 039652a | 2020-06-17 12:48:25 +0800 | [diff] [blame] | 541 | struct device *codec_dev = NULL; |
Nicolin Chen | 114bb13 | 2015-08-12 13:06:12 -0700 | [diff] [blame] | 542 | const char *codec_dai_name; |
Shengjiu Wang | 039652a | 2020-06-17 12:48:25 +0800 | [diff] [blame] | 543 | const char *codec_dev_name; |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 544 | u32 width; |
| 545 | int ret; |
| 546 | |
| 547 | priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); |
| 548 | if (!priv) |
| 549 | return -ENOMEM; |
| 550 | |
| 551 | cpu_np = of_parse_phandle(np, "audio-cpu", 0); |
| 552 | /* Give a chance to old DT binding */ |
| 553 | if (!cpu_np) |
| 554 | cpu_np = of_parse_phandle(np, "ssi-controller", 0); |
Maciej S. Szmigiero | 50760ca | 2015-09-19 02:00:25 +0200 | [diff] [blame] | 555 | if (!cpu_np) { |
| 556 | dev_err(&pdev->dev, "CPU phandle missing or invalid\n"); |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 557 | ret = -EINVAL; |
| 558 | goto fail; |
| 559 | } |
| 560 | |
| 561 | cpu_pdev = of_find_device_by_node(cpu_np); |
| 562 | if (!cpu_pdev) { |
| 563 | dev_err(&pdev->dev, "failed to find CPU DAI device\n"); |
| 564 | ret = -EINVAL; |
| 565 | goto fail; |
| 566 | } |
| 567 | |
Maciej S. Szmigiero | 50760ca | 2015-09-19 02:00:25 +0200 | [diff] [blame] | 568 | codec_np = of_parse_phandle(np, "audio-codec", 0); |
Shengjiu Wang | 039652a | 2020-06-17 12:48:25 +0800 | [diff] [blame] | 569 | if (codec_np) { |
| 570 | struct platform_device *codec_pdev; |
| 571 | struct i2c_client *codec_i2c; |
| 572 | |
| 573 | codec_i2c = of_find_i2c_device_by_node(codec_np); |
| 574 | if (codec_i2c) { |
| 575 | codec_dev = &codec_i2c->dev; |
| 576 | codec_dev_name = codec_i2c->name; |
| 577 | } |
| 578 | if (!codec_dev) { |
| 579 | codec_pdev = of_find_device_by_node(codec_np); |
| 580 | if (codec_pdev) { |
| 581 | codec_dev = &codec_pdev->dev; |
| 582 | codec_dev_name = codec_pdev->name; |
| 583 | } |
| 584 | } |
| 585 | } |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 586 | |
| 587 | asrc_np = of_parse_phandle(np, "audio-asrc", 0); |
| 588 | if (asrc_np) |
| 589 | asrc_pdev = of_find_device_by_node(asrc_np); |
| 590 | |
| 591 | /* Get the MCLK rate only, and leave it controlled by CODEC drivers */ |
Maciej S. Szmigiero | 50760ca | 2015-09-19 02:00:25 +0200 | [diff] [blame] | 592 | if (codec_dev) { |
Shengjiu Wang | 039652a | 2020-06-17 12:48:25 +0800 | [diff] [blame] | 593 | struct clk *codec_clk = clk_get(codec_dev, NULL); |
Maciej S. Szmigiero | 50760ca | 2015-09-19 02:00:25 +0200 | [diff] [blame] | 594 | |
| 595 | if (!IS_ERR(codec_clk)) { |
| 596 | priv->codec_priv.mclk_freq = clk_get_rate(codec_clk); |
| 597 | clk_put(codec_clk); |
| 598 | } |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | /* Default sample rate and format, will be updated in hw_params() */ |
| 602 | priv->sample_rate = 44100; |
| 603 | priv->sample_format = SNDRV_PCM_FORMAT_S16_LE; |
| 604 | |
| 605 | /* Assign a default DAI format, and allow each card to overwrite it */ |
| 606 | priv->dai_fmt = DAI_FMT_BASE; |
| 607 | |
Shengjiu Wang | 039652a | 2020-06-17 12:48:25 +0800 | [diff] [blame] | 608 | memcpy(priv->dai_link, fsl_asoc_card_dai, |
| 609 | sizeof(struct snd_soc_dai_link) * ARRAY_SIZE(priv->dai_link)); |
| 610 | |
| 611 | priv->card.dapm_routes = audio_map; |
| 612 | priv->card.num_dapm_routes = ARRAY_SIZE(audio_map); |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 613 | /* Diversify the card configurations */ |
| 614 | if (of_device_is_compatible(np, "fsl,imx-audio-cs42888")) { |
Nicolin Chen | 114bb13 | 2015-08-12 13:06:12 -0700 | [diff] [blame] | 615 | codec_dai_name = "cs42888"; |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 616 | priv->cpu_priv.sysclk_freq[TX] = priv->codec_priv.mclk_freq; |
| 617 | priv->cpu_priv.sysclk_freq[RX] = priv->codec_priv.mclk_freq; |
| 618 | priv->cpu_priv.sysclk_dir[TX] = SND_SOC_CLOCK_OUT; |
| 619 | priv->cpu_priv.sysclk_dir[RX] = SND_SOC_CLOCK_OUT; |
Nicolin Chen | cb3fc1f | 2014-10-24 16:48:13 -0700 | [diff] [blame] | 620 | priv->cpu_priv.slot_width = 32; |
Mark Brown | 8fcfd34 | 2021-09-21 22:35:28 +0100 | [diff] [blame] | 621 | priv->dai_fmt |= SND_SOC_DAIFMT_CBC_CFC; |
Felipe F. Tonello | 57e756d | 2016-01-29 11:01:00 +0000 | [diff] [blame] | 622 | } else if (of_device_is_compatible(np, "fsl,imx-audio-cs427x")) { |
| 623 | codec_dai_name = "cs4271-hifi"; |
| 624 | priv->codec_priv.mclk_id = CS427x_SYSCLK_MCLK; |
Mark Brown | 8fcfd34 | 2021-09-21 22:35:28 +0100 | [diff] [blame] | 625 | priv->dai_fmt |= SND_SOC_DAIFMT_CBP_CFP; |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 626 | } else if (of_device_is_compatible(np, "fsl,imx-audio-sgtl5000")) { |
Nicolin Chen | 114bb13 | 2015-08-12 13:06:12 -0700 | [diff] [blame] | 627 | codec_dai_name = "sgtl5000"; |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 628 | priv->codec_priv.mclk_id = SGTL5000_SYSCLK; |
Mark Brown | 8fcfd34 | 2021-09-21 22:35:28 +0100 | [diff] [blame] | 629 | priv->dai_fmt |= SND_SOC_DAIFMT_CBP_CFP; |
Matthias Schiffer | b507475 | 2020-08-21 09:11:53 +0200 | [diff] [blame] | 630 | } else if (of_device_is_compatible(np, "fsl,imx-audio-tlv320aic32x4")) { |
| 631 | codec_dai_name = "tlv320aic32x4-hifi"; |
Mark Brown | 8fcfd34 | 2021-09-21 22:35:28 +0100 | [diff] [blame] | 632 | priv->dai_fmt |= SND_SOC_DAIFMT_CBP_CFP; |
Ariel D'Alessandro | 8c9b9cfb | 2021-11-19 12:32:48 -0300 | [diff] [blame] | 633 | } else if (of_device_is_compatible(np, "fsl,imx-audio-tlv320aic31xx")) { |
| 634 | codec_dai_name = "tlv320dac31xx-hifi"; |
| 635 | priv->dai_fmt |= SND_SOC_DAIFMT_CBS_CFS; |
| 636 | priv->dai_link[1].dpcm_capture = 0; |
| 637 | priv->dai_link[2].dpcm_capture = 0; |
| 638 | priv->cpu_priv.sysclk_dir[TX] = SND_SOC_CLOCK_OUT; |
| 639 | priv->cpu_priv.sysclk_dir[RX] = SND_SOC_CLOCK_OUT; |
| 640 | priv->codec_priv.mclk_id = AIC31XX_PLL_CLKIN_BCLK; |
| 641 | priv->card.dapm_routes = audio_map_tx; |
| 642 | priv->card.num_dapm_routes = ARRAY_SIZE(audio_map_tx); |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 643 | } else if (of_device_is_compatible(np, "fsl,imx-audio-wm8962")) { |
Nicolin Chen | 114bb13 | 2015-08-12 13:06:12 -0700 | [diff] [blame] | 644 | codec_dai_name = "wm8962"; |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 645 | priv->codec_priv.mclk_id = WM8962_SYSCLK_MCLK; |
| 646 | priv->codec_priv.fll_id = WM8962_SYSCLK_FLL; |
| 647 | priv->codec_priv.pll_id = WM8962_FLL; |
Mark Brown | 8fcfd34 | 2021-09-21 22:35:28 +0100 | [diff] [blame] | 648 | priv->dai_fmt |= SND_SOC_DAIFMT_CBP_CFP; |
Zidan Wang | 50e0ee0 | 2015-08-14 19:11:09 +0800 | [diff] [blame] | 649 | } else if (of_device_is_compatible(np, "fsl,imx-audio-wm8960")) { |
| 650 | codec_dai_name = "wm8960-hifi"; |
Zidan Wang | 50e0ee0 | 2015-08-14 19:11:09 +0800 | [diff] [blame] | 651 | priv->codec_priv.fll_id = WM8960_SYSCLK_AUTO; |
| 652 | priv->codec_priv.pll_id = WM8960_SYSCLK_AUTO; |
Mark Brown | 8fcfd34 | 2021-09-21 22:35:28 +0100 | [diff] [blame] | 653 | priv->dai_fmt |= SND_SOC_DAIFMT_CBP_CFP; |
Maciej S. Szmigiero | 50760ca | 2015-09-19 02:00:25 +0200 | [diff] [blame] | 654 | } else if (of_device_is_compatible(np, "fsl,imx-audio-ac97")) { |
| 655 | codec_dai_name = "ac97-hifi"; |
Maciej S. Szmigiero | 50760ca | 2015-09-19 02:00:25 +0200 | [diff] [blame] | 656 | priv->dai_fmt = SND_SOC_DAIFMT_AC97; |
Shengjiu Wang | 039652a | 2020-06-17 12:48:25 +0800 | [diff] [blame] | 657 | priv->card.dapm_routes = audio_map_ac97; |
| 658 | priv->card.num_dapm_routes = ARRAY_SIZE(audio_map_ac97); |
| 659 | } else if (of_device_is_compatible(np, "fsl,imx-audio-mqs")) { |
| 660 | codec_dai_name = "fsl-mqs-dai"; |
Shengjiu Wang | 039652a | 2020-06-17 12:48:25 +0800 | [diff] [blame] | 661 | priv->dai_fmt = SND_SOC_DAIFMT_LEFT_J | |
Mark Brown | 8fcfd34 | 2021-09-21 22:35:28 +0100 | [diff] [blame] | 662 | SND_SOC_DAIFMT_CBC_CFC | |
Shengjiu Wang | 039652a | 2020-06-17 12:48:25 +0800 | [diff] [blame] | 663 | SND_SOC_DAIFMT_NB_NF; |
| 664 | priv->dai_link[1].dpcm_capture = 0; |
| 665 | priv->dai_link[2].dpcm_capture = 0; |
| 666 | priv->card.dapm_routes = audio_map_tx; |
| 667 | priv->card.num_dapm_routes = ARRAY_SIZE(audio_map_tx); |
Shengjiu Wang | 3cd9902 | 2020-06-23 14:52:46 +0800 | [diff] [blame] | 668 | } else if (of_device_is_compatible(np, "fsl,imx-audio-wm8524")) { |
| 669 | codec_dai_name = "wm8524-hifi"; |
Mark Brown | 8fcfd34 | 2021-09-21 22:35:28 +0100 | [diff] [blame] | 670 | priv->dai_fmt |= SND_SOC_DAIFMT_CBC_CFC; |
Shengjiu Wang | 3cd9902 | 2020-06-23 14:52:46 +0800 | [diff] [blame] | 671 | priv->dai_link[1].dpcm_capture = 0; |
| 672 | priv->dai_link[2].dpcm_capture = 0; |
| 673 | priv->cpu_priv.slot_width = 32; |
| 674 | priv->card.dapm_routes = audio_map_tx; |
| 675 | priv->card.num_dapm_routes = ARRAY_SIZE(audio_map_tx); |
Shengjiu Wang | 77f1ff75 | 2020-11-30 11:57:47 +0800 | [diff] [blame] | 676 | } else if (of_device_is_compatible(np, "fsl,imx-audio-si476x")) { |
| 677 | codec_dai_name = "si476x-codec"; |
Mark Brown | 8fcfd34 | 2021-09-21 22:35:28 +0100 | [diff] [blame] | 678 | priv->dai_fmt |= SND_SOC_DAIFMT_CBC_CFC; |
Shengjiu Wang | 77f1ff75 | 2020-11-30 11:57:47 +0800 | [diff] [blame] | 679 | priv->card.dapm_routes = audio_map_rx; |
| 680 | priv->card.num_dapm_routes = ARRAY_SIZE(audio_map_rx); |
Shengjiu Wang | efd0b16 | 2021-03-17 21:05:02 +0800 | [diff] [blame] | 681 | } else if (of_device_is_compatible(np, "fsl,imx-audio-wm8958")) { |
| 682 | codec_dai_name = "wm8994-aif1"; |
Mark Brown | 8fcfd34 | 2021-09-21 22:35:28 +0100 | [diff] [blame] | 683 | priv->dai_fmt |= SND_SOC_DAIFMT_CBP_CFP; |
Shengjiu Wang | efd0b16 | 2021-03-17 21:05:02 +0800 | [diff] [blame] | 684 | priv->codec_priv.mclk_id = WM8994_FLL_SRC_MCLK1; |
| 685 | priv->codec_priv.fll_id = WM8994_SYSCLK_FLL1; |
| 686 | priv->codec_priv.pll_id = WM8994_FLL1; |
| 687 | priv->codec_priv.free_freq = priv->codec_priv.mclk_freq; |
| 688 | priv->card.dapm_routes = NULL; |
| 689 | priv->card.num_dapm_routes = 0; |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 690 | } else { |
| 691 | dev_err(&pdev->dev, "unknown Device Tree compatible\n"); |
Maciej S. Szmigiero | 6bd3c6f | 2015-08-31 17:07:12 +0200 | [diff] [blame] | 692 | ret = -EINVAL; |
| 693 | goto asrc_fail; |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 694 | } |
| 695 | |
Shengjiu Wang | 08b54b5e | 2020-07-21 11:41:49 +0800 | [diff] [blame] | 696 | /* Format info from DT is optional. */ |
Mark Brown | 8fcfd34 | 2021-09-21 22:35:28 +0100 | [diff] [blame] | 697 | snd_soc_daifmt_parse_clock_provider_as_phandle(np, NULL, &bitclkprovider, &frameprovider); |
| 698 | if (bitclkprovider || frameprovider) { |
Kuninori Morimoto | 3bba941 | 2021-06-14 09:57:51 +0900 | [diff] [blame] | 699 | unsigned int daifmt = snd_soc_daifmt_parse_format(np, NULL); |
| 700 | |
Mark Brown | 8fcfd34 | 2021-09-21 22:35:28 +0100 | [diff] [blame] | 701 | if (codec_np == bitclkprovider) |
| 702 | daifmt |= (codec_np == frameprovider) ? |
| 703 | SND_SOC_DAIFMT_CBP_CFP : SND_SOC_DAIFMT_CBP_CFC; |
Shengjiu Wang | 08b54b5e | 2020-07-21 11:41:49 +0800 | [diff] [blame] | 704 | else |
Mark Brown | 8fcfd34 | 2021-09-21 22:35:28 +0100 | [diff] [blame] | 705 | daifmt |= (codec_np == frameprovider) ? |
| 706 | SND_SOC_DAIFMT_CBC_CFP : SND_SOC_DAIFMT_CBC_CFC; |
Shengjiu Wang | 08b54b5e | 2020-07-21 11:41:49 +0800 | [diff] [blame] | 707 | |
| 708 | /* Override dai_fmt with value from DT */ |
| 709 | priv->dai_fmt = daifmt; |
| 710 | } |
| 711 | |
| 712 | /* Change direction according to format */ |
Mark Brown | 8fcfd34 | 2021-09-21 22:35:28 +0100 | [diff] [blame] | 713 | if (priv->dai_fmt & SND_SOC_DAIFMT_CBP_CFP) { |
Shengjiu Wang | 08b54b5e | 2020-07-21 11:41:49 +0800 | [diff] [blame] | 714 | priv->cpu_priv.sysclk_dir[TX] = SND_SOC_CLOCK_IN; |
| 715 | priv->cpu_priv.sysclk_dir[RX] = SND_SOC_CLOCK_IN; |
| 716 | } |
| 717 | |
Mark Brown | 8fcfd34 | 2021-09-21 22:35:28 +0100 | [diff] [blame] | 718 | of_node_put(bitclkprovider); |
| 719 | of_node_put(frameprovider); |
Shengjiu Wang | 08b54b5e | 2020-07-21 11:41:49 +0800 | [diff] [blame] | 720 | |
Maciej S. Szmigiero | 50760ca | 2015-09-19 02:00:25 +0200 | [diff] [blame] | 721 | if (!fsl_asoc_card_is_ac97(priv) && !codec_dev) { |
Shengjiu Wang | 4b1d517 | 2021-06-02 14:42:12 +0800 | [diff] [blame] | 722 | dev_dbg(&pdev->dev, "failed to find codec device\n"); |
Shengjiu Wang | e396dec | 2020-06-04 14:25:30 +0800 | [diff] [blame] | 723 | ret = -EPROBE_DEFER; |
Maciej S. Szmigiero | 50760ca | 2015-09-19 02:00:25 +0200 | [diff] [blame] | 724 | goto asrc_fail; |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 725 | } |
| 726 | |
| 727 | /* Common settings for corresponding Freescale CPU DAI driver */ |
Rob Herring | 1d52a74 | 2018-12-05 13:50:49 -0600 | [diff] [blame] | 728 | if (of_node_name_eq(cpu_np, "ssi")) { |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 729 | /* Only SSI needs to configure AUDMUX */ |
| 730 | ret = fsl_asoc_card_audmux_init(np, priv); |
| 731 | if (ret) { |
| 732 | dev_err(&pdev->dev, "failed to init audmux\n"); |
Shengjiu Wang | 5f37671 | 2014-08-18 16:38:39 +0800 | [diff] [blame] | 733 | goto asrc_fail; |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 734 | } |
Rob Herring | 1d52a74 | 2018-12-05 13:50:49 -0600 | [diff] [blame] | 735 | } else if (of_node_name_eq(cpu_np, "esai")) { |
Shengjiu Wang | a8fd5ca | 2020-08-10 16:11:43 +0800 | [diff] [blame] | 736 | struct clk *esai_clk = clk_get(&cpu_pdev->dev, "extal"); |
| 737 | |
| 738 | if (!IS_ERR(esai_clk)) { |
| 739 | priv->cpu_priv.sysclk_freq[TX] = clk_get_rate(esai_clk); |
| 740 | priv->cpu_priv.sysclk_freq[RX] = clk_get_rate(esai_clk); |
| 741 | clk_put(esai_clk); |
| 742 | } else if (PTR_ERR(esai_clk) == -EPROBE_DEFER) { |
| 743 | ret = -EPROBE_DEFER; |
| 744 | goto asrc_fail; |
| 745 | } |
| 746 | |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 747 | priv->cpu_priv.sysclk_id[1] = ESAI_HCKT_EXTAL; |
| 748 | priv->cpu_priv.sysclk_id[0] = ESAI_HCKR_EXTAL; |
Rob Herring | 1d52a74 | 2018-12-05 13:50:49 -0600 | [diff] [blame] | 749 | } else if (of_node_name_eq(cpu_np, "sai")) { |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 750 | priv->cpu_priv.sysclk_id[1] = FSL_SAI_CLK_MAST1; |
| 751 | priv->cpu_priv.sysclk_id[0] = FSL_SAI_CLK_MAST1; |
| 752 | } |
| 753 | |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 754 | /* Initialize sound card */ |
| 755 | priv->pdev = pdev; |
| 756 | priv->card.dev = &pdev->dev; |
Nicolas Cavallari | a8437f0 | 2021-05-27 18:34:09 +0200 | [diff] [blame] | 757 | priv->card.owner = THIS_MODULE; |
Shengjiu Wang | 039652a | 2020-06-17 12:48:25 +0800 | [diff] [blame] | 758 | ret = snd_soc_of_parse_card_name(&priv->card, "model"); |
| 759 | if (ret) { |
| 760 | snprintf(priv->name, sizeof(priv->name), "%s-audio", |
| 761 | fsl_asoc_card_is_ac97(priv) ? "ac97" : codec_dev_name); |
| 762 | priv->card.name = priv->name; |
| 763 | } |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 764 | priv->card.dai_link = priv->dai_link; |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 765 | priv->card.late_probe = fsl_asoc_card_late_probe; |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 766 | priv->card.dapm_widgets = fsl_asoc_card_dapm_widgets; |
| 767 | priv->card.num_dapm_widgets = ARRAY_SIZE(fsl_asoc_card_dapm_widgets); |
| 768 | |
Nicolin Chen | 089dfaf | 2016-01-30 23:07:00 -0800 | [diff] [blame] | 769 | /* Drop the second half of DAPM routes -- ASRC */ |
| 770 | if (!asrc_pdev) |
| 771 | priv->card.num_dapm_routes /= 2; |
| 772 | |
Shengjiu Wang | 039652a | 2020-06-17 12:48:25 +0800 | [diff] [blame] | 773 | if (of_property_read_bool(np, "audio-routing")) { |
| 774 | ret = snd_soc_of_parse_audio_routing(&priv->card, "audio-routing"); |
| 775 | if (ret) { |
| 776 | dev_err(&pdev->dev, "failed to parse audio-routing: %d\n", ret); |
| 777 | goto asrc_fail; |
| 778 | } |
Nicolin Chen | 3185878 | 2015-02-14 17:22:50 -0800 | [diff] [blame] | 779 | } |
| 780 | |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 781 | /* Normal DAI Link */ |
Kuninori Morimoto | 893f195 | 2019-06-06 13:15:11 +0900 | [diff] [blame] | 782 | priv->dai_link[0].cpus->of_node = cpu_np; |
| 783 | priv->dai_link[0].codecs->dai_name = codec_dai_name; |
Maciej S. Szmigiero | 50760ca | 2015-09-19 02:00:25 +0200 | [diff] [blame] | 784 | |
| 785 | if (!fsl_asoc_card_is_ac97(priv)) |
Kuninori Morimoto | 893f195 | 2019-06-06 13:15:11 +0900 | [diff] [blame] | 786 | priv->dai_link[0].codecs->of_node = codec_np; |
Maciej S. Szmigiero | 50760ca | 2015-09-19 02:00:25 +0200 | [diff] [blame] | 787 | else { |
| 788 | u32 idx; |
| 789 | |
| 790 | ret = of_property_read_u32(cpu_np, "cell-index", &idx); |
| 791 | if (ret) { |
| 792 | dev_err(&pdev->dev, |
| 793 | "cannot get CPU index property\n"); |
| 794 | goto asrc_fail; |
| 795 | } |
| 796 | |
Kuninori Morimoto | 893f195 | 2019-06-06 13:15:11 +0900 | [diff] [blame] | 797 | priv->dai_link[0].codecs->name = |
Maciej S. Szmigiero | 50760ca | 2015-09-19 02:00:25 +0200 | [diff] [blame] | 798 | devm_kasprintf(&pdev->dev, GFP_KERNEL, |
| 799 | "ac97-codec.%u", |
| 800 | (unsigned int)idx); |
Kuninori Morimoto | 893f195 | 2019-06-06 13:15:11 +0900 | [diff] [blame] | 801 | if (!priv->dai_link[0].codecs->name) { |
Arvind Yadav | 7add71b | 2017-09-21 10:50:03 +0530 | [diff] [blame] | 802 | ret = -ENOMEM; |
| 803 | goto asrc_fail; |
| 804 | } |
Maciej S. Szmigiero | 50760ca | 2015-09-19 02:00:25 +0200 | [diff] [blame] | 805 | } |
| 806 | |
Kuninori Morimoto | 9998d3e | 2019-06-28 10:47:18 +0900 | [diff] [blame] | 807 | priv->dai_link[0].platforms->of_node = cpu_np; |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 808 | priv->dai_link[0].dai_fmt = priv->dai_fmt; |
| 809 | priv->card.num_links = 1; |
| 810 | |
| 811 | if (asrc_pdev) { |
| 812 | /* DPCM DAI Links only if ASRC exsits */ |
Kuninori Morimoto | 893f195 | 2019-06-06 13:15:11 +0900 | [diff] [blame] | 813 | priv->dai_link[1].cpus->of_node = asrc_np; |
Kuninori Morimoto | 9998d3e | 2019-06-28 10:47:18 +0900 | [diff] [blame] | 814 | priv->dai_link[1].platforms->of_node = asrc_np; |
Kuninori Morimoto | 893f195 | 2019-06-06 13:15:11 +0900 | [diff] [blame] | 815 | priv->dai_link[2].codecs->dai_name = codec_dai_name; |
| 816 | priv->dai_link[2].codecs->of_node = codec_np; |
| 817 | priv->dai_link[2].codecs->name = |
| 818 | priv->dai_link[0].codecs->name; |
| 819 | priv->dai_link[2].cpus->of_node = cpu_np; |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 820 | priv->dai_link[2].dai_fmt = priv->dai_fmt; |
| 821 | priv->card.num_links = 3; |
| 822 | |
| 823 | ret = of_property_read_u32(asrc_np, "fsl,asrc-rate", |
| 824 | &priv->asrc_rate); |
| 825 | if (ret) { |
| 826 | dev_err(&pdev->dev, "failed to get output rate\n"); |
| 827 | ret = -EINVAL; |
Shengjiu Wang | 5f37671 | 2014-08-18 16:38:39 +0800 | [diff] [blame] | 828 | goto asrc_fail; |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 829 | } |
| 830 | |
Shengjiu Wang | 859e364 | 2020-04-16 20:25:33 +0800 | [diff] [blame] | 831 | ret = of_property_read_u32(asrc_np, "fsl,asrc-format", |
| 832 | &priv->asrc_format); |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 833 | if (ret) { |
Shengjiu Wang | 859e364 | 2020-04-16 20:25:33 +0800 | [diff] [blame] | 834 | /* Fallback to old binding; translate to asrc_format */ |
| 835 | ret = of_property_read_u32(asrc_np, "fsl,asrc-width", |
| 836 | &width); |
| 837 | if (ret) { |
| 838 | dev_err(&pdev->dev, |
| 839 | "failed to decide output format\n"); |
| 840 | goto asrc_fail; |
| 841 | } |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 842 | |
Shengjiu Wang | 859e364 | 2020-04-16 20:25:33 +0800 | [diff] [blame] | 843 | if (width == 24) |
| 844 | priv->asrc_format = SNDRV_PCM_FORMAT_S24_LE; |
| 845 | else |
| 846 | priv->asrc_format = SNDRV_PCM_FORMAT_S16_LE; |
| 847 | } |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 848 | } |
| 849 | |
| 850 | /* Finish card registering */ |
| 851 | platform_set_drvdata(pdev, priv); |
| 852 | snd_soc_card_set_drvdata(&priv->card, priv); |
| 853 | |
| 854 | ret = devm_snd_soc_register_card(&pdev->dev, &priv->card); |
Shengjiu Wang | 3b17119 | 2020-07-15 22:09:39 +0800 | [diff] [blame] | 855 | if (ret) { |
Kuninori Morimoto | 2e6f557 | 2021-12-14 11:08:34 +0900 | [diff] [blame] | 856 | dev_err_probe(&pdev->dev, ret, "snd_soc_register_card failed\n"); |
Shengjiu Wang | 3b17119 | 2020-07-15 22:09:39 +0800 | [diff] [blame] | 857 | goto asrc_fail; |
| 858 | } |
| 859 | |
| 860 | /* |
| 861 | * Properties "hp-det-gpio" and "mic-det-gpio" are optional, and |
| 862 | * asoc_simple_init_jack uses these properties for creating |
| 863 | * Headphone Jack and Microphone Jack. |
| 864 | * |
| 865 | * The notifier is initialized in snd_soc_card_jack_new(), then |
| 866 | * snd_soc_jack_notifier_register can be called. |
| 867 | */ |
| 868 | if (of_property_read_bool(np, "hp-det-gpio")) { |
| 869 | ret = asoc_simple_init_jack(&priv->card, &priv->hp_jack, |
| 870 | 1, NULL, "Headphone Jack"); |
| 871 | if (ret) |
| 872 | goto asrc_fail; |
| 873 | |
| 874 | snd_soc_jack_notifier_register(&priv->hp_jack.jack, &hp_jack_nb); |
| 875 | } |
| 876 | |
| 877 | if (of_property_read_bool(np, "mic-det-gpio")) { |
| 878 | ret = asoc_simple_init_jack(&priv->card, &priv->mic_jack, |
| 879 | 0, NULL, "Mic Jack"); |
| 880 | if (ret) |
| 881 | goto asrc_fail; |
| 882 | |
| 883 | snd_soc_jack_notifier_register(&priv->mic_jack.jack, &mic_jack_nb); |
| 884 | } |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 885 | |
Shengjiu Wang | 5f37671 | 2014-08-18 16:38:39 +0800 | [diff] [blame] | 886 | asrc_fail: |
| 887 | of_node_put(asrc_np); |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 888 | of_node_put(codec_np); |
wen yang | 11907e9d | 2019-02-02 14:53:16 +0000 | [diff] [blame] | 889 | put_device(&cpu_pdev->dev); |
Maciej S. Szmigiero | 50760ca | 2015-09-19 02:00:25 +0200 | [diff] [blame] | 890 | fail: |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 891 | of_node_put(cpu_np); |
| 892 | |
| 893 | return ret; |
| 894 | } |
| 895 | |
| 896 | static const struct of_device_id fsl_asoc_card_dt_ids[] = { |
Maciej S. Szmigiero | 50760ca | 2015-09-19 02:00:25 +0200 | [diff] [blame] | 897 | { .compatible = "fsl,imx-audio-ac97", }, |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 898 | { .compatible = "fsl,imx-audio-cs42888", }, |
Felipe F. Tonello | 57e756d | 2016-01-29 11:01:00 +0000 | [diff] [blame] | 899 | { .compatible = "fsl,imx-audio-cs427x", }, |
Matthias Schiffer | b507475 | 2020-08-21 09:11:53 +0200 | [diff] [blame] | 900 | { .compatible = "fsl,imx-audio-tlv320aic32x4", }, |
Ariel D'Alessandro | 8c9b9cfb | 2021-11-19 12:32:48 -0300 | [diff] [blame] | 901 | { .compatible = "fsl,imx-audio-tlv320aic31xx", }, |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 902 | { .compatible = "fsl,imx-audio-sgtl5000", }, |
| 903 | { .compatible = "fsl,imx-audio-wm8962", }, |
Zidan Wang | 50e0ee0 | 2015-08-14 19:11:09 +0800 | [diff] [blame] | 904 | { .compatible = "fsl,imx-audio-wm8960", }, |
Shengjiu Wang | 039652a | 2020-06-17 12:48:25 +0800 | [diff] [blame] | 905 | { .compatible = "fsl,imx-audio-mqs", }, |
Shengjiu Wang | 3cd9902 | 2020-06-23 14:52:46 +0800 | [diff] [blame] | 906 | { .compatible = "fsl,imx-audio-wm8524", }, |
Shengjiu Wang | 77f1ff75 | 2020-11-30 11:57:47 +0800 | [diff] [blame] | 907 | { .compatible = "fsl,imx-audio-si476x", }, |
Shengjiu Wang | efd0b16 | 2021-03-17 21:05:02 +0800 | [diff] [blame] | 908 | { .compatible = "fsl,imx-audio-wm8958", }, |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 909 | {} |
| 910 | }; |
Luis de Bethencourt | 5226f23 | 2015-09-03 12:57:47 +0200 | [diff] [blame] | 911 | MODULE_DEVICE_TABLE(of, fsl_asoc_card_dt_ids); |
Nicolin Chen | 708b435 | 2014-07-30 19:27:38 +0800 | [diff] [blame] | 912 | |
| 913 | static struct platform_driver fsl_asoc_card_driver = { |
| 914 | .probe = fsl_asoc_card_probe, |
| 915 | .driver = { |
| 916 | .name = "fsl-asoc-card", |
| 917 | .pm = &snd_soc_pm_ops, |
| 918 | .of_match_table = fsl_asoc_card_dt_ids, |
| 919 | }, |
| 920 | }; |
| 921 | module_platform_driver(fsl_asoc_card_driver); |
| 922 | |
| 923 | MODULE_DESCRIPTION("Freescale Generic ASoC Sound Card driver with ASRC"); |
| 924 | MODULE_AUTHOR("Nicolin Chen <nicoleotsuka@gmail.com>"); |
| 925 | MODULE_ALIAS("platform:fsl-asoc-card"); |
| 926 | MODULE_LICENSE("GPL"); |