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 |
| 15 | * DAC's/ADC's. |
| 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 | |
| 32 | #include <linux/module.h> |
| 33 | #include <linux/moduleparam.h> |
| 34 | #include <linux/init.h> |
| 35 | #include <linux/delay.h> |
| 36 | #include <linux/pm.h> |
| 37 | #include <linux/bitops.h> |
| 38 | #include <linux/platform_device.h> |
| 39 | #include <linux/jiffies.h> |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 40 | #include <sound/core.h> |
| 41 | #include <sound/pcm.h> |
| 42 | #include <sound/pcm_params.h> |
| 43 | #include <sound/soc-dapm.h> |
| 44 | #include <sound/initval.h> |
| 45 | |
| 46 | /* debug */ |
Mark Brown | c1286b8 | 2008-07-07 19:26:03 +0100 | [diff] [blame] | 47 | #ifdef DEBUG |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 48 | #define dump_dapm(codec, action) dbg_dump_dapm(codec, action) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 49 | #else |
| 50 | #define dump_dapm(codec, action) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 51 | #endif |
| 52 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 53 | /* dapm power sequences - make this per codec in the future */ |
| 54 | static int dapm_up_seq[] = { |
| 55 | snd_soc_dapm_pre, snd_soc_dapm_micbias, snd_soc_dapm_mic, |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 56 | snd_soc_dapm_mux, snd_soc_dapm_value_mux, snd_soc_dapm_dac, |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 57 | snd_soc_dapm_mixer, snd_soc_dapm_mixer_named_ctl, snd_soc_dapm_pga, |
| 58 | snd_soc_dapm_adc, snd_soc_dapm_hp, snd_soc_dapm_spk, snd_soc_dapm_post |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 59 | }; |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 60 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 61 | static int dapm_down_seq[] = { |
| 62 | snd_soc_dapm_pre, snd_soc_dapm_adc, snd_soc_dapm_hp, snd_soc_dapm_spk, |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 63 | snd_soc_dapm_pga, snd_soc_dapm_mixer_named_ctl, snd_soc_dapm_mixer, |
| 64 | snd_soc_dapm_dac, snd_soc_dapm_mic, snd_soc_dapm_micbias, |
| 65 | snd_soc_dapm_mux, snd_soc_dapm_value_mux, snd_soc_dapm_post |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | static int dapm_status = 1; |
| 69 | module_param(dapm_status, int, 0); |
| 70 | MODULE_PARM_DESC(dapm_status, "enable DPM sysfs entries"); |
| 71 | |
Troy Kisky | 12ef193 | 2008-10-13 17:42:14 -0700 | [diff] [blame] | 72 | static void pop_wait(u32 pop_time) |
Mark Brown | 15e4c72 | 2008-07-02 11:51:20 +0100 | [diff] [blame] | 73 | { |
| 74 | if (pop_time) |
| 75 | schedule_timeout_uninterruptible(msecs_to_jiffies(pop_time)); |
| 76 | } |
| 77 | |
Troy Kisky | 12ef193 | 2008-10-13 17:42:14 -0700 | [diff] [blame] | 78 | static void pop_dbg(u32 pop_time, const char *fmt, ...) |
Mark Brown | 15e4c72 | 2008-07-02 11:51:20 +0100 | [diff] [blame] | 79 | { |
| 80 | va_list args; |
| 81 | |
| 82 | va_start(args, fmt); |
| 83 | |
| 84 | if (pop_time) { |
| 85 | vprintk(fmt, args); |
Troy Kisky | 12ef193 | 2008-10-13 17:42:14 -0700 | [diff] [blame] | 86 | pop_wait(pop_time); |
Mark Brown | 15e4c72 | 2008-07-02 11:51:20 +0100 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | va_end(args); |
| 90 | } |
| 91 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 92 | /* create a new dapm widget */ |
Takashi Iwai | 88cb429 | 2007-02-05 14:56:20 +0100 | [diff] [blame] | 93 | static inline struct snd_soc_dapm_widget *dapm_cnew_widget( |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 94 | const struct snd_soc_dapm_widget *_widget) |
| 95 | { |
Takashi Iwai | 88cb429 | 2007-02-05 14:56:20 +0100 | [diff] [blame] | 96 | return kmemdup(_widget, sizeof(*_widget), GFP_KERNEL); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | /* set up initial codec paths */ |
| 100 | static void dapm_set_path_status(struct snd_soc_dapm_widget *w, |
| 101 | struct snd_soc_dapm_path *p, int i) |
| 102 | { |
| 103 | switch (w->id) { |
| 104 | case snd_soc_dapm_switch: |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 105 | case snd_soc_dapm_mixer: |
| 106 | case snd_soc_dapm_mixer_named_ctl: { |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 107 | int val; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 108 | struct soc_mixer_control *mc = (struct soc_mixer_control *) |
| 109 | w->kcontrols[i].private_value; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 110 | unsigned int reg = mc->reg; |
| 111 | unsigned int shift = mc->shift; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 112 | int max = mc->max; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 113 | unsigned int mask = (1 << fls(max)) - 1; |
| 114 | unsigned int invert = mc->invert; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 115 | |
| 116 | val = snd_soc_read(w->codec, reg); |
| 117 | val = (val >> shift) & mask; |
| 118 | |
| 119 | if ((invert && !val) || (!invert && val)) |
| 120 | p->connect = 1; |
| 121 | else |
| 122 | p->connect = 0; |
| 123 | } |
| 124 | break; |
| 125 | case snd_soc_dapm_mux: { |
| 126 | struct soc_enum *e = (struct soc_enum *)w->kcontrols[i].private_value; |
| 127 | int val, item, bitmask; |
| 128 | |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 129 | for (bitmask = 1; bitmask < e->max; bitmask <<= 1) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 130 | ; |
| 131 | val = snd_soc_read(w->codec, e->reg); |
| 132 | item = (val >> e->shift_l) & (bitmask - 1); |
| 133 | |
| 134 | p->connect = 0; |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 135 | for (i = 0; i < e->max; i++) { |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 136 | if (!(strcmp(p->name, e->texts[i])) && item == i) |
| 137 | p->connect = 1; |
| 138 | } |
| 139 | } |
| 140 | break; |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 141 | case snd_soc_dapm_value_mux: { |
| 142 | struct soc_value_enum *e = (struct soc_value_enum *) |
| 143 | w->kcontrols[i].private_value; |
| 144 | int val, item; |
| 145 | |
| 146 | val = snd_soc_read(w->codec, e->reg); |
| 147 | val = (val >> e->shift_l) & e->mask; |
| 148 | for (item = 0; item < e->max; item++) { |
| 149 | if (val == e->values[item]) |
| 150 | break; |
| 151 | } |
| 152 | |
| 153 | p->connect = 0; |
| 154 | for (i = 0; i < e->max; i++) { |
| 155 | if (!(strcmp(p->name, e->texts[i])) && item == i) |
| 156 | p->connect = 1; |
| 157 | } |
| 158 | } |
| 159 | break; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 160 | /* does not effect routing - always connected */ |
| 161 | case snd_soc_dapm_pga: |
| 162 | case snd_soc_dapm_output: |
| 163 | case snd_soc_dapm_adc: |
| 164 | case snd_soc_dapm_input: |
| 165 | case snd_soc_dapm_dac: |
| 166 | case snd_soc_dapm_micbias: |
| 167 | case snd_soc_dapm_vmid: |
| 168 | p->connect = 1; |
| 169 | break; |
| 170 | /* does effect routing - dynamically connected */ |
| 171 | case snd_soc_dapm_hp: |
| 172 | case snd_soc_dapm_mic: |
| 173 | case snd_soc_dapm_spk: |
| 174 | case snd_soc_dapm_line: |
| 175 | case snd_soc_dapm_pre: |
| 176 | case snd_soc_dapm_post: |
| 177 | p->connect = 0; |
| 178 | break; |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | /* connect mux widget to it's interconnecting audio paths */ |
| 183 | static int dapm_connect_mux(struct snd_soc_codec *codec, |
| 184 | struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest, |
| 185 | struct snd_soc_dapm_path *path, const char *control_name, |
| 186 | const struct snd_kcontrol_new *kcontrol) |
| 187 | { |
| 188 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
| 189 | int i; |
| 190 | |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 191 | for (i = 0; i < e->max; i++) { |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 192 | if (!(strcmp(control_name, e->texts[i]))) { |
| 193 | list_add(&path->list, &codec->dapm_paths); |
| 194 | list_add(&path->list_sink, &dest->sources); |
| 195 | list_add(&path->list_source, &src->sinks); |
| 196 | path->name = (char*)e->texts[i]; |
| 197 | dapm_set_path_status(dest, path, 0); |
| 198 | return 0; |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | return -ENODEV; |
| 203 | } |
| 204 | |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 205 | /* connect value_mux widget to it's interconnecting audio paths */ |
| 206 | static int dapm_connect_value_mux(struct snd_soc_codec *codec, |
| 207 | struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest, |
| 208 | struct snd_soc_dapm_path *path, const char *control_name, |
| 209 | const struct snd_kcontrol_new *kcontrol) |
| 210 | { |
| 211 | struct soc_value_enum *e = (struct soc_value_enum *) |
| 212 | kcontrol->private_value; |
| 213 | int i; |
| 214 | |
| 215 | for (i = 0; i < e->max; i++) { |
| 216 | if (!(strcmp(control_name, e->texts[i]))) { |
| 217 | list_add(&path->list, &codec->dapm_paths); |
| 218 | list_add(&path->list_sink, &dest->sources); |
| 219 | list_add(&path->list_source, &src->sinks); |
| 220 | path->name = (char *)e->texts[i]; |
| 221 | dapm_set_path_status(dest, path, 0); |
| 222 | return 0; |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | return -ENODEV; |
| 227 | } |
| 228 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 229 | /* connect mixer widget to it's interconnecting audio paths */ |
| 230 | static int dapm_connect_mixer(struct snd_soc_codec *codec, |
| 231 | struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest, |
| 232 | struct snd_soc_dapm_path *path, const char *control_name) |
| 233 | { |
| 234 | int i; |
| 235 | |
| 236 | /* search for mixer kcontrol */ |
| 237 | for (i = 0; i < dest->num_kcontrols; i++) { |
| 238 | if (!strcmp(control_name, dest->kcontrols[i].name)) { |
| 239 | list_add(&path->list, &codec->dapm_paths); |
| 240 | list_add(&path->list_sink, &dest->sources); |
| 241 | list_add(&path->list_source, &src->sinks); |
| 242 | path->name = dest->kcontrols[i].name; |
| 243 | dapm_set_path_status(dest, path, i); |
| 244 | return 0; |
| 245 | } |
| 246 | } |
| 247 | return -ENODEV; |
| 248 | } |
| 249 | |
| 250 | /* update dapm codec register bits */ |
| 251 | static int dapm_update_bits(struct snd_soc_dapm_widget *widget) |
| 252 | { |
| 253 | int change, power; |
| 254 | unsigned short old, new; |
| 255 | struct snd_soc_codec *codec = widget->codec; |
| 256 | |
| 257 | /* check for valid widgets */ |
| 258 | if (widget->reg < 0 || widget->id == snd_soc_dapm_input || |
| 259 | widget->id == snd_soc_dapm_output || |
| 260 | widget->id == snd_soc_dapm_hp || |
| 261 | widget->id == snd_soc_dapm_mic || |
| 262 | widget->id == snd_soc_dapm_line || |
| 263 | widget->id == snd_soc_dapm_spk) |
| 264 | return 0; |
| 265 | |
| 266 | power = widget->power; |
| 267 | if (widget->invert) |
| 268 | power = (power ? 0:1); |
| 269 | |
| 270 | old = snd_soc_read(codec, widget->reg); |
| 271 | new = (old & ~(0x1 << widget->shift)) | (power << widget->shift); |
| 272 | |
| 273 | change = old != new; |
| 274 | if (change) { |
Troy Kisky | 12ef193 | 2008-10-13 17:42:14 -0700 | [diff] [blame] | 275 | pop_dbg(codec->pop_time, "pop test %s : %s in %d ms\n", |
| 276 | widget->name, widget->power ? "on" : "off", |
| 277 | codec->pop_time); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 278 | snd_soc_write(codec, widget->reg, new); |
Troy Kisky | 12ef193 | 2008-10-13 17:42:14 -0700 | [diff] [blame] | 279 | pop_wait(codec->pop_time); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 280 | } |
Mark Brown | c1286b8 | 2008-07-07 19:26:03 +0100 | [diff] [blame] | 281 | pr_debug("reg %x old %x new %x change %d\n", widget->reg, |
| 282 | old, new, change); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 283 | return change; |
| 284 | } |
| 285 | |
| 286 | /* ramps the volume up or down to minimise pops before or after a |
| 287 | * DAPM power event */ |
| 288 | static int dapm_set_pga(struct snd_soc_dapm_widget *widget, int power) |
| 289 | { |
| 290 | const struct snd_kcontrol_new *k = widget->kcontrols; |
| 291 | |
| 292 | if (widget->muted && !power) |
| 293 | return 0; |
| 294 | if (!widget->muted && power) |
| 295 | return 0; |
| 296 | |
| 297 | if (widget->num_kcontrols && k) { |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 298 | struct soc_mixer_control *mc = |
| 299 | (struct soc_mixer_control *)k->private_value; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 300 | unsigned int reg = mc->reg; |
| 301 | unsigned int shift = mc->shift; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 302 | int max = mc->max; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 303 | unsigned int mask = (1 << fls(max)) - 1; |
| 304 | unsigned int invert = mc->invert; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 305 | |
| 306 | if (power) { |
| 307 | int i; |
| 308 | /* power up has happended, increase volume to last level */ |
| 309 | if (invert) { |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 310 | for (i = max; i > widget->saved_value; i--) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 311 | snd_soc_update_bits(widget->codec, reg, mask, i); |
| 312 | } else { |
| 313 | for (i = 0; i < widget->saved_value; i++) |
| 314 | snd_soc_update_bits(widget->codec, reg, mask, i); |
| 315 | } |
| 316 | widget->muted = 0; |
| 317 | } else { |
| 318 | /* power down is about to occur, decrease volume to mute */ |
| 319 | int val = snd_soc_read(widget->codec, reg); |
| 320 | int i = widget->saved_value = (val >> shift) & mask; |
| 321 | if (invert) { |
| 322 | for (; i < mask; i++) |
| 323 | snd_soc_update_bits(widget->codec, reg, mask, i); |
| 324 | } else { |
| 325 | for (; i > 0; i--) |
| 326 | snd_soc_update_bits(widget->codec, reg, mask, i); |
| 327 | } |
| 328 | widget->muted = 1; |
| 329 | } |
| 330 | } |
| 331 | return 0; |
| 332 | } |
| 333 | |
| 334 | /* create new dapm mixer control */ |
| 335 | static int dapm_new_mixer(struct snd_soc_codec *codec, |
| 336 | struct snd_soc_dapm_widget *w) |
| 337 | { |
| 338 | int i, ret = 0; |
Mark Brown | 219b93f | 2008-10-28 13:02:31 +0000 | [diff] [blame] | 339 | size_t name_len; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 340 | struct snd_soc_dapm_path *path; |
| 341 | |
| 342 | /* add kcontrol */ |
| 343 | for (i = 0; i < w->num_kcontrols; i++) { |
| 344 | |
| 345 | /* match name */ |
| 346 | list_for_each_entry(path, &w->sources, list_sink) { |
| 347 | |
| 348 | /* mixer/mux paths name must match control name */ |
| 349 | if (path->name != (char*)w->kcontrols[i].name) |
| 350 | continue; |
| 351 | |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 352 | /* add dapm control with long name. |
| 353 | * for dapm_mixer this is the concatenation of the |
| 354 | * mixer and kcontrol name. |
| 355 | * for dapm_mixer_named_ctl this is simply the |
| 356 | * kcontrol name. |
| 357 | */ |
| 358 | name_len = strlen(w->kcontrols[i].name) + 1; |
| 359 | if (w->id == snd_soc_dapm_mixer) |
| 360 | name_len += 1 + strlen(w->name); |
| 361 | |
Mark Brown | 219b93f | 2008-10-28 13:02:31 +0000 | [diff] [blame] | 362 | path->long_name = kmalloc(name_len, GFP_KERNEL); |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 363 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 364 | if (path->long_name == NULL) |
| 365 | return -ENOMEM; |
| 366 | |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 367 | switch (w->id) { |
| 368 | case snd_soc_dapm_mixer: |
| 369 | default: |
| 370 | snprintf(path->long_name, name_len, "%s %s", |
| 371 | w->name, w->kcontrols[i].name); |
| 372 | break; |
| 373 | case snd_soc_dapm_mixer_named_ctl: |
| 374 | snprintf(path->long_name, name_len, "%s", |
| 375 | w->kcontrols[i].name); |
| 376 | break; |
| 377 | } |
| 378 | |
Mark Brown | 219b93f | 2008-10-28 13:02:31 +0000 | [diff] [blame] | 379 | path->long_name[name_len - 1] = '\0'; |
| 380 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 381 | path->kcontrol = snd_soc_cnew(&w->kcontrols[i], w, |
| 382 | path->long_name); |
| 383 | ret = snd_ctl_add(codec->card, path->kcontrol); |
| 384 | if (ret < 0) { |
| 385 | printk(KERN_ERR "asoc: failed to add dapm kcontrol %s\n", |
| 386 | path->long_name); |
| 387 | kfree(path->long_name); |
| 388 | path->long_name = NULL; |
| 389 | return ret; |
| 390 | } |
| 391 | } |
| 392 | } |
| 393 | return ret; |
| 394 | } |
| 395 | |
| 396 | /* create new dapm mux control */ |
| 397 | static int dapm_new_mux(struct snd_soc_codec *codec, |
| 398 | struct snd_soc_dapm_widget *w) |
| 399 | { |
| 400 | struct snd_soc_dapm_path *path = NULL; |
| 401 | struct snd_kcontrol *kcontrol; |
| 402 | int ret = 0; |
| 403 | |
| 404 | if (!w->num_kcontrols) { |
| 405 | printk(KERN_ERR "asoc: mux %s has no controls\n", w->name); |
| 406 | return -EINVAL; |
| 407 | } |
| 408 | |
| 409 | kcontrol = snd_soc_cnew(&w->kcontrols[0], w, w->name); |
| 410 | ret = snd_ctl_add(codec->card, kcontrol); |
| 411 | if (ret < 0) |
| 412 | goto err; |
| 413 | |
| 414 | list_for_each_entry(path, &w->sources, list_sink) |
| 415 | path->kcontrol = kcontrol; |
| 416 | |
| 417 | return ret; |
| 418 | |
| 419 | err: |
| 420 | printk(KERN_ERR "asoc: failed to add kcontrol %s\n", w->name); |
| 421 | return ret; |
| 422 | } |
| 423 | |
| 424 | /* create new dapm volume control */ |
| 425 | static int dapm_new_pga(struct snd_soc_codec *codec, |
| 426 | struct snd_soc_dapm_widget *w) |
| 427 | { |
| 428 | struct snd_kcontrol *kcontrol; |
| 429 | int ret = 0; |
| 430 | |
| 431 | if (!w->num_kcontrols) |
| 432 | return -EINVAL; |
| 433 | |
| 434 | kcontrol = snd_soc_cnew(&w->kcontrols[0], w, w->name); |
| 435 | ret = snd_ctl_add(codec->card, kcontrol); |
| 436 | if (ret < 0) { |
| 437 | printk(KERN_ERR "asoc: failed to add kcontrol %s\n", w->name); |
| 438 | return ret; |
| 439 | } |
| 440 | |
| 441 | return ret; |
| 442 | } |
| 443 | |
| 444 | /* reset 'walked' bit for each dapm path */ |
| 445 | static inline void dapm_clear_walk(struct snd_soc_codec *codec) |
| 446 | { |
| 447 | struct snd_soc_dapm_path *p; |
| 448 | |
| 449 | list_for_each_entry(p, &codec->dapm_paths, list) |
| 450 | p->walked = 0; |
| 451 | } |
| 452 | |
| 453 | /* |
| 454 | * Recursively check for a completed path to an active or physically connected |
| 455 | * output widget. Returns number of complete paths. |
| 456 | */ |
| 457 | static int is_connected_output_ep(struct snd_soc_dapm_widget *widget) |
| 458 | { |
| 459 | struct snd_soc_dapm_path *path; |
| 460 | int con = 0; |
| 461 | |
| 462 | if (widget->id == snd_soc_dapm_adc && widget->active) |
| 463 | return 1; |
| 464 | |
| 465 | if (widget->connected) { |
| 466 | /* connected pin ? */ |
| 467 | if (widget->id == snd_soc_dapm_output && !widget->ext) |
| 468 | return 1; |
| 469 | |
| 470 | /* connected jack or spk ? */ |
| 471 | if (widget->id == snd_soc_dapm_hp || widget->id == snd_soc_dapm_spk || |
| 472 | widget->id == snd_soc_dapm_line) |
| 473 | return 1; |
| 474 | } |
| 475 | |
| 476 | list_for_each_entry(path, &widget->sinks, list_source) { |
| 477 | if (path->walked) |
| 478 | continue; |
| 479 | |
| 480 | if (path->sink && path->connect) { |
| 481 | path->walked = 1; |
| 482 | con += is_connected_output_ep(path->sink); |
| 483 | } |
| 484 | } |
| 485 | |
| 486 | return con; |
| 487 | } |
| 488 | |
| 489 | /* |
| 490 | * Recursively check for a completed path to an active or physically connected |
| 491 | * input widget. Returns number of complete paths. |
| 492 | */ |
| 493 | static int is_connected_input_ep(struct snd_soc_dapm_widget *widget) |
| 494 | { |
| 495 | struct snd_soc_dapm_path *path; |
| 496 | int con = 0; |
| 497 | |
| 498 | /* active stream ? */ |
| 499 | if (widget->id == snd_soc_dapm_dac && widget->active) |
| 500 | return 1; |
| 501 | |
| 502 | if (widget->connected) { |
| 503 | /* connected pin ? */ |
| 504 | if (widget->id == snd_soc_dapm_input && !widget->ext) |
| 505 | return 1; |
| 506 | |
| 507 | /* connected VMID/Bias for lower pops */ |
| 508 | if (widget->id == snd_soc_dapm_vmid) |
| 509 | return 1; |
| 510 | |
| 511 | /* connected jack ? */ |
| 512 | if (widget->id == snd_soc_dapm_mic || widget->id == snd_soc_dapm_line) |
| 513 | return 1; |
| 514 | } |
| 515 | |
| 516 | list_for_each_entry(path, &widget->sources, list_sink) { |
| 517 | if (path->walked) |
| 518 | continue; |
| 519 | |
| 520 | if (path->source && path->connect) { |
| 521 | path->walked = 1; |
| 522 | con += is_connected_input_ep(path->source); |
| 523 | } |
| 524 | } |
| 525 | |
| 526 | return con; |
| 527 | } |
| 528 | |
| 529 | /* |
Jarkko Nikula | e2be2cc | 2008-06-25 14:42:07 +0300 | [diff] [blame] | 530 | * Handler for generic register modifier widget. |
| 531 | */ |
| 532 | int dapm_reg_event(struct snd_soc_dapm_widget *w, |
| 533 | struct snd_kcontrol *kcontrol, int event) |
| 534 | { |
| 535 | unsigned int val; |
| 536 | |
| 537 | if (SND_SOC_DAPM_EVENT_ON(event)) |
| 538 | val = w->on_val; |
| 539 | else |
| 540 | val = w->off_val; |
| 541 | |
| 542 | snd_soc_update_bits(w->codec, -(w->reg + 1), |
| 543 | w->mask << w->shift, val << w->shift); |
| 544 | |
| 545 | return 0; |
| 546 | } |
Mark Brown | 1158941 | 2008-07-29 11:42:23 +0100 | [diff] [blame] | 547 | EXPORT_SYMBOL_GPL(dapm_reg_event); |
Jarkko Nikula | e2be2cc | 2008-06-25 14:42:07 +0300 | [diff] [blame] | 548 | |
| 549 | /* |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 550 | * Scan each dapm widget for complete audio path. |
| 551 | * A complete path is a route that has valid endpoints i.e.:- |
| 552 | * |
| 553 | * o DAC to output pin. |
| 554 | * o Input Pin to ADC. |
| 555 | * o Input pin to Output pin (bypass, sidetone) |
| 556 | * o DAC to ADC (loopback). |
| 557 | */ |
Adrian Bunk | d9c96cf | 2006-11-28 12:10:09 +0100 | [diff] [blame] | 558 | static int dapm_power_widgets(struct snd_soc_codec *codec, int event) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 559 | { |
| 560 | struct snd_soc_dapm_widget *w; |
| 561 | int in, out, i, c = 1, *seq = NULL, ret = 0, power_change, power; |
| 562 | |
| 563 | /* do we have a sequenced stream event */ |
| 564 | if (event == SND_SOC_DAPM_STREAM_START) { |
| 565 | c = ARRAY_SIZE(dapm_up_seq); |
| 566 | seq = dapm_up_seq; |
| 567 | } else if (event == SND_SOC_DAPM_STREAM_STOP) { |
| 568 | c = ARRAY_SIZE(dapm_down_seq); |
| 569 | seq = dapm_down_seq; |
| 570 | } |
| 571 | |
| 572 | for(i = 0; i < c; i++) { |
| 573 | list_for_each_entry(w, &codec->dapm_widgets, list) { |
| 574 | |
| 575 | /* is widget in stream order */ |
| 576 | if (seq && seq[i] && w->id != seq[i]) |
| 577 | continue; |
| 578 | |
| 579 | /* vmid - no action */ |
| 580 | if (w->id == snd_soc_dapm_vmid) |
| 581 | continue; |
| 582 | |
| 583 | /* active ADC */ |
| 584 | if (w->id == snd_soc_dapm_adc && w->active) { |
| 585 | in = is_connected_input_ep(w); |
| 586 | dapm_clear_walk(w->codec); |
| 587 | w->power = (in != 0) ? 1 : 0; |
| 588 | dapm_update_bits(w); |
| 589 | continue; |
| 590 | } |
| 591 | |
| 592 | /* active DAC */ |
| 593 | if (w->id == snd_soc_dapm_dac && w->active) { |
| 594 | out = is_connected_output_ep(w); |
| 595 | dapm_clear_walk(w->codec); |
| 596 | w->power = (out != 0) ? 1 : 0; |
| 597 | dapm_update_bits(w); |
| 598 | continue; |
| 599 | } |
| 600 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 601 | /* pre and post event widgets */ |
| 602 | if (w->id == snd_soc_dapm_pre) { |
| 603 | if (!w->event) |
| 604 | continue; |
| 605 | |
| 606 | if (event == SND_SOC_DAPM_STREAM_START) { |
Laim Girdwood | 9af6d95 | 2008-01-10 14:41:02 +0100 | [diff] [blame] | 607 | ret = w->event(w, |
| 608 | NULL, SND_SOC_DAPM_PRE_PMU); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 609 | if (ret < 0) |
| 610 | return ret; |
| 611 | } else if (event == SND_SOC_DAPM_STREAM_STOP) { |
Laim Girdwood | 9af6d95 | 2008-01-10 14:41:02 +0100 | [diff] [blame] | 612 | ret = w->event(w, |
| 613 | NULL, SND_SOC_DAPM_PRE_PMD); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 614 | if (ret < 0) |
| 615 | return ret; |
| 616 | } |
| 617 | continue; |
| 618 | } |
| 619 | if (w->id == snd_soc_dapm_post) { |
| 620 | if (!w->event) |
| 621 | continue; |
| 622 | |
| 623 | if (event == SND_SOC_DAPM_STREAM_START) { |
Laim Girdwood | 9af6d95 | 2008-01-10 14:41:02 +0100 | [diff] [blame] | 624 | ret = w->event(w, |
| 625 | NULL, SND_SOC_DAPM_POST_PMU); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 626 | if (ret < 0) |
| 627 | return ret; |
| 628 | } else if (event == SND_SOC_DAPM_STREAM_STOP) { |
Laim Girdwood | 9af6d95 | 2008-01-10 14:41:02 +0100 | [diff] [blame] | 629 | ret = w->event(w, |
| 630 | NULL, SND_SOC_DAPM_POST_PMD); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 631 | if (ret < 0) |
| 632 | return ret; |
| 633 | } |
| 634 | continue; |
| 635 | } |
| 636 | |
| 637 | /* all other widgets */ |
| 638 | in = is_connected_input_ep(w); |
| 639 | dapm_clear_walk(w->codec); |
| 640 | out = is_connected_output_ep(w); |
| 641 | dapm_clear_walk(w->codec); |
| 642 | power = (out != 0 && in != 0) ? 1 : 0; |
| 643 | power_change = (w->power == power) ? 0: 1; |
| 644 | w->power = power; |
| 645 | |
Mark Brown | 2927d6e | 2008-07-17 15:06:50 +0100 | [diff] [blame] | 646 | if (!power_change) |
| 647 | continue; |
| 648 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 649 | /* call any power change event handlers */ |
Mark Brown | 2927d6e | 2008-07-17 15:06:50 +0100 | [diff] [blame] | 650 | if (w->event) |
| 651 | pr_debug("power %s event for %s flags %x\n", |
| 652 | w->power ? "on" : "off", |
| 653 | w->name, w->event_flags); |
| 654 | |
| 655 | /* power up pre event */ |
| 656 | if (power && w->event && |
| 657 | (w->event_flags & SND_SOC_DAPM_PRE_PMU)) { |
| 658 | ret = w->event(w, NULL, SND_SOC_DAPM_PRE_PMU); |
| 659 | if (ret < 0) |
| 660 | return ret; |
| 661 | } |
| 662 | |
| 663 | /* power down pre event */ |
| 664 | if (!power && w->event && |
| 665 | (w->event_flags & SND_SOC_DAPM_PRE_PMD)) { |
| 666 | ret = w->event(w, NULL, SND_SOC_DAPM_PRE_PMD); |
| 667 | if (ret < 0) |
| 668 | return ret; |
| 669 | } |
| 670 | |
Mark Brown | 9dd8d81 | 2008-07-17 15:06:51 +0100 | [diff] [blame] | 671 | /* Lower PGA volume to reduce pops */ |
| 672 | if (w->id == snd_soc_dapm_pga && !power) |
| 673 | dapm_set_pga(w, power); |
| 674 | |
Mark Brown | 2927d6e | 2008-07-17 15:06:50 +0100 | [diff] [blame] | 675 | dapm_update_bits(w); |
| 676 | |
Mark Brown | 9dd8d81 | 2008-07-17 15:06:51 +0100 | [diff] [blame] | 677 | /* Raise PGA volume to reduce pops */ |
| 678 | if (w->id == snd_soc_dapm_pga && power) |
| 679 | dapm_set_pga(w, power); |
| 680 | |
Mark Brown | 2927d6e | 2008-07-17 15:06:50 +0100 | [diff] [blame] | 681 | /* power up post event */ |
| 682 | if (power && w->event && |
| 683 | (w->event_flags & SND_SOC_DAPM_POST_PMU)) { |
| 684 | ret = w->event(w, |
| 685 | NULL, SND_SOC_DAPM_POST_PMU); |
| 686 | if (ret < 0) |
| 687 | return ret; |
| 688 | } |
| 689 | |
| 690 | /* power down post event */ |
| 691 | if (!power && w->event && |
| 692 | (w->event_flags & SND_SOC_DAPM_POST_PMD)) { |
| 693 | ret = w->event(w, NULL, SND_SOC_DAPM_POST_PMD); |
| 694 | if (ret < 0) |
| 695 | return ret; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 696 | } |
| 697 | } |
| 698 | } |
| 699 | |
| 700 | return ret; |
| 701 | } |
| 702 | |
Mark Brown | c1286b8 | 2008-07-07 19:26:03 +0100 | [diff] [blame] | 703 | #ifdef DEBUG |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 704 | static void dbg_dump_dapm(struct snd_soc_codec* codec, const char *action) |
| 705 | { |
| 706 | struct snd_soc_dapm_widget *w; |
| 707 | struct snd_soc_dapm_path *p = NULL; |
| 708 | int in, out; |
| 709 | |
| 710 | printk("DAPM %s %s\n", codec->name, action); |
| 711 | |
| 712 | list_for_each_entry(w, &codec->dapm_widgets, list) { |
| 713 | |
| 714 | /* only display widgets that effect routing */ |
| 715 | switch (w->id) { |
| 716 | case snd_soc_dapm_pre: |
| 717 | case snd_soc_dapm_post: |
| 718 | case snd_soc_dapm_vmid: |
| 719 | continue; |
| 720 | case snd_soc_dapm_mux: |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 721 | case snd_soc_dapm_value_mux: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 722 | case snd_soc_dapm_output: |
| 723 | case snd_soc_dapm_input: |
| 724 | case snd_soc_dapm_switch: |
| 725 | case snd_soc_dapm_hp: |
| 726 | case snd_soc_dapm_mic: |
| 727 | case snd_soc_dapm_spk: |
| 728 | case snd_soc_dapm_line: |
| 729 | case snd_soc_dapm_micbias: |
| 730 | case snd_soc_dapm_dac: |
| 731 | case snd_soc_dapm_adc: |
| 732 | case snd_soc_dapm_pga: |
| 733 | case snd_soc_dapm_mixer: |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 734 | case snd_soc_dapm_mixer_named_ctl: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 735 | if (w->name) { |
| 736 | in = is_connected_input_ep(w); |
| 737 | dapm_clear_walk(w->codec); |
| 738 | out = is_connected_output_ep(w); |
| 739 | dapm_clear_walk(w->codec); |
| 740 | printk("%s: %s in %d out %d\n", w->name, |
| 741 | w->power ? "On":"Off",in, out); |
| 742 | |
| 743 | list_for_each_entry(p, &w->sources, list_sink) { |
| 744 | if (p->connect) |
| 745 | printk(" in %s %s\n", p->name ? p->name : "static", |
| 746 | p->source->name); |
| 747 | } |
| 748 | list_for_each_entry(p, &w->sinks, list_source) { |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 749 | if (p->connect) |
| 750 | printk(" out %s %s\n", p->name ? p->name : "static", |
| 751 | p->sink->name); |
| 752 | } |
| 753 | } |
| 754 | break; |
| 755 | } |
| 756 | } |
| 757 | } |
| 758 | #endif |
| 759 | |
| 760 | /* test and update the power status of a mux widget */ |
Adrian Bunk | d9c96cf | 2006-11-28 12:10:09 +0100 | [diff] [blame] | 761 | static int dapm_mux_update_power(struct snd_soc_dapm_widget *widget, |
| 762 | struct snd_kcontrol *kcontrol, int mask, |
Richard Zhao | cb01e2b | 2008-10-07 08:05:20 +0800 | [diff] [blame] | 763 | int mux, int val, struct soc_enum *e) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 764 | { |
| 765 | struct snd_soc_dapm_path *path; |
| 766 | int found = 0; |
| 767 | |
| 768 | if (widget->id != snd_soc_dapm_mux) |
| 769 | return -ENODEV; |
| 770 | |
| 771 | if (!snd_soc_test_bits(widget->codec, e->reg, mask, val)) |
| 772 | return 0; |
| 773 | |
| 774 | /* find dapm widget path assoc with kcontrol */ |
| 775 | list_for_each_entry(path, &widget->codec->dapm_paths, list) { |
| 776 | if (path->kcontrol != kcontrol) |
| 777 | continue; |
| 778 | |
Richard Zhao | cb01e2b | 2008-10-07 08:05:20 +0800 | [diff] [blame] | 779 | if (!path->name || !e->texts[mux]) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 780 | continue; |
| 781 | |
| 782 | found = 1; |
| 783 | /* we now need to match the string in the enum to the path */ |
Richard Zhao | cb01e2b | 2008-10-07 08:05:20 +0800 | [diff] [blame] | 784 | if (!(strcmp(path->name, e->texts[mux]))) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 785 | path->connect = 1; /* new connection */ |
| 786 | else |
| 787 | path->connect = 0; /* old connection must be powered down */ |
| 788 | } |
| 789 | |
Mark Brown | 3fccd8b | 2008-07-07 19:26:04 +0100 | [diff] [blame] | 790 | if (found) { |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 791 | dapm_power_widgets(widget->codec, SND_SOC_DAPM_STREAM_NOP); |
Mark Brown | 3fccd8b | 2008-07-07 19:26:04 +0100 | [diff] [blame] | 792 | dump_dapm(widget->codec, "mux power update"); |
| 793 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 794 | |
| 795 | return 0; |
| 796 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 797 | |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 798 | /* test and update the power status of a value_mux widget */ |
| 799 | static int dapm_value_mux_update_power(struct snd_soc_dapm_widget *widget, |
| 800 | struct snd_kcontrol *kcontrol, int mask, |
| 801 | int mux, int val, struct soc_value_enum *e) |
| 802 | { |
| 803 | struct snd_soc_dapm_path *path; |
| 804 | int found = 0; |
| 805 | |
| 806 | if (widget->id != snd_soc_dapm_value_mux) |
| 807 | return -ENODEV; |
| 808 | |
| 809 | if (!snd_soc_test_bits(widget->codec, e->reg, mask, val)) |
| 810 | return 0; |
| 811 | |
| 812 | /* find dapm widget path assoc with kcontrol */ |
| 813 | list_for_each_entry(path, &widget->codec->dapm_paths, list) { |
| 814 | if (path->kcontrol != kcontrol) |
| 815 | continue; |
| 816 | |
| 817 | if (!path->name || !e->texts[mux]) |
| 818 | continue; |
| 819 | |
| 820 | found = 1; |
| 821 | /* we now need to match the string in the enum to the path */ |
| 822 | if (!(strcmp(path->name, e->texts[mux]))) |
| 823 | path->connect = 1; /* new connection */ |
| 824 | else |
| 825 | path->connect = 0; /* old connection must be |
| 826 | powered down */ |
| 827 | } |
| 828 | |
| 829 | if (found) { |
| 830 | dapm_power_widgets(widget->codec, SND_SOC_DAPM_STREAM_NOP); |
| 831 | dump_dapm(widget->codec, "mux power update"); |
| 832 | } |
| 833 | |
| 834 | return 0; |
| 835 | } |
| 836 | |
Milan plzik | 1b075e3 | 2008-01-10 14:39:46 +0100 | [diff] [blame] | 837 | /* test and update the power status of a mixer or switch widget */ |
Adrian Bunk | d9c96cf | 2006-11-28 12:10:09 +0100 | [diff] [blame] | 838 | static int dapm_mixer_update_power(struct snd_soc_dapm_widget *widget, |
| 839 | struct snd_kcontrol *kcontrol, int reg, |
| 840 | int val_mask, int val, int invert) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 841 | { |
| 842 | struct snd_soc_dapm_path *path; |
| 843 | int found = 0; |
| 844 | |
Milan plzik | 1b075e3 | 2008-01-10 14:39:46 +0100 | [diff] [blame] | 845 | if (widget->id != snd_soc_dapm_mixer && |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 846 | widget->id != snd_soc_dapm_mixer_named_ctl && |
Milan plzik | 1b075e3 | 2008-01-10 14:39:46 +0100 | [diff] [blame] | 847 | widget->id != snd_soc_dapm_switch) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 848 | return -ENODEV; |
| 849 | |
| 850 | if (!snd_soc_test_bits(widget->codec, reg, val_mask, val)) |
| 851 | return 0; |
| 852 | |
| 853 | /* find dapm widget path assoc with kcontrol */ |
| 854 | list_for_each_entry(path, &widget->codec->dapm_paths, list) { |
| 855 | if (path->kcontrol != kcontrol) |
| 856 | continue; |
| 857 | |
| 858 | /* found, now check type */ |
| 859 | found = 1; |
| 860 | if (val) |
| 861 | /* new connection */ |
| 862 | path->connect = invert ? 0:1; |
| 863 | else |
| 864 | /* old connection must be powered down */ |
| 865 | path->connect = invert ? 1:0; |
| 866 | break; |
| 867 | } |
| 868 | |
Mark Brown | 3fccd8b | 2008-07-07 19:26:04 +0100 | [diff] [blame] | 869 | if (found) { |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 870 | dapm_power_widgets(widget->codec, SND_SOC_DAPM_STREAM_NOP); |
Mark Brown | 3fccd8b | 2008-07-07 19:26:04 +0100 | [diff] [blame] | 871 | dump_dapm(widget->codec, "mixer power update"); |
| 872 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 873 | |
| 874 | return 0; |
| 875 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 876 | |
| 877 | /* show dapm widget status in sys fs */ |
| 878 | static ssize_t dapm_widget_show(struct device *dev, |
| 879 | struct device_attribute *attr, char *buf) |
| 880 | { |
| 881 | struct snd_soc_device *devdata = dev_get_drvdata(dev); |
| 882 | struct snd_soc_codec *codec = devdata->codec; |
| 883 | struct snd_soc_dapm_widget *w; |
| 884 | int count = 0; |
| 885 | char *state = "not set"; |
| 886 | |
| 887 | list_for_each_entry(w, &codec->dapm_widgets, list) { |
| 888 | |
| 889 | /* only display widgets that burnm power */ |
| 890 | switch (w->id) { |
| 891 | case snd_soc_dapm_hp: |
| 892 | case snd_soc_dapm_mic: |
| 893 | case snd_soc_dapm_spk: |
| 894 | case snd_soc_dapm_line: |
| 895 | case snd_soc_dapm_micbias: |
| 896 | case snd_soc_dapm_dac: |
| 897 | case snd_soc_dapm_adc: |
| 898 | case snd_soc_dapm_pga: |
| 899 | case snd_soc_dapm_mixer: |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 900 | case snd_soc_dapm_mixer_named_ctl: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 901 | if (w->name) |
| 902 | count += sprintf(buf + count, "%s: %s\n", |
| 903 | w->name, w->power ? "On":"Off"); |
| 904 | break; |
| 905 | default: |
| 906 | break; |
| 907 | } |
| 908 | } |
| 909 | |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 910 | switch (codec->bias_level) { |
| 911 | case SND_SOC_BIAS_ON: |
| 912 | state = "On"; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 913 | break; |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 914 | case SND_SOC_BIAS_PREPARE: |
| 915 | state = "Prepare"; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 916 | break; |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 917 | case SND_SOC_BIAS_STANDBY: |
| 918 | state = "Standby"; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 919 | break; |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 920 | case SND_SOC_BIAS_OFF: |
| 921 | state = "Off"; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 922 | break; |
| 923 | } |
| 924 | count += sprintf(buf + count, "PM State: %s\n", state); |
| 925 | |
| 926 | return count; |
| 927 | } |
| 928 | |
| 929 | static DEVICE_ATTR(dapm_widget, 0444, dapm_widget_show, NULL); |
| 930 | |
| 931 | int snd_soc_dapm_sys_add(struct device *dev) |
| 932 | { |
Mark Brown | f0062a9 | 2008-08-28 12:46:24 +0100 | [diff] [blame] | 933 | if (!dapm_status) |
| 934 | return 0; |
Troy Kisky | 12ef193 | 2008-10-13 17:42:14 -0700 | [diff] [blame] | 935 | return device_create_file(dev, &dev_attr_dapm_widget); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 936 | } |
| 937 | |
| 938 | static void snd_soc_dapm_sys_remove(struct device *dev) |
| 939 | { |
Mark Brown | 15e4c72 | 2008-07-02 11:51:20 +0100 | [diff] [blame] | 940 | if (dapm_status) { |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 941 | device_remove_file(dev, &dev_attr_dapm_widget); |
Mark Brown | 15e4c72 | 2008-07-02 11:51:20 +0100 | [diff] [blame] | 942 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 943 | } |
| 944 | |
| 945 | /* free all dapm widgets and resources */ |
Adrian Bunk | d9c96cf | 2006-11-28 12:10:09 +0100 | [diff] [blame] | 946 | static void dapm_free_widgets(struct snd_soc_codec *codec) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 947 | { |
| 948 | struct snd_soc_dapm_widget *w, *next_w; |
| 949 | struct snd_soc_dapm_path *p, *next_p; |
| 950 | |
| 951 | list_for_each_entry_safe(w, next_w, &codec->dapm_widgets, list) { |
| 952 | list_del(&w->list); |
| 953 | kfree(w); |
| 954 | } |
| 955 | |
| 956 | list_for_each_entry_safe(p, next_p, &codec->dapm_paths, list) { |
| 957 | list_del(&p->list); |
| 958 | kfree(p->long_name); |
| 959 | kfree(p); |
| 960 | } |
| 961 | } |
| 962 | |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 963 | static int snd_soc_dapm_set_pin(struct snd_soc_codec *codec, |
Mark Brown | 1649923 | 2009-01-07 18:25:13 +0000 | [diff] [blame^] | 964 | const char *pin, int status) |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 965 | { |
| 966 | struct snd_soc_dapm_widget *w; |
| 967 | |
| 968 | list_for_each_entry(w, &codec->dapm_widgets, list) { |
| 969 | if (!strcmp(w->name, pin)) { |
Mark Brown | c1286b8 | 2008-07-07 19:26:03 +0100 | [diff] [blame] | 970 | pr_debug("dapm: %s: pin %s\n", codec->name, pin); |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 971 | w->connected = status; |
| 972 | return 0; |
| 973 | } |
| 974 | } |
| 975 | |
Mark Brown | c1286b8 | 2008-07-07 19:26:03 +0100 | [diff] [blame] | 976 | pr_err("dapm: %s: configuring unknown pin %s\n", codec->name, pin); |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 977 | return -EINVAL; |
| 978 | } |
| 979 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 980 | /** |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 981 | * snd_soc_dapm_sync - scan and power dapm paths |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 982 | * @codec: audio codec |
| 983 | * |
| 984 | * Walks all dapm audio paths and powers widgets according to their |
| 985 | * stream or path usage. |
| 986 | * |
| 987 | * Returns 0 for success. |
| 988 | */ |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 989 | int snd_soc_dapm_sync(struct snd_soc_codec *codec) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 990 | { |
Mark Brown | 3fccd8b | 2008-07-07 19:26:04 +0100 | [diff] [blame] | 991 | int ret = dapm_power_widgets(codec, SND_SOC_DAPM_STREAM_NOP); |
| 992 | dump_dapm(codec, "sync"); |
| 993 | return ret; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 994 | } |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 995 | EXPORT_SYMBOL_GPL(snd_soc_dapm_sync); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 996 | |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 997 | static int snd_soc_dapm_add_route(struct snd_soc_codec *codec, |
| 998 | const char *sink, const char *control, const char *source) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 999 | { |
| 1000 | struct snd_soc_dapm_path *path; |
| 1001 | struct snd_soc_dapm_widget *wsource = NULL, *wsink = NULL, *w; |
| 1002 | int ret = 0; |
| 1003 | |
| 1004 | /* find src and dest widgets */ |
| 1005 | list_for_each_entry(w, &codec->dapm_widgets, list) { |
| 1006 | |
| 1007 | if (!wsink && !(strcmp(w->name, sink))) { |
| 1008 | wsink = w; |
| 1009 | continue; |
| 1010 | } |
| 1011 | if (!wsource && !(strcmp(w->name, source))) { |
| 1012 | wsource = w; |
| 1013 | } |
| 1014 | } |
| 1015 | |
| 1016 | if (wsource == NULL || wsink == NULL) |
| 1017 | return -ENODEV; |
| 1018 | |
| 1019 | path = kzalloc(sizeof(struct snd_soc_dapm_path), GFP_KERNEL); |
| 1020 | if (!path) |
| 1021 | return -ENOMEM; |
| 1022 | |
| 1023 | path->source = wsource; |
| 1024 | path->sink = wsink; |
| 1025 | INIT_LIST_HEAD(&path->list); |
| 1026 | INIT_LIST_HEAD(&path->list_source); |
| 1027 | INIT_LIST_HEAD(&path->list_sink); |
| 1028 | |
| 1029 | /* check for external widgets */ |
| 1030 | if (wsink->id == snd_soc_dapm_input) { |
| 1031 | if (wsource->id == snd_soc_dapm_micbias || |
| 1032 | wsource->id == snd_soc_dapm_mic || |
Seth Forshee | 1e39221 | 2007-04-16 15:36:42 +0200 | [diff] [blame] | 1033 | wsink->id == snd_soc_dapm_line || |
| 1034 | wsink->id == snd_soc_dapm_output) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1035 | wsink->ext = 1; |
| 1036 | } |
| 1037 | if (wsource->id == snd_soc_dapm_output) { |
| 1038 | if (wsink->id == snd_soc_dapm_spk || |
| 1039 | wsink->id == snd_soc_dapm_hp || |
Seth Forshee | 1e39221 | 2007-04-16 15:36:42 +0200 | [diff] [blame] | 1040 | wsink->id == snd_soc_dapm_line || |
| 1041 | wsink->id == snd_soc_dapm_input) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1042 | wsource->ext = 1; |
| 1043 | } |
| 1044 | |
| 1045 | /* connect static paths */ |
| 1046 | if (control == NULL) { |
| 1047 | list_add(&path->list, &codec->dapm_paths); |
| 1048 | list_add(&path->list_sink, &wsink->sources); |
| 1049 | list_add(&path->list_source, &wsource->sinks); |
| 1050 | path->connect = 1; |
| 1051 | return 0; |
| 1052 | } |
| 1053 | |
| 1054 | /* connect dynamic paths */ |
| 1055 | switch(wsink->id) { |
| 1056 | case snd_soc_dapm_adc: |
| 1057 | case snd_soc_dapm_dac: |
| 1058 | case snd_soc_dapm_pga: |
| 1059 | case snd_soc_dapm_input: |
| 1060 | case snd_soc_dapm_output: |
| 1061 | case snd_soc_dapm_micbias: |
| 1062 | case snd_soc_dapm_vmid: |
| 1063 | case snd_soc_dapm_pre: |
| 1064 | case snd_soc_dapm_post: |
| 1065 | list_add(&path->list, &codec->dapm_paths); |
| 1066 | list_add(&path->list_sink, &wsink->sources); |
| 1067 | list_add(&path->list_source, &wsource->sinks); |
| 1068 | path->connect = 1; |
| 1069 | return 0; |
| 1070 | case snd_soc_dapm_mux: |
| 1071 | ret = dapm_connect_mux(codec, wsource, wsink, path, control, |
| 1072 | &wsink->kcontrols[0]); |
| 1073 | if (ret != 0) |
| 1074 | goto err; |
| 1075 | break; |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 1076 | case snd_soc_dapm_value_mux: |
| 1077 | ret = dapm_connect_value_mux(codec, wsource, wsink, path, |
| 1078 | control, &wsink->kcontrols[0]); |
| 1079 | if (ret != 0) |
| 1080 | goto err; |
| 1081 | break; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1082 | case snd_soc_dapm_switch: |
| 1083 | case snd_soc_dapm_mixer: |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 1084 | case snd_soc_dapm_mixer_named_ctl: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1085 | ret = dapm_connect_mixer(codec, wsource, wsink, path, control); |
| 1086 | if (ret != 0) |
| 1087 | goto err; |
| 1088 | break; |
| 1089 | case snd_soc_dapm_hp: |
| 1090 | case snd_soc_dapm_mic: |
| 1091 | case snd_soc_dapm_line: |
| 1092 | case snd_soc_dapm_spk: |
| 1093 | list_add(&path->list, &codec->dapm_paths); |
| 1094 | list_add(&path->list_sink, &wsink->sources); |
| 1095 | list_add(&path->list_source, &wsource->sinks); |
| 1096 | path->connect = 0; |
| 1097 | return 0; |
| 1098 | } |
| 1099 | return 0; |
| 1100 | |
| 1101 | err: |
| 1102 | printk(KERN_WARNING "asoc: no dapm match for %s --> %s --> %s\n", source, |
| 1103 | control, sink); |
| 1104 | kfree(path); |
| 1105 | return ret; |
| 1106 | } |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 1107 | |
| 1108 | /** |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 1109 | * snd_soc_dapm_add_routes - Add routes between DAPM widgets |
| 1110 | * @codec: codec |
| 1111 | * @route: audio routes |
| 1112 | * @num: number of routes |
| 1113 | * |
| 1114 | * Connects 2 dapm widgets together via a named audio path. The sink is |
| 1115 | * the widget receiving the audio signal, whilst the source is the sender |
| 1116 | * of the audio signal. |
| 1117 | * |
| 1118 | * Returns 0 for success else error. On error all resources can be freed |
| 1119 | * with a call to snd_soc_card_free(). |
| 1120 | */ |
| 1121 | int snd_soc_dapm_add_routes(struct snd_soc_codec *codec, |
| 1122 | const struct snd_soc_dapm_route *route, int num) |
| 1123 | { |
| 1124 | int i, ret; |
| 1125 | |
| 1126 | for (i = 0; i < num; i++) { |
| 1127 | ret = snd_soc_dapm_add_route(codec, route->sink, |
| 1128 | route->control, route->source); |
| 1129 | if (ret < 0) { |
| 1130 | printk(KERN_ERR "Failed to add route %s->%s\n", |
| 1131 | route->source, |
| 1132 | route->sink); |
| 1133 | return ret; |
| 1134 | } |
| 1135 | route++; |
| 1136 | } |
| 1137 | |
| 1138 | return 0; |
| 1139 | } |
| 1140 | EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes); |
| 1141 | |
| 1142 | /** |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1143 | * snd_soc_dapm_new_widgets - add new dapm widgets |
| 1144 | * @codec: audio codec |
| 1145 | * |
| 1146 | * Checks the codec for any new dapm widgets and creates them if found. |
| 1147 | * |
| 1148 | * Returns 0 for success. |
| 1149 | */ |
| 1150 | int snd_soc_dapm_new_widgets(struct snd_soc_codec *codec) |
| 1151 | { |
| 1152 | struct snd_soc_dapm_widget *w; |
| 1153 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1154 | list_for_each_entry(w, &codec->dapm_widgets, list) |
| 1155 | { |
| 1156 | if (w->new) |
| 1157 | continue; |
| 1158 | |
| 1159 | switch(w->id) { |
| 1160 | case snd_soc_dapm_switch: |
| 1161 | case snd_soc_dapm_mixer: |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 1162 | case snd_soc_dapm_mixer_named_ctl: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1163 | dapm_new_mixer(codec, w); |
| 1164 | break; |
| 1165 | case snd_soc_dapm_mux: |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 1166 | case snd_soc_dapm_value_mux: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1167 | dapm_new_mux(codec, w); |
| 1168 | break; |
| 1169 | case snd_soc_dapm_adc: |
| 1170 | case snd_soc_dapm_dac: |
| 1171 | case snd_soc_dapm_pga: |
| 1172 | dapm_new_pga(codec, w); |
| 1173 | break; |
| 1174 | case snd_soc_dapm_input: |
| 1175 | case snd_soc_dapm_output: |
| 1176 | case snd_soc_dapm_micbias: |
| 1177 | case snd_soc_dapm_spk: |
| 1178 | case snd_soc_dapm_hp: |
| 1179 | case snd_soc_dapm_mic: |
| 1180 | case snd_soc_dapm_line: |
| 1181 | case snd_soc_dapm_vmid: |
| 1182 | case snd_soc_dapm_pre: |
| 1183 | case snd_soc_dapm_post: |
| 1184 | break; |
| 1185 | } |
| 1186 | w->new = 1; |
| 1187 | } |
| 1188 | |
| 1189 | dapm_power_widgets(codec, SND_SOC_DAPM_STREAM_NOP); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1190 | return 0; |
| 1191 | } |
| 1192 | EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets); |
| 1193 | |
| 1194 | /** |
| 1195 | * snd_soc_dapm_get_volsw - dapm mixer get callback |
| 1196 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 1197 | * @ucontrol: control element information |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1198 | * |
| 1199 | * Callback to get the value of a dapm mixer control. |
| 1200 | * |
| 1201 | * Returns 0 for success. |
| 1202 | */ |
| 1203 | int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol, |
| 1204 | struct snd_ctl_elem_value *ucontrol) |
| 1205 | { |
| 1206 | struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol); |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 1207 | struct soc_mixer_control *mc = |
| 1208 | (struct soc_mixer_control *)kcontrol->private_value; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 1209 | unsigned int reg = mc->reg; |
| 1210 | unsigned int shift = mc->shift; |
| 1211 | unsigned int rshift = mc->rshift; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 1212 | int max = mc->max; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 1213 | unsigned int invert = mc->invert; |
| 1214 | unsigned int mask = (1 << fls(max)) - 1; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1215 | |
| 1216 | /* return the saved value if we are powered down */ |
| 1217 | if (widget->id == snd_soc_dapm_pga && !widget->power) { |
| 1218 | ucontrol->value.integer.value[0] = widget->saved_value; |
| 1219 | return 0; |
| 1220 | } |
| 1221 | |
| 1222 | ucontrol->value.integer.value[0] = |
| 1223 | (snd_soc_read(widget->codec, reg) >> shift) & mask; |
| 1224 | if (shift != rshift) |
| 1225 | ucontrol->value.integer.value[1] = |
| 1226 | (snd_soc_read(widget->codec, reg) >> rshift) & mask; |
| 1227 | if (invert) { |
| 1228 | ucontrol->value.integer.value[0] = |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 1229 | max - ucontrol->value.integer.value[0]; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1230 | if (shift != rshift) |
| 1231 | ucontrol->value.integer.value[1] = |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 1232 | max - ucontrol->value.integer.value[1]; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1233 | } |
| 1234 | |
| 1235 | return 0; |
| 1236 | } |
| 1237 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw); |
| 1238 | |
| 1239 | /** |
| 1240 | * snd_soc_dapm_put_volsw - dapm mixer set callback |
| 1241 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 1242 | * @ucontrol: control element information |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1243 | * |
| 1244 | * Callback to set the value of a dapm mixer control. |
| 1245 | * |
| 1246 | * Returns 0 for success. |
| 1247 | */ |
| 1248 | int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol, |
| 1249 | struct snd_ctl_elem_value *ucontrol) |
| 1250 | { |
| 1251 | struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol); |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 1252 | struct soc_mixer_control *mc = |
| 1253 | (struct soc_mixer_control *)kcontrol->private_value; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 1254 | unsigned int reg = mc->reg; |
| 1255 | unsigned int shift = mc->shift; |
| 1256 | unsigned int rshift = mc->rshift; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 1257 | int max = mc->max; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 1258 | unsigned int mask = (1 << fls(max)) - 1; |
| 1259 | unsigned int invert = mc->invert; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1260 | unsigned short val, val2, val_mask; |
| 1261 | int ret; |
| 1262 | |
| 1263 | val = (ucontrol->value.integer.value[0] & mask); |
| 1264 | |
| 1265 | if (invert) |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 1266 | val = max - val; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1267 | val_mask = mask << shift; |
| 1268 | val = val << shift; |
| 1269 | if (shift != rshift) { |
| 1270 | val2 = (ucontrol->value.integer.value[1] & mask); |
| 1271 | if (invert) |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 1272 | val2 = max - val2; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1273 | val_mask |= mask << rshift; |
| 1274 | val |= val2 << rshift; |
| 1275 | } |
| 1276 | |
| 1277 | mutex_lock(&widget->codec->mutex); |
| 1278 | widget->value = val; |
| 1279 | |
| 1280 | /* save volume value if the widget is powered down */ |
| 1281 | if (widget->id == snd_soc_dapm_pga && !widget->power) { |
| 1282 | widget->saved_value = val; |
| 1283 | mutex_unlock(&widget->codec->mutex); |
| 1284 | return 1; |
| 1285 | } |
| 1286 | |
| 1287 | dapm_mixer_update_power(widget, kcontrol, reg, val_mask, val, invert); |
| 1288 | if (widget->event) { |
| 1289 | if (widget->event_flags & SND_SOC_DAPM_PRE_REG) { |
Laim Girdwood | 9af6d95 | 2008-01-10 14:41:02 +0100 | [diff] [blame] | 1290 | ret = widget->event(widget, kcontrol, |
| 1291 | SND_SOC_DAPM_PRE_REG); |
| 1292 | if (ret < 0) { |
| 1293 | ret = 1; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1294 | goto out; |
Laim Girdwood | 9af6d95 | 2008-01-10 14:41:02 +0100 | [diff] [blame] | 1295 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1296 | } |
| 1297 | ret = snd_soc_update_bits(widget->codec, reg, val_mask, val); |
| 1298 | if (widget->event_flags & SND_SOC_DAPM_POST_REG) |
Laim Girdwood | 9af6d95 | 2008-01-10 14:41:02 +0100 | [diff] [blame] | 1299 | ret = widget->event(widget, kcontrol, |
| 1300 | SND_SOC_DAPM_POST_REG); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1301 | } else |
| 1302 | ret = snd_soc_update_bits(widget->codec, reg, val_mask, val); |
| 1303 | |
| 1304 | out: |
| 1305 | mutex_unlock(&widget->codec->mutex); |
| 1306 | return ret; |
| 1307 | } |
| 1308 | EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw); |
| 1309 | |
| 1310 | /** |
| 1311 | * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback |
| 1312 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 1313 | * @ucontrol: control element information |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1314 | * |
| 1315 | * Callback to get the value of a dapm enumerated double mixer control. |
| 1316 | * |
| 1317 | * Returns 0 for success. |
| 1318 | */ |
| 1319 | int snd_soc_dapm_get_enum_double(struct snd_kcontrol *kcontrol, |
| 1320 | struct snd_ctl_elem_value *ucontrol) |
| 1321 | { |
| 1322 | struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol); |
| 1323 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
| 1324 | unsigned short val, bitmask; |
| 1325 | |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 1326 | for (bitmask = 1; bitmask < e->max; bitmask <<= 1) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1327 | ; |
| 1328 | val = snd_soc_read(widget->codec, e->reg); |
| 1329 | ucontrol->value.enumerated.item[0] = (val >> e->shift_l) & (bitmask - 1); |
| 1330 | if (e->shift_l != e->shift_r) |
| 1331 | ucontrol->value.enumerated.item[1] = |
| 1332 | (val >> e->shift_r) & (bitmask - 1); |
| 1333 | |
| 1334 | return 0; |
| 1335 | } |
| 1336 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double); |
| 1337 | |
| 1338 | /** |
| 1339 | * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback |
| 1340 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 1341 | * @ucontrol: control element information |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1342 | * |
| 1343 | * Callback to set the value of a dapm enumerated double mixer control. |
| 1344 | * |
| 1345 | * Returns 0 for success. |
| 1346 | */ |
| 1347 | int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol, |
| 1348 | struct snd_ctl_elem_value *ucontrol) |
| 1349 | { |
| 1350 | struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol); |
| 1351 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
| 1352 | unsigned short val, mux; |
| 1353 | unsigned short mask, bitmask; |
| 1354 | int ret = 0; |
| 1355 | |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 1356 | for (bitmask = 1; bitmask < e->max; bitmask <<= 1) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1357 | ; |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 1358 | if (ucontrol->value.enumerated.item[0] > e->max - 1) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1359 | return -EINVAL; |
| 1360 | mux = ucontrol->value.enumerated.item[0]; |
| 1361 | val = mux << e->shift_l; |
| 1362 | mask = (bitmask - 1) << e->shift_l; |
| 1363 | if (e->shift_l != e->shift_r) { |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 1364 | if (ucontrol->value.enumerated.item[1] > e->max - 1) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1365 | return -EINVAL; |
| 1366 | val |= ucontrol->value.enumerated.item[1] << e->shift_r; |
| 1367 | mask |= (bitmask - 1) << e->shift_r; |
| 1368 | } |
| 1369 | |
| 1370 | mutex_lock(&widget->codec->mutex); |
| 1371 | widget->value = val; |
Richard Zhao | cb01e2b | 2008-10-07 08:05:20 +0800 | [diff] [blame] | 1372 | dapm_mux_update_power(widget, kcontrol, mask, mux, val, e); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1373 | if (widget->event) { |
| 1374 | if (widget->event_flags & SND_SOC_DAPM_PRE_REG) { |
Laim Girdwood | 9af6d95 | 2008-01-10 14:41:02 +0100 | [diff] [blame] | 1375 | ret = widget->event(widget, |
| 1376 | kcontrol, SND_SOC_DAPM_PRE_REG); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1377 | if (ret < 0) |
| 1378 | goto out; |
| 1379 | } |
| 1380 | ret = snd_soc_update_bits(widget->codec, e->reg, mask, val); |
| 1381 | if (widget->event_flags & SND_SOC_DAPM_POST_REG) |
Laim Girdwood | 9af6d95 | 2008-01-10 14:41:02 +0100 | [diff] [blame] | 1382 | ret = widget->event(widget, |
| 1383 | kcontrol, SND_SOC_DAPM_POST_REG); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1384 | } else |
| 1385 | ret = snd_soc_update_bits(widget->codec, e->reg, mask, val); |
| 1386 | |
| 1387 | out: |
| 1388 | mutex_unlock(&widget->codec->mutex); |
| 1389 | return ret; |
| 1390 | } |
| 1391 | EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double); |
| 1392 | |
| 1393 | /** |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 1394 | * snd_soc_dapm_get_value_enum_double - dapm semi enumerated double mixer get |
| 1395 | * callback |
| 1396 | * @kcontrol: mixer control |
| 1397 | * @ucontrol: control element information |
| 1398 | * |
| 1399 | * Callback to get the value of a dapm semi enumerated double mixer control. |
| 1400 | * |
| 1401 | * Semi enumerated mixer: the enumerated items are referred as values. Can be |
| 1402 | * used for handling bitfield coded enumeration for example. |
| 1403 | * |
| 1404 | * Returns 0 for success. |
| 1405 | */ |
| 1406 | int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol *kcontrol, |
| 1407 | struct snd_ctl_elem_value *ucontrol) |
| 1408 | { |
| 1409 | struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol); |
| 1410 | struct soc_value_enum *e = (struct soc_value_enum *) |
| 1411 | kcontrol->private_value; |
| 1412 | unsigned short reg_val, val, mux; |
| 1413 | |
| 1414 | reg_val = snd_soc_read(widget->codec, e->reg); |
| 1415 | val = (reg_val >> e->shift_l) & e->mask; |
| 1416 | for (mux = 0; mux < e->max; mux++) { |
| 1417 | if (val == e->values[mux]) |
| 1418 | break; |
| 1419 | } |
| 1420 | ucontrol->value.enumerated.item[0] = mux; |
| 1421 | if (e->shift_l != e->shift_r) { |
| 1422 | val = (reg_val >> e->shift_r) & e->mask; |
| 1423 | for (mux = 0; mux < e->max; mux++) { |
| 1424 | if (val == e->values[mux]) |
| 1425 | break; |
| 1426 | } |
| 1427 | ucontrol->value.enumerated.item[1] = mux; |
| 1428 | } |
| 1429 | |
| 1430 | return 0; |
| 1431 | } |
| 1432 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_value_enum_double); |
| 1433 | |
| 1434 | /** |
| 1435 | * snd_soc_dapm_put_value_enum_double - dapm semi enumerated double mixer set |
| 1436 | * callback |
| 1437 | * @kcontrol: mixer control |
| 1438 | * @ucontrol: control element information |
| 1439 | * |
| 1440 | * Callback to set the value of a dapm semi enumerated double mixer control. |
| 1441 | * |
| 1442 | * Semi enumerated mixer: the enumerated items are referred as values. Can be |
| 1443 | * used for handling bitfield coded enumeration for example. |
| 1444 | * |
| 1445 | * Returns 0 for success. |
| 1446 | */ |
| 1447 | int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol *kcontrol, |
| 1448 | struct snd_ctl_elem_value *ucontrol) |
| 1449 | { |
| 1450 | struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol); |
| 1451 | struct soc_value_enum *e = (struct soc_value_enum *) |
| 1452 | kcontrol->private_value; |
| 1453 | unsigned short val, mux; |
| 1454 | unsigned short mask; |
| 1455 | int ret = 0; |
| 1456 | |
| 1457 | if (ucontrol->value.enumerated.item[0] > e->max - 1) |
| 1458 | return -EINVAL; |
| 1459 | mux = ucontrol->value.enumerated.item[0]; |
| 1460 | val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l; |
| 1461 | mask = e->mask << e->shift_l; |
| 1462 | if (e->shift_l != e->shift_r) { |
| 1463 | if (ucontrol->value.enumerated.item[1] > e->max - 1) |
| 1464 | return -EINVAL; |
| 1465 | val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r; |
| 1466 | mask |= e->mask << e->shift_r; |
| 1467 | } |
| 1468 | |
| 1469 | mutex_lock(&widget->codec->mutex); |
| 1470 | widget->value = val; |
| 1471 | dapm_value_mux_update_power(widget, kcontrol, mask, mux, val, e); |
| 1472 | if (widget->event) { |
| 1473 | if (widget->event_flags & SND_SOC_DAPM_PRE_REG) { |
| 1474 | ret = widget->event(widget, |
| 1475 | kcontrol, SND_SOC_DAPM_PRE_REG); |
| 1476 | if (ret < 0) |
| 1477 | goto out; |
| 1478 | } |
| 1479 | ret = snd_soc_update_bits(widget->codec, e->reg, mask, val); |
| 1480 | if (widget->event_flags & SND_SOC_DAPM_POST_REG) |
| 1481 | ret = widget->event(widget, |
| 1482 | kcontrol, SND_SOC_DAPM_POST_REG); |
| 1483 | } else |
| 1484 | ret = snd_soc_update_bits(widget->codec, e->reg, mask, val); |
| 1485 | |
| 1486 | out: |
| 1487 | mutex_unlock(&widget->codec->mutex); |
| 1488 | return ret; |
| 1489 | } |
| 1490 | EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double); |
| 1491 | |
| 1492 | /** |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1493 | * snd_soc_dapm_new_control - create new dapm control |
| 1494 | * @codec: audio codec |
| 1495 | * @widget: widget template |
| 1496 | * |
| 1497 | * Creates a new dapm control based upon the template. |
| 1498 | * |
| 1499 | * Returns 0 for success else error. |
| 1500 | */ |
| 1501 | int snd_soc_dapm_new_control(struct snd_soc_codec *codec, |
| 1502 | const struct snd_soc_dapm_widget *widget) |
| 1503 | { |
| 1504 | struct snd_soc_dapm_widget *w; |
| 1505 | |
| 1506 | if ((w = dapm_cnew_widget(widget)) == NULL) |
| 1507 | return -ENOMEM; |
| 1508 | |
| 1509 | w->codec = codec; |
| 1510 | INIT_LIST_HEAD(&w->sources); |
| 1511 | INIT_LIST_HEAD(&w->sinks); |
| 1512 | INIT_LIST_HEAD(&w->list); |
| 1513 | list_add(&w->list, &codec->dapm_widgets); |
| 1514 | |
| 1515 | /* machine layer set ups unconnected pins and insertions */ |
| 1516 | w->connected = 1; |
| 1517 | return 0; |
| 1518 | } |
| 1519 | EXPORT_SYMBOL_GPL(snd_soc_dapm_new_control); |
| 1520 | |
| 1521 | /** |
Mark Brown | 4ba1327 | 2008-05-13 14:51:19 +0200 | [diff] [blame] | 1522 | * snd_soc_dapm_new_controls - create new dapm controls |
| 1523 | * @codec: audio codec |
| 1524 | * @widget: widget array |
| 1525 | * @num: number of widgets |
| 1526 | * |
| 1527 | * Creates new DAPM controls based upon the templates. |
| 1528 | * |
| 1529 | * Returns 0 for success else error. |
| 1530 | */ |
| 1531 | int snd_soc_dapm_new_controls(struct snd_soc_codec *codec, |
| 1532 | const struct snd_soc_dapm_widget *widget, |
| 1533 | int num) |
| 1534 | { |
| 1535 | int i, ret; |
| 1536 | |
| 1537 | for (i = 0; i < num; i++) { |
| 1538 | ret = snd_soc_dapm_new_control(codec, widget); |
Mark Brown | b8b33cb | 2008-12-18 11:19:30 +0000 | [diff] [blame] | 1539 | if (ret < 0) { |
| 1540 | printk(KERN_ERR |
| 1541 | "ASoC: Failed to create DAPM control %s: %d\n", |
| 1542 | widget->name, ret); |
Mark Brown | 4ba1327 | 2008-05-13 14:51:19 +0200 | [diff] [blame] | 1543 | return ret; |
Mark Brown | b8b33cb | 2008-12-18 11:19:30 +0000 | [diff] [blame] | 1544 | } |
Mark Brown | 4ba1327 | 2008-05-13 14:51:19 +0200 | [diff] [blame] | 1545 | widget++; |
| 1546 | } |
| 1547 | return 0; |
| 1548 | } |
| 1549 | EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls); |
| 1550 | |
| 1551 | |
| 1552 | /** |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1553 | * snd_soc_dapm_stream_event - send a stream event to the dapm core |
| 1554 | * @codec: audio codec |
| 1555 | * @stream: stream name |
| 1556 | * @event: stream event |
| 1557 | * |
| 1558 | * Sends a stream event to the dapm core. The core then makes any |
| 1559 | * necessary widget power changes. |
| 1560 | * |
| 1561 | * Returns 0 for success else error. |
| 1562 | */ |
| 1563 | int snd_soc_dapm_stream_event(struct snd_soc_codec *codec, |
| 1564 | char *stream, int event) |
| 1565 | { |
| 1566 | struct snd_soc_dapm_widget *w; |
| 1567 | |
Seth Forshee | 11da21a | 2007-02-02 17:14:19 +0100 | [diff] [blame] | 1568 | if (stream == NULL) |
| 1569 | return 0; |
| 1570 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1571 | mutex_lock(&codec->mutex); |
| 1572 | list_for_each_entry(w, &codec->dapm_widgets, list) |
| 1573 | { |
| 1574 | if (!w->sname) |
| 1575 | continue; |
Mark Brown | c1286b8 | 2008-07-07 19:26:03 +0100 | [diff] [blame] | 1576 | pr_debug("widget %s\n %s stream %s event %d\n", |
| 1577 | w->name, w->sname, stream, event); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1578 | if (strstr(w->sname, stream)) { |
| 1579 | switch(event) { |
| 1580 | case SND_SOC_DAPM_STREAM_START: |
| 1581 | w->active = 1; |
| 1582 | break; |
| 1583 | case SND_SOC_DAPM_STREAM_STOP: |
| 1584 | w->active = 0; |
| 1585 | break; |
| 1586 | case SND_SOC_DAPM_STREAM_SUSPEND: |
| 1587 | if (w->active) |
| 1588 | w->suspend = 1; |
| 1589 | w->active = 0; |
| 1590 | break; |
| 1591 | case SND_SOC_DAPM_STREAM_RESUME: |
| 1592 | if (w->suspend) { |
| 1593 | w->active = 1; |
| 1594 | w->suspend = 0; |
| 1595 | } |
| 1596 | break; |
| 1597 | case SND_SOC_DAPM_STREAM_PAUSE_PUSH: |
| 1598 | break; |
| 1599 | case SND_SOC_DAPM_STREAM_PAUSE_RELEASE: |
| 1600 | break; |
| 1601 | } |
| 1602 | } |
| 1603 | } |
| 1604 | mutex_unlock(&codec->mutex); |
| 1605 | |
| 1606 | dapm_power_widgets(codec, event); |
Harvey Harrison | 9bf8e7d | 2008-03-03 15:32:18 -0800 | [diff] [blame] | 1607 | dump_dapm(codec, __func__); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1608 | return 0; |
| 1609 | } |
| 1610 | EXPORT_SYMBOL_GPL(snd_soc_dapm_stream_event); |
| 1611 | |
| 1612 | /** |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1613 | * snd_soc_dapm_set_bias_level - set the bias level for the system |
Liam Girdwood | 0b4d221 | 2008-01-10 14:36:20 +0100 | [diff] [blame] | 1614 | * @socdev: audio device |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1615 | * @level: level to configure |
Liam Girdwood | 0b4d221 | 2008-01-10 14:36:20 +0100 | [diff] [blame] | 1616 | * |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1617 | * Configure the bias (power) levels for the SoC audio device. |
Liam Girdwood | 0b4d221 | 2008-01-10 14:36:20 +0100 | [diff] [blame] | 1618 | * |
| 1619 | * Returns 0 for success else error. |
| 1620 | */ |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1621 | int snd_soc_dapm_set_bias_level(struct snd_soc_device *socdev, |
| 1622 | enum snd_soc_bias_level level) |
Liam Girdwood | 0b4d221 | 2008-01-10 14:36:20 +0100 | [diff] [blame] | 1623 | { |
| 1624 | struct snd_soc_codec *codec = socdev->codec; |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 1625 | struct snd_soc_card *card = socdev->card; |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1626 | int ret = 0; |
Liam Girdwood | 0b4d221 | 2008-01-10 14:36:20 +0100 | [diff] [blame] | 1627 | |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 1628 | if (card->set_bias_level) |
| 1629 | ret = card->set_bias_level(card, level); |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1630 | if (ret == 0 && codec->set_bias_level) |
| 1631 | ret = codec->set_bias_level(codec, level); |
| 1632 | |
| 1633 | return ret; |
Liam Girdwood | 0b4d221 | 2008-01-10 14:36:20 +0100 | [diff] [blame] | 1634 | } |
Liam Girdwood | 0b4d221 | 2008-01-10 14:36:20 +0100 | [diff] [blame] | 1635 | |
| 1636 | /** |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 1637 | * snd_soc_dapm_enable_pin - enable pin. |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 1638 | * @codec: SoC codec |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 1639 | * @pin: pin name |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1640 | * |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 1641 | * Enables input/output pin and it's parents or children widgets iff there is |
| 1642 | * a valid audio route and active audio stream. |
| 1643 | * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to |
| 1644 | * do any widget power switching. |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1645 | */ |
Mark Brown | 1649923 | 2009-01-07 18:25:13 +0000 | [diff] [blame^] | 1646 | int snd_soc_dapm_enable_pin(struct snd_soc_codec *codec, const char *pin) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1647 | { |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 1648 | return snd_soc_dapm_set_pin(codec, pin, 1); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1649 | } |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 1650 | EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1651 | |
| 1652 | /** |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 1653 | * snd_soc_dapm_disable_pin - disable pin. |
| 1654 | * @codec: SoC codec |
| 1655 | * @pin: pin name |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 1656 | * |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 1657 | * Disables input/output pin and it's parents or children widgets. |
| 1658 | * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to |
| 1659 | * do any widget power switching. |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 1660 | */ |
Mark Brown | 1649923 | 2009-01-07 18:25:13 +0000 | [diff] [blame^] | 1661 | int snd_soc_dapm_disable_pin(struct snd_soc_codec *codec, const char *pin) |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 1662 | { |
| 1663 | return snd_soc_dapm_set_pin(codec, pin, 0); |
| 1664 | } |
| 1665 | EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin); |
| 1666 | |
| 1667 | /** |
Mark Brown | 5817b52 | 2008-09-24 11:23:11 +0100 | [diff] [blame] | 1668 | * snd_soc_dapm_nc_pin - permanently disable pin. |
| 1669 | * @codec: SoC codec |
| 1670 | * @pin: pin name |
| 1671 | * |
| 1672 | * Marks the specified pin as being not connected, disabling it along |
| 1673 | * any parent or child widgets. At present this is identical to |
| 1674 | * snd_soc_dapm_disable_pin() but in future it will be extended to do |
| 1675 | * additional things such as disabling controls which only affect |
| 1676 | * paths through the pin. |
| 1677 | * |
| 1678 | * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to |
| 1679 | * do any widget power switching. |
| 1680 | */ |
Mark Brown | 1649923 | 2009-01-07 18:25:13 +0000 | [diff] [blame^] | 1681 | int snd_soc_dapm_nc_pin(struct snd_soc_codec *codec, const char *pin) |
Mark Brown | 5817b52 | 2008-09-24 11:23:11 +0100 | [diff] [blame] | 1682 | { |
| 1683 | return snd_soc_dapm_set_pin(codec, pin, 0); |
| 1684 | } |
| 1685 | EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin); |
| 1686 | |
| 1687 | /** |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 1688 | * snd_soc_dapm_get_pin_status - get audio pin status |
| 1689 | * @codec: audio codec |
| 1690 | * @pin: audio signal pin endpoint (or start point) |
| 1691 | * |
| 1692 | * Get audio pin status - connected or disconnected. |
| 1693 | * |
| 1694 | * Returns 1 for connected otherwise 0. |
| 1695 | */ |
Mark Brown | 1649923 | 2009-01-07 18:25:13 +0000 | [diff] [blame^] | 1696 | int snd_soc_dapm_get_pin_status(struct snd_soc_codec *codec, const char *pin) |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 1697 | { |
| 1698 | struct snd_soc_dapm_widget *w; |
| 1699 | |
| 1700 | list_for_each_entry(w, &codec->dapm_widgets, list) { |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 1701 | if (!strcmp(w->name, pin)) |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 1702 | return w->connected; |
| 1703 | } |
| 1704 | |
| 1705 | return 0; |
| 1706 | } |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 1707 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status); |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 1708 | |
| 1709 | /** |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1710 | * snd_soc_dapm_free - free dapm resources |
| 1711 | * @socdev: SoC device |
| 1712 | * |
| 1713 | * Free all dapm widgets and resources. |
| 1714 | */ |
| 1715 | void snd_soc_dapm_free(struct snd_soc_device *socdev) |
| 1716 | { |
| 1717 | struct snd_soc_codec *codec = socdev->codec; |
| 1718 | |
| 1719 | snd_soc_dapm_sys_remove(socdev->dev); |
| 1720 | dapm_free_widgets(codec); |
| 1721 | } |
| 1722 | EXPORT_SYMBOL_GPL(snd_soc_dapm_free); |
| 1723 | |
| 1724 | /* Module information */ |
Liam Girdwood | d331124 | 2008-10-12 13:17:36 +0100 | [diff] [blame] | 1725 | MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk"); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1726 | MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC"); |
| 1727 | MODULE_LICENSE("GPL"); |