soc-core.c 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439
  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 = NULL;
  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. socdev->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 = socdev->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 = socdev->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 = socdev->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 = socdev->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 = socdev->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 = socdev->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. dev_dbg(socdev->dev, "scheduling resume work\n");
  662. if (!schedule_work(&card->deferred_resume_work))
  663. dev_err(socdev->dev, "resume work item may be lost\n");
  664. return 0;
  665. }
  666. #else
  667. #define soc_suspend NULL
  668. #define soc_resume NULL
  669. #endif
  670. static void snd_soc_instantiate_card(struct snd_soc_card *card)
  671. {
  672. struct platform_device *pdev = container_of(card->dev,
  673. struct platform_device,
  674. dev);
  675. struct snd_soc_codec_device *codec_dev = card->socdev->codec_dev;
  676. struct snd_soc_platform *platform;
  677. struct snd_soc_dai *dai;
  678. int i, found, ret, ac97;
  679. if (card->instantiated)
  680. return;
  681. found = 0;
  682. list_for_each_entry(platform, &platform_list, list)
  683. if (card->platform == platform) {
  684. found = 1;
  685. break;
  686. }
  687. if (!found) {
  688. dev_dbg(card->dev, "Platform %s not registered\n",
  689. card->platform->name);
  690. return;
  691. }
  692. ac97 = 0;
  693. for (i = 0; i < card->num_links; i++) {
  694. found = 0;
  695. list_for_each_entry(dai, &dai_list, list)
  696. if (card->dai_link[i].cpu_dai == dai) {
  697. found = 1;
  698. break;
  699. }
  700. if (!found) {
  701. dev_dbg(card->dev, "DAI %s not registered\n",
  702. card->dai_link[i].cpu_dai->name);
  703. return;
  704. }
  705. if (card->dai_link[i].cpu_dai->ac97_control)
  706. ac97 = 1;
  707. }
  708. /* If we have AC97 in the system then don't wait for the
  709. * codec. This will need revisiting if we have to handle
  710. * systems with mixed AC97 and non-AC97 parts. Only check for
  711. * DAIs currently; we can't do this per link since some AC97
  712. * codecs have non-AC97 DAIs.
  713. */
  714. if (!ac97)
  715. for (i = 0; i < card->num_links; i++) {
  716. found = 0;
  717. list_for_each_entry(dai, &dai_list, list)
  718. if (card->dai_link[i].codec_dai == dai) {
  719. found = 1;
  720. break;
  721. }
  722. if (!found) {
  723. dev_dbg(card->dev, "DAI %s not registered\n",
  724. card->dai_link[i].codec_dai->name);
  725. return;
  726. }
  727. }
  728. /* Note that we do not current check for codec components */
  729. dev_dbg(card->dev, "All components present, instantiating\n");
  730. /* Found everything, bring it up */
  731. if (card->probe) {
  732. ret = card->probe(pdev);
  733. if (ret < 0)
  734. return;
  735. }
  736. for (i = 0; i < card->num_links; i++) {
  737. struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai;
  738. if (cpu_dai->probe) {
  739. ret = cpu_dai->probe(pdev, cpu_dai);
  740. if (ret < 0)
  741. goto cpu_dai_err;
  742. }
  743. }
  744. if (codec_dev->probe) {
  745. ret = codec_dev->probe(pdev);
  746. if (ret < 0)
  747. goto cpu_dai_err;
  748. }
  749. if (platform->probe) {
  750. ret = platform->probe(pdev);
  751. if (ret < 0)
  752. goto platform_err;
  753. }
  754. /* DAPM stream work */
  755. INIT_DELAYED_WORK(&card->delayed_work, close_delayed_work);
  756. #ifdef CONFIG_PM
  757. /* deferred resume work */
  758. INIT_WORK(&card->deferred_resume_work, soc_resume_deferred);
  759. #endif
  760. card->instantiated = 1;
  761. return;
  762. platform_err:
  763. if (codec_dev->remove)
  764. codec_dev->remove(pdev);
  765. cpu_dai_err:
  766. for (i--; i >= 0; i--) {
  767. struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai;
  768. if (cpu_dai->remove)
  769. cpu_dai->remove(pdev, cpu_dai);
  770. }
  771. if (card->remove)
  772. card->remove(pdev);
  773. }
  774. /*
  775. * Attempt to initialise any uninitalised cards. Must be called with
  776. * client_mutex.
  777. */
  778. static void snd_soc_instantiate_cards(void)
  779. {
  780. struct snd_soc_card *card;
  781. list_for_each_entry(card, &card_list, list)
  782. snd_soc_instantiate_card(card);
  783. }
  784. /* probes a new socdev */
  785. static int soc_probe(struct platform_device *pdev)
  786. {
  787. int ret = 0;
  788. struct snd_soc_device *socdev = platform_get_drvdata(pdev);
  789. struct snd_soc_card *card = socdev->card;
  790. /* Bodge while we push things out of socdev */
  791. card->socdev = socdev;
  792. /* Bodge while we unpick instantiation */
  793. card->dev = &pdev->dev;
  794. ret = snd_soc_register_card(card);
  795. if (ret != 0) {
  796. dev_err(&pdev->dev, "Failed to register card\n");
  797. return ret;
  798. }
  799. return 0;
  800. }
  801. /* removes a socdev */
  802. static int soc_remove(struct platform_device *pdev)
  803. {
  804. int i;
  805. struct snd_soc_device *socdev = platform_get_drvdata(pdev);
  806. struct snd_soc_card *card = socdev->card;
  807. struct snd_soc_platform *platform = card->platform;
  808. struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
  809. run_delayed_work(&card->delayed_work);
  810. if (platform->remove)
  811. platform->remove(pdev);
  812. if (codec_dev->remove)
  813. codec_dev->remove(pdev);
  814. for (i = 0; i < card->num_links; i++) {
  815. struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai;
  816. if (cpu_dai->remove)
  817. cpu_dai->remove(pdev, cpu_dai);
  818. }
  819. if (card->remove)
  820. card->remove(pdev);
  821. snd_soc_unregister_card(card);
  822. return 0;
  823. }
  824. /* ASoC platform driver */
  825. static struct platform_driver soc_driver = {
  826. .driver = {
  827. .name = "soc-audio",
  828. .owner = THIS_MODULE,
  829. },
  830. .probe = soc_probe,
  831. .remove = soc_remove,
  832. .suspend = soc_suspend,
  833. .resume = soc_resume,
  834. };
  835. /* create a new pcm */
  836. static int soc_new_pcm(struct snd_soc_device *socdev,
  837. struct snd_soc_dai_link *dai_link, int num)
  838. {
  839. struct snd_soc_codec *codec = socdev->codec;
  840. struct snd_soc_card *card = socdev->card;
  841. struct snd_soc_platform *platform = card->platform;
  842. struct snd_soc_dai *codec_dai = dai_link->codec_dai;
  843. struct snd_soc_dai *cpu_dai = dai_link->cpu_dai;
  844. struct snd_soc_pcm_runtime *rtd;
  845. struct snd_pcm *pcm;
  846. char new_name[64];
  847. int ret = 0, playback = 0, capture = 0;
  848. rtd = kzalloc(sizeof(struct snd_soc_pcm_runtime), GFP_KERNEL);
  849. if (rtd == NULL)
  850. return -ENOMEM;
  851. rtd->dai = dai_link;
  852. rtd->socdev = socdev;
  853. codec_dai->codec = socdev->codec;
  854. /* check client and interface hw capabilities */
  855. sprintf(new_name, "%s %s-%d", dai_link->stream_name, codec_dai->name,
  856. num);
  857. if (codec_dai->playback.channels_min)
  858. playback = 1;
  859. if (codec_dai->capture.channels_min)
  860. capture = 1;
  861. ret = snd_pcm_new(codec->card, new_name, codec->pcm_devs++, playback,
  862. capture, &pcm);
  863. if (ret < 0) {
  864. printk(KERN_ERR "asoc: can't create pcm for codec %s\n",
  865. codec->name);
  866. kfree(rtd);
  867. return ret;
  868. }
  869. dai_link->pcm = pcm;
  870. pcm->private_data = rtd;
  871. soc_pcm_ops.mmap = platform->pcm_ops->mmap;
  872. soc_pcm_ops.pointer = platform->pcm_ops->pointer;
  873. soc_pcm_ops.ioctl = platform->pcm_ops->ioctl;
  874. soc_pcm_ops.copy = platform->pcm_ops->copy;
  875. soc_pcm_ops.silence = platform->pcm_ops->silence;
  876. soc_pcm_ops.ack = platform->pcm_ops->ack;
  877. soc_pcm_ops.page = platform->pcm_ops->page;
  878. if (playback)
  879. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &soc_pcm_ops);
  880. if (capture)
  881. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &soc_pcm_ops);
  882. ret = platform->pcm_new(codec->card, codec_dai, pcm);
  883. if (ret < 0) {
  884. printk(KERN_ERR "asoc: platform pcm constructor failed\n");
  885. kfree(rtd);
  886. return ret;
  887. }
  888. pcm->private_free = platform->pcm_free;
  889. printk(KERN_INFO "asoc: %s <-> %s mapping ok\n", codec_dai->name,
  890. cpu_dai->name);
  891. return ret;
  892. }
  893. /* codec register dump */
  894. static ssize_t soc_codec_reg_show(struct snd_soc_device *devdata, char *buf)
  895. {
  896. struct snd_soc_codec *codec = devdata->codec;
  897. int i, step = 1, count = 0;
  898. if (!codec->reg_cache_size)
  899. return 0;
  900. if (codec->reg_cache_step)
  901. step = codec->reg_cache_step;
  902. count += sprintf(buf, "%s registers\n", codec->name);
  903. for (i = 0; i < codec->reg_cache_size; i += step) {
  904. count += sprintf(buf + count, "%2x: ", i);
  905. if (count >= PAGE_SIZE - 1)
  906. break;
  907. if (codec->display_register)
  908. count += codec->display_register(codec, buf + count,
  909. PAGE_SIZE - count, i);
  910. else
  911. count += snprintf(buf + count, PAGE_SIZE - count,
  912. "%4x", codec->read(codec, i));
  913. if (count >= PAGE_SIZE - 1)
  914. break;
  915. count += snprintf(buf + count, PAGE_SIZE - count, "\n");
  916. if (count >= PAGE_SIZE - 1)
  917. break;
  918. }
  919. /* Truncate count; min() would cause a warning */
  920. if (count >= PAGE_SIZE)
  921. count = PAGE_SIZE - 1;
  922. return count;
  923. }
  924. static ssize_t codec_reg_show(struct device *dev,
  925. struct device_attribute *attr, char *buf)
  926. {
  927. struct snd_soc_device *devdata = dev_get_drvdata(dev);
  928. return soc_codec_reg_show(devdata, buf);
  929. }
  930. static DEVICE_ATTR(codec_reg, 0444, codec_reg_show, NULL);
  931. #ifdef CONFIG_DEBUG_FS
  932. static int codec_reg_open_file(struct inode *inode, struct file *file)
  933. {
  934. file->private_data = inode->i_private;
  935. return 0;
  936. }
  937. static ssize_t codec_reg_read_file(struct file *file, char __user *user_buf,
  938. size_t count, loff_t *ppos)
  939. {
  940. ssize_t ret;
  941. struct snd_soc_codec *codec = file->private_data;
  942. struct device *card_dev = codec->card->dev;
  943. struct snd_soc_device *devdata = card_dev->driver_data;
  944. char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
  945. if (!buf)
  946. return -ENOMEM;
  947. ret = soc_codec_reg_show(devdata, buf);
  948. if (ret >= 0)
  949. ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
  950. kfree(buf);
  951. return ret;
  952. }
  953. static ssize_t codec_reg_write_file(struct file *file,
  954. const char __user *user_buf, size_t count, loff_t *ppos)
  955. {
  956. char buf[32];
  957. int buf_size;
  958. char *start = buf;
  959. unsigned long reg, value;
  960. int step = 1;
  961. struct snd_soc_codec *codec = file->private_data;
  962. buf_size = min(count, (sizeof(buf)-1));
  963. if (copy_from_user(buf, user_buf, buf_size))
  964. return -EFAULT;
  965. buf[buf_size] = 0;
  966. if (codec->reg_cache_step)
  967. step = codec->reg_cache_step;
  968. while (*start == ' ')
  969. start++;
  970. reg = simple_strtoul(start, &start, 16);
  971. if ((reg >= codec->reg_cache_size) || (reg % step))
  972. return -EINVAL;
  973. while (*start == ' ')
  974. start++;
  975. if (strict_strtoul(start, 16, &value))
  976. return -EINVAL;
  977. codec->write(codec, reg, value);
  978. return buf_size;
  979. }
  980. static const struct file_operations codec_reg_fops = {
  981. .open = codec_reg_open_file,
  982. .read = codec_reg_read_file,
  983. .write = codec_reg_write_file,
  984. };
  985. static void soc_init_codec_debugfs(struct snd_soc_codec *codec)
  986. {
  987. codec->debugfs_reg = debugfs_create_file("codec_reg", 0644,
  988. debugfs_root, codec,
  989. &codec_reg_fops);
  990. if (!codec->debugfs_reg)
  991. printk(KERN_WARNING
  992. "ASoC: Failed to create codec register debugfs file\n");
  993. codec->debugfs_pop_time = debugfs_create_u32("dapm_pop_time", 0744,
  994. debugfs_root,
  995. &codec->pop_time);
  996. if (!codec->debugfs_pop_time)
  997. printk(KERN_WARNING
  998. "Failed to create pop time debugfs file\n");
  999. }
  1000. static void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec)
  1001. {
  1002. debugfs_remove(codec->debugfs_pop_time);
  1003. debugfs_remove(codec->debugfs_reg);
  1004. }
  1005. #else
  1006. static inline void soc_init_codec_debugfs(struct snd_soc_codec *codec)
  1007. {
  1008. }
  1009. static inline void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec)
  1010. {
  1011. }
  1012. #endif
  1013. /**
  1014. * snd_soc_new_ac97_codec - initailise AC97 device
  1015. * @codec: audio codec
  1016. * @ops: AC97 bus operations
  1017. * @num: AC97 codec number
  1018. *
  1019. * Initialises AC97 codec resources for use by ad-hoc devices only.
  1020. */
  1021. int snd_soc_new_ac97_codec(struct snd_soc_codec *codec,
  1022. struct snd_ac97_bus_ops *ops, int num)
  1023. {
  1024. mutex_lock(&codec->mutex);
  1025. codec->ac97 = kzalloc(sizeof(struct snd_ac97), GFP_KERNEL);
  1026. if (codec->ac97 == NULL) {
  1027. mutex_unlock(&codec->mutex);
  1028. return -ENOMEM;
  1029. }
  1030. codec->ac97->bus = kzalloc(sizeof(struct snd_ac97_bus), GFP_KERNEL);
  1031. if (codec->ac97->bus == NULL) {
  1032. kfree(codec->ac97);
  1033. codec->ac97 = NULL;
  1034. mutex_unlock(&codec->mutex);
  1035. return -ENOMEM;
  1036. }
  1037. codec->ac97->bus->ops = ops;
  1038. codec->ac97->num = num;
  1039. mutex_unlock(&codec->mutex);
  1040. return 0;
  1041. }
  1042. EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec);
  1043. /**
  1044. * snd_soc_free_ac97_codec - free AC97 codec device
  1045. * @codec: audio codec
  1046. *
  1047. * Frees AC97 codec device resources.
  1048. */
  1049. void snd_soc_free_ac97_codec(struct snd_soc_codec *codec)
  1050. {
  1051. mutex_lock(&codec->mutex);
  1052. kfree(codec->ac97->bus);
  1053. kfree(codec->ac97);
  1054. codec->ac97 = NULL;
  1055. mutex_unlock(&codec->mutex);
  1056. }
  1057. EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec);
  1058. /**
  1059. * snd_soc_update_bits - update codec register bits
  1060. * @codec: audio codec
  1061. * @reg: codec register
  1062. * @mask: register mask
  1063. * @value: new value
  1064. *
  1065. * Writes new register value.
  1066. *
  1067. * Returns 1 for change else 0.
  1068. */
  1069. int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg,
  1070. unsigned short mask, unsigned short value)
  1071. {
  1072. int change;
  1073. unsigned short old, new;
  1074. mutex_lock(&io_mutex);
  1075. old = snd_soc_read(codec, reg);
  1076. new = (old & ~mask) | value;
  1077. change = old != new;
  1078. if (change)
  1079. snd_soc_write(codec, reg, new);
  1080. mutex_unlock(&io_mutex);
  1081. return change;
  1082. }
  1083. EXPORT_SYMBOL_GPL(snd_soc_update_bits);
  1084. /**
  1085. * snd_soc_test_bits - test register for change
  1086. * @codec: audio codec
  1087. * @reg: codec register
  1088. * @mask: register mask
  1089. * @value: new value
  1090. *
  1091. * Tests a register with a new value and checks if the new value is
  1092. * different from the old value.
  1093. *
  1094. * Returns 1 for change else 0.
  1095. */
  1096. int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned short reg,
  1097. unsigned short mask, unsigned short value)
  1098. {
  1099. int change;
  1100. unsigned short old, new;
  1101. mutex_lock(&io_mutex);
  1102. old = snd_soc_read(codec, reg);
  1103. new = (old & ~mask) | value;
  1104. change = old != new;
  1105. mutex_unlock(&io_mutex);
  1106. return change;
  1107. }
  1108. EXPORT_SYMBOL_GPL(snd_soc_test_bits);
  1109. /**
  1110. * snd_soc_new_pcms - create new sound card and pcms
  1111. * @socdev: the SoC audio device
  1112. * @idx: ALSA card index
  1113. * @xid: card identification
  1114. *
  1115. * Create a new sound card based upon the codec and interface pcms.
  1116. *
  1117. * Returns 0 for success, else error.
  1118. */
  1119. int snd_soc_new_pcms(struct snd_soc_device *socdev, int idx, const char *xid)
  1120. {
  1121. struct snd_soc_codec *codec = socdev->codec;
  1122. struct snd_soc_card *card = socdev->card;
  1123. int ret = 0, i;
  1124. mutex_lock(&codec->mutex);
  1125. /* register a sound card */
  1126. codec->card = snd_card_new(idx, xid, codec->owner, 0);
  1127. if (!codec->card) {
  1128. printk(KERN_ERR "asoc: can't create sound card for codec %s\n",
  1129. codec->name);
  1130. mutex_unlock(&codec->mutex);
  1131. return -ENODEV;
  1132. }
  1133. codec->card->dev = socdev->dev;
  1134. codec->card->private_data = codec;
  1135. strncpy(codec->card->driver, codec->name, sizeof(codec->card->driver));
  1136. /* create the pcms */
  1137. for (i = 0; i < card->num_links; i++) {
  1138. ret = soc_new_pcm(socdev, &card->dai_link[i], i);
  1139. if (ret < 0) {
  1140. printk(KERN_ERR "asoc: can't create pcm %s\n",
  1141. card->dai_link[i].stream_name);
  1142. mutex_unlock(&codec->mutex);
  1143. return ret;
  1144. }
  1145. }
  1146. mutex_unlock(&codec->mutex);
  1147. return ret;
  1148. }
  1149. EXPORT_SYMBOL_GPL(snd_soc_new_pcms);
  1150. /**
  1151. * snd_soc_init_card - register sound card
  1152. * @socdev: the SoC audio device
  1153. *
  1154. * Register a SoC sound card. Also registers an AC97 device if the
  1155. * codec is AC97 for ad hoc devices.
  1156. *
  1157. * Returns 0 for success, else error.
  1158. */
  1159. int snd_soc_init_card(struct snd_soc_device *socdev)
  1160. {
  1161. struct snd_soc_codec *codec = socdev->codec;
  1162. struct snd_soc_card *card = socdev->card;
  1163. int ret = 0, i, ac97 = 0, err = 0;
  1164. for (i = 0; i < card->num_links; i++) {
  1165. if (card->dai_link[i].init) {
  1166. err = card->dai_link[i].init(codec);
  1167. if (err < 0) {
  1168. printk(KERN_ERR "asoc: failed to init %s\n",
  1169. card->dai_link[i].stream_name);
  1170. continue;
  1171. }
  1172. }
  1173. if (card->dai_link[i].codec_dai->ac97_control)
  1174. ac97 = 1;
  1175. }
  1176. snprintf(codec->card->shortname, sizeof(codec->card->shortname),
  1177. "%s", card->name);
  1178. snprintf(codec->card->longname, sizeof(codec->card->longname),
  1179. "%s (%s)", card->name, codec->name);
  1180. ret = snd_card_register(codec->card);
  1181. if (ret < 0) {
  1182. printk(KERN_ERR "asoc: failed to register soundcard for %s\n",
  1183. codec->name);
  1184. goto out;
  1185. }
  1186. mutex_lock(&codec->mutex);
  1187. #ifdef CONFIG_SND_SOC_AC97_BUS
  1188. if (ac97) {
  1189. ret = soc_ac97_dev_register(codec);
  1190. if (ret < 0) {
  1191. printk(KERN_ERR "asoc: AC97 device register failed\n");
  1192. snd_card_free(codec->card);
  1193. mutex_unlock(&codec->mutex);
  1194. goto out;
  1195. }
  1196. }
  1197. #endif
  1198. err = snd_soc_dapm_sys_add(socdev->dev);
  1199. if (err < 0)
  1200. printk(KERN_WARNING "asoc: failed to add dapm sysfs entries\n");
  1201. err = device_create_file(socdev->dev, &dev_attr_codec_reg);
  1202. if (err < 0)
  1203. printk(KERN_WARNING "asoc: failed to add codec sysfs files\n");
  1204. soc_init_codec_debugfs(socdev->codec);
  1205. mutex_unlock(&codec->mutex);
  1206. out:
  1207. return ret;
  1208. }
  1209. EXPORT_SYMBOL_GPL(snd_soc_init_card);
  1210. /**
  1211. * snd_soc_free_pcms - free sound card and pcms
  1212. * @socdev: the SoC audio device
  1213. *
  1214. * Frees sound card and pcms associated with the socdev.
  1215. * Also unregister the codec if it is an AC97 device.
  1216. */
  1217. void snd_soc_free_pcms(struct snd_soc_device *socdev)
  1218. {
  1219. struct snd_soc_codec *codec = socdev->codec;
  1220. #ifdef CONFIG_SND_SOC_AC97_BUS
  1221. struct snd_soc_dai *codec_dai;
  1222. int i;
  1223. #endif
  1224. mutex_lock(&codec->mutex);
  1225. soc_cleanup_codec_debugfs(socdev->codec);
  1226. #ifdef CONFIG_SND_SOC_AC97_BUS
  1227. for (i = 0; i < codec->num_dai; i++) {
  1228. codec_dai = &codec->dai[i];
  1229. if (codec_dai->ac97_control && codec->ac97) {
  1230. soc_ac97_dev_unregister(codec);
  1231. goto free_card;
  1232. }
  1233. }
  1234. free_card:
  1235. #endif
  1236. if (codec->card)
  1237. snd_card_free(codec->card);
  1238. device_remove_file(socdev->dev, &dev_attr_codec_reg);
  1239. mutex_unlock(&codec->mutex);
  1240. }
  1241. EXPORT_SYMBOL_GPL(snd_soc_free_pcms);
  1242. /**
  1243. * snd_soc_set_runtime_hwparams - set the runtime hardware parameters
  1244. * @substream: the pcm substream
  1245. * @hw: the hardware parameters
  1246. *
  1247. * Sets the substream runtime hardware parameters.
  1248. */
  1249. int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
  1250. const struct snd_pcm_hardware *hw)
  1251. {
  1252. struct snd_pcm_runtime *runtime = substream->runtime;
  1253. runtime->hw.info = hw->info;
  1254. runtime->hw.formats = hw->formats;
  1255. runtime->hw.period_bytes_min = hw->period_bytes_min;
  1256. runtime->hw.period_bytes_max = hw->period_bytes_max;
  1257. runtime->hw.periods_min = hw->periods_min;
  1258. runtime->hw.periods_max = hw->periods_max;
  1259. runtime->hw.buffer_bytes_max = hw->buffer_bytes_max;
  1260. runtime->hw.fifo_size = hw->fifo_size;
  1261. return 0;
  1262. }
  1263. EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hwparams);
  1264. /**
  1265. * snd_soc_cnew - create new control
  1266. * @_template: control template
  1267. * @data: control private data
  1268. * @long_name: control long name
  1269. *
  1270. * Create a new mixer control from a template control.
  1271. *
  1272. * Returns 0 for success, else error.
  1273. */
  1274. struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
  1275. void *data, char *long_name)
  1276. {
  1277. struct snd_kcontrol_new template;
  1278. memcpy(&template, _template, sizeof(template));
  1279. if (long_name)
  1280. template.name = long_name;
  1281. template.index = 0;
  1282. return snd_ctl_new1(&template, data);
  1283. }
  1284. EXPORT_SYMBOL_GPL(snd_soc_cnew);
  1285. /**
  1286. * snd_soc_add_controls - add an array of controls to a codec.
  1287. * Convienience function to add a list of controls. Many codecs were
  1288. * duplicating this code.
  1289. *
  1290. * @codec: codec to add controls to
  1291. * @controls: array of controls to add
  1292. * @num_controls: number of elements in the array
  1293. *
  1294. * Return 0 for success, else error.
  1295. */
  1296. int snd_soc_add_controls(struct snd_soc_codec *codec,
  1297. const struct snd_kcontrol_new *controls, int num_controls)
  1298. {
  1299. struct snd_card *card = codec->card;
  1300. int err, i;
  1301. for (i = 0; i < num_controls; i++) {
  1302. const struct snd_kcontrol_new *control = &controls[i];
  1303. err = snd_ctl_add(card, snd_soc_cnew(control, codec, NULL));
  1304. if (err < 0) {
  1305. dev_err(codec->dev, "%s: Failed to add %s\n",
  1306. codec->name, control->name);
  1307. return err;
  1308. }
  1309. }
  1310. return 0;
  1311. }
  1312. EXPORT_SYMBOL_GPL(snd_soc_add_controls);
  1313. /**
  1314. * snd_soc_info_enum_double - enumerated double mixer info callback
  1315. * @kcontrol: mixer control
  1316. * @uinfo: control element information
  1317. *
  1318. * Callback to provide information about a double enumerated
  1319. * mixer control.
  1320. *
  1321. * Returns 0 for success.
  1322. */
  1323. int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
  1324. struct snd_ctl_elem_info *uinfo)
  1325. {
  1326. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  1327. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  1328. uinfo->count = e->shift_l == e->shift_r ? 1 : 2;
  1329. uinfo->value.enumerated.items = e->max;
  1330. if (uinfo->value.enumerated.item > e->max - 1)
  1331. uinfo->value.enumerated.item = e->max - 1;
  1332. strcpy(uinfo->value.enumerated.name,
  1333. e->texts[uinfo->value.enumerated.item]);
  1334. return 0;
  1335. }
  1336. EXPORT_SYMBOL_GPL(snd_soc_info_enum_double);
  1337. /**
  1338. * snd_soc_get_enum_double - enumerated double mixer get callback
  1339. * @kcontrol: mixer control
  1340. * @ucontrol: control element information
  1341. *
  1342. * Callback to get the value of a double enumerated mixer.
  1343. *
  1344. * Returns 0 for success.
  1345. */
  1346. int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
  1347. struct snd_ctl_elem_value *ucontrol)
  1348. {
  1349. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  1350. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  1351. unsigned short val, bitmask;
  1352. for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
  1353. ;
  1354. val = snd_soc_read(codec, e->reg);
  1355. ucontrol->value.enumerated.item[0]
  1356. = (val >> e->shift_l) & (bitmask - 1);
  1357. if (e->shift_l != e->shift_r)
  1358. ucontrol->value.enumerated.item[1] =
  1359. (val >> e->shift_r) & (bitmask - 1);
  1360. return 0;
  1361. }
  1362. EXPORT_SYMBOL_GPL(snd_soc_get_enum_double);
  1363. /**
  1364. * snd_soc_put_enum_double - enumerated double mixer put callback
  1365. * @kcontrol: mixer control
  1366. * @ucontrol: control element information
  1367. *
  1368. * Callback to set the value of a double enumerated mixer.
  1369. *
  1370. * Returns 0 for success.
  1371. */
  1372. int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
  1373. struct snd_ctl_elem_value *ucontrol)
  1374. {
  1375. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  1376. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  1377. unsigned short val;
  1378. unsigned short mask, bitmask;
  1379. for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
  1380. ;
  1381. if (ucontrol->value.enumerated.item[0] > e->max - 1)
  1382. return -EINVAL;
  1383. val = ucontrol->value.enumerated.item[0] << e->shift_l;
  1384. mask = (bitmask - 1) << e->shift_l;
  1385. if (e->shift_l != e->shift_r) {
  1386. if (ucontrol->value.enumerated.item[1] > e->max - 1)
  1387. return -EINVAL;
  1388. val |= ucontrol->value.enumerated.item[1] << e->shift_r;
  1389. mask |= (bitmask - 1) << e->shift_r;
  1390. }
  1391. return snd_soc_update_bits(codec, e->reg, mask, val);
  1392. }
  1393. EXPORT_SYMBOL_GPL(snd_soc_put_enum_double);
  1394. /**
  1395. * snd_soc_info_value_enum_double - semi enumerated double mixer info callback
  1396. * @kcontrol: mixer control
  1397. * @uinfo: control element information
  1398. *
  1399. * Callback to provide information about a double semi enumerated
  1400. * mixer control.
  1401. *
  1402. * Semi enumerated mixer: the enumerated items are referred as values. Can be
  1403. * used for handling bitfield coded enumeration for example.
  1404. *
  1405. * Returns 0 for success.
  1406. */
  1407. int snd_soc_info_value_enum_double(struct snd_kcontrol *kcontrol,
  1408. struct snd_ctl_elem_info *uinfo)
  1409. {
  1410. struct soc_value_enum *e = (struct soc_value_enum *)
  1411. kcontrol->private_value;
  1412. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  1413. uinfo->count = e->shift_l == e->shift_r ? 1 : 2;
  1414. uinfo->value.enumerated.items = e->max;
  1415. if (uinfo->value.enumerated.item > e->max - 1)
  1416. uinfo->value.enumerated.item = e->max - 1;
  1417. strcpy(uinfo->value.enumerated.name,
  1418. e->texts[uinfo->value.enumerated.item]);
  1419. return 0;
  1420. }
  1421. EXPORT_SYMBOL_GPL(snd_soc_info_value_enum_double);
  1422. /**
  1423. * snd_soc_get_value_enum_double - semi enumerated double mixer get callback
  1424. * @kcontrol: mixer control
  1425. * @ucontrol: control element information
  1426. *
  1427. * Callback to get the value of a double semi enumerated mixer.
  1428. *
  1429. * Semi enumerated mixer: the enumerated items are referred as values. Can be
  1430. * used for handling bitfield coded enumeration for example.
  1431. *
  1432. * Returns 0 for success.
  1433. */
  1434. int snd_soc_get_value_enum_double(struct snd_kcontrol *kcontrol,
  1435. struct snd_ctl_elem_value *ucontrol)
  1436. {
  1437. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  1438. struct soc_value_enum *e = (struct soc_value_enum *)
  1439. kcontrol->private_value;
  1440. unsigned short reg_val, val, mux;
  1441. reg_val = snd_soc_read(codec, e->reg);
  1442. val = (reg_val >> e->shift_l) & e->mask;
  1443. for (mux = 0; mux < e->max; mux++) {
  1444. if (val == e->values[mux])
  1445. break;
  1446. }
  1447. ucontrol->value.enumerated.item[0] = mux;
  1448. if (e->shift_l != e->shift_r) {
  1449. val = (reg_val >> e->shift_r) & e->mask;
  1450. for (mux = 0; mux < e->max; mux++) {
  1451. if (val == e->values[mux])
  1452. break;
  1453. }
  1454. ucontrol->value.enumerated.item[1] = mux;
  1455. }
  1456. return 0;
  1457. }
  1458. EXPORT_SYMBOL_GPL(snd_soc_get_value_enum_double);
  1459. /**
  1460. * snd_soc_put_value_enum_double - semi enumerated double mixer put callback
  1461. * @kcontrol: mixer control
  1462. * @ucontrol: control element information
  1463. *
  1464. * Callback to set the value of a double semi enumerated mixer.
  1465. *
  1466. * Semi enumerated mixer: the enumerated items are referred as values. Can be
  1467. * used for handling bitfield coded enumeration for example.
  1468. *
  1469. * Returns 0 for success.
  1470. */
  1471. int snd_soc_put_value_enum_double(struct snd_kcontrol *kcontrol,
  1472. struct snd_ctl_elem_value *ucontrol)
  1473. {
  1474. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  1475. struct soc_value_enum *e = (struct soc_value_enum *)
  1476. kcontrol->private_value;
  1477. unsigned short val;
  1478. unsigned short mask;
  1479. if (ucontrol->value.enumerated.item[0] > e->max - 1)
  1480. return -EINVAL;
  1481. val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l;
  1482. mask = e->mask << e->shift_l;
  1483. if (e->shift_l != e->shift_r) {
  1484. if (ucontrol->value.enumerated.item[1] > e->max - 1)
  1485. return -EINVAL;
  1486. val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r;
  1487. mask |= e->mask << e->shift_r;
  1488. }
  1489. return snd_soc_update_bits(codec, e->reg, mask, val);
  1490. }
  1491. EXPORT_SYMBOL_GPL(snd_soc_put_value_enum_double);
  1492. /**
  1493. * snd_soc_info_enum_ext - external enumerated single mixer info callback
  1494. * @kcontrol: mixer control
  1495. * @uinfo: control element information
  1496. *
  1497. * Callback to provide information about an external enumerated
  1498. * single mixer.
  1499. *
  1500. * Returns 0 for success.
  1501. */
  1502. int snd_soc_info_enum_ext(struct snd_kcontrol *kcontrol,
  1503. struct snd_ctl_elem_info *uinfo)
  1504. {
  1505. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  1506. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  1507. uinfo->count = 1;
  1508. uinfo->value.enumerated.items = e->max;
  1509. if (uinfo->value.enumerated.item > e->max - 1)
  1510. uinfo->value.enumerated.item = e->max - 1;
  1511. strcpy(uinfo->value.enumerated.name,
  1512. e->texts[uinfo->value.enumerated.item]);
  1513. return 0;
  1514. }
  1515. EXPORT_SYMBOL_GPL(snd_soc_info_enum_ext);
  1516. /**
  1517. * snd_soc_info_volsw_ext - external single mixer info callback
  1518. * @kcontrol: mixer control
  1519. * @uinfo: control element information
  1520. *
  1521. * Callback to provide information about a single external mixer control.
  1522. *
  1523. * Returns 0 for success.
  1524. */
  1525. int snd_soc_info_volsw_ext(struct snd_kcontrol *kcontrol,
  1526. struct snd_ctl_elem_info *uinfo)
  1527. {
  1528. int max = kcontrol->private_value;
  1529. if (max == 1)
  1530. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  1531. else
  1532. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  1533. uinfo->count = 1;
  1534. uinfo->value.integer.min = 0;
  1535. uinfo->value.integer.max = max;
  1536. return 0;
  1537. }
  1538. EXPORT_SYMBOL_GPL(snd_soc_info_volsw_ext);
  1539. /**
  1540. * snd_soc_info_volsw - single mixer info callback
  1541. * @kcontrol: mixer control
  1542. * @uinfo: control element information
  1543. *
  1544. * Callback to provide information about a single mixer control.
  1545. *
  1546. * Returns 0 for success.
  1547. */
  1548. int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
  1549. struct snd_ctl_elem_info *uinfo)
  1550. {
  1551. struct soc_mixer_control *mc =
  1552. (struct soc_mixer_control *)kcontrol->private_value;
  1553. int max = mc->max;
  1554. unsigned int shift = mc->shift;
  1555. unsigned int rshift = mc->rshift;
  1556. if (max == 1)
  1557. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  1558. else
  1559. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  1560. uinfo->count = shift == rshift ? 1 : 2;
  1561. uinfo->value.integer.min = 0;
  1562. uinfo->value.integer.max = max;
  1563. return 0;
  1564. }
  1565. EXPORT_SYMBOL_GPL(snd_soc_info_volsw);
  1566. /**
  1567. * snd_soc_get_volsw - single mixer get callback
  1568. * @kcontrol: mixer control
  1569. * @ucontrol: control element information
  1570. *
  1571. * Callback to get the value of a single mixer control.
  1572. *
  1573. * Returns 0 for success.
  1574. */
  1575. int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
  1576. struct snd_ctl_elem_value *ucontrol)
  1577. {
  1578. struct soc_mixer_control *mc =
  1579. (struct soc_mixer_control *)kcontrol->private_value;
  1580. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  1581. unsigned int reg = mc->reg;
  1582. unsigned int shift = mc->shift;
  1583. unsigned int rshift = mc->rshift;
  1584. int max = mc->max;
  1585. unsigned int mask = (1 << fls(max)) - 1;
  1586. unsigned int invert = mc->invert;
  1587. ucontrol->value.integer.value[0] =
  1588. (snd_soc_read(codec, reg) >> shift) & mask;
  1589. if (shift != rshift)
  1590. ucontrol->value.integer.value[1] =
  1591. (snd_soc_read(codec, reg) >> rshift) & mask;
  1592. if (invert) {
  1593. ucontrol->value.integer.value[0] =
  1594. max - ucontrol->value.integer.value[0];
  1595. if (shift != rshift)
  1596. ucontrol->value.integer.value[1] =
  1597. max - ucontrol->value.integer.value[1];
  1598. }
  1599. return 0;
  1600. }
  1601. EXPORT_SYMBOL_GPL(snd_soc_get_volsw);
  1602. /**
  1603. * snd_soc_put_volsw - single mixer put callback
  1604. * @kcontrol: mixer control
  1605. * @ucontrol: control element information
  1606. *
  1607. * Callback to set the value of a single mixer control.
  1608. *
  1609. * Returns 0 for success.
  1610. */
  1611. int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
  1612. struct snd_ctl_elem_value *ucontrol)
  1613. {
  1614. struct soc_mixer_control *mc =
  1615. (struct soc_mixer_control *)kcontrol->private_value;
  1616. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  1617. unsigned int reg = mc->reg;
  1618. unsigned int shift = mc->shift;
  1619. unsigned int rshift = mc->rshift;
  1620. int max = mc->max;
  1621. unsigned int mask = (1 << fls(max)) - 1;
  1622. unsigned int invert = mc->invert;
  1623. unsigned short val, val2, val_mask;
  1624. val = (ucontrol->value.integer.value[0] & mask);
  1625. if (invert)
  1626. val = max - val;
  1627. val_mask = mask << shift;
  1628. val = val << shift;
  1629. if (shift != rshift) {
  1630. val2 = (ucontrol->value.integer.value[1] & mask);
  1631. if (invert)
  1632. val2 = max - val2;
  1633. val_mask |= mask << rshift;
  1634. val |= val2 << rshift;
  1635. }
  1636. return snd_soc_update_bits(codec, reg, val_mask, val);
  1637. }
  1638. EXPORT_SYMBOL_GPL(snd_soc_put_volsw);
  1639. /**
  1640. * snd_soc_info_volsw_2r - double mixer info callback
  1641. * @kcontrol: mixer control
  1642. * @uinfo: control element information
  1643. *
  1644. * Callback to provide information about a double mixer control that
  1645. * spans 2 codec registers.
  1646. *
  1647. * Returns 0 for success.
  1648. */
  1649. int snd_soc_info_volsw_2r(struct snd_kcontrol *kcontrol,
  1650. struct snd_ctl_elem_info *uinfo)
  1651. {
  1652. struct soc_mixer_control *mc =
  1653. (struct soc_mixer_control *)kcontrol->private_value;
  1654. int max = mc->max;
  1655. if (max == 1)
  1656. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  1657. else
  1658. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  1659. uinfo->count = 2;
  1660. uinfo->value.integer.min = 0;
  1661. uinfo->value.integer.max = max;
  1662. return 0;
  1663. }
  1664. EXPORT_SYMBOL_GPL(snd_soc_info_volsw_2r);
  1665. /**
  1666. * snd_soc_get_volsw_2r - double mixer get callback
  1667. * @kcontrol: mixer control
  1668. * @ucontrol: control element information
  1669. *
  1670. * Callback to get the value of a double mixer control that spans 2 registers.
  1671. *
  1672. * Returns 0 for success.
  1673. */
  1674. int snd_soc_get_volsw_2r(struct snd_kcontrol *kcontrol,
  1675. struct snd_ctl_elem_value *ucontrol)
  1676. {
  1677. struct soc_mixer_control *mc =
  1678. (struct soc_mixer_control *)kcontrol->private_value;
  1679. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  1680. unsigned int reg = mc->reg;
  1681. unsigned int reg2 = mc->rreg;
  1682. unsigned int shift = mc->shift;
  1683. int max = mc->max;
  1684. unsigned int mask = (1<<fls(max))-1;
  1685. unsigned int invert = mc->invert;
  1686. ucontrol->value.integer.value[0] =
  1687. (snd_soc_read(codec, reg) >> shift) & mask;
  1688. ucontrol->value.integer.value[1] =
  1689. (snd_soc_read(codec, reg2) >> shift) & mask;
  1690. if (invert) {
  1691. ucontrol->value.integer.value[0] =
  1692. max - ucontrol->value.integer.value[0];
  1693. ucontrol->value.integer.value[1] =
  1694. max - ucontrol->value.integer.value[1];
  1695. }
  1696. return 0;
  1697. }
  1698. EXPORT_SYMBOL_GPL(snd_soc_get_volsw_2r);
  1699. /**
  1700. * snd_soc_put_volsw_2r - double mixer set callback
  1701. * @kcontrol: mixer control
  1702. * @ucontrol: control element information
  1703. *
  1704. * Callback to set the value of a double mixer control that spans 2 registers.
  1705. *
  1706. * Returns 0 for success.
  1707. */
  1708. int snd_soc_put_volsw_2r(struct snd_kcontrol *kcontrol,
  1709. struct snd_ctl_elem_value *ucontrol)
  1710. {
  1711. struct soc_mixer_control *mc =
  1712. (struct soc_mixer_control *)kcontrol->private_value;
  1713. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  1714. unsigned int reg = mc->reg;
  1715. unsigned int reg2 = mc->rreg;
  1716. unsigned int shift = mc->shift;
  1717. int max = mc->max;
  1718. unsigned int mask = (1 << fls(max)) - 1;
  1719. unsigned int invert = mc->invert;
  1720. int err;
  1721. unsigned short val, val2, val_mask;
  1722. val_mask = mask << shift;
  1723. val = (ucontrol->value.integer.value[0] & mask);
  1724. val2 = (ucontrol->value.integer.value[1] & mask);
  1725. if (invert) {
  1726. val = max - val;
  1727. val2 = max - val2;
  1728. }
  1729. val = val << shift;
  1730. val2 = val2 << shift;
  1731. err = snd_soc_update_bits(codec, reg, val_mask, val);
  1732. if (err < 0)
  1733. return err;
  1734. err = snd_soc_update_bits(codec, reg2, val_mask, val2);
  1735. return err;
  1736. }
  1737. EXPORT_SYMBOL_GPL(snd_soc_put_volsw_2r);
  1738. /**
  1739. * snd_soc_info_volsw_s8 - signed mixer info callback
  1740. * @kcontrol: mixer control
  1741. * @uinfo: control element information
  1742. *
  1743. * Callback to provide information about a signed mixer control.
  1744. *
  1745. * Returns 0 for success.
  1746. */
  1747. int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol,
  1748. struct snd_ctl_elem_info *uinfo)
  1749. {
  1750. struct soc_mixer_control *mc =
  1751. (struct soc_mixer_control *)kcontrol->private_value;
  1752. int max = mc->max;
  1753. int min = mc->min;
  1754. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  1755. uinfo->count = 2;
  1756. uinfo->value.integer.min = 0;
  1757. uinfo->value.integer.max = max-min;
  1758. return 0;
  1759. }
  1760. EXPORT_SYMBOL_GPL(snd_soc_info_volsw_s8);
  1761. /**
  1762. * snd_soc_get_volsw_s8 - signed mixer get callback
  1763. * @kcontrol: mixer control
  1764. * @ucontrol: control element information
  1765. *
  1766. * Callback to get the value of a signed mixer control.
  1767. *
  1768. * Returns 0 for success.
  1769. */
  1770. int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol,
  1771. struct snd_ctl_elem_value *ucontrol)
  1772. {
  1773. struct soc_mixer_control *mc =
  1774. (struct soc_mixer_control *)kcontrol->private_value;
  1775. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  1776. unsigned int reg = mc->reg;
  1777. int min = mc->min;
  1778. int val = snd_soc_read(codec, reg);
  1779. ucontrol->value.integer.value[0] =
  1780. ((signed char)(val & 0xff))-min;
  1781. ucontrol->value.integer.value[1] =
  1782. ((signed char)((val >> 8) & 0xff))-min;
  1783. return 0;
  1784. }
  1785. EXPORT_SYMBOL_GPL(snd_soc_get_volsw_s8);
  1786. /**
  1787. * snd_soc_put_volsw_sgn - signed mixer put callback
  1788. * @kcontrol: mixer control
  1789. * @ucontrol: control element information
  1790. *
  1791. * Callback to set the value of a signed mixer control.
  1792. *
  1793. * Returns 0 for success.
  1794. */
  1795. int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol,
  1796. struct snd_ctl_elem_value *ucontrol)
  1797. {
  1798. struct soc_mixer_control *mc =
  1799. (struct soc_mixer_control *)kcontrol->private_value;
  1800. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  1801. unsigned int reg = mc->reg;
  1802. int min = mc->min;
  1803. unsigned short val;
  1804. val = (ucontrol->value.integer.value[0]+min) & 0xff;
  1805. val |= ((ucontrol->value.integer.value[1]+min) & 0xff) << 8;
  1806. return snd_soc_update_bits(codec, reg, 0xffff, val);
  1807. }
  1808. EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8);
  1809. /**
  1810. * snd_soc_dai_set_sysclk - configure DAI system or master clock.
  1811. * @dai: DAI
  1812. * @clk_id: DAI specific clock ID
  1813. * @freq: new clock frequency in Hz
  1814. * @dir: new clock direction - input/output.
  1815. *
  1816. * Configures the DAI master (MCLK) or system (SYSCLK) clocking.
  1817. */
  1818. int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id,
  1819. unsigned int freq, int dir)
  1820. {
  1821. if (dai->ops.set_sysclk)
  1822. return dai->ops.set_sysclk(dai, clk_id, freq, dir);
  1823. else
  1824. return -EINVAL;
  1825. }
  1826. EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk);
  1827. /**
  1828. * snd_soc_dai_set_clkdiv - configure DAI clock dividers.
  1829. * @dai: DAI
  1830. * @div_id: DAI specific clock divider ID
  1831. * @div: new clock divisor.
  1832. *
  1833. * Configures the clock dividers. This is used to derive the best DAI bit and
  1834. * frame clocks from the system or master clock. It's best to set the DAI bit
  1835. * and frame clocks as low as possible to save system power.
  1836. */
  1837. int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai,
  1838. int div_id, int div)
  1839. {
  1840. if (dai->ops.set_clkdiv)
  1841. return dai->ops.set_clkdiv(dai, div_id, div);
  1842. else
  1843. return -EINVAL;
  1844. }
  1845. EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv);
  1846. /**
  1847. * snd_soc_dai_set_pll - configure DAI PLL.
  1848. * @dai: DAI
  1849. * @pll_id: DAI specific PLL ID
  1850. * @freq_in: PLL input clock frequency in Hz
  1851. * @freq_out: requested PLL output clock frequency in Hz
  1852. *
  1853. * Configures and enables PLL to generate output clock based on input clock.
  1854. */
  1855. int snd_soc_dai_set_pll(struct snd_soc_dai *dai,
  1856. int pll_id, unsigned int freq_in, unsigned int freq_out)
  1857. {
  1858. if (dai->ops.set_pll)
  1859. return dai->ops.set_pll(dai, pll_id, freq_in, freq_out);
  1860. else
  1861. return -EINVAL;
  1862. }
  1863. EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll);
  1864. /**
  1865. * snd_soc_dai_set_fmt - configure DAI hardware audio format.
  1866. * @dai: DAI
  1867. * @fmt: SND_SOC_DAIFMT_ format value.
  1868. *
  1869. * Configures the DAI hardware format and clocking.
  1870. */
  1871. int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
  1872. {
  1873. if (dai->ops.set_fmt)
  1874. return dai->ops.set_fmt(dai, fmt);
  1875. else
  1876. return -EINVAL;
  1877. }
  1878. EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt);
  1879. /**
  1880. * snd_soc_dai_set_tdm_slot - configure DAI TDM.
  1881. * @dai: DAI
  1882. * @mask: DAI specific mask representing used slots.
  1883. * @slots: Number of slots in use.
  1884. *
  1885. * Configures a DAI for TDM operation. Both mask and slots are codec and DAI
  1886. * specific.
  1887. */
  1888. int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,
  1889. unsigned int mask, int slots)
  1890. {
  1891. if (dai->ops.set_sysclk)
  1892. return dai->ops.set_tdm_slot(dai, mask, slots);
  1893. else
  1894. return -EINVAL;
  1895. }
  1896. EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot);
  1897. /**
  1898. * snd_soc_dai_set_tristate - configure DAI system or master clock.
  1899. * @dai: DAI
  1900. * @tristate: tristate enable
  1901. *
  1902. * Tristates the DAI so that others can use it.
  1903. */
  1904. int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate)
  1905. {
  1906. if (dai->ops.set_sysclk)
  1907. return dai->ops.set_tristate(dai, tristate);
  1908. else
  1909. return -EINVAL;
  1910. }
  1911. EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate);
  1912. /**
  1913. * snd_soc_dai_digital_mute - configure DAI system or master clock.
  1914. * @dai: DAI
  1915. * @mute: mute enable
  1916. *
  1917. * Mutes the DAI DAC.
  1918. */
  1919. int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute)
  1920. {
  1921. if (dai->ops.digital_mute)
  1922. return dai->ops.digital_mute(dai, mute);
  1923. else
  1924. return -EINVAL;
  1925. }
  1926. EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute);
  1927. /**
  1928. * snd_soc_register_card - Register a card with the ASoC core
  1929. *
  1930. * @card: Card to register
  1931. *
  1932. * Note that currently this is an internal only function: it will be
  1933. * exposed to machine drivers after further backporting of ASoC v2
  1934. * registration APIs.
  1935. */
  1936. static int snd_soc_register_card(struct snd_soc_card *card)
  1937. {
  1938. if (!card->name || !card->dev)
  1939. return -EINVAL;
  1940. INIT_LIST_HEAD(&card->list);
  1941. card->instantiated = 0;
  1942. mutex_lock(&client_mutex);
  1943. list_add(&card->list, &card_list);
  1944. snd_soc_instantiate_cards();
  1945. mutex_unlock(&client_mutex);
  1946. dev_dbg(card->dev, "Registered card '%s'\n", card->name);
  1947. return 0;
  1948. }
  1949. /**
  1950. * snd_soc_unregister_card - Unregister a card with the ASoC core
  1951. *
  1952. * @card: Card to unregister
  1953. *
  1954. * Note that currently this is an internal only function: it will be
  1955. * exposed to machine drivers after further backporting of ASoC v2
  1956. * registration APIs.
  1957. */
  1958. static int snd_soc_unregister_card(struct snd_soc_card *card)
  1959. {
  1960. mutex_lock(&client_mutex);
  1961. list_del(&card->list);
  1962. mutex_unlock(&client_mutex);
  1963. dev_dbg(card->dev, "Unregistered card '%s'\n", card->name);
  1964. return 0;
  1965. }
  1966. /**
  1967. * snd_soc_register_dai - Register a DAI with the ASoC core
  1968. *
  1969. * @dai: DAI to register
  1970. */
  1971. int snd_soc_register_dai(struct snd_soc_dai *dai)
  1972. {
  1973. if (!dai->name)
  1974. return -EINVAL;
  1975. /* The device should become mandatory over time */
  1976. if (!dai->dev)
  1977. printk(KERN_WARNING "No device for DAI %s\n", dai->name);
  1978. INIT_LIST_HEAD(&dai->list);
  1979. mutex_lock(&client_mutex);
  1980. list_add(&dai->list, &dai_list);
  1981. snd_soc_instantiate_cards();
  1982. mutex_unlock(&client_mutex);
  1983. pr_debug("Registered DAI '%s'\n", dai->name);
  1984. return 0;
  1985. }
  1986. EXPORT_SYMBOL_GPL(snd_soc_register_dai);
  1987. /**
  1988. * snd_soc_unregister_dai - Unregister a DAI from the ASoC core
  1989. *
  1990. * @dai: DAI to unregister
  1991. */
  1992. void snd_soc_unregister_dai(struct snd_soc_dai *dai)
  1993. {
  1994. mutex_lock(&client_mutex);
  1995. list_del(&dai->list);
  1996. mutex_unlock(&client_mutex);
  1997. pr_debug("Unregistered DAI '%s'\n", dai->name);
  1998. }
  1999. EXPORT_SYMBOL_GPL(snd_soc_unregister_dai);
  2000. /**
  2001. * snd_soc_register_dais - Register multiple DAIs with the ASoC core
  2002. *
  2003. * @dai: Array of DAIs to register
  2004. * @count: Number of DAIs
  2005. */
  2006. int snd_soc_register_dais(struct snd_soc_dai *dai, size_t count)
  2007. {
  2008. int i, ret;
  2009. for (i = 0; i < count; i++) {
  2010. ret = snd_soc_register_dai(&dai[i]);
  2011. if (ret != 0)
  2012. goto err;
  2013. }
  2014. return 0;
  2015. err:
  2016. for (i--; i >= 0; i--)
  2017. snd_soc_unregister_dai(&dai[i]);
  2018. return ret;
  2019. }
  2020. EXPORT_SYMBOL_GPL(snd_soc_register_dais);
  2021. /**
  2022. * snd_soc_unregister_dais - Unregister multiple DAIs from the ASoC core
  2023. *
  2024. * @dai: Array of DAIs to unregister
  2025. * @count: Number of DAIs
  2026. */
  2027. void snd_soc_unregister_dais(struct snd_soc_dai *dai, size_t count)
  2028. {
  2029. int i;
  2030. for (i = 0; i < count; i++)
  2031. snd_soc_unregister_dai(&dai[i]);
  2032. }
  2033. EXPORT_SYMBOL_GPL(snd_soc_unregister_dais);
  2034. /**
  2035. * snd_soc_register_platform - Register a platform with the ASoC core
  2036. *
  2037. * @platform: platform to register
  2038. */
  2039. int snd_soc_register_platform(struct snd_soc_platform *platform)
  2040. {
  2041. if (!platform->name)
  2042. return -EINVAL;
  2043. INIT_LIST_HEAD(&platform->list);
  2044. mutex_lock(&client_mutex);
  2045. list_add(&platform->list, &platform_list);
  2046. snd_soc_instantiate_cards();
  2047. mutex_unlock(&client_mutex);
  2048. pr_debug("Registered platform '%s'\n", platform->name);
  2049. return 0;
  2050. }
  2051. EXPORT_SYMBOL_GPL(snd_soc_register_platform);
  2052. /**
  2053. * snd_soc_unregister_platform - Unregister a platform from the ASoC core
  2054. *
  2055. * @platform: platform to unregister
  2056. */
  2057. void snd_soc_unregister_platform(struct snd_soc_platform *platform)
  2058. {
  2059. mutex_lock(&client_mutex);
  2060. list_del(&platform->list);
  2061. mutex_unlock(&client_mutex);
  2062. pr_debug("Unregistered platform '%s'\n", platform->name);
  2063. }
  2064. EXPORT_SYMBOL_GPL(snd_soc_unregister_platform);
  2065. /**
  2066. * snd_soc_register_codec - Register a codec with the ASoC core
  2067. *
  2068. * @codec: codec to register
  2069. */
  2070. int snd_soc_register_codec(struct snd_soc_codec *codec)
  2071. {
  2072. if (!codec->name)
  2073. return -EINVAL;
  2074. /* The device should become mandatory over time */
  2075. if (!codec->dev)
  2076. printk(KERN_WARNING "No device for codec %s\n", codec->name);
  2077. INIT_LIST_HEAD(&codec->list);
  2078. mutex_lock(&client_mutex);
  2079. list_add(&codec->list, &codec_list);
  2080. snd_soc_instantiate_cards();
  2081. mutex_unlock(&client_mutex);
  2082. pr_debug("Registered codec '%s'\n", codec->name);
  2083. return 0;
  2084. }
  2085. EXPORT_SYMBOL_GPL(snd_soc_register_codec);
  2086. /**
  2087. * snd_soc_unregister_codec - Unregister a codec from the ASoC core
  2088. *
  2089. * @codec: codec to unregister
  2090. */
  2091. void snd_soc_unregister_codec(struct snd_soc_codec *codec)
  2092. {
  2093. mutex_lock(&client_mutex);
  2094. list_del(&codec->list);
  2095. mutex_unlock(&client_mutex);
  2096. pr_debug("Unregistered codec '%s'\n", codec->name);
  2097. }
  2098. EXPORT_SYMBOL_GPL(snd_soc_unregister_codec);
  2099. static int __init snd_soc_init(void)
  2100. {
  2101. #ifdef CONFIG_DEBUG_FS
  2102. debugfs_root = debugfs_create_dir("asoc", NULL);
  2103. if (IS_ERR(debugfs_root) || !debugfs_root) {
  2104. printk(KERN_WARNING
  2105. "ASoC: Failed to create debugfs directory\n");
  2106. debugfs_root = NULL;
  2107. }
  2108. #endif
  2109. return platform_driver_register(&soc_driver);
  2110. }
  2111. static void __exit snd_soc_exit(void)
  2112. {
  2113. #ifdef CONFIG_DEBUG_FS
  2114. debugfs_remove_recursive(debugfs_root);
  2115. #endif
  2116. platform_driver_unregister(&soc_driver);
  2117. }
  2118. module_init(snd_soc_init);
  2119. module_exit(snd_soc_exit);
  2120. /* Module information */
  2121. MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
  2122. MODULE_DESCRIPTION("ALSA SoC Core");
  2123. MODULE_LICENSE("GPL");
  2124. MODULE_ALIAS("platform:soc-audio");