soc-dapm.c 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492
  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/async.h>
  35. #include <linux/delay.h>
  36. #include <linux/pm.h>
  37. #include <linux/bitops.h>
  38. #include <linux/platform_device.h>
  39. #include <linux/jiffies.h>
  40. #include <linux/debugfs.h>
  41. #include <linux/slab.h>
  42. #include <sound/core.h>
  43. #include <sound/pcm.h>
  44. #include <sound/pcm_params.h>
  45. #include <sound/soc.h>
  46. #include <sound/initval.h>
  47. #include <trace/events/asoc.h>
  48. /* dapm power sequences - make this per codec in the future */
  49. static int dapm_up_seq[] = {
  50. [snd_soc_dapm_pre] = 0,
  51. [snd_soc_dapm_supply] = 1,
  52. [snd_soc_dapm_micbias] = 2,
  53. [snd_soc_dapm_aif_in] = 3,
  54. [snd_soc_dapm_aif_out] = 3,
  55. [snd_soc_dapm_mic] = 4,
  56. [snd_soc_dapm_mux] = 5,
  57. [snd_soc_dapm_virt_mux] = 5,
  58. [snd_soc_dapm_value_mux] = 5,
  59. [snd_soc_dapm_dac] = 6,
  60. [snd_soc_dapm_mixer] = 7,
  61. [snd_soc_dapm_mixer_named_ctl] = 7,
  62. [snd_soc_dapm_pga] = 8,
  63. [snd_soc_dapm_adc] = 9,
  64. [snd_soc_dapm_out_drv] = 10,
  65. [snd_soc_dapm_hp] = 10,
  66. [snd_soc_dapm_spk] = 10,
  67. [snd_soc_dapm_post] = 11,
  68. };
  69. static int dapm_down_seq[] = {
  70. [snd_soc_dapm_pre] = 0,
  71. [snd_soc_dapm_adc] = 1,
  72. [snd_soc_dapm_hp] = 2,
  73. [snd_soc_dapm_spk] = 2,
  74. [snd_soc_dapm_out_drv] = 2,
  75. [snd_soc_dapm_pga] = 4,
  76. [snd_soc_dapm_mixer_named_ctl] = 5,
  77. [snd_soc_dapm_mixer] = 5,
  78. [snd_soc_dapm_dac] = 6,
  79. [snd_soc_dapm_mic] = 7,
  80. [snd_soc_dapm_micbias] = 8,
  81. [snd_soc_dapm_mux] = 9,
  82. [snd_soc_dapm_virt_mux] = 9,
  83. [snd_soc_dapm_value_mux] = 9,
  84. [snd_soc_dapm_aif_in] = 10,
  85. [snd_soc_dapm_aif_out] = 10,
  86. [snd_soc_dapm_supply] = 11,
  87. [snd_soc_dapm_post] = 12,
  88. };
  89. static void pop_wait(u32 pop_time)
  90. {
  91. if (pop_time)
  92. schedule_timeout_uninterruptible(msecs_to_jiffies(pop_time));
  93. }
  94. static void pop_dbg(struct device *dev, u32 pop_time, const char *fmt, ...)
  95. {
  96. va_list args;
  97. char *buf;
  98. if (!pop_time)
  99. return;
  100. buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
  101. if (buf == NULL)
  102. return;
  103. va_start(args, fmt);
  104. vsnprintf(buf, PAGE_SIZE, fmt, args);
  105. dev_info(dev, "%s", buf);
  106. va_end(args);
  107. kfree(buf);
  108. }
  109. /* create a new dapm widget */
  110. static inline struct snd_soc_dapm_widget *dapm_cnew_widget(
  111. const struct snd_soc_dapm_widget *_widget)
  112. {
  113. return kmemdup(_widget, sizeof(*_widget), GFP_KERNEL);
  114. }
  115. /**
  116. * snd_soc_dapm_set_bias_level - set the bias level for the system
  117. * @dapm: DAPM context
  118. * @level: level to configure
  119. *
  120. * Configure the bias (power) levels for the SoC audio device.
  121. *
  122. * Returns 0 for success else error.
  123. */
  124. static int snd_soc_dapm_set_bias_level(struct snd_soc_dapm_context *dapm,
  125. enum snd_soc_bias_level level)
  126. {
  127. struct snd_soc_card *card = dapm->card;
  128. int ret = 0;
  129. switch (level) {
  130. case SND_SOC_BIAS_ON:
  131. dev_dbg(dapm->dev, "Setting full bias\n");
  132. break;
  133. case SND_SOC_BIAS_PREPARE:
  134. dev_dbg(dapm->dev, "Setting bias prepare\n");
  135. break;
  136. case SND_SOC_BIAS_STANDBY:
  137. dev_dbg(dapm->dev, "Setting standby bias\n");
  138. break;
  139. case SND_SOC_BIAS_OFF:
  140. dev_dbg(dapm->dev, "Setting bias off\n");
  141. break;
  142. default:
  143. dev_err(dapm->dev, "Setting invalid bias %d\n", level);
  144. return -EINVAL;
  145. }
  146. trace_snd_soc_bias_level_start(card, level);
  147. if (card && card->set_bias_level)
  148. ret = card->set_bias_level(card, level);
  149. if (ret == 0) {
  150. if (dapm->codec && dapm->codec->driver->set_bias_level)
  151. ret = dapm->codec->driver->set_bias_level(dapm->codec, level);
  152. else
  153. dapm->bias_level = level;
  154. }
  155. if (ret == 0) {
  156. if (card && card->set_bias_level_post)
  157. ret = card->set_bias_level_post(card, level);
  158. }
  159. trace_snd_soc_bias_level_done(card, level);
  160. return ret;
  161. }
  162. /* set up initial codec paths */
  163. static void dapm_set_path_status(struct snd_soc_dapm_widget *w,
  164. struct snd_soc_dapm_path *p, int i)
  165. {
  166. switch (w->id) {
  167. case snd_soc_dapm_switch:
  168. case snd_soc_dapm_mixer:
  169. case snd_soc_dapm_mixer_named_ctl: {
  170. int val;
  171. struct soc_mixer_control *mc = (struct soc_mixer_control *)
  172. w->kcontrols[i].private_value;
  173. unsigned int reg = mc->reg;
  174. unsigned int shift = mc->shift;
  175. int max = mc->max;
  176. unsigned int mask = (1 << fls(max)) - 1;
  177. unsigned int invert = mc->invert;
  178. val = snd_soc_read(w->codec, reg);
  179. val = (val >> shift) & mask;
  180. if ((invert && !val) || (!invert && val))
  181. p->connect = 1;
  182. else
  183. p->connect = 0;
  184. }
  185. break;
  186. case snd_soc_dapm_mux: {
  187. struct soc_enum *e = (struct soc_enum *)w->kcontrols[i].private_value;
  188. int val, item, bitmask;
  189. for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
  190. ;
  191. val = snd_soc_read(w->codec, e->reg);
  192. item = (val >> e->shift_l) & (bitmask - 1);
  193. p->connect = 0;
  194. for (i = 0; i < e->max; i++) {
  195. if (!(strcmp(p->name, e->texts[i])) && item == i)
  196. p->connect = 1;
  197. }
  198. }
  199. break;
  200. case snd_soc_dapm_virt_mux: {
  201. struct soc_enum *e = (struct soc_enum *)w->kcontrols[i].private_value;
  202. p->connect = 0;
  203. /* since a virtual mux has no backing registers to
  204. * decide which path to connect, it will try to match
  205. * with the first enumeration. This is to ensure
  206. * that the default mux choice (the first) will be
  207. * correctly powered up during initialization.
  208. */
  209. if (!strcmp(p->name, e->texts[0]))
  210. p->connect = 1;
  211. }
  212. break;
  213. case snd_soc_dapm_value_mux: {
  214. struct soc_enum *e = (struct soc_enum *)
  215. w->kcontrols[i].private_value;
  216. int val, item;
  217. val = snd_soc_read(w->codec, e->reg);
  218. val = (val >> e->shift_l) & e->mask;
  219. for (item = 0; item < e->max; item++) {
  220. if (val == e->values[item])
  221. break;
  222. }
  223. p->connect = 0;
  224. for (i = 0; i < e->max; i++) {
  225. if (!(strcmp(p->name, e->texts[i])) && item == i)
  226. p->connect = 1;
  227. }
  228. }
  229. break;
  230. /* does not effect routing - always connected */
  231. case snd_soc_dapm_pga:
  232. case snd_soc_dapm_out_drv:
  233. case snd_soc_dapm_output:
  234. case snd_soc_dapm_adc:
  235. case snd_soc_dapm_input:
  236. case snd_soc_dapm_dac:
  237. case snd_soc_dapm_micbias:
  238. case snd_soc_dapm_vmid:
  239. case snd_soc_dapm_supply:
  240. case snd_soc_dapm_aif_in:
  241. case snd_soc_dapm_aif_out:
  242. p->connect = 1;
  243. break;
  244. /* does effect routing - dynamically connected */
  245. case snd_soc_dapm_hp:
  246. case snd_soc_dapm_mic:
  247. case snd_soc_dapm_spk:
  248. case snd_soc_dapm_line:
  249. case snd_soc_dapm_pre:
  250. case snd_soc_dapm_post:
  251. p->connect = 0;
  252. break;
  253. }
  254. }
  255. /* connect mux widget to its interconnecting audio paths */
  256. static int dapm_connect_mux(struct snd_soc_dapm_context *dapm,
  257. struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest,
  258. struct snd_soc_dapm_path *path, const char *control_name,
  259. const struct snd_kcontrol_new *kcontrol)
  260. {
  261. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  262. int i;
  263. for (i = 0; i < e->max; i++) {
  264. if (!(strcmp(control_name, e->texts[i]))) {
  265. list_add(&path->list, &dapm->card->paths);
  266. list_add(&path->list_sink, &dest->sources);
  267. list_add(&path->list_source, &src->sinks);
  268. path->name = (char*)e->texts[i];
  269. dapm_set_path_status(dest, path, 0);
  270. return 0;
  271. }
  272. }
  273. return -ENODEV;
  274. }
  275. /* connect mixer widget to its interconnecting audio paths */
  276. static int dapm_connect_mixer(struct snd_soc_dapm_context *dapm,
  277. struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest,
  278. struct snd_soc_dapm_path *path, const char *control_name)
  279. {
  280. int i;
  281. /* search for mixer kcontrol */
  282. for (i = 0; i < dest->num_kcontrols; i++) {
  283. if (!strcmp(control_name, dest->kcontrols[i].name)) {
  284. list_add(&path->list, &dapm->card->paths);
  285. list_add(&path->list_sink, &dest->sources);
  286. list_add(&path->list_source, &src->sinks);
  287. path->name = dest->kcontrols[i].name;
  288. dapm_set_path_status(dest, path, i);
  289. return 0;
  290. }
  291. }
  292. return -ENODEV;
  293. }
  294. /* update dapm codec register bits */
  295. static int dapm_update_bits(struct snd_soc_dapm_widget *widget)
  296. {
  297. int change, power;
  298. unsigned int old, new;
  299. struct snd_soc_codec *codec = widget->codec;
  300. struct snd_soc_dapm_context *dapm = widget->dapm;
  301. struct snd_soc_card *card = dapm->card;
  302. /* check for valid widgets */
  303. if (widget->reg < 0 || widget->id == snd_soc_dapm_input ||
  304. widget->id == snd_soc_dapm_output ||
  305. widget->id == snd_soc_dapm_hp ||
  306. widget->id == snd_soc_dapm_mic ||
  307. widget->id == snd_soc_dapm_line ||
  308. widget->id == snd_soc_dapm_spk)
  309. return 0;
  310. power = widget->power;
  311. if (widget->invert)
  312. power = (power ? 0:1);
  313. old = snd_soc_read(codec, widget->reg);
  314. new = (old & ~(0x1 << widget->shift)) | (power << widget->shift);
  315. change = old != new;
  316. if (change) {
  317. pop_dbg(dapm->dev, card->pop_time,
  318. "pop test %s : %s in %d ms\n",
  319. widget->name, widget->power ? "on" : "off",
  320. card->pop_time);
  321. pop_wait(card->pop_time);
  322. snd_soc_write(codec, widget->reg, new);
  323. }
  324. dev_dbg(dapm->dev, "reg %x old %x new %x change %d\n", widget->reg,
  325. old, new, change);
  326. return change;
  327. }
  328. /* create new dapm mixer control */
  329. static int dapm_new_mixer(struct snd_soc_dapm_context *dapm,
  330. struct snd_soc_dapm_widget *w)
  331. {
  332. int i, ret = 0;
  333. size_t name_len;
  334. struct snd_soc_dapm_path *path;
  335. struct snd_card *card = dapm->card->snd_card;
  336. const char *prefix;
  337. if (dapm->codec)
  338. prefix = dapm->codec->name_prefix;
  339. else
  340. prefix = NULL;
  341. /* add kcontrol */
  342. for (i = 0; i < w->num_kcontrols; i++) {
  343. /* match name */
  344. list_for_each_entry(path, &w->sources, list_sink) {
  345. /* mixer/mux paths name must match control name */
  346. if (path->name != (char*)w->kcontrols[i].name)
  347. continue;
  348. /* add dapm control with long name.
  349. * for dapm_mixer this is the concatenation of the
  350. * mixer and kcontrol name.
  351. * for dapm_mixer_named_ctl this is simply the
  352. * kcontrol name.
  353. */
  354. name_len = strlen(w->kcontrols[i].name) + 1;
  355. if (w->id != snd_soc_dapm_mixer_named_ctl)
  356. name_len += 1 + strlen(w->name);
  357. path->long_name = kmalloc(name_len, GFP_KERNEL);
  358. if (path->long_name == NULL)
  359. return -ENOMEM;
  360. switch (w->id) {
  361. default:
  362. snprintf(path->long_name, name_len, "%s %s",
  363. w->name, w->kcontrols[i].name);
  364. break;
  365. case snd_soc_dapm_mixer_named_ctl:
  366. snprintf(path->long_name, name_len, "%s",
  367. w->kcontrols[i].name);
  368. break;
  369. }
  370. path->long_name[name_len - 1] = '\0';
  371. path->kcontrol = snd_soc_cnew(&w->kcontrols[i], w,
  372. path->long_name, prefix);
  373. ret = snd_ctl_add(card, path->kcontrol);
  374. if (ret < 0) {
  375. dev_err(dapm->dev,
  376. "asoc: failed to add dapm kcontrol %s: %d\n",
  377. path->long_name, ret);
  378. kfree(path->long_name);
  379. path->long_name = NULL;
  380. return ret;
  381. }
  382. }
  383. }
  384. return ret;
  385. }
  386. /* create new dapm mux control */
  387. static int dapm_new_mux(struct snd_soc_dapm_context *dapm,
  388. struct snd_soc_dapm_widget *w)
  389. {
  390. struct snd_soc_dapm_path *path = NULL;
  391. struct snd_kcontrol *kcontrol;
  392. struct snd_card *card = dapm->card->snd_card;
  393. const char *prefix;
  394. int ret = 0;
  395. if (!w->num_kcontrols) {
  396. dev_err(dapm->dev, "asoc: mux %s has no controls\n", w->name);
  397. return -EINVAL;
  398. }
  399. if (dapm->codec)
  400. prefix = dapm->codec->name_prefix;
  401. else
  402. prefix = NULL;
  403. kcontrol = snd_soc_cnew(&w->kcontrols[0], w, w->name, prefix);
  404. ret = snd_ctl_add(card, kcontrol);
  405. if (ret < 0)
  406. goto err;
  407. list_for_each_entry(path, &w->sources, list_sink)
  408. path->kcontrol = kcontrol;
  409. return ret;
  410. err:
  411. dev_err(dapm->dev, "asoc: failed to add kcontrol %s\n", w->name);
  412. return ret;
  413. }
  414. /* create new dapm volume control */
  415. static int dapm_new_pga(struct snd_soc_dapm_context *dapm,
  416. struct snd_soc_dapm_widget *w)
  417. {
  418. if (w->num_kcontrols)
  419. dev_err(w->dapm->dev,
  420. "asoc: PGA controls not supported: '%s'\n", w->name);
  421. return 0;
  422. }
  423. /* reset 'walked' bit for each dapm path */
  424. static inline void dapm_clear_walk(struct snd_soc_dapm_context *dapm)
  425. {
  426. struct snd_soc_dapm_path *p;
  427. list_for_each_entry(p, &dapm->card->paths, list)
  428. p->walked = 0;
  429. }
  430. /* We implement power down on suspend by checking the power state of
  431. * the ALSA card - when we are suspending the ALSA state for the card
  432. * is set to D3.
  433. */
  434. static int snd_soc_dapm_suspend_check(struct snd_soc_dapm_widget *widget)
  435. {
  436. int level = snd_power_get_state(widget->dapm->card->snd_card);
  437. switch (level) {
  438. case SNDRV_CTL_POWER_D3hot:
  439. case SNDRV_CTL_POWER_D3cold:
  440. if (widget->ignore_suspend)
  441. dev_dbg(widget->dapm->dev, "%s ignoring suspend\n",
  442. widget->name);
  443. return widget->ignore_suspend;
  444. default:
  445. return 1;
  446. }
  447. }
  448. /*
  449. * Recursively check for a completed path to an active or physically connected
  450. * output widget. Returns number of complete paths.
  451. */
  452. static int is_connected_output_ep(struct snd_soc_dapm_widget *widget)
  453. {
  454. struct snd_soc_dapm_path *path;
  455. int con = 0;
  456. if (widget->id == snd_soc_dapm_supply)
  457. return 0;
  458. switch (widget->id) {
  459. case snd_soc_dapm_adc:
  460. case snd_soc_dapm_aif_out:
  461. if (widget->active)
  462. return snd_soc_dapm_suspend_check(widget);
  463. default:
  464. break;
  465. }
  466. if (widget->connected) {
  467. /* connected pin ? */
  468. if (widget->id == snd_soc_dapm_output && !widget->ext)
  469. return snd_soc_dapm_suspend_check(widget);
  470. /* connected jack or spk ? */
  471. if (widget->id == snd_soc_dapm_hp || widget->id == snd_soc_dapm_spk ||
  472. (widget->id == snd_soc_dapm_line && !list_empty(&widget->sources)))
  473. return snd_soc_dapm_suspend_check(widget);
  474. }
  475. list_for_each_entry(path, &widget->sinks, list_source) {
  476. if (path->walked)
  477. continue;
  478. if (path->sink && path->connect) {
  479. path->walked = 1;
  480. con += is_connected_output_ep(path->sink);
  481. }
  482. }
  483. return con;
  484. }
  485. /*
  486. * Recursively check for a completed path to an active or physically connected
  487. * input widget. Returns number of complete paths.
  488. */
  489. static int is_connected_input_ep(struct snd_soc_dapm_widget *widget)
  490. {
  491. struct snd_soc_dapm_path *path;
  492. int con = 0;
  493. if (widget->id == snd_soc_dapm_supply)
  494. return 0;
  495. /* active stream ? */
  496. switch (widget->id) {
  497. case snd_soc_dapm_dac:
  498. case snd_soc_dapm_aif_in:
  499. if (widget->active)
  500. return snd_soc_dapm_suspend_check(widget);
  501. default:
  502. break;
  503. }
  504. if (widget->connected) {
  505. /* connected pin ? */
  506. if (widget->id == snd_soc_dapm_input && !widget->ext)
  507. return snd_soc_dapm_suspend_check(widget);
  508. /* connected VMID/Bias for lower pops */
  509. if (widget->id == snd_soc_dapm_vmid)
  510. return snd_soc_dapm_suspend_check(widget);
  511. /* connected jack ? */
  512. if (widget->id == snd_soc_dapm_mic ||
  513. (widget->id == snd_soc_dapm_line && !list_empty(&widget->sinks)))
  514. return snd_soc_dapm_suspend_check(widget);
  515. }
  516. list_for_each_entry(path, &widget->sources, list_sink) {
  517. if (path->walked)
  518. continue;
  519. if (path->source && path->connect) {
  520. path->walked = 1;
  521. con += is_connected_input_ep(path->source);
  522. }
  523. }
  524. return con;
  525. }
  526. /*
  527. * Handler for generic register modifier widget.
  528. */
  529. int dapm_reg_event(struct snd_soc_dapm_widget *w,
  530. struct snd_kcontrol *kcontrol, int event)
  531. {
  532. unsigned int val;
  533. if (SND_SOC_DAPM_EVENT_ON(event))
  534. val = w->on_val;
  535. else
  536. val = w->off_val;
  537. snd_soc_update_bits(w->codec, -(w->reg + 1),
  538. w->mask << w->shift, val << w->shift);
  539. return 0;
  540. }
  541. EXPORT_SYMBOL_GPL(dapm_reg_event);
  542. /* Standard power change method, used to apply power changes to most
  543. * widgets.
  544. */
  545. static int dapm_generic_apply_power(struct snd_soc_dapm_widget *w)
  546. {
  547. int ret;
  548. /* call any power change event handlers */
  549. if (w->event)
  550. dev_dbg(w->dapm->dev, "power %s event for %s flags %x\n",
  551. w->power ? "on" : "off",
  552. w->name, w->event_flags);
  553. /* power up pre event */
  554. if (w->power && w->event &&
  555. (w->event_flags & SND_SOC_DAPM_PRE_PMU)) {
  556. ret = w->event(w, NULL, SND_SOC_DAPM_PRE_PMU);
  557. if (ret < 0)
  558. return ret;
  559. }
  560. /* power down pre event */
  561. if (!w->power && w->event &&
  562. (w->event_flags & SND_SOC_DAPM_PRE_PMD)) {
  563. ret = w->event(w, NULL, SND_SOC_DAPM_PRE_PMD);
  564. if (ret < 0)
  565. return ret;
  566. }
  567. dapm_update_bits(w);
  568. /* power up post event */
  569. if (w->power && w->event &&
  570. (w->event_flags & SND_SOC_DAPM_POST_PMU)) {
  571. ret = w->event(w,
  572. NULL, SND_SOC_DAPM_POST_PMU);
  573. if (ret < 0)
  574. return ret;
  575. }
  576. /* power down post event */
  577. if (!w->power && w->event &&
  578. (w->event_flags & SND_SOC_DAPM_POST_PMD)) {
  579. ret = w->event(w, NULL, SND_SOC_DAPM_POST_PMD);
  580. if (ret < 0)
  581. return ret;
  582. }
  583. return 0;
  584. }
  585. /* Generic check to see if a widget should be powered.
  586. */
  587. static int dapm_generic_check_power(struct snd_soc_dapm_widget *w)
  588. {
  589. int in, out;
  590. in = is_connected_input_ep(w);
  591. dapm_clear_walk(w->dapm);
  592. out = is_connected_output_ep(w);
  593. dapm_clear_walk(w->dapm);
  594. return out != 0 && in != 0;
  595. }
  596. /* Check to see if an ADC has power */
  597. static int dapm_adc_check_power(struct snd_soc_dapm_widget *w)
  598. {
  599. int in;
  600. if (w->active) {
  601. in = is_connected_input_ep(w);
  602. dapm_clear_walk(w->dapm);
  603. return in != 0;
  604. } else {
  605. return dapm_generic_check_power(w);
  606. }
  607. }
  608. /* Check to see if a DAC has power */
  609. static int dapm_dac_check_power(struct snd_soc_dapm_widget *w)
  610. {
  611. int out;
  612. if (w->active) {
  613. out = is_connected_output_ep(w);
  614. dapm_clear_walk(w->dapm);
  615. return out != 0;
  616. } else {
  617. return dapm_generic_check_power(w);
  618. }
  619. }
  620. /* Check to see if a power supply is needed */
  621. static int dapm_supply_check_power(struct snd_soc_dapm_widget *w)
  622. {
  623. struct snd_soc_dapm_path *path;
  624. int power = 0;
  625. /* Check if one of our outputs is connected */
  626. list_for_each_entry(path, &w->sinks, list_source) {
  627. if (path->connected &&
  628. !path->connected(path->source, path->sink))
  629. continue;
  630. if (!path->sink)
  631. continue;
  632. if (path->sink->force) {
  633. power = 1;
  634. break;
  635. }
  636. if (path->sink->power_check &&
  637. path->sink->power_check(path->sink)) {
  638. power = 1;
  639. break;
  640. }
  641. }
  642. dapm_clear_walk(w->dapm);
  643. return power;
  644. }
  645. static int dapm_seq_compare(struct snd_soc_dapm_widget *a,
  646. struct snd_soc_dapm_widget *b,
  647. bool power_up)
  648. {
  649. int *sort;
  650. if (power_up)
  651. sort = dapm_up_seq;
  652. else
  653. sort = dapm_down_seq;
  654. if (sort[a->id] != sort[b->id])
  655. return sort[a->id] - sort[b->id];
  656. if (a->subseq != b->subseq) {
  657. if (power_up)
  658. return a->subseq - b->subseq;
  659. else
  660. return b->subseq - a->subseq;
  661. }
  662. if (a->reg != b->reg)
  663. return a->reg - b->reg;
  664. if (a->dapm != b->dapm)
  665. return (unsigned long)a->dapm - (unsigned long)b->dapm;
  666. return 0;
  667. }
  668. /* Insert a widget in order into a DAPM power sequence. */
  669. static void dapm_seq_insert(struct snd_soc_dapm_widget *new_widget,
  670. struct list_head *list,
  671. bool power_up)
  672. {
  673. struct snd_soc_dapm_widget *w;
  674. list_for_each_entry(w, list, power_list)
  675. if (dapm_seq_compare(new_widget, w, power_up) < 0) {
  676. list_add_tail(&new_widget->power_list, &w->power_list);
  677. return;
  678. }
  679. list_add_tail(&new_widget->power_list, list);
  680. }
  681. static void dapm_seq_check_event(struct snd_soc_dapm_context *dapm,
  682. struct snd_soc_dapm_widget *w, int event)
  683. {
  684. struct snd_soc_card *card = dapm->card;
  685. const char *ev_name;
  686. int power, ret;
  687. switch (event) {
  688. case SND_SOC_DAPM_PRE_PMU:
  689. ev_name = "PRE_PMU";
  690. power = 1;
  691. break;
  692. case SND_SOC_DAPM_POST_PMU:
  693. ev_name = "POST_PMU";
  694. power = 1;
  695. break;
  696. case SND_SOC_DAPM_PRE_PMD:
  697. ev_name = "PRE_PMD";
  698. power = 0;
  699. break;
  700. case SND_SOC_DAPM_POST_PMD:
  701. ev_name = "POST_PMD";
  702. power = 0;
  703. break;
  704. default:
  705. BUG();
  706. return;
  707. }
  708. if (w->power != power)
  709. return;
  710. if (w->event && (w->event_flags & event)) {
  711. pop_dbg(dapm->dev, card->pop_time, "pop test : %s %s\n",
  712. w->name, ev_name);
  713. trace_snd_soc_dapm_widget_event_start(w, event);
  714. ret = w->event(w, NULL, event);
  715. trace_snd_soc_dapm_widget_event_done(w, event);
  716. if (ret < 0)
  717. pr_err("%s: %s event failed: %d\n",
  718. ev_name, w->name, ret);
  719. }
  720. }
  721. /* Apply the coalesced changes from a DAPM sequence */
  722. static void dapm_seq_run_coalesced(struct snd_soc_dapm_context *dapm,
  723. struct list_head *pending)
  724. {
  725. struct snd_soc_card *card = dapm->card;
  726. struct snd_soc_dapm_widget *w;
  727. int reg, power;
  728. unsigned int value = 0;
  729. unsigned int mask = 0;
  730. unsigned int cur_mask;
  731. reg = list_first_entry(pending, struct snd_soc_dapm_widget,
  732. power_list)->reg;
  733. list_for_each_entry(w, pending, power_list) {
  734. cur_mask = 1 << w->shift;
  735. BUG_ON(reg != w->reg);
  736. if (w->invert)
  737. power = !w->power;
  738. else
  739. power = w->power;
  740. mask |= cur_mask;
  741. if (power)
  742. value |= cur_mask;
  743. pop_dbg(dapm->dev, card->pop_time,
  744. "pop test : Queue %s: reg=0x%x, 0x%x/0x%x\n",
  745. w->name, reg, value, mask);
  746. /* Check for events */
  747. dapm_seq_check_event(dapm, w, SND_SOC_DAPM_PRE_PMU);
  748. dapm_seq_check_event(dapm, w, SND_SOC_DAPM_PRE_PMD);
  749. }
  750. if (reg >= 0) {
  751. pop_dbg(dapm->dev, card->pop_time,
  752. "pop test : Applying 0x%x/0x%x to %x in %dms\n",
  753. value, mask, reg, card->pop_time);
  754. pop_wait(card->pop_time);
  755. snd_soc_update_bits(dapm->codec, reg, mask, value);
  756. }
  757. list_for_each_entry(w, pending, power_list) {
  758. dapm_seq_check_event(dapm, w, SND_SOC_DAPM_POST_PMU);
  759. dapm_seq_check_event(dapm, w, SND_SOC_DAPM_POST_PMD);
  760. }
  761. }
  762. /* Apply a DAPM power sequence.
  763. *
  764. * We walk over a pre-sorted list of widgets to apply power to. In
  765. * order to minimise the number of writes to the device required
  766. * multiple widgets will be updated in a single write where possible.
  767. * Currently anything that requires more than a single write is not
  768. * handled.
  769. */
  770. static void dapm_seq_run(struct snd_soc_dapm_context *dapm,
  771. struct list_head *list, int event, bool power_up)
  772. {
  773. struct snd_soc_dapm_widget *w, *n;
  774. LIST_HEAD(pending);
  775. int cur_sort = -1;
  776. int cur_subseq = -1;
  777. int cur_reg = SND_SOC_NOPM;
  778. struct snd_soc_dapm_context *cur_dapm = NULL;
  779. int ret, i;
  780. int *sort;
  781. if (power_up)
  782. sort = dapm_up_seq;
  783. else
  784. sort = dapm_down_seq;
  785. list_for_each_entry_safe(w, n, list, power_list) {
  786. ret = 0;
  787. /* Do we need to apply any queued changes? */
  788. if (sort[w->id] != cur_sort || w->reg != cur_reg ||
  789. w->dapm != cur_dapm || w->subseq != cur_subseq) {
  790. if (!list_empty(&pending))
  791. dapm_seq_run_coalesced(cur_dapm, &pending);
  792. if (cur_dapm && cur_dapm->seq_notifier) {
  793. for (i = 0; i < ARRAY_SIZE(dapm_up_seq); i++)
  794. if (sort[i] == cur_sort)
  795. cur_dapm->seq_notifier(cur_dapm,
  796. i,
  797. cur_subseq);
  798. }
  799. INIT_LIST_HEAD(&pending);
  800. cur_sort = -1;
  801. cur_subseq = -1;
  802. cur_reg = SND_SOC_NOPM;
  803. cur_dapm = NULL;
  804. }
  805. switch (w->id) {
  806. case snd_soc_dapm_pre:
  807. if (!w->event)
  808. list_for_each_entry_safe_continue(w, n, list,
  809. power_list);
  810. if (event == SND_SOC_DAPM_STREAM_START)
  811. ret = w->event(w,
  812. NULL, SND_SOC_DAPM_PRE_PMU);
  813. else if (event == SND_SOC_DAPM_STREAM_STOP)
  814. ret = w->event(w,
  815. NULL, SND_SOC_DAPM_PRE_PMD);
  816. break;
  817. case snd_soc_dapm_post:
  818. if (!w->event)
  819. list_for_each_entry_safe_continue(w, n, list,
  820. power_list);
  821. if (event == SND_SOC_DAPM_STREAM_START)
  822. ret = w->event(w,
  823. NULL, SND_SOC_DAPM_POST_PMU);
  824. else if (event == SND_SOC_DAPM_STREAM_STOP)
  825. ret = w->event(w,
  826. NULL, SND_SOC_DAPM_POST_PMD);
  827. break;
  828. case snd_soc_dapm_input:
  829. case snd_soc_dapm_output:
  830. case snd_soc_dapm_hp:
  831. case snd_soc_dapm_mic:
  832. case snd_soc_dapm_line:
  833. case snd_soc_dapm_spk:
  834. /* No register support currently */
  835. ret = dapm_generic_apply_power(w);
  836. break;
  837. default:
  838. /* Queue it up for application */
  839. cur_sort = sort[w->id];
  840. cur_subseq = w->subseq;
  841. cur_reg = w->reg;
  842. cur_dapm = w->dapm;
  843. list_move(&w->power_list, &pending);
  844. break;
  845. }
  846. if (ret < 0)
  847. dev_err(w->dapm->dev,
  848. "Failed to apply widget power: %d\n", ret);
  849. }
  850. if (!list_empty(&pending))
  851. dapm_seq_run_coalesced(dapm, &pending);
  852. if (cur_dapm && cur_dapm->seq_notifier) {
  853. for (i = 0; i < ARRAY_SIZE(dapm_up_seq); i++)
  854. if (sort[i] == cur_sort)
  855. cur_dapm->seq_notifier(cur_dapm,
  856. i, cur_subseq);
  857. }
  858. }
  859. static void dapm_widget_update(struct snd_soc_dapm_context *dapm)
  860. {
  861. struct snd_soc_dapm_update *update = dapm->update;
  862. struct snd_soc_dapm_widget *w;
  863. int ret;
  864. if (!update)
  865. return;
  866. w = update->widget;
  867. if (w->event &&
  868. (w->event_flags & SND_SOC_DAPM_PRE_REG)) {
  869. ret = w->event(w, update->kcontrol, SND_SOC_DAPM_PRE_REG);
  870. if (ret != 0)
  871. pr_err("%s DAPM pre-event failed: %d\n",
  872. w->name, ret);
  873. }
  874. ret = snd_soc_update_bits(w->codec, update->reg, update->mask,
  875. update->val);
  876. if (ret < 0)
  877. pr_err("%s DAPM update failed: %d\n", w->name, ret);
  878. if (w->event &&
  879. (w->event_flags & SND_SOC_DAPM_POST_REG)) {
  880. ret = w->event(w, update->kcontrol, SND_SOC_DAPM_POST_REG);
  881. if (ret != 0)
  882. pr_err("%s DAPM post-event failed: %d\n",
  883. w->name, ret);
  884. }
  885. }
  886. /* Async callback run prior to DAPM sequences - brings to _PREPARE if
  887. * they're changing state.
  888. */
  889. static void dapm_pre_sequence_async(void *data, async_cookie_t cookie)
  890. {
  891. struct snd_soc_dapm_context *d = data;
  892. int ret;
  893. if (d->dev_power && d->bias_level == SND_SOC_BIAS_OFF) {
  894. ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_STANDBY);
  895. if (ret != 0)
  896. dev_err(d->dev,
  897. "Failed to turn on bias: %d\n", ret);
  898. }
  899. /* If we're changing to all on or all off then prepare */
  900. if ((d->dev_power && d->bias_level == SND_SOC_BIAS_STANDBY) ||
  901. (!d->dev_power && d->bias_level == SND_SOC_BIAS_ON)) {
  902. ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_PREPARE);
  903. if (ret != 0)
  904. dev_err(d->dev,
  905. "Failed to prepare bias: %d\n", ret);
  906. }
  907. }
  908. /* Async callback run prior to DAPM sequences - brings to their final
  909. * state.
  910. */
  911. static void dapm_post_sequence_async(void *data, async_cookie_t cookie)
  912. {
  913. struct snd_soc_dapm_context *d = data;
  914. int ret;
  915. /* If we just powered the last thing off drop to standby bias */
  916. if (d->bias_level == SND_SOC_BIAS_PREPARE && !d->dev_power) {
  917. ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_STANDBY);
  918. if (ret != 0)
  919. dev_err(d->dev, "Failed to apply standby bias: %d\n",
  920. ret);
  921. }
  922. /* If we're in standby and can support bias off then do that */
  923. if (d->bias_level == SND_SOC_BIAS_STANDBY && d->idle_bias_off) {
  924. ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_OFF);
  925. if (ret != 0)
  926. dev_err(d->dev, "Failed to turn off bias: %d\n", ret);
  927. }
  928. /* If we just powered up then move to active bias */
  929. if (d->bias_level == SND_SOC_BIAS_PREPARE && d->dev_power) {
  930. ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_ON);
  931. if (ret != 0)
  932. dev_err(d->dev, "Failed to apply active bias: %d\n",
  933. ret);
  934. }
  935. }
  936. /*
  937. * Scan each dapm widget for complete audio path.
  938. * A complete path is a route that has valid endpoints i.e.:-
  939. *
  940. * o DAC to output pin.
  941. * o Input Pin to ADC.
  942. * o Input pin to Output pin (bypass, sidetone)
  943. * o DAC to ADC (loopback).
  944. */
  945. static int dapm_power_widgets(struct snd_soc_dapm_context *dapm, int event)
  946. {
  947. struct snd_soc_card *card = dapm->card;
  948. struct snd_soc_dapm_widget *w;
  949. struct snd_soc_dapm_context *d;
  950. LIST_HEAD(up_list);
  951. LIST_HEAD(down_list);
  952. LIST_HEAD(async_domain);
  953. int power;
  954. trace_snd_soc_dapm_start(card);
  955. list_for_each_entry(d, &card->dapm_list, list)
  956. if (d->n_widgets)
  957. d->dev_power = 0;
  958. /* Check which widgets we need to power and store them in
  959. * lists indicating if they should be powered up or down.
  960. */
  961. list_for_each_entry(w, &card->widgets, list) {
  962. switch (w->id) {
  963. case snd_soc_dapm_pre:
  964. dapm_seq_insert(w, &down_list, false);
  965. break;
  966. case snd_soc_dapm_post:
  967. dapm_seq_insert(w, &up_list, true);
  968. break;
  969. default:
  970. if (!w->power_check)
  971. continue;
  972. if (!w->force)
  973. power = w->power_check(w);
  974. else
  975. power = 1;
  976. if (power)
  977. w->dapm->dev_power = 1;
  978. if (w->power == power)
  979. continue;
  980. trace_snd_soc_dapm_widget_power(w, power);
  981. if (power)
  982. dapm_seq_insert(w, &up_list, true);
  983. else
  984. dapm_seq_insert(w, &down_list, false);
  985. w->power = power;
  986. break;
  987. }
  988. }
  989. /* If there are no DAPM widgets then try to figure out power from the
  990. * event type.
  991. */
  992. if (!dapm->n_widgets) {
  993. switch (event) {
  994. case SND_SOC_DAPM_STREAM_START:
  995. case SND_SOC_DAPM_STREAM_RESUME:
  996. dapm->dev_power = 1;
  997. break;
  998. case SND_SOC_DAPM_STREAM_STOP:
  999. dapm->dev_power = !!dapm->codec->active;
  1000. break;
  1001. case SND_SOC_DAPM_STREAM_SUSPEND:
  1002. dapm->dev_power = 0;
  1003. break;
  1004. case SND_SOC_DAPM_STREAM_NOP:
  1005. switch (dapm->bias_level) {
  1006. case SND_SOC_BIAS_STANDBY:
  1007. case SND_SOC_BIAS_OFF:
  1008. dapm->dev_power = 0;
  1009. break;
  1010. default:
  1011. dapm->dev_power = 1;
  1012. break;
  1013. }
  1014. break;
  1015. default:
  1016. break;
  1017. }
  1018. }
  1019. /* Run all the bias changes in parallel */
  1020. list_for_each_entry(d, &dapm->card->dapm_list, list)
  1021. async_schedule_domain(dapm_pre_sequence_async, d,
  1022. &async_domain);
  1023. async_synchronize_full_domain(&async_domain);
  1024. /* Power down widgets first; try to avoid amplifying pops. */
  1025. dapm_seq_run(dapm, &down_list, event, false);
  1026. dapm_widget_update(dapm);
  1027. /* Now power up. */
  1028. dapm_seq_run(dapm, &up_list, event, true);
  1029. /* Run all the bias changes in parallel */
  1030. list_for_each_entry(d, &dapm->card->dapm_list, list)
  1031. async_schedule_domain(dapm_post_sequence_async, d,
  1032. &async_domain);
  1033. async_synchronize_full_domain(&async_domain);
  1034. pop_dbg(dapm->dev, card->pop_time,
  1035. "DAPM sequencing finished, waiting %dms\n", card->pop_time);
  1036. pop_wait(card->pop_time);
  1037. trace_snd_soc_dapm_done(card);
  1038. return 0;
  1039. }
  1040. #ifdef CONFIG_DEBUG_FS
  1041. static int dapm_widget_power_open_file(struct inode *inode, struct file *file)
  1042. {
  1043. file->private_data = inode->i_private;
  1044. return 0;
  1045. }
  1046. static ssize_t dapm_widget_power_read_file(struct file *file,
  1047. char __user *user_buf,
  1048. size_t count, loff_t *ppos)
  1049. {
  1050. struct snd_soc_dapm_widget *w = file->private_data;
  1051. char *buf;
  1052. int in, out;
  1053. ssize_t ret;
  1054. struct snd_soc_dapm_path *p = NULL;
  1055. buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
  1056. if (!buf)
  1057. return -ENOMEM;
  1058. in = is_connected_input_ep(w);
  1059. dapm_clear_walk(w->dapm);
  1060. out = is_connected_output_ep(w);
  1061. dapm_clear_walk(w->dapm);
  1062. ret = snprintf(buf, PAGE_SIZE, "%s: %s in %d out %d",
  1063. w->name, w->power ? "On" : "Off", in, out);
  1064. if (w->reg >= 0)
  1065. ret += snprintf(buf + ret, PAGE_SIZE - ret,
  1066. " - R%d(0x%x) bit %d",
  1067. w->reg, w->reg, w->shift);
  1068. ret += snprintf(buf + ret, PAGE_SIZE - ret, "\n");
  1069. if (w->sname)
  1070. ret += snprintf(buf + ret, PAGE_SIZE - ret, " stream %s %s\n",
  1071. w->sname,
  1072. w->active ? "active" : "inactive");
  1073. list_for_each_entry(p, &w->sources, list_sink) {
  1074. if (p->connected && !p->connected(w, p->sink))
  1075. continue;
  1076. if (p->connect)
  1077. ret += snprintf(buf + ret, PAGE_SIZE - ret,
  1078. " in \"%s\" \"%s\"\n",
  1079. p->name ? p->name : "static",
  1080. p->source->name);
  1081. }
  1082. list_for_each_entry(p, &w->sinks, list_source) {
  1083. if (p->connected && !p->connected(w, p->sink))
  1084. continue;
  1085. if (p->connect)
  1086. ret += snprintf(buf + ret, PAGE_SIZE - ret,
  1087. " out \"%s\" \"%s\"\n",
  1088. p->name ? p->name : "static",
  1089. p->sink->name);
  1090. }
  1091. ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
  1092. kfree(buf);
  1093. return ret;
  1094. }
  1095. static const struct file_operations dapm_widget_power_fops = {
  1096. .open = dapm_widget_power_open_file,
  1097. .read = dapm_widget_power_read_file,
  1098. .llseek = default_llseek,
  1099. };
  1100. void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm)
  1101. {
  1102. struct snd_soc_dapm_widget *w;
  1103. struct dentry *d;
  1104. if (!dapm->debugfs_dapm)
  1105. return;
  1106. list_for_each_entry(w, &dapm->card->widgets, list) {
  1107. if (!w->name || w->dapm != dapm)
  1108. continue;
  1109. d = debugfs_create_file(w->name, 0444,
  1110. dapm->debugfs_dapm, w,
  1111. &dapm_widget_power_fops);
  1112. if (!d)
  1113. dev_warn(w->dapm->dev,
  1114. "ASoC: Failed to create %s debugfs file\n",
  1115. w->name);
  1116. }
  1117. }
  1118. #else
  1119. void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm)
  1120. {
  1121. }
  1122. #endif
  1123. /* test and update the power status of a mux widget */
  1124. static int dapm_mux_update_power(struct snd_soc_dapm_widget *widget,
  1125. struct snd_kcontrol *kcontrol, int change,
  1126. int mux, struct soc_enum *e)
  1127. {
  1128. struct snd_soc_dapm_path *path;
  1129. int found = 0;
  1130. if (widget->id != snd_soc_dapm_mux &&
  1131. widget->id != snd_soc_dapm_virt_mux &&
  1132. widget->id != snd_soc_dapm_value_mux)
  1133. return -ENODEV;
  1134. if (!change)
  1135. return 0;
  1136. /* find dapm widget path assoc with kcontrol */
  1137. list_for_each_entry(path, &widget->dapm->card->paths, list) {
  1138. if (path->kcontrol != kcontrol)
  1139. continue;
  1140. if (!path->name || !e->texts[mux])
  1141. continue;
  1142. found = 1;
  1143. /* we now need to match the string in the enum to the path */
  1144. if (!(strcmp(path->name, e->texts[mux])))
  1145. path->connect = 1; /* new connection */
  1146. else
  1147. path->connect = 0; /* old connection must be powered down */
  1148. }
  1149. if (found)
  1150. dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP);
  1151. return 0;
  1152. }
  1153. /* test and update the power status of a mixer or switch widget */
  1154. static int dapm_mixer_update_power(struct snd_soc_dapm_widget *widget,
  1155. struct snd_kcontrol *kcontrol, int connect)
  1156. {
  1157. struct snd_soc_dapm_path *path;
  1158. int found = 0;
  1159. if (widget->id != snd_soc_dapm_mixer &&
  1160. widget->id != snd_soc_dapm_mixer_named_ctl &&
  1161. widget->id != snd_soc_dapm_switch)
  1162. return -ENODEV;
  1163. /* find dapm widget path assoc with kcontrol */
  1164. list_for_each_entry(path, &widget->dapm->card->paths, list) {
  1165. if (path->kcontrol != kcontrol)
  1166. continue;
  1167. /* found, now check type */
  1168. found = 1;
  1169. path->connect = connect;
  1170. break;
  1171. }
  1172. if (found)
  1173. dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP);
  1174. return 0;
  1175. }
  1176. /* show dapm widget status in sys fs */
  1177. static ssize_t dapm_widget_show(struct device *dev,
  1178. struct device_attribute *attr, char *buf)
  1179. {
  1180. struct snd_soc_pcm_runtime *rtd =
  1181. container_of(dev, struct snd_soc_pcm_runtime, dev);
  1182. struct snd_soc_codec *codec =rtd->codec;
  1183. struct snd_soc_dapm_widget *w;
  1184. int count = 0;
  1185. char *state = "not set";
  1186. list_for_each_entry(w, &codec->card->widgets, list) {
  1187. if (w->dapm != &codec->dapm)
  1188. continue;
  1189. /* only display widgets that burnm power */
  1190. switch (w->id) {
  1191. case snd_soc_dapm_hp:
  1192. case snd_soc_dapm_mic:
  1193. case snd_soc_dapm_spk:
  1194. case snd_soc_dapm_line:
  1195. case snd_soc_dapm_micbias:
  1196. case snd_soc_dapm_dac:
  1197. case snd_soc_dapm_adc:
  1198. case snd_soc_dapm_pga:
  1199. case snd_soc_dapm_out_drv:
  1200. case snd_soc_dapm_mixer:
  1201. case snd_soc_dapm_mixer_named_ctl:
  1202. case snd_soc_dapm_supply:
  1203. if (w->name)
  1204. count += sprintf(buf + count, "%s: %s\n",
  1205. w->name, w->power ? "On":"Off");
  1206. break;
  1207. default:
  1208. break;
  1209. }
  1210. }
  1211. switch (codec->dapm.bias_level) {
  1212. case SND_SOC_BIAS_ON:
  1213. state = "On";
  1214. break;
  1215. case SND_SOC_BIAS_PREPARE:
  1216. state = "Prepare";
  1217. break;
  1218. case SND_SOC_BIAS_STANDBY:
  1219. state = "Standby";
  1220. break;
  1221. case SND_SOC_BIAS_OFF:
  1222. state = "Off";
  1223. break;
  1224. }
  1225. count += sprintf(buf + count, "PM State: %s\n", state);
  1226. return count;
  1227. }
  1228. static DEVICE_ATTR(dapm_widget, 0444, dapm_widget_show, NULL);
  1229. int snd_soc_dapm_sys_add(struct device *dev)
  1230. {
  1231. return device_create_file(dev, &dev_attr_dapm_widget);
  1232. }
  1233. static void snd_soc_dapm_sys_remove(struct device *dev)
  1234. {
  1235. device_remove_file(dev, &dev_attr_dapm_widget);
  1236. }
  1237. /* free all dapm widgets and resources */
  1238. static void dapm_free_widgets(struct snd_soc_dapm_context *dapm)
  1239. {
  1240. struct snd_soc_dapm_widget *w, *next_w;
  1241. struct snd_soc_dapm_path *p, *next_p;
  1242. list_for_each_entry_safe(w, next_w, &dapm->card->widgets, list) {
  1243. if (w->dapm != dapm)
  1244. continue;
  1245. list_del(&w->list);
  1246. /*
  1247. * remove source and sink paths associated to this widget.
  1248. * While removing the path, remove reference to it from both
  1249. * source and sink widgets so that path is removed only once.
  1250. */
  1251. list_for_each_entry_safe(p, next_p, &w->sources, list_sink) {
  1252. list_del(&p->list_sink);
  1253. list_del(&p->list_source);
  1254. list_del(&p->list);
  1255. kfree(p->long_name);
  1256. kfree(p);
  1257. }
  1258. list_for_each_entry_safe(p, next_p, &w->sinks, list_source) {
  1259. list_del(&p->list_sink);
  1260. list_del(&p->list_source);
  1261. list_del(&p->list);
  1262. kfree(p->long_name);
  1263. kfree(p);
  1264. }
  1265. kfree(w->name);
  1266. kfree(w);
  1267. }
  1268. }
  1269. static int snd_soc_dapm_set_pin(struct snd_soc_dapm_context *dapm,
  1270. const char *pin, int status)
  1271. {
  1272. struct snd_soc_dapm_widget *w;
  1273. list_for_each_entry(w, &dapm->card->widgets, list) {
  1274. if (w->dapm != dapm)
  1275. continue;
  1276. if (!strcmp(w->name, pin)) {
  1277. dev_dbg(w->dapm->dev, "dapm: pin %s = %d\n",
  1278. pin, status);
  1279. w->connected = status;
  1280. /* Allow disabling of forced pins */
  1281. if (status == 0)
  1282. w->force = 0;
  1283. return 0;
  1284. }
  1285. }
  1286. dev_err(dapm->dev, "dapm: unknown pin %s\n", pin);
  1287. return -EINVAL;
  1288. }
  1289. /**
  1290. * snd_soc_dapm_sync - scan and power dapm paths
  1291. * @dapm: DAPM context
  1292. *
  1293. * Walks all dapm audio paths and powers widgets according to their
  1294. * stream or path usage.
  1295. *
  1296. * Returns 0 for success.
  1297. */
  1298. int snd_soc_dapm_sync(struct snd_soc_dapm_context *dapm)
  1299. {
  1300. return dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP);
  1301. }
  1302. EXPORT_SYMBOL_GPL(snd_soc_dapm_sync);
  1303. static int snd_soc_dapm_add_route(struct snd_soc_dapm_context *dapm,
  1304. const struct snd_soc_dapm_route *route)
  1305. {
  1306. struct snd_soc_dapm_path *path;
  1307. struct snd_soc_dapm_widget *wsource = NULL, *wsink = NULL, *w;
  1308. struct snd_soc_dapm_widget *wtsource = NULL, *wtsink = NULL;
  1309. const char *sink;
  1310. const char *control = route->control;
  1311. const char *source;
  1312. char prefixed_sink[80];
  1313. char prefixed_source[80];
  1314. int ret = 0;
  1315. if (dapm->codec && dapm->codec->name_prefix) {
  1316. snprintf(prefixed_sink, sizeof(prefixed_sink), "%s %s",
  1317. dapm->codec->name_prefix, route->sink);
  1318. sink = prefixed_sink;
  1319. snprintf(prefixed_source, sizeof(prefixed_source), "%s %s",
  1320. dapm->codec->name_prefix, route->source);
  1321. source = prefixed_source;
  1322. } else {
  1323. sink = route->sink;
  1324. source = route->source;
  1325. }
  1326. /*
  1327. * find src and dest widgets over all widgets but favor a widget from
  1328. * current DAPM context
  1329. */
  1330. list_for_each_entry(w, &dapm->card->widgets, list) {
  1331. if (!wsink && !(strcmp(w->name, sink))) {
  1332. wtsink = w;
  1333. if (w->dapm == dapm)
  1334. wsink = w;
  1335. continue;
  1336. }
  1337. if (!wsource && !(strcmp(w->name, source))) {
  1338. wtsource = w;
  1339. if (w->dapm == dapm)
  1340. wsource = w;
  1341. }
  1342. }
  1343. /* use widget from another DAPM context if not found from this */
  1344. if (!wsink)
  1345. wsink = wtsink;
  1346. if (!wsource)
  1347. wsource = wtsource;
  1348. if (wsource == NULL || wsink == NULL)
  1349. return -ENODEV;
  1350. path = kzalloc(sizeof(struct snd_soc_dapm_path), GFP_KERNEL);
  1351. if (!path)
  1352. return -ENOMEM;
  1353. path->source = wsource;
  1354. path->sink = wsink;
  1355. path->connected = route->connected;
  1356. INIT_LIST_HEAD(&path->list);
  1357. INIT_LIST_HEAD(&path->list_source);
  1358. INIT_LIST_HEAD(&path->list_sink);
  1359. /* check for external widgets */
  1360. if (wsink->id == snd_soc_dapm_input) {
  1361. if (wsource->id == snd_soc_dapm_micbias ||
  1362. wsource->id == snd_soc_dapm_mic ||
  1363. wsource->id == snd_soc_dapm_line ||
  1364. wsource->id == snd_soc_dapm_output)
  1365. wsink->ext = 1;
  1366. }
  1367. if (wsource->id == snd_soc_dapm_output) {
  1368. if (wsink->id == snd_soc_dapm_spk ||
  1369. wsink->id == snd_soc_dapm_hp ||
  1370. wsink->id == snd_soc_dapm_line ||
  1371. wsink->id == snd_soc_dapm_input)
  1372. wsource->ext = 1;
  1373. }
  1374. /* connect static paths */
  1375. if (control == NULL) {
  1376. list_add(&path->list, &dapm->card->paths);
  1377. list_add(&path->list_sink, &wsink->sources);
  1378. list_add(&path->list_source, &wsource->sinks);
  1379. path->connect = 1;
  1380. return 0;
  1381. }
  1382. /* connect dynamic paths */
  1383. switch(wsink->id) {
  1384. case snd_soc_dapm_adc:
  1385. case snd_soc_dapm_dac:
  1386. case snd_soc_dapm_pga:
  1387. case snd_soc_dapm_out_drv:
  1388. case snd_soc_dapm_input:
  1389. case snd_soc_dapm_output:
  1390. case snd_soc_dapm_micbias:
  1391. case snd_soc_dapm_vmid:
  1392. case snd_soc_dapm_pre:
  1393. case snd_soc_dapm_post:
  1394. case snd_soc_dapm_supply:
  1395. case snd_soc_dapm_aif_in:
  1396. case snd_soc_dapm_aif_out:
  1397. list_add(&path->list, &dapm->card->paths);
  1398. list_add(&path->list_sink, &wsink->sources);
  1399. list_add(&path->list_source, &wsource->sinks);
  1400. path->connect = 1;
  1401. return 0;
  1402. case snd_soc_dapm_mux:
  1403. case snd_soc_dapm_virt_mux:
  1404. case snd_soc_dapm_value_mux:
  1405. ret = dapm_connect_mux(dapm, wsource, wsink, path, control,
  1406. &wsink->kcontrols[0]);
  1407. if (ret != 0)
  1408. goto err;
  1409. break;
  1410. case snd_soc_dapm_switch:
  1411. case snd_soc_dapm_mixer:
  1412. case snd_soc_dapm_mixer_named_ctl:
  1413. ret = dapm_connect_mixer(dapm, wsource, wsink, path, control);
  1414. if (ret != 0)
  1415. goto err;
  1416. break;
  1417. case snd_soc_dapm_hp:
  1418. case snd_soc_dapm_mic:
  1419. case snd_soc_dapm_line:
  1420. case snd_soc_dapm_spk:
  1421. list_add(&path->list, &dapm->card->paths);
  1422. list_add(&path->list_sink, &wsink->sources);
  1423. list_add(&path->list_source, &wsource->sinks);
  1424. path->connect = 0;
  1425. return 0;
  1426. }
  1427. return 0;
  1428. err:
  1429. dev_warn(dapm->dev, "asoc: no dapm match for %s --> %s --> %s\n",
  1430. source, control, sink);
  1431. kfree(path);
  1432. return ret;
  1433. }
  1434. /**
  1435. * snd_soc_dapm_add_routes - Add routes between DAPM widgets
  1436. * @dapm: DAPM context
  1437. * @route: audio routes
  1438. * @num: number of routes
  1439. *
  1440. * Connects 2 dapm widgets together via a named audio path. The sink is
  1441. * the widget receiving the audio signal, whilst the source is the sender
  1442. * of the audio signal.
  1443. *
  1444. * Returns 0 for success else error. On error all resources can be freed
  1445. * with a call to snd_soc_card_free().
  1446. */
  1447. int snd_soc_dapm_add_routes(struct snd_soc_dapm_context *dapm,
  1448. const struct snd_soc_dapm_route *route, int num)
  1449. {
  1450. int i, ret;
  1451. for (i = 0; i < num; i++) {
  1452. ret = snd_soc_dapm_add_route(dapm, route);
  1453. if (ret < 0) {
  1454. dev_err(dapm->dev, "Failed to add route %s->%s\n",
  1455. route->source, route->sink);
  1456. return ret;
  1457. }
  1458. route++;
  1459. }
  1460. return 0;
  1461. }
  1462. EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes);
  1463. /**
  1464. * snd_soc_dapm_new_widgets - add new dapm widgets
  1465. * @dapm: DAPM context
  1466. *
  1467. * Checks the codec for any new dapm widgets and creates them if found.
  1468. *
  1469. * Returns 0 for success.
  1470. */
  1471. int snd_soc_dapm_new_widgets(struct snd_soc_dapm_context *dapm)
  1472. {
  1473. struct snd_soc_dapm_widget *w;
  1474. unsigned int val;
  1475. list_for_each_entry(w, &dapm->card->widgets, list)
  1476. {
  1477. if (w->new)
  1478. continue;
  1479. switch(w->id) {
  1480. case snd_soc_dapm_switch:
  1481. case snd_soc_dapm_mixer:
  1482. case snd_soc_dapm_mixer_named_ctl:
  1483. w->power_check = dapm_generic_check_power;
  1484. dapm_new_mixer(dapm, w);
  1485. break;
  1486. case snd_soc_dapm_mux:
  1487. case snd_soc_dapm_virt_mux:
  1488. case snd_soc_dapm_value_mux:
  1489. w->power_check = dapm_generic_check_power;
  1490. dapm_new_mux(dapm, w);
  1491. break;
  1492. case snd_soc_dapm_adc:
  1493. case snd_soc_dapm_aif_out:
  1494. w->power_check = dapm_adc_check_power;
  1495. break;
  1496. case snd_soc_dapm_dac:
  1497. case snd_soc_dapm_aif_in:
  1498. w->power_check = dapm_dac_check_power;
  1499. break;
  1500. case snd_soc_dapm_pga:
  1501. case snd_soc_dapm_out_drv:
  1502. w->power_check = dapm_generic_check_power;
  1503. dapm_new_pga(dapm, w);
  1504. break;
  1505. case snd_soc_dapm_input:
  1506. case snd_soc_dapm_output:
  1507. case snd_soc_dapm_micbias:
  1508. case snd_soc_dapm_spk:
  1509. case snd_soc_dapm_hp:
  1510. case snd_soc_dapm_mic:
  1511. case snd_soc_dapm_line:
  1512. w->power_check = dapm_generic_check_power;
  1513. break;
  1514. case snd_soc_dapm_supply:
  1515. w->power_check = dapm_supply_check_power;
  1516. case snd_soc_dapm_vmid:
  1517. case snd_soc_dapm_pre:
  1518. case snd_soc_dapm_post:
  1519. break;
  1520. }
  1521. /* Read the initial power state from the device */
  1522. if (w->reg >= 0) {
  1523. val = snd_soc_read(w->codec, w->reg);
  1524. val &= 1 << w->shift;
  1525. if (w->invert)
  1526. val = !val;
  1527. if (val)
  1528. w->power = 1;
  1529. }
  1530. w->new = 1;
  1531. }
  1532. dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP);
  1533. return 0;
  1534. }
  1535. EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets);
  1536. /**
  1537. * snd_soc_dapm_get_volsw - dapm mixer get callback
  1538. * @kcontrol: mixer control
  1539. * @ucontrol: control element information
  1540. *
  1541. * Callback to get the value of a dapm mixer control.
  1542. *
  1543. * Returns 0 for success.
  1544. */
  1545. int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol,
  1546. struct snd_ctl_elem_value *ucontrol)
  1547. {
  1548. struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
  1549. struct soc_mixer_control *mc =
  1550. (struct soc_mixer_control *)kcontrol->private_value;
  1551. unsigned int reg = mc->reg;
  1552. unsigned int shift = mc->shift;
  1553. unsigned int rshift = mc->rshift;
  1554. int max = mc->max;
  1555. unsigned int invert = mc->invert;
  1556. unsigned int mask = (1 << fls(max)) - 1;
  1557. ucontrol->value.integer.value[0] =
  1558. (snd_soc_read(widget->codec, reg) >> shift) & mask;
  1559. if (shift != rshift)
  1560. ucontrol->value.integer.value[1] =
  1561. (snd_soc_read(widget->codec, reg) >> rshift) & mask;
  1562. if (invert) {
  1563. ucontrol->value.integer.value[0] =
  1564. max - ucontrol->value.integer.value[0];
  1565. if (shift != rshift)
  1566. ucontrol->value.integer.value[1] =
  1567. max - ucontrol->value.integer.value[1];
  1568. }
  1569. return 0;
  1570. }
  1571. EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw);
  1572. /**
  1573. * snd_soc_dapm_put_volsw - dapm mixer set callback
  1574. * @kcontrol: mixer control
  1575. * @ucontrol: control element information
  1576. *
  1577. * Callback to set the value of a dapm mixer control.
  1578. *
  1579. * Returns 0 for success.
  1580. */
  1581. int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol,
  1582. struct snd_ctl_elem_value *ucontrol)
  1583. {
  1584. struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
  1585. struct soc_mixer_control *mc =
  1586. (struct soc_mixer_control *)kcontrol->private_value;
  1587. unsigned int reg = mc->reg;
  1588. unsigned int shift = mc->shift;
  1589. int max = mc->max;
  1590. unsigned int mask = (1 << fls(max)) - 1;
  1591. unsigned int invert = mc->invert;
  1592. unsigned int val;
  1593. int connect, change;
  1594. struct snd_soc_dapm_update update;
  1595. val = (ucontrol->value.integer.value[0] & mask);
  1596. if (invert)
  1597. val = max - val;
  1598. mask = mask << shift;
  1599. val = val << shift;
  1600. mutex_lock(&widget->codec->mutex);
  1601. widget->value = val;
  1602. change = snd_soc_test_bits(widget->codec, reg, mask, val);
  1603. if (change) {
  1604. if (val)
  1605. /* new connection */
  1606. connect = invert ? 0:1;
  1607. else
  1608. /* old connection must be powered down */
  1609. connect = invert ? 1:0;
  1610. update.kcontrol = kcontrol;
  1611. update.widget = widget;
  1612. update.reg = reg;
  1613. update.mask = mask;
  1614. update.val = val;
  1615. widget->dapm->update = &update;
  1616. dapm_mixer_update_power(widget, kcontrol, connect);
  1617. widget->dapm->update = NULL;
  1618. }
  1619. mutex_unlock(&widget->codec->mutex);
  1620. return 0;
  1621. }
  1622. EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw);
  1623. /**
  1624. * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback
  1625. * @kcontrol: mixer control
  1626. * @ucontrol: control element information
  1627. *
  1628. * Callback to get the value of a dapm enumerated double mixer control.
  1629. *
  1630. * Returns 0 for success.
  1631. */
  1632. int snd_soc_dapm_get_enum_double(struct snd_kcontrol *kcontrol,
  1633. struct snd_ctl_elem_value *ucontrol)
  1634. {
  1635. struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
  1636. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  1637. unsigned int val, bitmask;
  1638. for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
  1639. ;
  1640. val = snd_soc_read(widget->codec, e->reg);
  1641. ucontrol->value.enumerated.item[0] = (val >> e->shift_l) & (bitmask - 1);
  1642. if (e->shift_l != e->shift_r)
  1643. ucontrol->value.enumerated.item[1] =
  1644. (val >> e->shift_r) & (bitmask - 1);
  1645. return 0;
  1646. }
  1647. EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double);
  1648. /**
  1649. * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback
  1650. * @kcontrol: mixer control
  1651. * @ucontrol: control element information
  1652. *
  1653. * Callback to set the value of a dapm enumerated double mixer control.
  1654. *
  1655. * Returns 0 for success.
  1656. */
  1657. int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol,
  1658. struct snd_ctl_elem_value *ucontrol)
  1659. {
  1660. struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
  1661. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  1662. unsigned int val, mux, change;
  1663. unsigned int mask, bitmask;
  1664. struct snd_soc_dapm_update update;
  1665. for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
  1666. ;
  1667. if (ucontrol->value.enumerated.item[0] > e->max - 1)
  1668. return -EINVAL;
  1669. mux = ucontrol->value.enumerated.item[0];
  1670. val = mux << e->shift_l;
  1671. mask = (bitmask - 1) << e->shift_l;
  1672. if (e->shift_l != e->shift_r) {
  1673. if (ucontrol->value.enumerated.item[1] > e->max - 1)
  1674. return -EINVAL;
  1675. val |= ucontrol->value.enumerated.item[1] << e->shift_r;
  1676. mask |= (bitmask - 1) << e->shift_r;
  1677. }
  1678. mutex_lock(&widget->codec->mutex);
  1679. widget->value = val;
  1680. change = snd_soc_test_bits(widget->codec, e->reg, mask, val);
  1681. update.kcontrol = kcontrol;
  1682. update.widget = widget;
  1683. update.reg = e->reg;
  1684. update.mask = mask;
  1685. update.val = val;
  1686. widget->dapm->update = &update;
  1687. dapm_mux_update_power(widget, kcontrol, change, mux, e);
  1688. widget->dapm->update = NULL;
  1689. mutex_unlock(&widget->codec->mutex);
  1690. return change;
  1691. }
  1692. EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double);
  1693. /**
  1694. * snd_soc_dapm_get_enum_virt - Get virtual DAPM mux
  1695. * @kcontrol: mixer control
  1696. * @ucontrol: control element information
  1697. *
  1698. * Returns 0 for success.
  1699. */
  1700. int snd_soc_dapm_get_enum_virt(struct snd_kcontrol *kcontrol,
  1701. struct snd_ctl_elem_value *ucontrol)
  1702. {
  1703. struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
  1704. ucontrol->value.enumerated.item[0] = widget->value;
  1705. return 0;
  1706. }
  1707. EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_virt);
  1708. /**
  1709. * snd_soc_dapm_put_enum_virt - Set virtual DAPM mux
  1710. * @kcontrol: mixer control
  1711. * @ucontrol: control element information
  1712. *
  1713. * Returns 0 for success.
  1714. */
  1715. int snd_soc_dapm_put_enum_virt(struct snd_kcontrol *kcontrol,
  1716. struct snd_ctl_elem_value *ucontrol)
  1717. {
  1718. struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
  1719. struct soc_enum *e =
  1720. (struct soc_enum *)kcontrol->private_value;
  1721. int change;
  1722. int ret = 0;
  1723. if (ucontrol->value.enumerated.item[0] >= e->max)
  1724. return -EINVAL;
  1725. mutex_lock(&widget->codec->mutex);
  1726. change = widget->value != ucontrol->value.enumerated.item[0];
  1727. widget->value = ucontrol->value.enumerated.item[0];
  1728. dapm_mux_update_power(widget, kcontrol, change, widget->value, e);
  1729. mutex_unlock(&widget->codec->mutex);
  1730. return ret;
  1731. }
  1732. EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_virt);
  1733. /**
  1734. * snd_soc_dapm_get_value_enum_double - dapm semi enumerated double mixer get
  1735. * callback
  1736. * @kcontrol: mixer control
  1737. * @ucontrol: control element information
  1738. *
  1739. * Callback to get the value of a dapm semi enumerated double mixer control.
  1740. *
  1741. * Semi enumerated mixer: the enumerated items are referred as values. Can be
  1742. * used for handling bitfield coded enumeration for example.
  1743. *
  1744. * Returns 0 for success.
  1745. */
  1746. int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol *kcontrol,
  1747. struct snd_ctl_elem_value *ucontrol)
  1748. {
  1749. struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
  1750. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  1751. unsigned int reg_val, val, mux;
  1752. reg_val = snd_soc_read(widget->codec, e->reg);
  1753. val = (reg_val >> e->shift_l) & e->mask;
  1754. for (mux = 0; mux < e->max; mux++) {
  1755. if (val == e->values[mux])
  1756. break;
  1757. }
  1758. ucontrol->value.enumerated.item[0] = mux;
  1759. if (e->shift_l != e->shift_r) {
  1760. val = (reg_val >> e->shift_r) & e->mask;
  1761. for (mux = 0; mux < e->max; mux++) {
  1762. if (val == e->values[mux])
  1763. break;
  1764. }
  1765. ucontrol->value.enumerated.item[1] = mux;
  1766. }
  1767. return 0;
  1768. }
  1769. EXPORT_SYMBOL_GPL(snd_soc_dapm_get_value_enum_double);
  1770. /**
  1771. * snd_soc_dapm_put_value_enum_double - dapm semi enumerated double mixer set
  1772. * callback
  1773. * @kcontrol: mixer control
  1774. * @ucontrol: control element information
  1775. *
  1776. * Callback to set the value of a dapm semi enumerated double mixer control.
  1777. *
  1778. * Semi enumerated mixer: the enumerated items are referred as values. Can be
  1779. * used for handling bitfield coded enumeration for example.
  1780. *
  1781. * Returns 0 for success.
  1782. */
  1783. int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol *kcontrol,
  1784. struct snd_ctl_elem_value *ucontrol)
  1785. {
  1786. struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
  1787. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  1788. unsigned int val, mux, change;
  1789. unsigned int mask;
  1790. struct snd_soc_dapm_update update;
  1791. if (ucontrol->value.enumerated.item[0] > e->max - 1)
  1792. return -EINVAL;
  1793. mux = ucontrol->value.enumerated.item[0];
  1794. val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l;
  1795. mask = e->mask << e->shift_l;
  1796. if (e->shift_l != e->shift_r) {
  1797. if (ucontrol->value.enumerated.item[1] > e->max - 1)
  1798. return -EINVAL;
  1799. val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r;
  1800. mask |= e->mask << e->shift_r;
  1801. }
  1802. mutex_lock(&widget->codec->mutex);
  1803. widget->value = val;
  1804. change = snd_soc_test_bits(widget->codec, e->reg, mask, val);
  1805. update.kcontrol = kcontrol;
  1806. update.widget = widget;
  1807. update.reg = e->reg;
  1808. update.mask = mask;
  1809. update.val = val;
  1810. widget->dapm->update = &update;
  1811. dapm_mux_update_power(widget, kcontrol, change, mux, e);
  1812. widget->dapm->update = NULL;
  1813. mutex_unlock(&widget->codec->mutex);
  1814. return change;
  1815. }
  1816. EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double);
  1817. /**
  1818. * snd_soc_dapm_info_pin_switch - Info for a pin switch
  1819. *
  1820. * @kcontrol: mixer control
  1821. * @uinfo: control element information
  1822. *
  1823. * Callback to provide information about a pin switch control.
  1824. */
  1825. int snd_soc_dapm_info_pin_switch(struct snd_kcontrol *kcontrol,
  1826. struct snd_ctl_elem_info *uinfo)
  1827. {
  1828. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  1829. uinfo->count = 1;
  1830. uinfo->value.integer.min = 0;
  1831. uinfo->value.integer.max = 1;
  1832. return 0;
  1833. }
  1834. EXPORT_SYMBOL_GPL(snd_soc_dapm_info_pin_switch);
  1835. /**
  1836. * snd_soc_dapm_get_pin_switch - Get information for a pin switch
  1837. *
  1838. * @kcontrol: mixer control
  1839. * @ucontrol: Value
  1840. */
  1841. int snd_soc_dapm_get_pin_switch(struct snd_kcontrol *kcontrol,
  1842. struct snd_ctl_elem_value *ucontrol)
  1843. {
  1844. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  1845. const char *pin = (const char *)kcontrol->private_value;
  1846. mutex_lock(&codec->mutex);
  1847. ucontrol->value.integer.value[0] =
  1848. snd_soc_dapm_get_pin_status(&codec->dapm, pin);
  1849. mutex_unlock(&codec->mutex);
  1850. return 0;
  1851. }
  1852. EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_switch);
  1853. /**
  1854. * snd_soc_dapm_put_pin_switch - Set information for a pin switch
  1855. *
  1856. * @kcontrol: mixer control
  1857. * @ucontrol: Value
  1858. */
  1859. int snd_soc_dapm_put_pin_switch(struct snd_kcontrol *kcontrol,
  1860. struct snd_ctl_elem_value *ucontrol)
  1861. {
  1862. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  1863. const char *pin = (const char *)kcontrol->private_value;
  1864. mutex_lock(&codec->mutex);
  1865. if (ucontrol->value.integer.value[0])
  1866. snd_soc_dapm_enable_pin(&codec->dapm, pin);
  1867. else
  1868. snd_soc_dapm_disable_pin(&codec->dapm, pin);
  1869. snd_soc_dapm_sync(&codec->dapm);
  1870. mutex_unlock(&codec->mutex);
  1871. return 0;
  1872. }
  1873. EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch);
  1874. /**
  1875. * snd_soc_dapm_new_control - create new dapm control
  1876. * @dapm: DAPM context
  1877. * @widget: widget template
  1878. *
  1879. * Creates a new dapm control based upon the template.
  1880. *
  1881. * Returns 0 for success else error.
  1882. */
  1883. int snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm,
  1884. const struct snd_soc_dapm_widget *widget)
  1885. {
  1886. struct snd_soc_dapm_widget *w;
  1887. size_t name_len;
  1888. if ((w = dapm_cnew_widget(widget)) == NULL)
  1889. return -ENOMEM;
  1890. name_len = strlen(widget->name) + 1;
  1891. if (dapm->codec && dapm->codec->name_prefix)
  1892. name_len += 1 + strlen(dapm->codec->name_prefix);
  1893. w->name = kmalloc(name_len, GFP_KERNEL);
  1894. if (w->name == NULL) {
  1895. kfree(w);
  1896. return -ENOMEM;
  1897. }
  1898. if (dapm->codec && dapm->codec->name_prefix)
  1899. snprintf(w->name, name_len, "%s %s",
  1900. dapm->codec->name_prefix, widget->name);
  1901. else
  1902. snprintf(w->name, name_len, "%s", widget->name);
  1903. dapm->n_widgets++;
  1904. w->dapm = dapm;
  1905. w->codec = dapm->codec;
  1906. INIT_LIST_HEAD(&w->sources);
  1907. INIT_LIST_HEAD(&w->sinks);
  1908. INIT_LIST_HEAD(&w->list);
  1909. list_add(&w->list, &dapm->card->widgets);
  1910. /* machine layer set ups unconnected pins and insertions */
  1911. w->connected = 1;
  1912. return 0;
  1913. }
  1914. EXPORT_SYMBOL_GPL(snd_soc_dapm_new_control);
  1915. /**
  1916. * snd_soc_dapm_new_controls - create new dapm controls
  1917. * @dapm: DAPM context
  1918. * @widget: widget array
  1919. * @num: number of widgets
  1920. *
  1921. * Creates new DAPM controls based upon the templates.
  1922. *
  1923. * Returns 0 for success else error.
  1924. */
  1925. int snd_soc_dapm_new_controls(struct snd_soc_dapm_context *dapm,
  1926. const struct snd_soc_dapm_widget *widget,
  1927. int num)
  1928. {
  1929. int i, ret;
  1930. for (i = 0; i < num; i++) {
  1931. ret = snd_soc_dapm_new_control(dapm, widget);
  1932. if (ret < 0) {
  1933. dev_err(dapm->dev,
  1934. "ASoC: Failed to create DAPM control %s: %d\n",
  1935. widget->name, ret);
  1936. return ret;
  1937. }
  1938. widget++;
  1939. }
  1940. return 0;
  1941. }
  1942. EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls);
  1943. static void soc_dapm_stream_event(struct snd_soc_dapm_context *dapm,
  1944. const char *stream, int event)
  1945. {
  1946. struct snd_soc_dapm_widget *w;
  1947. list_for_each_entry(w, &dapm->card->widgets, list)
  1948. {
  1949. if (!w->sname || w->dapm != dapm)
  1950. continue;
  1951. dev_dbg(w->dapm->dev, "widget %s\n %s stream %s event %d\n",
  1952. w->name, w->sname, stream, event);
  1953. if (strstr(w->sname, stream)) {
  1954. switch(event) {
  1955. case SND_SOC_DAPM_STREAM_START:
  1956. w->active = 1;
  1957. break;
  1958. case SND_SOC_DAPM_STREAM_STOP:
  1959. w->active = 0;
  1960. break;
  1961. case SND_SOC_DAPM_STREAM_SUSPEND:
  1962. case SND_SOC_DAPM_STREAM_RESUME:
  1963. case SND_SOC_DAPM_STREAM_PAUSE_PUSH:
  1964. case SND_SOC_DAPM_STREAM_PAUSE_RELEASE:
  1965. break;
  1966. }
  1967. }
  1968. }
  1969. dapm_power_widgets(dapm, event);
  1970. }
  1971. /**
  1972. * snd_soc_dapm_stream_event - send a stream event to the dapm core
  1973. * @rtd: PCM runtime data
  1974. * @stream: stream name
  1975. * @event: stream event
  1976. *
  1977. * Sends a stream event to the dapm core. The core then makes any
  1978. * necessary widget power changes.
  1979. *
  1980. * Returns 0 for success else error.
  1981. */
  1982. int snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd,
  1983. const char *stream, int event)
  1984. {
  1985. struct snd_soc_codec *codec = rtd->codec;
  1986. if (stream == NULL)
  1987. return 0;
  1988. mutex_lock(&codec->mutex);
  1989. soc_dapm_stream_event(&codec->dapm, stream, event);
  1990. mutex_unlock(&codec->mutex);
  1991. return 0;
  1992. }
  1993. /**
  1994. * snd_soc_dapm_enable_pin - enable pin.
  1995. * @dapm: DAPM context
  1996. * @pin: pin name
  1997. *
  1998. * Enables input/output pin and its parents or children widgets iff there is
  1999. * a valid audio route and active audio stream.
  2000. * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
  2001. * do any widget power switching.
  2002. */
  2003. int snd_soc_dapm_enable_pin(struct snd_soc_dapm_context *dapm, const char *pin)
  2004. {
  2005. return snd_soc_dapm_set_pin(dapm, pin, 1);
  2006. }
  2007. EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin);
  2008. /**
  2009. * snd_soc_dapm_force_enable_pin - force a pin to be enabled
  2010. * @dapm: DAPM context
  2011. * @pin: pin name
  2012. *
  2013. * Enables input/output pin regardless of any other state. This is
  2014. * intended for use with microphone bias supplies used in microphone
  2015. * jack detection.
  2016. *
  2017. * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
  2018. * do any widget power switching.
  2019. */
  2020. int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context *dapm,
  2021. const char *pin)
  2022. {
  2023. struct snd_soc_dapm_widget *w;
  2024. list_for_each_entry(w, &dapm->card->widgets, list) {
  2025. if (w->dapm != dapm)
  2026. continue;
  2027. if (!strcmp(w->name, pin)) {
  2028. dev_dbg(w->dapm->dev,
  2029. "dapm: force enable pin %s\n", pin);
  2030. w->connected = 1;
  2031. w->force = 1;
  2032. return 0;
  2033. }
  2034. }
  2035. dev_err(dapm->dev, "dapm: unknown pin %s\n", pin);
  2036. return -EINVAL;
  2037. }
  2038. EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin);
  2039. /**
  2040. * snd_soc_dapm_disable_pin - disable pin.
  2041. * @dapm: DAPM context
  2042. * @pin: pin name
  2043. *
  2044. * Disables input/output pin and its parents or children widgets.
  2045. * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
  2046. * do any widget power switching.
  2047. */
  2048. int snd_soc_dapm_disable_pin(struct snd_soc_dapm_context *dapm,
  2049. const char *pin)
  2050. {
  2051. return snd_soc_dapm_set_pin(dapm, pin, 0);
  2052. }
  2053. EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin);
  2054. /**
  2055. * snd_soc_dapm_nc_pin - permanently disable pin.
  2056. * @dapm: DAPM context
  2057. * @pin: pin name
  2058. *
  2059. * Marks the specified pin as being not connected, disabling it along
  2060. * any parent or child widgets. At present this is identical to
  2061. * snd_soc_dapm_disable_pin() but in future it will be extended to do
  2062. * additional things such as disabling controls which only affect
  2063. * paths through the pin.
  2064. *
  2065. * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
  2066. * do any widget power switching.
  2067. */
  2068. int snd_soc_dapm_nc_pin(struct snd_soc_dapm_context *dapm, const char *pin)
  2069. {
  2070. return snd_soc_dapm_set_pin(dapm, pin, 0);
  2071. }
  2072. EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin);
  2073. /**
  2074. * snd_soc_dapm_get_pin_status - get audio pin status
  2075. * @dapm: DAPM context
  2076. * @pin: audio signal pin endpoint (or start point)
  2077. *
  2078. * Get audio pin status - connected or disconnected.
  2079. *
  2080. * Returns 1 for connected otherwise 0.
  2081. */
  2082. int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context *dapm,
  2083. const char *pin)
  2084. {
  2085. struct snd_soc_dapm_widget *w;
  2086. list_for_each_entry(w, &dapm->card->widgets, list) {
  2087. if (w->dapm != dapm)
  2088. continue;
  2089. if (!strcmp(w->name, pin))
  2090. return w->connected;
  2091. }
  2092. return 0;
  2093. }
  2094. EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status);
  2095. /**
  2096. * snd_soc_dapm_ignore_suspend - ignore suspend status for DAPM endpoint
  2097. * @dapm: DAPM context
  2098. * @pin: audio signal pin endpoint (or start point)
  2099. *
  2100. * Mark the given endpoint or pin as ignoring suspend. When the
  2101. * system is disabled a path between two endpoints flagged as ignoring
  2102. * suspend will not be disabled. The path must already be enabled via
  2103. * normal means at suspend time, it will not be turned on if it was not
  2104. * already enabled.
  2105. */
  2106. int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context *dapm,
  2107. const char *pin)
  2108. {
  2109. struct snd_soc_dapm_widget *w;
  2110. list_for_each_entry(w, &dapm->card->widgets, list) {
  2111. if (w->dapm != dapm)
  2112. continue;
  2113. if (!strcmp(w->name, pin)) {
  2114. w->ignore_suspend = 1;
  2115. return 0;
  2116. }
  2117. }
  2118. dev_err(dapm->dev, "dapm: unknown pin %s\n", pin);
  2119. return -EINVAL;
  2120. }
  2121. EXPORT_SYMBOL_GPL(snd_soc_dapm_ignore_suspend);
  2122. /**
  2123. * snd_soc_dapm_free - free dapm resources
  2124. * @card: SoC device
  2125. *
  2126. * Free all dapm widgets and resources.
  2127. */
  2128. void snd_soc_dapm_free(struct snd_soc_dapm_context *dapm)
  2129. {
  2130. snd_soc_dapm_sys_remove(dapm->dev);
  2131. dapm_free_widgets(dapm);
  2132. list_del(&dapm->list);
  2133. }
  2134. EXPORT_SYMBOL_GPL(snd_soc_dapm_free);
  2135. static void soc_dapm_shutdown_codec(struct snd_soc_dapm_context *dapm)
  2136. {
  2137. struct snd_soc_dapm_widget *w;
  2138. LIST_HEAD(down_list);
  2139. int powerdown = 0;
  2140. list_for_each_entry(w, &dapm->card->widgets, list) {
  2141. if (w->dapm != dapm)
  2142. continue;
  2143. if (w->power) {
  2144. dapm_seq_insert(w, &down_list, false);
  2145. w->power = 0;
  2146. powerdown = 1;
  2147. }
  2148. }
  2149. /* If there were no widgets to power down we're already in
  2150. * standby.
  2151. */
  2152. if (powerdown) {
  2153. snd_soc_dapm_set_bias_level(dapm, SND_SOC_BIAS_PREPARE);
  2154. dapm_seq_run(dapm, &down_list, 0, false);
  2155. snd_soc_dapm_set_bias_level(dapm, SND_SOC_BIAS_STANDBY);
  2156. }
  2157. }
  2158. /*
  2159. * snd_soc_dapm_shutdown - callback for system shutdown
  2160. */
  2161. void snd_soc_dapm_shutdown(struct snd_soc_card *card)
  2162. {
  2163. struct snd_soc_codec *codec;
  2164. list_for_each_entry(codec, &card->codec_dev_list, list) {
  2165. soc_dapm_shutdown_codec(&codec->dapm);
  2166. snd_soc_dapm_set_bias_level(&codec->dapm, SND_SOC_BIAS_OFF);
  2167. }
  2168. }
  2169. /* Module information */
  2170. MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
  2171. MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC");
  2172. MODULE_LICENSE("GPL");