Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1 | /* |
| 2 | * soc-dapm.c -- ALSA SoC Dynamic Audio Power Management |
| 3 | * |
| 4 | * Copyright 2005 Wolfson Microelectronics PLC. |
Liam Girdwood | d331124 | 2008-10-12 13:17:36 +0100 | [diff] [blame] | 5 | * Author: Liam Girdwood <lrg@slimlogic.co.uk> |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of the GNU General Public License as published by the |
| 9 | * Free Software Foundation; either version 2 of the License, or (at your |
| 10 | * option) any later version. |
| 11 | * |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 12 | * Features: |
| 13 | * o Changes power status of internal codec blocks depending on the |
| 14 | * dynamic configuration of codec internal audio paths and active |
Mark Brown | 74b8f95 | 2009-06-06 11:26:15 +0100 | [diff] [blame] | 15 | * DACs/ADCs. |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 16 | * o Platform power domain - can support external components i.e. amps and |
| 17 | * mic/meadphone insertion events. |
| 18 | * o Automatic Mic Bias support |
| 19 | * o Jack insertion power event initiation - e.g. hp insertion will enable |
| 20 | * sinks, dacs, etc |
Robert P. J. Day | 3a4fa0a | 2007-10-19 23:10:43 +0200 | [diff] [blame] | 21 | * o Delayed powerdown of audio susbsystem to reduce pops between a quick |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 22 | * device reopen. |
| 23 | * |
| 24 | * Todo: |
| 25 | * o DAPM power change sequencing - allow for configurable per |
| 26 | * codec sequences. |
| 27 | * o Support for analogue bias optimisation. |
| 28 | * o Support for reduced codec oversampling rates. |
| 29 | * o Support for reduced codec bias currents. |
| 30 | */ |
| 31 | |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 32 | #undef DEBUG |
Liam Girdwood | 7987a11 | 2011-01-31 19:52:42 +0000 | [diff] [blame] | 33 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 34 | #include <linux/module.h> |
| 35 | #include <linux/moduleparam.h> |
| 36 | #include <linux/init.h> |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 37 | #include <linux/async.h> |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 38 | #include <linux/delay.h> |
| 39 | #include <linux/pm.h> |
| 40 | #include <linux/bitops.h> |
| 41 | #include <linux/platform_device.h> |
| 42 | #include <linux/jiffies.h> |
Takashi Iwai | 20496ff | 2009-08-24 09:40:34 +0200 | [diff] [blame] | 43 | #include <linux/debugfs.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 44 | #include <linux/slab.h> |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 45 | #include <sound/core.h> |
| 46 | #include <sound/pcm.h> |
| 47 | #include <sound/pcm_params.h> |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 48 | #include <sound/soc.h> |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 49 | #include <sound/initval.h> |
| 50 | |
Mark Brown | 84e9093 | 2010-11-04 00:07:02 -0400 | [diff] [blame] | 51 | #include <trace/events/asoc.h> |
| 52 | |
Liam Girdwood | ab1058a | 2011-01-31 20:33:07 +0000 | [diff] [blame] | 53 | #define PATH_MAX_HOPS 16 |
| 54 | |
Liam Girdwood | e002c98 | 2011-02-08 11:45:20 +0000 | [diff] [blame] | 55 | int soc_dsp_runtime_update(struct snd_soc_dapm_widget *); |
| 56 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 57 | /* dapm power sequences - make this per codec in the future */ |
| 58 | static int dapm_up_seq[] = { |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 59 | [snd_soc_dapm_pre] = 0, |
| 60 | [snd_soc_dapm_supply] = 1, |
| 61 | [snd_soc_dapm_micbias] = 2, |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 62 | [snd_soc_dapm_aif_in] = 3, |
| 63 | [snd_soc_dapm_aif_out] = 3, |
| 64 | [snd_soc_dapm_mic] = 4, |
| 65 | [snd_soc_dapm_mux] = 5, |
Dimitris Papastamos | 24ff33a | 2010-12-16 15:53:39 +0000 | [diff] [blame] | 66 | [snd_soc_dapm_virt_mux] = 5, |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 67 | [snd_soc_dapm_value_mux] = 5, |
| 68 | [snd_soc_dapm_dac] = 6, |
| 69 | [snd_soc_dapm_mixer] = 7, |
| 70 | [snd_soc_dapm_mixer_named_ctl] = 7, |
| 71 | [snd_soc_dapm_pga] = 8, |
| 72 | [snd_soc_dapm_adc] = 9, |
Olaya, Margarita | d88429a | 2010-12-10 21:11:44 -0600 | [diff] [blame] | 73 | [snd_soc_dapm_out_drv] = 10, |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 74 | [snd_soc_dapm_hp] = 10, |
| 75 | [snd_soc_dapm_spk] = 10, |
| 76 | [snd_soc_dapm_post] = 11, |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 77 | }; |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 78 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 79 | static int dapm_down_seq[] = { |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 80 | [snd_soc_dapm_pre] = 0, |
| 81 | [snd_soc_dapm_adc] = 1, |
| 82 | [snd_soc_dapm_hp] = 2, |
Mark Brown | 1ca0406 | 2009-08-17 16:26:59 +0100 | [diff] [blame] | 83 | [snd_soc_dapm_spk] = 2, |
Olaya, Margarita | d88429a | 2010-12-10 21:11:44 -0600 | [diff] [blame] | 84 | [snd_soc_dapm_out_drv] = 2, |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 85 | [snd_soc_dapm_pga] = 4, |
| 86 | [snd_soc_dapm_mixer_named_ctl] = 5, |
Mark Brown | e3d4dab | 2009-06-07 13:08:45 +0100 | [diff] [blame] | 87 | [snd_soc_dapm_mixer] = 5, |
| 88 | [snd_soc_dapm_dac] = 6, |
| 89 | [snd_soc_dapm_mic] = 7, |
| 90 | [snd_soc_dapm_micbias] = 8, |
| 91 | [snd_soc_dapm_mux] = 9, |
Dimitris Papastamos | 24ff33a | 2010-12-16 15:53:39 +0000 | [diff] [blame] | 92 | [snd_soc_dapm_virt_mux] = 9, |
Mark Brown | e3d4dab | 2009-06-07 13:08:45 +0100 | [diff] [blame] | 93 | [snd_soc_dapm_value_mux] = 9, |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 94 | [snd_soc_dapm_aif_in] = 10, |
| 95 | [snd_soc_dapm_aif_out] = 10, |
| 96 | [snd_soc_dapm_supply] = 11, |
| 97 | [snd_soc_dapm_post] = 12, |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 98 | }; |
| 99 | |
Troy Kisky | 12ef193 | 2008-10-13 17:42:14 -0700 | [diff] [blame] | 100 | static void pop_wait(u32 pop_time) |
Mark Brown | 15e4c72 | 2008-07-02 11:51:20 +0100 | [diff] [blame] | 101 | { |
| 102 | if (pop_time) |
| 103 | schedule_timeout_uninterruptible(msecs_to_jiffies(pop_time)); |
| 104 | } |
| 105 | |
Jarkko Nikula | fd8d3bc | 2010-11-09 14:40:28 +0200 | [diff] [blame] | 106 | static void pop_dbg(struct device *dev, u32 pop_time, const char *fmt, ...) |
Mark Brown | 15e4c72 | 2008-07-02 11:51:20 +0100 | [diff] [blame] | 107 | { |
| 108 | va_list args; |
Jarkko Nikula | fd8d3bc | 2010-11-09 14:40:28 +0200 | [diff] [blame] | 109 | char *buf; |
| 110 | |
| 111 | if (!pop_time) |
| 112 | return; |
| 113 | |
| 114 | buf = kmalloc(PAGE_SIZE, GFP_KERNEL); |
| 115 | if (buf == NULL) |
| 116 | return; |
Mark Brown | 15e4c72 | 2008-07-02 11:51:20 +0100 | [diff] [blame] | 117 | |
| 118 | va_start(args, fmt); |
Jarkko Nikula | fd8d3bc | 2010-11-09 14:40:28 +0200 | [diff] [blame] | 119 | vsnprintf(buf, PAGE_SIZE, fmt, args); |
Takashi Iwai | 9d01df0 | 2010-12-22 14:08:40 +0100 | [diff] [blame] | 120 | dev_info(dev, "%s", buf); |
Mark Brown | 15e4c72 | 2008-07-02 11:51:20 +0100 | [diff] [blame] | 121 | va_end(args); |
Jarkko Nikula | fd8d3bc | 2010-11-09 14:40:28 +0200 | [diff] [blame] | 122 | |
| 123 | kfree(buf); |
Mark Brown | 15e4c72 | 2008-07-02 11:51:20 +0100 | [diff] [blame] | 124 | } |
| 125 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 126 | /* create a new dapm widget */ |
Takashi Iwai | 88cb429 | 2007-02-05 14:56:20 +0100 | [diff] [blame] | 127 | static inline struct snd_soc_dapm_widget *dapm_cnew_widget( |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 128 | const struct snd_soc_dapm_widget *_widget) |
| 129 | { |
Takashi Iwai | 88cb429 | 2007-02-05 14:56:20 +0100 | [diff] [blame] | 130 | return kmemdup(_widget, sizeof(*_widget), GFP_KERNEL); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 131 | } |
| 132 | |
Liam Girdwood | 7987a11 | 2011-01-31 19:52:42 +0000 | [diff] [blame] | 133 | static inline struct snd_card *dapm_get_card(struct snd_soc_dapm_context *dapm) |
| 134 | { |
| 135 | if (dapm->codec) |
| 136 | return dapm->codec->card->snd_card; |
| 137 | else if (dapm->platform) |
| 138 | return dapm->platform->card->snd_card; |
| 139 | else |
| 140 | BUG(); |
| 141 | } |
| 142 | |
| 143 | static inline struct snd_soc_card *dapm_get_soc_card( |
| 144 | struct snd_soc_dapm_context *dapm) |
| 145 | { |
| 146 | if (dapm->codec) |
| 147 | return dapm->codec->card; |
| 148 | else if (dapm->platform) |
| 149 | return dapm->platform->card; |
| 150 | else |
| 151 | BUG(); |
| 152 | } |
| 153 | |
Liam Girdwood | 35ca660 | 2011-01-28 17:45:35 +0000 | [diff] [blame] | 154 | static int soc_widget_read(struct snd_soc_dapm_widget *w, int reg) |
| 155 | { |
| 156 | if (w->codec) |
| 157 | return snd_soc_read(w->codec, reg); |
Liam Girdwood | 7987a11 | 2011-01-31 19:52:42 +0000 | [diff] [blame] | 158 | else if (w->platform) |
| 159 | return snd_soc_platform_read(w->platform, reg); |
Liam Girdwood | 35ca660 | 2011-01-28 17:45:35 +0000 | [diff] [blame] | 160 | return 0; |
| 161 | } |
| 162 | |
| 163 | static int soc_widget_write(struct snd_soc_dapm_widget *w,int reg, int val) |
| 164 | { |
| 165 | if (w->codec) |
| 166 | return snd_soc_write(w->codec, reg, val); |
Liam Girdwood | 7987a11 | 2011-01-31 19:52:42 +0000 | [diff] [blame] | 167 | else if (w->platform) |
| 168 | return snd_soc_platform_write(w->platform, reg, val); |
Liam Girdwood | 35ca660 | 2011-01-28 17:45:35 +0000 | [diff] [blame] | 169 | return 0; |
| 170 | } |
| 171 | |
| 172 | int soc_widget_update_bits(struct snd_soc_dapm_widget *w, unsigned short reg, |
| 173 | unsigned int mask, unsigned int value) |
| 174 | { |
| 175 | int change; |
| 176 | unsigned int old, new; |
| 177 | |
| 178 | old = soc_widget_read(w, reg); |
| 179 | new = (old & ~mask) | value; |
| 180 | change = old != new; |
| 181 | if (change) |
| 182 | soc_widget_write(w, reg, new); |
| 183 | |
| 184 | return change; |
| 185 | } |
| 186 | |
| 187 | int soc_widget_test_bits(struct snd_soc_dapm_widget *w, unsigned short reg, |
| 188 | unsigned int mask, unsigned int value) |
| 189 | { |
| 190 | int change; |
| 191 | unsigned int old, new; |
| 192 | |
| 193 | old = soc_widget_read(w, reg); |
| 194 | new = (old & ~mask) | value; |
| 195 | change = old != new; |
| 196 | |
| 197 | return change; |
| 198 | } |
| 199 | |
Liam Girdwood | ab1058a | 2011-01-31 20:33:07 +0000 | [diff] [blame] | 200 | /* reset 'walked' bit for each dapm path */ |
| 201 | static inline void dapm_clear_walk(struct snd_soc_dapm_context *dapm) |
| 202 | { |
| 203 | struct snd_soc_dapm_path *p; |
| 204 | |
| 205 | list_for_each_entry(p, &dapm->card->paths, list) |
| 206 | p->walked = 0; |
| 207 | } |
| 208 | |
| 209 | static void dapm_clear_paths(struct snd_soc_dapm_context *dapm) |
| 210 | { |
| 211 | struct snd_soc_dapm_path *p; |
| 212 | struct snd_soc_dapm_widget *w; |
| 213 | struct list_head *l; |
| 214 | |
Liam Girdwood | e002c98 | 2011-02-08 11:45:20 +0000 | [diff] [blame] | 215 | list_for_each(l, &dapm->card->paths) { |
Liam Girdwood | ab1058a | 2011-01-31 20:33:07 +0000 | [diff] [blame] | 216 | p = list_entry(l, struct snd_soc_dapm_path, list); |
| 217 | p->length = 0; |
| 218 | } |
| 219 | list_for_each(l, &dapm->card->widgets) { |
| 220 | w = list_entry(l, struct snd_soc_dapm_widget, list); |
| 221 | w->hops = 0; |
| 222 | } |
| 223 | dapm_clear_walk(dapm); |
| 224 | } |
| 225 | |
| 226 | /* |
| 227 | * find all the paths between source and sink |
| 228 | */ |
| 229 | static int dapm_find_playback_paths (struct snd_soc_dapm_context *dapm, |
| 230 | struct snd_soc_dapm_widget *source, struct snd_soc_dapm_widget *sink, |
| 231 | int hops) |
| 232 | { |
| 233 | struct list_head *lp; |
| 234 | struct snd_soc_dapm_path *path; |
| 235 | int dist = 0; |
| 236 | |
| 237 | if (hops > PATH_MAX_HOPS) |
| 238 | return 0; |
| 239 | |
| 240 | if (source == sink) { |
| 241 | dev_dbg(dapm->dev," ! %d: valid route found\n", hops); |
| 242 | dapm->num_valid_paths++; |
| 243 | return 1; |
| 244 | } |
| 245 | |
| 246 | if (source->hops && source->hops <= hops) |
| 247 | return 0; |
| 248 | source->hops = hops; |
| 249 | |
| 250 | /* check all the output paths on this source widget by walking |
| 251 | * from source to sink */ |
| 252 | list_for_each(lp, &source->sinks) { |
| 253 | path = list_entry(lp, struct snd_soc_dapm_path, list_source); |
| 254 | |
| 255 | dev_dbg(dapm->dev," %c %d: %s -> %s -> %s\n", |
| 256 | path->connect ? '*' : ' ', hops, |
| 257 | source->name, path->name, path->sink->name); |
| 258 | |
| 259 | /* been here before ? */ |
| 260 | if (path->length && path->length <= hops) |
| 261 | continue; |
| 262 | |
| 263 | /* check down the next path if connected */ |
| 264 | if (path->sink && path->connect && |
| 265 | dapm_find_playback_paths(dapm, path->sink, sink, hops + 1)) { |
| 266 | path->length = hops; |
| 267 | if (!dist || dist > path->length) |
| 268 | dist = path->length; |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | return dist; |
| 273 | } |
| 274 | |
| 275 | static int dapm_find_capture_paths (struct snd_soc_dapm_context *dapm, |
| 276 | struct snd_soc_dapm_widget *source, struct snd_soc_dapm_widget *sink, |
| 277 | int hops) |
| 278 | { |
| 279 | struct list_head *lp; |
| 280 | struct snd_soc_dapm_path *path; |
| 281 | int dist = 0; |
| 282 | |
| 283 | if (hops > PATH_MAX_HOPS) |
| 284 | return 0; |
| 285 | |
| 286 | if (source == sink) { |
| 287 | dev_dbg(dapm->dev," ! %d: valid route found\n", hops); |
| 288 | dapm->num_valid_paths++; |
| 289 | return 1; |
| 290 | } |
| 291 | |
| 292 | if (sink->hops && sink->hops <= hops) |
| 293 | return 0; |
| 294 | sink->hops = hops; |
| 295 | |
| 296 | /* check all the output paths on this source widget by walking from |
| 297 | * sink to source */ |
| 298 | list_for_each(lp, &sink->sources) { |
| 299 | path = list_entry(lp, struct snd_soc_dapm_path, list_sink); |
| 300 | |
| 301 | dev_dbg(dapm->dev," %c %d: %s <- %s <- %s\n", |
| 302 | path->connect ? '*' : ' ', hops, |
| 303 | sink->name, path->name, path->source->name); |
| 304 | |
| 305 | /* been here before ? */ |
| 306 | if (path->length && path->length <= hops) |
| 307 | continue; |
| 308 | |
| 309 | /* check down the next path if connected */ |
| 310 | if (path->source && path->connect && |
| 311 | dapm_find_capture_paths(dapm, source, path->source, hops + 1)) { |
| 312 | path->length = hops; |
| 313 | if (!dist || dist > path->length) |
| 314 | dist = path->length; |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | return dist; |
| 319 | } |
| 320 | |
| 321 | /* |
| 322 | * traverse the tree from sink to source via the shortest path |
| 323 | */ |
| 324 | static int dapm_get_playback_paths(struct snd_soc_dapm_context *dapm, |
| 325 | struct snd_soc_dapm_widget *source, struct snd_soc_dapm_widget *sink) |
| 326 | { |
| 327 | dev_dbg(dapm->dev, "Playback: checking path from %s to %s\n", |
| 328 | source->name, sink->name); |
| 329 | |
| 330 | dapm->num_valid_paths = 0; |
| 331 | dapm_find_playback_paths(dapm, source, sink, 1); |
| 332 | return dapm->num_valid_paths; |
| 333 | } |
| 334 | |
| 335 | static int dapm_get_capture_paths(struct snd_soc_dapm_context *dapm, |
| 336 | struct snd_soc_dapm_widget *source, struct snd_soc_dapm_widget *sink) |
| 337 | { |
| 338 | dev_dbg(dapm->dev, "check capture path to %s from %s\n", |
| 339 | source->name, sink->name); |
| 340 | |
| 341 | dapm->num_valid_paths = 0; |
| 342 | dapm_find_capture_paths(dapm, sink, source, 1); |
| 343 | return dapm->num_valid_paths; |
| 344 | } |
| 345 | |
| 346 | /** |
| 347 | * snd_soc_dapm_query_path - query audio path |
| 348 | * @dapm: the dapm context |
| 349 | * @source_name: source widget name |
| 350 | * @sink_name: sink widget name |
| 351 | * @stream: stream direction |
| 352 | * |
| 353 | * Queries DAPM graph as to whether an valid audio stream path exists between |
| 354 | * the source and sink widgets specified. This takes into account current |
| 355 | * mixer and mux kcontrol settings. |
| 356 | * |
| 357 | * Returns the number of valid paths or negative error. |
| 358 | */ |
| 359 | int snd_soc_dapm_query_path(struct snd_soc_dapm_context *dapm, |
| 360 | const char *source_name, const char *sink_name, int stream) |
| 361 | { |
| 362 | struct snd_soc_dapm_widget *sink = NULL, *source = NULL; |
| 363 | struct list_head *l = NULL; |
| 364 | int routes; |
| 365 | |
| 366 | /* find source and sink widgets */ |
| 367 | list_for_each(l, &dapm->card->widgets) { |
| 368 | struct snd_soc_dapm_widget *w = |
| 369 | list_entry(l, struct snd_soc_dapm_widget, list); |
| 370 | |
| 371 | if (!source && !strcmp(w->name, source_name)) { |
| 372 | source = w; |
| 373 | continue; |
| 374 | } |
| 375 | |
| 376 | if (!sink && !strcmp(w->name, sink_name)) |
| 377 | sink = w; |
| 378 | } |
| 379 | |
| 380 | if (!source) { |
| 381 | dev_err(dapm->dev, "can't find source widget: %s\n", source_name); |
| 382 | return -EINVAL; |
| 383 | } |
| 384 | if (!sink) { |
| 385 | dev_err(dapm->dev, "can't find sink widget: %s\n", sink_name); |
| 386 | return -EINVAL; |
| 387 | } |
| 388 | |
| 389 | if (stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 390 | routes = dapm_get_playback_paths(dapm, source, sink); |
| 391 | else |
| 392 | routes = dapm_get_capture_paths(dapm, source, sink); |
| 393 | |
| 394 | dapm_clear_paths(dapm); |
| 395 | return routes; |
| 396 | } |
| 397 | EXPORT_SYMBOL_GPL(snd_soc_dapm_query_path); |
Liam Girdwood | 35ca660 | 2011-01-28 17:45:35 +0000 | [diff] [blame] | 398 | |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 399 | /** |
| 400 | * snd_soc_dapm_set_bias_level - set the bias level for the system |
Mark Brown | ed5a4c4 | 2011-02-18 11:12:42 -0800 | [diff] [blame] | 401 | * @dapm: DAPM context |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 402 | * @level: level to configure |
| 403 | * |
| 404 | * Configure the bias (power) levels for the SoC audio device. |
| 405 | * |
| 406 | * Returns 0 for success else error. |
| 407 | */ |
Mark Brown | ed5a4c4 | 2011-02-18 11:12:42 -0800 | [diff] [blame] | 408 | static int snd_soc_dapm_set_bias_level(struct snd_soc_dapm_context *dapm, |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 409 | enum snd_soc_bias_level level) |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 410 | { |
Mark Brown | ed5a4c4 | 2011-02-18 11:12:42 -0800 | [diff] [blame] | 411 | struct snd_soc_card *card = dapm->card; |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 412 | int ret = 0; |
| 413 | |
Mark Brown | f83fba8 | 2009-05-18 15:44:43 +0100 | [diff] [blame] | 414 | switch (level) { |
| 415 | case SND_SOC_BIAS_ON: |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 416 | dev_dbg(dapm->dev, "Setting full bias\n"); |
Mark Brown | f83fba8 | 2009-05-18 15:44:43 +0100 | [diff] [blame] | 417 | break; |
| 418 | case SND_SOC_BIAS_PREPARE: |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 419 | dev_dbg(dapm->dev, "Setting bias prepare\n"); |
Mark Brown | f83fba8 | 2009-05-18 15:44:43 +0100 | [diff] [blame] | 420 | break; |
| 421 | case SND_SOC_BIAS_STANDBY: |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 422 | dev_dbg(dapm->dev, "Setting standby bias\n"); |
Mark Brown | f83fba8 | 2009-05-18 15:44:43 +0100 | [diff] [blame] | 423 | break; |
| 424 | case SND_SOC_BIAS_OFF: |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 425 | dev_dbg(dapm->dev, "Setting bias off\n"); |
Mark Brown | f83fba8 | 2009-05-18 15:44:43 +0100 | [diff] [blame] | 426 | break; |
| 427 | default: |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 428 | dev_err(dapm->dev, "Setting invalid bias %d\n", level); |
Mark Brown | f83fba8 | 2009-05-18 15:44:43 +0100 | [diff] [blame] | 429 | return -EINVAL; |
| 430 | } |
| 431 | |
Mark Brown | 84e9093 | 2010-11-04 00:07:02 -0400 | [diff] [blame] | 432 | trace_snd_soc_bias_level_start(card, level); |
| 433 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 434 | if (card && card->set_bias_level) |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 435 | ret = card->set_bias_level(card, level); |
Mark Brown | 474e09c | 2009-08-19 14:18:53 +0100 | [diff] [blame] | 436 | if (ret == 0) { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 437 | if (dapm->codec && dapm->codec->driver->set_bias_level) |
| 438 | ret = dapm->codec->driver->set_bias_level(dapm->codec, level); |
Mark Brown | 474e09c | 2009-08-19 14:18:53 +0100 | [diff] [blame] | 439 | else |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 440 | dapm->bias_level = level; |
Mark Brown | 474e09c | 2009-08-19 14:18:53 +0100 | [diff] [blame] | 441 | } |
Mark Brown | 1badabd | 2010-12-04 12:41:04 +0000 | [diff] [blame] | 442 | if (ret == 0) { |
| 443 | if (card && card->set_bias_level_post) |
| 444 | ret = card->set_bias_level_post(card, level); |
| 445 | } |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 446 | |
Mark Brown | 84e9093 | 2010-11-04 00:07:02 -0400 | [diff] [blame] | 447 | trace_snd_soc_bias_level_done(card, level); |
| 448 | |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 449 | return ret; |
| 450 | } |
| 451 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 452 | /* set up initial codec paths */ |
| 453 | static void dapm_set_path_status(struct snd_soc_dapm_widget *w, |
| 454 | struct snd_soc_dapm_path *p, int i) |
| 455 | { |
| 456 | switch (w->id) { |
| 457 | case snd_soc_dapm_switch: |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 458 | case snd_soc_dapm_mixer: |
| 459 | case snd_soc_dapm_mixer_named_ctl: { |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 460 | int val; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 461 | struct soc_mixer_control *mc = (struct soc_mixer_control *) |
Stephen Warren | 82cfecd | 2011-04-28 17:37:58 -0600 | [diff] [blame] | 462 | w->kcontrol_news[i].private_value; |
Jon Smirl | 815ecf8 | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 463 | unsigned int reg = mc->reg; |
| 464 | unsigned int shift = mc->shift; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 465 | int max = mc->max; |
Jon Smirl | 815ecf8 | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 466 | unsigned int mask = (1 << fls(max)) - 1; |
| 467 | unsigned int invert = mc->invert; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 468 | |
Liam Girdwood | 35ca660 | 2011-01-28 17:45:35 +0000 | [diff] [blame] | 469 | val = soc_widget_read(w, reg); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 470 | val = (val >> shift) & mask; |
| 471 | |
| 472 | if ((invert && !val) || (!invert && val)) |
| 473 | p->connect = 1; |
| 474 | else |
| 475 | p->connect = 0; |
| 476 | } |
| 477 | break; |
| 478 | case snd_soc_dapm_mux: { |
Stephen Warren | 82cfecd | 2011-04-28 17:37:58 -0600 | [diff] [blame] | 479 | struct soc_enum *e = (struct soc_enum *) |
| 480 | w->kcontrol_news[i].private_value; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 481 | int val, item, bitmask; |
| 482 | |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 483 | for (bitmask = 1; bitmask < e->max; bitmask <<= 1) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 484 | ; |
Liam Girdwood | 35ca660 | 2011-01-28 17:45:35 +0000 | [diff] [blame] | 485 | val = soc_widget_read(w, e->reg); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 486 | item = (val >> e->shift_l) & (bitmask - 1); |
| 487 | |
| 488 | p->connect = 0; |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 489 | for (i = 0; i < e->max; i++) { |
Liam Girdwood | a8f13d8 | 2011-05-18 18:39:21 +0100 | [diff] [blame^] | 490 | if (!(strcmp(p->name, snd_soc_get_enum_text(e, i))) && item == i) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 491 | p->connect = 1; |
| 492 | } |
| 493 | } |
| 494 | break; |
Dimitris Papastamos | 24ff33a | 2010-12-16 15:53:39 +0000 | [diff] [blame] | 495 | case snd_soc_dapm_virt_mux: { |
Stephen Warren | 82cfecd | 2011-04-28 17:37:58 -0600 | [diff] [blame] | 496 | struct soc_enum *e = (struct soc_enum *) |
| 497 | w->kcontrol_news[i].private_value; |
Dimitris Papastamos | 24ff33a | 2010-12-16 15:53:39 +0000 | [diff] [blame] | 498 | |
| 499 | p->connect = 0; |
| 500 | /* since a virtual mux has no backing registers to |
| 501 | * decide which path to connect, it will try to match |
| 502 | * with the first enumeration. This is to ensure |
| 503 | * that the default mux choice (the first) will be |
| 504 | * correctly powered up during initialization. |
| 505 | */ |
Liam Girdwood | a8f13d8 | 2011-05-18 18:39:21 +0100 | [diff] [blame^] | 506 | if (!strcmp(p->name, snd_soc_get_enum_text(e, 0))) |
Dimitris Papastamos | 24ff33a | 2010-12-16 15:53:39 +0000 | [diff] [blame] | 507 | p->connect = 1; |
| 508 | } |
| 509 | break; |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 510 | case snd_soc_dapm_value_mux: { |
Peter Ujfalusi | 7415555 | 2009-01-08 13:34:29 +0200 | [diff] [blame] | 511 | struct soc_enum *e = (struct soc_enum *) |
Stephen Warren | 82cfecd | 2011-04-28 17:37:58 -0600 | [diff] [blame] | 512 | w->kcontrol_news[i].private_value; |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 513 | int val, item; |
| 514 | |
Liam Girdwood | 35ca660 | 2011-01-28 17:45:35 +0000 | [diff] [blame] | 515 | val = soc_widget_read(w, e->reg); |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 516 | val = (val >> e->shift_l) & e->mask; |
| 517 | for (item = 0; item < e->max; item++) { |
| 518 | if (val == e->values[item]) |
| 519 | break; |
| 520 | } |
| 521 | |
| 522 | p->connect = 0; |
| 523 | for (i = 0; i < e->max; i++) { |
Liam Girdwood | a8f13d8 | 2011-05-18 18:39:21 +0100 | [diff] [blame^] | 524 | if (!(strcmp(p->name, snd_soc_get_enum_text(e, i))) && item == i) |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 525 | p->connect = 1; |
| 526 | } |
| 527 | } |
| 528 | break; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 529 | /* does not effect routing - always connected */ |
| 530 | case snd_soc_dapm_pga: |
Olaya, Margarita | d88429a | 2010-12-10 21:11:44 -0600 | [diff] [blame] | 531 | case snd_soc_dapm_out_drv: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 532 | case snd_soc_dapm_output: |
| 533 | case snd_soc_dapm_adc: |
| 534 | case snd_soc_dapm_input: |
| 535 | case snd_soc_dapm_dac: |
| 536 | case snd_soc_dapm_micbias: |
| 537 | case snd_soc_dapm_vmid: |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 538 | case snd_soc_dapm_supply: |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 539 | case snd_soc_dapm_aif_in: |
| 540 | case snd_soc_dapm_aif_out: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 541 | p->connect = 1; |
| 542 | break; |
| 543 | /* does effect routing - dynamically connected */ |
| 544 | case snd_soc_dapm_hp: |
| 545 | case snd_soc_dapm_mic: |
| 546 | case snd_soc_dapm_spk: |
| 547 | case snd_soc_dapm_line: |
| 548 | case snd_soc_dapm_pre: |
| 549 | case snd_soc_dapm_post: |
| 550 | p->connect = 0; |
| 551 | break; |
| 552 | } |
| 553 | } |
| 554 | |
Mark Brown | 74b8f95 | 2009-06-06 11:26:15 +0100 | [diff] [blame] | 555 | /* connect mux widget to its interconnecting audio paths */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 556 | static int dapm_connect_mux(struct snd_soc_dapm_context *dapm, |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 557 | struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest, |
| 558 | struct snd_soc_dapm_path *path, const char *control_name, |
| 559 | const struct snd_kcontrol_new *kcontrol) |
| 560 | { |
| 561 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
| 562 | int i; |
| 563 | |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 564 | for (i = 0; i < e->max; i++) { |
Liam Girdwood | a8f13d8 | 2011-05-18 18:39:21 +0100 | [diff] [blame^] | 565 | if (!(strcmp(control_name, snd_soc_get_enum_text(e, i)))) { |
Jarkko Nikula | 8ddab3f | 2010-12-14 12:18:30 +0200 | [diff] [blame] | 566 | list_add(&path->list, &dapm->card->paths); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 567 | list_add(&path->list_sink, &dest->sources); |
| 568 | list_add(&path->list_source, &src->sinks); |
Liam Girdwood | a8f13d8 | 2011-05-18 18:39:21 +0100 | [diff] [blame^] | 569 | path->name = (char*)snd_soc_get_enum_text(e, i); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 570 | dapm_set_path_status(dest, path, 0); |
| 571 | return 0; |
| 572 | } |
| 573 | } |
| 574 | |
| 575 | return -ENODEV; |
| 576 | } |
| 577 | |
Mark Brown | 74b8f95 | 2009-06-06 11:26:15 +0100 | [diff] [blame] | 578 | /* connect mixer widget to its interconnecting audio paths */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 579 | static int dapm_connect_mixer(struct snd_soc_dapm_context *dapm, |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 580 | struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest, |
| 581 | struct snd_soc_dapm_path *path, const char *control_name) |
| 582 | { |
| 583 | int i; |
| 584 | |
| 585 | /* search for mixer kcontrol */ |
| 586 | for (i = 0; i < dest->num_kcontrols; i++) { |
Stephen Warren | 82cfecd | 2011-04-28 17:37:58 -0600 | [diff] [blame] | 587 | if (!strcmp(control_name, dest->kcontrol_news[i].name)) { |
Jarkko Nikula | 8ddab3f | 2010-12-14 12:18:30 +0200 | [diff] [blame] | 588 | list_add(&path->list, &dapm->card->paths); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 589 | list_add(&path->list_sink, &dest->sources); |
| 590 | list_add(&path->list_source, &src->sinks); |
Stephen Warren | 82cfecd | 2011-04-28 17:37:58 -0600 | [diff] [blame] | 591 | path->name = dest->kcontrol_news[i].name; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 592 | dapm_set_path_status(dest, path, i); |
| 593 | return 0; |
| 594 | } |
| 595 | } |
| 596 | return -ENODEV; |
| 597 | } |
| 598 | |
Stephen Warren | af46800 | 2011-04-28 17:38:01 -0600 | [diff] [blame] | 599 | static int dapm_is_shared_kcontrol(struct snd_soc_dapm_context *dapm, |
Stephen Warren | 1007da0 | 2011-05-26 09:57:33 -0600 | [diff] [blame] | 600 | struct snd_soc_dapm_widget *kcontrolw, |
Stephen Warren | af46800 | 2011-04-28 17:38:01 -0600 | [diff] [blame] | 601 | const struct snd_kcontrol_new *kcontrol_new, |
| 602 | struct snd_kcontrol **kcontrol) |
| 603 | { |
| 604 | struct snd_soc_dapm_widget *w; |
| 605 | int i; |
| 606 | |
| 607 | *kcontrol = NULL; |
| 608 | |
| 609 | list_for_each_entry(w, &dapm->card->widgets, list) { |
Stephen Warren | 1007da0 | 2011-05-26 09:57:33 -0600 | [diff] [blame] | 610 | if (w == kcontrolw || w->dapm != kcontrolw->dapm) |
| 611 | continue; |
Stephen Warren | af46800 | 2011-04-28 17:38:01 -0600 | [diff] [blame] | 612 | for (i = 0; i < w->num_kcontrols; i++) { |
| 613 | if (&w->kcontrol_news[i] == kcontrol_new) { |
| 614 | if (w->kcontrols) |
| 615 | *kcontrol = w->kcontrols[i]; |
| 616 | return 1; |
| 617 | } |
| 618 | } |
| 619 | } |
| 620 | |
| 621 | return 0; |
| 622 | } |
| 623 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 624 | /* create new dapm mixer control */ |
Lars-Peter Clausen | 4b80b8c | 2011-06-09 13:22:36 +0200 | [diff] [blame] | 625 | static int dapm_new_mixer(struct snd_soc_dapm_widget *w) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 626 | { |
Lars-Peter Clausen | 4b80b8c | 2011-06-09 13:22:36 +0200 | [diff] [blame] | 627 | struct snd_soc_dapm_context *dapm = w->dapm; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 628 | int i, ret = 0; |
Mark Brown | 3e5ff4d | 2011-03-09 11:33:09 +0000 | [diff] [blame] | 629 | size_t name_len, prefix_len; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 630 | struct snd_soc_dapm_path *path; |
Mark Brown | 12ea2c7 | 2011-03-02 18:17:32 +0000 | [diff] [blame] | 631 | struct snd_card *card = dapm->card->snd_card; |
Mark Brown | efb7ac3 | 2011-03-08 17:23:24 +0000 | [diff] [blame] | 632 | const char *prefix; |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 633 | struct snd_soc_dapm_widget_list *wlist; |
| 634 | size_t wlistsize; |
Mark Brown | efb7ac3 | 2011-03-08 17:23:24 +0000 | [diff] [blame] | 635 | |
| 636 | if (dapm->codec) |
| 637 | prefix = dapm->codec->name_prefix; |
| 638 | else |
| 639 | prefix = NULL; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 640 | |
Mark Brown | 3e5ff4d | 2011-03-09 11:33:09 +0000 | [diff] [blame] | 641 | if (prefix) |
| 642 | prefix_len = strlen(prefix) + 1; |
| 643 | else |
| 644 | prefix_len = 0; |
| 645 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 646 | /* add kcontrol */ |
| 647 | for (i = 0; i < w->num_kcontrols; i++) { |
| 648 | |
| 649 | /* match name */ |
| 650 | list_for_each_entry(path, &w->sources, list_sink) { |
| 651 | |
| 652 | /* mixer/mux paths name must match control name */ |
Stephen Warren | 82cfecd | 2011-04-28 17:37:58 -0600 | [diff] [blame] | 653 | if (path->name != (char *)w->kcontrol_news[i].name) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 654 | continue; |
| 655 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 656 | wlistsize = sizeof(struct snd_soc_dapm_widget_list) + |
| 657 | sizeof(struct snd_soc_dapm_widget *), |
| 658 | wlist = kzalloc(wlistsize, GFP_KERNEL); |
| 659 | if (wlist == NULL) { |
| 660 | dev_err(dapm->dev, |
| 661 | "asoc: can't allocate widget list for %s\n", |
| 662 | w->name); |
| 663 | return -ENOMEM; |
| 664 | } |
| 665 | wlist->num_widgets = 1; |
| 666 | wlist->widgets[0] = w; |
| 667 | |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 668 | /* add dapm control with long name. |
| 669 | * for dapm_mixer this is the concatenation of the |
| 670 | * mixer and kcontrol name. |
| 671 | * for dapm_mixer_named_ctl this is simply the |
| 672 | * kcontrol name. |
| 673 | */ |
Stephen Warren | 82cfecd | 2011-04-28 17:37:58 -0600 | [diff] [blame] | 674 | name_len = strlen(w->kcontrol_news[i].name) + 1; |
Mark Brown | 07495f3 | 2009-03-05 17:06:23 +0000 | [diff] [blame] | 675 | if (w->id != snd_soc_dapm_mixer_named_ctl) |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 676 | name_len += 1 + strlen(w->name); |
| 677 | |
Mark Brown | 219b93f | 2008-10-28 13:02:31 +0000 | [diff] [blame] | 678 | path->long_name = kmalloc(name_len, GFP_KERNEL); |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 679 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 680 | if (path->long_name == NULL) { |
| 681 | kfree(wlist); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 682 | return -ENOMEM; |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 683 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 684 | |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 685 | switch (w->id) { |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 686 | default: |
Mark Brown | 3e5ff4d | 2011-03-09 11:33:09 +0000 | [diff] [blame] | 687 | /* The control will get a prefix from |
| 688 | * the control creation process but |
| 689 | * we're also using the same prefix |
| 690 | * for widgets so cut the prefix off |
| 691 | * the front of the widget name. |
| 692 | */ |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 693 | snprintf(path->long_name, name_len, "%s %s", |
Mark Brown | 3e5ff4d | 2011-03-09 11:33:09 +0000 | [diff] [blame] | 694 | w->name + prefix_len, |
Stephen Warren | 82cfecd | 2011-04-28 17:37:58 -0600 | [diff] [blame] | 695 | w->kcontrol_news[i].name); |
Mark Brown | 07495f3 | 2009-03-05 17:06:23 +0000 | [diff] [blame] | 696 | break; |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 697 | case snd_soc_dapm_mixer_named_ctl: |
| 698 | snprintf(path->long_name, name_len, "%s", |
Stephen Warren | 82cfecd | 2011-04-28 17:37:58 -0600 | [diff] [blame] | 699 | w->kcontrol_news[i].name); |
Mark Brown | 07495f3 | 2009-03-05 17:06:23 +0000 | [diff] [blame] | 700 | break; |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 701 | } |
| 702 | |
Mark Brown | 219b93f | 2008-10-28 13:02:31 +0000 | [diff] [blame] | 703 | path->long_name[name_len - 1] = '\0'; |
| 704 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 705 | path->kcontrol = snd_soc_cnew(&w->kcontrol_news[i], |
| 706 | wlist, path->long_name, |
| 707 | prefix); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 708 | ret = snd_ctl_add(card, path->kcontrol); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 709 | if (ret < 0) { |
Jarkko Nikula | f7d41ae | 2010-11-09 14:40:27 +0200 | [diff] [blame] | 710 | dev_err(dapm->dev, |
| 711 | "asoc: failed to add dapm kcontrol %s: %d\n", |
| 712 | path->long_name, ret); |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 713 | kfree(wlist); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 714 | kfree(path->long_name); |
| 715 | path->long_name = NULL; |
| 716 | return ret; |
| 717 | } |
Stephen Warren | fad5988 | 2011-04-28 17:37:59 -0600 | [diff] [blame] | 718 | w->kcontrols[i] = path->kcontrol; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 719 | } |
| 720 | } |
| 721 | return ret; |
| 722 | } |
| 723 | |
| 724 | /* create new dapm mux control */ |
Lars-Peter Clausen | 4b80b8c | 2011-06-09 13:22:36 +0200 | [diff] [blame] | 725 | static int dapm_new_mux(struct snd_soc_dapm_widget *w) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 726 | { |
Lars-Peter Clausen | 4b80b8c | 2011-06-09 13:22:36 +0200 | [diff] [blame] | 727 | struct snd_soc_dapm_context *dapm = w->dapm; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 728 | struct snd_soc_dapm_path *path = NULL; |
| 729 | struct snd_kcontrol *kcontrol; |
Mark Brown | 12ea2c7 | 2011-03-02 18:17:32 +0000 | [diff] [blame] | 730 | struct snd_card *card = dapm->card->snd_card; |
Mark Brown | efb7ac3 | 2011-03-08 17:23:24 +0000 | [diff] [blame] | 731 | const char *prefix; |
Mark Brown | 3e5ff4d | 2011-03-09 11:33:09 +0000 | [diff] [blame] | 732 | size_t prefix_len; |
Stephen Warren | af46800 | 2011-04-28 17:38:01 -0600 | [diff] [blame] | 733 | int ret; |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 734 | struct snd_soc_dapm_widget_list *wlist; |
Stephen Warren | af46800 | 2011-04-28 17:38:01 -0600 | [diff] [blame] | 735 | int shared, wlistentries; |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 736 | size_t wlistsize; |
Stephen Warren | af46800 | 2011-04-28 17:38:01 -0600 | [diff] [blame] | 737 | char *name; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 738 | |
Stephen Warren | af46800 | 2011-04-28 17:38:01 -0600 | [diff] [blame] | 739 | if (w->num_kcontrols != 1) { |
| 740 | dev_err(dapm->dev, |
| 741 | "asoc: mux %s has incorrect number of controls\n", |
| 742 | w->name); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 743 | return -EINVAL; |
| 744 | } |
| 745 | |
Stephen Warren | 1007da0 | 2011-05-26 09:57:33 -0600 | [diff] [blame] | 746 | shared = dapm_is_shared_kcontrol(dapm, w, &w->kcontrol_news[0], |
Stephen Warren | af46800 | 2011-04-28 17:38:01 -0600 | [diff] [blame] | 747 | &kcontrol); |
| 748 | if (kcontrol) { |
| 749 | wlist = kcontrol->private_data; |
| 750 | wlistentries = wlist->num_widgets + 1; |
| 751 | } else { |
| 752 | wlist = NULL; |
| 753 | wlistentries = 1; |
| 754 | } |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 755 | wlistsize = sizeof(struct snd_soc_dapm_widget_list) + |
Stephen Warren | af46800 | 2011-04-28 17:38:01 -0600 | [diff] [blame] | 756 | wlistentries * sizeof(struct snd_soc_dapm_widget *), |
| 757 | wlist = krealloc(wlist, wlistsize, GFP_KERNEL); |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 758 | if (wlist == NULL) { |
| 759 | dev_err(dapm->dev, |
| 760 | "asoc: can't allocate widget list for %s\n", w->name); |
| 761 | return -ENOMEM; |
| 762 | } |
Stephen Warren | af46800 | 2011-04-28 17:38:01 -0600 | [diff] [blame] | 763 | wlist->num_widgets = wlistentries; |
| 764 | wlist->widgets[wlistentries - 1] = w; |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 765 | |
Stephen Warren | af46800 | 2011-04-28 17:38:01 -0600 | [diff] [blame] | 766 | if (!kcontrol) { |
Liam Girdwood | 4d74b36 | 2011-05-18 17:50:07 +0100 | [diff] [blame] | 767 | if (dapm->codec && dapm->codec->name_prefix) |
Stephen Warren | af46800 | 2011-04-28 17:38:01 -0600 | [diff] [blame] | 768 | prefix = dapm->codec->name_prefix; |
| 769 | else |
Liam Girdwood | 4d74b36 | 2011-05-18 17:50:07 +0100 | [diff] [blame] | 770 | prefix = w->name; |
Mark Brown | efb7ac3 | 2011-03-08 17:23:24 +0000 | [diff] [blame] | 771 | |
Stephen Warren | af46800 | 2011-04-28 17:38:01 -0600 | [diff] [blame] | 772 | if (shared) { |
| 773 | name = w->kcontrol_news[0].name; |
| 774 | prefix_len = 0; |
| 775 | } else { |
| 776 | name = w->name; |
| 777 | if (prefix) |
| 778 | prefix_len = strlen(prefix) + 1; |
| 779 | else |
| 780 | prefix_len = 0; |
| 781 | } |
Mark Brown | 3e5ff4d | 2011-03-09 11:33:09 +0000 | [diff] [blame] | 782 | |
Stephen Warren | af46800 | 2011-04-28 17:38:01 -0600 | [diff] [blame] | 783 | /* |
| 784 | * The control will get a prefix from the control creation |
| 785 | * process but we're also using the same prefix for widgets so |
| 786 | * cut the prefix off the front of the widget name. |
| 787 | */ |
| 788 | kcontrol = snd_soc_cnew(&w->kcontrol_news[0], wlist, |
| 789 | name + prefix_len, prefix); |
| 790 | ret = snd_ctl_add(card, kcontrol); |
| 791 | if (ret < 0) { |
| 792 | dev_err(dapm->dev, |
| 793 | "asoc: failed to add kcontrol %s\n", w->name); |
| 794 | kfree(wlist); |
| 795 | return ret; |
| 796 | } |
| 797 | } |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 798 | |
Stephen Warren | af46800 | 2011-04-28 17:38:01 -0600 | [diff] [blame] | 799 | kcontrol->private_data = wlist; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 800 | |
Stephen Warren | fad5988 | 2011-04-28 17:37:59 -0600 | [diff] [blame] | 801 | w->kcontrols[0] = kcontrol; |
| 802 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 803 | list_for_each_entry(path, &w->sources, list_sink) |
| 804 | path->kcontrol = kcontrol; |
| 805 | |
Stephen Warren | af46800 | 2011-04-28 17:38:01 -0600 | [diff] [blame] | 806 | return 0; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 807 | } |
| 808 | |
| 809 | /* create new dapm volume control */ |
Lars-Peter Clausen | 4b80b8c | 2011-06-09 13:22:36 +0200 | [diff] [blame] | 810 | static int dapm_new_pga(struct snd_soc_dapm_widget *w) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 811 | { |
Mark Brown | a6c6573 | 2010-03-03 17:45:21 +0000 | [diff] [blame] | 812 | if (w->num_kcontrols) |
Jarkko Nikula | f7d41ae | 2010-11-09 14:40:27 +0200 | [diff] [blame] | 813 | dev_err(w->dapm->dev, |
| 814 | "asoc: PGA controls not supported: '%s'\n", w->name); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 815 | |
Mark Brown | a6c6573 | 2010-03-03 17:45:21 +0000 | [diff] [blame] | 816 | return 0; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 817 | } |
| 818 | |
Mark Brown | 9949788 | 2010-05-07 20:24:05 +0100 | [diff] [blame] | 819 | /* We implement power down on suspend by checking the power state of |
| 820 | * the ALSA card - when we are suspending the ALSA state for the card |
| 821 | * is set to D3. |
| 822 | */ |
| 823 | static int snd_soc_dapm_suspend_check(struct snd_soc_dapm_widget *widget) |
| 824 | { |
Mark Brown | 12ea2c7 | 2011-03-02 18:17:32 +0000 | [diff] [blame] | 825 | int level = snd_power_get_state(widget->dapm->card->snd_card); |
Mark Brown | 9949788 | 2010-05-07 20:24:05 +0100 | [diff] [blame] | 826 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 827 | switch (level) { |
Mark Brown | 9949788 | 2010-05-07 20:24:05 +0100 | [diff] [blame] | 828 | case SNDRV_CTL_POWER_D3hot: |
| 829 | case SNDRV_CTL_POWER_D3cold: |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 830 | if (widget->ignore_suspend) |
Jarkko Nikula | f7d41ae | 2010-11-09 14:40:27 +0200 | [diff] [blame] | 831 | dev_dbg(widget->dapm->dev, "%s ignoring suspend\n", |
| 832 | widget->name); |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 833 | return widget->ignore_suspend; |
Mark Brown | 9949788 | 2010-05-07 20:24:05 +0100 | [diff] [blame] | 834 | default: |
| 835 | return 1; |
| 836 | } |
| 837 | } |
| 838 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 839 | /* |
| 840 | * Recursively check for a completed path to an active or physically connected |
| 841 | * output widget. Returns number of complete paths. |
| 842 | */ |
| 843 | static int is_connected_output_ep(struct snd_soc_dapm_widget *widget) |
| 844 | { |
| 845 | struct snd_soc_dapm_path *path; |
| 846 | int con = 0; |
| 847 | |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 848 | if (widget->id == snd_soc_dapm_supply) |
| 849 | return 0; |
| 850 | |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 851 | switch (widget->id) { |
| 852 | case snd_soc_dapm_adc: |
| 853 | case snd_soc_dapm_aif_out: |
| 854 | if (widget->active) |
Mark Brown | 9949788 | 2010-05-07 20:24:05 +0100 | [diff] [blame] | 855 | return snd_soc_dapm_suspend_check(widget); |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 856 | default: |
| 857 | break; |
| 858 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 859 | |
| 860 | if (widget->connected) { |
| 861 | /* connected pin ? */ |
| 862 | if (widget->id == snd_soc_dapm_output && !widget->ext) |
Mark Brown | 9949788 | 2010-05-07 20:24:05 +0100 | [diff] [blame] | 863 | return snd_soc_dapm_suspend_check(widget); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 864 | |
| 865 | /* connected jack or spk ? */ |
| 866 | if (widget->id == snd_soc_dapm_hp || widget->id == snd_soc_dapm_spk || |
Peter Ujfalusi | eaeae5d | 2009-09-30 09:27:24 +0300 | [diff] [blame] | 867 | (widget->id == snd_soc_dapm_line && !list_empty(&widget->sources))) |
Mark Brown | 9949788 | 2010-05-07 20:24:05 +0100 | [diff] [blame] | 868 | return snd_soc_dapm_suspend_check(widget); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 869 | } |
| 870 | |
| 871 | list_for_each_entry(path, &widget->sinks, list_source) { |
| 872 | if (path->walked) |
| 873 | continue; |
| 874 | |
| 875 | if (path->sink && path->connect) { |
| 876 | path->walked = 1; |
| 877 | con += is_connected_output_ep(path->sink); |
| 878 | } |
| 879 | } |
| 880 | |
| 881 | return con; |
| 882 | } |
| 883 | |
| 884 | /* |
| 885 | * Recursively check for a completed path to an active or physically connected |
| 886 | * input widget. Returns number of complete paths. |
| 887 | */ |
| 888 | static int is_connected_input_ep(struct snd_soc_dapm_widget *widget) |
| 889 | { |
| 890 | struct snd_soc_dapm_path *path; |
| 891 | int con = 0; |
| 892 | |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 893 | if (widget->id == snd_soc_dapm_supply) |
| 894 | return 0; |
| 895 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 896 | /* active stream ? */ |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 897 | switch (widget->id) { |
| 898 | case snd_soc_dapm_dac: |
| 899 | case snd_soc_dapm_aif_in: |
| 900 | if (widget->active) |
Mark Brown | 9949788 | 2010-05-07 20:24:05 +0100 | [diff] [blame] | 901 | return snd_soc_dapm_suspend_check(widget); |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 902 | default: |
| 903 | break; |
| 904 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 905 | |
| 906 | if (widget->connected) { |
| 907 | /* connected pin ? */ |
| 908 | if (widget->id == snd_soc_dapm_input && !widget->ext) |
Mark Brown | 9949788 | 2010-05-07 20:24:05 +0100 | [diff] [blame] | 909 | return snd_soc_dapm_suspend_check(widget); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 910 | |
| 911 | /* connected VMID/Bias for lower pops */ |
| 912 | if (widget->id == snd_soc_dapm_vmid) |
Mark Brown | 9949788 | 2010-05-07 20:24:05 +0100 | [diff] [blame] | 913 | return snd_soc_dapm_suspend_check(widget); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 914 | |
| 915 | /* connected jack ? */ |
Peter Ujfalusi | eaeae5d | 2009-09-30 09:27:24 +0300 | [diff] [blame] | 916 | if (widget->id == snd_soc_dapm_mic || |
| 917 | (widget->id == snd_soc_dapm_line && !list_empty(&widget->sinks))) |
Mark Brown | 9949788 | 2010-05-07 20:24:05 +0100 | [diff] [blame] | 918 | return snd_soc_dapm_suspend_check(widget); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 919 | } |
| 920 | |
| 921 | list_for_each_entry(path, &widget->sources, list_sink) { |
| 922 | if (path->walked) |
| 923 | continue; |
| 924 | |
| 925 | if (path->source && path->connect) { |
| 926 | path->walked = 1; |
| 927 | con += is_connected_input_ep(path->source); |
| 928 | } |
| 929 | } |
| 930 | |
| 931 | return con; |
| 932 | } |
| 933 | |
| 934 | /* |
Jarkko Nikula | e2be2cc | 2008-06-25 14:42:07 +0300 | [diff] [blame] | 935 | * Handler for generic register modifier widget. |
| 936 | */ |
| 937 | int dapm_reg_event(struct snd_soc_dapm_widget *w, |
| 938 | struct snd_kcontrol *kcontrol, int event) |
| 939 | { |
| 940 | unsigned int val; |
| 941 | |
| 942 | if (SND_SOC_DAPM_EVENT_ON(event)) |
| 943 | val = w->on_val; |
| 944 | else |
| 945 | val = w->off_val; |
| 946 | |
Liam Girdwood | 35ca660 | 2011-01-28 17:45:35 +0000 | [diff] [blame] | 947 | soc_widget_update_bits(w, -(w->reg + 1), |
Jarkko Nikula | e2be2cc | 2008-06-25 14:42:07 +0300 | [diff] [blame] | 948 | w->mask << w->shift, val << w->shift); |
| 949 | |
| 950 | return 0; |
| 951 | } |
Mark Brown | 1158941 | 2008-07-29 11:42:23 +0100 | [diff] [blame] | 952 | EXPORT_SYMBOL_GPL(dapm_reg_event); |
Jarkko Nikula | e2be2cc | 2008-06-25 14:42:07 +0300 | [diff] [blame] | 953 | |
Mark Brown | cd0f2d4 | 2009-04-20 16:56:59 +0100 | [diff] [blame] | 954 | /* Generic check to see if a widget should be powered. |
| 955 | */ |
| 956 | static int dapm_generic_check_power(struct snd_soc_dapm_widget *w) |
| 957 | { |
| 958 | int in, out; |
| 959 | |
| 960 | in = is_connected_input_ep(w); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 961 | dapm_clear_walk(w->dapm); |
Mark Brown | cd0f2d4 | 2009-04-20 16:56:59 +0100 | [diff] [blame] | 962 | out = is_connected_output_ep(w); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 963 | dapm_clear_walk(w->dapm); |
Mark Brown | cd0f2d4 | 2009-04-20 16:56:59 +0100 | [diff] [blame] | 964 | return out != 0 && in != 0; |
| 965 | } |
| 966 | |
Mark Brown | 6ea31b9 | 2009-04-20 17:15:41 +0100 | [diff] [blame] | 967 | /* Check to see if an ADC has power */ |
| 968 | static int dapm_adc_check_power(struct snd_soc_dapm_widget *w) |
| 969 | { |
| 970 | int in; |
| 971 | |
| 972 | if (w->active) { |
| 973 | in = is_connected_input_ep(w); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 974 | dapm_clear_walk(w->dapm); |
Mark Brown | 6ea31b9 | 2009-04-20 17:15:41 +0100 | [diff] [blame] | 975 | return in != 0; |
| 976 | } else { |
| 977 | return dapm_generic_check_power(w); |
| 978 | } |
| 979 | } |
| 980 | |
| 981 | /* Check to see if a DAC has power */ |
| 982 | static int dapm_dac_check_power(struct snd_soc_dapm_widget *w) |
| 983 | { |
| 984 | int out; |
| 985 | |
| 986 | if (w->active) { |
| 987 | out = is_connected_output_ep(w); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 988 | dapm_clear_walk(w->dapm); |
Mark Brown | 6ea31b9 | 2009-04-20 17:15:41 +0100 | [diff] [blame] | 989 | return out != 0; |
| 990 | } else { |
| 991 | return dapm_generic_check_power(w); |
| 992 | } |
| 993 | } |
| 994 | |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 995 | /* Check to see if a power supply is needed */ |
| 996 | static int dapm_supply_check_power(struct snd_soc_dapm_widget *w) |
| 997 | { |
| 998 | struct snd_soc_dapm_path *path; |
| 999 | int power = 0; |
| 1000 | |
| 1001 | /* Check if one of our outputs is connected */ |
| 1002 | list_for_each_entry(path, &w->sinks, list_source) { |
Mark Brown | 215edda | 2009-09-08 18:59:05 +0100 | [diff] [blame] | 1003 | if (path->connected && |
| 1004 | !path->connected(path->source, path->sink)) |
| 1005 | continue; |
| 1006 | |
Mark Brown | 3017358 | 2011-02-11 11:42:19 +0000 | [diff] [blame] | 1007 | if (!path->sink) |
| 1008 | continue; |
| 1009 | |
| 1010 | if (path->sink->force) { |
| 1011 | power = 1; |
| 1012 | break; |
| 1013 | } |
| 1014 | |
| 1015 | if (path->sink->power_check && |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 1016 | path->sink->power_check(path->sink)) { |
| 1017 | power = 1; |
| 1018 | break; |
| 1019 | } |
| 1020 | } |
| 1021 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1022 | dapm_clear_walk(w->dapm); |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 1023 | |
| 1024 | return power; |
| 1025 | } |
| 1026 | |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 1027 | static int dapm_seq_compare(struct snd_soc_dapm_widget *a, |
| 1028 | struct snd_soc_dapm_widget *b, |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 1029 | bool power_up) |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 1030 | { |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 1031 | int *sort; |
| 1032 | |
| 1033 | if (power_up) |
| 1034 | sort = dapm_up_seq; |
| 1035 | else |
| 1036 | sort = dapm_down_seq; |
| 1037 | |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 1038 | if (sort[a->id] != sort[b->id]) |
| 1039 | return sort[a->id] - sort[b->id]; |
Mark Brown | 20e4859 | 2011-01-15 13:40:50 +0000 | [diff] [blame] | 1040 | if (a->subseq != b->subseq) { |
| 1041 | if (power_up) |
| 1042 | return a->subseq - b->subseq; |
| 1043 | else |
| 1044 | return b->subseq - a->subseq; |
| 1045 | } |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1046 | if (a->reg != b->reg) |
| 1047 | return a->reg - b->reg; |
Mark Brown | 84dab56 | 2010-11-12 15:28:42 +0000 | [diff] [blame] | 1048 | if (a->dapm != b->dapm) |
| 1049 | return (unsigned long)a->dapm - (unsigned long)b->dapm; |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 1050 | |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 1051 | return 0; |
| 1052 | } |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 1053 | |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 1054 | /* Insert a widget in order into a DAPM power sequence. */ |
| 1055 | static void dapm_seq_insert(struct snd_soc_dapm_widget *new_widget, |
| 1056 | struct list_head *list, |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 1057 | bool power_up) |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 1058 | { |
| 1059 | struct snd_soc_dapm_widget *w; |
| 1060 | |
| 1061 | list_for_each_entry(w, list, power_list) |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 1062 | if (dapm_seq_compare(new_widget, w, power_up) < 0) { |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 1063 | list_add_tail(&new_widget->power_list, &w->power_list); |
| 1064 | return; |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 1065 | } |
Mark Brown | 6ea31b9 | 2009-04-20 17:15:41 +0100 | [diff] [blame] | 1066 | |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 1067 | list_add_tail(&new_widget->power_list, list); |
| 1068 | } |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 1069 | |
Mark Brown | 68f89ad | 2010-11-03 23:51:49 -0400 | [diff] [blame] | 1070 | static void dapm_seq_check_event(struct snd_soc_dapm_context *dapm, |
| 1071 | struct snd_soc_dapm_widget *w, int event) |
| 1072 | { |
| 1073 | struct snd_soc_card *card = dapm->card; |
| 1074 | const char *ev_name; |
| 1075 | int power, ret; |
| 1076 | |
| 1077 | switch (event) { |
| 1078 | case SND_SOC_DAPM_PRE_PMU: |
| 1079 | ev_name = "PRE_PMU"; |
| 1080 | power = 1; |
| 1081 | break; |
| 1082 | case SND_SOC_DAPM_POST_PMU: |
| 1083 | ev_name = "POST_PMU"; |
| 1084 | power = 1; |
| 1085 | break; |
| 1086 | case SND_SOC_DAPM_PRE_PMD: |
| 1087 | ev_name = "PRE_PMD"; |
| 1088 | power = 0; |
| 1089 | break; |
| 1090 | case SND_SOC_DAPM_POST_PMD: |
| 1091 | ev_name = "POST_PMD"; |
| 1092 | power = 0; |
| 1093 | break; |
| 1094 | default: |
| 1095 | BUG(); |
| 1096 | return; |
| 1097 | } |
| 1098 | |
| 1099 | if (w->power != power) |
| 1100 | return; |
| 1101 | |
| 1102 | if (w->event && (w->event_flags & event)) { |
| 1103 | pop_dbg(dapm->dev, card->pop_time, "pop test : %s %s\n", |
| 1104 | w->name, ev_name); |
Mark Brown | 84e9093 | 2010-11-04 00:07:02 -0400 | [diff] [blame] | 1105 | trace_snd_soc_dapm_widget_event_start(w, event); |
Mark Brown | 68f89ad | 2010-11-03 23:51:49 -0400 | [diff] [blame] | 1106 | ret = w->event(w, NULL, event); |
Mark Brown | 84e9093 | 2010-11-04 00:07:02 -0400 | [diff] [blame] | 1107 | trace_snd_soc_dapm_widget_event_done(w, event); |
Mark Brown | 68f89ad | 2010-11-03 23:51:49 -0400 | [diff] [blame] | 1108 | if (ret < 0) |
| 1109 | pr_err("%s: %s event failed: %d\n", |
| 1110 | ev_name, w->name, ret); |
| 1111 | } |
| 1112 | } |
| 1113 | |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1114 | /* Apply the coalesced changes from a DAPM sequence */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1115 | static void dapm_seq_run_coalesced(struct snd_soc_dapm_context *dapm, |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1116 | struct list_head *pending) |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1117 | { |
Jarkko Nikula | 3a45b86 | 2010-11-05 20:35:21 +0200 | [diff] [blame] | 1118 | struct snd_soc_card *card = dapm->card; |
Liam Girdwood | ecc1a0d | 2011-02-16 16:24:17 +0000 | [diff] [blame] | 1119 | struct snd_soc_dapm_widget *w, *_w; |
Mark Brown | 68f89ad | 2010-11-03 23:51:49 -0400 | [diff] [blame] | 1120 | int reg, power; |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1121 | unsigned int value = 0; |
| 1122 | unsigned int mask = 0; |
| 1123 | unsigned int cur_mask; |
| 1124 | |
Liam Girdwood | ecc1a0d | 2011-02-16 16:24:17 +0000 | [diff] [blame] | 1125 | _w = list_first_entry(pending, struct snd_soc_dapm_widget, |
| 1126 | power_list); |
| 1127 | reg = _w->reg; |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1128 | |
| 1129 | list_for_each_entry(w, pending, power_list) { |
| 1130 | cur_mask = 1 << w->shift; |
| 1131 | BUG_ON(reg != w->reg); |
| 1132 | |
| 1133 | if (w->invert) |
| 1134 | power = !w->power; |
| 1135 | else |
| 1136 | power = w->power; |
| 1137 | |
| 1138 | mask |= cur_mask; |
| 1139 | if (power) |
| 1140 | value |= cur_mask; |
| 1141 | |
Jarkko Nikula | fd8d3bc | 2010-11-09 14:40:28 +0200 | [diff] [blame] | 1142 | pop_dbg(dapm->dev, card->pop_time, |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1143 | "pop test : Queue %s: reg=0x%x, 0x%x/0x%x\n", |
| 1144 | w->name, reg, value, mask); |
Mark Brown | 8162810 | 2009-06-07 13:21:24 +0100 | [diff] [blame] | 1145 | |
Mark Brown | 68f89ad | 2010-11-03 23:51:49 -0400 | [diff] [blame] | 1146 | /* Check for events */ |
| 1147 | dapm_seq_check_event(dapm, w, SND_SOC_DAPM_PRE_PMU); |
| 1148 | dapm_seq_check_event(dapm, w, SND_SOC_DAPM_PRE_PMD); |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1149 | } |
| 1150 | |
Mark Brown | 8162810 | 2009-06-07 13:21:24 +0100 | [diff] [blame] | 1151 | if (reg >= 0) { |
Jarkko Nikula | fd8d3bc | 2010-11-09 14:40:28 +0200 | [diff] [blame] | 1152 | pop_dbg(dapm->dev, card->pop_time, |
Mark Brown | 8162810 | 2009-06-07 13:21:24 +0100 | [diff] [blame] | 1153 | "pop test : Applying 0x%x/0x%x to %x in %dms\n", |
Jarkko Nikula | 3a45b86 | 2010-11-05 20:35:21 +0200 | [diff] [blame] | 1154 | value, mask, reg, card->pop_time); |
| 1155 | pop_wait(card->pop_time); |
Liam Girdwood | ecc1a0d | 2011-02-16 16:24:17 +0000 | [diff] [blame] | 1156 | soc_widget_update_bits(_w, reg, mask, value); |
Mark Brown | 8162810 | 2009-06-07 13:21:24 +0100 | [diff] [blame] | 1157 | } |
| 1158 | |
| 1159 | list_for_each_entry(w, pending, power_list) { |
Mark Brown | 68f89ad | 2010-11-03 23:51:49 -0400 | [diff] [blame] | 1160 | dapm_seq_check_event(dapm, w, SND_SOC_DAPM_POST_PMU); |
| 1161 | dapm_seq_check_event(dapm, w, SND_SOC_DAPM_POST_PMD); |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 1162 | } |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 1163 | } |
| 1164 | |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1165 | /* Apply a DAPM power sequence. |
| 1166 | * |
| 1167 | * We walk over a pre-sorted list of widgets to apply power to. In |
| 1168 | * order to minimise the number of writes to the device required |
| 1169 | * multiple widgets will be updated in a single write where possible. |
| 1170 | * Currently anything that requires more than a single write is not |
| 1171 | * handled. |
| 1172 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1173 | static void dapm_seq_run(struct snd_soc_dapm_context *dapm, |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 1174 | struct list_head *list, int event, bool power_up) |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1175 | { |
| 1176 | struct snd_soc_dapm_widget *w, *n; |
| 1177 | LIST_HEAD(pending); |
| 1178 | int cur_sort = -1; |
Mark Brown | 20e4859 | 2011-01-15 13:40:50 +0000 | [diff] [blame] | 1179 | int cur_subseq = -1; |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1180 | int cur_reg = SND_SOC_NOPM; |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 1181 | struct snd_soc_dapm_context *cur_dapm = NULL; |
Mark Brown | 474b62d | 2011-01-18 16:14:44 +0000 | [diff] [blame] | 1182 | int ret, i; |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 1183 | int *sort; |
| 1184 | |
| 1185 | if (power_up) |
| 1186 | sort = dapm_up_seq; |
| 1187 | else |
| 1188 | sort = dapm_down_seq; |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1189 | |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1190 | list_for_each_entry_safe(w, n, list, power_list) { |
| 1191 | ret = 0; |
| 1192 | |
| 1193 | /* Do we need to apply any queued changes? */ |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 1194 | if (sort[w->id] != cur_sort || w->reg != cur_reg || |
Mark Brown | 20e4859 | 2011-01-15 13:40:50 +0000 | [diff] [blame] | 1195 | w->dapm != cur_dapm || w->subseq != cur_subseq) { |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1196 | if (!list_empty(&pending)) |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 1197 | dapm_seq_run_coalesced(cur_dapm, &pending); |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1198 | |
Mark Brown | 474b62d | 2011-01-18 16:14:44 +0000 | [diff] [blame] | 1199 | if (cur_dapm && cur_dapm->seq_notifier) { |
| 1200 | for (i = 0; i < ARRAY_SIZE(dapm_up_seq); i++) |
| 1201 | if (sort[i] == cur_sort) |
| 1202 | cur_dapm->seq_notifier(cur_dapm, |
Mark Brown | f85a9e0 | 2011-01-26 21:41:28 +0000 | [diff] [blame] | 1203 | i, |
| 1204 | cur_subseq); |
Mark Brown | 474b62d | 2011-01-18 16:14:44 +0000 | [diff] [blame] | 1205 | } |
| 1206 | |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1207 | INIT_LIST_HEAD(&pending); |
| 1208 | cur_sort = -1; |
Mark Brown | 20e4859 | 2011-01-15 13:40:50 +0000 | [diff] [blame] | 1209 | cur_subseq = -1; |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1210 | cur_reg = SND_SOC_NOPM; |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 1211 | cur_dapm = NULL; |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1212 | } |
| 1213 | |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1214 | switch (w->id) { |
| 1215 | case snd_soc_dapm_pre: |
| 1216 | if (!w->event) |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1217 | list_for_each_entry_safe_continue(w, n, list, |
| 1218 | power_list); |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1219 | |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1220 | if (event == SND_SOC_DAPM_STREAM_START) |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1221 | ret = w->event(w, |
| 1222 | NULL, SND_SOC_DAPM_PRE_PMU); |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1223 | else if (event == SND_SOC_DAPM_STREAM_STOP) |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1224 | ret = w->event(w, |
| 1225 | NULL, SND_SOC_DAPM_PRE_PMD); |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1226 | break; |
| 1227 | |
| 1228 | case snd_soc_dapm_post: |
| 1229 | if (!w->event) |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1230 | list_for_each_entry_safe_continue(w, n, list, |
| 1231 | power_list); |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1232 | |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1233 | if (event == SND_SOC_DAPM_STREAM_START) |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1234 | ret = w->event(w, |
| 1235 | NULL, SND_SOC_DAPM_POST_PMU); |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1236 | else if (event == SND_SOC_DAPM_STREAM_STOP) |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1237 | ret = w->event(w, |
| 1238 | NULL, SND_SOC_DAPM_POST_PMD); |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1239 | break; |
| 1240 | |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1241 | default: |
Mark Brown | 8162810 | 2009-06-07 13:21:24 +0100 | [diff] [blame] | 1242 | /* Queue it up for application */ |
| 1243 | cur_sort = sort[w->id]; |
Mark Brown | 20e4859 | 2011-01-15 13:40:50 +0000 | [diff] [blame] | 1244 | cur_subseq = w->subseq; |
Mark Brown | 8162810 | 2009-06-07 13:21:24 +0100 | [diff] [blame] | 1245 | cur_reg = w->reg; |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 1246 | cur_dapm = w->dapm; |
Mark Brown | 8162810 | 2009-06-07 13:21:24 +0100 | [diff] [blame] | 1247 | list_move(&w->power_list, &pending); |
| 1248 | break; |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1249 | } |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1250 | |
| 1251 | if (ret < 0) |
Jarkko Nikula | f7d41ae | 2010-11-09 14:40:27 +0200 | [diff] [blame] | 1252 | dev_err(w->dapm->dev, |
| 1253 | "Failed to apply widget power: %d\n", ret); |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1254 | } |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1255 | |
| 1256 | if (!list_empty(&pending)) |
Mark Brown | 28e8680 | 2011-03-08 19:29:53 +0000 | [diff] [blame] | 1257 | dapm_seq_run_coalesced(cur_dapm, &pending); |
Mark Brown | 474b62d | 2011-01-18 16:14:44 +0000 | [diff] [blame] | 1258 | |
| 1259 | if (cur_dapm && cur_dapm->seq_notifier) { |
| 1260 | for (i = 0; i < ARRAY_SIZE(dapm_up_seq); i++) |
| 1261 | if (sort[i] == cur_sort) |
| 1262 | cur_dapm->seq_notifier(cur_dapm, |
Mark Brown | f85a9e0 | 2011-01-26 21:41:28 +0000 | [diff] [blame] | 1263 | i, cur_subseq); |
Mark Brown | 474b62d | 2011-01-18 16:14:44 +0000 | [diff] [blame] | 1264 | } |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1265 | } |
| 1266 | |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 1267 | static void dapm_widget_update(struct snd_soc_dapm_context *dapm) |
| 1268 | { |
| 1269 | struct snd_soc_dapm_update *update = dapm->update; |
| 1270 | struct snd_soc_dapm_widget *w; |
| 1271 | int ret; |
| 1272 | |
| 1273 | if (!update) |
| 1274 | return; |
| 1275 | |
| 1276 | w = update->widget; |
| 1277 | |
| 1278 | if (w->event && |
| 1279 | (w->event_flags & SND_SOC_DAPM_PRE_REG)) { |
| 1280 | ret = w->event(w, update->kcontrol, SND_SOC_DAPM_PRE_REG); |
| 1281 | if (ret != 0) |
| 1282 | pr_err("%s DAPM pre-event failed: %d\n", |
| 1283 | w->name, ret); |
| 1284 | } |
| 1285 | |
| 1286 | ret = snd_soc_update_bits(w->codec, update->reg, update->mask, |
| 1287 | update->val); |
| 1288 | if (ret < 0) |
| 1289 | pr_err("%s DAPM update failed: %d\n", w->name, ret); |
| 1290 | |
| 1291 | if (w->event && |
| 1292 | (w->event_flags & SND_SOC_DAPM_POST_REG)) { |
| 1293 | ret = w->event(w, update->kcontrol, SND_SOC_DAPM_POST_REG); |
| 1294 | if (ret != 0) |
| 1295 | pr_err("%s DAPM post-event failed: %d\n", |
| 1296 | w->name, ret); |
| 1297 | } |
| 1298 | } |
| 1299 | |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1300 | /* Async callback run prior to DAPM sequences - brings to _PREPARE if |
| 1301 | * they're changing state. |
| 1302 | */ |
| 1303 | static void dapm_pre_sequence_async(void *data, async_cookie_t cookie) |
| 1304 | { |
| 1305 | struct snd_soc_dapm_context *d = data; |
| 1306 | int ret; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 1307 | |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1308 | if (d->dev_power && d->bias_level == SND_SOC_BIAS_OFF) { |
| 1309 | ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_STANDBY); |
| 1310 | if (ret != 0) |
| 1311 | dev_err(d->dev, |
| 1312 | "Failed to turn on bias: %d\n", ret); |
| 1313 | } |
| 1314 | |
| 1315 | /* If we're changing to all on or all off then prepare */ |
| 1316 | if ((d->dev_power && d->bias_level == SND_SOC_BIAS_STANDBY) || |
| 1317 | (!d->dev_power && d->bias_level == SND_SOC_BIAS_ON)) { |
| 1318 | ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_PREPARE); |
| 1319 | if (ret != 0) |
| 1320 | dev_err(d->dev, |
| 1321 | "Failed to prepare bias: %d\n", ret); |
| 1322 | } |
| 1323 | } |
| 1324 | |
| 1325 | /* Async callback run prior to DAPM sequences - brings to their final |
| 1326 | * state. |
| 1327 | */ |
| 1328 | static void dapm_post_sequence_async(void *data, async_cookie_t cookie) |
| 1329 | { |
| 1330 | struct snd_soc_dapm_context *d = data; |
| 1331 | int ret; |
| 1332 | |
| 1333 | /* If we just powered the last thing off drop to standby bias */ |
| 1334 | if (d->bias_level == SND_SOC_BIAS_PREPARE && !d->dev_power) { |
| 1335 | ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_STANDBY); |
| 1336 | if (ret != 0) |
| 1337 | dev_err(d->dev, "Failed to apply standby bias: %d\n", |
| 1338 | ret); |
| 1339 | } |
| 1340 | |
| 1341 | /* If we're in standby and can support bias off then do that */ |
| 1342 | if (d->bias_level == SND_SOC_BIAS_STANDBY && d->idle_bias_off) { |
| 1343 | ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_OFF); |
| 1344 | if (ret != 0) |
| 1345 | dev_err(d->dev, "Failed to turn off bias: %d\n", ret); |
| 1346 | } |
| 1347 | |
| 1348 | /* If we just powered up then move to active bias */ |
| 1349 | if (d->bias_level == SND_SOC_BIAS_PREPARE && d->dev_power) { |
| 1350 | ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_ON); |
| 1351 | if (ret != 0) |
| 1352 | dev_err(d->dev, "Failed to apply active bias: %d\n", |
| 1353 | ret); |
| 1354 | } |
| 1355 | } |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 1356 | |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 1357 | /* |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1358 | * Scan each dapm widget for complete audio path. |
| 1359 | * A complete path is a route that has valid endpoints i.e.:- |
| 1360 | * |
| 1361 | * o DAC to output pin. |
| 1362 | * o Input Pin to ADC. |
| 1363 | * o Input pin to Output pin (bypass, sidetone) |
| 1364 | * o DAC to ADC (loopback). |
| 1365 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1366 | static int dapm_power_widgets(struct snd_soc_dapm_context *dapm, int event) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1367 | { |
Mark Brown | 12ea2c7 | 2011-03-02 18:17:32 +0000 | [diff] [blame] | 1368 | struct snd_soc_card *card = dapm->card; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1369 | struct snd_soc_dapm_widget *w; |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 1370 | struct snd_soc_dapm_context *d; |
Mark Brown | 291f3bb | 2009-06-07 13:57:17 +0100 | [diff] [blame] | 1371 | LIST_HEAD(up_list); |
| 1372 | LIST_HEAD(down_list); |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1373 | LIST_HEAD(async_domain); |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 1374 | int power; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1375 | |
Mark Brown | 84e9093 | 2010-11-04 00:07:02 -0400 | [diff] [blame] | 1376 | trace_snd_soc_dapm_start(card); |
| 1377 | |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 1378 | list_for_each_entry(d, &card->dapm_list, list) |
Jarkko Nikula | ea77b94 | 2011-05-26 16:32:18 +0300 | [diff] [blame] | 1379 | if (d->n_widgets || d->codec == NULL) |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 1380 | d->dev_power = 0; |
| 1381 | |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1382 | /* Check which widgets we need to power and store them in |
| 1383 | * lists indicating if they should be powered up or down. |
| 1384 | */ |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 1385 | list_for_each_entry(w, &card->widgets, list) { |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1386 | switch (w->id) { |
| 1387 | case snd_soc_dapm_pre: |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 1388 | dapm_seq_insert(w, &down_list, false); |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1389 | break; |
| 1390 | case snd_soc_dapm_post: |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 1391 | dapm_seq_insert(w, &up_list, true); |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1392 | break; |
| 1393 | |
| 1394 | default: |
| 1395 | if (!w->power_check) |
| 1396 | continue; |
| 1397 | |
Mark Brown | 9949788 | 2010-05-07 20:24:05 +0100 | [diff] [blame] | 1398 | if (!w->force) |
Mark Brown | 50b6bce | 2009-11-23 13:11:53 +0000 | [diff] [blame] | 1399 | power = w->power_check(w); |
Mark Brown | 9949788 | 2010-05-07 20:24:05 +0100 | [diff] [blame] | 1400 | else |
| 1401 | power = 1; |
| 1402 | if (power) |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 1403 | w->dapm->dev_power = 1; |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 1404 | |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1405 | if (w->power == power) |
| 1406 | continue; |
| 1407 | |
Mark Brown | 84e9093 | 2010-11-04 00:07:02 -0400 | [diff] [blame] | 1408 | trace_snd_soc_dapm_widget_power(w, power); |
| 1409 | |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1410 | if (power) |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 1411 | dapm_seq_insert(w, &up_list, true); |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1412 | else |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 1413 | dapm_seq_insert(w, &down_list, false); |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1414 | |
| 1415 | w->power = power; |
| 1416 | break; |
| 1417 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1418 | } |
| 1419 | |
Mark Brown | b14b76a | 2009-08-17 11:55:38 +0100 | [diff] [blame] | 1420 | /* If there are no DAPM widgets then try to figure out power from the |
| 1421 | * event type. |
| 1422 | */ |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 1423 | if (!dapm->n_widgets) { |
Mark Brown | b14b76a | 2009-08-17 11:55:38 +0100 | [diff] [blame] | 1424 | switch (event) { |
| 1425 | case SND_SOC_DAPM_STREAM_START: |
| 1426 | case SND_SOC_DAPM_STREAM_RESUME: |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 1427 | dapm->dev_power = 1; |
Mark Brown | b14b76a | 2009-08-17 11:55:38 +0100 | [diff] [blame] | 1428 | break; |
Jarkko Nikula | 862af8a | 2010-12-10 20:53:55 +0200 | [diff] [blame] | 1429 | case SND_SOC_DAPM_STREAM_STOP: |
Liam Girdwood | 7987a11 | 2011-01-31 19:52:42 +0000 | [diff] [blame] | 1430 | #warning need re-work |
| 1431 | if (dapm->codec) |
| 1432 | dapm->dev_power = !!dapm->codec->active; |
| 1433 | else |
| 1434 | dapm->dev_power = 0; |
Jarkko Nikula | 862af8a | 2010-12-10 20:53:55 +0200 | [diff] [blame] | 1435 | break; |
Mark Brown | 50b6bce | 2009-11-23 13:11:53 +0000 | [diff] [blame] | 1436 | case SND_SOC_DAPM_STREAM_SUSPEND: |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 1437 | dapm->dev_power = 0; |
Mark Brown | 50b6bce | 2009-11-23 13:11:53 +0000 | [diff] [blame] | 1438 | break; |
Mark Brown | b14b76a | 2009-08-17 11:55:38 +0100 | [diff] [blame] | 1439 | case SND_SOC_DAPM_STREAM_NOP: |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1440 | switch (dapm->bias_level) { |
Mark Brown | a96ca33 | 2010-01-19 22:49:43 +0000 | [diff] [blame] | 1441 | case SND_SOC_BIAS_STANDBY: |
| 1442 | case SND_SOC_BIAS_OFF: |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 1443 | dapm->dev_power = 0; |
Mark Brown | a96ca33 | 2010-01-19 22:49:43 +0000 | [diff] [blame] | 1444 | break; |
| 1445 | default: |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 1446 | dapm->dev_power = 1; |
Mark Brown | a96ca33 | 2010-01-19 22:49:43 +0000 | [diff] [blame] | 1447 | break; |
| 1448 | } |
Mark Brown | 50b6bce | 2009-11-23 13:11:53 +0000 | [diff] [blame] | 1449 | break; |
Mark Brown | b14b76a | 2009-08-17 11:55:38 +0100 | [diff] [blame] | 1450 | default: |
| 1451 | break; |
| 1452 | } |
| 1453 | } |
| 1454 | |
Mark Brown | 52ba67b | 2011-04-04 21:05:11 +0900 | [diff] [blame] | 1455 | /* Force all contexts in the card to the same bias state */ |
| 1456 | power = 0; |
| 1457 | list_for_each_entry(d, &card->dapm_list, list) |
| 1458 | if (d->dev_power) |
| 1459 | power = 1; |
| 1460 | list_for_each_entry(d, &card->dapm_list, list) |
| 1461 | d->dev_power = power; |
| 1462 | |
| 1463 | |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1464 | /* Run all the bias changes in parallel */ |
| 1465 | list_for_each_entry(d, &dapm->card->dapm_list, list) |
| 1466 | async_schedule_domain(dapm_pre_sequence_async, d, |
| 1467 | &async_domain); |
| 1468 | async_synchronize_full_domain(&async_domain); |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 1469 | |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1470 | /* Power down widgets first; try to avoid amplifying pops. */ |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 1471 | dapm_seq_run(dapm, &down_list, event, false); |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1472 | |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 1473 | dapm_widget_update(dapm); |
| 1474 | |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1475 | /* Now power up. */ |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 1476 | dapm_seq_run(dapm, &up_list, event, true); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1477 | |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1478 | /* Run all the bias changes in parallel */ |
| 1479 | list_for_each_entry(d, &dapm->card->dapm_list, list) |
| 1480 | async_schedule_domain(dapm_post_sequence_async, d, |
| 1481 | &async_domain); |
| 1482 | async_synchronize_full_domain(&async_domain); |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 1483 | |
Jarkko Nikula | fd8d3bc | 2010-11-09 14:40:28 +0200 | [diff] [blame] | 1484 | pop_dbg(dapm->dev, card->pop_time, |
| 1485 | "DAPM sequencing finished, waiting %dms\n", card->pop_time); |
Jarkko Nikula | 3a45b86 | 2010-11-05 20:35:21 +0200 | [diff] [blame] | 1486 | pop_wait(card->pop_time); |
Mark Brown | cb507e7 | 2009-07-08 18:54:57 +0100 | [diff] [blame] | 1487 | |
Mark Brown | 84e9093 | 2010-11-04 00:07:02 -0400 | [diff] [blame] | 1488 | trace_snd_soc_dapm_done(card); |
| 1489 | |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 1490 | return 0; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1491 | } |
| 1492 | |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1493 | #ifdef CONFIG_DEBUG_FS |
| 1494 | static int dapm_widget_power_open_file(struct inode *inode, struct file *file) |
| 1495 | { |
| 1496 | file->private_data = inode->i_private; |
| 1497 | return 0; |
| 1498 | } |
| 1499 | |
| 1500 | static ssize_t dapm_widget_power_read_file(struct file *file, |
| 1501 | char __user *user_buf, |
| 1502 | size_t count, loff_t *ppos) |
| 1503 | { |
| 1504 | struct snd_soc_dapm_widget *w = file->private_data; |
| 1505 | char *buf; |
| 1506 | int in, out; |
| 1507 | ssize_t ret; |
| 1508 | struct snd_soc_dapm_path *p = NULL; |
| 1509 | |
| 1510 | buf = kmalloc(PAGE_SIZE, GFP_KERNEL); |
| 1511 | if (!buf) |
| 1512 | return -ENOMEM; |
| 1513 | |
| 1514 | in = is_connected_input_ep(w); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1515 | dapm_clear_walk(w->dapm); |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1516 | out = is_connected_output_ep(w); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1517 | dapm_clear_walk(w->dapm); |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1518 | |
Mark Brown | d033c36 | 2009-12-04 15:25:56 +0000 | [diff] [blame] | 1519 | ret = snprintf(buf, PAGE_SIZE, "%s: %s in %d out %d", |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1520 | w->name, w->power ? "On" : "Off", in, out); |
| 1521 | |
Mark Brown | d033c36 | 2009-12-04 15:25:56 +0000 | [diff] [blame] | 1522 | if (w->reg >= 0) |
| 1523 | ret += snprintf(buf + ret, PAGE_SIZE - ret, |
| 1524 | " - R%d(0x%x) bit %d", |
| 1525 | w->reg, w->reg, w->shift); |
| 1526 | |
| 1527 | ret += snprintf(buf + ret, PAGE_SIZE - ret, "\n"); |
| 1528 | |
Mark Brown | 3eef08b | 2009-09-14 16:49:00 +0100 | [diff] [blame] | 1529 | if (w->sname) |
| 1530 | ret += snprintf(buf + ret, PAGE_SIZE - ret, " stream %s %s\n", |
| 1531 | w->sname, |
| 1532 | w->active ? "active" : "inactive"); |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1533 | |
| 1534 | list_for_each_entry(p, &w->sources, list_sink) { |
Mark Brown | 215edda | 2009-09-08 18:59:05 +0100 | [diff] [blame] | 1535 | if (p->connected && !p->connected(w, p->sink)) |
| 1536 | continue; |
| 1537 | |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1538 | if (p->connect) |
| 1539 | ret += snprintf(buf + ret, PAGE_SIZE - ret, |
Dimitris Papastamos | 67f5ed6 | 2011-02-24 17:09:32 +0000 | [diff] [blame] | 1540 | " in \"%s\" \"%s\"\n", |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1541 | p->name ? p->name : "static", |
| 1542 | p->source->name); |
| 1543 | } |
| 1544 | list_for_each_entry(p, &w->sinks, list_source) { |
Mark Brown | 215edda | 2009-09-08 18:59:05 +0100 | [diff] [blame] | 1545 | if (p->connected && !p->connected(w, p->sink)) |
| 1546 | continue; |
| 1547 | |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1548 | if (p->connect) |
| 1549 | ret += snprintf(buf + ret, PAGE_SIZE - ret, |
Dimitris Papastamos | 67f5ed6 | 2011-02-24 17:09:32 +0000 | [diff] [blame] | 1550 | " out \"%s\" \"%s\"\n", |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1551 | p->name ? p->name : "static", |
| 1552 | p->sink->name); |
| 1553 | } |
| 1554 | |
| 1555 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); |
| 1556 | |
| 1557 | kfree(buf); |
| 1558 | return ret; |
| 1559 | } |
| 1560 | |
| 1561 | static const struct file_operations dapm_widget_power_fops = { |
| 1562 | .open = dapm_widget_power_open_file, |
| 1563 | .read = dapm_widget_power_read_file, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 1564 | .llseek = default_llseek, |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1565 | }; |
| 1566 | |
Mark Brown | ef49e4f | 2011-04-04 20:48:13 +0900 | [diff] [blame] | 1567 | static int dapm_bias_open_file(struct inode *inode, struct file *file) |
| 1568 | { |
| 1569 | file->private_data = inode->i_private; |
| 1570 | return 0; |
| 1571 | } |
| 1572 | |
| 1573 | static ssize_t dapm_bias_read_file(struct file *file, char __user *user_buf, |
| 1574 | size_t count, loff_t *ppos) |
| 1575 | { |
| 1576 | struct snd_soc_dapm_context *dapm = file->private_data; |
| 1577 | char *level; |
| 1578 | |
| 1579 | switch (dapm->bias_level) { |
| 1580 | case SND_SOC_BIAS_ON: |
| 1581 | level = "On\n"; |
| 1582 | break; |
| 1583 | case SND_SOC_BIAS_PREPARE: |
| 1584 | level = "Prepare\n"; |
| 1585 | break; |
| 1586 | case SND_SOC_BIAS_STANDBY: |
| 1587 | level = "Standby\n"; |
| 1588 | break; |
| 1589 | case SND_SOC_BIAS_OFF: |
| 1590 | level = "Off\n"; |
| 1591 | break; |
| 1592 | default: |
| 1593 | BUG(); |
| 1594 | level = "Unknown\n"; |
| 1595 | break; |
| 1596 | } |
| 1597 | |
| 1598 | return simple_read_from_buffer(user_buf, count, ppos, level, |
| 1599 | strlen(level)); |
| 1600 | } |
| 1601 | |
| 1602 | static const struct file_operations dapm_bias_fops = { |
| 1603 | .open = dapm_bias_open_file, |
| 1604 | .read = dapm_bias_read_file, |
| 1605 | .llseek = default_llseek, |
| 1606 | }; |
| 1607 | |
Lars-Peter Clausen | 8eecaf6 | 2011-04-30 19:45:48 +0200 | [diff] [blame] | 1608 | void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm, |
| 1609 | struct dentry *parent) |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1610 | { |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1611 | struct dentry *d; |
| 1612 | |
Lars-Peter Clausen | 8eecaf6 | 2011-04-30 19:45:48 +0200 | [diff] [blame] | 1613 | dapm->debugfs_dapm = debugfs_create_dir("dapm", parent); |
| 1614 | |
| 1615 | if (!dapm->debugfs_dapm) { |
| 1616 | printk(KERN_WARNING |
| 1617 | "Failed to create DAPM debugfs directory\n"); |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1618 | return; |
Lars-Peter Clausen | 8eecaf6 | 2011-04-30 19:45:48 +0200 | [diff] [blame] | 1619 | } |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1620 | |
Mark Brown | ef49e4f | 2011-04-04 20:48:13 +0900 | [diff] [blame] | 1621 | d = debugfs_create_file("bias_level", 0444, |
| 1622 | dapm->debugfs_dapm, dapm, |
| 1623 | &dapm_bias_fops); |
| 1624 | if (!d) |
| 1625 | dev_warn(dapm->dev, |
| 1626 | "ASoC: Failed to create bias level debugfs file\n"); |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1627 | } |
Lars-Peter Clausen | d5d1e0b | 2011-04-30 19:45:49 +0200 | [diff] [blame] | 1628 | |
| 1629 | static void dapm_debugfs_add_widget(struct snd_soc_dapm_widget *w) |
| 1630 | { |
| 1631 | struct snd_soc_dapm_context *dapm = w->dapm; |
| 1632 | struct dentry *d; |
| 1633 | |
| 1634 | if (!dapm->debugfs_dapm || !w->name) |
| 1635 | return; |
| 1636 | |
| 1637 | d = debugfs_create_file(w->name, 0444, |
| 1638 | dapm->debugfs_dapm, w, |
| 1639 | &dapm_widget_power_fops); |
| 1640 | if (!d) |
| 1641 | dev_warn(w->dapm->dev, |
| 1642 | "ASoC: Failed to create %s debugfs file\n", |
| 1643 | w->name); |
| 1644 | } |
| 1645 | |
Lars-Peter Clausen | 6c45e12 | 2011-04-30 19:45:50 +0200 | [diff] [blame] | 1646 | static void dapm_debugfs_cleanup(struct snd_soc_dapm_context *dapm) |
| 1647 | { |
| 1648 | debugfs_remove_recursive(dapm->debugfs_dapm); |
| 1649 | } |
| 1650 | |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1651 | #else |
Lars-Peter Clausen | 8eecaf6 | 2011-04-30 19:45:48 +0200 | [diff] [blame] | 1652 | void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm, |
| 1653 | struct dentry *parent) |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1654 | { |
| 1655 | } |
Lars-Peter Clausen | d5d1e0b | 2011-04-30 19:45:49 +0200 | [diff] [blame] | 1656 | |
| 1657 | static inline void dapm_debugfs_add_widget(struct snd_soc_dapm_widget *w) |
| 1658 | { |
| 1659 | } |
| 1660 | |
Lars-Peter Clausen | 6c45e12 | 2011-04-30 19:45:50 +0200 | [diff] [blame] | 1661 | static inline void dapm_debugfs_cleanup(struct snd_soc_dapm_context *dapm) |
| 1662 | { |
| 1663 | } |
| 1664 | |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1665 | #endif |
| 1666 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1667 | /* test and update the power status of a mux widget */ |
Liam Girdwood | e002c98 | 2011-02-08 11:45:20 +0000 | [diff] [blame] | 1668 | int snd_soc_dapm_mux_update_power(struct snd_soc_dapm_widget *widget, |
Mark Brown | 3a65577 | 2009-10-05 17:23:30 +0100 | [diff] [blame] | 1669 | struct snd_kcontrol *kcontrol, int change, |
| 1670 | int mux, struct soc_enum *e) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1671 | { |
| 1672 | struct snd_soc_dapm_path *path; |
| 1673 | int found = 0; |
| 1674 | |
Peter Ujfalusi | eff317d | 2009-01-15 14:40:47 +0200 | [diff] [blame] | 1675 | if (widget->id != snd_soc_dapm_mux && |
Dimitris Papastamos | 24ff33a | 2010-12-16 15:53:39 +0000 | [diff] [blame] | 1676 | widget->id != snd_soc_dapm_virt_mux && |
Peter Ujfalusi | eff317d | 2009-01-15 14:40:47 +0200 | [diff] [blame] | 1677 | widget->id != snd_soc_dapm_value_mux) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1678 | return -ENODEV; |
| 1679 | |
Mark Brown | 3a65577 | 2009-10-05 17:23:30 +0100 | [diff] [blame] | 1680 | if (!change) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1681 | return 0; |
| 1682 | |
| 1683 | /* find dapm widget path assoc with kcontrol */ |
Jarkko Nikula | 8ddab3f | 2010-12-14 12:18:30 +0200 | [diff] [blame] | 1684 | list_for_each_entry(path, &widget->dapm->card->paths, list) { |
Liam Girdwood | e002c98 | 2011-02-08 11:45:20 +0000 | [diff] [blame] | 1685 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1686 | if (path->kcontrol != kcontrol) |
| 1687 | continue; |
| 1688 | |
Liam Girdwood | a8f13d8 | 2011-05-18 18:39:21 +0100 | [diff] [blame^] | 1689 | if (!path->name || !snd_soc_get_enum_text(e, mux)) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1690 | continue; |
| 1691 | |
| 1692 | found = 1; |
| 1693 | /* we now need to match the string in the enum to the path */ |
Liam Girdwood | a8f13d8 | 2011-05-18 18:39:21 +0100 | [diff] [blame^] | 1694 | if (!(strcmp(path->name, snd_soc_get_enum_text(e, mux)))) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1695 | path->connect = 1; /* new connection */ |
| 1696 | else |
| 1697 | path->connect = 0; /* old connection must be powered down */ |
| 1698 | } |
| 1699 | |
Liam Girdwood | e002c98 | 2011-02-08 11:45:20 +0000 | [diff] [blame] | 1700 | if (found) { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1701 | dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP); |
Liam Girdwood | e002c98 | 2011-02-08 11:45:20 +0000 | [diff] [blame] | 1702 | soc_dsp_runtime_update(widget); |
| 1703 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1704 | |
| 1705 | return 0; |
| 1706 | } |
Liam Girdwood | e002c98 | 2011-02-08 11:45:20 +0000 | [diff] [blame] | 1707 | EXPORT_SYMBOL_GPL(snd_soc_dapm_mux_update_power); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1708 | |
Milan plzik | 1b075e3 | 2008-01-10 14:39:46 +0100 | [diff] [blame] | 1709 | /* test and update the power status of a mixer or switch widget */ |
Liam Girdwood | e002c98 | 2011-02-08 11:45:20 +0000 | [diff] [blame] | 1710 | int snd_soc_dapm_mixer_update_power(struct snd_soc_dapm_widget *widget, |
| 1711 | struct snd_kcontrol *kcontrol, int connect) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1712 | { |
| 1713 | struct snd_soc_dapm_path *path; |
| 1714 | int found = 0; |
| 1715 | |
Milan plzik | 1b075e3 | 2008-01-10 14:39:46 +0100 | [diff] [blame] | 1716 | if (widget->id != snd_soc_dapm_mixer && |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 1717 | widget->id != snd_soc_dapm_mixer_named_ctl && |
Milan plzik | 1b075e3 | 2008-01-10 14:39:46 +0100 | [diff] [blame] | 1718 | widget->id != snd_soc_dapm_switch) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1719 | return -ENODEV; |
| 1720 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1721 | /* find dapm widget path assoc with kcontrol */ |
Jarkko Nikula | 8ddab3f | 2010-12-14 12:18:30 +0200 | [diff] [blame] | 1722 | list_for_each_entry(path, &widget->dapm->card->paths, list) { |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1723 | if (path->kcontrol != kcontrol) |
| 1724 | continue; |
| 1725 | |
| 1726 | /* found, now check type */ |
| 1727 | found = 1; |
Mark Brown | 283375c | 2009-12-07 18:09:03 +0000 | [diff] [blame] | 1728 | path->connect = connect; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1729 | break; |
| 1730 | } |
| 1731 | |
Liam Girdwood | e002c98 | 2011-02-08 11:45:20 +0000 | [diff] [blame] | 1732 | if (found) { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1733 | dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP); |
Liam Girdwood | e002c98 | 2011-02-08 11:45:20 +0000 | [diff] [blame] | 1734 | soc_dsp_runtime_update(widget); |
| 1735 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1736 | |
| 1737 | return 0; |
| 1738 | } |
Liam Girdwood | e002c98 | 2011-02-08 11:45:20 +0000 | [diff] [blame] | 1739 | EXPORT_SYMBOL_GPL(snd_soc_dapm_mixer_update_power); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1740 | |
| 1741 | /* show dapm widget status in sys fs */ |
Liam Girdwood | 7987a11 | 2011-01-31 19:52:42 +0000 | [diff] [blame] | 1742 | static ssize_t widget_show(struct snd_soc_dapm_context *dapm, |
| 1743 | const char *name, char *buf, ssize_t count) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1744 | { |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1745 | struct snd_soc_dapm_widget *w; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1746 | char *state = "not set"; |
| 1747 | |
Liam Girdwood | 7987a11 | 2011-01-31 19:52:42 +0000 | [diff] [blame] | 1748 | count += sprintf(buf + count, "\n%s\n", name); |
| 1749 | |
Liam Girdwood | ab1058a | 2011-01-31 20:33:07 +0000 | [diff] [blame] | 1750 | list_for_each_entry(w, &dapm->card->widgets, list) { |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1751 | |
| 1752 | /* only display widgets that burnm power */ |
| 1753 | switch (w->id) { |
| 1754 | case snd_soc_dapm_hp: |
| 1755 | case snd_soc_dapm_mic: |
| 1756 | case snd_soc_dapm_spk: |
| 1757 | case snd_soc_dapm_line: |
| 1758 | case snd_soc_dapm_micbias: |
| 1759 | case snd_soc_dapm_dac: |
| 1760 | case snd_soc_dapm_adc: |
| 1761 | case snd_soc_dapm_pga: |
Olaya, Margarita | d88429a | 2010-12-10 21:11:44 -0600 | [diff] [blame] | 1762 | case snd_soc_dapm_out_drv: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1763 | case snd_soc_dapm_mixer: |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 1764 | case snd_soc_dapm_mixer_named_ctl: |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 1765 | case snd_soc_dapm_supply: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1766 | if (w->name) |
| 1767 | count += sprintf(buf + count, "%s: %s\n", |
| 1768 | w->name, w->power ? "On":"Off"); |
| 1769 | break; |
| 1770 | default: |
| 1771 | break; |
| 1772 | } |
| 1773 | } |
| 1774 | |
Liam Girdwood | 7987a11 | 2011-01-31 19:52:42 +0000 | [diff] [blame] | 1775 | switch (dapm->bias_level) { |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1776 | case SND_SOC_BIAS_ON: |
| 1777 | state = "On"; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1778 | break; |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1779 | case SND_SOC_BIAS_PREPARE: |
| 1780 | state = "Prepare"; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1781 | break; |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1782 | case SND_SOC_BIAS_STANDBY: |
| 1783 | state = "Standby"; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1784 | break; |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1785 | case SND_SOC_BIAS_OFF: |
| 1786 | state = "Off"; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1787 | break; |
| 1788 | } |
| 1789 | count += sprintf(buf + count, "PM State: %s\n", state); |
| 1790 | |
| 1791 | return count; |
| 1792 | } |
| 1793 | |
Liam Girdwood | 7987a11 | 2011-01-31 19:52:42 +0000 | [diff] [blame] | 1794 | /* show dapm widget status in sys fs */ |
| 1795 | static ssize_t dapm_widget_show(struct device *dev, |
| 1796 | struct device_attribute *attr, char *buf) |
| 1797 | { |
| 1798 | struct snd_soc_pcm_runtime *rtd = |
| 1799 | container_of(dev, struct snd_soc_pcm_runtime, dev); |
| 1800 | struct snd_soc_codec *codec = rtd->codec; |
| 1801 | struct snd_soc_platform *platform = rtd->platform; |
| 1802 | ssize_t count = 0; |
| 1803 | |
| 1804 | count += widget_show(&codec->dapm, codec->name, buf, count); |
| 1805 | count += widget_show(&platform->dapm, platform->name, buf, count); |
| 1806 | return count; |
| 1807 | } |
| 1808 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1809 | static DEVICE_ATTR(dapm_widget, 0444, dapm_widget_show, NULL); |
| 1810 | |
| 1811 | int snd_soc_dapm_sys_add(struct device *dev) |
| 1812 | { |
Troy Kisky | 12ef193 | 2008-10-13 17:42:14 -0700 | [diff] [blame] | 1813 | return device_create_file(dev, &dev_attr_dapm_widget); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1814 | } |
| 1815 | |
| 1816 | static void snd_soc_dapm_sys_remove(struct device *dev) |
| 1817 | { |
Mark Brown | aef9084 | 2009-05-16 17:53:16 +0100 | [diff] [blame] | 1818 | device_remove_file(dev, &dev_attr_dapm_widget); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1819 | } |
| 1820 | |
| 1821 | /* free all dapm widgets and resources */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1822 | static void dapm_free_widgets(struct snd_soc_dapm_context *dapm) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1823 | { |
| 1824 | struct snd_soc_dapm_widget *w, *next_w; |
| 1825 | struct snd_soc_dapm_path *p, *next_p; |
| 1826 | |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 1827 | list_for_each_entry_safe(w, next_w, &dapm->card->widgets, list) { |
| 1828 | if (w->dapm != dapm) |
| 1829 | continue; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1830 | list_del(&w->list); |
Jarkko Nikula | 8ddab3f | 2010-12-14 12:18:30 +0200 | [diff] [blame] | 1831 | /* |
| 1832 | * remove source and sink paths associated to this widget. |
| 1833 | * While removing the path, remove reference to it from both |
| 1834 | * source and sink widgets so that path is removed only once. |
| 1835 | */ |
| 1836 | list_for_each_entry_safe(p, next_p, &w->sources, list_sink) { |
| 1837 | list_del(&p->list_sink); |
| 1838 | list_del(&p->list_source); |
| 1839 | list_del(&p->list); |
| 1840 | kfree(p->long_name); |
| 1841 | kfree(p); |
| 1842 | } |
| 1843 | list_for_each_entry_safe(p, next_p, &w->sinks, list_source) { |
| 1844 | list_del(&p->list_sink); |
| 1845 | list_del(&p->list_source); |
| 1846 | list_del(&p->list); |
| 1847 | kfree(p->long_name); |
| 1848 | kfree(p); |
| 1849 | } |
Stephen Warren | fad5988 | 2011-04-28 17:37:59 -0600 | [diff] [blame] | 1850 | kfree(w->kcontrols); |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 1851 | kfree(w->name); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1852 | kfree(w); |
| 1853 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1854 | } |
| 1855 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 1856 | static struct snd_soc_dapm_widget *dapm_find_widget( |
| 1857 | struct snd_soc_dapm_context *dapm, const char *pin, |
| 1858 | bool search_other_contexts) |
| 1859 | { |
| 1860 | struct snd_soc_dapm_widget *w; |
| 1861 | struct snd_soc_dapm_widget *fallback = NULL; |
| 1862 | |
| 1863 | list_for_each_entry(w, &dapm->card->widgets, list) { |
| 1864 | if (!strcmp(w->name, pin)) { |
| 1865 | if (w->dapm == dapm) |
| 1866 | return w; |
| 1867 | else |
| 1868 | fallback = w; |
| 1869 | } |
| 1870 | } |
| 1871 | |
| 1872 | if (search_other_contexts) |
| 1873 | return fallback; |
| 1874 | |
| 1875 | return NULL; |
| 1876 | } |
| 1877 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1878 | static int snd_soc_dapm_set_pin(struct snd_soc_dapm_context *dapm, |
Mark Brown | 1649923 | 2009-01-07 18:25:13 +0000 | [diff] [blame] | 1879 | const char *pin, int status) |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 1880 | { |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 1881 | struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true); |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 1882 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 1883 | if (!w) { |
| 1884 | dev_err(dapm->dev, "dapm: unknown pin %s\n", pin); |
| 1885 | return -EINVAL; |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 1886 | } |
| 1887 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 1888 | w->connected = status; |
| 1889 | if (status == 0) |
| 1890 | w->force = 0; |
Mark Brown | 0d86733 | 2011-04-06 11:38:14 +0900 | [diff] [blame] | 1891 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 1892 | return 0; |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 1893 | } |
| 1894 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1895 | /** |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 1896 | * snd_soc_dapm_sync - scan and power dapm paths |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1897 | * @dapm: DAPM context |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1898 | * |
| 1899 | * Walks all dapm audio paths and powers widgets according to their |
| 1900 | * stream or path usage. |
| 1901 | * |
| 1902 | * Returns 0 for success. |
| 1903 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1904 | int snd_soc_dapm_sync(struct snd_soc_dapm_context *dapm) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1905 | { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1906 | return dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1907 | } |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 1908 | EXPORT_SYMBOL_GPL(snd_soc_dapm_sync); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1909 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1910 | static int snd_soc_dapm_add_route(struct snd_soc_dapm_context *dapm, |
Mark Brown | 215edda | 2009-09-08 18:59:05 +0100 | [diff] [blame] | 1911 | const struct snd_soc_dapm_route *route) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1912 | { |
| 1913 | struct snd_soc_dapm_path *path; |
| 1914 | struct snd_soc_dapm_widget *wsource = NULL, *wsink = NULL, *w; |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 1915 | struct snd_soc_dapm_widget *wtsource = NULL, *wtsink = NULL; |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 1916 | const char *sink; |
Mark Brown | 215edda | 2009-09-08 18:59:05 +0100 | [diff] [blame] | 1917 | const char *control = route->control; |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 1918 | const char *source; |
| 1919 | char prefixed_sink[80]; |
| 1920 | char prefixed_source[80]; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1921 | int ret = 0; |
| 1922 | |
Mark Brown | 88e8b9a | 2011-03-02 18:18:24 +0000 | [diff] [blame] | 1923 | if (dapm->codec && dapm->codec->name_prefix) { |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 1924 | snprintf(prefixed_sink, sizeof(prefixed_sink), "%s %s", |
| 1925 | dapm->codec->name_prefix, route->sink); |
| 1926 | sink = prefixed_sink; |
| 1927 | snprintf(prefixed_source, sizeof(prefixed_source), "%s %s", |
| 1928 | dapm->codec->name_prefix, route->source); |
| 1929 | source = prefixed_source; |
| 1930 | } else { |
| 1931 | sink = route->sink; |
| 1932 | source = route->source; |
| 1933 | } |
| 1934 | |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 1935 | /* |
| 1936 | * find src and dest widgets over all widgets but favor a widget from |
| 1937 | * current DAPM context |
| 1938 | */ |
| 1939 | list_for_each_entry(w, &dapm->card->widgets, list) { |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1940 | if (!wsink && !(strcmp(w->name, sink))) { |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 1941 | wtsink = w; |
| 1942 | if (w->dapm == dapm) |
| 1943 | wsink = w; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1944 | continue; |
| 1945 | } |
| 1946 | if (!wsource && !(strcmp(w->name, source))) { |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 1947 | wtsource = w; |
| 1948 | if (w->dapm == dapm) |
| 1949 | wsource = w; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1950 | } |
| 1951 | } |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 1952 | /* use widget from another DAPM context if not found from this */ |
| 1953 | if (!wsink) |
| 1954 | wsink = wtsink; |
| 1955 | if (!wsource) |
| 1956 | wsource = wtsource; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1957 | |
| 1958 | if (wsource == NULL || wsink == NULL) |
| 1959 | return -ENODEV; |
| 1960 | |
| 1961 | path = kzalloc(sizeof(struct snd_soc_dapm_path), GFP_KERNEL); |
| 1962 | if (!path) |
| 1963 | return -ENOMEM; |
| 1964 | |
| 1965 | path->source = wsource; |
| 1966 | path->sink = wsink; |
Mark Brown | 215edda | 2009-09-08 18:59:05 +0100 | [diff] [blame] | 1967 | path->connected = route->connected; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1968 | INIT_LIST_HEAD(&path->list); |
| 1969 | INIT_LIST_HEAD(&path->list_source); |
| 1970 | INIT_LIST_HEAD(&path->list_sink); |
| 1971 | |
| 1972 | /* check for external widgets */ |
| 1973 | if (wsink->id == snd_soc_dapm_input) { |
| 1974 | if (wsource->id == snd_soc_dapm_micbias || |
| 1975 | wsource->id == snd_soc_dapm_mic || |
Rongrong Cao | 087d53a | 2009-07-10 20:13:30 +0100 | [diff] [blame] | 1976 | wsource->id == snd_soc_dapm_line || |
| 1977 | wsource->id == snd_soc_dapm_output) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1978 | wsink->ext = 1; |
| 1979 | } |
| 1980 | if (wsource->id == snd_soc_dapm_output) { |
| 1981 | if (wsink->id == snd_soc_dapm_spk || |
| 1982 | wsink->id == snd_soc_dapm_hp || |
Seth Forshee | 1e39221 | 2007-04-16 15:36:42 +0200 | [diff] [blame] | 1983 | wsink->id == snd_soc_dapm_line || |
| 1984 | wsink->id == snd_soc_dapm_input) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1985 | wsource->ext = 1; |
| 1986 | } |
| 1987 | |
| 1988 | /* connect static paths */ |
| 1989 | if (control == NULL) { |
Jarkko Nikula | 8ddab3f | 2010-12-14 12:18:30 +0200 | [diff] [blame] | 1990 | list_add(&path->list, &dapm->card->paths); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1991 | list_add(&path->list_sink, &wsink->sources); |
| 1992 | list_add(&path->list_source, &wsource->sinks); |
| 1993 | path->connect = 1; |
| 1994 | return 0; |
| 1995 | } |
| 1996 | |
| 1997 | /* connect dynamic paths */ |
Lu Guanqun | dc2bea6 | 2011-04-20 16:00:36 +0800 | [diff] [blame] | 1998 | switch (wsink->id) { |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1999 | case snd_soc_dapm_adc: |
| 2000 | case snd_soc_dapm_dac: |
| 2001 | case snd_soc_dapm_pga: |
Olaya, Margarita | d88429a | 2010-12-10 21:11:44 -0600 | [diff] [blame] | 2002 | case snd_soc_dapm_out_drv: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2003 | case snd_soc_dapm_input: |
| 2004 | case snd_soc_dapm_output: |
| 2005 | case snd_soc_dapm_micbias: |
| 2006 | case snd_soc_dapm_vmid: |
| 2007 | case snd_soc_dapm_pre: |
| 2008 | case snd_soc_dapm_post: |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 2009 | case snd_soc_dapm_supply: |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 2010 | case snd_soc_dapm_aif_in: |
| 2011 | case snd_soc_dapm_aif_out: |
Jarkko Nikula | 8ddab3f | 2010-12-14 12:18:30 +0200 | [diff] [blame] | 2012 | list_add(&path->list, &dapm->card->paths); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2013 | list_add(&path->list_sink, &wsink->sources); |
| 2014 | list_add(&path->list_source, &wsource->sinks); |
| 2015 | path->connect = 1; |
| 2016 | return 0; |
| 2017 | case snd_soc_dapm_mux: |
Dimitris Papastamos | 24ff33a | 2010-12-16 15:53:39 +0000 | [diff] [blame] | 2018 | case snd_soc_dapm_virt_mux: |
Peter Ujfalusi | 7415555 | 2009-01-08 13:34:29 +0200 | [diff] [blame] | 2019 | case snd_soc_dapm_value_mux: |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2020 | ret = dapm_connect_mux(dapm, wsource, wsink, path, control, |
Stephen Warren | 82cfecd | 2011-04-28 17:37:58 -0600 | [diff] [blame] | 2021 | &wsink->kcontrol_news[0]); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2022 | if (ret != 0) |
| 2023 | goto err; |
| 2024 | break; |
| 2025 | case snd_soc_dapm_switch: |
| 2026 | case snd_soc_dapm_mixer: |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 2027 | case snd_soc_dapm_mixer_named_ctl: |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2028 | ret = dapm_connect_mixer(dapm, wsource, wsink, path, control); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2029 | if (ret != 0) |
| 2030 | goto err; |
| 2031 | break; |
| 2032 | case snd_soc_dapm_hp: |
| 2033 | case snd_soc_dapm_mic: |
| 2034 | case snd_soc_dapm_line: |
| 2035 | case snd_soc_dapm_spk: |
Jarkko Nikula | 8ddab3f | 2010-12-14 12:18:30 +0200 | [diff] [blame] | 2036 | list_add(&path->list, &dapm->card->paths); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2037 | list_add(&path->list_sink, &wsink->sources); |
| 2038 | list_add(&path->list_source, &wsource->sinks); |
| 2039 | path->connect = 0; |
| 2040 | return 0; |
| 2041 | } |
| 2042 | return 0; |
| 2043 | |
| 2044 | err: |
Jarkko Nikula | f7d41ae | 2010-11-09 14:40:27 +0200 | [diff] [blame] | 2045 | dev_warn(dapm->dev, "asoc: no dapm match for %s --> %s --> %s\n", |
| 2046 | source, control, sink); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2047 | kfree(path); |
| 2048 | return ret; |
| 2049 | } |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 2050 | |
| 2051 | /** |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 2052 | * snd_soc_dapm_add_routes - Add routes between DAPM widgets |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2053 | * @dapm: DAPM context |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 2054 | * @route: audio routes |
| 2055 | * @num: number of routes |
| 2056 | * |
| 2057 | * Connects 2 dapm widgets together via a named audio path. The sink is |
| 2058 | * the widget receiving the audio signal, whilst the source is the sender |
| 2059 | * of the audio signal. |
| 2060 | * |
| 2061 | * Returns 0 for success else error. On error all resources can be freed |
| 2062 | * with a call to snd_soc_card_free(). |
| 2063 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2064 | int snd_soc_dapm_add_routes(struct snd_soc_dapm_context *dapm, |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 2065 | const struct snd_soc_dapm_route *route, int num) |
| 2066 | { |
| 2067 | int i, ret; |
| 2068 | |
| 2069 | for (i = 0; i < num; i++) { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2070 | ret = snd_soc_dapm_add_route(dapm, route); |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 2071 | if (ret < 0) { |
Jarkko Nikula | f7d41ae | 2010-11-09 14:40:27 +0200 | [diff] [blame] | 2072 | dev_err(dapm->dev, "Failed to add route %s->%s\n", |
| 2073 | route->source, route->sink); |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 2074 | return ret; |
| 2075 | } |
| 2076 | route++; |
| 2077 | } |
| 2078 | |
| 2079 | return 0; |
| 2080 | } |
| 2081 | EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes); |
| 2082 | |
| 2083 | /** |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2084 | * snd_soc_dapm_new_widgets - add new dapm widgets |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2085 | * @dapm: DAPM context |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2086 | * |
| 2087 | * Checks the codec for any new dapm widgets and creates them if found. |
| 2088 | * |
| 2089 | * Returns 0 for success. |
| 2090 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2091 | int snd_soc_dapm_new_widgets(struct snd_soc_dapm_context *dapm) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2092 | { |
| 2093 | struct snd_soc_dapm_widget *w; |
Mark Brown | b66a70d | 2011-02-09 18:04:11 +0000 | [diff] [blame] | 2094 | unsigned int val; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2095 | |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 2096 | list_for_each_entry(w, &dapm->card->widgets, list) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2097 | { |
| 2098 | if (w->new) |
| 2099 | continue; |
| 2100 | |
Stephen Warren | fad5988 | 2011-04-28 17:37:59 -0600 | [diff] [blame] | 2101 | if (w->num_kcontrols) { |
| 2102 | w->kcontrols = kzalloc(w->num_kcontrols * |
| 2103 | sizeof(struct snd_kcontrol *), |
| 2104 | GFP_KERNEL); |
| 2105 | if (!w->kcontrols) |
| 2106 | return -ENOMEM; |
| 2107 | } |
| 2108 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2109 | switch(w->id) { |
| 2110 | case snd_soc_dapm_switch: |
| 2111 | case snd_soc_dapm_mixer: |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 2112 | case snd_soc_dapm_mixer_named_ctl: |
Mark Brown | b75576d | 2009-04-20 17:56:13 +0100 | [diff] [blame] | 2113 | w->power_check = dapm_generic_check_power; |
Lars-Peter Clausen | 4b80b8c | 2011-06-09 13:22:36 +0200 | [diff] [blame] | 2114 | dapm_new_mixer(w); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2115 | break; |
| 2116 | case snd_soc_dapm_mux: |
Dimitris Papastamos | 24ff33a | 2010-12-16 15:53:39 +0000 | [diff] [blame] | 2117 | case snd_soc_dapm_virt_mux: |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 2118 | case snd_soc_dapm_value_mux: |
Mark Brown | b75576d | 2009-04-20 17:56:13 +0100 | [diff] [blame] | 2119 | w->power_check = dapm_generic_check_power; |
Lars-Peter Clausen | 4b80b8c | 2011-06-09 13:22:36 +0200 | [diff] [blame] | 2120 | dapm_new_mux(w); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2121 | break; |
| 2122 | case snd_soc_dapm_adc: |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 2123 | case snd_soc_dapm_aif_out: |
Mark Brown | b75576d | 2009-04-20 17:56:13 +0100 | [diff] [blame] | 2124 | w->power_check = dapm_adc_check_power; |
| 2125 | break; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2126 | case snd_soc_dapm_dac: |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 2127 | case snd_soc_dapm_aif_in: |
Mark Brown | b75576d | 2009-04-20 17:56:13 +0100 | [diff] [blame] | 2128 | w->power_check = dapm_dac_check_power; |
| 2129 | break; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2130 | case snd_soc_dapm_pga: |
Olaya, Margarita | d88429a | 2010-12-10 21:11:44 -0600 | [diff] [blame] | 2131 | case snd_soc_dapm_out_drv: |
Mark Brown | b75576d | 2009-04-20 17:56:13 +0100 | [diff] [blame] | 2132 | w->power_check = dapm_generic_check_power; |
Lars-Peter Clausen | 4b80b8c | 2011-06-09 13:22:36 +0200 | [diff] [blame] | 2133 | dapm_new_pga(w); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2134 | break; |
| 2135 | case snd_soc_dapm_input: |
| 2136 | case snd_soc_dapm_output: |
| 2137 | case snd_soc_dapm_micbias: |
| 2138 | case snd_soc_dapm_spk: |
| 2139 | case snd_soc_dapm_hp: |
| 2140 | case snd_soc_dapm_mic: |
| 2141 | case snd_soc_dapm_line: |
Mark Brown | b75576d | 2009-04-20 17:56:13 +0100 | [diff] [blame] | 2142 | w->power_check = dapm_generic_check_power; |
| 2143 | break; |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 2144 | case snd_soc_dapm_supply: |
| 2145 | w->power_check = dapm_supply_check_power; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2146 | case snd_soc_dapm_vmid: |
| 2147 | case snd_soc_dapm_pre: |
| 2148 | case snd_soc_dapm_post: |
| 2149 | break; |
| 2150 | } |
Mark Brown | b66a70d | 2011-02-09 18:04:11 +0000 | [diff] [blame] | 2151 | |
| 2152 | /* Read the initial power state from the device */ |
| 2153 | if (w->reg >= 0) { |
Liam Girdwood | 35ca660 | 2011-01-28 17:45:35 +0000 | [diff] [blame] | 2154 | val = soc_widget_read(w, w->reg); |
Mark Brown | b66a70d | 2011-02-09 18:04:11 +0000 | [diff] [blame] | 2155 | val &= 1 << w->shift; |
| 2156 | if (w->invert) |
| 2157 | val = !val; |
| 2158 | |
| 2159 | if (val) |
| 2160 | w->power = 1; |
| 2161 | } |
| 2162 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2163 | w->new = 1; |
Lars-Peter Clausen | d5d1e0b | 2011-04-30 19:45:49 +0200 | [diff] [blame] | 2164 | |
| 2165 | dapm_debugfs_add_widget(w); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2166 | } |
| 2167 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2168 | dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2169 | return 0; |
| 2170 | } |
| 2171 | EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets); |
| 2172 | |
Liam Girdwood | 7038dfd9 | 2011-02-01 20:58:15 +0000 | [diff] [blame] | 2173 | const char *snd_soc_dapm_get_aif(struct snd_soc_dapm_context *dapm, |
| 2174 | const char *stream_name, enum snd_soc_dapm_type type) |
| 2175 | { |
| 2176 | struct snd_soc_dapm_widget *w; |
| 2177 | |
Liam Girdwood | ab1058a | 2011-01-31 20:33:07 +0000 | [diff] [blame] | 2178 | list_for_each_entry(w, &dapm->card->widgets, list) { |
Liam Girdwood | 7038dfd9 | 2011-02-01 20:58:15 +0000 | [diff] [blame] | 2179 | |
| 2180 | if (!w->sname) |
| 2181 | continue; |
| 2182 | |
| 2183 | if (w->id == type && strstr(w->sname, stream_name)) |
| 2184 | return w->name; |
Liam Girdwood | ab1058a | 2011-01-31 20:33:07 +0000 | [diff] [blame] | 2185 | |
Liam Girdwood | 7038dfd9 | 2011-02-01 20:58:15 +0000 | [diff] [blame] | 2186 | } |
| 2187 | return NULL; |
| 2188 | } |
| 2189 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_aif); |
| 2190 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2191 | /** |
| 2192 | * snd_soc_dapm_get_volsw - dapm mixer get callback |
| 2193 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2194 | * @ucontrol: control element information |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2195 | * |
| 2196 | * Callback to get the value of a dapm mixer control. |
| 2197 | * |
| 2198 | * Returns 0 for success. |
| 2199 | */ |
| 2200 | int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol, |
| 2201 | struct snd_ctl_elem_value *ucontrol) |
| 2202 | { |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2203 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 2204 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2205 | struct soc_mixer_control *mc = |
| 2206 | (struct soc_mixer_control *)kcontrol->private_value; |
Jon Smirl | 815ecf8 | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 2207 | unsigned int reg = mc->reg; |
| 2208 | unsigned int shift = mc->shift; |
| 2209 | unsigned int rshift = mc->rshift; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2210 | int max = mc->max; |
Jon Smirl | 815ecf8 | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 2211 | unsigned int invert = mc->invert; |
| 2212 | unsigned int mask = (1 << fls(max)) - 1; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2213 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2214 | ucontrol->value.integer.value[0] = |
| 2215 | (snd_soc_read(widget->codec, reg) >> shift) & mask; |
| 2216 | if (shift != rshift) |
| 2217 | ucontrol->value.integer.value[1] = |
| 2218 | (snd_soc_read(widget->codec, reg) >> rshift) & mask; |
| 2219 | if (invert) { |
| 2220 | ucontrol->value.integer.value[0] = |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 2221 | max - ucontrol->value.integer.value[0]; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2222 | if (shift != rshift) |
| 2223 | ucontrol->value.integer.value[1] = |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 2224 | max - ucontrol->value.integer.value[1]; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2225 | } |
| 2226 | |
| 2227 | return 0; |
| 2228 | } |
| 2229 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw); |
| 2230 | |
| 2231 | /** |
| 2232 | * snd_soc_dapm_put_volsw - dapm mixer set callback |
| 2233 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2234 | * @ucontrol: control element information |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2235 | * |
| 2236 | * Callback to set the value of a dapm mixer control. |
| 2237 | * |
| 2238 | * Returns 0 for success. |
| 2239 | */ |
| 2240 | int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol, |
| 2241 | struct snd_ctl_elem_value *ucontrol) |
| 2242 | { |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2243 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 2244 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
| 2245 | struct snd_soc_codec *codec = widget->codec; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2246 | struct soc_mixer_control *mc = |
| 2247 | (struct soc_mixer_control *)kcontrol->private_value; |
Jon Smirl | 815ecf8 | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 2248 | unsigned int reg = mc->reg; |
| 2249 | unsigned int shift = mc->shift; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2250 | int max = mc->max; |
Jon Smirl | 815ecf8 | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 2251 | unsigned int mask = (1 << fls(max)) - 1; |
| 2252 | unsigned int invert = mc->invert; |
Stephen Warren | e9cf704 | 2011-01-27 14:54:05 -0700 | [diff] [blame] | 2253 | unsigned int val; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2254 | int connect, change; |
| 2255 | struct snd_soc_dapm_update update; |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2256 | int wi; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2257 | |
| 2258 | val = (ucontrol->value.integer.value[0] & mask); |
| 2259 | |
| 2260 | if (invert) |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 2261 | val = max - val; |
Stephen Warren | e9cf704 | 2011-01-27 14:54:05 -0700 | [diff] [blame] | 2262 | mask = mask << shift; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2263 | val = val << shift; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2264 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2265 | if (val) |
| 2266 | /* new connection */ |
| 2267 | connect = invert ? 0 : 1; |
| 2268 | else |
| 2269 | /* old connection must be powered down */ |
| 2270 | connect = invert ? 1 : 0; |
| 2271 | |
| 2272 | mutex_lock(&codec->mutex); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2273 | |
Stephen Warren | e9cf704 | 2011-01-27 14:54:05 -0700 | [diff] [blame] | 2274 | change = snd_soc_test_bits(widget->codec, reg, mask, val); |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2275 | if (change) { |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2276 | for (wi = 0; wi < wlist->num_widgets; wi++) { |
| 2277 | widget = wlist->widgets[wi]; |
Mark Brown | 283375c | 2009-12-07 18:09:03 +0000 | [diff] [blame] | 2278 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2279 | widget->value = val; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2280 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2281 | update.kcontrol = kcontrol; |
| 2282 | update.widget = widget; |
| 2283 | update.reg = reg; |
| 2284 | update.mask = mask; |
| 2285 | update.val = val; |
| 2286 | widget->dapm->update = &update; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2287 | |
Liam Girdwood | e002c98 | 2011-02-08 11:45:20 +0000 | [diff] [blame] | 2288 | snd_soc_dapm_mixer_update_power(widget, kcontrol, connect); |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2289 | |
| 2290 | widget->dapm->update = NULL; |
| 2291 | } |
Mark Brown | 283375c | 2009-12-07 18:09:03 +0000 | [diff] [blame] | 2292 | } |
| 2293 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2294 | mutex_unlock(&codec->mutex); |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2295 | return 0; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2296 | } |
| 2297 | EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw); |
| 2298 | |
| 2299 | /** |
| 2300 | * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback |
| 2301 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2302 | * @ucontrol: control element information |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2303 | * |
| 2304 | * Callback to get the value of a dapm enumerated double mixer control. |
| 2305 | * |
| 2306 | * Returns 0 for success. |
| 2307 | */ |
| 2308 | int snd_soc_dapm_get_enum_double(struct snd_kcontrol *kcontrol, |
| 2309 | struct snd_ctl_elem_value *ucontrol) |
| 2310 | { |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2311 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 2312 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2313 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 2314 | unsigned int val, bitmask; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2315 | |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 2316 | for (bitmask = 1; bitmask < e->max; bitmask <<= 1) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2317 | ; |
| 2318 | val = snd_soc_read(widget->codec, e->reg); |
| 2319 | ucontrol->value.enumerated.item[0] = (val >> e->shift_l) & (bitmask - 1); |
| 2320 | if (e->shift_l != e->shift_r) |
| 2321 | ucontrol->value.enumerated.item[1] = |
| 2322 | (val >> e->shift_r) & (bitmask - 1); |
| 2323 | |
| 2324 | return 0; |
| 2325 | } |
| 2326 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double); |
| 2327 | |
| 2328 | /** |
| 2329 | * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback |
| 2330 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2331 | * @ucontrol: control element information |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2332 | * |
| 2333 | * Callback to set the value of a dapm enumerated double mixer control. |
| 2334 | * |
| 2335 | * Returns 0 for success. |
| 2336 | */ |
| 2337 | int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol, |
| 2338 | struct snd_ctl_elem_value *ucontrol) |
| 2339 | { |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2340 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 2341 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
| 2342 | struct snd_soc_codec *codec = widget->codec; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2343 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Mark Brown | 3a65577 | 2009-10-05 17:23:30 +0100 | [diff] [blame] | 2344 | unsigned int val, mux, change; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 2345 | unsigned int mask, bitmask; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2346 | struct snd_soc_dapm_update update; |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2347 | int wi; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2348 | |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 2349 | for (bitmask = 1; bitmask < e->max; bitmask <<= 1) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2350 | ; |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 2351 | if (ucontrol->value.enumerated.item[0] > e->max - 1) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2352 | return -EINVAL; |
| 2353 | mux = ucontrol->value.enumerated.item[0]; |
| 2354 | val = mux << e->shift_l; |
| 2355 | mask = (bitmask - 1) << e->shift_l; |
| 2356 | if (e->shift_l != e->shift_r) { |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 2357 | if (ucontrol->value.enumerated.item[1] > e->max - 1) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2358 | return -EINVAL; |
| 2359 | val |= ucontrol->value.enumerated.item[1] << e->shift_r; |
| 2360 | mask |= (bitmask - 1) << e->shift_r; |
| 2361 | } |
| 2362 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2363 | mutex_lock(&codec->mutex); |
| 2364 | |
Mark Brown | 3a65577 | 2009-10-05 17:23:30 +0100 | [diff] [blame] | 2365 | change = snd_soc_test_bits(widget->codec, e->reg, mask, val); |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2366 | if (change) { |
| 2367 | for (wi = 0; wi < wlist->num_widgets; wi++) { |
| 2368 | widget = wlist->widgets[wi]; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2369 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2370 | widget->value = val; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2371 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2372 | update.kcontrol = kcontrol; |
| 2373 | update.widget = widget; |
| 2374 | update.reg = e->reg; |
| 2375 | update.mask = mask; |
| 2376 | update.val = val; |
| 2377 | widget->dapm->update = &update; |
Mark Brown | 1642e3d | 2009-10-05 16:24:26 +0100 | [diff] [blame] | 2378 | |
Liam Girdwood | e002c98 | 2011-02-08 11:45:20 +0000 | [diff] [blame] | 2379 | snd_soc_dapm_mux_update_power(widget, kcontrol, change, mux, e); |
Mark Brown | 1642e3d | 2009-10-05 16:24:26 +0100 | [diff] [blame] | 2380 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2381 | widget->dapm->update = NULL; |
| 2382 | } |
| 2383 | } |
| 2384 | |
| 2385 | mutex_unlock(&codec->mutex); |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2386 | return change; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2387 | } |
| 2388 | EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double); |
| 2389 | |
| 2390 | /** |
Mark Brown | d2b247a | 2009-10-06 15:21:04 +0100 | [diff] [blame] | 2391 | * snd_soc_dapm_get_enum_virt - Get virtual DAPM mux |
| 2392 | * @kcontrol: mixer control |
| 2393 | * @ucontrol: control element information |
| 2394 | * |
| 2395 | * Returns 0 for success. |
| 2396 | */ |
| 2397 | int snd_soc_dapm_get_enum_virt(struct snd_kcontrol *kcontrol, |
| 2398 | struct snd_ctl_elem_value *ucontrol) |
| 2399 | { |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2400 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 2401 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
Mark Brown | d2b247a | 2009-10-06 15:21:04 +0100 | [diff] [blame] | 2402 | |
| 2403 | ucontrol->value.enumerated.item[0] = widget->value; |
| 2404 | |
| 2405 | return 0; |
| 2406 | } |
| 2407 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_virt); |
| 2408 | |
| 2409 | /** |
| 2410 | * snd_soc_dapm_put_enum_virt - Set virtual DAPM mux |
| 2411 | * @kcontrol: mixer control |
| 2412 | * @ucontrol: control element information |
| 2413 | * |
| 2414 | * Returns 0 for success. |
| 2415 | */ |
| 2416 | int snd_soc_dapm_put_enum_virt(struct snd_kcontrol *kcontrol, |
| 2417 | struct snd_ctl_elem_value *ucontrol) |
| 2418 | { |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2419 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 2420 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
| 2421 | struct snd_soc_codec *codec = widget->codec; |
Mark Brown | d2b247a | 2009-10-06 15:21:04 +0100 | [diff] [blame] | 2422 | struct soc_enum *e = |
| 2423 | (struct soc_enum *)kcontrol->private_value; |
| 2424 | int change; |
| 2425 | int ret = 0; |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2426 | int wi; |
Mark Brown | d2b247a | 2009-10-06 15:21:04 +0100 | [diff] [blame] | 2427 | |
| 2428 | if (ucontrol->value.enumerated.item[0] >= e->max) |
| 2429 | return -EINVAL; |
| 2430 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2431 | mutex_lock(&codec->mutex); |
Mark Brown | d2b247a | 2009-10-06 15:21:04 +0100 | [diff] [blame] | 2432 | |
| 2433 | change = widget->value != ucontrol->value.enumerated.item[0]; |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2434 | if (change) { |
| 2435 | for (wi = 0; wi < wlist->num_widgets; wi++) { |
| 2436 | widget = wlist->widgets[wi]; |
Mark Brown | d2b247a | 2009-10-06 15:21:04 +0100 | [diff] [blame] | 2437 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2438 | widget->value = ucontrol->value.enumerated.item[0]; |
| 2439 | |
Liam Girdwood | e002c98 | 2011-02-08 11:45:20 +0000 | [diff] [blame] | 2440 | snd_soc_dapm_mux_update_power(widget, kcontrol, change, |
| 2441 | widget->value, e); |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2442 | } |
| 2443 | } |
| 2444 | |
| 2445 | mutex_unlock(&codec->mutex); |
Mark Brown | d2b247a | 2009-10-06 15:21:04 +0100 | [diff] [blame] | 2446 | return ret; |
| 2447 | } |
| 2448 | EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_virt); |
| 2449 | |
| 2450 | /** |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 2451 | * snd_soc_dapm_get_value_enum_double - dapm semi enumerated double mixer get |
| 2452 | * callback |
| 2453 | * @kcontrol: mixer control |
| 2454 | * @ucontrol: control element information |
| 2455 | * |
| 2456 | * Callback to get the value of a dapm semi enumerated double mixer control. |
| 2457 | * |
| 2458 | * Semi enumerated mixer: the enumerated items are referred as values. Can be |
| 2459 | * used for handling bitfield coded enumeration for example. |
| 2460 | * |
| 2461 | * Returns 0 for success. |
| 2462 | */ |
| 2463 | int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol *kcontrol, |
| 2464 | struct snd_ctl_elem_value *ucontrol) |
| 2465 | { |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2466 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 2467 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
Peter Ujfalusi | 7415555 | 2009-01-08 13:34:29 +0200 | [diff] [blame] | 2468 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 2469 | unsigned int reg_val, val, mux; |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 2470 | |
| 2471 | reg_val = snd_soc_read(widget->codec, e->reg); |
| 2472 | val = (reg_val >> e->shift_l) & e->mask; |
| 2473 | for (mux = 0; mux < e->max; mux++) { |
| 2474 | if (val == e->values[mux]) |
| 2475 | break; |
| 2476 | } |
| 2477 | ucontrol->value.enumerated.item[0] = mux; |
| 2478 | if (e->shift_l != e->shift_r) { |
| 2479 | val = (reg_val >> e->shift_r) & e->mask; |
| 2480 | for (mux = 0; mux < e->max; mux++) { |
| 2481 | if (val == e->values[mux]) |
| 2482 | break; |
| 2483 | } |
| 2484 | ucontrol->value.enumerated.item[1] = mux; |
| 2485 | } |
| 2486 | |
| 2487 | return 0; |
| 2488 | } |
| 2489 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_value_enum_double); |
| 2490 | |
| 2491 | /** |
| 2492 | * snd_soc_dapm_put_value_enum_double - dapm semi enumerated double mixer set |
| 2493 | * callback |
| 2494 | * @kcontrol: mixer control |
| 2495 | * @ucontrol: control element information |
| 2496 | * |
| 2497 | * Callback to set the value of a dapm semi enumerated double mixer control. |
| 2498 | * |
| 2499 | * Semi enumerated mixer: the enumerated items are referred as values. Can be |
| 2500 | * used for handling bitfield coded enumeration for example. |
| 2501 | * |
| 2502 | * Returns 0 for success. |
| 2503 | */ |
| 2504 | int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol *kcontrol, |
| 2505 | struct snd_ctl_elem_value *ucontrol) |
| 2506 | { |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2507 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 2508 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
| 2509 | struct snd_soc_codec *codec = widget->codec; |
Peter Ujfalusi | 7415555 | 2009-01-08 13:34:29 +0200 | [diff] [blame] | 2510 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Mark Brown | 3a65577 | 2009-10-05 17:23:30 +0100 | [diff] [blame] | 2511 | unsigned int val, mux, change; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 2512 | unsigned int mask; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2513 | struct snd_soc_dapm_update update; |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2514 | int wi; |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 2515 | |
| 2516 | if (ucontrol->value.enumerated.item[0] > e->max - 1) |
| 2517 | return -EINVAL; |
| 2518 | mux = ucontrol->value.enumerated.item[0]; |
| 2519 | val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l; |
| 2520 | mask = e->mask << e->shift_l; |
| 2521 | if (e->shift_l != e->shift_r) { |
| 2522 | if (ucontrol->value.enumerated.item[1] > e->max - 1) |
| 2523 | return -EINVAL; |
| 2524 | val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r; |
| 2525 | mask |= e->mask << e->shift_r; |
| 2526 | } |
| 2527 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2528 | mutex_lock(&codec->mutex); |
| 2529 | |
Mark Brown | 3a65577 | 2009-10-05 17:23:30 +0100 | [diff] [blame] | 2530 | change = snd_soc_test_bits(widget->codec, e->reg, mask, val); |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2531 | if (change) { |
| 2532 | for (wi = 0; wi < wlist->num_widgets; wi++) { |
| 2533 | widget = wlist->widgets[wi]; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2534 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2535 | widget->value = val; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2536 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2537 | update.kcontrol = kcontrol; |
| 2538 | update.widget = widget; |
| 2539 | update.reg = e->reg; |
| 2540 | update.mask = mask; |
| 2541 | update.val = val; |
| 2542 | widget->dapm->update = &update; |
Mark Brown | 1642e3d | 2009-10-05 16:24:26 +0100 | [diff] [blame] | 2543 | |
Liam Girdwood | e002c98 | 2011-02-08 11:45:20 +0000 | [diff] [blame] | 2544 | snd_soc_dapm_mux_update_power(widget, kcontrol, change, mux, e); |
Mark Brown | 1642e3d | 2009-10-05 16:24:26 +0100 | [diff] [blame] | 2545 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2546 | widget->dapm->update = NULL; |
| 2547 | } |
| 2548 | } |
| 2549 | |
| 2550 | mutex_unlock(&codec->mutex); |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2551 | return change; |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 2552 | } |
| 2553 | EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double); |
| 2554 | |
| 2555 | /** |
Mark Brown | 8b37dbd | 2009-02-28 21:14:20 +0000 | [diff] [blame] | 2556 | * snd_soc_dapm_info_pin_switch - Info for a pin switch |
| 2557 | * |
| 2558 | * @kcontrol: mixer control |
| 2559 | * @uinfo: control element information |
| 2560 | * |
| 2561 | * Callback to provide information about a pin switch control. |
| 2562 | */ |
| 2563 | int snd_soc_dapm_info_pin_switch(struct snd_kcontrol *kcontrol, |
| 2564 | struct snd_ctl_elem_info *uinfo) |
| 2565 | { |
| 2566 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; |
| 2567 | uinfo->count = 1; |
| 2568 | uinfo->value.integer.min = 0; |
| 2569 | uinfo->value.integer.max = 1; |
| 2570 | |
| 2571 | return 0; |
| 2572 | } |
| 2573 | EXPORT_SYMBOL_GPL(snd_soc_dapm_info_pin_switch); |
| 2574 | |
| 2575 | /** |
| 2576 | * snd_soc_dapm_get_pin_switch - Get information for a pin switch |
| 2577 | * |
| 2578 | * @kcontrol: mixer control |
| 2579 | * @ucontrol: Value |
| 2580 | */ |
| 2581 | int snd_soc_dapm_get_pin_switch(struct snd_kcontrol *kcontrol, |
| 2582 | struct snd_ctl_elem_value *ucontrol) |
| 2583 | { |
| 2584 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2585 | const char *pin = (const char *)kcontrol->private_value; |
| 2586 | |
| 2587 | mutex_lock(&codec->mutex); |
| 2588 | |
| 2589 | ucontrol->value.integer.value[0] = |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2590 | snd_soc_dapm_get_pin_status(&codec->dapm, pin); |
Mark Brown | 8b37dbd | 2009-02-28 21:14:20 +0000 | [diff] [blame] | 2591 | |
| 2592 | mutex_unlock(&codec->mutex); |
| 2593 | |
| 2594 | return 0; |
| 2595 | } |
| 2596 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_switch); |
| 2597 | |
| 2598 | /** |
| 2599 | * snd_soc_dapm_put_pin_switch - Set information for a pin switch |
| 2600 | * |
| 2601 | * @kcontrol: mixer control |
| 2602 | * @ucontrol: Value |
| 2603 | */ |
| 2604 | int snd_soc_dapm_put_pin_switch(struct snd_kcontrol *kcontrol, |
| 2605 | struct snd_ctl_elem_value *ucontrol) |
| 2606 | { |
| 2607 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2608 | const char *pin = (const char *)kcontrol->private_value; |
| 2609 | |
| 2610 | mutex_lock(&codec->mutex); |
| 2611 | |
| 2612 | if (ucontrol->value.integer.value[0]) |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2613 | snd_soc_dapm_enable_pin(&codec->dapm, pin); |
Mark Brown | 8b37dbd | 2009-02-28 21:14:20 +0000 | [diff] [blame] | 2614 | else |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2615 | snd_soc_dapm_disable_pin(&codec->dapm, pin); |
Mark Brown | 8b37dbd | 2009-02-28 21:14:20 +0000 | [diff] [blame] | 2616 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2617 | snd_soc_dapm_sync(&codec->dapm); |
Mark Brown | 8b37dbd | 2009-02-28 21:14:20 +0000 | [diff] [blame] | 2618 | |
| 2619 | mutex_unlock(&codec->mutex); |
| 2620 | |
| 2621 | return 0; |
| 2622 | } |
| 2623 | EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch); |
| 2624 | |
| 2625 | /** |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2626 | * snd_soc_dapm_new_control - create new dapm control |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2627 | * @dapm: DAPM context |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2628 | * @widget: widget template |
| 2629 | * |
| 2630 | * Creates a new dapm control based upon the template. |
| 2631 | * |
| 2632 | * Returns 0 for success else error. |
| 2633 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2634 | int snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm, |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2635 | const struct snd_soc_dapm_widget *widget) |
| 2636 | { |
| 2637 | struct snd_soc_dapm_widget *w; |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 2638 | size_t name_len; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2639 | |
| 2640 | if ((w = dapm_cnew_widget(widget)) == NULL) |
| 2641 | return -ENOMEM; |
| 2642 | |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 2643 | name_len = strlen(widget->name) + 1; |
Mark Brown | 88e8b9a | 2011-03-02 18:18:24 +0000 | [diff] [blame] | 2644 | if (dapm->codec && dapm->codec->name_prefix) |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 2645 | name_len += 1 + strlen(dapm->codec->name_prefix); |
| 2646 | w->name = kmalloc(name_len, GFP_KERNEL); |
| 2647 | if (w->name == NULL) { |
| 2648 | kfree(w); |
| 2649 | return -ENOMEM; |
| 2650 | } |
Mark Brown | 88e8b9a | 2011-03-02 18:18:24 +0000 | [diff] [blame] | 2651 | if (dapm->codec && dapm->codec->name_prefix) |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 2652 | snprintf(w->name, name_len, "%s %s", |
| 2653 | dapm->codec->name_prefix, widget->name); |
| 2654 | else |
| 2655 | snprintf(w->name, name_len, "%s", widget->name); |
| 2656 | |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 2657 | dapm->n_widgets++; |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2658 | w->dapm = dapm; |
| 2659 | w->codec = dapm->codec; |
Liam Girdwood | 7987a11 | 2011-01-31 19:52:42 +0000 | [diff] [blame] | 2660 | w->platform = dapm->platform; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2661 | INIT_LIST_HEAD(&w->sources); |
| 2662 | INIT_LIST_HEAD(&w->sinks); |
| 2663 | INIT_LIST_HEAD(&w->list); |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 2664 | list_add(&w->list, &dapm->card->widgets); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2665 | |
| 2666 | /* machine layer set ups unconnected pins and insertions */ |
| 2667 | w->connected = 1; |
| 2668 | return 0; |
| 2669 | } |
| 2670 | EXPORT_SYMBOL_GPL(snd_soc_dapm_new_control); |
| 2671 | |
| 2672 | /** |
Mark Brown | 4ba1327 | 2008-05-13 14:51:19 +0200 | [diff] [blame] | 2673 | * snd_soc_dapm_new_controls - create new dapm controls |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2674 | * @dapm: DAPM context |
Mark Brown | 4ba1327 | 2008-05-13 14:51:19 +0200 | [diff] [blame] | 2675 | * @widget: widget array |
| 2676 | * @num: number of widgets |
| 2677 | * |
| 2678 | * Creates new DAPM controls based upon the templates. |
| 2679 | * |
| 2680 | * Returns 0 for success else error. |
| 2681 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2682 | int snd_soc_dapm_new_controls(struct snd_soc_dapm_context *dapm, |
Mark Brown | 4ba1327 | 2008-05-13 14:51:19 +0200 | [diff] [blame] | 2683 | const struct snd_soc_dapm_widget *widget, |
| 2684 | int num) |
| 2685 | { |
| 2686 | int i, ret; |
| 2687 | |
| 2688 | for (i = 0; i < num; i++) { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2689 | ret = snd_soc_dapm_new_control(dapm, widget); |
Mark Brown | b8b33cb | 2008-12-18 11:19:30 +0000 | [diff] [blame] | 2690 | if (ret < 0) { |
Jarkko Nikula | f7d41ae | 2010-11-09 14:40:27 +0200 | [diff] [blame] | 2691 | dev_err(dapm->dev, |
| 2692 | "ASoC: Failed to create DAPM control %s: %d\n", |
| 2693 | widget->name, ret); |
Mark Brown | 4ba1327 | 2008-05-13 14:51:19 +0200 | [diff] [blame] | 2694 | return ret; |
Mark Brown | b8b33cb | 2008-12-18 11:19:30 +0000 | [diff] [blame] | 2695 | } |
Mark Brown | 4ba1327 | 2008-05-13 14:51:19 +0200 | [diff] [blame] | 2696 | widget++; |
| 2697 | } |
| 2698 | return 0; |
| 2699 | } |
| 2700 | EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls); |
| 2701 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2702 | static void soc_dapm_stream_event(struct snd_soc_dapm_context *dapm, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2703 | const char *stream, int event) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2704 | { |
| 2705 | struct snd_soc_dapm_widget *w; |
| 2706 | |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 2707 | if (!dapm) |
| 2708 | return; |
| 2709 | |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 2710 | list_for_each_entry(w, &dapm->card->widgets, list) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2711 | { |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 2712 | if (!w->sname || w->dapm != dapm) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2713 | continue; |
Jarkko Nikula | f7d41ae | 2010-11-09 14:40:27 +0200 | [diff] [blame] | 2714 | dev_dbg(w->dapm->dev, "widget %s\n %s stream %s event %d\n", |
| 2715 | w->name, w->sname, stream, event); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2716 | if (strstr(w->sname, stream)) { |
| 2717 | switch(event) { |
| 2718 | case SND_SOC_DAPM_STREAM_START: |
| 2719 | w->active = 1; |
| 2720 | break; |
| 2721 | case SND_SOC_DAPM_STREAM_STOP: |
| 2722 | w->active = 0; |
| 2723 | break; |
| 2724 | case SND_SOC_DAPM_STREAM_SUSPEND: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2725 | case SND_SOC_DAPM_STREAM_RESUME: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2726 | case SND_SOC_DAPM_STREAM_PAUSE_PUSH: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2727 | case SND_SOC_DAPM_STREAM_PAUSE_RELEASE: |
| 2728 | break; |
| 2729 | } |
| 2730 | } |
| 2731 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2732 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2733 | dapm_power_widgets(dapm, event); |
Liam Girdwood | 670ff44 | 2011-03-30 23:27:27 +0100 | [diff] [blame] | 2734 | /* do we need to notify any clients that DAPM stream is complete */ |
| 2735 | if (dapm->stream_event) |
| 2736 | dapm->stream_event(dapm); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2737 | } |
| 2738 | |
| 2739 | /** |
| 2740 | * snd_soc_dapm_stream_event - send a stream event to the dapm core |
| 2741 | * @rtd: PCM runtime data |
| 2742 | * @stream: stream name |
| 2743 | * @event: stream event |
| 2744 | * |
| 2745 | * Sends a stream event to the dapm core. The core then makes any |
| 2746 | * necessary widget power changes. |
| 2747 | * |
| 2748 | * Returns 0 for success else error. |
| 2749 | */ |
| 2750 | int snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, |
| 2751 | const char *stream, int event) |
| 2752 | { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2753 | if (stream == NULL) |
| 2754 | return 0; |
Liam Girdwood | ecc1a0d | 2011-02-16 16:24:17 +0000 | [diff] [blame] | 2755 | |
Liam Girdwood | 670ff44 | 2011-03-30 23:27:27 +0100 | [diff] [blame] | 2756 | mutex_lock(&rtd->card->dapm_mutex); |
| 2757 | |
| 2758 | soc_dapm_stream_event(&rtd->platform->dapm, stream, event); |
| 2759 | soc_dapm_stream_event(&rtd->codec->dapm, stream, event); |
| 2760 | |
| 2761 | mutex_unlock(&rtd->card->dapm_mutex); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2762 | return 0; |
| 2763 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2764 | |
| 2765 | /** |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2766 | * snd_soc_dapm_enable_pin - enable pin. |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2767 | * @dapm: DAPM context |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2768 | * @pin: pin name |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2769 | * |
Mark Brown | 74b8f95 | 2009-06-06 11:26:15 +0100 | [diff] [blame] | 2770 | * Enables input/output pin and its parents or children widgets iff there is |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2771 | * a valid audio route and active audio stream. |
| 2772 | * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to |
| 2773 | * do any widget power switching. |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2774 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2775 | int snd_soc_dapm_enable_pin(struct snd_soc_dapm_context *dapm, const char *pin) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2776 | { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2777 | return snd_soc_dapm_set_pin(dapm, pin, 1); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2778 | } |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2779 | EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2780 | |
| 2781 | /** |
Mark Brown | da34183 | 2010-03-15 19:23:37 +0000 | [diff] [blame] | 2782 | * snd_soc_dapm_force_enable_pin - force a pin to be enabled |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2783 | * @dapm: DAPM context |
Mark Brown | da34183 | 2010-03-15 19:23:37 +0000 | [diff] [blame] | 2784 | * @pin: pin name |
| 2785 | * |
| 2786 | * Enables input/output pin regardless of any other state. This is |
| 2787 | * intended for use with microphone bias supplies used in microphone |
| 2788 | * jack detection. |
| 2789 | * |
| 2790 | * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to |
| 2791 | * do any widget power switching. |
| 2792 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2793 | int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context *dapm, |
| 2794 | const char *pin) |
Mark Brown | da34183 | 2010-03-15 19:23:37 +0000 | [diff] [blame] | 2795 | { |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2796 | struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true); |
Mark Brown | da34183 | 2010-03-15 19:23:37 +0000 | [diff] [blame] | 2797 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2798 | if (!w) { |
| 2799 | dev_err(dapm->dev, "dapm: unknown pin %s\n", pin); |
| 2800 | return -EINVAL; |
Mark Brown | da34183 | 2010-03-15 19:23:37 +0000 | [diff] [blame] | 2801 | } |
| 2802 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2803 | dev_dbg(w->dapm->dev, "dapm: force enable pin %s\n", pin); |
| 2804 | w->connected = 1; |
| 2805 | w->force = 1; |
Mark Brown | 0d86733 | 2011-04-06 11:38:14 +0900 | [diff] [blame] | 2806 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2807 | return 0; |
Mark Brown | da34183 | 2010-03-15 19:23:37 +0000 | [diff] [blame] | 2808 | } |
| 2809 | EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin); |
| 2810 | |
| 2811 | /** |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2812 | * snd_soc_dapm_disable_pin - disable pin. |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2813 | * @dapm: DAPM context |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2814 | * @pin: pin name |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 2815 | * |
Mark Brown | 74b8f95 | 2009-06-06 11:26:15 +0100 | [diff] [blame] | 2816 | * Disables input/output pin and its parents or children widgets. |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2817 | * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to |
| 2818 | * do any widget power switching. |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 2819 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2820 | int snd_soc_dapm_disable_pin(struct snd_soc_dapm_context *dapm, |
| 2821 | const char *pin) |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2822 | { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2823 | return snd_soc_dapm_set_pin(dapm, pin, 0); |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2824 | } |
| 2825 | EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin); |
| 2826 | |
| 2827 | /** |
Mark Brown | 5817b52 | 2008-09-24 11:23:11 +0100 | [diff] [blame] | 2828 | * snd_soc_dapm_nc_pin - permanently disable pin. |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2829 | * @dapm: DAPM context |
Mark Brown | 5817b52 | 2008-09-24 11:23:11 +0100 | [diff] [blame] | 2830 | * @pin: pin name |
| 2831 | * |
| 2832 | * Marks the specified pin as being not connected, disabling it along |
| 2833 | * any parent or child widgets. At present this is identical to |
| 2834 | * snd_soc_dapm_disable_pin() but in future it will be extended to do |
| 2835 | * additional things such as disabling controls which only affect |
| 2836 | * paths through the pin. |
| 2837 | * |
| 2838 | * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to |
| 2839 | * do any widget power switching. |
| 2840 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2841 | int snd_soc_dapm_nc_pin(struct snd_soc_dapm_context *dapm, const char *pin) |
Mark Brown | 5817b52 | 2008-09-24 11:23:11 +0100 | [diff] [blame] | 2842 | { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2843 | return snd_soc_dapm_set_pin(dapm, pin, 0); |
Mark Brown | 5817b52 | 2008-09-24 11:23:11 +0100 | [diff] [blame] | 2844 | } |
| 2845 | EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin); |
| 2846 | |
| 2847 | /** |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2848 | * snd_soc_dapm_get_pin_status - get audio pin status |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2849 | * @dapm: DAPM context |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2850 | * @pin: audio signal pin endpoint (or start point) |
| 2851 | * |
| 2852 | * Get audio pin status - connected or disconnected. |
| 2853 | * |
| 2854 | * Returns 1 for connected otherwise 0. |
| 2855 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2856 | int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context *dapm, |
| 2857 | const char *pin) |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 2858 | { |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2859 | struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true); |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 2860 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2861 | if (w) |
| 2862 | return w->connected; |
Stephen Warren | a68b38a | 2011-04-19 15:25:11 -0600 | [diff] [blame] | 2863 | |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 2864 | return 0; |
| 2865 | } |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2866 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status); |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 2867 | |
| 2868 | /** |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 2869 | * snd_soc_dapm_ignore_suspend - ignore suspend status for DAPM endpoint |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2870 | * @dapm: DAPM context |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 2871 | * @pin: audio signal pin endpoint (or start point) |
| 2872 | * |
| 2873 | * Mark the given endpoint or pin as ignoring suspend. When the |
| 2874 | * system is disabled a path between two endpoints flagged as ignoring |
| 2875 | * suspend will not be disabled. The path must already be enabled via |
| 2876 | * normal means at suspend time, it will not be turned on if it was not |
| 2877 | * already enabled. |
| 2878 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2879 | int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context *dapm, |
| 2880 | const char *pin) |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 2881 | { |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2882 | struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, false); |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 2883 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2884 | if (!w) { |
| 2885 | dev_err(dapm->dev, "dapm: unknown pin %s\n", pin); |
| 2886 | return -EINVAL; |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 2887 | } |
| 2888 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2889 | w->ignore_suspend = 1; |
| 2890 | |
| 2891 | return 0; |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 2892 | } |
| 2893 | EXPORT_SYMBOL_GPL(snd_soc_dapm_ignore_suspend); |
| 2894 | |
| 2895 | /** |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2896 | * snd_soc_dapm_free - free dapm resources |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2897 | * @card: SoC device |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2898 | * |
| 2899 | * Free all dapm widgets and resources. |
| 2900 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2901 | void snd_soc_dapm_free(struct snd_soc_dapm_context *dapm) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2902 | { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2903 | snd_soc_dapm_sys_remove(dapm->dev); |
Lars-Peter Clausen | 6c45e12 | 2011-04-30 19:45:50 +0200 | [diff] [blame] | 2904 | dapm_debugfs_cleanup(dapm); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2905 | dapm_free_widgets(dapm); |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 2906 | list_del(&dapm->list); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2907 | } |
| 2908 | EXPORT_SYMBOL_GPL(snd_soc_dapm_free); |
| 2909 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2910 | static void soc_dapm_shutdown_codec(struct snd_soc_dapm_context *dapm) |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 2911 | { |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 2912 | struct snd_soc_dapm_widget *w; |
| 2913 | LIST_HEAD(down_list); |
| 2914 | int powerdown = 0; |
| 2915 | |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 2916 | list_for_each_entry(w, &dapm->card->widgets, list) { |
| 2917 | if (w->dapm != dapm) |
| 2918 | continue; |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 2919 | if (w->power) { |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 2920 | dapm_seq_insert(w, &down_list, false); |
Mark Brown | c2caa4d | 2009-06-26 15:36:56 +0100 | [diff] [blame] | 2921 | w->power = 0; |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 2922 | powerdown = 1; |
| 2923 | } |
| 2924 | } |
| 2925 | |
| 2926 | /* If there were no widgets to power down we're already in |
| 2927 | * standby. |
| 2928 | */ |
| 2929 | if (powerdown) { |
Mark Brown | ed5a4c4 | 2011-02-18 11:12:42 -0800 | [diff] [blame] | 2930 | snd_soc_dapm_set_bias_level(dapm, SND_SOC_BIAS_PREPARE); |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 2931 | dapm_seq_run(dapm, &down_list, 0, false); |
Mark Brown | ed5a4c4 | 2011-02-18 11:12:42 -0800 | [diff] [blame] | 2932 | snd_soc_dapm_set_bias_level(dapm, SND_SOC_BIAS_STANDBY); |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 2933 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2934 | } |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 2935 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2936 | /* |
| 2937 | * snd_soc_dapm_shutdown - callback for system shutdown |
| 2938 | */ |
| 2939 | void snd_soc_dapm_shutdown(struct snd_soc_card *card) |
| 2940 | { |
| 2941 | struct snd_soc_codec *codec; |
Liam Girdwood | 7987a11 | 2011-01-31 19:52:42 +0000 | [diff] [blame] | 2942 | struct snd_soc_platform *platform; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2943 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2944 | list_for_each_entry(codec, &card->codec_dev_list, list) { |
| 2945 | soc_dapm_shutdown_codec(&codec->dapm); |
Mark Brown | ed5a4c4 | 2011-02-18 11:12:42 -0800 | [diff] [blame] | 2946 | snd_soc_dapm_set_bias_level(&codec->dapm, SND_SOC_BIAS_OFF); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2947 | } |
Liam Girdwood | 7987a11 | 2011-01-31 19:52:42 +0000 | [diff] [blame] | 2948 | |
| 2949 | list_for_each_entry(platform, &card->platform_dev_list, list) { |
| 2950 | soc_dapm_shutdown_codec(&platform->dapm); |
| 2951 | snd_soc_dapm_set_bias_level(&platform->dapm, SND_SOC_BIAS_OFF); |
| 2952 | } |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 2953 | } |
| 2954 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2955 | /* Module information */ |
Liam Girdwood | d331124 | 2008-10-12 13:17:36 +0100 | [diff] [blame] | 2956 | MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk"); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2957 | MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC"); |
| 2958 | MODULE_LICENSE("GPL"); |