Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 1 | /* |
| 2 | * ASoC simple sound card support |
| 3 | * |
| 4 | * Copyright (C) 2012 Renesas Solutions Corp. |
| 5 | * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | */ |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 11 | #include <linux/clk.h> |
Xiubo Li | 6ff62ee | 2014-02-14 09:34:36 +0800 | [diff] [blame] | 12 | #include <linux/device.h> |
Dylan Reid | 3fe2403 | 2014-10-01 14:25:20 -0700 | [diff] [blame] | 13 | #include <linux/gpio.h> |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 14 | #include <linux/module.h> |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 15 | #include <linux/of.h> |
Dylan Reid | 3fe2403 | 2014-10-01 14:25:20 -0700 | [diff] [blame] | 16 | #include <linux/of_gpio.h> |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 17 | #include <linux/platform_device.h> |
Xiubo Li | ca919fe | 2014-01-14 12:35:32 +0800 | [diff] [blame] | 18 | #include <linux/string.h> |
Dylan Reid | 3fe2403 | 2014-10-01 14:25:20 -0700 | [diff] [blame] | 19 | #include <sound/jack.h> |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 20 | #include <sound/simple_card.h> |
Xiubo Li | 6ff62ee | 2014-02-14 09:34:36 +0800 | [diff] [blame] | 21 | #include <sound/soc-dai.h> |
| 22 | #include <sound/soc.h> |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 23 | |
Kuninori Morimoto | 9eac361 | 2016-05-31 08:59:46 +0000 | [diff] [blame] | 24 | struct asoc_simple_jack { |
| 25 | struct snd_soc_jack jack; |
| 26 | struct snd_soc_jack_pin pin; |
| 27 | struct snd_soc_jack_gpio gpio; |
| 28 | }; |
| 29 | |
Jean-Francois Moine | 45fce59 | 2014-01-15 16:51:56 +0100 | [diff] [blame] | 30 | struct simple_card_data { |
| 31 | struct snd_soc_card snd_card; |
Jean-Francois Moine | cf7dc23 | 2014-03-20 10:52:41 +0100 | [diff] [blame] | 32 | struct simple_dai_props { |
| 33 | struct asoc_simple_dai cpu_dai; |
| 34 | struct asoc_simple_dai codec_dai; |
Arnaud Pouliquen | 85a4bfd | 2015-06-05 10:19:05 +0200 | [diff] [blame] | 35 | unsigned int mclk_fs; |
Jean-Francois Moine | cf7dc23 | 2014-03-20 10:52:41 +0100 | [diff] [blame] | 36 | } *dai_props; |
Andrew Lunn | 2942a0e | 2014-05-22 17:31:49 +0200 | [diff] [blame] | 37 | unsigned int mclk_fs; |
Kuninori Morimoto | 9eac361 | 2016-05-31 08:59:46 +0000 | [diff] [blame] | 38 | struct asoc_simple_jack hp_jack; |
| 39 | struct asoc_simple_jack mic_jack; |
Jean-Francois Moine | cf7dc23 | 2014-03-20 10:52:41 +0100 | [diff] [blame] | 40 | struct snd_soc_dai_link dai_link[]; /* dynamically allocated */ |
Jean-Francois Moine | 45fce59 | 2014-01-15 16:51:56 +0100 | [diff] [blame] | 41 | }; |
| 42 | |
Kuninori Morimoto | f531913f | 2014-09-09 21:37:57 -0700 | [diff] [blame] | 43 | #define simple_priv_to_dev(priv) ((priv)->snd_card.dev) |
Kuninori Morimoto | 9810f53 | 2014-09-09 21:38:24 -0700 | [diff] [blame] | 44 | #define simple_priv_to_link(priv, i) ((priv)->snd_card.dai_link + i) |
| 45 | #define simple_priv_to_props(priv, i) ((priv)->dai_props + i) |
Kuninori Morimoto | f531913f | 2014-09-09 21:37:57 -0700 | [diff] [blame] | 46 | |
Kuninori Morimoto | 44c16af | 2016-08-08 06:02:07 +0000 | [diff] [blame^] | 47 | #define DAI "sound-dai" |
| 48 | #define CELL "#sound-dai-cells" |
Kuninori Morimoto | 548563f | 2016-05-31 08:59:01 +0000 | [diff] [blame] | 49 | #define PREFIX "simple-audio-card," |
| 50 | |
Kuninori Morimoto | 9eac361 | 2016-05-31 08:59:46 +0000 | [diff] [blame] | 51 | #define asoc_simple_card_init_hp(card, sjack, prefix)\ |
| 52 | asoc_simple_card_init_jack(card, sjack, 1, prefix) |
| 53 | #define asoc_simple_card_init_mic(card, sjack, prefix)\ |
| 54 | asoc_simple_card_init_jack(card, sjack, 0, prefix) |
| 55 | static int asoc_simple_card_init_jack(struct snd_soc_card *card, |
| 56 | struct asoc_simple_jack *sjack, |
| 57 | int is_hp, char *prefix) |
| 58 | { |
| 59 | struct device *dev = card->dev; |
| 60 | enum of_gpio_flags flags; |
| 61 | char prop[128]; |
| 62 | char *pin_name; |
| 63 | char *gpio_name; |
| 64 | int mask; |
| 65 | int det; |
| 66 | |
| 67 | sjack->gpio.gpio = -ENOENT; |
| 68 | |
| 69 | if (is_hp) { |
| 70 | snprintf(prop, sizeof(prop), "%shp-det-gpio", prefix); |
| 71 | pin_name = "Headphones"; |
| 72 | gpio_name = "Headphone detection"; |
| 73 | mask = SND_JACK_HEADPHONE; |
| 74 | } else { |
| 75 | snprintf(prop, sizeof(prop), "%smic-det-gpio", prefix); |
| 76 | pin_name = "Mic Jack"; |
| 77 | gpio_name = "Mic detection"; |
| 78 | mask = SND_JACK_MICROPHONE; |
| 79 | } |
| 80 | |
| 81 | det = of_get_named_gpio_flags(dev->of_node, prop, 0, &flags); |
| 82 | if (det == -EPROBE_DEFER) |
| 83 | return -EPROBE_DEFER; |
| 84 | |
| 85 | if (gpio_is_valid(det)) { |
| 86 | sjack->pin.pin = pin_name; |
| 87 | sjack->pin.mask = mask; |
| 88 | |
| 89 | sjack->gpio.name = gpio_name; |
| 90 | sjack->gpio.report = mask; |
| 91 | sjack->gpio.gpio = det; |
| 92 | sjack->gpio.invert = !!(flags & OF_GPIO_ACTIVE_LOW); |
| 93 | sjack->gpio.debounce_time = 150; |
| 94 | |
| 95 | snd_soc_card_jack_new(card, pin_name, mask, |
| 96 | &sjack->jack, |
| 97 | &sjack->pin, 1); |
| 98 | |
| 99 | snd_soc_jack_add_gpios(&sjack->jack, 1, |
| 100 | &sjack->gpio); |
| 101 | } |
| 102 | |
| 103 | return 0; |
| 104 | } |
| 105 | |
| 106 | static void asoc_simple_card_remove_jack(struct asoc_simple_jack *sjack) |
| 107 | { |
| 108 | if (gpio_is_valid(sjack->gpio.gpio)) |
| 109 | snd_soc_jack_free_gpios(&sjack->jack, 1, &sjack->gpio); |
| 110 | } |
| 111 | |
Jyri Sarha | f991180 | 2015-01-13 21:16:34 +0200 | [diff] [blame] | 112 | static int asoc_simple_card_startup(struct snd_pcm_substream *substream) |
| 113 | { |
| 114 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 115 | struct simple_card_data *priv = snd_soc_card_get_drvdata(rtd->card); |
| 116 | struct simple_dai_props *dai_props = |
Mengdong Lin | 1a49798 | 2015-11-18 02:34:11 -0500 | [diff] [blame] | 117 | &priv->dai_props[rtd->num]; |
Jyri Sarha | f991180 | 2015-01-13 21:16:34 +0200 | [diff] [blame] | 118 | int ret; |
| 119 | |
| 120 | ret = clk_prepare_enable(dai_props->cpu_dai.clk); |
| 121 | if (ret) |
| 122 | return ret; |
| 123 | |
| 124 | ret = clk_prepare_enable(dai_props->codec_dai.clk); |
| 125 | if (ret) |
| 126 | clk_disable_unprepare(dai_props->cpu_dai.clk); |
| 127 | |
| 128 | return ret; |
| 129 | } |
| 130 | |
| 131 | static void asoc_simple_card_shutdown(struct snd_pcm_substream *substream) |
| 132 | { |
| 133 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 134 | struct simple_card_data *priv = snd_soc_card_get_drvdata(rtd->card); |
| 135 | struct simple_dai_props *dai_props = |
Mengdong Lin | 1a49798 | 2015-11-18 02:34:11 -0500 | [diff] [blame] | 136 | &priv->dai_props[rtd->num]; |
Jyri Sarha | f991180 | 2015-01-13 21:16:34 +0200 | [diff] [blame] | 137 | |
| 138 | clk_disable_unprepare(dai_props->cpu_dai.clk); |
| 139 | |
| 140 | clk_disable_unprepare(dai_props->codec_dai.clk); |
| 141 | } |
| 142 | |
Andrew Lunn | 2942a0e | 2014-05-22 17:31:49 +0200 | [diff] [blame] | 143 | static int asoc_simple_card_hw_params(struct snd_pcm_substream *substream, |
| 144 | struct snd_pcm_hw_params *params) |
| 145 | { |
| 146 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 147 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
Arnaud Pouliquen | e225797 | 2015-06-05 10:19:06 +0200 | [diff] [blame] | 148 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Andrew Lunn | 2942a0e | 2014-05-22 17:31:49 +0200 | [diff] [blame] | 149 | struct simple_card_data *priv = snd_soc_card_get_drvdata(rtd->card); |
Mengdong Lin | 1a49798 | 2015-11-18 02:34:11 -0500 | [diff] [blame] | 150 | struct simple_dai_props *dai_props = &priv->dai_props[rtd->num]; |
Arnaud Pouliquen | 85a4bfd | 2015-06-05 10:19:05 +0200 | [diff] [blame] | 151 | unsigned int mclk, mclk_fs = 0; |
Andrew Lunn | 2942a0e | 2014-05-22 17:31:49 +0200 | [diff] [blame] | 152 | int ret = 0; |
| 153 | |
Arnaud Pouliquen | 85a4bfd | 2015-06-05 10:19:05 +0200 | [diff] [blame] | 154 | if (priv->mclk_fs) |
| 155 | mclk_fs = priv->mclk_fs; |
| 156 | else if (dai_props->mclk_fs) |
| 157 | mclk_fs = dai_props->mclk_fs; |
| 158 | |
| 159 | if (mclk_fs) { |
| 160 | mclk = params_rate(params) * mclk_fs; |
Andrew Lunn | 2942a0e | 2014-05-22 17:31:49 +0200 | [diff] [blame] | 161 | ret = snd_soc_dai_set_sysclk(codec_dai, 0, mclk, |
| 162 | SND_SOC_CLOCK_IN); |
Arnaud Pouliquen | e225797 | 2015-06-05 10:19:06 +0200 | [diff] [blame] | 163 | if (ret && ret != -ENOTSUPP) |
| 164 | goto err; |
| 165 | |
| 166 | ret = snd_soc_dai_set_sysclk(cpu_dai, 0, mclk, |
| 167 | SND_SOC_CLOCK_OUT); |
| 168 | if (ret && ret != -ENOTSUPP) |
| 169 | goto err; |
Andrew Lunn | 2942a0e | 2014-05-22 17:31:49 +0200 | [diff] [blame] | 170 | } |
Aaro Koskinen | ee43a1a | 2016-01-24 00:36:40 +0200 | [diff] [blame] | 171 | return 0; |
Arnaud Pouliquen | e225797 | 2015-06-05 10:19:06 +0200 | [diff] [blame] | 172 | err: |
Andrew Lunn | 2942a0e | 2014-05-22 17:31:49 +0200 | [diff] [blame] | 173 | return ret; |
| 174 | } |
| 175 | |
| 176 | static struct snd_soc_ops asoc_simple_card_ops = { |
Jyri Sarha | f991180 | 2015-01-13 21:16:34 +0200 | [diff] [blame] | 177 | .startup = asoc_simple_card_startup, |
| 178 | .shutdown = asoc_simple_card_shutdown, |
Andrew Lunn | 2942a0e | 2014-05-22 17:31:49 +0200 | [diff] [blame] | 179 | .hw_params = asoc_simple_card_hw_params, |
| 180 | }; |
| 181 | |
Kuninori Morimoto | a4a2992 | 2013-01-10 16:49:11 -0800 | [diff] [blame] | 182 | static int __asoc_simple_card_dai_init(struct snd_soc_dai *dai, |
Xiubo Li | 30d0341 | 2014-01-24 15:43:01 +0800 | [diff] [blame] | 183 | struct asoc_simple_dai *set) |
Kuninori Morimoto | a4a2992 | 2013-01-10 16:49:11 -0800 | [diff] [blame] | 184 | { |
Xiubo Li | 4763ebe | 2014-01-24 15:43:00 +0800 | [diff] [blame] | 185 | int ret; |
Kuninori Morimoto | a4a2992 | 2013-01-10 16:49:11 -0800 | [diff] [blame] | 186 | |
Xiubo Li | 4763ebe | 2014-01-24 15:43:00 +0800 | [diff] [blame] | 187 | if (set->sysclk) { |
Kuninori Morimoto | a4a2992 | 2013-01-10 16:49:11 -0800 | [diff] [blame] | 188 | ret = snd_soc_dai_set_sysclk(dai, 0, set->sysclk, 0); |
Xiubo Li | 4763ebe | 2014-01-24 15:43:00 +0800 | [diff] [blame] | 189 | if (ret && ret != -ENOTSUPP) { |
| 190 | dev_err(dai->dev, "simple-card: set_sysclk error\n"); |
| 191 | goto err; |
| 192 | } |
| 193 | } |
Kuninori Morimoto | a4a2992 | 2013-01-10 16:49:11 -0800 | [diff] [blame] | 194 | |
Xiubo Li | 6ff62ee | 2014-02-14 09:34:36 +0800 | [diff] [blame] | 195 | if (set->slots) { |
Jyri Sarha | 6131084 | 2015-09-09 21:27:43 +0300 | [diff] [blame] | 196 | ret = snd_soc_dai_set_tdm_slot(dai, |
| 197 | set->tx_slot_mask, |
| 198 | set->rx_slot_mask, |
Xiubo Li | 6ff62ee | 2014-02-14 09:34:36 +0800 | [diff] [blame] | 199 | set->slots, |
| 200 | set->slot_width); |
| 201 | if (ret && ret != -ENOTSUPP) { |
| 202 | dev_err(dai->dev, "simple-card: set_tdm_slot error\n"); |
| 203 | goto err; |
| 204 | } |
| 205 | } |
| 206 | |
Xiubo Li | 4763ebe | 2014-01-24 15:43:00 +0800 | [diff] [blame] | 207 | ret = 0; |
| 208 | |
| 209 | err: |
Kuninori Morimoto | a4a2992 | 2013-01-10 16:49:11 -0800 | [diff] [blame] | 210 | return ret; |
| 211 | } |
| 212 | |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 213 | static int asoc_simple_card_dai_init(struct snd_soc_pcm_runtime *rtd) |
| 214 | { |
Nicolin Chen | 781cbeb | 2014-04-24 19:14:00 +0800 | [diff] [blame] | 215 | struct simple_card_data *priv = snd_soc_card_get_drvdata(rtd->card); |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 216 | struct snd_soc_dai *codec = rtd->codec_dai; |
| 217 | struct snd_soc_dai *cpu = rtd->cpu_dai; |
Jean-Francois Moine | 6a91a17bd | 2014-03-20 11:49:55 +0100 | [diff] [blame] | 218 | struct simple_dai_props *dai_props; |
Mengdong Lin | 1a49798 | 2015-11-18 02:34:11 -0500 | [diff] [blame] | 219 | int ret; |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 220 | |
Mengdong Lin | 1a49798 | 2015-11-18 02:34:11 -0500 | [diff] [blame] | 221 | dai_props = &priv->dai_props[rtd->num]; |
Jean-Francois Moine | 6a91a17bd | 2014-03-20 11:49:55 +0100 | [diff] [blame] | 222 | ret = __asoc_simple_card_dai_init(codec, &dai_props->codec_dai); |
Kuninori Morimoto | a4a2992 | 2013-01-10 16:49:11 -0800 | [diff] [blame] | 223 | if (ret < 0) |
| 224 | return ret; |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 225 | |
Jean-Francois Moine | 6a91a17bd | 2014-03-20 11:49:55 +0100 | [diff] [blame] | 226 | ret = __asoc_simple_card_dai_init(cpu, &dai_props->cpu_dai); |
Kuninori Morimoto | a4a2992 | 2013-01-10 16:49:11 -0800 | [diff] [blame] | 227 | if (ret < 0) |
| 228 | return ret; |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 229 | |
Kuninori Morimoto | 9eac361 | 2016-05-31 08:59:46 +0000 | [diff] [blame] | 230 | ret = asoc_simple_card_init_hp(rtd->card, &priv->hp_jack, PREFIX); |
| 231 | if (ret < 0) |
| 232 | return ret; |
Dylan Reid | 3fe2403 | 2014-10-01 14:25:20 -0700 | [diff] [blame] | 233 | |
Kuninori Morimoto | 9eac361 | 2016-05-31 08:59:46 +0000 | [diff] [blame] | 234 | ret = asoc_simple_card_init_mic(rtd->card, &priv->hp_jack, PREFIX); |
| 235 | if (ret < 0) |
| 236 | return ret; |
Dylan Reid | 3fe2403 | 2014-10-01 14:25:20 -0700 | [diff] [blame] | 237 | |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 238 | return 0; |
| 239 | } |
| 240 | |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 241 | static int |
| 242 | asoc_simple_card_sub_parse_of(struct device_node *np, |
| 243 | struct asoc_simple_dai *dai, |
Xiubo Li | 8ea2134 | 2014-08-18 15:00:15 +0800 | [diff] [blame] | 244 | struct device_node **p_node, |
Kuninori Morimoto | 7c7b9cf | 2014-09-02 04:05:30 -0700 | [diff] [blame] | 245 | const char **name, |
| 246 | int *args_count) |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 247 | { |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 248 | int ret; |
| 249 | |
Kuninori Morimoto | 5fb9cb1 | 2016-05-20 09:40:41 +0000 | [diff] [blame] | 250 | if (!np) |
| 251 | return 0; |
| 252 | |
Kuninori Morimoto | 5fb9cb1 | 2016-05-20 09:40:41 +0000 | [diff] [blame] | 253 | if (!dai) |
| 254 | return 0; |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 255 | |
Xiubo Li | 0dd4fc3 | 2014-09-10 09:59:55 +0800 | [diff] [blame] | 256 | /* Parse TDM slot */ |
Jyri Sarha | 6131084 | 2015-09-09 21:27:43 +0300 | [diff] [blame] | 257 | ret = snd_soc_of_parse_tdm_slot(np, &dai->tx_slot_mask, |
| 258 | &dai->rx_slot_mask, |
| 259 | &dai->slots, &dai->slot_width); |
Xiubo Li | 6ff62ee | 2014-02-14 09:34:36 +0800 | [diff] [blame] | 260 | if (ret) |
Jean-Francois Moine | e512e00 | 2014-03-11 10:03:40 +0100 | [diff] [blame] | 261 | return ret; |
Xiubo Li | 6ff62ee | 2014-02-14 09:34:36 +0800 | [diff] [blame] | 262 | |
Jean-Francois Moine | e512e00 | 2014-03-11 10:03:40 +0100 | [diff] [blame] | 263 | return 0; |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 264 | } |
| 265 | |
Kuninori Morimoto | 2d82eeb | 2014-08-27 20:07:46 -0700 | [diff] [blame] | 266 | static int asoc_simple_card_dai_link_of(struct device_node *node, |
Kuninori Morimoto | f531913f | 2014-09-09 21:37:57 -0700 | [diff] [blame] | 267 | struct simple_card_data *priv, |
Kuninori Morimoto | 9810f53 | 2014-09-09 21:38:24 -0700 | [diff] [blame] | 268 | int idx, |
Kuninori Morimoto | 2d82eeb | 2014-08-27 20:07:46 -0700 | [diff] [blame] | 269 | bool is_top_level_node) |
Jean-Francois Moine | 6a91a17bd | 2014-03-20 11:49:55 +0100 | [diff] [blame] | 270 | { |
Kuninori Morimoto | f531913f | 2014-09-09 21:37:57 -0700 | [diff] [blame] | 271 | struct device *dev = simple_priv_to_dev(priv); |
Kuninori Morimoto | 9810f53 | 2014-09-09 21:38:24 -0700 | [diff] [blame] | 272 | struct snd_soc_dai_link *dai_link = simple_priv_to_link(priv, idx); |
| 273 | struct simple_dai_props *dai_props = simple_priv_to_props(priv, idx); |
Kuninori Morimoto | 28abd99 | 2016-07-19 02:53:13 +0000 | [diff] [blame] | 274 | struct asoc_simple_dai *cpu_dai = &dai_props->cpu_dai; |
| 275 | struct asoc_simple_dai *codec_dai = &dai_props->codec_dai; |
Kuninori Morimoto | 1b5721b | 2014-10-27 18:04:52 -0700 | [diff] [blame] | 276 | struct device_node *cpu = NULL; |
Jun Nie | e0ae225 | 2015-04-29 18:11:07 +0800 | [diff] [blame] | 277 | struct device_node *plat = NULL; |
Kuninori Morimoto | 1b5721b | 2014-10-27 18:04:52 -0700 | [diff] [blame] | 278 | struct device_node *codec = NULL; |
Jyri Sarha | b3ca11f | 2014-03-24 12:15:25 +0200 | [diff] [blame] | 279 | char prop[128]; |
| 280 | char *prefix = ""; |
Kuninori Morimoto | 44c16af | 2016-08-08 06:02:07 +0000 | [diff] [blame^] | 281 | int ret, single_cpu; |
Arnaud Pouliquen | 85a4bfd | 2015-06-05 10:19:05 +0200 | [diff] [blame] | 282 | u32 val; |
Jean-Francois Moine | 6a91a17bd | 2014-03-20 11:49:55 +0100 | [diff] [blame] | 283 | |
Xiubo Li | 2080437 | 2014-09-03 10:23:39 +0800 | [diff] [blame] | 284 | /* For single DAI link & old style of DT node */ |
Jyri Sarha | 6487221 | 2014-04-24 19:42:00 +0300 | [diff] [blame] | 285 | if (is_top_level_node) |
Kuninori Morimoto | 548563f | 2016-05-31 08:59:01 +0000 | [diff] [blame] | 286 | prefix = PREFIX; |
Jean-Francois Moine | 6a91a17bd | 2014-03-20 11:49:55 +0100 | [diff] [blame] | 287 | |
Jyri Sarha | b3ca11f | 2014-03-24 12:15:25 +0200 | [diff] [blame] | 288 | snprintf(prop, sizeof(prop), "%scpu", prefix); |
Kuninori Morimoto | 1b5721b | 2014-10-27 18:04:52 -0700 | [diff] [blame] | 289 | cpu = of_get_child_by_name(node, prop); |
| 290 | |
Jun Nie | e0ae225 | 2015-04-29 18:11:07 +0800 | [diff] [blame] | 291 | snprintf(prop, sizeof(prop), "%splat", prefix); |
| 292 | plat = of_get_child_by_name(node, prop); |
| 293 | |
Kuninori Morimoto | 1b5721b | 2014-10-27 18:04:52 -0700 | [diff] [blame] | 294 | snprintf(prop, sizeof(prop), "%scodec", prefix); |
| 295 | codec = of_get_child_by_name(node, prop); |
| 296 | |
| 297 | if (!cpu || !codec) { |
Jyri Sarha | b3ca11f | 2014-03-24 12:15:25 +0200 | [diff] [blame] | 298 | ret = -EINVAL; |
Nicolin Chen | 966b806 | 2014-04-24 19:13:59 +0800 | [diff] [blame] | 299 | dev_err(dev, "%s: Can't find %s DT node\n", __func__, prop); |
Jyri Sarha | b3ca11f | 2014-03-24 12:15:25 +0200 | [diff] [blame] | 300 | goto dai_link_of_err; |
Jean-Francois Moine | 6a91a17bd | 2014-03-20 11:49:55 +0100 | [diff] [blame] | 301 | } |
Jyri Sarha | b3ca11f | 2014-03-24 12:15:25 +0200 | [diff] [blame] | 302 | |
Kuninori Morimoto | cecdef3 | 2016-06-30 06:02:46 +0000 | [diff] [blame] | 303 | ret = asoc_simple_card_parse_daifmt(dev, node, codec, |
| 304 | prefix, &dai_link->dai_fmt); |
Kuninori Morimoto | 1b5721b | 2014-10-27 18:04:52 -0700 | [diff] [blame] | 305 | if (ret < 0) |
| 306 | goto dai_link_of_err; |
| 307 | |
Arnaud Pouliquen | 85a4bfd | 2015-06-05 10:19:05 +0200 | [diff] [blame] | 308 | if (!of_property_read_u32(node, "mclk-fs", &val)) |
| 309 | dai_props->mclk_fs = val; |
| 310 | |
Kuninori Morimoto | 44c16af | 2016-08-08 06:02:07 +0000 | [diff] [blame^] | 311 | ret = asoc_simple_card_parse_cpu(cpu, dai_link, |
| 312 | DAI, CELL, &single_cpu); |
| 313 | if (ret < 0) |
| 314 | goto dai_link_of_err; |
| 315 | |
| 316 | ret = asoc_simple_card_parse_codec(codec, dai_link, DAI, CELL); |
| 317 | if (ret < 0) |
| 318 | goto dai_link_of_err; |
| 319 | |
| 320 | ret = asoc_simple_card_parse_platform(plat, dai_link, DAI, CELL); |
| 321 | if (ret < 0) |
| 322 | goto dai_link_of_err; |
| 323 | |
Kuninori Morimoto | 1b5721b | 2014-10-27 18:04:52 -0700 | [diff] [blame] | 324 | ret = asoc_simple_card_sub_parse_of(cpu, &dai_props->cpu_dai, |
Jyri Sarha | b3ca11f | 2014-03-24 12:15:25 +0200 | [diff] [blame] | 325 | &dai_link->cpu_of_node, |
Kuninori Morimoto | 7c7b9cf | 2014-09-02 04:05:30 -0700 | [diff] [blame] | 326 | &dai_link->cpu_dai_name, |
Kuninori Morimoto | 44c16af | 2016-08-08 06:02:07 +0000 | [diff] [blame^] | 327 | &single_cpu); |
Jyri Sarha | b3ca11f | 2014-03-24 12:15:25 +0200 | [diff] [blame] | 328 | if (ret < 0) |
| 329 | goto dai_link_of_err; |
| 330 | |
Kuninori Morimoto | 1b5721b | 2014-10-27 18:04:52 -0700 | [diff] [blame] | 331 | ret = asoc_simple_card_sub_parse_of(codec, &dai_props->codec_dai, |
Jyri Sarha | b3ca11f | 2014-03-24 12:15:25 +0200 | [diff] [blame] | 332 | &dai_link->codec_of_node, |
Kuninori Morimoto | 7c7b9cf | 2014-09-02 04:05:30 -0700 | [diff] [blame] | 333 | &dai_link->codec_dai_name, NULL); |
Jyri Sarha | b3ca11f | 2014-03-24 12:15:25 +0200 | [diff] [blame] | 334 | if (ret < 0) |
| 335 | goto dai_link_of_err; |
| 336 | |
Kuninori Morimoto | 5fb9cb1 | 2016-05-20 09:40:41 +0000 | [diff] [blame] | 337 | ret = asoc_simple_card_sub_parse_of(plat, NULL, |
| 338 | &dai_link->platform_of_node, |
| 339 | NULL, NULL); |
| 340 | if (ret < 0) |
| 341 | goto dai_link_of_err; |
| 342 | |
Kuninori Morimoto | 28abd99 | 2016-07-19 02:53:13 +0000 | [diff] [blame] | 343 | ret = asoc_simple_card_parse_clk_cpu(cpu, dai_link, cpu_dai); |
| 344 | if (ret < 0) |
| 345 | goto dai_link_of_err; |
| 346 | |
| 347 | ret = asoc_simple_card_parse_clk_codec(codec, dai_link, codec_dai); |
| 348 | if (ret < 0) |
| 349 | goto dai_link_of_err; |
| 350 | |
Jyri Sarha | b3ca11f | 2014-03-24 12:15:25 +0200 | [diff] [blame] | 351 | if (!dai_link->cpu_dai_name || !dai_link->codec_dai_name) { |
Nicolin Chen | 781cbeb | 2014-04-24 19:14:00 +0800 | [diff] [blame] | 352 | ret = -EINVAL; |
| 353 | goto dai_link_of_err; |
Jyri Sarha | b3ca11f | 2014-03-24 12:15:25 +0200 | [diff] [blame] | 354 | } |
| 355 | |
Kuninori Morimoto | 5fb9cb1 | 2016-05-20 09:40:41 +0000 | [diff] [blame] | 356 | /* Assumes platform == cpu */ |
| 357 | if (!dai_link->platform_of_node) |
Jun Nie | e0ae225 | 2015-04-29 18:11:07 +0800 | [diff] [blame] | 358 | dai_link->platform_of_node = dai_link->cpu_of_node; |
Jyri Sarha | b3ca11f | 2014-03-24 12:15:25 +0200 | [diff] [blame] | 359 | |
Kuninori Morimoto | 2e8d1c7 | 2016-07-11 23:57:34 +0000 | [diff] [blame] | 360 | ret = asoc_simple_card_set_dailink_name(dev, dai_link, |
| 361 | "%s-%s", |
| 362 | dai_link->cpu_dai_name, |
| 363 | dai_link->codec_dai_name); |
| 364 | if (ret < 0) |
Vishal Thanki | 31f3032 | 2015-03-03 18:59:00 +0530 | [diff] [blame] | 365 | goto dai_link_of_err; |
Vishal Thanki | 31f3032 | 2015-03-03 18:59:00 +0530 | [diff] [blame] | 366 | |
Andrew Lunn | 2942a0e | 2014-05-22 17:31:49 +0200 | [diff] [blame] | 367 | dai_link->ops = &asoc_simple_card_ops; |
Kuninori Morimoto | a5960bd | 2014-08-27 20:08:27 -0700 | [diff] [blame] | 368 | dai_link->init = asoc_simple_card_dai_init; |
Jyri Sarha | b3ca11f | 2014-03-24 12:15:25 +0200 | [diff] [blame] | 369 | |
| 370 | dev_dbg(dev, "\tname : %s\n", dai_link->stream_name); |
Lars-Peter Clausen | 1efb53a | 2015-03-24 01:07:08 +0000 | [diff] [blame] | 371 | dev_dbg(dev, "\tformat : %04x\n", dai_link->dai_fmt); |
| 372 | dev_dbg(dev, "\tcpu : %s / %d\n", |
Jyri Sarha | b3ca11f | 2014-03-24 12:15:25 +0200 | [diff] [blame] | 373 | dai_link->cpu_dai_name, |
Jyri Sarha | b3ca11f | 2014-03-24 12:15:25 +0200 | [diff] [blame] | 374 | dai_props->cpu_dai.sysclk); |
Lars-Peter Clausen | 1efb53a | 2015-03-24 01:07:08 +0000 | [diff] [blame] | 375 | dev_dbg(dev, "\tcodec : %s / %d\n", |
Jyri Sarha | b3ca11f | 2014-03-24 12:15:25 +0200 | [diff] [blame] | 376 | dai_link->codec_dai_name, |
Jyri Sarha | b3ca11f | 2014-03-24 12:15:25 +0200 | [diff] [blame] | 377 | dai_props->codec_dai.sysclk); |
| 378 | |
Kuninori Morimoto | 179949b | 2014-08-27 20:08:06 -0700 | [diff] [blame] | 379 | /* |
Xiubo Li | 0dd4fc3 | 2014-09-10 09:59:55 +0800 | [diff] [blame] | 380 | * In soc_bind_dai_link() will check cpu name after |
| 381 | * of_node matching if dai_link has cpu_dai_name. |
| 382 | * but, it will never match if name was created by |
| 383 | * fmt_single_name() remove cpu_dai_name if cpu_args |
| 384 | * was 0. See: |
Kuninori Morimoto | 179949b | 2014-08-27 20:08:06 -0700 | [diff] [blame] | 385 | * fmt_single_name() |
| 386 | * fmt_multiple_name() |
| 387 | */ |
Kuninori Morimoto | 44c16af | 2016-08-08 06:02:07 +0000 | [diff] [blame^] | 388 | if (single_cpu) |
Kuninori Morimoto | 7c7b9cf | 2014-09-02 04:05:30 -0700 | [diff] [blame] | 389 | dai_link->cpu_dai_name = NULL; |
Kuninori Morimoto | 179949b | 2014-08-27 20:08:06 -0700 | [diff] [blame] | 390 | |
Jyri Sarha | b3ca11f | 2014-03-24 12:15:25 +0200 | [diff] [blame] | 391 | dai_link_of_err: |
Kuninori Morimoto | 1b5721b | 2014-10-27 18:04:52 -0700 | [diff] [blame] | 392 | of_node_put(cpu); |
| 393 | of_node_put(codec); |
| 394 | |
Jean-Francois Moine | 6a91a17bd | 2014-03-20 11:49:55 +0100 | [diff] [blame] | 395 | return ret; |
| 396 | } |
| 397 | |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 398 | static int asoc_simple_card_parse_of(struct device_node *node, |
Kuninori Morimoto | f531913f | 2014-09-09 21:37:57 -0700 | [diff] [blame] | 399 | struct simple_card_data *priv) |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 400 | { |
Kuninori Morimoto | f531913f | 2014-09-09 21:37:57 -0700 | [diff] [blame] | 401 | struct device *dev = simple_priv_to_dev(priv); |
Jyri Sarha | c7099eb | 2014-06-13 13:04:36 +0300 | [diff] [blame] | 402 | u32 val; |
Xiubo Li | d4c2209 | 2013-12-23 12:57:01 +0800 | [diff] [blame] | 403 | int ret; |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 404 | |
Xiubo Li | 2080437 | 2014-09-03 10:23:39 +0800 | [diff] [blame] | 405 | if (!node) |
| 406 | return -EINVAL; |
| 407 | |
Xiubo Li | 0dd4fc3 | 2014-09-10 09:59:55 +0800 | [diff] [blame] | 408 | /* The off-codec widgets */ |
Kuninori Morimoto | 548563f | 2016-05-31 08:59:01 +0000 | [diff] [blame] | 409 | if (of_property_read_bool(node, PREFIX "widgets")) { |
Xiubo Li | 9d681f5 | 2014-02-08 15:59:53 +0800 | [diff] [blame] | 410 | ret = snd_soc_of_parse_audio_simple_widgets(&priv->snd_card, |
Kuninori Morimoto | 548563f | 2016-05-31 08:59:01 +0000 | [diff] [blame] | 411 | PREFIX "widgets"); |
Xiubo Li | 9d681f5 | 2014-02-08 15:59:53 +0800 | [diff] [blame] | 412 | if (ret) |
| 413 | return ret; |
| 414 | } |
| 415 | |
Xiubo Li | d4c2209 | 2013-12-23 12:57:01 +0800 | [diff] [blame] | 416 | /* DAPM routes */ |
Kuninori Morimoto | 548563f | 2016-05-31 08:59:01 +0000 | [diff] [blame] | 417 | if (of_property_read_bool(node, PREFIX "routing")) { |
Jean-Francois Moine | b367a32 | 2014-01-15 16:52:00 +0100 | [diff] [blame] | 418 | ret = snd_soc_of_parse_audio_routing(&priv->snd_card, |
Kuninori Morimoto | 548563f | 2016-05-31 08:59:01 +0000 | [diff] [blame] | 419 | PREFIX "routing"); |
Xiubo Li | f87a3e8 | 2014-01-07 09:13:42 +0800 | [diff] [blame] | 420 | if (ret) |
| 421 | return ret; |
| 422 | } |
Xiubo Li | d4c2209 | 2013-12-23 12:57:01 +0800 | [diff] [blame] | 423 | |
Andrew Lunn | 2942a0e | 2014-05-22 17:31:49 +0200 | [diff] [blame] | 424 | /* Factor to mclk, used in hw_params() */ |
Kuninori Morimoto | 548563f | 2016-05-31 08:59:01 +0000 | [diff] [blame] | 425 | ret = of_property_read_u32(node, PREFIX "mclk-fs", &val); |
Jyri Sarha | c7099eb | 2014-06-13 13:04:36 +0300 | [diff] [blame] | 426 | if (ret == 0) |
| 427 | priv->mclk_fs = val; |
Andrew Lunn | 2942a0e | 2014-05-22 17:31:49 +0200 | [diff] [blame] | 428 | |
Xiubo Li | 2080437 | 2014-09-03 10:23:39 +0800 | [diff] [blame] | 429 | /* Single/Muti DAI link(s) & New style of DT node */ |
Kuninori Morimoto | 548563f | 2016-05-31 08:59:01 +0000 | [diff] [blame] | 430 | if (of_get_child_by_name(node, PREFIX "dai-link")) { |
Jyri Sarha | b3ca11f | 2014-03-24 12:15:25 +0200 | [diff] [blame] | 431 | struct device_node *np = NULL; |
Kuninori Morimoto | a44a750 | 2014-08-27 20:08:47 -0700 | [diff] [blame] | 432 | int i = 0; |
| 433 | |
| 434 | for_each_child_of_node(node, np) { |
Jyri Sarha | b3ca11f | 2014-03-24 12:15:25 +0200 | [diff] [blame] | 435 | dev_dbg(dev, "\tlink %d:\n", i); |
Kuninori Morimoto | f531913f | 2014-09-09 21:37:57 -0700 | [diff] [blame] | 436 | ret = asoc_simple_card_dai_link_of(np, priv, |
Kuninori Morimoto | 9810f53 | 2014-09-09 21:38:24 -0700 | [diff] [blame] | 437 | i, false); |
Jyri Sarha | b3ca11f | 2014-03-24 12:15:25 +0200 | [diff] [blame] | 438 | if (ret < 0) { |
| 439 | of_node_put(np); |
| 440 | return ret; |
| 441 | } |
Kuninori Morimoto | a44a750 | 2014-08-27 20:08:47 -0700 | [diff] [blame] | 442 | i++; |
Jyri Sarha | b3ca11f | 2014-03-24 12:15:25 +0200 | [diff] [blame] | 443 | } |
| 444 | } else { |
Xiubo Li | 2080437 | 2014-09-03 10:23:39 +0800 | [diff] [blame] | 445 | /* For single DAI link & old style of DT node */ |
Kuninori Morimoto | 9810f53 | 2014-09-09 21:38:24 -0700 | [diff] [blame] | 446 | ret = asoc_simple_card_dai_link_of(node, priv, 0, true); |
Jean-Francois Moine | 6a91a17bd | 2014-03-20 11:49:55 +0100 | [diff] [blame] | 447 | if (ret < 0) |
Jyri Sarha | b3ca11f | 2014-03-24 12:15:25 +0200 | [diff] [blame] | 448 | return ret; |
Jean-Francois Moine | e512e00 | 2014-03-11 10:03:40 +0100 | [diff] [blame] | 449 | } |
Xiubo Li | dd41e0c | 2013-12-20 14:39:50 +0800 | [diff] [blame] | 450 | |
Kuninori Morimoto | 3527d85 | 2016-07-11 23:59:40 +0000 | [diff] [blame] | 451 | ret = asoc_simple_card_parse_card_name(&priv->snd_card, PREFIX); |
| 452 | if (ret) |
| 453 | return ret; |
Kuninori Morimoto | f687d90 | 2014-02-27 18:25:24 -0800 | [diff] [blame] | 454 | |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 455 | return 0; |
| 456 | } |
| 457 | |
Xiubo Li | 0dd4fc3 | 2014-09-10 09:59:55 +0800 | [diff] [blame] | 458 | /* Decrease the reference count of the device nodes */ |
Geert Uytterhoeven | 7ddfdb5 | 2015-01-13 21:03:37 +0100 | [diff] [blame] | 459 | static int asoc_simple_card_unref(struct snd_soc_card *card) |
Jean-Francois Moine | e512e00 | 2014-03-11 10:03:40 +0100 | [diff] [blame] | 460 | { |
Jean-Francois Moine | e512e00 | 2014-03-11 10:03:40 +0100 | [diff] [blame] | 461 | struct snd_soc_dai_link *dai_link; |
Jean-Francois Moine | e512e00 | 2014-03-11 10:03:40 +0100 | [diff] [blame] | 462 | int num_links; |
| 463 | |
| 464 | for (num_links = 0, dai_link = card->dai_link; |
| 465 | num_links < card->num_links; |
| 466 | num_links++, dai_link++) { |
Jean-Francois Moine | 0099c76 | 2014-11-09 12:38:56 +0100 | [diff] [blame] | 467 | of_node_put(dai_link->cpu_of_node); |
| 468 | of_node_put(dai_link->codec_of_node); |
Jean-Francois Moine | e512e00 | 2014-03-11 10:03:40 +0100 | [diff] [blame] | 469 | } |
| 470 | return 0; |
| 471 | } |
| 472 | |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 473 | static int asoc_simple_card_probe(struct platform_device *pdev) |
| 474 | { |
Jean-Francois Moine | 45fce59 | 2014-01-15 16:51:56 +0100 | [diff] [blame] | 475 | struct simple_card_data *priv; |
Jean-Francois Moine | 5ca8ba4 | 2014-01-15 16:51:45 +0100 | [diff] [blame] | 476 | struct snd_soc_dai_link *dai_link; |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 477 | struct device_node *np = pdev->dev.of_node; |
Kuninori Morimoto | f89983e | 2012-12-25 22:52:33 -0800 | [diff] [blame] | 478 | struct device *dev = &pdev->dev; |
Xiubo Li | 2080437 | 2014-09-03 10:23:39 +0800 | [diff] [blame] | 479 | int num_links, ret; |
Jean-Francois Moine | 6a91a17bd | 2014-03-20 11:49:55 +0100 | [diff] [blame] | 480 | |
Xiubo Li | 0dd4fc3 | 2014-09-10 09:59:55 +0800 | [diff] [blame] | 481 | /* Get the number of DAI links */ |
Kuninori Morimoto | 548563f | 2016-05-31 08:59:01 +0000 | [diff] [blame] | 482 | if (np && of_get_child_by_name(np, PREFIX "dai-link")) |
Jean-Francois Moine | 6a91a17bd | 2014-03-20 11:49:55 +0100 | [diff] [blame] | 483 | num_links = of_get_child_count(np); |
Xiubo Li | 2080437 | 2014-09-03 10:23:39 +0800 | [diff] [blame] | 484 | else |
Jean-Francois Moine | 6a91a17bd | 2014-03-20 11:49:55 +0100 | [diff] [blame] | 485 | num_links = 1; |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 486 | |
Xiubo Li | 0dd4fc3 | 2014-09-10 09:59:55 +0800 | [diff] [blame] | 487 | /* Allocate the private data and the DAI link array */ |
Jean-Francois Moine | cf7dc23 | 2014-03-20 10:52:41 +0100 | [diff] [blame] | 488 | priv = devm_kzalloc(dev, |
Jean-Francois Moine | 6a91a17bd | 2014-03-20 11:49:55 +0100 | [diff] [blame] | 489 | sizeof(*priv) + sizeof(*dai_link) * num_links, |
Jean-Francois Moine | cf7dc23 | 2014-03-20 10:52:41 +0100 | [diff] [blame] | 490 | GFP_KERNEL); |
Jean-Francois Moine | ca65b49 | 2014-01-15 16:51:52 +0100 | [diff] [blame] | 491 | if (!priv) |
Xiubo Li | ca919fe | 2014-01-14 12:35:32 +0800 | [diff] [blame] | 492 | return -ENOMEM; |
| 493 | |
Xiubo Li | 0dd4fc3 | 2014-09-10 09:59:55 +0800 | [diff] [blame] | 494 | /* Init snd_soc_card */ |
Jean-Francois Moine | ca65b49 | 2014-01-15 16:51:52 +0100 | [diff] [blame] | 495 | priv->snd_card.owner = THIS_MODULE; |
| 496 | priv->snd_card.dev = dev; |
Jean-Francois Moine | cf7dc23 | 2014-03-20 10:52:41 +0100 | [diff] [blame] | 497 | dai_link = priv->dai_link; |
Jean-Francois Moine | ca65b49 | 2014-01-15 16:51:52 +0100 | [diff] [blame] | 498 | priv->snd_card.dai_link = dai_link; |
Jean-Francois Moine | 6a91a17bd | 2014-03-20 11:49:55 +0100 | [diff] [blame] | 499 | priv->snd_card.num_links = num_links; |
Xiubo Li | ca919fe | 2014-01-14 12:35:32 +0800 | [diff] [blame] | 500 | |
Xiubo Li | 0dd4fc3 | 2014-09-10 09:59:55 +0800 | [diff] [blame] | 501 | /* Get room for the other properties */ |
Jean-Francois Moine | cf7dc23 | 2014-03-20 10:52:41 +0100 | [diff] [blame] | 502 | priv->dai_props = devm_kzalloc(dev, |
Jean-Francois Moine | 6a91a17bd | 2014-03-20 11:49:55 +0100 | [diff] [blame] | 503 | sizeof(*priv->dai_props) * num_links, |
Jean-Francois Moine | cf7dc23 | 2014-03-20 10:52:41 +0100 | [diff] [blame] | 504 | GFP_KERNEL); |
| 505 | if (!priv->dai_props) |
| 506 | return -ENOMEM; |
| 507 | |
Jean-Francois Moine | 201a0ea | 2014-01-15 16:51:41 +0100 | [diff] [blame] | 508 | if (np && of_device_is_available(np)) { |
| 509 | |
Kuninori Morimoto | f531913f | 2014-09-09 21:37:57 -0700 | [diff] [blame] | 510 | ret = asoc_simple_card_parse_of(np, priv); |
Xiubo Li | ca919fe | 2014-01-14 12:35:32 +0800 | [diff] [blame] | 511 | if (ret < 0) { |
| 512 | if (ret != -EPROBE_DEFER) |
| 513 | dev_err(dev, "parse error %d\n", ret); |
Jean-Francois Moine | e512e00 | 2014-03-11 10:03:40 +0100 | [diff] [blame] | 514 | goto err; |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 515 | } |
Jean-Francois Moine | 6a91a17bd | 2014-03-20 11:49:55 +0100 | [diff] [blame] | 516 | |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 517 | } else { |
Jean-Francois Moine | ca65b49 | 2014-01-15 16:51:52 +0100 | [diff] [blame] | 518 | struct asoc_simple_card_info *cinfo; |
| 519 | |
| 520 | cinfo = dev->platform_data; |
| 521 | if (!cinfo) { |
Xiubo Li | 34787d0a | 2014-01-09 17:49:40 +0800 | [diff] [blame] | 522 | dev_err(dev, "no info for asoc-simple-card\n"); |
| 523 | return -EINVAL; |
| 524 | } |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 525 | |
Nicolin Chen | 781cbeb | 2014-04-24 19:14:00 +0800 | [diff] [blame] | 526 | if (!cinfo->name || |
| 527 | !cinfo->codec_dai.name || |
| 528 | !cinfo->codec || |
| 529 | !cinfo->platform || |
Jean-Francois Moine | 7722f83 | 2014-01-15 16:51:33 +0100 | [diff] [blame] | 530 | !cinfo->cpu_dai.name) { |
| 531 | dev_err(dev, "insufficient asoc_simple_card_info settings\n"); |
| 532 | return -EINVAL; |
| 533 | } |
Jean-Francois Moine | 2bee991 | 2014-01-15 16:51:37 +0100 | [diff] [blame] | 534 | |
Kuninori Morimoto | 12ffa6f | 2014-03-09 19:37:56 -0700 | [diff] [blame] | 535 | priv->snd_card.name = (cinfo->card) ? cinfo->card : cinfo->name; |
Jean-Francois Moine | 5ca8ba4 | 2014-01-15 16:51:45 +0100 | [diff] [blame] | 536 | dai_link->name = cinfo->name; |
| 537 | dai_link->stream_name = cinfo->name; |
| 538 | dai_link->platform_name = cinfo->platform; |
| 539 | dai_link->codec_name = cinfo->codec; |
Jean-Francois Moine | 5200847 | 2014-01-15 16:51:48 +0100 | [diff] [blame] | 540 | dai_link->cpu_dai_name = cinfo->cpu_dai.name; |
| 541 | dai_link->codec_dai_name = cinfo->codec_dai.name; |
Lars-Peter Clausen | 1efb53a | 2015-03-24 01:07:08 +0000 | [diff] [blame] | 542 | dai_link->dai_fmt = cinfo->daifmt; |
Kuninori Morimoto | a5960bd | 2014-08-27 20:08:27 -0700 | [diff] [blame] | 543 | dai_link->init = asoc_simple_card_dai_init; |
Jean-Francois Moine | cf7dc23 | 2014-03-20 10:52:41 +0100 | [diff] [blame] | 544 | memcpy(&priv->dai_props->cpu_dai, &cinfo->cpu_dai, |
| 545 | sizeof(priv->dai_props->cpu_dai)); |
| 546 | memcpy(&priv->dai_props->codec_dai, &cinfo->codec_dai, |
| 547 | sizeof(priv->dai_props->codec_dai)); |
Kuninori Morimoto | 81985bd | 2014-03-02 20:32:43 -0800 | [diff] [blame] | 548 | |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 549 | } |
| 550 | |
Jean-Francois Moine | ca65b49 | 2014-01-15 16:51:52 +0100 | [diff] [blame] | 551 | snd_soc_card_set_drvdata(&priv->snd_card, priv); |
Xiubo Li | ba194a4 | 2014-01-13 17:08:08 +0800 | [diff] [blame] | 552 | |
Jean-Francois Moine | e512e00 | 2014-03-11 10:03:40 +0100 | [diff] [blame] | 553 | ret = devm_snd_soc_register_card(&pdev->dev, &priv->snd_card); |
Xiubo Li | e3c4a28 | 2014-09-01 14:46:52 +0800 | [diff] [blame] | 554 | if (ret >= 0) |
| 555 | return ret; |
Jean-Francois Moine | e512e00 | 2014-03-11 10:03:40 +0100 | [diff] [blame] | 556 | |
| 557 | err: |
Geert Uytterhoeven | 7ddfdb5 | 2015-01-13 21:03:37 +0100 | [diff] [blame] | 558 | asoc_simple_card_unref(&priv->snd_card); |
Jean-Francois Moine | e512e00 | 2014-03-11 10:03:40 +0100 | [diff] [blame] | 559 | return ret; |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 560 | } |
| 561 | |
Xiubo Li | e3c4a28 | 2014-09-01 14:46:52 +0800 | [diff] [blame] | 562 | static int asoc_simple_card_remove(struct platform_device *pdev) |
| 563 | { |
Dylan Reid | 3fe2403 | 2014-10-01 14:25:20 -0700 | [diff] [blame] | 564 | struct snd_soc_card *card = platform_get_drvdata(pdev); |
| 565 | struct simple_card_data *priv = snd_soc_card_get_drvdata(card); |
| 566 | |
Kuninori Morimoto | 9eac361 | 2016-05-31 08:59:46 +0000 | [diff] [blame] | 567 | asoc_simple_card_remove_jack(&priv->hp_jack); |
| 568 | asoc_simple_card_remove_jack(&priv->mic_jack); |
Dylan Reid | 3fe2403 | 2014-10-01 14:25:20 -0700 | [diff] [blame] | 569 | |
Geert Uytterhoeven | 7ddfdb5 | 2015-01-13 21:03:37 +0100 | [diff] [blame] | 570 | return asoc_simple_card_unref(card); |
Xiubo Li | e3c4a28 | 2014-09-01 14:46:52 +0800 | [diff] [blame] | 571 | } |
| 572 | |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 573 | static const struct of_device_id asoc_simple_of_match[] = { |
| 574 | { .compatible = "simple-audio-card", }, |
| 575 | {}, |
| 576 | }; |
| 577 | MODULE_DEVICE_TABLE(of, asoc_simple_of_match); |
| 578 | |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 579 | static struct platform_driver asoc_simple_card = { |
| 580 | .driver = { |
Nicolin Chen | 781cbeb | 2014-04-24 19:14:00 +0800 | [diff] [blame] | 581 | .name = "asoc-simple-card", |
Peter Ujfalusi | 7c37671 | 2016-05-09 13:38:10 +0300 | [diff] [blame] | 582 | .pm = &snd_soc_pm_ops, |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 583 | .of_match_table = asoc_simple_of_match, |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 584 | }, |
Nicolin Chen | 781cbeb | 2014-04-24 19:14:00 +0800 | [diff] [blame] | 585 | .probe = asoc_simple_card_probe, |
Xiubo Li | e3c4a28 | 2014-09-01 14:46:52 +0800 | [diff] [blame] | 586 | .remove = asoc_simple_card_remove, |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 587 | }; |
| 588 | |
| 589 | module_platform_driver(asoc_simple_card); |
| 590 | |
Fabio Estevam | c445be3 | 2013-08-23 14:35:17 -0300 | [diff] [blame] | 591 | MODULE_ALIAS("platform:asoc-simple-card"); |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 592 | MODULE_LICENSE("GPL"); |
| 593 | MODULE_DESCRIPTION("ASoC Simple Sound Card"); |
| 594 | MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>"); |