soc-dapm.c 92 KB

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