soc-dapm.c 77 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149
  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/headphone 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 power down of audio subsystem to reduce pops between a quick
  22. * device reopen.
  23. *
  24. */
  25. #include <linux/module.h>
  26. #include <linux/moduleparam.h>
  27. #include <linux/init.h>
  28. #include <linux/async.h>
  29. #include <linux/delay.h>
  30. #include <linux/pm.h>
  31. #include <linux/bitops.h>
  32. #include <linux/platform_device.h>
  33. #include <linux/jiffies.h>
  34. #include <linux/debugfs.h>
  35. #include <linux/pm_runtime.h>
  36. #include <linux/regulator/consumer.h>
  37. #include <linux/slab.h>
  38. #include <sound/core.h>
  39. #include <sound/pcm.h>
  40. #include <sound/pcm_params.h>
  41. #include <sound/soc.h>
  42. #include <sound/initval.h>
  43. #include <trace/events/asoc.h>
  44. #define DAPM_UPDATE_STAT(widget, val) widget->dapm->card->dapm_stats.val++;
  45. /* dapm power sequences - make this per codec in the future */
  46. static int dapm_up_seq[] = {
  47. [snd_soc_dapm_pre] = 0,
  48. [snd_soc_dapm_supply] = 1,
  49. [snd_soc_dapm_regulator_supply] = 1,
  50. [snd_soc_dapm_micbias] = 2,
  51. [snd_soc_dapm_aif_in] = 3,
  52. [snd_soc_dapm_aif_out] = 3,
  53. [snd_soc_dapm_mic] = 4,
  54. [snd_soc_dapm_mux] = 5,
  55. [snd_soc_dapm_virt_mux] = 5,
  56. [snd_soc_dapm_value_mux] = 5,
  57. [snd_soc_dapm_dac] = 6,
  58. [snd_soc_dapm_mixer] = 7,
  59. [snd_soc_dapm_mixer_named_ctl] = 7,
  60. [snd_soc_dapm_pga] = 8,
  61. [snd_soc_dapm_adc] = 9,
  62. [snd_soc_dapm_out_drv] = 10,
  63. [snd_soc_dapm_hp] = 10,
  64. [snd_soc_dapm_spk] = 10,
  65. [snd_soc_dapm_post] = 11,
  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] = 2,
  72. [snd_soc_dapm_out_drv] = 2,
  73. [snd_soc_dapm_pga] = 4,
  74. [snd_soc_dapm_mixer_named_ctl] = 5,
  75. [snd_soc_dapm_mixer] = 5,
  76. [snd_soc_dapm_dac] = 6,
  77. [snd_soc_dapm_mic] = 7,
  78. [snd_soc_dapm_micbias] = 8,
  79. [snd_soc_dapm_mux] = 9,
  80. [snd_soc_dapm_virt_mux] = 9,
  81. [snd_soc_dapm_value_mux] = 9,
  82. [snd_soc_dapm_aif_in] = 10,
  83. [snd_soc_dapm_aif_out] = 10,
  84. [snd_soc_dapm_regulator_supply] = 11,
  85. [snd_soc_dapm_supply] = 11,
  86. [snd_soc_dapm_post] = 12,
  87. };
  88. static void pop_wait(u32 pop_time)
  89. {
  90. if (pop_time)
  91. schedule_timeout_uninterruptible(msecs_to_jiffies(pop_time));
  92. }
  93. static void pop_dbg(struct device *dev, u32 pop_time, const char *fmt, ...)
  94. {
  95. va_list args;
  96. char *buf;
  97. if (!pop_time)
  98. return;
  99. buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
  100. if (buf == NULL)
  101. return;
  102. va_start(args, fmt);
  103. vsnprintf(buf, PAGE_SIZE, fmt, args);
  104. dev_info(dev, "%s", buf);
  105. va_end(args);
  106. kfree(buf);
  107. }
  108. static bool dapm_dirty_widget(struct snd_soc_dapm_widget *w)
  109. {
  110. return !list_empty(&w->dirty);
  111. }
  112. void dapm_mark_dirty(struct snd_soc_dapm_widget *w, const char *reason)
  113. {
  114. if (!dapm_dirty_widget(w)) {
  115. dev_vdbg(w->dapm->dev, "Marking %s dirty due to %s\n",
  116. w->name, reason);
  117. list_add_tail(&w->dirty, &w->dapm->card->dapm_dirty);
  118. }
  119. }
  120. EXPORT_SYMBOL_GPL(dapm_mark_dirty);
  121. /* create a new dapm widget */
  122. static inline struct snd_soc_dapm_widget *dapm_cnew_widget(
  123. const struct snd_soc_dapm_widget *_widget)
  124. {
  125. return kmemdup(_widget, sizeof(*_widget), GFP_KERNEL);
  126. }
  127. /* get snd_card from DAPM context */
  128. static inline struct snd_card *dapm_get_snd_card(
  129. struct snd_soc_dapm_context *dapm)
  130. {
  131. if (dapm->codec)
  132. return dapm->codec->card->snd_card;
  133. else if (dapm->platform)
  134. return dapm->platform->card->snd_card;
  135. else
  136. BUG();
  137. /* unreachable */
  138. return NULL;
  139. }
  140. /* get soc_card from DAPM context */
  141. static inline struct snd_soc_card *dapm_get_soc_card(
  142. struct snd_soc_dapm_context *dapm)
  143. {
  144. if (dapm->codec)
  145. return dapm->codec->card;
  146. else if (dapm->platform)
  147. return dapm->platform->card;
  148. else
  149. BUG();
  150. /* unreachable */
  151. return NULL;
  152. }
  153. static void dapm_reset(struct snd_soc_card *card)
  154. {
  155. struct snd_soc_dapm_widget *w;
  156. memset(&card->dapm_stats, 0, sizeof(card->dapm_stats));
  157. list_for_each_entry(w, &card->widgets, list) {
  158. w->power_checked = false;
  159. w->inputs = -1;
  160. w->outputs = -1;
  161. }
  162. }
  163. static int soc_widget_read(struct snd_soc_dapm_widget *w, int reg)
  164. {
  165. if (w->codec)
  166. return snd_soc_read(w->codec, reg);
  167. else if (w->platform)
  168. return snd_soc_platform_read(w->platform, reg);
  169. dev_err(w->dapm->dev, "no valid widget read method\n");
  170. return -1;
  171. }
  172. static int soc_widget_write(struct snd_soc_dapm_widget *w, int reg, int val)
  173. {
  174. if (w->codec)
  175. return snd_soc_write(w->codec, reg, val);
  176. else if (w->platform)
  177. return snd_soc_platform_write(w->platform, reg, val);
  178. dev_err(w->dapm->dev, "no valid widget write method\n");
  179. return -1;
  180. }
  181. static int soc_widget_update_bits(struct snd_soc_dapm_widget *w,
  182. unsigned short reg, unsigned int mask, unsigned int value)
  183. {
  184. bool change;
  185. unsigned int old, new;
  186. int ret;
  187. if (w->codec && w->codec->using_regmap) {
  188. ret = regmap_update_bits_check(w->codec->control_data,
  189. reg, mask, value, &change);
  190. if (ret != 0)
  191. return ret;
  192. } else {
  193. ret = soc_widget_read(w, reg);
  194. if (ret < 0)
  195. return ret;
  196. old = ret;
  197. new = (old & ~mask) | (value & mask);
  198. change = old != new;
  199. if (change) {
  200. ret = soc_widget_write(w, reg, new);
  201. if (ret < 0)
  202. return ret;
  203. }
  204. }
  205. return change;
  206. }
  207. /**
  208. * snd_soc_dapm_set_bias_level - set the bias level for the system
  209. * @dapm: DAPM context
  210. * @level: level to configure
  211. *
  212. * Configure the bias (power) levels for the SoC audio device.
  213. *
  214. * Returns 0 for success else error.
  215. */
  216. static int snd_soc_dapm_set_bias_level(struct snd_soc_dapm_context *dapm,
  217. enum snd_soc_bias_level level)
  218. {
  219. struct snd_soc_card *card = dapm->card;
  220. int ret = 0;
  221. trace_snd_soc_bias_level_start(card, level);
  222. if (card && card->set_bias_level)
  223. ret = card->set_bias_level(card, dapm, level);
  224. if (ret != 0)
  225. goto out;
  226. if (dapm->codec) {
  227. if (dapm->codec->driver->set_bias_level)
  228. ret = dapm->codec->driver->set_bias_level(dapm->codec,
  229. level);
  230. else
  231. dapm->bias_level = level;
  232. }
  233. if (ret != 0)
  234. goto out;
  235. if (card && card->set_bias_level_post)
  236. ret = card->set_bias_level_post(card, dapm, level);
  237. out:
  238. trace_snd_soc_bias_level_done(card, level);
  239. return ret;
  240. }
  241. /* set up initial codec paths */
  242. static void dapm_set_path_status(struct snd_soc_dapm_widget *w,
  243. struct snd_soc_dapm_path *p, int i)
  244. {
  245. switch (w->id) {
  246. case snd_soc_dapm_switch:
  247. case snd_soc_dapm_mixer:
  248. case snd_soc_dapm_mixer_named_ctl: {
  249. int val;
  250. struct soc_mixer_control *mc = (struct soc_mixer_control *)
  251. w->kcontrol_news[i].private_value;
  252. unsigned int reg = mc->reg;
  253. unsigned int shift = mc->shift;
  254. int max = mc->max;
  255. unsigned int mask = (1 << fls(max)) - 1;
  256. unsigned int invert = mc->invert;
  257. val = soc_widget_read(w, reg);
  258. val = (val >> shift) & mask;
  259. if ((invert && !val) || (!invert && val))
  260. p->connect = 1;
  261. else
  262. p->connect = 0;
  263. }
  264. break;
  265. case snd_soc_dapm_mux: {
  266. struct soc_enum *e = (struct soc_enum *)
  267. w->kcontrol_news[i].private_value;
  268. int val, item, bitmask;
  269. for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
  270. ;
  271. val = soc_widget_read(w, e->reg);
  272. item = (val >> e->shift_l) & (bitmask - 1);
  273. p->connect = 0;
  274. for (i = 0; i < e->max; i++) {
  275. if (!(strcmp(p->name, e->texts[i])) && item == i)
  276. p->connect = 1;
  277. }
  278. }
  279. break;
  280. case snd_soc_dapm_virt_mux: {
  281. struct soc_enum *e = (struct soc_enum *)
  282. w->kcontrol_news[i].private_value;
  283. p->connect = 0;
  284. /* since a virtual mux has no backing registers to
  285. * decide which path to connect, it will try to match
  286. * with the first enumeration. This is to ensure
  287. * that the default mux choice (the first) will be
  288. * correctly powered up during initialization.
  289. */
  290. if (!strcmp(p->name, e->texts[0]))
  291. p->connect = 1;
  292. }
  293. break;
  294. case snd_soc_dapm_value_mux: {
  295. struct soc_enum *e = (struct soc_enum *)
  296. w->kcontrol_news[i].private_value;
  297. int val, item;
  298. val = soc_widget_read(w, e->reg);
  299. val = (val >> e->shift_l) & e->mask;
  300. for (item = 0; item < e->max; item++) {
  301. if (val == e->values[item])
  302. break;
  303. }
  304. p->connect = 0;
  305. for (i = 0; i < e->max; i++) {
  306. if (!(strcmp(p->name, e->texts[i])) && item == i)
  307. p->connect = 1;
  308. }
  309. }
  310. break;
  311. /* does not affect routing - always connected */
  312. case snd_soc_dapm_pga:
  313. case snd_soc_dapm_out_drv:
  314. case snd_soc_dapm_output:
  315. case snd_soc_dapm_adc:
  316. case snd_soc_dapm_input:
  317. case snd_soc_dapm_siggen:
  318. case snd_soc_dapm_dac:
  319. case snd_soc_dapm_micbias:
  320. case snd_soc_dapm_vmid:
  321. case snd_soc_dapm_supply:
  322. case snd_soc_dapm_regulator_supply:
  323. case snd_soc_dapm_aif_in:
  324. case snd_soc_dapm_aif_out:
  325. case snd_soc_dapm_hp:
  326. case snd_soc_dapm_mic:
  327. case snd_soc_dapm_spk:
  328. case snd_soc_dapm_line:
  329. p->connect = 1;
  330. break;
  331. /* does affect routing - dynamically connected */
  332. case snd_soc_dapm_pre:
  333. case snd_soc_dapm_post:
  334. p->connect = 0;
  335. break;
  336. }
  337. }
  338. /* connect mux widget to its interconnecting audio paths */
  339. static int dapm_connect_mux(struct snd_soc_dapm_context *dapm,
  340. struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest,
  341. struct snd_soc_dapm_path *path, const char *control_name,
  342. const struct snd_kcontrol_new *kcontrol)
  343. {
  344. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  345. int i;
  346. for (i = 0; i < e->max; i++) {
  347. if (!(strcmp(control_name, e->texts[i]))) {
  348. list_add(&path->list, &dapm->card->paths);
  349. list_add(&path->list_sink, &dest->sources);
  350. list_add(&path->list_source, &src->sinks);
  351. path->name = (char*)e->texts[i];
  352. dapm_set_path_status(dest, path, 0);
  353. return 0;
  354. }
  355. }
  356. return -ENODEV;
  357. }
  358. /* connect mixer widget to its interconnecting audio paths */
  359. static int dapm_connect_mixer(struct snd_soc_dapm_context *dapm,
  360. struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest,
  361. struct snd_soc_dapm_path *path, const char *control_name)
  362. {
  363. int i;
  364. /* search for mixer kcontrol */
  365. for (i = 0; i < dest->num_kcontrols; i++) {
  366. if (!strcmp(control_name, dest->kcontrol_news[i].name)) {
  367. list_add(&path->list, &dapm->card->paths);
  368. list_add(&path->list_sink, &dest->sources);
  369. list_add(&path->list_source, &src->sinks);
  370. path->name = dest->kcontrol_news[i].name;
  371. dapm_set_path_status(dest, path, i);
  372. return 0;
  373. }
  374. }
  375. return -ENODEV;
  376. }
  377. static int dapm_is_shared_kcontrol(struct snd_soc_dapm_context *dapm,
  378. struct snd_soc_dapm_widget *kcontrolw,
  379. const struct snd_kcontrol_new *kcontrol_new,
  380. struct snd_kcontrol **kcontrol)
  381. {
  382. struct snd_soc_dapm_widget *w;
  383. int i;
  384. *kcontrol = NULL;
  385. list_for_each_entry(w, &dapm->card->widgets, list) {
  386. if (w == kcontrolw || w->dapm != kcontrolw->dapm)
  387. continue;
  388. for (i = 0; i < w->num_kcontrols; i++) {
  389. if (&w->kcontrol_news[i] == kcontrol_new) {
  390. if (w->kcontrols)
  391. *kcontrol = w->kcontrols[i];
  392. return 1;
  393. }
  394. }
  395. }
  396. return 0;
  397. }
  398. /* create new dapm mixer control */
  399. static int dapm_new_mixer(struct snd_soc_dapm_widget *w)
  400. {
  401. struct snd_soc_dapm_context *dapm = w->dapm;
  402. int i, ret = 0;
  403. size_t name_len, prefix_len;
  404. struct snd_soc_dapm_path *path;
  405. struct snd_card *card = dapm->card->snd_card;
  406. const char *prefix;
  407. struct snd_soc_dapm_widget_list *wlist;
  408. size_t wlistsize;
  409. if (dapm->codec)
  410. prefix = dapm->codec->name_prefix;
  411. else
  412. prefix = NULL;
  413. if (prefix)
  414. prefix_len = strlen(prefix) + 1;
  415. else
  416. prefix_len = 0;
  417. /* add kcontrol */
  418. for (i = 0; i < w->num_kcontrols; i++) {
  419. /* match name */
  420. list_for_each_entry(path, &w->sources, list_sink) {
  421. /* mixer/mux paths name must match control name */
  422. if (path->name != (char *)w->kcontrol_news[i].name)
  423. continue;
  424. if (w->kcontrols[i]) {
  425. path->kcontrol = w->kcontrols[i];
  426. continue;
  427. }
  428. wlistsize = sizeof(struct snd_soc_dapm_widget_list) +
  429. sizeof(struct snd_soc_dapm_widget *),
  430. wlist = kzalloc(wlistsize, GFP_KERNEL);
  431. if (wlist == NULL) {
  432. dev_err(dapm->dev,
  433. "asoc: can't allocate widget list for %s\n",
  434. w->name);
  435. return -ENOMEM;
  436. }
  437. wlist->num_widgets = 1;
  438. wlist->widgets[0] = w;
  439. /* add dapm control with long name.
  440. * for dapm_mixer this is the concatenation of the
  441. * mixer and kcontrol name.
  442. * for dapm_mixer_named_ctl this is simply the
  443. * kcontrol name.
  444. */
  445. name_len = strlen(w->kcontrol_news[i].name) + 1;
  446. if (w->id != snd_soc_dapm_mixer_named_ctl)
  447. name_len += 1 + strlen(w->name);
  448. path->long_name = kmalloc(name_len, GFP_KERNEL);
  449. if (path->long_name == NULL) {
  450. kfree(wlist);
  451. return -ENOMEM;
  452. }
  453. switch (w->id) {
  454. default:
  455. /* The control will get a prefix from
  456. * the control creation process but
  457. * we're also using the same prefix
  458. * for widgets so cut the prefix off
  459. * the front of the widget name.
  460. */
  461. snprintf(path->long_name, name_len, "%s %s",
  462. w->name + prefix_len,
  463. w->kcontrol_news[i].name);
  464. break;
  465. case snd_soc_dapm_mixer_named_ctl:
  466. snprintf(path->long_name, name_len, "%s",
  467. w->kcontrol_news[i].name);
  468. break;
  469. }
  470. path->long_name[name_len - 1] = '\0';
  471. path->kcontrol = snd_soc_cnew(&w->kcontrol_news[i],
  472. wlist, path->long_name,
  473. prefix);
  474. ret = snd_ctl_add(card, path->kcontrol);
  475. if (ret < 0) {
  476. dev_err(dapm->dev,
  477. "asoc: failed to add dapm kcontrol %s: %d\n",
  478. path->long_name, ret);
  479. kfree(wlist);
  480. kfree(path->long_name);
  481. path->long_name = NULL;
  482. return ret;
  483. }
  484. w->kcontrols[i] = path->kcontrol;
  485. }
  486. }
  487. return ret;
  488. }
  489. /* create new dapm mux control */
  490. static int dapm_new_mux(struct snd_soc_dapm_widget *w)
  491. {
  492. struct snd_soc_dapm_context *dapm = w->dapm;
  493. struct snd_soc_dapm_path *path = NULL;
  494. struct snd_kcontrol *kcontrol;
  495. struct snd_card *card = dapm->card->snd_card;
  496. const char *prefix;
  497. size_t prefix_len;
  498. int ret;
  499. struct snd_soc_dapm_widget_list *wlist;
  500. int shared, wlistentries;
  501. size_t wlistsize;
  502. char *name;
  503. if (w->num_kcontrols != 1) {
  504. dev_err(dapm->dev,
  505. "asoc: mux %s has incorrect number of controls\n",
  506. w->name);
  507. return -EINVAL;
  508. }
  509. shared = dapm_is_shared_kcontrol(dapm, w, &w->kcontrol_news[0],
  510. &kcontrol);
  511. if (kcontrol) {
  512. wlist = kcontrol->private_data;
  513. wlistentries = wlist->num_widgets + 1;
  514. } else {
  515. wlist = NULL;
  516. wlistentries = 1;
  517. }
  518. wlistsize = sizeof(struct snd_soc_dapm_widget_list) +
  519. wlistentries * sizeof(struct snd_soc_dapm_widget *),
  520. wlist = krealloc(wlist, wlistsize, GFP_KERNEL);
  521. if (wlist == NULL) {
  522. dev_err(dapm->dev,
  523. "asoc: can't allocate widget list for %s\n", w->name);
  524. return -ENOMEM;
  525. }
  526. wlist->num_widgets = wlistentries;
  527. wlist->widgets[wlistentries - 1] = w;
  528. if (!kcontrol) {
  529. if (dapm->codec)
  530. prefix = dapm->codec->name_prefix;
  531. else
  532. prefix = NULL;
  533. if (shared) {
  534. name = w->kcontrol_news[0].name;
  535. prefix_len = 0;
  536. } else {
  537. name = w->name;
  538. if (prefix)
  539. prefix_len = strlen(prefix) + 1;
  540. else
  541. prefix_len = 0;
  542. }
  543. /*
  544. * The control will get a prefix from the control creation
  545. * process but we're also using the same prefix for widgets so
  546. * cut the prefix off the front of the widget name.
  547. */
  548. kcontrol = snd_soc_cnew(&w->kcontrol_news[0], wlist,
  549. name + prefix_len, prefix);
  550. ret = snd_ctl_add(card, kcontrol);
  551. if (ret < 0) {
  552. dev_err(dapm->dev, "failed to add kcontrol %s: %d\n",
  553. w->name, ret);
  554. kfree(wlist);
  555. return ret;
  556. }
  557. }
  558. kcontrol->private_data = wlist;
  559. w->kcontrols[0] = kcontrol;
  560. list_for_each_entry(path, &w->sources, list_sink)
  561. path->kcontrol = kcontrol;
  562. return 0;
  563. }
  564. /* create new dapm volume control */
  565. static int dapm_new_pga(struct snd_soc_dapm_widget *w)
  566. {
  567. if (w->num_kcontrols)
  568. dev_err(w->dapm->dev,
  569. "asoc: PGA controls not supported: '%s'\n", w->name);
  570. return 0;
  571. }
  572. /* reset 'walked' bit for each dapm path */
  573. static inline void dapm_clear_walk(struct snd_soc_dapm_context *dapm)
  574. {
  575. struct snd_soc_dapm_path *p;
  576. list_for_each_entry(p, &dapm->card->paths, list)
  577. p->walked = 0;
  578. }
  579. /* We implement power down on suspend by checking the power state of
  580. * the ALSA card - when we are suspending the ALSA state for the card
  581. * is set to D3.
  582. */
  583. static int snd_soc_dapm_suspend_check(struct snd_soc_dapm_widget *widget)
  584. {
  585. int level = snd_power_get_state(widget->dapm->card->snd_card);
  586. switch (level) {
  587. case SNDRV_CTL_POWER_D3hot:
  588. case SNDRV_CTL_POWER_D3cold:
  589. if (widget->ignore_suspend)
  590. dev_dbg(widget->dapm->dev, "%s ignoring suspend\n",
  591. widget->name);
  592. return widget->ignore_suspend;
  593. default:
  594. return 1;
  595. }
  596. }
  597. /*
  598. * Recursively check for a completed path to an active or physically connected
  599. * output widget. Returns number of complete paths.
  600. */
  601. static int is_connected_output_ep(struct snd_soc_dapm_widget *widget)
  602. {
  603. struct snd_soc_dapm_path *path;
  604. int con = 0;
  605. if (widget->outputs >= 0)
  606. return widget->outputs;
  607. DAPM_UPDATE_STAT(widget, path_checks);
  608. switch (widget->id) {
  609. case snd_soc_dapm_supply:
  610. case snd_soc_dapm_regulator_supply:
  611. return 0;
  612. default:
  613. break;
  614. }
  615. switch (widget->id) {
  616. case snd_soc_dapm_adc:
  617. case snd_soc_dapm_aif_out:
  618. if (widget->active) {
  619. widget->outputs = snd_soc_dapm_suspend_check(widget);
  620. return widget->outputs;
  621. }
  622. default:
  623. break;
  624. }
  625. if (widget->connected) {
  626. /* connected pin ? */
  627. if (widget->id == snd_soc_dapm_output && !widget->ext) {
  628. widget->outputs = snd_soc_dapm_suspend_check(widget);
  629. return widget->outputs;
  630. }
  631. /* connected jack or spk ? */
  632. if (widget->id == snd_soc_dapm_hp ||
  633. widget->id == snd_soc_dapm_spk ||
  634. (widget->id == snd_soc_dapm_line &&
  635. !list_empty(&widget->sources))) {
  636. widget->outputs = snd_soc_dapm_suspend_check(widget);
  637. return widget->outputs;
  638. }
  639. }
  640. list_for_each_entry(path, &widget->sinks, list_source) {
  641. DAPM_UPDATE_STAT(widget, neighbour_checks);
  642. if (path->weak)
  643. continue;
  644. if (path->walked)
  645. continue;
  646. if (path->sink && path->connect) {
  647. path->walked = 1;
  648. con += is_connected_output_ep(path->sink);
  649. }
  650. }
  651. widget->outputs = con;
  652. return con;
  653. }
  654. /*
  655. * Recursively check for a completed path to an active or physically connected
  656. * input widget. Returns number of complete paths.
  657. */
  658. static int is_connected_input_ep(struct snd_soc_dapm_widget *widget)
  659. {
  660. struct snd_soc_dapm_path *path;
  661. int con = 0;
  662. if (widget->inputs >= 0)
  663. return widget->inputs;
  664. DAPM_UPDATE_STAT(widget, path_checks);
  665. switch (widget->id) {
  666. case snd_soc_dapm_supply:
  667. case snd_soc_dapm_regulator_supply:
  668. return 0;
  669. default:
  670. break;
  671. }
  672. /* active stream ? */
  673. switch (widget->id) {
  674. case snd_soc_dapm_dac:
  675. case snd_soc_dapm_aif_in:
  676. if (widget->active) {
  677. widget->inputs = snd_soc_dapm_suspend_check(widget);
  678. return widget->inputs;
  679. }
  680. default:
  681. break;
  682. }
  683. if (widget->connected) {
  684. /* connected pin ? */
  685. if (widget->id == snd_soc_dapm_input && !widget->ext) {
  686. widget->inputs = snd_soc_dapm_suspend_check(widget);
  687. return widget->inputs;
  688. }
  689. /* connected VMID/Bias for lower pops */
  690. if (widget->id == snd_soc_dapm_vmid) {
  691. widget->inputs = snd_soc_dapm_suspend_check(widget);
  692. return widget->inputs;
  693. }
  694. /* connected jack ? */
  695. if (widget->id == snd_soc_dapm_mic ||
  696. (widget->id == snd_soc_dapm_line &&
  697. !list_empty(&widget->sinks))) {
  698. widget->inputs = snd_soc_dapm_suspend_check(widget);
  699. return widget->inputs;
  700. }
  701. /* signal generator */
  702. if (widget->id == snd_soc_dapm_siggen) {
  703. widget->inputs = snd_soc_dapm_suspend_check(widget);
  704. return widget->inputs;
  705. }
  706. }
  707. list_for_each_entry(path, &widget->sources, list_sink) {
  708. DAPM_UPDATE_STAT(widget, neighbour_checks);
  709. if (path->weak)
  710. continue;
  711. if (path->walked)
  712. continue;
  713. if (path->source && path->connect) {
  714. path->walked = 1;
  715. con += is_connected_input_ep(path->source);
  716. }
  717. }
  718. widget->inputs = con;
  719. return con;
  720. }
  721. /*
  722. * Handler for generic register modifier widget.
  723. */
  724. int dapm_reg_event(struct snd_soc_dapm_widget *w,
  725. struct snd_kcontrol *kcontrol, int event)
  726. {
  727. unsigned int val;
  728. if (SND_SOC_DAPM_EVENT_ON(event))
  729. val = w->on_val;
  730. else
  731. val = w->off_val;
  732. soc_widget_update_bits(w, -(w->reg + 1),
  733. w->mask << w->shift, val << w->shift);
  734. return 0;
  735. }
  736. EXPORT_SYMBOL_GPL(dapm_reg_event);
  737. /*
  738. * Handler for regulator supply widget.
  739. */
  740. int dapm_regulator_event(struct snd_soc_dapm_widget *w,
  741. struct snd_kcontrol *kcontrol, int event)
  742. {
  743. if (SND_SOC_DAPM_EVENT_ON(event))
  744. return regulator_enable(w->priv);
  745. else
  746. return regulator_disable_deferred(w->priv, w->shift);
  747. }
  748. EXPORT_SYMBOL_GPL(dapm_regulator_event);
  749. static int dapm_widget_power_check(struct snd_soc_dapm_widget *w)
  750. {
  751. if (w->power_checked)
  752. return w->new_power;
  753. if (w->force)
  754. w->new_power = 1;
  755. else
  756. w->new_power = w->power_check(w);
  757. w->power_checked = true;
  758. return w->new_power;
  759. }
  760. /* Generic check to see if a widget should be powered.
  761. */
  762. static int dapm_generic_check_power(struct snd_soc_dapm_widget *w)
  763. {
  764. int in, out;
  765. DAPM_UPDATE_STAT(w, power_checks);
  766. in = is_connected_input_ep(w);
  767. dapm_clear_walk(w->dapm);
  768. out = is_connected_output_ep(w);
  769. dapm_clear_walk(w->dapm);
  770. return out != 0 && in != 0;
  771. }
  772. /* Check to see if an ADC has power */
  773. static int dapm_adc_check_power(struct snd_soc_dapm_widget *w)
  774. {
  775. int in;
  776. DAPM_UPDATE_STAT(w, power_checks);
  777. if (w->active) {
  778. in = is_connected_input_ep(w);
  779. dapm_clear_walk(w->dapm);
  780. return in != 0;
  781. } else {
  782. return dapm_generic_check_power(w);
  783. }
  784. }
  785. /* Check to see if a DAC has power */
  786. static int dapm_dac_check_power(struct snd_soc_dapm_widget *w)
  787. {
  788. int out;
  789. DAPM_UPDATE_STAT(w, power_checks);
  790. if (w->active) {
  791. out = is_connected_output_ep(w);
  792. dapm_clear_walk(w->dapm);
  793. return out != 0;
  794. } else {
  795. return dapm_generic_check_power(w);
  796. }
  797. }
  798. /* Check to see if a power supply is needed */
  799. static int dapm_supply_check_power(struct snd_soc_dapm_widget *w)
  800. {
  801. struct snd_soc_dapm_path *path;
  802. DAPM_UPDATE_STAT(w, power_checks);
  803. /* Check if one of our outputs is connected */
  804. list_for_each_entry(path, &w->sinks, list_source) {
  805. DAPM_UPDATE_STAT(w, neighbour_checks);
  806. if (path->weak)
  807. continue;
  808. if (path->connected &&
  809. !path->connected(path->source, path->sink))
  810. continue;
  811. if (!path->sink)
  812. continue;
  813. if (dapm_widget_power_check(path->sink))
  814. return 1;
  815. }
  816. dapm_clear_walk(w->dapm);
  817. return 0;
  818. }
  819. static int dapm_always_on_check_power(struct snd_soc_dapm_widget *w)
  820. {
  821. return 1;
  822. }
  823. static int dapm_seq_compare(struct snd_soc_dapm_widget *a,
  824. struct snd_soc_dapm_widget *b,
  825. bool power_up)
  826. {
  827. int *sort;
  828. if (power_up)
  829. sort = dapm_up_seq;
  830. else
  831. sort = dapm_down_seq;
  832. if (sort[a->id] != sort[b->id])
  833. return sort[a->id] - sort[b->id];
  834. if (a->subseq != b->subseq) {
  835. if (power_up)
  836. return a->subseq - b->subseq;
  837. else
  838. return b->subseq - a->subseq;
  839. }
  840. if (a->reg != b->reg)
  841. return a->reg - b->reg;
  842. if (a->dapm != b->dapm)
  843. return (unsigned long)a->dapm - (unsigned long)b->dapm;
  844. return 0;
  845. }
  846. /* Insert a widget in order into a DAPM power sequence. */
  847. static void dapm_seq_insert(struct snd_soc_dapm_widget *new_widget,
  848. struct list_head *list,
  849. bool power_up)
  850. {
  851. struct snd_soc_dapm_widget *w;
  852. list_for_each_entry(w, list, power_list)
  853. if (dapm_seq_compare(new_widget, w, power_up) < 0) {
  854. list_add_tail(&new_widget->power_list, &w->power_list);
  855. return;
  856. }
  857. list_add_tail(&new_widget->power_list, list);
  858. }
  859. static void dapm_seq_check_event(struct snd_soc_dapm_context *dapm,
  860. struct snd_soc_dapm_widget *w, int event)
  861. {
  862. struct snd_soc_card *card = dapm->card;
  863. const char *ev_name;
  864. int power, ret;
  865. switch (event) {
  866. case SND_SOC_DAPM_PRE_PMU:
  867. ev_name = "PRE_PMU";
  868. power = 1;
  869. break;
  870. case SND_SOC_DAPM_POST_PMU:
  871. ev_name = "POST_PMU";
  872. power = 1;
  873. break;
  874. case SND_SOC_DAPM_PRE_PMD:
  875. ev_name = "PRE_PMD";
  876. power = 0;
  877. break;
  878. case SND_SOC_DAPM_POST_PMD:
  879. ev_name = "POST_PMD";
  880. power = 0;
  881. break;
  882. default:
  883. BUG();
  884. return;
  885. }
  886. if (w->power != power)
  887. return;
  888. if (w->event && (w->event_flags & event)) {
  889. pop_dbg(dapm->dev, card->pop_time, "pop test : %s %s\n",
  890. w->name, ev_name);
  891. trace_snd_soc_dapm_widget_event_start(w, event);
  892. ret = w->event(w, NULL, event);
  893. trace_snd_soc_dapm_widget_event_done(w, event);
  894. if (ret < 0)
  895. pr_err("%s: %s event failed: %d\n",
  896. ev_name, w->name, ret);
  897. }
  898. }
  899. /* Apply the coalesced changes from a DAPM sequence */
  900. static void dapm_seq_run_coalesced(struct snd_soc_dapm_context *dapm,
  901. struct list_head *pending)
  902. {
  903. struct snd_soc_card *card = dapm->card;
  904. struct snd_soc_dapm_widget *w;
  905. int reg, power;
  906. unsigned int value = 0;
  907. unsigned int mask = 0;
  908. unsigned int cur_mask;
  909. reg = list_first_entry(pending, struct snd_soc_dapm_widget,
  910. power_list)->reg;
  911. list_for_each_entry(w, pending, power_list) {
  912. cur_mask = 1 << w->shift;
  913. BUG_ON(reg != w->reg);
  914. if (w->invert)
  915. power = !w->power;
  916. else
  917. power = w->power;
  918. mask |= cur_mask;
  919. if (power)
  920. value |= cur_mask;
  921. pop_dbg(dapm->dev, card->pop_time,
  922. "pop test : Queue %s: reg=0x%x, 0x%x/0x%x\n",
  923. w->name, reg, value, mask);
  924. /* Check for events */
  925. dapm_seq_check_event(dapm, w, SND_SOC_DAPM_PRE_PMU);
  926. dapm_seq_check_event(dapm, w, SND_SOC_DAPM_PRE_PMD);
  927. }
  928. if (reg >= 0) {
  929. /* Any widget will do, they should all be updating the
  930. * same register.
  931. */
  932. w = list_first_entry(pending, struct snd_soc_dapm_widget,
  933. power_list);
  934. pop_dbg(dapm->dev, card->pop_time,
  935. "pop test : Applying 0x%x/0x%x to %x in %dms\n",
  936. value, mask, reg, card->pop_time);
  937. pop_wait(card->pop_time);
  938. soc_widget_update_bits(w, reg, mask, value);
  939. }
  940. list_for_each_entry(w, pending, power_list) {
  941. dapm_seq_check_event(dapm, w, SND_SOC_DAPM_POST_PMU);
  942. dapm_seq_check_event(dapm, w, SND_SOC_DAPM_POST_PMD);
  943. }
  944. }
  945. /* Apply a DAPM power sequence.
  946. *
  947. * We walk over a pre-sorted list of widgets to apply power to. In
  948. * order to minimise the number of writes to the device required
  949. * multiple widgets will be updated in a single write where possible.
  950. * Currently anything that requires more than a single write is not
  951. * handled.
  952. */
  953. static void dapm_seq_run(struct snd_soc_dapm_context *dapm,
  954. struct list_head *list, int event, bool power_up)
  955. {
  956. struct snd_soc_dapm_widget *w, *n;
  957. LIST_HEAD(pending);
  958. int cur_sort = -1;
  959. int cur_subseq = -1;
  960. int cur_reg = SND_SOC_NOPM;
  961. struct snd_soc_dapm_context *cur_dapm = NULL;
  962. int ret, i;
  963. int *sort;
  964. if (power_up)
  965. sort = dapm_up_seq;
  966. else
  967. sort = dapm_down_seq;
  968. list_for_each_entry_safe(w, n, list, power_list) {
  969. ret = 0;
  970. /* Do we need to apply any queued changes? */
  971. if (sort[w->id] != cur_sort || w->reg != cur_reg ||
  972. w->dapm != cur_dapm || w->subseq != cur_subseq) {
  973. if (!list_empty(&pending))
  974. dapm_seq_run_coalesced(cur_dapm, &pending);
  975. if (cur_dapm && cur_dapm->seq_notifier) {
  976. for (i = 0; i < ARRAY_SIZE(dapm_up_seq); i++)
  977. if (sort[i] == cur_sort)
  978. cur_dapm->seq_notifier(cur_dapm,
  979. i,
  980. cur_subseq);
  981. }
  982. INIT_LIST_HEAD(&pending);
  983. cur_sort = -1;
  984. cur_subseq = INT_MIN;
  985. cur_reg = SND_SOC_NOPM;
  986. cur_dapm = NULL;
  987. }
  988. switch (w->id) {
  989. case snd_soc_dapm_pre:
  990. if (!w->event)
  991. list_for_each_entry_safe_continue(w, n, list,
  992. power_list);
  993. if (event == SND_SOC_DAPM_STREAM_START)
  994. ret = w->event(w,
  995. NULL, SND_SOC_DAPM_PRE_PMU);
  996. else if (event == SND_SOC_DAPM_STREAM_STOP)
  997. ret = w->event(w,
  998. NULL, SND_SOC_DAPM_PRE_PMD);
  999. break;
  1000. case snd_soc_dapm_post:
  1001. if (!w->event)
  1002. list_for_each_entry_safe_continue(w, n, list,
  1003. power_list);
  1004. if (event == SND_SOC_DAPM_STREAM_START)
  1005. ret = w->event(w,
  1006. NULL, SND_SOC_DAPM_POST_PMU);
  1007. else if (event == SND_SOC_DAPM_STREAM_STOP)
  1008. ret = w->event(w,
  1009. NULL, SND_SOC_DAPM_POST_PMD);
  1010. break;
  1011. default:
  1012. /* Queue it up for application */
  1013. cur_sort = sort[w->id];
  1014. cur_subseq = w->subseq;
  1015. cur_reg = w->reg;
  1016. cur_dapm = w->dapm;
  1017. list_move(&w->power_list, &pending);
  1018. break;
  1019. }
  1020. if (ret < 0)
  1021. dev_err(w->dapm->dev,
  1022. "Failed to apply widget power: %d\n", ret);
  1023. }
  1024. if (!list_empty(&pending))
  1025. dapm_seq_run_coalesced(cur_dapm, &pending);
  1026. if (cur_dapm && cur_dapm->seq_notifier) {
  1027. for (i = 0; i < ARRAY_SIZE(dapm_up_seq); i++)
  1028. if (sort[i] == cur_sort)
  1029. cur_dapm->seq_notifier(cur_dapm,
  1030. i, cur_subseq);
  1031. }
  1032. }
  1033. static void dapm_widget_update(struct snd_soc_dapm_context *dapm)
  1034. {
  1035. struct snd_soc_dapm_update *update = dapm->update;
  1036. struct snd_soc_dapm_widget *w;
  1037. int ret;
  1038. if (!update)
  1039. return;
  1040. w = update->widget;
  1041. if (w->event &&
  1042. (w->event_flags & SND_SOC_DAPM_PRE_REG)) {
  1043. ret = w->event(w, update->kcontrol, SND_SOC_DAPM_PRE_REG);
  1044. if (ret != 0)
  1045. pr_err("%s DAPM pre-event failed: %d\n",
  1046. w->name, ret);
  1047. }
  1048. ret = snd_soc_update_bits(w->codec, update->reg, update->mask,
  1049. update->val);
  1050. if (ret < 0)
  1051. pr_err("%s DAPM update failed: %d\n", w->name, ret);
  1052. if (w->event &&
  1053. (w->event_flags & SND_SOC_DAPM_POST_REG)) {
  1054. ret = w->event(w, update->kcontrol, SND_SOC_DAPM_POST_REG);
  1055. if (ret != 0)
  1056. pr_err("%s DAPM post-event failed: %d\n",
  1057. w->name, ret);
  1058. }
  1059. }
  1060. /* Async callback run prior to DAPM sequences - brings to _PREPARE if
  1061. * they're changing state.
  1062. */
  1063. static void dapm_pre_sequence_async(void *data, async_cookie_t cookie)
  1064. {
  1065. struct snd_soc_dapm_context *d = data;
  1066. int ret;
  1067. /* If we're off and we're not supposed to be go into STANDBY */
  1068. if (d->bias_level == SND_SOC_BIAS_OFF &&
  1069. d->target_bias_level != SND_SOC_BIAS_OFF) {
  1070. if (d->dev)
  1071. pm_runtime_get_sync(d->dev);
  1072. ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_STANDBY);
  1073. if (ret != 0)
  1074. dev_err(d->dev,
  1075. "Failed to turn on bias: %d\n", ret);
  1076. }
  1077. /* Prepare for a STADDBY->ON or ON->STANDBY transition */
  1078. if (d->bias_level != d->target_bias_level) {
  1079. ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_PREPARE);
  1080. if (ret != 0)
  1081. dev_err(d->dev,
  1082. "Failed to prepare bias: %d\n", ret);
  1083. }
  1084. }
  1085. /* Async callback run prior to DAPM sequences - brings to their final
  1086. * state.
  1087. */
  1088. static void dapm_post_sequence_async(void *data, async_cookie_t cookie)
  1089. {
  1090. struct snd_soc_dapm_context *d = data;
  1091. int ret;
  1092. /* If we just powered the last thing off drop to standby bias */
  1093. if (d->bias_level == SND_SOC_BIAS_PREPARE &&
  1094. (d->target_bias_level == SND_SOC_BIAS_STANDBY ||
  1095. d->target_bias_level == SND_SOC_BIAS_OFF)) {
  1096. ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_STANDBY);
  1097. if (ret != 0)
  1098. dev_err(d->dev, "Failed to apply standby bias: %d\n",
  1099. ret);
  1100. }
  1101. /* If we're in standby and can support bias off then do that */
  1102. if (d->bias_level == SND_SOC_BIAS_STANDBY &&
  1103. d->target_bias_level == SND_SOC_BIAS_OFF) {
  1104. ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_OFF);
  1105. if (ret != 0)
  1106. dev_err(d->dev, "Failed to turn off bias: %d\n", ret);
  1107. if (d->dev)
  1108. pm_runtime_put(d->dev);
  1109. }
  1110. /* If we just powered up then move to active bias */
  1111. if (d->bias_level == SND_SOC_BIAS_PREPARE &&
  1112. d->target_bias_level == SND_SOC_BIAS_ON) {
  1113. ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_ON);
  1114. if (ret != 0)
  1115. dev_err(d->dev, "Failed to apply active bias: %d\n",
  1116. ret);
  1117. }
  1118. }
  1119. static void dapm_widget_set_peer_power(struct snd_soc_dapm_widget *peer,
  1120. bool power, bool connect)
  1121. {
  1122. /* If a connection is being made or broken then that update
  1123. * will have marked the peer dirty, otherwise the widgets are
  1124. * not connected and this update has no impact. */
  1125. if (!connect)
  1126. return;
  1127. /* If the peer is already in the state we're moving to then we
  1128. * won't have an impact on it. */
  1129. if (power != peer->power)
  1130. dapm_mark_dirty(peer, "peer state change");
  1131. }
  1132. static void dapm_widget_set_power(struct snd_soc_dapm_widget *w, bool power,
  1133. struct list_head *up_list,
  1134. struct list_head *down_list)
  1135. {
  1136. struct snd_soc_dapm_path *path;
  1137. if (w->power == power)
  1138. return;
  1139. trace_snd_soc_dapm_widget_power(w, power);
  1140. /* If we changed our power state perhaps our neigbours changed
  1141. * also.
  1142. */
  1143. list_for_each_entry(path, &w->sources, list_sink) {
  1144. if (path->source) {
  1145. dapm_widget_set_peer_power(path->source, power,
  1146. path->connect);
  1147. }
  1148. }
  1149. switch (w->id) {
  1150. case snd_soc_dapm_supply:
  1151. case snd_soc_dapm_regulator_supply:
  1152. /* Supplies can't affect their outputs, only their inputs */
  1153. break;
  1154. default:
  1155. list_for_each_entry(path, &w->sinks, list_source) {
  1156. if (path->sink) {
  1157. dapm_widget_set_peer_power(path->sink, power,
  1158. path->connect);
  1159. }
  1160. }
  1161. break;
  1162. }
  1163. if (power)
  1164. dapm_seq_insert(w, up_list, true);
  1165. else
  1166. dapm_seq_insert(w, down_list, false);
  1167. w->power = power;
  1168. }
  1169. static void dapm_power_one_widget(struct snd_soc_dapm_widget *w,
  1170. struct list_head *up_list,
  1171. struct list_head *down_list)
  1172. {
  1173. int power;
  1174. switch (w->id) {
  1175. case snd_soc_dapm_pre:
  1176. dapm_seq_insert(w, down_list, false);
  1177. break;
  1178. case snd_soc_dapm_post:
  1179. dapm_seq_insert(w, up_list, true);
  1180. break;
  1181. default:
  1182. power = dapm_widget_power_check(w);
  1183. dapm_widget_set_power(w, power, up_list, down_list);
  1184. break;
  1185. }
  1186. }
  1187. /*
  1188. * Scan each dapm widget for complete audio path.
  1189. * A complete path is a route that has valid endpoints i.e.:-
  1190. *
  1191. * o DAC to output pin.
  1192. * o Input Pin to ADC.
  1193. * o Input pin to Output pin (bypass, sidetone)
  1194. * o DAC to ADC (loopback).
  1195. */
  1196. static int dapm_power_widgets(struct snd_soc_dapm_context *dapm, int event)
  1197. {
  1198. struct snd_soc_card *card = dapm->card;
  1199. struct snd_soc_dapm_widget *w;
  1200. struct snd_soc_dapm_context *d;
  1201. LIST_HEAD(up_list);
  1202. LIST_HEAD(down_list);
  1203. LIST_HEAD(async_domain);
  1204. enum snd_soc_bias_level bias;
  1205. trace_snd_soc_dapm_start(card);
  1206. list_for_each_entry(d, &card->dapm_list, list) {
  1207. if (d->n_widgets || d->codec == NULL) {
  1208. if (d->idle_bias_off)
  1209. d->target_bias_level = SND_SOC_BIAS_OFF;
  1210. else
  1211. d->target_bias_level = SND_SOC_BIAS_STANDBY;
  1212. }
  1213. }
  1214. dapm_reset(card);
  1215. /* Check which widgets we need to power and store them in
  1216. * lists indicating if they should be powered up or down. We
  1217. * only check widgets that have been flagged as dirty but note
  1218. * that new widgets may be added to the dirty list while we
  1219. * iterate.
  1220. */
  1221. list_for_each_entry(w, &card->dapm_dirty, dirty) {
  1222. dapm_power_one_widget(w, &up_list, &down_list);
  1223. }
  1224. list_for_each_entry(w, &card->widgets, list) {
  1225. list_del_init(&w->dirty);
  1226. if (w->power) {
  1227. d = w->dapm;
  1228. /* Supplies and micbiases only bring the
  1229. * context up to STANDBY as unless something
  1230. * else is active and passing audio they
  1231. * generally don't require full power. Signal
  1232. * generators are virtual pins and have no
  1233. * power impact themselves.
  1234. */
  1235. switch (w->id) {
  1236. case snd_soc_dapm_siggen:
  1237. break;
  1238. case snd_soc_dapm_supply:
  1239. case snd_soc_dapm_regulator_supply:
  1240. case snd_soc_dapm_micbias:
  1241. if (d->target_bias_level < SND_SOC_BIAS_STANDBY)
  1242. d->target_bias_level = SND_SOC_BIAS_STANDBY;
  1243. break;
  1244. default:
  1245. d->target_bias_level = SND_SOC_BIAS_ON;
  1246. break;
  1247. }
  1248. }
  1249. }
  1250. /* If there are no DAPM widgets then try to figure out power from the
  1251. * event type.
  1252. */
  1253. if (!dapm->n_widgets) {
  1254. switch (event) {
  1255. case SND_SOC_DAPM_STREAM_START:
  1256. case SND_SOC_DAPM_STREAM_RESUME:
  1257. dapm->target_bias_level = SND_SOC_BIAS_ON;
  1258. break;
  1259. case SND_SOC_DAPM_STREAM_STOP:
  1260. if (dapm->codec && dapm->codec->active)
  1261. dapm->target_bias_level = SND_SOC_BIAS_ON;
  1262. else
  1263. dapm->target_bias_level = SND_SOC_BIAS_STANDBY;
  1264. break;
  1265. case SND_SOC_DAPM_STREAM_SUSPEND:
  1266. dapm->target_bias_level = SND_SOC_BIAS_STANDBY;
  1267. break;
  1268. case SND_SOC_DAPM_STREAM_NOP:
  1269. dapm->target_bias_level = dapm->bias_level;
  1270. break;
  1271. default:
  1272. break;
  1273. }
  1274. }
  1275. /* Force all contexts in the card to the same bias state if
  1276. * they're not ground referenced.
  1277. */
  1278. bias = SND_SOC_BIAS_OFF;
  1279. list_for_each_entry(d, &card->dapm_list, list)
  1280. if (d->target_bias_level > bias)
  1281. bias = d->target_bias_level;
  1282. list_for_each_entry(d, &card->dapm_list, list)
  1283. if (!d->idle_bias_off)
  1284. d->target_bias_level = bias;
  1285. trace_snd_soc_dapm_walk_done(card);
  1286. /* Run all the bias changes in parallel */
  1287. list_for_each_entry(d, &dapm->card->dapm_list, list)
  1288. async_schedule_domain(dapm_pre_sequence_async, d,
  1289. &async_domain);
  1290. async_synchronize_full_domain(&async_domain);
  1291. /* Power down widgets first; try to avoid amplifying pops. */
  1292. dapm_seq_run(dapm, &down_list, event, false);
  1293. dapm_widget_update(dapm);
  1294. /* Now power up. */
  1295. dapm_seq_run(dapm, &up_list, event, true);
  1296. /* Run all the bias changes in parallel */
  1297. list_for_each_entry(d, &dapm->card->dapm_list, list)
  1298. async_schedule_domain(dapm_post_sequence_async, d,
  1299. &async_domain);
  1300. async_synchronize_full_domain(&async_domain);
  1301. pop_dbg(dapm->dev, card->pop_time,
  1302. "DAPM sequencing finished, waiting %dms\n", card->pop_time);
  1303. pop_wait(card->pop_time);
  1304. trace_snd_soc_dapm_done(card);
  1305. return 0;
  1306. }
  1307. #ifdef CONFIG_DEBUG_FS
  1308. static int dapm_widget_power_open_file(struct inode *inode, struct file *file)
  1309. {
  1310. file->private_data = inode->i_private;
  1311. return 0;
  1312. }
  1313. static ssize_t dapm_widget_power_read_file(struct file *file,
  1314. char __user *user_buf,
  1315. size_t count, loff_t *ppos)
  1316. {
  1317. struct snd_soc_dapm_widget *w = file->private_data;
  1318. char *buf;
  1319. int in, out;
  1320. ssize_t ret;
  1321. struct snd_soc_dapm_path *p = NULL;
  1322. buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
  1323. if (!buf)
  1324. return -ENOMEM;
  1325. in = is_connected_input_ep(w);
  1326. dapm_clear_walk(w->dapm);
  1327. out = is_connected_output_ep(w);
  1328. dapm_clear_walk(w->dapm);
  1329. ret = snprintf(buf, PAGE_SIZE, "%s: %s in %d out %d",
  1330. w->name, w->power ? "On" : "Off", in, out);
  1331. if (w->reg >= 0)
  1332. ret += snprintf(buf + ret, PAGE_SIZE - ret,
  1333. " - R%d(0x%x) bit %d",
  1334. w->reg, w->reg, w->shift);
  1335. ret += snprintf(buf + ret, PAGE_SIZE - ret, "\n");
  1336. if (w->sname)
  1337. ret += snprintf(buf + ret, PAGE_SIZE - ret, " stream %s %s\n",
  1338. w->sname,
  1339. w->active ? "active" : "inactive");
  1340. list_for_each_entry(p, &w->sources, list_sink) {
  1341. if (p->connected && !p->connected(w, p->sink))
  1342. continue;
  1343. if (p->connect)
  1344. ret += snprintf(buf + ret, PAGE_SIZE - ret,
  1345. " in \"%s\" \"%s\"\n",
  1346. p->name ? p->name : "static",
  1347. p->source->name);
  1348. }
  1349. list_for_each_entry(p, &w->sinks, list_source) {
  1350. if (p->connected && !p->connected(w, p->sink))
  1351. continue;
  1352. if (p->connect)
  1353. ret += snprintf(buf + ret, PAGE_SIZE - ret,
  1354. " out \"%s\" \"%s\"\n",
  1355. p->name ? p->name : "static",
  1356. p->sink->name);
  1357. }
  1358. ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
  1359. kfree(buf);
  1360. return ret;
  1361. }
  1362. static const struct file_operations dapm_widget_power_fops = {
  1363. .open = dapm_widget_power_open_file,
  1364. .read = dapm_widget_power_read_file,
  1365. .llseek = default_llseek,
  1366. };
  1367. static int dapm_bias_open_file(struct inode *inode, struct file *file)
  1368. {
  1369. file->private_data = inode->i_private;
  1370. return 0;
  1371. }
  1372. static ssize_t dapm_bias_read_file(struct file *file, char __user *user_buf,
  1373. size_t count, loff_t *ppos)
  1374. {
  1375. struct snd_soc_dapm_context *dapm = file->private_data;
  1376. char *level;
  1377. switch (dapm->bias_level) {
  1378. case SND_SOC_BIAS_ON:
  1379. level = "On\n";
  1380. break;
  1381. case SND_SOC_BIAS_PREPARE:
  1382. level = "Prepare\n";
  1383. break;
  1384. case SND_SOC_BIAS_STANDBY:
  1385. level = "Standby\n";
  1386. break;
  1387. case SND_SOC_BIAS_OFF:
  1388. level = "Off\n";
  1389. break;
  1390. default:
  1391. BUG();
  1392. level = "Unknown\n";
  1393. break;
  1394. }
  1395. return simple_read_from_buffer(user_buf, count, ppos, level,
  1396. strlen(level));
  1397. }
  1398. static const struct file_operations dapm_bias_fops = {
  1399. .open = dapm_bias_open_file,
  1400. .read = dapm_bias_read_file,
  1401. .llseek = default_llseek,
  1402. };
  1403. void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm,
  1404. struct dentry *parent)
  1405. {
  1406. struct dentry *d;
  1407. dapm->debugfs_dapm = debugfs_create_dir("dapm", parent);
  1408. if (!dapm->debugfs_dapm) {
  1409. printk(KERN_WARNING
  1410. "Failed to create DAPM debugfs directory\n");
  1411. return;
  1412. }
  1413. d = debugfs_create_file("bias_level", 0444,
  1414. dapm->debugfs_dapm, dapm,
  1415. &dapm_bias_fops);
  1416. if (!d)
  1417. dev_warn(dapm->dev,
  1418. "ASoC: Failed to create bias level debugfs file\n");
  1419. }
  1420. static void dapm_debugfs_add_widget(struct snd_soc_dapm_widget *w)
  1421. {
  1422. struct snd_soc_dapm_context *dapm = w->dapm;
  1423. struct dentry *d;
  1424. if (!dapm->debugfs_dapm || !w->name)
  1425. return;
  1426. d = debugfs_create_file(w->name, 0444,
  1427. dapm->debugfs_dapm, w,
  1428. &dapm_widget_power_fops);
  1429. if (!d)
  1430. dev_warn(w->dapm->dev,
  1431. "ASoC: Failed to create %s debugfs file\n",
  1432. w->name);
  1433. }
  1434. static void dapm_debugfs_cleanup(struct snd_soc_dapm_context *dapm)
  1435. {
  1436. debugfs_remove_recursive(dapm->debugfs_dapm);
  1437. }
  1438. #else
  1439. void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm,
  1440. struct dentry *parent)
  1441. {
  1442. }
  1443. static inline void dapm_debugfs_add_widget(struct snd_soc_dapm_widget *w)
  1444. {
  1445. }
  1446. static inline void dapm_debugfs_cleanup(struct snd_soc_dapm_context *dapm)
  1447. {
  1448. }
  1449. #endif
  1450. /* test and update the power status of a mux widget */
  1451. int snd_soc_dapm_mux_update_power(struct snd_soc_dapm_widget *widget,
  1452. struct snd_kcontrol *kcontrol, int mux, struct soc_enum *e)
  1453. {
  1454. struct snd_soc_dapm_path *path;
  1455. int found = 0;
  1456. if (widget->id != snd_soc_dapm_mux &&
  1457. widget->id != snd_soc_dapm_virt_mux &&
  1458. widget->id != snd_soc_dapm_value_mux)
  1459. return -ENODEV;
  1460. /* find dapm widget path assoc with kcontrol */
  1461. list_for_each_entry(path, &widget->dapm->card->paths, list) {
  1462. if (path->kcontrol != kcontrol)
  1463. continue;
  1464. if (!path->name || !e->texts[mux])
  1465. continue;
  1466. found = 1;
  1467. /* we now need to match the string in the enum to the path */
  1468. if (!(strcmp(path->name, e->texts[mux]))) {
  1469. path->connect = 1; /* new connection */
  1470. dapm_mark_dirty(path->source, "mux connection");
  1471. } else {
  1472. if (path->connect)
  1473. dapm_mark_dirty(path->source,
  1474. "mux disconnection");
  1475. path->connect = 0; /* old connection must be powered down */
  1476. }
  1477. }
  1478. if (found) {
  1479. dapm_mark_dirty(widget, "mux change");
  1480. dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP);
  1481. }
  1482. return 0;
  1483. }
  1484. EXPORT_SYMBOL_GPL(snd_soc_dapm_mux_update_power);
  1485. /* test and update the power status of a mixer or switch widget */
  1486. int snd_soc_dapm_mixer_update_power(struct snd_soc_dapm_widget *widget,
  1487. struct snd_kcontrol *kcontrol, int connect)
  1488. {
  1489. struct snd_soc_dapm_path *path;
  1490. int found = 0;
  1491. if (widget->id != snd_soc_dapm_mixer &&
  1492. widget->id != snd_soc_dapm_mixer_named_ctl &&
  1493. widget->id != snd_soc_dapm_switch)
  1494. return -ENODEV;
  1495. /* find dapm widget path assoc with kcontrol */
  1496. list_for_each_entry(path, &widget->dapm->card->paths, list) {
  1497. if (path->kcontrol != kcontrol)
  1498. continue;
  1499. /* found, now check type */
  1500. found = 1;
  1501. path->connect = connect;
  1502. dapm_mark_dirty(path->source, "mixer connection");
  1503. }
  1504. if (found) {
  1505. dapm_mark_dirty(widget, "mixer update");
  1506. dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP);
  1507. }
  1508. return 0;
  1509. }
  1510. EXPORT_SYMBOL_GPL(snd_soc_dapm_mixer_update_power);
  1511. /* show dapm widget status in sys fs */
  1512. static ssize_t dapm_widget_show(struct device *dev,
  1513. struct device_attribute *attr, char *buf)
  1514. {
  1515. struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
  1516. struct snd_soc_codec *codec =rtd->codec;
  1517. struct snd_soc_dapm_widget *w;
  1518. int count = 0;
  1519. char *state = "not set";
  1520. list_for_each_entry(w, &codec->card->widgets, list) {
  1521. if (w->dapm != &codec->dapm)
  1522. continue;
  1523. /* only display widgets that burnm power */
  1524. switch (w->id) {
  1525. case snd_soc_dapm_hp:
  1526. case snd_soc_dapm_mic:
  1527. case snd_soc_dapm_spk:
  1528. case snd_soc_dapm_line:
  1529. case snd_soc_dapm_micbias:
  1530. case snd_soc_dapm_dac:
  1531. case snd_soc_dapm_adc:
  1532. case snd_soc_dapm_pga:
  1533. case snd_soc_dapm_out_drv:
  1534. case snd_soc_dapm_mixer:
  1535. case snd_soc_dapm_mixer_named_ctl:
  1536. case snd_soc_dapm_supply:
  1537. case snd_soc_dapm_regulator_supply:
  1538. if (w->name)
  1539. count += sprintf(buf + count, "%s: %s\n",
  1540. w->name, w->power ? "On":"Off");
  1541. break;
  1542. default:
  1543. break;
  1544. }
  1545. }
  1546. switch (codec->dapm.bias_level) {
  1547. case SND_SOC_BIAS_ON:
  1548. state = "On";
  1549. break;
  1550. case SND_SOC_BIAS_PREPARE:
  1551. state = "Prepare";
  1552. break;
  1553. case SND_SOC_BIAS_STANDBY:
  1554. state = "Standby";
  1555. break;
  1556. case SND_SOC_BIAS_OFF:
  1557. state = "Off";
  1558. break;
  1559. }
  1560. count += sprintf(buf + count, "PM State: %s\n", state);
  1561. return count;
  1562. }
  1563. static DEVICE_ATTR(dapm_widget, 0444, dapm_widget_show, NULL);
  1564. int snd_soc_dapm_sys_add(struct device *dev)
  1565. {
  1566. return device_create_file(dev, &dev_attr_dapm_widget);
  1567. }
  1568. static void snd_soc_dapm_sys_remove(struct device *dev)
  1569. {
  1570. device_remove_file(dev, &dev_attr_dapm_widget);
  1571. }
  1572. /* free all dapm widgets and resources */
  1573. static void dapm_free_widgets(struct snd_soc_dapm_context *dapm)
  1574. {
  1575. struct snd_soc_dapm_widget *w, *next_w;
  1576. struct snd_soc_dapm_path *p, *next_p;
  1577. list_for_each_entry_safe(w, next_w, &dapm->card->widgets, list) {
  1578. if (w->dapm != dapm)
  1579. continue;
  1580. list_del(&w->list);
  1581. /*
  1582. * remove source and sink paths associated to this widget.
  1583. * While removing the path, remove reference to it from both
  1584. * source and sink widgets so that path is removed only once.
  1585. */
  1586. list_for_each_entry_safe(p, next_p, &w->sources, list_sink) {
  1587. list_del(&p->list_sink);
  1588. list_del(&p->list_source);
  1589. list_del(&p->list);
  1590. kfree(p->long_name);
  1591. kfree(p);
  1592. }
  1593. list_for_each_entry_safe(p, next_p, &w->sinks, list_source) {
  1594. list_del(&p->list_sink);
  1595. list_del(&p->list_source);
  1596. list_del(&p->list);
  1597. kfree(p->long_name);
  1598. kfree(p);
  1599. }
  1600. kfree(w->kcontrols);
  1601. kfree(w->name);
  1602. kfree(w);
  1603. }
  1604. }
  1605. static struct snd_soc_dapm_widget *dapm_find_widget(
  1606. struct snd_soc_dapm_context *dapm, const char *pin,
  1607. bool search_other_contexts)
  1608. {
  1609. struct snd_soc_dapm_widget *w;
  1610. struct snd_soc_dapm_widget *fallback = NULL;
  1611. list_for_each_entry(w, &dapm->card->widgets, list) {
  1612. if (!strcmp(w->name, pin)) {
  1613. if (w->dapm == dapm)
  1614. return w;
  1615. else
  1616. fallback = w;
  1617. }
  1618. }
  1619. if (search_other_contexts)
  1620. return fallback;
  1621. return NULL;
  1622. }
  1623. static int snd_soc_dapm_set_pin(struct snd_soc_dapm_context *dapm,
  1624. const char *pin, int status)
  1625. {
  1626. struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true);
  1627. if (!w) {
  1628. dev_err(dapm->dev, "dapm: unknown pin %s\n", pin);
  1629. return -EINVAL;
  1630. }
  1631. w->connected = status;
  1632. if (status == 0)
  1633. w->force = 0;
  1634. dapm_mark_dirty(w, "pin configuration");
  1635. return 0;
  1636. }
  1637. /**
  1638. * snd_soc_dapm_sync - scan and power dapm paths
  1639. * @dapm: DAPM context
  1640. *
  1641. * Walks all dapm audio paths and powers widgets according to their
  1642. * stream or path usage.
  1643. *
  1644. * Returns 0 for success.
  1645. */
  1646. int snd_soc_dapm_sync(struct snd_soc_dapm_context *dapm)
  1647. {
  1648. /*
  1649. * Suppress early reports (eg, jacks syncing their state) to avoid
  1650. * silly DAPM runs during card startup.
  1651. */
  1652. if (!dapm->card || !dapm->card->instantiated)
  1653. return 0;
  1654. return dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP);
  1655. }
  1656. EXPORT_SYMBOL_GPL(snd_soc_dapm_sync);
  1657. static int snd_soc_dapm_add_route(struct snd_soc_dapm_context *dapm,
  1658. const struct snd_soc_dapm_route *route)
  1659. {
  1660. struct snd_soc_dapm_path *path;
  1661. struct snd_soc_dapm_widget *wsource = NULL, *wsink = NULL, *w;
  1662. struct snd_soc_dapm_widget *wtsource = NULL, *wtsink = NULL;
  1663. const char *sink;
  1664. const char *control = route->control;
  1665. const char *source;
  1666. char prefixed_sink[80];
  1667. char prefixed_source[80];
  1668. int ret = 0;
  1669. if (dapm->codec && dapm->codec->name_prefix) {
  1670. snprintf(prefixed_sink, sizeof(prefixed_sink), "%s %s",
  1671. dapm->codec->name_prefix, route->sink);
  1672. sink = prefixed_sink;
  1673. snprintf(prefixed_source, sizeof(prefixed_source), "%s %s",
  1674. dapm->codec->name_prefix, route->source);
  1675. source = prefixed_source;
  1676. } else {
  1677. sink = route->sink;
  1678. source = route->source;
  1679. }
  1680. /*
  1681. * find src and dest widgets over all widgets but favor a widget from
  1682. * current DAPM context
  1683. */
  1684. list_for_each_entry(w, &dapm->card->widgets, list) {
  1685. if (!wsink && !(strcmp(w->name, sink))) {
  1686. wtsink = w;
  1687. if (w->dapm == dapm)
  1688. wsink = w;
  1689. continue;
  1690. }
  1691. if (!wsource && !(strcmp(w->name, source))) {
  1692. wtsource = w;
  1693. if (w->dapm == dapm)
  1694. wsource = w;
  1695. }
  1696. }
  1697. /* use widget from another DAPM context if not found from this */
  1698. if (!wsink)
  1699. wsink = wtsink;
  1700. if (!wsource)
  1701. wsource = wtsource;
  1702. if (wsource == NULL || wsink == NULL)
  1703. return -ENODEV;
  1704. path = kzalloc(sizeof(struct snd_soc_dapm_path), GFP_KERNEL);
  1705. if (!path)
  1706. return -ENOMEM;
  1707. path->source = wsource;
  1708. path->sink = wsink;
  1709. path->connected = route->connected;
  1710. INIT_LIST_HEAD(&path->list);
  1711. INIT_LIST_HEAD(&path->list_source);
  1712. INIT_LIST_HEAD(&path->list_sink);
  1713. /* check for external widgets */
  1714. if (wsink->id == snd_soc_dapm_input) {
  1715. if (wsource->id == snd_soc_dapm_micbias ||
  1716. wsource->id == snd_soc_dapm_mic ||
  1717. wsource->id == snd_soc_dapm_line ||
  1718. wsource->id == snd_soc_dapm_output)
  1719. wsink->ext = 1;
  1720. }
  1721. if (wsource->id == snd_soc_dapm_output) {
  1722. if (wsink->id == snd_soc_dapm_spk ||
  1723. wsink->id == snd_soc_dapm_hp ||
  1724. wsink->id == snd_soc_dapm_line ||
  1725. wsink->id == snd_soc_dapm_input)
  1726. wsource->ext = 1;
  1727. }
  1728. /* connect static paths */
  1729. if (control == NULL) {
  1730. list_add(&path->list, &dapm->card->paths);
  1731. list_add(&path->list_sink, &wsink->sources);
  1732. list_add(&path->list_source, &wsource->sinks);
  1733. path->connect = 1;
  1734. return 0;
  1735. }
  1736. /* connect dynamic paths */
  1737. switch (wsink->id) {
  1738. case snd_soc_dapm_adc:
  1739. case snd_soc_dapm_dac:
  1740. case snd_soc_dapm_pga:
  1741. case snd_soc_dapm_out_drv:
  1742. case snd_soc_dapm_input:
  1743. case snd_soc_dapm_output:
  1744. case snd_soc_dapm_siggen:
  1745. case snd_soc_dapm_micbias:
  1746. case snd_soc_dapm_vmid:
  1747. case snd_soc_dapm_pre:
  1748. case snd_soc_dapm_post:
  1749. case snd_soc_dapm_supply:
  1750. case snd_soc_dapm_regulator_supply:
  1751. case snd_soc_dapm_aif_in:
  1752. case snd_soc_dapm_aif_out:
  1753. list_add(&path->list, &dapm->card->paths);
  1754. list_add(&path->list_sink, &wsink->sources);
  1755. list_add(&path->list_source, &wsource->sinks);
  1756. path->connect = 1;
  1757. return 0;
  1758. case snd_soc_dapm_mux:
  1759. case snd_soc_dapm_virt_mux:
  1760. case snd_soc_dapm_value_mux:
  1761. ret = dapm_connect_mux(dapm, wsource, wsink, path, control,
  1762. &wsink->kcontrol_news[0]);
  1763. if (ret != 0)
  1764. goto err;
  1765. break;
  1766. case snd_soc_dapm_switch:
  1767. case snd_soc_dapm_mixer:
  1768. case snd_soc_dapm_mixer_named_ctl:
  1769. ret = dapm_connect_mixer(dapm, wsource, wsink, path, control);
  1770. if (ret != 0)
  1771. goto err;
  1772. break;
  1773. case snd_soc_dapm_hp:
  1774. case snd_soc_dapm_mic:
  1775. case snd_soc_dapm_line:
  1776. case snd_soc_dapm_spk:
  1777. list_add(&path->list, &dapm->card->paths);
  1778. list_add(&path->list_sink, &wsink->sources);
  1779. list_add(&path->list_source, &wsource->sinks);
  1780. path->connect = 0;
  1781. return 0;
  1782. }
  1783. return 0;
  1784. err:
  1785. dev_warn(dapm->dev, "asoc: no dapm match for %s --> %s --> %s\n",
  1786. source, control, sink);
  1787. kfree(path);
  1788. return ret;
  1789. }
  1790. /**
  1791. * snd_soc_dapm_add_routes - Add routes between DAPM widgets
  1792. * @dapm: DAPM context
  1793. * @route: audio routes
  1794. * @num: number of routes
  1795. *
  1796. * Connects 2 dapm widgets together via a named audio path. The sink is
  1797. * the widget receiving the audio signal, whilst the source is the sender
  1798. * of the audio signal.
  1799. *
  1800. * Returns 0 for success else error. On error all resources can be freed
  1801. * with a call to snd_soc_card_free().
  1802. */
  1803. int snd_soc_dapm_add_routes(struct snd_soc_dapm_context *dapm,
  1804. const struct snd_soc_dapm_route *route, int num)
  1805. {
  1806. int i, ret;
  1807. for (i = 0; i < num; i++) {
  1808. ret = snd_soc_dapm_add_route(dapm, route);
  1809. if (ret < 0) {
  1810. dev_err(dapm->dev, "Failed to add route %s->%s\n",
  1811. route->source, route->sink);
  1812. return ret;
  1813. }
  1814. route++;
  1815. }
  1816. return 0;
  1817. }
  1818. EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes);
  1819. static int snd_soc_dapm_weak_route(struct snd_soc_dapm_context *dapm,
  1820. const struct snd_soc_dapm_route *route)
  1821. {
  1822. struct snd_soc_dapm_widget *source = dapm_find_widget(dapm,
  1823. route->source,
  1824. true);
  1825. struct snd_soc_dapm_widget *sink = dapm_find_widget(dapm,
  1826. route->sink,
  1827. true);
  1828. struct snd_soc_dapm_path *path;
  1829. int count = 0;
  1830. if (!source) {
  1831. dev_err(dapm->dev, "Unable to find source %s for weak route\n",
  1832. route->source);
  1833. return -ENODEV;
  1834. }
  1835. if (!sink) {
  1836. dev_err(dapm->dev, "Unable to find sink %s for weak route\n",
  1837. route->sink);
  1838. return -ENODEV;
  1839. }
  1840. if (route->control || route->connected)
  1841. dev_warn(dapm->dev, "Ignoring control for weak route %s->%s\n",
  1842. route->source, route->sink);
  1843. list_for_each_entry(path, &source->sinks, list_source) {
  1844. if (path->sink == sink) {
  1845. path->weak = 1;
  1846. count++;
  1847. }
  1848. }
  1849. if (count == 0)
  1850. dev_err(dapm->dev, "No path found for weak route %s->%s\n",
  1851. route->source, route->sink);
  1852. if (count > 1)
  1853. dev_warn(dapm->dev, "%d paths found for weak route %s->%s\n",
  1854. count, route->source, route->sink);
  1855. return 0;
  1856. }
  1857. /**
  1858. * snd_soc_dapm_weak_routes - Mark routes between DAPM widgets as weak
  1859. * @dapm: DAPM context
  1860. * @route: audio routes
  1861. * @num: number of routes
  1862. *
  1863. * Mark existing routes matching those specified in the passed array
  1864. * as being weak, meaning that they are ignored for the purpose of
  1865. * power decisions. The main intended use case is for sidetone paths
  1866. * which couple audio between other independent paths if they are both
  1867. * active in order to make the combination work better at the user
  1868. * level but which aren't intended to be "used".
  1869. *
  1870. * Note that CODEC drivers should not use this as sidetone type paths
  1871. * can frequently also be used as bypass paths.
  1872. */
  1873. int snd_soc_dapm_weak_routes(struct snd_soc_dapm_context *dapm,
  1874. const struct snd_soc_dapm_route *route, int num)
  1875. {
  1876. int i, err;
  1877. int ret = 0;
  1878. for (i = 0; i < num; i++) {
  1879. err = snd_soc_dapm_weak_route(dapm, route);
  1880. if (err)
  1881. ret = err;
  1882. route++;
  1883. }
  1884. return ret;
  1885. }
  1886. EXPORT_SYMBOL_GPL(snd_soc_dapm_weak_routes);
  1887. /**
  1888. * snd_soc_dapm_new_widgets - add new dapm widgets
  1889. * @dapm: DAPM context
  1890. *
  1891. * Checks the codec for any new dapm widgets and creates them if found.
  1892. *
  1893. * Returns 0 for success.
  1894. */
  1895. int snd_soc_dapm_new_widgets(struct snd_soc_dapm_context *dapm)
  1896. {
  1897. struct snd_soc_dapm_widget *w;
  1898. unsigned int val;
  1899. list_for_each_entry(w, &dapm->card->widgets, list)
  1900. {
  1901. if (w->new)
  1902. continue;
  1903. if (w->num_kcontrols) {
  1904. w->kcontrols = kzalloc(w->num_kcontrols *
  1905. sizeof(struct snd_kcontrol *),
  1906. GFP_KERNEL);
  1907. if (!w->kcontrols)
  1908. return -ENOMEM;
  1909. }
  1910. switch(w->id) {
  1911. case snd_soc_dapm_switch:
  1912. case snd_soc_dapm_mixer:
  1913. case snd_soc_dapm_mixer_named_ctl:
  1914. dapm_new_mixer(w);
  1915. break;
  1916. case snd_soc_dapm_mux:
  1917. case snd_soc_dapm_virt_mux:
  1918. case snd_soc_dapm_value_mux:
  1919. dapm_new_mux(w);
  1920. break;
  1921. case snd_soc_dapm_pga:
  1922. case snd_soc_dapm_out_drv:
  1923. dapm_new_pga(w);
  1924. break;
  1925. default:
  1926. break;
  1927. }
  1928. /* Read the initial power state from the device */
  1929. if (w->reg >= 0) {
  1930. val = soc_widget_read(w, w->reg);
  1931. val &= 1 << w->shift;
  1932. if (w->invert)
  1933. val = !val;
  1934. if (val)
  1935. w->power = 1;
  1936. }
  1937. w->new = 1;
  1938. dapm_mark_dirty(w, "new widget");
  1939. dapm_debugfs_add_widget(w);
  1940. }
  1941. dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP);
  1942. return 0;
  1943. }
  1944. EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets);
  1945. /**
  1946. * snd_soc_dapm_get_volsw - dapm mixer get callback
  1947. * @kcontrol: mixer control
  1948. * @ucontrol: control element information
  1949. *
  1950. * Callback to get the value of a dapm mixer control.
  1951. *
  1952. * Returns 0 for success.
  1953. */
  1954. int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol,
  1955. struct snd_ctl_elem_value *ucontrol)
  1956. {
  1957. struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
  1958. struct snd_soc_dapm_widget *widget = wlist->widgets[0];
  1959. struct soc_mixer_control *mc =
  1960. (struct soc_mixer_control *)kcontrol->private_value;
  1961. unsigned int reg = mc->reg;
  1962. unsigned int shift = mc->shift;
  1963. unsigned int rshift = mc->rshift;
  1964. int max = mc->max;
  1965. unsigned int invert = mc->invert;
  1966. unsigned int mask = (1 << fls(max)) - 1;
  1967. ucontrol->value.integer.value[0] =
  1968. (snd_soc_read(widget->codec, reg) >> shift) & mask;
  1969. if (shift != rshift)
  1970. ucontrol->value.integer.value[1] =
  1971. (snd_soc_read(widget->codec, reg) >> rshift) & mask;
  1972. if (invert) {
  1973. ucontrol->value.integer.value[0] =
  1974. max - ucontrol->value.integer.value[0];
  1975. if (shift != rshift)
  1976. ucontrol->value.integer.value[1] =
  1977. max - ucontrol->value.integer.value[1];
  1978. }
  1979. return 0;
  1980. }
  1981. EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw);
  1982. /**
  1983. * snd_soc_dapm_put_volsw - dapm mixer set callback
  1984. * @kcontrol: mixer control
  1985. * @ucontrol: control element information
  1986. *
  1987. * Callback to set the value of a dapm mixer control.
  1988. *
  1989. * Returns 0 for success.
  1990. */
  1991. int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol,
  1992. struct snd_ctl_elem_value *ucontrol)
  1993. {
  1994. struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
  1995. struct snd_soc_dapm_widget *widget = wlist->widgets[0];
  1996. struct snd_soc_codec *codec = widget->codec;
  1997. struct soc_mixer_control *mc =
  1998. (struct soc_mixer_control *)kcontrol->private_value;
  1999. unsigned int reg = mc->reg;
  2000. unsigned int shift = mc->shift;
  2001. int max = mc->max;
  2002. unsigned int mask = (1 << fls(max)) - 1;
  2003. unsigned int invert = mc->invert;
  2004. unsigned int val;
  2005. int connect, change;
  2006. struct snd_soc_dapm_update update;
  2007. int wi;
  2008. val = (ucontrol->value.integer.value[0] & mask);
  2009. if (invert)
  2010. val = max - val;
  2011. mask = mask << shift;
  2012. val = val << shift;
  2013. if (val)
  2014. /* new connection */
  2015. connect = invert ? 0 : 1;
  2016. else
  2017. /* old connection must be powered down */
  2018. connect = invert ? 1 : 0;
  2019. mutex_lock(&codec->mutex);
  2020. change = snd_soc_test_bits(widget->codec, reg, mask, val);
  2021. if (change) {
  2022. for (wi = 0; wi < wlist->num_widgets; wi++) {
  2023. widget = wlist->widgets[wi];
  2024. widget->value = val;
  2025. update.kcontrol = kcontrol;
  2026. update.widget = widget;
  2027. update.reg = reg;
  2028. update.mask = mask;
  2029. update.val = val;
  2030. widget->dapm->update = &update;
  2031. snd_soc_dapm_mixer_update_power(widget, kcontrol, connect);
  2032. widget->dapm->update = NULL;
  2033. }
  2034. }
  2035. mutex_unlock(&codec->mutex);
  2036. return 0;
  2037. }
  2038. EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw);
  2039. /**
  2040. * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback
  2041. * @kcontrol: mixer control
  2042. * @ucontrol: control element information
  2043. *
  2044. * Callback to get the value of a dapm enumerated double mixer control.
  2045. *
  2046. * Returns 0 for success.
  2047. */
  2048. int snd_soc_dapm_get_enum_double(struct snd_kcontrol *kcontrol,
  2049. struct snd_ctl_elem_value *ucontrol)
  2050. {
  2051. struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
  2052. struct snd_soc_dapm_widget *widget = wlist->widgets[0];
  2053. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  2054. unsigned int val, bitmask;
  2055. for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
  2056. ;
  2057. val = snd_soc_read(widget->codec, e->reg);
  2058. ucontrol->value.enumerated.item[0] = (val >> e->shift_l) & (bitmask - 1);
  2059. if (e->shift_l != e->shift_r)
  2060. ucontrol->value.enumerated.item[1] =
  2061. (val >> e->shift_r) & (bitmask - 1);
  2062. return 0;
  2063. }
  2064. EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double);
  2065. /**
  2066. * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback
  2067. * @kcontrol: mixer control
  2068. * @ucontrol: control element information
  2069. *
  2070. * Callback to set the value of a dapm enumerated double mixer control.
  2071. *
  2072. * Returns 0 for success.
  2073. */
  2074. int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol,
  2075. struct snd_ctl_elem_value *ucontrol)
  2076. {
  2077. struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
  2078. struct snd_soc_dapm_widget *widget = wlist->widgets[0];
  2079. struct snd_soc_codec *codec = widget->codec;
  2080. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  2081. unsigned int val, mux, change;
  2082. unsigned int mask, bitmask;
  2083. struct snd_soc_dapm_update update;
  2084. int wi;
  2085. for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
  2086. ;
  2087. if (ucontrol->value.enumerated.item[0] > e->max - 1)
  2088. return -EINVAL;
  2089. mux = ucontrol->value.enumerated.item[0];
  2090. val = mux << e->shift_l;
  2091. mask = (bitmask - 1) << e->shift_l;
  2092. if (e->shift_l != e->shift_r) {
  2093. if (ucontrol->value.enumerated.item[1] > e->max - 1)
  2094. return -EINVAL;
  2095. val |= ucontrol->value.enumerated.item[1] << e->shift_r;
  2096. mask |= (bitmask - 1) << e->shift_r;
  2097. }
  2098. mutex_lock(&codec->mutex);
  2099. change = snd_soc_test_bits(widget->codec, e->reg, mask, val);
  2100. if (change) {
  2101. for (wi = 0; wi < wlist->num_widgets; wi++) {
  2102. widget = wlist->widgets[wi];
  2103. widget->value = val;
  2104. update.kcontrol = kcontrol;
  2105. update.widget = widget;
  2106. update.reg = e->reg;
  2107. update.mask = mask;
  2108. update.val = val;
  2109. widget->dapm->update = &update;
  2110. snd_soc_dapm_mux_update_power(widget, kcontrol, mux, e);
  2111. widget->dapm->update = NULL;
  2112. }
  2113. }
  2114. mutex_unlock(&codec->mutex);
  2115. return change;
  2116. }
  2117. EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double);
  2118. /**
  2119. * snd_soc_dapm_get_enum_virt - Get virtual DAPM mux
  2120. * @kcontrol: mixer control
  2121. * @ucontrol: control element information
  2122. *
  2123. * Returns 0 for success.
  2124. */
  2125. int snd_soc_dapm_get_enum_virt(struct snd_kcontrol *kcontrol,
  2126. struct snd_ctl_elem_value *ucontrol)
  2127. {
  2128. struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
  2129. struct snd_soc_dapm_widget *widget = wlist->widgets[0];
  2130. ucontrol->value.enumerated.item[0] = widget->value;
  2131. return 0;
  2132. }
  2133. EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_virt);
  2134. /**
  2135. * snd_soc_dapm_put_enum_virt - Set virtual DAPM mux
  2136. * @kcontrol: mixer control
  2137. * @ucontrol: control element information
  2138. *
  2139. * Returns 0 for success.
  2140. */
  2141. int snd_soc_dapm_put_enum_virt(struct snd_kcontrol *kcontrol,
  2142. struct snd_ctl_elem_value *ucontrol)
  2143. {
  2144. struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
  2145. struct snd_soc_dapm_widget *widget = wlist->widgets[0];
  2146. struct snd_soc_codec *codec = widget->codec;
  2147. struct soc_enum *e =
  2148. (struct soc_enum *)kcontrol->private_value;
  2149. int change;
  2150. int ret = 0;
  2151. int wi;
  2152. if (ucontrol->value.enumerated.item[0] >= e->max)
  2153. return -EINVAL;
  2154. mutex_lock(&codec->mutex);
  2155. change = widget->value != ucontrol->value.enumerated.item[0];
  2156. if (change) {
  2157. for (wi = 0; wi < wlist->num_widgets; wi++) {
  2158. widget = wlist->widgets[wi];
  2159. widget->value = ucontrol->value.enumerated.item[0];
  2160. snd_soc_dapm_mux_update_power(widget, kcontrol, widget->value, e);
  2161. }
  2162. }
  2163. mutex_unlock(&codec->mutex);
  2164. return ret;
  2165. }
  2166. EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_virt);
  2167. /**
  2168. * snd_soc_dapm_get_value_enum_double - dapm semi enumerated double mixer get
  2169. * callback
  2170. * @kcontrol: mixer control
  2171. * @ucontrol: control element information
  2172. *
  2173. * Callback to get the value of a dapm semi enumerated double mixer control.
  2174. *
  2175. * Semi enumerated mixer: the enumerated items are referred as values. Can be
  2176. * used for handling bitfield coded enumeration for example.
  2177. *
  2178. * Returns 0 for success.
  2179. */
  2180. int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol *kcontrol,
  2181. struct snd_ctl_elem_value *ucontrol)
  2182. {
  2183. struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
  2184. struct snd_soc_dapm_widget *widget = wlist->widgets[0];
  2185. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  2186. unsigned int reg_val, val, mux;
  2187. reg_val = snd_soc_read(widget->codec, e->reg);
  2188. val = (reg_val >> e->shift_l) & e->mask;
  2189. for (mux = 0; mux < e->max; mux++) {
  2190. if (val == e->values[mux])
  2191. break;
  2192. }
  2193. ucontrol->value.enumerated.item[0] = mux;
  2194. if (e->shift_l != e->shift_r) {
  2195. val = (reg_val >> e->shift_r) & e->mask;
  2196. for (mux = 0; mux < e->max; mux++) {
  2197. if (val == e->values[mux])
  2198. break;
  2199. }
  2200. ucontrol->value.enumerated.item[1] = mux;
  2201. }
  2202. return 0;
  2203. }
  2204. EXPORT_SYMBOL_GPL(snd_soc_dapm_get_value_enum_double);
  2205. /**
  2206. * snd_soc_dapm_put_value_enum_double - dapm semi enumerated double mixer set
  2207. * callback
  2208. * @kcontrol: mixer control
  2209. * @ucontrol: control element information
  2210. *
  2211. * Callback to set the value of a dapm semi enumerated double mixer control.
  2212. *
  2213. * Semi enumerated mixer: the enumerated items are referred as values. Can be
  2214. * used for handling bitfield coded enumeration for example.
  2215. *
  2216. * Returns 0 for success.
  2217. */
  2218. int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol *kcontrol,
  2219. struct snd_ctl_elem_value *ucontrol)
  2220. {
  2221. struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
  2222. struct snd_soc_dapm_widget *widget = wlist->widgets[0];
  2223. struct snd_soc_codec *codec = widget->codec;
  2224. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  2225. unsigned int val, mux, change;
  2226. unsigned int mask;
  2227. struct snd_soc_dapm_update update;
  2228. int wi;
  2229. if (ucontrol->value.enumerated.item[0] > e->max - 1)
  2230. return -EINVAL;
  2231. mux = ucontrol->value.enumerated.item[0];
  2232. val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l;
  2233. mask = e->mask << e->shift_l;
  2234. if (e->shift_l != e->shift_r) {
  2235. if (ucontrol->value.enumerated.item[1] > e->max - 1)
  2236. return -EINVAL;
  2237. val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r;
  2238. mask |= e->mask << e->shift_r;
  2239. }
  2240. mutex_lock(&codec->mutex);
  2241. change = snd_soc_test_bits(widget->codec, e->reg, mask, val);
  2242. if (change) {
  2243. for (wi = 0; wi < wlist->num_widgets; wi++) {
  2244. widget = wlist->widgets[wi];
  2245. widget->value = val;
  2246. update.kcontrol = kcontrol;
  2247. update.widget = widget;
  2248. update.reg = e->reg;
  2249. update.mask = mask;
  2250. update.val = val;
  2251. widget->dapm->update = &update;
  2252. snd_soc_dapm_mux_update_power(widget, kcontrol, mux, e);
  2253. widget->dapm->update = NULL;
  2254. }
  2255. }
  2256. mutex_unlock(&codec->mutex);
  2257. return change;
  2258. }
  2259. EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double);
  2260. /**
  2261. * snd_soc_dapm_info_pin_switch - Info for a pin switch
  2262. *
  2263. * @kcontrol: mixer control
  2264. * @uinfo: control element information
  2265. *
  2266. * Callback to provide information about a pin switch control.
  2267. */
  2268. int snd_soc_dapm_info_pin_switch(struct snd_kcontrol *kcontrol,
  2269. struct snd_ctl_elem_info *uinfo)
  2270. {
  2271. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  2272. uinfo->count = 1;
  2273. uinfo->value.integer.min = 0;
  2274. uinfo->value.integer.max = 1;
  2275. return 0;
  2276. }
  2277. EXPORT_SYMBOL_GPL(snd_soc_dapm_info_pin_switch);
  2278. /**
  2279. * snd_soc_dapm_get_pin_switch - Get information for a pin switch
  2280. *
  2281. * @kcontrol: mixer control
  2282. * @ucontrol: Value
  2283. */
  2284. int snd_soc_dapm_get_pin_switch(struct snd_kcontrol *kcontrol,
  2285. struct snd_ctl_elem_value *ucontrol)
  2286. {
  2287. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  2288. const char *pin = (const char *)kcontrol->private_value;
  2289. mutex_lock(&codec->mutex);
  2290. ucontrol->value.integer.value[0] =
  2291. snd_soc_dapm_get_pin_status(&codec->dapm, pin);
  2292. mutex_unlock(&codec->mutex);
  2293. return 0;
  2294. }
  2295. EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_switch);
  2296. /**
  2297. * snd_soc_dapm_put_pin_switch - Set information for a pin switch
  2298. *
  2299. * @kcontrol: mixer control
  2300. * @ucontrol: Value
  2301. */
  2302. int snd_soc_dapm_put_pin_switch(struct snd_kcontrol *kcontrol,
  2303. struct snd_ctl_elem_value *ucontrol)
  2304. {
  2305. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  2306. const char *pin = (const char *)kcontrol->private_value;
  2307. mutex_lock(&codec->mutex);
  2308. if (ucontrol->value.integer.value[0])
  2309. snd_soc_dapm_enable_pin(&codec->dapm, pin);
  2310. else
  2311. snd_soc_dapm_disable_pin(&codec->dapm, pin);
  2312. snd_soc_dapm_sync(&codec->dapm);
  2313. mutex_unlock(&codec->mutex);
  2314. return 0;
  2315. }
  2316. EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch);
  2317. /**
  2318. * snd_soc_dapm_new_control - create new dapm control
  2319. * @dapm: DAPM context
  2320. * @widget: widget template
  2321. *
  2322. * Creates a new dapm control based upon the template.
  2323. *
  2324. * Returns 0 for success else error.
  2325. */
  2326. int snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm,
  2327. const struct snd_soc_dapm_widget *widget)
  2328. {
  2329. struct snd_soc_dapm_widget *w;
  2330. size_t name_len;
  2331. int ret;
  2332. if ((w = dapm_cnew_widget(widget)) == NULL)
  2333. return -ENOMEM;
  2334. switch (w->id) {
  2335. case snd_soc_dapm_regulator_supply:
  2336. w->priv = devm_regulator_get(dapm->dev, w->name);
  2337. if (IS_ERR(w->priv)) {
  2338. ret = PTR_ERR(w->priv);
  2339. dev_err(dapm->dev, "Failed to request %s: %d\n",
  2340. w->name, ret);
  2341. return ret;
  2342. }
  2343. break;
  2344. default:
  2345. break;
  2346. }
  2347. name_len = strlen(widget->name) + 1;
  2348. if (dapm->codec && dapm->codec->name_prefix)
  2349. name_len += 1 + strlen(dapm->codec->name_prefix);
  2350. w->name = kmalloc(name_len, GFP_KERNEL);
  2351. if (w->name == NULL) {
  2352. kfree(w);
  2353. return -ENOMEM;
  2354. }
  2355. if (dapm->codec && dapm->codec->name_prefix)
  2356. snprintf(w->name, name_len, "%s %s",
  2357. dapm->codec->name_prefix, widget->name);
  2358. else
  2359. snprintf(w->name, name_len, "%s", widget->name);
  2360. switch (w->id) {
  2361. case snd_soc_dapm_switch:
  2362. case snd_soc_dapm_mixer:
  2363. case snd_soc_dapm_mixer_named_ctl:
  2364. w->power_check = dapm_generic_check_power;
  2365. break;
  2366. case snd_soc_dapm_mux:
  2367. case snd_soc_dapm_virt_mux:
  2368. case snd_soc_dapm_value_mux:
  2369. w->power_check = dapm_generic_check_power;
  2370. break;
  2371. case snd_soc_dapm_adc:
  2372. case snd_soc_dapm_aif_out:
  2373. w->power_check = dapm_adc_check_power;
  2374. break;
  2375. case snd_soc_dapm_dac:
  2376. case snd_soc_dapm_aif_in:
  2377. w->power_check = dapm_dac_check_power;
  2378. break;
  2379. case snd_soc_dapm_pga:
  2380. case snd_soc_dapm_out_drv:
  2381. case snd_soc_dapm_input:
  2382. case snd_soc_dapm_output:
  2383. case snd_soc_dapm_micbias:
  2384. case snd_soc_dapm_spk:
  2385. case snd_soc_dapm_hp:
  2386. case snd_soc_dapm_mic:
  2387. case snd_soc_dapm_line:
  2388. w->power_check = dapm_generic_check_power;
  2389. break;
  2390. case snd_soc_dapm_supply:
  2391. case snd_soc_dapm_regulator_supply:
  2392. w->power_check = dapm_supply_check_power;
  2393. break;
  2394. default:
  2395. w->power_check = dapm_always_on_check_power;
  2396. break;
  2397. }
  2398. dapm->n_widgets++;
  2399. w->dapm = dapm;
  2400. w->codec = dapm->codec;
  2401. w->platform = dapm->platform;
  2402. INIT_LIST_HEAD(&w->sources);
  2403. INIT_LIST_HEAD(&w->sinks);
  2404. INIT_LIST_HEAD(&w->list);
  2405. INIT_LIST_HEAD(&w->dirty);
  2406. list_add(&w->list, &dapm->card->widgets);
  2407. /* machine layer set ups unconnected pins and insertions */
  2408. w->connected = 1;
  2409. return 0;
  2410. }
  2411. EXPORT_SYMBOL_GPL(snd_soc_dapm_new_control);
  2412. /**
  2413. * snd_soc_dapm_new_controls - create new dapm controls
  2414. * @dapm: DAPM context
  2415. * @widget: widget array
  2416. * @num: number of widgets
  2417. *
  2418. * Creates new DAPM controls based upon the templates.
  2419. *
  2420. * Returns 0 for success else error.
  2421. */
  2422. int snd_soc_dapm_new_controls(struct snd_soc_dapm_context *dapm,
  2423. const struct snd_soc_dapm_widget *widget,
  2424. int num)
  2425. {
  2426. int i, ret;
  2427. for (i = 0; i < num; i++) {
  2428. ret = snd_soc_dapm_new_control(dapm, widget);
  2429. if (ret < 0) {
  2430. dev_err(dapm->dev,
  2431. "ASoC: Failed to create DAPM control %s: %d\n",
  2432. widget->name, ret);
  2433. return ret;
  2434. }
  2435. widget++;
  2436. }
  2437. return 0;
  2438. }
  2439. EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls);
  2440. static void soc_dapm_stream_event(struct snd_soc_dapm_context *dapm,
  2441. const char *stream, int event)
  2442. {
  2443. struct snd_soc_dapm_widget *w;
  2444. list_for_each_entry(w, &dapm->card->widgets, list)
  2445. {
  2446. if (!w->sname || w->dapm != dapm)
  2447. continue;
  2448. dev_vdbg(w->dapm->dev, "widget %s\n %s stream %s event %d\n",
  2449. w->name, w->sname, stream, event);
  2450. if (strstr(w->sname, stream)) {
  2451. dapm_mark_dirty(w, "stream event");
  2452. switch(event) {
  2453. case SND_SOC_DAPM_STREAM_START:
  2454. w->active = 1;
  2455. break;
  2456. case SND_SOC_DAPM_STREAM_STOP:
  2457. w->active = 0;
  2458. break;
  2459. case SND_SOC_DAPM_STREAM_SUSPEND:
  2460. case SND_SOC_DAPM_STREAM_RESUME:
  2461. case SND_SOC_DAPM_STREAM_PAUSE_PUSH:
  2462. case SND_SOC_DAPM_STREAM_PAUSE_RELEASE:
  2463. break;
  2464. }
  2465. }
  2466. }
  2467. dapm_power_widgets(dapm, event);
  2468. /* do we need to notify any clients that DAPM stream is complete */
  2469. if (dapm->stream_event)
  2470. dapm->stream_event(dapm, event);
  2471. }
  2472. /**
  2473. * snd_soc_dapm_stream_event - send a stream event to the dapm core
  2474. * @rtd: PCM runtime data
  2475. * @stream: stream name
  2476. * @event: stream event
  2477. *
  2478. * Sends a stream event to the dapm core. The core then makes any
  2479. * necessary widget power changes.
  2480. *
  2481. * Returns 0 for success else error.
  2482. */
  2483. int snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd,
  2484. const char *stream, int event)
  2485. {
  2486. struct snd_soc_codec *codec = rtd->codec;
  2487. if (stream == NULL)
  2488. return 0;
  2489. mutex_lock(&codec->mutex);
  2490. soc_dapm_stream_event(&codec->dapm, stream, event);
  2491. mutex_unlock(&codec->mutex);
  2492. return 0;
  2493. }
  2494. /**
  2495. * snd_soc_dapm_enable_pin - enable pin.
  2496. * @dapm: DAPM context
  2497. * @pin: pin name
  2498. *
  2499. * Enables input/output pin and its parents or children widgets iff there is
  2500. * a valid audio route and active audio stream.
  2501. * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
  2502. * do any widget power switching.
  2503. */
  2504. int snd_soc_dapm_enable_pin(struct snd_soc_dapm_context *dapm, const char *pin)
  2505. {
  2506. return snd_soc_dapm_set_pin(dapm, pin, 1);
  2507. }
  2508. EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin);
  2509. /**
  2510. * snd_soc_dapm_force_enable_pin - force a pin to be enabled
  2511. * @dapm: DAPM context
  2512. * @pin: pin name
  2513. *
  2514. * Enables input/output pin regardless of any other state. This is
  2515. * intended for use with microphone bias supplies used in microphone
  2516. * jack detection.
  2517. *
  2518. * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
  2519. * do any widget power switching.
  2520. */
  2521. int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context *dapm,
  2522. const char *pin)
  2523. {
  2524. struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true);
  2525. if (!w) {
  2526. dev_err(dapm->dev, "dapm: unknown pin %s\n", pin);
  2527. return -EINVAL;
  2528. }
  2529. dev_dbg(w->dapm->dev, "dapm: force enable pin %s\n", pin);
  2530. w->connected = 1;
  2531. w->force = 1;
  2532. dapm_mark_dirty(w, "force enable");
  2533. return 0;
  2534. }
  2535. EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin);
  2536. /**
  2537. * snd_soc_dapm_disable_pin - disable pin.
  2538. * @dapm: DAPM context
  2539. * @pin: pin name
  2540. *
  2541. * Disables input/output pin and its parents or children widgets.
  2542. * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
  2543. * do any widget power switching.
  2544. */
  2545. int snd_soc_dapm_disable_pin(struct snd_soc_dapm_context *dapm,
  2546. const char *pin)
  2547. {
  2548. return snd_soc_dapm_set_pin(dapm, pin, 0);
  2549. }
  2550. EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin);
  2551. /**
  2552. * snd_soc_dapm_nc_pin - permanently disable pin.
  2553. * @dapm: DAPM context
  2554. * @pin: pin name
  2555. *
  2556. * Marks the specified pin as being not connected, disabling it along
  2557. * any parent or child widgets. At present this is identical to
  2558. * snd_soc_dapm_disable_pin() but in future it will be extended to do
  2559. * additional things such as disabling controls which only affect
  2560. * paths through the pin.
  2561. *
  2562. * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
  2563. * do any widget power switching.
  2564. */
  2565. int snd_soc_dapm_nc_pin(struct snd_soc_dapm_context *dapm, const char *pin)
  2566. {
  2567. return snd_soc_dapm_set_pin(dapm, pin, 0);
  2568. }
  2569. EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin);
  2570. /**
  2571. * snd_soc_dapm_get_pin_status - get audio pin status
  2572. * @dapm: DAPM context
  2573. * @pin: audio signal pin endpoint (or start point)
  2574. *
  2575. * Get audio pin status - connected or disconnected.
  2576. *
  2577. * Returns 1 for connected otherwise 0.
  2578. */
  2579. int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context *dapm,
  2580. const char *pin)
  2581. {
  2582. struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true);
  2583. if (w)
  2584. return w->connected;
  2585. return 0;
  2586. }
  2587. EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status);
  2588. /**
  2589. * snd_soc_dapm_ignore_suspend - ignore suspend status for DAPM endpoint
  2590. * @dapm: DAPM context
  2591. * @pin: audio signal pin endpoint (or start point)
  2592. *
  2593. * Mark the given endpoint or pin as ignoring suspend. When the
  2594. * system is disabled a path between two endpoints flagged as ignoring
  2595. * suspend will not be disabled. The path must already be enabled via
  2596. * normal means at suspend time, it will not be turned on if it was not
  2597. * already enabled.
  2598. */
  2599. int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context *dapm,
  2600. const char *pin)
  2601. {
  2602. struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, false);
  2603. if (!w) {
  2604. dev_err(dapm->dev, "dapm: unknown pin %s\n", pin);
  2605. return -EINVAL;
  2606. }
  2607. w->ignore_suspend = 1;
  2608. return 0;
  2609. }
  2610. EXPORT_SYMBOL_GPL(snd_soc_dapm_ignore_suspend);
  2611. static bool snd_soc_dapm_widget_in_card_paths(struct snd_soc_card *card,
  2612. struct snd_soc_dapm_widget *w)
  2613. {
  2614. struct snd_soc_dapm_path *p;
  2615. list_for_each_entry(p, &card->paths, list) {
  2616. if ((p->source == w) || (p->sink == w)) {
  2617. dev_dbg(card->dev,
  2618. "... Path %s(id:%d dapm:%p) - %s(id:%d dapm:%p)\n",
  2619. p->source->name, p->source->id, p->source->dapm,
  2620. p->sink->name, p->sink->id, p->sink->dapm);
  2621. /* Connected to something other than the codec */
  2622. if (p->source->dapm != p->sink->dapm)
  2623. return true;
  2624. /*
  2625. * Loopback connection from codec external pin to
  2626. * codec external pin
  2627. */
  2628. if (p->sink->id == snd_soc_dapm_input) {
  2629. switch (p->source->id) {
  2630. case snd_soc_dapm_output:
  2631. case snd_soc_dapm_micbias:
  2632. return true;
  2633. default:
  2634. break;
  2635. }
  2636. }
  2637. }
  2638. }
  2639. return false;
  2640. }
  2641. /**
  2642. * snd_soc_dapm_auto_nc_codec_pins - call snd_soc_dapm_nc_pin for unused pins
  2643. * @codec: The codec whose pins should be processed
  2644. *
  2645. * Automatically call snd_soc_dapm_nc_pin() for any external pins in the codec
  2646. * which are unused. Pins are used if they are connected externally to the
  2647. * codec, whether that be to some other device, or a loop-back connection to
  2648. * the codec itself.
  2649. */
  2650. void snd_soc_dapm_auto_nc_codec_pins(struct snd_soc_codec *codec)
  2651. {
  2652. struct snd_soc_card *card = codec->card;
  2653. struct snd_soc_dapm_context *dapm = &codec->dapm;
  2654. struct snd_soc_dapm_widget *w;
  2655. dev_dbg(codec->dev, "Auto NC: DAPMs: card:%p codec:%p\n",
  2656. &card->dapm, &codec->dapm);
  2657. list_for_each_entry(w, &card->widgets, list) {
  2658. if (w->dapm != dapm)
  2659. continue;
  2660. switch (w->id) {
  2661. case snd_soc_dapm_input:
  2662. case snd_soc_dapm_output:
  2663. case snd_soc_dapm_micbias:
  2664. dev_dbg(codec->dev, "Auto NC: Checking widget %s\n",
  2665. w->name);
  2666. if (!snd_soc_dapm_widget_in_card_paths(card, w)) {
  2667. dev_dbg(codec->dev,
  2668. "... Not in map; disabling\n");
  2669. snd_soc_dapm_nc_pin(dapm, w->name);
  2670. }
  2671. break;
  2672. default:
  2673. break;
  2674. }
  2675. }
  2676. }
  2677. /**
  2678. * snd_soc_dapm_free - free dapm resources
  2679. * @dapm: DAPM context
  2680. *
  2681. * Free all dapm widgets and resources.
  2682. */
  2683. void snd_soc_dapm_free(struct snd_soc_dapm_context *dapm)
  2684. {
  2685. snd_soc_dapm_sys_remove(dapm->dev);
  2686. dapm_debugfs_cleanup(dapm);
  2687. dapm_free_widgets(dapm);
  2688. list_del(&dapm->list);
  2689. }
  2690. EXPORT_SYMBOL_GPL(snd_soc_dapm_free);
  2691. static void soc_dapm_shutdown_codec(struct snd_soc_dapm_context *dapm)
  2692. {
  2693. struct snd_soc_dapm_widget *w;
  2694. LIST_HEAD(down_list);
  2695. int powerdown = 0;
  2696. list_for_each_entry(w, &dapm->card->widgets, list) {
  2697. if (w->dapm != dapm)
  2698. continue;
  2699. if (w->power) {
  2700. dapm_seq_insert(w, &down_list, false);
  2701. w->power = 0;
  2702. powerdown = 1;
  2703. }
  2704. }
  2705. /* If there were no widgets to power down we're already in
  2706. * standby.
  2707. */
  2708. if (powerdown) {
  2709. snd_soc_dapm_set_bias_level(dapm, SND_SOC_BIAS_PREPARE);
  2710. dapm_seq_run(dapm, &down_list, 0, false);
  2711. snd_soc_dapm_set_bias_level(dapm, SND_SOC_BIAS_STANDBY);
  2712. }
  2713. }
  2714. /*
  2715. * snd_soc_dapm_shutdown - callback for system shutdown
  2716. */
  2717. void snd_soc_dapm_shutdown(struct snd_soc_card *card)
  2718. {
  2719. struct snd_soc_codec *codec;
  2720. list_for_each_entry(codec, &card->codec_dev_list, list) {
  2721. soc_dapm_shutdown_codec(&codec->dapm);
  2722. snd_soc_dapm_set_bias_level(&codec->dapm, SND_SOC_BIAS_OFF);
  2723. }
  2724. }
  2725. /* Module information */
  2726. MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
  2727. MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC");
  2728. MODULE_LICENSE("GPL");