soc-core.c 49 KB

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