soc-core.c 50 KB

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