soc-dapm.c 48 KB

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