| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * sam9g20_wm8731 -- SoC audio for AT91SAM9G20-based |
|---|
| 3 | 4 | * ATMEL AT91SAM9G20ek board. |
|---|
| .. | .. |
|---|
| 13 | 14 | * Based on corgi.c by: |
|---|
| 14 | 15 | * Copyright 2005 Wolfson Microelectronics PLC. |
|---|
| 15 | 16 | * Copyright 2005 Openedhand Ltd. |
|---|
| 16 | | - * |
|---|
| 17 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 18 | | - * it under the terms of the GNU General Public License as published by |
|---|
| 19 | | - * the Free Software Foundation; either version 2 of the License, or |
|---|
| 20 | | - * (at your option) any later version. |
|---|
| 21 | | - * |
|---|
| 22 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 23 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 24 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 25 | | - * GNU General Public License for more details. |
|---|
| 26 | | - * |
|---|
| 27 | | - * You should have received a copy of the GNU General Public License |
|---|
| 28 | | - * along with this program; if not, write to the Free Software |
|---|
| 29 | | - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 30 | 17 | */ |
|---|
| 31 | 18 | |
|---|
| 32 | 19 | #include <linux/module.h> |
|---|
| .. | .. |
|---|
| 59 | 46 | */ |
|---|
| 60 | 47 | #undef ENABLE_MIC_INPUT |
|---|
| 61 | 48 | |
|---|
| 62 | | -static struct clk *mclk; |
|---|
| 63 | | - |
|---|
| 64 | | -static int at91sam9g20ek_set_bias_level(struct snd_soc_card *card, |
|---|
| 65 | | - struct snd_soc_dapm_context *dapm, |
|---|
| 66 | | - enum snd_soc_bias_level level) |
|---|
| 67 | | -{ |
|---|
| 68 | | - static int mclk_on; |
|---|
| 69 | | - int ret = 0; |
|---|
| 70 | | - |
|---|
| 71 | | - switch (level) { |
|---|
| 72 | | - case SND_SOC_BIAS_ON: |
|---|
| 73 | | - case SND_SOC_BIAS_PREPARE: |
|---|
| 74 | | - if (!mclk_on) |
|---|
| 75 | | - ret = clk_enable(mclk); |
|---|
| 76 | | - if (ret == 0) |
|---|
| 77 | | - mclk_on = 1; |
|---|
| 78 | | - break; |
|---|
| 79 | | - |
|---|
| 80 | | - case SND_SOC_BIAS_OFF: |
|---|
| 81 | | - case SND_SOC_BIAS_STANDBY: |
|---|
| 82 | | - if (mclk_on) |
|---|
| 83 | | - clk_disable(mclk); |
|---|
| 84 | | - mclk_on = 0; |
|---|
| 85 | | - break; |
|---|
| 86 | | - } |
|---|
| 87 | | - |
|---|
| 88 | | - return ret; |
|---|
| 89 | | -} |
|---|
| 90 | | - |
|---|
| 91 | 49 | static const struct snd_soc_dapm_widget at91sam9g20ek_dapm_widgets[] = { |
|---|
| 92 | 50 | SND_SOC_DAPM_MIC("Int Mic", NULL), |
|---|
| 93 | 51 | SND_SOC_DAPM_SPK("Ext Spk", NULL), |
|---|
| .. | .. |
|---|
| 109 | 67 | */ |
|---|
| 110 | 68 | static int at91sam9g20ek_wm8731_init(struct snd_soc_pcm_runtime *rtd) |
|---|
| 111 | 69 | { |
|---|
| 112 | | - struct snd_soc_dai *codec_dai = rtd->codec_dai; |
|---|
| 70 | + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0); |
|---|
| 113 | 71 | struct device *dev = rtd->dev; |
|---|
| 114 | 72 | int ret; |
|---|
| 115 | 73 | |
|---|
| .. | .. |
|---|
| 129 | 87 | return 0; |
|---|
| 130 | 88 | } |
|---|
| 131 | 89 | |
|---|
| 90 | +SND_SOC_DAILINK_DEFS(pcm, |
|---|
| 91 | + DAILINK_COMP_ARRAY(COMP_CPU("at91rm9200_ssc.0")), |
|---|
| 92 | + DAILINK_COMP_ARRAY(COMP_CODEC("wm8731.0-001b", "wm8731-hifi")), |
|---|
| 93 | + DAILINK_COMP_ARRAY(COMP_PLATFORM("at91rm9200_ssc.0"))); |
|---|
| 94 | + |
|---|
| 132 | 95 | static struct snd_soc_dai_link at91sam9g20ek_dai = { |
|---|
| 133 | 96 | .name = "WM8731", |
|---|
| 134 | 97 | .stream_name = "WM8731 PCM", |
|---|
| 135 | | - .cpu_dai_name = "at91rm9200_ssc.0", |
|---|
| 136 | | - .codec_dai_name = "wm8731-hifi", |
|---|
| 137 | 98 | .init = at91sam9g20ek_wm8731_init, |
|---|
| 138 | | - .platform_name = "at91rm9200_ssc.0", |
|---|
| 139 | | - .codec_name = "wm8731.0-001b", |
|---|
| 140 | 99 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | |
|---|
| 141 | 100 | SND_SOC_DAIFMT_CBM_CFM, |
|---|
| 101 | + SND_SOC_DAILINK_REG(pcm), |
|---|
| 142 | 102 | }; |
|---|
| 143 | 103 | |
|---|
| 144 | 104 | static struct snd_soc_card snd_soc_at91sam9g20ek = { |
|---|
| .. | .. |
|---|
| 146 | 106 | .owner = THIS_MODULE, |
|---|
| 147 | 107 | .dai_link = &at91sam9g20ek_dai, |
|---|
| 148 | 108 | .num_links = 1, |
|---|
| 149 | | - .set_bias_level = at91sam9g20ek_set_bias_level, |
|---|
| 150 | 109 | |
|---|
| 151 | 110 | .dapm_widgets = at91sam9g20ek_dapm_widgets, |
|---|
| 152 | 111 | .num_dapm_widgets = ARRAY_SIZE(at91sam9g20ek_dapm_widgets), |
|---|
| .. | .. |
|---|
| 159 | 118 | { |
|---|
| 160 | 119 | struct device_node *np = pdev->dev.of_node; |
|---|
| 161 | 120 | struct device_node *codec_np, *cpu_np; |
|---|
| 162 | | - struct clk *pllb; |
|---|
| 163 | 121 | struct snd_soc_card *card = &snd_soc_at91sam9g20ek; |
|---|
| 164 | 122 | int ret; |
|---|
| 165 | 123 | |
|---|
| .. | .. |
|---|
| 172 | 130 | dev_err(&pdev->dev, "ssc channel is not valid\n"); |
|---|
| 173 | 131 | return -EINVAL; |
|---|
| 174 | 132 | } |
|---|
| 175 | | - |
|---|
| 176 | | - /* |
|---|
| 177 | | - * Codec MCLK is supplied by PCK0 - set it up. |
|---|
| 178 | | - */ |
|---|
| 179 | | - mclk = clk_get(NULL, "pck0"); |
|---|
| 180 | | - if (IS_ERR(mclk)) { |
|---|
| 181 | | - dev_err(&pdev->dev, "Failed to get MCLK\n"); |
|---|
| 182 | | - ret = PTR_ERR(mclk); |
|---|
| 183 | | - goto err; |
|---|
| 184 | | - } |
|---|
| 185 | | - |
|---|
| 186 | | - pllb = clk_get(NULL, "pllb"); |
|---|
| 187 | | - if (IS_ERR(pllb)) { |
|---|
| 188 | | - dev_err(&pdev->dev, "Failed to get PLLB\n"); |
|---|
| 189 | | - ret = PTR_ERR(pllb); |
|---|
| 190 | | - goto err_mclk; |
|---|
| 191 | | - } |
|---|
| 192 | | - ret = clk_set_parent(mclk, pllb); |
|---|
| 193 | | - clk_put(pllb); |
|---|
| 194 | | - if (ret != 0) { |
|---|
| 195 | | - dev_err(&pdev->dev, "Failed to set MCLK parent\n"); |
|---|
| 196 | | - goto err_mclk; |
|---|
| 197 | | - } |
|---|
| 198 | | - |
|---|
| 199 | | - clk_set_rate(mclk, MCLK_RATE); |
|---|
| 200 | 133 | |
|---|
| 201 | 134 | card->dev = &pdev->dev; |
|---|
| 202 | 135 | |
|---|
| .. | .. |
|---|
| 211 | 144 | goto err; |
|---|
| 212 | 145 | |
|---|
| 213 | 146 | /* Parse codec info */ |
|---|
| 214 | | - at91sam9g20ek_dai.codec_name = NULL; |
|---|
| 147 | + at91sam9g20ek_dai.codecs->name = NULL; |
|---|
| 215 | 148 | codec_np = of_parse_phandle(np, "atmel,audio-codec", 0); |
|---|
| 216 | 149 | if (!codec_np) { |
|---|
| 217 | 150 | dev_err(&pdev->dev, "codec info missing\n"); |
|---|
| 218 | 151 | return -EINVAL; |
|---|
| 219 | 152 | } |
|---|
| 220 | | - at91sam9g20ek_dai.codec_of_node = codec_np; |
|---|
| 153 | + at91sam9g20ek_dai.codecs->of_node = codec_np; |
|---|
| 221 | 154 | |
|---|
| 222 | 155 | /* Parse dai and platform info */ |
|---|
| 223 | | - at91sam9g20ek_dai.cpu_dai_name = NULL; |
|---|
| 224 | | - at91sam9g20ek_dai.platform_name = NULL; |
|---|
| 156 | + at91sam9g20ek_dai.cpus->dai_name = NULL; |
|---|
| 157 | + at91sam9g20ek_dai.platforms->name = NULL; |
|---|
| 225 | 158 | cpu_np = of_parse_phandle(np, "atmel,ssc-controller", 0); |
|---|
| 226 | 159 | if (!cpu_np) { |
|---|
| 227 | 160 | dev_err(&pdev->dev, "dai and pcm info missing\n"); |
|---|
| 161 | + of_node_put(codec_np); |
|---|
| 228 | 162 | return -EINVAL; |
|---|
| 229 | 163 | } |
|---|
| 230 | | - at91sam9g20ek_dai.cpu_of_node = cpu_np; |
|---|
| 231 | | - at91sam9g20ek_dai.platform_of_node = cpu_np; |
|---|
| 164 | + at91sam9g20ek_dai.cpus->of_node = cpu_np; |
|---|
| 165 | + at91sam9g20ek_dai.platforms->of_node = cpu_np; |
|---|
| 232 | 166 | |
|---|
| 233 | 167 | of_node_put(codec_np); |
|---|
| 234 | 168 | of_node_put(cpu_np); |
|---|
| .. | .. |
|---|
| 240 | 174 | |
|---|
| 241 | 175 | return ret; |
|---|
| 242 | 176 | |
|---|
| 243 | | -err_mclk: |
|---|
| 244 | | - clk_put(mclk); |
|---|
| 245 | | - mclk = NULL; |
|---|
| 246 | 177 | err: |
|---|
| 247 | 178 | atmel_ssc_put_audio(0); |
|---|
| 248 | 179 | return ret; |
|---|
| .. | .. |
|---|
| 252 | 183 | { |
|---|
| 253 | 184 | struct snd_soc_card *card = platform_get_drvdata(pdev); |
|---|
| 254 | 185 | |
|---|
| 255 | | - clk_disable(mclk); |
|---|
| 256 | | - mclk = NULL; |
|---|
| 257 | 186 | snd_soc_unregister_card(card); |
|---|
| 258 | 187 | atmel_ssc_put_audio(0); |
|---|
| 259 | 188 | |
|---|