Kuninori Morimoto | decd896 | 2018-07-02 06:31:16 +0000 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | // |
| 3 | // ASoC audio graph sound card support |
| 4 | // |
| 5 | // Copyright (C) 2016 Renesas Solutions Corp. |
| 6 | // Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> |
| 7 | // |
| 8 | // based on ${LINUX}/sound/soc/generic/simple-card.c |
| 9 | |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 10 | #include <linux/clk.h> |
| 11 | #include <linux/device.h> |
| 12 | #include <linux/gpio.h> |
Shawn Guo | f986907 | 2017-06-29 21:26:38 +0800 | [diff] [blame] | 13 | #include <linux/gpio/consumer.h> |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 14 | #include <linux/module.h> |
| 15 | #include <linux/of.h> |
| 16 | #include <linux/of_device.h> |
| 17 | #include <linux/of_gpio.h> |
| 18 | #include <linux/of_graph.h> |
| 19 | #include <linux/platform_device.h> |
| 20 | #include <linux/string.h> |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 21 | #include <sound/simple_card_utils.h> |
| 22 | |
| 23 | struct graph_card_data { |
| 24 | struct snd_soc_card snd_card; |
| 25 | struct graph_dai_props { |
Kuninori Morimoto | 0e3460b | 2018-11-30 02:07:48 +0000 | [diff] [blame^] | 26 | struct asoc_simple_dai *cpu_dai; |
| 27 | struct asoc_simple_dai *codec_dai; |
Kuninori Morimoto | 8e6746d | 2018-08-31 03:09:05 +0000 | [diff] [blame] | 28 | struct snd_soc_dai_link_component codecs; /* single codec */ |
Kuninori Morimoto | 46c73187 | 2018-08-31 03:10:58 +0000 | [diff] [blame] | 29 | struct snd_soc_dai_link_component platform; |
Olivier Moysan | 757652d | 2017-11-09 15:07:58 +0100 | [diff] [blame] | 30 | unsigned int mclk_fs; |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 31 | } *dai_props; |
Olivier Moysan | 757652d | 2017-11-09 15:07:58 +0100 | [diff] [blame] | 32 | unsigned int mclk_fs; |
Katsuhiro Suzuki | f6de35c | 2018-06-11 17:32:14 +0900 | [diff] [blame] | 33 | struct asoc_simple_jack hp_jack; |
| 34 | struct asoc_simple_jack mic_jack; |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 35 | struct snd_soc_dai_link *dai_link; |
Kuninori Morimoto | 0e3460b | 2018-11-30 02:07:48 +0000 | [diff] [blame^] | 36 | struct asoc_simple_dai *dais; |
Shawn Guo | f986907 | 2017-06-29 21:26:38 +0800 | [diff] [blame] | 37 | struct gpio_desc *pa_gpio; |
| 38 | }; |
| 39 | |
Kuninori Morimoto | 64ef081 | 2018-11-22 00:57:40 +0000 | [diff] [blame] | 40 | #define graph_priv_to_card(priv) (&(priv)->snd_card) |
| 41 | #define graph_priv_to_props(priv, i) ((priv)->dai_props + (i)) |
| 42 | #define graph_priv_to_dev(priv) (graph_priv_to_card(priv)->dev) |
| 43 | #define graph_priv_to_link(priv, i) (graph_priv_to_card(priv)->dai_link + (i)) |
| 44 | |
Shawn Guo | f986907 | 2017-06-29 21:26:38 +0800 | [diff] [blame] | 45 | static int asoc_graph_card_outdrv_event(struct snd_soc_dapm_widget *w, |
| 46 | struct snd_kcontrol *kcontrol, |
| 47 | int event) |
| 48 | { |
| 49 | struct snd_soc_dapm_context *dapm = w->dapm; |
| 50 | struct graph_card_data *priv = snd_soc_card_get_drvdata(dapm->card); |
| 51 | |
| 52 | switch (event) { |
| 53 | case SND_SOC_DAPM_POST_PMU: |
| 54 | gpiod_set_value_cansleep(priv->pa_gpio, 1); |
| 55 | break; |
| 56 | case SND_SOC_DAPM_PRE_PMD: |
| 57 | gpiod_set_value_cansleep(priv->pa_gpio, 0); |
| 58 | break; |
| 59 | default: |
| 60 | return -EINVAL; |
| 61 | } |
| 62 | |
| 63 | return 0; |
| 64 | } |
| 65 | |
| 66 | static const struct snd_soc_dapm_widget asoc_graph_card_dapm_widgets[] = { |
| 67 | SND_SOC_DAPM_OUT_DRV_E("Amplifier", SND_SOC_NOPM, |
| 68 | 0, 0, NULL, 0, asoc_graph_card_outdrv_event, |
| 69 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 70 | }; |
| 71 | |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 72 | static int asoc_graph_card_startup(struct snd_pcm_substream *substream) |
| 73 | { |
| 74 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 75 | struct graph_card_data *priv = snd_soc_card_get_drvdata(rtd->card); |
| 76 | struct graph_dai_props *dai_props = graph_priv_to_props(priv, rtd->num); |
| 77 | int ret; |
| 78 | |
Kuninori Morimoto | 0e3460b | 2018-11-30 02:07:48 +0000 | [diff] [blame^] | 79 | ret = asoc_simple_card_clk_enable(dai_props->cpu_dai); |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 80 | if (ret) |
| 81 | return ret; |
| 82 | |
Kuninori Morimoto | 0e3460b | 2018-11-30 02:07:48 +0000 | [diff] [blame^] | 83 | ret = asoc_simple_card_clk_enable(dai_props->codec_dai); |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 84 | if (ret) |
Kuninori Morimoto | 0e3460b | 2018-11-30 02:07:48 +0000 | [diff] [blame^] | 85 | asoc_simple_card_clk_disable(dai_props->cpu_dai); |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 86 | |
| 87 | return ret; |
| 88 | } |
| 89 | |
| 90 | static void asoc_graph_card_shutdown(struct snd_pcm_substream *substream) |
| 91 | { |
| 92 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 93 | struct graph_card_data *priv = snd_soc_card_get_drvdata(rtd->card); |
| 94 | struct graph_dai_props *dai_props = graph_priv_to_props(priv, rtd->num); |
| 95 | |
Kuninori Morimoto | 0e3460b | 2018-11-30 02:07:48 +0000 | [diff] [blame^] | 96 | asoc_simple_card_clk_disable(dai_props->cpu_dai); |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 97 | |
Kuninori Morimoto | 0e3460b | 2018-11-30 02:07:48 +0000 | [diff] [blame^] | 98 | asoc_simple_card_clk_disable(dai_props->codec_dai); |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 99 | } |
| 100 | |
Olivier Moysan | 757652d | 2017-11-09 15:07:58 +0100 | [diff] [blame] | 101 | static int asoc_graph_card_hw_params(struct snd_pcm_substream *substream, |
| 102 | struct snd_pcm_hw_params *params) |
| 103 | { |
| 104 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 105 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 106 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
| 107 | struct graph_card_data *priv = snd_soc_card_get_drvdata(rtd->card); |
| 108 | struct graph_dai_props *dai_props = graph_priv_to_props(priv, rtd->num); |
| 109 | unsigned int mclk, mclk_fs = 0; |
| 110 | int ret = 0; |
| 111 | |
| 112 | if (priv->mclk_fs) |
| 113 | mclk_fs = priv->mclk_fs; |
| 114 | else if (dai_props->mclk_fs) |
| 115 | mclk_fs = dai_props->mclk_fs; |
| 116 | |
| 117 | if (mclk_fs) { |
| 118 | mclk = params_rate(params) * mclk_fs; |
| 119 | ret = snd_soc_dai_set_sysclk(codec_dai, 0, mclk, |
| 120 | SND_SOC_CLOCK_IN); |
| 121 | if (ret && ret != -ENOTSUPP) |
| 122 | goto err; |
| 123 | |
| 124 | ret = snd_soc_dai_set_sysclk(cpu_dai, 0, mclk, |
| 125 | SND_SOC_CLOCK_OUT); |
| 126 | if (ret && ret != -ENOTSUPP) |
| 127 | goto err; |
| 128 | } |
| 129 | return 0; |
| 130 | err: |
| 131 | return ret; |
| 132 | } |
| 133 | |
Bhumika Goyal | e23d834 | 2017-08-16 22:29:26 +0530 | [diff] [blame] | 134 | static const struct snd_soc_ops asoc_graph_card_ops = { |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 135 | .startup = asoc_graph_card_startup, |
| 136 | .shutdown = asoc_graph_card_shutdown, |
Olivier Moysan | 757652d | 2017-11-09 15:07:58 +0100 | [diff] [blame] | 137 | .hw_params = asoc_graph_card_hw_params, |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 138 | }; |
| 139 | |
| 140 | static int asoc_graph_card_dai_init(struct snd_soc_pcm_runtime *rtd) |
| 141 | { |
| 142 | struct graph_card_data *priv = snd_soc_card_get_drvdata(rtd->card); |
Kuninori Morimoto | 0e3460b | 2018-11-30 02:07:48 +0000 | [diff] [blame^] | 143 | struct graph_dai_props *dai_props = graph_priv_to_props(priv, rtd->num); |
| 144 | int ret = 0; |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 145 | |
Kuninori Morimoto | 0e3460b | 2018-11-30 02:07:48 +0000 | [diff] [blame^] | 146 | ret = asoc_simple_card_init_dai(rtd->codec_dai, |
| 147 | dai_props->codec_dai); |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 148 | if (ret < 0) |
| 149 | return ret; |
| 150 | |
Kuninori Morimoto | 0e3460b | 2018-11-30 02:07:48 +0000 | [diff] [blame^] | 151 | ret = asoc_simple_card_init_dai(rtd->cpu_dai, |
| 152 | dai_props->cpu_dai); |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 153 | if (ret < 0) |
| 154 | return ret; |
| 155 | |
| 156 | return 0; |
| 157 | } |
| 158 | |
| 159 | static int asoc_graph_card_dai_link_of(struct device_node *cpu_port, |
| 160 | struct graph_card_data *priv, |
Kuninori Morimoto | 0e3460b | 2018-11-30 02:07:48 +0000 | [diff] [blame^] | 161 | int *dai_idx, int link_idx) |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 162 | { |
| 163 | struct device *dev = graph_priv_to_dev(priv); |
Kuninori Morimoto | 0e3460b | 2018-11-30 02:07:48 +0000 | [diff] [blame^] | 164 | struct snd_soc_dai_link *dai_link = graph_priv_to_link(priv, link_idx); |
| 165 | struct graph_dai_props *dai_props = graph_priv_to_props(priv, link_idx); |
| 166 | struct asoc_simple_dai *cpu_dai; |
| 167 | struct asoc_simple_dai *codec_dai; |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 168 | struct device_node *cpu_ep = of_get_next_child(cpu_port, NULL); |
| 169 | struct device_node *codec_ep = of_graph_get_remote_endpoint(cpu_ep); |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 170 | int ret; |
| 171 | |
Kuninori Morimoto | 0e3460b | 2018-11-30 02:07:48 +0000 | [diff] [blame^] | 172 | cpu_dai = |
| 173 | dai_props->cpu_dai = &priv->dais[(*dai_idx)++]; |
| 174 | codec_dai = |
| 175 | dai_props->codec_dai = &priv->dais[(*dai_idx)++]; |
| 176 | |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 177 | ret = asoc_simple_card_parse_daifmt(dev, cpu_ep, codec_ep, |
| 178 | NULL, &dai_link->dai_fmt); |
| 179 | if (ret < 0) |
| 180 | goto dai_link_of_err; |
| 181 | |
Kuninori Morimoto | 8036dbc | 2018-10-10 02:22:29 +0000 | [diff] [blame] | 182 | of_property_read_u32(cpu_ep, "mclk-fs", &dai_props->mclk_fs); |
| 183 | of_property_read_u32(codec_ep, "mclk-fs", &dai_props->mclk_fs); |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 184 | |
| 185 | ret = asoc_simple_card_parse_graph_cpu(cpu_ep, dai_link); |
| 186 | if (ret < 0) |
| 187 | goto dai_link_of_err; |
| 188 | |
| 189 | ret = asoc_simple_card_parse_graph_codec(codec_ep, dai_link); |
| 190 | if (ret < 0) |
| 191 | goto dai_link_of_err; |
| 192 | |
Kuninori Morimoto | c98907d | 2017-06-14 00:35:30 +0000 | [diff] [blame] | 193 | ret = asoc_simple_card_of_parse_tdm(cpu_ep, cpu_dai); |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 194 | if (ret < 0) |
| 195 | goto dai_link_of_err; |
| 196 | |
Kuninori Morimoto | c98907d | 2017-06-14 00:35:30 +0000 | [diff] [blame] | 197 | ret = asoc_simple_card_of_parse_tdm(codec_ep, codec_dai); |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 198 | if (ret < 0) |
| 199 | goto dai_link_of_err; |
| 200 | |
| 201 | ret = asoc_simple_card_parse_clk_cpu(dev, cpu_ep, dai_link, cpu_dai); |
| 202 | if (ret < 0) |
| 203 | goto dai_link_of_err; |
| 204 | |
| 205 | ret = asoc_simple_card_parse_clk_codec(dev, codec_ep, dai_link, codec_dai); |
| 206 | if (ret < 0) |
| 207 | goto dai_link_of_err; |
| 208 | |
| 209 | ret = asoc_simple_card_canonicalize_dailink(dai_link); |
| 210 | if (ret < 0) |
| 211 | goto dai_link_of_err; |
| 212 | |
| 213 | ret = asoc_simple_card_set_dailink_name(dev, dai_link, |
| 214 | "%s-%s", |
| 215 | dai_link->cpu_dai_name, |
Kuninori Morimoto | 8e6746d | 2018-08-31 03:09:05 +0000 | [diff] [blame] | 216 | dai_link->codecs->dai_name); |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 217 | if (ret < 0) |
| 218 | goto dai_link_of_err; |
| 219 | |
| 220 | dai_link->ops = &asoc_graph_card_ops; |
| 221 | dai_link->init = asoc_graph_card_dai_init; |
| 222 | |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 223 | asoc_simple_card_canonicalize_cpu(dai_link, |
Kuninori Morimoto | 47ca959 | 2017-06-22 06:21:49 +0000 | [diff] [blame] | 224 | of_graph_get_endpoint_count(dai_link->cpu_of_node) == 1); |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 225 | |
| 226 | dai_link_of_err: |
| 227 | of_node_put(cpu_ep); |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 228 | of_node_put(codec_ep); |
| 229 | |
| 230 | return ret; |
| 231 | } |
| 232 | |
| 233 | static int asoc_graph_card_parse_of(struct graph_card_data *priv) |
| 234 | { |
| 235 | struct of_phandle_iterator it; |
| 236 | struct device *dev = graph_priv_to_dev(priv); |
| 237 | struct snd_soc_card *card = graph_priv_to_card(priv); |
| 238 | struct device_node *node = dev->of_node; |
Kuninori Morimoto | 0e3460b | 2018-11-30 02:07:48 +0000 | [diff] [blame^] | 239 | int rc, ret; |
| 240 | int link_idx, dai_idx; |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 241 | |
Shawn Guo | f986907 | 2017-06-29 21:26:38 +0800 | [diff] [blame] | 242 | ret = asoc_simple_card_of_parse_widgets(card, NULL); |
| 243 | if (ret < 0) |
| 244 | return ret; |
| 245 | |
Kuninori Morimoto | 33404f3 | 2018-11-21 02:11:13 +0000 | [diff] [blame] | 246 | ret = asoc_simple_card_of_parse_routing(card, NULL); |
Shawn Guo | f986907 | 2017-06-29 21:26:38 +0800 | [diff] [blame] | 247 | if (ret < 0) |
| 248 | return ret; |
| 249 | |
Olivier Moysan | 757652d | 2017-11-09 15:07:58 +0100 | [diff] [blame] | 250 | /* Factor to mclk, used in hw_params() */ |
| 251 | of_property_read_u32(node, "mclk-fs", &priv->mclk_fs); |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 252 | |
Kuninori Morimoto | 0e3460b | 2018-11-30 02:07:48 +0000 | [diff] [blame^] | 253 | link_idx = 0; |
| 254 | dai_idx = 0; |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 255 | of_for_each_phandle(&it, rc, node, "dais", NULL, 0) { |
Kuninori Morimoto | 0e3460b | 2018-11-30 02:07:48 +0000 | [diff] [blame^] | 256 | ret = asoc_graph_card_dai_link_of(it.node, priv, |
| 257 | &dai_idx, link_idx++); |
Tony Lindgren | c0a480d | 2017-07-28 01:23:15 -0700 | [diff] [blame] | 258 | if (ret < 0) { |
| 259 | of_node_put(it.node); |
| 260 | |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 261 | return ret; |
Tony Lindgren | c0a480d | 2017-07-28 01:23:15 -0700 | [diff] [blame] | 262 | } |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | return asoc_simple_card_parse_card_name(card, NULL); |
| 266 | } |
| 267 | |
| 268 | static int asoc_graph_get_dais_count(struct device *dev) |
| 269 | { |
| 270 | struct of_phandle_iterator it; |
| 271 | struct device_node *node = dev->of_node; |
| 272 | int count = 0; |
| 273 | int rc; |
| 274 | |
Tony Lindgren | c0a480d | 2017-07-28 01:23:15 -0700 | [diff] [blame] | 275 | of_for_each_phandle(&it, rc, node, "dais", NULL, 0) |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 276 | count++; |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 277 | |
| 278 | return count; |
| 279 | } |
| 280 | |
Katsuhiro Suzuki | f6de35c | 2018-06-11 17:32:14 +0900 | [diff] [blame] | 281 | static int asoc_graph_soc_card_probe(struct snd_soc_card *card) |
| 282 | { |
| 283 | struct graph_card_data *priv = snd_soc_card_get_drvdata(card); |
| 284 | int ret; |
| 285 | |
| 286 | ret = asoc_simple_card_init_hp(card, &priv->hp_jack, NULL); |
| 287 | if (ret < 0) |
| 288 | return ret; |
| 289 | |
| 290 | ret = asoc_simple_card_init_mic(card, &priv->mic_jack, NULL); |
| 291 | if (ret < 0) |
| 292 | return ret; |
| 293 | |
| 294 | return 0; |
| 295 | } |
| 296 | |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 297 | static int asoc_graph_card_probe(struct platform_device *pdev) |
| 298 | { |
| 299 | struct graph_card_data *priv; |
| 300 | struct snd_soc_dai_link *dai_link; |
| 301 | struct graph_dai_props *dai_props; |
Kuninori Morimoto | 0e3460b | 2018-11-30 02:07:48 +0000 | [diff] [blame^] | 302 | struct asoc_simple_dai *dais; |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 303 | struct device *dev = &pdev->dev; |
| 304 | struct snd_soc_card *card; |
Kuninori Morimoto | 8e6746d | 2018-08-31 03:09:05 +0000 | [diff] [blame] | 305 | int num, ret, i; |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 306 | |
| 307 | /* Allocate the private data and the DAI link array */ |
| 308 | priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); |
| 309 | if (!priv) |
| 310 | return -ENOMEM; |
| 311 | |
| 312 | num = asoc_graph_get_dais_count(dev); |
| 313 | if (num == 0) |
| 314 | return -EINVAL; |
| 315 | |
Kees Cook | a86854d | 2018-06-12 14:07:58 -0700 | [diff] [blame] | 316 | dai_props = devm_kcalloc(dev, num, sizeof(*dai_props), GFP_KERNEL); |
| 317 | dai_link = devm_kcalloc(dev, num, sizeof(*dai_link), GFP_KERNEL); |
Kuninori Morimoto | 0e3460b | 2018-11-30 02:07:48 +0000 | [diff] [blame^] | 318 | dais = devm_kcalloc(dev, num * 2, sizeof(*dais), GFP_KERNEL); |
| 319 | if (!dai_props || !dai_link || !dais) |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 320 | return -ENOMEM; |
| 321 | |
Kuninori Morimoto | 8e6746d | 2018-08-31 03:09:05 +0000 | [diff] [blame] | 322 | /* |
| 323 | * Use snd_soc_dai_link_component instead of legacy style |
| 324 | * It is codec only. but cpu/platform will be supported in the future. |
| 325 | * see |
| 326 | * soc-core.c :: snd_soc_init_multicodec() |
| 327 | */ |
| 328 | for (i = 0; i < num; i++) { |
| 329 | dai_link[i].codecs = &dai_props[i].codecs; |
| 330 | dai_link[i].num_codecs = 1; |
Kuninori Morimoto | 46c73187 | 2018-08-31 03:10:58 +0000 | [diff] [blame] | 331 | dai_link[i].platform = &dai_props[i].platform; |
Kuninori Morimoto | 8e6746d | 2018-08-31 03:09:05 +0000 | [diff] [blame] | 332 | } |
| 333 | |
Shawn Guo | f986907 | 2017-06-29 21:26:38 +0800 | [diff] [blame] | 334 | priv->pa_gpio = devm_gpiod_get_optional(dev, "pa", GPIOD_OUT_LOW); |
| 335 | if (IS_ERR(priv->pa_gpio)) { |
| 336 | ret = PTR_ERR(priv->pa_gpio); |
| 337 | dev_err(dev, "failed to get amplifier gpio: %d\n", ret); |
| 338 | return ret; |
| 339 | } |
| 340 | |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 341 | priv->dai_props = dai_props; |
| 342 | priv->dai_link = dai_link; |
Kuninori Morimoto | 0e3460b | 2018-11-30 02:07:48 +0000 | [diff] [blame^] | 343 | priv->dais = dais; |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 344 | |
| 345 | /* Init snd_soc_card */ |
| 346 | card = graph_priv_to_card(priv); |
| 347 | card->owner = THIS_MODULE; |
| 348 | card->dev = dev; |
| 349 | card->dai_link = dai_link; |
| 350 | card->num_links = num; |
Shawn Guo | f986907 | 2017-06-29 21:26:38 +0800 | [diff] [blame] | 351 | card->dapm_widgets = asoc_graph_card_dapm_widgets; |
| 352 | card->num_dapm_widgets = ARRAY_SIZE(asoc_graph_card_dapm_widgets); |
Katsuhiro Suzuki | f6de35c | 2018-06-11 17:32:14 +0900 | [diff] [blame] | 353 | card->probe = asoc_graph_soc_card_probe; |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 354 | |
| 355 | ret = asoc_graph_card_parse_of(priv); |
| 356 | if (ret < 0) { |
| 357 | if (ret != -EPROBE_DEFER) |
| 358 | dev_err(dev, "parse error %d\n", ret); |
| 359 | goto err; |
| 360 | } |
| 361 | |
| 362 | snd_soc_card_set_drvdata(card, priv); |
| 363 | |
| 364 | ret = devm_snd_soc_register_card(dev, card); |
Kuninori Morimoto | ecea931 | 2017-05-19 00:58:00 +0000 | [diff] [blame] | 365 | if (ret < 0) |
| 366 | goto err; |
| 367 | |
| 368 | return 0; |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 369 | err: |
| 370 | asoc_simple_card_clean_reference(card); |
| 371 | |
| 372 | return ret; |
| 373 | } |
| 374 | |
| 375 | static int asoc_graph_card_remove(struct platform_device *pdev) |
| 376 | { |
| 377 | struct snd_soc_card *card = platform_get_drvdata(pdev); |
| 378 | |
| 379 | return asoc_simple_card_clean_reference(card); |
| 380 | } |
| 381 | |
| 382 | static const struct of_device_id asoc_graph_of_match[] = { |
| 383 | { .compatible = "audio-graph-card", }, |
| 384 | {}, |
| 385 | }; |
| 386 | MODULE_DEVICE_TABLE(of, asoc_graph_of_match); |
| 387 | |
| 388 | static struct platform_driver asoc_graph_card = { |
| 389 | .driver = { |
| 390 | .name = "asoc-audio-graph-card", |
Kuninori Morimoto | 7b828a3 | 2017-08-22 04:56:44 +0000 | [diff] [blame] | 391 | .pm = &snd_soc_pm_ops, |
Kuninori Morimoto | 2692c1c | 2017-04-20 01:36:08 +0000 | [diff] [blame] | 392 | .of_match_table = asoc_graph_of_match, |
| 393 | }, |
| 394 | .probe = asoc_graph_card_probe, |
| 395 | .remove = asoc_graph_card_remove, |
| 396 | }; |
| 397 | module_platform_driver(asoc_graph_card); |
| 398 | |
| 399 | MODULE_ALIAS("platform:asoc-audio-graph-card"); |
| 400 | MODULE_LICENSE("GPL v2"); |
| 401 | MODULE_DESCRIPTION("ASoC Audio Graph Sound Card"); |
| 402 | MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>"); |