| .. | .. |
|---|
| 14 | 14 | #include <sound/jack.h> |
|---|
| 15 | 15 | #include <sound/simple_card_utils.h> |
|---|
| 16 | 16 | |
|---|
| 17 | | -void asoc_simple_card_convert_fixup(struct asoc_simple_card_data *data, |
|---|
| 18 | | - struct snd_pcm_hw_params *params) |
|---|
| 17 | +void asoc_simple_convert_fixup(struct asoc_simple_data *data, |
|---|
| 18 | + struct snd_pcm_hw_params *params) |
|---|
| 19 | 19 | { |
|---|
| 20 | 20 | struct snd_interval *rate = hw_param_interval(params, |
|---|
| 21 | 21 | SNDRV_PCM_HW_PARAM_RATE); |
|---|
| .. | .. |
|---|
| 30 | 30 | channels->min = |
|---|
| 31 | 31 | channels->max = data->convert_channels; |
|---|
| 32 | 32 | } |
|---|
| 33 | | -EXPORT_SYMBOL_GPL(asoc_simple_card_convert_fixup); |
|---|
| 33 | +EXPORT_SYMBOL_GPL(asoc_simple_convert_fixup); |
|---|
| 34 | 34 | |
|---|
| 35 | | -void asoc_simple_card_parse_convert(struct device *dev, char *prefix, |
|---|
| 36 | | - struct asoc_simple_card_data *data) |
|---|
| 35 | +void asoc_simple_parse_convert(struct device *dev, |
|---|
| 36 | + struct device_node *np, |
|---|
| 37 | + char *prefix, |
|---|
| 38 | + struct asoc_simple_data *data) |
|---|
| 37 | 39 | { |
|---|
| 38 | | - struct device_node *np = dev->of_node; |
|---|
| 39 | 40 | char prop[128]; |
|---|
| 40 | 41 | |
|---|
| 41 | 42 | if (!prefix) |
|---|
| .. | .. |
|---|
| 48 | 49 | /* channels transfer */ |
|---|
| 49 | 50 | snprintf(prop, sizeof(prop), "%s%s", prefix, "convert-channels"); |
|---|
| 50 | 51 | of_property_read_u32(np, prop, &data->convert_channels); |
|---|
| 51 | | - |
|---|
| 52 | | - dev_dbg(dev, "convert_rate %d\n", data->convert_rate); |
|---|
| 53 | | - dev_dbg(dev, "convert_channels %d\n", data->convert_channels); |
|---|
| 54 | 52 | } |
|---|
| 55 | | -EXPORT_SYMBOL_GPL(asoc_simple_card_parse_convert); |
|---|
| 53 | +EXPORT_SYMBOL_GPL(asoc_simple_parse_convert); |
|---|
| 56 | 54 | |
|---|
| 57 | | -int asoc_simple_card_parse_daifmt(struct device *dev, |
|---|
| 58 | | - struct device_node *node, |
|---|
| 59 | | - struct device_node *codec, |
|---|
| 60 | | - char *prefix, |
|---|
| 61 | | - unsigned int *retfmt) |
|---|
| 55 | +int asoc_simple_parse_daifmt(struct device *dev, |
|---|
| 56 | + struct device_node *node, |
|---|
| 57 | + struct device_node *codec, |
|---|
| 58 | + char *prefix, |
|---|
| 59 | + unsigned int *retfmt) |
|---|
| 62 | 60 | { |
|---|
| 63 | 61 | struct device_node *bitclkmaster = NULL; |
|---|
| 64 | 62 | struct device_node *framemaster = NULL; |
|---|
| .. | .. |
|---|
| 92 | 90 | |
|---|
| 93 | 91 | *retfmt = daifmt; |
|---|
| 94 | 92 | |
|---|
| 95 | | - dev_dbg(dev, "format : %04x\n", daifmt); |
|---|
| 96 | | - |
|---|
| 97 | 93 | return 0; |
|---|
| 98 | 94 | } |
|---|
| 99 | | -EXPORT_SYMBOL_GPL(asoc_simple_card_parse_daifmt); |
|---|
| 95 | +EXPORT_SYMBOL_GPL(asoc_simple_parse_daifmt); |
|---|
| 100 | 96 | |
|---|
| 101 | | -int asoc_simple_card_set_dailink_name(struct device *dev, |
|---|
| 102 | | - struct snd_soc_dai_link *dai_link, |
|---|
| 103 | | - const char *fmt, ...) |
|---|
| 97 | +int asoc_simple_set_dailink_name(struct device *dev, |
|---|
| 98 | + struct snd_soc_dai_link *dai_link, |
|---|
| 99 | + const char *fmt, ...) |
|---|
| 104 | 100 | { |
|---|
| 105 | 101 | va_list ap; |
|---|
| 106 | 102 | char *name = NULL; |
|---|
| .. | .. |
|---|
| 115 | 111 | |
|---|
| 116 | 112 | dai_link->name = name; |
|---|
| 117 | 113 | dai_link->stream_name = name; |
|---|
| 118 | | - |
|---|
| 119 | | - dev_dbg(dev, "name : %s\n", name); |
|---|
| 120 | 114 | } |
|---|
| 121 | 115 | |
|---|
| 122 | 116 | return ret; |
|---|
| 123 | 117 | } |
|---|
| 124 | | -EXPORT_SYMBOL_GPL(asoc_simple_card_set_dailink_name); |
|---|
| 118 | +EXPORT_SYMBOL_GPL(asoc_simple_set_dailink_name); |
|---|
| 125 | 119 | |
|---|
| 126 | | -int asoc_simple_card_parse_card_name(struct snd_soc_card *card, |
|---|
| 127 | | - char *prefix) |
|---|
| 120 | +int asoc_simple_parse_card_name(struct snd_soc_card *card, |
|---|
| 121 | + char *prefix) |
|---|
| 128 | 122 | { |
|---|
| 129 | 123 | int ret; |
|---|
| 130 | 124 | |
|---|
| .. | .. |
|---|
| 145 | 139 | if (!card->name && card->dai_link) |
|---|
| 146 | 140 | card->name = card->dai_link->name; |
|---|
| 147 | 141 | |
|---|
| 148 | | - dev_dbg(card->dev, "Card Name: %s\n", card->name ? card->name : ""); |
|---|
| 142 | + return 0; |
|---|
| 143 | +} |
|---|
| 144 | +EXPORT_SYMBOL_GPL(asoc_simple_parse_card_name); |
|---|
| 145 | + |
|---|
| 146 | +static int asoc_simple_clk_enable(struct asoc_simple_dai *dai) |
|---|
| 147 | +{ |
|---|
| 148 | + if (dai) |
|---|
| 149 | + return clk_prepare_enable(dai->clk); |
|---|
| 149 | 150 | |
|---|
| 150 | 151 | return 0; |
|---|
| 151 | 152 | } |
|---|
| 152 | | -EXPORT_SYMBOL_GPL(asoc_simple_card_parse_card_name); |
|---|
| 153 | 153 | |
|---|
| 154 | | -static void asoc_simple_card_clk_register(struct asoc_simple_dai *dai, |
|---|
| 155 | | - struct clk *clk) |
|---|
| 154 | +static void asoc_simple_clk_disable(struct asoc_simple_dai *dai) |
|---|
| 156 | 155 | { |
|---|
| 157 | | - dai->clk = clk; |
|---|
| 156 | + if (dai) |
|---|
| 157 | + clk_disable_unprepare(dai->clk); |
|---|
| 158 | 158 | } |
|---|
| 159 | 159 | |
|---|
| 160 | | -int asoc_simple_card_clk_enable(struct asoc_simple_dai *dai) |
|---|
| 161 | | -{ |
|---|
| 162 | | - return clk_prepare_enable(dai->clk); |
|---|
| 163 | | -} |
|---|
| 164 | | -EXPORT_SYMBOL_GPL(asoc_simple_card_clk_enable); |
|---|
| 165 | | - |
|---|
| 166 | | -void asoc_simple_card_clk_disable(struct asoc_simple_dai *dai) |
|---|
| 167 | | -{ |
|---|
| 168 | | - clk_disable_unprepare(dai->clk); |
|---|
| 169 | | -} |
|---|
| 170 | | -EXPORT_SYMBOL_GPL(asoc_simple_card_clk_disable); |
|---|
| 171 | | - |
|---|
| 172 | | -int asoc_simple_card_parse_clk(struct device *dev, |
|---|
| 173 | | - struct device_node *node, |
|---|
| 174 | | - struct device_node *dai_of_node, |
|---|
| 175 | | - struct asoc_simple_dai *simple_dai, |
|---|
| 176 | | - const char *name) |
|---|
| 160 | +int asoc_simple_parse_clk(struct device *dev, |
|---|
| 161 | + struct device_node *node, |
|---|
| 162 | + struct asoc_simple_dai *simple_dai, |
|---|
| 163 | + struct snd_soc_dai_link_component *dlc) |
|---|
| 177 | 164 | { |
|---|
| 178 | 165 | struct clk *clk; |
|---|
| 179 | 166 | u32 val; |
|---|
| .. | .. |
|---|
| 188 | 175 | if (!IS_ERR(clk)) { |
|---|
| 189 | 176 | simple_dai->sysclk = clk_get_rate(clk); |
|---|
| 190 | 177 | |
|---|
| 191 | | - asoc_simple_card_clk_register(simple_dai, clk); |
|---|
| 178 | + simple_dai->clk = clk; |
|---|
| 192 | 179 | } else if (!of_property_read_u32(node, "system-clock-frequency", &val)) { |
|---|
| 193 | 180 | simple_dai->sysclk = val; |
|---|
| 194 | 181 | } else { |
|---|
| 195 | | - clk = devm_get_clk_from_child(dev, dai_of_node, NULL); |
|---|
| 182 | + clk = devm_get_clk_from_child(dev, dlc->of_node, NULL); |
|---|
| 196 | 183 | if (!IS_ERR(clk)) |
|---|
| 197 | 184 | simple_dai->sysclk = clk_get_rate(clk); |
|---|
| 198 | 185 | } |
|---|
| .. | .. |
|---|
| 200 | 187 | if (of_property_read_bool(node, "system-clock-direction-out")) |
|---|
| 201 | 188 | simple_dai->clk_direction = SND_SOC_CLOCK_OUT; |
|---|
| 202 | 189 | |
|---|
| 203 | | - dev_dbg(dev, "%s : sysclk = %d, direction %d\n", name, |
|---|
| 204 | | - simple_dai->sysclk, simple_dai->clk_direction); |
|---|
| 205 | | - |
|---|
| 206 | 190 | return 0; |
|---|
| 207 | 191 | } |
|---|
| 208 | | -EXPORT_SYMBOL_GPL(asoc_simple_card_parse_clk); |
|---|
| 192 | +EXPORT_SYMBOL_GPL(asoc_simple_parse_clk); |
|---|
| 209 | 193 | |
|---|
| 210 | | -int asoc_simple_card_parse_dai(struct device_node *node, |
|---|
| 211 | | - struct device_node **dai_of_node, |
|---|
| 212 | | - const char **dai_name, |
|---|
| 213 | | - const char *list_name, |
|---|
| 214 | | - const char *cells_name, |
|---|
| 215 | | - int *is_single_link) |
|---|
| 194 | +int asoc_simple_startup(struct snd_pcm_substream *substream) |
|---|
| 216 | 195 | { |
|---|
| 217 | | - struct of_phandle_args args; |
|---|
| 196 | + struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
|---|
| 197 | + struct asoc_simple_priv *priv = snd_soc_card_get_drvdata(rtd->card); |
|---|
| 198 | + struct simple_dai_props *dai_props = simple_priv_to_props(priv, rtd->num); |
|---|
| 218 | 199 | int ret; |
|---|
| 219 | 200 | |
|---|
| 220 | | - if (!node) |
|---|
| 221 | | - return 0; |
|---|
| 222 | | - |
|---|
| 223 | | - /* |
|---|
| 224 | | - * Get node via "sound-dai = <&phandle port>" |
|---|
| 225 | | - * it will be used as xxx_of_node on soc_bind_dai_link() |
|---|
| 226 | | - */ |
|---|
| 227 | | - ret = of_parse_phandle_with_args(node, list_name, cells_name, 0, &args); |
|---|
| 201 | + ret = asoc_simple_clk_enable(dai_props->cpu_dai); |
|---|
| 228 | 202 | if (ret) |
|---|
| 229 | 203 | return ret; |
|---|
| 230 | 204 | |
|---|
| 231 | | - /* Get dai->name */ |
|---|
| 232 | | - if (dai_name) { |
|---|
| 233 | | - ret = snd_soc_of_get_dai_name(node, dai_name); |
|---|
| 205 | + ret = asoc_simple_clk_enable(dai_props->codec_dai); |
|---|
| 206 | + if (ret) |
|---|
| 207 | + asoc_simple_clk_disable(dai_props->cpu_dai); |
|---|
| 208 | + |
|---|
| 209 | + return ret; |
|---|
| 210 | +} |
|---|
| 211 | +EXPORT_SYMBOL_GPL(asoc_simple_startup); |
|---|
| 212 | + |
|---|
| 213 | +void asoc_simple_shutdown(struct snd_pcm_substream *substream) |
|---|
| 214 | +{ |
|---|
| 215 | + struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
|---|
| 216 | + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0); |
|---|
| 217 | + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0); |
|---|
| 218 | + struct asoc_simple_priv *priv = snd_soc_card_get_drvdata(rtd->card); |
|---|
| 219 | + struct simple_dai_props *dai_props = |
|---|
| 220 | + simple_priv_to_props(priv, rtd->num); |
|---|
| 221 | + |
|---|
| 222 | + if (dai_props->mclk_fs) { |
|---|
| 223 | + snd_soc_dai_set_sysclk(codec_dai, 0, 0, SND_SOC_CLOCK_IN); |
|---|
| 224 | + snd_soc_dai_set_sysclk(cpu_dai, 0, 0, SND_SOC_CLOCK_OUT); |
|---|
| 225 | + } |
|---|
| 226 | + |
|---|
| 227 | + asoc_simple_clk_disable(dai_props->cpu_dai); |
|---|
| 228 | + |
|---|
| 229 | + asoc_simple_clk_disable(dai_props->codec_dai); |
|---|
| 230 | +} |
|---|
| 231 | +EXPORT_SYMBOL_GPL(asoc_simple_shutdown); |
|---|
| 232 | + |
|---|
| 233 | +static int asoc_simple_set_clk_rate(struct asoc_simple_dai *simple_dai, |
|---|
| 234 | + unsigned long rate) |
|---|
| 235 | +{ |
|---|
| 236 | + if (!simple_dai) |
|---|
| 237 | + return 0; |
|---|
| 238 | + |
|---|
| 239 | + if (!simple_dai->clk) |
|---|
| 240 | + return 0; |
|---|
| 241 | + |
|---|
| 242 | + if (clk_get_rate(simple_dai->clk) == rate) |
|---|
| 243 | + return 0; |
|---|
| 244 | + |
|---|
| 245 | + return clk_set_rate(simple_dai->clk, rate); |
|---|
| 246 | +} |
|---|
| 247 | + |
|---|
| 248 | +int asoc_simple_hw_params(struct snd_pcm_substream *substream, |
|---|
| 249 | + struct snd_pcm_hw_params *params) |
|---|
| 250 | +{ |
|---|
| 251 | + struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
|---|
| 252 | + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0); |
|---|
| 253 | + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0); |
|---|
| 254 | + struct asoc_simple_priv *priv = snd_soc_card_get_drvdata(rtd->card); |
|---|
| 255 | + struct simple_dai_props *dai_props = |
|---|
| 256 | + simple_priv_to_props(priv, rtd->num); |
|---|
| 257 | + unsigned int mclk, mclk_fs = 0; |
|---|
| 258 | + int ret; |
|---|
| 259 | + |
|---|
| 260 | + if (dai_props->mclk_fs) |
|---|
| 261 | + mclk_fs = dai_props->mclk_fs; |
|---|
| 262 | + |
|---|
| 263 | + if (mclk_fs) { |
|---|
| 264 | + mclk = params_rate(params) * mclk_fs; |
|---|
| 265 | + |
|---|
| 266 | + ret = asoc_simple_set_clk_rate(dai_props->codec_dai, mclk); |
|---|
| 234 | 267 | if (ret < 0) |
|---|
| 235 | 268 | return ret; |
|---|
| 269 | + |
|---|
| 270 | + ret = asoc_simple_set_clk_rate(dai_props->cpu_dai, mclk); |
|---|
| 271 | + if (ret < 0) |
|---|
| 272 | + return ret; |
|---|
| 273 | + |
|---|
| 274 | + ret = snd_soc_dai_set_sysclk(codec_dai, 0, mclk, |
|---|
| 275 | + SND_SOC_CLOCK_IN); |
|---|
| 276 | + if (ret && ret != -ENOTSUPP) |
|---|
| 277 | + goto err; |
|---|
| 278 | + |
|---|
| 279 | + ret = snd_soc_dai_set_sysclk(cpu_dai, 0, mclk, |
|---|
| 280 | + SND_SOC_CLOCK_OUT); |
|---|
| 281 | + if (ret && ret != -ENOTSUPP) |
|---|
| 282 | + goto err; |
|---|
| 236 | 283 | } |
|---|
| 284 | + return 0; |
|---|
| 285 | +err: |
|---|
| 286 | + return ret; |
|---|
| 287 | +} |
|---|
| 288 | +EXPORT_SYMBOL_GPL(asoc_simple_hw_params); |
|---|
| 237 | 289 | |
|---|
| 238 | | - *dai_of_node = args.np; |
|---|
| 290 | +int asoc_simple_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, |
|---|
| 291 | + struct snd_pcm_hw_params *params) |
|---|
| 292 | +{ |
|---|
| 293 | + struct asoc_simple_priv *priv = snd_soc_card_get_drvdata(rtd->card); |
|---|
| 294 | + struct simple_dai_props *dai_props = simple_priv_to_props(priv, rtd->num); |
|---|
| 239 | 295 | |
|---|
| 240 | | - if (is_single_link) |
|---|
| 241 | | - *is_single_link = !args.args_count; |
|---|
| 296 | + asoc_simple_convert_fixup(&dai_props->adata, params); |
|---|
| 242 | 297 | |
|---|
| 243 | 298 | return 0; |
|---|
| 244 | 299 | } |
|---|
| 245 | | -EXPORT_SYMBOL_GPL(asoc_simple_card_parse_dai); |
|---|
| 300 | +EXPORT_SYMBOL_GPL(asoc_simple_be_hw_params_fixup); |
|---|
| 246 | 301 | |
|---|
| 247 | | -static int asoc_simple_card_get_dai_id(struct device_node *ep) |
|---|
| 302 | +static int asoc_simple_init_dai(struct snd_soc_dai *dai, |
|---|
| 303 | + struct asoc_simple_dai *simple_dai) |
|---|
| 248 | 304 | { |
|---|
| 249 | | - struct device_node *node; |
|---|
| 250 | | - struct device_node *endpoint; |
|---|
| 251 | | - int i, id; |
|---|
| 252 | 305 | int ret; |
|---|
| 253 | 306 | |
|---|
| 254 | | - ret = snd_soc_get_dai_id(ep); |
|---|
| 255 | | - if (ret != -ENOTSUPP) |
|---|
| 256 | | - return ret; |
|---|
| 257 | | - |
|---|
| 258 | | - node = of_graph_get_port_parent(ep); |
|---|
| 259 | | - |
|---|
| 260 | | - /* |
|---|
| 261 | | - * Non HDMI sound case, counting port/endpoint on its DT |
|---|
| 262 | | - * is enough. Let's count it. |
|---|
| 263 | | - */ |
|---|
| 264 | | - i = 0; |
|---|
| 265 | | - id = -1; |
|---|
| 266 | | - for_each_endpoint_of_node(node, endpoint) { |
|---|
| 267 | | - if (endpoint == ep) |
|---|
| 268 | | - id = i; |
|---|
| 269 | | - i++; |
|---|
| 270 | | - } |
|---|
| 271 | | - |
|---|
| 272 | | - of_node_put(node); |
|---|
| 273 | | - |
|---|
| 274 | | - if (id < 0) |
|---|
| 275 | | - return -ENODEV; |
|---|
| 276 | | - |
|---|
| 277 | | - return id; |
|---|
| 278 | | -} |
|---|
| 279 | | - |
|---|
| 280 | | -int asoc_simple_card_parse_graph_dai(struct device_node *ep, |
|---|
| 281 | | - struct device_node **dai_of_node, |
|---|
| 282 | | - const char **dai_name) |
|---|
| 283 | | -{ |
|---|
| 284 | | - struct device_node *node; |
|---|
| 285 | | - struct of_phandle_args args; |
|---|
| 286 | | - int ret; |
|---|
| 287 | | - |
|---|
| 288 | | - if (!ep) |
|---|
| 307 | + if (!simple_dai) |
|---|
| 289 | 308 | return 0; |
|---|
| 290 | | - if (!dai_name) |
|---|
| 291 | | - return 0; |
|---|
| 292 | | - |
|---|
| 293 | | - node = of_graph_get_port_parent(ep); |
|---|
| 294 | | - |
|---|
| 295 | | - /* Get dai->name */ |
|---|
| 296 | | - args.np = node; |
|---|
| 297 | | - args.args[0] = asoc_simple_card_get_dai_id(ep); |
|---|
| 298 | | - args.args_count = (of_graph_get_endpoint_count(node) > 1); |
|---|
| 299 | | - |
|---|
| 300 | | - ret = snd_soc_get_dai_name(&args, dai_name); |
|---|
| 301 | | - if (ret < 0) |
|---|
| 302 | | - return ret; |
|---|
| 303 | | - |
|---|
| 304 | | - *dai_of_node = node; |
|---|
| 305 | | - |
|---|
| 306 | | - return 0; |
|---|
| 307 | | -} |
|---|
| 308 | | -EXPORT_SYMBOL_GPL(asoc_simple_card_parse_graph_dai); |
|---|
| 309 | | - |
|---|
| 310 | | -int asoc_simple_card_init_dai(struct snd_soc_dai *dai, |
|---|
| 311 | | - struct asoc_simple_dai *simple_dai) |
|---|
| 312 | | -{ |
|---|
| 313 | | - int ret; |
|---|
| 314 | 309 | |
|---|
| 315 | 310 | if (simple_dai->sysclk) { |
|---|
| 316 | 311 | ret = snd_soc_dai_set_sysclk(dai, 0, simple_dai->sysclk, |
|---|
| .. | .. |
|---|
| 335 | 330 | |
|---|
| 336 | 331 | return 0; |
|---|
| 337 | 332 | } |
|---|
| 338 | | -EXPORT_SYMBOL_GPL(asoc_simple_card_init_dai); |
|---|
| 339 | 333 | |
|---|
| 340 | | -int asoc_simple_card_canonicalize_dailink(struct snd_soc_dai_link *dai_link) |
|---|
| 334 | +static int asoc_simple_init_dai_link_params(struct snd_soc_pcm_runtime *rtd, |
|---|
| 335 | + struct simple_dai_props *dai_props) |
|---|
| 341 | 336 | { |
|---|
| 342 | | - /* Assumes platform == cpu */ |
|---|
| 343 | | - if (!dai_link->platform_of_node) |
|---|
| 344 | | - dai_link->platform_of_node = dai_link->cpu_of_node; |
|---|
| 337 | + struct snd_soc_dai_link *dai_link = rtd->dai_link; |
|---|
| 338 | + struct snd_soc_component *component; |
|---|
| 339 | + struct snd_soc_pcm_stream *params; |
|---|
| 340 | + struct snd_pcm_hardware hw; |
|---|
| 341 | + int i, ret, stream; |
|---|
| 342 | + |
|---|
| 343 | + /* Only codecs should have non_legacy_dai_naming set. */ |
|---|
| 344 | + for_each_rtd_components(rtd, i, component) { |
|---|
| 345 | + if (!component->driver->non_legacy_dai_naming) |
|---|
| 346 | + return 0; |
|---|
| 347 | + } |
|---|
| 348 | + |
|---|
| 349 | + /* Assumes the capabilities are the same for all supported streams */ |
|---|
| 350 | + for_each_pcm_streams(stream) { |
|---|
| 351 | + ret = snd_soc_runtime_calc_hw(rtd, &hw, stream); |
|---|
| 352 | + if (ret == 0) |
|---|
| 353 | + break; |
|---|
| 354 | + } |
|---|
| 355 | + |
|---|
| 356 | + if (ret < 0) { |
|---|
| 357 | + dev_err(rtd->dev, "simple-card: no valid dai_link params\n"); |
|---|
| 358 | + return ret; |
|---|
| 359 | + } |
|---|
| 360 | + |
|---|
| 361 | + params = devm_kzalloc(rtd->dev, sizeof(*params), GFP_KERNEL); |
|---|
| 362 | + if (!params) |
|---|
| 363 | + return -ENOMEM; |
|---|
| 364 | + |
|---|
| 365 | + params->formats = hw.formats; |
|---|
| 366 | + params->rates = hw.rates; |
|---|
| 367 | + params->rate_min = hw.rate_min; |
|---|
| 368 | + params->rate_max = hw.rate_max; |
|---|
| 369 | + params->channels_min = hw.channels_min; |
|---|
| 370 | + params->channels_max = hw.channels_max; |
|---|
| 371 | + |
|---|
| 372 | + dai_link->params = params; |
|---|
| 373 | + dai_link->num_params = 1; |
|---|
| 345 | 374 | |
|---|
| 346 | 375 | return 0; |
|---|
| 347 | 376 | } |
|---|
| 348 | | -EXPORT_SYMBOL_GPL(asoc_simple_card_canonicalize_dailink); |
|---|
| 349 | 377 | |
|---|
| 350 | | -void asoc_simple_card_canonicalize_cpu(struct snd_soc_dai_link *dai_link, |
|---|
| 351 | | - int is_single_links) |
|---|
| 378 | +int asoc_simple_dai_init(struct snd_soc_pcm_runtime *rtd) |
|---|
| 379 | +{ |
|---|
| 380 | + struct asoc_simple_priv *priv = snd_soc_card_get_drvdata(rtd->card); |
|---|
| 381 | + struct simple_dai_props *dai_props = simple_priv_to_props(priv, rtd->num); |
|---|
| 382 | + int ret; |
|---|
| 383 | + |
|---|
| 384 | + ret = asoc_simple_init_dai(asoc_rtd_to_codec(rtd, 0), |
|---|
| 385 | + dai_props->codec_dai); |
|---|
| 386 | + if (ret < 0) |
|---|
| 387 | + return ret; |
|---|
| 388 | + |
|---|
| 389 | + ret = asoc_simple_init_dai(asoc_rtd_to_cpu(rtd, 0), |
|---|
| 390 | + dai_props->cpu_dai); |
|---|
| 391 | + if (ret < 0) |
|---|
| 392 | + return ret; |
|---|
| 393 | + |
|---|
| 394 | + ret = asoc_simple_init_dai_link_params(rtd, dai_props); |
|---|
| 395 | + if (ret < 0) |
|---|
| 396 | + return ret; |
|---|
| 397 | + |
|---|
| 398 | + return 0; |
|---|
| 399 | +} |
|---|
| 400 | +EXPORT_SYMBOL_GPL(asoc_simple_dai_init); |
|---|
| 401 | + |
|---|
| 402 | +void asoc_simple_canonicalize_platform(struct snd_soc_dai_link *dai_link) |
|---|
| 403 | +{ |
|---|
| 404 | + /* Assumes platform == cpu */ |
|---|
| 405 | + if (!dai_link->platforms->of_node) |
|---|
| 406 | + dai_link->platforms->of_node = dai_link->cpus->of_node; |
|---|
| 407 | + |
|---|
| 408 | + /* |
|---|
| 409 | + * DPCM BE can be no platform. |
|---|
| 410 | + * Alloced memory will be waste, but not leak. |
|---|
| 411 | + */ |
|---|
| 412 | + if (!dai_link->platforms->of_node) |
|---|
| 413 | + dai_link->num_platforms = 0; |
|---|
| 414 | +} |
|---|
| 415 | +EXPORT_SYMBOL_GPL(asoc_simple_canonicalize_platform); |
|---|
| 416 | + |
|---|
| 417 | +void asoc_simple_canonicalize_cpu(struct snd_soc_dai_link *dai_link, |
|---|
| 418 | + int is_single_links) |
|---|
| 352 | 419 | { |
|---|
| 353 | 420 | /* |
|---|
| 354 | 421 | * In soc_bind_dai_link() will check cpu name after |
|---|
| .. | .. |
|---|
| 360 | 427 | * fmt_multiple_name() |
|---|
| 361 | 428 | */ |
|---|
| 362 | 429 | if (is_single_links) |
|---|
| 363 | | - dai_link->cpu_dai_name = NULL; |
|---|
| 430 | + dai_link->cpus->dai_name = NULL; |
|---|
| 364 | 431 | } |
|---|
| 365 | | -EXPORT_SYMBOL_GPL(asoc_simple_card_canonicalize_cpu); |
|---|
| 432 | +EXPORT_SYMBOL_GPL(asoc_simple_canonicalize_cpu); |
|---|
| 366 | 433 | |
|---|
| 367 | | -int asoc_simple_card_clean_reference(struct snd_soc_card *card) |
|---|
| 434 | +int asoc_simple_clean_reference(struct snd_soc_card *card) |
|---|
| 368 | 435 | { |
|---|
| 369 | 436 | struct snd_soc_dai_link *dai_link; |
|---|
| 370 | | - int num_links; |
|---|
| 437 | + int i; |
|---|
| 371 | 438 | |
|---|
| 372 | | - for (num_links = 0, dai_link = card->dai_link; |
|---|
| 373 | | - num_links < card->num_links; |
|---|
| 374 | | - num_links++, dai_link++) { |
|---|
| 375 | | - of_node_put(dai_link->cpu_of_node); |
|---|
| 376 | | - of_node_put(dai_link->codec_of_node); |
|---|
| 439 | + for_each_card_prelinks(card, i, dai_link) { |
|---|
| 440 | + of_node_put(dai_link->cpus->of_node); |
|---|
| 441 | + of_node_put(dai_link->codecs->of_node); |
|---|
| 377 | 442 | } |
|---|
| 378 | 443 | return 0; |
|---|
| 379 | 444 | } |
|---|
| 380 | | -EXPORT_SYMBOL_GPL(asoc_simple_card_clean_reference); |
|---|
| 445 | +EXPORT_SYMBOL_GPL(asoc_simple_clean_reference); |
|---|
| 381 | 446 | |
|---|
| 382 | | -int asoc_simple_card_of_parse_routing(struct snd_soc_card *card, |
|---|
| 383 | | - char *prefix, |
|---|
| 384 | | - int optional) |
|---|
| 447 | +int asoc_simple_parse_routing(struct snd_soc_card *card, |
|---|
| 448 | + char *prefix) |
|---|
| 385 | 449 | { |
|---|
| 386 | 450 | struct device_node *node = card->dev->of_node; |
|---|
| 387 | 451 | char prop[128]; |
|---|
| .. | .. |
|---|
| 391 | 455 | |
|---|
| 392 | 456 | snprintf(prop, sizeof(prop), "%s%s", prefix, "routing"); |
|---|
| 393 | 457 | |
|---|
| 394 | | - if (!of_property_read_bool(node, prop)) { |
|---|
| 395 | | - if (optional) |
|---|
| 396 | | - return 0; |
|---|
| 397 | | - return -EINVAL; |
|---|
| 398 | | - } |
|---|
| 458 | + if (!of_property_read_bool(node, prop)) |
|---|
| 459 | + return 0; |
|---|
| 399 | 460 | |
|---|
| 400 | 461 | return snd_soc_of_parse_audio_routing(card, prop); |
|---|
| 401 | 462 | } |
|---|
| 402 | | -EXPORT_SYMBOL_GPL(asoc_simple_card_of_parse_routing); |
|---|
| 463 | +EXPORT_SYMBOL_GPL(asoc_simple_parse_routing); |
|---|
| 403 | 464 | |
|---|
| 404 | | -int asoc_simple_card_of_parse_widgets(struct snd_soc_card *card, |
|---|
| 405 | | - char *prefix) |
|---|
| 465 | +int asoc_simple_parse_widgets(struct snd_soc_card *card, |
|---|
| 466 | + char *prefix) |
|---|
| 406 | 467 | { |
|---|
| 407 | 468 | struct device_node *node = card->dev->of_node; |
|---|
| 408 | 469 | char prop[128]; |
|---|
| .. | .. |
|---|
| 418 | 479 | /* no widgets is not error */ |
|---|
| 419 | 480 | return 0; |
|---|
| 420 | 481 | } |
|---|
| 421 | | -EXPORT_SYMBOL_GPL(asoc_simple_card_of_parse_widgets); |
|---|
| 482 | +EXPORT_SYMBOL_GPL(asoc_simple_parse_widgets); |
|---|
| 422 | 483 | |
|---|
| 423 | | -int asoc_simple_card_init_jack(struct snd_soc_card *card, |
|---|
| 424 | | - struct asoc_simple_jack *sjack, |
|---|
| 425 | | - int is_hp, char *prefix) |
|---|
| 484 | +int asoc_simple_parse_pin_switches(struct snd_soc_card *card, |
|---|
| 485 | + char *prefix) |
|---|
| 486 | +{ |
|---|
| 487 | + const unsigned int nb_controls_max = 16; |
|---|
| 488 | + const char **strings, *control_name; |
|---|
| 489 | + struct snd_kcontrol_new *controls; |
|---|
| 490 | + struct device *dev = card->dev; |
|---|
| 491 | + unsigned int i, nb_controls; |
|---|
| 492 | + char prop[128]; |
|---|
| 493 | + int ret; |
|---|
| 494 | + |
|---|
| 495 | + if (!prefix) |
|---|
| 496 | + prefix = ""; |
|---|
| 497 | + |
|---|
| 498 | + snprintf(prop, sizeof(prop), "%s%s", prefix, "pin-switches"); |
|---|
| 499 | + |
|---|
| 500 | + if (!of_property_read_bool(dev->of_node, prop)) |
|---|
| 501 | + return 0; |
|---|
| 502 | + |
|---|
| 503 | + strings = devm_kcalloc(dev, nb_controls_max, |
|---|
| 504 | + sizeof(*strings), GFP_KERNEL); |
|---|
| 505 | + if (!strings) |
|---|
| 506 | + return -ENOMEM; |
|---|
| 507 | + |
|---|
| 508 | + ret = of_property_read_string_array(dev->of_node, prop, |
|---|
| 509 | + strings, nb_controls_max); |
|---|
| 510 | + if (ret < 0) |
|---|
| 511 | + return ret; |
|---|
| 512 | + |
|---|
| 513 | + nb_controls = (unsigned int)ret; |
|---|
| 514 | + |
|---|
| 515 | + controls = devm_kcalloc(dev, nb_controls, |
|---|
| 516 | + sizeof(*controls), GFP_KERNEL); |
|---|
| 517 | + if (!controls) |
|---|
| 518 | + return -ENOMEM; |
|---|
| 519 | + |
|---|
| 520 | + for (i = 0; i < nb_controls; i++) { |
|---|
| 521 | + control_name = devm_kasprintf(dev, GFP_KERNEL, |
|---|
| 522 | + "%s Switch", strings[i]); |
|---|
| 523 | + if (!control_name) |
|---|
| 524 | + return -ENOMEM; |
|---|
| 525 | + |
|---|
| 526 | + controls[i].iface = SNDRV_CTL_ELEM_IFACE_MIXER; |
|---|
| 527 | + controls[i].name = control_name; |
|---|
| 528 | + controls[i].info = snd_soc_dapm_info_pin_switch; |
|---|
| 529 | + controls[i].get = snd_soc_dapm_get_pin_switch; |
|---|
| 530 | + controls[i].put = snd_soc_dapm_put_pin_switch; |
|---|
| 531 | + controls[i].private_value = (unsigned long)strings[i]; |
|---|
| 532 | + } |
|---|
| 533 | + |
|---|
| 534 | + card->controls = controls; |
|---|
| 535 | + card->num_controls = nb_controls; |
|---|
| 536 | + |
|---|
| 537 | + return 0; |
|---|
| 538 | +} |
|---|
| 539 | +EXPORT_SYMBOL_GPL(asoc_simple_parse_pin_switches); |
|---|
| 540 | + |
|---|
| 541 | +int asoc_simple_init_jack(struct snd_soc_card *card, |
|---|
| 542 | + struct asoc_simple_jack *sjack, |
|---|
| 543 | + int is_hp, char *prefix, |
|---|
| 544 | + char *pin) |
|---|
| 426 | 545 | { |
|---|
| 427 | 546 | struct device *dev = card->dev; |
|---|
| 428 | 547 | enum of_gpio_flags flags; |
|---|
| .. | .. |
|---|
| 439 | 558 | |
|---|
| 440 | 559 | if (is_hp) { |
|---|
| 441 | 560 | snprintf(prop, sizeof(prop), "%shp-det-gpio", prefix); |
|---|
| 442 | | - pin_name = "Headphones"; |
|---|
| 561 | + pin_name = pin ? pin : "Headphones"; |
|---|
| 443 | 562 | gpio_name = "Headphone detection"; |
|---|
| 444 | 563 | mask = SND_JACK_HEADPHONE; |
|---|
| 445 | 564 | } else { |
|---|
| 446 | 565 | snprintf(prop, sizeof(prop), "%smic-det-gpio", prefix); |
|---|
| 447 | | - pin_name = "Mic Jack"; |
|---|
| 566 | + pin_name = pin ? pin : "Mic Jack"; |
|---|
| 448 | 567 | gpio_name = "Mic detection"; |
|---|
| 449 | 568 | mask = SND_JACK_MICROPHONE; |
|---|
| 450 | 569 | } |
|---|
| .. | .. |
|---|
| 473 | 592 | |
|---|
| 474 | 593 | return 0; |
|---|
| 475 | 594 | } |
|---|
| 476 | | -EXPORT_SYMBOL_GPL(asoc_simple_card_init_jack); |
|---|
| 595 | +EXPORT_SYMBOL_GPL(asoc_simple_init_jack); |
|---|
| 596 | + |
|---|
| 597 | +int asoc_simple_init_priv(struct asoc_simple_priv *priv, |
|---|
| 598 | + struct link_info *li) |
|---|
| 599 | +{ |
|---|
| 600 | + struct snd_soc_card *card = simple_priv_to_card(priv); |
|---|
| 601 | + struct device *dev = simple_priv_to_dev(priv); |
|---|
| 602 | + struct snd_soc_dai_link *dai_link; |
|---|
| 603 | + struct simple_dai_props *dai_props; |
|---|
| 604 | + struct asoc_simple_dai *dais; |
|---|
| 605 | + struct snd_soc_codec_conf *cconf = NULL; |
|---|
| 606 | + int i; |
|---|
| 607 | + |
|---|
| 608 | + dai_props = devm_kcalloc(dev, li->link, sizeof(*dai_props), GFP_KERNEL); |
|---|
| 609 | + dai_link = devm_kcalloc(dev, li->link, sizeof(*dai_link), GFP_KERNEL); |
|---|
| 610 | + dais = devm_kcalloc(dev, li->dais, sizeof(*dais), GFP_KERNEL); |
|---|
| 611 | + if (!dai_props || !dai_link || !dais) |
|---|
| 612 | + return -ENOMEM; |
|---|
| 613 | + |
|---|
| 614 | + if (li->conf) { |
|---|
| 615 | + cconf = devm_kcalloc(dev, li->conf, sizeof(*cconf), GFP_KERNEL); |
|---|
| 616 | + if (!cconf) |
|---|
| 617 | + return -ENOMEM; |
|---|
| 618 | + } |
|---|
| 619 | + |
|---|
| 620 | + /* |
|---|
| 621 | + * Use snd_soc_dai_link_component instead of legacy style |
|---|
| 622 | + * It is codec only. but cpu/platform will be supported in the future. |
|---|
| 623 | + * see |
|---|
| 624 | + * soc-core.c :: snd_soc_init_multicodec() |
|---|
| 625 | + * |
|---|
| 626 | + * "platform" might be removed |
|---|
| 627 | + * see |
|---|
| 628 | + * simple-card-utils.c :: asoc_simple_canonicalize_platform() |
|---|
| 629 | + */ |
|---|
| 630 | + for (i = 0; i < li->link; i++) { |
|---|
| 631 | + dai_link[i].cpus = &dai_props[i].cpus; |
|---|
| 632 | + dai_link[i].num_cpus = 1; |
|---|
| 633 | + dai_link[i].codecs = &dai_props[i].codecs; |
|---|
| 634 | + dai_link[i].num_codecs = 1; |
|---|
| 635 | + dai_link[i].platforms = &dai_props[i].platforms; |
|---|
| 636 | + dai_link[i].num_platforms = 1; |
|---|
| 637 | + } |
|---|
| 638 | + |
|---|
| 639 | + priv->dai_props = dai_props; |
|---|
| 640 | + priv->dai_link = dai_link; |
|---|
| 641 | + priv->dais = dais; |
|---|
| 642 | + priv->codec_conf = cconf; |
|---|
| 643 | + |
|---|
| 644 | + card->dai_link = priv->dai_link; |
|---|
| 645 | + card->num_links = li->link; |
|---|
| 646 | + card->codec_conf = cconf; |
|---|
| 647 | + card->num_configs = li->conf; |
|---|
| 648 | + |
|---|
| 649 | + return 0; |
|---|
| 650 | +} |
|---|
| 651 | +EXPORT_SYMBOL_GPL(asoc_simple_init_priv); |
|---|
| 477 | 652 | |
|---|
| 478 | 653 | /* Module information */ |
|---|
| 479 | 654 | MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>"); |
|---|