| 1 |
// SPDX-License-Identifier: GPL-2.0 |
| 2 |
// |
| 3 |
// ASoC audio graph sound card support |
| 4 |
// |
| 5 |
// Copyright (C) 2016 Renesas Solutions Corp. |
| 6 |
// Kuninori Morimoto <[email protected]> |
| 7 |
// |
| 8 |
// based on ${LINUX}/sound/soc/generic/simple-card.c |
| 9 |
|
| 10 |
#include <linux/cleanup.h> |
| 11 |
#include <linux/clk.h> |
| 12 |
#include <linux/device.h> |
| 13 |
#include <linux/gpio/consumer.h> |
| 14 |
#include <linux/module.h> |
| 15 |
#include <linux/of.h> |
| 16 |
#include <linux/of_graph.h> |
| 17 |
#include <linux/platform_device.h> |
| 18 |
#include <linux/string.h> |
| 19 |
#include <sound/graph_card.h> |
| 20 |
|
| 21 |
#define DPCM_SELECTABLE 1 |
| 22 |
|
| 23 |
#define graph_ret(priv, ret) _graph_ret(priv, __func__, ret) |
| 24 |
static inline int _graph_ret(struct simple_util_priv *priv, |
| 25 |
const char *func, int ret) |
| 26 |
{ |
| 27 |
return snd_soc_ret(simple_priv_to_dev(priv), ret, "at %s()\n", func); |
| 28 |
} |
| 29 |
|
| 30 |
#define ep_to_port(ep) of_get_parent(ep) |
| 31 |
static struct device_node *port_to_ports(struct device_node *port) |
| 32 |
{ |
| 33 |
struct device_node *ports = of_get_parent(port); |
| 34 |
|
| 35 |
if (!of_node_name_eq(ports, "ports")) { |
| 36 |
of_node_put(ports); |
| 37 |
return NULL; |
| 38 |
} |
| 39 |
return ports; |
| 40 |
} |
| 41 |
|
| 42 |
static int graph_outdrv_event(struct snd_soc_dapm_widget *w, |
| 43 |
struct snd_kcontrol *kcontrol, |
| 44 |
int event) |
| 45 |
{ |
| 46 |
struct snd_soc_card *card = snd_soc_dapm_to_card(w->dapm); |
| 47 |
struct simple_util_priv *priv = snd_soc_card_get_drvdata(card); |
| 48 |
|
| 49 |
switch (event) { |
| 50 |
case SND_SOC_DAPM_POST_PMU: |
| 51 |
gpiod_set_value_cansleep(priv->pa_gpio, 1); |
| 52 |
break; |
| 53 |
case SND_SOC_DAPM_PRE_PMD: |
| 54 |
gpiod_set_value_cansleep(priv->pa_gpio, 0); |
| 55 |
break; |
| 56 |
default: |
| 57 |
return -EINVAL; |
| 58 |
} |
| 59 |
|
| 60 |
return 0; |
| 61 |
} |
| 62 |
|
| 63 |
static const struct snd_soc_dapm_widget graph_dapm_widgets[] = { |
| 64 |
SND_SOC_DAPM_OUT_DRV_E("Amplifier", SND_SOC_NOPM, |
| 65 |
0, 0, NULL, 0, graph_outdrv_event, |
| 66 |
SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), |
| 67 |
}; |
| 68 |
|
| 69 |
static const struct snd_soc_ops graph_ops = { |
| 70 |
.startup = simple_util_startup, |
| 71 |
.shutdown = simple_util_shutdown, |
| 72 |
.hw_params = simple_util_hw_params, |
| 73 |
}; |
| 74 |
|
| 75 |
static bool soc_component_is_pcm(struct snd_soc_dai_link_component *dlc) |
| 76 |
{ |
| 77 |
struct snd_soc_dai *dai = snd_soc_find_dai_with_mutex(dlc); |
| 78 |
|
| 79 |
if (dai && (dai->component->driver->pcm_construct || |
| 80 |
dai->component->driver->pcm_new || |
| 81 |
(dai->driver->ops && dai->driver->ops->pcm_new))) |
| 82 |
return true; |
| 83 |
|
| 84 |
return false; |
| 85 |
} |
| 86 |
|
| 87 |
static void graph_parse_convert(struct device *dev, |
| 88 |
struct device_node *ep, |
| 89 |
struct simple_util_data *adata) |
| 90 |
{ |
| 91 |
struct device_node *top = dev->of_node; |
| 92 |
struct device_node *port __free(device_node) = ep_to_port(ep); |
| 93 |
struct device_node *ports __free(device_node) = port_to_ports(port); |
| 94 |
struct device_node *node __free(device_node) = of_graph_get_port_parent(ep); |
| 95 |
|
| 96 |
simple_util_parse_convert(top, NULL, adata); |
| 97 |
simple_util_parse_convert(ports, NULL, adata); |
| 98 |
simple_util_parse_convert(port, NULL, adata); |
| 99 |
simple_util_parse_convert(ep, NULL, adata); |
| 100 |
} |
| 101 |
|
| 102 |
static int graph_parse_node(struct simple_util_priv *priv, |
| 103 |
struct device_node *ep, |
| 104 |
struct link_info *li, |
| 105 |
int *cpu) |
| 106 |
{ |
| 107 |
struct device *dev = simple_priv_to_dev(priv); |
| 108 |
struct snd_soc_dai_link *dai_link = simple_priv_to_link(priv, li->link); |
| 109 |
struct simple_dai_props *dai_props = simple_priv_to_props(priv, li->link); |
| 110 |
struct snd_soc_dai_link_component *dlc; |
| 111 |
struct simple_util_dai *dai; |
| 112 |
int ret; |
| 113 |
|
| 114 |
if (cpu) { |
| 115 |
dlc = snd_soc_link_to_cpu(dai_link, 0); |
| 116 |
dai = simple_props_to_dai_cpu(dai_props, 0); |
| 117 |
} else { |
| 118 |
dlc = snd_soc_link_to_codec(dai_link, 0); |
| 119 |
dai = simple_props_to_dai_codec(dai_props, 0); |
| 120 |
} |
| 121 |
|
| 122 |
ret = graph_util_parse_dai(priv, ep, dlc, cpu); |
| 123 |
if (ret < 0) |
| 124 |
goto end; |
| 125 |
|
| 126 |
ret = simple_util_parse_tdm(ep, dai); |
| 127 |
if (ret < 0) |
| 128 |
goto end; |
| 129 |
|
| 130 |
ret = simple_util_parse_clk(dev, ep, dai, dlc); |
| 131 |
end: |
| 132 |
return graph_ret(priv, ret); |
| 133 |
} |
| 134 |
|
| 135 |
static int graph_link_init(struct simple_util_priv *priv, |
| 136 |
struct device_node *ep_cpu, |
| 137 |
struct device_node *ep_codec, |
| 138 |
struct link_info *li, |
| 139 |
char *name) |
| 140 |
{ |
| 141 |
struct device *dev = simple_priv_to_dev(priv); |
| 142 |
struct device_node *top = dev->of_node; |
| 143 |
struct snd_soc_dai_link *dai_link = simple_priv_to_link(priv, li->link); |
| 144 |
struct simple_dai_props *dai_props = simple_priv_to_props(priv, li->link); |
| 145 |
struct device_node *port_cpu __free(device_node) = ep_to_port(ep_cpu); |
| 146 |
struct device_node *port_codec __free(device_node) = ep_to_port(ep_codec); |
| 147 |
struct device_node *ports_cpu __free(device_node) = port_to_ports(port_cpu); |
| 148 |
struct device_node *ports_codec __free(device_node) = port_to_ports(port_codec); |
| 149 |
enum snd_soc_trigger_order trigger_start = SND_SOC_TRIGGER_ORDER_DEFAULT; |
| 150 |
enum snd_soc_trigger_order trigger_stop = SND_SOC_TRIGGER_ORDER_DEFAULT; |
| 151 |
bool playback_only = 0, capture_only = 0; |
| 152 |
int ret; |
| 153 |
|
| 154 |
ret = simple_util_parse_daifmt(dev, ep_cpu, ep_codec, |
| 155 |
NULL, &dai_link->dai_fmt); |
| 156 |
if (ret < 0) |
| 157 |
goto end; |
| 158 |
|
| 159 |
graph_util_parse_link_direction(top, &playback_only, &capture_only); |
| 160 |
graph_util_parse_link_direction(port_cpu, &playback_only, &capture_only); |
| 161 |
graph_util_parse_link_direction(port_codec, &playback_only, &capture_only); |
| 162 |
graph_util_parse_link_direction(ep_cpu, &playback_only, &capture_only); |
| 163 |
graph_util_parse_link_direction(ep_codec, &playback_only, &capture_only); |
| 164 |
|
| 165 |
of_property_read_u32(top, "mclk-fs", &dai_props->mclk_fs); |
| 166 |
of_property_read_u32(ports_cpu, "mclk-fs", &dai_props->mclk_fs); |
| 167 |
of_property_read_u32(ports_codec, "mclk-fs", &dai_props->mclk_fs); |
| 168 |
of_property_read_u32(port_cpu, "mclk-fs", &dai_props->mclk_fs); |
| 169 |
of_property_read_u32(port_codec, "mclk-fs", &dai_props->mclk_fs); |
| 170 |
of_property_read_u32(ep_cpu, "mclk-fs", &dai_props->mclk_fs); |
| 171 |
of_property_read_u32(ep_codec, "mclk-fs", &dai_props->mclk_fs); |
| 172 |
|
| 173 |
graph_util_parse_trigger_order(priv, top, &trigger_start, &trigger_stop); |
| 174 |
graph_util_parse_trigger_order(priv, ports_cpu, &trigger_start, &trigger_stop); |
| 175 |
graph_util_parse_trigger_order(priv, ports_codec, &trigger_start, &trigger_stop); |
| 176 |
graph_util_parse_trigger_order(priv, port_cpu, &trigger_start, &trigger_stop); |
| 177 |
graph_util_parse_trigger_order(priv, port_cpu, &trigger_start, &trigger_stop); |
| 178 |
graph_util_parse_trigger_order(priv, ep_cpu, &trigger_start, &trigger_stop); |
| 179 |
graph_util_parse_trigger_order(priv, ep_codec, &trigger_start, &trigger_stop); |
| 180 |
|
| 181 |
dai_link->playback_only = playback_only; |
| 182 |
dai_link->capture_only = capture_only; |
| 183 |
|
| 184 |
dai_link->trigger_start = trigger_start; |
| 185 |
dai_link->trigger_stop = trigger_stop; |
| 186 |
|
| 187 |
dai_link->init = simple_util_dai_init; |
| 188 |
dai_link->ops = &graph_ops; |
| 189 |
if (priv->ops) |
| 190 |
dai_link->ops = priv->ops; |
| 191 |
|
| 192 |
ret = simple_util_set_dailink_name(priv, dai_link, name); |
| 193 |
end: |
| 194 |
return graph_ret(priv, ret); |
| 195 |
} |
| 196 |
|
| 197 |
static int graph_dai_link_of_dpcm(struct simple_util_priv *priv, |
| 198 |
struct device_node *cpu_ep, |
| 199 |
struct device_node *codec_ep, |
| 200 |
struct link_info *li) |
| 201 |
{ |
| 202 |
struct device *dev = simple_priv_to_dev(priv); |
| 203 |
struct snd_soc_dai_link *dai_link = simple_priv_to_link(priv, li->link); |
| 204 |
struct simple_dai_props *dai_props = simple_priv_to_props(priv, li->link); |
| 205 |
struct device_node *top = dev->of_node; |
| 206 |
struct device_node *ep = li->cpu ? cpu_ep : codec_ep; |
| 207 |
char dai_name[64]; |
| 208 |
int ret; |
| 209 |
|
| 210 |
dev_dbg(dev, "link_of DPCM (%pOF)\n", ep); |
| 211 |
|
| 212 |
if (li->cpu) { |
| 213 |
struct snd_soc_card *card = simple_priv_to_card(priv); |
| 214 |
struct snd_soc_dai_link_component *cpus = snd_soc_link_to_cpu(dai_link, 0); |
| 215 |
struct snd_soc_dai_link_component *platforms = snd_soc_link_to_platform(dai_link, 0); |
| 216 |
int is_single_links = 0; |
| 217 |
|
| 218 |
/* Codec is dummy */ |
| 219 |
|
| 220 |
/* FE settings */ |
| 221 |
dai_link->dynamic = 1; |
| 222 |
dai_link->dpcm_merged_format = 1; |
| 223 |
|
| 224 |
ret = graph_parse_node(priv, cpu_ep, li, &is_single_links); |
| 225 |
if (ret) |
| 226 |
goto end; |
| 227 |
|
| 228 |
snprintf(dai_name, sizeof(dai_name), |
| 229 |
"fe.%pOFP.%s", cpus->of_node, cpus->dai_name); |
| 230 |
/* |
| 231 |
* In BE<->BE connections it is not required to create |
| 232 |
* PCM devices at CPU end of the dai link and thus 'no_pcm' |
| 233 |
* flag needs to be set. It is useful when there are many |
| 234 |
* BE components and some of these have to be connected to |
| 235 |
* form a valid audio path. |
| 236 |
* |
| 237 |
* For example: FE <-> BE1 <-> BE2 <-> ... <-> BEn where |
| 238 |
* there are 'n' BE components in the path. |
| 239 |
*/ |
| 240 |
if (card->component_chaining && !soc_component_is_pcm(cpus)) { |
| 241 |
dai_link->no_pcm = 1; |
| 242 |
dai_link->be_hw_params_fixup = simple_util_be_hw_params_fixup; |
| 243 |
} |
| 244 |
|
| 245 |
simple_util_canonicalize_cpu(cpus, is_single_links); |
| 246 |
simple_util_canonicalize_platform(platforms, cpus); |
| 247 |
} else { |
| 248 |
struct snd_soc_codec_conf *cconf = simple_props_to_codec_conf(dai_props, 0); |
| 249 |
struct snd_soc_dai_link_component *codecs = snd_soc_link_to_codec(dai_link, 0); |
| 250 |
|
| 251 |
/* CPU is dummy */ |
| 252 |
|
| 253 |
/* BE settings */ |
| 254 |
dai_link->no_pcm = 1; |
| 255 |
dai_link->be_hw_params_fixup = simple_util_be_hw_params_fixup; |
| 256 |
|
| 257 |
ret = graph_parse_node(priv, codec_ep, li, NULL); |
| 258 |
if (ret < 0) |
| 259 |
goto end; |
| 260 |
|
| 261 |
snprintf(dai_name, sizeof(dai_name), |
| 262 |
"be.%pOFP.%s", codecs->of_node, codecs->dai_name); |
| 263 |
|
| 264 |
/* check "prefix" from top node */ |
| 265 |
struct device_node *port __free(device_node) = ep_to_port(ep); |
| 266 |
struct device_node *ports __free(device_node) = port_to_ports(port); |
| 267 |
|
| 268 |
snd_soc_of_parse_node_prefix(top, cconf, codecs->of_node, "prefix"); |
| 269 |
snd_soc_of_parse_node_prefix(ports, cconf, codecs->of_node, "prefix"); |
| 270 |
snd_soc_of_parse_node_prefix(port, cconf, codecs->of_node, "prefix"); |
| 271 |
} |
| 272 |
|
| 273 |
graph_parse_convert(dev, ep, &dai_props->adata); |
| 274 |
|
| 275 |
ret = graph_link_init(priv, cpu_ep, codec_ep, li, dai_name); |
| 276 |
|
| 277 |
li->link++; |
| 278 |
end: |
| 279 |
return graph_ret(priv, ret); |
| 280 |
} |
| 281 |
|
| 282 |
static int graph_dai_link_of(struct simple_util_priv *priv, |
| 283 |
struct device_node *cpu_ep, |
| 284 |
struct device_node *codec_ep, |
| 285 |
struct link_info *li) |
| 286 |
{ |
| 287 |
struct device *dev = simple_priv_to_dev(priv); |
| 288 |
struct snd_soc_dai_link *dai_link = simple_priv_to_link(priv, li->link); |
| 289 |
struct snd_soc_dai_link_component *cpus = snd_soc_link_to_cpu(dai_link, 0); |
| 290 |
struct snd_soc_dai_link_component *codecs = snd_soc_link_to_codec(dai_link, 0); |
| 291 |
struct snd_soc_dai_link_component *platforms = snd_soc_link_to_platform(dai_link, 0); |
| 292 |
char dai_name[64]; |
| 293 |
int ret, is_single_links = 0; |
| 294 |
|
| 295 |
dev_dbg(dev, "link_of (%pOF)\n", cpu_ep); |
| 296 |
|
| 297 |
ret = graph_parse_node(priv, cpu_ep, li, &is_single_links); |
| 298 |
if (ret < 0) |
| 299 |
goto end; |
| 300 |
|
| 301 |
ret = graph_parse_node(priv, codec_ep, li, NULL); |
| 302 |
if (ret < 0) |
| 303 |
goto end; |
| 304 |
|
| 305 |
snprintf(dai_name, sizeof(dai_name), |
| 306 |
"%s-%s", cpus->dai_name, codecs->dai_name); |
| 307 |
|
| 308 |
simple_util_canonicalize_cpu(cpus, is_single_links); |
| 309 |
simple_util_canonicalize_platform(platforms, cpus); |
| 310 |
|
| 311 |
ret = graph_link_init(priv, cpu_ep, codec_ep, li, dai_name); |
| 312 |
if (ret < 0) |
| 313 |
goto end; |
| 314 |
|
| 315 |
li->link++; |
| 316 |
end: |
| 317 |
return graph_ret(priv, ret); |
| 318 |
} |
| 319 |
|
| 320 |
static inline bool parse_as_dpcm_link(struct simple_util_priv *priv, |
| 321 |
struct device_node *codec_port, |
| 322 |
struct simple_util_data *adata) |
| 323 |
{ |
| 324 |
if (priv->force_dpcm) |
| 325 |
return true; |
| 326 |
|
| 327 |
if (!priv->dpcm_selectable) |
| 328 |
return false; |
| 329 |
|
| 330 |
/* |
| 331 |
* It is DPCM |
| 332 |
* if Codec port has many endpoints, |
| 333 |
* or has convert-xxx property |
| 334 |
*/ |
| 335 |
if ((of_get_child_count(codec_port) > 1) || |
| 336 |
simple_util_is_convert_required(adata)) |
| 337 |
return true; |
| 338 |
|
| 339 |
return false; |
| 340 |
} |
| 341 |
|
| 342 |
static int __graph_for_each_link(struct simple_util_priv *priv, |
| 343 |
struct link_info *li, |
| 344 |
int (*func_noml)(struct simple_util_priv *priv, |
| 345 |
struct device_node *cpu_ep, |
| 346 |
struct device_node *codec_ep, |
| 347 |
struct link_info *li), |
| 348 |
int (*func_dpcm)(struct simple_util_priv *priv, |
| 349 |
struct device_node *cpu_ep, |
| 350 |
struct device_node *codec_ep, |
| 351 |
struct link_info *li)) |
| 352 |
{ |
| 353 |
struct of_phandle_iterator it; |
| 354 |
struct device *dev = simple_priv_to_dev(priv); |
| 355 |
struct device_node *node = dev->of_node; |
| 356 |
struct device_node *cpu_port; |
| 357 |
struct device_node *codec_port_old = NULL; |
| 358 |
struct simple_util_data adata; |
| 359 |
int rc, ret = 0; |
| 360 |
|
| 361 |
/* loop for all listed CPU port */ |
| 362 |
of_for_each_phandle(&it, rc, node, "dais", NULL, 0) { |
| 363 |
cpu_port = it.node; |
| 364 |
|
| 365 |
/* loop for all CPU endpoint */ |
| 366 |
for_each_of_graph_port_endpoint(cpu_port, cpu_ep) { |
| 367 |
/* get codec */ |
| 368 |
struct device_node *codec_ep __free(device_node) = of_graph_get_remote_endpoint(cpu_ep); |
| 369 |
struct device_node *codec_port __free(device_node) = ep_to_port(codec_ep); |
| 370 |
|
| 371 |
/* get convert-xxx property */ |
| 372 |
memset(&adata, 0, sizeof(adata)); |
| 373 |
graph_parse_convert(dev, codec_ep, &adata); |
| 374 |
graph_parse_convert(dev, cpu_ep, &adata); |
| 375 |
|
| 376 |
/* check if link requires DPCM parsing */ |
| 377 |
if (parse_as_dpcm_link(priv, codec_port, &adata)) { |
| 378 |
/* |
| 379 |
* Codec endpoint can be NULL for pluggable audio HW. |
| 380 |
* Platform DT can populate the Codec endpoint depending on the |
| 381 |
* plugged HW. |
| 382 |
*/ |
| 383 |
/* Do it all CPU endpoint, and 1st Codec endpoint */ |
| 384 |
if (li->cpu || |
| 385 |
((codec_port_old != codec_port) && codec_ep)) |
| 386 |
ret = func_dpcm(priv, cpu_ep, codec_ep, li); |
| 387 |
/* else normal sound */ |
| 388 |
} else { |
| 389 |
if (li->cpu) |
| 390 |
ret = func_noml(priv, cpu_ep, codec_ep, li); |
| 391 |
} |
| 392 |
|
| 393 |
if (ret < 0) |
| 394 |
goto end; |
| 395 |
|
| 396 |
codec_port_old = codec_port; |
| 397 |
} |
| 398 |
} |
| 399 |
end: |
| 400 |
return graph_ret(priv, ret); |
| 401 |
} |
| 402 |
|
| 403 |
static int graph_for_each_link(struct simple_util_priv *priv, |
| 404 |
struct link_info *li, |
| 405 |
int (*func_noml)(struct simple_util_priv *priv, |
| 406 |
struct device_node *cpu_ep, |
| 407 |
struct device_node *codec_ep, |
| 408 |
struct link_info *li), |
| 409 |
int (*func_dpcm)(struct simple_util_priv *priv, |
| 410 |
struct device_node *cpu_ep, |
| 411 |
struct device_node *codec_ep, |
| 412 |
struct link_info *li)) |
| 413 |
{ |
| 414 |
int ret; |
| 415 |
/* |
| 416 |
* Detect all CPU first, and Detect all Codec 2nd. |
| 417 |
* |
| 418 |
* In Normal sound case, all DAIs are detected |
| 419 |
* as "CPU-Codec". |
| 420 |
* |
| 421 |
* In DPCM sound case, |
| 422 |
* all CPUs are detected as "CPU-dummy", and |
| 423 |
* all Codecs are detected as "dummy-Codec". |
| 424 |
* To avoid random sub-device numbering, |
| 425 |
* detect "dummy-Codec" in last; |
| 426 |
*/ |
| 427 |
for (li->cpu = 1; li->cpu >= 0; li->cpu--) { |
| 428 |
ret = __graph_for_each_link(priv, li, func_noml, func_dpcm); |
| 429 |
if (ret < 0) |
| 430 |
break; |
| 431 |
} |
| 432 |
|
| 433 |
return graph_ret(priv, ret); |
| 434 |
} |
| 435 |
|
| 436 |
static int graph_count_noml(struct simple_util_priv *priv, |
| 437 |
struct device_node *cpu_ep, |
| 438 |
struct device_node *codec_ep, |
| 439 |
struct link_info *li) |
| 440 |
{ |
| 441 |
struct device *dev = simple_priv_to_dev(priv); |
| 442 |
int ret = -EINVAL; |
| 443 |
|
| 444 |
if (li->link >= SNDRV_MAX_LINKS) |
| 445 |
goto end; |
| 446 |
|
| 447 |
/* |
| 448 |
* DON'T REMOVE platforms |
| 449 |
* see |
| 450 |
* simple-card.c :: simple_count_noml() |
| 451 |
*/ |
| 452 |
li->num[li->link].cpus = 1; |
| 453 |
li->num[li->link].platforms = 1; |
| 454 |
|
| 455 |
li->num[li->link].codecs = 1; |
| 456 |
|
| 457 |
li->link += 1; /* 1xCPU-Codec */ |
| 458 |
|
| 459 |
dev_dbg(dev, "Count As Normal\n"); |
| 460 |
ret = 0; |
| 461 |
end: |
| 462 |
return graph_ret(priv, ret); |
| 463 |
} |
| 464 |
|
| 465 |
static int graph_count_dpcm(struct simple_util_priv *priv, |
| 466 |
struct device_node *cpu_ep, |
| 467 |
struct device_node *codec_ep, |
| 468 |
struct link_info *li) |
| 469 |
{ |
| 470 |
struct device *dev = simple_priv_to_dev(priv); |
| 471 |
int ret = -EINVAL; |
| 472 |
|
| 473 |
if (li->link >= SNDRV_MAX_LINKS) |
| 474 |
goto end; |
| 475 |
|
| 476 |
if (li->cpu) { |
| 477 |
/* |
| 478 |
* DON'T REMOVE platforms |
| 479 |
* see |
| 480 |
* simple-card.c :: simple_count_noml() |
| 481 |
*/ |
| 482 |
li->num[li->link].cpus = 1; |
| 483 |
li->num[li->link].platforms = 1; |
| 484 |
|
| 485 |
li->link++; /* 1xCPU-dummy */ |
| 486 |
} else { |
| 487 |
li->num[li->link].codecs = 1; |
| 488 |
|
| 489 |
li->link++; /* 1xdummy-Codec */ |
| 490 |
} |
| 491 |
|
| 492 |
dev_dbg(dev, "Count As DPCM\n"); |
| 493 |
ret = 0; |
| 494 |
end: |
| 495 |
return graph_ret(priv, ret); |
| 496 |
} |
| 497 |
|
| 498 |
static int graph_get_dais_count(struct simple_util_priv *priv, |
| 499 |
struct link_info *li) |
| 500 |
{ |
| 501 |
/* |
| 502 |
* link_num : number of links. |
| 503 |
* CPU-Codec / CPU-dummy / dummy-Codec |
| 504 |
* dais_num : number of DAIs |
| 505 |
* ccnf_num : number of codec_conf |
| 506 |
* same number for "dummy-Codec" |
| 507 |
* |
| 508 |
* ex1) |
| 509 |
* CPU0 --- Codec0 link : 5 |
| 510 |
* CPU1 --- Codec1 dais : 7 |
| 511 |
* CPU2 -/ ccnf : 1 |
| 512 |
* CPU3 --- Codec2 |
| 513 |
* |
| 514 |
* => 5 links = 2xCPU-Codec + 2xCPU-dummy + 1xdummy-Codec |
| 515 |
* => 7 DAIs = 4xCPU + 3xCodec |
| 516 |
* => 1 ccnf = 1xdummy-Codec |
| 517 |
* |
| 518 |
* ex2) |
| 519 |
* CPU0 --- Codec0 link : 5 |
| 520 |
* CPU1 --- Codec1 dais : 6 |
| 521 |
* CPU2 -/ ccnf : 1 |
| 522 |
* CPU3 -/ |
| 523 |
* |
| 524 |
* => 5 links = 1xCPU-Codec + 3xCPU-dummy + 1xdummy-Codec |
| 525 |
* => 6 DAIs = 4xCPU + 2xCodec |
| 526 |
* => 1 ccnf = 1xdummy-Codec |
| 527 |
* |
| 528 |
* ex3) |
| 529 |
* CPU0 --- Codec0 link : 6 |
| 530 |
* CPU1 -/ dais : 6 |
| 531 |
* CPU2 --- Codec1 ccnf : 2 |
| 532 |
* CPU3 -/ |
| 533 |
* |
| 534 |
* => 6 links = 0xCPU-Codec + 4xCPU-dummy + 2xdummy-Codec |
| 535 |
* => 6 DAIs = 4xCPU + 2xCodec |
| 536 |
* => 2 ccnf = 2xdummy-Codec |
| 537 |
* |
| 538 |
* ex4) |
| 539 |
* CPU0 --- Codec0 (convert-rate) link : 3 |
| 540 |
* CPU1 --- Codec1 dais : 4 |
| 541 |
* ccnf : 1 |
| 542 |
* |
| 543 |
* => 3 links = 1xCPU-Codec + 1xCPU-dummy + 1xdummy-Codec |
| 544 |
* => 4 DAIs = 2xCPU + 2xCodec |
| 545 |
* => 1 ccnf = 1xdummy-Codec |
| 546 |
*/ |
| 547 |
return graph_for_each_link(priv, li, |
| 548 |
graph_count_noml, |
| 549 |
graph_count_dpcm); |
| 550 |
} |
| 551 |
|
| 552 |
int audio_graph_parse_of(struct simple_util_priv *priv, struct device *dev) |
| 553 |
{ |
| 554 |
struct snd_soc_card *card = simple_priv_to_card(priv); |
| 555 |
int ret = -ENOMEM; |
| 556 |
|
| 557 |
struct link_info *li __free(kfree) = kzalloc_obj(*li); |
| 558 |
if (!li) |
| 559 |
goto end; |
| 560 |
|
| 561 |
card->owner = THIS_MODULE; |
| 562 |
card->dev = dev; |
| 563 |
|
| 564 |
ret = graph_get_dais_count(priv, li); |
| 565 |
if (ret < 0) |
| 566 |
goto end; |
| 567 |
|
| 568 |
ret = -EINVAL; |
| 569 |
if (!li->link) |
| 570 |
goto end; |
| 571 |
|
| 572 |
ret = simple_util_init_priv(priv, li); |
| 573 |
if (ret < 0) |
| 574 |
goto end; |
| 575 |
|
| 576 |
priv->pa_gpio = devm_gpiod_get_optional(dev, "pa", GPIOD_OUT_LOW); |
| 577 |
if (IS_ERR(priv->pa_gpio)) { |
| 578 |
ret = PTR_ERR(priv->pa_gpio); |
| 579 |
dev_err(dev, "failed to get amplifier gpio: %d\n", ret); |
| 580 |
goto end; |
| 581 |
} |
| 582 |
|
| 583 |
ret = simple_util_parse_widgets(card, NULL); |
| 584 |
if (ret < 0) |
| 585 |
goto end; |
| 586 |
|
| 587 |
ret = simple_util_parse_routing(card, NULL); |
| 588 |
if (ret < 0) |
| 589 |
goto end; |
| 590 |
|
| 591 |
memset(li, 0, sizeof(*li)); |
| 592 |
ret = graph_for_each_link(priv, li, |
| 593 |
graph_dai_link_of, |
| 594 |
graph_dai_link_of_dpcm); |
| 595 |
if (ret < 0) |
| 596 |
goto err; |
| 597 |
|
| 598 |
ret = simple_util_parse_card_name(priv, NULL); |
| 599 |
if (ret < 0) |
| 600 |
goto err; |
| 601 |
|
| 602 |
snd_soc_card_set_drvdata(card, priv); |
| 603 |
|
| 604 |
simple_util_debug_info(priv); |
| 605 |
|
| 606 |
ret = devm_snd_soc_register_card(dev, card); |
| 607 |
if (ret < 0) |
| 608 |
goto err; |
| 609 |
|
| 610 |
return 0; |
| 611 |
err: |
| 612 |
simple_util_clean_reference(card); |
| 613 |
end: |
| 614 |
return dev_err_probe(dev, ret, "parse error\n"); |
| 615 |
} |
| 616 |
EXPORT_SYMBOL_GPL(audio_graph_parse_of); |
| 617 |
|
| 618 |
static int graph_probe(struct platform_device *pdev) |
| 619 |
{ |
| 620 |
struct simple_util_priv *priv; |
| 621 |
struct device *dev = &pdev->dev; |
| 622 |
struct snd_soc_card *card; |
| 623 |
|
| 624 |
/* Allocate the private data and the DAI link array */ |
| 625 |
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); |
| 626 |
if (!priv) |
| 627 |
return -ENOMEM; |
| 628 |
|
| 629 |
card = simple_priv_to_card(priv); |
| 630 |
card->dapm_widgets = graph_dapm_widgets; |
| 631 |
card->num_dapm_widgets = ARRAY_SIZE(graph_dapm_widgets); |
| 632 |
card->probe = graph_util_card_probe; |
| 633 |
|
| 634 |
if (of_device_get_match_data(dev)) |
| 635 |
priv->dpcm_selectable = 1; |
| 636 |
|
| 637 |
return audio_graph_parse_of(priv, dev); |
| 638 |
} |
| 639 |
|
| 640 |
static const struct of_device_id graph_of_match[] = { |
| 641 |
{ .compatible = "audio-graph-card", }, |
| 642 |
{ .compatible = "audio-graph-scu-card", |
| 643 |
.data = (void *)DPCM_SELECTABLE }, |
| 644 |
{}, |
| 645 |
}; |
| 646 |
MODULE_DEVICE_TABLE(of, graph_of_match); |
| 647 |
|
| 648 |
static struct platform_driver graph_card = { |
| 649 |
.driver = { |
| 650 |
.name = "asoc-audio-graph-card", |
| 651 |
.pm = &snd_soc_pm_ops, |
| 652 |
.of_match_table = graph_of_match, |
| 653 |
}, |
| 654 |
.probe = graph_probe, |
| 655 |
.remove = simple_util_remove, |
| 656 |
}; |
| 657 |
module_platform_driver(graph_card); |
| 658 |
|
| 659 |
MODULE_ALIAS("platform:asoc-audio-graph-card"); |
| 660 |
MODULE_LICENSE("GPL v2"); |
| 661 |
MODULE_DESCRIPTION("ASoC Audio Graph Sound Card"); |
| 662 |
MODULE_AUTHOR("Kuninori Morimoto <[email protected]>"); |