soc-pcm.c 76 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774
  1. /*
  2. * soc-pcm.c -- ALSA SoC PCM
  3. *
  4. * Copyright 2005 Wolfson Microelectronics PLC.
  5. * Copyright 2005 Openedhand Ltd.
  6. * Copyright (C) 2010 Slimlogic Ltd.
  7. * Copyright (C) 2010 Texas Instruments Inc.
  8. *
  9. * Authors: Liam Girdwood <lrg@ti.com>
  10. * Mark Brown <broonie@opensource.wolfsonmicro.com>
  11. *
  12. * This program is free software; you can redistribute it and/or modify it
  13. * under the terms of the GNU General Public License as published by the
  14. * Free Software Foundation; either version 2 of the License, or (at your
  15. * option) any later version.
  16. *
  17. */
  18. #include <linux/kernel.h>
  19. #include <linux/init.h>
  20. #include <linux/delay.h>
  21. #include <linux/pm_runtime.h>
  22. #include <linux/slab.h>
  23. #include <linux/workqueue.h>
  24. #include <linux/debugfs.h>
  25. #include <linux/dma-mapping.h>
  26. #include <linux/export.h>
  27. #include <sound/core.h>
  28. #include <sound/pcm.h>
  29. #include <sound/pcm_params.h>
  30. #include <sound/soc.h>
  31. #include <sound/soc-dpcm.h>
  32. #include <sound/initval.h>
  33. #define MAX_BE_USERS 8 /* adjust if too low for everday use */
  34. /* ASoC no host IO hardware.
  35. * TODO: fine tune these values for all host less transfers.
  36. */
  37. static const struct snd_pcm_hardware no_host_hardware = {
  38. .info = SNDRV_PCM_INFO_MMAP |
  39. SNDRV_PCM_INFO_MMAP_VALID |
  40. SNDRV_PCM_INFO_INTERLEAVED |
  41. SNDRV_PCM_INFO_PAUSE |
  42. SNDRV_PCM_INFO_RESUME,
  43. .formats = SNDRV_PCM_FMTBIT_S16_LE |
  44. SNDRV_PCM_FMTBIT_S32_LE,
  45. .period_bytes_min = PAGE_SIZE >> 2,
  46. .period_bytes_max = PAGE_SIZE >> 1,
  47. .periods_min = 2,
  48. .periods_max = 4,
  49. .buffer_bytes_max = PAGE_SIZE,
  50. };
  51. /*
  52. * We can only hw_free, stop, pause or suspend a BE DAI if any of it's FE
  53. * are not running, paused or suspended for the specified stream direction.
  54. */
  55. int snd_soc_dpcm_can_be_free_stop(struct snd_soc_pcm_runtime *fe,
  56. struct snd_soc_pcm_runtime *be, int stream)
  57. {
  58. struct snd_soc_dpcm_params *dpcm_params;
  59. list_for_each_entry(dpcm_params, &be->dpcm[stream].fe_clients, list_fe) {
  60. if (dpcm_params->fe == fe)
  61. continue;
  62. if (dpcm_params->fe->dpcm[stream].state == SND_SOC_DPCM_STATE_START ||
  63. dpcm_params->fe->dpcm[stream].state == SND_SOC_DPCM_STATE_PAUSED ||
  64. dpcm_params->fe->dpcm[stream].state == SND_SOC_DPCM_STATE_SUSPEND)
  65. return 0;
  66. }
  67. return 1;
  68. }
  69. EXPORT_SYMBOL_GPL(snd_soc_dpcm_can_be_free_stop);
  70. /*
  71. * We can only change hw params a BE DAI if any of it's FE are not prepared,
  72. * running, paused or suspended for the specified stream direction.
  73. */
  74. static int snd_soc_dpcm_can_be_params(struct snd_soc_pcm_runtime *fe,
  75. struct snd_soc_pcm_runtime *be, int stream)
  76. {
  77. struct snd_soc_dpcm_params *dpcm_params;
  78. list_for_each_entry(dpcm_params, &be->dpcm[stream].fe_clients, list_fe) {
  79. if (dpcm_params->fe == fe)
  80. continue;
  81. if (dpcm_params->fe->dpcm[stream].state == SND_SOC_DPCM_STATE_START ||
  82. dpcm_params->fe->dpcm[stream].state == SND_SOC_DPCM_STATE_PAUSED ||
  83. dpcm_params->fe->dpcm[stream].state == SND_SOC_DPCM_STATE_SUSPEND ||
  84. dpcm_params->fe->dpcm[stream].state == SND_SOC_DPCM_STATE_PREPARE)
  85. return 0;
  86. }
  87. return 1;
  88. }
  89. static int soc_pcm_apply_symmetry(struct snd_pcm_substream *substream,
  90. struct snd_soc_dai *soc_dai)
  91. {
  92. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  93. int ret;
  94. if (!soc_dai->driver->symmetric_rates &&
  95. !rtd->dai_link->symmetric_rates)
  96. return 0;
  97. /* This can happen if multiple streams are starting simultaneously -
  98. * the second can need to get its constraints before the first has
  99. * picked a rate. Complain and allow the application to carry on.
  100. */
  101. if (!soc_dai->rate) {
  102. dev_warn(soc_dai->dev,
  103. "Not enforcing symmetric_rates due to race\n");
  104. return 0;
  105. }
  106. dev_dbg(soc_dai->dev, "Symmetry forces %dHz rate\n", soc_dai->rate);
  107. ret = snd_pcm_hw_constraint_minmax(substream->runtime,
  108. SNDRV_PCM_HW_PARAM_RATE,
  109. soc_dai->rate, soc_dai->rate);
  110. if (ret < 0) {
  111. dev_err(soc_dai->dev,
  112. "Unable to apply rate symmetry constraint: %d\n", ret);
  113. return ret;
  114. }
  115. return 0;
  116. }
  117. /*
  118. * List of sample sizes that might go over the bus for parameter
  119. * application. There ought to be a wildcard sample size for things
  120. * like the DAC/ADC resolution to use but there isn't right now.
  121. */
  122. static int sample_sizes[] = {
  123. 8, 16, 24, 32,
  124. };
  125. static void soc_pcm_apply_msb(struct snd_pcm_substream *substream,
  126. struct snd_soc_dai *dai)
  127. {
  128. int ret, i, bits;
  129. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  130. bits = dai->driver->playback.sig_bits;
  131. else
  132. bits = dai->driver->capture.sig_bits;
  133. if (!bits)
  134. return;
  135. for (i = 0; i < ARRAY_SIZE(sample_sizes); i++) {
  136. if (bits >= sample_sizes[i])
  137. continue;
  138. ret = snd_pcm_hw_constraint_msbits(substream->runtime, 0,
  139. sample_sizes[i], bits);
  140. if (ret != 0)
  141. dev_warn(dai->dev,
  142. "Failed to set MSB %d/%d: %d\n",
  143. bits, sample_sizes[i], ret);
  144. }
  145. }
  146. /*
  147. * stream event, send event to FE and all active BEs.
  148. */
  149. int dpcm_dapm_stream_event(struct snd_soc_pcm_runtime *fe,
  150. int dir, const char *stream, int event)
  151. {
  152. struct snd_soc_dpcm_params *dpcm_params;
  153. snd_soc_dapm_rtd_stream_event(fe, dir, event);
  154. list_for_each_entry(dpcm_params, &fe->dpcm[dir].be_clients, list_be) {
  155. struct snd_soc_pcm_runtime *be = dpcm_params->be;
  156. dev_dbg(be->dev, "pm: BE %s stream %s event %d dir %d\n",
  157. be->dai_link->name, stream, event, dir);
  158. snd_soc_dapm_rtd_stream_event(be, dir, event);
  159. }
  160. return 0;
  161. }
  162. /*
  163. * Called by ALSA when a PCM substream is opened, the runtime->hw record is
  164. * then initialized and any private data can be allocated. This also calls
  165. * startup for the cpu DAI, platform, machine and codec DAI.
  166. */
  167. static int soc_pcm_open(struct snd_pcm_substream *substream)
  168. {
  169. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  170. struct snd_pcm_runtime *runtime = substream->runtime;
  171. struct snd_soc_platform *platform = NULL;
  172. struct snd_soc_dai *cpu_dai = NULL;
  173. struct snd_soc_dai *codec_dai = NULL;
  174. struct snd_soc_dai_driver *cpu_dai_drv = NULL;
  175. struct snd_soc_dai_driver *codec_dai_drv = NULL;
  176. int ret = 0;
  177. if (!rtd) {
  178. printk(KERN_ERR "asoc: incomplete substream %i \"%s\": private_data "
  179. "is NULL\n", substream->number, substream->name);
  180. return -EINVAL;
  181. }
  182. platform = rtd->platform;
  183. cpu_dai = rtd->cpu_dai;
  184. codec_dai = rtd->codec_dai;
  185. cpu_dai_drv = cpu_dai->driver;
  186. codec_dai_drv = codec_dai->driver;
  187. pm_runtime_get_sync(cpu_dai->dev);
  188. pm_runtime_get_sync(codec_dai->dev);
  189. pm_runtime_get_sync(platform->dev);
  190. mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
  191. if (rtd->dai_link->no_host_mode == SND_SOC_DAI_LINK_NO_HOST)
  192. snd_soc_set_runtime_hwparams(substream, &no_host_hardware);
  193. /* startup the audio subsystem */
  194. if (cpu_dai->driver->ops->startup) {
  195. ret = cpu_dai->driver->ops->startup(substream, cpu_dai);
  196. if (ret < 0) {
  197. printk(KERN_ERR "asoc: can't open interface %s\n",
  198. cpu_dai->name);
  199. goto out;
  200. }
  201. }
  202. if (platform->driver->ops && platform->driver->ops->open) {
  203. ret = platform->driver->ops->open(substream);
  204. if (ret < 0) {
  205. printk(KERN_ERR "asoc: can't open platform %s\n", platform->name);
  206. goto platform_err;
  207. }
  208. }
  209. if (codec_dai->driver->ops->startup) {
  210. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  211. ret = codec_dai->driver->ops->startup(substream,
  212. codec_dai);
  213. if (ret < 0) {
  214. printk(KERN_ERR "asoc: can't open codec %s\n",
  215. codec_dai->name);
  216. goto codec_dai_err;
  217. }
  218. } else {
  219. if (!codec_dai->capture_active) {
  220. ret = codec_dai->driver->ops->startup(substream,
  221. codec_dai);
  222. if (ret < 0) {
  223. printk(KERN_ERR "can't open codec %s\n",
  224. codec_dai->name);
  225. goto codec_dai_err;
  226. }
  227. }
  228. }
  229. }
  230. if (rtd->dai_link->ops && rtd->dai_link->ops->startup) {
  231. ret = rtd->dai_link->ops->startup(substream);
  232. if (ret < 0) {
  233. printk(KERN_ERR "asoc: %s startup failed\n", rtd->dai_link->name);
  234. goto machine_err;
  235. }
  236. }
  237. /* DSP DAI links compat checks are different */
  238. if (rtd->dai_link->dynamic || rtd->dai_link->no_pcm)
  239. goto dynamic;
  240. /* Check that the codec and cpu DAIs are compatible */
  241. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  242. runtime->hw.rate_min =
  243. max(codec_dai_drv->playback.rate_min,
  244. cpu_dai_drv->playback.rate_min);
  245. runtime->hw.rate_max =
  246. min(codec_dai_drv->playback.rate_max,
  247. cpu_dai_drv->playback.rate_max);
  248. runtime->hw.channels_min =
  249. max(codec_dai_drv->playback.channels_min,
  250. cpu_dai_drv->playback.channels_min);
  251. runtime->hw.channels_max =
  252. min(codec_dai_drv->playback.channels_max,
  253. cpu_dai_drv->playback.channels_max);
  254. runtime->hw.formats =
  255. codec_dai_drv->playback.formats & cpu_dai_drv->playback.formats;
  256. runtime->hw.rates =
  257. codec_dai_drv->playback.rates & cpu_dai_drv->playback.rates;
  258. if (codec_dai_drv->playback.rates
  259. & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS))
  260. runtime->hw.rates |= cpu_dai_drv->playback.rates;
  261. if (cpu_dai_drv->playback.rates
  262. & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS))
  263. runtime->hw.rates |= codec_dai_drv->playback.rates;
  264. } else {
  265. runtime->hw.rate_min =
  266. max(codec_dai_drv->capture.rate_min,
  267. cpu_dai_drv->capture.rate_min);
  268. runtime->hw.rate_max =
  269. min(codec_dai_drv->capture.rate_max,
  270. cpu_dai_drv->capture.rate_max);
  271. runtime->hw.channels_min =
  272. max(codec_dai_drv->capture.channels_min,
  273. cpu_dai_drv->capture.channels_min);
  274. runtime->hw.channels_max =
  275. min(codec_dai_drv->capture.channels_max,
  276. cpu_dai_drv->capture.channels_max);
  277. runtime->hw.formats =
  278. codec_dai_drv->capture.formats & cpu_dai_drv->capture.formats;
  279. runtime->hw.rates =
  280. codec_dai_drv->capture.rates & cpu_dai_drv->capture.rates;
  281. if (codec_dai_drv->capture.rates
  282. & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS))
  283. runtime->hw.rates |= cpu_dai_drv->capture.rates;
  284. if (cpu_dai_drv->capture.rates
  285. & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS))
  286. runtime->hw.rates |= codec_dai_drv->capture.rates;
  287. }
  288. ret = -EINVAL;
  289. snd_pcm_limit_hw_rates(runtime);
  290. if (!runtime->hw.rates) {
  291. printk(KERN_ERR "asoc: %s <-> %s No matching rates\n",
  292. codec_dai->name, cpu_dai->name);
  293. goto config_err;
  294. }
  295. if (!runtime->hw.formats) {
  296. printk(KERN_ERR "asoc: %s <-> %s No matching formats\n",
  297. codec_dai->name, cpu_dai->name);
  298. goto config_err;
  299. }
  300. if (!runtime->hw.channels_min || !runtime->hw.channels_max ||
  301. runtime->hw.channels_min > runtime->hw.channels_max) {
  302. printk(KERN_ERR "asoc: %s <-> %s No matching channels\n",
  303. codec_dai->name, cpu_dai->name);
  304. goto config_err;
  305. }
  306. soc_pcm_apply_msb(substream, codec_dai);
  307. soc_pcm_apply_msb(substream, cpu_dai);
  308. /* Symmetry only applies if we've already got an active stream. */
  309. if (cpu_dai->active) {
  310. ret = soc_pcm_apply_symmetry(substream, cpu_dai);
  311. if (ret != 0)
  312. goto config_err;
  313. }
  314. if (codec_dai->active) {
  315. ret = soc_pcm_apply_symmetry(substream, codec_dai);
  316. if (ret != 0)
  317. goto config_err;
  318. }
  319. pr_debug("asoc: %s <-> %s info:\n",
  320. codec_dai->name, cpu_dai->name);
  321. pr_debug("asoc: rate mask 0x%x\n", runtime->hw.rates);
  322. pr_debug("asoc: min ch %d max ch %d\n", runtime->hw.channels_min,
  323. runtime->hw.channels_max);
  324. pr_debug("asoc: min rate %d max rate %d\n", runtime->hw.rate_min,
  325. runtime->hw.rate_max);
  326. dynamic:
  327. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  328. cpu_dai->playback_active++;
  329. codec_dai->playback_active++;
  330. } else {
  331. cpu_dai->capture_active++;
  332. codec_dai->capture_active++;
  333. }
  334. cpu_dai->active++;
  335. codec_dai->active++;
  336. rtd->codec->active++;
  337. mutex_unlock(&rtd->pcm_mutex);
  338. return 0;
  339. config_err:
  340. if (rtd->dai_link->ops && rtd->dai_link->ops->shutdown)
  341. rtd->dai_link->ops->shutdown(substream);
  342. machine_err:
  343. if (codec_dai->driver->ops->shutdown)
  344. codec_dai->driver->ops->shutdown(substream, codec_dai);
  345. codec_dai_err:
  346. if (platform->driver->ops && platform->driver->ops->close)
  347. platform->driver->ops->close(substream);
  348. platform_err:
  349. if (cpu_dai->driver->ops->shutdown)
  350. cpu_dai->driver->ops->shutdown(substream, cpu_dai);
  351. out:
  352. mutex_unlock(&rtd->pcm_mutex);
  353. pm_runtime_put(platform->dev);
  354. pm_runtime_put(codec_dai->dev);
  355. pm_runtime_put(cpu_dai->dev);
  356. return ret;
  357. }
  358. /*
  359. * Power down the audio subsystem pmdown_time msecs after close is called.
  360. * This is to ensure there are no pops or clicks in between any music tracks
  361. * due to DAPM power cycling.
  362. */
  363. static void close_delayed_work(struct work_struct *work)
  364. {
  365. struct snd_soc_pcm_runtime *rtd =
  366. container_of(work, struct snd_soc_pcm_runtime, delayed_work.work);
  367. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  368. mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
  369. pr_debug("pop wq checking: %s status: %s waiting: %s\n",
  370. codec_dai->driver->playback.stream_name,
  371. codec_dai->playback_active ? "active" : "inactive",
  372. codec_dai->pop_wait ? "yes" : "no");
  373. /* are we waiting on this codec DAI stream */
  374. if (codec_dai->pop_wait == 1) {
  375. codec_dai->pop_wait = 0;
  376. snd_soc_dapm_stream_event(rtd,
  377. codec_dai->driver->playback.stream_name,
  378. SND_SOC_DAPM_STREAM_STOP);
  379. }
  380. mutex_unlock(&rtd->pcm_mutex);
  381. }
  382. /*
  383. * Called by ALSA when a PCM substream is closed. Private data can be
  384. * freed here. The cpu DAI, codec DAI, machine and platform are also
  385. * shutdown.
  386. */
  387. static int soc_pcm_close(struct snd_pcm_substream *substream)
  388. {
  389. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  390. struct snd_soc_platform *platform = rtd->platform;
  391. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  392. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  393. struct snd_soc_codec *codec = rtd->codec;
  394. mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
  395. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  396. cpu_dai->playback_active--;
  397. codec_dai->playback_active--;
  398. } else {
  399. cpu_dai->capture_active--;
  400. codec_dai->capture_active--;
  401. }
  402. cpu_dai->active--;
  403. codec_dai->active--;
  404. codec->active--;
  405. /* clear the corresponding DAIs rate when inactive */
  406. if (!cpu_dai->active)
  407. cpu_dai->rate = 0;
  408. if (!codec_dai->active)
  409. codec_dai->rate = 0;
  410. /* Muting the DAC suppresses artifacts caused during digital
  411. * shutdown, for example from stopping clocks.
  412. */
  413. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  414. snd_soc_dai_digital_mute(codec_dai, 1);
  415. if (cpu_dai->driver->ops->shutdown)
  416. cpu_dai->driver->ops->shutdown(substream, cpu_dai);
  417. if (codec_dai->driver->ops->shutdown) {
  418. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  419. codec_dai->driver->ops->shutdown(substream, codec_dai);
  420. } else {
  421. if (!codec_dai->capture_active)
  422. codec_dai->driver->ops->shutdown(substream,
  423. codec_dai);
  424. }
  425. }
  426. if (rtd->dai_link->ops && rtd->dai_link->ops->shutdown)
  427. rtd->dai_link->ops->shutdown(substream);
  428. if (platform->driver->ops && platform->driver->ops->close)
  429. platform->driver->ops->close(substream);
  430. cpu_dai->runtime = NULL;
  431. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  432. if (codec->ignore_pmdown_time ||
  433. rtd->dai_link->ignore_pmdown_time ||
  434. !rtd->pmdown_time) {
  435. /* powered down playback stream now */
  436. snd_soc_dapm_stream_event(rtd,
  437. codec_dai->driver->playback.stream_name,
  438. SND_SOC_DAPM_STREAM_STOP);
  439. } else {
  440. /* start delayed pop wq here for playback streams */
  441. codec_dai->pop_wait = 1;
  442. schedule_delayed_work(&rtd->delayed_work,
  443. msecs_to_jiffies(rtd->pmdown_time));
  444. }
  445. } else {
  446. /* capture streams can be powered down now */
  447. if (!codec_dai->capture_active)
  448. snd_soc_dapm_stream_event(rtd,
  449. codec_dai->driver->capture.stream_name,
  450. SND_SOC_DAPM_STREAM_STOP);
  451. }
  452. mutex_unlock(&rtd->pcm_mutex);
  453. pm_runtime_put(platform->dev);
  454. pm_runtime_put(codec_dai->dev);
  455. pm_runtime_put(cpu_dai->dev);
  456. return 0;
  457. }
  458. /*
  459. * Called by ALSA when the PCM substream is prepared, can set format, sample
  460. * rate, etc. This function is non atomic and can be called multiple times,
  461. * it can refer to the runtime info.
  462. */
  463. static int soc_pcm_prepare(struct snd_pcm_substream *substream)
  464. {
  465. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  466. struct snd_soc_platform *platform = rtd->platform;
  467. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  468. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  469. int ret = 0;
  470. mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
  471. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  472. snd_soc_dapm_stream_event(rtd,
  473. codec_dai->driver->playback.stream_name,
  474. SND_SOC_DAPM_STREAM_START);
  475. if (rtd->dai_link->ops && rtd->dai_link->ops->prepare) {
  476. ret = rtd->dai_link->ops->prepare(substream);
  477. if (ret < 0) {
  478. printk(KERN_ERR "asoc: machine prepare error\n");
  479. goto out;
  480. }
  481. }
  482. if (platform->driver->ops && platform->driver->ops->prepare) {
  483. ret = platform->driver->ops->prepare(substream);
  484. if (ret < 0) {
  485. printk(KERN_ERR "asoc: platform prepare error\n");
  486. goto out;
  487. }
  488. }
  489. if (codec_dai->driver->ops->prepare) {
  490. ret = codec_dai->driver->ops->prepare(substream, codec_dai);
  491. if (ret < 0) {
  492. printk(KERN_ERR "asoc: codec DAI prepare error\n");
  493. goto out;
  494. }
  495. }
  496. if (cpu_dai->driver->ops->prepare) {
  497. ret = cpu_dai->driver->ops->prepare(substream, cpu_dai);
  498. if (ret < 0) {
  499. printk(KERN_ERR "asoc: cpu DAI prepare error\n");
  500. goto out;
  501. }
  502. }
  503. /* cancel any delayed stream shutdown that is pending */
  504. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK &&
  505. codec_dai->pop_wait) {
  506. codec_dai->pop_wait = 0;
  507. cancel_delayed_work(&rtd->delayed_work);
  508. }
  509. if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
  510. if (codec_dai->capture_active == 1)
  511. snd_soc_dapm_stream_event(rtd,
  512. codec_dai->driver->capture.stream_name,
  513. SND_SOC_DAPM_STREAM_START);
  514. }
  515. snd_soc_dai_digital_mute(codec_dai, 0);
  516. out:
  517. if (ret < 0 && substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  518. pr_err("%s: Issue stop stream for codec_dai due to op failure %d = ret\n",
  519. __func__, ret);
  520. snd_soc_dapm_stream_event(rtd,
  521. codec_dai->driver->playback.stream_name,
  522. SND_SOC_DAPM_STREAM_STOP);
  523. }
  524. mutex_unlock(&rtd->pcm_mutex);
  525. return ret;
  526. }
  527. /*
  528. * Called by ALSA when the hardware params are set by application. This
  529. * function can also be called multiple times and can allocate buffers
  530. * (using snd_pcm_lib_* ). It's non-atomic.
  531. */
  532. static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
  533. struct snd_pcm_hw_params *params)
  534. {
  535. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  536. struct snd_soc_platform *platform = rtd->platform;
  537. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  538. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  539. int ret = 0;
  540. mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
  541. if (rtd->dai_link->ops && rtd->dai_link->ops->hw_params) {
  542. ret = rtd->dai_link->ops->hw_params(substream, params);
  543. if (ret < 0) {
  544. printk(KERN_ERR "asoc: machine hw_params failed\n");
  545. goto out;
  546. }
  547. }
  548. if (codec_dai->driver->ops->hw_params) {
  549. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  550. ret = codec_dai->driver->ops->hw_params(substream,
  551. params, codec_dai);
  552. if (ret < 0) {
  553. printk(KERN_ERR "not set codec %s hw params\n",
  554. codec_dai->name);
  555. goto codec_err;
  556. }
  557. } else {
  558. if (codec_dai->capture_active == 1) {
  559. ret = codec_dai->driver->ops->hw_params(
  560. substream, params, codec_dai);
  561. if (ret < 0) {
  562. printk(KERN_ERR "fail: %s hw params\n",
  563. codec_dai->name);
  564. goto codec_err;
  565. }
  566. }
  567. }
  568. }
  569. if (cpu_dai->driver->ops->hw_params) {
  570. ret = cpu_dai->driver->ops->hw_params(substream, params, cpu_dai);
  571. if (ret < 0) {
  572. printk(KERN_ERR "asoc: interface %s hw params failed\n",
  573. cpu_dai->name);
  574. goto interface_err;
  575. }
  576. }
  577. if (platform->driver->ops && platform->driver->ops->hw_params) {
  578. ret = platform->driver->ops->hw_params(substream, params);
  579. if (ret < 0) {
  580. printk(KERN_ERR "asoc: platform %s hw params failed\n",
  581. platform->name);
  582. goto platform_err;
  583. }
  584. }
  585. /* store the rate for each DAIs */
  586. cpu_dai->rate = params_rate(params);
  587. codec_dai->rate = params_rate(params);
  588. /* malloc a page for hostless IO.
  589. * FIXME: rework with alsa-lib changes so that this malloc is not required.
  590. */
  591. if (rtd->dai_link->no_host_mode == SND_SOC_DAI_LINK_NO_HOST) {
  592. substream->dma_buffer.dev.type = SNDRV_DMA_TYPE_DEV;
  593. substream->dma_buffer.dev.dev = rtd->dev;
  594. substream->dma_buffer.dev.dev->coherent_dma_mask = DMA_BIT_MASK(32);
  595. substream->dma_buffer.private_data = NULL;
  596. ret = snd_pcm_lib_malloc_pages(substream, PAGE_SIZE);
  597. if (ret < 0)
  598. goto platform_err;
  599. }
  600. out:
  601. mutex_unlock(&rtd->pcm_mutex);
  602. return ret;
  603. platform_err:
  604. if (cpu_dai->driver->ops->hw_free)
  605. cpu_dai->driver->ops->hw_free(substream, cpu_dai);
  606. interface_err:
  607. if (codec_dai->driver->ops->hw_free)
  608. codec_dai->driver->ops->hw_free(substream, codec_dai);
  609. codec_err:
  610. if (rtd->dai_link->ops && rtd->dai_link->ops->hw_free)
  611. rtd->dai_link->ops->hw_free(substream);
  612. mutex_unlock(&rtd->pcm_mutex);
  613. return ret;
  614. }
  615. /*
  616. * Frees resources allocated by hw_params, can be called multiple times
  617. */
  618. static int soc_pcm_hw_free(struct snd_pcm_substream *substream)
  619. {
  620. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  621. struct snd_soc_platform *platform = rtd->platform;
  622. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  623. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  624. struct snd_soc_codec *codec = rtd->codec;
  625. mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
  626. /* apply codec digital mute */
  627. if (!codec->active)
  628. snd_soc_dai_digital_mute(codec_dai, 1);
  629. /* free any machine hw params */
  630. if (rtd->dai_link->ops && rtd->dai_link->ops->hw_free)
  631. rtd->dai_link->ops->hw_free(substream);
  632. /* free any DMA resources */
  633. if (platform->driver->ops && platform->driver->ops->hw_free)
  634. platform->driver->ops->hw_free(substream);
  635. /* now free hw params for the DAIs */
  636. if (codec_dai->driver->ops->hw_free)
  637. codec_dai->driver->ops->hw_free(substream, codec_dai);
  638. if (cpu_dai->driver->ops->hw_free)
  639. cpu_dai->driver->ops->hw_free(substream, cpu_dai);
  640. if (rtd->dai_link->no_host_mode == SND_SOC_DAI_LINK_NO_HOST)
  641. snd_pcm_lib_free_pages(substream);
  642. mutex_unlock(&rtd->pcm_mutex);
  643. return 0;
  644. }
  645. static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
  646. {
  647. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  648. struct snd_soc_platform *platform = rtd->platform;
  649. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  650. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  651. int ret;
  652. if (codec_dai->driver->ops->trigger) {
  653. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  654. ret = codec_dai->driver->ops->trigger(substream,
  655. cmd, codec_dai);
  656. if (ret < 0)
  657. return ret;
  658. } else {
  659. if (codec_dai->capture_active == 1) {
  660. ret = codec_dai->driver->ops->trigger(
  661. substream, cmd, codec_dai);
  662. if (ret < 0)
  663. return ret;
  664. }
  665. }
  666. }
  667. if (platform->driver->ops && platform->driver->ops->trigger) {
  668. ret = platform->driver->ops->trigger(substream, cmd);
  669. if (ret < 0)
  670. return ret;
  671. }
  672. if (cpu_dai->driver->ops->trigger) {
  673. ret = cpu_dai->driver->ops->trigger(substream, cmd, cpu_dai);
  674. if (ret < 0)
  675. return ret;
  676. }
  677. return 0;
  678. }
  679. int soc_pcm_bespoke_trigger(struct snd_pcm_substream *substream, int cmd)
  680. {
  681. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  682. struct snd_soc_platform *platform = rtd->platform;
  683. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  684. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  685. int ret;
  686. if (codec_dai->driver->ops->bespoke_trigger) {
  687. ret = codec_dai->driver->ops->bespoke_trigger(substream, cmd, codec_dai);
  688. if (ret < 0)
  689. return ret;
  690. }
  691. if (platform->driver->bespoke_trigger) {
  692. ret = platform->driver->bespoke_trigger(substream, cmd);
  693. if (ret < 0)
  694. return ret;
  695. }
  696. if (cpu_dai->driver->ops->bespoke_trigger) {
  697. ret = cpu_dai->driver->ops->bespoke_trigger(substream, cmd, cpu_dai);
  698. if (ret < 0)
  699. return ret;
  700. }
  701. return 0;
  702. }
  703. /*
  704. * soc level wrapper for pointer callback
  705. * If cpu_dai, codec_dai, platform driver has the delay callback, than
  706. * the runtime->delay will be updated accordingly.
  707. */
  708. static snd_pcm_uframes_t soc_pcm_pointer(struct snd_pcm_substream *substream)
  709. {
  710. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  711. struct snd_soc_platform *platform = rtd->platform;
  712. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  713. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  714. struct snd_pcm_runtime *runtime = substream->runtime;
  715. snd_pcm_uframes_t offset = 0;
  716. snd_pcm_sframes_t delay = 0;
  717. if (platform->driver->ops && platform->driver->ops->pointer)
  718. offset = platform->driver->ops->pointer(substream);
  719. if (cpu_dai->driver->ops->delay)
  720. delay += cpu_dai->driver->ops->delay(substream, cpu_dai);
  721. if (codec_dai->driver->ops->delay)
  722. delay += codec_dai->driver->ops->delay(substream, codec_dai);
  723. if (platform->driver->delay)
  724. delay += platform->driver->delay(substream, codec_dai);
  725. runtime->delay = delay;
  726. return offset;
  727. }
  728. static inline int be_connect(struct snd_soc_pcm_runtime *fe,
  729. struct snd_soc_pcm_runtime *be, int stream)
  730. {
  731. struct snd_soc_dpcm_params *dpcm_params;
  732. if (!fe->dpcm[stream].runtime && !fe->fe_compr) {
  733. dev_err(fe->dev, "%s no runtime\n", fe->dai_link->name);
  734. return -ENODEV;
  735. }
  736. /* only add new dpcm_paramss */
  737. list_for_each_entry(dpcm_params, &fe->dpcm[stream].be_clients, list_be) {
  738. if (dpcm_params->be == be && dpcm_params->fe == fe)
  739. return 0;
  740. }
  741. dpcm_params = kzalloc(sizeof(struct snd_soc_dpcm_params), GFP_KERNEL);
  742. if (!dpcm_params)
  743. return -ENOMEM;
  744. dpcm_params->be = be;
  745. dpcm_params->fe = fe;
  746. be->dpcm[stream].runtime = fe->dpcm[stream].runtime;
  747. dpcm_params->state = SND_SOC_DPCM_LINK_STATE_NEW;
  748. list_add(&dpcm_params->list_be, &fe->dpcm[stream].be_clients);
  749. list_add(&dpcm_params->list_fe, &be->dpcm[stream].fe_clients);
  750. dev_dbg(fe->dev, " connected new DSP %s path %s %s %s\n",
  751. stream ? "capture" : "playback", fe->dai_link->name,
  752. stream ? "<-" : "->", be->dai_link->name);
  753. #ifdef CONFIG_DEBUG_FS
  754. dpcm_params->debugfs_state = debugfs_create_u32(be->dai_link->name, 0644,
  755. fe->debugfs_dpcm_root, &dpcm_params->state);
  756. #endif
  757. return 1;
  758. }
  759. static inline void be_reparent(struct snd_soc_pcm_runtime *fe,
  760. struct snd_soc_pcm_runtime *be, int stream)
  761. {
  762. struct snd_soc_dpcm_params *dpcm_params;
  763. struct snd_pcm_substream *fe_substream, *be_substream;
  764. /* reparent if BE is connected to other FEs */
  765. if (!be->dpcm[stream].users)
  766. return;
  767. be_substream = snd_soc_dpcm_get_substream(be, stream);
  768. list_for_each_entry(dpcm_params, &be->dpcm[stream].fe_clients, list_fe) {
  769. if (dpcm_params->fe != fe) {
  770. dev_dbg(fe->dev, " reparent %s path %s %s %s\n",
  771. stream ? "capture" : "playback",
  772. dpcm_params->fe->dai_link->name,
  773. stream ? "<-" : "->", dpcm_params->be->dai_link->name);
  774. fe_substream = snd_soc_dpcm_get_substream(dpcm_params->fe,
  775. stream);
  776. be_substream->runtime = fe_substream->runtime;
  777. break;
  778. }
  779. }
  780. }
  781. void dpcm_be_disconnect(struct snd_soc_pcm_runtime *fe, int stream)
  782. {
  783. struct snd_soc_dpcm_params *dpcm_params, *d;
  784. list_for_each_entry_safe(dpcm_params, d, &fe->dpcm[stream].be_clients, list_be) {
  785. dev_dbg(fe->dev, "BE %s disconnect check for %s\n",
  786. stream ? "capture" : "playback",
  787. dpcm_params->be->dai_link->name);
  788. if (dpcm_params->state == SND_SOC_DPCM_LINK_STATE_FREE) {
  789. dev_dbg(fe->dev, " freed DSP %s path %s %s %s\n",
  790. stream ? "capture" : "playback", fe->dai_link->name,
  791. stream ? "<-" : "->", dpcm_params->be->dai_link->name);
  792. /* BEs still alive need new FE */
  793. be_reparent(fe, dpcm_params->be, stream);
  794. #ifdef CONFIG_DEBUG_FS
  795. debugfs_remove(dpcm_params->debugfs_state);
  796. #endif
  797. list_del(&dpcm_params->list_be);
  798. list_del(&dpcm_params->list_fe);
  799. kfree(dpcm_params);
  800. }
  801. }
  802. }
  803. static struct snd_soc_pcm_runtime *be_get_rtd(struct snd_soc_card *card,
  804. struct snd_soc_dapm_widget *widget)
  805. {
  806. struct snd_soc_pcm_runtime *be;
  807. int i;
  808. if (!widget->sname) {
  809. dev_err(card->dev, "widget %s has no stream\n", widget->name);
  810. return NULL;
  811. }
  812. for (i = 0; i < card->num_links; i++) {
  813. be = &card->rtd[i];
  814. if (!strcmp(widget->sname, be->dai_link->stream_name))
  815. return be;
  816. }
  817. dev_err(card->dev, "can't get BE for %s\n", widget->name);
  818. return NULL;
  819. }
  820. static struct snd_soc_dapm_widget *be_get_widget(struct snd_soc_card *card,
  821. struct snd_soc_pcm_runtime *rtd)
  822. {
  823. struct snd_soc_dapm_widget *widget;
  824. list_for_each_entry(widget, &card->widgets, list) {
  825. if (!widget->sname)
  826. continue;
  827. if (!strcmp(widget->sname, rtd->dai_link->stream_name))
  828. return widget;
  829. }
  830. dev_err(card->dev, "can't get widget for %s\n",
  831. rtd->dai_link->stream_name);
  832. return NULL;
  833. }
  834. static int widget_in_list(struct snd_soc_dapm_widget_list *list,
  835. struct snd_soc_dapm_widget *widget)
  836. {
  837. int i;
  838. for (i = 0; i < list->num_widgets; i++) {
  839. if (widget == list->widgets[i])
  840. return 1;
  841. }
  842. return 0;
  843. }
  844. int dpcm_path_get(struct snd_soc_pcm_runtime *fe,
  845. int stream, struct snd_soc_dapm_widget_list **list_)
  846. {
  847. struct snd_soc_dai *cpu_dai = fe->cpu_dai;
  848. struct snd_soc_dapm_widget_list *list;
  849. int paths;
  850. list = kzalloc(sizeof(struct snd_soc_dapm_widget_list) +
  851. sizeof(struct snd_soc_dapm_widget *), GFP_KERNEL);
  852. if (list == NULL)
  853. return -ENOMEM;
  854. /* get number of valid DAI paths and their widgets */
  855. paths = snd_soc_dapm_dai_get_connected_widgets(cpu_dai, stream, &list);
  856. dev_dbg(fe->dev, "found %d audio %s paths\n", paths,
  857. stream ? "capture" : "playback");
  858. *list_ = list;
  859. return paths;
  860. }
  861. static int be_prune_old(struct snd_soc_pcm_runtime *fe, int stream,
  862. struct snd_soc_dapm_widget_list **list_)
  863. {
  864. struct snd_soc_card *card = fe->card;
  865. struct snd_soc_dpcm_params *dpcm_params;
  866. struct snd_soc_dapm_widget_list *list = *list_;
  867. struct snd_soc_dapm_widget *widget;
  868. int old = 0;
  869. /* Destroy any old FE <--> BE connections */
  870. list_for_each_entry(dpcm_params, &fe->dpcm[stream].be_clients, list_be) {
  871. /* is there a valid widget for this BE */
  872. widget = be_get_widget(card, dpcm_params->be);
  873. if (!widget) {
  874. dev_err(fe->dev, "no widget found for %s\n",
  875. dpcm_params->be->dai_link->name);
  876. continue;
  877. }
  878. /* prune the BE if it's no longer in our active list */
  879. if (widget_in_list(list, widget))
  880. continue;
  881. dev_dbg(fe->dev, "pruning %s BE %s for %s\n",
  882. stream ? "capture" : "playback", dpcm_params->be->dai_link->name,
  883. fe->dai_link->name);
  884. dpcm_params->state = SND_SOC_DPCM_LINK_STATE_FREE;
  885. dpcm_params->be->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_BE;
  886. old++;
  887. }
  888. dev_dbg(fe->dev, "found %d old BEs\n", old);
  889. return old;
  890. }
  891. static int be_add_new(struct snd_soc_pcm_runtime *fe, int stream,
  892. struct snd_soc_dapm_widget_list **list_)
  893. {
  894. struct snd_soc_card *card = fe->card;
  895. struct snd_soc_dapm_widget_list *list = *list_;
  896. enum snd_soc_dapm_type be_type;
  897. int i, new = 0, err;
  898. if (stream == SNDRV_PCM_STREAM_PLAYBACK)
  899. be_type = snd_soc_dapm_aif_out;
  900. else
  901. be_type = snd_soc_dapm_aif_in;
  902. /* Create any new FE <--> BE connections */
  903. for (i = 0; i < list->num_widgets; i++) {
  904. if (list->widgets[i]->id == be_type) {
  905. struct snd_soc_pcm_runtime *be;
  906. /* is there a valid BE rtd for this widget */
  907. be = be_get_rtd(card, list->widgets[i]);
  908. if (!be) {
  909. dev_err(fe->dev, "no BE found for %s\n",
  910. list->widgets[i]->name);
  911. continue;
  912. }
  913. /* don't connect if FE is not running */
  914. if (!fe->dpcm[stream].runtime && !fe->fe_compr)
  915. continue;
  916. /* newly connected FE and BE */
  917. err = be_connect(fe, be, stream);
  918. if (err < 0) {
  919. dev_err(fe->dev, "can't connect %s\n", list->widgets[i]->name);
  920. break;
  921. } else if (err == 0) /* already connected */
  922. continue;
  923. /* new */
  924. be->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_BE;
  925. new++;
  926. }
  927. }
  928. dev_dbg(fe->dev, "found %d new BEs\n", new);
  929. return new;
  930. }
  931. /*
  932. * Find the corresponding BE DAIs that source or sink audio to this
  933. * FE substream.
  934. */
  935. int dpcm_process_paths(struct snd_soc_pcm_runtime *fe,
  936. int stream, struct snd_soc_dapm_widget_list **list, int new)
  937. {
  938. if (new)
  939. return be_add_new(fe, stream, list);
  940. else
  941. return be_prune_old(fe, stream, list);
  942. return 0;
  943. }
  944. /*
  945. * Clear the runtime pending state of all BE's.
  946. */
  947. void dpcm_clear_pending_state(struct snd_soc_pcm_runtime *fe, int stream)
  948. {
  949. struct snd_soc_dpcm_params *dpcm_params;
  950. list_for_each_entry(dpcm_params, &fe->dpcm[stream].be_clients, list_be)
  951. dpcm_params->be->dpcm[stream].runtime_update =
  952. SND_SOC_DPCM_UPDATE_NO;
  953. }
  954. /* Unwind the BE startup */
  955. static void soc_dpcm_be_dai_startup_unwind(struct snd_soc_pcm_runtime *fe, int stream)
  956. {
  957. struct snd_soc_dpcm_params *dpcm_params;
  958. /* disable any enabled and non active backends */
  959. list_for_each_entry(dpcm_params, &fe->dpcm[stream].be_clients, list_be) {
  960. struct snd_soc_pcm_runtime *be = dpcm_params->be;
  961. struct snd_pcm_substream *be_substream =
  962. snd_soc_dpcm_get_substream(be, stream);
  963. if (be->dpcm[stream].users == 0)
  964. dev_err(be->dev, "no users %s at close - state %d\n",
  965. stream ? "capture" : "playback", be->dpcm[stream].state);
  966. if (--be->dpcm[stream].users != 0)
  967. continue;
  968. if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_OPEN)
  969. continue;
  970. soc_pcm_close(be_substream);
  971. be_substream->runtime = NULL;
  972. be->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE;
  973. }
  974. }
  975. /* Startup all new BE */
  976. int dpcm_be_dai_startup(struct snd_soc_pcm_runtime *fe, int stream)
  977. {
  978. struct snd_soc_dpcm_params *dpcm_params;
  979. int err, count = 0;
  980. /* only startup BE DAIs that are either sinks or sources to this FE DAI */
  981. list_for_each_entry(dpcm_params, &fe->dpcm[stream].be_clients, list_be) {
  982. struct snd_soc_pcm_runtime *be = dpcm_params->be;
  983. struct snd_pcm_substream *be_substream =
  984. snd_soc_dpcm_get_substream(be, stream);
  985. /* is this op for this BE ? */
  986. if (!snd_soc_dpcm_be_can_update(fe, be, stream))
  987. continue;
  988. /* first time the dpcm_params is open ? */
  989. if (be->dpcm[stream].users == MAX_BE_USERS)
  990. dev_err(be->dev, "too many users %s at open - state %d\n",
  991. stream ? "capture" : "playback", be->dpcm[stream].state);
  992. if (be->dpcm[stream].users++ != 0)
  993. continue;
  994. if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_NEW) &&
  995. (be->dpcm[stream].state != SND_SOC_DPCM_STATE_CLOSE))
  996. continue;
  997. dev_info(be->dev, "dpcm: open BE %s\n", be->dai_link->name);
  998. be_substream->runtime = be->dpcm[stream].runtime;
  999. err = soc_pcm_open(be_substream);
  1000. if (err < 0) {
  1001. dev_err(be->dev, "BE open failed %d\n", err);
  1002. be->dpcm[stream].users--;
  1003. if (be->dpcm[stream].users < 0)
  1004. dev_err(be->dev, "no users %s at unwind - state %d\n",
  1005. stream ? "capture" : "playback",
  1006. be->dpcm[stream].state);
  1007. be->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE;
  1008. goto unwind;
  1009. }
  1010. be->dpcm[stream].state = SND_SOC_DPCM_STATE_OPEN;
  1011. count++;
  1012. }
  1013. return count;
  1014. unwind:
  1015. /* disable any enabled and non active backends */
  1016. list_for_each_entry_continue_reverse(dpcm_params, &fe->dpcm[stream].be_clients, list_be) {
  1017. struct snd_soc_pcm_runtime *be = dpcm_params->be;
  1018. struct snd_pcm_substream *be_substream =
  1019. snd_soc_dpcm_get_substream(be, stream);
  1020. if (!snd_soc_dpcm_be_can_update(fe, be, stream))
  1021. continue;
  1022. if (be->dpcm[stream].users == 0)
  1023. dev_err(be->dev, "no users %s at close - state %d\n",
  1024. stream ? "capture" : "playback", be->dpcm[stream].state);
  1025. if (--be->dpcm[stream].users != 0)
  1026. continue;
  1027. if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_OPEN)
  1028. continue;
  1029. soc_pcm_close(be_substream);
  1030. be_substream->runtime = NULL;
  1031. be->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE;
  1032. }
  1033. return err;
  1034. }
  1035. void soc_dpcm_set_dynamic_runtime(struct snd_pcm_substream *substream)
  1036. {
  1037. struct snd_pcm_runtime *runtime = substream->runtime;
  1038. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  1039. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  1040. struct snd_soc_dai_driver *cpu_dai_drv = cpu_dai->driver;
  1041. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  1042. runtime->hw.rate_min = cpu_dai_drv->playback.rate_min;
  1043. runtime->hw.rate_max = cpu_dai_drv->playback.rate_max;
  1044. runtime->hw.channels_min = cpu_dai_drv->playback.channels_min;
  1045. runtime->hw.channels_max = cpu_dai_drv->playback.channels_max;
  1046. runtime->hw.formats &= cpu_dai_drv->playback.formats;
  1047. runtime->hw.rates = cpu_dai_drv->playback.rates;
  1048. } else {
  1049. runtime->hw.rate_min = cpu_dai_drv->capture.rate_min;
  1050. runtime->hw.rate_max = cpu_dai_drv->capture.rate_max;
  1051. runtime->hw.channels_min = cpu_dai_drv->capture.channels_min;
  1052. runtime->hw.channels_max = cpu_dai_drv->capture.channels_max;
  1053. runtime->hw.formats &= cpu_dai_drv->capture.formats;
  1054. runtime->hw.rates = cpu_dai_drv->capture.rates;
  1055. }
  1056. }
  1057. static int soc_dpcm_fe_dai_startup(struct snd_pcm_substream *fe_substream)
  1058. {
  1059. struct snd_soc_pcm_runtime *fe = fe_substream->private_data;
  1060. struct snd_pcm_runtime *runtime = fe_substream->runtime;
  1061. int stream = fe_substream->stream, ret = 0;
  1062. fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE;
  1063. ret = dpcm_be_dai_startup(fe, fe_substream->stream);
  1064. if (ret < 0) {
  1065. dev_err(fe->dev,"dpcm: failed to start some BEs %d\n", ret);
  1066. goto be_err;
  1067. }
  1068. dev_info(fe->dev, "dpcm: open FE %s\n", fe->dai_link->name);
  1069. /* start the DAI frontend */
  1070. ret = soc_pcm_open(fe_substream);
  1071. if (ret < 0) {
  1072. dev_err(fe->dev,"dpcm: failed to start FE %d\n", ret);
  1073. goto unwind;
  1074. }
  1075. fe->dpcm[stream].state = SND_SOC_DPCM_STATE_OPEN;
  1076. soc_dpcm_set_dynamic_runtime(fe_substream);
  1077. snd_pcm_limit_hw_rates(runtime);
  1078. fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
  1079. return 0;
  1080. unwind:
  1081. soc_dpcm_be_dai_startup_unwind(fe, fe_substream->stream);
  1082. be_err:
  1083. fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
  1084. return ret;
  1085. }
  1086. /* BE shutdown - called on DAPM sync updates (i.e. FE is already running)*/
  1087. int dpcm_be_dai_shutdown(struct snd_soc_pcm_runtime *fe, int stream)
  1088. {
  1089. struct snd_soc_dpcm_params *dpcm_params;
  1090. /* only shutdown backends that are either sinks or sources to this frontend DAI */
  1091. list_for_each_entry(dpcm_params, &fe->dpcm[stream].be_clients, list_be) {
  1092. struct snd_soc_pcm_runtime *be = dpcm_params->be;
  1093. struct snd_pcm_substream *be_substream =
  1094. snd_soc_dpcm_get_substream(be, stream);
  1095. /* is this op for this BE ? */
  1096. if (!snd_soc_dpcm_be_can_update(fe, be, stream))
  1097. continue;
  1098. if (be->dpcm[stream].users == 0)
  1099. dev_err(be->dev, "no users %s at close - state %d\n",
  1100. stream ? "capture" : "playback", be->dpcm[stream].state);
  1101. if (--be->dpcm[stream].users != 0)
  1102. continue;
  1103. if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_FREE) &&
  1104. (be->dpcm[stream].state != SND_SOC_DPCM_STATE_OPEN))
  1105. continue;
  1106. dev_info(be->dev, "dpcm: close BE %s\n",
  1107. dpcm_params->fe->dai_link->name);
  1108. soc_pcm_close(be_substream);
  1109. be_substream->runtime = NULL;
  1110. be->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE;
  1111. }
  1112. return 0;
  1113. }
  1114. /* FE +BE shutdown - called on FE PCM ops */
  1115. static int soc_dpcm_fe_dai_shutdown(struct snd_pcm_substream *substream)
  1116. {
  1117. struct snd_soc_pcm_runtime *fe = substream->private_data;
  1118. int stream = substream->stream;
  1119. fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE;
  1120. dev_info(fe->dev, "dpcm: close FE %s\n", fe->dai_link->name);
  1121. /* now shutdown the frontend */
  1122. soc_pcm_close(substream);
  1123. /* shutdown the BEs */
  1124. dpcm_be_dai_shutdown(fe, substream->stream);
  1125. /* run the stream event for each BE */
  1126. if (stream == SNDRV_PCM_STREAM_PLAYBACK)
  1127. dpcm_dapm_stream_event(fe, stream,
  1128. fe->cpu_dai->driver->playback.stream_name,
  1129. SND_SOC_DAPM_STREAM_STOP);
  1130. else
  1131. dpcm_dapm_stream_event(fe, stream,
  1132. fe->cpu_dai->driver->capture.stream_name,
  1133. SND_SOC_DAPM_STREAM_STOP);
  1134. fe->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE;
  1135. fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
  1136. return 0;
  1137. }
  1138. int dpcm_be_dai_hw_params(struct snd_soc_pcm_runtime *fe, int stream)
  1139. {
  1140. struct snd_soc_dpcm_params *dpcm_params;
  1141. int ret;
  1142. list_for_each_entry(dpcm_params, &fe->dpcm[stream].be_clients, list_be) {
  1143. struct snd_soc_pcm_runtime *be = dpcm_params->be;
  1144. struct snd_pcm_substream *be_substream =
  1145. snd_soc_dpcm_get_substream(be, stream);
  1146. /* is this op for this BE ? */
  1147. if (!snd_soc_dpcm_be_can_update(fe, be, stream))
  1148. continue;
  1149. /* only allow hw_params() if no connected FEs are running */
  1150. if (!snd_soc_dpcm_can_be_params(fe, be, stream))
  1151. continue;
  1152. if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_OPEN) &&
  1153. (be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_PARAMS) &&
  1154. (be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_FREE))
  1155. continue;
  1156. dev_dbg(be->dev, "dpcm: hw_params BE %s\n",
  1157. dpcm_params->fe->dai_link->name);
  1158. /* copy params for each dpcm_params */
  1159. memcpy(&dpcm_params->hw_params, &fe->dpcm[stream].hw_params,
  1160. sizeof(struct snd_pcm_hw_params));
  1161. /* perform any hw_params fixups */
  1162. if (be->dai_link->be_hw_params_fixup) {
  1163. ret = be->dai_link->be_hw_params_fixup(be,
  1164. &dpcm_params->hw_params);
  1165. if (ret < 0) {
  1166. dev_err(be->dev,
  1167. "dpcm: hw_params BE fixup failed %d\n",
  1168. ret);
  1169. goto unwind;
  1170. }
  1171. }
  1172. ret = soc_pcm_hw_params(be_substream, &dpcm_params->hw_params);
  1173. if (ret < 0) {
  1174. dev_err(dpcm_params->be->dev, "dpcm: hw_params BE failed %d\n", ret);
  1175. goto unwind;
  1176. }
  1177. be->dpcm[stream].state = SND_SOC_DPCM_STATE_HW_PARAMS;
  1178. }
  1179. return 0;
  1180. unwind:
  1181. /* disable any enabled and non active backends */
  1182. list_for_each_entry_continue_reverse(dpcm_params, &fe->dpcm[stream].be_clients, list_be) {
  1183. struct snd_soc_pcm_runtime *be = dpcm_params->be;
  1184. struct snd_pcm_substream *be_substream =
  1185. snd_soc_dpcm_get_substream(be, stream);
  1186. if (!snd_soc_dpcm_be_can_update(fe, be, stream))
  1187. continue;
  1188. /* only allow hw_free() if no connected FEs are running */
  1189. if (!snd_soc_dpcm_can_be_free_stop(fe, be, stream))
  1190. continue;
  1191. if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_OPEN) &&
  1192. (be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_PARAMS) &&
  1193. (be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_FREE) &&
  1194. (be->dpcm[stream].state != SND_SOC_DPCM_STATE_STOP))
  1195. continue;
  1196. soc_pcm_hw_free(be_substream);
  1197. }
  1198. return ret;
  1199. }
  1200. int soc_dpcm_fe_dai_hw_params(struct snd_pcm_substream *substream,
  1201. struct snd_pcm_hw_params *params)
  1202. {
  1203. struct snd_soc_pcm_runtime *fe = substream->private_data;
  1204. int ret, stream = substream->stream;
  1205. mutex_lock(&fe->card->dpcm_mutex);
  1206. fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE;
  1207. memcpy(&fe->dpcm[substream->stream].hw_params, params,
  1208. sizeof(struct snd_pcm_hw_params));
  1209. ret = dpcm_be_dai_hw_params(fe, substream->stream);
  1210. if (ret < 0) {
  1211. dev_err(fe->dev,"dpcm: hw_params failed for some BEs %d\n", ret);
  1212. goto out;
  1213. }
  1214. dev_dbg(fe->dev, "dpcm: hw_params FE %s rate %d chan %x fmt %d\n",
  1215. fe->dai_link->name, params_rate(params), params_channels(params),
  1216. params_format(params));
  1217. /* call hw_params on the frontend */
  1218. ret = soc_pcm_hw_params(substream, params);
  1219. if (ret < 0) {
  1220. dev_err(fe->dev,"dpcm: hw_params FE failed %d\n", ret);
  1221. dpcm_be_dai_hw_free(fe, stream);
  1222. } else
  1223. fe->dpcm[stream].state = SND_SOC_DPCM_STATE_HW_PARAMS;
  1224. out:
  1225. fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
  1226. mutex_unlock(&fe->card->dpcm_mutex);
  1227. return ret;
  1228. }
  1229. static int dpcm_do_trigger(struct snd_soc_dpcm_params *dpcm_params,
  1230. struct snd_pcm_substream *substream, int cmd)
  1231. {
  1232. int ret;
  1233. dev_dbg(dpcm_params->be->dev, "dpcm: trigger BE %s cmd %d\n",
  1234. dpcm_params->fe->dai_link->name, cmd);
  1235. ret = soc_pcm_trigger(substream, cmd);
  1236. if (ret < 0)
  1237. dev_err(dpcm_params->be->dev,"dpcm: trigger BE failed %d\n", ret);
  1238. return ret;
  1239. }
  1240. int dpcm_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream, int cmd)
  1241. {
  1242. struct snd_soc_dpcm_params *dpcm_params;
  1243. int ret = 0;
  1244. list_for_each_entry(dpcm_params, &fe->dpcm[stream].be_clients, list_be) {
  1245. struct snd_soc_pcm_runtime *be = dpcm_params->be;
  1246. struct snd_pcm_substream *be_substream =
  1247. snd_soc_dpcm_get_substream(be, stream);
  1248. /* is this op for this BE ? */
  1249. if (!snd_soc_dpcm_be_can_update(fe, be, stream))
  1250. continue;
  1251. switch (cmd) {
  1252. case SNDRV_PCM_TRIGGER_START:
  1253. if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_PREPARE) &&
  1254. (be->dpcm[stream].state != SND_SOC_DPCM_STATE_STOP))
  1255. continue;
  1256. ret = dpcm_do_trigger(dpcm_params, be_substream, cmd);
  1257. if (ret)
  1258. return ret;
  1259. be->dpcm[stream].state = SND_SOC_DPCM_STATE_START;
  1260. break;
  1261. case SNDRV_PCM_TRIGGER_RESUME:
  1262. if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_SUSPEND))
  1263. continue;
  1264. ret = dpcm_do_trigger(dpcm_params, be_substream, cmd);
  1265. if (ret)
  1266. return ret;
  1267. be->dpcm[stream].state = SND_SOC_DPCM_STATE_START;
  1268. break;
  1269. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  1270. if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_PAUSED))
  1271. continue;
  1272. ret = dpcm_do_trigger(dpcm_params, be_substream, cmd);
  1273. if (ret)
  1274. return ret;
  1275. be->dpcm[stream].state = SND_SOC_DPCM_STATE_START;
  1276. break;
  1277. case SNDRV_PCM_TRIGGER_STOP:
  1278. if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_START)
  1279. continue;
  1280. if (!snd_soc_dpcm_can_be_free_stop(fe, be, stream))
  1281. continue;
  1282. ret = dpcm_do_trigger(dpcm_params, be_substream, cmd);
  1283. if (ret)
  1284. return ret;
  1285. be->dpcm[stream].state = SND_SOC_DPCM_STATE_STOP;
  1286. break;
  1287. case SNDRV_PCM_TRIGGER_SUSPEND:
  1288. if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_STOP)
  1289. continue;
  1290. if (!snd_soc_dpcm_can_be_free_stop(fe, be, stream))
  1291. continue;
  1292. ret = dpcm_do_trigger(dpcm_params, be_substream, cmd);
  1293. if (ret)
  1294. return ret;
  1295. be->dpcm[stream].state = SND_SOC_DPCM_STATE_SUSPEND;
  1296. break;
  1297. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  1298. if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_START)
  1299. continue;
  1300. if (!snd_soc_dpcm_can_be_free_stop(fe, be, stream))
  1301. continue;
  1302. ret = dpcm_do_trigger(dpcm_params, be_substream, cmd);
  1303. if (ret)
  1304. return ret;
  1305. be->dpcm[stream].state = SND_SOC_DPCM_STATE_PAUSED;
  1306. break;
  1307. }
  1308. }
  1309. return ret;
  1310. }
  1311. EXPORT_SYMBOL_GPL(dpcm_be_dai_trigger);
  1312. int soc_dpcm_fe_dai_trigger(struct snd_pcm_substream *substream, int cmd)
  1313. {
  1314. struct snd_soc_pcm_runtime *fe = substream->private_data;
  1315. int stream = substream->stream, ret;
  1316. enum snd_soc_dpcm_trigger trigger = fe->dai_link->trigger[stream];
  1317. fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE;
  1318. switch (trigger) {
  1319. case SND_SOC_DPCM_TRIGGER_PRE:
  1320. /* call trigger on the frontend before the backend. */
  1321. dev_dbg(fe->dev, "dpcm: pre trigger FE %s cmd %d\n",
  1322. fe->dai_link->name, cmd);
  1323. ret = soc_pcm_trigger(substream, cmd);
  1324. if (ret < 0) {
  1325. dev_err(fe->dev,"dpcm: trigger FE failed %d\n", ret);
  1326. goto out;
  1327. }
  1328. ret = dpcm_be_dai_trigger(fe, substream->stream, cmd);
  1329. break;
  1330. case SND_SOC_DPCM_TRIGGER_POST:
  1331. /* call trigger on the frontend after the backend. */
  1332. ret = dpcm_be_dai_trigger(fe, substream->stream, cmd);
  1333. if (ret < 0) {
  1334. dev_err(fe->dev,"dpcm: trigger FE failed %d\n", ret);
  1335. goto out;
  1336. }
  1337. dev_dbg(fe->dev, "dpcm: post trigger FE %s cmd %d\n",
  1338. fe->dai_link->name, cmd);
  1339. ret = soc_pcm_trigger(substream, cmd);
  1340. break;
  1341. case SND_SOC_DPCM_TRIGGER_BESPOKE:
  1342. /* bespoke trigger() - handles both FE and BEs */
  1343. dev_dbg(fe->dev, "dpcm: bespoke trigger FE %s cmd %d\n",
  1344. fe->dai_link->name, cmd);
  1345. ret = soc_pcm_bespoke_trigger(substream, cmd);
  1346. if (ret < 0) {
  1347. dev_err(fe->dev,"dpcm: trigger FE failed %d\n", ret);
  1348. goto out;
  1349. }
  1350. break;
  1351. default:
  1352. dev_err(fe->dev, "dpcm: invalid trigger cmd %d for %s\n", cmd,
  1353. fe->dai_link->name);
  1354. ret = -EINVAL;
  1355. goto out;
  1356. }
  1357. switch (cmd) {
  1358. case SNDRV_PCM_TRIGGER_START:
  1359. case SNDRV_PCM_TRIGGER_RESUME:
  1360. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  1361. fe->dpcm[stream].state = SND_SOC_DPCM_STATE_START;
  1362. break;
  1363. case SNDRV_PCM_TRIGGER_STOP:
  1364. case SNDRV_PCM_TRIGGER_SUSPEND:
  1365. fe->dpcm[stream].state = SND_SOC_DPCM_STATE_STOP;
  1366. break;
  1367. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  1368. fe->dpcm[stream].state = SND_SOC_DPCM_STATE_PAUSED;
  1369. break;
  1370. }
  1371. out:
  1372. fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
  1373. return ret;
  1374. }
  1375. int dpcm_be_dai_prepare(struct snd_soc_pcm_runtime *fe, int stream)
  1376. {
  1377. struct snd_soc_dpcm_params *dpcm_params;
  1378. int ret = 0;
  1379. list_for_each_entry(dpcm_params, &fe->dpcm[stream].be_clients, list_be) {
  1380. struct snd_soc_pcm_runtime *be = dpcm_params->be;
  1381. struct snd_pcm_substream *be_substream =
  1382. snd_soc_dpcm_get_substream(be, stream);
  1383. /* is this op for this BE ? */
  1384. if (!snd_soc_dpcm_be_can_update(fe, be, stream))
  1385. continue;
  1386. if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_PARAMS) &&
  1387. (be->dpcm[stream].state != SND_SOC_DPCM_STATE_STOP))
  1388. continue;
  1389. dev_dbg(be->dev, "dpcm: prepare BE %s\n",
  1390. dpcm_params->fe->dai_link->name);
  1391. ret = soc_pcm_prepare(be_substream);
  1392. if (ret < 0) {
  1393. dev_err(be->dev, "dpcm: backend prepare failed %d\n",
  1394. ret);
  1395. break;
  1396. }
  1397. be->dpcm[stream].state = SND_SOC_DPCM_STATE_PREPARE;
  1398. }
  1399. return ret;
  1400. }
  1401. int soc_dpcm_fe_dai_prepare(struct snd_pcm_substream *substream)
  1402. {
  1403. struct snd_soc_pcm_runtime *fe = substream->private_data;
  1404. int stream = substream->stream, ret = 0;
  1405. mutex_lock(&fe->card->dpcm_mutex);
  1406. dev_dbg(fe->dev, "dpcm: prepare FE %s\n", fe->dai_link->name);
  1407. fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE;
  1408. /* there is no point preparing this FE if there are no BEs */
  1409. if (list_empty(&fe->dpcm[stream].be_clients)) {
  1410. dev_err(fe->dev, "dpcm: no backend DAIs enabled for %s\n",
  1411. fe->dai_link->name);
  1412. ret = -EINVAL;
  1413. goto out;
  1414. }
  1415. ret = dpcm_be_dai_prepare(fe, substream->stream);
  1416. if (ret < 0) {
  1417. dev_err(fe->dev, "ASoC: prepare FE %s failed\n",
  1418. fe->dai_link->name);
  1419. goto out;
  1420. }
  1421. /* call prepare on the frontend */
  1422. if (!fe->fe_compr) {
  1423. ret = soc_pcm_prepare(substream);
  1424. if (ret < 0) {
  1425. dev_err(fe->dev, "ASoC: prepare FE %s failed\n",
  1426. fe->dai_link->name);
  1427. goto out;
  1428. }
  1429. }
  1430. /* run the stream event for each BE */
  1431. if (stream == SNDRV_PCM_STREAM_PLAYBACK)
  1432. dpcm_dapm_stream_event(fe, stream,
  1433. fe->cpu_dai->driver->playback.stream_name,
  1434. SND_SOC_DAPM_STREAM_START);
  1435. else
  1436. dpcm_dapm_stream_event(fe, stream,
  1437. fe->cpu_dai->driver->capture.stream_name,
  1438. SND_SOC_DAPM_STREAM_START);
  1439. fe->dpcm[stream].state = SND_SOC_DPCM_STATE_PREPARE;
  1440. out:
  1441. fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
  1442. mutex_unlock(&fe->card->dpcm_mutex);
  1443. return ret;
  1444. }
  1445. int dpcm_be_dai_hw_free(struct snd_soc_pcm_runtime *fe, int stream)
  1446. {
  1447. struct snd_soc_dpcm_params *dpcm_params;
  1448. /* only hw_params backends that are either sinks or sources
  1449. * to this frontend DAI */
  1450. list_for_each_entry(dpcm_params, &fe->dpcm[stream].be_clients, list_be) {
  1451. struct snd_soc_pcm_runtime *be = dpcm_params->be;
  1452. struct snd_pcm_substream *be_substream =
  1453. snd_soc_dpcm_get_substream(be, stream);
  1454. /* is this op for this BE ? */
  1455. if (!snd_soc_dpcm_be_can_update(fe, be, stream))
  1456. continue;
  1457. /* only free hw when no longer used - check all FEs */
  1458. if (!snd_soc_dpcm_can_be_free_stop(fe, be, stream))
  1459. continue;
  1460. if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_PARAMS) &&
  1461. (be->dpcm[stream].state != SND_SOC_DPCM_STATE_PREPARE) &&
  1462. (be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_FREE) &&
  1463. (be->dpcm[stream].state != SND_SOC_DPCM_STATE_PAUSED) &&
  1464. (be->dpcm[stream].state != SND_SOC_DPCM_STATE_STOP) &&
  1465. !((be->dpcm[stream].state == SND_SOC_DPCM_STATE_START) &&
  1466. ((fe->dpcm[stream].state != SND_SOC_DPCM_STATE_START) &&
  1467. (fe->dpcm[stream].state != SND_SOC_DPCM_STATE_PAUSED) &&
  1468. (fe->dpcm[stream].state !=
  1469. SND_SOC_DPCM_STATE_SUSPEND))))
  1470. continue;
  1471. dev_dbg(be->dev, "dpcm: hw_free BE %s\n",
  1472. dpcm_params->fe->dai_link->name);
  1473. soc_pcm_hw_free(be_substream);
  1474. be->dpcm[stream].state = SND_SOC_DPCM_STATE_HW_FREE;
  1475. }
  1476. return 0;
  1477. }
  1478. int soc_dpcm_fe_dai_hw_free(struct snd_pcm_substream *substream)
  1479. {
  1480. struct snd_soc_pcm_runtime *fe = substream->private_data;
  1481. int err, stream = substream->stream;
  1482. mutex_lock(&fe->card->dpcm_mutex);
  1483. fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE;
  1484. dev_dbg(fe->dev, "dpcm: hw_free FE %s\n", fe->dai_link->name);
  1485. /* call hw_free on the frontend */
  1486. err = soc_pcm_hw_free(substream);
  1487. if (err < 0)
  1488. dev_err(fe->dev,"dpcm: hw_free FE %s failed\n", fe->dai_link->name);
  1489. /* only hw_params backends that are either sinks or sources
  1490. * to this frontend DAI */
  1491. err = dpcm_be_dai_hw_free(fe, stream);
  1492. fe->dpcm[stream].state = SND_SOC_DPCM_STATE_HW_FREE;
  1493. fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
  1494. mutex_unlock(&fe->card->dpcm_mutex);
  1495. return 0;
  1496. }
  1497. static int soc_pcm_ioctl(struct snd_pcm_substream *substream,
  1498. unsigned int cmd, void *arg)
  1499. {
  1500. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  1501. struct snd_soc_platform *platform = rtd->platform;
  1502. if (platform->driver->ops->ioctl)
  1503. return platform->driver->ops->ioctl(substream, cmd, arg);
  1504. return snd_pcm_lib_ioctl(substream, cmd, arg);
  1505. }
  1506. static int dpcm_run_update_shutdown(struct snd_soc_pcm_runtime *fe, int stream)
  1507. {
  1508. struct snd_pcm_substream *substream = snd_soc_dpcm_get_substream(fe, stream);
  1509. enum snd_soc_dpcm_trigger trigger = fe->dai_link->trigger[stream];
  1510. int err;
  1511. dev_dbg(fe->dev, "runtime %s close on FE %s\n",
  1512. stream ? "capture" : "playback", fe->dai_link->name);
  1513. if (trigger == SND_SOC_DPCM_TRIGGER_BESPOKE) {
  1514. /* call bespoke trigger - FE takes care of all BE triggers */
  1515. dev_dbg(fe->dev, "dpcm: bespoke trigger FE %s cmd stop\n",
  1516. fe->dai_link->name);
  1517. err = soc_pcm_bespoke_trigger(substream, SNDRV_PCM_TRIGGER_STOP);
  1518. if (err < 0)
  1519. dev_err(fe->dev,"dpcm: trigger FE failed %d\n", err);
  1520. } else {
  1521. dev_dbg(fe->dev, "dpcm: trigger FE %s cmd stop\n",
  1522. fe->dai_link->name);
  1523. err = dpcm_be_dai_trigger(fe, stream, SNDRV_PCM_TRIGGER_STOP);
  1524. if (err < 0)
  1525. dev_err(fe->dev,"dpcm: trigger FE failed %d\n", err);
  1526. }
  1527. err = dpcm_be_dai_hw_free(fe, stream);
  1528. if (err < 0)
  1529. dev_err(fe->dev,"dpcm: hw_free FE failed %d\n", err);
  1530. err = dpcm_be_dai_shutdown(fe, stream);
  1531. if (err < 0)
  1532. dev_err(fe->dev,"dpcm: shutdown FE failed %d\n", err);
  1533. /* run the stream event for each BE */
  1534. if (stream == SNDRV_PCM_STREAM_PLAYBACK)
  1535. dpcm_dapm_stream_event(fe, stream,
  1536. fe->cpu_dai->driver->playback.stream_name,
  1537. SND_SOC_DAPM_STREAM_NOP);
  1538. else
  1539. dpcm_dapm_stream_event(fe, stream,
  1540. fe->cpu_dai->driver->capture.stream_name,
  1541. SND_SOC_DAPM_STREAM_NOP);
  1542. return 0;
  1543. }
  1544. static int dpcm_run_update_startup(struct snd_soc_pcm_runtime *fe, int stream)
  1545. {
  1546. struct snd_pcm_substream *substream = snd_soc_dpcm_get_substream(fe, stream);
  1547. struct snd_soc_dpcm_params *dpcm_params;
  1548. enum snd_soc_dpcm_trigger trigger = fe->dai_link->trigger[stream];
  1549. int ret;
  1550. dev_dbg(fe->dev, "runtime %s open on FE %s\n",
  1551. stream ? "capture" : "playback", fe->dai_link->name);
  1552. /* Only start the BE if the FE is ready */
  1553. if (fe->dpcm[stream].state == SND_SOC_DPCM_STATE_HW_FREE ||
  1554. fe->dpcm[stream].state == SND_SOC_DPCM_STATE_CLOSE)
  1555. return -EINVAL;
  1556. /* startup must always be called for new BEs */
  1557. ret = dpcm_be_dai_startup(fe, stream);
  1558. if (ret < 0) {
  1559. goto disconnect;
  1560. return ret;
  1561. }
  1562. /* keep going if FE state is > open */
  1563. if (fe->dpcm[stream].state == SND_SOC_DPCM_STATE_OPEN)
  1564. return 0;
  1565. ret = dpcm_be_dai_hw_params(fe, stream);
  1566. if (ret < 0) {
  1567. goto close;
  1568. return ret;
  1569. }
  1570. /* keep going if FE state is > hw_params */
  1571. if (fe->dpcm[stream].state == SND_SOC_DPCM_STATE_HW_PARAMS)
  1572. return 0;
  1573. ret = dpcm_be_dai_prepare(fe, stream);
  1574. if (ret < 0) {
  1575. goto hw_free;
  1576. return ret;
  1577. }
  1578. /* run the stream event for each BE */
  1579. if (stream == SNDRV_PCM_STREAM_PLAYBACK)
  1580. dpcm_dapm_stream_event(fe, stream,
  1581. fe->cpu_dai->driver->playback.stream_name,
  1582. SND_SOC_DAPM_STREAM_NOP);
  1583. else
  1584. dpcm_dapm_stream_event(fe, stream,
  1585. fe->cpu_dai->driver->capture.stream_name,
  1586. SND_SOC_DAPM_STREAM_NOP);
  1587. /* keep going if FE state is > prepare */
  1588. if (fe->dpcm[stream].state == SND_SOC_DPCM_STATE_PREPARE ||
  1589. fe->dpcm[stream].state == SND_SOC_DPCM_STATE_STOP)
  1590. return 0;
  1591. if (trigger == SND_SOC_DPCM_TRIGGER_BESPOKE) {
  1592. /* call trigger on the frontend - FE takes care of all BE triggers */
  1593. dev_dbg(fe->dev, "dpcm: bespoke trigger FE %s cmd start\n",
  1594. fe->dai_link->name);
  1595. ret = soc_pcm_bespoke_trigger(substream, SNDRV_PCM_TRIGGER_START);
  1596. if (ret < 0) {
  1597. dev_err(fe->dev,"dpcm: bespoke trigger FE failed %d\n", ret);
  1598. goto hw_free;
  1599. }
  1600. } else {
  1601. dev_dbg(fe->dev, "dpcm: trigger FE %s cmd start\n",
  1602. fe->dai_link->name);
  1603. ret = dpcm_be_dai_trigger(fe, stream,
  1604. SNDRV_PCM_TRIGGER_START);
  1605. if (ret < 0) {
  1606. dev_err(fe->dev,"dpcm: trigger FE failed %d\n", ret);
  1607. goto hw_free;
  1608. }
  1609. }
  1610. return 0;
  1611. hw_free:
  1612. dpcm_be_dai_hw_free(fe, stream);
  1613. close:
  1614. dpcm_be_dai_shutdown(fe, stream);
  1615. disconnect:
  1616. /* disconnect any non started BEs */
  1617. list_for_each_entry(dpcm_params, &fe->dpcm[stream].be_clients, list_be) {
  1618. struct snd_soc_pcm_runtime *be = dpcm_params->be;
  1619. if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_START)
  1620. dpcm_params->state = SND_SOC_DPCM_LINK_STATE_FREE;
  1621. }
  1622. return ret;
  1623. }
  1624. static int dpcm_run_new_update(struct snd_soc_pcm_runtime *fe, int stream)
  1625. {
  1626. int ret;
  1627. fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_BE;
  1628. ret = dpcm_run_update_startup(fe, stream);
  1629. if (ret < 0)
  1630. dev_err(fe->dev, "failed to startup some BEs\n");
  1631. fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
  1632. return ret;
  1633. }
  1634. static int dpcm_run_old_update(struct snd_soc_pcm_runtime *fe, int stream)
  1635. {
  1636. int ret;
  1637. fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_BE;
  1638. ret = dpcm_run_update_shutdown(fe, stream);
  1639. if (ret < 0)
  1640. dev_err(fe->dev, "failed to shutdown some BEs\n");
  1641. fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
  1642. return ret;
  1643. }
  1644. /* called when any mixer updates change FE -> BE the stream */
  1645. int soc_dpcm_runtime_update(struct snd_soc_dapm_widget *widget)
  1646. {
  1647. struct snd_soc_card *card;
  1648. int i, ret = 0, old, new, paths;
  1649. if (widget->codec)
  1650. card = widget->codec->card;
  1651. else if (widget->platform)
  1652. card = widget->platform->card;
  1653. else
  1654. return -EINVAL;
  1655. mutex_lock(&card->dpcm_mutex);
  1656. for (i = 0; i < card->num_rtd; i++) {
  1657. struct snd_soc_dapm_widget_list *list;
  1658. struct snd_soc_pcm_runtime *fe = &card->rtd[i];
  1659. /* make sure link is FE */
  1660. if (!fe->dai_link->dynamic)
  1661. continue;
  1662. /* only check active links */
  1663. if (!fe->cpu_dai->active)
  1664. continue;
  1665. /* DAPM sync will call this to update DSP paths */
  1666. dev_dbg(fe->dev, "DPCM runtime update for FE %s\n", fe->dai_link->name);
  1667. /* skip if FE doesn't have playback capability */
  1668. if (!fe->cpu_dai->driver->playback.channels_min)
  1669. goto capture;
  1670. paths = dpcm_path_get(fe, SNDRV_PCM_STREAM_PLAYBACK, &list);
  1671. if (paths < 0) {
  1672. dev_warn(fe->dev, "%s no valid %s route from source to sink\n",
  1673. fe->dai_link->name, "playback");
  1674. ret = paths;
  1675. goto out;
  1676. }
  1677. /* update any new playback paths */
  1678. new = dpcm_process_paths(fe, SNDRV_PCM_STREAM_PLAYBACK, &list, 1);
  1679. if (new) {
  1680. dpcm_run_new_update(fe, SNDRV_PCM_STREAM_PLAYBACK);
  1681. dpcm_clear_pending_state(fe, SNDRV_PCM_STREAM_PLAYBACK);
  1682. dpcm_be_disconnect(fe, SNDRV_PCM_STREAM_PLAYBACK);
  1683. }
  1684. /* update any old playback paths */
  1685. old = dpcm_process_paths(fe, SNDRV_PCM_STREAM_PLAYBACK, &list, 0);
  1686. if (old) {
  1687. dpcm_run_old_update(fe, SNDRV_PCM_STREAM_PLAYBACK);
  1688. dpcm_clear_pending_state(fe, SNDRV_PCM_STREAM_PLAYBACK);
  1689. dpcm_be_disconnect(fe, SNDRV_PCM_STREAM_PLAYBACK);
  1690. }
  1691. dpcm_path_put(&list);
  1692. capture:
  1693. /* skip if FE doesn't have capture capability */
  1694. if (!fe->cpu_dai->driver->capture.channels_min)
  1695. continue;
  1696. paths = dpcm_path_get(fe, SNDRV_PCM_STREAM_CAPTURE, &list);
  1697. if (paths < 0) {
  1698. dev_warn(fe->dev, "%s no valid %s route from source to sink\n",
  1699. fe->dai_link->name, "capture");
  1700. ret = paths;
  1701. goto out;
  1702. }
  1703. /* update any new capture paths */
  1704. new = dpcm_process_paths(fe, SNDRV_PCM_STREAM_CAPTURE, &list, 1);
  1705. if (new) {
  1706. dpcm_run_new_update(fe, SNDRV_PCM_STREAM_CAPTURE);
  1707. dpcm_clear_pending_state(fe, SNDRV_PCM_STREAM_CAPTURE);
  1708. dpcm_be_disconnect(fe, SNDRV_PCM_STREAM_CAPTURE);
  1709. }
  1710. /* update any old capture paths */
  1711. old = dpcm_process_paths(fe, SNDRV_PCM_STREAM_CAPTURE, &list, 0);
  1712. if (old) {
  1713. dpcm_run_old_update(fe, SNDRV_PCM_STREAM_CAPTURE);
  1714. dpcm_clear_pending_state(fe, SNDRV_PCM_STREAM_CAPTURE);
  1715. dpcm_be_disconnect(fe, SNDRV_PCM_STREAM_CAPTURE);
  1716. }
  1717. dpcm_path_put(&list);
  1718. }
  1719. out:
  1720. mutex_unlock(&card->dpcm_mutex);
  1721. return ret;
  1722. }
  1723. int soc_dpcm_be_digital_mute(struct snd_soc_pcm_runtime *fe, int mute)
  1724. {
  1725. struct snd_soc_dpcm_params *dpcm_params;
  1726. list_for_each_entry(dpcm_params,
  1727. &fe->dpcm[SNDRV_PCM_STREAM_PLAYBACK].be_clients, list_be) {
  1728. struct snd_soc_pcm_runtime *be = dpcm_params->be;
  1729. struct snd_soc_dai *dai = be->codec_dai;
  1730. struct snd_soc_dai_driver *drv = dai->driver;
  1731. if (be->dai_link->ignore_suspend)
  1732. continue;
  1733. dev_dbg(be->dev, "BE digital mute %s\n", be->dai_link->name);
  1734. if (drv->ops->digital_mute && dai->playback_active)
  1735. drv->ops->digital_mute(dai, mute);
  1736. }
  1737. return 0;
  1738. }
  1739. int soc_dpcm_be_cpu_dai_suspend(struct snd_soc_pcm_runtime *fe)
  1740. {
  1741. struct snd_soc_dpcm_params *dpcm_params;
  1742. /* suspend for playback */
  1743. list_for_each_entry(dpcm_params,
  1744. &fe->dpcm[SNDRV_PCM_STREAM_PLAYBACK].be_clients, list_be) {
  1745. struct snd_soc_pcm_runtime *be = dpcm_params->be;
  1746. struct snd_soc_dai *dai = be->cpu_dai;
  1747. struct snd_soc_dai_driver *drv = dai->driver;
  1748. if (be->dai_link->ignore_suspend)
  1749. continue;
  1750. dev_dbg(be->dev, "pm: BE CPU DAI playback suspend %s\n",
  1751. be->dai_link->name);
  1752. if (drv->suspend && !drv->ac97_control)
  1753. drv->suspend(dai);
  1754. }
  1755. /* suspend for capture */
  1756. list_for_each_entry(dpcm_params,
  1757. &fe->dpcm[SNDRV_PCM_STREAM_CAPTURE].be_clients, list_be) {
  1758. struct snd_soc_pcm_runtime *be = dpcm_params->be;
  1759. struct snd_soc_dai *dai = be->cpu_dai;
  1760. struct snd_soc_dai_driver *drv = dai->driver;
  1761. if (be->dai_link->ignore_suspend)
  1762. continue;
  1763. dev_dbg(be->dev, "pm: BE CPU DAI capture suspend %s\n",
  1764. be->dai_link->name);
  1765. if (drv->suspend && !drv->ac97_control)
  1766. drv->suspend(dai);
  1767. }
  1768. return 0;
  1769. }
  1770. int soc_dpcm_be_ac97_cpu_dai_suspend(struct snd_soc_pcm_runtime *fe)
  1771. {
  1772. struct snd_soc_dpcm_params *dpcm_params;
  1773. /* suspend for playback */
  1774. list_for_each_entry(dpcm_params,
  1775. &fe->dpcm[SNDRV_PCM_STREAM_PLAYBACK].be_clients, list_be) {
  1776. struct snd_soc_pcm_runtime *be = dpcm_params->be;
  1777. struct snd_soc_dai *dai = be->cpu_dai;
  1778. struct snd_soc_dai_driver *drv = dai->driver;
  1779. if (be->dai_link->ignore_suspend)
  1780. continue;
  1781. dev_dbg(be->dev, "pm: BE CPU DAI playback suspend %s\n",
  1782. be->dai_link->name);
  1783. if (drv->suspend && drv->ac97_control)
  1784. drv->suspend(dai);
  1785. }
  1786. /* suspend for capture */
  1787. list_for_each_entry(dpcm_params,
  1788. &fe->dpcm[SNDRV_PCM_STREAM_CAPTURE].be_clients, list_be) {
  1789. struct snd_soc_pcm_runtime *be = dpcm_params->be;
  1790. struct snd_soc_dai *dai = be->cpu_dai;
  1791. struct snd_soc_dai_driver *drv = dai->driver;
  1792. if (be->dai_link->ignore_suspend)
  1793. continue;
  1794. dev_dbg(be->dev, "pm: BE CPU DAI capture suspend %s\n",
  1795. be->dai_link->name);
  1796. if (drv->suspend && drv->ac97_control)
  1797. drv->suspend(dai);
  1798. }
  1799. return 0;
  1800. }
  1801. int soc_dpcm_be_platform_suspend(struct snd_soc_pcm_runtime *fe)
  1802. {
  1803. struct snd_soc_dpcm_params *dpcm_params;
  1804. /* suspend for playback */
  1805. list_for_each_entry(dpcm_params,
  1806. &fe->dpcm[SNDRV_PCM_STREAM_PLAYBACK].be_clients, list_be) {
  1807. struct snd_soc_pcm_runtime *be = dpcm_params->be;
  1808. struct snd_soc_platform *platform = be->platform;
  1809. struct snd_soc_platform_driver *drv = platform->driver;
  1810. struct snd_soc_dai *dai = be->cpu_dai;
  1811. if (be->dai_link->ignore_suspend)
  1812. continue;
  1813. dev_dbg(be->dev, "pm: BE platform playback suspend %s\n",
  1814. be->dai_link->name);
  1815. if (drv->suspend && !platform->suspended) {
  1816. drv->suspend(dai);
  1817. platform->suspended = 1;
  1818. }
  1819. }
  1820. /* suspend for capture */
  1821. list_for_each_entry(dpcm_params,
  1822. &fe->dpcm[SNDRV_PCM_STREAM_CAPTURE].be_clients, list_be) {
  1823. struct snd_soc_pcm_runtime *be = dpcm_params->be;
  1824. struct snd_soc_platform *platform = be->platform;
  1825. struct snd_soc_platform_driver *drv = platform->driver;
  1826. struct snd_soc_dai *dai = be->cpu_dai;
  1827. if (be->dai_link->ignore_suspend)
  1828. continue;
  1829. dev_dbg(be->dev, "pm: BE platform capture suspend %s\n",
  1830. be->dai_link->name);
  1831. if (drv->suspend && !platform->suspended) {
  1832. drv->suspend(dai);
  1833. platform->suspended = 1;
  1834. }
  1835. }
  1836. return 0;
  1837. }
  1838. int soc_dpcm_fe_suspend(struct snd_soc_pcm_runtime *fe)
  1839. {
  1840. struct snd_soc_dai *dai = fe->cpu_dai;
  1841. struct snd_soc_dai_driver *dai_drv = dai->driver;
  1842. struct snd_soc_platform *platform = fe->platform;
  1843. struct snd_soc_platform_driver *plat_drv = platform->driver;
  1844. if (dai_drv->suspend && !dai_drv->ac97_control)
  1845. dai_drv->suspend(dai);
  1846. if (plat_drv->suspend && !platform->suspended) {
  1847. plat_drv->suspend(dai);
  1848. platform->suspended = 1;
  1849. }
  1850. soc_dpcm_be_cpu_dai_suspend(fe);
  1851. soc_dpcm_be_platform_suspend(fe);
  1852. return 0;
  1853. }
  1854. int soc_dpcm_be_cpu_dai_resume(struct snd_soc_pcm_runtime *fe)
  1855. {
  1856. struct snd_soc_dpcm_params *dpcm_params;
  1857. /* resume for playback */
  1858. list_for_each_entry(dpcm_params,
  1859. &fe->dpcm[SNDRV_PCM_STREAM_PLAYBACK].be_clients, list_be) {
  1860. struct snd_soc_pcm_runtime *be = dpcm_params->be;
  1861. struct snd_soc_dai *dai = be->cpu_dai;
  1862. struct snd_soc_dai_driver *drv = dai->driver;
  1863. if (be->dai_link->ignore_suspend)
  1864. continue;
  1865. dev_dbg(be->dev, "pm: BE CPU DAI playback resume %s\n",
  1866. be->dai_link->name);
  1867. if (drv->resume && !drv->ac97_control)
  1868. drv->resume(dai);
  1869. }
  1870. /* suspend for capture */
  1871. list_for_each_entry(dpcm_params,
  1872. &fe->dpcm[SNDRV_PCM_STREAM_CAPTURE].be_clients, list_be) {
  1873. struct snd_soc_pcm_runtime *be = dpcm_params->be;
  1874. struct snd_soc_dai *dai = be->cpu_dai;
  1875. struct snd_soc_dai_driver *drv = dai->driver;
  1876. if (be->dai_link->ignore_suspend)
  1877. continue;
  1878. dev_dbg(be->dev, "pm: BE CPU DAI capture resume %s\n",
  1879. be->dai_link->name);
  1880. if (drv->resume && !drv->ac97_control)
  1881. drv->resume(dai);
  1882. }
  1883. return 0;
  1884. }
  1885. int soc_dpcm_be_ac97_cpu_dai_resume(struct snd_soc_pcm_runtime *fe)
  1886. {
  1887. struct snd_soc_dpcm_params *dpcm_params;
  1888. /* resume for playback */
  1889. list_for_each_entry(dpcm_params,
  1890. &fe->dpcm[SNDRV_PCM_STREAM_PLAYBACK].be_clients, list_be) {
  1891. struct snd_soc_pcm_runtime *be = dpcm_params->be;
  1892. struct snd_soc_dai *dai = be->cpu_dai;
  1893. struct snd_soc_dai_driver *drv = dai->driver;
  1894. if (be->dai_link->ignore_suspend)
  1895. continue;
  1896. dev_dbg(be->dev, "pm: BE CPU DAI playback resume %s\n",
  1897. be->dai_link->name);
  1898. if (drv->resume && drv->ac97_control)
  1899. drv->resume(dai);
  1900. }
  1901. /* suspend for capture */
  1902. list_for_each_entry(dpcm_params,
  1903. &fe->dpcm[SNDRV_PCM_STREAM_CAPTURE].be_clients, list_be) {
  1904. struct snd_soc_pcm_runtime *be = dpcm_params->be;
  1905. struct snd_soc_dai *dai = be->cpu_dai;
  1906. struct snd_soc_dai_driver *drv = dai->driver;
  1907. if (be->dai_link->ignore_suspend)
  1908. continue;
  1909. dev_dbg(be->dev, "pm: BE CPU DAI capture resume %s\n",
  1910. be->dai_link->name);
  1911. if (drv->resume && drv->ac97_control)
  1912. drv->resume(dai);
  1913. }
  1914. return 0;
  1915. }
  1916. int soc_dpcm_be_platform_resume(struct snd_soc_pcm_runtime *fe)
  1917. {
  1918. struct snd_soc_dpcm_params *dpcm_params;
  1919. /* resume for playback */
  1920. list_for_each_entry(dpcm_params,
  1921. &fe->dpcm[SNDRV_PCM_STREAM_PLAYBACK].be_clients, list_be) {
  1922. struct snd_soc_pcm_runtime *be = dpcm_params->be;
  1923. struct snd_soc_platform *platform = be->platform;
  1924. struct snd_soc_platform_driver *drv = platform->driver;
  1925. struct snd_soc_dai *dai = be->cpu_dai;
  1926. if (be->dai_link->ignore_suspend)
  1927. continue;
  1928. dev_dbg(be->dev, "pm: BE platform playback resume %s\n",
  1929. be->dai_link->name);
  1930. if (drv->resume && platform->suspended) {
  1931. drv->resume(dai);
  1932. platform->suspended = 0;
  1933. }
  1934. }
  1935. /* resume for capture */
  1936. list_for_each_entry(dpcm_params,
  1937. &fe->dpcm[SNDRV_PCM_STREAM_CAPTURE].be_clients, list_be) {
  1938. struct snd_soc_pcm_runtime *be = dpcm_params->be;
  1939. struct snd_soc_platform *platform = be->platform;
  1940. struct snd_soc_platform_driver *drv = platform->driver;
  1941. struct snd_soc_dai *dai = be->cpu_dai;
  1942. if (be->dai_link->ignore_suspend)
  1943. continue;
  1944. dev_dbg(be->dev, "pm: BE platform capture resume %s\n",
  1945. be->dai_link->name);
  1946. if (drv->resume && platform->suspended) {
  1947. drv->resume(dai);
  1948. platform->suspended = 0;
  1949. }
  1950. }
  1951. return 0;
  1952. }
  1953. int soc_dpcm_fe_resume(struct snd_soc_pcm_runtime *fe)
  1954. {
  1955. struct snd_soc_dai *dai = fe->cpu_dai;
  1956. struct snd_soc_dai_driver *dai_drv = dai->driver;
  1957. struct snd_soc_platform *platform = fe->platform;
  1958. struct snd_soc_platform_driver *plat_drv = platform->driver;
  1959. soc_dpcm_be_cpu_dai_resume(fe);
  1960. soc_dpcm_be_platform_resume(fe);
  1961. if (dai_drv->resume && !dai_drv->ac97_control)
  1962. dai_drv->resume(dai);
  1963. if (plat_drv->resume && platform->suspended) {
  1964. plat_drv->resume(dai);
  1965. platform->suspended = 0;
  1966. }
  1967. return 0;
  1968. }
  1969. /* called when opening FE stream */
  1970. int soc_dpcm_fe_dai_open(struct snd_pcm_substream *fe_substream)
  1971. {
  1972. struct snd_soc_pcm_runtime *fe = fe_substream->private_data;
  1973. struct snd_soc_dpcm_params *dpcm_params;
  1974. struct snd_soc_dapm_widget_list *list;
  1975. int ret;
  1976. int stream = fe_substream->stream;
  1977. mutex_lock(&fe->card->dpcm_mutex);
  1978. fe->dpcm[stream].runtime = fe_substream->runtime;
  1979. if (dpcm_path_get(fe, stream, &list) <= 0) {
  1980. dev_warn(fe->dev, "asoc: %s no valid %s route from source to sink\n",
  1981. fe->dai_link->name, stream ? "capture" : "playback");
  1982. mutex_unlock(&fe->card->dpcm_mutex);
  1983. return -EINVAL;
  1984. }
  1985. /* calculate valid and active FE <-> BE dpcm_paramss */
  1986. dpcm_process_paths(fe, stream, &list, 1);
  1987. ret = soc_dpcm_fe_dai_startup(fe_substream);
  1988. if (ret < 0) {
  1989. /* clean up all links */
  1990. list_for_each_entry(dpcm_params, &fe->dpcm[stream].be_clients, list_be)
  1991. dpcm_params->state = SND_SOC_DPCM_LINK_STATE_FREE;
  1992. dpcm_be_disconnect(fe, stream);
  1993. fe->dpcm[stream].runtime = NULL;
  1994. }
  1995. dpcm_clear_pending_state(fe, stream);
  1996. dpcm_path_put(&list);
  1997. mutex_unlock(&fe->card->dpcm_mutex);
  1998. return ret;
  1999. }
  2000. /* called when closing FE stream */
  2001. int soc_dpcm_fe_dai_close(struct snd_pcm_substream *fe_substream)
  2002. {
  2003. struct snd_soc_pcm_runtime *fe = fe_substream->private_data;
  2004. struct snd_soc_dpcm_params *dpcm_params;
  2005. int stream = fe_substream->stream, ret;
  2006. mutex_lock(&fe->card->dpcm_mutex);
  2007. ret = soc_dpcm_fe_dai_shutdown(fe_substream);
  2008. /* mark FE's links ready to prune */
  2009. list_for_each_entry(dpcm_params, &fe->dpcm[stream].be_clients, list_be)
  2010. dpcm_params->state = SND_SOC_DPCM_LINK_STATE_FREE;
  2011. dpcm_be_disconnect(fe, stream);
  2012. fe->dpcm[stream].runtime = NULL;
  2013. mutex_unlock(&fe->card->dpcm_mutex);
  2014. return ret;
  2015. }
  2016. /* create a new pcm */
  2017. int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
  2018. {
  2019. struct snd_soc_codec *codec = rtd->codec;
  2020. struct snd_soc_platform *platform = rtd->platform;
  2021. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  2022. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  2023. struct snd_pcm_substream *substream[2];
  2024. struct snd_pcm *pcm;
  2025. char new_name[64];
  2026. int ret = 0, playback = 0, capture = 0;
  2027. if (rtd->dai_link->dynamic || rtd->dai_link->no_pcm) {
  2028. if (cpu_dai->driver->playback.channels_min)
  2029. playback = 1;
  2030. if (cpu_dai->driver->capture.channels_min)
  2031. capture = 1;
  2032. } else {
  2033. if (codec_dai->driver->playback.channels_min)
  2034. playback = 1;
  2035. if (codec_dai->driver->capture.channels_min)
  2036. capture = 1;
  2037. }
  2038. /* create the PCM */
  2039. if (rtd->dai_link->no_pcm) {
  2040. snprintf(new_name, sizeof(new_name), "(%s)",
  2041. rtd->dai_link->stream_name);
  2042. ret = snd_pcm_new_soc_be(rtd->card->snd_card, new_name, num,
  2043. playback, capture, &pcm);
  2044. } else {
  2045. if (rtd->dai_link->dynamic)
  2046. snprintf(new_name, sizeof(new_name), "%s (*)",
  2047. rtd->dai_link->stream_name);
  2048. else
  2049. snprintf(new_name, sizeof(new_name), "%s %s-%d",
  2050. rtd->dai_link->stream_name, codec_dai->name, num);
  2051. ret = snd_pcm_new(rtd->card->snd_card, new_name, num, playback,
  2052. capture, &pcm);
  2053. }
  2054. if (ret < 0) {
  2055. printk(KERN_ERR "asoc: can't create pcm for codec %s\n", codec->name);
  2056. return ret;
  2057. }
  2058. dev_dbg(rtd->card->dev, "registered pcm #%d %s\n",num, new_name);
  2059. rtd->pcm = pcm;
  2060. pcm->private_data = rtd;
  2061. INIT_DELAYED_WORK(&rtd->delayed_work, close_delayed_work);
  2062. substream[SNDRV_PCM_STREAM_PLAYBACK] =
  2063. pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream;
  2064. substream[SNDRV_PCM_STREAM_CAPTURE] =
  2065. pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream;
  2066. if (rtd->dai_link->no_pcm) {
  2067. if (playback)
  2068. substream[SNDRV_PCM_STREAM_PLAYBACK]->private_data = rtd;
  2069. if (capture)
  2070. substream[SNDRV_PCM_STREAM_CAPTURE]->private_data = rtd;
  2071. goto out;
  2072. }
  2073. /* setup any hostless PCMs - i.e. no host IO is performed */
  2074. if (rtd->dai_link->no_host_mode) {
  2075. if (substream[SNDRV_PCM_STREAM_PLAYBACK]) {
  2076. substream[SNDRV_PCM_STREAM_PLAYBACK]->hw_no_buffer = 1;
  2077. snd_soc_set_runtime_hwparams(
  2078. substream[SNDRV_PCM_STREAM_PLAYBACK],
  2079. &no_host_hardware);
  2080. }
  2081. if (substream[SNDRV_PCM_STREAM_CAPTURE]) {
  2082. substream[SNDRV_PCM_STREAM_CAPTURE]->hw_no_buffer = 1;
  2083. snd_soc_set_runtime_hwparams(
  2084. substream[SNDRV_PCM_STREAM_CAPTURE],
  2085. &no_host_hardware);
  2086. }
  2087. }
  2088. /* ASoC PCM operations */
  2089. if (rtd->dai_link->dynamic) {
  2090. rtd->ops.open = soc_dpcm_fe_dai_open;
  2091. rtd->ops.hw_params = soc_dpcm_fe_dai_hw_params;
  2092. rtd->ops.prepare = soc_dpcm_fe_dai_prepare;
  2093. rtd->ops.trigger = soc_dpcm_fe_dai_trigger;
  2094. rtd->ops.hw_free = soc_dpcm_fe_dai_hw_free;
  2095. rtd->ops.close = soc_dpcm_fe_dai_close;
  2096. rtd->ops.pointer = soc_pcm_pointer;
  2097. rtd->ops.ioctl = soc_pcm_ioctl;
  2098. } else {
  2099. rtd->ops.open = soc_pcm_open;
  2100. rtd->ops.hw_params = soc_pcm_hw_params;
  2101. rtd->ops.prepare = soc_pcm_prepare;
  2102. rtd->ops.trigger = soc_pcm_trigger;
  2103. rtd->ops.hw_free = soc_pcm_hw_free;
  2104. rtd->ops.close = soc_pcm_close;
  2105. rtd->ops.pointer = soc_pcm_pointer;
  2106. rtd->ops.ioctl = soc_pcm_ioctl;
  2107. }
  2108. if (platform->driver->ops) {
  2109. rtd->ops.ack = platform->driver->ops->ack;
  2110. rtd->ops.copy = platform->driver->ops->copy;
  2111. rtd->ops.silence = platform->driver->ops->silence;
  2112. rtd->ops.page = platform->driver->ops->page;
  2113. rtd->ops.mmap = platform->driver->ops->mmap;
  2114. rtd->ops.restart = platform->driver->ops->restart;
  2115. }
  2116. if (playback)
  2117. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &rtd->ops);
  2118. if (capture)
  2119. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &rtd->ops);
  2120. if (platform->driver->pcm_new) {
  2121. ret = platform->driver->pcm_new(rtd);
  2122. if (ret < 0) {
  2123. pr_err("asoc: platform pcm constructor failed\n");
  2124. return ret;
  2125. }
  2126. }
  2127. pcm->private_free = platform->driver->pcm_free;
  2128. out:
  2129. printk(KERN_INFO "asoc: %s <-> %s mapping ok\n", codec_dai->name,
  2130. cpu_dai->name);
  2131. return ret;
  2132. }
  2133. #ifdef CONFIG_DEBUG_FS
  2134. static char *dpcm_state_string(enum snd_soc_dpcm_state state)
  2135. {
  2136. switch (state) {
  2137. case SND_SOC_DPCM_STATE_NEW:
  2138. return "new";
  2139. case SND_SOC_DPCM_STATE_OPEN:
  2140. return "open";
  2141. case SND_SOC_DPCM_STATE_HW_PARAMS:
  2142. return "hw_params";
  2143. case SND_SOC_DPCM_STATE_PREPARE:
  2144. return "prepare";
  2145. case SND_SOC_DPCM_STATE_START:
  2146. return "start";
  2147. case SND_SOC_DPCM_STATE_STOP:
  2148. return "stop";
  2149. case SND_SOC_DPCM_STATE_SUSPEND:
  2150. return "suspend";
  2151. case SND_SOC_DPCM_STATE_PAUSED:
  2152. return "paused";
  2153. case SND_SOC_DPCM_STATE_HW_FREE:
  2154. return "hw_free";
  2155. case SND_SOC_DPCM_STATE_CLOSE:
  2156. return "close";
  2157. }
  2158. return "unknown";
  2159. }
  2160. static int soc_dpcm_state_open_file(struct inode *inode, struct file *file)
  2161. {
  2162. file->private_data = inode->i_private;
  2163. return 0;
  2164. }
  2165. static ssize_t soc_dpcm_show_state(struct snd_soc_pcm_runtime *fe,
  2166. int stream, char *buf, size_t size)
  2167. {
  2168. struct snd_pcm_hw_params *params = &fe->dpcm[stream].hw_params;
  2169. struct snd_soc_dpcm_params *dpcm_params;
  2170. ssize_t offset = 0;
  2171. /* FE state */
  2172. offset += snprintf(buf + offset, size - offset,
  2173. "[%s - %s]\n", fe->dai_link->name,
  2174. stream ? "Capture" : "Playback");
  2175. offset += snprintf(buf + offset, size - offset, "State: %s\n",
  2176. dpcm_state_string(fe->dpcm[stream].state));
  2177. if ((fe->dpcm[stream].state >= SND_SOC_DPCM_STATE_HW_PARAMS) &&
  2178. (fe->dpcm[stream].state <= SND_SOC_DPCM_STATE_STOP))
  2179. offset += snprintf(buf + offset, size - offset,
  2180. "Hardware Params: "
  2181. "Format = %s, Channels = %d, Rate = %d\n",
  2182. snd_pcm_format_name(params_format(params)),
  2183. params_channels(params),
  2184. params_rate(params));
  2185. /* BEs state */
  2186. offset += snprintf(buf + offset, size - offset, "Backends:\n");
  2187. if (list_empty(&fe->dpcm[stream].be_clients)) {
  2188. offset += snprintf(buf + offset, size - offset,
  2189. " No active DSP links\n");
  2190. goto out;
  2191. }
  2192. list_for_each_entry(dpcm_params, &fe->dpcm[stream].be_clients, list_be) {
  2193. struct snd_soc_pcm_runtime *be = dpcm_params->be;
  2194. offset += snprintf(buf + offset, size - offset,
  2195. "- %s\n", be->dai_link->name);
  2196. offset += snprintf(buf + offset, size - offset,
  2197. " State: %s\n",
  2198. dpcm_state_string(fe->dpcm[stream].state));
  2199. if ((be->dpcm[stream].state >= SND_SOC_DPCM_STATE_HW_PARAMS) &&
  2200. (be->dpcm[stream].state <= SND_SOC_DPCM_STATE_STOP))
  2201. offset += snprintf(buf + offset, size - offset,
  2202. " Hardware Params: "
  2203. "Format = %s, Channels = %d, Rate = %d\n",
  2204. snd_pcm_format_name(params_format(params)),
  2205. params_channels(params),
  2206. params_rate(params));
  2207. }
  2208. out:
  2209. return offset;
  2210. }
  2211. static ssize_t soc_dpcm_state_read_file(struct file *file, char __user *user_buf,
  2212. size_t count, loff_t *ppos)
  2213. {
  2214. struct snd_soc_pcm_runtime *fe = file->private_data;
  2215. ssize_t out_count = PAGE_SIZE, offset = 0, ret = 0;
  2216. char *buf;
  2217. buf = kmalloc(out_count, GFP_KERNEL);
  2218. if (!buf)
  2219. return -ENOMEM;
  2220. if (fe->cpu_dai->driver->playback.channels_min)
  2221. offset += soc_dpcm_show_state(fe, SNDRV_PCM_STREAM_PLAYBACK,
  2222. buf + offset, out_count - offset);
  2223. if (fe->cpu_dai->driver->capture.channels_min)
  2224. offset += soc_dpcm_show_state(fe, SNDRV_PCM_STREAM_CAPTURE,
  2225. buf + offset, out_count - offset);
  2226. ret = simple_read_from_buffer(user_buf, count, ppos, buf, offset);
  2227. kfree(buf);
  2228. return ret;
  2229. }
  2230. static const struct file_operations soc_dpcm_state_fops = {
  2231. .open = soc_dpcm_state_open_file,
  2232. .read = soc_dpcm_state_read_file,
  2233. .llseek = default_llseek,
  2234. };
  2235. int soc_dpcm_debugfs_add(struct snd_soc_pcm_runtime *rtd)
  2236. {
  2237. rtd->debugfs_dpcm_root = debugfs_create_dir(rtd->dai_link->name,
  2238. rtd->card->debugfs_card_root);
  2239. if (!rtd->debugfs_dpcm_root) {
  2240. dev_dbg(rtd->dev,
  2241. "ASoC: Failed to create dpcm debugfs directory %s\n",
  2242. rtd->dai_link->name);
  2243. return -EINVAL;
  2244. }
  2245. rtd->debugfs_dpcm_state = debugfs_create_file("state", 0644,
  2246. rtd->debugfs_dpcm_root,
  2247. rtd, &soc_dpcm_state_fops);
  2248. return 0;
  2249. }
  2250. #endif