soc-dapm.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323
  1. /*
  2. * soc-dapm.c -- ALSA SoC Dynamic Audio Power Management
  3. *
  4. * Copyright 2005 Wolfson Microelectronics PLC.
  5. * Author: Liam Girdwood
  6. * liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. *
  13. * Revision history
  14. * 12th Aug 2005 Initial version.
  15. * 25th Oct 2005 Implemented path power domain.
  16. * 18th Dec 2005 Implemented machine and stream level power domain.
  17. *
  18. * Features:
  19. * o Changes power status of internal codec blocks depending on the
  20. * dynamic configuration of codec internal audio paths and active
  21. * DAC's/ADC's.
  22. * o Platform power domain - can support external components i.e. amps and
  23. * mic/meadphone insertion events.
  24. * o Automatic Mic Bias support
  25. * o Jack insertion power event initiation - e.g. hp insertion will enable
  26. * sinks, dacs, etc
  27. * o Delayed powerdown of audio susbsytem to reduce pops between a quick
  28. * device reopen.
  29. *
  30. * Todo:
  31. * o DAPM power change sequencing - allow for configurable per
  32. * codec sequences.
  33. * o Support for analogue bias optimisation.
  34. * o Support for reduced codec oversampling rates.
  35. * o Support for reduced codec bias currents.
  36. */
  37. #include <linux/module.h>
  38. #include <linux/moduleparam.h>
  39. #include <linux/init.h>
  40. #include <linux/delay.h>
  41. #include <linux/pm.h>
  42. #include <linux/bitops.h>
  43. #include <linux/platform_device.h>
  44. #include <linux/jiffies.h>
  45. #include <sound/driver.h>
  46. #include <sound/core.h>
  47. #include <sound/pcm.h>
  48. #include <sound/pcm_params.h>
  49. #include <sound/soc-dapm.h>
  50. #include <sound/initval.h>
  51. /* debug */
  52. #define DAPM_DEBUG 0
  53. #if DAPM_DEBUG
  54. #define dump_dapm(codec, action) dbg_dump_dapm(codec, action)
  55. #define dbg(format, arg...) printk(format, ## arg)
  56. #else
  57. #define dump_dapm(codec, action)
  58. #define dbg(format, arg...)
  59. #endif
  60. #define POP_DEBUG 0
  61. #if POP_DEBUG
  62. #define POP_TIME 500 /* 500 msecs - change if pop debug is too fast */
  63. #define pop_wait(time) schedule_timeout_interruptible(msecs_to_jiffies(time))
  64. #define pop_dbg(format, arg...) printk(format, ## arg); pop_wait(POP_TIME)
  65. #else
  66. #define pop_dbg(format, arg...)
  67. #define pop_wait(time)
  68. #endif
  69. /* dapm power sequences - make this per codec in the future */
  70. static int dapm_up_seq[] = {
  71. snd_soc_dapm_pre, snd_soc_dapm_micbias, snd_soc_dapm_mic,
  72. snd_soc_dapm_mux, snd_soc_dapm_dac, snd_soc_dapm_mixer, snd_soc_dapm_pga,
  73. snd_soc_dapm_adc, snd_soc_dapm_hp, snd_soc_dapm_spk, snd_soc_dapm_post
  74. };
  75. static int dapm_down_seq[] = {
  76. snd_soc_dapm_pre, snd_soc_dapm_adc, snd_soc_dapm_hp, snd_soc_dapm_spk,
  77. snd_soc_dapm_pga, snd_soc_dapm_mixer, snd_soc_dapm_dac, snd_soc_dapm_mic,
  78. snd_soc_dapm_micbias, snd_soc_dapm_mux, snd_soc_dapm_post
  79. };
  80. static int dapm_status = 1;
  81. module_param(dapm_status, int, 0);
  82. MODULE_PARM_DESC(dapm_status, "enable DPM sysfs entries");
  83. /* create a new dapm widget */
  84. static inline struct snd_soc_dapm_widget *dapm_cnew_widget(
  85. const struct snd_soc_dapm_widget *_widget)
  86. {
  87. return kmemdup(_widget, sizeof(*_widget), GFP_KERNEL);
  88. }
  89. /* set up initial codec paths */
  90. static void dapm_set_path_status(struct snd_soc_dapm_widget *w,
  91. struct snd_soc_dapm_path *p, int i)
  92. {
  93. switch (w->id) {
  94. case snd_soc_dapm_switch:
  95. case snd_soc_dapm_mixer: {
  96. int val;
  97. int reg = w->kcontrols[i].private_value & 0xff;
  98. int shift = (w->kcontrols[i].private_value >> 8) & 0x0f;
  99. int mask = (w->kcontrols[i].private_value >> 16) & 0xff;
  100. int invert = (w->kcontrols[i].private_value >> 24) & 0x01;
  101. val = snd_soc_read(w->codec, reg);
  102. val = (val >> shift) & mask;
  103. if ((invert && !val) || (!invert && val))
  104. p->connect = 1;
  105. else
  106. p->connect = 0;
  107. }
  108. break;
  109. case snd_soc_dapm_mux: {
  110. struct soc_enum *e = (struct soc_enum *)w->kcontrols[i].private_value;
  111. int val, item, bitmask;
  112. for (bitmask = 1; bitmask < e->mask; bitmask <<= 1)
  113. ;
  114. val = snd_soc_read(w->codec, e->reg);
  115. item = (val >> e->shift_l) & (bitmask - 1);
  116. p->connect = 0;
  117. for (i = 0; i < e->mask; i++) {
  118. if (!(strcmp(p->name, e->texts[i])) && item == i)
  119. p->connect = 1;
  120. }
  121. }
  122. break;
  123. /* does not effect routing - always connected */
  124. case snd_soc_dapm_pga:
  125. case snd_soc_dapm_output:
  126. case snd_soc_dapm_adc:
  127. case snd_soc_dapm_input:
  128. case snd_soc_dapm_dac:
  129. case snd_soc_dapm_micbias:
  130. case snd_soc_dapm_vmid:
  131. p->connect = 1;
  132. break;
  133. /* does effect routing - dynamically connected */
  134. case snd_soc_dapm_hp:
  135. case snd_soc_dapm_mic:
  136. case snd_soc_dapm_spk:
  137. case snd_soc_dapm_line:
  138. case snd_soc_dapm_pre:
  139. case snd_soc_dapm_post:
  140. p->connect = 0;
  141. break;
  142. }
  143. }
  144. /* connect mux widget to it's interconnecting audio paths */
  145. static int dapm_connect_mux(struct snd_soc_codec *codec,
  146. struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest,
  147. struct snd_soc_dapm_path *path, const char *control_name,
  148. const struct snd_kcontrol_new *kcontrol)
  149. {
  150. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  151. int i;
  152. for (i = 0; i < e->mask; i++) {
  153. if (!(strcmp(control_name, e->texts[i]))) {
  154. list_add(&path->list, &codec->dapm_paths);
  155. list_add(&path->list_sink, &dest->sources);
  156. list_add(&path->list_source, &src->sinks);
  157. path->name = (char*)e->texts[i];
  158. dapm_set_path_status(dest, path, 0);
  159. return 0;
  160. }
  161. }
  162. return -ENODEV;
  163. }
  164. /* connect mixer widget to it's interconnecting audio paths */
  165. static int dapm_connect_mixer(struct snd_soc_codec *codec,
  166. struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest,
  167. struct snd_soc_dapm_path *path, const char *control_name)
  168. {
  169. int i;
  170. /* search for mixer kcontrol */
  171. for (i = 0; i < dest->num_kcontrols; i++) {
  172. if (!strcmp(control_name, dest->kcontrols[i].name)) {
  173. list_add(&path->list, &codec->dapm_paths);
  174. list_add(&path->list_sink, &dest->sources);
  175. list_add(&path->list_source, &src->sinks);
  176. path->name = dest->kcontrols[i].name;
  177. dapm_set_path_status(dest, path, i);
  178. return 0;
  179. }
  180. }
  181. return -ENODEV;
  182. }
  183. /* update dapm codec register bits */
  184. static int dapm_update_bits(struct snd_soc_dapm_widget *widget)
  185. {
  186. int change, power;
  187. unsigned short old, new;
  188. struct snd_soc_codec *codec = widget->codec;
  189. /* check for valid widgets */
  190. if (widget->reg < 0 || widget->id == snd_soc_dapm_input ||
  191. widget->id == snd_soc_dapm_output ||
  192. widget->id == snd_soc_dapm_hp ||
  193. widget->id == snd_soc_dapm_mic ||
  194. widget->id == snd_soc_dapm_line ||
  195. widget->id == snd_soc_dapm_spk)
  196. return 0;
  197. power = widget->power;
  198. if (widget->invert)
  199. power = (power ? 0:1);
  200. old = snd_soc_read(codec, widget->reg);
  201. new = (old & ~(0x1 << widget->shift)) | (power << widget->shift);
  202. change = old != new;
  203. if (change) {
  204. pop_dbg("pop test %s : %s in %d ms\n", widget->name,
  205. widget->power ? "on" : "off", POP_TIME);
  206. snd_soc_write(codec, widget->reg, new);
  207. pop_wait(POP_TIME);
  208. }
  209. dbg("reg old %x new %x change %d\n", old, new, change);
  210. return change;
  211. }
  212. /* ramps the volume up or down to minimise pops before or after a
  213. * DAPM power event */
  214. static int dapm_set_pga(struct snd_soc_dapm_widget *widget, int power)
  215. {
  216. const struct snd_kcontrol_new *k = widget->kcontrols;
  217. if (widget->muted && !power)
  218. return 0;
  219. if (!widget->muted && power)
  220. return 0;
  221. if (widget->num_kcontrols && k) {
  222. int reg = k->private_value & 0xff;
  223. int shift = (k->private_value >> 8) & 0x0f;
  224. int mask = (k->private_value >> 16) & 0xff;
  225. int invert = (k->private_value >> 24) & 0x01;
  226. if (power) {
  227. int i;
  228. /* power up has happended, increase volume to last level */
  229. if (invert) {
  230. for (i = mask; i > widget->saved_value; i--)
  231. snd_soc_update_bits(widget->codec, reg, mask, i);
  232. } else {
  233. for (i = 0; i < widget->saved_value; i++)
  234. snd_soc_update_bits(widget->codec, reg, mask, i);
  235. }
  236. widget->muted = 0;
  237. } else {
  238. /* power down is about to occur, decrease volume to mute */
  239. int val = snd_soc_read(widget->codec, reg);
  240. int i = widget->saved_value = (val >> shift) & mask;
  241. if (invert) {
  242. for (; i < mask; i++)
  243. snd_soc_update_bits(widget->codec, reg, mask, i);
  244. } else {
  245. for (; i > 0; i--)
  246. snd_soc_update_bits(widget->codec, reg, mask, i);
  247. }
  248. widget->muted = 1;
  249. }
  250. }
  251. return 0;
  252. }
  253. /* create new dapm mixer control */
  254. static int dapm_new_mixer(struct snd_soc_codec *codec,
  255. struct snd_soc_dapm_widget *w)
  256. {
  257. int i, ret = 0;
  258. char name[32];
  259. struct snd_soc_dapm_path *path;
  260. /* add kcontrol */
  261. for (i = 0; i < w->num_kcontrols; i++) {
  262. /* match name */
  263. list_for_each_entry(path, &w->sources, list_sink) {
  264. /* mixer/mux paths name must match control name */
  265. if (path->name != (char*)w->kcontrols[i].name)
  266. continue;
  267. /* add dapm control with long name */
  268. snprintf(name, 32, "%s %s", w->name, w->kcontrols[i].name);
  269. path->long_name = kstrdup (name, GFP_KERNEL);
  270. if (path->long_name == NULL)
  271. return -ENOMEM;
  272. path->kcontrol = snd_soc_cnew(&w->kcontrols[i], w,
  273. path->long_name);
  274. ret = snd_ctl_add(codec->card, path->kcontrol);
  275. if (ret < 0) {
  276. printk(KERN_ERR "asoc: failed to add dapm kcontrol %s\n",
  277. path->long_name);
  278. kfree(path->long_name);
  279. path->long_name = NULL;
  280. return ret;
  281. }
  282. }
  283. }
  284. return ret;
  285. }
  286. /* create new dapm mux control */
  287. static int dapm_new_mux(struct snd_soc_codec *codec,
  288. struct snd_soc_dapm_widget *w)
  289. {
  290. struct snd_soc_dapm_path *path = NULL;
  291. struct snd_kcontrol *kcontrol;
  292. int ret = 0;
  293. if (!w->num_kcontrols) {
  294. printk(KERN_ERR "asoc: mux %s has no controls\n", w->name);
  295. return -EINVAL;
  296. }
  297. kcontrol = snd_soc_cnew(&w->kcontrols[0], w, w->name);
  298. ret = snd_ctl_add(codec->card, kcontrol);
  299. if (ret < 0)
  300. goto err;
  301. list_for_each_entry(path, &w->sources, list_sink)
  302. path->kcontrol = kcontrol;
  303. return ret;
  304. err:
  305. printk(KERN_ERR "asoc: failed to add kcontrol %s\n", w->name);
  306. return ret;
  307. }
  308. /* create new dapm volume control */
  309. static int dapm_new_pga(struct snd_soc_codec *codec,
  310. struct snd_soc_dapm_widget *w)
  311. {
  312. struct snd_kcontrol *kcontrol;
  313. int ret = 0;
  314. if (!w->num_kcontrols)
  315. return -EINVAL;
  316. kcontrol = snd_soc_cnew(&w->kcontrols[0], w, w->name);
  317. ret = snd_ctl_add(codec->card, kcontrol);
  318. if (ret < 0) {
  319. printk(KERN_ERR "asoc: failed to add kcontrol %s\n", w->name);
  320. return ret;
  321. }
  322. return ret;
  323. }
  324. /* reset 'walked' bit for each dapm path */
  325. static inline void dapm_clear_walk(struct snd_soc_codec *codec)
  326. {
  327. struct snd_soc_dapm_path *p;
  328. list_for_each_entry(p, &codec->dapm_paths, list)
  329. p->walked = 0;
  330. }
  331. /*
  332. * Recursively check for a completed path to an active or physically connected
  333. * output widget. Returns number of complete paths.
  334. */
  335. static int is_connected_output_ep(struct snd_soc_dapm_widget *widget)
  336. {
  337. struct snd_soc_dapm_path *path;
  338. int con = 0;
  339. if (widget->id == snd_soc_dapm_adc && widget->active)
  340. return 1;
  341. if (widget->connected) {
  342. /* connected pin ? */
  343. if (widget->id == snd_soc_dapm_output && !widget->ext)
  344. return 1;
  345. /* connected jack or spk ? */
  346. if (widget->id == snd_soc_dapm_hp || widget->id == snd_soc_dapm_spk ||
  347. widget->id == snd_soc_dapm_line)
  348. return 1;
  349. }
  350. list_for_each_entry(path, &widget->sinks, list_source) {
  351. if (path->walked)
  352. continue;
  353. if (path->sink && path->connect) {
  354. path->walked = 1;
  355. con += is_connected_output_ep(path->sink);
  356. }
  357. }
  358. return con;
  359. }
  360. /*
  361. * Recursively check for a completed path to an active or physically connected
  362. * input widget. Returns number of complete paths.
  363. */
  364. static int is_connected_input_ep(struct snd_soc_dapm_widget *widget)
  365. {
  366. struct snd_soc_dapm_path *path;
  367. int con = 0;
  368. /* active stream ? */
  369. if (widget->id == snd_soc_dapm_dac && widget->active)
  370. return 1;
  371. if (widget->connected) {
  372. /* connected pin ? */
  373. if (widget->id == snd_soc_dapm_input && !widget->ext)
  374. return 1;
  375. /* connected VMID/Bias for lower pops */
  376. if (widget->id == snd_soc_dapm_vmid)
  377. return 1;
  378. /* connected jack ? */
  379. if (widget->id == snd_soc_dapm_mic || widget->id == snd_soc_dapm_line)
  380. return 1;
  381. }
  382. list_for_each_entry(path, &widget->sources, list_sink) {
  383. if (path->walked)
  384. continue;
  385. if (path->source && path->connect) {
  386. path->walked = 1;
  387. con += is_connected_input_ep(path->source);
  388. }
  389. }
  390. return con;
  391. }
  392. /*
  393. * Scan each dapm widget for complete audio path.
  394. * A complete path is a route that has valid endpoints i.e.:-
  395. *
  396. * o DAC to output pin.
  397. * o Input Pin to ADC.
  398. * o Input pin to Output pin (bypass, sidetone)
  399. * o DAC to ADC (loopback).
  400. */
  401. static int dapm_power_widgets(struct snd_soc_codec *codec, int event)
  402. {
  403. struct snd_soc_dapm_widget *w;
  404. int in, out, i, c = 1, *seq = NULL, ret = 0, power_change, power;
  405. /* do we have a sequenced stream event */
  406. if (event == SND_SOC_DAPM_STREAM_START) {
  407. c = ARRAY_SIZE(dapm_up_seq);
  408. seq = dapm_up_seq;
  409. } else if (event == SND_SOC_DAPM_STREAM_STOP) {
  410. c = ARRAY_SIZE(dapm_down_seq);
  411. seq = dapm_down_seq;
  412. }
  413. for(i = 0; i < c; i++) {
  414. list_for_each_entry(w, &codec->dapm_widgets, list) {
  415. /* is widget in stream order */
  416. if (seq && seq[i] && w->id != seq[i])
  417. continue;
  418. /* vmid - no action */
  419. if (w->id == snd_soc_dapm_vmid)
  420. continue;
  421. /* active ADC */
  422. if (w->id == snd_soc_dapm_adc && w->active) {
  423. in = is_connected_input_ep(w);
  424. dapm_clear_walk(w->codec);
  425. w->power = (in != 0) ? 1 : 0;
  426. dapm_update_bits(w);
  427. continue;
  428. }
  429. /* active DAC */
  430. if (w->id == snd_soc_dapm_dac && w->active) {
  431. out = is_connected_output_ep(w);
  432. dapm_clear_walk(w->codec);
  433. w->power = (out != 0) ? 1 : 0;
  434. dapm_update_bits(w);
  435. continue;
  436. }
  437. /* programmable gain/attenuation */
  438. if (w->id == snd_soc_dapm_pga) {
  439. int on;
  440. in = is_connected_input_ep(w);
  441. dapm_clear_walk(w->codec);
  442. out = is_connected_output_ep(w);
  443. dapm_clear_walk(w->codec);
  444. w->power = on = (out != 0 && in != 0) ? 1 : 0;
  445. if (!on)
  446. dapm_set_pga(w, on); /* lower volume to reduce pops */
  447. dapm_update_bits(w);
  448. if (on)
  449. dapm_set_pga(w, on); /* restore volume from zero */
  450. continue;
  451. }
  452. /* pre and post event widgets */
  453. if (w->id == snd_soc_dapm_pre) {
  454. if (!w->event)
  455. continue;
  456. if (event == SND_SOC_DAPM_STREAM_START) {
  457. ret = w->event(w, SND_SOC_DAPM_PRE_PMU);
  458. if (ret < 0)
  459. return ret;
  460. } else if (event == SND_SOC_DAPM_STREAM_STOP) {
  461. ret = w->event(w, SND_SOC_DAPM_PRE_PMD);
  462. if (ret < 0)
  463. return ret;
  464. }
  465. continue;
  466. }
  467. if (w->id == snd_soc_dapm_post) {
  468. if (!w->event)
  469. continue;
  470. if (event == SND_SOC_DAPM_STREAM_START) {
  471. ret = w->event(w, SND_SOC_DAPM_POST_PMU);
  472. if (ret < 0)
  473. return ret;
  474. } else if (event == SND_SOC_DAPM_STREAM_STOP) {
  475. ret = w->event(w, SND_SOC_DAPM_POST_PMD);
  476. if (ret < 0)
  477. return ret;
  478. }
  479. continue;
  480. }
  481. /* all other widgets */
  482. in = is_connected_input_ep(w);
  483. dapm_clear_walk(w->codec);
  484. out = is_connected_output_ep(w);
  485. dapm_clear_walk(w->codec);
  486. power = (out != 0 && in != 0) ? 1 : 0;
  487. power_change = (w->power == power) ? 0: 1;
  488. w->power = power;
  489. /* call any power change event handlers */
  490. if (power_change) {
  491. if (w->event) {
  492. dbg("power %s event for %s flags %x\n",
  493. w->power ? "on" : "off", w->name, w->event_flags);
  494. if (power) {
  495. /* power up event */
  496. if (w->event_flags & SND_SOC_DAPM_PRE_PMU) {
  497. ret = w->event(w, SND_SOC_DAPM_PRE_PMU);
  498. if (ret < 0)
  499. return ret;
  500. }
  501. dapm_update_bits(w);
  502. if (w->event_flags & SND_SOC_DAPM_POST_PMU){
  503. ret = w->event(w, SND_SOC_DAPM_POST_PMU);
  504. if (ret < 0)
  505. return ret;
  506. }
  507. } else {
  508. /* power down event */
  509. if (w->event_flags & SND_SOC_DAPM_PRE_PMD) {
  510. ret = w->event(w, SND_SOC_DAPM_PRE_PMD);
  511. if (ret < 0)
  512. return ret;
  513. }
  514. dapm_update_bits(w);
  515. if (w->event_flags & SND_SOC_DAPM_POST_PMD) {
  516. ret = w->event(w, SND_SOC_DAPM_POST_PMD);
  517. if (ret < 0)
  518. return ret;
  519. }
  520. }
  521. } else
  522. /* no event handler */
  523. dapm_update_bits(w);
  524. }
  525. }
  526. }
  527. return ret;
  528. }
  529. #if DAPM_DEBUG
  530. static void dbg_dump_dapm(struct snd_soc_codec* codec, const char *action)
  531. {
  532. struct snd_soc_dapm_widget *w;
  533. struct snd_soc_dapm_path *p = NULL;
  534. int in, out;
  535. printk("DAPM %s %s\n", codec->name, action);
  536. list_for_each_entry(w, &codec->dapm_widgets, list) {
  537. /* only display widgets that effect routing */
  538. switch (w->id) {
  539. case snd_soc_dapm_pre:
  540. case snd_soc_dapm_post:
  541. case snd_soc_dapm_vmid:
  542. continue;
  543. case snd_soc_dapm_mux:
  544. case snd_soc_dapm_output:
  545. case snd_soc_dapm_input:
  546. case snd_soc_dapm_switch:
  547. case snd_soc_dapm_hp:
  548. case snd_soc_dapm_mic:
  549. case snd_soc_dapm_spk:
  550. case snd_soc_dapm_line:
  551. case snd_soc_dapm_micbias:
  552. case snd_soc_dapm_dac:
  553. case snd_soc_dapm_adc:
  554. case snd_soc_dapm_pga:
  555. case snd_soc_dapm_mixer:
  556. if (w->name) {
  557. in = is_connected_input_ep(w);
  558. dapm_clear_walk(w->codec);
  559. out = is_connected_output_ep(w);
  560. dapm_clear_walk(w->codec);
  561. printk("%s: %s in %d out %d\n", w->name,
  562. w->power ? "On":"Off",in, out);
  563. list_for_each_entry(p, &w->sources, list_sink) {
  564. if (p->connect)
  565. printk(" in %s %s\n", p->name ? p->name : "static",
  566. p->source->name);
  567. }
  568. list_for_each_entry(p, &w->sinks, list_source) {
  569. if (p->connect)
  570. printk(" out %s %s\n", p->name ? p->name : "static",
  571. p->sink->name);
  572. }
  573. }
  574. break;
  575. }
  576. }
  577. }
  578. #endif
  579. /* test and update the power status of a mux widget */
  580. static int dapm_mux_update_power(struct snd_soc_dapm_widget *widget,
  581. struct snd_kcontrol *kcontrol, int mask,
  582. int val, struct soc_enum* e)
  583. {
  584. struct snd_soc_dapm_path *path;
  585. int found = 0;
  586. if (widget->id != snd_soc_dapm_mux)
  587. return -ENODEV;
  588. if (!snd_soc_test_bits(widget->codec, e->reg, mask, val))
  589. return 0;
  590. /* find dapm widget path assoc with kcontrol */
  591. list_for_each_entry(path, &widget->codec->dapm_paths, list) {
  592. if (path->kcontrol != kcontrol)
  593. continue;
  594. if (!path->name || ! e->texts[val])
  595. continue;
  596. found = 1;
  597. /* we now need to match the string in the enum to the path */
  598. if (!(strcmp(path->name, e->texts[val])))
  599. path->connect = 1; /* new connection */
  600. else
  601. path->connect = 0; /* old connection must be powered down */
  602. }
  603. if (found)
  604. dapm_power_widgets(widget->codec, SND_SOC_DAPM_STREAM_NOP);
  605. return 0;
  606. }
  607. /* test and update the power status of a mixer widget */
  608. static int dapm_mixer_update_power(struct snd_soc_dapm_widget *widget,
  609. struct snd_kcontrol *kcontrol, int reg,
  610. int val_mask, int val, int invert)
  611. {
  612. struct snd_soc_dapm_path *path;
  613. int found = 0;
  614. if (widget->id != snd_soc_dapm_mixer)
  615. return -ENODEV;
  616. if (!snd_soc_test_bits(widget->codec, reg, val_mask, val))
  617. return 0;
  618. /* find dapm widget path assoc with kcontrol */
  619. list_for_each_entry(path, &widget->codec->dapm_paths, list) {
  620. if (path->kcontrol != kcontrol)
  621. continue;
  622. /* found, now check type */
  623. found = 1;
  624. if (val)
  625. /* new connection */
  626. path->connect = invert ? 0:1;
  627. else
  628. /* old connection must be powered down */
  629. path->connect = invert ? 1:0;
  630. break;
  631. }
  632. if (found)
  633. dapm_power_widgets(widget->codec, SND_SOC_DAPM_STREAM_NOP);
  634. return 0;
  635. }
  636. /* show dapm widget status in sys fs */
  637. static ssize_t dapm_widget_show(struct device *dev,
  638. struct device_attribute *attr, char *buf)
  639. {
  640. struct snd_soc_device *devdata = dev_get_drvdata(dev);
  641. struct snd_soc_codec *codec = devdata->codec;
  642. struct snd_soc_dapm_widget *w;
  643. int count = 0;
  644. char *state = "not set";
  645. list_for_each_entry(w, &codec->dapm_widgets, list) {
  646. /* only display widgets that burnm power */
  647. switch (w->id) {
  648. case snd_soc_dapm_hp:
  649. case snd_soc_dapm_mic:
  650. case snd_soc_dapm_spk:
  651. case snd_soc_dapm_line:
  652. case snd_soc_dapm_micbias:
  653. case snd_soc_dapm_dac:
  654. case snd_soc_dapm_adc:
  655. case snd_soc_dapm_pga:
  656. case snd_soc_dapm_mixer:
  657. if (w->name)
  658. count += sprintf(buf + count, "%s: %s\n",
  659. w->name, w->power ? "On":"Off");
  660. break;
  661. default:
  662. break;
  663. }
  664. }
  665. switch(codec->dapm_state){
  666. case SNDRV_CTL_POWER_D0:
  667. state = "D0";
  668. break;
  669. case SNDRV_CTL_POWER_D1:
  670. state = "D1";
  671. break;
  672. case SNDRV_CTL_POWER_D2:
  673. state = "D2";
  674. break;
  675. case SNDRV_CTL_POWER_D3hot:
  676. state = "D3hot";
  677. break;
  678. case SNDRV_CTL_POWER_D3cold:
  679. state = "D3cold";
  680. break;
  681. }
  682. count += sprintf(buf + count, "PM State: %s\n", state);
  683. return count;
  684. }
  685. static DEVICE_ATTR(dapm_widget, 0444, dapm_widget_show, NULL);
  686. int snd_soc_dapm_sys_add(struct device *dev)
  687. {
  688. int ret = 0;
  689. if (dapm_status)
  690. ret = device_create_file(dev, &dev_attr_dapm_widget);
  691. return ret;
  692. }
  693. static void snd_soc_dapm_sys_remove(struct device *dev)
  694. {
  695. if (dapm_status)
  696. device_remove_file(dev, &dev_attr_dapm_widget);
  697. }
  698. /* free all dapm widgets and resources */
  699. static void dapm_free_widgets(struct snd_soc_codec *codec)
  700. {
  701. struct snd_soc_dapm_widget *w, *next_w;
  702. struct snd_soc_dapm_path *p, *next_p;
  703. list_for_each_entry_safe(w, next_w, &codec->dapm_widgets, list) {
  704. list_del(&w->list);
  705. kfree(w);
  706. }
  707. list_for_each_entry_safe(p, next_p, &codec->dapm_paths, list) {
  708. list_del(&p->list);
  709. kfree(p->long_name);
  710. kfree(p);
  711. }
  712. }
  713. /**
  714. * snd_soc_dapm_sync_endpoints - scan and power dapm paths
  715. * @codec: audio codec
  716. *
  717. * Walks all dapm audio paths and powers widgets according to their
  718. * stream or path usage.
  719. *
  720. * Returns 0 for success.
  721. */
  722. int snd_soc_dapm_sync_endpoints(struct snd_soc_codec *codec)
  723. {
  724. return dapm_power_widgets(codec, SND_SOC_DAPM_STREAM_NOP);
  725. }
  726. EXPORT_SYMBOL_GPL(snd_soc_dapm_sync_endpoints);
  727. /**
  728. * snd_soc_dapm_connect_input - connect dapm widgets
  729. * @codec: audio codec
  730. * @sink: name of target widget
  731. * @control: mixer control name
  732. * @source: name of source name
  733. *
  734. * Connects 2 dapm widgets together via a named audio path. The sink is
  735. * the widget receiving the audio signal, whilst the source is the sender
  736. * of the audio signal.
  737. *
  738. * Returns 0 for success else error.
  739. */
  740. int snd_soc_dapm_connect_input(struct snd_soc_codec *codec, const char *sink,
  741. const char * control, const char *source)
  742. {
  743. struct snd_soc_dapm_path *path;
  744. struct snd_soc_dapm_widget *wsource = NULL, *wsink = NULL, *w;
  745. int ret = 0;
  746. /* find src and dest widgets */
  747. list_for_each_entry(w, &codec->dapm_widgets, list) {
  748. if (!wsink && !(strcmp(w->name, sink))) {
  749. wsink = w;
  750. continue;
  751. }
  752. if (!wsource && !(strcmp(w->name, source))) {
  753. wsource = w;
  754. }
  755. }
  756. if (wsource == NULL || wsink == NULL)
  757. return -ENODEV;
  758. path = kzalloc(sizeof(struct snd_soc_dapm_path), GFP_KERNEL);
  759. if (!path)
  760. return -ENOMEM;
  761. path->source = wsource;
  762. path->sink = wsink;
  763. INIT_LIST_HEAD(&path->list);
  764. INIT_LIST_HEAD(&path->list_source);
  765. INIT_LIST_HEAD(&path->list_sink);
  766. /* check for external widgets */
  767. if (wsink->id == snd_soc_dapm_input) {
  768. if (wsource->id == snd_soc_dapm_micbias ||
  769. wsource->id == snd_soc_dapm_mic ||
  770. wsink->id == snd_soc_dapm_line)
  771. wsink->ext = 1;
  772. }
  773. if (wsource->id == snd_soc_dapm_output) {
  774. if (wsink->id == snd_soc_dapm_spk ||
  775. wsink->id == snd_soc_dapm_hp ||
  776. wsink->id == snd_soc_dapm_line)
  777. wsource->ext = 1;
  778. }
  779. /* connect static paths */
  780. if (control == NULL) {
  781. list_add(&path->list, &codec->dapm_paths);
  782. list_add(&path->list_sink, &wsink->sources);
  783. list_add(&path->list_source, &wsource->sinks);
  784. path->connect = 1;
  785. return 0;
  786. }
  787. /* connect dynamic paths */
  788. switch(wsink->id) {
  789. case snd_soc_dapm_adc:
  790. case snd_soc_dapm_dac:
  791. case snd_soc_dapm_pga:
  792. case snd_soc_dapm_input:
  793. case snd_soc_dapm_output:
  794. case snd_soc_dapm_micbias:
  795. case snd_soc_dapm_vmid:
  796. case snd_soc_dapm_pre:
  797. case snd_soc_dapm_post:
  798. list_add(&path->list, &codec->dapm_paths);
  799. list_add(&path->list_sink, &wsink->sources);
  800. list_add(&path->list_source, &wsource->sinks);
  801. path->connect = 1;
  802. return 0;
  803. case snd_soc_dapm_mux:
  804. ret = dapm_connect_mux(codec, wsource, wsink, path, control,
  805. &wsink->kcontrols[0]);
  806. if (ret != 0)
  807. goto err;
  808. break;
  809. case snd_soc_dapm_switch:
  810. case snd_soc_dapm_mixer:
  811. ret = dapm_connect_mixer(codec, wsource, wsink, path, control);
  812. if (ret != 0)
  813. goto err;
  814. break;
  815. case snd_soc_dapm_hp:
  816. case snd_soc_dapm_mic:
  817. case snd_soc_dapm_line:
  818. case snd_soc_dapm_spk:
  819. list_add(&path->list, &codec->dapm_paths);
  820. list_add(&path->list_sink, &wsink->sources);
  821. list_add(&path->list_source, &wsource->sinks);
  822. path->connect = 0;
  823. return 0;
  824. }
  825. return 0;
  826. err:
  827. printk(KERN_WARNING "asoc: no dapm match for %s --> %s --> %s\n", source,
  828. control, sink);
  829. kfree(path);
  830. return ret;
  831. }
  832. EXPORT_SYMBOL_GPL(snd_soc_dapm_connect_input);
  833. /**
  834. * snd_soc_dapm_new_widgets - add new dapm widgets
  835. * @codec: audio codec
  836. *
  837. * Checks the codec for any new dapm widgets and creates them if found.
  838. *
  839. * Returns 0 for success.
  840. */
  841. int snd_soc_dapm_new_widgets(struct snd_soc_codec *codec)
  842. {
  843. struct snd_soc_dapm_widget *w;
  844. mutex_lock(&codec->mutex);
  845. list_for_each_entry(w, &codec->dapm_widgets, list)
  846. {
  847. if (w->new)
  848. continue;
  849. switch(w->id) {
  850. case snd_soc_dapm_switch:
  851. case snd_soc_dapm_mixer:
  852. dapm_new_mixer(codec, w);
  853. break;
  854. case snd_soc_dapm_mux:
  855. dapm_new_mux(codec, w);
  856. break;
  857. case snd_soc_dapm_adc:
  858. case snd_soc_dapm_dac:
  859. case snd_soc_dapm_pga:
  860. dapm_new_pga(codec, w);
  861. break;
  862. case snd_soc_dapm_input:
  863. case snd_soc_dapm_output:
  864. case snd_soc_dapm_micbias:
  865. case snd_soc_dapm_spk:
  866. case snd_soc_dapm_hp:
  867. case snd_soc_dapm_mic:
  868. case snd_soc_dapm_line:
  869. case snd_soc_dapm_vmid:
  870. case snd_soc_dapm_pre:
  871. case snd_soc_dapm_post:
  872. break;
  873. }
  874. w->new = 1;
  875. }
  876. dapm_power_widgets(codec, SND_SOC_DAPM_STREAM_NOP);
  877. mutex_unlock(&codec->mutex);
  878. return 0;
  879. }
  880. EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets);
  881. /**
  882. * snd_soc_dapm_get_volsw - dapm mixer get callback
  883. * @kcontrol: mixer control
  884. * @uinfo: control element information
  885. *
  886. * Callback to get the value of a dapm mixer control.
  887. *
  888. * Returns 0 for success.
  889. */
  890. int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol,
  891. struct snd_ctl_elem_value *ucontrol)
  892. {
  893. struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
  894. int reg = kcontrol->private_value & 0xff;
  895. int shift = (kcontrol->private_value >> 8) & 0x0f;
  896. int rshift = (kcontrol->private_value >> 12) & 0x0f;
  897. int mask = (kcontrol->private_value >> 16) & 0xff;
  898. int invert = (kcontrol->private_value >> 24) & 0x01;
  899. /* return the saved value if we are powered down */
  900. if (widget->id == snd_soc_dapm_pga && !widget->power) {
  901. ucontrol->value.integer.value[0] = widget->saved_value;
  902. return 0;
  903. }
  904. ucontrol->value.integer.value[0] =
  905. (snd_soc_read(widget->codec, reg) >> shift) & mask;
  906. if (shift != rshift)
  907. ucontrol->value.integer.value[1] =
  908. (snd_soc_read(widget->codec, reg) >> rshift) & mask;
  909. if (invert) {
  910. ucontrol->value.integer.value[0] =
  911. mask - ucontrol->value.integer.value[0];
  912. if (shift != rshift)
  913. ucontrol->value.integer.value[1] =
  914. mask - ucontrol->value.integer.value[1];
  915. }
  916. return 0;
  917. }
  918. EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw);
  919. /**
  920. * snd_soc_dapm_put_volsw - dapm mixer set callback
  921. * @kcontrol: mixer control
  922. * @uinfo: control element information
  923. *
  924. * Callback to set the value of a dapm mixer control.
  925. *
  926. * Returns 0 for success.
  927. */
  928. int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol,
  929. struct snd_ctl_elem_value *ucontrol)
  930. {
  931. struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
  932. int reg = kcontrol->private_value & 0xff;
  933. int shift = (kcontrol->private_value >> 8) & 0x0f;
  934. int rshift = (kcontrol->private_value >> 12) & 0x0f;
  935. int mask = (kcontrol->private_value >> 16) & 0xff;
  936. int invert = (kcontrol->private_value >> 24) & 0x01;
  937. unsigned short val, val2, val_mask;
  938. int ret;
  939. val = (ucontrol->value.integer.value[0] & mask);
  940. if (invert)
  941. val = mask - val;
  942. val_mask = mask << shift;
  943. val = val << shift;
  944. if (shift != rshift) {
  945. val2 = (ucontrol->value.integer.value[1] & mask);
  946. if (invert)
  947. val2 = mask - val2;
  948. val_mask |= mask << rshift;
  949. val |= val2 << rshift;
  950. }
  951. mutex_lock(&widget->codec->mutex);
  952. widget->value = val;
  953. /* save volume value if the widget is powered down */
  954. if (widget->id == snd_soc_dapm_pga && !widget->power) {
  955. widget->saved_value = val;
  956. mutex_unlock(&widget->codec->mutex);
  957. return 1;
  958. }
  959. dapm_mixer_update_power(widget, kcontrol, reg, val_mask, val, invert);
  960. if (widget->event) {
  961. if (widget->event_flags & SND_SOC_DAPM_PRE_REG) {
  962. ret = widget->event(widget, SND_SOC_DAPM_PRE_REG);
  963. if (ret < 0)
  964. goto out;
  965. }
  966. ret = snd_soc_update_bits(widget->codec, reg, val_mask, val);
  967. if (widget->event_flags & SND_SOC_DAPM_POST_REG)
  968. ret = widget->event(widget, SND_SOC_DAPM_POST_REG);
  969. } else
  970. ret = snd_soc_update_bits(widget->codec, reg, val_mask, val);
  971. out:
  972. mutex_unlock(&widget->codec->mutex);
  973. return ret;
  974. }
  975. EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw);
  976. /**
  977. * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback
  978. * @kcontrol: mixer control
  979. * @uinfo: control element information
  980. *
  981. * Callback to get the value of a dapm enumerated double mixer control.
  982. *
  983. * Returns 0 for success.
  984. */
  985. int snd_soc_dapm_get_enum_double(struct snd_kcontrol *kcontrol,
  986. struct snd_ctl_elem_value *ucontrol)
  987. {
  988. struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
  989. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  990. unsigned short val, bitmask;
  991. for (bitmask = 1; bitmask < e->mask; bitmask <<= 1)
  992. ;
  993. val = snd_soc_read(widget->codec, e->reg);
  994. ucontrol->value.enumerated.item[0] = (val >> e->shift_l) & (bitmask - 1);
  995. if (e->shift_l != e->shift_r)
  996. ucontrol->value.enumerated.item[1] =
  997. (val >> e->shift_r) & (bitmask - 1);
  998. return 0;
  999. }
  1000. EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double);
  1001. /**
  1002. * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback
  1003. * @kcontrol: mixer control
  1004. * @uinfo: control element information
  1005. *
  1006. * Callback to set the value of a dapm enumerated double mixer control.
  1007. *
  1008. * Returns 0 for success.
  1009. */
  1010. int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol,
  1011. struct snd_ctl_elem_value *ucontrol)
  1012. {
  1013. struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
  1014. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  1015. unsigned short val, mux;
  1016. unsigned short mask, bitmask;
  1017. int ret = 0;
  1018. for (bitmask = 1; bitmask < e->mask; bitmask <<= 1)
  1019. ;
  1020. if (ucontrol->value.enumerated.item[0] > e->mask - 1)
  1021. return -EINVAL;
  1022. mux = ucontrol->value.enumerated.item[0];
  1023. val = mux << e->shift_l;
  1024. mask = (bitmask - 1) << e->shift_l;
  1025. if (e->shift_l != e->shift_r) {
  1026. if (ucontrol->value.enumerated.item[1] > e->mask - 1)
  1027. return -EINVAL;
  1028. val |= ucontrol->value.enumerated.item[1] << e->shift_r;
  1029. mask |= (bitmask - 1) << e->shift_r;
  1030. }
  1031. mutex_lock(&widget->codec->mutex);
  1032. widget->value = val;
  1033. dapm_mux_update_power(widget, kcontrol, mask, mux, e);
  1034. if (widget->event) {
  1035. if (widget->event_flags & SND_SOC_DAPM_PRE_REG) {
  1036. ret = widget->event(widget, SND_SOC_DAPM_PRE_REG);
  1037. if (ret < 0)
  1038. goto out;
  1039. }
  1040. ret = snd_soc_update_bits(widget->codec, e->reg, mask, val);
  1041. if (widget->event_flags & SND_SOC_DAPM_POST_REG)
  1042. ret = widget->event(widget, SND_SOC_DAPM_POST_REG);
  1043. } else
  1044. ret = snd_soc_update_bits(widget->codec, e->reg, mask, val);
  1045. out:
  1046. mutex_unlock(&widget->codec->mutex);
  1047. return ret;
  1048. }
  1049. EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double);
  1050. /**
  1051. * snd_soc_dapm_new_control - create new dapm control
  1052. * @codec: audio codec
  1053. * @widget: widget template
  1054. *
  1055. * Creates a new dapm control based upon the template.
  1056. *
  1057. * Returns 0 for success else error.
  1058. */
  1059. int snd_soc_dapm_new_control(struct snd_soc_codec *codec,
  1060. const struct snd_soc_dapm_widget *widget)
  1061. {
  1062. struct snd_soc_dapm_widget *w;
  1063. if ((w = dapm_cnew_widget(widget)) == NULL)
  1064. return -ENOMEM;
  1065. w->codec = codec;
  1066. INIT_LIST_HEAD(&w->sources);
  1067. INIT_LIST_HEAD(&w->sinks);
  1068. INIT_LIST_HEAD(&w->list);
  1069. list_add(&w->list, &codec->dapm_widgets);
  1070. /* machine layer set ups unconnected pins and insertions */
  1071. w->connected = 1;
  1072. return 0;
  1073. }
  1074. EXPORT_SYMBOL_GPL(snd_soc_dapm_new_control);
  1075. /**
  1076. * snd_soc_dapm_stream_event - send a stream event to the dapm core
  1077. * @codec: audio codec
  1078. * @stream: stream name
  1079. * @event: stream event
  1080. *
  1081. * Sends a stream event to the dapm core. The core then makes any
  1082. * necessary widget power changes.
  1083. *
  1084. * Returns 0 for success else error.
  1085. */
  1086. int snd_soc_dapm_stream_event(struct snd_soc_codec *codec,
  1087. char *stream, int event)
  1088. {
  1089. struct snd_soc_dapm_widget *w;
  1090. if (stream == NULL)
  1091. return 0;
  1092. mutex_lock(&codec->mutex);
  1093. list_for_each_entry(w, &codec->dapm_widgets, list)
  1094. {
  1095. if (!w->sname)
  1096. continue;
  1097. dbg("widget %s\n %s stream %s event %d\n", w->name, w->sname,
  1098. stream, event);
  1099. if (strstr(w->sname, stream)) {
  1100. switch(event) {
  1101. case SND_SOC_DAPM_STREAM_START:
  1102. w->active = 1;
  1103. break;
  1104. case SND_SOC_DAPM_STREAM_STOP:
  1105. w->active = 0;
  1106. break;
  1107. case SND_SOC_DAPM_STREAM_SUSPEND:
  1108. if (w->active)
  1109. w->suspend = 1;
  1110. w->active = 0;
  1111. break;
  1112. case SND_SOC_DAPM_STREAM_RESUME:
  1113. if (w->suspend) {
  1114. w->active = 1;
  1115. w->suspend = 0;
  1116. }
  1117. break;
  1118. case SND_SOC_DAPM_STREAM_PAUSE_PUSH:
  1119. break;
  1120. case SND_SOC_DAPM_STREAM_PAUSE_RELEASE:
  1121. break;
  1122. }
  1123. }
  1124. }
  1125. mutex_unlock(&codec->mutex);
  1126. dapm_power_widgets(codec, event);
  1127. dump_dapm(codec, __FUNCTION__);
  1128. return 0;
  1129. }
  1130. EXPORT_SYMBOL_GPL(snd_soc_dapm_stream_event);
  1131. /**
  1132. * snd_soc_dapm_set_endpoint - set audio endpoint status
  1133. * @codec: audio codec
  1134. * @endpoint: audio signal endpoint (or start point)
  1135. * @status: point status
  1136. *
  1137. * Set audio endpoint status - connected or disconnected.
  1138. *
  1139. * Returns 0 for success else error.
  1140. */
  1141. int snd_soc_dapm_set_endpoint(struct snd_soc_codec *codec,
  1142. char *endpoint, int status)
  1143. {
  1144. struct snd_soc_dapm_widget *w;
  1145. list_for_each_entry(w, &codec->dapm_widgets, list) {
  1146. if (!strcmp(w->name, endpoint)) {
  1147. w->connected = status;
  1148. }
  1149. }
  1150. return 0;
  1151. }
  1152. EXPORT_SYMBOL_GPL(snd_soc_dapm_set_endpoint);
  1153. /**
  1154. * snd_soc_dapm_free - free dapm resources
  1155. * @socdev: SoC device
  1156. *
  1157. * Free all dapm widgets and resources.
  1158. */
  1159. void snd_soc_dapm_free(struct snd_soc_device *socdev)
  1160. {
  1161. struct snd_soc_codec *codec = socdev->codec;
  1162. snd_soc_dapm_sys_remove(socdev->dev);
  1163. dapm_free_widgets(codec);
  1164. }
  1165. EXPORT_SYMBOL_GPL(snd_soc_dapm_free);
  1166. /* Module information */
  1167. MODULE_AUTHOR("Liam Girdwood, liam.girdwood@wolfsonmicro.com, www.wolfsonmicro.com");
  1168. MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC");
  1169. MODULE_LICENSE("GPL");