| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * sam9x5_wm8731 -- SoC audio for AT91SAM9X5-based boards |
|---|
| 3 | 4 | * that are using WM8731 as codec. |
|---|
| .. | .. |
|---|
| 10 | 11 | * |
|---|
| 11 | 12 | * Based on sam9g20_wm8731.c by: |
|---|
| 12 | 13 | * Sedji Gaouaou <sedji.gaouaou@atmel.com> |
|---|
| 13 | | - * |
|---|
| 14 | | - * This program is free software; you can redistribute it and/or modify it |
|---|
| 15 | | - * under the terms of the GNU General Public License as published by the |
|---|
| 16 | | - * Free Software Foundation; either version 2 of the License, or (at your |
|---|
| 17 | | - * option) any later version. |
|---|
| 18 | | - * |
|---|
| 19 | 14 | */ |
|---|
| 20 | 15 | #include <linux/of.h> |
|---|
| 21 | 16 | #include <linux/export.h> |
|---|
| .. | .. |
|---|
| 45 | 40 | */ |
|---|
| 46 | 41 | static int sam9x5_wm8731_init(struct snd_soc_pcm_runtime *rtd) |
|---|
| 47 | 42 | { |
|---|
| 48 | | - struct snd_soc_dai *codec_dai = rtd->codec_dai; |
|---|
| 43 | + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0); |
|---|
| 49 | 44 | struct device *dev = rtd->dev; |
|---|
| 50 | 45 | int ret; |
|---|
| 51 | 46 | |
|---|
| .. | .. |
|---|
| 82 | 77 | struct snd_soc_card *card; |
|---|
| 83 | 78 | struct snd_soc_dai_link *dai; |
|---|
| 84 | 79 | struct sam9x5_drvdata *priv; |
|---|
| 80 | + struct snd_soc_dai_link_component *comp; |
|---|
| 85 | 81 | int ret; |
|---|
| 86 | 82 | |
|---|
| 87 | 83 | if (!np) { |
|---|
| .. | .. |
|---|
| 92 | 88 | card = devm_kzalloc(&pdev->dev, sizeof(*card), GFP_KERNEL); |
|---|
| 93 | 89 | priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); |
|---|
| 94 | 90 | dai = devm_kzalloc(&pdev->dev, sizeof(*dai), GFP_KERNEL); |
|---|
| 95 | | - if (!dai || !card || !priv) { |
|---|
| 91 | + comp = devm_kzalloc(&pdev->dev, 3 * sizeof(*comp), GFP_KERNEL); |
|---|
| 92 | + if (!dai || !card || !priv || !comp) { |
|---|
| 96 | 93 | ret = -ENOMEM; |
|---|
| 97 | 94 | goto out; |
|---|
| 98 | 95 | } |
|---|
| .. | .. |
|---|
| 105 | 102 | card->num_links = 1; |
|---|
| 106 | 103 | card->dapm_widgets = sam9x5_dapm_widgets; |
|---|
| 107 | 104 | card->num_dapm_widgets = ARRAY_SIZE(sam9x5_dapm_widgets); |
|---|
| 105 | + |
|---|
| 106 | + dai->cpus = &comp[0]; |
|---|
| 107 | + dai->num_cpus = 1; |
|---|
| 108 | + dai->codecs = &comp[1]; |
|---|
| 109 | + dai->num_codecs = 1; |
|---|
| 110 | + dai->platforms = &comp[2]; |
|---|
| 111 | + dai->num_platforms = 1; |
|---|
| 112 | + |
|---|
| 108 | 113 | dai->name = "WM8731"; |
|---|
| 109 | 114 | dai->stream_name = "WM8731 PCM"; |
|---|
| 110 | | - dai->codec_dai_name = "wm8731-hifi"; |
|---|
| 115 | + dai->codecs->dai_name = "wm8731-hifi"; |
|---|
| 111 | 116 | dai->init = sam9x5_wm8731_init; |
|---|
| 112 | 117 | dai->dai_fmt = SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_NB_NF |
|---|
| 113 | 118 | | SND_SOC_DAIFMT_CBM_CFM; |
|---|
| .. | .. |
|---|
| 131 | 136 | goto out; |
|---|
| 132 | 137 | } |
|---|
| 133 | 138 | |
|---|
| 134 | | - dai->codec_of_node = codec_np; |
|---|
| 139 | + dai->codecs->of_node = codec_np; |
|---|
| 135 | 140 | |
|---|
| 136 | 141 | cpu_np = of_parse_phandle(np, "atmel,ssc-controller", 0); |
|---|
| 137 | 142 | if (!cpu_np) { |
|---|
| 138 | 143 | dev_err(&pdev->dev, "atmel,ssc-controller node missing\n"); |
|---|
| 139 | 144 | ret = -EINVAL; |
|---|
| 140 | | - goto out; |
|---|
| 145 | + goto out_put_codec_np; |
|---|
| 141 | 146 | } |
|---|
| 142 | | - dai->cpu_of_node = cpu_np; |
|---|
| 143 | | - dai->platform_of_node = cpu_np; |
|---|
| 147 | + dai->cpus->of_node = cpu_np; |
|---|
| 148 | + dai->platforms->of_node = cpu_np; |
|---|
| 144 | 149 | |
|---|
| 145 | 150 | priv->ssc_id = of_alias_get_id(cpu_np, "ssc"); |
|---|
| 146 | 151 | |
|---|
| .. | .. |
|---|
| 148 | 153 | if (ret != 0) { |
|---|
| 149 | 154 | dev_err(&pdev->dev, "Failed to set SSC %d for audio: %d\n", |
|---|
| 150 | 155 | ret, priv->ssc_id); |
|---|
| 151 | | - goto out; |
|---|
| 156 | + goto out_put_cpu_np; |
|---|
| 152 | 157 | } |
|---|
| 153 | 158 | |
|---|
| 154 | | - of_node_put(codec_np); |
|---|
| 155 | | - of_node_put(cpu_np); |
|---|
| 156 | | - |
|---|
| 157 | | - ret = snd_soc_register_card(card); |
|---|
| 159 | + ret = devm_snd_soc_register_card(&pdev->dev, card); |
|---|
| 158 | 160 | if (ret) { |
|---|
| 159 | 161 | dev_err(&pdev->dev, "Platform device allocation failed\n"); |
|---|
| 160 | 162 | goto out_put_audio; |
|---|
| .. | .. |
|---|
| 162 | 164 | |
|---|
| 163 | 165 | dev_dbg(&pdev->dev, "%s ok\n", __func__); |
|---|
| 164 | 166 | |
|---|
| 165 | | - return ret; |
|---|
| 167 | + goto out_put_cpu_np; |
|---|
| 166 | 168 | |
|---|
| 167 | 169 | out_put_audio: |
|---|
| 168 | 170 | atmel_ssc_put_audio(priv->ssc_id); |
|---|
| 171 | +out_put_cpu_np: |
|---|
| 172 | + of_node_put(cpu_np); |
|---|
| 173 | +out_put_codec_np: |
|---|
| 174 | + of_node_put(codec_np); |
|---|
| 169 | 175 | out: |
|---|
| 170 | 176 | return ret; |
|---|
| 171 | 177 | } |
|---|
| .. | .. |
|---|
| 175 | 181 | struct snd_soc_card *card = platform_get_drvdata(pdev); |
|---|
| 176 | 182 | struct sam9x5_drvdata *priv = card->drvdata; |
|---|
| 177 | 183 | |
|---|
| 178 | | - snd_soc_unregister_card(card); |
|---|
| 179 | 184 | atmel_ssc_put_audio(priv->ssc_id); |
|---|
| 180 | 185 | |
|---|
| 181 | 186 | return 0; |
|---|