Kuninori Morimoto | 9afe58f | 2018-07-02 06:30:58 +0000 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | // |
| 3 | // ASoC simple SCU sound card support |
| 4 | // |
| 5 | // Copyright (C) 2015 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 | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 10 | #include <linux/clk.h> |
| 11 | #include <linux/device.h> |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/of.h> |
| 14 | #include <linux/of_device.h> |
| 15 | #include <linux/platform_device.h> |
| 16 | #include <linux/string.h> |
| 17 | #include <sound/jack.h> |
| 18 | #include <sound/soc.h> |
| 19 | #include <sound/soc-dai.h> |
Kuninori Morimoto | d6a4a9a4 | 2016-06-30 06:03:13 +0000 | [diff] [blame] | 20 | #include <sound/simple_card_utils.h> |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 21 | |
Kuninori Morimoto | 6910e86 | 2016-10-28 03:37:44 +0000 | [diff] [blame] | 22 | struct simple_card_data { |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 23 | struct snd_soc_card snd_card; |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 24 | struct snd_soc_codec_conf codec_conf; |
Kuninori Morimoto | 5ece10a | 2018-08-31 03:08:38 +0000 | [diff] [blame] | 25 | struct simple_dai_props { |
| 26 | struct asoc_simple_dai dai; |
Kuninori Morimoto | 2289cc1 | 2018-08-31 03:08:51 +0000 | [diff] [blame] | 27 | struct snd_soc_dai_link_component codecs; |
Kuninori Morimoto | 24f3bea | 2018-08-31 03:10:46 +0000 | [diff] [blame] | 28 | struct snd_soc_dai_link_component platform; |
Kuninori Morimoto | 5ece10a | 2018-08-31 03:08:38 +0000 | [diff] [blame] | 29 | } *dai_props; |
Kuninori Morimoto | 3433bf0 | 2015-06-15 06:22:30 +0000 | [diff] [blame] | 30 | struct snd_soc_dai_link *dai_link; |
Kuninori Morimoto | cd8957f | 2017-06-15 00:24:28 +0000 | [diff] [blame] | 31 | struct asoc_simple_card_data adata; |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 32 | }; |
| 33 | |
Kuninori Morimoto | d27f3b4 | 2017-03-15 04:44:16 +0000 | [diff] [blame] | 34 | #define simple_priv_to_card(priv) (&(priv)->snd_card) |
Kuninori Morimoto | 53e682b | 2016-08-23 01:34:17 +0000 | [diff] [blame] | 35 | #define simple_priv_to_props(priv, i) ((priv)->dai_props + (i)) |
Kuninori Morimoto | d27f3b4 | 2017-03-15 04:44:16 +0000 | [diff] [blame] | 36 | #define simple_priv_to_dev(priv) (simple_priv_to_card(priv)->dev) |
| 37 | #define simple_priv_to_link(priv, i) (simple_priv_to_card(priv)->dai_link + (i)) |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 38 | |
Kuninori Morimoto | 5bbf3866 | 2016-08-08 06:02:31 +0000 | [diff] [blame] | 39 | #define DAI "sound-dai" |
| 40 | #define CELL "#sound-dai-cells" |
Kuninori Morimoto | 64df0e6 | 2016-08-23 01:34:43 +0000 | [diff] [blame] | 41 | #define PREFIX "simple-audio-card," |
Kuninori Morimoto | 5bbf3866 | 2016-08-08 06:02:31 +0000 | [diff] [blame] | 42 | |
Kuninori Morimoto | 53e682b | 2016-08-23 01:34:17 +0000 | [diff] [blame] | 43 | static int asoc_simple_card_startup(struct snd_pcm_substream *substream) |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 44 | { |
| 45 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Kuninori Morimoto | 6910e86 | 2016-10-28 03:37:44 +0000 | [diff] [blame] | 46 | struct simple_card_data *priv = snd_soc_card_get_drvdata(rtd->card); |
Kuninori Morimoto | 5ece10a | 2018-08-31 03:08:38 +0000 | [diff] [blame] | 47 | struct simple_dai_props *dai_props = |
Kuninori Morimoto | 53e682b | 2016-08-23 01:34:17 +0000 | [diff] [blame] | 48 | simple_priv_to_props(priv, rtd->num); |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 49 | |
Kuninori Morimoto | 5ece10a | 2018-08-31 03:08:38 +0000 | [diff] [blame] | 50 | return asoc_simple_card_clk_enable(&dai_props->dai); |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 51 | } |
| 52 | |
Kuninori Morimoto | 53e682b | 2016-08-23 01:34:17 +0000 | [diff] [blame] | 53 | static void asoc_simple_card_shutdown(struct snd_pcm_substream *substream) |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 54 | { |
| 55 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Kuninori Morimoto | 6910e86 | 2016-10-28 03:37:44 +0000 | [diff] [blame] | 56 | struct simple_card_data *priv = snd_soc_card_get_drvdata(rtd->card); |
Kuninori Morimoto | 5ece10a | 2018-08-31 03:08:38 +0000 | [diff] [blame] | 57 | struct simple_dai_props *dai_props = |
Kuninori Morimoto | 53e682b | 2016-08-23 01:34:17 +0000 | [diff] [blame] | 58 | simple_priv_to_props(priv, rtd->num); |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 59 | |
Kuninori Morimoto | 5ece10a | 2018-08-31 03:08:38 +0000 | [diff] [blame] | 60 | asoc_simple_card_clk_disable(&dai_props->dai); |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 61 | } |
| 62 | |
Julia Lawall | 9b6fdef | 2016-10-15 16:55:49 +0200 | [diff] [blame] | 63 | static const struct snd_soc_ops asoc_simple_card_ops = { |
Kuninori Morimoto | 53e682b | 2016-08-23 01:34:17 +0000 | [diff] [blame] | 64 | .startup = asoc_simple_card_startup, |
| 65 | .shutdown = asoc_simple_card_shutdown, |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 66 | }; |
| 67 | |
Kuninori Morimoto | 53e682b | 2016-08-23 01:34:17 +0000 | [diff] [blame] | 68 | static int asoc_simple_card_dai_init(struct snd_soc_pcm_runtime *rtd) |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 69 | { |
Kuninori Morimoto | 6910e86 | 2016-10-28 03:37:44 +0000 | [diff] [blame] | 70 | struct simple_card_data *priv = snd_soc_card_get_drvdata(rtd->card); |
Kuninori Morimoto | 0470002 | 2015-06-15 06:24:15 +0000 | [diff] [blame] | 71 | struct snd_soc_dai *dai; |
| 72 | struct snd_soc_dai_link *dai_link; |
Kuninori Morimoto | 5ece10a | 2018-08-31 03:08:38 +0000 | [diff] [blame] | 73 | struct simple_dai_props *dai_props; |
Mengdong Lin | 1a49798 | 2015-11-18 02:34:11 -0500 | [diff] [blame] | 74 | int num = rtd->num; |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 75 | |
Kuninori Morimoto | 53e682b | 2016-08-23 01:34:17 +0000 | [diff] [blame] | 76 | dai_link = simple_priv_to_link(priv, num); |
| 77 | dai_props = simple_priv_to_props(priv, num); |
Kuninori Morimoto | 0470002 | 2015-06-15 06:24:15 +0000 | [diff] [blame] | 78 | dai = dai_link->dynamic ? |
| 79 | rtd->cpu_dai : |
| 80 | rtd->codec_dai; |
| 81 | |
Kuninori Morimoto | 5ece10a | 2018-08-31 03:08:38 +0000 | [diff] [blame] | 82 | return asoc_simple_card_init_dai(dai, &dai_props->dai); |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 83 | } |
| 84 | |
Kuninori Morimoto | 53e682b | 2016-08-23 01:34:17 +0000 | [diff] [blame] | 85 | static int asoc_simple_card_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, |
Kuninori Morimoto | af7e2be | 2015-03-26 04:01:46 +0000 | [diff] [blame] | 86 | struct snd_pcm_hw_params *params) |
| 87 | { |
Kuninori Morimoto | 6910e86 | 2016-10-28 03:37:44 +0000 | [diff] [blame] | 88 | struct simple_card_data *priv = snd_soc_card_get_drvdata(rtd->card); |
Kuninori Morimoto | af7e2be | 2015-03-26 04:01:46 +0000 | [diff] [blame] | 89 | |
Kuninori Morimoto | cd8957f | 2017-06-15 00:24:28 +0000 | [diff] [blame] | 90 | asoc_simple_card_convert_fixup(&priv->adata, params); |
Kuninori Morimoto | af7e2be | 2015-03-26 04:01:46 +0000 | [diff] [blame] | 91 | |
| 92 | return 0; |
| 93 | } |
| 94 | |
Kuninori Morimoto | dbd08fe | 2018-12-04 08:20:13 +0000 | [diff] [blame] | 95 | static int asoc_simple_card_dai_link_of(struct device_node *link, |
| 96 | struct device_node *np, |
| 97 | struct device_node *codec, |
Kuninori Morimoto | 6910e86 | 2016-10-28 03:37:44 +0000 | [diff] [blame] | 98 | struct simple_card_data *priv, |
Kuninori Morimoto | dbd08fe | 2018-12-04 08:20:13 +0000 | [diff] [blame] | 99 | int idx, bool is_fe, |
| 100 | bool is_top_level_node) |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 101 | { |
Kuninori Morimoto | 53e682b | 2016-08-23 01:34:17 +0000 | [diff] [blame] | 102 | struct device *dev = simple_priv_to_dev(priv); |
| 103 | struct snd_soc_dai_link *dai_link = simple_priv_to_link(priv, idx); |
Kuninori Morimoto | 5ece10a | 2018-08-31 03:08:38 +0000 | [diff] [blame] | 104 | struct simple_dai_props *dai_props = simple_priv_to_props(priv, idx); |
Kuninori Morimoto | d27f3b4 | 2017-03-15 04:44:16 +0000 | [diff] [blame] | 105 | struct snd_soc_card *card = simple_priv_to_card(priv); |
Kuninori Morimoto | dbd08fe | 2018-12-04 08:20:13 +0000 | [diff] [blame] | 106 | char *prefix = ""; |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 107 | int ret; |
| 108 | |
Kuninori Morimoto | dbd08fe | 2018-12-04 08:20:13 +0000 | [diff] [blame] | 109 | /* For single DAI link & old style of DT node */ |
| 110 | if (is_top_level_node) |
| 111 | prefix = PREFIX; |
| 112 | |
Kuninori Morimoto | 0470002 | 2015-06-15 06:24:15 +0000 | [diff] [blame] | 113 | if (is_fe) { |
Kuninori Morimoto | 27b0108 | 2016-08-10 02:21:03 +0000 | [diff] [blame] | 114 | int is_single_links = 0; |
Kuninori Morimoto | 2289cc1 | 2018-08-31 03:08:51 +0000 | [diff] [blame] | 115 | struct snd_soc_dai_link_component *codecs; |
Kuninori Morimoto | 27b0108 | 2016-08-10 02:21:03 +0000 | [diff] [blame] | 116 | |
Kuninori Morimoto | 0470002 | 2015-06-15 06:24:15 +0000 | [diff] [blame] | 117 | /* BE is dummy */ |
Kuninori Morimoto | 2289cc1 | 2018-08-31 03:08:51 +0000 | [diff] [blame] | 118 | codecs = dai_link->codecs; |
| 119 | codecs->of_node = NULL; |
| 120 | codecs->dai_name = "snd-soc-dummy-dai"; |
| 121 | codecs->name = "snd-soc-dummy"; |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 122 | |
Kuninori Morimoto | 0470002 | 2015-06-15 06:24:15 +0000 | [diff] [blame] | 123 | /* FE settings */ |
| 124 | dai_link->dynamic = 1; |
| 125 | dai_link->dpcm_merged_format = 1; |
Kuninori Morimoto | 5bbf3866 | 2016-08-08 06:02:31 +0000 | [diff] [blame] | 126 | |
| 127 | ret = asoc_simple_card_parse_cpu(np, dai_link, DAI, CELL, |
| 128 | &is_single_links); |
| 129 | if (ret) |
Kuninori Morimoto | 575f1f9 | 2015-12-01 08:33:23 +0000 | [diff] [blame] | 130 | return ret; |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 131 | |
Kuninori Morimoto | 5ece10a | 2018-08-31 03:08:38 +0000 | [diff] [blame] | 132 | ret = asoc_simple_card_parse_clk_cpu(dev, np, dai_link, &dai_props->dai); |
Kuninori Morimoto | c9a235d | 2016-07-19 02:53:32 +0000 | [diff] [blame] | 133 | if (ret < 0) |
| 134 | return ret; |
| 135 | |
Kuninori Morimoto | 8a99a6b | 2016-07-11 23:58:25 +0000 | [diff] [blame] | 136 | ret = asoc_simple_card_set_dailink_name(dev, dai_link, |
| 137 | "fe.%s", |
| 138 | dai_link->cpu_dai_name); |
| 139 | if (ret < 0) |
| 140 | return ret; |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 141 | |
Kuninori Morimoto | 27b0108 | 2016-08-10 02:21:03 +0000 | [diff] [blame] | 142 | asoc_simple_card_canonicalize_cpu(dai_link, is_single_links); |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 143 | } else { |
Kuninori Morimoto | 0470002 | 2015-06-15 06:24:15 +0000 | [diff] [blame] | 144 | /* FE is dummy */ |
| 145 | dai_link->cpu_of_node = NULL; |
| 146 | dai_link->cpu_dai_name = "snd-soc-dummy-dai"; |
| 147 | dai_link->cpu_name = "snd-soc-dummy"; |
| 148 | |
| 149 | /* BE settings */ |
| 150 | dai_link->no_pcm = 1; |
Kuninori Morimoto | 53e682b | 2016-08-23 01:34:17 +0000 | [diff] [blame] | 151 | dai_link->be_hw_params_fixup = asoc_simple_card_be_hw_params_fixup; |
Kuninori Morimoto | 5bbf3866 | 2016-08-08 06:02:31 +0000 | [diff] [blame] | 152 | |
| 153 | ret = asoc_simple_card_parse_codec(np, dai_link, DAI, CELL); |
Kuninori Morimoto | 575f1f9 | 2015-12-01 08:33:23 +0000 | [diff] [blame] | 154 | if (ret < 0) |
| 155 | return ret; |
Kuninori Morimoto | 0470002 | 2015-06-15 06:24:15 +0000 | [diff] [blame] | 156 | |
Kuninori Morimoto | 5ece10a | 2018-08-31 03:08:38 +0000 | [diff] [blame] | 157 | ret = asoc_simple_card_parse_clk_codec(dev, np, dai_link, &dai_props->dai); |
Kuninori Morimoto | c9a235d | 2016-07-19 02:53:32 +0000 | [diff] [blame] | 158 | if (ret < 0) |
| 159 | return ret; |
| 160 | |
Kuninori Morimoto | 8a99a6b | 2016-07-11 23:58:25 +0000 | [diff] [blame] | 161 | ret = asoc_simple_card_set_dailink_name(dev, dai_link, |
| 162 | "be.%s", |
Kuninori Morimoto | 2289cc1 | 2018-08-31 03:08:51 +0000 | [diff] [blame] | 163 | dai_link->codecs->dai_name); |
Kuninori Morimoto | 8a99a6b | 2016-07-11 23:58:25 +0000 | [diff] [blame] | 164 | if (ret < 0) |
| 165 | return ret; |
| 166 | |
Kuninori Morimoto | ca8d95c | 2018-11-22 00:55:40 +0000 | [diff] [blame] | 167 | /* check "prefix" from top node */ |
Kuninori Morimoto | d27f3b4 | 2017-03-15 04:44:16 +0000 | [diff] [blame] | 168 | snd_soc_of_parse_audio_prefix(card, |
Kuninori Morimoto | 64df0e6 | 2016-08-23 01:34:43 +0000 | [diff] [blame] | 169 | &priv->codec_conf, |
Kuninori Morimoto | 2289cc1 | 2018-08-31 03:08:51 +0000 | [diff] [blame] | 170 | dai_link->codecs->of_node, |
Kuninori Morimoto | 64df0e6 | 2016-08-23 01:34:43 +0000 | [diff] [blame] | 171 | PREFIX "prefix"); |
Kuninori Morimoto | ca8d95c | 2018-11-22 00:55:40 +0000 | [diff] [blame] | 172 | /* check "prefix" from each node if top doesn't have */ |
| 173 | if (!priv->codec_conf.of_node) |
| 174 | snd_soc_of_parse_node_prefix(np, |
| 175 | &priv->codec_conf, |
| 176 | dai_link->codecs->of_node, |
| 177 | "prefix"); |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 178 | } |
| 179 | |
Kuninori Morimoto | 5ece10a | 2018-08-31 03:08:38 +0000 | [diff] [blame] | 180 | ret = asoc_simple_card_of_parse_tdm(np, &dai_props->dai); |
Kuninori Morimoto | 9f64542 | 2016-08-25 01:58:55 +0000 | [diff] [blame] | 181 | if (ret) |
| 182 | return ret; |
| 183 | |
Kuninori Morimoto | a09f383 | 2016-08-09 05:50:19 +0000 | [diff] [blame] | 184 | ret = asoc_simple_card_canonicalize_dailink(dai_link); |
| 185 | if (ret < 0) |
| 186 | return ret; |
| 187 | |
Kuninori Morimoto | dbd08fe | 2018-12-04 08:20:13 +0000 | [diff] [blame] | 188 | ret = asoc_simple_card_parse_daifmt(dev, link, codec, |
| 189 | prefix, &dai_link->dai_fmt); |
| 190 | if (ret < 0) |
| 191 | return ret; |
| 192 | |
Kuninori Morimoto | 0470002 | 2015-06-15 06:24:15 +0000 | [diff] [blame] | 193 | dai_link->dpcm_playback = 1; |
| 194 | dai_link->dpcm_capture = 1; |
Kuninori Morimoto | 53e682b | 2016-08-23 01:34:17 +0000 | [diff] [blame] | 195 | dai_link->ops = &asoc_simple_card_ops; |
| 196 | dai_link->init = asoc_simple_card_dai_init; |
Kuninori Morimoto | 0470002 | 2015-06-15 06:24:15 +0000 | [diff] [blame] | 197 | |
Kuninori Morimoto | c9a235d | 2016-07-19 02:53:32 +0000 | [diff] [blame] | 198 | return 0; |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 199 | } |
| 200 | |
Kuninori Morimoto | 0d6b352 | 2017-06-07 00:37:30 +0000 | [diff] [blame] | 201 | static int asoc_simple_card_parse_of(struct simple_card_data *priv) |
Kuninori Morimoto | 15a190ff | 2016-10-28 03:37:26 +0000 | [diff] [blame] | 202 | |
Kuninori Morimoto | af998f8 | 2015-12-17 02:49:43 +0000 | [diff] [blame] | 203 | { |
Kuninori Morimoto | 53e682b | 2016-08-23 01:34:17 +0000 | [diff] [blame] | 204 | struct device *dev = simple_priv_to_dev(priv); |
Kuninori Morimoto | da32d65 | 2018-12-11 03:24:57 +0000 | [diff] [blame] | 205 | struct device_node *top = dev->of_node; |
| 206 | struct device_node *node; |
Kuninori Morimoto | dbd08fe | 2018-12-04 08:20:13 +0000 | [diff] [blame] | 207 | struct device_node *np; |
| 208 | struct device_node *codec; |
| 209 | struct snd_soc_card *card = simple_priv_to_card(priv); |
Kuninori Morimoto | af998f8 | 2015-12-17 02:49:43 +0000 | [diff] [blame] | 210 | bool is_fe; |
Kuninori Morimoto | da32d65 | 2018-12-11 03:24:57 +0000 | [diff] [blame] | 211 | int ret, i, loop; |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 212 | |
Kuninori Morimoto | da32d65 | 2018-12-11 03:24:57 +0000 | [diff] [blame] | 213 | if (!top) |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 214 | return -EINVAL; |
| 215 | |
Daniel Baluta | d0148eb | 2017-08-11 17:12:19 +0300 | [diff] [blame] | 216 | ret = asoc_simple_card_of_parse_widgets(card, PREFIX); |
| 217 | if (ret < 0) |
| 218 | return ret; |
| 219 | |
Kuninori Morimoto | 33404f3 | 2018-11-21 02:11:13 +0000 | [diff] [blame] | 220 | ret = asoc_simple_card_of_parse_routing(card, PREFIX); |
Kuninori Morimoto | 64df0e6 | 2016-08-23 01:34:43 +0000 | [diff] [blame] | 221 | if (ret < 0) |
| 222 | return ret; |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 223 | |
Kuninori Morimoto | da32d65 | 2018-12-11 03:24:57 +0000 | [diff] [blame] | 224 | asoc_simple_card_parse_convert(dev, top, PREFIX, &priv->adata); |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 225 | |
Kuninori Morimoto | da32d65 | 2018-12-11 03:24:57 +0000 | [diff] [blame] | 226 | loop = 1; |
Kuninori Morimoto | dbd08fe | 2018-12-04 08:20:13 +0000 | [diff] [blame] | 227 | i = 0; |
Kuninori Morimoto | da32d65 | 2018-12-11 03:24:57 +0000 | [diff] [blame] | 228 | node = of_get_child_by_name(top, PREFIX "dai-link"); |
| 229 | if (!node) { |
| 230 | node = dev->of_node; |
| 231 | loop = 0; |
Kuninori Morimoto | 15a190ff | 2016-10-28 03:37:26 +0000 | [diff] [blame] | 232 | } |
| 233 | |
Kuninori Morimoto | da32d65 | 2018-12-11 03:24:57 +0000 | [diff] [blame] | 234 | do { |
| 235 | codec = of_get_child_by_name(node, |
| 236 | loop ? "codec" : PREFIX "codec"); |
| 237 | if (!codec) |
| 238 | return -ENODEV; |
| 239 | |
| 240 | for_each_child_of_node(node, np) { |
| 241 | is_fe = (np != codec); |
| 242 | |
| 243 | ret = asoc_simple_card_dai_link_of(node, np, codec, priv, |
| 244 | i, is_fe, !loop); |
| 245 | if (ret < 0) |
| 246 | return ret; |
| 247 | i++; |
| 248 | } |
| 249 | node = of_get_next_child(top, node); |
| 250 | } while (loop && node); |
| 251 | |
Kuninori Morimoto | d27f3b4 | 2017-03-15 04:44:16 +0000 | [diff] [blame] | 252 | ret = asoc_simple_card_parse_card_name(card, PREFIX); |
Kuninori Morimoto | 53ae918 | 2016-07-12 00:00:00 +0000 | [diff] [blame] | 253 | if (ret < 0) |
| 254 | return ret; |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 255 | |
| 256 | return 0; |
| 257 | } |
| 258 | |
Kuninori Morimoto | b8d8f9a | 2018-12-11 03:25:08 +0000 | [diff] [blame^] | 259 | static void asoc_simple_card_get_dais_count(struct device *dev, |
| 260 | int *link_num, |
| 261 | int *dais_num, |
| 262 | int *ccnf_num) |
| 263 | { |
| 264 | struct device_node *top = dev->of_node; |
| 265 | struct device_node *node; |
| 266 | int loop; |
| 267 | int num; |
| 268 | |
| 269 | /* |
| 270 | * link_num : number of links. |
| 271 | * CPU-Codec / CPU-dummy / dummy-Codec |
| 272 | * dais_num : number of DAIs |
| 273 | * ccnf_num : number of codec_conf |
| 274 | * same number for "dummy-Codec" |
| 275 | * |
| 276 | * ex1) |
| 277 | * CPU0 --- Codec0 link : 5 |
| 278 | * CPU1 --- Codec1 dais : 7 |
| 279 | * CPU2 -/ ccnf : 1 |
| 280 | * CPU3 --- Codec2 |
| 281 | * |
| 282 | * => 5 links = 2xCPU-Codec + 2xCPU-dummy + 1xdummy-Codec |
| 283 | * => 7 DAIs = 4xCPU + 3xCodec |
| 284 | * => 1 ccnf = 1xdummy-Codec |
| 285 | * |
| 286 | * ex2) |
| 287 | * CPU0 --- Codec0 link : 5 |
| 288 | * CPU1 --- Codec1 dais : 6 |
| 289 | * CPU2 -/ ccnf : 1 |
| 290 | * CPU3 -/ |
| 291 | * |
| 292 | * => 5 links = 1xCPU-Codec + 3xCPU-dummy + 1xdummy-Codec |
| 293 | * => 6 DAIs = 4xCPU + 2xCodec |
| 294 | * => 1 ccnf = 1xdummy-Codec |
| 295 | * |
| 296 | * ex3) |
| 297 | * CPU0 --- Codec0 link : 6 |
| 298 | * CPU1 -/ dais : 6 |
| 299 | * CPU2 --- Codec1 ccnf : 2 |
| 300 | * CPU3 -/ |
| 301 | * |
| 302 | * => 6 links = 0xCPU-Codec + 4xCPU-dummy + 2xdummy-Codec |
| 303 | * => 6 DAIs = 4xCPU + 2xCodec |
| 304 | * => 2 ccnf = 2xdummy-Codec |
| 305 | */ |
| 306 | if (!top) { |
| 307 | (*link_num) = 1; |
| 308 | (*dais_num) = 2; |
| 309 | (*ccnf_num) = 0; |
| 310 | return; |
| 311 | } |
| 312 | |
| 313 | loop = 1; |
| 314 | node = of_get_child_by_name(top, PREFIX "dai-link"); |
| 315 | if (!node) { |
| 316 | node = top; |
| 317 | loop = 0; |
| 318 | } |
| 319 | |
| 320 | do { |
| 321 | num = of_get_child_count(node); |
| 322 | (*dais_num) += num; |
| 323 | if (num > 2) { |
| 324 | (*link_num) += num; |
| 325 | (*ccnf_num)++; |
| 326 | } else { |
| 327 | (*link_num)++; |
| 328 | } |
| 329 | node = of_get_next_child(top, node); |
| 330 | } while (loop && node); |
| 331 | } |
| 332 | |
Kuninori Morimoto | 53e682b | 2016-08-23 01:34:17 +0000 | [diff] [blame] | 333 | static int asoc_simple_card_probe(struct platform_device *pdev) |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 334 | { |
Kuninori Morimoto | 6910e86 | 2016-10-28 03:37:44 +0000 | [diff] [blame] | 335 | struct simple_card_data *priv; |
Kuninori Morimoto | 1935992 | 2016-10-28 03:38:00 +0000 | [diff] [blame] | 336 | struct snd_soc_dai_link *dai_link; |
Kuninori Morimoto | 5ece10a | 2018-08-31 03:08:38 +0000 | [diff] [blame] | 337 | struct simple_dai_props *dai_props; |
Kuninori Morimoto | d27f3b4 | 2017-03-15 04:44:16 +0000 | [diff] [blame] | 338 | struct snd_soc_card *card; |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 339 | struct device *dev = &pdev->dev; |
Kuninori Morimoto | b8d8f9a | 2018-12-11 03:25:08 +0000 | [diff] [blame^] | 340 | int ret, i; |
| 341 | int lnum = 0, dnum = 0, cnum = 0; |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 342 | |
| 343 | /* Allocate the private data */ |
| 344 | priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); |
| 345 | if (!priv) |
| 346 | return -ENOMEM; |
| 347 | |
Kuninori Morimoto | b8d8f9a | 2018-12-11 03:25:08 +0000 | [diff] [blame^] | 348 | asoc_simple_card_get_dais_count(dev, &lnum, &dnum, &cnum); |
| 349 | if (!lnum || !dnum) |
| 350 | return -EINVAL; |
Kuninori Morimoto | 15a190ff | 2016-10-28 03:37:26 +0000 | [diff] [blame] | 351 | |
Kuninori Morimoto | b8d8f9a | 2018-12-11 03:25:08 +0000 | [diff] [blame^] | 352 | dai_props = devm_kcalloc(dev, lnum, sizeof(*dai_props), GFP_KERNEL); |
| 353 | dai_link = devm_kcalloc(dev, lnum, sizeof(*dai_link), GFP_KERNEL); |
Kuninori Morimoto | 1935992 | 2016-10-28 03:38:00 +0000 | [diff] [blame] | 354 | if (!dai_props || !dai_link) |
Kuninori Morimoto | 15a190ff | 2016-10-28 03:37:26 +0000 | [diff] [blame] | 355 | return -ENOMEM; |
| 356 | |
Kuninori Morimoto | 2289cc1 | 2018-08-31 03:08:51 +0000 | [diff] [blame] | 357 | /* |
| 358 | * Use snd_soc_dai_link_component instead of legacy style |
| 359 | * It is codec only. but cpu/platform will be supported in the future. |
| 360 | * see |
| 361 | * soc-core.c :: snd_soc_init_multicodec() |
| 362 | */ |
Kuninori Morimoto | b8d8f9a | 2018-12-11 03:25:08 +0000 | [diff] [blame^] | 363 | for (i = 0; i < lnum; i++) { |
Kuninori Morimoto | 2289cc1 | 2018-08-31 03:08:51 +0000 | [diff] [blame] | 364 | dai_link[i].codecs = &dai_props[i].codecs; |
| 365 | dai_link[i].num_codecs = 1; |
Kuninori Morimoto | 24f3bea | 2018-08-31 03:10:46 +0000 | [diff] [blame] | 366 | dai_link[i].platform = &dai_props[i].platform; |
Kuninori Morimoto | 2289cc1 | 2018-08-31 03:08:51 +0000 | [diff] [blame] | 367 | } |
| 368 | |
Kuninori Morimoto | 1935992 | 2016-10-28 03:38:00 +0000 | [diff] [blame] | 369 | priv->dai_props = dai_props; |
| 370 | priv->dai_link = dai_link; |
Kuninori Morimoto | 15a190ff | 2016-10-28 03:37:26 +0000 | [diff] [blame] | 371 | |
| 372 | /* Init snd_soc_card */ |
Kuninori Morimoto | d27f3b4 | 2017-03-15 04:44:16 +0000 | [diff] [blame] | 373 | card = simple_priv_to_card(priv); |
| 374 | card->owner = THIS_MODULE; |
| 375 | card->dev = dev; |
| 376 | card->dai_link = priv->dai_link; |
Kuninori Morimoto | b8d8f9a | 2018-12-11 03:25:08 +0000 | [diff] [blame^] | 377 | card->num_links = lnum; |
Kuninori Morimoto | d27f3b4 | 2017-03-15 04:44:16 +0000 | [diff] [blame] | 378 | card->codec_conf = &priv->codec_conf; |
| 379 | card->num_configs = 1; |
Kuninori Morimoto | 15a190ff | 2016-10-28 03:37:26 +0000 | [diff] [blame] | 380 | |
Kuninori Morimoto | 0d6b352 | 2017-06-07 00:37:30 +0000 | [diff] [blame] | 381 | ret = asoc_simple_card_parse_of(priv); |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 382 | if (ret < 0) { |
| 383 | if (ret != -EPROBE_DEFER) |
| 384 | dev_err(dev, "parse error %d\n", ret); |
| 385 | goto err; |
| 386 | } |
| 387 | |
Kuninori Morimoto | d27f3b4 | 2017-03-15 04:44:16 +0000 | [diff] [blame] | 388 | snd_soc_card_set_drvdata(card, priv); |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 389 | |
Kuninori Morimoto | d27f3b4 | 2017-03-15 04:44:16 +0000 | [diff] [blame] | 390 | ret = devm_snd_soc_register_card(dev, card); |
Kuninori Morimoto | c73df77 | 2017-05-19 00:57:44 +0000 | [diff] [blame] | 391 | if (ret < 0) |
| 392 | goto err; |
| 393 | |
| 394 | return 0; |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 395 | err: |
Kuninori Morimoto | d27f3b4 | 2017-03-15 04:44:16 +0000 | [diff] [blame] | 396 | asoc_simple_card_clean_reference(card); |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 397 | |
| 398 | return ret; |
| 399 | } |
| 400 | |
Kuninori Morimoto | 53e682b | 2016-08-23 01:34:17 +0000 | [diff] [blame] | 401 | static int asoc_simple_card_remove(struct platform_device *pdev) |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 402 | { |
| 403 | struct snd_soc_card *card = platform_get_drvdata(pdev); |
| 404 | |
Kuninori Morimoto | 239486b | 2016-08-10 02:22:01 +0000 | [diff] [blame] | 405 | return asoc_simple_card_clean_reference(card); |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 406 | } |
| 407 | |
Kuninori Morimoto | f4d70709 | 2016-08-25 01:58:31 +0000 | [diff] [blame] | 408 | static const struct of_device_id asoc_simple_of_match[] = { |
| 409 | { .compatible = "renesas,rsrc-card", }, |
| 410 | { .compatible = "simple-scu-audio-card", }, |
| 411 | {}, |
| 412 | }; |
| 413 | MODULE_DEVICE_TABLE(of, asoc_simple_of_match); |
| 414 | |
Kuninori Morimoto | 53e682b | 2016-08-23 01:34:17 +0000 | [diff] [blame] | 415 | static struct platform_driver asoc_simple_card = { |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 416 | .driver = { |
Kuninori Morimoto | 64df0e6 | 2016-08-23 01:34:43 +0000 | [diff] [blame] | 417 | .name = "simple-scu-audio-card", |
Kuninori Morimoto | b4e0180 | 2017-08-22 04:56:06 +0000 | [diff] [blame] | 418 | .pm = &snd_soc_pm_ops, |
Kuninori Morimoto | f4d70709 | 2016-08-25 01:58:31 +0000 | [diff] [blame] | 419 | .of_match_table = asoc_simple_of_match, |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 420 | }, |
Kuninori Morimoto | 53e682b | 2016-08-23 01:34:17 +0000 | [diff] [blame] | 421 | .probe = asoc_simple_card_probe, |
| 422 | .remove = asoc_simple_card_remove, |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 423 | }; |
| 424 | |
Kuninori Morimoto | 53e682b | 2016-08-23 01:34:17 +0000 | [diff] [blame] | 425 | module_platform_driver(asoc_simple_card); |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 426 | |
Kuninori Morimoto | 53e682b | 2016-08-23 01:34:17 +0000 | [diff] [blame] | 427 | MODULE_ALIAS("platform:asoc-simple-scu-card"); |
Kuninori Morimoto | 93bc047 | 2016-08-25 01:56:38 +0000 | [diff] [blame] | 428 | MODULE_LICENSE("GPL v2"); |
Kuninori Morimoto | 53e682b | 2016-08-23 01:34:17 +0000 | [diff] [blame] | 429 | MODULE_DESCRIPTION("ASoC Simple SCU Sound Card"); |
Kuninori Morimoto | 415f1cb | 2015-03-26 04:01:27 +0000 | [diff] [blame] | 430 | MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>"); |