soc-dapm.c 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325
  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 susbsystem 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_uninterruptible(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->id == snd_soc_dapm_output)
  772. wsink->ext = 1;
  773. }
  774. if (wsource->id == snd_soc_dapm_output) {
  775. if (wsink->id == snd_soc_dapm_spk ||
  776. wsink->id == snd_soc_dapm_hp ||
  777. wsink->id == snd_soc_dapm_line ||
  778. wsink->id == snd_soc_dapm_input)
  779. wsource->ext = 1;
  780. }
  781. /* connect static paths */
  782. if (control == NULL) {
  783. list_add(&path->list, &codec->dapm_paths);
  784. list_add(&path->list_sink, &wsink->sources);
  785. list_add(&path->list_source, &wsource->sinks);
  786. path->connect = 1;
  787. return 0;
  788. }
  789. /* connect dynamic paths */
  790. switch(wsink->id) {
  791. case snd_soc_dapm_adc:
  792. case snd_soc_dapm_dac:
  793. case snd_soc_dapm_pga:
  794. case snd_soc_dapm_input:
  795. case snd_soc_dapm_output:
  796. case snd_soc_dapm_micbias:
  797. case snd_soc_dapm_vmid:
  798. case snd_soc_dapm_pre:
  799. case snd_soc_dapm_post:
  800. list_add(&path->list, &codec->dapm_paths);
  801. list_add(&path->list_sink, &wsink->sources);
  802. list_add(&path->list_source, &wsource->sinks);
  803. path->connect = 1;
  804. return 0;
  805. case snd_soc_dapm_mux:
  806. ret = dapm_connect_mux(codec, wsource, wsink, path, control,
  807. &wsink->kcontrols[0]);
  808. if (ret != 0)
  809. goto err;
  810. break;
  811. case snd_soc_dapm_switch:
  812. case snd_soc_dapm_mixer:
  813. ret = dapm_connect_mixer(codec, wsource, wsink, path, control);
  814. if (ret != 0)
  815. goto err;
  816. break;
  817. case snd_soc_dapm_hp:
  818. case snd_soc_dapm_mic:
  819. case snd_soc_dapm_line:
  820. case snd_soc_dapm_spk:
  821. list_add(&path->list, &codec->dapm_paths);
  822. list_add(&path->list_sink, &wsink->sources);
  823. list_add(&path->list_source, &wsource->sinks);
  824. path->connect = 0;
  825. return 0;
  826. }
  827. return 0;
  828. err:
  829. printk(KERN_WARNING "asoc: no dapm match for %s --> %s --> %s\n", source,
  830. control, sink);
  831. kfree(path);
  832. return ret;
  833. }
  834. EXPORT_SYMBOL_GPL(snd_soc_dapm_connect_input);
  835. /**
  836. * snd_soc_dapm_new_widgets - add new dapm widgets
  837. * @codec: audio codec
  838. *
  839. * Checks the codec for any new dapm widgets and creates them if found.
  840. *
  841. * Returns 0 for success.
  842. */
  843. int snd_soc_dapm_new_widgets(struct snd_soc_codec *codec)
  844. {
  845. struct snd_soc_dapm_widget *w;
  846. mutex_lock(&codec->mutex);
  847. list_for_each_entry(w, &codec->dapm_widgets, list)
  848. {
  849. if (w->new)
  850. continue;
  851. switch(w->id) {
  852. case snd_soc_dapm_switch:
  853. case snd_soc_dapm_mixer:
  854. dapm_new_mixer(codec, w);
  855. break;
  856. case snd_soc_dapm_mux:
  857. dapm_new_mux(codec, w);
  858. break;
  859. case snd_soc_dapm_adc:
  860. case snd_soc_dapm_dac:
  861. case snd_soc_dapm_pga:
  862. dapm_new_pga(codec, w);
  863. break;
  864. case snd_soc_dapm_input:
  865. case snd_soc_dapm_output:
  866. case snd_soc_dapm_micbias:
  867. case snd_soc_dapm_spk:
  868. case snd_soc_dapm_hp:
  869. case snd_soc_dapm_mic:
  870. case snd_soc_dapm_line:
  871. case snd_soc_dapm_vmid:
  872. case snd_soc_dapm_pre:
  873. case snd_soc_dapm_post:
  874. break;
  875. }
  876. w->new = 1;
  877. }
  878. dapm_power_widgets(codec, SND_SOC_DAPM_STREAM_NOP);
  879. mutex_unlock(&codec->mutex);
  880. return 0;
  881. }
  882. EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets);
  883. /**
  884. * snd_soc_dapm_get_volsw - dapm mixer get callback
  885. * @kcontrol: mixer control
  886. * @uinfo: control element information
  887. *
  888. * Callback to get the value of a dapm mixer control.
  889. *
  890. * Returns 0 for success.
  891. */
  892. int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol,
  893. struct snd_ctl_elem_value *ucontrol)
  894. {
  895. struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
  896. int reg = kcontrol->private_value & 0xff;
  897. int shift = (kcontrol->private_value >> 8) & 0x0f;
  898. int rshift = (kcontrol->private_value >> 12) & 0x0f;
  899. int mask = (kcontrol->private_value >> 16) & 0xff;
  900. int invert = (kcontrol->private_value >> 24) & 0x01;
  901. /* return the saved value if we are powered down */
  902. if (widget->id == snd_soc_dapm_pga && !widget->power) {
  903. ucontrol->value.integer.value[0] = widget->saved_value;
  904. return 0;
  905. }
  906. ucontrol->value.integer.value[0] =
  907. (snd_soc_read(widget->codec, reg) >> shift) & mask;
  908. if (shift != rshift)
  909. ucontrol->value.integer.value[1] =
  910. (snd_soc_read(widget->codec, reg) >> rshift) & mask;
  911. if (invert) {
  912. ucontrol->value.integer.value[0] =
  913. mask - ucontrol->value.integer.value[0];
  914. if (shift != rshift)
  915. ucontrol->value.integer.value[1] =
  916. mask - ucontrol->value.integer.value[1];
  917. }
  918. return 0;
  919. }
  920. EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw);
  921. /**
  922. * snd_soc_dapm_put_volsw - dapm mixer set callback
  923. * @kcontrol: mixer control
  924. * @uinfo: control element information
  925. *
  926. * Callback to set the value of a dapm mixer control.
  927. *
  928. * Returns 0 for success.
  929. */
  930. int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol,
  931. struct snd_ctl_elem_value *ucontrol)
  932. {
  933. struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
  934. int reg = kcontrol->private_value & 0xff;
  935. int shift = (kcontrol->private_value >> 8) & 0x0f;
  936. int rshift = (kcontrol->private_value >> 12) & 0x0f;
  937. int mask = (kcontrol->private_value >> 16) & 0xff;
  938. int invert = (kcontrol->private_value >> 24) & 0x01;
  939. unsigned short val, val2, val_mask;
  940. int ret;
  941. val = (ucontrol->value.integer.value[0] & mask);
  942. if (invert)
  943. val = mask - val;
  944. val_mask = mask << shift;
  945. val = val << shift;
  946. if (shift != rshift) {
  947. val2 = (ucontrol->value.integer.value[1] & mask);
  948. if (invert)
  949. val2 = mask - val2;
  950. val_mask |= mask << rshift;
  951. val |= val2 << rshift;
  952. }
  953. mutex_lock(&widget->codec->mutex);
  954. widget->value = val;
  955. /* save volume value if the widget is powered down */
  956. if (widget->id == snd_soc_dapm_pga && !widget->power) {
  957. widget->saved_value = val;
  958. mutex_unlock(&widget->codec->mutex);
  959. return 1;
  960. }
  961. dapm_mixer_update_power(widget, kcontrol, reg, val_mask, val, invert);
  962. if (widget->event) {
  963. if (widget->event_flags & SND_SOC_DAPM_PRE_REG) {
  964. ret = widget->event(widget, SND_SOC_DAPM_PRE_REG);
  965. if (ret < 0)
  966. goto out;
  967. }
  968. ret = snd_soc_update_bits(widget->codec, reg, val_mask, val);
  969. if (widget->event_flags & SND_SOC_DAPM_POST_REG)
  970. ret = widget->event(widget, SND_SOC_DAPM_POST_REG);
  971. } else
  972. ret = snd_soc_update_bits(widget->codec, reg, val_mask, val);
  973. out:
  974. mutex_unlock(&widget->codec->mutex);
  975. return ret;
  976. }
  977. EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw);
  978. /**
  979. * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback
  980. * @kcontrol: mixer control
  981. * @uinfo: control element information
  982. *
  983. * Callback to get the value of a dapm enumerated double mixer control.
  984. *
  985. * Returns 0 for success.
  986. */
  987. int snd_soc_dapm_get_enum_double(struct snd_kcontrol *kcontrol,
  988. struct snd_ctl_elem_value *ucontrol)
  989. {
  990. struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
  991. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  992. unsigned short val, bitmask;
  993. for (bitmask = 1; bitmask < e->mask; bitmask <<= 1)
  994. ;
  995. val = snd_soc_read(widget->codec, e->reg);
  996. ucontrol->value.enumerated.item[0] = (val >> e->shift_l) & (bitmask - 1);
  997. if (e->shift_l != e->shift_r)
  998. ucontrol->value.enumerated.item[1] =
  999. (val >> e->shift_r) & (bitmask - 1);
  1000. return 0;
  1001. }
  1002. EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double);
  1003. /**
  1004. * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback
  1005. * @kcontrol: mixer control
  1006. * @uinfo: control element information
  1007. *
  1008. * Callback to set the value of a dapm enumerated double mixer control.
  1009. *
  1010. * Returns 0 for success.
  1011. */
  1012. int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol,
  1013. struct snd_ctl_elem_value *ucontrol)
  1014. {
  1015. struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
  1016. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  1017. unsigned short val, mux;
  1018. unsigned short mask, bitmask;
  1019. int ret = 0;
  1020. for (bitmask = 1; bitmask < e->mask; bitmask <<= 1)
  1021. ;
  1022. if (ucontrol->value.enumerated.item[0] > e->mask - 1)
  1023. return -EINVAL;
  1024. mux = ucontrol->value.enumerated.item[0];
  1025. val = mux << e->shift_l;
  1026. mask = (bitmask - 1) << e->shift_l;
  1027. if (e->shift_l != e->shift_r) {
  1028. if (ucontrol->value.enumerated.item[1] > e->mask - 1)
  1029. return -EINVAL;
  1030. val |= ucontrol->value.enumerated.item[1] << e->shift_r;
  1031. mask |= (bitmask - 1) << e->shift_r;
  1032. }
  1033. mutex_lock(&widget->codec->mutex);
  1034. widget->value = val;
  1035. dapm_mux_update_power(widget, kcontrol, mask, mux, e);
  1036. if (widget->event) {
  1037. if (widget->event_flags & SND_SOC_DAPM_PRE_REG) {
  1038. ret = widget->event(widget, SND_SOC_DAPM_PRE_REG);
  1039. if (ret < 0)
  1040. goto out;
  1041. }
  1042. ret = snd_soc_update_bits(widget->codec, e->reg, mask, val);
  1043. if (widget->event_flags & SND_SOC_DAPM_POST_REG)
  1044. ret = widget->event(widget, SND_SOC_DAPM_POST_REG);
  1045. } else
  1046. ret = snd_soc_update_bits(widget->codec, e->reg, mask, val);
  1047. out:
  1048. mutex_unlock(&widget->codec->mutex);
  1049. return ret;
  1050. }
  1051. EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double);
  1052. /**
  1053. * snd_soc_dapm_new_control - create new dapm control
  1054. * @codec: audio codec
  1055. * @widget: widget template
  1056. *
  1057. * Creates a new dapm control based upon the template.
  1058. *
  1059. * Returns 0 for success else error.
  1060. */
  1061. int snd_soc_dapm_new_control(struct snd_soc_codec *codec,
  1062. const struct snd_soc_dapm_widget *widget)
  1063. {
  1064. struct snd_soc_dapm_widget *w;
  1065. if ((w = dapm_cnew_widget(widget)) == NULL)
  1066. return -ENOMEM;
  1067. w->codec = codec;
  1068. INIT_LIST_HEAD(&w->sources);
  1069. INIT_LIST_HEAD(&w->sinks);
  1070. INIT_LIST_HEAD(&w->list);
  1071. list_add(&w->list, &codec->dapm_widgets);
  1072. /* machine layer set ups unconnected pins and insertions */
  1073. w->connected = 1;
  1074. return 0;
  1075. }
  1076. EXPORT_SYMBOL_GPL(snd_soc_dapm_new_control);
  1077. /**
  1078. * snd_soc_dapm_stream_event - send a stream event to the dapm core
  1079. * @codec: audio codec
  1080. * @stream: stream name
  1081. * @event: stream event
  1082. *
  1083. * Sends a stream event to the dapm core. The core then makes any
  1084. * necessary widget power changes.
  1085. *
  1086. * Returns 0 for success else error.
  1087. */
  1088. int snd_soc_dapm_stream_event(struct snd_soc_codec *codec,
  1089. char *stream, int event)
  1090. {
  1091. struct snd_soc_dapm_widget *w;
  1092. if (stream == NULL)
  1093. return 0;
  1094. mutex_lock(&codec->mutex);
  1095. list_for_each_entry(w, &codec->dapm_widgets, list)
  1096. {
  1097. if (!w->sname)
  1098. continue;
  1099. dbg("widget %s\n %s stream %s event %d\n", w->name, w->sname,
  1100. stream, event);
  1101. if (strstr(w->sname, stream)) {
  1102. switch(event) {
  1103. case SND_SOC_DAPM_STREAM_START:
  1104. w->active = 1;
  1105. break;
  1106. case SND_SOC_DAPM_STREAM_STOP:
  1107. w->active = 0;
  1108. break;
  1109. case SND_SOC_DAPM_STREAM_SUSPEND:
  1110. if (w->active)
  1111. w->suspend = 1;
  1112. w->active = 0;
  1113. break;
  1114. case SND_SOC_DAPM_STREAM_RESUME:
  1115. if (w->suspend) {
  1116. w->active = 1;
  1117. w->suspend = 0;
  1118. }
  1119. break;
  1120. case SND_SOC_DAPM_STREAM_PAUSE_PUSH:
  1121. break;
  1122. case SND_SOC_DAPM_STREAM_PAUSE_RELEASE:
  1123. break;
  1124. }
  1125. }
  1126. }
  1127. mutex_unlock(&codec->mutex);
  1128. dapm_power_widgets(codec, event);
  1129. dump_dapm(codec, __FUNCTION__);
  1130. return 0;
  1131. }
  1132. EXPORT_SYMBOL_GPL(snd_soc_dapm_stream_event);
  1133. /**
  1134. * snd_soc_dapm_set_endpoint - set audio endpoint status
  1135. * @codec: audio codec
  1136. * @endpoint: audio signal endpoint (or start point)
  1137. * @status: point status
  1138. *
  1139. * Set audio endpoint status - connected or disconnected.
  1140. *
  1141. * Returns 0 for success else error.
  1142. */
  1143. int snd_soc_dapm_set_endpoint(struct snd_soc_codec *codec,
  1144. char *endpoint, int status)
  1145. {
  1146. struct snd_soc_dapm_widget *w;
  1147. list_for_each_entry(w, &codec->dapm_widgets, list) {
  1148. if (!strcmp(w->name, endpoint)) {
  1149. w->connected = status;
  1150. }
  1151. }
  1152. return 0;
  1153. }
  1154. EXPORT_SYMBOL_GPL(snd_soc_dapm_set_endpoint);
  1155. /**
  1156. * snd_soc_dapm_free - free dapm resources
  1157. * @socdev: SoC device
  1158. *
  1159. * Free all dapm widgets and resources.
  1160. */
  1161. void snd_soc_dapm_free(struct snd_soc_device *socdev)
  1162. {
  1163. struct snd_soc_codec *codec = socdev->codec;
  1164. snd_soc_dapm_sys_remove(socdev->dev);
  1165. dapm_free_widgets(codec);
  1166. }
  1167. EXPORT_SYMBOL_GPL(snd_soc_dapm_free);
  1168. /* Module information */
  1169. MODULE_AUTHOR("Liam Girdwood, liam.girdwood@wolfsonmicro.com, www.wolfsonmicro.com");
  1170. MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC");
  1171. MODULE_LICENSE("GPL");