soc-core.c 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423
  1. /*
  2. * soc-core.c -- ALSA SoC Audio Layer
  3. *
  4. * Copyright 2005 Wolfson Microelectronics PLC.
  5. * Copyright 2005 Openedhand Ltd.
  6. *
  7. * Author: Liam Girdwood <lrg@slimlogic.co.uk>
  8. * with code, comments and ideas from :-
  9. * Richard Purdie <richard@openedhand.com>
  10. *
  11. * This program is free software; you can redistribute it and/or modify it
  12. * under the terms of the GNU General Public License as published by the
  13. * Free Software Foundation; either version 2 of the License, or (at your
  14. * option) any later version.
  15. *
  16. * TODO:
  17. * o Add hw rules to enforce rates, etc.
  18. * o More testing with other codecs/machines.
  19. * o Add more codecs and platforms to ensure good API coverage.
  20. * o Support TDM on PCM and I2S
  21. */
  22. #include <linux/module.h>
  23. #include <linux/moduleparam.h>
  24. #include <linux/init.h>
  25. #include <linux/delay.h>
  26. #include <linux/pm.h>
  27. #include <linux/bitops.h>
  28. #include <linux/debugfs.h>
  29. #include <linux/platform_device.h>
  30. #include <sound/core.h>
  31. #include <sound/pcm.h>
  32. #include <sound/pcm_params.h>
  33. #include <sound/soc.h>
  34. #include <sound/soc-dapm.h>
  35. #include <sound/initval.h>
  36. static DEFINE_MUTEX(pcm_mutex);
  37. static DEFINE_MUTEX(io_mutex);
  38. static DECLARE_WAIT_QUEUE_HEAD(soc_pm_waitq);
  39. #ifdef CONFIG_DEBUG_FS
  40. static struct dentry *debugfs_root;
  41. #endif
  42. static DEFINE_MUTEX(client_mutex);
  43. static LIST_HEAD(card_list);
  44. static LIST_HEAD(dai_list);
  45. static LIST_HEAD(platform_list);
  46. static LIST_HEAD(codec_list);
  47. static int snd_soc_register_card(struct snd_soc_card *card);
  48. static int snd_soc_unregister_card(struct snd_soc_card *card);
  49. /*
  50. * This is a timeout to do a DAPM powerdown after a stream is closed().
  51. * It can be used to eliminate pops between different playback streams, e.g.
  52. * between two audio tracks.
  53. */
  54. static int pmdown_time = 5000;
  55. module_param(pmdown_time, int, 0);
  56. MODULE_PARM_DESC(pmdown_time, "DAPM stream powerdown time (msecs)");
  57. /*
  58. * This function forces any delayed work to be queued and run.
  59. */
  60. static int run_delayed_work(struct delayed_work *dwork)
  61. {
  62. int ret;
  63. /* cancel any work waiting to be queued. */
  64. ret = cancel_delayed_work(dwork);
  65. /* if there was any work waiting then we run it now and
  66. * wait for it's completion */
  67. if (ret) {
  68. schedule_delayed_work(dwork, 0);
  69. flush_scheduled_work();
  70. }
  71. return ret;
  72. }
  73. #ifdef CONFIG_SND_SOC_AC97_BUS
  74. /* unregister ac97 codec */
  75. static int soc_ac97_dev_unregister(struct snd_soc_codec *codec)
  76. {
  77. if (codec->ac97->dev.bus)
  78. device_unregister(&codec->ac97->dev);
  79. return 0;
  80. }
  81. /* stop no dev release warning */
  82. static void soc_ac97_device_release(struct device *dev){}
  83. /* register ac97 codec to bus */
  84. static int soc_ac97_dev_register(struct snd_soc_codec *codec)
  85. {
  86. int err;
  87. codec->ac97->dev.bus = &ac97_bus_type;
  88. codec->ac97->dev.parent = codec->card->dev;
  89. codec->ac97->dev.release = soc_ac97_device_release;
  90. dev_set_name(&codec->ac97->dev, "%d-%d:%s",
  91. codec->card->number, 0, codec->name);
  92. err = device_register(&codec->ac97->dev);
  93. if (err < 0) {
  94. snd_printk(KERN_ERR "Can't register ac97 bus\n");
  95. codec->ac97->dev.bus = NULL;
  96. return err;
  97. }
  98. return 0;
  99. }
  100. #endif
  101. /*
  102. * Called by ALSA when a PCM substream is opened, the runtime->hw record is
  103. * then initialized and any private data can be allocated. This also calls
  104. * startup for the cpu DAI, platform, machine and codec DAI.
  105. */
  106. static int soc_pcm_open(struct snd_pcm_substream *substream)
  107. {
  108. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  109. struct snd_soc_device *socdev = rtd->socdev;
  110. struct snd_soc_card *card = socdev->card;
  111. struct snd_pcm_runtime *runtime = substream->runtime;
  112. struct snd_soc_dai_link *machine = rtd->dai;
  113. struct snd_soc_platform *platform = card->platform;
  114. struct snd_soc_dai *cpu_dai = machine->cpu_dai;
  115. struct snd_soc_dai *codec_dai = machine->codec_dai;
  116. int ret = 0;
  117. mutex_lock(&pcm_mutex);
  118. /* startup the audio subsystem */
  119. if (cpu_dai->ops->startup) {
  120. ret = cpu_dai->ops->startup(substream, cpu_dai);
  121. if (ret < 0) {
  122. printk(KERN_ERR "asoc: can't open interface %s\n",
  123. cpu_dai->name);
  124. goto out;
  125. }
  126. }
  127. if (platform->pcm_ops->open) {
  128. ret = platform->pcm_ops->open(substream);
  129. if (ret < 0) {
  130. printk(KERN_ERR "asoc: can't open platform %s\n", platform->name);
  131. goto platform_err;
  132. }
  133. }
  134. if (codec_dai->ops->startup) {
  135. ret = codec_dai->ops->startup(substream, codec_dai);
  136. if (ret < 0) {
  137. printk(KERN_ERR "asoc: can't open codec %s\n",
  138. codec_dai->name);
  139. goto codec_dai_err;
  140. }
  141. }
  142. if (machine->ops && machine->ops->startup) {
  143. ret = machine->ops->startup(substream);
  144. if (ret < 0) {
  145. printk(KERN_ERR "asoc: %s startup failed\n", machine->name);
  146. goto machine_err;
  147. }
  148. }
  149. /* Check that the codec and cpu DAI's are compatible */
  150. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  151. runtime->hw.rate_min =
  152. max(codec_dai->playback.rate_min,
  153. cpu_dai->playback.rate_min);
  154. runtime->hw.rate_max =
  155. min(codec_dai->playback.rate_max,
  156. cpu_dai->playback.rate_max);
  157. runtime->hw.channels_min =
  158. max(codec_dai->playback.channels_min,
  159. cpu_dai->playback.channels_min);
  160. runtime->hw.channels_max =
  161. min(codec_dai->playback.channels_max,
  162. cpu_dai->playback.channels_max);
  163. runtime->hw.formats =
  164. codec_dai->playback.formats & cpu_dai->playback.formats;
  165. runtime->hw.rates =
  166. codec_dai->playback.rates & cpu_dai->playback.rates;
  167. } else {
  168. runtime->hw.rate_min =
  169. max(codec_dai->capture.rate_min,
  170. cpu_dai->capture.rate_min);
  171. runtime->hw.rate_max =
  172. min(codec_dai->capture.rate_max,
  173. cpu_dai->capture.rate_max);
  174. runtime->hw.channels_min =
  175. max(codec_dai->capture.channels_min,
  176. cpu_dai->capture.channels_min);
  177. runtime->hw.channels_max =
  178. min(codec_dai->capture.channels_max,
  179. cpu_dai->capture.channels_max);
  180. runtime->hw.formats =
  181. codec_dai->capture.formats & cpu_dai->capture.formats;
  182. runtime->hw.rates =
  183. codec_dai->capture.rates & cpu_dai->capture.rates;
  184. }
  185. snd_pcm_limit_hw_rates(runtime);
  186. if (!runtime->hw.rates) {
  187. printk(KERN_ERR "asoc: %s <-> %s No matching rates\n",
  188. codec_dai->name, cpu_dai->name);
  189. goto machine_err;
  190. }
  191. if (!runtime->hw.formats) {
  192. printk(KERN_ERR "asoc: %s <-> %s No matching formats\n",
  193. codec_dai->name, cpu_dai->name);
  194. goto machine_err;
  195. }
  196. if (!runtime->hw.channels_min || !runtime->hw.channels_max) {
  197. printk(KERN_ERR "asoc: %s <-> %s No matching channels\n",
  198. codec_dai->name, cpu_dai->name);
  199. goto machine_err;
  200. }
  201. pr_debug("asoc: %s <-> %s info:\n", codec_dai->name, cpu_dai->name);
  202. pr_debug("asoc: rate mask 0x%x\n", runtime->hw.rates);
  203. pr_debug("asoc: min ch %d max ch %d\n", runtime->hw.channels_min,
  204. runtime->hw.channels_max);
  205. pr_debug("asoc: min rate %d max rate %d\n", runtime->hw.rate_min,
  206. runtime->hw.rate_max);
  207. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  208. cpu_dai->playback.active = codec_dai->playback.active = 1;
  209. else
  210. cpu_dai->capture.active = codec_dai->capture.active = 1;
  211. cpu_dai->active = codec_dai->active = 1;
  212. cpu_dai->runtime = runtime;
  213. card->codec->active++;
  214. mutex_unlock(&pcm_mutex);
  215. return 0;
  216. machine_err:
  217. if (machine->ops && machine->ops->shutdown)
  218. machine->ops->shutdown(substream);
  219. codec_dai_err:
  220. if (platform->pcm_ops->close)
  221. platform->pcm_ops->close(substream);
  222. platform_err:
  223. if (cpu_dai->ops->shutdown)
  224. cpu_dai->ops->shutdown(substream, cpu_dai);
  225. out:
  226. mutex_unlock(&pcm_mutex);
  227. return ret;
  228. }
  229. /*
  230. * Power down the audio subsystem pmdown_time msecs after close is called.
  231. * This is to ensure there are no pops or clicks in between any music tracks
  232. * due to DAPM power cycling.
  233. */
  234. static void close_delayed_work(struct work_struct *work)
  235. {
  236. struct snd_soc_card *card = container_of(work, struct snd_soc_card,
  237. delayed_work.work);
  238. struct snd_soc_device *socdev = card->socdev;
  239. struct snd_soc_codec *codec = card->codec;
  240. struct snd_soc_dai *codec_dai;
  241. int i;
  242. mutex_lock(&pcm_mutex);
  243. for (i = 0; i < codec->num_dai; i++) {
  244. codec_dai = &codec->dai[i];
  245. pr_debug("pop wq checking: %s status: %s waiting: %s\n",
  246. codec_dai->playback.stream_name,
  247. codec_dai->playback.active ? "active" : "inactive",
  248. codec_dai->pop_wait ? "yes" : "no");
  249. /* are we waiting on this codec DAI stream */
  250. if (codec_dai->pop_wait == 1) {
  251. /* Reduce power if no longer active */
  252. if (codec->active == 0) {
  253. pr_debug("pop wq D1 %s %s\n", codec->name,
  254. codec_dai->playback.stream_name);
  255. snd_soc_dapm_set_bias_level(socdev,
  256. SND_SOC_BIAS_PREPARE);
  257. }
  258. codec_dai->pop_wait = 0;
  259. snd_soc_dapm_stream_event(codec,
  260. codec_dai->playback.stream_name,
  261. SND_SOC_DAPM_STREAM_STOP);
  262. /* Fall into standby if no longer active */
  263. if (codec->active == 0) {
  264. pr_debug("pop wq D3 %s %s\n", codec->name,
  265. codec_dai->playback.stream_name);
  266. snd_soc_dapm_set_bias_level(socdev,
  267. SND_SOC_BIAS_STANDBY);
  268. }
  269. }
  270. }
  271. mutex_unlock(&pcm_mutex);
  272. }
  273. /*
  274. * Called by ALSA when a PCM substream is closed. Private data can be
  275. * freed here. The cpu DAI, codec DAI, machine and platform are also
  276. * shutdown.
  277. */
  278. static int soc_codec_close(struct snd_pcm_substream *substream)
  279. {
  280. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  281. struct snd_soc_device *socdev = rtd->socdev;
  282. struct snd_soc_card *card = socdev->card;
  283. struct snd_soc_dai_link *machine = rtd->dai;
  284. struct snd_soc_platform *platform = card->platform;
  285. struct snd_soc_dai *cpu_dai = machine->cpu_dai;
  286. struct snd_soc_dai *codec_dai = machine->codec_dai;
  287. struct snd_soc_codec *codec = card->codec;
  288. mutex_lock(&pcm_mutex);
  289. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  290. cpu_dai->playback.active = codec_dai->playback.active = 0;
  291. else
  292. cpu_dai->capture.active = codec_dai->capture.active = 0;
  293. if (codec_dai->playback.active == 0 &&
  294. codec_dai->capture.active == 0) {
  295. cpu_dai->active = codec_dai->active = 0;
  296. }
  297. codec->active--;
  298. /* Muting the DAC suppresses artifacts caused during digital
  299. * shutdown, for example from stopping clocks.
  300. */
  301. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  302. snd_soc_dai_digital_mute(codec_dai, 1);
  303. if (cpu_dai->ops->shutdown)
  304. cpu_dai->ops->shutdown(substream, cpu_dai);
  305. if (codec_dai->ops->shutdown)
  306. codec_dai->ops->shutdown(substream, codec_dai);
  307. if (machine->ops && machine->ops->shutdown)
  308. machine->ops->shutdown(substream);
  309. if (platform->pcm_ops->close)
  310. platform->pcm_ops->close(substream);
  311. cpu_dai->runtime = NULL;
  312. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  313. /* start delayed pop wq here for playback streams */
  314. codec_dai->pop_wait = 1;
  315. schedule_delayed_work(&card->delayed_work,
  316. msecs_to_jiffies(pmdown_time));
  317. } else {
  318. /* capture streams can be powered down now */
  319. snd_soc_dapm_stream_event(codec,
  320. codec_dai->capture.stream_name,
  321. SND_SOC_DAPM_STREAM_STOP);
  322. if (codec->active == 0 && codec_dai->pop_wait == 0)
  323. snd_soc_dapm_set_bias_level(socdev,
  324. SND_SOC_BIAS_STANDBY);
  325. }
  326. mutex_unlock(&pcm_mutex);
  327. return 0;
  328. }
  329. /*
  330. * Called by ALSA when the PCM substream is prepared, can set format, sample
  331. * rate, etc. This function is non atomic and can be called multiple times,
  332. * it can refer to the runtime info.
  333. */
  334. static int soc_pcm_prepare(struct snd_pcm_substream *substream)
  335. {
  336. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  337. struct snd_soc_device *socdev = rtd->socdev;
  338. struct snd_soc_card *card = socdev->card;
  339. struct snd_soc_dai_link *machine = rtd->dai;
  340. struct snd_soc_platform *platform = card->platform;
  341. struct snd_soc_dai *cpu_dai = machine->cpu_dai;
  342. struct snd_soc_dai *codec_dai = machine->codec_dai;
  343. struct snd_soc_codec *codec = card->codec;
  344. int ret = 0;
  345. mutex_lock(&pcm_mutex);
  346. if (machine->ops && machine->ops->prepare) {
  347. ret = machine->ops->prepare(substream);
  348. if (ret < 0) {
  349. printk(KERN_ERR "asoc: machine prepare error\n");
  350. goto out;
  351. }
  352. }
  353. if (platform->pcm_ops->prepare) {
  354. ret = platform->pcm_ops->prepare(substream);
  355. if (ret < 0) {
  356. printk(KERN_ERR "asoc: platform prepare error\n");
  357. goto out;
  358. }
  359. }
  360. if (codec_dai->ops->prepare) {
  361. ret = codec_dai->ops->prepare(substream, codec_dai);
  362. if (ret < 0) {
  363. printk(KERN_ERR "asoc: codec DAI prepare error\n");
  364. goto out;
  365. }
  366. }
  367. if (cpu_dai->ops->prepare) {
  368. ret = cpu_dai->ops->prepare(substream, cpu_dai);
  369. if (ret < 0) {
  370. printk(KERN_ERR "asoc: cpu DAI prepare error\n");
  371. goto out;
  372. }
  373. }
  374. /* cancel any delayed stream shutdown that is pending */
  375. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK &&
  376. codec_dai->pop_wait) {
  377. codec_dai->pop_wait = 0;
  378. cancel_delayed_work(&card->delayed_work);
  379. }
  380. /* do we need to power up codec */
  381. if (codec->bias_level != SND_SOC_BIAS_ON) {
  382. snd_soc_dapm_set_bias_level(socdev,
  383. SND_SOC_BIAS_PREPARE);
  384. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  385. snd_soc_dapm_stream_event(codec,
  386. codec_dai->playback.stream_name,
  387. SND_SOC_DAPM_STREAM_START);
  388. else
  389. snd_soc_dapm_stream_event(codec,
  390. codec_dai->capture.stream_name,
  391. SND_SOC_DAPM_STREAM_START);
  392. snd_soc_dapm_set_bias_level(socdev, SND_SOC_BIAS_ON);
  393. snd_soc_dai_digital_mute(codec_dai, 0);
  394. } else {
  395. /* codec already powered - power on widgets */
  396. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  397. snd_soc_dapm_stream_event(codec,
  398. codec_dai->playback.stream_name,
  399. SND_SOC_DAPM_STREAM_START);
  400. else
  401. snd_soc_dapm_stream_event(codec,
  402. codec_dai->capture.stream_name,
  403. SND_SOC_DAPM_STREAM_START);
  404. snd_soc_dai_digital_mute(codec_dai, 0);
  405. }
  406. out:
  407. mutex_unlock(&pcm_mutex);
  408. return ret;
  409. }
  410. /*
  411. * Called by ALSA when the hardware params are set by application. This
  412. * function can also be called multiple times and can allocate buffers
  413. * (using snd_pcm_lib_* ). It's non-atomic.
  414. */
  415. static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
  416. struct snd_pcm_hw_params *params)
  417. {
  418. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  419. struct snd_soc_device *socdev = rtd->socdev;
  420. struct snd_soc_dai_link *machine = rtd->dai;
  421. struct snd_soc_card *card = socdev->card;
  422. struct snd_soc_platform *platform = card->platform;
  423. struct snd_soc_dai *cpu_dai = machine->cpu_dai;
  424. struct snd_soc_dai *codec_dai = machine->codec_dai;
  425. int ret = 0;
  426. mutex_lock(&pcm_mutex);
  427. if (machine->ops && machine->ops->hw_params) {
  428. ret = machine->ops->hw_params(substream, params);
  429. if (ret < 0) {
  430. printk(KERN_ERR "asoc: machine hw_params failed\n");
  431. goto out;
  432. }
  433. }
  434. if (codec_dai->ops->hw_params) {
  435. ret = codec_dai->ops->hw_params(substream, params, codec_dai);
  436. if (ret < 0) {
  437. printk(KERN_ERR "asoc: can't set codec %s hw params\n",
  438. codec_dai->name);
  439. goto codec_err;
  440. }
  441. }
  442. if (cpu_dai->ops->hw_params) {
  443. ret = cpu_dai->ops->hw_params(substream, params, cpu_dai);
  444. if (ret < 0) {
  445. printk(KERN_ERR "asoc: interface %s hw params failed\n",
  446. cpu_dai->name);
  447. goto interface_err;
  448. }
  449. }
  450. if (platform->pcm_ops->hw_params) {
  451. ret = platform->pcm_ops->hw_params(substream, params);
  452. if (ret < 0) {
  453. printk(KERN_ERR "asoc: platform %s hw params failed\n",
  454. platform->name);
  455. goto platform_err;
  456. }
  457. }
  458. out:
  459. mutex_unlock(&pcm_mutex);
  460. return ret;
  461. platform_err:
  462. if (cpu_dai->ops->hw_free)
  463. cpu_dai->ops->hw_free(substream, cpu_dai);
  464. interface_err:
  465. if (codec_dai->ops->hw_free)
  466. codec_dai->ops->hw_free(substream, codec_dai);
  467. codec_err:
  468. if (machine->ops && machine->ops->hw_free)
  469. machine->ops->hw_free(substream);
  470. mutex_unlock(&pcm_mutex);
  471. return ret;
  472. }
  473. /*
  474. * Free's resources allocated by hw_params, can be called multiple times
  475. */
  476. static int soc_pcm_hw_free(struct snd_pcm_substream *substream)
  477. {
  478. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  479. struct snd_soc_device *socdev = rtd->socdev;
  480. struct snd_soc_dai_link *machine = rtd->dai;
  481. struct snd_soc_card *card = socdev->card;
  482. struct snd_soc_platform *platform = card->platform;
  483. struct snd_soc_dai *cpu_dai = machine->cpu_dai;
  484. struct snd_soc_dai *codec_dai = machine->codec_dai;
  485. struct snd_soc_codec *codec = card->codec;
  486. mutex_lock(&pcm_mutex);
  487. /* apply codec digital mute */
  488. if (!codec->active)
  489. snd_soc_dai_digital_mute(codec_dai, 1);
  490. /* free any machine hw params */
  491. if (machine->ops && machine->ops->hw_free)
  492. machine->ops->hw_free(substream);
  493. /* free any DMA resources */
  494. if (platform->pcm_ops->hw_free)
  495. platform->pcm_ops->hw_free(substream);
  496. /* now free hw params for the DAI's */
  497. if (codec_dai->ops->hw_free)
  498. codec_dai->ops->hw_free(substream, codec_dai);
  499. if (cpu_dai->ops->hw_free)
  500. cpu_dai->ops->hw_free(substream, cpu_dai);
  501. mutex_unlock(&pcm_mutex);
  502. return 0;
  503. }
  504. static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
  505. {
  506. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  507. struct snd_soc_device *socdev = rtd->socdev;
  508. struct snd_soc_card *card= socdev->card;
  509. struct snd_soc_dai_link *machine = rtd->dai;
  510. struct snd_soc_platform *platform = card->platform;
  511. struct snd_soc_dai *cpu_dai = machine->cpu_dai;
  512. struct snd_soc_dai *codec_dai = machine->codec_dai;
  513. int ret;
  514. if (codec_dai->ops->trigger) {
  515. ret = codec_dai->ops->trigger(substream, cmd, codec_dai);
  516. if (ret < 0)
  517. return ret;
  518. }
  519. if (platform->pcm_ops->trigger) {
  520. ret = platform->pcm_ops->trigger(substream, cmd);
  521. if (ret < 0)
  522. return ret;
  523. }
  524. if (cpu_dai->ops->trigger) {
  525. ret = cpu_dai->ops->trigger(substream, cmd, cpu_dai);
  526. if (ret < 0)
  527. return ret;
  528. }
  529. return 0;
  530. }
  531. /* ASoC PCM operations */
  532. static struct snd_pcm_ops soc_pcm_ops = {
  533. .open = soc_pcm_open,
  534. .close = soc_codec_close,
  535. .hw_params = soc_pcm_hw_params,
  536. .hw_free = soc_pcm_hw_free,
  537. .prepare = soc_pcm_prepare,
  538. .trigger = soc_pcm_trigger,
  539. };
  540. #ifdef CONFIG_PM
  541. /* powers down audio subsystem for suspend */
  542. static int soc_suspend(struct platform_device *pdev, pm_message_t state)
  543. {
  544. struct snd_soc_device *socdev = platform_get_drvdata(pdev);
  545. struct snd_soc_card *card = socdev->card;
  546. struct snd_soc_platform *platform = card->platform;
  547. struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
  548. struct snd_soc_codec *codec = card->codec;
  549. int i;
  550. /* Due to the resume being scheduled into a workqueue we could
  551. * suspend before that's finished - wait for it to complete.
  552. */
  553. snd_power_lock(codec->card);
  554. snd_power_wait(codec->card, SNDRV_CTL_POWER_D0);
  555. snd_power_unlock(codec->card);
  556. /* we're going to block userspace touching us until resume completes */
  557. snd_power_change_state(codec->card, SNDRV_CTL_POWER_D3hot);
  558. /* mute any active DAC's */
  559. for (i = 0; i < card->num_links; i++) {
  560. struct snd_soc_dai *dai = card->dai_link[i].codec_dai;
  561. if (dai->ops->digital_mute && dai->playback.active)
  562. dai->ops->digital_mute(dai, 1);
  563. }
  564. /* suspend all pcms */
  565. for (i = 0; i < card->num_links; i++)
  566. snd_pcm_suspend_all(card->dai_link[i].pcm);
  567. if (card->suspend_pre)
  568. card->suspend_pre(pdev, state);
  569. for (i = 0; i < card->num_links; i++) {
  570. struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai;
  571. if (cpu_dai->suspend && !cpu_dai->ac97_control)
  572. cpu_dai->suspend(cpu_dai);
  573. if (platform->suspend)
  574. platform->suspend(cpu_dai);
  575. }
  576. /* close any waiting streams and save state */
  577. run_delayed_work(&card->delayed_work);
  578. codec->suspend_bias_level = codec->bias_level;
  579. for (i = 0; i < codec->num_dai; i++) {
  580. char *stream = codec->dai[i].playback.stream_name;
  581. if (stream != NULL)
  582. snd_soc_dapm_stream_event(codec, stream,
  583. SND_SOC_DAPM_STREAM_SUSPEND);
  584. stream = codec->dai[i].capture.stream_name;
  585. if (stream != NULL)
  586. snd_soc_dapm_stream_event(codec, stream,
  587. SND_SOC_DAPM_STREAM_SUSPEND);
  588. }
  589. if (codec_dev->suspend)
  590. codec_dev->suspend(pdev, state);
  591. for (i = 0; i < card->num_links; i++) {
  592. struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai;
  593. if (cpu_dai->suspend && cpu_dai->ac97_control)
  594. cpu_dai->suspend(cpu_dai);
  595. }
  596. if (card->suspend_post)
  597. card->suspend_post(pdev, state);
  598. return 0;
  599. }
  600. /* deferred resume work, so resume can complete before we finished
  601. * setting our codec back up, which can be very slow on I2C
  602. */
  603. static void soc_resume_deferred(struct work_struct *work)
  604. {
  605. struct snd_soc_card *card = container_of(work,
  606. struct snd_soc_card,
  607. deferred_resume_work);
  608. struct snd_soc_device *socdev = card->socdev;
  609. struct snd_soc_platform *platform = card->platform;
  610. struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
  611. struct snd_soc_codec *codec = card->codec;
  612. struct platform_device *pdev = to_platform_device(socdev->dev);
  613. int i;
  614. /* our power state is still SNDRV_CTL_POWER_D3hot from suspend time,
  615. * so userspace apps are blocked from touching us
  616. */
  617. dev_dbg(socdev->dev, "starting resume work\n");
  618. if (card->resume_pre)
  619. card->resume_pre(pdev);
  620. for (i = 0; i < card->num_links; i++) {
  621. struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai;
  622. if (cpu_dai->resume && cpu_dai->ac97_control)
  623. cpu_dai->resume(cpu_dai);
  624. }
  625. if (codec_dev->resume)
  626. codec_dev->resume(pdev);
  627. for (i = 0; i < codec->num_dai; i++) {
  628. char *stream = codec->dai[i].playback.stream_name;
  629. if (stream != NULL)
  630. snd_soc_dapm_stream_event(codec, stream,
  631. SND_SOC_DAPM_STREAM_RESUME);
  632. stream = codec->dai[i].capture.stream_name;
  633. if (stream != NULL)
  634. snd_soc_dapm_stream_event(codec, stream,
  635. SND_SOC_DAPM_STREAM_RESUME);
  636. }
  637. /* unmute any active DACs */
  638. for (i = 0; i < card->num_links; i++) {
  639. struct snd_soc_dai *dai = card->dai_link[i].codec_dai;
  640. if (dai->ops->digital_mute && dai->playback.active)
  641. dai->ops->digital_mute(dai, 0);
  642. }
  643. for (i = 0; i < card->num_links; i++) {
  644. struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai;
  645. if (cpu_dai->resume && !cpu_dai->ac97_control)
  646. cpu_dai->resume(cpu_dai);
  647. if (platform->resume)
  648. platform->resume(cpu_dai);
  649. }
  650. if (card->resume_post)
  651. card->resume_post(pdev);
  652. dev_dbg(socdev->dev, "resume work completed\n");
  653. /* userspace can access us now we are back as we were before */
  654. snd_power_change_state(codec->card, SNDRV_CTL_POWER_D0);
  655. }
  656. /* powers up audio subsystem after a suspend */
  657. static int soc_resume(struct platform_device *pdev)
  658. {
  659. struct snd_soc_device *socdev = platform_get_drvdata(pdev);
  660. struct snd_soc_card *card = socdev->card;
  661. struct snd_soc_dai *cpu_dai = card->dai_link[0].cpu_dai;
  662. /* AC97 devices might have other drivers hanging off them so
  663. * need to resume immediately. Other drivers don't have that
  664. * problem and may take a substantial amount of time to resume
  665. * due to I/O costs and anti-pop so handle them out of line.
  666. */
  667. if (cpu_dai->ac97_control) {
  668. dev_dbg(socdev->dev, "Resuming AC97 immediately\n");
  669. soc_resume_deferred(&card->deferred_resume_work);
  670. } else {
  671. dev_dbg(socdev->dev, "Scheduling resume work\n");
  672. if (!schedule_work(&card->deferred_resume_work))
  673. dev_err(socdev->dev, "resume work item may be lost\n");
  674. }
  675. return 0;
  676. }
  677. #else
  678. #define soc_suspend NULL
  679. #define soc_resume NULL
  680. #endif
  681. static void snd_soc_instantiate_card(struct snd_soc_card *card)
  682. {
  683. struct platform_device *pdev = container_of(card->dev,
  684. struct platform_device,
  685. dev);
  686. struct snd_soc_codec_device *codec_dev = card->socdev->codec_dev;
  687. struct snd_soc_platform *platform;
  688. struct snd_soc_dai *dai;
  689. int i, found, ret, ac97;
  690. if (card->instantiated)
  691. return;
  692. found = 0;
  693. list_for_each_entry(platform, &platform_list, list)
  694. if (card->platform == platform) {
  695. found = 1;
  696. break;
  697. }
  698. if (!found) {
  699. dev_dbg(card->dev, "Platform %s not registered\n",
  700. card->platform->name);
  701. return;
  702. }
  703. ac97 = 0;
  704. for (i = 0; i < card->num_links; i++) {
  705. found = 0;
  706. list_for_each_entry(dai, &dai_list, list)
  707. if (card->dai_link[i].cpu_dai == dai) {
  708. found = 1;
  709. break;
  710. }
  711. if (!found) {
  712. dev_dbg(card->dev, "DAI %s not registered\n",
  713. card->dai_link[i].cpu_dai->name);
  714. return;
  715. }
  716. if (card->dai_link[i].cpu_dai->ac97_control)
  717. ac97 = 1;
  718. }
  719. /* If we have AC97 in the system then don't wait for the
  720. * codec. This will need revisiting if we have to handle
  721. * systems with mixed AC97 and non-AC97 parts. Only check for
  722. * DAIs currently; we can't do this per link since some AC97
  723. * codecs have non-AC97 DAIs.
  724. */
  725. if (!ac97)
  726. for (i = 0; i < card->num_links; i++) {
  727. found = 0;
  728. list_for_each_entry(dai, &dai_list, list)
  729. if (card->dai_link[i].codec_dai == dai) {
  730. found = 1;
  731. break;
  732. }
  733. if (!found) {
  734. dev_dbg(card->dev, "DAI %s not registered\n",
  735. card->dai_link[i].codec_dai->name);
  736. return;
  737. }
  738. }
  739. /* Note that we do not current check for codec components */
  740. dev_dbg(card->dev, "All components present, instantiating\n");
  741. /* Found everything, bring it up */
  742. if (card->probe) {
  743. ret = card->probe(pdev);
  744. if (ret < 0)
  745. return;
  746. }
  747. for (i = 0; i < card->num_links; i++) {
  748. struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai;
  749. if (cpu_dai->probe) {
  750. ret = cpu_dai->probe(pdev, cpu_dai);
  751. if (ret < 0)
  752. goto cpu_dai_err;
  753. }
  754. }
  755. if (codec_dev->probe) {
  756. ret = codec_dev->probe(pdev);
  757. if (ret < 0)
  758. goto cpu_dai_err;
  759. }
  760. if (platform->probe) {
  761. ret = platform->probe(pdev);
  762. if (ret < 0)
  763. goto platform_err;
  764. }
  765. /* DAPM stream work */
  766. INIT_DELAYED_WORK(&card->delayed_work, close_delayed_work);
  767. #ifdef CONFIG_PM
  768. /* deferred resume work */
  769. INIT_WORK(&card->deferred_resume_work, soc_resume_deferred);
  770. #endif
  771. card->instantiated = 1;
  772. return;
  773. platform_err:
  774. if (codec_dev->remove)
  775. codec_dev->remove(pdev);
  776. cpu_dai_err:
  777. for (i--; i >= 0; i--) {
  778. struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai;
  779. if (cpu_dai->remove)
  780. cpu_dai->remove(pdev, cpu_dai);
  781. }
  782. if (card->remove)
  783. card->remove(pdev);
  784. }
  785. /*
  786. * Attempt to initialise any uninitalised cards. Must be called with
  787. * client_mutex.
  788. */
  789. static void snd_soc_instantiate_cards(void)
  790. {
  791. struct snd_soc_card *card;
  792. list_for_each_entry(card, &card_list, list)
  793. snd_soc_instantiate_card(card);
  794. }
  795. /* probes a new socdev */
  796. static int soc_probe(struct platform_device *pdev)
  797. {
  798. int ret = 0;
  799. struct snd_soc_device *socdev = platform_get_drvdata(pdev);
  800. struct snd_soc_card *card = socdev->card;
  801. /* Bodge while we push things out of socdev */
  802. card->socdev = socdev;
  803. /* Bodge while we unpick instantiation */
  804. card->dev = &pdev->dev;
  805. ret = snd_soc_register_card(card);
  806. if (ret != 0) {
  807. dev_err(&pdev->dev, "Failed to register card\n");
  808. return ret;
  809. }
  810. return 0;
  811. }
  812. /* removes a socdev */
  813. static int soc_remove(struct platform_device *pdev)
  814. {
  815. int i;
  816. struct snd_soc_device *socdev = platform_get_drvdata(pdev);
  817. struct snd_soc_card *card = socdev->card;
  818. struct snd_soc_platform *platform = card->platform;
  819. struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
  820. run_delayed_work(&card->delayed_work);
  821. if (platform->remove)
  822. platform->remove(pdev);
  823. if (codec_dev->remove)
  824. codec_dev->remove(pdev);
  825. for (i = 0; i < card->num_links; i++) {
  826. struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai;
  827. if (cpu_dai->remove)
  828. cpu_dai->remove(pdev, cpu_dai);
  829. }
  830. if (card->remove)
  831. card->remove(pdev);
  832. snd_soc_unregister_card(card);
  833. return 0;
  834. }
  835. /* ASoC platform driver */
  836. static struct platform_driver soc_driver = {
  837. .driver = {
  838. .name = "soc-audio",
  839. .owner = THIS_MODULE,
  840. },
  841. .probe = soc_probe,
  842. .remove = soc_remove,
  843. .suspend = soc_suspend,
  844. .resume = soc_resume,
  845. };
  846. /* create a new pcm */
  847. static int soc_new_pcm(struct snd_soc_device *socdev,
  848. struct snd_soc_dai_link *dai_link, int num)
  849. {
  850. struct snd_soc_card *card = socdev->card;
  851. struct snd_soc_codec *codec = card->codec;
  852. struct snd_soc_platform *platform = card->platform;
  853. struct snd_soc_dai *codec_dai = dai_link->codec_dai;
  854. struct snd_soc_dai *cpu_dai = dai_link->cpu_dai;
  855. struct snd_soc_pcm_runtime *rtd;
  856. struct snd_pcm *pcm;
  857. char new_name[64];
  858. int ret = 0, playback = 0, capture = 0;
  859. rtd = kzalloc(sizeof(struct snd_soc_pcm_runtime), GFP_KERNEL);
  860. if (rtd == NULL)
  861. return -ENOMEM;
  862. rtd->dai = dai_link;
  863. rtd->socdev = socdev;
  864. codec_dai->codec = card->codec;
  865. /* check client and interface hw capabilities */
  866. sprintf(new_name, "%s %s-%d", dai_link->stream_name, codec_dai->name,
  867. num);
  868. if (codec_dai->playback.channels_min)
  869. playback = 1;
  870. if (codec_dai->capture.channels_min)
  871. capture = 1;
  872. ret = snd_pcm_new(codec->card, new_name, codec->pcm_devs++, playback,
  873. capture, &pcm);
  874. if (ret < 0) {
  875. printk(KERN_ERR "asoc: can't create pcm for codec %s\n",
  876. codec->name);
  877. kfree(rtd);
  878. return ret;
  879. }
  880. dai_link->pcm = pcm;
  881. pcm->private_data = rtd;
  882. soc_pcm_ops.mmap = platform->pcm_ops->mmap;
  883. soc_pcm_ops.pointer = platform->pcm_ops->pointer;
  884. soc_pcm_ops.ioctl = platform->pcm_ops->ioctl;
  885. soc_pcm_ops.copy = platform->pcm_ops->copy;
  886. soc_pcm_ops.silence = platform->pcm_ops->silence;
  887. soc_pcm_ops.ack = platform->pcm_ops->ack;
  888. soc_pcm_ops.page = platform->pcm_ops->page;
  889. if (playback)
  890. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &soc_pcm_ops);
  891. if (capture)
  892. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &soc_pcm_ops);
  893. ret = platform->pcm_new(codec->card, codec_dai, pcm);
  894. if (ret < 0) {
  895. printk(KERN_ERR "asoc: platform pcm constructor failed\n");
  896. kfree(rtd);
  897. return ret;
  898. }
  899. pcm->private_free = platform->pcm_free;
  900. printk(KERN_INFO "asoc: %s <-> %s mapping ok\n", codec_dai->name,
  901. cpu_dai->name);
  902. return ret;
  903. }
  904. /* codec register dump */
  905. static ssize_t soc_codec_reg_show(struct snd_soc_codec *codec, char *buf)
  906. {
  907. int i, step = 1, count = 0;
  908. if (!codec->reg_cache_size)
  909. return 0;
  910. if (codec->reg_cache_step)
  911. step = codec->reg_cache_step;
  912. count += sprintf(buf, "%s registers\n", codec->name);
  913. for (i = 0; i < codec->reg_cache_size; i += step) {
  914. count += sprintf(buf + count, "%2x: ", i);
  915. if (count >= PAGE_SIZE - 1)
  916. break;
  917. if (codec->display_register)
  918. count += codec->display_register(codec, buf + count,
  919. PAGE_SIZE - count, i);
  920. else
  921. count += snprintf(buf + count, PAGE_SIZE - count,
  922. "%4x", codec->read(codec, i));
  923. if (count >= PAGE_SIZE - 1)
  924. break;
  925. count += snprintf(buf + count, PAGE_SIZE - count, "\n");
  926. if (count >= PAGE_SIZE - 1)
  927. break;
  928. }
  929. /* Truncate count; min() would cause a warning */
  930. if (count >= PAGE_SIZE)
  931. count = PAGE_SIZE - 1;
  932. return count;
  933. }
  934. static ssize_t codec_reg_show(struct device *dev,
  935. struct device_attribute *attr, char *buf)
  936. {
  937. struct snd_soc_device *devdata = dev_get_drvdata(dev);
  938. return soc_codec_reg_show(devdata->card->codec, buf);
  939. }
  940. static DEVICE_ATTR(codec_reg, 0444, codec_reg_show, NULL);
  941. #ifdef CONFIG_DEBUG_FS
  942. static int codec_reg_open_file(struct inode *inode, struct file *file)
  943. {
  944. file->private_data = inode->i_private;
  945. return 0;
  946. }
  947. static ssize_t codec_reg_read_file(struct file *file, char __user *user_buf,
  948. size_t count, loff_t *ppos)
  949. {
  950. ssize_t ret;
  951. struct snd_soc_codec *codec = file->private_data;
  952. char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
  953. if (!buf)
  954. return -ENOMEM;
  955. ret = soc_codec_reg_show(codec, buf);
  956. if (ret >= 0)
  957. ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
  958. kfree(buf);
  959. return ret;
  960. }
  961. static ssize_t codec_reg_write_file(struct file *file,
  962. const char __user *user_buf, size_t count, loff_t *ppos)
  963. {
  964. char buf[32];
  965. int buf_size;
  966. char *start = buf;
  967. unsigned long reg, value;
  968. int step = 1;
  969. struct snd_soc_codec *codec = file->private_data;
  970. buf_size = min(count, (sizeof(buf)-1));
  971. if (copy_from_user(buf, user_buf, buf_size))
  972. return -EFAULT;
  973. buf[buf_size] = 0;
  974. if (codec->reg_cache_step)
  975. step = codec->reg_cache_step;
  976. while (*start == ' ')
  977. start++;
  978. reg = simple_strtoul(start, &start, 16);
  979. if ((reg >= codec->reg_cache_size) || (reg % step))
  980. return -EINVAL;
  981. while (*start == ' ')
  982. start++;
  983. if (strict_strtoul(start, 16, &value))
  984. return -EINVAL;
  985. codec->write(codec, reg, value);
  986. return buf_size;
  987. }
  988. static const struct file_operations codec_reg_fops = {
  989. .open = codec_reg_open_file,
  990. .read = codec_reg_read_file,
  991. .write = codec_reg_write_file,
  992. };
  993. static void soc_init_codec_debugfs(struct snd_soc_codec *codec)
  994. {
  995. codec->debugfs_reg = debugfs_create_file("codec_reg", 0644,
  996. debugfs_root, codec,
  997. &codec_reg_fops);
  998. if (!codec->debugfs_reg)
  999. printk(KERN_WARNING
  1000. "ASoC: Failed to create codec register debugfs file\n");
  1001. codec->debugfs_pop_time = debugfs_create_u32("dapm_pop_time", 0744,
  1002. debugfs_root,
  1003. &codec->pop_time);
  1004. if (!codec->debugfs_pop_time)
  1005. printk(KERN_WARNING
  1006. "Failed to create pop time debugfs file\n");
  1007. }
  1008. static void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec)
  1009. {
  1010. debugfs_remove(codec->debugfs_pop_time);
  1011. debugfs_remove(codec->debugfs_reg);
  1012. }
  1013. #else
  1014. static inline void soc_init_codec_debugfs(struct snd_soc_codec *codec)
  1015. {
  1016. }
  1017. static inline void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec)
  1018. {
  1019. }
  1020. #endif
  1021. /**
  1022. * snd_soc_new_ac97_codec - initailise AC97 device
  1023. * @codec: audio codec
  1024. * @ops: AC97 bus operations
  1025. * @num: AC97 codec number
  1026. *
  1027. * Initialises AC97 codec resources for use by ad-hoc devices only.
  1028. */
  1029. int snd_soc_new_ac97_codec(struct snd_soc_codec *codec,
  1030. struct snd_ac97_bus_ops *ops, int num)
  1031. {
  1032. mutex_lock(&codec->mutex);
  1033. codec->ac97 = kzalloc(sizeof(struct snd_ac97), GFP_KERNEL);
  1034. if (codec->ac97 == NULL) {
  1035. mutex_unlock(&codec->mutex);
  1036. return -ENOMEM;
  1037. }
  1038. codec->ac97->bus = kzalloc(sizeof(struct snd_ac97_bus), GFP_KERNEL);
  1039. if (codec->ac97->bus == NULL) {
  1040. kfree(codec->ac97);
  1041. codec->ac97 = NULL;
  1042. mutex_unlock(&codec->mutex);
  1043. return -ENOMEM;
  1044. }
  1045. codec->ac97->bus->ops = ops;
  1046. codec->ac97->num = num;
  1047. mutex_unlock(&codec->mutex);
  1048. return 0;
  1049. }
  1050. EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec);
  1051. /**
  1052. * snd_soc_free_ac97_codec - free AC97 codec device
  1053. * @codec: audio codec
  1054. *
  1055. * Frees AC97 codec device resources.
  1056. */
  1057. void snd_soc_free_ac97_codec(struct snd_soc_codec *codec)
  1058. {
  1059. mutex_lock(&codec->mutex);
  1060. kfree(codec->ac97->bus);
  1061. kfree(codec->ac97);
  1062. codec->ac97 = NULL;
  1063. mutex_unlock(&codec->mutex);
  1064. }
  1065. EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec);
  1066. /**
  1067. * snd_soc_update_bits - update codec register bits
  1068. * @codec: audio codec
  1069. * @reg: codec register
  1070. * @mask: register mask
  1071. * @value: new value
  1072. *
  1073. * Writes new register value.
  1074. *
  1075. * Returns 1 for change else 0.
  1076. */
  1077. int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg,
  1078. unsigned short mask, unsigned short value)
  1079. {
  1080. int change;
  1081. unsigned short old, new;
  1082. mutex_lock(&io_mutex);
  1083. old = snd_soc_read(codec, reg);
  1084. new = (old & ~mask) | value;
  1085. change = old != new;
  1086. if (change)
  1087. snd_soc_write(codec, reg, new);
  1088. mutex_unlock(&io_mutex);
  1089. return change;
  1090. }
  1091. EXPORT_SYMBOL_GPL(snd_soc_update_bits);
  1092. /**
  1093. * snd_soc_test_bits - test register for change
  1094. * @codec: audio codec
  1095. * @reg: codec register
  1096. * @mask: register mask
  1097. * @value: new value
  1098. *
  1099. * Tests a register with a new value and checks if the new value is
  1100. * different from the old value.
  1101. *
  1102. * Returns 1 for change else 0.
  1103. */
  1104. int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned short reg,
  1105. unsigned short mask, unsigned short value)
  1106. {
  1107. int change;
  1108. unsigned short old, new;
  1109. mutex_lock(&io_mutex);
  1110. old = snd_soc_read(codec, reg);
  1111. new = (old & ~mask) | value;
  1112. change = old != new;
  1113. mutex_unlock(&io_mutex);
  1114. return change;
  1115. }
  1116. EXPORT_SYMBOL_GPL(snd_soc_test_bits);
  1117. /**
  1118. * snd_soc_new_pcms - create new sound card and pcms
  1119. * @socdev: the SoC audio device
  1120. * @idx: ALSA card index
  1121. * @xid: card identification
  1122. *
  1123. * Create a new sound card based upon the codec and interface pcms.
  1124. *
  1125. * Returns 0 for success, else error.
  1126. */
  1127. int snd_soc_new_pcms(struct snd_soc_device *socdev, int idx, const char *xid)
  1128. {
  1129. struct snd_soc_card *card = socdev->card;
  1130. struct snd_soc_codec *codec = card->codec;
  1131. int ret, i;
  1132. mutex_lock(&codec->mutex);
  1133. /* register a sound card */
  1134. ret = snd_card_create(idx, xid, codec->owner, 0, &codec->card);
  1135. if (ret < 0) {
  1136. printk(KERN_ERR "asoc: can't create sound card for codec %s\n",
  1137. codec->name);
  1138. mutex_unlock(&codec->mutex);
  1139. return ret;
  1140. }
  1141. codec->card->dev = socdev->dev;
  1142. codec->card->private_data = codec;
  1143. strncpy(codec->card->driver, codec->name, sizeof(codec->card->driver));
  1144. /* create the pcms */
  1145. for (i = 0; i < card->num_links; i++) {
  1146. ret = soc_new_pcm(socdev, &card->dai_link[i], i);
  1147. if (ret < 0) {
  1148. printk(KERN_ERR "asoc: can't create pcm %s\n",
  1149. card->dai_link[i].stream_name);
  1150. mutex_unlock(&codec->mutex);
  1151. return ret;
  1152. }
  1153. }
  1154. mutex_unlock(&codec->mutex);
  1155. return ret;
  1156. }
  1157. EXPORT_SYMBOL_GPL(snd_soc_new_pcms);
  1158. /**
  1159. * snd_soc_init_card - register sound card
  1160. * @socdev: the SoC audio device
  1161. *
  1162. * Register a SoC sound card. Also registers an AC97 device if the
  1163. * codec is AC97 for ad hoc devices.
  1164. *
  1165. * Returns 0 for success, else error.
  1166. */
  1167. int snd_soc_init_card(struct snd_soc_device *socdev)
  1168. {
  1169. struct snd_soc_card *card = socdev->card;
  1170. struct snd_soc_codec *codec = card->codec;
  1171. int ret = 0, i, ac97 = 0, err = 0;
  1172. for (i = 0; i < card->num_links; i++) {
  1173. if (card->dai_link[i].init) {
  1174. err = card->dai_link[i].init(codec);
  1175. if (err < 0) {
  1176. printk(KERN_ERR "asoc: failed to init %s\n",
  1177. card->dai_link[i].stream_name);
  1178. continue;
  1179. }
  1180. }
  1181. if (card->dai_link[i].codec_dai->ac97_control)
  1182. ac97 = 1;
  1183. }
  1184. snprintf(codec->card->shortname, sizeof(codec->card->shortname),
  1185. "%s", card->name);
  1186. snprintf(codec->card->longname, sizeof(codec->card->longname),
  1187. "%s (%s)", card->name, codec->name);
  1188. ret = snd_card_register(codec->card);
  1189. if (ret < 0) {
  1190. printk(KERN_ERR "asoc: failed to register soundcard for %s\n",
  1191. codec->name);
  1192. goto out;
  1193. }
  1194. mutex_lock(&codec->mutex);
  1195. #ifdef CONFIG_SND_SOC_AC97_BUS
  1196. /* Only instantiate AC97 if not already done by the adaptor
  1197. * for the generic AC97 subsystem.
  1198. */
  1199. if (ac97 && strcmp(codec->name, "AC97") != 0) {
  1200. ret = soc_ac97_dev_register(codec);
  1201. if (ret < 0) {
  1202. printk(KERN_ERR "asoc: AC97 device register failed\n");
  1203. snd_card_free(codec->card);
  1204. mutex_unlock(&codec->mutex);
  1205. goto out;
  1206. }
  1207. }
  1208. #endif
  1209. err = snd_soc_dapm_sys_add(socdev->dev);
  1210. if (err < 0)
  1211. printk(KERN_WARNING "asoc: failed to add dapm sysfs entries\n");
  1212. err = device_create_file(socdev->dev, &dev_attr_codec_reg);
  1213. if (err < 0)
  1214. printk(KERN_WARNING "asoc: failed to add codec sysfs files\n");
  1215. soc_init_codec_debugfs(codec);
  1216. mutex_unlock(&codec->mutex);
  1217. out:
  1218. return ret;
  1219. }
  1220. EXPORT_SYMBOL_GPL(snd_soc_init_card);
  1221. /**
  1222. * snd_soc_free_pcms - free sound card and pcms
  1223. * @socdev: the SoC audio device
  1224. *
  1225. * Frees sound card and pcms associated with the socdev.
  1226. * Also unregister the codec if it is an AC97 device.
  1227. */
  1228. void snd_soc_free_pcms(struct snd_soc_device *socdev)
  1229. {
  1230. struct snd_soc_codec *codec = socdev->card->codec;
  1231. #ifdef CONFIG_SND_SOC_AC97_BUS
  1232. struct snd_soc_dai *codec_dai;
  1233. int i;
  1234. #endif
  1235. mutex_lock(&codec->mutex);
  1236. soc_cleanup_codec_debugfs(codec);
  1237. #ifdef CONFIG_SND_SOC_AC97_BUS
  1238. for (i = 0; i < codec->num_dai; i++) {
  1239. codec_dai = &codec->dai[i];
  1240. if (codec_dai->ac97_control && codec->ac97 &&
  1241. strcmp(codec->name, "AC97") != 0) {
  1242. soc_ac97_dev_unregister(codec);
  1243. goto free_card;
  1244. }
  1245. }
  1246. free_card:
  1247. #endif
  1248. if (codec->card)
  1249. snd_card_free(codec->card);
  1250. device_remove_file(socdev->dev, &dev_attr_codec_reg);
  1251. mutex_unlock(&codec->mutex);
  1252. }
  1253. EXPORT_SYMBOL_GPL(snd_soc_free_pcms);
  1254. /**
  1255. * snd_soc_set_runtime_hwparams - set the runtime hardware parameters
  1256. * @substream: the pcm substream
  1257. * @hw: the hardware parameters
  1258. *
  1259. * Sets the substream runtime hardware parameters.
  1260. */
  1261. int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
  1262. const struct snd_pcm_hardware *hw)
  1263. {
  1264. struct snd_pcm_runtime *runtime = substream->runtime;
  1265. runtime->hw.info = hw->info;
  1266. runtime->hw.formats = hw->formats;
  1267. runtime->hw.period_bytes_min = hw->period_bytes_min;
  1268. runtime->hw.period_bytes_max = hw->period_bytes_max;
  1269. runtime->hw.periods_min = hw->periods_min;
  1270. runtime->hw.periods_max = hw->periods_max;
  1271. runtime->hw.buffer_bytes_max = hw->buffer_bytes_max;
  1272. runtime->hw.fifo_size = hw->fifo_size;
  1273. return 0;
  1274. }
  1275. EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hwparams);
  1276. /**
  1277. * snd_soc_cnew - create new control
  1278. * @_template: control template
  1279. * @data: control private data
  1280. * @long_name: control long name
  1281. *
  1282. * Create a new mixer control from a template control.
  1283. *
  1284. * Returns 0 for success, else error.
  1285. */
  1286. struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
  1287. void *data, char *long_name)
  1288. {
  1289. struct snd_kcontrol_new template;
  1290. memcpy(&template, _template, sizeof(template));
  1291. if (long_name)
  1292. template.name = long_name;
  1293. template.index = 0;
  1294. return snd_ctl_new1(&template, data);
  1295. }
  1296. EXPORT_SYMBOL_GPL(snd_soc_cnew);
  1297. /**
  1298. * snd_soc_add_controls - add an array of controls to a codec.
  1299. * Convienience function to add a list of controls. Many codecs were
  1300. * duplicating this code.
  1301. *
  1302. * @codec: codec to add controls to
  1303. * @controls: array of controls to add
  1304. * @num_controls: number of elements in the array
  1305. *
  1306. * Return 0 for success, else error.
  1307. */
  1308. int snd_soc_add_controls(struct snd_soc_codec *codec,
  1309. const struct snd_kcontrol_new *controls, int num_controls)
  1310. {
  1311. struct snd_card *card = codec->card;
  1312. int err, i;
  1313. for (i = 0; i < num_controls; i++) {
  1314. const struct snd_kcontrol_new *control = &controls[i];
  1315. err = snd_ctl_add(card, snd_soc_cnew(control, codec, NULL));
  1316. if (err < 0) {
  1317. dev_err(codec->dev, "%s: Failed to add %s\n",
  1318. codec->name, control->name);
  1319. return err;
  1320. }
  1321. }
  1322. return 0;
  1323. }
  1324. EXPORT_SYMBOL_GPL(snd_soc_add_controls);
  1325. /**
  1326. * snd_soc_info_enum_double - enumerated double mixer info callback
  1327. * @kcontrol: mixer control
  1328. * @uinfo: control element information
  1329. *
  1330. * Callback to provide information about a double enumerated
  1331. * mixer control.
  1332. *
  1333. * Returns 0 for success.
  1334. */
  1335. int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
  1336. struct snd_ctl_elem_info *uinfo)
  1337. {
  1338. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  1339. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  1340. uinfo->count = e->shift_l == e->shift_r ? 1 : 2;
  1341. uinfo->value.enumerated.items = e->max;
  1342. if (uinfo->value.enumerated.item > e->max - 1)
  1343. uinfo->value.enumerated.item = e->max - 1;
  1344. strcpy(uinfo->value.enumerated.name,
  1345. e->texts[uinfo->value.enumerated.item]);
  1346. return 0;
  1347. }
  1348. EXPORT_SYMBOL_GPL(snd_soc_info_enum_double);
  1349. /**
  1350. * snd_soc_get_enum_double - enumerated double mixer get callback
  1351. * @kcontrol: mixer control
  1352. * @ucontrol: control element information
  1353. *
  1354. * Callback to get the value of a double enumerated mixer.
  1355. *
  1356. * Returns 0 for success.
  1357. */
  1358. int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
  1359. struct snd_ctl_elem_value *ucontrol)
  1360. {
  1361. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  1362. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  1363. unsigned short val, bitmask;
  1364. for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
  1365. ;
  1366. val = snd_soc_read(codec, e->reg);
  1367. ucontrol->value.enumerated.item[0]
  1368. = (val >> e->shift_l) & (bitmask - 1);
  1369. if (e->shift_l != e->shift_r)
  1370. ucontrol->value.enumerated.item[1] =
  1371. (val >> e->shift_r) & (bitmask - 1);
  1372. return 0;
  1373. }
  1374. EXPORT_SYMBOL_GPL(snd_soc_get_enum_double);
  1375. /**
  1376. * snd_soc_put_enum_double - enumerated double mixer put callback
  1377. * @kcontrol: mixer control
  1378. * @ucontrol: control element information
  1379. *
  1380. * Callback to set the value of a double enumerated mixer.
  1381. *
  1382. * Returns 0 for success.
  1383. */
  1384. int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
  1385. struct snd_ctl_elem_value *ucontrol)
  1386. {
  1387. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  1388. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  1389. unsigned short val;
  1390. unsigned short mask, bitmask;
  1391. for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
  1392. ;
  1393. if (ucontrol->value.enumerated.item[0] > e->max - 1)
  1394. return -EINVAL;
  1395. val = ucontrol->value.enumerated.item[0] << e->shift_l;
  1396. mask = (bitmask - 1) << e->shift_l;
  1397. if (e->shift_l != e->shift_r) {
  1398. if (ucontrol->value.enumerated.item[1] > e->max - 1)
  1399. return -EINVAL;
  1400. val |= ucontrol->value.enumerated.item[1] << e->shift_r;
  1401. mask |= (bitmask - 1) << e->shift_r;
  1402. }
  1403. return snd_soc_update_bits(codec, e->reg, mask, val);
  1404. }
  1405. EXPORT_SYMBOL_GPL(snd_soc_put_enum_double);
  1406. /**
  1407. * snd_soc_get_value_enum_double - semi enumerated double mixer get callback
  1408. * @kcontrol: mixer control
  1409. * @ucontrol: control element information
  1410. *
  1411. * Callback to get the value of a double semi enumerated mixer.
  1412. *
  1413. * Semi enumerated mixer: the enumerated items are referred as values. Can be
  1414. * used for handling bitfield coded enumeration for example.
  1415. *
  1416. * Returns 0 for success.
  1417. */
  1418. int snd_soc_get_value_enum_double(struct snd_kcontrol *kcontrol,
  1419. struct snd_ctl_elem_value *ucontrol)
  1420. {
  1421. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  1422. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  1423. unsigned short reg_val, val, mux;
  1424. reg_val = snd_soc_read(codec, e->reg);
  1425. val = (reg_val >> e->shift_l) & e->mask;
  1426. for (mux = 0; mux < e->max; mux++) {
  1427. if (val == e->values[mux])
  1428. break;
  1429. }
  1430. ucontrol->value.enumerated.item[0] = mux;
  1431. if (e->shift_l != e->shift_r) {
  1432. val = (reg_val >> e->shift_r) & e->mask;
  1433. for (mux = 0; mux < e->max; mux++) {
  1434. if (val == e->values[mux])
  1435. break;
  1436. }
  1437. ucontrol->value.enumerated.item[1] = mux;
  1438. }
  1439. return 0;
  1440. }
  1441. EXPORT_SYMBOL_GPL(snd_soc_get_value_enum_double);
  1442. /**
  1443. * snd_soc_put_value_enum_double - semi enumerated double mixer put callback
  1444. * @kcontrol: mixer control
  1445. * @ucontrol: control element information
  1446. *
  1447. * Callback to set the value of a double semi enumerated mixer.
  1448. *
  1449. * Semi enumerated mixer: the enumerated items are referred as values. Can be
  1450. * used for handling bitfield coded enumeration for example.
  1451. *
  1452. * Returns 0 for success.
  1453. */
  1454. int snd_soc_put_value_enum_double(struct snd_kcontrol *kcontrol,
  1455. struct snd_ctl_elem_value *ucontrol)
  1456. {
  1457. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  1458. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  1459. unsigned short val;
  1460. unsigned short mask;
  1461. if (ucontrol->value.enumerated.item[0] > e->max - 1)
  1462. return -EINVAL;
  1463. val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l;
  1464. mask = e->mask << e->shift_l;
  1465. if (e->shift_l != e->shift_r) {
  1466. if (ucontrol->value.enumerated.item[1] > e->max - 1)
  1467. return -EINVAL;
  1468. val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r;
  1469. mask |= e->mask << e->shift_r;
  1470. }
  1471. return snd_soc_update_bits(codec, e->reg, mask, val);
  1472. }
  1473. EXPORT_SYMBOL_GPL(snd_soc_put_value_enum_double);
  1474. /**
  1475. * snd_soc_info_enum_ext - external enumerated single mixer info callback
  1476. * @kcontrol: mixer control
  1477. * @uinfo: control element information
  1478. *
  1479. * Callback to provide information about an external enumerated
  1480. * single mixer.
  1481. *
  1482. * Returns 0 for success.
  1483. */
  1484. int snd_soc_info_enum_ext(struct snd_kcontrol *kcontrol,
  1485. struct snd_ctl_elem_info *uinfo)
  1486. {
  1487. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  1488. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  1489. uinfo->count = 1;
  1490. uinfo->value.enumerated.items = e->max;
  1491. if (uinfo->value.enumerated.item > e->max - 1)
  1492. uinfo->value.enumerated.item = e->max - 1;
  1493. strcpy(uinfo->value.enumerated.name,
  1494. e->texts[uinfo->value.enumerated.item]);
  1495. return 0;
  1496. }
  1497. EXPORT_SYMBOL_GPL(snd_soc_info_enum_ext);
  1498. /**
  1499. * snd_soc_info_volsw_ext - external single mixer info callback
  1500. * @kcontrol: mixer control
  1501. * @uinfo: control element information
  1502. *
  1503. * Callback to provide information about a single external mixer control.
  1504. *
  1505. * Returns 0 for success.
  1506. */
  1507. int snd_soc_info_volsw_ext(struct snd_kcontrol *kcontrol,
  1508. struct snd_ctl_elem_info *uinfo)
  1509. {
  1510. int max = kcontrol->private_value;
  1511. if (max == 1)
  1512. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  1513. else
  1514. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  1515. uinfo->count = 1;
  1516. uinfo->value.integer.min = 0;
  1517. uinfo->value.integer.max = max;
  1518. return 0;
  1519. }
  1520. EXPORT_SYMBOL_GPL(snd_soc_info_volsw_ext);
  1521. /**
  1522. * snd_soc_info_volsw - single mixer info callback
  1523. * @kcontrol: mixer control
  1524. * @uinfo: control element information
  1525. *
  1526. * Callback to provide information about a single mixer control.
  1527. *
  1528. * Returns 0 for success.
  1529. */
  1530. int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
  1531. struct snd_ctl_elem_info *uinfo)
  1532. {
  1533. struct soc_mixer_control *mc =
  1534. (struct soc_mixer_control *)kcontrol->private_value;
  1535. int max = mc->max;
  1536. unsigned int shift = mc->shift;
  1537. unsigned int rshift = mc->rshift;
  1538. if (max == 1)
  1539. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  1540. else
  1541. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  1542. uinfo->count = shift == rshift ? 1 : 2;
  1543. uinfo->value.integer.min = 0;
  1544. uinfo->value.integer.max = max;
  1545. return 0;
  1546. }
  1547. EXPORT_SYMBOL_GPL(snd_soc_info_volsw);
  1548. /**
  1549. * snd_soc_get_volsw - single mixer get callback
  1550. * @kcontrol: mixer control
  1551. * @ucontrol: control element information
  1552. *
  1553. * Callback to get the value of a single mixer control.
  1554. *
  1555. * Returns 0 for success.
  1556. */
  1557. int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
  1558. struct snd_ctl_elem_value *ucontrol)
  1559. {
  1560. struct soc_mixer_control *mc =
  1561. (struct soc_mixer_control *)kcontrol->private_value;
  1562. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  1563. unsigned int reg = mc->reg;
  1564. unsigned int shift = mc->shift;
  1565. unsigned int rshift = mc->rshift;
  1566. int max = mc->max;
  1567. unsigned int mask = (1 << fls(max)) - 1;
  1568. unsigned int invert = mc->invert;
  1569. ucontrol->value.integer.value[0] =
  1570. (snd_soc_read(codec, reg) >> shift) & mask;
  1571. if (shift != rshift)
  1572. ucontrol->value.integer.value[1] =
  1573. (snd_soc_read(codec, reg) >> rshift) & mask;
  1574. if (invert) {
  1575. ucontrol->value.integer.value[0] =
  1576. max - ucontrol->value.integer.value[0];
  1577. if (shift != rshift)
  1578. ucontrol->value.integer.value[1] =
  1579. max - ucontrol->value.integer.value[1];
  1580. }
  1581. return 0;
  1582. }
  1583. EXPORT_SYMBOL_GPL(snd_soc_get_volsw);
  1584. /**
  1585. * snd_soc_put_volsw - single mixer put callback
  1586. * @kcontrol: mixer control
  1587. * @ucontrol: control element information
  1588. *
  1589. * Callback to set the value of a single mixer control.
  1590. *
  1591. * Returns 0 for success.
  1592. */
  1593. int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
  1594. struct snd_ctl_elem_value *ucontrol)
  1595. {
  1596. struct soc_mixer_control *mc =
  1597. (struct soc_mixer_control *)kcontrol->private_value;
  1598. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  1599. unsigned int reg = mc->reg;
  1600. unsigned int shift = mc->shift;
  1601. unsigned int rshift = mc->rshift;
  1602. int max = mc->max;
  1603. unsigned int mask = (1 << fls(max)) - 1;
  1604. unsigned int invert = mc->invert;
  1605. unsigned short val, val2, val_mask;
  1606. val = (ucontrol->value.integer.value[0] & mask);
  1607. if (invert)
  1608. val = max - val;
  1609. val_mask = mask << shift;
  1610. val = val << shift;
  1611. if (shift != rshift) {
  1612. val2 = (ucontrol->value.integer.value[1] & mask);
  1613. if (invert)
  1614. val2 = max - val2;
  1615. val_mask |= mask << rshift;
  1616. val |= val2 << rshift;
  1617. }
  1618. return snd_soc_update_bits(codec, reg, val_mask, val);
  1619. }
  1620. EXPORT_SYMBOL_GPL(snd_soc_put_volsw);
  1621. /**
  1622. * snd_soc_info_volsw_2r - double mixer info callback
  1623. * @kcontrol: mixer control
  1624. * @uinfo: control element information
  1625. *
  1626. * Callback to provide information about a double mixer control that
  1627. * spans 2 codec registers.
  1628. *
  1629. * Returns 0 for success.
  1630. */
  1631. int snd_soc_info_volsw_2r(struct snd_kcontrol *kcontrol,
  1632. struct snd_ctl_elem_info *uinfo)
  1633. {
  1634. struct soc_mixer_control *mc =
  1635. (struct soc_mixer_control *)kcontrol->private_value;
  1636. int max = mc->max;
  1637. if (max == 1)
  1638. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  1639. else
  1640. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  1641. uinfo->count = 2;
  1642. uinfo->value.integer.min = 0;
  1643. uinfo->value.integer.max = max;
  1644. return 0;
  1645. }
  1646. EXPORT_SYMBOL_GPL(snd_soc_info_volsw_2r);
  1647. /**
  1648. * snd_soc_get_volsw_2r - double mixer get callback
  1649. * @kcontrol: mixer control
  1650. * @ucontrol: control element information
  1651. *
  1652. * Callback to get the value of a double mixer control that spans 2 registers.
  1653. *
  1654. * Returns 0 for success.
  1655. */
  1656. int snd_soc_get_volsw_2r(struct snd_kcontrol *kcontrol,
  1657. struct snd_ctl_elem_value *ucontrol)
  1658. {
  1659. struct soc_mixer_control *mc =
  1660. (struct soc_mixer_control *)kcontrol->private_value;
  1661. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  1662. unsigned int reg = mc->reg;
  1663. unsigned int reg2 = mc->rreg;
  1664. unsigned int shift = mc->shift;
  1665. int max = mc->max;
  1666. unsigned int mask = (1<<fls(max))-1;
  1667. unsigned int invert = mc->invert;
  1668. ucontrol->value.integer.value[0] =
  1669. (snd_soc_read(codec, reg) >> shift) & mask;
  1670. ucontrol->value.integer.value[1] =
  1671. (snd_soc_read(codec, reg2) >> shift) & mask;
  1672. if (invert) {
  1673. ucontrol->value.integer.value[0] =
  1674. max - ucontrol->value.integer.value[0];
  1675. ucontrol->value.integer.value[1] =
  1676. max - ucontrol->value.integer.value[1];
  1677. }
  1678. return 0;
  1679. }
  1680. EXPORT_SYMBOL_GPL(snd_soc_get_volsw_2r);
  1681. /**
  1682. * snd_soc_put_volsw_2r - double mixer set callback
  1683. * @kcontrol: mixer control
  1684. * @ucontrol: control element information
  1685. *
  1686. * Callback to set the value of a double mixer control that spans 2 registers.
  1687. *
  1688. * Returns 0 for success.
  1689. */
  1690. int snd_soc_put_volsw_2r(struct snd_kcontrol *kcontrol,
  1691. struct snd_ctl_elem_value *ucontrol)
  1692. {
  1693. struct soc_mixer_control *mc =
  1694. (struct soc_mixer_control *)kcontrol->private_value;
  1695. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  1696. unsigned int reg = mc->reg;
  1697. unsigned int reg2 = mc->rreg;
  1698. unsigned int shift = mc->shift;
  1699. int max = mc->max;
  1700. unsigned int mask = (1 << fls(max)) - 1;
  1701. unsigned int invert = mc->invert;
  1702. int err;
  1703. unsigned short val, val2, val_mask;
  1704. val_mask = mask << shift;
  1705. val = (ucontrol->value.integer.value[0] & mask);
  1706. val2 = (ucontrol->value.integer.value[1] & mask);
  1707. if (invert) {
  1708. val = max - val;
  1709. val2 = max - val2;
  1710. }
  1711. val = val << shift;
  1712. val2 = val2 << shift;
  1713. err = snd_soc_update_bits(codec, reg, val_mask, val);
  1714. if (err < 0)
  1715. return err;
  1716. err = snd_soc_update_bits(codec, reg2, val_mask, val2);
  1717. return err;
  1718. }
  1719. EXPORT_SYMBOL_GPL(snd_soc_put_volsw_2r);
  1720. /**
  1721. * snd_soc_info_volsw_s8 - signed mixer info callback
  1722. * @kcontrol: mixer control
  1723. * @uinfo: control element information
  1724. *
  1725. * Callback to provide information about a signed mixer control.
  1726. *
  1727. * Returns 0 for success.
  1728. */
  1729. int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol,
  1730. struct snd_ctl_elem_info *uinfo)
  1731. {
  1732. struct soc_mixer_control *mc =
  1733. (struct soc_mixer_control *)kcontrol->private_value;
  1734. int max = mc->max;
  1735. int min = mc->min;
  1736. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  1737. uinfo->count = 2;
  1738. uinfo->value.integer.min = 0;
  1739. uinfo->value.integer.max = max-min;
  1740. return 0;
  1741. }
  1742. EXPORT_SYMBOL_GPL(snd_soc_info_volsw_s8);
  1743. /**
  1744. * snd_soc_get_volsw_s8 - signed mixer get callback
  1745. * @kcontrol: mixer control
  1746. * @ucontrol: control element information
  1747. *
  1748. * Callback to get the value of a signed mixer control.
  1749. *
  1750. * Returns 0 for success.
  1751. */
  1752. int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol,
  1753. struct snd_ctl_elem_value *ucontrol)
  1754. {
  1755. struct soc_mixer_control *mc =
  1756. (struct soc_mixer_control *)kcontrol->private_value;
  1757. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  1758. unsigned int reg = mc->reg;
  1759. int min = mc->min;
  1760. int val = snd_soc_read(codec, reg);
  1761. ucontrol->value.integer.value[0] =
  1762. ((signed char)(val & 0xff))-min;
  1763. ucontrol->value.integer.value[1] =
  1764. ((signed char)((val >> 8) & 0xff))-min;
  1765. return 0;
  1766. }
  1767. EXPORT_SYMBOL_GPL(snd_soc_get_volsw_s8);
  1768. /**
  1769. * snd_soc_put_volsw_sgn - signed mixer put callback
  1770. * @kcontrol: mixer control
  1771. * @ucontrol: control element information
  1772. *
  1773. * Callback to set the value of a signed mixer control.
  1774. *
  1775. * Returns 0 for success.
  1776. */
  1777. int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol,
  1778. struct snd_ctl_elem_value *ucontrol)
  1779. {
  1780. struct soc_mixer_control *mc =
  1781. (struct soc_mixer_control *)kcontrol->private_value;
  1782. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  1783. unsigned int reg = mc->reg;
  1784. int min = mc->min;
  1785. unsigned short val;
  1786. val = (ucontrol->value.integer.value[0]+min) & 0xff;
  1787. val |= ((ucontrol->value.integer.value[1]+min) & 0xff) << 8;
  1788. return snd_soc_update_bits(codec, reg, 0xffff, val);
  1789. }
  1790. EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8);
  1791. /**
  1792. * snd_soc_dai_set_sysclk - configure DAI system or master clock.
  1793. * @dai: DAI
  1794. * @clk_id: DAI specific clock ID
  1795. * @freq: new clock frequency in Hz
  1796. * @dir: new clock direction - input/output.
  1797. *
  1798. * Configures the DAI master (MCLK) or system (SYSCLK) clocking.
  1799. */
  1800. int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id,
  1801. unsigned int freq, int dir)
  1802. {
  1803. if (dai->ops->set_sysclk)
  1804. return dai->ops->set_sysclk(dai, clk_id, freq, dir);
  1805. else
  1806. return -EINVAL;
  1807. }
  1808. EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk);
  1809. /**
  1810. * snd_soc_dai_set_clkdiv - configure DAI clock dividers.
  1811. * @dai: DAI
  1812. * @div_id: DAI specific clock divider ID
  1813. * @div: new clock divisor.
  1814. *
  1815. * Configures the clock dividers. This is used to derive the best DAI bit and
  1816. * frame clocks from the system or master clock. It's best to set the DAI bit
  1817. * and frame clocks as low as possible to save system power.
  1818. */
  1819. int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai,
  1820. int div_id, int div)
  1821. {
  1822. if (dai->ops->set_clkdiv)
  1823. return dai->ops->set_clkdiv(dai, div_id, div);
  1824. else
  1825. return -EINVAL;
  1826. }
  1827. EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv);
  1828. /**
  1829. * snd_soc_dai_set_pll - configure DAI PLL.
  1830. * @dai: DAI
  1831. * @pll_id: DAI specific PLL ID
  1832. * @freq_in: PLL input clock frequency in Hz
  1833. * @freq_out: requested PLL output clock frequency in Hz
  1834. *
  1835. * Configures and enables PLL to generate output clock based on input clock.
  1836. */
  1837. int snd_soc_dai_set_pll(struct snd_soc_dai *dai,
  1838. int pll_id, unsigned int freq_in, unsigned int freq_out)
  1839. {
  1840. if (dai->ops->set_pll)
  1841. return dai->ops->set_pll(dai, pll_id, freq_in, freq_out);
  1842. else
  1843. return -EINVAL;
  1844. }
  1845. EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll);
  1846. /**
  1847. * snd_soc_dai_set_fmt - configure DAI hardware audio format.
  1848. * @dai: DAI
  1849. * @fmt: SND_SOC_DAIFMT_ format value.
  1850. *
  1851. * Configures the DAI hardware format and clocking.
  1852. */
  1853. int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
  1854. {
  1855. if (dai->ops->set_fmt)
  1856. return dai->ops->set_fmt(dai, fmt);
  1857. else
  1858. return -EINVAL;
  1859. }
  1860. EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt);
  1861. /**
  1862. * snd_soc_dai_set_tdm_slot - configure DAI TDM.
  1863. * @dai: DAI
  1864. * @mask: DAI specific mask representing used slots.
  1865. * @slots: Number of slots in use.
  1866. *
  1867. * Configures a DAI for TDM operation. Both mask and slots are codec and DAI
  1868. * specific.
  1869. */
  1870. int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,
  1871. unsigned int mask, int slots)
  1872. {
  1873. if (dai->ops->set_sysclk)
  1874. return dai->ops->set_tdm_slot(dai, mask, slots);
  1875. else
  1876. return -EINVAL;
  1877. }
  1878. EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot);
  1879. /**
  1880. * snd_soc_dai_set_tristate - configure DAI system or master clock.
  1881. * @dai: DAI
  1882. * @tristate: tristate enable
  1883. *
  1884. * Tristates the DAI so that others can use it.
  1885. */
  1886. int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate)
  1887. {
  1888. if (dai->ops->set_sysclk)
  1889. return dai->ops->set_tristate(dai, tristate);
  1890. else
  1891. return -EINVAL;
  1892. }
  1893. EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate);
  1894. /**
  1895. * snd_soc_dai_digital_mute - configure DAI system or master clock.
  1896. * @dai: DAI
  1897. * @mute: mute enable
  1898. *
  1899. * Mutes the DAI DAC.
  1900. */
  1901. int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute)
  1902. {
  1903. if (dai->ops->digital_mute)
  1904. return dai->ops->digital_mute(dai, mute);
  1905. else
  1906. return -EINVAL;
  1907. }
  1908. EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute);
  1909. /**
  1910. * snd_soc_register_card - Register a card with the ASoC core
  1911. *
  1912. * @card: Card to register
  1913. *
  1914. * Note that currently this is an internal only function: it will be
  1915. * exposed to machine drivers after further backporting of ASoC v2
  1916. * registration APIs.
  1917. */
  1918. static int snd_soc_register_card(struct snd_soc_card *card)
  1919. {
  1920. if (!card->name || !card->dev)
  1921. return -EINVAL;
  1922. INIT_LIST_HEAD(&card->list);
  1923. card->instantiated = 0;
  1924. mutex_lock(&client_mutex);
  1925. list_add(&card->list, &card_list);
  1926. snd_soc_instantiate_cards();
  1927. mutex_unlock(&client_mutex);
  1928. dev_dbg(card->dev, "Registered card '%s'\n", card->name);
  1929. return 0;
  1930. }
  1931. /**
  1932. * snd_soc_unregister_card - Unregister a card with the ASoC core
  1933. *
  1934. * @card: Card to unregister
  1935. *
  1936. * Note that currently this is an internal only function: it will be
  1937. * exposed to machine drivers after further backporting of ASoC v2
  1938. * registration APIs.
  1939. */
  1940. static int snd_soc_unregister_card(struct snd_soc_card *card)
  1941. {
  1942. mutex_lock(&client_mutex);
  1943. list_del(&card->list);
  1944. mutex_unlock(&client_mutex);
  1945. dev_dbg(card->dev, "Unregistered card '%s'\n", card->name);
  1946. return 0;
  1947. }
  1948. static struct snd_soc_dai_ops null_dai_ops = {
  1949. };
  1950. /**
  1951. * snd_soc_register_dai - Register a DAI with the ASoC core
  1952. *
  1953. * @dai: DAI to register
  1954. */
  1955. int snd_soc_register_dai(struct snd_soc_dai *dai)
  1956. {
  1957. if (!dai->name)
  1958. return -EINVAL;
  1959. /* The device should become mandatory over time */
  1960. if (!dai->dev)
  1961. printk(KERN_WARNING "No device for DAI %s\n", dai->name);
  1962. if (!dai->ops)
  1963. dai->ops = &null_dai_ops;
  1964. INIT_LIST_HEAD(&dai->list);
  1965. mutex_lock(&client_mutex);
  1966. list_add(&dai->list, &dai_list);
  1967. snd_soc_instantiate_cards();
  1968. mutex_unlock(&client_mutex);
  1969. pr_debug("Registered DAI '%s'\n", dai->name);
  1970. return 0;
  1971. }
  1972. EXPORT_SYMBOL_GPL(snd_soc_register_dai);
  1973. /**
  1974. * snd_soc_unregister_dai - Unregister a DAI from the ASoC core
  1975. *
  1976. * @dai: DAI to unregister
  1977. */
  1978. void snd_soc_unregister_dai(struct snd_soc_dai *dai)
  1979. {
  1980. mutex_lock(&client_mutex);
  1981. list_del(&dai->list);
  1982. mutex_unlock(&client_mutex);
  1983. pr_debug("Unregistered DAI '%s'\n", dai->name);
  1984. }
  1985. EXPORT_SYMBOL_GPL(snd_soc_unregister_dai);
  1986. /**
  1987. * snd_soc_register_dais - Register multiple DAIs with the ASoC core
  1988. *
  1989. * @dai: Array of DAIs to register
  1990. * @count: Number of DAIs
  1991. */
  1992. int snd_soc_register_dais(struct snd_soc_dai *dai, size_t count)
  1993. {
  1994. int i, ret;
  1995. for (i = 0; i < count; i++) {
  1996. ret = snd_soc_register_dai(&dai[i]);
  1997. if (ret != 0)
  1998. goto err;
  1999. }
  2000. return 0;
  2001. err:
  2002. for (i--; i >= 0; i--)
  2003. snd_soc_unregister_dai(&dai[i]);
  2004. return ret;
  2005. }
  2006. EXPORT_SYMBOL_GPL(snd_soc_register_dais);
  2007. /**
  2008. * snd_soc_unregister_dais - Unregister multiple DAIs from the ASoC core
  2009. *
  2010. * @dai: Array of DAIs to unregister
  2011. * @count: Number of DAIs
  2012. */
  2013. void snd_soc_unregister_dais(struct snd_soc_dai *dai, size_t count)
  2014. {
  2015. int i;
  2016. for (i = 0; i < count; i++)
  2017. snd_soc_unregister_dai(&dai[i]);
  2018. }
  2019. EXPORT_SYMBOL_GPL(snd_soc_unregister_dais);
  2020. /**
  2021. * snd_soc_register_platform - Register a platform with the ASoC core
  2022. *
  2023. * @platform: platform to register
  2024. */
  2025. int snd_soc_register_platform(struct snd_soc_platform *platform)
  2026. {
  2027. if (!platform->name)
  2028. return -EINVAL;
  2029. INIT_LIST_HEAD(&platform->list);
  2030. mutex_lock(&client_mutex);
  2031. list_add(&platform->list, &platform_list);
  2032. snd_soc_instantiate_cards();
  2033. mutex_unlock(&client_mutex);
  2034. pr_debug("Registered platform '%s'\n", platform->name);
  2035. return 0;
  2036. }
  2037. EXPORT_SYMBOL_GPL(snd_soc_register_platform);
  2038. /**
  2039. * snd_soc_unregister_platform - Unregister a platform from the ASoC core
  2040. *
  2041. * @platform: platform to unregister
  2042. */
  2043. void snd_soc_unregister_platform(struct snd_soc_platform *platform)
  2044. {
  2045. mutex_lock(&client_mutex);
  2046. list_del(&platform->list);
  2047. mutex_unlock(&client_mutex);
  2048. pr_debug("Unregistered platform '%s'\n", platform->name);
  2049. }
  2050. EXPORT_SYMBOL_GPL(snd_soc_unregister_platform);
  2051. /**
  2052. * snd_soc_register_codec - Register a codec with the ASoC core
  2053. *
  2054. * @codec: codec to register
  2055. */
  2056. int snd_soc_register_codec(struct snd_soc_codec *codec)
  2057. {
  2058. if (!codec->name)
  2059. return -EINVAL;
  2060. /* The device should become mandatory over time */
  2061. if (!codec->dev)
  2062. printk(KERN_WARNING "No device for codec %s\n", codec->name);
  2063. INIT_LIST_HEAD(&codec->list);
  2064. mutex_lock(&client_mutex);
  2065. list_add(&codec->list, &codec_list);
  2066. snd_soc_instantiate_cards();
  2067. mutex_unlock(&client_mutex);
  2068. pr_debug("Registered codec '%s'\n", codec->name);
  2069. return 0;
  2070. }
  2071. EXPORT_SYMBOL_GPL(snd_soc_register_codec);
  2072. /**
  2073. * snd_soc_unregister_codec - Unregister a codec from the ASoC core
  2074. *
  2075. * @codec: codec to unregister
  2076. */
  2077. void snd_soc_unregister_codec(struct snd_soc_codec *codec)
  2078. {
  2079. mutex_lock(&client_mutex);
  2080. list_del(&codec->list);
  2081. mutex_unlock(&client_mutex);
  2082. pr_debug("Unregistered codec '%s'\n", codec->name);
  2083. }
  2084. EXPORT_SYMBOL_GPL(snd_soc_unregister_codec);
  2085. static int __init snd_soc_init(void)
  2086. {
  2087. #ifdef CONFIG_DEBUG_FS
  2088. debugfs_root = debugfs_create_dir("asoc", NULL);
  2089. if (IS_ERR(debugfs_root) || !debugfs_root) {
  2090. printk(KERN_WARNING
  2091. "ASoC: Failed to create debugfs directory\n");
  2092. debugfs_root = NULL;
  2093. }
  2094. #endif
  2095. return platform_driver_register(&soc_driver);
  2096. }
  2097. static void __exit snd_soc_exit(void)
  2098. {
  2099. #ifdef CONFIG_DEBUG_FS
  2100. debugfs_remove_recursive(debugfs_root);
  2101. #endif
  2102. platform_driver_unregister(&soc_driver);
  2103. }
  2104. module_init(snd_soc_init);
  2105. module_exit(snd_soc_exit);
  2106. /* Module information */
  2107. MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
  2108. MODULE_DESCRIPTION("ALSA SoC Core");
  2109. MODULE_LICENSE("GPL");
  2110. MODULE_ALIAS("platform:soc-audio");