soc-dapm.c 92 KB

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