soc-topology.c 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209
  1. // SPDX-License-Identifier: GPL-2.0+
  2. //
  3. // soc-topology.c -- ALSA SoC Topology
  4. //
  5. // Copyright (C) 2012 Texas Instruments Inc.
  6. // Copyright (C) 2015 Intel Corporation.
  7. //
  8. // Authors: Liam Girdwood <liam.r.girdwood@linux.intel.com>
  9. // K, Mythri P <mythri.p.k@intel.com>
  10. // Prusty, Subhransu S <subhransu.s.prusty@intel.com>
  11. // B, Jayachandran <jayachandran.b@intel.com>
  12. // Abdullah, Omair M <omair.m.abdullah@intel.com>
  13. // Jin, Yao <yao.jin@intel.com>
  14. // Lin, Mengdong <mengdong.lin@intel.com>
  15. //
  16. // Add support to read audio firmware topology alongside firmware text. The
  17. // topology data can contain kcontrols, DAPM graphs, widgets, DAIs, DAI links,
  18. // equalizers, firmware, coefficients etc.
  19. //
  20. // This file only manages the core ALSA and ASoC components, all other bespoke
  21. // firmware topology data is passed to component drivers for bespoke handling.
  22. #include <linux/kernel.h>
  23. #include <linux/export.h>
  24. #include <linux/list.h>
  25. #include <linux/firmware.h>
  26. #include <linux/slab.h>
  27. #include <sound/soc.h>
  28. #include <sound/soc-dapm.h>
  29. #include <sound/soc-topology.h>
  30. #include <sound/tlv.h>
  31. #define SOC_TPLG_MAGIC_BIG_ENDIAN 0x436F5341 /* ASoC in reverse */
  32. /*
  33. * We make several passes over the data (since it wont necessarily be ordered)
  34. * and process objects in the following order. This guarantees the component
  35. * drivers will be ready with any vendor data before the mixers and DAPM objects
  36. * are loaded (that may make use of the vendor data).
  37. */
  38. #define SOC_TPLG_PASS_MANIFEST 0
  39. #define SOC_TPLG_PASS_VENDOR 1
  40. #define SOC_TPLG_PASS_CONTROL 2
  41. #define SOC_TPLG_PASS_WIDGET 3
  42. #define SOC_TPLG_PASS_PCM_DAI 4
  43. #define SOC_TPLG_PASS_GRAPH 5
  44. #define SOC_TPLG_PASS_BE_DAI 6
  45. #define SOC_TPLG_PASS_LINK 7
  46. #define SOC_TPLG_PASS_START SOC_TPLG_PASS_MANIFEST
  47. #define SOC_TPLG_PASS_END SOC_TPLG_PASS_LINK
  48. /* topology context */
  49. struct soc_tplg {
  50. const struct firmware *fw;
  51. /* runtime FW parsing */
  52. const u8 *pos; /* read position */
  53. const u8 *hdr_pos; /* header position */
  54. unsigned int pass; /* pass number */
  55. /* component caller */
  56. struct device *dev;
  57. struct snd_soc_component *comp;
  58. u32 index; /* current block index */
  59. /* vendor specific kcontrol operations */
  60. const struct snd_soc_tplg_kcontrol_ops *io_ops;
  61. int io_ops_count;
  62. /* vendor specific bytes ext handlers, for TLV bytes controls */
  63. const struct snd_soc_tplg_bytes_ext_ops *bytes_ext_ops;
  64. int bytes_ext_ops_count;
  65. /* optional fw loading callbacks to component drivers */
  66. const struct snd_soc_tplg_ops *ops;
  67. };
  68. /* check we dont overflow the data for this control chunk */
  69. static int soc_tplg_check_elem_count(struct soc_tplg *tplg, size_t elem_size,
  70. unsigned int count, size_t bytes, const char *elem_type)
  71. {
  72. const u8 *end = tplg->pos + elem_size * count;
  73. if (end > tplg->fw->data + tplg->fw->size) {
  74. dev_err(tplg->dev, "ASoC: %s overflow end of data\n",
  75. elem_type);
  76. return -EINVAL;
  77. }
  78. /* check there is enough room in chunk for control.
  79. extra bytes at the end of control are for vendor data here */
  80. if (elem_size * count > bytes) {
  81. dev_err(tplg->dev,
  82. "ASoC: %s count %d of size %zu is bigger than chunk %zu\n",
  83. elem_type, count, elem_size, bytes);
  84. return -EINVAL;
  85. }
  86. return 0;
  87. }
  88. static inline bool soc_tplg_is_eof(struct soc_tplg *tplg)
  89. {
  90. const u8 *end = tplg->hdr_pos;
  91. if (end >= tplg->fw->data + tplg->fw->size)
  92. return true;
  93. return false;
  94. }
  95. static inline unsigned long soc_tplg_get_hdr_offset(struct soc_tplg *tplg)
  96. {
  97. return (unsigned long)(tplg->hdr_pos - tplg->fw->data);
  98. }
  99. static inline unsigned long soc_tplg_get_offset(struct soc_tplg *tplg)
  100. {
  101. return (unsigned long)(tplg->pos - tplg->fw->data);
  102. }
  103. /* mapping of Kcontrol types and associated operations. */
  104. static const struct snd_soc_tplg_kcontrol_ops io_ops[] = {
  105. {SND_SOC_TPLG_CTL_VOLSW, snd_soc_get_volsw,
  106. snd_soc_put_volsw, snd_soc_info_volsw},
  107. {SND_SOC_TPLG_CTL_VOLSW_SX, snd_soc_get_volsw_sx,
  108. snd_soc_put_volsw_sx, NULL},
  109. {SND_SOC_TPLG_CTL_ENUM, snd_soc_get_enum_double,
  110. snd_soc_put_enum_double, snd_soc_info_enum_double},
  111. {SND_SOC_TPLG_CTL_ENUM_VALUE, snd_soc_get_enum_double,
  112. snd_soc_put_enum_double, NULL},
  113. {SND_SOC_TPLG_CTL_BYTES, snd_soc_bytes_get,
  114. snd_soc_bytes_put, snd_soc_bytes_info},
  115. {SND_SOC_TPLG_CTL_RANGE, snd_soc_get_volsw,
  116. snd_soc_put_volsw, snd_soc_info_volsw},
  117. {SND_SOC_TPLG_CTL_VOLSW_XR_SX, snd_soc_get_xr_sx,
  118. snd_soc_put_xr_sx, snd_soc_info_xr_sx},
  119. {SND_SOC_TPLG_CTL_STROBE, snd_soc_get_strobe,
  120. snd_soc_put_strobe, NULL},
  121. {SND_SOC_TPLG_DAPM_CTL_VOLSW, snd_soc_dapm_get_volsw,
  122. snd_soc_dapm_put_volsw, snd_soc_info_volsw},
  123. {SND_SOC_TPLG_DAPM_CTL_ENUM_DOUBLE, snd_soc_dapm_get_enum_double,
  124. snd_soc_dapm_put_enum_double, snd_soc_info_enum_double},
  125. {SND_SOC_TPLG_DAPM_CTL_ENUM_VIRT, snd_soc_dapm_get_enum_double,
  126. snd_soc_dapm_put_enum_double, NULL},
  127. {SND_SOC_TPLG_DAPM_CTL_ENUM_VALUE, snd_soc_dapm_get_enum_double,
  128. snd_soc_dapm_put_enum_double, NULL},
  129. {SND_SOC_TPLG_DAPM_CTL_PIN, snd_soc_dapm_get_pin_switch,
  130. snd_soc_dapm_put_pin_switch, snd_soc_dapm_info_pin_switch},
  131. };
  132. struct soc_tplg_map {
  133. int uid;
  134. int kid;
  135. };
  136. /* mapping of widget types from UAPI IDs to kernel IDs */
  137. static const struct soc_tplg_map dapm_map[] = {
  138. {SND_SOC_TPLG_DAPM_INPUT, snd_soc_dapm_input},
  139. {SND_SOC_TPLG_DAPM_OUTPUT, snd_soc_dapm_output},
  140. {SND_SOC_TPLG_DAPM_MUX, snd_soc_dapm_mux},
  141. {SND_SOC_TPLG_DAPM_MIXER, snd_soc_dapm_mixer},
  142. {SND_SOC_TPLG_DAPM_PGA, snd_soc_dapm_pga},
  143. {SND_SOC_TPLG_DAPM_OUT_DRV, snd_soc_dapm_out_drv},
  144. {SND_SOC_TPLG_DAPM_ADC, snd_soc_dapm_adc},
  145. {SND_SOC_TPLG_DAPM_DAC, snd_soc_dapm_dac},
  146. {SND_SOC_TPLG_DAPM_SWITCH, snd_soc_dapm_switch},
  147. {SND_SOC_TPLG_DAPM_PRE, snd_soc_dapm_pre},
  148. {SND_SOC_TPLG_DAPM_POST, snd_soc_dapm_post},
  149. {SND_SOC_TPLG_DAPM_AIF_IN, snd_soc_dapm_aif_in},
  150. {SND_SOC_TPLG_DAPM_AIF_OUT, snd_soc_dapm_aif_out},
  151. {SND_SOC_TPLG_DAPM_DAI_IN, snd_soc_dapm_dai_in},
  152. {SND_SOC_TPLG_DAPM_DAI_OUT, snd_soc_dapm_dai_out},
  153. {SND_SOC_TPLG_DAPM_DAI_LINK, snd_soc_dapm_dai_link},
  154. {SND_SOC_TPLG_DAPM_BUFFER, snd_soc_dapm_buffer},
  155. {SND_SOC_TPLG_DAPM_SCHEDULER, snd_soc_dapm_scheduler},
  156. {SND_SOC_TPLG_DAPM_EFFECT, snd_soc_dapm_effect},
  157. {SND_SOC_TPLG_DAPM_SIGGEN, snd_soc_dapm_siggen},
  158. {SND_SOC_TPLG_DAPM_SRC, snd_soc_dapm_src},
  159. {SND_SOC_TPLG_DAPM_ASRC, snd_soc_dapm_asrc},
  160. {SND_SOC_TPLG_DAPM_ENCODER, snd_soc_dapm_encoder},
  161. {SND_SOC_TPLG_DAPM_DECODER, snd_soc_dapm_decoder},
  162. };
  163. static int tplg_chan_get_reg(struct soc_tplg *tplg,
  164. struct snd_soc_tplg_channel *chan, int map)
  165. {
  166. int i;
  167. for (i = 0; i < SND_SOC_TPLG_MAX_CHAN; i++) {
  168. if (le32_to_cpu(chan[i].id) == map)
  169. return le32_to_cpu(chan[i].reg);
  170. }
  171. return -EINVAL;
  172. }
  173. static int tplg_chan_get_shift(struct soc_tplg *tplg,
  174. struct snd_soc_tplg_channel *chan, int map)
  175. {
  176. int i;
  177. for (i = 0; i < SND_SOC_TPLG_MAX_CHAN; i++) {
  178. if (le32_to_cpu(chan[i].id) == map)
  179. return le32_to_cpu(chan[i].shift);
  180. }
  181. return -EINVAL;
  182. }
  183. static int get_widget_id(int tplg_type)
  184. {
  185. int i;
  186. for (i = 0; i < ARRAY_SIZE(dapm_map); i++) {
  187. if (tplg_type == dapm_map[i].uid)
  188. return dapm_map[i].kid;
  189. }
  190. return -EINVAL;
  191. }
  192. static inline void soc_control_err(struct soc_tplg *tplg,
  193. struct snd_soc_tplg_ctl_hdr *hdr, const char *name)
  194. {
  195. dev_err(tplg->dev,
  196. "ASoC: no complete control IO handler for %s type (g,p,i) %d:%d:%d at 0x%lx\n",
  197. name, hdr->ops.get, hdr->ops.put, hdr->ops.info,
  198. soc_tplg_get_offset(tplg));
  199. }
  200. /* pass vendor data to component driver for processing */
  201. static int soc_tplg_vendor_load(struct soc_tplg *tplg,
  202. struct snd_soc_tplg_hdr *hdr)
  203. {
  204. int ret = 0;
  205. if (tplg->ops && tplg->ops->vendor_load)
  206. ret = tplg->ops->vendor_load(tplg->comp, tplg->index, hdr);
  207. else {
  208. dev_err(tplg->dev, "ASoC: no vendor load callback for ID %d\n",
  209. hdr->vendor_type);
  210. return -EINVAL;
  211. }
  212. if (ret < 0)
  213. dev_err(tplg->dev,
  214. "ASoC: vendor load failed at hdr offset %ld/0x%lx for type %d:%d\n",
  215. soc_tplg_get_hdr_offset(tplg),
  216. soc_tplg_get_hdr_offset(tplg),
  217. hdr->type, hdr->vendor_type);
  218. return ret;
  219. }
  220. /* optionally pass new dynamic widget to component driver. This is mainly for
  221. * external widgets where we can assign private data/ops */
  222. static int soc_tplg_widget_load(struct soc_tplg *tplg,
  223. struct snd_soc_dapm_widget *w, struct snd_soc_tplg_dapm_widget *tplg_w)
  224. {
  225. if (tplg->ops && tplg->ops->widget_load)
  226. return tplg->ops->widget_load(tplg->comp, tplg->index, w,
  227. tplg_w);
  228. return 0;
  229. }
  230. /* optionally pass new dynamic widget to component driver. This is mainly for
  231. * external widgets where we can assign private data/ops */
  232. static int soc_tplg_widget_ready(struct soc_tplg *tplg,
  233. struct snd_soc_dapm_widget *w, struct snd_soc_tplg_dapm_widget *tplg_w)
  234. {
  235. if (tplg->ops && tplg->ops->widget_ready)
  236. return tplg->ops->widget_ready(tplg->comp, tplg->index, w,
  237. tplg_w);
  238. return 0;
  239. }
  240. /* pass DAI configurations to component driver for extra initialization */
  241. static int soc_tplg_dai_load(struct soc_tplg *tplg,
  242. struct snd_soc_dai_driver *dai_drv,
  243. struct snd_soc_tplg_pcm *pcm, struct snd_soc_dai *dai)
  244. {
  245. if (tplg->ops && tplg->ops->dai_load)
  246. return tplg->ops->dai_load(tplg->comp, tplg->index, dai_drv,
  247. pcm, dai);
  248. return 0;
  249. }
  250. /* pass link configurations to component driver for extra initialization */
  251. static int soc_tplg_dai_link_load(struct soc_tplg *tplg,
  252. struct snd_soc_dai_link *link, struct snd_soc_tplg_link_config *cfg)
  253. {
  254. if (tplg->ops && tplg->ops->link_load)
  255. return tplg->ops->link_load(tplg->comp, tplg->index, link, cfg);
  256. return 0;
  257. }
  258. /* tell the component driver that all firmware has been loaded in this request */
  259. static int soc_tplg_complete(struct soc_tplg *tplg)
  260. {
  261. if (tplg->ops && tplg->ops->complete)
  262. return tplg->ops->complete(tplg->comp);
  263. return 0;
  264. }
  265. /* add a dynamic kcontrol */
  266. static int soc_tplg_add_dcontrol(struct snd_card *card, struct device *dev,
  267. const struct snd_kcontrol_new *control_new, const char *prefix,
  268. void *data, struct snd_kcontrol **kcontrol)
  269. {
  270. int err;
  271. *kcontrol = snd_soc_cnew(control_new, data, control_new->name, prefix);
  272. if (*kcontrol == NULL) {
  273. dev_err(dev, "ASoC: Failed to create new kcontrol %s\n",
  274. control_new->name);
  275. return -ENOMEM;
  276. }
  277. err = snd_ctl_add(card, *kcontrol);
  278. if (err < 0) {
  279. dev_err(dev, "ASoC: Failed to add %s: %d\n",
  280. control_new->name, err);
  281. return err;
  282. }
  283. return 0;
  284. }
  285. /* add a dynamic kcontrol for component driver */
  286. static int soc_tplg_add_kcontrol(struct soc_tplg *tplg,
  287. struct snd_kcontrol_new *k, struct snd_kcontrol **kcontrol)
  288. {
  289. struct snd_soc_component *comp = tplg->comp;
  290. return soc_tplg_add_dcontrol(comp->card->snd_card,
  291. tplg->dev, k, comp->name_prefix, comp, kcontrol);
  292. }
  293. /* remove kcontrol */
  294. static void soc_tplg_remove_kcontrol(struct snd_soc_component *comp, struct snd_soc_dobj *dobj,
  295. int pass)
  296. {
  297. struct snd_card *card = comp->card->snd_card;
  298. if (pass != SOC_TPLG_PASS_CONTROL)
  299. return;
  300. if (dobj->unload)
  301. dobj->unload(comp, dobj);
  302. snd_ctl_remove(card, dobj->control.kcontrol);
  303. list_del(&dobj->list);
  304. }
  305. /* remove a route */
  306. static void soc_tplg_remove_route(struct snd_soc_component *comp,
  307. struct snd_soc_dobj *dobj, int pass)
  308. {
  309. if (pass != SOC_TPLG_PASS_GRAPH)
  310. return;
  311. if (dobj->unload)
  312. dobj->unload(comp, dobj);
  313. list_del(&dobj->list);
  314. }
  315. /* remove a widget and it's kcontrols - routes must be removed first */
  316. static void soc_tplg_remove_widget(struct snd_soc_component *comp,
  317. struct snd_soc_dobj *dobj, int pass)
  318. {
  319. struct snd_card *card = comp->card->snd_card;
  320. struct snd_soc_dapm_widget *w =
  321. container_of(dobj, struct snd_soc_dapm_widget, dobj);
  322. int i;
  323. if (pass != SOC_TPLG_PASS_WIDGET)
  324. return;
  325. if (dobj->unload)
  326. dobj->unload(comp, dobj);
  327. if (w->kcontrols)
  328. for (i = 0; i < w->num_kcontrols; i++)
  329. snd_ctl_remove(card, w->kcontrols[i]);
  330. list_del(&dobj->list);
  331. /* widget w is freed by soc-dapm.c */
  332. }
  333. /* remove DAI configurations */
  334. static void soc_tplg_remove_dai(struct snd_soc_component *comp,
  335. struct snd_soc_dobj *dobj, int pass)
  336. {
  337. struct snd_soc_dai_driver *dai_drv =
  338. container_of(dobj, struct snd_soc_dai_driver, dobj);
  339. struct snd_soc_dai *dai, *_dai;
  340. if (pass != SOC_TPLG_PASS_PCM_DAI)
  341. return;
  342. if (dobj->unload)
  343. dobj->unload(comp, dobj);
  344. for_each_component_dais_safe(comp, dai, _dai)
  345. if (dai->driver == dai_drv)
  346. snd_soc_unregister_dai(dai);
  347. list_del(&dobj->list);
  348. }
  349. /* remove link configurations */
  350. static void soc_tplg_remove_link(struct snd_soc_component *comp,
  351. struct snd_soc_dobj *dobj, int pass)
  352. {
  353. struct snd_soc_dai_link *link =
  354. container_of(dobj, struct snd_soc_dai_link, dobj);
  355. if (pass != SOC_TPLG_PASS_PCM_DAI)
  356. return;
  357. if (dobj->unload)
  358. dobj->unload(comp, dobj);
  359. list_del(&dobj->list);
  360. /* Ignored links do not need to be removed, they are not added */
  361. if (!link->ignore)
  362. snd_soc_remove_pcm_runtime(comp->card,
  363. snd_soc_get_pcm_runtime(comp->card, link));
  364. }
  365. /* unload dai link */
  366. static void remove_backend_link(struct snd_soc_component *comp,
  367. struct snd_soc_dobj *dobj, int pass)
  368. {
  369. if (pass != SOC_TPLG_PASS_LINK)
  370. return;
  371. if (dobj->unload)
  372. dobj->unload(comp, dobj);
  373. /*
  374. * We don't free the link here as what soc_tplg_remove_link() do since BE
  375. * links are not allocated by topology.
  376. * We however need to reset the dobj type to its initial values
  377. */
  378. dobj->type = SND_SOC_DOBJ_NONE;
  379. list_del(&dobj->list);
  380. }
  381. /* bind a kcontrol to it's IO handlers */
  382. static int soc_tplg_kcontrol_bind_io(struct snd_soc_tplg_ctl_hdr *hdr,
  383. struct snd_kcontrol_new *k,
  384. const struct soc_tplg *tplg)
  385. {
  386. const struct snd_soc_tplg_kcontrol_ops *ops;
  387. const struct snd_soc_tplg_bytes_ext_ops *ext_ops;
  388. int num_ops, i;
  389. if (le32_to_cpu(hdr->ops.info) == SND_SOC_TPLG_CTL_BYTES
  390. && k->iface & SNDRV_CTL_ELEM_IFACE_MIXER
  391. && (k->access & SNDRV_CTL_ELEM_ACCESS_TLV_READ
  392. || k->access & SNDRV_CTL_ELEM_ACCESS_TLV_WRITE)
  393. && k->access & SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK) {
  394. struct soc_bytes_ext *sbe;
  395. struct snd_soc_tplg_bytes_control *be;
  396. sbe = (struct soc_bytes_ext *)k->private_value;
  397. be = container_of(hdr, struct snd_soc_tplg_bytes_control, hdr);
  398. /* TLV bytes controls need standard kcontrol info handler,
  399. * TLV callback and extended put/get handlers.
  400. */
  401. k->info = snd_soc_bytes_info_ext;
  402. k->tlv.c = snd_soc_bytes_tlv_callback;
  403. /*
  404. * When a topology-based implementation abuses the
  405. * control interface and uses bytes_ext controls of
  406. * more than 512 bytes, we need to disable the size
  407. * checks, otherwise accesses to such controls will
  408. * return an -EINVAL error and prevent the card from
  409. * being configured.
  410. */
  411. if (sbe->max > 512)
  412. k->access |= SNDRV_CTL_ELEM_ACCESS_SKIP_CHECK;
  413. ext_ops = tplg->bytes_ext_ops;
  414. num_ops = tplg->bytes_ext_ops_count;
  415. for (i = 0; i < num_ops; i++) {
  416. if (!sbe->put &&
  417. ext_ops[i].id == le32_to_cpu(be->ext_ops.put))
  418. sbe->put = ext_ops[i].put;
  419. if (!sbe->get &&
  420. ext_ops[i].id == le32_to_cpu(be->ext_ops.get))
  421. sbe->get = ext_ops[i].get;
  422. }
  423. if ((k->access & SNDRV_CTL_ELEM_ACCESS_TLV_READ) && !sbe->get)
  424. return -EINVAL;
  425. if ((k->access & SNDRV_CTL_ELEM_ACCESS_TLV_WRITE) && !sbe->put)
  426. return -EINVAL;
  427. return 0;
  428. }
  429. /* try and map vendor specific kcontrol handlers first */
  430. ops = tplg->io_ops;
  431. num_ops = tplg->io_ops_count;
  432. for (i = 0; i < num_ops; i++) {
  433. if (k->put == NULL && ops[i].id == le32_to_cpu(hdr->ops.put))
  434. k->put = ops[i].put;
  435. if (k->get == NULL && ops[i].id == le32_to_cpu(hdr->ops.get))
  436. k->get = ops[i].get;
  437. if (k->info == NULL && ops[i].id == le32_to_cpu(hdr->ops.info))
  438. k->info = ops[i].info;
  439. }
  440. /* vendor specific handlers found ? */
  441. if (k->put && k->get && k->info)
  442. return 0;
  443. /* none found so try standard kcontrol handlers */
  444. ops = io_ops;
  445. num_ops = ARRAY_SIZE(io_ops);
  446. for (i = 0; i < num_ops; i++) {
  447. if (k->put == NULL && ops[i].id == le32_to_cpu(hdr->ops.put))
  448. k->put = ops[i].put;
  449. if (k->get == NULL && ops[i].id == le32_to_cpu(hdr->ops.get))
  450. k->get = ops[i].get;
  451. if (k->info == NULL && ops[i].id == le32_to_cpu(hdr->ops.info))
  452. k->info = ops[i].info;
  453. }
  454. /* standard handlers found ? */
  455. if (k->put && k->get && k->info)
  456. return 0;
  457. /* nothing to bind */
  458. return -EINVAL;
  459. }
  460. /* bind a widgets to it's evnt handlers */
  461. int snd_soc_tplg_widget_bind_event(struct snd_soc_dapm_widget *w,
  462. const struct snd_soc_tplg_widget_events *events,
  463. int num_events, u16 event_type)
  464. {
  465. int i;
  466. w->event = NULL;
  467. for (i = 0; i < num_events; i++) {
  468. if (event_type == events[i].type) {
  469. /* found - so assign event */
  470. w->event = events[i].event_handler;
  471. return 0;
  472. }
  473. }
  474. /* not found */
  475. return -EINVAL;
  476. }
  477. EXPORT_SYMBOL_GPL(snd_soc_tplg_widget_bind_event);
  478. /* optionally pass new dynamic kcontrol to component driver. */
  479. static int soc_tplg_control_load(struct soc_tplg *tplg,
  480. struct snd_kcontrol_new *k, struct snd_soc_tplg_ctl_hdr *hdr)
  481. {
  482. int ret = 0;
  483. if (tplg->ops && tplg->ops->control_load)
  484. ret = tplg->ops->control_load(tplg->comp, tplg->index, k, hdr);
  485. if (ret)
  486. dev_err(tplg->dev, "ASoC: failed to init %s\n", hdr->name);
  487. return ret;
  488. }
  489. static int soc_tplg_create_tlv_db_scale(struct soc_tplg *tplg,
  490. struct snd_kcontrol_new *kc, struct snd_soc_tplg_tlv_dbscale *scale)
  491. {
  492. unsigned int item_len = 2 * sizeof(unsigned int);
  493. unsigned int *p;
  494. p = devm_kzalloc(tplg->dev, item_len + 2 * sizeof(unsigned int), GFP_KERNEL);
  495. if (!p)
  496. return -ENOMEM;
  497. p[0] = SNDRV_CTL_TLVT_DB_SCALE;
  498. p[1] = item_len;
  499. p[2] = le32_to_cpu(scale->min);
  500. p[3] = (le32_to_cpu(scale->step) & TLV_DB_SCALE_MASK)
  501. | (le32_to_cpu(scale->mute) ? TLV_DB_SCALE_MUTE : 0);
  502. kc->tlv.p = (void *)p;
  503. return 0;
  504. }
  505. static int soc_tplg_create_tlv(struct soc_tplg *tplg,
  506. struct snd_kcontrol_new *kc, struct snd_soc_tplg_ctl_hdr *tc)
  507. {
  508. struct snd_soc_tplg_ctl_tlv *tplg_tlv;
  509. u32 access = le32_to_cpu(tc->access);
  510. if (!(access & SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE))
  511. return 0;
  512. if (!(access & SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK)) {
  513. tplg_tlv = &tc->tlv;
  514. switch (le32_to_cpu(tplg_tlv->type)) {
  515. case SNDRV_CTL_TLVT_DB_SCALE:
  516. return soc_tplg_create_tlv_db_scale(tplg, kc,
  517. &tplg_tlv->scale);
  518. /* TODO: add support for other TLV types */
  519. default:
  520. dev_dbg(tplg->dev, "Unsupported TLV type %d\n",
  521. tplg_tlv->type);
  522. return -EINVAL;
  523. }
  524. }
  525. return 0;
  526. }
  527. static int soc_tplg_control_dmixer_create(struct soc_tplg *tplg, struct snd_kcontrol_new *kc)
  528. {
  529. struct snd_soc_tplg_mixer_control *mc;
  530. struct soc_mixer_control *sm;
  531. int err;
  532. mc = (struct snd_soc_tplg_mixer_control *)tplg->pos;
  533. /* validate kcontrol */
  534. if (strnlen(mc->hdr.name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) == SNDRV_CTL_ELEM_ID_NAME_MAXLEN)
  535. return -EINVAL;
  536. sm = devm_kzalloc(tplg->dev, sizeof(*sm), GFP_KERNEL);
  537. if (!sm)
  538. return -ENOMEM;
  539. tplg->pos += sizeof(struct snd_soc_tplg_mixer_control) + le32_to_cpu(mc->priv.size);
  540. dev_dbg(tplg->dev, "ASoC: adding mixer kcontrol %s with access 0x%x\n",
  541. mc->hdr.name, mc->hdr.access);
  542. kc->name = devm_kstrdup(tplg->dev, mc->hdr.name, GFP_KERNEL);
  543. if (!kc->name)
  544. return -ENOMEM;
  545. kc->private_value = (long)sm;
  546. kc->iface = SNDRV_CTL_ELEM_IFACE_MIXER;
  547. kc->access = le32_to_cpu(mc->hdr.access);
  548. /* we only support FL/FR channel mapping atm */
  549. sm->reg = tplg_chan_get_reg(tplg, mc->channel, SNDRV_CHMAP_FL);
  550. sm->rreg = tplg_chan_get_reg(tplg, mc->channel, SNDRV_CHMAP_FR);
  551. sm->shift = tplg_chan_get_shift(tplg, mc->channel, SNDRV_CHMAP_FL);
  552. sm->rshift = tplg_chan_get_shift(tplg, mc->channel, SNDRV_CHMAP_FR);
  553. sm->max = le32_to_cpu(mc->max);
  554. sm->min = le32_to_cpu(mc->min);
  555. sm->invert = le32_to_cpu(mc->invert);
  556. sm->platform_max = le32_to_cpu(mc->platform_max);
  557. sm->num_channels = le32_to_cpu(mc->num_channels);
  558. /* map io handlers */
  559. err = soc_tplg_kcontrol_bind_io(&mc->hdr, kc, tplg);
  560. if (err) {
  561. soc_control_err(tplg, &mc->hdr, mc->hdr.name);
  562. return err;
  563. }
  564. /* create any TLV data */
  565. err = soc_tplg_create_tlv(tplg, kc, &mc->hdr);
  566. if (err < 0) {
  567. dev_err(tplg->dev, "ASoC: failed to create TLV %s\n", mc->hdr.name);
  568. return err;
  569. }
  570. /* pass control to driver for optional further init */
  571. return soc_tplg_control_load(tplg, kc, &mc->hdr);
  572. }
  573. static int soc_tplg_denum_create_texts(struct soc_tplg *tplg, struct soc_enum *se,
  574. struct snd_soc_tplg_enum_control *ec)
  575. {
  576. int i, ret;
  577. if (le32_to_cpu(ec->items) > ARRAY_SIZE(ec->texts))
  578. return -EINVAL;
  579. se->dobj.control.dtexts =
  580. devm_kcalloc(tplg->dev, le32_to_cpu(ec->items), sizeof(char *), GFP_KERNEL);
  581. if (se->dobj.control.dtexts == NULL)
  582. return -ENOMEM;
  583. for (i = 0; i < le32_to_cpu(ec->items); i++) {
  584. if (strnlen(ec->texts[i], SNDRV_CTL_ELEM_ID_NAME_MAXLEN) ==
  585. SNDRV_CTL_ELEM_ID_NAME_MAXLEN) {
  586. ret = -EINVAL;
  587. goto err;
  588. }
  589. se->dobj.control.dtexts[i] = devm_kstrdup(tplg->dev, ec->texts[i], GFP_KERNEL);
  590. if (!se->dobj.control.dtexts[i]) {
  591. ret = -ENOMEM;
  592. goto err;
  593. }
  594. }
  595. se->items = le32_to_cpu(ec->items);
  596. se->texts = (const char * const *)se->dobj.control.dtexts;
  597. return 0;
  598. err:
  599. return ret;
  600. }
  601. static int soc_tplg_denum_create_values(struct soc_tplg *tplg, struct soc_enum *se,
  602. struct snd_soc_tplg_enum_control *ec)
  603. {
  604. int i;
  605. /*
  606. * Following "if" checks if we have at most SND_SOC_TPLG_NUM_TEXTS
  607. * values instead of using ARRAY_SIZE(ec->values) due to the fact that
  608. * it is oversized for its purpose. Additionally it is done so because
  609. * it is defined in UAPI header where it can't be easily changed.
  610. */
  611. if (le32_to_cpu(ec->items) > SND_SOC_TPLG_NUM_TEXTS)
  612. return -EINVAL;
  613. se->dobj.control.dvalues = devm_kcalloc(tplg->dev, le32_to_cpu(ec->items),
  614. sizeof(*se->dobj.control.dvalues),
  615. GFP_KERNEL);
  616. if (!se->dobj.control.dvalues)
  617. return -ENOMEM;
  618. /* convert from little-endian */
  619. for (i = 0; i < le32_to_cpu(ec->items); i++) {
  620. se->dobj.control.dvalues[i] = le32_to_cpu(ec->values[i]);
  621. }
  622. se->items = le32_to_cpu(ec->items);
  623. se->values = (const unsigned int *)se->dobj.control.dvalues;
  624. return 0;
  625. }
  626. static int soc_tplg_control_denum_create(struct soc_tplg *tplg, struct snd_kcontrol_new *kc)
  627. {
  628. struct snd_soc_tplg_enum_control *ec;
  629. struct soc_enum *se;
  630. int err;
  631. ec = (struct snd_soc_tplg_enum_control *)tplg->pos;
  632. /* validate kcontrol */
  633. if (strnlen(ec->hdr.name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) == SNDRV_CTL_ELEM_ID_NAME_MAXLEN)
  634. return -EINVAL;
  635. se = devm_kzalloc(tplg->dev, sizeof(*se), GFP_KERNEL);
  636. if (!se)
  637. return -ENOMEM;
  638. tplg->pos += (sizeof(struct snd_soc_tplg_enum_control) + le32_to_cpu(ec->priv.size));
  639. dev_dbg(tplg->dev, "ASoC: adding enum kcontrol %s size %d\n", ec->hdr.name, ec->items);
  640. kc->name = devm_kstrdup(tplg->dev, ec->hdr.name, GFP_KERNEL);
  641. if (!kc->name)
  642. return -ENOMEM;
  643. kc->private_value = (long)se;
  644. kc->iface = SNDRV_CTL_ELEM_IFACE_MIXER;
  645. kc->access = le32_to_cpu(ec->hdr.access);
  646. /* we only support FL/FR channel mapping atm */
  647. se->reg = tplg_chan_get_reg(tplg, ec->channel, SNDRV_CHMAP_FL);
  648. se->shift_l = tplg_chan_get_shift(tplg, ec->channel, SNDRV_CHMAP_FL);
  649. se->shift_r = tplg_chan_get_shift(tplg, ec->channel, SNDRV_CHMAP_FR);
  650. se->mask = le32_to_cpu(ec->mask);
  651. switch (le32_to_cpu(ec->hdr.ops.info)) {
  652. case SND_SOC_TPLG_CTL_ENUM_VALUE:
  653. case SND_SOC_TPLG_DAPM_CTL_ENUM_VALUE:
  654. err = soc_tplg_denum_create_values(tplg, se, ec);
  655. if (err < 0) {
  656. dev_err(tplg->dev, "ASoC: could not create values for %s\n", ec->hdr.name);
  657. return err;
  658. }
  659. fallthrough;
  660. case SND_SOC_TPLG_CTL_ENUM:
  661. case SND_SOC_TPLG_DAPM_CTL_ENUM_DOUBLE:
  662. case SND_SOC_TPLG_DAPM_CTL_ENUM_VIRT:
  663. err = soc_tplg_denum_create_texts(tplg, se, ec);
  664. if (err < 0) {
  665. dev_err(tplg->dev, "ASoC: could not create texts for %s\n", ec->hdr.name);
  666. return err;
  667. }
  668. break;
  669. default:
  670. dev_err(tplg->dev, "ASoC: invalid enum control type %d for %s\n",
  671. ec->hdr.ops.info, ec->hdr.name);
  672. return -EINVAL;
  673. }
  674. /* map io handlers */
  675. err = soc_tplg_kcontrol_bind_io(&ec->hdr, kc, tplg);
  676. if (err) {
  677. soc_control_err(tplg, &ec->hdr, ec->hdr.name);
  678. return err;
  679. }
  680. /* pass control to driver for optional further init */
  681. return soc_tplg_control_load(tplg, kc, &ec->hdr);
  682. }
  683. static int soc_tplg_control_dbytes_create(struct soc_tplg *tplg, struct snd_kcontrol_new *kc)
  684. {
  685. struct snd_soc_tplg_bytes_control *be;
  686. struct soc_bytes_ext *sbe;
  687. int err;
  688. be = (struct snd_soc_tplg_bytes_control *)tplg->pos;
  689. /* validate kcontrol */
  690. if (strnlen(be->hdr.name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) == SNDRV_CTL_ELEM_ID_NAME_MAXLEN)
  691. return -EINVAL;
  692. sbe = devm_kzalloc(tplg->dev, sizeof(*sbe), GFP_KERNEL);
  693. if (!sbe)
  694. return -ENOMEM;
  695. tplg->pos += (sizeof(struct snd_soc_tplg_bytes_control) + le32_to_cpu(be->priv.size));
  696. dev_dbg(tplg->dev, "ASoC: adding bytes kcontrol %s with access 0x%x\n",
  697. be->hdr.name, be->hdr.access);
  698. kc->name = devm_kstrdup(tplg->dev, be->hdr.name, GFP_KERNEL);
  699. if (!kc->name)
  700. return -ENOMEM;
  701. kc->private_value = (long)sbe;
  702. kc->iface = SNDRV_CTL_ELEM_IFACE_MIXER;
  703. kc->access = le32_to_cpu(be->hdr.access);
  704. sbe->max = le32_to_cpu(be->max);
  705. /* map standard io handlers and check for external handlers */
  706. err = soc_tplg_kcontrol_bind_io(&be->hdr, kc, tplg);
  707. if (err) {
  708. soc_control_err(tplg, &be->hdr, be->hdr.name);
  709. return err;
  710. }
  711. /* pass control to driver for optional further init */
  712. return soc_tplg_control_load(tplg, kc, &be->hdr);
  713. }
  714. static int soc_tplg_dbytes_create(struct soc_tplg *tplg, size_t size)
  715. {
  716. struct snd_kcontrol_new kc = {0};
  717. struct soc_bytes_ext *sbe;
  718. int ret;
  719. if (soc_tplg_check_elem_count(tplg,
  720. sizeof(struct snd_soc_tplg_bytes_control),
  721. 1, size, "mixer bytes"))
  722. return -EINVAL;
  723. ret = soc_tplg_control_dbytes_create(tplg, &kc);
  724. if (ret)
  725. return ret;
  726. /* register dynamic object */
  727. sbe = (struct soc_bytes_ext *)kc.private_value;
  728. INIT_LIST_HEAD(&sbe->dobj.list);
  729. sbe->dobj.type = SND_SOC_DOBJ_BYTES;
  730. sbe->dobj.index = tplg->index;
  731. if (tplg->ops)
  732. sbe->dobj.unload = tplg->ops->control_unload;
  733. /* create control directly */
  734. ret = soc_tplg_add_kcontrol(tplg, &kc, &sbe->dobj.control.kcontrol);
  735. if (ret < 0)
  736. return ret;
  737. list_add(&sbe->dobj.list, &tplg->comp->dobj_list);
  738. return ret;
  739. }
  740. static int soc_tplg_dmixer_create(struct soc_tplg *tplg, size_t size)
  741. {
  742. struct snd_kcontrol_new kc = {0};
  743. struct soc_mixer_control *sm;
  744. int ret;
  745. if (soc_tplg_check_elem_count(tplg,
  746. sizeof(struct snd_soc_tplg_mixer_control),
  747. 1, size, "mixers"))
  748. return -EINVAL;
  749. ret = soc_tplg_control_dmixer_create(tplg, &kc);
  750. if (ret)
  751. return ret;
  752. /* register dynamic object */
  753. sm = (struct soc_mixer_control *)kc.private_value;
  754. INIT_LIST_HEAD(&sm->dobj.list);
  755. sm->dobj.type = SND_SOC_DOBJ_MIXER;
  756. sm->dobj.index = tplg->index;
  757. if (tplg->ops)
  758. sm->dobj.unload = tplg->ops->control_unload;
  759. /* create control directly */
  760. ret = soc_tplg_add_kcontrol(tplg, &kc, &sm->dobj.control.kcontrol);
  761. if (ret < 0)
  762. return ret;
  763. list_add(&sm->dobj.list, &tplg->comp->dobj_list);
  764. return ret;
  765. }
  766. static int soc_tplg_denum_create(struct soc_tplg *tplg, size_t size)
  767. {
  768. struct snd_kcontrol_new kc = {0};
  769. struct soc_enum *se;
  770. int ret;
  771. if (soc_tplg_check_elem_count(tplg,
  772. sizeof(struct snd_soc_tplg_enum_control),
  773. 1, size, "enums"))
  774. return -EINVAL;
  775. ret = soc_tplg_control_denum_create(tplg, &kc);
  776. if (ret)
  777. return ret;
  778. /* register dynamic object */
  779. se = (struct soc_enum *)kc.private_value;
  780. INIT_LIST_HEAD(&se->dobj.list);
  781. se->dobj.type = SND_SOC_DOBJ_ENUM;
  782. se->dobj.index = tplg->index;
  783. if (tplg->ops)
  784. se->dobj.unload = tplg->ops->control_unload;
  785. /* create control directly */
  786. ret = soc_tplg_add_kcontrol(tplg, &kc, &se->dobj.control.kcontrol);
  787. if (ret < 0)
  788. return ret;
  789. list_add(&se->dobj.list, &tplg->comp->dobj_list);
  790. return ret;
  791. }
  792. static int soc_tplg_kcontrol_elems_load(struct soc_tplg *tplg,
  793. struct snd_soc_tplg_hdr *hdr)
  794. {
  795. int ret;
  796. int i;
  797. dev_dbg(tplg->dev, "ASoC: adding %d kcontrols at 0x%lx\n", hdr->count,
  798. soc_tplg_get_offset(tplg));
  799. for (i = 0; i < le32_to_cpu(hdr->count); i++) {
  800. struct snd_soc_tplg_ctl_hdr *control_hdr = (struct snd_soc_tplg_ctl_hdr *)tplg->pos;
  801. if (le32_to_cpu(control_hdr->size) != sizeof(*control_hdr)) {
  802. dev_err(tplg->dev, "ASoC: invalid control size\n");
  803. return -EINVAL;
  804. }
  805. switch (le32_to_cpu(control_hdr->type)) {
  806. case SND_SOC_TPLG_TYPE_MIXER:
  807. ret = soc_tplg_dmixer_create(tplg, le32_to_cpu(hdr->payload_size));
  808. break;
  809. case SND_SOC_TPLG_TYPE_ENUM:
  810. ret = soc_tplg_denum_create(tplg, le32_to_cpu(hdr->payload_size));
  811. break;
  812. case SND_SOC_TPLG_TYPE_BYTES:
  813. ret = soc_tplg_dbytes_create(tplg, le32_to_cpu(hdr->payload_size));
  814. break;
  815. default:
  816. ret = -EINVAL;
  817. break;
  818. }
  819. if (ret < 0) {
  820. dev_err(tplg->dev, "ASoC: invalid control type: %d, index: %d at 0x%lx\n",
  821. control_hdr->type, i, soc_tplg_get_offset(tplg));
  822. return ret;
  823. }
  824. }
  825. return 0;
  826. }
  827. /* optionally pass new dynamic kcontrol to component driver. */
  828. static int soc_tplg_add_route(struct soc_tplg *tplg,
  829. struct snd_soc_dapm_route *route)
  830. {
  831. if (tplg->ops && tplg->ops->dapm_route_load)
  832. return tplg->ops->dapm_route_load(tplg->comp, tplg->index,
  833. route);
  834. return 0;
  835. }
  836. static int soc_tplg_dapm_graph_elems_load(struct soc_tplg *tplg,
  837. struct snd_soc_tplg_hdr *hdr)
  838. {
  839. struct snd_soc_dapm_context *dapm = snd_soc_component_to_dapm(tplg->comp);
  840. const size_t maxlen = SNDRV_CTL_ELEM_ID_NAME_MAXLEN;
  841. struct snd_soc_tplg_dapm_graph_elem *elem;
  842. struct snd_soc_dapm_route *route;
  843. int count, i;
  844. int ret = 0;
  845. count = le32_to_cpu(hdr->count);
  846. if (soc_tplg_check_elem_count(tplg,
  847. sizeof(struct snd_soc_tplg_dapm_graph_elem),
  848. count, le32_to_cpu(hdr->payload_size), "graph"))
  849. return -EINVAL;
  850. dev_dbg(tplg->dev, "ASoC: adding %d DAPM routes for index %d\n", count,
  851. hdr->index);
  852. for (i = 0; i < count; i++) {
  853. route = devm_kzalloc(tplg->dev, sizeof(*route), GFP_KERNEL);
  854. if (!route)
  855. return -ENOMEM;
  856. elem = (struct snd_soc_tplg_dapm_graph_elem *)tplg->pos;
  857. tplg->pos += sizeof(struct snd_soc_tplg_dapm_graph_elem);
  858. /* validate routes */
  859. if ((strnlen(elem->source, maxlen) == maxlen) ||
  860. (strnlen(elem->sink, maxlen) == maxlen) ||
  861. (strnlen(elem->control, maxlen) == maxlen)) {
  862. ret = -EINVAL;
  863. break;
  864. }
  865. route->source = devm_kstrdup(tplg->dev, elem->source, GFP_KERNEL);
  866. route->sink = devm_kstrdup(tplg->dev, elem->sink, GFP_KERNEL);
  867. if (!route->source || !route->sink) {
  868. ret = -ENOMEM;
  869. break;
  870. }
  871. if (strnlen(elem->control, maxlen) != 0) {
  872. route->control = devm_kstrdup(tplg->dev, elem->control, GFP_KERNEL);
  873. if (!route->control) {
  874. ret = -ENOMEM;
  875. break;
  876. }
  877. }
  878. /* add route dobj to dobj_list */
  879. route->dobj.type = SND_SOC_DOBJ_GRAPH;
  880. if (tplg->ops)
  881. route->dobj.unload = tplg->ops->dapm_route_unload;
  882. route->dobj.index = tplg->index;
  883. list_add(&route->dobj.list, &tplg->comp->dobj_list);
  884. ret = soc_tplg_add_route(tplg, route);
  885. if (ret < 0) {
  886. dev_err(tplg->dev, "ASoC: topology: add_route failed: %d\n", ret);
  887. break;
  888. }
  889. ret = snd_soc_dapm_add_routes(dapm, route, 1);
  890. if (ret)
  891. break;
  892. }
  893. return ret;
  894. }
  895. static int soc_tplg_dapm_widget_create(struct soc_tplg *tplg,
  896. struct snd_soc_tplg_dapm_widget *w)
  897. {
  898. struct snd_soc_dapm_context *dapm = snd_soc_component_to_dapm(tplg->comp);
  899. struct snd_soc_dapm_widget template, *widget;
  900. struct snd_soc_tplg_ctl_hdr *control_hdr;
  901. struct snd_soc_card *card = tplg->comp->card;
  902. unsigned int *kcontrol_type = NULL;
  903. struct snd_kcontrol_new *kc;
  904. int mixer_count = 0;
  905. int bytes_count = 0;
  906. int enum_count = 0;
  907. int ret = 0;
  908. int i;
  909. if (strnlen(w->name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) ==
  910. SNDRV_CTL_ELEM_ID_NAME_MAXLEN)
  911. return -EINVAL;
  912. if (strnlen(w->sname, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) ==
  913. SNDRV_CTL_ELEM_ID_NAME_MAXLEN)
  914. return -EINVAL;
  915. dev_dbg(tplg->dev, "ASoC: creating DAPM widget %s id %d\n",
  916. w->name, w->id);
  917. memset(&template, 0, sizeof(template));
  918. /* map user to kernel widget ID */
  919. template.id = get_widget_id(le32_to_cpu(w->id));
  920. if ((int)template.id < 0)
  921. return template.id;
  922. /* strings are allocated here, but used and freed by the widget */
  923. template.name = kstrdup(w->name, GFP_KERNEL);
  924. if (!template.name)
  925. return -ENOMEM;
  926. template.sname = kstrdup(w->sname, GFP_KERNEL);
  927. if (!template.sname) {
  928. ret = -ENOMEM;
  929. goto err;
  930. }
  931. template.reg = le32_to_cpu(w->reg);
  932. template.shift = le32_to_cpu(w->shift);
  933. template.mask = le32_to_cpu(w->mask);
  934. template.subseq = le32_to_cpu(w->subseq);
  935. template.on_val = w->invert ? 0 : 1;
  936. template.off_val = w->invert ? 1 : 0;
  937. template.ignore_suspend = le32_to_cpu(w->ignore_suspend);
  938. template.event_flags = le16_to_cpu(w->event_flags);
  939. template.dobj.index = tplg->index;
  940. tplg->pos +=
  941. (sizeof(struct snd_soc_tplg_dapm_widget) +
  942. le32_to_cpu(w->priv.size));
  943. if (w->num_kcontrols == 0) {
  944. template.num_kcontrols = 0;
  945. goto widget;
  946. }
  947. template.num_kcontrols = le32_to_cpu(w->num_kcontrols);
  948. kc = devm_kcalloc(tplg->dev, le32_to_cpu(w->num_kcontrols), sizeof(*kc), GFP_KERNEL);
  949. if (!kc) {
  950. ret = -ENOMEM;
  951. goto hdr_err;
  952. }
  953. kcontrol_type = devm_kcalloc(tplg->dev, le32_to_cpu(w->num_kcontrols), sizeof(unsigned int),
  954. GFP_KERNEL);
  955. if (!kcontrol_type) {
  956. ret = -ENOMEM;
  957. goto hdr_err;
  958. }
  959. for (i = 0; i < le32_to_cpu(w->num_kcontrols); i++) {
  960. control_hdr = (struct snd_soc_tplg_ctl_hdr *)tplg->pos;
  961. switch (le32_to_cpu(control_hdr->type)) {
  962. case SND_SOC_TPLG_TYPE_MIXER:
  963. /* volume mixer */
  964. kc[i].index = mixer_count;
  965. kcontrol_type[i] = SND_SOC_TPLG_TYPE_MIXER;
  966. mixer_count++;
  967. ret = soc_tplg_control_dmixer_create(tplg, &kc[i]);
  968. if (ret < 0)
  969. goto hdr_err;
  970. break;
  971. case SND_SOC_TPLG_TYPE_ENUM:
  972. /* enumerated mixer */
  973. kc[i].index = enum_count;
  974. kcontrol_type[i] = SND_SOC_TPLG_TYPE_ENUM;
  975. enum_count++;
  976. ret = soc_tplg_control_denum_create(tplg, &kc[i]);
  977. if (ret < 0)
  978. goto hdr_err;
  979. break;
  980. case SND_SOC_TPLG_TYPE_BYTES:
  981. /* bytes control */
  982. kc[i].index = bytes_count;
  983. kcontrol_type[i] = SND_SOC_TPLG_TYPE_BYTES;
  984. bytes_count++;
  985. ret = soc_tplg_control_dbytes_create(tplg, &kc[i]);
  986. if (ret < 0)
  987. goto hdr_err;
  988. break;
  989. default:
  990. dev_err(tplg->dev, "ASoC: invalid widget control type %d:%d:%d\n",
  991. control_hdr->ops.get, control_hdr->ops.put,
  992. le32_to_cpu(control_hdr->ops.info));
  993. ret = -EINVAL;
  994. goto hdr_err;
  995. }
  996. }
  997. template.kcontrol_news = kc;
  998. dev_dbg(tplg->dev, "ASoC: template %s with %d/%d/%d (mixer/enum/bytes) control\n",
  999. w->name, mixer_count, enum_count, bytes_count);
  1000. widget:
  1001. ret = soc_tplg_widget_load(tplg, &template, w);
  1002. if (ret < 0)
  1003. goto hdr_err;
  1004. /* card dapm mutex is held by the core if we are loading topology
  1005. * data during sound card init. */
  1006. if (snd_soc_card_is_instantiated(card))
  1007. widget = snd_soc_dapm_new_control(dapm, &template);
  1008. else
  1009. widget = snd_soc_dapm_new_control_unlocked(dapm, &template);
  1010. if (IS_ERR(widget)) {
  1011. ret = PTR_ERR(widget);
  1012. goto hdr_err;
  1013. }
  1014. widget->dobj.type = SND_SOC_DOBJ_WIDGET;
  1015. widget->dobj.widget.kcontrol_type = kcontrol_type;
  1016. if (tplg->ops)
  1017. widget->dobj.unload = tplg->ops->widget_unload;
  1018. widget->dobj.index = tplg->index;
  1019. list_add(&widget->dobj.list, &tplg->comp->dobj_list);
  1020. ret = soc_tplg_widget_ready(tplg, widget, w);
  1021. if (ret < 0)
  1022. goto ready_err;
  1023. kfree(template.sname);
  1024. kfree(template.name);
  1025. return 0;
  1026. ready_err:
  1027. soc_tplg_remove_widget(snd_soc_dapm_to_component(widget->dapm),
  1028. &widget->dobj, SOC_TPLG_PASS_WIDGET);
  1029. snd_soc_dapm_free_widget(widget);
  1030. hdr_err:
  1031. kfree(template.sname);
  1032. err:
  1033. kfree(template.name);
  1034. return ret;
  1035. }
  1036. static int soc_tplg_dapm_widget_elems_load(struct soc_tplg *tplg,
  1037. struct snd_soc_tplg_hdr *hdr)
  1038. {
  1039. int count, i;
  1040. count = le32_to_cpu(hdr->count);
  1041. dev_dbg(tplg->dev, "ASoC: adding %d DAPM widgets\n", count);
  1042. for (i = 0; i < count; i++) {
  1043. struct snd_soc_tplg_dapm_widget *widget = (struct snd_soc_tplg_dapm_widget *) tplg->pos;
  1044. int ret;
  1045. /*
  1046. * check if widget itself fits within topology file
  1047. * use sizeof instead of widget->size, as we can't be sure
  1048. * it is set properly yet (file may end before it is present)
  1049. */
  1050. if (soc_tplg_get_offset(tplg) + sizeof(*widget) >= tplg->fw->size) {
  1051. dev_err(tplg->dev, "ASoC: invalid widget data size\n");
  1052. return -EINVAL;
  1053. }
  1054. /* check if widget has proper size */
  1055. if (le32_to_cpu(widget->size) != sizeof(*widget)) {
  1056. dev_err(tplg->dev, "ASoC: invalid widget size\n");
  1057. return -EINVAL;
  1058. }
  1059. /* check if widget private data fits within topology file */
  1060. if (soc_tplg_get_offset(tplg) + le32_to_cpu(widget->priv.size) >= tplg->fw->size) {
  1061. dev_err(tplg->dev, "ASoC: invalid widget private data size\n");
  1062. return -EINVAL;
  1063. }
  1064. ret = soc_tplg_dapm_widget_create(tplg, widget);
  1065. if (ret < 0) {
  1066. dev_err(tplg->dev, "ASoC: failed to load widget %s\n",
  1067. widget->name);
  1068. return ret;
  1069. }
  1070. }
  1071. return 0;
  1072. }
  1073. static int soc_tplg_dapm_complete(struct soc_tplg *tplg)
  1074. {
  1075. struct snd_soc_card *card = tplg->comp->card;
  1076. int ret;
  1077. /* Card might not have been registered at this point.
  1078. * If so, just return success.
  1079. */
  1080. if (!snd_soc_card_is_instantiated(card)) {
  1081. dev_warn(tplg->dev, "ASoC: Parent card not yet available, widget card binding deferred\n");
  1082. return 0;
  1083. }
  1084. ret = snd_soc_dapm_new_widgets(card);
  1085. if (ret < 0)
  1086. dev_err(tplg->dev, "ASoC: failed to create new widgets %d\n", ret);
  1087. return ret;
  1088. }
  1089. static int set_stream_info(struct soc_tplg *tplg, struct snd_soc_pcm_stream *stream,
  1090. struct snd_soc_tplg_stream_caps *caps)
  1091. {
  1092. stream->stream_name = devm_kstrdup(tplg->dev, caps->name, GFP_KERNEL);
  1093. if (!stream->stream_name)
  1094. return -ENOMEM;
  1095. stream->channels_min = le32_to_cpu(caps->channels_min);
  1096. stream->channels_max = le32_to_cpu(caps->channels_max);
  1097. stream->rates = le32_to_cpu(caps->rates);
  1098. stream->rate_min = le32_to_cpu(caps->rate_min);
  1099. stream->rate_max = le32_to_cpu(caps->rate_max);
  1100. stream->formats = le64_to_cpu(caps->formats);
  1101. stream->sig_bits = le32_to_cpu(caps->sig_bits);
  1102. return 0;
  1103. }
  1104. static void set_dai_flags(struct snd_soc_dai_driver *dai_drv,
  1105. unsigned int flag_mask, unsigned int flags)
  1106. {
  1107. if (flag_mask & SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_RATES)
  1108. dai_drv->symmetric_rate =
  1109. (flags & SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_RATES) ? 1 : 0;
  1110. if (flag_mask & SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_CHANNELS)
  1111. dai_drv->symmetric_channels =
  1112. (flags & SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_CHANNELS) ?
  1113. 1 : 0;
  1114. if (flag_mask & SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_SAMPLEBITS)
  1115. dai_drv->symmetric_sample_bits =
  1116. (flags & SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_SAMPLEBITS) ?
  1117. 1 : 0;
  1118. }
  1119. static const struct snd_soc_dai_ops tplg_dai_ops = {
  1120. .compress_new = snd_soc_new_compress,
  1121. };
  1122. static int soc_tplg_dai_create(struct soc_tplg *tplg,
  1123. struct snd_soc_tplg_pcm *pcm)
  1124. {
  1125. struct snd_soc_dai_driver *dai_drv;
  1126. struct snd_soc_pcm_stream *stream;
  1127. struct snd_soc_tplg_stream_caps *caps;
  1128. struct snd_soc_dai *dai;
  1129. struct snd_soc_dapm_context *dapm = snd_soc_component_to_dapm(tplg->comp);
  1130. int ret;
  1131. dai_drv = devm_kzalloc(tplg->dev, sizeof(struct snd_soc_dai_driver), GFP_KERNEL);
  1132. if (dai_drv == NULL)
  1133. return -ENOMEM;
  1134. if (strlen(pcm->dai_name)) {
  1135. dai_drv->name = devm_kstrdup(tplg->dev, pcm->dai_name, GFP_KERNEL);
  1136. if (!dai_drv->name) {
  1137. ret = -ENOMEM;
  1138. goto err;
  1139. }
  1140. }
  1141. dai_drv->id = le32_to_cpu(pcm->dai_id);
  1142. if (pcm->playback) {
  1143. stream = &dai_drv->playback;
  1144. caps = &pcm->caps[SND_SOC_TPLG_STREAM_PLAYBACK];
  1145. ret = set_stream_info(tplg, stream, caps);
  1146. if (ret < 0)
  1147. goto err;
  1148. }
  1149. if (pcm->capture) {
  1150. stream = &dai_drv->capture;
  1151. caps = &pcm->caps[SND_SOC_TPLG_STREAM_CAPTURE];
  1152. ret = set_stream_info(tplg, stream, caps);
  1153. if (ret < 0)
  1154. goto err;
  1155. }
  1156. if (pcm->compress)
  1157. dai_drv->ops = &tplg_dai_ops;
  1158. /* pass control to component driver for optional further init */
  1159. ret = soc_tplg_dai_load(tplg, dai_drv, pcm, NULL);
  1160. if (ret < 0) {
  1161. dev_err(tplg->dev, "ASoC: DAI loading failed\n");
  1162. goto err;
  1163. }
  1164. dai_drv->dobj.index = tplg->index;
  1165. dai_drv->dobj.type = SND_SOC_DOBJ_PCM;
  1166. if (tplg->ops)
  1167. dai_drv->dobj.unload = tplg->ops->dai_unload;
  1168. list_add(&dai_drv->dobj.list, &tplg->comp->dobj_list);
  1169. /* register the DAI to the component */
  1170. dai = snd_soc_register_dai(tplg->comp, dai_drv, false);
  1171. if (!dai)
  1172. return -ENOMEM;
  1173. /* Create the DAI widgets here */
  1174. ret = snd_soc_dapm_new_dai_widgets(dapm, dai);
  1175. if (ret != 0) {
  1176. dev_err(dai->dev, "Failed to create DAI widgets %d\n", ret);
  1177. snd_soc_unregister_dai(dai);
  1178. return ret;
  1179. }
  1180. return 0;
  1181. err:
  1182. return ret;
  1183. }
  1184. static void set_link_flags(struct snd_soc_dai_link *link,
  1185. unsigned int flag_mask, unsigned int flags)
  1186. {
  1187. if (flag_mask & SND_SOC_TPLG_LNK_FLGBIT_SYMMETRIC_RATES)
  1188. link->symmetric_rate =
  1189. (flags & SND_SOC_TPLG_LNK_FLGBIT_SYMMETRIC_RATES) ? 1 : 0;
  1190. if (flag_mask & SND_SOC_TPLG_LNK_FLGBIT_SYMMETRIC_CHANNELS)
  1191. link->symmetric_channels =
  1192. (flags & SND_SOC_TPLG_LNK_FLGBIT_SYMMETRIC_CHANNELS) ?
  1193. 1 : 0;
  1194. if (flag_mask & SND_SOC_TPLG_LNK_FLGBIT_SYMMETRIC_SAMPLEBITS)
  1195. link->symmetric_sample_bits =
  1196. (flags & SND_SOC_TPLG_LNK_FLGBIT_SYMMETRIC_SAMPLEBITS) ?
  1197. 1 : 0;
  1198. if (flag_mask & SND_SOC_TPLG_LNK_FLGBIT_VOICE_WAKEUP)
  1199. link->ignore_suspend =
  1200. (flags & SND_SOC_TPLG_LNK_FLGBIT_VOICE_WAKEUP) ?
  1201. 1 : 0;
  1202. }
  1203. /* create the FE DAI link */
  1204. static int soc_tplg_fe_link_create(struct soc_tplg *tplg,
  1205. struct snd_soc_tplg_pcm *pcm)
  1206. {
  1207. struct snd_soc_dai_link *link;
  1208. struct snd_soc_dai_link_component *dlc;
  1209. int ret;
  1210. /* link + cpu + codec + platform */
  1211. link = devm_kzalloc(tplg->dev, sizeof(*link) + (3 * sizeof(*dlc)), GFP_KERNEL);
  1212. if (link == NULL)
  1213. return -ENOMEM;
  1214. dlc = (struct snd_soc_dai_link_component *)(link + 1);
  1215. link->cpus = &dlc[0];
  1216. link->num_cpus = 1;
  1217. link->dobj.index = tplg->index;
  1218. link->dobj.type = SND_SOC_DOBJ_DAI_LINK;
  1219. if (tplg->ops)
  1220. link->dobj.unload = tplg->ops->link_unload;
  1221. if (strlen(pcm->pcm_name)) {
  1222. link->name = devm_kstrdup(tplg->dev, pcm->pcm_name, GFP_KERNEL);
  1223. link->stream_name = devm_kstrdup(tplg->dev, pcm->pcm_name, GFP_KERNEL);
  1224. if (!link->name || !link->stream_name) {
  1225. ret = -ENOMEM;
  1226. goto err;
  1227. }
  1228. }
  1229. link->id = le32_to_cpu(pcm->pcm_id);
  1230. if (strlen(pcm->dai_name)) {
  1231. link->cpus->dai_name = devm_kstrdup(tplg->dev, pcm->dai_name, GFP_KERNEL);
  1232. if (!link->cpus->dai_name) {
  1233. ret = -ENOMEM;
  1234. goto err;
  1235. }
  1236. }
  1237. /*
  1238. * Many topology are assuming link has Codec / Platform, and
  1239. * these might be overwritten at soc_tplg_dai_link_load().
  1240. * Don't use &snd_soc_dummy_dlc here.
  1241. */
  1242. link->codecs = &dlc[1]; /* Don't use &snd_soc_dummy_dlc here */
  1243. link->codecs->name = "snd-soc-dummy";
  1244. link->codecs->dai_name = "snd-soc-dummy-dai";
  1245. link->num_codecs = 1;
  1246. link->platforms = &dlc[2]; /* Don't use &snd_soc_dummy_dlc here */
  1247. link->platforms->name = "snd-soc-dummy";
  1248. link->num_platforms = 1;
  1249. /* enable DPCM */
  1250. link->dynamic = 1;
  1251. link->ignore_pmdown_time = 1;
  1252. link->playback_only = le32_to_cpu(pcm->playback) && !le32_to_cpu(pcm->capture);
  1253. link->capture_only = !le32_to_cpu(pcm->playback) && le32_to_cpu(pcm->capture);
  1254. if (pcm->flag_mask)
  1255. set_link_flags(link,
  1256. le32_to_cpu(pcm->flag_mask),
  1257. le32_to_cpu(pcm->flags));
  1258. /* pass control to component driver for optional further init */
  1259. ret = soc_tplg_dai_link_load(tplg, link, NULL);
  1260. if (ret < 0) {
  1261. dev_err(tplg->dev, "ASoC: FE link loading failed\n");
  1262. goto err;
  1263. }
  1264. ret = snd_soc_add_pcm_runtimes(tplg->comp->card, link, 1);
  1265. if (ret < 0) {
  1266. if (ret != -EPROBE_DEFER)
  1267. dev_err(tplg->dev, "ASoC: adding FE link failed\n");
  1268. goto err;
  1269. }
  1270. list_add(&link->dobj.list, &tplg->comp->dobj_list);
  1271. return 0;
  1272. err:
  1273. return ret;
  1274. }
  1275. /* create a FE DAI and DAI link from the PCM object */
  1276. static int soc_tplg_pcm_create(struct soc_tplg *tplg,
  1277. struct snd_soc_tplg_pcm *pcm)
  1278. {
  1279. int ret;
  1280. ret = soc_tplg_dai_create(tplg, pcm);
  1281. if (ret < 0)
  1282. return ret;
  1283. return soc_tplg_fe_link_create(tplg, pcm);
  1284. }
  1285. static int soc_tplg_pcm_elems_load(struct soc_tplg *tplg,
  1286. struct snd_soc_tplg_hdr *hdr)
  1287. {
  1288. struct snd_soc_tplg_pcm *pcm;
  1289. int count;
  1290. int size;
  1291. int i;
  1292. int ret;
  1293. count = le32_to_cpu(hdr->count);
  1294. /* check the element size and count */
  1295. pcm = (struct snd_soc_tplg_pcm *)tplg->pos;
  1296. size = le32_to_cpu(pcm->size);
  1297. if (size > sizeof(struct snd_soc_tplg_pcm)) {
  1298. dev_err(tplg->dev, "ASoC: invalid size %d for PCM elems\n",
  1299. size);
  1300. return -EINVAL;
  1301. }
  1302. if (soc_tplg_check_elem_count(tplg,
  1303. size, count,
  1304. le32_to_cpu(hdr->payload_size),
  1305. "PCM DAI"))
  1306. return -EINVAL;
  1307. for (i = 0; i < count; i++) {
  1308. pcm = (struct snd_soc_tplg_pcm *)tplg->pos;
  1309. size = le32_to_cpu(pcm->size);
  1310. /* check ABI version by size, create a new version of pcm
  1311. * if abi not match.
  1312. */
  1313. if (size != sizeof(*pcm))
  1314. return -EINVAL;
  1315. /* create the FE DAIs and DAI links */
  1316. ret = soc_tplg_pcm_create(tplg, pcm);
  1317. if (ret < 0)
  1318. return ret;
  1319. /* offset by version-specific struct size and
  1320. * real priv data size
  1321. */
  1322. tplg->pos += size + le32_to_cpu(pcm->priv.size);
  1323. }
  1324. dev_dbg(tplg->dev, "ASoC: adding %d PCM DAIs\n", count);
  1325. return 0;
  1326. }
  1327. /**
  1328. * set_link_hw_format - Set the HW audio format of the physical DAI link.
  1329. * @link: &snd_soc_dai_link which should be updated
  1330. * @cfg: physical link configs.
  1331. *
  1332. * Topology context contains a list of supported HW formats (configs) and
  1333. * a default format ID for the physical link. This function will use this
  1334. * default ID to choose the HW format to set the link's DAI format for init.
  1335. */
  1336. static void set_link_hw_format(struct snd_soc_dai_link *link,
  1337. struct snd_soc_tplg_link_config *cfg)
  1338. {
  1339. struct snd_soc_tplg_hw_config *hw_config;
  1340. unsigned char bclk_provider, fsync_provider;
  1341. unsigned char invert_bclk, invert_fsync;
  1342. int i;
  1343. for (i = 0; i < le32_to_cpu(cfg->num_hw_configs); i++) {
  1344. hw_config = &cfg->hw_config[i];
  1345. if (hw_config->id != cfg->default_hw_config_id)
  1346. continue;
  1347. link->dai_fmt = le32_to_cpu(hw_config->fmt) &
  1348. SND_SOC_DAIFMT_FORMAT_MASK;
  1349. /* clock gating */
  1350. switch (hw_config->clock_gated) {
  1351. case SND_SOC_TPLG_DAI_CLK_GATE_GATED:
  1352. link->dai_fmt |= SND_SOC_DAIFMT_GATED;
  1353. break;
  1354. case SND_SOC_TPLG_DAI_CLK_GATE_CONT:
  1355. link->dai_fmt |= SND_SOC_DAIFMT_CONT;
  1356. break;
  1357. default:
  1358. /* ignore the value */
  1359. break;
  1360. }
  1361. /* clock signal polarity */
  1362. invert_bclk = hw_config->invert_bclk;
  1363. invert_fsync = hw_config->invert_fsync;
  1364. if (!invert_bclk && !invert_fsync)
  1365. link->dai_fmt |= SND_SOC_DAIFMT_NB_NF;
  1366. else if (!invert_bclk && invert_fsync)
  1367. link->dai_fmt |= SND_SOC_DAIFMT_NB_IF;
  1368. else if (invert_bclk && !invert_fsync)
  1369. link->dai_fmt |= SND_SOC_DAIFMT_IB_NF;
  1370. else
  1371. link->dai_fmt |= SND_SOC_DAIFMT_IB_IF;
  1372. /* clock masters */
  1373. bclk_provider = (hw_config->bclk_provider ==
  1374. SND_SOC_TPLG_BCLK_CP);
  1375. fsync_provider = (hw_config->fsync_provider ==
  1376. SND_SOC_TPLG_FSYNC_CP);
  1377. if (bclk_provider && fsync_provider)
  1378. link->dai_fmt |= SND_SOC_DAIFMT_CBP_CFP;
  1379. else if (!bclk_provider && fsync_provider)
  1380. link->dai_fmt |= SND_SOC_DAIFMT_CBC_CFP;
  1381. else if (bclk_provider && !fsync_provider)
  1382. link->dai_fmt |= SND_SOC_DAIFMT_CBP_CFC;
  1383. else
  1384. link->dai_fmt |= SND_SOC_DAIFMT_CBC_CFC;
  1385. }
  1386. }
  1387. /**
  1388. * snd_soc_find_dai_link - Find a DAI link
  1389. *
  1390. * @card: soc card
  1391. * @id: DAI link ID to match
  1392. * @name: DAI link name to match, optional
  1393. * @stream_name: DAI link stream name to match, optional
  1394. *
  1395. * This function will search all existing DAI links of the soc card to
  1396. * find the link of the same ID. Since DAI links may not have their
  1397. * unique ID, so name and stream name should also match if being
  1398. * specified.
  1399. *
  1400. * Return: pointer of DAI link, or NULL if not found.
  1401. */
  1402. static struct snd_soc_dai_link *snd_soc_find_dai_link(struct snd_soc_card *card,
  1403. int id, const char *name,
  1404. const char *stream_name)
  1405. {
  1406. struct snd_soc_pcm_runtime *rtd;
  1407. for_each_card_rtds(card, rtd) {
  1408. struct snd_soc_dai_link *link = rtd->dai_link;
  1409. if (link->id != id)
  1410. continue;
  1411. if (name && (!link->name || !strstr(link->name, name)))
  1412. continue;
  1413. if (stream_name && (!link->stream_name ||
  1414. !strstr(link->stream_name, stream_name)))
  1415. continue;
  1416. return link;
  1417. }
  1418. return NULL;
  1419. }
  1420. /* Find and configure an existing physical DAI link */
  1421. static int soc_tplg_link_config(struct soc_tplg *tplg,
  1422. struct snd_soc_tplg_link_config *cfg)
  1423. {
  1424. struct snd_soc_dai_link *link;
  1425. const char *name, *stream_name;
  1426. size_t len;
  1427. int ret;
  1428. len = strnlen(cfg->name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
  1429. if (len == SNDRV_CTL_ELEM_ID_NAME_MAXLEN)
  1430. return -EINVAL;
  1431. else if (len)
  1432. name = cfg->name;
  1433. else
  1434. name = NULL;
  1435. len = strnlen(cfg->stream_name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
  1436. if (len == SNDRV_CTL_ELEM_ID_NAME_MAXLEN)
  1437. return -EINVAL;
  1438. else if (len)
  1439. stream_name = cfg->stream_name;
  1440. else
  1441. stream_name = NULL;
  1442. link = snd_soc_find_dai_link(tplg->comp->card, le32_to_cpu(cfg->id),
  1443. name, stream_name);
  1444. if (!link) {
  1445. dev_err(tplg->dev, "ASoC: physical link %s (id %d) not exist\n",
  1446. name, cfg->id);
  1447. return -EINVAL;
  1448. }
  1449. /* hw format */
  1450. if (cfg->num_hw_configs)
  1451. set_link_hw_format(link, cfg);
  1452. /* flags */
  1453. if (cfg->flag_mask)
  1454. set_link_flags(link,
  1455. le32_to_cpu(cfg->flag_mask),
  1456. le32_to_cpu(cfg->flags));
  1457. /* pass control to component driver for optional further init */
  1458. ret = soc_tplg_dai_link_load(tplg, link, cfg);
  1459. if (ret < 0) {
  1460. dev_err(tplg->dev, "ASoC: physical link loading failed\n");
  1461. return ret;
  1462. }
  1463. /* for unloading it in snd_soc_tplg_component_remove */
  1464. link->dobj.index = tplg->index;
  1465. link->dobj.type = SND_SOC_DOBJ_BACKEND_LINK;
  1466. if (tplg->ops)
  1467. link->dobj.unload = tplg->ops->link_unload;
  1468. list_add(&link->dobj.list, &tplg->comp->dobj_list);
  1469. return 0;
  1470. }
  1471. /* Load physical link config elements from the topology context */
  1472. static int soc_tplg_link_elems_load(struct soc_tplg *tplg,
  1473. struct snd_soc_tplg_hdr *hdr)
  1474. {
  1475. struct snd_soc_tplg_link_config *link;
  1476. int count;
  1477. int size;
  1478. int i, ret;
  1479. count = le32_to_cpu(hdr->count);
  1480. /* check the element size and count */
  1481. link = (struct snd_soc_tplg_link_config *)tplg->pos;
  1482. size = le32_to_cpu(link->size);
  1483. if (size > sizeof(struct snd_soc_tplg_link_config)) {
  1484. dev_err(tplg->dev, "ASoC: invalid size %d for physical link elems\n",
  1485. size);
  1486. return -EINVAL;
  1487. }
  1488. if (soc_tplg_check_elem_count(tplg, size, count,
  1489. le32_to_cpu(hdr->payload_size),
  1490. "physical link config"))
  1491. return -EINVAL;
  1492. /* config physical DAI links */
  1493. for (i = 0; i < count; i++) {
  1494. link = (struct snd_soc_tplg_link_config *)tplg->pos;
  1495. size = le32_to_cpu(link->size);
  1496. if (size != sizeof(*link))
  1497. return -EINVAL;
  1498. ret = soc_tplg_link_config(tplg, link);
  1499. if (ret < 0)
  1500. return ret;
  1501. /* offset by version-specific struct size and
  1502. * real priv data size
  1503. */
  1504. tplg->pos += size + le32_to_cpu(link->priv.size);
  1505. }
  1506. return 0;
  1507. }
  1508. /**
  1509. * soc_tplg_dai_config - Find and configure an existing physical DAI.
  1510. * @tplg: topology context
  1511. * @d: physical DAI configs.
  1512. *
  1513. * The physical dai should already be registered by the platform driver.
  1514. * The platform driver should specify the DAI name and ID for matching.
  1515. */
  1516. static int soc_tplg_dai_config(struct soc_tplg *tplg,
  1517. struct snd_soc_tplg_dai *d)
  1518. {
  1519. struct snd_soc_dai_link_component dai_component;
  1520. struct snd_soc_dai *dai;
  1521. struct snd_soc_dai_driver *dai_drv;
  1522. struct snd_soc_pcm_stream *stream;
  1523. struct snd_soc_tplg_stream_caps *caps;
  1524. int ret;
  1525. memset(&dai_component, 0, sizeof(dai_component));
  1526. dai_component.dai_name = d->dai_name;
  1527. dai = snd_soc_find_dai(&dai_component);
  1528. if (!dai) {
  1529. dev_err(tplg->dev, "ASoC: physical DAI %s not registered\n",
  1530. d->dai_name);
  1531. return -EINVAL;
  1532. }
  1533. if (le32_to_cpu(d->dai_id) != dai->id) {
  1534. dev_err(tplg->dev, "ASoC: physical DAI %s id mismatch\n",
  1535. d->dai_name);
  1536. return -EINVAL;
  1537. }
  1538. dai_drv = dai->driver;
  1539. if (!dai_drv)
  1540. return -EINVAL;
  1541. if (d->playback) {
  1542. stream = &dai_drv->playback;
  1543. caps = &d->caps[SND_SOC_TPLG_STREAM_PLAYBACK];
  1544. ret = set_stream_info(tplg, stream, caps);
  1545. if (ret < 0)
  1546. return ret;
  1547. }
  1548. if (d->capture) {
  1549. stream = &dai_drv->capture;
  1550. caps = &d->caps[SND_SOC_TPLG_STREAM_CAPTURE];
  1551. ret = set_stream_info(tplg, stream, caps);
  1552. if (ret < 0)
  1553. return ret;
  1554. }
  1555. if (d->flag_mask)
  1556. set_dai_flags(dai_drv,
  1557. le32_to_cpu(d->flag_mask),
  1558. le32_to_cpu(d->flags));
  1559. /* pass control to component driver for optional further init */
  1560. ret = soc_tplg_dai_load(tplg, dai_drv, NULL, dai);
  1561. if (ret < 0) {
  1562. dev_err(tplg->dev, "ASoC: DAI loading failed\n");
  1563. return ret;
  1564. }
  1565. return 0;
  1566. }
  1567. /* load physical DAI elements */
  1568. static int soc_tplg_dai_elems_load(struct soc_tplg *tplg,
  1569. struct snd_soc_tplg_hdr *hdr)
  1570. {
  1571. int count;
  1572. int i;
  1573. count = le32_to_cpu(hdr->count);
  1574. /* config the existing BE DAIs */
  1575. for (i = 0; i < count; i++) {
  1576. struct snd_soc_tplg_dai *dai = (struct snd_soc_tplg_dai *)tplg->pos;
  1577. int ret;
  1578. if (le32_to_cpu(dai->size) != sizeof(*dai)) {
  1579. dev_err(tplg->dev, "ASoC: invalid physical DAI size\n");
  1580. return -EINVAL;
  1581. }
  1582. ret = soc_tplg_dai_config(tplg, dai);
  1583. if (ret < 0) {
  1584. dev_err(tplg->dev, "ASoC: failed to configure DAI\n");
  1585. return ret;
  1586. }
  1587. tplg->pos += (sizeof(*dai) + le32_to_cpu(dai->priv.size));
  1588. }
  1589. dev_dbg(tplg->dev, "ASoC: Configure %d BE DAIs\n", count);
  1590. return 0;
  1591. }
  1592. static int soc_tplg_manifest_load(struct soc_tplg *tplg,
  1593. struct snd_soc_tplg_hdr *hdr)
  1594. {
  1595. struct snd_soc_tplg_manifest *manifest;
  1596. int ret = 0;
  1597. manifest = (struct snd_soc_tplg_manifest *)tplg->pos;
  1598. /* check ABI version by size, create a new manifest if abi not match */
  1599. if (le32_to_cpu(manifest->size) != sizeof(*manifest))
  1600. return -EINVAL;
  1601. /* pass control to component driver for optional further init */
  1602. if (tplg->ops && tplg->ops->manifest)
  1603. ret = tplg->ops->manifest(tplg->comp, tplg->index, manifest);
  1604. return ret;
  1605. }
  1606. /* validate header magic, size and type */
  1607. static int soc_tplg_valid_header(struct soc_tplg *tplg,
  1608. struct snd_soc_tplg_hdr *hdr)
  1609. {
  1610. if (le32_to_cpu(hdr->size) != sizeof(*hdr)) {
  1611. dev_err(tplg->dev,
  1612. "ASoC: invalid header size for type %d at offset 0x%lx size 0x%zx.\n",
  1613. le32_to_cpu(hdr->type), soc_tplg_get_hdr_offset(tplg),
  1614. tplg->fw->size);
  1615. return -EINVAL;
  1616. }
  1617. if (soc_tplg_get_hdr_offset(tplg) + le32_to_cpu(hdr->payload_size) >= tplg->fw->size) {
  1618. dev_err(tplg->dev,
  1619. "ASoC: invalid header of type %d at offset %ld payload_size %d\n",
  1620. le32_to_cpu(hdr->type), soc_tplg_get_hdr_offset(tplg),
  1621. hdr->payload_size);
  1622. return -EINVAL;
  1623. }
  1624. /* big endian firmware objects not supported atm */
  1625. if (le32_to_cpu(hdr->magic) == SOC_TPLG_MAGIC_BIG_ENDIAN) {
  1626. dev_err(tplg->dev,
  1627. "ASoC: pass %d big endian not supported header got %x at offset 0x%lx size 0x%zx.\n",
  1628. tplg->pass, hdr->magic,
  1629. soc_tplg_get_hdr_offset(tplg), tplg->fw->size);
  1630. return -EINVAL;
  1631. }
  1632. if (le32_to_cpu(hdr->magic) != SND_SOC_TPLG_MAGIC) {
  1633. dev_err(tplg->dev,
  1634. "ASoC: pass %d does not have a valid header got %x at offset 0x%lx size 0x%zx.\n",
  1635. tplg->pass, hdr->magic,
  1636. soc_tplg_get_hdr_offset(tplg), tplg->fw->size);
  1637. return -EINVAL;
  1638. }
  1639. /* Support ABI from version 4 */
  1640. if (le32_to_cpu(hdr->abi) > SND_SOC_TPLG_ABI_VERSION ||
  1641. le32_to_cpu(hdr->abi) < SND_SOC_TPLG_ABI_VERSION_MIN) {
  1642. dev_err(tplg->dev,
  1643. "ASoC: pass %d invalid ABI version got 0x%x need 0x%x at offset 0x%lx size 0x%zx.\n",
  1644. tplg->pass, hdr->abi,
  1645. SND_SOC_TPLG_ABI_VERSION, soc_tplg_get_hdr_offset(tplg),
  1646. tplg->fw->size);
  1647. return -EINVAL;
  1648. }
  1649. if (hdr->payload_size == 0) {
  1650. dev_err(tplg->dev, "ASoC: header has 0 size at offset 0x%lx.\n",
  1651. soc_tplg_get_hdr_offset(tplg));
  1652. return -EINVAL;
  1653. }
  1654. return 0;
  1655. }
  1656. /* check header type and call appropriate handler */
  1657. static int soc_tplg_load_header(struct soc_tplg *tplg,
  1658. struct snd_soc_tplg_hdr *hdr)
  1659. {
  1660. int (*elem_load)(struct soc_tplg *tplg,
  1661. struct snd_soc_tplg_hdr *hdr);
  1662. unsigned int hdr_pass;
  1663. tplg->pos = tplg->hdr_pos + sizeof(struct snd_soc_tplg_hdr);
  1664. tplg->index = le32_to_cpu(hdr->index);
  1665. switch (le32_to_cpu(hdr->type)) {
  1666. case SND_SOC_TPLG_TYPE_MIXER:
  1667. case SND_SOC_TPLG_TYPE_ENUM:
  1668. case SND_SOC_TPLG_TYPE_BYTES:
  1669. hdr_pass = SOC_TPLG_PASS_CONTROL;
  1670. elem_load = soc_tplg_kcontrol_elems_load;
  1671. break;
  1672. case SND_SOC_TPLG_TYPE_DAPM_GRAPH:
  1673. hdr_pass = SOC_TPLG_PASS_GRAPH;
  1674. elem_load = soc_tplg_dapm_graph_elems_load;
  1675. break;
  1676. case SND_SOC_TPLG_TYPE_DAPM_WIDGET:
  1677. hdr_pass = SOC_TPLG_PASS_WIDGET;
  1678. elem_load = soc_tplg_dapm_widget_elems_load;
  1679. break;
  1680. case SND_SOC_TPLG_TYPE_PCM:
  1681. hdr_pass = SOC_TPLG_PASS_PCM_DAI;
  1682. elem_load = soc_tplg_pcm_elems_load;
  1683. break;
  1684. case SND_SOC_TPLG_TYPE_DAI:
  1685. hdr_pass = SOC_TPLG_PASS_BE_DAI;
  1686. elem_load = soc_tplg_dai_elems_load;
  1687. break;
  1688. case SND_SOC_TPLG_TYPE_DAI_LINK:
  1689. case SND_SOC_TPLG_TYPE_BACKEND_LINK:
  1690. /* physical link configurations */
  1691. hdr_pass = SOC_TPLG_PASS_LINK;
  1692. elem_load = soc_tplg_link_elems_load;
  1693. break;
  1694. case SND_SOC_TPLG_TYPE_MANIFEST:
  1695. hdr_pass = SOC_TPLG_PASS_MANIFEST;
  1696. elem_load = soc_tplg_manifest_load;
  1697. break;
  1698. default:
  1699. /* bespoke vendor data object */
  1700. hdr_pass = SOC_TPLG_PASS_VENDOR;
  1701. elem_load = soc_tplg_vendor_load;
  1702. break;
  1703. }
  1704. if (tplg->pass == hdr_pass) {
  1705. dev_dbg(tplg->dev,
  1706. "ASoC: Got 0x%x bytes of type %d version %d vendor %d at pass %d\n",
  1707. hdr->payload_size, hdr->type, hdr->version,
  1708. hdr->vendor_type, tplg->pass);
  1709. return elem_load(tplg, hdr);
  1710. }
  1711. return 0;
  1712. }
  1713. /* process the topology file headers */
  1714. static int soc_tplg_process_headers(struct soc_tplg *tplg)
  1715. {
  1716. int ret;
  1717. /* process the header types from start to end */
  1718. for (tplg->pass = SOC_TPLG_PASS_START; tplg->pass <= SOC_TPLG_PASS_END; tplg->pass++) {
  1719. struct snd_soc_tplg_hdr *hdr;
  1720. tplg->hdr_pos = tplg->fw->data;
  1721. hdr = (struct snd_soc_tplg_hdr *)tplg->hdr_pos;
  1722. while (!soc_tplg_is_eof(tplg)) {
  1723. /* make sure header is valid before loading */
  1724. ret = soc_tplg_valid_header(tplg, hdr);
  1725. if (ret < 0)
  1726. return ret;
  1727. /* load the header object */
  1728. ret = soc_tplg_load_header(tplg, hdr);
  1729. if (ret < 0) {
  1730. if (ret != -EPROBE_DEFER) {
  1731. dev_err(tplg->dev,
  1732. "ASoC: topology: could not load header: %d\n",
  1733. ret);
  1734. }
  1735. return ret;
  1736. }
  1737. /* goto next header */
  1738. tplg->hdr_pos += le32_to_cpu(hdr->payload_size) +
  1739. sizeof(struct snd_soc_tplg_hdr);
  1740. hdr = (struct snd_soc_tplg_hdr *)tplg->hdr_pos;
  1741. }
  1742. }
  1743. /* signal DAPM we are complete */
  1744. ret = soc_tplg_dapm_complete(tplg);
  1745. return ret;
  1746. }
  1747. static int soc_tplg_load(struct soc_tplg *tplg)
  1748. {
  1749. int ret;
  1750. ret = soc_tplg_process_headers(tplg);
  1751. if (ret == 0)
  1752. return soc_tplg_complete(tplg);
  1753. return ret;
  1754. }
  1755. /* load audio component topology from "firmware" file */
  1756. int snd_soc_tplg_component_load(struct snd_soc_component *comp,
  1757. const struct snd_soc_tplg_ops *ops, const struct firmware *fw)
  1758. {
  1759. struct soc_tplg tplg;
  1760. int ret;
  1761. /*
  1762. * check if we have sane parameters:
  1763. * comp - needs to exist to keep and reference data while parsing
  1764. * comp->card - used for setting card related parameters
  1765. * comp->card->dev - used for resource management and prints
  1766. * fw - we need it, as it is the very thing we parse
  1767. */
  1768. if (!comp || !comp->card || !comp->card->dev || !fw)
  1769. return -EINVAL;
  1770. /* setup parsing context */
  1771. memset(&tplg, 0, sizeof(tplg));
  1772. tplg.fw = fw;
  1773. tplg.dev = comp->card->dev;
  1774. tplg.comp = comp;
  1775. if (ops) {
  1776. tplg.ops = ops;
  1777. tplg.io_ops = ops->io_ops;
  1778. tplg.io_ops_count = ops->io_ops_count;
  1779. tplg.bytes_ext_ops = ops->bytes_ext_ops;
  1780. tplg.bytes_ext_ops_count = ops->bytes_ext_ops_count;
  1781. }
  1782. ret = soc_tplg_load(&tplg);
  1783. /* free the created components if fail to load topology */
  1784. if (ret)
  1785. snd_soc_tplg_component_remove(comp);
  1786. return ret;
  1787. }
  1788. EXPORT_SYMBOL_GPL(snd_soc_tplg_component_load);
  1789. /* remove dynamic controls from the component driver */
  1790. int snd_soc_tplg_component_remove(struct snd_soc_component *comp)
  1791. {
  1792. struct snd_soc_dobj *dobj, *next_dobj;
  1793. int pass;
  1794. /* process the header types from end to start */
  1795. for (pass = SOC_TPLG_PASS_END; pass >= SOC_TPLG_PASS_START; pass--) {
  1796. /* remove mixer controls */
  1797. list_for_each_entry_safe(dobj, next_dobj, &comp->dobj_list,
  1798. list) {
  1799. switch (dobj->type) {
  1800. case SND_SOC_DOBJ_BYTES:
  1801. case SND_SOC_DOBJ_ENUM:
  1802. case SND_SOC_DOBJ_MIXER:
  1803. soc_tplg_remove_kcontrol(comp, dobj, pass);
  1804. break;
  1805. case SND_SOC_DOBJ_GRAPH:
  1806. soc_tplg_remove_route(comp, dobj, pass);
  1807. break;
  1808. case SND_SOC_DOBJ_WIDGET:
  1809. soc_tplg_remove_widget(comp, dobj, pass);
  1810. break;
  1811. case SND_SOC_DOBJ_PCM:
  1812. soc_tplg_remove_dai(comp, dobj, pass);
  1813. break;
  1814. case SND_SOC_DOBJ_DAI_LINK:
  1815. soc_tplg_remove_link(comp, dobj, pass);
  1816. break;
  1817. case SND_SOC_DOBJ_BACKEND_LINK:
  1818. /*
  1819. * call link_unload ops if extra
  1820. * deinitialization is needed.
  1821. */
  1822. remove_backend_link(comp, dobj, pass);
  1823. break;
  1824. default:
  1825. dev_err(comp->dev, "ASoC: invalid component type %d for removal\n",
  1826. dobj->type);
  1827. break;
  1828. }
  1829. }
  1830. }
  1831. /* let caller know if FW can be freed when no objects are left */
  1832. return !list_empty(&comp->dobj_list);
  1833. }
  1834. EXPORT_SYMBOL_GPL(snd_soc_tplg_component_remove);