soc-dapm.c 91 KB

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