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