soc-core.c 93 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805
  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. lockdep_assert_held(&client_mutex);
  933. /*
  934. * Notify the machine driver for extra destruction
  935. */
  936. snd_soc_card_remove_dai_link(card, rtd->dai_link);
  937. soc_free_pcm_runtime(rtd);
  938. }
  939. EXPORT_SYMBOL_GPL(snd_soc_remove_pcm_runtime);
  940. /**
  941. * snd_soc_add_pcm_runtime - Add a pcm_runtime dynamically via dai_link
  942. * @card: The ASoC card to which the pcm_runtime is added
  943. * @dai_link: The DAI link to find pcm_runtime
  944. *
  945. * This function adds a pcm_runtime ASoC card by using dai_link.
  946. *
  947. * Note: Topology can use this API to add pcm_runtime when probing the
  948. * topology component. And machine drivers can still define static
  949. * DAI links in dai_link array.
  950. */
  951. static int snd_soc_add_pcm_runtime(struct snd_soc_card *card,
  952. struct snd_soc_dai_link *dai_link)
  953. {
  954. struct snd_soc_pcm_runtime *rtd;
  955. struct snd_soc_dai_link_component *codec, *platform, *cpu;
  956. struct snd_soc_component *component;
  957. int i, ret;
  958. lockdep_assert_held(&client_mutex);
  959. /*
  960. * Notify the machine driver for extra initialization
  961. */
  962. ret = snd_soc_card_add_dai_link(card, dai_link);
  963. if (ret < 0)
  964. return ret;
  965. if (dai_link->ignore)
  966. return 0;
  967. dev_dbg(card->dev, "ASoC: binding %s\n", dai_link->name);
  968. ret = soc_dai_link_sanity_check(card, dai_link);
  969. if (ret < 0)
  970. return ret;
  971. rtd = soc_new_pcm_runtime(card, dai_link);
  972. if (!rtd)
  973. return -ENOMEM;
  974. for_each_link_cpus(dai_link, i, cpu) {
  975. snd_soc_rtd_to_cpu(rtd, i) = snd_soc_find_dai(cpu);
  976. if (!snd_soc_rtd_to_cpu(rtd, i)) {
  977. dev_info(card->dev, "ASoC: CPU DAI %s not registered\n",
  978. cpu->dai_name);
  979. goto _err_defer;
  980. }
  981. snd_soc_rtd_add_component(rtd, snd_soc_rtd_to_cpu(rtd, i)->component);
  982. }
  983. /* Find CODEC from registered CODECs */
  984. for_each_link_codecs(dai_link, i, codec) {
  985. snd_soc_rtd_to_codec(rtd, i) = snd_soc_find_dai(codec);
  986. if (!snd_soc_rtd_to_codec(rtd, i)) {
  987. dev_info(card->dev, "ASoC: CODEC DAI %s not registered\n",
  988. codec->dai_name);
  989. goto _err_defer;
  990. }
  991. snd_soc_rtd_add_component(rtd, snd_soc_rtd_to_codec(rtd, i)->component);
  992. }
  993. /* Find PLATFORM from registered PLATFORMs */
  994. for_each_link_platforms(dai_link, i, platform) {
  995. for_each_component(component) {
  996. if (!snd_soc_is_matching_component(platform, component))
  997. continue;
  998. if (snd_soc_component_is_dummy(component) && component->num_dai)
  999. continue;
  1000. snd_soc_rtd_add_component(rtd, component);
  1001. }
  1002. }
  1003. return 0;
  1004. _err_defer:
  1005. snd_soc_remove_pcm_runtime(card, rtd);
  1006. return -EPROBE_DEFER;
  1007. }
  1008. int snd_soc_add_pcm_runtimes(struct snd_soc_card *card,
  1009. struct snd_soc_dai_link *dai_link,
  1010. int num_dai_link)
  1011. {
  1012. for (int i = 0; i < num_dai_link; i++) {
  1013. int ret;
  1014. ret = snd_soc_compensate_channel_connection_map(card, dai_link + i);
  1015. if (ret < 0)
  1016. return ret;
  1017. ret = snd_soc_add_pcm_runtime(card, dai_link + i);
  1018. if (ret < 0)
  1019. return ret;
  1020. }
  1021. return 0;
  1022. }
  1023. EXPORT_SYMBOL_GPL(snd_soc_add_pcm_runtimes);
  1024. static void snd_soc_runtime_get_dai_fmt(struct snd_soc_pcm_runtime *rtd)
  1025. {
  1026. struct snd_soc_dai_link *dai_link = rtd->dai_link;
  1027. struct snd_soc_dai *dai, *not_used;
  1028. u64 pos, possible_fmt;
  1029. unsigned int mask = 0, dai_fmt = 0;
  1030. int i, j, priority, pri, until;
  1031. /*
  1032. * Get selectable format from each DAIs.
  1033. *
  1034. ****************************
  1035. * NOTE
  1036. * Using .auto_selectable_formats is not mandatory,
  1037. * we can select format manually from Sound Card.
  1038. * When use it, driver should list well tested format only.
  1039. ****************************
  1040. *
  1041. * ex)
  1042. * auto_selectable_formats (= SND_SOC_POSSIBLE_xxx)
  1043. * (A) (B) (C)
  1044. * DAI0_: { 0x000F, 0x00F0, 0x0F00 };
  1045. * DAI1 : { 0xF000, 0x0F00 };
  1046. * (X) (Y)
  1047. *
  1048. * "until" will be 3 in this case (MAX array size from DAI0 and DAI1)
  1049. * Here is dev_dbg() message and comments
  1050. *
  1051. * priority = 1
  1052. * DAI0: (pri, fmt) = (1, 000000000000000F) // 1st check (A) DAI1 is not selected
  1053. * DAI1: (pri, fmt) = (0, 0000000000000000) // Necessary Waste
  1054. * DAI0: (pri, fmt) = (1, 000000000000000F) // 2nd check (A)
  1055. * DAI1: (pri, fmt) = (1, 000000000000F000) // (X)
  1056. * priority = 2
  1057. * DAI0: (pri, fmt) = (2, 00000000000000FF) // 3rd check (A) + (B)
  1058. * DAI1: (pri, fmt) = (1, 000000000000F000) // (X)
  1059. * DAI0: (pri, fmt) = (2, 00000000000000FF) // 4th check (A) + (B)
  1060. * DAI1: (pri, fmt) = (2, 000000000000FF00) // (X) + (Y)
  1061. * priority = 3
  1062. * DAI0: (pri, fmt) = (3, 0000000000000FFF) // 5th check (A) + (B) + (C)
  1063. * DAI1: (pri, fmt) = (2, 000000000000FF00) // (X) + (Y)
  1064. * found auto selected format: 0000000000000F00
  1065. */
  1066. until = snd_soc_dai_get_fmt_max_priority(rtd);
  1067. for (priority = 1; priority <= until; priority++) {
  1068. for_each_rtd_dais(rtd, j, not_used) {
  1069. possible_fmt = ULLONG_MAX;
  1070. for_each_rtd_dais(rtd, i, dai) {
  1071. u64 fmt = 0;
  1072. pri = (j >= i) ? priority : priority - 1;
  1073. fmt = snd_soc_dai_get_fmt(dai, pri);
  1074. possible_fmt &= fmt;
  1075. }
  1076. if (possible_fmt)
  1077. goto found;
  1078. }
  1079. }
  1080. /* Not Found */
  1081. return;
  1082. found:
  1083. /*
  1084. * convert POSSIBLE_DAIFMT to DAIFMT
  1085. *
  1086. * Some basic/default settings on each is defined as 0.
  1087. * see
  1088. * SND_SOC_DAIFMT_NB_NF
  1089. * SND_SOC_DAIFMT_GATED
  1090. *
  1091. * SND_SOC_DAIFMT_xxx_MASK can't notice it if Sound Card specify
  1092. * these value, and will be overwrite to auto selected value.
  1093. *
  1094. * To avoid such issue, loop from 63 to 0 here.
  1095. * Small number of SND_SOC_POSSIBLE_xxx will be Hi priority.
  1096. * Basic/Default settings of each part and above are defined
  1097. * as Hi priority (= small number) of SND_SOC_POSSIBLE_xxx.
  1098. */
  1099. for (i = 63; i >= 0; i--) {
  1100. pos = 1ULL << i;
  1101. switch (possible_fmt & pos) {
  1102. /*
  1103. * for format
  1104. */
  1105. case SND_SOC_POSSIBLE_DAIFMT_I2S:
  1106. case SND_SOC_POSSIBLE_DAIFMT_RIGHT_J:
  1107. case SND_SOC_POSSIBLE_DAIFMT_LEFT_J:
  1108. case SND_SOC_POSSIBLE_DAIFMT_DSP_A:
  1109. case SND_SOC_POSSIBLE_DAIFMT_DSP_B:
  1110. case SND_SOC_POSSIBLE_DAIFMT_AC97:
  1111. case SND_SOC_POSSIBLE_DAIFMT_PDM:
  1112. dai_fmt = (dai_fmt & ~SND_SOC_DAIFMT_FORMAT_MASK) | i;
  1113. break;
  1114. /*
  1115. * for clock
  1116. */
  1117. case SND_SOC_POSSIBLE_DAIFMT_CONT:
  1118. dai_fmt = (dai_fmt & ~SND_SOC_DAIFMT_CLOCK_MASK) | SND_SOC_DAIFMT_CONT;
  1119. break;
  1120. case SND_SOC_POSSIBLE_DAIFMT_GATED:
  1121. dai_fmt = (dai_fmt & ~SND_SOC_DAIFMT_CLOCK_MASK) | SND_SOC_DAIFMT_GATED;
  1122. break;
  1123. /*
  1124. * for clock invert
  1125. */
  1126. case SND_SOC_POSSIBLE_DAIFMT_NB_NF:
  1127. dai_fmt = (dai_fmt & ~SND_SOC_DAIFMT_INV_MASK) | SND_SOC_DAIFMT_NB_NF;
  1128. break;
  1129. case SND_SOC_POSSIBLE_DAIFMT_NB_IF:
  1130. dai_fmt = (dai_fmt & ~SND_SOC_DAIFMT_INV_MASK) | SND_SOC_DAIFMT_NB_IF;
  1131. break;
  1132. case SND_SOC_POSSIBLE_DAIFMT_IB_NF:
  1133. dai_fmt = (dai_fmt & ~SND_SOC_DAIFMT_INV_MASK) | SND_SOC_DAIFMT_IB_NF;
  1134. break;
  1135. case SND_SOC_POSSIBLE_DAIFMT_IB_IF:
  1136. dai_fmt = (dai_fmt & ~SND_SOC_DAIFMT_INV_MASK) | SND_SOC_DAIFMT_IB_IF;
  1137. break;
  1138. /*
  1139. * for clock provider / consumer
  1140. */
  1141. case SND_SOC_POSSIBLE_DAIFMT_CBP_CFP:
  1142. dai_fmt = (dai_fmt & ~SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK) | SND_SOC_DAIFMT_CBP_CFP;
  1143. break;
  1144. case SND_SOC_POSSIBLE_DAIFMT_CBC_CFP:
  1145. dai_fmt = (dai_fmt & ~SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK) | SND_SOC_DAIFMT_CBC_CFP;
  1146. break;
  1147. case SND_SOC_POSSIBLE_DAIFMT_CBP_CFC:
  1148. dai_fmt = (dai_fmt & ~SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK) | SND_SOC_DAIFMT_CBP_CFC;
  1149. break;
  1150. case SND_SOC_POSSIBLE_DAIFMT_CBC_CFC:
  1151. dai_fmt = (dai_fmt & ~SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK) | SND_SOC_DAIFMT_CBC_CFC;
  1152. break;
  1153. }
  1154. }
  1155. /*
  1156. * Some driver might have very complex limitation.
  1157. * In such case, user want to auto-select non-limitation part,
  1158. * and want to manually specify complex part.
  1159. *
  1160. * Or for example, if both CPU and Codec can be clock provider,
  1161. * but because of its quality, user want to specify it manually.
  1162. *
  1163. * Use manually specified settings if sound card did.
  1164. */
  1165. if (!(dai_link->dai_fmt & SND_SOC_DAIFMT_FORMAT_MASK))
  1166. mask |= SND_SOC_DAIFMT_FORMAT_MASK;
  1167. if (!(dai_link->dai_fmt & SND_SOC_DAIFMT_CLOCK_MASK))
  1168. mask |= SND_SOC_DAIFMT_CLOCK_MASK;
  1169. if (!(dai_link->dai_fmt & SND_SOC_DAIFMT_INV_MASK))
  1170. mask |= SND_SOC_DAIFMT_INV_MASK;
  1171. if (!(dai_link->dai_fmt & SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK))
  1172. mask |= SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK;
  1173. dai_link->dai_fmt |= (dai_fmt & mask);
  1174. }
  1175. /**
  1176. * snd_soc_runtime_set_dai_fmt() - Change DAI link format for a ASoC runtime
  1177. * @rtd: The runtime for which the DAI link format should be changed
  1178. * @dai_fmt: The new DAI link format
  1179. *
  1180. * This function updates the DAI link format for all DAIs connected to the DAI
  1181. * link for the specified runtime.
  1182. *
  1183. * Note: For setups with a static format set the dai_fmt field in the
  1184. * corresponding snd_dai_link struct instead of using this function.
  1185. *
  1186. * Returns 0 on success, otherwise a negative error code.
  1187. */
  1188. int snd_soc_runtime_set_dai_fmt(struct snd_soc_pcm_runtime *rtd,
  1189. unsigned int dai_fmt)
  1190. {
  1191. struct snd_soc_dai *cpu_dai;
  1192. struct snd_soc_dai *codec_dai;
  1193. unsigned int i;
  1194. int ret;
  1195. if (!dai_fmt)
  1196. return 0;
  1197. for_each_rtd_codec_dais(rtd, i, codec_dai) {
  1198. ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt);
  1199. if (ret != 0 && ret != -ENOTSUPP)
  1200. return ret;
  1201. }
  1202. /* Flip the polarity for the "CPU" end of link */
  1203. dai_fmt = snd_soc_daifmt_clock_provider_flipped(dai_fmt);
  1204. for_each_rtd_cpu_dais(rtd, i, cpu_dai) {
  1205. ret = snd_soc_dai_set_fmt(cpu_dai, dai_fmt);
  1206. if (ret != 0 && ret != -ENOTSUPP)
  1207. return ret;
  1208. }
  1209. return 0;
  1210. }
  1211. EXPORT_SYMBOL_GPL(snd_soc_runtime_set_dai_fmt);
  1212. static int soc_init_pcm_runtime(struct snd_soc_card *card,
  1213. struct snd_soc_pcm_runtime *rtd)
  1214. {
  1215. struct snd_soc_dai_link *dai_link = rtd->dai_link;
  1216. struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
  1217. struct snd_soc_component *component;
  1218. int ret, num, i;
  1219. /* do machine specific initialization */
  1220. ret = snd_soc_link_init(rtd);
  1221. if (ret < 0)
  1222. return ret;
  1223. snd_soc_runtime_get_dai_fmt(rtd);
  1224. ret = snd_soc_runtime_set_dai_fmt(rtd, dai_link->dai_fmt);
  1225. if (ret)
  1226. goto err;
  1227. /* add DPCM sysfs entries */
  1228. soc_dpcm_debugfs_add(rtd);
  1229. num = rtd->num;
  1230. /*
  1231. * most drivers will register their PCMs using DAI link ordering but
  1232. * topology based drivers can use the DAI link id field to set PCM
  1233. * device number and then use rtd + a base offset of the BEs.
  1234. */
  1235. for_each_rtd_components(rtd, i, component) {
  1236. if (!component->driver->use_dai_pcm_id)
  1237. continue;
  1238. if (rtd->dai_link->no_pcm)
  1239. num += component->driver->be_pcm_base;
  1240. else
  1241. num = rtd->dai_link->id;
  1242. }
  1243. /* create compress_device if possible */
  1244. ret = snd_soc_dai_compress_new(cpu_dai, rtd, num);
  1245. if (ret != -ENOTSUPP)
  1246. goto err;
  1247. /* create the pcm */
  1248. ret = soc_new_pcm(rtd, num);
  1249. if (ret < 0) {
  1250. dev_err(card->dev, "ASoC: can't create pcm %s :%d\n",
  1251. dai_link->stream_name, ret);
  1252. goto err;
  1253. }
  1254. ret = snd_soc_pcm_dai_new(rtd);
  1255. if (ret < 0)
  1256. goto err;
  1257. rtd->initialized = true;
  1258. return 0;
  1259. err:
  1260. snd_soc_link_exit(rtd);
  1261. return ret;
  1262. }
  1263. static void soc_set_name_prefix(struct snd_soc_card *card,
  1264. struct snd_soc_component *component)
  1265. {
  1266. struct device_node *of_node = soc_component_to_node(component);
  1267. const char *str;
  1268. int ret, i;
  1269. for (i = 0; i < card->num_configs; i++) {
  1270. struct snd_soc_codec_conf *map = &card->codec_conf[i];
  1271. if (snd_soc_is_matching_component(&map->dlc, component) &&
  1272. map->name_prefix) {
  1273. component->name_prefix = map->name_prefix;
  1274. return;
  1275. }
  1276. }
  1277. /*
  1278. * If there is no configuration table or no match in the table,
  1279. * check if a prefix is provided in the node
  1280. */
  1281. ret = of_property_read_string(of_node, "sound-name-prefix", &str);
  1282. if (ret < 0)
  1283. return;
  1284. component->name_prefix = str;
  1285. }
  1286. static void soc_remove_component(struct snd_soc_component *component,
  1287. int probed)
  1288. {
  1289. if (!component->card)
  1290. return;
  1291. if (probed)
  1292. snd_soc_component_remove(component);
  1293. list_del_init(&component->card_list);
  1294. snd_soc_dapm_free(snd_soc_component_get_dapm(component));
  1295. soc_cleanup_component_debugfs(component);
  1296. component->card = NULL;
  1297. snd_soc_component_module_put_when_remove(component);
  1298. }
  1299. static int soc_probe_component(struct snd_soc_card *card,
  1300. struct snd_soc_component *component)
  1301. {
  1302. struct snd_soc_dapm_context *dapm =
  1303. snd_soc_component_get_dapm(component);
  1304. struct snd_soc_dai *dai;
  1305. int probed = 0;
  1306. int ret;
  1307. if (snd_soc_component_is_dummy(component))
  1308. return 0;
  1309. if (component->card) {
  1310. if (component->card != card) {
  1311. dev_err(component->dev,
  1312. "Trying to bind component \"%s\" to card \"%s\" but is already bound to card \"%s\"\n",
  1313. component->name, card->name, component->card->name);
  1314. return -ENODEV;
  1315. }
  1316. return 0;
  1317. }
  1318. ret = snd_soc_component_module_get_when_probe(component);
  1319. if (ret < 0)
  1320. return ret;
  1321. component->card = card;
  1322. soc_set_name_prefix(card, component);
  1323. soc_init_component_debugfs(component);
  1324. snd_soc_dapm_init(dapm, card, component);
  1325. ret = snd_soc_dapm_new_controls(dapm,
  1326. component->driver->dapm_widgets,
  1327. component->driver->num_dapm_widgets);
  1328. if (ret != 0) {
  1329. dev_err(component->dev,
  1330. "Failed to create new controls %d\n", ret);
  1331. goto err_probe;
  1332. }
  1333. for_each_component_dais(component, dai) {
  1334. ret = snd_soc_dapm_new_dai_widgets(dapm, dai);
  1335. if (ret != 0) {
  1336. dev_err(component->dev,
  1337. "Failed to create DAI widgets %d\n", ret);
  1338. goto err_probe;
  1339. }
  1340. }
  1341. ret = snd_soc_component_probe(component);
  1342. if (ret < 0)
  1343. goto err_probe;
  1344. WARN(dapm->idle_bias_off &&
  1345. dapm->bias_level != SND_SOC_BIAS_OFF,
  1346. "codec %s can not start from non-off bias with idle_bias_off==1\n",
  1347. component->name);
  1348. probed = 1;
  1349. /*
  1350. * machine specific init
  1351. * see
  1352. * snd_soc_component_set_aux()
  1353. */
  1354. ret = snd_soc_component_init(component);
  1355. if (ret < 0)
  1356. goto err_probe;
  1357. ret = snd_soc_add_component_controls(component,
  1358. component->driver->controls,
  1359. component->driver->num_controls);
  1360. if (ret < 0)
  1361. goto err_probe;
  1362. ret = snd_soc_dapm_add_routes(dapm,
  1363. component->driver->dapm_routes,
  1364. component->driver->num_dapm_routes);
  1365. if (ret < 0) {
  1366. if (card->disable_route_checks) {
  1367. dev_info(card->dev,
  1368. "%s: disable_route_checks set, ignoring errors on add_routes\n",
  1369. __func__);
  1370. } else {
  1371. dev_err(card->dev,
  1372. "%s: snd_soc_dapm_add_routes failed: %d\n",
  1373. __func__, ret);
  1374. goto err_probe;
  1375. }
  1376. }
  1377. /* see for_each_card_components */
  1378. list_add(&component->card_list, &card->component_dev_list);
  1379. err_probe:
  1380. if (ret < 0)
  1381. soc_remove_component(component, probed);
  1382. return ret;
  1383. }
  1384. static void soc_remove_link_dais(struct snd_soc_card *card)
  1385. {
  1386. struct snd_soc_pcm_runtime *rtd;
  1387. int order;
  1388. for_each_comp_order(order) {
  1389. for_each_card_rtds(card, rtd) {
  1390. /* remove all rtd connected DAIs in good order */
  1391. snd_soc_pcm_dai_remove(rtd, order);
  1392. }
  1393. }
  1394. }
  1395. static int soc_probe_link_dais(struct snd_soc_card *card)
  1396. {
  1397. struct snd_soc_pcm_runtime *rtd;
  1398. int order, ret;
  1399. for_each_comp_order(order) {
  1400. for_each_card_rtds(card, rtd) {
  1401. /* probe all rtd connected DAIs in good order */
  1402. ret = snd_soc_pcm_dai_probe(rtd, order);
  1403. if (ret)
  1404. return ret;
  1405. }
  1406. }
  1407. return 0;
  1408. }
  1409. static void soc_remove_link_components(struct snd_soc_card *card)
  1410. {
  1411. struct snd_soc_component *component;
  1412. struct snd_soc_pcm_runtime *rtd;
  1413. int i, order;
  1414. for_each_comp_order(order) {
  1415. for_each_card_rtds(card, rtd) {
  1416. for_each_rtd_components(rtd, i, component) {
  1417. if (component->driver->remove_order != order)
  1418. continue;
  1419. soc_remove_component(component, 1);
  1420. }
  1421. }
  1422. }
  1423. }
  1424. static int soc_probe_link_components(struct snd_soc_card *card)
  1425. {
  1426. struct snd_soc_component *component;
  1427. struct snd_soc_pcm_runtime *rtd;
  1428. int i, ret, order;
  1429. for_each_comp_order(order) {
  1430. for_each_card_rtds(card, rtd) {
  1431. for_each_rtd_components(rtd, i, component) {
  1432. if (component->driver->probe_order != order)
  1433. continue;
  1434. ret = soc_probe_component(card, component);
  1435. if (ret < 0)
  1436. return ret;
  1437. }
  1438. }
  1439. }
  1440. return 0;
  1441. }
  1442. static void soc_unbind_aux_dev(struct snd_soc_card *card)
  1443. {
  1444. struct snd_soc_component *component, *_component;
  1445. for_each_card_auxs_safe(card, component, _component) {
  1446. /* for snd_soc_component_init() */
  1447. snd_soc_component_set_aux(component, NULL);
  1448. list_del(&component->card_aux_list);
  1449. }
  1450. }
  1451. static int soc_bind_aux_dev(struct snd_soc_card *card)
  1452. {
  1453. struct snd_soc_component *component;
  1454. struct snd_soc_aux_dev *aux;
  1455. int i;
  1456. for_each_card_pre_auxs(card, i, aux) {
  1457. /* codecs, usually analog devices */
  1458. component = soc_find_component(&aux->dlc);
  1459. if (!component)
  1460. return -EPROBE_DEFER;
  1461. /* for snd_soc_component_init() */
  1462. snd_soc_component_set_aux(component, aux);
  1463. /* see for_each_card_auxs */
  1464. list_add(&component->card_aux_list, &card->aux_comp_list);
  1465. }
  1466. return 0;
  1467. }
  1468. static int soc_probe_aux_devices(struct snd_soc_card *card)
  1469. {
  1470. struct snd_soc_component *component;
  1471. int order;
  1472. int ret;
  1473. for_each_comp_order(order) {
  1474. for_each_card_auxs(card, component) {
  1475. if (component->driver->probe_order != order)
  1476. continue;
  1477. ret = soc_probe_component(card, component);
  1478. if (ret < 0)
  1479. return ret;
  1480. }
  1481. }
  1482. return 0;
  1483. }
  1484. static void soc_remove_aux_devices(struct snd_soc_card *card)
  1485. {
  1486. struct snd_soc_component *comp, *_comp;
  1487. int order;
  1488. for_each_comp_order(order) {
  1489. for_each_card_auxs_safe(card, comp, _comp) {
  1490. if (comp->driver->remove_order == order)
  1491. soc_remove_component(comp, 1);
  1492. }
  1493. }
  1494. }
  1495. #ifdef CONFIG_DMI
  1496. /*
  1497. * If a DMI filed contain strings in this blacklist (e.g.
  1498. * "Type2 - Board Manufacturer" or "Type1 - TBD by OEM"), it will be taken
  1499. * as invalid and dropped when setting the card long name from DMI info.
  1500. */
  1501. static const char * const dmi_blacklist[] = {
  1502. "To be filled by OEM",
  1503. "TBD by OEM",
  1504. "Default String",
  1505. "Board Manufacturer",
  1506. "Board Vendor Name",
  1507. "Board Product Name",
  1508. NULL, /* terminator */
  1509. };
  1510. /*
  1511. * Trim special characters, and replace '-' with '_' since '-' is used to
  1512. * separate different DMI fields in the card long name. Only number and
  1513. * alphabet characters and a few separator characters are kept.
  1514. */
  1515. static void cleanup_dmi_name(char *name)
  1516. {
  1517. int i, j = 0;
  1518. for (i = 0; name[i]; i++) {
  1519. if (isalnum(name[i]) || (name[i] == '.')
  1520. || (name[i] == '_'))
  1521. name[j++] = name[i];
  1522. else if (name[i] == '-')
  1523. name[j++] = '_';
  1524. }
  1525. name[j] = '\0';
  1526. }
  1527. /*
  1528. * Check if a DMI field is valid, i.e. not containing any string
  1529. * in the black list.
  1530. */
  1531. static int is_dmi_valid(const char *field)
  1532. {
  1533. int i = 0;
  1534. while (dmi_blacklist[i]) {
  1535. if (strstr(field, dmi_blacklist[i]))
  1536. return 0;
  1537. i++;
  1538. }
  1539. return 1;
  1540. }
  1541. /*
  1542. * Append a string to card->dmi_longname with character cleanups.
  1543. */
  1544. static void append_dmi_string(struct snd_soc_card *card, const char *str)
  1545. {
  1546. char *dst = card->dmi_longname;
  1547. size_t dst_len = sizeof(card->dmi_longname);
  1548. size_t len;
  1549. len = strlen(dst);
  1550. snprintf(dst + len, dst_len - len, "-%s", str);
  1551. len++; /* skip the separator "-" */
  1552. if (len < dst_len)
  1553. cleanup_dmi_name(dst + len);
  1554. }
  1555. /**
  1556. * snd_soc_set_dmi_name() - Register DMI names to card
  1557. * @card: The card to register DMI names
  1558. * @flavour: The flavour "differentiator" for the card amongst its peers.
  1559. *
  1560. * An Intel machine driver may be used by many different devices but are
  1561. * difficult for userspace to differentiate, since machine drivers usually
  1562. * use their own name as the card short name and leave the card long name
  1563. * blank. To differentiate such devices and fix bugs due to lack of
  1564. * device-specific configurations, this function allows DMI info to be used
  1565. * as the sound card long name, in the format of
  1566. * "vendor-product-version-board"
  1567. * (Character '-' is used to separate different DMI fields here).
  1568. * This will help the user space to load the device-specific Use Case Manager
  1569. * (UCM) configurations for the card.
  1570. *
  1571. * Possible card long names may be:
  1572. * DellInc.-XPS139343-01-0310JH
  1573. * ASUSTeKCOMPUTERINC.-T100TA-1.0-T100TA
  1574. * Circuitco-MinnowboardMaxD0PLATFORM-D0-MinnowBoardMAX
  1575. *
  1576. * This function also supports flavoring the card longname to provide
  1577. * the extra differentiation, like "vendor-product-version-board-flavor".
  1578. *
  1579. * We only keep number and alphabet characters and a few separator characters
  1580. * in the card long name since UCM in the user space uses the card long names
  1581. * as card configuration directory names and AudoConf cannot support special
  1582. * characters like SPACE.
  1583. *
  1584. * Returns 0 on success, otherwise a negative error code.
  1585. */
  1586. int snd_soc_set_dmi_name(struct snd_soc_card *card, const char *flavour)
  1587. {
  1588. const char *vendor, *product, *board;
  1589. if (card->long_name)
  1590. return 0; /* long name already set by driver or from DMI */
  1591. if (!dmi_available)
  1592. return 0;
  1593. /* make up dmi long name as: vendor-product-version-board */
  1594. vendor = dmi_get_system_info(DMI_BOARD_VENDOR);
  1595. if (!vendor || !is_dmi_valid(vendor)) {
  1596. dev_warn(card->dev, "ASoC: no DMI vendor name!\n");
  1597. return 0;
  1598. }
  1599. snprintf(card->dmi_longname, sizeof(card->dmi_longname), "%s", vendor);
  1600. cleanup_dmi_name(card->dmi_longname);
  1601. product = dmi_get_system_info(DMI_PRODUCT_NAME);
  1602. if (product && is_dmi_valid(product)) {
  1603. const char *product_version = dmi_get_system_info(DMI_PRODUCT_VERSION);
  1604. append_dmi_string(card, product);
  1605. /*
  1606. * some vendors like Lenovo may only put a self-explanatory
  1607. * name in the product version field
  1608. */
  1609. if (product_version && is_dmi_valid(product_version))
  1610. append_dmi_string(card, product_version);
  1611. }
  1612. board = dmi_get_system_info(DMI_BOARD_NAME);
  1613. if (board && is_dmi_valid(board)) {
  1614. if (!product || strcasecmp(board, product))
  1615. append_dmi_string(card, board);
  1616. } else if (!product) {
  1617. /* fall back to using legacy name */
  1618. dev_warn(card->dev, "ASoC: no DMI board/product name!\n");
  1619. return 0;
  1620. }
  1621. /* Add flavour to dmi long name */
  1622. if (flavour)
  1623. append_dmi_string(card, flavour);
  1624. /* set the card long name */
  1625. card->long_name = card->dmi_longname;
  1626. return 0;
  1627. }
  1628. EXPORT_SYMBOL_GPL(snd_soc_set_dmi_name);
  1629. #endif /* CONFIG_DMI */
  1630. static void soc_check_tplg_fes(struct snd_soc_card *card)
  1631. {
  1632. struct snd_soc_component *component;
  1633. const struct snd_soc_component_driver *comp_drv;
  1634. struct snd_soc_dai_link *dai_link;
  1635. int i;
  1636. for_each_component(component) {
  1637. /* does this component override BEs ? */
  1638. if (!component->driver->ignore_machine)
  1639. continue;
  1640. /* for this machine ? */
  1641. if (!strcmp(component->driver->ignore_machine,
  1642. card->dev->driver->name))
  1643. goto match;
  1644. if (strcmp(component->driver->ignore_machine,
  1645. dev_name(card->dev)))
  1646. continue;
  1647. match:
  1648. /* machine matches, so override the rtd data */
  1649. for_each_card_prelinks(card, i, dai_link) {
  1650. /* ignore this FE */
  1651. if (dai_link->dynamic) {
  1652. dai_link->ignore = true;
  1653. continue;
  1654. }
  1655. dev_dbg(card->dev, "info: override BE DAI link %s\n",
  1656. card->dai_link[i].name);
  1657. /* override platform component */
  1658. if (!dai_link->platforms) {
  1659. dev_err(card->dev, "init platform error");
  1660. continue;
  1661. }
  1662. if (component->dev->of_node)
  1663. dai_link->platforms->of_node = component->dev->of_node;
  1664. else
  1665. dai_link->platforms->name = component->name;
  1666. /* convert non BE into BE */
  1667. if (!dai_link->no_pcm) {
  1668. dai_link->no_pcm = 1;
  1669. if (dai_link->dpcm_playback)
  1670. dev_warn(card->dev,
  1671. "invalid configuration, dailink %s has flags no_pcm=0 and dpcm_playback=1\n",
  1672. dai_link->name);
  1673. if (dai_link->dpcm_capture)
  1674. dev_warn(card->dev,
  1675. "invalid configuration, dailink %s has flags no_pcm=0 and dpcm_capture=1\n",
  1676. dai_link->name);
  1677. /* convert normal link into DPCM one */
  1678. if (!(dai_link->dpcm_playback ||
  1679. dai_link->dpcm_capture)) {
  1680. dai_link->dpcm_playback = !dai_link->capture_only;
  1681. dai_link->dpcm_capture = !dai_link->playback_only;
  1682. }
  1683. }
  1684. /*
  1685. * override any BE fixups
  1686. * see
  1687. * snd_soc_link_be_hw_params_fixup()
  1688. */
  1689. dai_link->be_hw_params_fixup =
  1690. component->driver->be_hw_params_fixup;
  1691. /*
  1692. * most BE links don't set stream name, so set it to
  1693. * dai link name if it's NULL to help bind widgets.
  1694. */
  1695. if (!dai_link->stream_name)
  1696. dai_link->stream_name = dai_link->name;
  1697. }
  1698. /* Inform userspace we are using alternate topology */
  1699. if (component->driver->topology_name_prefix) {
  1700. /* topology shortname created? */
  1701. if (!card->topology_shortname_created) {
  1702. comp_drv = component->driver;
  1703. snprintf(card->topology_shortname, 32, "%s-%s",
  1704. comp_drv->topology_name_prefix,
  1705. card->name);
  1706. card->topology_shortname_created = true;
  1707. }
  1708. /* use topology shortname */
  1709. card->name = card->topology_shortname;
  1710. }
  1711. }
  1712. }
  1713. #define soc_setup_card_name(card, name, name1, name2) \
  1714. __soc_setup_card_name(card, name, sizeof(name), name1, name2)
  1715. static void __soc_setup_card_name(struct snd_soc_card *card,
  1716. char *name, int len,
  1717. const char *name1, const char *name2)
  1718. {
  1719. const char *src = name1 ? name1 : name2;
  1720. int i;
  1721. snprintf(name, len, "%s", src);
  1722. if (name != card->snd_card->driver)
  1723. return;
  1724. /*
  1725. * Name normalization (driver field)
  1726. *
  1727. * The driver name is somewhat special, as it's used as a key for
  1728. * searches in the user-space.
  1729. *
  1730. * ex)
  1731. * "abcd??efg" -> "abcd__efg"
  1732. */
  1733. for (i = 0; i < len; i++) {
  1734. switch (name[i]) {
  1735. case '_':
  1736. case '-':
  1737. case '\0':
  1738. break;
  1739. default:
  1740. if (!isalnum(name[i]))
  1741. name[i] = '_';
  1742. break;
  1743. }
  1744. }
  1745. /*
  1746. * The driver field should contain a valid string from the user view.
  1747. * The wrapping usually does not work so well here. Set a smaller string
  1748. * in the specific ASoC driver.
  1749. */
  1750. if (strlen(src) > len - 1)
  1751. dev_err(card->dev, "ASoC: driver name too long '%s' -> '%s'\n", src, name);
  1752. }
  1753. static void soc_cleanup_card_resources(struct snd_soc_card *card)
  1754. {
  1755. struct snd_soc_pcm_runtime *rtd, *n;
  1756. if (card->snd_card)
  1757. snd_card_disconnect_sync(card->snd_card);
  1758. snd_soc_dapm_shutdown(card);
  1759. /* release machine specific resources */
  1760. for_each_card_rtds(card, rtd)
  1761. if (rtd->initialized)
  1762. snd_soc_link_exit(rtd);
  1763. /* remove and free each DAI */
  1764. soc_remove_link_dais(card);
  1765. soc_remove_link_components(card);
  1766. for_each_card_rtds_safe(card, rtd, n)
  1767. snd_soc_remove_pcm_runtime(card, rtd);
  1768. /* remove auxiliary devices */
  1769. soc_remove_aux_devices(card);
  1770. soc_unbind_aux_dev(card);
  1771. snd_soc_dapm_free(&card->dapm);
  1772. soc_cleanup_card_debugfs(card);
  1773. /* remove the card */
  1774. snd_soc_card_remove(card);
  1775. if (card->snd_card) {
  1776. snd_card_free(card->snd_card);
  1777. card->snd_card = NULL;
  1778. }
  1779. }
  1780. static void snd_soc_unbind_card(struct snd_soc_card *card, bool unregister)
  1781. {
  1782. if (snd_soc_card_is_instantiated(card)) {
  1783. card->instantiated = false;
  1784. snd_soc_flush_all_delayed_work(card);
  1785. soc_cleanup_card_resources(card);
  1786. if (!unregister)
  1787. list_add(&card->list, &unbind_card_list);
  1788. } else {
  1789. if (unregister)
  1790. list_del(&card->list);
  1791. }
  1792. }
  1793. static int snd_soc_bind_card(struct snd_soc_card *card)
  1794. {
  1795. struct snd_soc_pcm_runtime *rtd;
  1796. struct snd_soc_component *component;
  1797. int ret;
  1798. mutex_lock(&client_mutex);
  1799. snd_soc_card_mutex_lock_root(card);
  1800. snd_soc_fill_dummy_dai(card);
  1801. snd_soc_dapm_init(&card->dapm, card, NULL);
  1802. /* check whether any platform is ignore machine FE and using topology */
  1803. soc_check_tplg_fes(card);
  1804. /* bind aux_devs too */
  1805. ret = soc_bind_aux_dev(card);
  1806. if (ret < 0)
  1807. goto probe_end;
  1808. /* add predefined DAI links to the list */
  1809. card->num_rtd = 0;
  1810. ret = snd_soc_add_pcm_runtimes(card, card->dai_link, card->num_links);
  1811. if (ret < 0)
  1812. goto probe_end;
  1813. /* card bind complete so register a sound card */
  1814. ret = snd_card_new(card->dev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
  1815. card->owner, 0, &card->snd_card);
  1816. if (ret < 0) {
  1817. dev_err(card->dev,
  1818. "ASoC: can't create sound card for card %s: %d\n",
  1819. card->name, ret);
  1820. goto probe_end;
  1821. }
  1822. soc_init_card_debugfs(card);
  1823. soc_resume_init(card);
  1824. ret = snd_soc_dapm_new_controls(&card->dapm, card->dapm_widgets,
  1825. card->num_dapm_widgets);
  1826. if (ret < 0)
  1827. goto probe_end;
  1828. ret = snd_soc_dapm_new_controls(&card->dapm, card->of_dapm_widgets,
  1829. card->num_of_dapm_widgets);
  1830. if (ret < 0)
  1831. goto probe_end;
  1832. /* initialise the sound card only once */
  1833. ret = snd_soc_card_probe(card);
  1834. if (ret < 0)
  1835. goto probe_end;
  1836. /* probe all components used by DAI links on this card */
  1837. ret = soc_probe_link_components(card);
  1838. if (ret < 0) {
  1839. if (ret != -EPROBE_DEFER) {
  1840. dev_err(card->dev,
  1841. "ASoC: failed to instantiate card %d\n", ret);
  1842. }
  1843. goto probe_end;
  1844. }
  1845. /* probe auxiliary components */
  1846. ret = soc_probe_aux_devices(card);
  1847. if (ret < 0) {
  1848. dev_err(card->dev,
  1849. "ASoC: failed to probe aux component %d\n", ret);
  1850. goto probe_end;
  1851. }
  1852. /* probe all DAI links on this card */
  1853. ret = soc_probe_link_dais(card);
  1854. if (ret < 0) {
  1855. dev_err(card->dev,
  1856. "ASoC: failed to instantiate card %d\n", ret);
  1857. goto probe_end;
  1858. }
  1859. for_each_card_rtds(card, rtd) {
  1860. ret = soc_init_pcm_runtime(card, rtd);
  1861. if (ret < 0)
  1862. goto probe_end;
  1863. }
  1864. snd_soc_dapm_link_dai_widgets(card);
  1865. snd_soc_dapm_connect_dai_link_widgets(card);
  1866. ret = snd_soc_add_card_controls(card, card->controls,
  1867. card->num_controls);
  1868. if (ret < 0)
  1869. goto probe_end;
  1870. ret = snd_soc_dapm_add_routes(&card->dapm, card->dapm_routes,
  1871. card->num_dapm_routes);
  1872. if (ret < 0) {
  1873. if (card->disable_route_checks) {
  1874. dev_info(card->dev,
  1875. "%s: disable_route_checks set, ignoring errors on add_routes\n",
  1876. __func__);
  1877. } else {
  1878. dev_err(card->dev,
  1879. "%s: snd_soc_dapm_add_routes failed: %d\n",
  1880. __func__, ret);
  1881. goto probe_end;
  1882. }
  1883. }
  1884. ret = snd_soc_dapm_add_routes(&card->dapm, card->of_dapm_routes,
  1885. card->num_of_dapm_routes);
  1886. if (ret < 0)
  1887. goto probe_end;
  1888. /* try to set some sane longname if DMI is available */
  1889. snd_soc_set_dmi_name(card, NULL);
  1890. soc_setup_card_name(card, card->snd_card->shortname,
  1891. card->name, NULL);
  1892. soc_setup_card_name(card, card->snd_card->longname,
  1893. card->long_name, card->name);
  1894. soc_setup_card_name(card, card->snd_card->driver,
  1895. card->driver_name, card->name);
  1896. if (card->components) {
  1897. /* the current implementation of snd_component_add() accepts */
  1898. /* multiple components in the string separated by space, */
  1899. /* but the string collision (identical string) check might */
  1900. /* not work correctly */
  1901. ret = snd_component_add(card->snd_card, card->components);
  1902. if (ret < 0) {
  1903. dev_err(card->dev, "ASoC: %s snd_component_add() failed: %d\n",
  1904. card->name, ret);
  1905. goto probe_end;
  1906. }
  1907. }
  1908. ret = snd_soc_card_late_probe(card);
  1909. if (ret < 0)
  1910. goto probe_end;
  1911. snd_soc_dapm_new_widgets(card);
  1912. snd_soc_card_fixup_controls(card);
  1913. ret = snd_card_register(card->snd_card);
  1914. if (ret < 0) {
  1915. dev_err(card->dev, "ASoC: failed to register soundcard %d\n",
  1916. ret);
  1917. goto probe_end;
  1918. }
  1919. card->instantiated = 1;
  1920. dapm_mark_endpoints_dirty(card);
  1921. snd_soc_dapm_sync(&card->dapm);
  1922. /* deactivate pins to sleep state */
  1923. for_each_card_components(card, component)
  1924. if (!snd_soc_component_active(component))
  1925. pinctrl_pm_select_sleep_state(component->dev);
  1926. probe_end:
  1927. if (ret < 0)
  1928. soc_cleanup_card_resources(card);
  1929. snd_soc_card_mutex_unlock(card);
  1930. mutex_unlock(&client_mutex);
  1931. return ret;
  1932. }
  1933. /* probes a new socdev */
  1934. static int soc_probe(struct platform_device *pdev)
  1935. {
  1936. struct snd_soc_card *card = platform_get_drvdata(pdev);
  1937. /*
  1938. * no card, so machine driver should be registering card
  1939. * we should not be here in that case so ret error
  1940. */
  1941. if (!card)
  1942. return -EINVAL;
  1943. dev_warn(&pdev->dev,
  1944. "ASoC: machine %s should use snd_soc_register_card()\n",
  1945. card->name);
  1946. /* Bodge while we unpick instantiation */
  1947. card->dev = &pdev->dev;
  1948. return devm_snd_soc_register_card(&pdev->dev, card);
  1949. }
  1950. int snd_soc_poweroff(struct device *dev)
  1951. {
  1952. struct snd_soc_card *card = dev_get_drvdata(dev);
  1953. struct snd_soc_component *component;
  1954. if (!snd_soc_card_is_instantiated(card))
  1955. return 0;
  1956. /*
  1957. * Flush out pmdown_time work - we actually do want to run it
  1958. * now, we're shutting down so no imminent restart.
  1959. */
  1960. snd_soc_flush_all_delayed_work(card);
  1961. snd_soc_dapm_shutdown(card);
  1962. /* deactivate pins to sleep state */
  1963. for_each_card_components(card, component)
  1964. pinctrl_pm_select_sleep_state(component->dev);
  1965. return 0;
  1966. }
  1967. EXPORT_SYMBOL_GPL(snd_soc_poweroff);
  1968. const struct dev_pm_ops snd_soc_pm_ops = {
  1969. .suspend = snd_soc_suspend,
  1970. .resume = snd_soc_resume,
  1971. .freeze = snd_soc_suspend,
  1972. .thaw = snd_soc_resume,
  1973. .poweroff = snd_soc_poweroff,
  1974. .restore = snd_soc_resume,
  1975. };
  1976. EXPORT_SYMBOL_GPL(snd_soc_pm_ops);
  1977. /* ASoC platform driver */
  1978. static struct platform_driver soc_driver = {
  1979. .driver = {
  1980. .name = "soc-audio",
  1981. .pm = &snd_soc_pm_ops,
  1982. },
  1983. .probe = soc_probe,
  1984. };
  1985. /**
  1986. * snd_soc_cnew - create new control
  1987. * @_template: control template
  1988. * @data: control private data
  1989. * @long_name: control long name
  1990. * @prefix: control name prefix
  1991. *
  1992. * Create a new mixer control from a template control.
  1993. *
  1994. * Returns 0 for success, else error.
  1995. */
  1996. struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
  1997. void *data, const char *long_name,
  1998. const char *prefix)
  1999. {
  2000. struct snd_kcontrol_new template;
  2001. struct snd_kcontrol *kcontrol;
  2002. char *name = NULL;
  2003. memcpy(&template, _template, sizeof(template));
  2004. template.index = 0;
  2005. if (!long_name)
  2006. long_name = template.name;
  2007. if (prefix) {
  2008. name = kasprintf(GFP_KERNEL, "%s %s", prefix, long_name);
  2009. if (!name)
  2010. return NULL;
  2011. template.name = name;
  2012. } else {
  2013. template.name = long_name;
  2014. }
  2015. kcontrol = snd_ctl_new1(&template, data);
  2016. kfree(name);
  2017. return kcontrol;
  2018. }
  2019. EXPORT_SYMBOL_GPL(snd_soc_cnew);
  2020. static int snd_soc_add_controls(struct snd_card *card, struct device *dev,
  2021. const struct snd_kcontrol_new *controls, int num_controls,
  2022. const char *prefix, void *data)
  2023. {
  2024. int i;
  2025. for (i = 0; i < num_controls; i++) {
  2026. const struct snd_kcontrol_new *control = &controls[i];
  2027. int err = snd_ctl_add(card, snd_soc_cnew(control, data,
  2028. control->name, prefix));
  2029. if (err < 0) {
  2030. dev_err(dev, "ASoC: Failed to add %s: %d\n",
  2031. control->name, err);
  2032. return err;
  2033. }
  2034. }
  2035. return 0;
  2036. }
  2037. /**
  2038. * snd_soc_add_component_controls - Add an array of controls to a component.
  2039. *
  2040. * @component: Component to add controls to
  2041. * @controls: Array of controls to add
  2042. * @num_controls: Number of elements in the array
  2043. *
  2044. * Return: 0 for success, else error.
  2045. */
  2046. int snd_soc_add_component_controls(struct snd_soc_component *component,
  2047. const struct snd_kcontrol_new *controls, unsigned int num_controls)
  2048. {
  2049. struct snd_card *card = component->card->snd_card;
  2050. return snd_soc_add_controls(card, component->dev, controls,
  2051. num_controls, component->name_prefix, component);
  2052. }
  2053. EXPORT_SYMBOL_GPL(snd_soc_add_component_controls);
  2054. /**
  2055. * snd_soc_add_card_controls - add an array of controls to a SoC card.
  2056. * Convenience function to add a list of controls.
  2057. *
  2058. * @soc_card: SoC card to add controls to
  2059. * @controls: array of controls to add
  2060. * @num_controls: number of elements in the array
  2061. *
  2062. * Return 0 for success, else error.
  2063. */
  2064. int snd_soc_add_card_controls(struct snd_soc_card *soc_card,
  2065. const struct snd_kcontrol_new *controls, int num_controls)
  2066. {
  2067. struct snd_card *card = soc_card->snd_card;
  2068. return snd_soc_add_controls(card, soc_card->dev, controls, num_controls,
  2069. NULL, soc_card);
  2070. }
  2071. EXPORT_SYMBOL_GPL(snd_soc_add_card_controls);
  2072. /**
  2073. * snd_soc_add_dai_controls - add an array of controls to a DAI.
  2074. * Convenience function to add a list of controls.
  2075. *
  2076. * @dai: DAI to add controls to
  2077. * @controls: array of controls to add
  2078. * @num_controls: number of elements in the array
  2079. *
  2080. * Return 0 for success, else error.
  2081. */
  2082. int snd_soc_add_dai_controls(struct snd_soc_dai *dai,
  2083. const struct snd_kcontrol_new *controls, int num_controls)
  2084. {
  2085. struct snd_card *card = dai->component->card->snd_card;
  2086. return snd_soc_add_controls(card, dai->dev, controls, num_controls,
  2087. NULL, dai);
  2088. }
  2089. EXPORT_SYMBOL_GPL(snd_soc_add_dai_controls);
  2090. /**
  2091. * snd_soc_register_card - Register a card with the ASoC core
  2092. *
  2093. * @card: Card to register
  2094. *
  2095. */
  2096. int snd_soc_register_card(struct snd_soc_card *card)
  2097. {
  2098. if (!card->name || !card->dev)
  2099. return -EINVAL;
  2100. dev_set_drvdata(card->dev, card);
  2101. INIT_LIST_HEAD(&card->widgets);
  2102. INIT_LIST_HEAD(&card->paths);
  2103. INIT_LIST_HEAD(&card->dapm_list);
  2104. INIT_LIST_HEAD(&card->aux_comp_list);
  2105. INIT_LIST_HEAD(&card->component_dev_list);
  2106. INIT_LIST_HEAD(&card->list);
  2107. INIT_LIST_HEAD(&card->rtd_list);
  2108. INIT_LIST_HEAD(&card->dapm_dirty);
  2109. INIT_LIST_HEAD(&card->dobj_list);
  2110. card->instantiated = 0;
  2111. mutex_init(&card->mutex);
  2112. mutex_init(&card->dapm_mutex);
  2113. mutex_init(&card->pcm_mutex);
  2114. return snd_soc_bind_card(card);
  2115. }
  2116. EXPORT_SYMBOL_GPL(snd_soc_register_card);
  2117. /**
  2118. * snd_soc_unregister_card - Unregister a card with the ASoC core
  2119. *
  2120. * @card: Card to unregister
  2121. *
  2122. */
  2123. void snd_soc_unregister_card(struct snd_soc_card *card)
  2124. {
  2125. mutex_lock(&client_mutex);
  2126. snd_soc_unbind_card(card, true);
  2127. mutex_unlock(&client_mutex);
  2128. dev_dbg(card->dev, "ASoC: Unregistered card '%s'\n", card->name);
  2129. }
  2130. EXPORT_SYMBOL_GPL(snd_soc_unregister_card);
  2131. /*
  2132. * Simplify DAI link configuration by removing ".-1" from device names
  2133. * and sanitizing names.
  2134. */
  2135. static char *fmt_single_name(struct device *dev, int *id)
  2136. {
  2137. const char *devname = dev_name(dev);
  2138. char *found, *name;
  2139. unsigned int id1, id2;
  2140. if (devname == NULL)
  2141. return NULL;
  2142. name = devm_kstrdup(dev, devname, GFP_KERNEL);
  2143. if (!name)
  2144. return NULL;
  2145. /* are we a "%s.%d" name (platform and SPI components) */
  2146. found = strstr(name, dev->driver->name);
  2147. if (found) {
  2148. /* get ID */
  2149. if (sscanf(&found[strlen(dev->driver->name)], ".%d", id) == 1) {
  2150. /* discard ID from name if ID == -1 */
  2151. if (*id == -1)
  2152. found[strlen(dev->driver->name)] = '\0';
  2153. }
  2154. /* I2C component devices are named "bus-addr" */
  2155. } else if (sscanf(name, "%x-%x", &id1, &id2) == 2) {
  2156. /* create unique ID number from I2C addr and bus */
  2157. *id = ((id1 & 0xffff) << 16) + id2;
  2158. devm_kfree(dev, name);
  2159. /* sanitize component name for DAI link creation */
  2160. name = devm_kasprintf(dev, GFP_KERNEL, "%s.%s", dev->driver->name, devname);
  2161. } else {
  2162. *id = 0;
  2163. }
  2164. return name;
  2165. }
  2166. /*
  2167. * Simplify DAI link naming for single devices with multiple DAIs by removing
  2168. * any ".-1" and using the DAI name (instead of device name).
  2169. */
  2170. static inline char *fmt_multiple_name(struct device *dev,
  2171. struct snd_soc_dai_driver *dai_drv)
  2172. {
  2173. if (dai_drv->name == NULL) {
  2174. dev_err(dev,
  2175. "ASoC: error - multiple DAI %s registered with no name\n",
  2176. dev_name(dev));
  2177. return NULL;
  2178. }
  2179. return devm_kstrdup(dev, dai_drv->name, GFP_KERNEL);
  2180. }
  2181. void snd_soc_unregister_dai(struct snd_soc_dai *dai)
  2182. {
  2183. dev_dbg(dai->dev, "ASoC: Unregistered DAI '%s'\n", dai->name);
  2184. list_del(&dai->list);
  2185. }
  2186. EXPORT_SYMBOL_GPL(snd_soc_unregister_dai);
  2187. /**
  2188. * snd_soc_register_dai - Register a DAI dynamically & create its widgets
  2189. *
  2190. * @component: The component the DAIs are registered for
  2191. * @dai_drv: DAI driver to use for the DAI
  2192. * @legacy_dai_naming: if %true, use legacy single-name format;
  2193. * if %false, use multiple-name format;
  2194. *
  2195. * Topology can use this API to register DAIs when probing a component.
  2196. * These DAIs's widgets will be freed in the card cleanup and the DAIs
  2197. * will be freed in the component cleanup.
  2198. */
  2199. struct snd_soc_dai *snd_soc_register_dai(struct snd_soc_component *component,
  2200. struct snd_soc_dai_driver *dai_drv,
  2201. bool legacy_dai_naming)
  2202. {
  2203. struct device *dev = component->dev;
  2204. struct snd_soc_dai *dai;
  2205. lockdep_assert_held(&client_mutex);
  2206. dai = devm_kzalloc(dev, sizeof(*dai), GFP_KERNEL);
  2207. if (dai == NULL)
  2208. return NULL;
  2209. /*
  2210. * Back in the old days when we still had component-less DAIs,
  2211. * instead of having a static name, component-less DAIs would
  2212. * inherit the name of the parent device so it is possible to
  2213. * register multiple instances of the DAI. We still need to keep
  2214. * the same naming style even though those DAIs are not
  2215. * component-less anymore.
  2216. */
  2217. if (legacy_dai_naming &&
  2218. (dai_drv->id == 0 || dai_drv->name == NULL)) {
  2219. dai->name = fmt_single_name(dev, &dai->id);
  2220. } else {
  2221. dai->name = fmt_multiple_name(dev, dai_drv);
  2222. if (dai_drv->id)
  2223. dai->id = dai_drv->id;
  2224. else
  2225. dai->id = component->num_dai;
  2226. }
  2227. if (!dai->name)
  2228. return NULL;
  2229. dai->component = component;
  2230. dai->dev = dev;
  2231. dai->driver = dai_drv;
  2232. /* see for_each_component_dais */
  2233. list_add_tail(&dai->list, &component->dai_list);
  2234. component->num_dai++;
  2235. dev_dbg(dev, "ASoC: Registered DAI '%s'\n", dai->name);
  2236. return dai;
  2237. }
  2238. EXPORT_SYMBOL_GPL(snd_soc_register_dai);
  2239. /**
  2240. * snd_soc_unregister_dais - Unregister DAIs from the ASoC core
  2241. *
  2242. * @component: The component for which the DAIs should be unregistered
  2243. */
  2244. static void snd_soc_unregister_dais(struct snd_soc_component *component)
  2245. {
  2246. struct snd_soc_dai *dai, *_dai;
  2247. for_each_component_dais_safe(component, dai, _dai)
  2248. snd_soc_unregister_dai(dai);
  2249. }
  2250. /**
  2251. * snd_soc_register_dais - Register a DAI with the ASoC core
  2252. *
  2253. * @component: The component the DAIs are registered for
  2254. * @dai_drv: DAI driver to use for the DAIs
  2255. * @count: Number of DAIs
  2256. */
  2257. static int snd_soc_register_dais(struct snd_soc_component *component,
  2258. struct snd_soc_dai_driver *dai_drv,
  2259. size_t count)
  2260. {
  2261. struct snd_soc_dai *dai;
  2262. unsigned int i;
  2263. int ret;
  2264. for (i = 0; i < count; i++) {
  2265. dai = snd_soc_register_dai(component, dai_drv + i, count == 1 &&
  2266. component->driver->legacy_dai_naming);
  2267. if (dai == NULL) {
  2268. ret = -ENOMEM;
  2269. goto err;
  2270. }
  2271. }
  2272. return 0;
  2273. err:
  2274. snd_soc_unregister_dais(component);
  2275. return ret;
  2276. }
  2277. #define ENDIANNESS_MAP(name) \
  2278. (SNDRV_PCM_FMTBIT_##name##LE | SNDRV_PCM_FMTBIT_##name##BE)
  2279. static u64 endianness_format_map[] = {
  2280. ENDIANNESS_MAP(S16_),
  2281. ENDIANNESS_MAP(U16_),
  2282. ENDIANNESS_MAP(S24_),
  2283. ENDIANNESS_MAP(U24_),
  2284. ENDIANNESS_MAP(S32_),
  2285. ENDIANNESS_MAP(U32_),
  2286. ENDIANNESS_MAP(S24_3),
  2287. ENDIANNESS_MAP(U24_3),
  2288. ENDIANNESS_MAP(S20_3),
  2289. ENDIANNESS_MAP(U20_3),
  2290. ENDIANNESS_MAP(S18_3),
  2291. ENDIANNESS_MAP(U18_3),
  2292. ENDIANNESS_MAP(FLOAT_),
  2293. ENDIANNESS_MAP(FLOAT64_),
  2294. ENDIANNESS_MAP(IEC958_SUBFRAME_),
  2295. };
  2296. /*
  2297. * Fix up the DAI formats for endianness: codecs don't actually see
  2298. * the endianness of the data but we're using the CPU format
  2299. * definitions which do need to include endianness so we ensure that
  2300. * codec DAIs always have both big and little endian variants set.
  2301. */
  2302. static void convert_endianness_formats(struct snd_soc_pcm_stream *stream)
  2303. {
  2304. int i;
  2305. for (i = 0; i < ARRAY_SIZE(endianness_format_map); i++)
  2306. if (stream->formats & endianness_format_map[i])
  2307. stream->formats |= endianness_format_map[i];
  2308. }
  2309. static void snd_soc_try_rebind_card(void)
  2310. {
  2311. struct snd_soc_card *card, *c;
  2312. list_for_each_entry_safe(card, c, &unbind_card_list, list)
  2313. if (!snd_soc_bind_card(card))
  2314. list_del(&card->list);
  2315. }
  2316. static void snd_soc_del_component_unlocked(struct snd_soc_component *component)
  2317. {
  2318. struct snd_soc_card *card = component->card;
  2319. snd_soc_unregister_dais(component);
  2320. if (card)
  2321. snd_soc_unbind_card(card, false);
  2322. list_del(&component->list);
  2323. }
  2324. int snd_soc_component_initialize(struct snd_soc_component *component,
  2325. const struct snd_soc_component_driver *driver,
  2326. struct device *dev)
  2327. {
  2328. INIT_LIST_HEAD(&component->dai_list);
  2329. INIT_LIST_HEAD(&component->dobj_list);
  2330. INIT_LIST_HEAD(&component->card_list);
  2331. INIT_LIST_HEAD(&component->list);
  2332. mutex_init(&component->io_mutex);
  2333. if (!component->name) {
  2334. component->name = fmt_single_name(dev, &component->id);
  2335. if (!component->name) {
  2336. dev_err(dev, "ASoC: Failed to allocate name\n");
  2337. return -ENOMEM;
  2338. }
  2339. }
  2340. component->dev = dev;
  2341. component->driver = driver;
  2342. #ifdef CONFIG_DEBUG_FS
  2343. if (!component->debugfs_prefix)
  2344. component->debugfs_prefix = driver->debugfs_prefix;
  2345. #endif
  2346. return 0;
  2347. }
  2348. EXPORT_SYMBOL_GPL(snd_soc_component_initialize);
  2349. int snd_soc_add_component(struct snd_soc_component *component,
  2350. struct snd_soc_dai_driver *dai_drv,
  2351. int num_dai)
  2352. {
  2353. int ret;
  2354. int i;
  2355. mutex_lock(&client_mutex);
  2356. if (component->driver->endianness) {
  2357. for (i = 0; i < num_dai; i++) {
  2358. convert_endianness_formats(&dai_drv[i].playback);
  2359. convert_endianness_formats(&dai_drv[i].capture);
  2360. }
  2361. }
  2362. ret = snd_soc_register_dais(component, dai_drv, num_dai);
  2363. if (ret < 0) {
  2364. dev_err(component->dev, "ASoC: Failed to register DAIs: %d\n",
  2365. ret);
  2366. goto err_cleanup;
  2367. }
  2368. if (!component->driver->write && !component->driver->read) {
  2369. if (!component->regmap)
  2370. component->regmap = dev_get_regmap(component->dev,
  2371. NULL);
  2372. if (component->regmap)
  2373. snd_soc_component_setup_regmap(component);
  2374. }
  2375. /* see for_each_component */
  2376. list_add(&component->list, &component_list);
  2377. err_cleanup:
  2378. if (ret < 0)
  2379. snd_soc_del_component_unlocked(component);
  2380. mutex_unlock(&client_mutex);
  2381. if (ret == 0)
  2382. snd_soc_try_rebind_card();
  2383. return ret;
  2384. }
  2385. EXPORT_SYMBOL_GPL(snd_soc_add_component);
  2386. int snd_soc_register_component(struct device *dev,
  2387. const struct snd_soc_component_driver *component_driver,
  2388. struct snd_soc_dai_driver *dai_drv,
  2389. int num_dai)
  2390. {
  2391. struct snd_soc_component *component;
  2392. int ret;
  2393. component = devm_kzalloc(dev, sizeof(*component), GFP_KERNEL);
  2394. if (!component)
  2395. return -ENOMEM;
  2396. ret = snd_soc_component_initialize(component, component_driver, dev);
  2397. if (ret < 0)
  2398. return ret;
  2399. return snd_soc_add_component(component, dai_drv, num_dai);
  2400. }
  2401. EXPORT_SYMBOL_GPL(snd_soc_register_component);
  2402. /**
  2403. * snd_soc_unregister_component_by_driver - Unregister component using a given driver
  2404. * from the ASoC core
  2405. *
  2406. * @dev: The device to unregister
  2407. * @component_driver: The component driver to unregister
  2408. */
  2409. void snd_soc_unregister_component_by_driver(struct device *dev,
  2410. const struct snd_soc_component_driver *component_driver)
  2411. {
  2412. struct snd_soc_component *component;
  2413. if (!component_driver)
  2414. return;
  2415. mutex_lock(&client_mutex);
  2416. component = snd_soc_lookup_component_nolocked(dev, component_driver->name);
  2417. if (!component)
  2418. goto out;
  2419. snd_soc_del_component_unlocked(component);
  2420. out:
  2421. mutex_unlock(&client_mutex);
  2422. }
  2423. EXPORT_SYMBOL_GPL(snd_soc_unregister_component_by_driver);
  2424. /**
  2425. * snd_soc_unregister_component - Unregister all related component
  2426. * from the ASoC core
  2427. *
  2428. * @dev: The device to unregister
  2429. */
  2430. void snd_soc_unregister_component(struct device *dev)
  2431. {
  2432. mutex_lock(&client_mutex);
  2433. while (1) {
  2434. struct snd_soc_component *component = snd_soc_lookup_component_nolocked(dev, NULL);
  2435. if (!component)
  2436. break;
  2437. snd_soc_del_component_unlocked(component);
  2438. }
  2439. mutex_unlock(&client_mutex);
  2440. }
  2441. EXPORT_SYMBOL_GPL(snd_soc_unregister_component);
  2442. /* Retrieve a card's name from device tree */
  2443. int snd_soc_of_parse_card_name(struct snd_soc_card *card,
  2444. const char *propname)
  2445. {
  2446. struct device_node *np;
  2447. int ret;
  2448. if (!card->dev) {
  2449. pr_err("card->dev is not set before calling %s\n", __func__);
  2450. return -EINVAL;
  2451. }
  2452. np = card->dev->of_node;
  2453. ret = of_property_read_string_index(np, propname, 0, &card->name);
  2454. /*
  2455. * EINVAL means the property does not exist. This is fine providing
  2456. * card->name was previously set, which is checked later in
  2457. * snd_soc_register_card.
  2458. */
  2459. if (ret < 0 && ret != -EINVAL) {
  2460. dev_err(card->dev,
  2461. "ASoC: Property '%s' could not be read: %d\n",
  2462. propname, ret);
  2463. return ret;
  2464. }
  2465. return 0;
  2466. }
  2467. EXPORT_SYMBOL_GPL(snd_soc_of_parse_card_name);
  2468. static const struct snd_soc_dapm_widget simple_widgets[] = {
  2469. SND_SOC_DAPM_MIC("Microphone", NULL),
  2470. SND_SOC_DAPM_LINE("Line", NULL),
  2471. SND_SOC_DAPM_HP("Headphone", NULL),
  2472. SND_SOC_DAPM_SPK("Speaker", NULL),
  2473. };
  2474. int snd_soc_of_parse_audio_simple_widgets(struct snd_soc_card *card,
  2475. const char *propname)
  2476. {
  2477. struct device_node *np = card->dev->of_node;
  2478. struct snd_soc_dapm_widget *widgets;
  2479. const char *template, *wname;
  2480. int i, j, num_widgets;
  2481. num_widgets = of_property_count_strings(np, propname);
  2482. if (num_widgets < 0) {
  2483. dev_err(card->dev,
  2484. "ASoC: Property '%s' does not exist\n", propname);
  2485. return -EINVAL;
  2486. }
  2487. if (!num_widgets) {
  2488. dev_err(card->dev, "ASoC: Property '%s's length is zero\n",
  2489. propname);
  2490. return -EINVAL;
  2491. }
  2492. if (num_widgets & 1) {
  2493. dev_err(card->dev,
  2494. "ASoC: Property '%s' length is not even\n", propname);
  2495. return -EINVAL;
  2496. }
  2497. num_widgets /= 2;
  2498. widgets = devm_kcalloc(card->dev, num_widgets, sizeof(*widgets),
  2499. GFP_KERNEL);
  2500. if (!widgets) {
  2501. dev_err(card->dev,
  2502. "ASoC: Could not allocate memory for widgets\n");
  2503. return -ENOMEM;
  2504. }
  2505. for (i = 0; i < num_widgets; i++) {
  2506. int ret = of_property_read_string_index(np, propname,
  2507. 2 * i, &template);
  2508. if (ret) {
  2509. dev_err(card->dev,
  2510. "ASoC: Property '%s' index %d read error:%d\n",
  2511. propname, 2 * i, ret);
  2512. return -EINVAL;
  2513. }
  2514. for (j = 0; j < ARRAY_SIZE(simple_widgets); j++) {
  2515. if (!strncmp(template, simple_widgets[j].name,
  2516. strlen(simple_widgets[j].name))) {
  2517. widgets[i] = simple_widgets[j];
  2518. break;
  2519. }
  2520. }
  2521. if (j >= ARRAY_SIZE(simple_widgets)) {
  2522. dev_err(card->dev,
  2523. "ASoC: DAPM widget '%s' is not supported\n",
  2524. template);
  2525. return -EINVAL;
  2526. }
  2527. ret = of_property_read_string_index(np, propname,
  2528. (2 * i) + 1,
  2529. &wname);
  2530. if (ret) {
  2531. dev_err(card->dev,
  2532. "ASoC: Property '%s' index %d read error:%d\n",
  2533. propname, (2 * i) + 1, ret);
  2534. return -EINVAL;
  2535. }
  2536. widgets[i].name = wname;
  2537. }
  2538. card->of_dapm_widgets = widgets;
  2539. card->num_of_dapm_widgets = num_widgets;
  2540. return 0;
  2541. }
  2542. EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_simple_widgets);
  2543. int snd_soc_of_parse_pin_switches(struct snd_soc_card *card, const char *prop)
  2544. {
  2545. const unsigned int nb_controls_max = 16;
  2546. const char **strings, *control_name;
  2547. struct snd_kcontrol_new *controls;
  2548. struct device *dev = card->dev;
  2549. unsigned int i, nb_controls;
  2550. int ret;
  2551. if (!of_property_read_bool(dev->of_node, prop))
  2552. return 0;
  2553. strings = devm_kcalloc(dev, nb_controls_max,
  2554. sizeof(*strings), GFP_KERNEL);
  2555. if (!strings)
  2556. return -ENOMEM;
  2557. ret = of_property_read_string_array(dev->of_node, prop,
  2558. strings, nb_controls_max);
  2559. if (ret < 0)
  2560. return ret;
  2561. nb_controls = (unsigned int)ret;
  2562. controls = devm_kcalloc(dev, nb_controls,
  2563. sizeof(*controls), GFP_KERNEL);
  2564. if (!controls)
  2565. return -ENOMEM;
  2566. for (i = 0; i < nb_controls; i++) {
  2567. control_name = devm_kasprintf(dev, GFP_KERNEL,
  2568. "%s Switch", strings[i]);
  2569. if (!control_name)
  2570. return -ENOMEM;
  2571. controls[i].iface = SNDRV_CTL_ELEM_IFACE_MIXER;
  2572. controls[i].name = control_name;
  2573. controls[i].info = snd_soc_dapm_info_pin_switch;
  2574. controls[i].get = snd_soc_dapm_get_pin_switch;
  2575. controls[i].put = snd_soc_dapm_put_pin_switch;
  2576. controls[i].private_value = (unsigned long)strings[i];
  2577. }
  2578. card->controls = controls;
  2579. card->num_controls = nb_controls;
  2580. return 0;
  2581. }
  2582. EXPORT_SYMBOL_GPL(snd_soc_of_parse_pin_switches);
  2583. int snd_soc_of_get_slot_mask(struct device_node *np,
  2584. const char *prop_name,
  2585. unsigned int *mask)
  2586. {
  2587. u32 val;
  2588. const __be32 *of_slot_mask = of_get_property(np, prop_name, &val);
  2589. int i;
  2590. if (!of_slot_mask)
  2591. return 0;
  2592. val /= sizeof(u32);
  2593. for (i = 0; i < val; i++)
  2594. if (be32_to_cpup(&of_slot_mask[i]))
  2595. *mask |= (1 << i);
  2596. return val;
  2597. }
  2598. EXPORT_SYMBOL_GPL(snd_soc_of_get_slot_mask);
  2599. int snd_soc_of_parse_tdm_slot(struct device_node *np,
  2600. unsigned int *tx_mask,
  2601. unsigned int *rx_mask,
  2602. unsigned int *slots,
  2603. unsigned int *slot_width)
  2604. {
  2605. u32 val;
  2606. int ret;
  2607. if (tx_mask)
  2608. snd_soc_of_get_slot_mask(np, "dai-tdm-slot-tx-mask", tx_mask);
  2609. if (rx_mask)
  2610. snd_soc_of_get_slot_mask(np, "dai-tdm-slot-rx-mask", rx_mask);
  2611. if (of_property_read_bool(np, "dai-tdm-slot-num")) {
  2612. ret = of_property_read_u32(np, "dai-tdm-slot-num", &val);
  2613. if (ret)
  2614. return ret;
  2615. if (slots)
  2616. *slots = val;
  2617. }
  2618. if (of_property_read_bool(np, "dai-tdm-slot-width")) {
  2619. ret = of_property_read_u32(np, "dai-tdm-slot-width", &val);
  2620. if (ret)
  2621. return ret;
  2622. if (slot_width)
  2623. *slot_width = val;
  2624. }
  2625. return 0;
  2626. }
  2627. EXPORT_SYMBOL_GPL(snd_soc_of_parse_tdm_slot);
  2628. void snd_soc_dlc_use_cpu_as_platform(struct snd_soc_dai_link_component *platforms,
  2629. struct snd_soc_dai_link_component *cpus)
  2630. {
  2631. platforms->of_node = cpus->of_node;
  2632. platforms->dai_args = cpus->dai_args;
  2633. }
  2634. EXPORT_SYMBOL_GPL(snd_soc_dlc_use_cpu_as_platform);
  2635. void snd_soc_of_parse_node_prefix(struct device_node *np,
  2636. struct snd_soc_codec_conf *codec_conf,
  2637. struct device_node *of_node,
  2638. const char *propname)
  2639. {
  2640. const char *str;
  2641. int ret;
  2642. ret = of_property_read_string(np, propname, &str);
  2643. if (ret < 0) {
  2644. /* no prefix is not error */
  2645. return;
  2646. }
  2647. codec_conf->dlc.of_node = of_node;
  2648. codec_conf->name_prefix = str;
  2649. }
  2650. EXPORT_SYMBOL_GPL(snd_soc_of_parse_node_prefix);
  2651. int snd_soc_of_parse_audio_routing(struct snd_soc_card *card,
  2652. const char *propname)
  2653. {
  2654. struct device_node *np = card->dev->of_node;
  2655. int num_routes;
  2656. struct snd_soc_dapm_route *routes;
  2657. int i;
  2658. num_routes = of_property_count_strings(np, propname);
  2659. if (num_routes < 0 || num_routes & 1) {
  2660. dev_err(card->dev,
  2661. "ASoC: Property '%s' does not exist or its length is not even\n",
  2662. propname);
  2663. return -EINVAL;
  2664. }
  2665. num_routes /= 2;
  2666. routes = devm_kcalloc(card->dev, num_routes, sizeof(*routes),
  2667. GFP_KERNEL);
  2668. if (!routes) {
  2669. dev_err(card->dev,
  2670. "ASoC: Could not allocate DAPM route table\n");
  2671. return -ENOMEM;
  2672. }
  2673. for (i = 0; i < num_routes; i++) {
  2674. int ret = of_property_read_string_index(np, propname,
  2675. 2 * i, &routes[i].sink);
  2676. if (ret) {
  2677. dev_err(card->dev,
  2678. "ASoC: Property '%s' index %d could not be read: %d\n",
  2679. propname, 2 * i, ret);
  2680. return -EINVAL;
  2681. }
  2682. ret = of_property_read_string_index(np, propname,
  2683. (2 * i) + 1, &routes[i].source);
  2684. if (ret) {
  2685. dev_err(card->dev,
  2686. "ASoC: Property '%s' index %d could not be read: %d\n",
  2687. propname, (2 * i) + 1, ret);
  2688. return -EINVAL;
  2689. }
  2690. }
  2691. card->num_of_dapm_routes = num_routes;
  2692. card->of_dapm_routes = routes;
  2693. return 0;
  2694. }
  2695. EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_routing);
  2696. int snd_soc_of_parse_aux_devs(struct snd_soc_card *card, const char *propname)
  2697. {
  2698. struct device_node *node = card->dev->of_node;
  2699. struct snd_soc_aux_dev *aux;
  2700. int num, i;
  2701. num = of_count_phandle_with_args(node, propname, NULL);
  2702. if (num == -ENOENT) {
  2703. return 0;
  2704. } else if (num < 0) {
  2705. dev_err(card->dev, "ASOC: Property '%s' could not be read: %d\n",
  2706. propname, num);
  2707. return num;
  2708. }
  2709. aux = devm_kcalloc(card->dev, num, sizeof(*aux), GFP_KERNEL);
  2710. if (!aux)
  2711. return -ENOMEM;
  2712. card->aux_dev = aux;
  2713. card->num_aux_devs = num;
  2714. for_each_card_pre_auxs(card, i, aux) {
  2715. aux->dlc.of_node = of_parse_phandle(node, propname, i);
  2716. if (!aux->dlc.of_node)
  2717. return -EINVAL;
  2718. }
  2719. return 0;
  2720. }
  2721. EXPORT_SYMBOL_GPL(snd_soc_of_parse_aux_devs);
  2722. unsigned int snd_soc_daifmt_clock_provider_flipped(unsigned int dai_fmt)
  2723. {
  2724. unsigned int inv_dai_fmt = dai_fmt & ~SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK;
  2725. switch (dai_fmt & SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK) {
  2726. case SND_SOC_DAIFMT_CBP_CFP:
  2727. inv_dai_fmt |= SND_SOC_DAIFMT_CBC_CFC;
  2728. break;
  2729. case SND_SOC_DAIFMT_CBP_CFC:
  2730. inv_dai_fmt |= SND_SOC_DAIFMT_CBC_CFP;
  2731. break;
  2732. case SND_SOC_DAIFMT_CBC_CFP:
  2733. inv_dai_fmt |= SND_SOC_DAIFMT_CBP_CFC;
  2734. break;
  2735. case SND_SOC_DAIFMT_CBC_CFC:
  2736. inv_dai_fmt |= SND_SOC_DAIFMT_CBP_CFP;
  2737. break;
  2738. }
  2739. return inv_dai_fmt;
  2740. }
  2741. EXPORT_SYMBOL_GPL(snd_soc_daifmt_clock_provider_flipped);
  2742. unsigned int snd_soc_daifmt_clock_provider_from_bitmap(unsigned int bit_frame)
  2743. {
  2744. /*
  2745. * bit_frame is return value from
  2746. * snd_soc_daifmt_parse_clock_provider_raw()
  2747. */
  2748. /* Codec base */
  2749. switch (bit_frame) {
  2750. case 0x11:
  2751. return SND_SOC_DAIFMT_CBP_CFP;
  2752. case 0x10:
  2753. return SND_SOC_DAIFMT_CBP_CFC;
  2754. case 0x01:
  2755. return SND_SOC_DAIFMT_CBC_CFP;
  2756. default:
  2757. return SND_SOC_DAIFMT_CBC_CFC;
  2758. }
  2759. return 0;
  2760. }
  2761. EXPORT_SYMBOL_GPL(snd_soc_daifmt_clock_provider_from_bitmap);
  2762. unsigned int snd_soc_daifmt_parse_format(struct device_node *np,
  2763. const char *prefix)
  2764. {
  2765. int ret;
  2766. char prop[128];
  2767. unsigned int format = 0;
  2768. int bit, frame;
  2769. const char *str;
  2770. struct {
  2771. char *name;
  2772. unsigned int val;
  2773. } of_fmt_table[] = {
  2774. { "i2s", SND_SOC_DAIFMT_I2S },
  2775. { "right_j", SND_SOC_DAIFMT_RIGHT_J },
  2776. { "left_j", SND_SOC_DAIFMT_LEFT_J },
  2777. { "dsp_a", SND_SOC_DAIFMT_DSP_A },
  2778. { "dsp_b", SND_SOC_DAIFMT_DSP_B },
  2779. { "ac97", SND_SOC_DAIFMT_AC97 },
  2780. { "pdm", SND_SOC_DAIFMT_PDM},
  2781. { "msb", SND_SOC_DAIFMT_MSB },
  2782. { "lsb", SND_SOC_DAIFMT_LSB },
  2783. };
  2784. if (!prefix)
  2785. prefix = "";
  2786. /*
  2787. * check "dai-format = xxx"
  2788. * or "[prefix]format = xxx"
  2789. * SND_SOC_DAIFMT_FORMAT_MASK area
  2790. */
  2791. ret = of_property_read_string(np, "dai-format", &str);
  2792. if (ret < 0) {
  2793. snprintf(prop, sizeof(prop), "%sformat", prefix);
  2794. ret = of_property_read_string(np, prop, &str);
  2795. }
  2796. if (ret == 0) {
  2797. int i;
  2798. for (i = 0; i < ARRAY_SIZE(of_fmt_table); i++) {
  2799. if (strcmp(str, of_fmt_table[i].name) == 0) {
  2800. format |= of_fmt_table[i].val;
  2801. break;
  2802. }
  2803. }
  2804. }
  2805. /*
  2806. * check "[prefix]continuous-clock"
  2807. * SND_SOC_DAIFMT_CLOCK_MASK area
  2808. */
  2809. snprintf(prop, sizeof(prop), "%scontinuous-clock", prefix);
  2810. if (of_property_read_bool(np, prop))
  2811. format |= SND_SOC_DAIFMT_CONT;
  2812. else
  2813. format |= SND_SOC_DAIFMT_GATED;
  2814. /*
  2815. * check "[prefix]bitclock-inversion"
  2816. * check "[prefix]frame-inversion"
  2817. * SND_SOC_DAIFMT_INV_MASK area
  2818. */
  2819. snprintf(prop, sizeof(prop), "%sbitclock-inversion", prefix);
  2820. bit = of_property_read_bool(np, prop);
  2821. snprintf(prop, sizeof(prop), "%sframe-inversion", prefix);
  2822. frame = of_property_read_bool(np, prop);
  2823. switch ((bit << 4) + frame) {
  2824. case 0x11:
  2825. format |= SND_SOC_DAIFMT_IB_IF;
  2826. break;
  2827. case 0x10:
  2828. format |= SND_SOC_DAIFMT_IB_NF;
  2829. break;
  2830. case 0x01:
  2831. format |= SND_SOC_DAIFMT_NB_IF;
  2832. break;
  2833. default:
  2834. /* SND_SOC_DAIFMT_NB_NF is default */
  2835. break;
  2836. }
  2837. return format;
  2838. }
  2839. EXPORT_SYMBOL_GPL(snd_soc_daifmt_parse_format);
  2840. unsigned int snd_soc_daifmt_parse_clock_provider_raw(struct device_node *np,
  2841. const char *prefix,
  2842. struct device_node **bitclkmaster,
  2843. struct device_node **framemaster)
  2844. {
  2845. char prop[128];
  2846. unsigned int bit, frame;
  2847. if (!prefix)
  2848. prefix = "";
  2849. /*
  2850. * check "[prefix]bitclock-master"
  2851. * check "[prefix]frame-master"
  2852. */
  2853. snprintf(prop, sizeof(prop), "%sbitclock-master", prefix);
  2854. bit = of_property_read_bool(np, prop);
  2855. if (bit && bitclkmaster)
  2856. *bitclkmaster = of_parse_phandle(np, prop, 0);
  2857. snprintf(prop, sizeof(prop), "%sframe-master", prefix);
  2858. frame = of_property_read_bool(np, prop);
  2859. if (frame && framemaster)
  2860. *framemaster = of_parse_phandle(np, prop, 0);
  2861. /*
  2862. * return bitmap.
  2863. * It will be parameter of
  2864. * snd_soc_daifmt_clock_provider_from_bitmap()
  2865. */
  2866. return (bit << 4) + frame;
  2867. }
  2868. EXPORT_SYMBOL_GPL(snd_soc_daifmt_parse_clock_provider_raw);
  2869. int snd_soc_get_stream_cpu(const struct snd_soc_dai_link *dai_link, int stream)
  2870. {
  2871. /*
  2872. * [Normal]
  2873. *
  2874. * Playback
  2875. * CPU : SNDRV_PCM_STREAM_PLAYBACK
  2876. * Codec: SNDRV_PCM_STREAM_PLAYBACK
  2877. *
  2878. * Capture
  2879. * CPU : SNDRV_PCM_STREAM_CAPTURE
  2880. * Codec: SNDRV_PCM_STREAM_CAPTURE
  2881. */
  2882. if (!dai_link->c2c_params)
  2883. return stream;
  2884. /*
  2885. * [Codec2Codec]
  2886. *
  2887. * Playback
  2888. * CPU : SNDRV_PCM_STREAM_CAPTURE
  2889. * Codec: SNDRV_PCM_STREAM_PLAYBACK
  2890. *
  2891. * Capture
  2892. * CPU : SNDRV_PCM_STREAM_PLAYBACK
  2893. * Codec: SNDRV_PCM_STREAM_CAPTURE
  2894. */
  2895. if (stream == SNDRV_PCM_STREAM_CAPTURE)
  2896. return SNDRV_PCM_STREAM_PLAYBACK;
  2897. return SNDRV_PCM_STREAM_CAPTURE;
  2898. }
  2899. EXPORT_SYMBOL_GPL(snd_soc_get_stream_cpu);
  2900. int snd_soc_get_dai_id(struct device_node *ep)
  2901. {
  2902. struct snd_soc_component *component;
  2903. struct snd_soc_dai_link_component dlc = {
  2904. .of_node = of_graph_get_port_parent(ep),
  2905. };
  2906. int ret;
  2907. /*
  2908. * For example HDMI case, HDMI has video/sound port,
  2909. * but ALSA SoC needs sound port number only.
  2910. * Thus counting HDMI DT port/endpoint doesn't work.
  2911. * Then, it should have .of_xlate_dai_id
  2912. */
  2913. ret = -ENOTSUPP;
  2914. mutex_lock(&client_mutex);
  2915. component = soc_find_component(&dlc);
  2916. if (component)
  2917. ret = snd_soc_component_of_xlate_dai_id(component, ep);
  2918. mutex_unlock(&client_mutex);
  2919. of_node_put(dlc.of_node);
  2920. return ret;
  2921. }
  2922. EXPORT_SYMBOL_GPL(snd_soc_get_dai_id);
  2923. int snd_soc_get_dlc(const struct of_phandle_args *args, struct snd_soc_dai_link_component *dlc)
  2924. {
  2925. struct snd_soc_component *pos;
  2926. int ret = -EPROBE_DEFER;
  2927. mutex_lock(&client_mutex);
  2928. for_each_component(pos) {
  2929. struct device_node *component_of_node = soc_component_to_node(pos);
  2930. if (component_of_node != args->np || !pos->num_dai)
  2931. continue;
  2932. ret = snd_soc_component_of_xlate_dai_name(pos, args, &dlc->dai_name);
  2933. if (ret == -ENOTSUPP) {
  2934. struct snd_soc_dai *dai;
  2935. int id = -1;
  2936. switch (args->args_count) {
  2937. case 0:
  2938. id = 0; /* same as dai_drv[0] */
  2939. break;
  2940. case 1:
  2941. id = args->args[0];
  2942. break;
  2943. default:
  2944. /* not supported */
  2945. break;
  2946. }
  2947. if (id < 0 || id >= pos->num_dai) {
  2948. ret = -EINVAL;
  2949. continue;
  2950. }
  2951. ret = 0;
  2952. /* find target DAI */
  2953. for_each_component_dais(pos, dai) {
  2954. if (id == 0)
  2955. break;
  2956. id--;
  2957. }
  2958. dlc->dai_name = snd_soc_dai_name_get(dai);
  2959. } else if (ret) {
  2960. /*
  2961. * if another error than ENOTSUPP is returned go on and
  2962. * check if another component is provided with the same
  2963. * node. This may happen if a device provides several
  2964. * components
  2965. */
  2966. continue;
  2967. }
  2968. break;
  2969. }
  2970. if (ret == 0)
  2971. dlc->of_node = args->np;
  2972. mutex_unlock(&client_mutex);
  2973. return ret;
  2974. }
  2975. EXPORT_SYMBOL_GPL(snd_soc_get_dlc);
  2976. int snd_soc_of_get_dlc(struct device_node *of_node,
  2977. struct of_phandle_args *args,
  2978. struct snd_soc_dai_link_component *dlc,
  2979. int index)
  2980. {
  2981. struct of_phandle_args __args;
  2982. int ret;
  2983. if (!args)
  2984. args = &__args;
  2985. ret = of_parse_phandle_with_args(of_node, "sound-dai",
  2986. "#sound-dai-cells", index, args);
  2987. if (ret)
  2988. return ret;
  2989. return snd_soc_get_dlc(args, dlc);
  2990. }
  2991. EXPORT_SYMBOL_GPL(snd_soc_of_get_dlc);
  2992. int snd_soc_get_dai_name(const struct of_phandle_args *args,
  2993. const char **dai_name)
  2994. {
  2995. struct snd_soc_dai_link_component dlc;
  2996. int ret = snd_soc_get_dlc(args, &dlc);
  2997. if (ret == 0)
  2998. *dai_name = dlc.dai_name;
  2999. return ret;
  3000. }
  3001. EXPORT_SYMBOL_GPL(snd_soc_get_dai_name);
  3002. int snd_soc_of_get_dai_name(struct device_node *of_node,
  3003. const char **dai_name, int index)
  3004. {
  3005. struct snd_soc_dai_link_component dlc;
  3006. int ret = snd_soc_of_get_dlc(of_node, NULL, &dlc, index);
  3007. if (ret == 0)
  3008. *dai_name = dlc.dai_name;
  3009. return ret;
  3010. }
  3011. EXPORT_SYMBOL_GPL(snd_soc_of_get_dai_name);
  3012. struct snd_soc_dai *snd_soc_get_dai_via_args(const struct of_phandle_args *dai_args)
  3013. {
  3014. struct snd_soc_dai *dai;
  3015. struct snd_soc_component *component;
  3016. mutex_lock(&client_mutex);
  3017. for_each_component(component) {
  3018. for_each_component_dais(component, dai)
  3019. if (snd_soc_is_match_dai_args(dai->driver->dai_args, dai_args))
  3020. goto found;
  3021. }
  3022. dai = NULL;
  3023. found:
  3024. mutex_unlock(&client_mutex);
  3025. return dai;
  3026. }
  3027. EXPORT_SYMBOL_GPL(snd_soc_get_dai_via_args);
  3028. static void __snd_soc_of_put_component(struct snd_soc_dai_link_component *component)
  3029. {
  3030. if (component->of_node) {
  3031. of_node_put(component->of_node);
  3032. component->of_node = NULL;
  3033. }
  3034. }
  3035. static int __snd_soc_of_get_dai_link_component_alloc(
  3036. struct device *dev, struct device_node *of_node,
  3037. struct snd_soc_dai_link_component **ret_component,
  3038. int *ret_num)
  3039. {
  3040. struct snd_soc_dai_link_component *component;
  3041. int num;
  3042. /* Count the number of CPUs/CODECs */
  3043. num = of_count_phandle_with_args(of_node, "sound-dai", "#sound-dai-cells");
  3044. if (num <= 0) {
  3045. if (num == -ENOENT)
  3046. dev_err(dev, "No 'sound-dai' property\n");
  3047. else
  3048. dev_err(dev, "Bad phandle in 'sound-dai'\n");
  3049. return num;
  3050. }
  3051. component = devm_kcalloc(dev, num, sizeof(*component), GFP_KERNEL);
  3052. if (!component)
  3053. return -ENOMEM;
  3054. *ret_component = component;
  3055. *ret_num = num;
  3056. return 0;
  3057. }
  3058. /*
  3059. * snd_soc_of_put_dai_link_codecs - Dereference device nodes in the codecs array
  3060. * @dai_link: DAI link
  3061. *
  3062. * Dereference device nodes acquired by snd_soc_of_get_dai_link_codecs().
  3063. */
  3064. void snd_soc_of_put_dai_link_codecs(struct snd_soc_dai_link *dai_link)
  3065. {
  3066. struct snd_soc_dai_link_component *component;
  3067. int index;
  3068. for_each_link_codecs(dai_link, index, component)
  3069. __snd_soc_of_put_component(component);
  3070. }
  3071. EXPORT_SYMBOL_GPL(snd_soc_of_put_dai_link_codecs);
  3072. /*
  3073. * snd_soc_of_get_dai_link_codecs - Parse a list of CODECs in the devicetree
  3074. * @dev: Card device
  3075. * @of_node: Device node
  3076. * @dai_link: DAI link
  3077. *
  3078. * Builds an array of CODEC DAI components from the DAI link property
  3079. * 'sound-dai'.
  3080. * The array is set in the DAI link and the number of DAIs is set accordingly.
  3081. * The device nodes in the array (of_node) must be dereferenced by calling
  3082. * snd_soc_of_put_dai_link_codecs() on @dai_link.
  3083. *
  3084. * Returns 0 for success
  3085. */
  3086. int snd_soc_of_get_dai_link_codecs(struct device *dev,
  3087. struct device_node *of_node,
  3088. struct snd_soc_dai_link *dai_link)
  3089. {
  3090. struct snd_soc_dai_link_component *component;
  3091. int index, ret;
  3092. ret = __snd_soc_of_get_dai_link_component_alloc(dev, of_node,
  3093. &dai_link->codecs, &dai_link->num_codecs);
  3094. if (ret < 0)
  3095. return ret;
  3096. /* Parse the list */
  3097. for_each_link_codecs(dai_link, index, component) {
  3098. ret = snd_soc_of_get_dlc(of_node, NULL, component, index);
  3099. if (ret)
  3100. goto err;
  3101. }
  3102. return 0;
  3103. err:
  3104. snd_soc_of_put_dai_link_codecs(dai_link);
  3105. dai_link->codecs = NULL;
  3106. dai_link->num_codecs = 0;
  3107. return ret;
  3108. }
  3109. EXPORT_SYMBOL_GPL(snd_soc_of_get_dai_link_codecs);
  3110. /*
  3111. * snd_soc_of_put_dai_link_cpus - Dereference device nodes in the codecs array
  3112. * @dai_link: DAI link
  3113. *
  3114. * Dereference device nodes acquired by snd_soc_of_get_dai_link_cpus().
  3115. */
  3116. void snd_soc_of_put_dai_link_cpus(struct snd_soc_dai_link *dai_link)
  3117. {
  3118. struct snd_soc_dai_link_component *component;
  3119. int index;
  3120. for_each_link_cpus(dai_link, index, component)
  3121. __snd_soc_of_put_component(component);
  3122. }
  3123. EXPORT_SYMBOL_GPL(snd_soc_of_put_dai_link_cpus);
  3124. /*
  3125. * snd_soc_of_get_dai_link_cpus - Parse a list of CPU DAIs in the devicetree
  3126. * @dev: Card device
  3127. * @of_node: Device node
  3128. * @dai_link: DAI link
  3129. *
  3130. * Is analogous to snd_soc_of_get_dai_link_codecs but parses a list of CPU DAIs
  3131. * instead.
  3132. *
  3133. * Returns 0 for success
  3134. */
  3135. int snd_soc_of_get_dai_link_cpus(struct device *dev,
  3136. struct device_node *of_node,
  3137. struct snd_soc_dai_link *dai_link)
  3138. {
  3139. struct snd_soc_dai_link_component *component;
  3140. int index, ret;
  3141. /* Count the number of CPUs */
  3142. ret = __snd_soc_of_get_dai_link_component_alloc(dev, of_node,
  3143. &dai_link->cpus, &dai_link->num_cpus);
  3144. if (ret < 0)
  3145. return ret;
  3146. /* Parse the list */
  3147. for_each_link_cpus(dai_link, index, component) {
  3148. ret = snd_soc_of_get_dlc(of_node, NULL, component, index);
  3149. if (ret)
  3150. goto err;
  3151. }
  3152. return 0;
  3153. err:
  3154. snd_soc_of_put_dai_link_cpus(dai_link);
  3155. dai_link->cpus = NULL;
  3156. dai_link->num_cpus = 0;
  3157. return ret;
  3158. }
  3159. EXPORT_SYMBOL_GPL(snd_soc_of_get_dai_link_cpus);
  3160. static int __init snd_soc_init(void)
  3161. {
  3162. int ret;
  3163. snd_soc_debugfs_init();
  3164. ret = snd_soc_util_init();
  3165. if (ret)
  3166. goto err_util_init;
  3167. ret = platform_driver_register(&soc_driver);
  3168. if (ret)
  3169. goto err_register;
  3170. return 0;
  3171. err_register:
  3172. snd_soc_util_exit();
  3173. err_util_init:
  3174. snd_soc_debugfs_exit();
  3175. return ret;
  3176. }
  3177. module_init(snd_soc_init);
  3178. static void __exit snd_soc_exit(void)
  3179. {
  3180. snd_soc_util_exit();
  3181. snd_soc_debugfs_exit();
  3182. platform_driver_unregister(&soc_driver);
  3183. }
  3184. module_exit(snd_soc_exit);
  3185. /* Module information */
  3186. MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
  3187. MODULE_DESCRIPTION("ALSA SoC Core");
  3188. MODULE_LICENSE("GPL");
  3189. MODULE_ALIAS("platform:soc-audio");