soc-core.c 93 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802
  1. // SPDX-License-Identifier: GPL-2.0+
  2. //
  3. // soc-core.c -- ALSA SoC Audio Layer
  4. //
  5. // Copyright 2005 Wolfson Microelectronics PLC.
  6. // Copyright 2005 Openedhand Ltd.
  7. // Copyright (C) 2010 Slimlogic Ltd.
  8. // Copyright (C) 2010 Texas Instruments Inc.
  9. //
  10. // Author: Liam Girdwood <lrg@slimlogic.co.uk>
  11. // with code, comments and ideas from :-
  12. // Richard Purdie <richard@openedhand.com>
  13. //
  14. // TODO:
  15. // o Add hw rules to enforce rates, etc.
  16. // o More testing with other codecs/machines.
  17. // o Add more codecs and platforms to ensure good API coverage.
  18. // o Support TDM on PCM and I2S
  19. #include <linux/module.h>
  20. #include <linux/moduleparam.h>
  21. #include <linux/init.h>
  22. #include <linux/delay.h>
  23. #include <linux/pm.h>
  24. #include <linux/bitops.h>
  25. #include <linux/debugfs.h>
  26. #include <linux/platform_device.h>
  27. #include <linux/pinctrl/consumer.h>
  28. #include <linux/ctype.h>
  29. #include <linux/slab.h>
  30. #include <linux/of.h>
  31. #include <linux/of_graph.h>
  32. #include <linux/dmi.h>
  33. #include <linux/acpi.h>
  34. #include <sound/core.h>
  35. #include <sound/pcm.h>
  36. #include <sound/pcm_params.h>
  37. #include <sound/soc.h>
  38. #include <sound/soc-dpcm.h>
  39. #include <sound/soc-topology.h>
  40. #include <sound/soc-link.h>
  41. #include <sound/initval.h>
  42. #define CREATE_TRACE_POINTS
  43. #include <trace/events/asoc.h>
  44. static DEFINE_MUTEX(client_mutex);
  45. static LIST_HEAD(component_list);
  46. static LIST_HEAD(unbind_card_list);
  47. #define for_each_component(component) \
  48. list_for_each_entry(component, &component_list, list)
  49. /*
  50. * This is used if driver don't need to have CPU/Codec/Platform
  51. * dai_link. see soc.h
  52. */
  53. struct snd_soc_dai_link_component null_dailink_component[0];
  54. EXPORT_SYMBOL_GPL(null_dailink_component);
  55. /*
  56. * This is a timeout to do a DAPM powerdown after a stream is closed().
  57. * It can be used to eliminate pops between different playback streams, e.g.
  58. * between two audio tracks.
  59. */
  60. static int pmdown_time = 5000;
  61. module_param(pmdown_time, int, 0);
  62. MODULE_PARM_DESC(pmdown_time, "DAPM stream powerdown time (msecs)");
  63. static ssize_t pmdown_time_show(struct device *dev,
  64. struct device_attribute *attr, char *buf)
  65. {
  66. struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
  67. return sysfs_emit(buf, "%ld\n", rtd->pmdown_time);
  68. }
  69. static ssize_t pmdown_time_store(struct device *dev,
  70. struct device_attribute *attr,
  71. const char *buf, size_t count)
  72. {
  73. struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
  74. int ret;
  75. ret = kstrtol(buf, 10, &rtd->pmdown_time);
  76. if (ret)
  77. return ret;
  78. return count;
  79. }
  80. static DEVICE_ATTR_RW(pmdown_time);
  81. static struct attribute *soc_dev_attrs[] = {
  82. &dev_attr_pmdown_time.attr,
  83. NULL
  84. };
  85. static umode_t soc_dev_attr_is_visible(struct kobject *kobj,
  86. struct attribute *attr, int idx)
  87. {
  88. struct device *dev = kobj_to_dev(kobj);
  89. struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
  90. if (!rtd)
  91. return 0;
  92. if (attr == &dev_attr_pmdown_time.attr)
  93. return attr->mode; /* always visible */
  94. return rtd->dai_link->num_codecs ? attr->mode : 0; /* enabled only with codec */
  95. }
  96. static const struct attribute_group soc_dapm_dev_group = {
  97. .attrs = soc_dapm_dev_attrs,
  98. .is_visible = soc_dev_attr_is_visible,
  99. };
  100. static const struct attribute_group soc_dev_group = {
  101. .attrs = soc_dev_attrs,
  102. .is_visible = soc_dev_attr_is_visible,
  103. };
  104. static const struct attribute_group *soc_dev_attr_groups[] = {
  105. &soc_dapm_dev_group,
  106. &soc_dev_group,
  107. NULL
  108. };
  109. #ifdef CONFIG_DEBUG_FS
  110. struct dentry *snd_soc_debugfs_root;
  111. EXPORT_SYMBOL_GPL(snd_soc_debugfs_root);
  112. static void soc_init_component_debugfs(struct snd_soc_component *component)
  113. {
  114. if (!component->card->debugfs_card_root)
  115. return;
  116. if (component->debugfs_prefix) {
  117. char *name;
  118. name = kasprintf(GFP_KERNEL, "%s:%s",
  119. component->debugfs_prefix, component->name);
  120. if (name) {
  121. component->debugfs_root = debugfs_create_dir(name,
  122. component->card->debugfs_card_root);
  123. kfree(name);
  124. }
  125. } else {
  126. component->debugfs_root = debugfs_create_dir(component->name,
  127. component->card->debugfs_card_root);
  128. }
  129. snd_soc_dapm_debugfs_init(snd_soc_component_get_dapm(component),
  130. component->debugfs_root);
  131. }
  132. static void soc_cleanup_component_debugfs(struct snd_soc_component *component)
  133. {
  134. if (!component->debugfs_root)
  135. return;
  136. debugfs_remove_recursive(component->debugfs_root);
  137. component->debugfs_root = NULL;
  138. }
  139. static int dai_list_show(struct seq_file *m, void *v)
  140. {
  141. struct snd_soc_component *component;
  142. struct snd_soc_dai *dai;
  143. mutex_lock(&client_mutex);
  144. for_each_component(component)
  145. for_each_component_dais(component, dai)
  146. seq_printf(m, "%s\n", dai->name);
  147. mutex_unlock(&client_mutex);
  148. return 0;
  149. }
  150. DEFINE_SHOW_ATTRIBUTE(dai_list);
  151. static int component_list_show(struct seq_file *m, void *v)
  152. {
  153. struct snd_soc_component *component;
  154. mutex_lock(&client_mutex);
  155. for_each_component(component)
  156. seq_printf(m, "%s\n", component->name);
  157. mutex_unlock(&client_mutex);
  158. return 0;
  159. }
  160. DEFINE_SHOW_ATTRIBUTE(component_list);
  161. static void soc_init_card_debugfs(struct snd_soc_card *card)
  162. {
  163. card->debugfs_card_root = debugfs_create_dir(card->name,
  164. snd_soc_debugfs_root);
  165. debugfs_create_u32("dapm_pop_time", 0644, card->debugfs_card_root,
  166. &card->pop_time);
  167. snd_soc_dapm_debugfs_init(&card->dapm, card->debugfs_card_root);
  168. }
  169. static void soc_cleanup_card_debugfs(struct snd_soc_card *card)
  170. {
  171. debugfs_remove_recursive(card->debugfs_card_root);
  172. card->debugfs_card_root = NULL;
  173. }
  174. static void snd_soc_debugfs_init(void)
  175. {
  176. snd_soc_debugfs_root = debugfs_create_dir("asoc", NULL);
  177. debugfs_create_file("dais", 0444, snd_soc_debugfs_root, NULL,
  178. &dai_list_fops);
  179. debugfs_create_file("components", 0444, snd_soc_debugfs_root, NULL,
  180. &component_list_fops);
  181. }
  182. static void snd_soc_debugfs_exit(void)
  183. {
  184. debugfs_remove_recursive(snd_soc_debugfs_root);
  185. }
  186. #else
  187. static inline void soc_init_component_debugfs(struct snd_soc_component *component) { }
  188. static inline void soc_cleanup_component_debugfs(struct snd_soc_component *component) { }
  189. static inline void soc_init_card_debugfs(struct snd_soc_card *card) { }
  190. static inline void soc_cleanup_card_debugfs(struct snd_soc_card *card) { }
  191. static inline void snd_soc_debugfs_init(void) { }
  192. static inline void snd_soc_debugfs_exit(void) { }
  193. #endif
  194. static int snd_soc_is_match_dai_args(const struct of_phandle_args *args1,
  195. const struct of_phandle_args *args2)
  196. {
  197. if (!args1 || !args2)
  198. return 0;
  199. if (args1->np != args2->np)
  200. return 0;
  201. for (int i = 0; i < args1->args_count; i++)
  202. if (args1->args[i] != args2->args[i])
  203. return 0;
  204. return 1;
  205. }
  206. static inline int snd_soc_dlc_component_is_empty(struct snd_soc_dai_link_component *dlc)
  207. {
  208. return !(dlc->dai_args || dlc->name || dlc->of_node);
  209. }
  210. static inline int snd_soc_dlc_component_is_invalid(struct snd_soc_dai_link_component *dlc)
  211. {
  212. return (dlc->name && dlc->of_node);
  213. }
  214. static inline int snd_soc_dlc_dai_is_empty(struct snd_soc_dai_link_component *dlc)
  215. {
  216. return !(dlc->dai_args || dlc->dai_name);
  217. }
  218. static int snd_soc_is_matching_dai(const struct snd_soc_dai_link_component *dlc,
  219. struct snd_soc_dai *dai)
  220. {
  221. if (!dlc)
  222. return 0;
  223. if (dlc->dai_args)
  224. return snd_soc_is_match_dai_args(dai->driver->dai_args, dlc->dai_args);
  225. if (!dlc->dai_name)
  226. return 1;
  227. /* see snd_soc_dai_name_get() */
  228. if (dai->driver->name &&
  229. strcmp(dlc->dai_name, dai->driver->name) == 0)
  230. return 1;
  231. if (strcmp(dlc->dai_name, dai->name) == 0)
  232. return 1;
  233. if (dai->component->name &&
  234. strcmp(dlc->dai_name, dai->component->name) == 0)
  235. return 1;
  236. return 0;
  237. }
  238. const char *snd_soc_dai_name_get(const struct snd_soc_dai *dai)
  239. {
  240. /* see snd_soc_is_matching_dai() */
  241. if (dai->driver->name)
  242. return dai->driver->name;
  243. if (dai->name)
  244. return dai->name;
  245. if (dai->component->name)
  246. return dai->component->name;
  247. return NULL;
  248. }
  249. EXPORT_SYMBOL_GPL(snd_soc_dai_name_get);
  250. static int snd_soc_rtd_add_component(struct snd_soc_pcm_runtime *rtd,
  251. struct snd_soc_component *component)
  252. {
  253. struct snd_soc_component *comp;
  254. int i;
  255. for_each_rtd_components(rtd, i, comp) {
  256. /* already connected */
  257. if (comp == component)
  258. return 0;
  259. }
  260. /* see for_each_rtd_components */
  261. rtd->num_components++; // increment flex array count at first
  262. rtd->components[rtd->num_components - 1] = component;
  263. return 0;
  264. }
  265. struct snd_soc_component *snd_soc_rtdcom_lookup(struct snd_soc_pcm_runtime *rtd,
  266. const char *driver_name)
  267. {
  268. struct snd_soc_component *component;
  269. int i;
  270. if (!driver_name)
  271. return NULL;
  272. /*
  273. * NOTE
  274. *
  275. * snd_soc_rtdcom_lookup() will find component from rtd by using
  276. * specified driver name.
  277. * But, if many components which have same driver name are connected
  278. * to 1 rtd, this function will return 1st found component.
  279. */
  280. for_each_rtd_components(rtd, i, component) {
  281. const char *component_name = component->driver->name;
  282. if (!component_name)
  283. continue;
  284. if ((component_name == driver_name) ||
  285. strcmp(component_name, driver_name) == 0)
  286. return component;
  287. }
  288. return NULL;
  289. }
  290. EXPORT_SYMBOL_GPL(snd_soc_rtdcom_lookup);
  291. struct snd_soc_component
  292. *snd_soc_lookup_component_nolocked(struct device *dev, const char *driver_name)
  293. {
  294. struct snd_soc_component *component;
  295. struct snd_soc_component *found_component;
  296. found_component = NULL;
  297. for_each_component(component) {
  298. if ((dev == component->dev) &&
  299. (!driver_name ||
  300. (driver_name == component->driver->name) ||
  301. (strcmp(component->driver->name, driver_name) == 0))) {
  302. found_component = component;
  303. break;
  304. }
  305. }
  306. return found_component;
  307. }
  308. EXPORT_SYMBOL_GPL(snd_soc_lookup_component_nolocked);
  309. struct snd_soc_component *snd_soc_lookup_component(struct device *dev,
  310. const char *driver_name)
  311. {
  312. struct snd_soc_component *component;
  313. mutex_lock(&client_mutex);
  314. component = snd_soc_lookup_component_nolocked(dev, driver_name);
  315. mutex_unlock(&client_mutex);
  316. return component;
  317. }
  318. EXPORT_SYMBOL_GPL(snd_soc_lookup_component);
  319. struct snd_soc_pcm_runtime
  320. *snd_soc_get_pcm_runtime(struct snd_soc_card *card,
  321. struct snd_soc_dai_link *dai_link)
  322. {
  323. struct snd_soc_pcm_runtime *rtd;
  324. for_each_card_rtds(card, rtd) {
  325. if (rtd->dai_link == dai_link)
  326. return rtd;
  327. }
  328. dev_dbg(card->dev, "ASoC: failed to find rtd %s\n", dai_link->name);
  329. return NULL;
  330. }
  331. EXPORT_SYMBOL_GPL(snd_soc_get_pcm_runtime);
  332. /*
  333. * Power down the audio subsystem pmdown_time msecs after close is called.
  334. * This is to ensure there are no pops or clicks in between any music tracks
  335. * due to DAPM power cycling.
  336. */
  337. void snd_soc_close_delayed_work(struct snd_soc_pcm_runtime *rtd)
  338. {
  339. struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0);
  340. int playback = SNDRV_PCM_STREAM_PLAYBACK;
  341. snd_soc_dpcm_mutex_lock(rtd);
  342. dev_dbg(rtd->dev,
  343. "ASoC: pop wq checking: %s status: %s waiting: %s\n",
  344. codec_dai->driver->playback.stream_name,
  345. snd_soc_dai_stream_active(codec_dai, playback) ?
  346. "active" : "inactive",
  347. rtd->pop_wait ? "yes" : "no");
  348. /* are we waiting on this codec DAI stream */
  349. if (rtd->pop_wait == 1) {
  350. rtd->pop_wait = 0;
  351. snd_soc_dapm_stream_event(rtd, playback,
  352. SND_SOC_DAPM_STREAM_STOP);
  353. }
  354. snd_soc_dpcm_mutex_unlock(rtd);
  355. }
  356. EXPORT_SYMBOL_GPL(snd_soc_close_delayed_work);
  357. static void soc_release_rtd_dev(struct device *dev)
  358. {
  359. /* "dev" means "rtd->dev" */
  360. kfree(dev);
  361. }
  362. static void soc_free_pcm_runtime(struct snd_soc_pcm_runtime *rtd)
  363. {
  364. if (!rtd)
  365. return;
  366. list_del(&rtd->list);
  367. if (delayed_work_pending(&rtd->delayed_work))
  368. flush_delayed_work(&rtd->delayed_work);
  369. snd_soc_pcm_component_free(rtd);
  370. /*
  371. * we don't need to call kfree() for rtd->dev
  372. * see
  373. * soc_release_rtd_dev()
  374. *
  375. * We don't need rtd->dev NULL check, because
  376. * it is alloced *before* rtd.
  377. * see
  378. * soc_new_pcm_runtime()
  379. *
  380. * We don't need to mind freeing for rtd,
  381. * because it was created from dev (= rtd->dev)
  382. * see
  383. * soc_new_pcm_runtime()
  384. *
  385. * rtd = devm_kzalloc(dev, ...);
  386. * rtd->dev = dev
  387. */
  388. device_unregister(rtd->dev);
  389. }
  390. static void close_delayed_work(struct work_struct *work) {
  391. struct snd_soc_pcm_runtime *rtd =
  392. container_of(work, struct snd_soc_pcm_runtime,
  393. delayed_work.work);
  394. if (rtd->close_delayed_work_func)
  395. rtd->close_delayed_work_func(rtd);
  396. }
  397. static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
  398. struct snd_soc_card *card, struct snd_soc_dai_link *dai_link)
  399. {
  400. struct snd_soc_pcm_runtime *rtd;
  401. struct device *dev;
  402. int ret;
  403. int stream;
  404. /*
  405. * for rtd->dev
  406. */
  407. dev = kzalloc(sizeof(struct device), GFP_KERNEL);
  408. if (!dev)
  409. return NULL;
  410. dev->parent = card->dev;
  411. dev->release = soc_release_rtd_dev;
  412. dev_set_name(dev, "%s", dai_link->name);
  413. ret = device_register(dev);
  414. if (ret < 0) {
  415. put_device(dev); /* soc_release_rtd_dev */
  416. return NULL;
  417. }
  418. /*
  419. * for rtd
  420. */
  421. rtd = devm_kzalloc(dev,
  422. struct_size(rtd, components,
  423. dai_link->num_cpus +
  424. dai_link->num_codecs +
  425. dai_link->num_platforms),
  426. GFP_KERNEL);
  427. if (!rtd) {
  428. device_unregister(dev);
  429. return NULL;
  430. }
  431. rtd->dev = dev;
  432. INIT_LIST_HEAD(&rtd->list);
  433. for_each_pcm_streams(stream) {
  434. INIT_LIST_HEAD(&rtd->dpcm[stream].be_clients);
  435. INIT_LIST_HEAD(&rtd->dpcm[stream].fe_clients);
  436. }
  437. dev_set_drvdata(dev, rtd);
  438. INIT_DELAYED_WORK(&rtd->delayed_work, close_delayed_work);
  439. /*
  440. * for rtd->dais
  441. */
  442. rtd->dais = devm_kcalloc(dev, dai_link->num_cpus + dai_link->num_codecs,
  443. sizeof(struct snd_soc_dai *),
  444. GFP_KERNEL);
  445. if (!rtd->dais)
  446. goto free_rtd;
  447. /*
  448. * dais = [][][][][][][][][][][][][][][][][][]
  449. * ^cpu_dais ^codec_dais
  450. * |--- num_cpus ---|--- num_codecs --|
  451. * see
  452. * snd_soc_rtd_to_cpu()
  453. * snd_soc_rtd_to_codec()
  454. */
  455. rtd->card = card;
  456. rtd->dai_link = dai_link;
  457. rtd->num = card->num_rtd++;
  458. rtd->pmdown_time = pmdown_time; /* default power off timeout */
  459. /* see for_each_card_rtds */
  460. list_add_tail(&rtd->list, &card->rtd_list);
  461. ret = device_add_groups(dev, soc_dev_attr_groups);
  462. if (ret < 0)
  463. goto free_rtd;
  464. return rtd;
  465. free_rtd:
  466. soc_free_pcm_runtime(rtd);
  467. return NULL;
  468. }
  469. static void snd_soc_fill_dummy_dai(struct snd_soc_card *card)
  470. {
  471. struct snd_soc_dai_link *dai_link;
  472. int i;
  473. /*
  474. * COMP_DUMMY() creates size 0 array on dai_link.
  475. * Fill it as dummy DAI in case of CPU/Codec here.
  476. * Do nothing for Platform.
  477. */
  478. for_each_card_prelinks(card, i, dai_link) {
  479. if (dai_link->num_cpus == 0 && dai_link->cpus) {
  480. dai_link->num_cpus = 1;
  481. dai_link->cpus = &snd_soc_dummy_dlc;
  482. }
  483. if (dai_link->num_codecs == 0 && dai_link->codecs) {
  484. dai_link->num_codecs = 1;
  485. dai_link->codecs = &snd_soc_dummy_dlc;
  486. }
  487. }
  488. }
  489. static void snd_soc_flush_all_delayed_work(struct snd_soc_card *card)
  490. {
  491. struct snd_soc_pcm_runtime *rtd;
  492. for_each_card_rtds(card, rtd)
  493. flush_delayed_work(&rtd->delayed_work);
  494. }
  495. #ifdef CONFIG_PM_SLEEP
  496. static void soc_playback_digital_mute(struct snd_soc_card *card, int mute)
  497. {
  498. struct snd_soc_pcm_runtime *rtd;
  499. struct snd_soc_dai *dai;
  500. int playback = SNDRV_PCM_STREAM_PLAYBACK;
  501. int i;
  502. for_each_card_rtds(card, rtd) {
  503. if (rtd->dai_link->ignore_suspend)
  504. continue;
  505. for_each_rtd_dais(rtd, i, dai) {
  506. if (snd_soc_dai_stream_active(dai, playback))
  507. snd_soc_dai_digital_mute(dai, mute, playback);
  508. }
  509. }
  510. }
  511. static void soc_dapm_suspend_resume(struct snd_soc_card *card, int event)
  512. {
  513. struct snd_soc_pcm_runtime *rtd;
  514. int stream;
  515. for_each_card_rtds(card, rtd) {
  516. if (rtd->dai_link->ignore_suspend)
  517. continue;
  518. for_each_pcm_streams(stream)
  519. snd_soc_dapm_stream_event(rtd, stream, event);
  520. }
  521. }
  522. /* powers down audio subsystem for suspend */
  523. int snd_soc_suspend(struct device *dev)
  524. {
  525. struct snd_soc_card *card = dev_get_drvdata(dev);
  526. struct snd_soc_component *component;
  527. struct snd_soc_pcm_runtime *rtd;
  528. int i;
  529. /* If the card is not initialized yet there is nothing to do */
  530. if (!snd_soc_card_is_instantiated(card))
  531. return 0;
  532. /*
  533. * Due to the resume being scheduled into a workqueue we could
  534. * suspend before that's finished - wait for it to complete.
  535. */
  536. snd_power_wait(card->snd_card);
  537. /* we're going to block userspace touching us until resume completes */
  538. snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D3hot);
  539. /* mute any active DACs */
  540. soc_playback_digital_mute(card, 1);
  541. /* suspend all pcms */
  542. for_each_card_rtds(card, rtd) {
  543. if (rtd->dai_link->ignore_suspend)
  544. continue;
  545. snd_pcm_suspend_all(rtd->pcm);
  546. }
  547. snd_soc_card_suspend_pre(card);
  548. /* close any waiting streams */
  549. snd_soc_flush_all_delayed_work(card);
  550. soc_dapm_suspend_resume(card, SND_SOC_DAPM_STREAM_SUSPEND);
  551. /* Recheck all endpoints too, their state is affected by suspend */
  552. dapm_mark_endpoints_dirty(card);
  553. snd_soc_dapm_sync(&card->dapm);
  554. /* suspend all COMPONENTs */
  555. for_each_card_rtds(card, rtd) {
  556. if (rtd->dai_link->ignore_suspend)
  557. continue;
  558. for_each_rtd_components(rtd, i, component) {
  559. struct snd_soc_dapm_context *dapm =
  560. snd_soc_component_get_dapm(component);
  561. /*
  562. * ignore if component was already suspended
  563. */
  564. if (snd_soc_component_is_suspended(component))
  565. continue;
  566. /*
  567. * If there are paths active then the COMPONENT will be
  568. * held with bias _ON and should not be suspended.
  569. */
  570. switch (snd_soc_dapm_get_bias_level(dapm)) {
  571. case SND_SOC_BIAS_STANDBY:
  572. /*
  573. * If the COMPONENT is capable of idle
  574. * bias off then being in STANDBY
  575. * means it's doing something,
  576. * otherwise fall through.
  577. */
  578. if (dapm->idle_bias_off) {
  579. dev_dbg(component->dev,
  580. "ASoC: idle_bias_off CODEC on over suspend\n");
  581. break;
  582. }
  583. fallthrough;
  584. case SND_SOC_BIAS_OFF:
  585. snd_soc_component_suspend(component);
  586. if (component->regmap)
  587. regcache_mark_dirty(component->regmap);
  588. /* deactivate pins to sleep state */
  589. pinctrl_pm_select_sleep_state(component->dev);
  590. break;
  591. default:
  592. dev_dbg(component->dev,
  593. "ASoC: COMPONENT is on over suspend\n");
  594. break;
  595. }
  596. }
  597. }
  598. snd_soc_card_suspend_post(card);
  599. return 0;
  600. }
  601. EXPORT_SYMBOL_GPL(snd_soc_suspend);
  602. /*
  603. * deferred resume work, so resume can complete before we finished
  604. * setting our codec back up, which can be very slow on I2C
  605. */
  606. static void soc_resume_deferred(struct work_struct *work)
  607. {
  608. struct snd_soc_card *card =
  609. container_of(work, struct snd_soc_card,
  610. deferred_resume_work);
  611. struct snd_soc_component *component;
  612. /*
  613. * our power state is still SNDRV_CTL_POWER_D3hot from suspend time,
  614. * so userspace apps are blocked from touching us
  615. */
  616. dev_dbg(card->dev, "ASoC: starting resume work\n");
  617. /* Bring us up into D2 so that DAPM starts enabling things */
  618. snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D2);
  619. snd_soc_card_resume_pre(card);
  620. for_each_card_components(card, component) {
  621. if (snd_soc_component_is_suspended(component))
  622. snd_soc_component_resume(component);
  623. }
  624. soc_dapm_suspend_resume(card, SND_SOC_DAPM_STREAM_RESUME);
  625. /* unmute any active DACs */
  626. soc_playback_digital_mute(card, 0);
  627. snd_soc_card_resume_post(card);
  628. dev_dbg(card->dev, "ASoC: resume work completed\n");
  629. /* Recheck all endpoints too, their state is affected by suspend */
  630. dapm_mark_endpoints_dirty(card);
  631. snd_soc_dapm_sync(&card->dapm);
  632. /* userspace can access us now we are back as we were before */
  633. snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D0);
  634. }
  635. /* powers up audio subsystem after a suspend */
  636. int snd_soc_resume(struct device *dev)
  637. {
  638. struct snd_soc_card *card = dev_get_drvdata(dev);
  639. struct snd_soc_component *component;
  640. /* If the card is not initialized yet there is nothing to do */
  641. if (!snd_soc_card_is_instantiated(card))
  642. return 0;
  643. /* activate pins from sleep state */
  644. for_each_card_components(card, component)
  645. if (snd_soc_component_active(component))
  646. pinctrl_pm_select_default_state(component->dev);
  647. dev_dbg(dev, "ASoC: Scheduling resume work\n");
  648. if (!schedule_work(&card->deferred_resume_work))
  649. dev_err(dev, "ASoC: resume work item may be lost\n");
  650. return 0;
  651. }
  652. EXPORT_SYMBOL_GPL(snd_soc_resume);
  653. static void soc_resume_init(struct snd_soc_card *card)
  654. {
  655. /* deferred resume work */
  656. INIT_WORK(&card->deferred_resume_work, soc_resume_deferred);
  657. }
  658. #else
  659. #define snd_soc_suspend NULL
  660. #define snd_soc_resume NULL
  661. static inline void soc_resume_init(struct snd_soc_card *card) { }
  662. #endif
  663. static struct device_node
  664. *soc_component_to_node(struct snd_soc_component *component)
  665. {
  666. struct device_node *of_node;
  667. of_node = component->dev->of_node;
  668. if (!of_node && component->dev->parent)
  669. of_node = component->dev->parent->of_node;
  670. return of_node;
  671. }
  672. struct of_phandle_args *snd_soc_copy_dai_args(struct device *dev,
  673. const struct of_phandle_args *args)
  674. {
  675. struct of_phandle_args *ret = devm_kzalloc(dev, sizeof(*ret), GFP_KERNEL);
  676. if (!ret)
  677. return NULL;
  678. *ret = *args;
  679. return ret;
  680. }
  681. EXPORT_SYMBOL_GPL(snd_soc_copy_dai_args);
  682. static int snd_soc_is_matching_component(
  683. const struct snd_soc_dai_link_component *dlc,
  684. struct snd_soc_component *component)
  685. {
  686. struct device_node *component_of_node;
  687. if (!dlc)
  688. return 0;
  689. if (dlc->dai_args) {
  690. struct snd_soc_dai *dai;
  691. for_each_component_dais(component, dai)
  692. if (snd_soc_is_matching_dai(dlc, dai))
  693. return 1;
  694. return 0;
  695. }
  696. component_of_node = soc_component_to_node(component);
  697. if (dlc->of_node && component_of_node != dlc->of_node)
  698. return 0;
  699. if (dlc->name && strcmp(component->name, dlc->name))
  700. return 0;
  701. return 1;
  702. }
  703. static struct snd_soc_component *soc_find_component(
  704. const struct snd_soc_dai_link_component *dlc)
  705. {
  706. struct snd_soc_component *component;
  707. lockdep_assert_held(&client_mutex);
  708. /*
  709. * NOTE
  710. *
  711. * It returns *1st* found component, but some driver
  712. * has few components by same of_node/name
  713. * ex)
  714. * CPU component and generic DMAEngine component
  715. */
  716. for_each_component(component)
  717. if (snd_soc_is_matching_component(dlc, component))
  718. return component;
  719. return NULL;
  720. }
  721. /**
  722. * snd_soc_find_dai - Find a registered DAI
  723. *
  724. * @dlc: name of the DAI or the DAI driver and optional component info to match
  725. *
  726. * This function will search all registered components and their DAIs to
  727. * find the DAI of the same name. The component's of_node and name
  728. * should also match if being specified.
  729. *
  730. * Return: pointer of DAI, or NULL if not found.
  731. */
  732. struct snd_soc_dai *snd_soc_find_dai(
  733. const struct snd_soc_dai_link_component *dlc)
  734. {
  735. struct snd_soc_component *component;
  736. struct snd_soc_dai *dai;
  737. lockdep_assert_held(&client_mutex);
  738. /* Find CPU DAI from registered DAIs */
  739. for_each_component(component)
  740. if (snd_soc_is_matching_component(dlc, component))
  741. for_each_component_dais(component, dai)
  742. if (snd_soc_is_matching_dai(dlc, dai))
  743. return dai;
  744. return NULL;
  745. }
  746. EXPORT_SYMBOL_GPL(snd_soc_find_dai);
  747. struct snd_soc_dai *snd_soc_find_dai_with_mutex(
  748. const struct snd_soc_dai_link_component *dlc)
  749. {
  750. struct snd_soc_dai *dai;
  751. mutex_lock(&client_mutex);
  752. dai = snd_soc_find_dai(dlc);
  753. mutex_unlock(&client_mutex);
  754. return dai;
  755. }
  756. EXPORT_SYMBOL_GPL(snd_soc_find_dai_with_mutex);
  757. static int soc_dai_link_sanity_check(struct snd_soc_card *card,
  758. struct snd_soc_dai_link *link)
  759. {
  760. int i;
  761. struct snd_soc_dai_link_component *dlc;
  762. /* Codec check */
  763. for_each_link_codecs(link, i, dlc) {
  764. /*
  765. * Codec must be specified by 1 of name or OF node,
  766. * not both or neither.
  767. */
  768. if (snd_soc_dlc_component_is_invalid(dlc))
  769. goto component_invalid;
  770. if (snd_soc_dlc_component_is_empty(dlc))
  771. goto component_empty;
  772. /* Codec DAI name must be specified */
  773. if (snd_soc_dlc_dai_is_empty(dlc))
  774. goto dai_empty;
  775. /*
  776. * Defer card registration if codec component is not added to
  777. * component list.
  778. */
  779. if (!soc_find_component(dlc))
  780. goto component_not_found;
  781. }
  782. /* Platform check */
  783. for_each_link_platforms(link, i, dlc) {
  784. /*
  785. * Platform may be specified by either name or OF node, but it
  786. * can be left unspecified, then no components will be inserted
  787. * in the rtdcom list
  788. */
  789. if (snd_soc_dlc_component_is_invalid(dlc))
  790. goto component_invalid;
  791. if (snd_soc_dlc_component_is_empty(dlc))
  792. goto component_empty;
  793. /*
  794. * Defer card registration if platform component is not added to
  795. * component list.
  796. */
  797. if (!soc_find_component(dlc))
  798. goto component_not_found;
  799. }
  800. /* CPU check */
  801. for_each_link_cpus(link, i, dlc) {
  802. /*
  803. * CPU device may be specified by either name or OF node, but
  804. * can be left unspecified, and will be matched based on DAI
  805. * name alone..
  806. */
  807. if (snd_soc_dlc_component_is_invalid(dlc))
  808. goto component_invalid;
  809. if (snd_soc_dlc_component_is_empty(dlc)) {
  810. /*
  811. * At least one of CPU DAI name or CPU device name/node must be specified
  812. */
  813. if (snd_soc_dlc_dai_is_empty(dlc))
  814. goto component_dai_empty;
  815. } else {
  816. /*
  817. * Defer card registration if Component is not added
  818. */
  819. if (!soc_find_component(dlc))
  820. goto component_not_found;
  821. }
  822. }
  823. return 0;
  824. component_invalid:
  825. dev_err(card->dev, "ASoC: Both Component name/of_node are set for %s\n", link->name);
  826. return -EINVAL;
  827. component_empty:
  828. dev_err(card->dev, "ASoC: Neither Component name/of_node are set for %s\n", link->name);
  829. return -EINVAL;
  830. component_not_found:
  831. dev_dbg(card->dev, "ASoC: Component %s not found for link %s\n", dlc->name, link->name);
  832. return -EPROBE_DEFER;
  833. dai_empty:
  834. dev_err(card->dev, "ASoC: DAI name is not set for %s\n", link->name);
  835. return -EINVAL;
  836. component_dai_empty:
  837. dev_err(card->dev, "ASoC: Neither DAI/Component name/of_node are set for %s\n", link->name);
  838. return -EINVAL;
  839. }
  840. #define MAX_DEFAULT_CH_MAP_SIZE 8
  841. static struct snd_soc_dai_link_ch_map default_ch_map_sync[MAX_DEFAULT_CH_MAP_SIZE] = {
  842. { .cpu = 0, .codec = 0 },
  843. { .cpu = 1, .codec = 1 },
  844. { .cpu = 2, .codec = 2 },
  845. { .cpu = 3, .codec = 3 },
  846. { .cpu = 4, .codec = 4 },
  847. { .cpu = 5, .codec = 5 },
  848. { .cpu = 6, .codec = 6 },
  849. { .cpu = 7, .codec = 7 },
  850. };
  851. static struct snd_soc_dai_link_ch_map default_ch_map_1cpu[MAX_DEFAULT_CH_MAP_SIZE] = {
  852. { .cpu = 0, .codec = 0 },
  853. { .cpu = 0, .codec = 1 },
  854. { .cpu = 0, .codec = 2 },
  855. { .cpu = 0, .codec = 3 },
  856. { .cpu = 0, .codec = 4 },
  857. { .cpu = 0, .codec = 5 },
  858. { .cpu = 0, .codec = 6 },
  859. { .cpu = 0, .codec = 7 },
  860. };
  861. static struct snd_soc_dai_link_ch_map default_ch_map_1codec[MAX_DEFAULT_CH_MAP_SIZE] = {
  862. { .cpu = 0, .codec = 0 },
  863. { .cpu = 1, .codec = 0 },
  864. { .cpu = 2, .codec = 0 },
  865. { .cpu = 3, .codec = 0 },
  866. { .cpu = 4, .codec = 0 },
  867. { .cpu = 5, .codec = 0 },
  868. { .cpu = 6, .codec = 0 },
  869. { .cpu = 7, .codec = 0 },
  870. };
  871. static int snd_soc_compensate_channel_connection_map(struct snd_soc_card *card,
  872. struct snd_soc_dai_link *dai_link)
  873. {
  874. struct snd_soc_dai_link_ch_map *ch_maps;
  875. int i;
  876. /*
  877. * dai_link->ch_maps indicates how CPU/Codec are connected.
  878. * It will be a map seen from a larger number of DAI.
  879. * see
  880. * soc.h :: [dai_link->ch_maps Image sample]
  881. */
  882. /* it should have ch_maps if connection was N:M */
  883. if (dai_link->num_cpus > 1 && dai_link->num_codecs > 1 &&
  884. dai_link->num_cpus != dai_link->num_codecs && !dai_link->ch_maps) {
  885. dev_err(card->dev, "need to have ch_maps when N:M connection (%s)",
  886. dai_link->name);
  887. return -EINVAL;
  888. }
  889. /* do nothing if it has own maps */
  890. if (dai_link->ch_maps)
  891. goto sanity_check;
  892. /* check default map size */
  893. if (dai_link->num_cpus > MAX_DEFAULT_CH_MAP_SIZE ||
  894. dai_link->num_codecs > MAX_DEFAULT_CH_MAP_SIZE) {
  895. dev_err(card->dev, "soc-core.c needs update default_connection_maps");
  896. return -EINVAL;
  897. }
  898. /* Compensate missing map for ... */
  899. if (dai_link->num_cpus == dai_link->num_codecs)
  900. dai_link->ch_maps = default_ch_map_sync; /* for 1:1 or N:N */
  901. else if (dai_link->num_cpus < dai_link->num_codecs)
  902. dai_link->ch_maps = default_ch_map_1cpu; /* for 1:N */
  903. else
  904. dai_link->ch_maps = default_ch_map_1codec; /* for N:1 */
  905. sanity_check:
  906. dev_dbg(card->dev, "dai_link %s\n", dai_link->stream_name);
  907. for_each_link_ch_maps(dai_link, i, ch_maps) {
  908. if ((ch_maps->cpu >= dai_link->num_cpus) ||
  909. (ch_maps->codec >= dai_link->num_codecs)) {
  910. dev_err(card->dev,
  911. "unexpected dai_link->ch_maps[%d] index (cpu(%d/%d) codec(%d/%d))",
  912. i,
  913. ch_maps->cpu, dai_link->num_cpus,
  914. ch_maps->codec, dai_link->num_codecs);
  915. return -EINVAL;
  916. }
  917. dev_dbg(card->dev, " [%d] cpu%d <-> codec%d\n",
  918. i, ch_maps->cpu, ch_maps->codec);
  919. }
  920. return 0;
  921. }
  922. /**
  923. * snd_soc_remove_pcm_runtime - Remove a pcm_runtime from card
  924. * @card: The ASoC card to which the pcm_runtime has
  925. * @rtd: The pcm_runtime to remove
  926. *
  927. * This function removes a pcm_runtime from the ASoC card.
  928. */
  929. void snd_soc_remove_pcm_runtime(struct snd_soc_card *card,
  930. struct snd_soc_pcm_runtime *rtd)
  931. {
  932. if (!rtd)
  933. return;
  934. lockdep_assert_held(&client_mutex);
  935. /*
  936. * Notify the machine driver for extra destruction
  937. */
  938. snd_soc_card_remove_dai_link(card, rtd->dai_link);
  939. soc_free_pcm_runtime(rtd);
  940. }
  941. EXPORT_SYMBOL_GPL(snd_soc_remove_pcm_runtime);
  942. /**
  943. * snd_soc_add_pcm_runtime - Add a pcm_runtime dynamically via dai_link
  944. * @card: The ASoC card to which the pcm_runtime is added
  945. * @dai_link: The DAI link to find pcm_runtime
  946. *
  947. * This function adds a pcm_runtime ASoC card by using dai_link.
  948. *
  949. * Note: Topology can use this API to add pcm_runtime when probing the
  950. * topology component. And machine drivers can still define static
  951. * DAI links in dai_link array.
  952. */
  953. static int snd_soc_add_pcm_runtime(struct snd_soc_card *card,
  954. struct snd_soc_dai_link *dai_link)
  955. {
  956. struct snd_soc_pcm_runtime *rtd;
  957. struct snd_soc_dai_link_component *codec, *platform, *cpu;
  958. struct snd_soc_component *component;
  959. int i, ret;
  960. lockdep_assert_held(&client_mutex);
  961. /*
  962. * Notify the machine driver for extra initialization
  963. */
  964. ret = snd_soc_card_add_dai_link(card, dai_link);
  965. if (ret < 0)
  966. return ret;
  967. if (dai_link->ignore)
  968. return 0;
  969. dev_dbg(card->dev, "ASoC: binding %s\n", dai_link->name);
  970. ret = soc_dai_link_sanity_check(card, dai_link);
  971. if (ret < 0)
  972. return ret;
  973. rtd = soc_new_pcm_runtime(card, dai_link);
  974. if (!rtd)
  975. return -ENOMEM;
  976. for_each_link_cpus(dai_link, i, cpu) {
  977. snd_soc_rtd_to_cpu(rtd, i) = snd_soc_find_dai(cpu);
  978. if (!snd_soc_rtd_to_cpu(rtd, i)) {
  979. dev_info(card->dev, "ASoC: CPU DAI %s not registered\n",
  980. cpu->dai_name);
  981. goto _err_defer;
  982. }
  983. snd_soc_rtd_add_component(rtd, snd_soc_rtd_to_cpu(rtd, i)->component);
  984. }
  985. /* Find CODEC from registered CODECs */
  986. for_each_link_codecs(dai_link, i, codec) {
  987. snd_soc_rtd_to_codec(rtd, i) = snd_soc_find_dai(codec);
  988. if (!snd_soc_rtd_to_codec(rtd, i)) {
  989. dev_info(card->dev, "ASoC: CODEC DAI %s not registered\n",
  990. codec->dai_name);
  991. goto _err_defer;
  992. }
  993. snd_soc_rtd_add_component(rtd, snd_soc_rtd_to_codec(rtd, i)->component);
  994. }
  995. /* Find PLATFORM from registered PLATFORMs */
  996. for_each_link_platforms(dai_link, i, platform) {
  997. for_each_component(component) {
  998. if (!snd_soc_is_matching_component(platform, component))
  999. continue;
  1000. if (snd_soc_component_is_dummy(component) && component->num_dai)
  1001. continue;
  1002. snd_soc_rtd_add_component(rtd, component);
  1003. }
  1004. }
  1005. return 0;
  1006. _err_defer:
  1007. snd_soc_remove_pcm_runtime(card, rtd);
  1008. return -EPROBE_DEFER;
  1009. }
  1010. int snd_soc_add_pcm_runtimes(struct snd_soc_card *card,
  1011. struct snd_soc_dai_link *dai_link,
  1012. int num_dai_link)
  1013. {
  1014. for (int i = 0; i < num_dai_link; i++) {
  1015. int ret;
  1016. ret = snd_soc_compensate_channel_connection_map(card, dai_link + i);
  1017. if (ret < 0)
  1018. return ret;
  1019. ret = snd_soc_add_pcm_runtime(card, dai_link + i);
  1020. if (ret < 0)
  1021. return ret;
  1022. }
  1023. return 0;
  1024. }
  1025. EXPORT_SYMBOL_GPL(snd_soc_add_pcm_runtimes);
  1026. static void snd_soc_runtime_get_dai_fmt(struct snd_soc_pcm_runtime *rtd)
  1027. {
  1028. struct snd_soc_dai_link *dai_link = rtd->dai_link;
  1029. struct snd_soc_dai *dai, *not_used;
  1030. u64 pos, possible_fmt;
  1031. unsigned int mask = 0, dai_fmt = 0;
  1032. int i, j, priority, pri, until;
  1033. /*
  1034. * Get selectable format from each DAIs.
  1035. *
  1036. ****************************
  1037. * NOTE
  1038. * Using .auto_selectable_formats is not mandatory,
  1039. * we can select format manually from Sound Card.
  1040. * When use it, driver should list well tested format only.
  1041. ****************************
  1042. *
  1043. * ex)
  1044. * auto_selectable_formats (= SND_SOC_POSSIBLE_xxx)
  1045. * (A) (B) (C)
  1046. * DAI0_: { 0x000F, 0x00F0, 0x0F00 };
  1047. * DAI1 : { 0xF000, 0x0F00 };
  1048. * (X) (Y)
  1049. *
  1050. * "until" will be 3 in this case (MAX array size from DAI0 and DAI1)
  1051. * Here is dev_dbg() message and comments
  1052. *
  1053. * priority = 1
  1054. * DAI0: (pri, fmt) = (1, 000000000000000F) // 1st check (A) DAI1 is not selected
  1055. * DAI1: (pri, fmt) = (0, 0000000000000000) // Necessary Waste
  1056. * DAI0: (pri, fmt) = (1, 000000000000000F) // 2nd check (A)
  1057. * DAI1: (pri, fmt) = (1, 000000000000F000) // (X)
  1058. * priority = 2
  1059. * DAI0: (pri, fmt) = (2, 00000000000000FF) // 3rd check (A) + (B)
  1060. * DAI1: (pri, fmt) = (1, 000000000000F000) // (X)
  1061. * DAI0: (pri, fmt) = (2, 00000000000000FF) // 4th check (A) + (B)
  1062. * DAI1: (pri, fmt) = (2, 000000000000FF00) // (X) + (Y)
  1063. * priority = 3
  1064. * DAI0: (pri, fmt) = (3, 0000000000000FFF) // 5th check (A) + (B) + (C)
  1065. * DAI1: (pri, fmt) = (2, 000000000000FF00) // (X) + (Y)
  1066. * found auto selected format: 0000000000000F00
  1067. */
  1068. until = snd_soc_dai_get_fmt_max_priority(rtd);
  1069. for (priority = 1; priority <= until; priority++) {
  1070. for_each_rtd_dais(rtd, j, not_used) {
  1071. possible_fmt = ULLONG_MAX;
  1072. for_each_rtd_dais(rtd, i, dai) {
  1073. u64 fmt = 0;
  1074. pri = (j >= i) ? priority : priority - 1;
  1075. fmt = snd_soc_dai_get_fmt(dai, pri);
  1076. possible_fmt &= fmt;
  1077. }
  1078. if (possible_fmt)
  1079. goto found;
  1080. }
  1081. }
  1082. /* Not Found */
  1083. return;
  1084. found:
  1085. /*
  1086. * convert POSSIBLE_DAIFMT to DAIFMT
  1087. *
  1088. * Some basic/default settings on each is defined as 0.
  1089. * see
  1090. * SND_SOC_DAIFMT_NB_NF
  1091. * SND_SOC_DAIFMT_GATED
  1092. *
  1093. * SND_SOC_DAIFMT_xxx_MASK can't notice it if Sound Card specify
  1094. * these value, and will be overwrite to auto selected value.
  1095. *
  1096. * To avoid such issue, loop from 63 to 0 here.
  1097. * Small number of SND_SOC_POSSIBLE_xxx will be Hi priority.
  1098. * Basic/Default settings of each part and above are defined
  1099. * as Hi priority (= small number) of SND_SOC_POSSIBLE_xxx.
  1100. */
  1101. for (i = 63; i >= 0; i--) {
  1102. pos = 1ULL << i;
  1103. switch (possible_fmt & pos) {
  1104. /*
  1105. * for format
  1106. */
  1107. case SND_SOC_POSSIBLE_DAIFMT_I2S:
  1108. case SND_SOC_POSSIBLE_DAIFMT_RIGHT_J:
  1109. case SND_SOC_POSSIBLE_DAIFMT_LEFT_J:
  1110. case SND_SOC_POSSIBLE_DAIFMT_DSP_A:
  1111. case SND_SOC_POSSIBLE_DAIFMT_DSP_B:
  1112. case SND_SOC_POSSIBLE_DAIFMT_AC97:
  1113. case SND_SOC_POSSIBLE_DAIFMT_PDM:
  1114. dai_fmt = (dai_fmt & ~SND_SOC_DAIFMT_FORMAT_MASK) | i;
  1115. break;
  1116. /*
  1117. * for clock
  1118. */
  1119. case SND_SOC_POSSIBLE_DAIFMT_CONT:
  1120. dai_fmt = (dai_fmt & ~SND_SOC_DAIFMT_CLOCK_MASK) | SND_SOC_DAIFMT_CONT;
  1121. break;
  1122. case SND_SOC_POSSIBLE_DAIFMT_GATED:
  1123. dai_fmt = (dai_fmt & ~SND_SOC_DAIFMT_CLOCK_MASK) | SND_SOC_DAIFMT_GATED;
  1124. break;
  1125. /*
  1126. * for clock invert
  1127. */
  1128. case SND_SOC_POSSIBLE_DAIFMT_NB_NF:
  1129. dai_fmt = (dai_fmt & ~SND_SOC_DAIFMT_INV_MASK) | SND_SOC_DAIFMT_NB_NF;
  1130. break;
  1131. case SND_SOC_POSSIBLE_DAIFMT_NB_IF:
  1132. dai_fmt = (dai_fmt & ~SND_SOC_DAIFMT_INV_MASK) | SND_SOC_DAIFMT_NB_IF;
  1133. break;
  1134. case SND_SOC_POSSIBLE_DAIFMT_IB_NF:
  1135. dai_fmt = (dai_fmt & ~SND_SOC_DAIFMT_INV_MASK) | SND_SOC_DAIFMT_IB_NF;
  1136. break;
  1137. case SND_SOC_POSSIBLE_DAIFMT_IB_IF:
  1138. dai_fmt = (dai_fmt & ~SND_SOC_DAIFMT_INV_MASK) | SND_SOC_DAIFMT_IB_IF;
  1139. break;
  1140. /*
  1141. * for clock provider / consumer
  1142. */
  1143. case SND_SOC_POSSIBLE_DAIFMT_CBP_CFP:
  1144. dai_fmt = (dai_fmt & ~SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK) | SND_SOC_DAIFMT_CBP_CFP;
  1145. break;
  1146. case SND_SOC_POSSIBLE_DAIFMT_CBC_CFP:
  1147. dai_fmt = (dai_fmt & ~SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK) | SND_SOC_DAIFMT_CBC_CFP;
  1148. break;
  1149. case SND_SOC_POSSIBLE_DAIFMT_CBP_CFC:
  1150. dai_fmt = (dai_fmt & ~SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK) | SND_SOC_DAIFMT_CBP_CFC;
  1151. break;
  1152. case SND_SOC_POSSIBLE_DAIFMT_CBC_CFC:
  1153. dai_fmt = (dai_fmt & ~SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK) | SND_SOC_DAIFMT_CBC_CFC;
  1154. break;
  1155. }
  1156. }
  1157. /*
  1158. * Some driver might have very complex limitation.
  1159. * In such case, user want to auto-select non-limitation part,
  1160. * and want to manually specify complex part.
  1161. *
  1162. * Or for example, if both CPU and Codec can be clock provider,
  1163. * but because of its quality, user want to specify it manually.
  1164. *
  1165. * Use manually specified settings if sound card did.
  1166. */
  1167. if (!(dai_link->dai_fmt & SND_SOC_DAIFMT_FORMAT_MASK))
  1168. mask |= SND_SOC_DAIFMT_FORMAT_MASK;
  1169. if (!(dai_link->dai_fmt & SND_SOC_DAIFMT_CLOCK_MASK))
  1170. mask |= SND_SOC_DAIFMT_CLOCK_MASK;
  1171. if (!(dai_link->dai_fmt & SND_SOC_DAIFMT_INV_MASK))
  1172. mask |= SND_SOC_DAIFMT_INV_MASK;
  1173. if (!(dai_link->dai_fmt & SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK))
  1174. mask |= SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK;
  1175. dai_link->dai_fmt |= (dai_fmt & mask);
  1176. }
  1177. /**
  1178. * snd_soc_runtime_set_dai_fmt() - Change DAI link format for a ASoC runtime
  1179. * @rtd: The runtime for which the DAI link format should be changed
  1180. * @dai_fmt: The new DAI link format
  1181. *
  1182. * This function updates the DAI link format for all DAIs connected to the DAI
  1183. * link for the specified runtime.
  1184. *
  1185. * Note: For setups with a static format set the dai_fmt field in the
  1186. * corresponding snd_dai_link struct instead of using this function.
  1187. *
  1188. * Returns 0 on success, otherwise a negative error code.
  1189. */
  1190. int snd_soc_runtime_set_dai_fmt(struct snd_soc_pcm_runtime *rtd,
  1191. unsigned int dai_fmt)
  1192. {
  1193. struct snd_soc_dai *cpu_dai;
  1194. struct snd_soc_dai *codec_dai;
  1195. unsigned int i;
  1196. int ret;
  1197. if (!dai_fmt)
  1198. return 0;
  1199. for_each_rtd_codec_dais(rtd, i, codec_dai) {
  1200. ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt);
  1201. if (ret != 0 && ret != -ENOTSUPP)
  1202. return ret;
  1203. }
  1204. /* Flip the polarity for the "CPU" end of link */
  1205. dai_fmt = snd_soc_daifmt_clock_provider_flipped(dai_fmt);
  1206. for_each_rtd_cpu_dais(rtd, i, cpu_dai) {
  1207. ret = snd_soc_dai_set_fmt(cpu_dai, dai_fmt);
  1208. if (ret != 0 && ret != -ENOTSUPP)
  1209. return ret;
  1210. }
  1211. return 0;
  1212. }
  1213. EXPORT_SYMBOL_GPL(snd_soc_runtime_set_dai_fmt);
  1214. static int soc_init_pcm_runtime(struct snd_soc_card *card,
  1215. struct snd_soc_pcm_runtime *rtd)
  1216. {
  1217. struct snd_soc_dai_link *dai_link = rtd->dai_link;
  1218. struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
  1219. struct snd_soc_component *component;
  1220. int ret, num, i;
  1221. /* do machine specific initialization */
  1222. ret = snd_soc_link_init(rtd);
  1223. if (ret < 0)
  1224. return ret;
  1225. snd_soc_runtime_get_dai_fmt(rtd);
  1226. ret = snd_soc_runtime_set_dai_fmt(rtd, dai_link->dai_fmt);
  1227. if (ret)
  1228. goto err;
  1229. /* add DPCM sysfs entries */
  1230. soc_dpcm_debugfs_add(rtd);
  1231. num = rtd->num;
  1232. /*
  1233. * most drivers will register their PCMs using DAI link ordering but
  1234. * topology based drivers can use the DAI link id field to set PCM
  1235. * device number and then use rtd + a base offset of the BEs.
  1236. */
  1237. for_each_rtd_components(rtd, i, component) {
  1238. if (!component->driver->use_dai_pcm_id)
  1239. continue;
  1240. if (rtd->dai_link->no_pcm)
  1241. num += component->driver->be_pcm_base;
  1242. else
  1243. num = rtd->dai_link->id;
  1244. }
  1245. /* create compress_device if possible */
  1246. ret = snd_soc_dai_compress_new(cpu_dai, rtd, num);
  1247. if (ret != -ENOTSUPP)
  1248. goto err;
  1249. /* create the pcm */
  1250. ret = soc_new_pcm(rtd, num);
  1251. if (ret < 0) {
  1252. dev_err(card->dev, "ASoC: can't create pcm %s :%d\n",
  1253. dai_link->stream_name, ret);
  1254. goto err;
  1255. }
  1256. ret = snd_soc_pcm_dai_new(rtd);
  1257. if (ret < 0)
  1258. goto err;
  1259. rtd->initialized = true;
  1260. return 0;
  1261. err:
  1262. snd_soc_link_exit(rtd);
  1263. return ret;
  1264. }
  1265. static void soc_set_name_prefix(struct snd_soc_card *card,
  1266. struct snd_soc_component *component)
  1267. {
  1268. struct device_node *of_node = soc_component_to_node(component);
  1269. const char *str;
  1270. int ret, i;
  1271. for (i = 0; i < card->num_configs; i++) {
  1272. struct snd_soc_codec_conf *map = &card->codec_conf[i];
  1273. if (snd_soc_is_matching_component(&map->dlc, component) &&
  1274. map->name_prefix) {
  1275. component->name_prefix = map->name_prefix;
  1276. return;
  1277. }
  1278. }
  1279. /*
  1280. * If there is no configuration table or no match in the table,
  1281. * check if a prefix is provided in the node
  1282. */
  1283. ret = of_property_read_string(of_node, "sound-name-prefix", &str);
  1284. if (ret < 0)
  1285. return;
  1286. component->name_prefix = str;
  1287. }
  1288. static void soc_remove_component(struct snd_soc_component *component,
  1289. int probed)
  1290. {
  1291. if (!component->card)
  1292. return;
  1293. if (probed)
  1294. snd_soc_component_remove(component);
  1295. list_del_init(&component->card_list);
  1296. snd_soc_dapm_free(snd_soc_component_get_dapm(component));
  1297. soc_cleanup_component_debugfs(component);
  1298. component->card = NULL;
  1299. snd_soc_component_module_put_when_remove(component);
  1300. }
  1301. static int soc_probe_component(struct snd_soc_card *card,
  1302. struct snd_soc_component *component)
  1303. {
  1304. struct snd_soc_dapm_context *dapm =
  1305. snd_soc_component_get_dapm(component);
  1306. struct snd_soc_dai *dai;
  1307. int probed = 0;
  1308. int ret;
  1309. if (snd_soc_component_is_dummy(component))
  1310. return 0;
  1311. if (component->card) {
  1312. if (component->card != card) {
  1313. dev_err(component->dev,
  1314. "Trying to bind component \"%s\" to card \"%s\" but is already bound to card \"%s\"\n",
  1315. component->name, card->name, component->card->name);
  1316. return -ENODEV;
  1317. }
  1318. return 0;
  1319. }
  1320. ret = snd_soc_component_module_get_when_probe(component);
  1321. if (ret < 0)
  1322. return ret;
  1323. component->card = card;
  1324. soc_set_name_prefix(card, component);
  1325. soc_init_component_debugfs(component);
  1326. snd_soc_dapm_init(dapm, card, component);
  1327. ret = snd_soc_dapm_new_controls(dapm,
  1328. component->driver->dapm_widgets,
  1329. component->driver->num_dapm_widgets);
  1330. if (ret != 0) {
  1331. dev_err(component->dev,
  1332. "Failed to create new controls %d\n", ret);
  1333. goto err_probe;
  1334. }
  1335. for_each_component_dais(component, dai) {
  1336. ret = snd_soc_dapm_new_dai_widgets(dapm, dai);
  1337. if (ret != 0) {
  1338. dev_err(component->dev,
  1339. "Failed to create DAI widgets %d\n", ret);
  1340. goto err_probe;
  1341. }
  1342. }
  1343. ret = snd_soc_component_probe(component);
  1344. if (ret < 0)
  1345. goto err_probe;
  1346. WARN(dapm->idle_bias_off &&
  1347. dapm->bias_level != SND_SOC_BIAS_OFF,
  1348. "codec %s can not start from non-off bias with idle_bias_off==1\n",
  1349. component->name);
  1350. probed = 1;
  1351. /*
  1352. * machine specific init
  1353. * see
  1354. * snd_soc_component_set_aux()
  1355. */
  1356. ret = snd_soc_component_init(component);
  1357. if (ret < 0)
  1358. goto err_probe;
  1359. ret = snd_soc_add_component_controls(component,
  1360. component->driver->controls,
  1361. component->driver->num_controls);
  1362. if (ret < 0)
  1363. goto err_probe;
  1364. ret = snd_soc_dapm_add_routes(dapm,
  1365. component->driver->dapm_routes,
  1366. component->driver->num_dapm_routes);
  1367. if (ret < 0) {
  1368. if (card->disable_route_checks) {
  1369. dev_info(card->dev,
  1370. "%s: disable_route_checks set, ignoring errors on add_routes\n",
  1371. __func__);
  1372. } else {
  1373. dev_err(card->dev,
  1374. "%s: snd_soc_dapm_add_routes failed: %d\n",
  1375. __func__, ret);
  1376. goto err_probe;
  1377. }
  1378. }
  1379. /* see for_each_card_components */
  1380. list_add(&component->card_list, &card->component_dev_list);
  1381. err_probe:
  1382. if (ret < 0)
  1383. soc_remove_component(component, probed);
  1384. return ret;
  1385. }
  1386. static void soc_remove_link_dais(struct snd_soc_card *card)
  1387. {
  1388. struct snd_soc_pcm_runtime *rtd;
  1389. int order;
  1390. for_each_comp_order(order) {
  1391. for_each_card_rtds(card, rtd) {
  1392. /* remove all rtd connected DAIs in good order */
  1393. snd_soc_pcm_dai_remove(rtd, order);
  1394. }
  1395. }
  1396. }
  1397. static int soc_probe_link_dais(struct snd_soc_card *card)
  1398. {
  1399. struct snd_soc_pcm_runtime *rtd;
  1400. int order, ret;
  1401. for_each_comp_order(order) {
  1402. for_each_card_rtds(card, rtd) {
  1403. /* probe all rtd connected DAIs in good order */
  1404. ret = snd_soc_pcm_dai_probe(rtd, order);
  1405. if (ret)
  1406. return ret;
  1407. }
  1408. }
  1409. return 0;
  1410. }
  1411. static void soc_remove_link_components(struct snd_soc_card *card)
  1412. {
  1413. struct snd_soc_component *component;
  1414. struct snd_soc_pcm_runtime *rtd;
  1415. int i, order;
  1416. for_each_comp_order(order) {
  1417. for_each_card_rtds(card, rtd) {
  1418. for_each_rtd_components(rtd, i, component) {
  1419. if (component->driver->remove_order != order)
  1420. continue;
  1421. soc_remove_component(component, 1);
  1422. }
  1423. }
  1424. }
  1425. }
  1426. static int soc_probe_link_components(struct snd_soc_card *card)
  1427. {
  1428. struct snd_soc_component *component;
  1429. struct snd_soc_pcm_runtime *rtd;
  1430. int i, ret, order;
  1431. for_each_comp_order(order) {
  1432. for_each_card_rtds(card, rtd) {
  1433. for_each_rtd_components(rtd, i, component) {
  1434. if (component->driver->probe_order != order)
  1435. continue;
  1436. ret = soc_probe_component(card, component);
  1437. if (ret < 0)
  1438. return ret;
  1439. }
  1440. }
  1441. }
  1442. return 0;
  1443. }
  1444. static void soc_unbind_aux_dev(struct snd_soc_card *card)
  1445. {
  1446. struct snd_soc_component *component, *_component;
  1447. for_each_card_auxs_safe(card, component, _component) {
  1448. /* for snd_soc_component_init() */
  1449. snd_soc_component_set_aux(component, NULL);
  1450. list_del(&component->card_aux_list);
  1451. }
  1452. }
  1453. static int soc_bind_aux_dev(struct snd_soc_card *card)
  1454. {
  1455. struct snd_soc_component *component;
  1456. struct snd_soc_aux_dev *aux;
  1457. int i;
  1458. for_each_card_pre_auxs(card, i, aux) {
  1459. /* codecs, usually analog devices */
  1460. component = soc_find_component(&aux->dlc);
  1461. if (!component)
  1462. return -EPROBE_DEFER;
  1463. /* for snd_soc_component_init() */
  1464. snd_soc_component_set_aux(component, aux);
  1465. /* see for_each_card_auxs */
  1466. list_add(&component->card_aux_list, &card->aux_comp_list);
  1467. }
  1468. return 0;
  1469. }
  1470. static int soc_probe_aux_devices(struct snd_soc_card *card)
  1471. {
  1472. struct snd_soc_component *component;
  1473. int order;
  1474. int ret;
  1475. for_each_comp_order(order) {
  1476. for_each_card_auxs(card, component) {
  1477. if (component->driver->probe_order != order)
  1478. continue;
  1479. ret = soc_probe_component(card, component);
  1480. if (ret < 0)
  1481. return ret;
  1482. }
  1483. }
  1484. return 0;
  1485. }
  1486. static void soc_remove_aux_devices(struct snd_soc_card *card)
  1487. {
  1488. struct snd_soc_component *comp, *_comp;
  1489. int order;
  1490. for_each_comp_order(order) {
  1491. for_each_card_auxs_safe(card, comp, _comp) {
  1492. if (comp->driver->remove_order == order)
  1493. soc_remove_component(comp, 1);
  1494. }
  1495. }
  1496. }
  1497. #ifdef CONFIG_DMI
  1498. /*
  1499. * If a DMI filed contain strings in this blacklist (e.g.
  1500. * "Type2 - Board Manufacturer" or "Type1 - TBD by OEM"), it will be taken
  1501. * as invalid and dropped when setting the card long name from DMI info.
  1502. */
  1503. static const char * const dmi_blacklist[] = {
  1504. "To be filled by OEM",
  1505. "TBD by OEM",
  1506. "Default String",
  1507. "Board Manufacturer",
  1508. "Board Vendor Name",
  1509. "Board Product Name",
  1510. NULL, /* terminator */
  1511. };
  1512. /*
  1513. * Trim special characters, and replace '-' with '_' since '-' is used to
  1514. * separate different DMI fields in the card long name. Only number and
  1515. * alphabet characters and a few separator characters are kept.
  1516. */
  1517. static void cleanup_dmi_name(char *name)
  1518. {
  1519. int i, j = 0;
  1520. for (i = 0; name[i]; i++) {
  1521. if (isalnum(name[i]) || (name[i] == '.')
  1522. || (name[i] == '_'))
  1523. name[j++] = name[i];
  1524. else if (name[i] == '-')
  1525. name[j++] = '_';
  1526. }
  1527. name[j] = '\0';
  1528. }
  1529. /*
  1530. * Check if a DMI field is valid, i.e. not containing any string
  1531. * in the black list.
  1532. */
  1533. static int is_dmi_valid(const char *field)
  1534. {
  1535. int i = 0;
  1536. while (dmi_blacklist[i]) {
  1537. if (strstr(field, dmi_blacklist[i]))
  1538. return 0;
  1539. i++;
  1540. }
  1541. return 1;
  1542. }
  1543. /*
  1544. * Append a string to card->dmi_longname with character cleanups.
  1545. */
  1546. static void append_dmi_string(struct snd_soc_card *card, const char *str)
  1547. {
  1548. char *dst = card->dmi_longname;
  1549. size_t dst_len = sizeof(card->dmi_longname);
  1550. size_t len;
  1551. len = strlen(dst);
  1552. snprintf(dst + len, dst_len - len, "-%s", str);
  1553. len++; /* skip the separator "-" */
  1554. if (len < dst_len)
  1555. cleanup_dmi_name(dst + len);
  1556. }
  1557. /**
  1558. * snd_soc_set_dmi_name() - Register DMI names to card
  1559. * @card: The card to register DMI names
  1560. * @flavour: The flavour "differentiator" for the card amongst its peers.
  1561. *
  1562. * An Intel machine driver may be used by many different devices but are
  1563. * difficult for userspace to differentiate, since machine drivers usually
  1564. * use their own name as the card short name and leave the card long name
  1565. * blank. To differentiate such devices and fix bugs due to lack of
  1566. * device-specific configurations, this function allows DMI info to be used
  1567. * as the sound card long name, in the format of
  1568. * "vendor-product-version-board"
  1569. * (Character '-' is used to separate different DMI fields here).
  1570. * This will help the user space to load the device-specific Use Case Manager
  1571. * (UCM) configurations for the card.
  1572. *
  1573. * Possible card long names may be:
  1574. * DellInc.-XPS139343-01-0310JH
  1575. * ASUSTeKCOMPUTERINC.-T100TA-1.0-T100TA
  1576. * Circuitco-MinnowboardMaxD0PLATFORM-D0-MinnowBoardMAX
  1577. *
  1578. * This function also supports flavoring the card longname to provide
  1579. * the extra differentiation, like "vendor-product-version-board-flavor".
  1580. *
  1581. * We only keep number and alphabet characters and a few separator characters
  1582. * in the card long name since UCM in the user space uses the card long names
  1583. * as card configuration directory names and AudoConf cannot support special
  1584. * characters like SPACE.
  1585. *
  1586. * Returns 0 on success, otherwise a negative error code.
  1587. */
  1588. int snd_soc_set_dmi_name(struct snd_soc_card *card, const char *flavour)
  1589. {
  1590. const char *vendor, *product, *board;
  1591. if (card->long_name)
  1592. return 0; /* long name already set by driver or from DMI */
  1593. if (!dmi_available)
  1594. return 0;
  1595. /* make up dmi long name as: vendor-product-version-board */
  1596. vendor = dmi_get_system_info(DMI_BOARD_VENDOR);
  1597. if (!vendor || !is_dmi_valid(vendor)) {
  1598. dev_warn(card->dev, "ASoC: no DMI vendor name!\n");
  1599. return 0;
  1600. }
  1601. snprintf(card->dmi_longname, sizeof(card->dmi_longname), "%s", vendor);
  1602. cleanup_dmi_name(card->dmi_longname);
  1603. product = dmi_get_system_info(DMI_PRODUCT_NAME);
  1604. if (product && is_dmi_valid(product)) {
  1605. const char *product_version = dmi_get_system_info(DMI_PRODUCT_VERSION);
  1606. append_dmi_string(card, product);
  1607. /*
  1608. * some vendors like Lenovo may only put a self-explanatory
  1609. * name in the product version field
  1610. */
  1611. if (product_version && is_dmi_valid(product_version))
  1612. append_dmi_string(card, product_version);
  1613. }
  1614. board = dmi_get_system_info(DMI_BOARD_NAME);
  1615. if (board && is_dmi_valid(board)) {
  1616. if (!product || strcasecmp(board, product))
  1617. append_dmi_string(card, board);
  1618. } else if (!product) {
  1619. /* fall back to using legacy name */
  1620. dev_warn(card->dev, "ASoC: no DMI board/product name!\n");
  1621. return 0;
  1622. }
  1623. /* Add flavour to dmi long name */
  1624. if (flavour)
  1625. append_dmi_string(card, flavour);
  1626. /* set the card long name */
  1627. card->long_name = card->dmi_longname;
  1628. return 0;
  1629. }
  1630. EXPORT_SYMBOL_GPL(snd_soc_set_dmi_name);
  1631. #endif /* CONFIG_DMI */
  1632. static void soc_check_tplg_fes(struct snd_soc_card *card)
  1633. {
  1634. struct snd_soc_component *component;
  1635. const struct snd_soc_component_driver *comp_drv;
  1636. struct snd_soc_dai_link *dai_link;
  1637. int i;
  1638. for_each_component(component) {
  1639. /* does this component override BEs ? */
  1640. if (!component->driver->ignore_machine)
  1641. continue;
  1642. /* for this machine ? */
  1643. if (!strcmp(component->driver->ignore_machine,
  1644. card->dev->driver->name))
  1645. goto match;
  1646. if (strcmp(component->driver->ignore_machine,
  1647. dev_name(card->dev)))
  1648. continue;
  1649. match:
  1650. /* machine matches, so override the rtd data */
  1651. for_each_card_prelinks(card, i, dai_link) {
  1652. /* ignore this FE */
  1653. if (dai_link->dynamic) {
  1654. dai_link->ignore = true;
  1655. continue;
  1656. }
  1657. dev_dbg(card->dev, "info: override BE DAI link %s\n",
  1658. card->dai_link[i].name);
  1659. /* override platform component */
  1660. if (!dai_link->platforms) {
  1661. dev_err(card->dev, "init platform error");
  1662. continue;
  1663. }
  1664. if (component->dev->of_node)
  1665. dai_link->platforms->of_node = component->dev->of_node;
  1666. else
  1667. dai_link->platforms->name = component->name;
  1668. /* convert non BE into BE */
  1669. if (!dai_link->no_pcm) {
  1670. dai_link->no_pcm = 1;
  1671. if (dai_link->dpcm_playback)
  1672. dev_warn(card->dev,
  1673. "invalid configuration, dailink %s has flags no_pcm=0 and dpcm_playback=1\n",
  1674. dai_link->name);
  1675. if (dai_link->dpcm_capture)
  1676. dev_warn(card->dev,
  1677. "invalid configuration, dailink %s has flags no_pcm=0 and dpcm_capture=1\n",
  1678. dai_link->name);
  1679. /* convert normal link into DPCM one */
  1680. if (!(dai_link->dpcm_playback ||
  1681. dai_link->dpcm_capture)) {
  1682. dai_link->dpcm_playback = !dai_link->capture_only;
  1683. dai_link->dpcm_capture = !dai_link->playback_only;
  1684. }
  1685. }
  1686. /*
  1687. * override any BE fixups
  1688. * see
  1689. * snd_soc_link_be_hw_params_fixup()
  1690. */
  1691. dai_link->be_hw_params_fixup =
  1692. component->driver->be_hw_params_fixup;
  1693. /*
  1694. * most BE links don't set stream name, so set it to
  1695. * dai link name if it's NULL to help bind widgets.
  1696. */
  1697. if (!dai_link->stream_name)
  1698. dai_link->stream_name = dai_link->name;
  1699. }
  1700. /* Inform userspace we are using alternate topology */
  1701. if (component->driver->topology_name_prefix) {
  1702. /* topology shortname created? */
  1703. if (!card->topology_shortname_created) {
  1704. comp_drv = component->driver;
  1705. snprintf(card->topology_shortname, 32, "%s-%s",
  1706. comp_drv->topology_name_prefix,
  1707. card->name);
  1708. card->topology_shortname_created = true;
  1709. }
  1710. /* use topology shortname */
  1711. card->name = card->topology_shortname;
  1712. }
  1713. }
  1714. }
  1715. #define soc_setup_card_name(card, name, name1, name2) \
  1716. __soc_setup_card_name(card, name, sizeof(name), name1, name2)
  1717. static void __soc_setup_card_name(struct snd_soc_card *card,
  1718. char *name, int len,
  1719. const char *name1, const char *name2)
  1720. {
  1721. const char *src = name1 ? name1 : name2;
  1722. int i;
  1723. snprintf(name, len, "%s", src);
  1724. if (name != card->snd_card->driver)
  1725. return;
  1726. /*
  1727. * Name normalization (driver field)
  1728. *
  1729. * The driver name is somewhat special, as it's used as a key for
  1730. * searches in the user-space.
  1731. *
  1732. * ex)
  1733. * "abcd??efg" -> "abcd__efg"
  1734. */
  1735. for (i = 0; i < len; i++) {
  1736. switch (name[i]) {
  1737. case '_':
  1738. case '-':
  1739. case '\0':
  1740. break;
  1741. default:
  1742. if (!isalnum(name[i]))
  1743. name[i] = '_';
  1744. break;
  1745. }
  1746. }
  1747. /*
  1748. * The driver field should contain a valid string from the user view.
  1749. * The wrapping usually does not work so well here. Set a smaller string
  1750. * in the specific ASoC driver.
  1751. */
  1752. if (strlen(src) > len - 1)
  1753. dev_err(card->dev, "ASoC: driver name too long '%s' -> '%s'\n", src, name);
  1754. }
  1755. static void soc_cleanup_card_resources(struct snd_soc_card *card)
  1756. {
  1757. struct snd_soc_pcm_runtime *rtd, *n;
  1758. if (card->snd_card)
  1759. snd_card_disconnect_sync(card->snd_card);
  1760. snd_soc_dapm_shutdown(card);
  1761. /* release machine specific resources */
  1762. for_each_card_rtds(card, rtd)
  1763. if (rtd->initialized)
  1764. snd_soc_link_exit(rtd);
  1765. /* remove and free each DAI */
  1766. soc_remove_link_dais(card);
  1767. soc_remove_link_components(card);
  1768. for_each_card_rtds_safe(card, rtd, n)
  1769. snd_soc_remove_pcm_runtime(card, rtd);
  1770. /* remove auxiliary devices */
  1771. soc_remove_aux_devices(card);
  1772. soc_unbind_aux_dev(card);
  1773. snd_soc_dapm_free(&card->dapm);
  1774. soc_cleanup_card_debugfs(card);
  1775. /* remove the card */
  1776. snd_soc_card_remove(card);
  1777. if (card->snd_card) {
  1778. snd_card_free(card->snd_card);
  1779. card->snd_card = NULL;
  1780. }
  1781. }
  1782. static void snd_soc_unbind_card(struct snd_soc_card *card, bool unregister)
  1783. {
  1784. if (snd_soc_card_is_instantiated(card)) {
  1785. card->instantiated = false;
  1786. snd_soc_flush_all_delayed_work(card);
  1787. soc_cleanup_card_resources(card);
  1788. if (!unregister)
  1789. list_add(&card->list, &unbind_card_list);
  1790. } else {
  1791. if (unregister)
  1792. list_del(&card->list);
  1793. }
  1794. }
  1795. static int snd_soc_bind_card(struct snd_soc_card *card)
  1796. {
  1797. struct snd_soc_pcm_runtime *rtd;
  1798. struct snd_soc_component *component;
  1799. int ret;
  1800. mutex_lock(&client_mutex);
  1801. snd_soc_card_mutex_lock_root(card);
  1802. snd_soc_fill_dummy_dai(card);
  1803. snd_soc_dapm_init(&card->dapm, card, NULL);
  1804. /* check whether any platform is ignore machine FE and using topology */
  1805. soc_check_tplg_fes(card);
  1806. /* bind aux_devs too */
  1807. ret = soc_bind_aux_dev(card);
  1808. if (ret < 0)
  1809. goto probe_end;
  1810. /* add predefined DAI links to the list */
  1811. card->num_rtd = 0;
  1812. ret = snd_soc_add_pcm_runtimes(card, card->dai_link, card->num_links);
  1813. if (ret < 0)
  1814. goto probe_end;
  1815. /* card bind complete so register a sound card */
  1816. ret = snd_card_new(card->dev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
  1817. card->owner, 0, &card->snd_card);
  1818. if (ret < 0) {
  1819. dev_err(card->dev,
  1820. "ASoC: can't create sound card for card %s: %d\n",
  1821. card->name, ret);
  1822. goto probe_end;
  1823. }
  1824. soc_init_card_debugfs(card);
  1825. soc_resume_init(card);
  1826. ret = snd_soc_dapm_new_controls(&card->dapm, card->dapm_widgets,
  1827. card->num_dapm_widgets);
  1828. if (ret < 0)
  1829. goto probe_end;
  1830. ret = snd_soc_dapm_new_controls(&card->dapm, card->of_dapm_widgets,
  1831. card->num_of_dapm_widgets);
  1832. if (ret < 0)
  1833. goto probe_end;
  1834. /* initialise the sound card only once */
  1835. ret = snd_soc_card_probe(card);
  1836. if (ret < 0)
  1837. goto probe_end;
  1838. /* probe all components used by DAI links on this card */
  1839. ret = soc_probe_link_components(card);
  1840. if (ret < 0) {
  1841. if (ret != -EPROBE_DEFER) {
  1842. dev_err(card->dev,
  1843. "ASoC: failed to instantiate card %d\n", ret);
  1844. }
  1845. goto probe_end;
  1846. }
  1847. /* probe auxiliary components */
  1848. ret = soc_probe_aux_devices(card);
  1849. if (ret < 0) {
  1850. dev_err(card->dev,
  1851. "ASoC: failed to probe aux component %d\n", ret);
  1852. goto probe_end;
  1853. }
  1854. /* probe all DAI links on this card */
  1855. ret = soc_probe_link_dais(card);
  1856. if (ret < 0) {
  1857. dev_err(card->dev,
  1858. "ASoC: failed to instantiate card %d\n", ret);
  1859. goto probe_end;
  1860. }
  1861. for_each_card_rtds(card, rtd) {
  1862. ret = soc_init_pcm_runtime(card, rtd);
  1863. if (ret < 0)
  1864. goto probe_end;
  1865. }
  1866. snd_soc_dapm_link_dai_widgets(card);
  1867. snd_soc_dapm_connect_dai_link_widgets(card);
  1868. ret = snd_soc_add_card_controls(card, card->controls,
  1869. card->num_controls);
  1870. if (ret < 0)
  1871. goto probe_end;
  1872. ret = snd_soc_dapm_add_routes(&card->dapm, card->dapm_routes,
  1873. card->num_dapm_routes);
  1874. if (ret < 0) {
  1875. if (card->disable_route_checks) {
  1876. dev_info(card->dev,
  1877. "%s: disable_route_checks set, ignoring errors on add_routes\n",
  1878. __func__);
  1879. } else {
  1880. dev_err(card->dev,
  1881. "%s: snd_soc_dapm_add_routes failed: %d\n",
  1882. __func__, ret);
  1883. goto probe_end;
  1884. }
  1885. }
  1886. ret = snd_soc_dapm_add_routes(&card->dapm, card->of_dapm_routes,
  1887. card->num_of_dapm_routes);
  1888. if (ret < 0)
  1889. goto probe_end;
  1890. /* try to set some sane longname if DMI is available */
  1891. snd_soc_set_dmi_name(card, NULL);
  1892. soc_setup_card_name(card, card->snd_card->shortname,
  1893. card->name, NULL);
  1894. soc_setup_card_name(card, card->snd_card->longname,
  1895. card->long_name, card->name);
  1896. soc_setup_card_name(card, card->snd_card->driver,
  1897. card->driver_name, card->name);
  1898. if (card->components) {
  1899. /* the current implementation of snd_component_add() accepts */
  1900. /* multiple components in the string separated by space, */
  1901. /* but the string collision (identical string) check might */
  1902. /* not work correctly */
  1903. ret = snd_component_add(card->snd_card, card->components);
  1904. if (ret < 0) {
  1905. dev_err(card->dev, "ASoC: %s snd_component_add() failed: %d\n",
  1906. card->name, ret);
  1907. goto probe_end;
  1908. }
  1909. }
  1910. ret = snd_soc_card_late_probe(card);
  1911. if (ret < 0)
  1912. goto probe_end;
  1913. snd_soc_dapm_new_widgets(card);
  1914. snd_soc_card_fixup_controls(card);
  1915. ret = snd_card_register(card->snd_card);
  1916. if (ret < 0) {
  1917. dev_err(card->dev, "ASoC: failed to register soundcard %d\n",
  1918. ret);
  1919. goto probe_end;
  1920. }
  1921. card->instantiated = 1;
  1922. dapm_mark_endpoints_dirty(card);
  1923. snd_soc_dapm_sync(&card->dapm);
  1924. /* deactivate pins to sleep state */
  1925. for_each_card_components(card, component)
  1926. if (!snd_soc_component_active(component))
  1927. pinctrl_pm_select_sleep_state(component->dev);
  1928. probe_end:
  1929. if (ret < 0)
  1930. soc_cleanup_card_resources(card);
  1931. snd_soc_card_mutex_unlock(card);
  1932. mutex_unlock(&client_mutex);
  1933. return ret;
  1934. }
  1935. /* probes a new socdev */
  1936. static int soc_probe(struct platform_device *pdev)
  1937. {
  1938. struct snd_soc_card *card = platform_get_drvdata(pdev);
  1939. /*
  1940. * no card, so machine driver should be registering card
  1941. * we should not be here in that case so ret error
  1942. */
  1943. if (!card)
  1944. return -EINVAL;
  1945. dev_warn(&pdev->dev,
  1946. "ASoC: machine %s should use snd_soc_register_card()\n",
  1947. card->name);
  1948. /* Bodge while we unpick instantiation */
  1949. card->dev = &pdev->dev;
  1950. return devm_snd_soc_register_card(&pdev->dev, card);
  1951. }
  1952. int snd_soc_poweroff(struct device *dev)
  1953. {
  1954. struct snd_soc_card *card = dev_get_drvdata(dev);
  1955. struct snd_soc_component *component;
  1956. if (!snd_soc_card_is_instantiated(card))
  1957. return 0;
  1958. /*
  1959. * Flush out pmdown_time work - we actually do want to run it
  1960. * now, we're shutting down so no imminent restart.
  1961. */
  1962. snd_soc_flush_all_delayed_work(card);
  1963. snd_soc_dapm_shutdown(card);
  1964. /* deactivate pins to sleep state */
  1965. for_each_card_components(card, component)
  1966. pinctrl_pm_select_sleep_state(component->dev);
  1967. return 0;
  1968. }
  1969. EXPORT_SYMBOL_GPL(snd_soc_poweroff);
  1970. const struct dev_pm_ops snd_soc_pm_ops = {
  1971. .suspend = snd_soc_suspend,
  1972. .resume = snd_soc_resume,
  1973. .freeze = snd_soc_suspend,
  1974. .thaw = snd_soc_resume,
  1975. .poweroff = snd_soc_poweroff,
  1976. .restore = snd_soc_resume,
  1977. };
  1978. EXPORT_SYMBOL_GPL(snd_soc_pm_ops);
  1979. /* ASoC platform driver */
  1980. static struct platform_driver soc_driver = {
  1981. .driver = {
  1982. .name = "soc-audio",
  1983. .pm = &snd_soc_pm_ops,
  1984. },
  1985. .probe = soc_probe,
  1986. };
  1987. /**
  1988. * snd_soc_cnew - create new control
  1989. * @_template: control template
  1990. * @data: control private data
  1991. * @long_name: control long name
  1992. * @prefix: control name prefix
  1993. *
  1994. * Create a new mixer control from a template control.
  1995. *
  1996. * Returns 0 for success, else error.
  1997. */
  1998. struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
  1999. void *data, const char *long_name,
  2000. const char *prefix)
  2001. {
  2002. struct snd_kcontrol_new template;
  2003. struct snd_kcontrol *kcontrol;
  2004. char *name = NULL;
  2005. memcpy(&template, _template, sizeof(template));
  2006. template.index = 0;
  2007. if (!long_name)
  2008. long_name = template.name;
  2009. if (prefix) {
  2010. name = kasprintf(GFP_KERNEL, "%s %s", prefix, long_name);
  2011. if (!name)
  2012. return NULL;
  2013. template.name = name;
  2014. } else {
  2015. template.name = long_name;
  2016. }
  2017. kcontrol = snd_ctl_new1(&template, data);
  2018. kfree(name);
  2019. return kcontrol;
  2020. }
  2021. EXPORT_SYMBOL_GPL(snd_soc_cnew);
  2022. static int snd_soc_add_controls(struct snd_card *card, struct device *dev,
  2023. const struct snd_kcontrol_new *controls, int num_controls,
  2024. const char *prefix, void *data)
  2025. {
  2026. int i;
  2027. for (i = 0; i < num_controls; i++) {
  2028. const struct snd_kcontrol_new *control = &controls[i];
  2029. int err = snd_ctl_add(card, snd_soc_cnew(control, data,
  2030. control->name, prefix));
  2031. if (err < 0) {
  2032. dev_err(dev, "ASoC: Failed to add %s: %d\n",
  2033. control->name, err);
  2034. return err;
  2035. }
  2036. }
  2037. return 0;
  2038. }
  2039. /**
  2040. * snd_soc_add_component_controls - Add an array of controls to a component.
  2041. *
  2042. * @component: Component to add controls to
  2043. * @controls: Array of controls to add
  2044. * @num_controls: Number of elements in the array
  2045. *
  2046. * Return: 0 for success, else error.
  2047. */
  2048. int snd_soc_add_component_controls(struct snd_soc_component *component,
  2049. const struct snd_kcontrol_new *controls, unsigned int num_controls)
  2050. {
  2051. struct snd_card *card = component->card->snd_card;
  2052. return snd_soc_add_controls(card, component->dev, controls,
  2053. num_controls, component->name_prefix, component);
  2054. }
  2055. EXPORT_SYMBOL_GPL(snd_soc_add_component_controls);
  2056. /**
  2057. * snd_soc_add_card_controls - add an array of controls to a SoC card.
  2058. * Convenience function to add a list of controls.
  2059. *
  2060. * @soc_card: SoC card to add controls to
  2061. * @controls: array of controls to add
  2062. * @num_controls: number of elements in the array
  2063. *
  2064. * Return 0 for success, else error.
  2065. */
  2066. int snd_soc_add_card_controls(struct snd_soc_card *soc_card,
  2067. const struct snd_kcontrol_new *controls, int num_controls)
  2068. {
  2069. struct snd_card *card = soc_card->snd_card;
  2070. return snd_soc_add_controls(card, soc_card->dev, controls, num_controls,
  2071. NULL, soc_card);
  2072. }
  2073. EXPORT_SYMBOL_GPL(snd_soc_add_card_controls);
  2074. /**
  2075. * snd_soc_add_dai_controls - add an array of controls to a DAI.
  2076. * Convenience function to add a list of controls.
  2077. *
  2078. * @dai: DAI to add controls to
  2079. * @controls: array of controls to add
  2080. * @num_controls: number of elements in the array
  2081. *
  2082. * Return 0 for success, else error.
  2083. */
  2084. int snd_soc_add_dai_controls(struct snd_soc_dai *dai,
  2085. const struct snd_kcontrol_new *controls, int num_controls)
  2086. {
  2087. struct snd_card *card = dai->component->card->snd_card;
  2088. return snd_soc_add_controls(card, dai->dev, controls, num_controls,
  2089. NULL, dai);
  2090. }
  2091. EXPORT_SYMBOL_GPL(snd_soc_add_dai_controls);
  2092. /**
  2093. * snd_soc_register_card - Register a card with the ASoC core
  2094. *
  2095. * @card: Card to register
  2096. *
  2097. */
  2098. int snd_soc_register_card(struct snd_soc_card *card)
  2099. {
  2100. if (!card->name || !card->dev)
  2101. return -EINVAL;
  2102. dev_set_drvdata(card->dev, card);
  2103. INIT_LIST_HEAD(&card->widgets);
  2104. INIT_LIST_HEAD(&card->paths);
  2105. INIT_LIST_HEAD(&card->dapm_list);
  2106. INIT_LIST_HEAD(&card->aux_comp_list);
  2107. INIT_LIST_HEAD(&card->component_dev_list);
  2108. INIT_LIST_HEAD(&card->list);
  2109. INIT_LIST_HEAD(&card->rtd_list);
  2110. INIT_LIST_HEAD(&card->dapm_dirty);
  2111. INIT_LIST_HEAD(&card->dobj_list);
  2112. card->instantiated = 0;
  2113. mutex_init(&card->mutex);
  2114. mutex_init(&card->dapm_mutex);
  2115. mutex_init(&card->pcm_mutex);
  2116. return snd_soc_bind_card(card);
  2117. }
  2118. EXPORT_SYMBOL_GPL(snd_soc_register_card);
  2119. /**
  2120. * snd_soc_unregister_card - Unregister a card with the ASoC core
  2121. *
  2122. * @card: Card to unregister
  2123. *
  2124. */
  2125. void snd_soc_unregister_card(struct snd_soc_card *card)
  2126. {
  2127. mutex_lock(&client_mutex);
  2128. snd_soc_unbind_card(card, true);
  2129. mutex_unlock(&client_mutex);
  2130. dev_dbg(card->dev, "ASoC: Unregistered card '%s'\n", card->name);
  2131. }
  2132. EXPORT_SYMBOL_GPL(snd_soc_unregister_card);
  2133. /*
  2134. * Simplify DAI link configuration by removing ".-1" from device names
  2135. * and sanitizing names.
  2136. */
  2137. static char *fmt_single_name(struct device *dev, int *id)
  2138. {
  2139. const char *devname = dev_name(dev);
  2140. char *found, *name;
  2141. unsigned int id1, id2;
  2142. if (devname == NULL)
  2143. return NULL;
  2144. name = devm_kstrdup(dev, devname, GFP_KERNEL);
  2145. if (!name)
  2146. return NULL;
  2147. /* are we a "%s.%d" name (platform and SPI components) */
  2148. found = strstr(name, dev->driver->name);
  2149. if (found) {
  2150. /* get ID */
  2151. if (sscanf(&found[strlen(dev->driver->name)], ".%d", id) == 1) {
  2152. /* discard ID from name if ID == -1 */
  2153. if (*id == -1)
  2154. found[strlen(dev->driver->name)] = '\0';
  2155. }
  2156. /* I2C component devices are named "bus-addr" */
  2157. } else if (sscanf(name, "%x-%x", &id1, &id2) == 2) {
  2158. /* create unique ID number from I2C addr and bus */
  2159. *id = ((id1 & 0xffff) << 16) + id2;
  2160. devm_kfree(dev, name);
  2161. /* sanitize component name for DAI link creation */
  2162. name = devm_kasprintf(dev, GFP_KERNEL, "%s.%s", dev->driver->name, devname);
  2163. } else {
  2164. *id = 0;
  2165. }
  2166. return name;
  2167. }
  2168. /*
  2169. * Simplify DAI link naming for single devices with multiple DAIs by removing
  2170. * any ".-1" and using the DAI name (instead of device name).
  2171. */
  2172. static inline char *fmt_multiple_name(struct device *dev,
  2173. struct snd_soc_dai_driver *dai_drv)
  2174. {
  2175. if (dai_drv->name == NULL) {
  2176. dev_err(dev,
  2177. "ASoC: error - multiple DAI %s registered with no name\n",
  2178. dev_name(dev));
  2179. return NULL;
  2180. }
  2181. return devm_kstrdup(dev, dai_drv->name, GFP_KERNEL);
  2182. }
  2183. void snd_soc_unregister_dai(struct snd_soc_dai *dai)
  2184. {
  2185. dev_dbg(dai->dev, "ASoC: Unregistered DAI '%s'\n", dai->name);
  2186. list_del(&dai->list);
  2187. }
  2188. EXPORT_SYMBOL_GPL(snd_soc_unregister_dai);
  2189. /**
  2190. * snd_soc_register_dai - Register a DAI dynamically & create its widgets
  2191. *
  2192. * @component: The component the DAIs are registered for
  2193. * @dai_drv: DAI driver to use for the DAI
  2194. * @legacy_dai_naming: if %true, use legacy single-name format;
  2195. * if %false, use multiple-name format;
  2196. *
  2197. * Topology can use this API to register DAIs when probing a component.
  2198. * These DAIs's widgets will be freed in the card cleanup and the DAIs
  2199. * will be freed in the component cleanup.
  2200. */
  2201. struct snd_soc_dai *snd_soc_register_dai(struct snd_soc_component *component,
  2202. struct snd_soc_dai_driver *dai_drv,
  2203. bool legacy_dai_naming)
  2204. {
  2205. struct device *dev = component->dev;
  2206. struct snd_soc_dai *dai;
  2207. lockdep_assert_held(&client_mutex);
  2208. dai = devm_kzalloc(dev, sizeof(*dai), GFP_KERNEL);
  2209. if (dai == NULL)
  2210. return NULL;
  2211. /*
  2212. * Back in the old days when we still had component-less DAIs,
  2213. * instead of having a static name, component-less DAIs would
  2214. * inherit the name of the parent device so it is possible to
  2215. * register multiple instances of the DAI. We still need to keep
  2216. * the same naming style even though those DAIs are not
  2217. * component-less anymore.
  2218. */
  2219. if (legacy_dai_naming &&
  2220. (dai_drv->id == 0 || dai_drv->name == NULL)) {
  2221. dai->name = fmt_single_name(dev, &dai->id);
  2222. } else {
  2223. dai->name = fmt_multiple_name(dev, dai_drv);
  2224. if (dai_drv->id)
  2225. dai->id = dai_drv->id;
  2226. else
  2227. dai->id = component->num_dai;
  2228. }
  2229. if (!dai->name)
  2230. return NULL;
  2231. dai->component = component;
  2232. dai->dev = dev;
  2233. dai->driver = dai_drv;
  2234. /* see for_each_component_dais */
  2235. list_add_tail(&dai->list, &component->dai_list);
  2236. component->num_dai++;
  2237. dev_dbg(dev, "ASoC: Registered DAI '%s'\n", dai->name);
  2238. return dai;
  2239. }
  2240. EXPORT_SYMBOL_GPL(snd_soc_register_dai);
  2241. /**
  2242. * snd_soc_unregister_dais - Unregister DAIs from the ASoC core
  2243. *
  2244. * @component: The component for which the DAIs should be unregistered
  2245. */
  2246. static void snd_soc_unregister_dais(struct snd_soc_component *component)
  2247. {
  2248. struct snd_soc_dai *dai, *_dai;
  2249. for_each_component_dais_safe(component, dai, _dai)
  2250. snd_soc_unregister_dai(dai);
  2251. }
  2252. /**
  2253. * snd_soc_register_dais - Register a DAI with the ASoC core
  2254. *
  2255. * @component: The component the DAIs are registered for
  2256. * @dai_drv: DAI driver to use for the DAIs
  2257. * @count: Number of DAIs
  2258. */
  2259. static int snd_soc_register_dais(struct snd_soc_component *component,
  2260. struct snd_soc_dai_driver *dai_drv,
  2261. size_t count)
  2262. {
  2263. struct snd_soc_dai *dai;
  2264. unsigned int i;
  2265. int ret;
  2266. for (i = 0; i < count; i++) {
  2267. dai = snd_soc_register_dai(component, dai_drv + i, count == 1 &&
  2268. component->driver->legacy_dai_naming);
  2269. if (dai == NULL) {
  2270. ret = -ENOMEM;
  2271. goto err;
  2272. }
  2273. }
  2274. return 0;
  2275. err:
  2276. snd_soc_unregister_dais(component);
  2277. return ret;
  2278. }
  2279. #define ENDIANNESS_MAP(name) \
  2280. (SNDRV_PCM_FMTBIT_##name##LE | SNDRV_PCM_FMTBIT_##name##BE)
  2281. static u64 endianness_format_map[] = {
  2282. ENDIANNESS_MAP(S16_),
  2283. ENDIANNESS_MAP(U16_),
  2284. ENDIANNESS_MAP(S24_),
  2285. ENDIANNESS_MAP(U24_),
  2286. ENDIANNESS_MAP(S32_),
  2287. ENDIANNESS_MAP(U32_),
  2288. ENDIANNESS_MAP(S24_3),
  2289. ENDIANNESS_MAP(U24_3),
  2290. ENDIANNESS_MAP(S20_3),
  2291. ENDIANNESS_MAP(U20_3),
  2292. ENDIANNESS_MAP(S18_3),
  2293. ENDIANNESS_MAP(U18_3),
  2294. ENDIANNESS_MAP(FLOAT_),
  2295. ENDIANNESS_MAP(FLOAT64_),
  2296. ENDIANNESS_MAP(IEC958_SUBFRAME_),
  2297. };
  2298. /*
  2299. * Fix up the DAI formats for endianness: codecs don't actually see
  2300. * the endianness of the data but we're using the CPU format
  2301. * definitions which do need to include endianness so we ensure that
  2302. * codec DAIs always have both big and little endian variants set.
  2303. */
  2304. static void convert_endianness_formats(struct snd_soc_pcm_stream *stream)
  2305. {
  2306. int i;
  2307. for (i = 0; i < ARRAY_SIZE(endianness_format_map); i++)
  2308. if (stream->formats & endianness_format_map[i])
  2309. stream->formats |= endianness_format_map[i];
  2310. }
  2311. static void snd_soc_try_rebind_card(void)
  2312. {
  2313. struct snd_soc_card *card, *c;
  2314. list_for_each_entry_safe(card, c, &unbind_card_list, list)
  2315. if (!snd_soc_bind_card(card))
  2316. list_del(&card->list);
  2317. }
  2318. static void snd_soc_del_component_unlocked(struct snd_soc_component *component)
  2319. {
  2320. struct snd_soc_card *card = component->card;
  2321. snd_soc_unregister_dais(component);
  2322. if (card)
  2323. snd_soc_unbind_card(card, false);
  2324. list_del(&component->list);
  2325. }
  2326. int snd_soc_component_initialize(struct snd_soc_component *component,
  2327. const struct snd_soc_component_driver *driver,
  2328. struct device *dev)
  2329. {
  2330. INIT_LIST_HEAD(&component->dai_list);
  2331. INIT_LIST_HEAD(&component->dobj_list);
  2332. INIT_LIST_HEAD(&component->card_list);
  2333. INIT_LIST_HEAD(&component->list);
  2334. mutex_init(&component->io_mutex);
  2335. if (!component->name) {
  2336. component->name = fmt_single_name(dev, &component->id);
  2337. if (!component->name) {
  2338. dev_err(dev, "ASoC: Failed to allocate name\n");
  2339. return -ENOMEM;
  2340. }
  2341. }
  2342. component->dev = dev;
  2343. component->driver = driver;
  2344. #ifdef CONFIG_DEBUG_FS
  2345. if (!component->debugfs_prefix)
  2346. component->debugfs_prefix = driver->debugfs_prefix;
  2347. #endif
  2348. return 0;
  2349. }
  2350. EXPORT_SYMBOL_GPL(snd_soc_component_initialize);
  2351. int snd_soc_add_component(struct snd_soc_component *component,
  2352. struct snd_soc_dai_driver *dai_drv,
  2353. int num_dai)
  2354. {
  2355. int ret;
  2356. int i;
  2357. mutex_lock(&client_mutex);
  2358. if (component->driver->endianness) {
  2359. for (i = 0; i < num_dai; i++) {
  2360. convert_endianness_formats(&dai_drv[i].playback);
  2361. convert_endianness_formats(&dai_drv[i].capture);
  2362. }
  2363. }
  2364. ret = snd_soc_register_dais(component, dai_drv, num_dai);
  2365. if (ret < 0) {
  2366. dev_err(component->dev, "ASoC: Failed to register DAIs: %d\n",
  2367. ret);
  2368. goto err_cleanup;
  2369. }
  2370. if (!component->driver->write && !component->driver->read) {
  2371. if (!component->regmap)
  2372. component->regmap = dev_get_regmap(component->dev,
  2373. NULL);
  2374. if (component->regmap)
  2375. snd_soc_component_setup_regmap(component);
  2376. }
  2377. /* see for_each_component */
  2378. list_add(&component->list, &component_list);
  2379. err_cleanup:
  2380. if (ret < 0)
  2381. snd_soc_del_component_unlocked(component);
  2382. mutex_unlock(&client_mutex);
  2383. if (ret == 0)
  2384. snd_soc_try_rebind_card();
  2385. return ret;
  2386. }
  2387. EXPORT_SYMBOL_GPL(snd_soc_add_component);
  2388. int snd_soc_register_component(struct device *dev,
  2389. const struct snd_soc_component_driver *component_driver,
  2390. struct snd_soc_dai_driver *dai_drv,
  2391. int num_dai)
  2392. {
  2393. struct snd_soc_component *component;
  2394. int ret;
  2395. component = devm_kzalloc(dev, sizeof(*component), GFP_KERNEL);
  2396. if (!component)
  2397. return -ENOMEM;
  2398. ret = snd_soc_component_initialize(component, component_driver, dev);
  2399. if (ret < 0)
  2400. return ret;
  2401. return snd_soc_add_component(component, dai_drv, num_dai);
  2402. }
  2403. EXPORT_SYMBOL_GPL(snd_soc_register_component);
  2404. /**
  2405. * snd_soc_unregister_component_by_driver - Unregister component using a given driver
  2406. * from the ASoC core
  2407. *
  2408. * @dev: The device to unregister
  2409. * @component_driver: The component driver to unregister
  2410. */
  2411. void snd_soc_unregister_component_by_driver(struct device *dev,
  2412. const struct snd_soc_component_driver *component_driver)
  2413. {
  2414. struct snd_soc_component *component;
  2415. if (!component_driver)
  2416. return;
  2417. mutex_lock(&client_mutex);
  2418. component = snd_soc_lookup_component_nolocked(dev, component_driver->name);
  2419. if (!component)
  2420. goto out;
  2421. snd_soc_del_component_unlocked(component);
  2422. out:
  2423. mutex_unlock(&client_mutex);
  2424. }
  2425. EXPORT_SYMBOL_GPL(snd_soc_unregister_component_by_driver);
  2426. /**
  2427. * snd_soc_unregister_component - Unregister all related component
  2428. * from the ASoC core
  2429. *
  2430. * @dev: The device to unregister
  2431. */
  2432. void snd_soc_unregister_component(struct device *dev)
  2433. {
  2434. mutex_lock(&client_mutex);
  2435. while (1) {
  2436. struct snd_soc_component *component = snd_soc_lookup_component_nolocked(dev, NULL);
  2437. if (!component)
  2438. break;
  2439. snd_soc_del_component_unlocked(component);
  2440. }
  2441. mutex_unlock(&client_mutex);
  2442. }
  2443. EXPORT_SYMBOL_GPL(snd_soc_unregister_component);
  2444. /* Retrieve a card's name from device tree */
  2445. int snd_soc_of_parse_card_name(struct snd_soc_card *card,
  2446. const char *propname)
  2447. {
  2448. struct device_node *np;
  2449. int ret;
  2450. if (!card->dev) {
  2451. pr_err("card->dev is not set before calling %s\n", __func__);
  2452. return -EINVAL;
  2453. }
  2454. np = card->dev->of_node;
  2455. ret = of_property_read_string_index(np, propname, 0, &card->name);
  2456. /*
  2457. * EINVAL means the property does not exist. This is fine providing
  2458. * card->name was previously set, which is checked later in
  2459. * snd_soc_register_card.
  2460. */
  2461. if (ret < 0 && ret != -EINVAL) {
  2462. dev_err(card->dev,
  2463. "ASoC: Property '%s' could not be read: %d\n",
  2464. propname, ret);
  2465. return ret;
  2466. }
  2467. return 0;
  2468. }
  2469. EXPORT_SYMBOL_GPL(snd_soc_of_parse_card_name);
  2470. static const struct snd_soc_dapm_widget simple_widgets[] = {
  2471. SND_SOC_DAPM_MIC("Microphone", NULL),
  2472. SND_SOC_DAPM_LINE("Line", NULL),
  2473. SND_SOC_DAPM_HP("Headphone", NULL),
  2474. SND_SOC_DAPM_SPK("Speaker", NULL),
  2475. };
  2476. int snd_soc_of_parse_audio_simple_widgets(struct snd_soc_card *card,
  2477. const char *propname)
  2478. {
  2479. struct device_node *np = card->dev->of_node;
  2480. struct snd_soc_dapm_widget *widgets;
  2481. const char *template, *wname;
  2482. int i, j, num_widgets;
  2483. num_widgets = of_property_count_strings(np, propname);
  2484. if (num_widgets < 0) {
  2485. dev_err(card->dev,
  2486. "ASoC: Property '%s' does not exist\n", propname);
  2487. return -EINVAL;
  2488. }
  2489. if (!num_widgets) {
  2490. dev_err(card->dev, "ASoC: Property '%s's length is zero\n",
  2491. propname);
  2492. return -EINVAL;
  2493. }
  2494. if (num_widgets & 1) {
  2495. dev_err(card->dev,
  2496. "ASoC: Property '%s' length is not even\n", propname);
  2497. return -EINVAL;
  2498. }
  2499. num_widgets /= 2;
  2500. widgets = devm_kcalloc(card->dev, num_widgets, sizeof(*widgets),
  2501. GFP_KERNEL);
  2502. if (!widgets) {
  2503. dev_err(card->dev,
  2504. "ASoC: Could not allocate memory for widgets\n");
  2505. return -ENOMEM;
  2506. }
  2507. for (i = 0; i < num_widgets; i++) {
  2508. int ret = of_property_read_string_index(np, propname,
  2509. 2 * i, &template);
  2510. if (ret) {
  2511. dev_err(card->dev,
  2512. "ASoC: Property '%s' index %d read error:%d\n",
  2513. propname, 2 * i, ret);
  2514. return -EINVAL;
  2515. }
  2516. for (j = 0; j < ARRAY_SIZE(simple_widgets); j++) {
  2517. if (!strncmp(template, simple_widgets[j].name,
  2518. strlen(simple_widgets[j].name))) {
  2519. widgets[i] = simple_widgets[j];
  2520. break;
  2521. }
  2522. }
  2523. if (j >= ARRAY_SIZE(simple_widgets)) {
  2524. dev_err(card->dev,
  2525. "ASoC: DAPM widget '%s' is not supported\n",
  2526. template);
  2527. return -EINVAL;
  2528. }
  2529. ret = of_property_read_string_index(np, propname,
  2530. (2 * i) + 1,
  2531. &wname);
  2532. if (ret) {
  2533. dev_err(card->dev,
  2534. "ASoC: Property '%s' index %d read error:%d\n",
  2535. propname, (2 * i) + 1, ret);
  2536. return -EINVAL;
  2537. }
  2538. widgets[i].name = wname;
  2539. }
  2540. card->of_dapm_widgets = widgets;
  2541. card->num_of_dapm_widgets = num_widgets;
  2542. return 0;
  2543. }
  2544. EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_simple_widgets);
  2545. int snd_soc_of_parse_pin_switches(struct snd_soc_card *card, const char *prop)
  2546. {
  2547. const unsigned int nb_controls_max = 16;
  2548. const char **strings, *control_name;
  2549. struct snd_kcontrol_new *controls;
  2550. struct device *dev = card->dev;
  2551. unsigned int i, nb_controls;
  2552. int ret;
  2553. if (!of_property_present(dev->of_node, prop))
  2554. return 0;
  2555. strings = devm_kcalloc(dev, nb_controls_max,
  2556. sizeof(*strings), GFP_KERNEL);
  2557. if (!strings)
  2558. return -ENOMEM;
  2559. ret = of_property_read_string_array(dev->of_node, prop,
  2560. strings, nb_controls_max);
  2561. if (ret < 0)
  2562. return ret;
  2563. nb_controls = (unsigned int)ret;
  2564. controls = devm_kcalloc(dev, nb_controls,
  2565. sizeof(*controls), GFP_KERNEL);
  2566. if (!controls)
  2567. return -ENOMEM;
  2568. for (i = 0; i < nb_controls; i++) {
  2569. control_name = devm_kasprintf(dev, GFP_KERNEL,
  2570. "%s Switch", strings[i]);
  2571. if (!control_name)
  2572. return -ENOMEM;
  2573. controls[i].iface = SNDRV_CTL_ELEM_IFACE_MIXER;
  2574. controls[i].name = control_name;
  2575. controls[i].info = snd_soc_dapm_info_pin_switch;
  2576. controls[i].get = snd_soc_dapm_get_pin_switch;
  2577. controls[i].put = snd_soc_dapm_put_pin_switch;
  2578. controls[i].private_value = (unsigned long)strings[i];
  2579. }
  2580. card->controls = controls;
  2581. card->num_controls = nb_controls;
  2582. return 0;
  2583. }
  2584. EXPORT_SYMBOL_GPL(snd_soc_of_parse_pin_switches);
  2585. int snd_soc_of_get_slot_mask(struct device_node *np,
  2586. const char *prop_name,
  2587. unsigned int *mask)
  2588. {
  2589. u32 val;
  2590. const __be32 *of_slot_mask = of_get_property(np, prop_name, &val);
  2591. int i;
  2592. if (!of_slot_mask)
  2593. return 0;
  2594. val /= sizeof(u32);
  2595. for (i = 0; i < val; i++)
  2596. if (be32_to_cpup(&of_slot_mask[i]))
  2597. *mask |= (1 << i);
  2598. return val;
  2599. }
  2600. EXPORT_SYMBOL_GPL(snd_soc_of_get_slot_mask);
  2601. int snd_soc_of_parse_tdm_slot(struct device_node *np,
  2602. unsigned int *tx_mask,
  2603. unsigned int *rx_mask,
  2604. unsigned int *slots,
  2605. unsigned int *slot_width)
  2606. {
  2607. u32 val;
  2608. int ret;
  2609. if (tx_mask)
  2610. snd_soc_of_get_slot_mask(np, "dai-tdm-slot-tx-mask", tx_mask);
  2611. if (rx_mask)
  2612. snd_soc_of_get_slot_mask(np, "dai-tdm-slot-rx-mask", rx_mask);
  2613. ret = of_property_read_u32(np, "dai-tdm-slot-num", &val);
  2614. if (ret && ret != -EINVAL)
  2615. return ret;
  2616. if (!ret && slots)
  2617. *slots = val;
  2618. ret = of_property_read_u32(np, "dai-tdm-slot-width", &val);
  2619. if (ret && ret != -EINVAL)
  2620. return ret;
  2621. if (!ret && slot_width)
  2622. *slot_width = val;
  2623. return 0;
  2624. }
  2625. EXPORT_SYMBOL_GPL(snd_soc_of_parse_tdm_slot);
  2626. void snd_soc_dlc_use_cpu_as_platform(struct snd_soc_dai_link_component *platforms,
  2627. struct snd_soc_dai_link_component *cpus)
  2628. {
  2629. platforms->of_node = cpus->of_node;
  2630. platforms->dai_args = cpus->dai_args;
  2631. }
  2632. EXPORT_SYMBOL_GPL(snd_soc_dlc_use_cpu_as_platform);
  2633. void snd_soc_of_parse_node_prefix(struct device_node *np,
  2634. struct snd_soc_codec_conf *codec_conf,
  2635. struct device_node *of_node,
  2636. const char *propname)
  2637. {
  2638. const char *str;
  2639. int ret;
  2640. ret = of_property_read_string(np, propname, &str);
  2641. if (ret < 0) {
  2642. /* no prefix is not error */
  2643. return;
  2644. }
  2645. codec_conf->dlc.of_node = of_node;
  2646. codec_conf->name_prefix = str;
  2647. }
  2648. EXPORT_SYMBOL_GPL(snd_soc_of_parse_node_prefix);
  2649. int snd_soc_of_parse_audio_routing(struct snd_soc_card *card,
  2650. const char *propname)
  2651. {
  2652. struct device_node *np = card->dev->of_node;
  2653. int num_routes;
  2654. struct snd_soc_dapm_route *routes;
  2655. int i;
  2656. num_routes = of_property_count_strings(np, propname);
  2657. if (num_routes < 0 || num_routes & 1) {
  2658. dev_err(card->dev,
  2659. "ASoC: Property '%s' does not exist or its length is not even\n",
  2660. propname);
  2661. return -EINVAL;
  2662. }
  2663. num_routes /= 2;
  2664. routes = devm_kcalloc(card->dev, num_routes, sizeof(*routes),
  2665. GFP_KERNEL);
  2666. if (!routes) {
  2667. dev_err(card->dev,
  2668. "ASoC: Could not allocate DAPM route table\n");
  2669. return -ENOMEM;
  2670. }
  2671. for (i = 0; i < num_routes; i++) {
  2672. int ret = of_property_read_string_index(np, propname,
  2673. 2 * i, &routes[i].sink);
  2674. if (ret) {
  2675. dev_err(card->dev,
  2676. "ASoC: Property '%s' index %d could not be read: %d\n",
  2677. propname, 2 * i, ret);
  2678. return -EINVAL;
  2679. }
  2680. ret = of_property_read_string_index(np, propname,
  2681. (2 * i) + 1, &routes[i].source);
  2682. if (ret) {
  2683. dev_err(card->dev,
  2684. "ASoC: Property '%s' index %d could not be read: %d\n",
  2685. propname, (2 * i) + 1, ret);
  2686. return -EINVAL;
  2687. }
  2688. }
  2689. card->num_of_dapm_routes = num_routes;
  2690. card->of_dapm_routes = routes;
  2691. return 0;
  2692. }
  2693. EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_routing);
  2694. int snd_soc_of_parse_aux_devs(struct snd_soc_card *card, const char *propname)
  2695. {
  2696. struct device_node *node = card->dev->of_node;
  2697. struct snd_soc_aux_dev *aux;
  2698. int num, i;
  2699. num = of_count_phandle_with_args(node, propname, NULL);
  2700. if (num == -ENOENT) {
  2701. return 0;
  2702. } else if (num < 0) {
  2703. dev_err(card->dev, "ASOC: Property '%s' could not be read: %d\n",
  2704. propname, num);
  2705. return num;
  2706. }
  2707. aux = devm_kcalloc(card->dev, num, sizeof(*aux), GFP_KERNEL);
  2708. if (!aux)
  2709. return -ENOMEM;
  2710. card->aux_dev = aux;
  2711. card->num_aux_devs = num;
  2712. for_each_card_pre_auxs(card, i, aux) {
  2713. aux->dlc.of_node = of_parse_phandle(node, propname, i);
  2714. if (!aux->dlc.of_node)
  2715. return -EINVAL;
  2716. }
  2717. return 0;
  2718. }
  2719. EXPORT_SYMBOL_GPL(snd_soc_of_parse_aux_devs);
  2720. unsigned int snd_soc_daifmt_clock_provider_flipped(unsigned int dai_fmt)
  2721. {
  2722. unsigned int inv_dai_fmt = dai_fmt & ~SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK;
  2723. switch (dai_fmt & SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK) {
  2724. case SND_SOC_DAIFMT_CBP_CFP:
  2725. inv_dai_fmt |= SND_SOC_DAIFMT_CBC_CFC;
  2726. break;
  2727. case SND_SOC_DAIFMT_CBP_CFC:
  2728. inv_dai_fmt |= SND_SOC_DAIFMT_CBC_CFP;
  2729. break;
  2730. case SND_SOC_DAIFMT_CBC_CFP:
  2731. inv_dai_fmt |= SND_SOC_DAIFMT_CBP_CFC;
  2732. break;
  2733. case SND_SOC_DAIFMT_CBC_CFC:
  2734. inv_dai_fmt |= SND_SOC_DAIFMT_CBP_CFP;
  2735. break;
  2736. }
  2737. return inv_dai_fmt;
  2738. }
  2739. EXPORT_SYMBOL_GPL(snd_soc_daifmt_clock_provider_flipped);
  2740. unsigned int snd_soc_daifmt_clock_provider_from_bitmap(unsigned int bit_frame)
  2741. {
  2742. /*
  2743. * bit_frame is return value from
  2744. * snd_soc_daifmt_parse_clock_provider_raw()
  2745. */
  2746. /* Codec base */
  2747. switch (bit_frame) {
  2748. case 0x11:
  2749. return SND_SOC_DAIFMT_CBP_CFP;
  2750. case 0x10:
  2751. return SND_SOC_DAIFMT_CBP_CFC;
  2752. case 0x01:
  2753. return SND_SOC_DAIFMT_CBC_CFP;
  2754. default:
  2755. return SND_SOC_DAIFMT_CBC_CFC;
  2756. }
  2757. return 0;
  2758. }
  2759. EXPORT_SYMBOL_GPL(snd_soc_daifmt_clock_provider_from_bitmap);
  2760. unsigned int snd_soc_daifmt_parse_format(struct device_node *np,
  2761. const char *prefix)
  2762. {
  2763. int ret;
  2764. char prop[128];
  2765. unsigned int format = 0;
  2766. int bit, frame;
  2767. const char *str;
  2768. struct {
  2769. char *name;
  2770. unsigned int val;
  2771. } of_fmt_table[] = {
  2772. { "i2s", SND_SOC_DAIFMT_I2S },
  2773. { "right_j", SND_SOC_DAIFMT_RIGHT_J },
  2774. { "left_j", SND_SOC_DAIFMT_LEFT_J },
  2775. { "dsp_a", SND_SOC_DAIFMT_DSP_A },
  2776. { "dsp_b", SND_SOC_DAIFMT_DSP_B },
  2777. { "ac97", SND_SOC_DAIFMT_AC97 },
  2778. { "pdm", SND_SOC_DAIFMT_PDM},
  2779. { "msb", SND_SOC_DAIFMT_MSB },
  2780. { "lsb", SND_SOC_DAIFMT_LSB },
  2781. };
  2782. if (!prefix)
  2783. prefix = "";
  2784. /*
  2785. * check "dai-format = xxx"
  2786. * or "[prefix]format = xxx"
  2787. * SND_SOC_DAIFMT_FORMAT_MASK area
  2788. */
  2789. ret = of_property_read_string(np, "dai-format", &str);
  2790. if (ret < 0) {
  2791. snprintf(prop, sizeof(prop), "%sformat", prefix);
  2792. ret = of_property_read_string(np, prop, &str);
  2793. }
  2794. if (ret == 0) {
  2795. int i;
  2796. for (i = 0; i < ARRAY_SIZE(of_fmt_table); i++) {
  2797. if (strcmp(str, of_fmt_table[i].name) == 0) {
  2798. format |= of_fmt_table[i].val;
  2799. break;
  2800. }
  2801. }
  2802. }
  2803. /*
  2804. * check "[prefix]continuous-clock"
  2805. * SND_SOC_DAIFMT_CLOCK_MASK area
  2806. */
  2807. snprintf(prop, sizeof(prop), "%scontinuous-clock", prefix);
  2808. if (of_property_read_bool(np, prop))
  2809. format |= SND_SOC_DAIFMT_CONT;
  2810. else
  2811. format |= SND_SOC_DAIFMT_GATED;
  2812. /*
  2813. * check "[prefix]bitclock-inversion"
  2814. * check "[prefix]frame-inversion"
  2815. * SND_SOC_DAIFMT_INV_MASK area
  2816. */
  2817. snprintf(prop, sizeof(prop), "%sbitclock-inversion", prefix);
  2818. bit = of_property_read_bool(np, prop);
  2819. snprintf(prop, sizeof(prop), "%sframe-inversion", prefix);
  2820. frame = of_property_read_bool(np, prop);
  2821. switch ((bit << 4) + frame) {
  2822. case 0x11:
  2823. format |= SND_SOC_DAIFMT_IB_IF;
  2824. break;
  2825. case 0x10:
  2826. format |= SND_SOC_DAIFMT_IB_NF;
  2827. break;
  2828. case 0x01:
  2829. format |= SND_SOC_DAIFMT_NB_IF;
  2830. break;
  2831. default:
  2832. /* SND_SOC_DAIFMT_NB_NF is default */
  2833. break;
  2834. }
  2835. return format;
  2836. }
  2837. EXPORT_SYMBOL_GPL(snd_soc_daifmt_parse_format);
  2838. unsigned int snd_soc_daifmt_parse_clock_provider_raw(struct device_node *np,
  2839. const char *prefix,
  2840. struct device_node **bitclkmaster,
  2841. struct device_node **framemaster)
  2842. {
  2843. char prop[128];
  2844. unsigned int bit, frame;
  2845. if (!prefix)
  2846. prefix = "";
  2847. /*
  2848. * check "[prefix]bitclock-master"
  2849. * check "[prefix]frame-master"
  2850. */
  2851. snprintf(prop, sizeof(prop), "%sbitclock-master", prefix);
  2852. bit = of_property_present(np, prop);
  2853. if (bit && bitclkmaster)
  2854. *bitclkmaster = of_parse_phandle(np, prop, 0);
  2855. snprintf(prop, sizeof(prop), "%sframe-master", prefix);
  2856. frame = of_property_present(np, prop);
  2857. if (frame && framemaster)
  2858. *framemaster = of_parse_phandle(np, prop, 0);
  2859. /*
  2860. * return bitmap.
  2861. * It will be parameter of
  2862. * snd_soc_daifmt_clock_provider_from_bitmap()
  2863. */
  2864. return (bit << 4) + frame;
  2865. }
  2866. EXPORT_SYMBOL_GPL(snd_soc_daifmt_parse_clock_provider_raw);
  2867. int snd_soc_get_stream_cpu(const struct snd_soc_dai_link *dai_link, int stream)
  2868. {
  2869. /*
  2870. * [Normal]
  2871. *
  2872. * Playback
  2873. * CPU : SNDRV_PCM_STREAM_PLAYBACK
  2874. * Codec: SNDRV_PCM_STREAM_PLAYBACK
  2875. *
  2876. * Capture
  2877. * CPU : SNDRV_PCM_STREAM_CAPTURE
  2878. * Codec: SNDRV_PCM_STREAM_CAPTURE
  2879. */
  2880. if (!dai_link->c2c_params)
  2881. return stream;
  2882. /*
  2883. * [Codec2Codec]
  2884. *
  2885. * Playback
  2886. * CPU : SNDRV_PCM_STREAM_CAPTURE
  2887. * Codec: SNDRV_PCM_STREAM_PLAYBACK
  2888. *
  2889. * Capture
  2890. * CPU : SNDRV_PCM_STREAM_PLAYBACK
  2891. * Codec: SNDRV_PCM_STREAM_CAPTURE
  2892. */
  2893. if (stream == SNDRV_PCM_STREAM_CAPTURE)
  2894. return SNDRV_PCM_STREAM_PLAYBACK;
  2895. return SNDRV_PCM_STREAM_CAPTURE;
  2896. }
  2897. EXPORT_SYMBOL_GPL(snd_soc_get_stream_cpu);
  2898. int snd_soc_get_dai_id(struct device_node *ep)
  2899. {
  2900. struct snd_soc_component *component;
  2901. struct snd_soc_dai_link_component dlc = {
  2902. .of_node = of_graph_get_port_parent(ep),
  2903. };
  2904. int ret;
  2905. /*
  2906. * For example HDMI case, HDMI has video/sound port,
  2907. * but ALSA SoC needs sound port number only.
  2908. * Thus counting HDMI DT port/endpoint doesn't work.
  2909. * Then, it should have .of_xlate_dai_id
  2910. */
  2911. ret = -ENOTSUPP;
  2912. mutex_lock(&client_mutex);
  2913. component = soc_find_component(&dlc);
  2914. if (component)
  2915. ret = snd_soc_component_of_xlate_dai_id(component, ep);
  2916. mutex_unlock(&client_mutex);
  2917. of_node_put(dlc.of_node);
  2918. return ret;
  2919. }
  2920. EXPORT_SYMBOL_GPL(snd_soc_get_dai_id);
  2921. int snd_soc_get_dlc(const struct of_phandle_args *args, struct snd_soc_dai_link_component *dlc)
  2922. {
  2923. struct snd_soc_component *pos;
  2924. int ret = -EPROBE_DEFER;
  2925. mutex_lock(&client_mutex);
  2926. for_each_component(pos) {
  2927. struct device_node *component_of_node = soc_component_to_node(pos);
  2928. if (component_of_node != args->np || !pos->num_dai)
  2929. continue;
  2930. ret = snd_soc_component_of_xlate_dai_name(pos, args, &dlc->dai_name);
  2931. if (ret == -ENOTSUPP) {
  2932. struct snd_soc_dai *dai;
  2933. int id = -1;
  2934. switch (args->args_count) {
  2935. case 0:
  2936. id = 0; /* same as dai_drv[0] */
  2937. break;
  2938. case 1:
  2939. id = args->args[0];
  2940. break;
  2941. default:
  2942. /* not supported */
  2943. break;
  2944. }
  2945. if (id < 0 || id >= pos->num_dai) {
  2946. ret = -EINVAL;
  2947. continue;
  2948. }
  2949. ret = 0;
  2950. /* find target DAI */
  2951. for_each_component_dais(pos, dai) {
  2952. if (id == 0)
  2953. break;
  2954. id--;
  2955. }
  2956. dlc->dai_name = snd_soc_dai_name_get(dai);
  2957. } else if (ret) {
  2958. /*
  2959. * if another error than ENOTSUPP is returned go on and
  2960. * check if another component is provided with the same
  2961. * node. This may happen if a device provides several
  2962. * components
  2963. */
  2964. continue;
  2965. }
  2966. break;
  2967. }
  2968. if (ret == 0)
  2969. dlc->of_node = args->np;
  2970. mutex_unlock(&client_mutex);
  2971. return ret;
  2972. }
  2973. EXPORT_SYMBOL_GPL(snd_soc_get_dlc);
  2974. int snd_soc_of_get_dlc(struct device_node *of_node,
  2975. struct of_phandle_args *args,
  2976. struct snd_soc_dai_link_component *dlc,
  2977. int index)
  2978. {
  2979. struct of_phandle_args __args;
  2980. int ret;
  2981. if (!args)
  2982. args = &__args;
  2983. ret = of_parse_phandle_with_args(of_node, "sound-dai",
  2984. "#sound-dai-cells", index, args);
  2985. if (ret)
  2986. return ret;
  2987. return snd_soc_get_dlc(args, dlc);
  2988. }
  2989. EXPORT_SYMBOL_GPL(snd_soc_of_get_dlc);
  2990. int snd_soc_get_dai_name(const struct of_phandle_args *args,
  2991. const char **dai_name)
  2992. {
  2993. struct snd_soc_dai_link_component dlc;
  2994. int ret = snd_soc_get_dlc(args, &dlc);
  2995. if (ret == 0)
  2996. *dai_name = dlc.dai_name;
  2997. return ret;
  2998. }
  2999. EXPORT_SYMBOL_GPL(snd_soc_get_dai_name);
  3000. int snd_soc_of_get_dai_name(struct device_node *of_node,
  3001. const char **dai_name, int index)
  3002. {
  3003. struct snd_soc_dai_link_component dlc;
  3004. int ret = snd_soc_of_get_dlc(of_node, NULL, &dlc, index);
  3005. if (ret == 0)
  3006. *dai_name = dlc.dai_name;
  3007. return ret;
  3008. }
  3009. EXPORT_SYMBOL_GPL(snd_soc_of_get_dai_name);
  3010. struct snd_soc_dai *snd_soc_get_dai_via_args(const struct of_phandle_args *dai_args)
  3011. {
  3012. struct snd_soc_dai *dai;
  3013. struct snd_soc_component *component;
  3014. mutex_lock(&client_mutex);
  3015. for_each_component(component) {
  3016. for_each_component_dais(component, dai)
  3017. if (snd_soc_is_match_dai_args(dai->driver->dai_args, dai_args))
  3018. goto found;
  3019. }
  3020. dai = NULL;
  3021. found:
  3022. mutex_unlock(&client_mutex);
  3023. return dai;
  3024. }
  3025. EXPORT_SYMBOL_GPL(snd_soc_get_dai_via_args);
  3026. static void __snd_soc_of_put_component(struct snd_soc_dai_link_component *component)
  3027. {
  3028. if (component->of_node) {
  3029. of_node_put(component->of_node);
  3030. component->of_node = NULL;
  3031. }
  3032. }
  3033. static int __snd_soc_of_get_dai_link_component_alloc(
  3034. struct device *dev, struct device_node *of_node,
  3035. struct snd_soc_dai_link_component **ret_component,
  3036. int *ret_num)
  3037. {
  3038. struct snd_soc_dai_link_component *component;
  3039. int num;
  3040. /* Count the number of CPUs/CODECs */
  3041. num = of_count_phandle_with_args(of_node, "sound-dai", "#sound-dai-cells");
  3042. if (num <= 0) {
  3043. if (num == -ENOENT)
  3044. dev_err(dev, "No 'sound-dai' property\n");
  3045. else
  3046. dev_err(dev, "Bad phandle in 'sound-dai'\n");
  3047. return num;
  3048. }
  3049. component = devm_kcalloc(dev, num, sizeof(*component), GFP_KERNEL);
  3050. if (!component)
  3051. return -ENOMEM;
  3052. *ret_component = component;
  3053. *ret_num = num;
  3054. return 0;
  3055. }
  3056. /*
  3057. * snd_soc_of_put_dai_link_codecs - Dereference device nodes in the codecs array
  3058. * @dai_link: DAI link
  3059. *
  3060. * Dereference device nodes acquired by snd_soc_of_get_dai_link_codecs().
  3061. */
  3062. void snd_soc_of_put_dai_link_codecs(struct snd_soc_dai_link *dai_link)
  3063. {
  3064. struct snd_soc_dai_link_component *component;
  3065. int index;
  3066. for_each_link_codecs(dai_link, index, component)
  3067. __snd_soc_of_put_component(component);
  3068. }
  3069. EXPORT_SYMBOL_GPL(snd_soc_of_put_dai_link_codecs);
  3070. /*
  3071. * snd_soc_of_get_dai_link_codecs - Parse a list of CODECs in the devicetree
  3072. * @dev: Card device
  3073. * @of_node: Device node
  3074. * @dai_link: DAI link
  3075. *
  3076. * Builds an array of CODEC DAI components from the DAI link property
  3077. * 'sound-dai'.
  3078. * The array is set in the DAI link and the number of DAIs is set accordingly.
  3079. * The device nodes in the array (of_node) must be dereferenced by calling
  3080. * snd_soc_of_put_dai_link_codecs() on @dai_link.
  3081. *
  3082. * Returns 0 for success
  3083. */
  3084. int snd_soc_of_get_dai_link_codecs(struct device *dev,
  3085. struct device_node *of_node,
  3086. struct snd_soc_dai_link *dai_link)
  3087. {
  3088. struct snd_soc_dai_link_component *component;
  3089. int index, ret;
  3090. ret = __snd_soc_of_get_dai_link_component_alloc(dev, of_node,
  3091. &dai_link->codecs, &dai_link->num_codecs);
  3092. if (ret < 0)
  3093. return ret;
  3094. /* Parse the list */
  3095. for_each_link_codecs(dai_link, index, component) {
  3096. ret = snd_soc_of_get_dlc(of_node, NULL, component, index);
  3097. if (ret)
  3098. goto err;
  3099. }
  3100. return 0;
  3101. err:
  3102. snd_soc_of_put_dai_link_codecs(dai_link);
  3103. dai_link->codecs = NULL;
  3104. dai_link->num_codecs = 0;
  3105. return ret;
  3106. }
  3107. EXPORT_SYMBOL_GPL(snd_soc_of_get_dai_link_codecs);
  3108. /*
  3109. * snd_soc_of_put_dai_link_cpus - Dereference device nodes in the codecs array
  3110. * @dai_link: DAI link
  3111. *
  3112. * Dereference device nodes acquired by snd_soc_of_get_dai_link_cpus().
  3113. */
  3114. void snd_soc_of_put_dai_link_cpus(struct snd_soc_dai_link *dai_link)
  3115. {
  3116. struct snd_soc_dai_link_component *component;
  3117. int index;
  3118. for_each_link_cpus(dai_link, index, component)
  3119. __snd_soc_of_put_component(component);
  3120. }
  3121. EXPORT_SYMBOL_GPL(snd_soc_of_put_dai_link_cpus);
  3122. /*
  3123. * snd_soc_of_get_dai_link_cpus - Parse a list of CPU DAIs in the devicetree
  3124. * @dev: Card device
  3125. * @of_node: Device node
  3126. * @dai_link: DAI link
  3127. *
  3128. * Is analogous to snd_soc_of_get_dai_link_codecs but parses a list of CPU DAIs
  3129. * instead.
  3130. *
  3131. * Returns 0 for success
  3132. */
  3133. int snd_soc_of_get_dai_link_cpus(struct device *dev,
  3134. struct device_node *of_node,
  3135. struct snd_soc_dai_link *dai_link)
  3136. {
  3137. struct snd_soc_dai_link_component *component;
  3138. int index, ret;
  3139. /* Count the number of CPUs */
  3140. ret = __snd_soc_of_get_dai_link_component_alloc(dev, of_node,
  3141. &dai_link->cpus, &dai_link->num_cpus);
  3142. if (ret < 0)
  3143. return ret;
  3144. /* Parse the list */
  3145. for_each_link_cpus(dai_link, index, component) {
  3146. ret = snd_soc_of_get_dlc(of_node, NULL, component, index);
  3147. if (ret)
  3148. goto err;
  3149. }
  3150. return 0;
  3151. err:
  3152. snd_soc_of_put_dai_link_cpus(dai_link);
  3153. dai_link->cpus = NULL;
  3154. dai_link->num_cpus = 0;
  3155. return ret;
  3156. }
  3157. EXPORT_SYMBOL_GPL(snd_soc_of_get_dai_link_cpus);
  3158. static int __init snd_soc_init(void)
  3159. {
  3160. int ret;
  3161. snd_soc_debugfs_init();
  3162. ret = snd_soc_util_init();
  3163. if (ret)
  3164. goto err_util_init;
  3165. ret = platform_driver_register(&soc_driver);
  3166. if (ret)
  3167. goto err_register;
  3168. return 0;
  3169. err_register:
  3170. snd_soc_util_exit();
  3171. err_util_init:
  3172. snd_soc_debugfs_exit();
  3173. return ret;
  3174. }
  3175. module_init(snd_soc_init);
  3176. static void __exit snd_soc_exit(void)
  3177. {
  3178. snd_soc_util_exit();
  3179. snd_soc_debugfs_exit();
  3180. platform_driver_unregister(&soc_driver);
  3181. }
  3182. module_exit(snd_soc_exit);
  3183. /* Module information */
  3184. MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
  3185. MODULE_DESCRIPTION("ALSA SoC Core");
  3186. MODULE_LICENSE("GPL");
  3187. MODULE_ALIAS("platform:soc-audio");