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