diff options
author | Lars-Peter Clausen <lars@metafoo.de> | 2011-04-27 12:34:31 -0400 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2011-04-27 17:33:13 -0400 |
commit | 91a5fca4b1987324f829efeff3bc5efb2ce6e752 (patch) | |
tree | 5b50655c0b67ad0107488df0c670c590749aede5 /sound/soc/soc-dapm.c | |
parent | b864a8c9dd93f08ccaa706e075810e9398e25680 (diff) |
ASoC: Add dapm_find_widget helper
This patch adds a helper function for searching DAPM widgets by name.
This allows to streamline functions which operate on widgets by name.
It also allows to get rid of copy'n'pasted code which was added to fallback to
widgets from other contexts if the widget was not found in the current context.
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Acked-by: Liam Girdwood <lrg@ti.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound/soc/soc-dapm.c')
-rw-r--r-- | sound/soc/soc-dapm.c | 115 |
1 files changed, 45 insertions, 70 deletions
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c index 856471703bd3..378f08adee56 100644 --- a/sound/soc/soc-dapm.c +++ b/sound/soc/soc-dapm.c | |||
@@ -1458,40 +1458,43 @@ static void dapm_free_widgets(struct snd_soc_dapm_context *dapm) | |||
1458 | } | 1458 | } |
1459 | } | 1459 | } |
1460 | 1460 | ||
1461 | static int snd_soc_dapm_set_pin(struct snd_soc_dapm_context *dapm, | 1461 | static struct snd_soc_dapm_widget *dapm_find_widget( |
1462 | const char *pin, int status) | 1462 | struct snd_soc_dapm_context *dapm, const char *pin, |
1463 | bool search_other_contexts) | ||
1463 | { | 1464 | { |
1464 | struct snd_soc_dapm_widget *w; | 1465 | struct snd_soc_dapm_widget *w; |
1466 | struct snd_soc_dapm_widget *fallback = NULL; | ||
1465 | 1467 | ||
1466 | list_for_each_entry(w, &dapm->card->widgets, list) { | 1468 | list_for_each_entry(w, &dapm->card->widgets, list) { |
1467 | if (w->dapm != dapm) | ||
1468 | continue; | ||
1469 | if (!strcmp(w->name, pin)) { | 1469 | if (!strcmp(w->name, pin)) { |
1470 | dev_dbg(w->dapm->dev, "dapm: pin %s = %d\n", | 1470 | if (w->dapm == dapm) |
1471 | pin, status); | 1471 | return w; |
1472 | w->connected = status; | 1472 | else |
1473 | /* Allow disabling of forced pins */ | 1473 | fallback = w; |
1474 | if (status == 0) | ||
1475 | w->force = 0; | ||
1476 | return 0; | ||
1477 | } | 1474 | } |
1478 | } | 1475 | } |
1479 | 1476 | ||
1480 | /* Try again in other contexts */ | 1477 | if (search_other_contexts) |
1481 | list_for_each_entry(w, &dapm->card->widgets, list) { | 1478 | return fallback; |
1482 | if (!strcmp(w->name, pin)) { | 1479 | |
1483 | dev_dbg(w->dapm->dev, "dapm: pin %s = %d\n", | 1480 | return NULL; |
1484 | pin, status); | 1481 | } |
1485 | w->connected = status; | 1482 | |
1486 | /* Allow disabling of forced pins */ | 1483 | static int snd_soc_dapm_set_pin(struct snd_soc_dapm_context *dapm, |
1487 | if (status == 0) | 1484 | const char *pin, int status) |
1488 | w->force = 0; | 1485 | { |
1489 | return 0; | 1486 | struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true); |
1490 | } | 1487 | |
1488 | if (!w) { | ||
1489 | dev_err(dapm->dev, "dapm: unknown pin %s\n", pin); | ||
1490 | return -EINVAL; | ||
1491 | } | 1491 | } |
1492 | 1492 | ||
1493 | dev_err(dapm->dev, "dapm: unknown pin %s\n", pin); | 1493 | w->connected = status; |
1494 | return -EINVAL; | 1494 | if (status == 0) |
1495 | w->force = 0; | ||
1496 | |||
1497 | return 0; | ||
1495 | } | 1498 | } |
1496 | 1499 | ||
1497 | /** | 1500 | /** |
@@ -2316,33 +2319,18 @@ EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin); | |||
2316 | int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context *dapm, | 2319 | int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context *dapm, |
2317 | const char *pin) | 2320 | const char *pin) |
2318 | { | 2321 | { |
2319 | struct snd_soc_dapm_widget *w; | 2322 | struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true); |
2320 | 2323 | ||
2321 | list_for_each_entry(w, &dapm->card->widgets, list) { | 2324 | if (!w) { |
2322 | if (w->dapm != dapm) | 2325 | dev_err(dapm->dev, "dapm: unknown pin %s\n", pin); |
2323 | continue; | 2326 | return -EINVAL; |
2324 | if (!strcmp(w->name, pin)) { | ||
2325 | dev_dbg(w->dapm->dev, | ||
2326 | "dapm: force enable pin %s\n", pin); | ||
2327 | w->connected = 1; | ||
2328 | w->force = 1; | ||
2329 | return 0; | ||
2330 | } | ||
2331 | } | 2327 | } |
2332 | 2328 | ||
2333 | /* Try again with other contexts */ | 2329 | dev_dbg(w->dapm->dev, "dapm: force enable pin %s\n", pin); |
2334 | list_for_each_entry(w, &dapm->card->widgets, list) { | 2330 | w->connected = 1; |
2335 | if (!strcmp(w->name, pin)) { | 2331 | w->force = 1; |
2336 | dev_dbg(w->dapm->dev, | ||
2337 | "dapm: force enable pin %s\n", pin); | ||
2338 | w->connected = 1; | ||
2339 | w->force = 1; | ||
2340 | return 0; | ||
2341 | } | ||
2342 | } | ||
2343 | 2332 | ||
2344 | dev_err(dapm->dev, "dapm: unknown pin %s\n", pin); | 2333 | return 0; |
2345 | return -EINVAL; | ||
2346 | } | 2334 | } |
2347 | EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin); | 2335 | EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin); |
2348 | 2336 | ||
@@ -2394,20 +2382,10 @@ EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin); | |||
2394 | int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context *dapm, | 2382 | int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context *dapm, |
2395 | const char *pin) | 2383 | const char *pin) |
2396 | { | 2384 | { |
2397 | struct snd_soc_dapm_widget *w; | 2385 | struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true); |
2398 | 2386 | ||
2399 | list_for_each_entry(w, &dapm->card->widgets, list) { | 2387 | if (w) |
2400 | if (w->dapm != dapm) | 2388 | return w->connected; |
2401 | continue; | ||
2402 | if (!strcmp(w->name, pin)) | ||
2403 | return w->connected; | ||
2404 | } | ||
2405 | |||
2406 | /* Try again in other contexts */ | ||
2407 | list_for_each_entry(w, &dapm->card->widgets, list) { | ||
2408 | if (!strcmp(w->name, pin)) | ||
2409 | return w->connected; | ||
2410 | } | ||
2411 | 2389 | ||
2412 | return 0; | 2390 | return 0; |
2413 | } | 2391 | } |
@@ -2427,19 +2405,16 @@ EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status); | |||
2427 | int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context *dapm, | 2405 | int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context *dapm, |
2428 | const char *pin) | 2406 | const char *pin) |
2429 | { | 2407 | { |
2430 | struct snd_soc_dapm_widget *w; | 2408 | struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, false); |
2431 | 2409 | ||
2432 | list_for_each_entry(w, &dapm->card->widgets, list) { | 2410 | if (!w) { |
2433 | if (w->dapm != dapm) | 2411 | dev_err(dapm->dev, "dapm: unknown pin %s\n", pin); |
2434 | continue; | 2412 | return -EINVAL; |
2435 | if (!strcmp(w->name, pin)) { | ||
2436 | w->ignore_suspend = 1; | ||
2437 | return 0; | ||
2438 | } | ||
2439 | } | 2413 | } |
2440 | 2414 | ||
2441 | dev_err(dapm->dev, "dapm: unknown pin %s\n", pin); | 2415 | w->ignore_suspend = 1; |
2442 | return -EINVAL; | 2416 | |
2417 | return 0; | ||
2443 | } | 2418 | } |
2444 | EXPORT_SYMBOL_GPL(snd_soc_dapm_ignore_suspend); | 2419 | EXPORT_SYMBOL_GPL(snd_soc_dapm_ignore_suspend); |
2445 | 2420 | ||