soc-core.c 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891
  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/platform_device.h>
  29. #include <sound/core.h>
  30. #include <sound/pcm.h>
  31. #include <sound/pcm_params.h>
  32. #include <sound/soc.h>
  33. #include <sound/soc-dapm.h>
  34. #include <sound/initval.h>
  35. /* debug */
  36. #define SOC_DEBUG 0
  37. #if SOC_DEBUG
  38. #define dbg(format, arg...) printk(format, ## arg)
  39. #else
  40. #define dbg(format, arg...)
  41. #endif
  42. static DEFINE_MUTEX(pcm_mutex);
  43. static DEFINE_MUTEX(io_mutex);
  44. static DECLARE_WAIT_QUEUE_HEAD(soc_pm_waitq);
  45. /*
  46. * This is a timeout to do a DAPM powerdown after a stream is closed().
  47. * It can be used to eliminate pops between different playback streams, e.g.
  48. * between two audio tracks.
  49. */
  50. static int pmdown_time = 5000;
  51. module_param(pmdown_time, int, 0);
  52. MODULE_PARM_DESC(pmdown_time, "DAPM stream powerdown time (msecs)");
  53. /*
  54. * This function forces any delayed work to be queued and run.
  55. */
  56. static int run_delayed_work(struct delayed_work *dwork)
  57. {
  58. int ret;
  59. /* cancel any work waiting to be queued. */
  60. ret = cancel_delayed_work(dwork);
  61. /* if there was any work waiting then we run it now and
  62. * wait for it's completion */
  63. if (ret) {
  64. schedule_delayed_work(dwork, 0);
  65. flush_scheduled_work();
  66. }
  67. return ret;
  68. }
  69. #ifdef CONFIG_SND_SOC_AC97_BUS
  70. /* unregister ac97 codec */
  71. static int soc_ac97_dev_unregister(struct snd_soc_codec *codec)
  72. {
  73. if (codec->ac97->dev.bus)
  74. device_unregister(&codec->ac97->dev);
  75. return 0;
  76. }
  77. /* stop no dev release warning */
  78. static void soc_ac97_device_release(struct device *dev){}
  79. /* register ac97 codec to bus */
  80. static int soc_ac97_dev_register(struct snd_soc_codec *codec)
  81. {
  82. int err;
  83. codec->ac97->dev.bus = &ac97_bus_type;
  84. codec->ac97->dev.parent = NULL;
  85. codec->ac97->dev.release = soc_ac97_device_release;
  86. dev_set_name(&codec->ac97->dev, "%d-%d:%s",
  87. codec->card->number, 0, codec->name);
  88. err = device_register(&codec->ac97->dev);
  89. if (err < 0) {
  90. snd_printk(KERN_ERR "Can't register ac97 bus\n");
  91. codec->ac97->dev.bus = NULL;
  92. return err;
  93. }
  94. return 0;
  95. }
  96. #endif
  97. static inline const char *get_dai_name(int type)
  98. {
  99. switch (type) {
  100. case SND_SOC_DAI_AC97_BUS:
  101. case SND_SOC_DAI_AC97:
  102. return "AC97";
  103. case SND_SOC_DAI_I2S:
  104. return "I2S";
  105. case SND_SOC_DAI_PCM:
  106. return "PCM";
  107. }
  108. return NULL;
  109. }
  110. /*
  111. * Called by ALSA when a PCM substream is opened, the runtime->hw record is
  112. * then initialized and any private data can be allocated. This also calls
  113. * startup for the cpu DAI, platform, machine and codec DAI.
  114. */
  115. static int soc_pcm_open(struct snd_pcm_substream *substream)
  116. {
  117. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  118. struct snd_soc_device *socdev = rtd->socdev;
  119. struct snd_pcm_runtime *runtime = substream->runtime;
  120. struct snd_soc_dai_link *machine = rtd->dai;
  121. struct snd_soc_platform *platform = socdev->platform;
  122. struct snd_soc_dai *cpu_dai = machine->cpu_dai;
  123. struct snd_soc_dai *codec_dai = machine->codec_dai;
  124. int ret = 0;
  125. mutex_lock(&pcm_mutex);
  126. /* startup the audio subsystem */
  127. if (cpu_dai->ops.startup) {
  128. ret = cpu_dai->ops.startup(substream);
  129. if (ret < 0) {
  130. printk(KERN_ERR "asoc: can't open interface %s\n",
  131. cpu_dai->name);
  132. goto out;
  133. }
  134. }
  135. if (platform->pcm_ops->open) {
  136. ret = platform->pcm_ops->open(substream);
  137. if (ret < 0) {
  138. printk(KERN_ERR "asoc: can't open platform %s\n", platform->name);
  139. goto platform_err;
  140. }
  141. }
  142. if (codec_dai->ops.startup) {
  143. ret = codec_dai->ops.startup(substream);
  144. if (ret < 0) {
  145. printk(KERN_ERR "asoc: can't open codec %s\n",
  146. codec_dai->name);
  147. goto codec_dai_err;
  148. }
  149. }
  150. if (machine->ops && machine->ops->startup) {
  151. ret = machine->ops->startup(substream);
  152. if (ret < 0) {
  153. printk(KERN_ERR "asoc: %s startup failed\n", machine->name);
  154. goto machine_err;
  155. }
  156. }
  157. /* Check that the codec and cpu DAI's are compatible */
  158. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  159. runtime->hw.rate_min =
  160. max(codec_dai->playback.rate_min,
  161. cpu_dai->playback.rate_min);
  162. runtime->hw.rate_max =
  163. min(codec_dai->playback.rate_max,
  164. cpu_dai->playback.rate_max);
  165. runtime->hw.channels_min =
  166. max(codec_dai->playback.channels_min,
  167. cpu_dai->playback.channels_min);
  168. runtime->hw.channels_max =
  169. min(codec_dai->playback.channels_max,
  170. cpu_dai->playback.channels_max);
  171. runtime->hw.formats =
  172. codec_dai->playback.formats & cpu_dai->playback.formats;
  173. runtime->hw.rates =
  174. codec_dai->playback.rates & cpu_dai->playback.rates;
  175. } else {
  176. runtime->hw.rate_min =
  177. max(codec_dai->capture.rate_min,
  178. cpu_dai->capture.rate_min);
  179. runtime->hw.rate_max =
  180. min(codec_dai->capture.rate_max,
  181. cpu_dai->capture.rate_max);
  182. runtime->hw.channels_min =
  183. max(codec_dai->capture.channels_min,
  184. cpu_dai->capture.channels_min);
  185. runtime->hw.channels_max =
  186. min(codec_dai->capture.channels_max,
  187. cpu_dai->capture.channels_max);
  188. runtime->hw.formats =
  189. codec_dai->capture.formats & cpu_dai->capture.formats;
  190. runtime->hw.rates =
  191. codec_dai->capture.rates & cpu_dai->capture.rates;
  192. }
  193. snd_pcm_limit_hw_rates(runtime);
  194. if (!runtime->hw.rates) {
  195. printk(KERN_ERR "asoc: %s <-> %s No matching rates\n",
  196. codec_dai->name, cpu_dai->name);
  197. goto machine_err;
  198. }
  199. if (!runtime->hw.formats) {
  200. printk(KERN_ERR "asoc: %s <-> %s No matching formats\n",
  201. codec_dai->name, cpu_dai->name);
  202. goto machine_err;
  203. }
  204. if (!runtime->hw.channels_min || !runtime->hw.channels_max) {
  205. printk(KERN_ERR "asoc: %s <-> %s No matching channels\n",
  206. codec_dai->name, cpu_dai->name);
  207. goto machine_err;
  208. }
  209. dbg("asoc: %s <-> %s info:\n", codec_dai->name, cpu_dai->name);
  210. dbg("asoc: rate mask 0x%x\n", runtime->hw.rates);
  211. dbg("asoc: min ch %d max ch %d\n", runtime->hw.channels_min,
  212. runtime->hw.channels_max);
  213. dbg("asoc: min rate %d max rate %d\n", runtime->hw.rate_min,
  214. runtime->hw.rate_max);
  215. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  216. cpu_dai->playback.active = codec_dai->playback.active = 1;
  217. else
  218. cpu_dai->capture.active = codec_dai->capture.active = 1;
  219. cpu_dai->active = codec_dai->active = 1;
  220. cpu_dai->runtime = runtime;
  221. socdev->codec->active++;
  222. mutex_unlock(&pcm_mutex);
  223. return 0;
  224. machine_err:
  225. if (machine->ops && machine->ops->shutdown)
  226. machine->ops->shutdown(substream);
  227. codec_dai_err:
  228. if (platform->pcm_ops->close)
  229. platform->pcm_ops->close(substream);
  230. platform_err:
  231. if (cpu_dai->ops.shutdown)
  232. cpu_dai->ops.shutdown(substream);
  233. out:
  234. mutex_unlock(&pcm_mutex);
  235. return ret;
  236. }
  237. /*
  238. * Power down the audio subsystem pmdown_time msecs after close is called.
  239. * This is to ensure there are no pops or clicks in between any music tracks
  240. * due to DAPM power cycling.
  241. */
  242. static void close_delayed_work(struct work_struct *work)
  243. {
  244. struct snd_soc_device *socdev =
  245. container_of(work, struct snd_soc_device, delayed_work.work);
  246. struct snd_soc_codec *codec = socdev->codec;
  247. struct snd_soc_dai *codec_dai;
  248. int i;
  249. mutex_lock(&pcm_mutex);
  250. for (i = 0; i < codec->num_dai; i++) {
  251. codec_dai = &codec->dai[i];
  252. dbg("pop wq checking: %s status: %s waiting: %s\n",
  253. codec_dai->playback.stream_name,
  254. codec_dai->playback.active ? "active" : "inactive",
  255. codec_dai->pop_wait ? "yes" : "no");
  256. /* are we waiting on this codec DAI stream */
  257. if (codec_dai->pop_wait == 1) {
  258. /* Reduce power if no longer active */
  259. if (codec->active == 0) {
  260. dbg("pop wq D1 %s %s\n", codec->name,
  261. codec_dai->playback.stream_name);
  262. snd_soc_dapm_set_bias_level(socdev,
  263. SND_SOC_BIAS_PREPARE);
  264. }
  265. codec_dai->pop_wait = 0;
  266. snd_soc_dapm_stream_event(codec,
  267. codec_dai->playback.stream_name,
  268. SND_SOC_DAPM_STREAM_STOP);
  269. /* Fall into standby if no longer active */
  270. if (codec->active == 0) {
  271. dbg("pop wq D3 %s %s\n", codec->name,
  272. codec_dai->playback.stream_name);
  273. snd_soc_dapm_set_bias_level(socdev,
  274. SND_SOC_BIAS_STANDBY);
  275. }
  276. }
  277. }
  278. mutex_unlock(&pcm_mutex);
  279. }
  280. /*
  281. * Called by ALSA when a PCM substream is closed. Private data can be
  282. * freed here. The cpu DAI, codec DAI, machine and platform are also
  283. * shutdown.
  284. */
  285. static int soc_codec_close(struct snd_pcm_substream *substream)
  286. {
  287. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  288. struct snd_soc_device *socdev = rtd->socdev;
  289. struct snd_soc_dai_link *machine = rtd->dai;
  290. struct snd_soc_platform *platform = socdev->platform;
  291. struct snd_soc_dai *cpu_dai = machine->cpu_dai;
  292. struct snd_soc_dai *codec_dai = machine->codec_dai;
  293. struct snd_soc_codec *codec = socdev->codec;
  294. mutex_lock(&pcm_mutex);
  295. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  296. cpu_dai->playback.active = codec_dai->playback.active = 0;
  297. else
  298. cpu_dai->capture.active = codec_dai->capture.active = 0;
  299. if (codec_dai->playback.active == 0 &&
  300. codec_dai->capture.active == 0) {
  301. cpu_dai->active = codec_dai->active = 0;
  302. }
  303. codec->active--;
  304. /* Muting the DAC suppresses artifacts caused during digital
  305. * shutdown, for example from stopping clocks.
  306. */
  307. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  308. snd_soc_dai_digital_mute(codec_dai, 1);
  309. if (cpu_dai->ops.shutdown)
  310. cpu_dai->ops.shutdown(substream);
  311. if (codec_dai->ops.shutdown)
  312. codec_dai->ops.shutdown(substream);
  313. if (machine->ops && machine->ops->shutdown)
  314. machine->ops->shutdown(substream);
  315. if (platform->pcm_ops->close)
  316. platform->pcm_ops->close(substream);
  317. cpu_dai->runtime = NULL;
  318. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  319. /* start delayed pop wq here for playback streams */
  320. codec_dai->pop_wait = 1;
  321. schedule_delayed_work(&socdev->delayed_work,
  322. msecs_to_jiffies(pmdown_time));
  323. } else {
  324. /* capture streams can be powered down now */
  325. snd_soc_dapm_stream_event(codec,
  326. codec_dai->capture.stream_name,
  327. SND_SOC_DAPM_STREAM_STOP);
  328. if (codec->active == 0 && codec_dai->pop_wait == 0)
  329. snd_soc_dapm_set_bias_level(socdev,
  330. SND_SOC_BIAS_STANDBY);
  331. }
  332. mutex_unlock(&pcm_mutex);
  333. return 0;
  334. }
  335. /*
  336. * Called by ALSA when the PCM substream is prepared, can set format, sample
  337. * rate, etc. This function is non atomic and can be called multiple times,
  338. * it can refer to the runtime info.
  339. */
  340. static int soc_pcm_prepare(struct snd_pcm_substream *substream)
  341. {
  342. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  343. struct snd_soc_device *socdev = rtd->socdev;
  344. struct snd_soc_dai_link *machine = rtd->dai;
  345. struct snd_soc_platform *platform = socdev->platform;
  346. struct snd_soc_dai *cpu_dai = machine->cpu_dai;
  347. struct snd_soc_dai *codec_dai = machine->codec_dai;
  348. struct snd_soc_codec *codec = socdev->codec;
  349. int ret = 0;
  350. mutex_lock(&pcm_mutex);
  351. if (machine->ops && machine->ops->prepare) {
  352. ret = machine->ops->prepare(substream);
  353. if (ret < 0) {
  354. printk(KERN_ERR "asoc: machine prepare error\n");
  355. goto out;
  356. }
  357. }
  358. if (platform->pcm_ops->prepare) {
  359. ret = platform->pcm_ops->prepare(substream);
  360. if (ret < 0) {
  361. printk(KERN_ERR "asoc: platform prepare error\n");
  362. goto out;
  363. }
  364. }
  365. if (codec_dai->ops.prepare) {
  366. ret = codec_dai->ops.prepare(substream);
  367. if (ret < 0) {
  368. printk(KERN_ERR "asoc: codec DAI prepare error\n");
  369. goto out;
  370. }
  371. }
  372. if (cpu_dai->ops.prepare) {
  373. ret = cpu_dai->ops.prepare(substream);
  374. if (ret < 0) {
  375. printk(KERN_ERR "asoc: cpu DAI prepare error\n");
  376. goto out;
  377. }
  378. }
  379. /* we only want to start a DAPM playback stream if we are not waiting
  380. * on an existing one stopping */
  381. if (codec_dai->pop_wait) {
  382. /* we are waiting for the delayed work to start */
  383. if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
  384. snd_soc_dapm_stream_event(socdev->codec,
  385. codec_dai->capture.stream_name,
  386. SND_SOC_DAPM_STREAM_START);
  387. else {
  388. codec_dai->pop_wait = 0;
  389. cancel_delayed_work(&socdev->delayed_work);
  390. snd_soc_dai_digital_mute(codec_dai, 0);
  391. }
  392. } else {
  393. /* no delayed work - do we need to power up codec */
  394. if (codec->bias_level != SND_SOC_BIAS_ON) {
  395. snd_soc_dapm_set_bias_level(socdev,
  396. SND_SOC_BIAS_PREPARE);
  397. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  398. snd_soc_dapm_stream_event(codec,
  399. codec_dai->playback.stream_name,
  400. SND_SOC_DAPM_STREAM_START);
  401. else
  402. snd_soc_dapm_stream_event(codec,
  403. codec_dai->capture.stream_name,
  404. SND_SOC_DAPM_STREAM_START);
  405. snd_soc_dapm_set_bias_level(socdev, SND_SOC_BIAS_ON);
  406. snd_soc_dai_digital_mute(codec_dai, 0);
  407. } else {
  408. /* codec already powered - power on widgets */
  409. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  410. snd_soc_dapm_stream_event(codec,
  411. codec_dai->playback.stream_name,
  412. SND_SOC_DAPM_STREAM_START);
  413. else
  414. snd_soc_dapm_stream_event(codec,
  415. codec_dai->capture.stream_name,
  416. SND_SOC_DAPM_STREAM_START);
  417. snd_soc_dai_digital_mute(codec_dai, 0);
  418. }
  419. }
  420. out:
  421. mutex_unlock(&pcm_mutex);
  422. return ret;
  423. }
  424. /*
  425. * Called by ALSA when the hardware params are set by application. This
  426. * function can also be called multiple times and can allocate buffers
  427. * (using snd_pcm_lib_* ). It's non-atomic.
  428. */
  429. static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
  430. struct snd_pcm_hw_params *params)
  431. {
  432. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  433. struct snd_soc_device *socdev = rtd->socdev;
  434. struct snd_soc_dai_link *machine = rtd->dai;
  435. struct snd_soc_platform *platform = socdev->platform;
  436. struct snd_soc_dai *cpu_dai = machine->cpu_dai;
  437. struct snd_soc_dai *codec_dai = machine->codec_dai;
  438. int ret = 0;
  439. mutex_lock(&pcm_mutex);
  440. if (machine->ops && machine->ops->hw_params) {
  441. ret = machine->ops->hw_params(substream, params);
  442. if (ret < 0) {
  443. printk(KERN_ERR "asoc: machine hw_params failed\n");
  444. goto out;
  445. }
  446. }
  447. if (codec_dai->ops.hw_params) {
  448. ret = codec_dai->ops.hw_params(substream, params);
  449. if (ret < 0) {
  450. printk(KERN_ERR "asoc: can't set codec %s hw params\n",
  451. codec_dai->name);
  452. goto codec_err;
  453. }
  454. }
  455. if (cpu_dai->ops.hw_params) {
  456. ret = cpu_dai->ops.hw_params(substream, params);
  457. if (ret < 0) {
  458. printk(KERN_ERR "asoc: interface %s hw params failed\n",
  459. cpu_dai->name);
  460. goto interface_err;
  461. }
  462. }
  463. if (platform->pcm_ops->hw_params) {
  464. ret = platform->pcm_ops->hw_params(substream, params);
  465. if (ret < 0) {
  466. printk(KERN_ERR "asoc: platform %s hw params failed\n",
  467. platform->name);
  468. goto platform_err;
  469. }
  470. }
  471. out:
  472. mutex_unlock(&pcm_mutex);
  473. return ret;
  474. platform_err:
  475. if (cpu_dai->ops.hw_free)
  476. cpu_dai->ops.hw_free(substream);
  477. interface_err:
  478. if (codec_dai->ops.hw_free)
  479. codec_dai->ops.hw_free(substream);
  480. codec_err:
  481. if (machine->ops && machine->ops->hw_free)
  482. machine->ops->hw_free(substream);
  483. mutex_unlock(&pcm_mutex);
  484. return ret;
  485. }
  486. /*
  487. * Free's resources allocated by hw_params, can be called multiple times
  488. */
  489. static int soc_pcm_hw_free(struct snd_pcm_substream *substream)
  490. {
  491. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  492. struct snd_soc_device *socdev = rtd->socdev;
  493. struct snd_soc_dai_link *machine = rtd->dai;
  494. struct snd_soc_platform *platform = socdev->platform;
  495. struct snd_soc_dai *cpu_dai = machine->cpu_dai;
  496. struct snd_soc_dai *codec_dai = machine->codec_dai;
  497. struct snd_soc_codec *codec = socdev->codec;
  498. mutex_lock(&pcm_mutex);
  499. /* apply codec digital mute */
  500. if (!codec->active)
  501. snd_soc_dai_digital_mute(codec_dai, 1);
  502. /* free any machine hw params */
  503. if (machine->ops && machine->ops->hw_free)
  504. machine->ops->hw_free(substream);
  505. /* free any DMA resources */
  506. if (platform->pcm_ops->hw_free)
  507. platform->pcm_ops->hw_free(substream);
  508. /* now free hw params for the DAI's */
  509. if (codec_dai->ops.hw_free)
  510. codec_dai->ops.hw_free(substream);
  511. if (cpu_dai->ops.hw_free)
  512. cpu_dai->ops.hw_free(substream);
  513. mutex_unlock(&pcm_mutex);
  514. return 0;
  515. }
  516. static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
  517. {
  518. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  519. struct snd_soc_device *socdev = rtd->socdev;
  520. struct snd_soc_dai_link *machine = rtd->dai;
  521. struct snd_soc_platform *platform = socdev->platform;
  522. struct snd_soc_dai *cpu_dai = machine->cpu_dai;
  523. struct snd_soc_dai *codec_dai = machine->codec_dai;
  524. int ret;
  525. if (codec_dai->ops.trigger) {
  526. ret = codec_dai->ops.trigger(substream, cmd);
  527. if (ret < 0)
  528. return ret;
  529. }
  530. if (platform->pcm_ops->trigger) {
  531. ret = platform->pcm_ops->trigger(substream, cmd);
  532. if (ret < 0)
  533. return ret;
  534. }
  535. if (cpu_dai->ops.trigger) {
  536. ret = cpu_dai->ops.trigger(substream, cmd);
  537. if (ret < 0)
  538. return ret;
  539. }
  540. return 0;
  541. }
  542. /* ASoC PCM operations */
  543. static struct snd_pcm_ops soc_pcm_ops = {
  544. .open = soc_pcm_open,
  545. .close = soc_codec_close,
  546. .hw_params = soc_pcm_hw_params,
  547. .hw_free = soc_pcm_hw_free,
  548. .prepare = soc_pcm_prepare,
  549. .trigger = soc_pcm_trigger,
  550. };
  551. #ifdef CONFIG_PM
  552. /* powers down audio subsystem for suspend */
  553. static int soc_suspend(struct platform_device *pdev, pm_message_t state)
  554. {
  555. struct snd_soc_device *socdev = platform_get_drvdata(pdev);
  556. struct snd_soc_machine *machine = socdev->machine;
  557. struct snd_soc_platform *platform = socdev->platform;
  558. struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
  559. struct snd_soc_codec *codec = socdev->codec;
  560. int i;
  561. /* Due to the resume being scheduled into a workqueue we could
  562. * suspend before that's finished - wait for it to complete.
  563. */
  564. snd_power_lock(codec->card);
  565. snd_power_wait(codec->card, SNDRV_CTL_POWER_D0);
  566. snd_power_unlock(codec->card);
  567. /* we're going to block userspace touching us until resume completes */
  568. snd_power_change_state(codec->card, SNDRV_CTL_POWER_D3hot);
  569. /* mute any active DAC's */
  570. for (i = 0; i < machine->num_links; i++) {
  571. struct snd_soc_dai *dai = machine->dai_link[i].codec_dai;
  572. if (dai->dai_ops.digital_mute && dai->playback.active)
  573. dai->dai_ops.digital_mute(dai, 1);
  574. }
  575. /* suspend all pcms */
  576. for (i = 0; i < machine->num_links; i++)
  577. snd_pcm_suspend_all(machine->dai_link[i].pcm);
  578. if (machine->suspend_pre)
  579. machine->suspend_pre(pdev, state);
  580. for (i = 0; i < machine->num_links; i++) {
  581. struct snd_soc_dai *cpu_dai = machine->dai_link[i].cpu_dai;
  582. if (cpu_dai->suspend && cpu_dai->type != SND_SOC_DAI_AC97)
  583. cpu_dai->suspend(pdev, cpu_dai);
  584. if (platform->suspend)
  585. platform->suspend(pdev, cpu_dai);
  586. }
  587. /* close any waiting streams and save state */
  588. run_delayed_work(&socdev->delayed_work);
  589. codec->suspend_bias_level = codec->bias_level;
  590. for (i = 0; i < codec->num_dai; i++) {
  591. char *stream = codec->dai[i].playback.stream_name;
  592. if (stream != NULL)
  593. snd_soc_dapm_stream_event(codec, stream,
  594. SND_SOC_DAPM_STREAM_SUSPEND);
  595. stream = codec->dai[i].capture.stream_name;
  596. if (stream != NULL)
  597. snd_soc_dapm_stream_event(codec, stream,
  598. SND_SOC_DAPM_STREAM_SUSPEND);
  599. }
  600. if (codec_dev->suspend)
  601. codec_dev->suspend(pdev, state);
  602. for (i = 0; i < machine->num_links; i++) {
  603. struct snd_soc_dai *cpu_dai = machine->dai_link[i].cpu_dai;
  604. if (cpu_dai->suspend && cpu_dai->type == SND_SOC_DAI_AC97)
  605. cpu_dai->suspend(pdev, cpu_dai);
  606. }
  607. if (machine->suspend_post)
  608. machine->suspend_post(pdev, state);
  609. return 0;
  610. }
  611. /* deferred resume work, so resume can complete before we finished
  612. * setting our codec back up, which can be very slow on I2C
  613. */
  614. static void soc_resume_deferred(struct work_struct *work)
  615. {
  616. struct snd_soc_device *socdev = container_of(work,
  617. struct snd_soc_device,
  618. deferred_resume_work);
  619. struct snd_soc_machine *machine = socdev->machine;
  620. struct snd_soc_platform *platform = socdev->platform;
  621. struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
  622. struct snd_soc_codec *codec = socdev->codec;
  623. struct platform_device *pdev = to_platform_device(socdev->dev);
  624. int i;
  625. /* our power state is still SNDRV_CTL_POWER_D3hot from suspend time,
  626. * so userspace apps are blocked from touching us
  627. */
  628. dev_info(socdev->dev, "starting resume work\n");
  629. if (machine->resume_pre)
  630. machine->resume_pre(pdev);
  631. for (i = 0; i < machine->num_links; i++) {
  632. struct snd_soc_dai *cpu_dai = machine->dai_link[i].cpu_dai;
  633. if (cpu_dai->resume && cpu_dai->type == SND_SOC_DAI_AC97)
  634. cpu_dai->resume(pdev, cpu_dai);
  635. }
  636. if (codec_dev->resume)
  637. codec_dev->resume(pdev);
  638. for (i = 0; i < codec->num_dai; i++) {
  639. char *stream = codec->dai[i].playback.stream_name;
  640. if (stream != NULL)
  641. snd_soc_dapm_stream_event(codec, stream,
  642. SND_SOC_DAPM_STREAM_RESUME);
  643. stream = codec->dai[i].capture.stream_name;
  644. if (stream != NULL)
  645. snd_soc_dapm_stream_event(codec, stream,
  646. SND_SOC_DAPM_STREAM_RESUME);
  647. }
  648. /* unmute any active DACs */
  649. for (i = 0; i < machine->num_links; i++) {
  650. struct snd_soc_dai *dai = machine->dai_link[i].codec_dai;
  651. if (dai->dai_ops.digital_mute && dai->playback.active)
  652. dai->dai_ops.digital_mute(dai, 0);
  653. }
  654. for (i = 0; i < machine->num_links; i++) {
  655. struct snd_soc_dai *cpu_dai = machine->dai_link[i].cpu_dai;
  656. if (cpu_dai->resume && cpu_dai->type != SND_SOC_DAI_AC97)
  657. cpu_dai->resume(pdev, cpu_dai);
  658. if (platform->resume)
  659. platform->resume(pdev, cpu_dai);
  660. }
  661. if (machine->resume_post)
  662. machine->resume_post(pdev);
  663. dev_info(socdev->dev, "resume work completed\n");
  664. /* userspace can access us now we are back as we were before */
  665. snd_power_change_state(codec->card, SNDRV_CTL_POWER_D0);
  666. }
  667. /* powers up audio subsystem after a suspend */
  668. static int soc_resume(struct platform_device *pdev)
  669. {
  670. struct snd_soc_device *socdev = platform_get_drvdata(pdev);
  671. dev_info(socdev->dev, "scheduling resume work\n");
  672. if (!schedule_work(&socdev->deferred_resume_work))
  673. dev_err(socdev->dev, "work item may be lost\n");
  674. return 0;
  675. }
  676. #else
  677. #define soc_suspend NULL
  678. #define soc_resume NULL
  679. #endif
  680. /* probes a new socdev */
  681. static int soc_probe(struct platform_device *pdev)
  682. {
  683. int ret = 0, i;
  684. struct snd_soc_device *socdev = platform_get_drvdata(pdev);
  685. struct snd_soc_machine *machine = socdev->machine;
  686. struct snd_soc_platform *platform = socdev->platform;
  687. struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
  688. if (machine->probe) {
  689. ret = machine->probe(pdev);
  690. if (ret < 0)
  691. return ret;
  692. }
  693. for (i = 0; i < machine->num_links; i++) {
  694. struct snd_soc_dai *cpu_dai = machine->dai_link[i].cpu_dai;
  695. if (cpu_dai->probe) {
  696. ret = cpu_dai->probe(pdev, cpu_dai);
  697. if (ret < 0)
  698. goto cpu_dai_err;
  699. }
  700. }
  701. if (codec_dev->probe) {
  702. ret = codec_dev->probe(pdev);
  703. if (ret < 0)
  704. goto cpu_dai_err;
  705. }
  706. if (platform->probe) {
  707. ret = platform->probe(pdev);
  708. if (ret < 0)
  709. goto platform_err;
  710. }
  711. /* DAPM stream work */
  712. INIT_DELAYED_WORK(&socdev->delayed_work, close_delayed_work);
  713. #ifdef CONFIG_PM
  714. /* deferred resume work */
  715. INIT_WORK(&socdev->deferred_resume_work, soc_resume_deferred);
  716. #endif
  717. return 0;
  718. platform_err:
  719. if (codec_dev->remove)
  720. codec_dev->remove(pdev);
  721. cpu_dai_err:
  722. for (i--; i >= 0; i--) {
  723. struct snd_soc_dai *cpu_dai = machine->dai_link[i].cpu_dai;
  724. if (cpu_dai->remove)
  725. cpu_dai->remove(pdev, cpu_dai);
  726. }
  727. if (machine->remove)
  728. machine->remove(pdev);
  729. return ret;
  730. }
  731. /* removes a socdev */
  732. static int soc_remove(struct platform_device *pdev)
  733. {
  734. int i;
  735. struct snd_soc_device *socdev = platform_get_drvdata(pdev);
  736. struct snd_soc_machine *machine = socdev->machine;
  737. struct snd_soc_platform *platform = socdev->platform;
  738. struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
  739. run_delayed_work(&socdev->delayed_work);
  740. if (platform->remove)
  741. platform->remove(pdev);
  742. if (codec_dev->remove)
  743. codec_dev->remove(pdev);
  744. for (i = 0; i < machine->num_links; i++) {
  745. struct snd_soc_dai *cpu_dai = machine->dai_link[i].cpu_dai;
  746. if (cpu_dai->remove)
  747. cpu_dai->remove(pdev, cpu_dai);
  748. }
  749. if (machine->remove)
  750. machine->remove(pdev);
  751. return 0;
  752. }
  753. /* ASoC platform driver */
  754. static struct platform_driver soc_driver = {
  755. .driver = {
  756. .name = "soc-audio",
  757. .owner = THIS_MODULE,
  758. },
  759. .probe = soc_probe,
  760. .remove = soc_remove,
  761. .suspend = soc_suspend,
  762. .resume = soc_resume,
  763. };
  764. /* create a new pcm */
  765. static int soc_new_pcm(struct snd_soc_device *socdev,
  766. struct snd_soc_dai_link *dai_link, int num)
  767. {
  768. struct snd_soc_codec *codec = socdev->codec;
  769. struct snd_soc_dai *codec_dai = dai_link->codec_dai;
  770. struct snd_soc_dai *cpu_dai = dai_link->cpu_dai;
  771. struct snd_soc_pcm_runtime *rtd;
  772. struct snd_pcm *pcm;
  773. char new_name[64];
  774. int ret = 0, playback = 0, capture = 0;
  775. rtd = kzalloc(sizeof(struct snd_soc_pcm_runtime), GFP_KERNEL);
  776. if (rtd == NULL)
  777. return -ENOMEM;
  778. rtd->dai = dai_link;
  779. rtd->socdev = socdev;
  780. codec_dai->codec = socdev->codec;
  781. /* check client and interface hw capabilities */
  782. sprintf(new_name, "%s %s-%s-%d", dai_link->stream_name, codec_dai->name,
  783. get_dai_name(cpu_dai->type), num);
  784. if (codec_dai->playback.channels_min)
  785. playback = 1;
  786. if (codec_dai->capture.channels_min)
  787. capture = 1;
  788. ret = snd_pcm_new(codec->card, new_name, codec->pcm_devs++, playback,
  789. capture, &pcm);
  790. if (ret < 0) {
  791. printk(KERN_ERR "asoc: can't create pcm for codec %s\n",
  792. codec->name);
  793. kfree(rtd);
  794. return ret;
  795. }
  796. dai_link->pcm = pcm;
  797. pcm->private_data = rtd;
  798. soc_pcm_ops.mmap = socdev->platform->pcm_ops->mmap;
  799. soc_pcm_ops.pointer = socdev->platform->pcm_ops->pointer;
  800. soc_pcm_ops.ioctl = socdev->platform->pcm_ops->ioctl;
  801. soc_pcm_ops.copy = socdev->platform->pcm_ops->copy;
  802. soc_pcm_ops.silence = socdev->platform->pcm_ops->silence;
  803. soc_pcm_ops.ack = socdev->platform->pcm_ops->ack;
  804. soc_pcm_ops.page = socdev->platform->pcm_ops->page;
  805. if (playback)
  806. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &soc_pcm_ops);
  807. if (capture)
  808. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &soc_pcm_ops);
  809. ret = socdev->platform->pcm_new(codec->card, codec_dai, pcm);
  810. if (ret < 0) {
  811. printk(KERN_ERR "asoc: platform pcm constructor failed\n");
  812. kfree(rtd);
  813. return ret;
  814. }
  815. pcm->private_free = socdev->platform->pcm_free;
  816. printk(KERN_INFO "asoc: %s <-> %s mapping ok\n", codec_dai->name,
  817. cpu_dai->name);
  818. return ret;
  819. }
  820. /* codec register dump */
  821. static ssize_t codec_reg_show(struct device *dev,
  822. struct device_attribute *attr, char *buf)
  823. {
  824. struct snd_soc_device *devdata = dev_get_drvdata(dev);
  825. struct snd_soc_codec *codec = devdata->codec;
  826. int i, step = 1, count = 0;
  827. if (!codec->reg_cache_size)
  828. return 0;
  829. if (codec->reg_cache_step)
  830. step = codec->reg_cache_step;
  831. count += sprintf(buf, "%s registers\n", codec->name);
  832. for (i = 0; i < codec->reg_cache_size; i += step) {
  833. count += sprintf(buf + count, "%2x: ", i);
  834. if (count >= PAGE_SIZE - 1)
  835. break;
  836. if (codec->display_register)
  837. count += codec->display_register(codec, buf + count,
  838. PAGE_SIZE - count, i);
  839. else
  840. count += snprintf(buf + count, PAGE_SIZE - count,
  841. "%4x", codec->read(codec, i));
  842. if (count >= PAGE_SIZE - 1)
  843. break;
  844. count += snprintf(buf + count, PAGE_SIZE - count, "\n");
  845. if (count >= PAGE_SIZE - 1)
  846. break;
  847. }
  848. /* Truncate count; min() would cause a warning */
  849. if (count >= PAGE_SIZE)
  850. count = PAGE_SIZE - 1;
  851. return count;
  852. }
  853. static DEVICE_ATTR(codec_reg, 0444, codec_reg_show, NULL);
  854. /**
  855. * snd_soc_new_ac97_codec - initailise AC97 device
  856. * @codec: audio codec
  857. * @ops: AC97 bus operations
  858. * @num: AC97 codec number
  859. *
  860. * Initialises AC97 codec resources for use by ad-hoc devices only.
  861. */
  862. int snd_soc_new_ac97_codec(struct snd_soc_codec *codec,
  863. struct snd_ac97_bus_ops *ops, int num)
  864. {
  865. mutex_lock(&codec->mutex);
  866. codec->ac97 = kzalloc(sizeof(struct snd_ac97), GFP_KERNEL);
  867. if (codec->ac97 == NULL) {
  868. mutex_unlock(&codec->mutex);
  869. return -ENOMEM;
  870. }
  871. codec->ac97->bus = kzalloc(sizeof(struct snd_ac97_bus), GFP_KERNEL);
  872. if (codec->ac97->bus == NULL) {
  873. kfree(codec->ac97);
  874. codec->ac97 = NULL;
  875. mutex_unlock(&codec->mutex);
  876. return -ENOMEM;
  877. }
  878. codec->ac97->bus->ops = ops;
  879. codec->ac97->num = num;
  880. mutex_unlock(&codec->mutex);
  881. return 0;
  882. }
  883. EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec);
  884. /**
  885. * snd_soc_free_ac97_codec - free AC97 codec device
  886. * @codec: audio codec
  887. *
  888. * Frees AC97 codec device resources.
  889. */
  890. void snd_soc_free_ac97_codec(struct snd_soc_codec *codec)
  891. {
  892. mutex_lock(&codec->mutex);
  893. kfree(codec->ac97->bus);
  894. kfree(codec->ac97);
  895. codec->ac97 = NULL;
  896. mutex_unlock(&codec->mutex);
  897. }
  898. EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec);
  899. /**
  900. * snd_soc_update_bits - update codec register bits
  901. * @codec: audio codec
  902. * @reg: codec register
  903. * @mask: register mask
  904. * @value: new value
  905. *
  906. * Writes new register value.
  907. *
  908. * Returns 1 for change else 0.
  909. */
  910. int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg,
  911. unsigned short mask, unsigned short value)
  912. {
  913. int change;
  914. unsigned short old, new;
  915. mutex_lock(&io_mutex);
  916. old = snd_soc_read(codec, reg);
  917. new = (old & ~mask) | value;
  918. change = old != new;
  919. if (change)
  920. snd_soc_write(codec, reg, new);
  921. mutex_unlock(&io_mutex);
  922. return change;
  923. }
  924. EXPORT_SYMBOL_GPL(snd_soc_update_bits);
  925. /**
  926. * snd_soc_test_bits - test register for change
  927. * @codec: audio codec
  928. * @reg: codec register
  929. * @mask: register mask
  930. * @value: new value
  931. *
  932. * Tests a register with a new value and checks if the new value is
  933. * different from the old value.
  934. *
  935. * Returns 1 for change else 0.
  936. */
  937. int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned short reg,
  938. unsigned short mask, unsigned short value)
  939. {
  940. int change;
  941. unsigned short old, new;
  942. mutex_lock(&io_mutex);
  943. old = snd_soc_read(codec, reg);
  944. new = (old & ~mask) | value;
  945. change = old != new;
  946. mutex_unlock(&io_mutex);
  947. return change;
  948. }
  949. EXPORT_SYMBOL_GPL(snd_soc_test_bits);
  950. /**
  951. * snd_soc_new_pcms - create new sound card and pcms
  952. * @socdev: the SoC audio device
  953. *
  954. * Create a new sound card based upon the codec and interface pcms.
  955. *
  956. * Returns 0 for success, else error.
  957. */
  958. int snd_soc_new_pcms(struct snd_soc_device *socdev, int idx, const char *xid)
  959. {
  960. struct snd_soc_codec *codec = socdev->codec;
  961. struct snd_soc_machine *machine = socdev->machine;
  962. int ret = 0, i;
  963. mutex_lock(&codec->mutex);
  964. /* register a sound card */
  965. codec->card = snd_card_new(idx, xid, codec->owner, 0);
  966. if (!codec->card) {
  967. printk(KERN_ERR "asoc: can't create sound card for codec %s\n",
  968. codec->name);
  969. mutex_unlock(&codec->mutex);
  970. return -ENODEV;
  971. }
  972. codec->card->dev = socdev->dev;
  973. codec->card->private_data = codec;
  974. strncpy(codec->card->driver, codec->name, sizeof(codec->card->driver));
  975. /* create the pcms */
  976. for (i = 0; i < machine->num_links; i++) {
  977. ret = soc_new_pcm(socdev, &machine->dai_link[i], i);
  978. if (ret < 0) {
  979. printk(KERN_ERR "asoc: can't create pcm %s\n",
  980. machine->dai_link[i].stream_name);
  981. mutex_unlock(&codec->mutex);
  982. return ret;
  983. }
  984. }
  985. mutex_unlock(&codec->mutex);
  986. return ret;
  987. }
  988. EXPORT_SYMBOL_GPL(snd_soc_new_pcms);
  989. /**
  990. * snd_soc_register_card - register sound card
  991. * @socdev: the SoC audio device
  992. *
  993. * Register a SoC sound card. Also registers an AC97 device if the
  994. * codec is AC97 for ad hoc devices.
  995. *
  996. * Returns 0 for success, else error.
  997. */
  998. int snd_soc_register_card(struct snd_soc_device *socdev)
  999. {
  1000. struct snd_soc_codec *codec = socdev->codec;
  1001. struct snd_soc_machine *machine = socdev->machine;
  1002. int ret = 0, i, ac97 = 0, err = 0;
  1003. for (i = 0; i < machine->num_links; i++) {
  1004. if (socdev->machine->dai_link[i].init) {
  1005. err = socdev->machine->dai_link[i].init(codec);
  1006. if (err < 0) {
  1007. printk(KERN_ERR "asoc: failed to init %s\n",
  1008. socdev->machine->dai_link[i].stream_name);
  1009. continue;
  1010. }
  1011. }
  1012. if (socdev->machine->dai_link[i].codec_dai->type ==
  1013. SND_SOC_DAI_AC97_BUS)
  1014. ac97 = 1;
  1015. }
  1016. snprintf(codec->card->shortname, sizeof(codec->card->shortname),
  1017. "%s", machine->name);
  1018. snprintf(codec->card->longname, sizeof(codec->card->longname),
  1019. "%s (%s)", machine->name, codec->name);
  1020. ret = snd_card_register(codec->card);
  1021. if (ret < 0) {
  1022. printk(KERN_ERR "asoc: failed to register soundcard for %s\n",
  1023. codec->name);
  1024. goto out;
  1025. }
  1026. mutex_lock(&codec->mutex);
  1027. #ifdef CONFIG_SND_SOC_AC97_BUS
  1028. if (ac97) {
  1029. ret = soc_ac97_dev_register(codec);
  1030. if (ret < 0) {
  1031. printk(KERN_ERR "asoc: AC97 device register failed\n");
  1032. snd_card_free(codec->card);
  1033. mutex_unlock(&codec->mutex);
  1034. goto out;
  1035. }
  1036. }
  1037. #endif
  1038. err = snd_soc_dapm_sys_add(socdev->dev);
  1039. if (err < 0)
  1040. printk(KERN_WARNING "asoc: failed to add dapm sysfs entries\n");
  1041. err = device_create_file(socdev->dev, &dev_attr_codec_reg);
  1042. if (err < 0)
  1043. printk(KERN_WARNING "asoc: failed to add codec sysfs files\n");
  1044. mutex_unlock(&codec->mutex);
  1045. out:
  1046. return ret;
  1047. }
  1048. EXPORT_SYMBOL_GPL(snd_soc_register_card);
  1049. /**
  1050. * snd_soc_free_pcms - free sound card and pcms
  1051. * @socdev: the SoC audio device
  1052. *
  1053. * Frees sound card and pcms associated with the socdev.
  1054. * Also unregister the codec if it is an AC97 device.
  1055. */
  1056. void snd_soc_free_pcms(struct snd_soc_device *socdev)
  1057. {
  1058. struct snd_soc_codec *codec = socdev->codec;
  1059. #ifdef CONFIG_SND_SOC_AC97_BUS
  1060. struct snd_soc_dai *codec_dai;
  1061. int i;
  1062. #endif
  1063. mutex_lock(&codec->mutex);
  1064. #ifdef CONFIG_SND_SOC_AC97_BUS
  1065. for (i = 0; i < codec->num_dai; i++) {
  1066. codec_dai = &codec->dai[i];
  1067. if (codec_dai->type == SND_SOC_DAI_AC97_BUS && codec->ac97) {
  1068. soc_ac97_dev_unregister(codec);
  1069. goto free_card;
  1070. }
  1071. }
  1072. free_card:
  1073. #endif
  1074. if (codec->card)
  1075. snd_card_free(codec->card);
  1076. device_remove_file(socdev->dev, &dev_attr_codec_reg);
  1077. mutex_unlock(&codec->mutex);
  1078. }
  1079. EXPORT_SYMBOL_GPL(snd_soc_free_pcms);
  1080. /**
  1081. * snd_soc_set_runtime_hwparams - set the runtime hardware parameters
  1082. * @substream: the pcm substream
  1083. * @hw: the hardware parameters
  1084. *
  1085. * Sets the substream runtime hardware parameters.
  1086. */
  1087. int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
  1088. const struct snd_pcm_hardware *hw)
  1089. {
  1090. struct snd_pcm_runtime *runtime = substream->runtime;
  1091. runtime->hw.info = hw->info;
  1092. runtime->hw.formats = hw->formats;
  1093. runtime->hw.period_bytes_min = hw->period_bytes_min;
  1094. runtime->hw.period_bytes_max = hw->period_bytes_max;
  1095. runtime->hw.periods_min = hw->periods_min;
  1096. runtime->hw.periods_max = hw->periods_max;
  1097. runtime->hw.buffer_bytes_max = hw->buffer_bytes_max;
  1098. runtime->hw.fifo_size = hw->fifo_size;
  1099. return 0;
  1100. }
  1101. EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hwparams);
  1102. /**
  1103. * snd_soc_cnew - create new control
  1104. * @_template: control template
  1105. * @data: control private data
  1106. * @lnng_name: control long name
  1107. *
  1108. * Create a new mixer control from a template control.
  1109. *
  1110. * Returns 0 for success, else error.
  1111. */
  1112. struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
  1113. void *data, char *long_name)
  1114. {
  1115. struct snd_kcontrol_new template;
  1116. memcpy(&template, _template, sizeof(template));
  1117. if (long_name)
  1118. template.name = long_name;
  1119. template.index = 0;
  1120. return snd_ctl_new1(&template, data);
  1121. }
  1122. EXPORT_SYMBOL_GPL(snd_soc_cnew);
  1123. /**
  1124. * snd_soc_info_enum_double - enumerated double mixer info callback
  1125. * @kcontrol: mixer control
  1126. * @uinfo: control element information
  1127. *
  1128. * Callback to provide information about a double enumerated
  1129. * mixer control.
  1130. *
  1131. * Returns 0 for success.
  1132. */
  1133. int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
  1134. struct snd_ctl_elem_info *uinfo)
  1135. {
  1136. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  1137. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  1138. uinfo->count = e->shift_l == e->shift_r ? 1 : 2;
  1139. uinfo->value.enumerated.items = e->max;
  1140. if (uinfo->value.enumerated.item > e->max - 1)
  1141. uinfo->value.enumerated.item = e->max - 1;
  1142. strcpy(uinfo->value.enumerated.name,
  1143. e->texts[uinfo->value.enumerated.item]);
  1144. return 0;
  1145. }
  1146. EXPORT_SYMBOL_GPL(snd_soc_info_enum_double);
  1147. /**
  1148. * snd_soc_get_enum_double - enumerated double mixer get callback
  1149. * @kcontrol: mixer control
  1150. * @uinfo: control element information
  1151. *
  1152. * Callback to get the value of a double enumerated mixer.
  1153. *
  1154. * Returns 0 for success.
  1155. */
  1156. int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
  1157. struct snd_ctl_elem_value *ucontrol)
  1158. {
  1159. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  1160. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  1161. unsigned short val, bitmask;
  1162. for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
  1163. ;
  1164. val = snd_soc_read(codec, e->reg);
  1165. ucontrol->value.enumerated.item[0]
  1166. = (val >> e->shift_l) & (bitmask - 1);
  1167. if (e->shift_l != e->shift_r)
  1168. ucontrol->value.enumerated.item[1] =
  1169. (val >> e->shift_r) & (bitmask - 1);
  1170. return 0;
  1171. }
  1172. EXPORT_SYMBOL_GPL(snd_soc_get_enum_double);
  1173. /**
  1174. * snd_soc_put_enum_double - enumerated double mixer put callback
  1175. * @kcontrol: mixer control
  1176. * @uinfo: control element information
  1177. *
  1178. * Callback to set the value of a double enumerated mixer.
  1179. *
  1180. * Returns 0 for success.
  1181. */
  1182. int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
  1183. struct snd_ctl_elem_value *ucontrol)
  1184. {
  1185. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  1186. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  1187. unsigned short val;
  1188. unsigned short mask, bitmask;
  1189. for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
  1190. ;
  1191. if (ucontrol->value.enumerated.item[0] > e->max - 1)
  1192. return -EINVAL;
  1193. val = ucontrol->value.enumerated.item[0] << e->shift_l;
  1194. mask = (bitmask - 1) << e->shift_l;
  1195. if (e->shift_l != e->shift_r) {
  1196. if (ucontrol->value.enumerated.item[1] > e->max - 1)
  1197. return -EINVAL;
  1198. val |= ucontrol->value.enumerated.item[1] << e->shift_r;
  1199. mask |= (bitmask - 1) << e->shift_r;
  1200. }
  1201. return snd_soc_update_bits(codec, e->reg, mask, val);
  1202. }
  1203. EXPORT_SYMBOL_GPL(snd_soc_put_enum_double);
  1204. /**
  1205. * snd_soc_info_enum_ext - external enumerated single mixer info callback
  1206. * @kcontrol: mixer control
  1207. * @uinfo: control element information
  1208. *
  1209. * Callback to provide information about an external enumerated
  1210. * single mixer.
  1211. *
  1212. * Returns 0 for success.
  1213. */
  1214. int snd_soc_info_enum_ext(struct snd_kcontrol *kcontrol,
  1215. struct snd_ctl_elem_info *uinfo)
  1216. {
  1217. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  1218. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  1219. uinfo->count = 1;
  1220. uinfo->value.enumerated.items = e->max;
  1221. if (uinfo->value.enumerated.item > e->max - 1)
  1222. uinfo->value.enumerated.item = e->max - 1;
  1223. strcpy(uinfo->value.enumerated.name,
  1224. e->texts[uinfo->value.enumerated.item]);
  1225. return 0;
  1226. }
  1227. EXPORT_SYMBOL_GPL(snd_soc_info_enum_ext);
  1228. /**
  1229. * snd_soc_info_volsw_ext - external single mixer info callback
  1230. * @kcontrol: mixer control
  1231. * @uinfo: control element information
  1232. *
  1233. * Callback to provide information about a single external mixer control.
  1234. *
  1235. * Returns 0 for success.
  1236. */
  1237. int snd_soc_info_volsw_ext(struct snd_kcontrol *kcontrol,
  1238. struct snd_ctl_elem_info *uinfo)
  1239. {
  1240. int max = kcontrol->private_value;
  1241. if (max == 1)
  1242. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  1243. else
  1244. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  1245. uinfo->count = 1;
  1246. uinfo->value.integer.min = 0;
  1247. uinfo->value.integer.max = max;
  1248. return 0;
  1249. }
  1250. EXPORT_SYMBOL_GPL(snd_soc_info_volsw_ext);
  1251. /**
  1252. * snd_soc_info_volsw - single mixer info callback
  1253. * @kcontrol: mixer control
  1254. * @uinfo: control element information
  1255. *
  1256. * Callback to provide information about a single mixer control.
  1257. *
  1258. * Returns 0 for success.
  1259. */
  1260. int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
  1261. struct snd_ctl_elem_info *uinfo)
  1262. {
  1263. struct soc_mixer_control *mc =
  1264. (struct soc_mixer_control *)kcontrol->private_value;
  1265. int max = mc->max;
  1266. unsigned int shift = mc->shift;
  1267. unsigned int rshift = mc->rshift;
  1268. if (max == 1)
  1269. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  1270. else
  1271. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  1272. uinfo->count = shift == rshift ? 1 : 2;
  1273. uinfo->value.integer.min = 0;
  1274. uinfo->value.integer.max = max;
  1275. return 0;
  1276. }
  1277. EXPORT_SYMBOL_GPL(snd_soc_info_volsw);
  1278. /**
  1279. * snd_soc_get_volsw - single mixer get callback
  1280. * @kcontrol: mixer control
  1281. * @uinfo: control element information
  1282. *
  1283. * Callback to get the value of a single mixer control.
  1284. *
  1285. * Returns 0 for success.
  1286. */
  1287. int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
  1288. struct snd_ctl_elem_value *ucontrol)
  1289. {
  1290. struct soc_mixer_control *mc =
  1291. (struct soc_mixer_control *)kcontrol->private_value;
  1292. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  1293. unsigned int reg = mc->reg;
  1294. unsigned int shift = mc->shift;
  1295. unsigned int rshift = mc->rshift;
  1296. int max = mc->max;
  1297. unsigned int mask = (1 << fls(max)) - 1;
  1298. unsigned int invert = mc->invert;
  1299. ucontrol->value.integer.value[0] =
  1300. (snd_soc_read(codec, reg) >> shift) & mask;
  1301. if (shift != rshift)
  1302. ucontrol->value.integer.value[1] =
  1303. (snd_soc_read(codec, reg) >> rshift) & mask;
  1304. if (invert) {
  1305. ucontrol->value.integer.value[0] =
  1306. max - ucontrol->value.integer.value[0];
  1307. if (shift != rshift)
  1308. ucontrol->value.integer.value[1] =
  1309. max - ucontrol->value.integer.value[1];
  1310. }
  1311. return 0;
  1312. }
  1313. EXPORT_SYMBOL_GPL(snd_soc_get_volsw);
  1314. /**
  1315. * snd_soc_put_volsw - single mixer put callback
  1316. * @kcontrol: mixer control
  1317. * @uinfo: control element information
  1318. *
  1319. * Callback to set the value of a single mixer control.
  1320. *
  1321. * Returns 0 for success.
  1322. */
  1323. int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
  1324. struct snd_ctl_elem_value *ucontrol)
  1325. {
  1326. struct soc_mixer_control *mc =
  1327. (struct soc_mixer_control *)kcontrol->private_value;
  1328. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  1329. unsigned int reg = mc->reg;
  1330. unsigned int shift = mc->shift;
  1331. unsigned int rshift = mc->rshift;
  1332. int max = mc->max;
  1333. unsigned int mask = (1 << fls(max)) - 1;
  1334. unsigned int invert = mc->invert;
  1335. unsigned short val, val2, val_mask;
  1336. val = (ucontrol->value.integer.value[0] & mask);
  1337. if (invert)
  1338. val = max - val;
  1339. val_mask = mask << shift;
  1340. val = val << shift;
  1341. if (shift != rshift) {
  1342. val2 = (ucontrol->value.integer.value[1] & mask);
  1343. if (invert)
  1344. val2 = max - val2;
  1345. val_mask |= mask << rshift;
  1346. val |= val2 << rshift;
  1347. }
  1348. return snd_soc_update_bits(codec, reg, val_mask, val);
  1349. }
  1350. EXPORT_SYMBOL_GPL(snd_soc_put_volsw);
  1351. /**
  1352. * snd_soc_info_volsw_2r - double mixer info callback
  1353. * @kcontrol: mixer control
  1354. * @uinfo: control element information
  1355. *
  1356. * Callback to provide information about a double mixer control that
  1357. * spans 2 codec registers.
  1358. *
  1359. * Returns 0 for success.
  1360. */
  1361. int snd_soc_info_volsw_2r(struct snd_kcontrol *kcontrol,
  1362. struct snd_ctl_elem_info *uinfo)
  1363. {
  1364. struct soc_mixer_control *mc =
  1365. (struct soc_mixer_control *)kcontrol->private_value;
  1366. int max = mc->max;
  1367. if (max == 1)
  1368. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  1369. else
  1370. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  1371. uinfo->count = 2;
  1372. uinfo->value.integer.min = 0;
  1373. uinfo->value.integer.max = max;
  1374. return 0;
  1375. }
  1376. EXPORT_SYMBOL_GPL(snd_soc_info_volsw_2r);
  1377. /**
  1378. * snd_soc_get_volsw_2r - double mixer get callback
  1379. * @kcontrol: mixer control
  1380. * @uinfo: control element information
  1381. *
  1382. * Callback to get the value of a double mixer control that spans 2 registers.
  1383. *
  1384. * Returns 0 for success.
  1385. */
  1386. int snd_soc_get_volsw_2r(struct snd_kcontrol *kcontrol,
  1387. struct snd_ctl_elem_value *ucontrol)
  1388. {
  1389. struct soc_mixer_control *mc =
  1390. (struct soc_mixer_control *)kcontrol->private_value;
  1391. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  1392. unsigned int reg = mc->reg;
  1393. unsigned int reg2 = mc->rreg;
  1394. unsigned int shift = mc->shift;
  1395. int max = mc->max;
  1396. unsigned int mask = (1<<fls(max))-1;
  1397. unsigned int invert = mc->invert;
  1398. ucontrol->value.integer.value[0] =
  1399. (snd_soc_read(codec, reg) >> shift) & mask;
  1400. ucontrol->value.integer.value[1] =
  1401. (snd_soc_read(codec, reg2) >> shift) & mask;
  1402. if (invert) {
  1403. ucontrol->value.integer.value[0] =
  1404. max - ucontrol->value.integer.value[0];
  1405. ucontrol->value.integer.value[1] =
  1406. max - ucontrol->value.integer.value[1];
  1407. }
  1408. return 0;
  1409. }
  1410. EXPORT_SYMBOL_GPL(snd_soc_get_volsw_2r);
  1411. /**
  1412. * snd_soc_put_volsw_2r - double mixer set callback
  1413. * @kcontrol: mixer control
  1414. * @uinfo: control element information
  1415. *
  1416. * Callback to set the value of a double mixer control that spans 2 registers.
  1417. *
  1418. * Returns 0 for success.
  1419. */
  1420. int snd_soc_put_volsw_2r(struct snd_kcontrol *kcontrol,
  1421. struct snd_ctl_elem_value *ucontrol)
  1422. {
  1423. struct soc_mixer_control *mc =
  1424. (struct soc_mixer_control *)kcontrol->private_value;
  1425. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  1426. unsigned int reg = mc->reg;
  1427. unsigned int reg2 = mc->rreg;
  1428. unsigned int shift = mc->shift;
  1429. int max = mc->max;
  1430. unsigned int mask = (1 << fls(max)) - 1;
  1431. unsigned int invert = mc->invert;
  1432. int err;
  1433. unsigned short val, val2, val_mask;
  1434. val_mask = mask << shift;
  1435. val = (ucontrol->value.integer.value[0] & mask);
  1436. val2 = (ucontrol->value.integer.value[1] & mask);
  1437. if (invert) {
  1438. val = max - val;
  1439. val2 = max - val2;
  1440. }
  1441. val = val << shift;
  1442. val2 = val2 << shift;
  1443. err = snd_soc_update_bits(codec, reg, val_mask, val);
  1444. if (err < 0)
  1445. return err;
  1446. err = snd_soc_update_bits(codec, reg2, val_mask, val2);
  1447. return err;
  1448. }
  1449. EXPORT_SYMBOL_GPL(snd_soc_put_volsw_2r);
  1450. /**
  1451. * snd_soc_info_volsw_s8 - signed mixer info callback
  1452. * @kcontrol: mixer control
  1453. * @uinfo: control element information
  1454. *
  1455. * Callback to provide information about a signed mixer control.
  1456. *
  1457. * Returns 0 for success.
  1458. */
  1459. int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol,
  1460. struct snd_ctl_elem_info *uinfo)
  1461. {
  1462. struct soc_mixer_control *mc =
  1463. (struct soc_mixer_control *)kcontrol->private_value;
  1464. int max = mc->max;
  1465. int min = mc->min;
  1466. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  1467. uinfo->count = 2;
  1468. uinfo->value.integer.min = 0;
  1469. uinfo->value.integer.max = max-min;
  1470. return 0;
  1471. }
  1472. EXPORT_SYMBOL_GPL(snd_soc_info_volsw_s8);
  1473. /**
  1474. * snd_soc_get_volsw_s8 - signed mixer get callback
  1475. * @kcontrol: mixer control
  1476. * @uinfo: control element information
  1477. *
  1478. * Callback to get the value of a signed mixer control.
  1479. *
  1480. * Returns 0 for success.
  1481. */
  1482. int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol,
  1483. struct snd_ctl_elem_value *ucontrol)
  1484. {
  1485. struct soc_mixer_control *mc =
  1486. (struct soc_mixer_control *)kcontrol->private_value;
  1487. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  1488. unsigned int reg = mc->reg;
  1489. int min = mc->min;
  1490. int val = snd_soc_read(codec, reg);
  1491. ucontrol->value.integer.value[0] =
  1492. ((signed char)(val & 0xff))-min;
  1493. ucontrol->value.integer.value[1] =
  1494. ((signed char)((val >> 8) & 0xff))-min;
  1495. return 0;
  1496. }
  1497. EXPORT_SYMBOL_GPL(snd_soc_get_volsw_s8);
  1498. /**
  1499. * snd_soc_put_volsw_sgn - signed mixer put callback
  1500. * @kcontrol: mixer control
  1501. * @uinfo: control element information
  1502. *
  1503. * Callback to set the value of a signed mixer control.
  1504. *
  1505. * Returns 0 for success.
  1506. */
  1507. int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol,
  1508. struct snd_ctl_elem_value *ucontrol)
  1509. {
  1510. struct soc_mixer_control *mc =
  1511. (struct soc_mixer_control *)kcontrol->private_value;
  1512. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  1513. unsigned int reg = mc->reg;
  1514. int min = mc->min;
  1515. unsigned short val;
  1516. val = (ucontrol->value.integer.value[0]+min) & 0xff;
  1517. val |= ((ucontrol->value.integer.value[1]+min) & 0xff) << 8;
  1518. return snd_soc_update_bits(codec, reg, 0xffff, val);
  1519. }
  1520. EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8);
  1521. /**
  1522. * snd_soc_dai_set_sysclk - configure DAI system or master clock.
  1523. * @dai: DAI
  1524. * @clk_id: DAI specific clock ID
  1525. * @freq: new clock frequency in Hz
  1526. * @dir: new clock direction - input/output.
  1527. *
  1528. * Configures the DAI master (MCLK) or system (SYSCLK) clocking.
  1529. */
  1530. int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id,
  1531. unsigned int freq, int dir)
  1532. {
  1533. if (dai->dai_ops.set_sysclk)
  1534. return dai->dai_ops.set_sysclk(dai, clk_id, freq, dir);
  1535. else
  1536. return -EINVAL;
  1537. }
  1538. EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk);
  1539. /**
  1540. * snd_soc_dai_set_clkdiv - configure DAI clock dividers.
  1541. * @dai: DAI
  1542. * @clk_id: DAI specific clock divider ID
  1543. * @div: new clock divisor.
  1544. *
  1545. * Configures the clock dividers. This is used to derive the best DAI bit and
  1546. * frame clocks from the system or master clock. It's best to set the DAI bit
  1547. * and frame clocks as low as possible to save system power.
  1548. */
  1549. int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai,
  1550. int div_id, int div)
  1551. {
  1552. if (dai->dai_ops.set_clkdiv)
  1553. return dai->dai_ops.set_clkdiv(dai, div_id, div);
  1554. else
  1555. return -EINVAL;
  1556. }
  1557. EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv);
  1558. /**
  1559. * snd_soc_dai_set_pll - configure DAI PLL.
  1560. * @dai: DAI
  1561. * @pll_id: DAI specific PLL ID
  1562. * @freq_in: PLL input clock frequency in Hz
  1563. * @freq_out: requested PLL output clock frequency in Hz
  1564. *
  1565. * Configures and enables PLL to generate output clock based on input clock.
  1566. */
  1567. int snd_soc_dai_set_pll(struct snd_soc_dai *dai,
  1568. int pll_id, unsigned int freq_in, unsigned int freq_out)
  1569. {
  1570. if (dai->dai_ops.set_pll)
  1571. return dai->dai_ops.set_pll(dai, pll_id, freq_in, freq_out);
  1572. else
  1573. return -EINVAL;
  1574. }
  1575. EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll);
  1576. /**
  1577. * snd_soc_dai_set_fmt - configure DAI hardware audio format.
  1578. * @dai: DAI
  1579. * @clk_id: DAI specific clock ID
  1580. * @fmt: SND_SOC_DAIFMT_ format value.
  1581. *
  1582. * Configures the DAI hardware format and clocking.
  1583. */
  1584. int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
  1585. {
  1586. if (dai->dai_ops.set_fmt)
  1587. return dai->dai_ops.set_fmt(dai, fmt);
  1588. else
  1589. return -EINVAL;
  1590. }
  1591. EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt);
  1592. /**
  1593. * snd_soc_dai_set_tdm_slot - configure DAI TDM.
  1594. * @dai: DAI
  1595. * @mask: DAI specific mask representing used slots.
  1596. * @slots: Number of slots in use.
  1597. *
  1598. * Configures a DAI for TDM operation. Both mask and slots are codec and DAI
  1599. * specific.
  1600. */
  1601. int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,
  1602. unsigned int mask, int slots)
  1603. {
  1604. if (dai->dai_ops.set_sysclk)
  1605. return dai->dai_ops.set_tdm_slot(dai, mask, slots);
  1606. else
  1607. return -EINVAL;
  1608. }
  1609. EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot);
  1610. /**
  1611. * snd_soc_dai_set_tristate - configure DAI system or master clock.
  1612. * @dai: DAI
  1613. * @tristate: tristate enable
  1614. *
  1615. * Tristates the DAI so that others can use it.
  1616. */
  1617. int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate)
  1618. {
  1619. if (dai->dai_ops.set_sysclk)
  1620. return dai->dai_ops.set_tristate(dai, tristate);
  1621. else
  1622. return -EINVAL;
  1623. }
  1624. EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate);
  1625. /**
  1626. * snd_soc_dai_digital_mute - configure DAI system or master clock.
  1627. * @dai: DAI
  1628. * @mute: mute enable
  1629. *
  1630. * Mutes the DAI DAC.
  1631. */
  1632. int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute)
  1633. {
  1634. if (dai->dai_ops.digital_mute)
  1635. return dai->dai_ops.digital_mute(dai, mute);
  1636. else
  1637. return -EINVAL;
  1638. }
  1639. EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute);
  1640. static int __devinit snd_soc_init(void)
  1641. {
  1642. printk(KERN_INFO "ASoC version %s\n", SND_SOC_VERSION);
  1643. return platform_driver_register(&soc_driver);
  1644. }
  1645. static void snd_soc_exit(void)
  1646. {
  1647. platform_driver_unregister(&soc_driver);
  1648. }
  1649. module_init(snd_soc_init);
  1650. module_exit(snd_soc_exit);
  1651. /* Module information */
  1652. MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
  1653. MODULE_DESCRIPTION("ALSA SoC Core");
  1654. MODULE_LICENSE("GPL");
  1655. MODULE_ALIAS("platform:soc-audio");