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> |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 13 | #include <linux/module.h> |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 14 | #include <linux/of.h> |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 15 | #include <linux/platform_device.h> |
Xiubo Li | ca919fe | 2014-01-14 12:35:32 +0800 | [diff] [blame] | 16 | #include <linux/string.h> |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 17 | #include <sound/simple_card.h> |
Xiubo Li | 6ff62ee | 2014-02-14 09:34:36 +0800 | [diff] [blame] | 18 | #include <sound/soc-dai.h> |
| 19 | #include <sound/soc.h> |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 20 | |
Jean-Francois Moine | 45fce59 | 2014-01-15 16:51:56 +0100 | [diff] [blame] | 21 | struct simple_card_data { |
| 22 | struct snd_soc_card snd_card; |
| 23 | unsigned int daifmt; |
| 24 | struct asoc_simple_dai cpu_dai; |
| 25 | struct asoc_simple_dai codec_dai; |
| 26 | struct snd_soc_dai_link snd_link; |
| 27 | }; |
| 28 | |
Kuninori Morimoto | a4a2992 | 2013-01-10 16:49:11 -0800 | [diff] [blame] | 29 | static int __asoc_simple_card_dai_init(struct snd_soc_dai *dai, |
Xiubo Li | 30d0341 | 2014-01-24 15:43:01 +0800 | [diff] [blame] | 30 | struct asoc_simple_dai *set) |
Kuninori Morimoto | a4a2992 | 2013-01-10 16:49:11 -0800 | [diff] [blame] | 31 | { |
Xiubo Li | 4763ebe | 2014-01-24 15:43:00 +0800 | [diff] [blame] | 32 | int ret; |
Kuninori Morimoto | a4a2992 | 2013-01-10 16:49:11 -0800 | [diff] [blame] | 33 | |
Xiubo Li | 30d0341 | 2014-01-24 15:43:01 +0800 | [diff] [blame] | 34 | if (set->fmt) { |
| 35 | ret = snd_soc_dai_set_fmt(dai, set->fmt); |
Xiubo Li | 4763ebe | 2014-01-24 15:43:00 +0800 | [diff] [blame] | 36 | if (ret && ret != -ENOTSUPP) { |
| 37 | dev_err(dai->dev, "simple-card: set_fmt error\n"); |
| 38 | goto err; |
| 39 | } |
Kuninori Morimoto | e244bb9 | 2013-10-17 22:46:49 -0700 | [diff] [blame] | 40 | } |
| 41 | |
Xiubo Li | 4763ebe | 2014-01-24 15:43:00 +0800 | [diff] [blame] | 42 | if (set->sysclk) { |
Kuninori Morimoto | a4a2992 | 2013-01-10 16:49:11 -0800 | [diff] [blame] | 43 | ret = snd_soc_dai_set_sysclk(dai, 0, set->sysclk, 0); |
Xiubo Li | 4763ebe | 2014-01-24 15:43:00 +0800 | [diff] [blame] | 44 | if (ret && ret != -ENOTSUPP) { |
| 45 | dev_err(dai->dev, "simple-card: set_sysclk error\n"); |
| 46 | goto err; |
| 47 | } |
| 48 | } |
Kuninori Morimoto | a4a2992 | 2013-01-10 16:49:11 -0800 | [diff] [blame] | 49 | |
Xiubo Li | 6ff62ee | 2014-02-14 09:34:36 +0800 | [diff] [blame] | 50 | if (set->slots) { |
| 51 | ret = snd_soc_dai_set_tdm_slot(dai, 0, 0, |
| 52 | set->slots, |
| 53 | set->slot_width); |
| 54 | if (ret && ret != -ENOTSUPP) { |
| 55 | dev_err(dai->dev, "simple-card: set_tdm_slot error\n"); |
| 56 | goto err; |
| 57 | } |
| 58 | } |
| 59 | |
Xiubo Li | 4763ebe | 2014-01-24 15:43:00 +0800 | [diff] [blame] | 60 | ret = 0; |
| 61 | |
| 62 | err: |
Kuninori Morimoto | a4a2992 | 2013-01-10 16:49:11 -0800 | [diff] [blame] | 63 | return ret; |
| 64 | } |
| 65 | |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 66 | static int asoc_simple_card_dai_init(struct snd_soc_pcm_runtime *rtd) |
| 67 | { |
Jean-Francois Moine | b367a32 | 2014-01-15 16:52:00 +0100 | [diff] [blame] | 68 | struct simple_card_data *priv = |
Xiubo Li | ba194a4 | 2014-01-13 17:08:08 +0800 | [diff] [blame] | 69 | snd_soc_card_get_drvdata(rtd->card); |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 70 | struct snd_soc_dai *codec = rtd->codec_dai; |
| 71 | struct snd_soc_dai *cpu = rtd->cpu_dai; |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 72 | int ret; |
| 73 | |
Xiubo Li | 30d0341 | 2014-01-24 15:43:01 +0800 | [diff] [blame] | 74 | ret = __asoc_simple_card_dai_init(codec, &priv->codec_dai); |
Kuninori Morimoto | a4a2992 | 2013-01-10 16:49:11 -0800 | [diff] [blame] | 75 | if (ret < 0) |
| 76 | return ret; |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 77 | |
Xiubo Li | 30d0341 | 2014-01-24 15:43:01 +0800 | [diff] [blame] | 78 | ret = __asoc_simple_card_dai_init(cpu, &priv->cpu_dai); |
Kuninori Morimoto | a4a2992 | 2013-01-10 16:49:11 -0800 | [diff] [blame] | 79 | if (ret < 0) |
| 80 | return ret; |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 81 | |
| 82 | return 0; |
| 83 | } |
| 84 | |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 85 | static int |
| 86 | asoc_simple_card_sub_parse_of(struct device_node *np, |
Xiubo Li | 30d0341 | 2014-01-24 15:43:01 +0800 | [diff] [blame] | 87 | unsigned int daifmt, |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 88 | struct asoc_simple_dai *dai, |
Jean-Francois Moine | 5200847 | 2014-01-15 16:51:48 +0100 | [diff] [blame] | 89 | const struct device_node **p_node, |
| 90 | const char **name) |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 91 | { |
Jean-Francois Moine | 201a0ea | 2014-01-15 16:51:41 +0100 | [diff] [blame] | 92 | struct device_node *node; |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 93 | struct clk *clk; |
| 94 | int ret; |
| 95 | |
| 96 | /* |
| 97 | * get node via "sound-dai = <&phandle port>" |
| 98 | * it will be used as xxx_of_node on soc_bind_dai_link() |
| 99 | */ |
Jean-Francois Moine | 201a0ea | 2014-01-15 16:51:41 +0100 | [diff] [blame] | 100 | node = of_parse_phandle(np, "sound-dai", 0); |
| 101 | if (!node) |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 102 | return -ENODEV; |
Jean-Francois Moine | 201a0ea | 2014-01-15 16:51:41 +0100 | [diff] [blame] | 103 | *p_node = node; |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 104 | |
| 105 | /* get dai->name */ |
Jean-Francois Moine | 5200847 | 2014-01-15 16:51:48 +0100 | [diff] [blame] | 106 | ret = snd_soc_of_get_dai_name(np, name); |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 107 | if (ret < 0) |
| 108 | goto parse_error; |
| 109 | |
Xiubo Li | 6ff62ee | 2014-02-14 09:34:36 +0800 | [diff] [blame] | 110 | /* parse TDM slot */ |
| 111 | ret = snd_soc_of_parse_tdm_slot(np, &dai->slots, &dai->slot_width); |
| 112 | if (ret) |
| 113 | goto parse_error; |
| 114 | |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 115 | /* |
| 116 | * bitclock-inversion, frame-inversion |
| 117 | * bitclock-master, frame-master |
| 118 | * and specific "format" if it has |
| 119 | */ |
| 120 | dai->fmt = snd_soc_of_parse_daifmt(np, NULL); |
Xiubo Li | 30d0341 | 2014-01-24 15:43:01 +0800 | [diff] [blame] | 121 | dai->fmt |= daifmt; |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 122 | |
| 123 | /* |
| 124 | * dai->sysclk come from |
| 125 | * "clocks = <&xxx>" (if system has common clock) |
| 126 | * or "system-clock-frequency = <xxx>" |
Xiubo Li | 71467e4 | 2013-12-23 15:25:38 +0800 | [diff] [blame] | 127 | * or device's module clock. |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 128 | */ |
Xiubo Li | 71467e4 | 2013-12-23 15:25:38 +0800 | [diff] [blame] | 129 | if (of_property_read_bool(np, "clocks")) { |
| 130 | clk = of_clk_get(np, 0); |
| 131 | if (IS_ERR(clk)) { |
| 132 | ret = PTR_ERR(clk); |
| 133 | goto parse_error; |
| 134 | } |
| 135 | |
| 136 | dai->sysclk = clk_get_rate(clk); |
| 137 | } else if (of_property_read_bool(np, "system-clock-frequency")) { |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 138 | of_property_read_u32(np, |
| 139 | "system-clock-frequency", |
| 140 | &dai->sysclk); |
Xiubo Li | 71467e4 | 2013-12-23 15:25:38 +0800 | [diff] [blame] | 141 | } else { |
Jean-Francois Moine | 201a0ea | 2014-01-15 16:51:41 +0100 | [diff] [blame] | 142 | clk = of_clk_get(node, 0); |
Xiubo Li | e2a19ac | 2014-01-06 12:34:36 +0800 | [diff] [blame] | 143 | if (!IS_ERR(clk)) |
| 144 | dai->sysclk = clk_get_rate(clk); |
Xiubo Li | 71467e4 | 2013-12-23 15:25:38 +0800 | [diff] [blame] | 145 | } |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 146 | |
| 147 | ret = 0; |
| 148 | |
| 149 | parse_error: |
Jean-Francois Moine | 201a0ea | 2014-01-15 16:51:41 +0100 | [diff] [blame] | 150 | of_node_put(node); |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 151 | |
| 152 | return ret; |
| 153 | } |
| 154 | |
| 155 | static int asoc_simple_card_parse_of(struct device_node *node, |
Jean-Francois Moine | b367a32 | 2014-01-15 16:52:00 +0100 | [diff] [blame] | 156 | struct simple_card_data *priv, |
Jean-Francois Moine | 201a0ea | 2014-01-15 16:51:41 +0100 | [diff] [blame] | 157 | struct device *dev) |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 158 | { |
Jean-Francois Moine | b367a32 | 2014-01-15 16:52:00 +0100 | [diff] [blame] | 159 | struct snd_soc_dai_link *dai_link = priv->snd_card.dai_link; |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 160 | struct device_node *np; |
| 161 | char *name; |
Xiubo Li | d4c2209 | 2013-12-23 12:57:01 +0800 | [diff] [blame] | 162 | int ret; |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 163 | |
Xiubo Li | 2772555 | 2014-01-24 15:43:02 +0800 | [diff] [blame] | 164 | /* parsing the card name from DT */ |
| 165 | snd_soc_of_parse_card_name(&priv->snd_card, "simple-audio-card,name"); |
| 166 | |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 167 | /* get CPU/CODEC common format via simple-audio-card,format */ |
Jean-Francois Moine | b367a32 | 2014-01-15 16:52:00 +0100 | [diff] [blame] | 168 | priv->daifmt = snd_soc_of_parse_daifmt(node, "simple-audio-card,") & |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 169 | (SND_SOC_DAIFMT_FORMAT_MASK | SND_SOC_DAIFMT_INV_MASK); |
| 170 | |
Xiubo Li | 9d681f5 | 2014-02-08 15:59:53 +0800 | [diff] [blame] | 171 | /* off-codec widgets */ |
| 172 | if (of_property_read_bool(node, "simple-audio-card,widgets")) { |
| 173 | ret = snd_soc_of_parse_audio_simple_widgets(&priv->snd_card, |
| 174 | "simple-audio-card,widgets"); |
| 175 | if (ret) |
| 176 | return ret; |
| 177 | } |
| 178 | |
Xiubo Li | d4c2209 | 2013-12-23 12:57:01 +0800 | [diff] [blame] | 179 | /* DAPM routes */ |
Xiubo Li | 8c0b823 | 2014-01-07 09:15:16 +0800 | [diff] [blame] | 180 | if (of_property_read_bool(node, "simple-audio-card,routing")) { |
Jean-Francois Moine | b367a32 | 2014-01-15 16:52:00 +0100 | [diff] [blame] | 181 | ret = snd_soc_of_parse_audio_routing(&priv->snd_card, |
Xiubo Li | 8c0b823 | 2014-01-07 09:15:16 +0800 | [diff] [blame] | 182 | "simple-audio-card,routing"); |
Xiubo Li | f87a3e8 | 2014-01-07 09:13:42 +0800 | [diff] [blame] | 183 | if (ret) |
| 184 | return ret; |
| 185 | } |
Xiubo Li | d4c2209 | 2013-12-23 12:57:01 +0800 | [diff] [blame] | 186 | |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 187 | /* CPU sub-node */ |
| 188 | ret = -EINVAL; |
| 189 | np = of_get_child_by_name(node, "simple-audio-card,cpu"); |
| 190 | if (np) |
Xiubo Li | 30d0341 | 2014-01-24 15:43:01 +0800 | [diff] [blame] | 191 | ret = asoc_simple_card_sub_parse_of(np, priv->daifmt, |
Jean-Francois Moine | b367a32 | 2014-01-15 16:52:00 +0100 | [diff] [blame] | 192 | &priv->cpu_dai, |
Jean-Francois Moine | 5200847 | 2014-01-15 16:51:48 +0100 | [diff] [blame] | 193 | &dai_link->cpu_of_node, |
| 194 | &dai_link->cpu_dai_name); |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 195 | if (ret < 0) |
| 196 | return ret; |
| 197 | |
| 198 | /* CODEC sub-node */ |
| 199 | ret = -EINVAL; |
| 200 | np = of_get_child_by_name(node, "simple-audio-card,codec"); |
| 201 | if (np) |
Xiubo Li | 30d0341 | 2014-01-24 15:43:01 +0800 | [diff] [blame] | 202 | ret = asoc_simple_card_sub_parse_of(np, priv->daifmt, |
Jean-Francois Moine | b367a32 | 2014-01-15 16:52:00 +0100 | [diff] [blame] | 203 | &priv->codec_dai, |
Jean-Francois Moine | 5200847 | 2014-01-15 16:51:48 +0100 | [diff] [blame] | 204 | &dai_link->codec_of_node, |
| 205 | &dai_link->codec_dai_name); |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 206 | if (ret < 0) |
| 207 | return ret; |
| 208 | |
Jean-Francois Moine | 5200847 | 2014-01-15 16:51:48 +0100 | [diff] [blame] | 209 | if (!dai_link->cpu_dai_name || !dai_link->codec_dai_name) |
Xiubo Li | dd41e0c | 2013-12-20 14:39:50 +0800 | [diff] [blame] | 210 | return -EINVAL; |
| 211 | |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 212 | /* card name is created from CPU/CODEC dai name */ |
| 213 | name = devm_kzalloc(dev, |
Jean-Francois Moine | 5200847 | 2014-01-15 16:51:48 +0100 | [diff] [blame] | 214 | strlen(dai_link->cpu_dai_name) + |
| 215 | strlen(dai_link->codec_dai_name) + 2, |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 216 | GFP_KERNEL); |
Jean-Francois Moine | 5200847 | 2014-01-15 16:51:48 +0100 | [diff] [blame] | 217 | sprintf(name, "%s-%s", dai_link->cpu_dai_name, |
| 218 | dai_link->codec_dai_name); |
Xiubo Li | 2772555 | 2014-01-24 15:43:02 +0800 | [diff] [blame] | 219 | if (!priv->snd_card.name) |
| 220 | priv->snd_card.name = name; |
Jean-Francois Moine | 5ca8ba4 | 2014-01-15 16:51:45 +0100 | [diff] [blame] | 221 | dai_link->name = dai_link->stream_name = name; |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 222 | |
| 223 | /* simple-card assumes platform == cpu */ |
Jean-Francois Moine | 5ca8ba4 | 2014-01-15 16:51:45 +0100 | [diff] [blame] | 224 | dai_link->platform_of_node = dai_link->cpu_of_node; |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 225 | |
Jean-Francois Moine | 2bee991 | 2014-01-15 16:51:37 +0100 | [diff] [blame] | 226 | dev_dbg(dev, "card-name : %s\n", name); |
Jean-Francois Moine | b367a32 | 2014-01-15 16:52:00 +0100 | [diff] [blame] | 227 | dev_dbg(dev, "platform : %04x\n", priv->daifmt); |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 228 | dev_dbg(dev, "cpu : %s / %04x / %d\n", |
Jean-Francois Moine | 5200847 | 2014-01-15 16:51:48 +0100 | [diff] [blame] | 229 | dai_link->cpu_dai_name, |
Jean-Francois Moine | b367a32 | 2014-01-15 16:52:00 +0100 | [diff] [blame] | 230 | priv->cpu_dai.fmt, |
| 231 | priv->cpu_dai.sysclk); |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 232 | dev_dbg(dev, "codec : %s / %04x / %d\n", |
Jean-Francois Moine | 5200847 | 2014-01-15 16:51:48 +0100 | [diff] [blame] | 233 | dai_link->codec_dai_name, |
Jean-Francois Moine | b367a32 | 2014-01-15 16:52:00 +0100 | [diff] [blame] | 234 | priv->codec_dai.fmt, |
| 235 | priv->codec_dai.sysclk); |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 236 | |
Kuninori Morimoto | f687d90 | 2014-02-27 18:25:24 -0800 | [diff] [blame] | 237 | /* |
| 238 | * soc_bind_dai_link() will check cpu name |
| 239 | * after of_node matching if dai_link has cpu_dai_name. |
| 240 | * but, it will never match if name was created by fmt_single_name() |
| 241 | * remove cpu_dai_name to escape name matching. |
| 242 | * see |
| 243 | * fmt_single_name() |
| 244 | * fmt_multiple_name() |
| 245 | */ |
| 246 | dai_link->cpu_dai_name = NULL; |
| 247 | |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 248 | return 0; |
| 249 | } |
| 250 | |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 251 | static int asoc_simple_card_probe(struct platform_device *pdev) |
| 252 | { |
Jean-Francois Moine | 45fce59 | 2014-01-15 16:51:56 +0100 | [diff] [blame] | 253 | struct simple_card_data *priv; |
Jean-Francois Moine | 5ca8ba4 | 2014-01-15 16:51:45 +0100 | [diff] [blame] | 254 | struct snd_soc_dai_link *dai_link; |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 255 | struct device_node *np = pdev->dev.of_node; |
Kuninori Morimoto | f89983e | 2012-12-25 22:52:33 -0800 | [diff] [blame] | 256 | struct device *dev = &pdev->dev; |
Xiubo Li | ca919fe | 2014-01-14 12:35:32 +0800 | [diff] [blame] | 257 | int ret; |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 258 | |
Jean-Francois Moine | ca65b49 | 2014-01-15 16:51:52 +0100 | [diff] [blame] | 259 | priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); |
| 260 | if (!priv) |
Xiubo Li | ca919fe | 2014-01-14 12:35:32 +0800 | [diff] [blame] | 261 | return -ENOMEM; |
| 262 | |
Jean-Francois Moine | 201a0ea | 2014-01-15 16:51:41 +0100 | [diff] [blame] | 263 | /* |
| 264 | * init snd_soc_card |
| 265 | */ |
Jean-Francois Moine | ca65b49 | 2014-01-15 16:51:52 +0100 | [diff] [blame] | 266 | priv->snd_card.owner = THIS_MODULE; |
| 267 | priv->snd_card.dev = dev; |
| 268 | dai_link = &priv->snd_link; |
| 269 | priv->snd_card.dai_link = dai_link; |
| 270 | priv->snd_card.num_links = 1; |
Xiubo Li | ca919fe | 2014-01-14 12:35:32 +0800 | [diff] [blame] | 271 | |
Jean-Francois Moine | 201a0ea | 2014-01-15 16:51:41 +0100 | [diff] [blame] | 272 | if (np && of_device_is_available(np)) { |
| 273 | |
Jean-Francois Moine | ca65b49 | 2014-01-15 16:51:52 +0100 | [diff] [blame] | 274 | ret = asoc_simple_card_parse_of(np, priv, dev); |
Xiubo Li | ca919fe | 2014-01-14 12:35:32 +0800 | [diff] [blame] | 275 | if (ret < 0) { |
| 276 | if (ret != -EPROBE_DEFER) |
| 277 | dev_err(dev, "parse error %d\n", ret); |
| 278 | return ret; |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 279 | } |
| 280 | } else { |
Jean-Francois Moine | ca65b49 | 2014-01-15 16:51:52 +0100 | [diff] [blame] | 281 | struct asoc_simple_card_info *cinfo; |
| 282 | |
| 283 | cinfo = dev->platform_data; |
| 284 | if (!cinfo) { |
Xiubo Li | 34787d0 | 2014-01-09 17:49:40 +0800 | [diff] [blame] | 285 | dev_err(dev, "no info for asoc-simple-card\n"); |
| 286 | return -EINVAL; |
| 287 | } |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 288 | |
Jean-Francois Moine | 7722f83 | 2014-01-15 16:51:33 +0100 | [diff] [blame] | 289 | if (!cinfo->name || |
| 290 | !cinfo->card || |
| 291 | !cinfo->codec_dai.name || |
| 292 | !cinfo->codec || |
| 293 | !cinfo->platform || |
| 294 | !cinfo->cpu_dai.name) { |
| 295 | dev_err(dev, "insufficient asoc_simple_card_info settings\n"); |
| 296 | return -EINVAL; |
| 297 | } |
Jean-Francois Moine | 2bee991 | 2014-01-15 16:51:37 +0100 | [diff] [blame] | 298 | |
Jean-Francois Moine | ca65b49 | 2014-01-15 16:51:52 +0100 | [diff] [blame] | 299 | priv->snd_card.name = cinfo->card; |
Jean-Francois Moine | 5ca8ba4 | 2014-01-15 16:51:45 +0100 | [diff] [blame] | 300 | dai_link->name = cinfo->name; |
| 301 | dai_link->stream_name = cinfo->name; |
| 302 | dai_link->platform_name = cinfo->platform; |
| 303 | dai_link->codec_name = cinfo->codec; |
Jean-Francois Moine | 5200847 | 2014-01-15 16:51:48 +0100 | [diff] [blame] | 304 | dai_link->cpu_dai_name = cinfo->cpu_dai.name; |
| 305 | dai_link->codec_dai_name = cinfo->codec_dai.name; |
Jean-Francois Moine | ca65b49 | 2014-01-15 16:51:52 +0100 | [diff] [blame] | 306 | memcpy(&priv->cpu_dai, &cinfo->cpu_dai, |
| 307 | sizeof(priv->cpu_dai)); |
| 308 | memcpy(&priv->codec_dai, &cinfo->codec_dai, |
| 309 | sizeof(priv->codec_dai)); |
Kuninori Morimoto | 81985bd | 2014-03-02 20:32:43 -0800 | [diff] [blame^] | 310 | |
| 311 | priv->cpu_dai.fmt |= cinfo->daifmt; |
| 312 | priv->codec_dai.fmt |= cinfo->daifmt; |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | /* |
| 316 | * init snd_soc_dai_link |
| 317 | */ |
Jean-Francois Moine | 5ca8ba4 | 2014-01-15 16:51:45 +0100 | [diff] [blame] | 318 | dai_link->init = asoc_simple_card_dai_init; |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 319 | |
Jean-Francois Moine | ca65b49 | 2014-01-15 16:51:52 +0100 | [diff] [blame] | 320 | snd_soc_card_set_drvdata(&priv->snd_card, priv); |
Xiubo Li | ba194a4 | 2014-01-13 17:08:08 +0800 | [diff] [blame] | 321 | |
Jean-Francois Moine | ca65b49 | 2014-01-15 16:51:52 +0100 | [diff] [blame] | 322 | return devm_snd_soc_register_card(&pdev->dev, &priv->snd_card); |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 323 | } |
| 324 | |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 325 | static const struct of_device_id asoc_simple_of_match[] = { |
| 326 | { .compatible = "simple-audio-card", }, |
| 327 | {}, |
| 328 | }; |
| 329 | MODULE_DEVICE_TABLE(of, asoc_simple_of_match); |
| 330 | |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 331 | static struct platform_driver asoc_simple_card = { |
| 332 | .driver = { |
| 333 | .name = "asoc-simple-card", |
Fabio Estevam | c445be3 | 2013-08-23 14:35:17 -0300 | [diff] [blame] | 334 | .owner = THIS_MODULE, |
Kuninori Morimoto | fa558c2 | 2013-11-20 15:25:02 +0900 | [diff] [blame] | 335 | .of_match_table = asoc_simple_of_match, |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 336 | }, |
| 337 | .probe = asoc_simple_card_probe, |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 338 | }; |
| 339 | |
| 340 | module_platform_driver(asoc_simple_card); |
| 341 | |
Fabio Estevam | c445be3 | 2013-08-23 14:35:17 -0300 | [diff] [blame] | 342 | MODULE_ALIAS("platform:asoc-simple-card"); |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 343 | MODULE_LICENSE("GPL"); |
| 344 | MODULE_DESCRIPTION("ASoC Simple Sound Card"); |
| 345 | MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>"); |