soc-core.c 93 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577
  1. /*
  2. * soc-core.c -- ALSA SoC Audio Layer
  3. *
  4. * Copyright 2005 Wolfson Microelectronics PLC.
  5. * Copyright 2005 Openedhand Ltd.
  6. * Copyright (C) 2010 Slimlogic Ltd.
  7. * Copyright (C) 2010 Texas Instruments Inc.
  8. *
  9. * Author: Liam Girdwood <lrg@slimlogic.co.uk>
  10. * with code, comments and ideas from :-
  11. * Richard Purdie <richard@openedhand.com>
  12. *
  13. * This program is free software; you can redistribute it and/or modify it
  14. * under the terms of the GNU General Public License as published by the
  15. * Free Software Foundation; either version 2 of the License, or (at your
  16. * option) any later version.
  17. *
  18. * TODO:
  19. * o Add hw rules to enforce rates, etc.
  20. * o More testing with other codecs/machines.
  21. * o Add more codecs and platforms to ensure good API coverage.
  22. * o Support TDM on PCM and I2S
  23. */
  24. #include <linux/module.h>
  25. #include <linux/moduleparam.h>
  26. #include <linux/init.h>
  27. #include <linux/delay.h>
  28. #include <linux/pm.h>
  29. #include <linux/bitops.h>
  30. #include <linux/debugfs.h>
  31. #include <linux/platform_device.h>
  32. #include <linux/slab.h>
  33. #include <sound/ac97_codec.h>
  34. #include <sound/core.h>
  35. #include <sound/pcm.h>
  36. #include <sound/pcm_params.h>
  37. #include <sound/soc.h>
  38. #include <sound/initval.h>
  39. #define CREATE_TRACE_POINTS
  40. #include <trace/events/asoc.h>
  41. #define NAME_SIZE 32
  42. static DEFINE_MUTEX(pcm_mutex);
  43. static DECLARE_WAIT_QUEUE_HEAD(soc_pm_waitq);
  44. #ifdef CONFIG_DEBUG_FS
  45. static struct dentry *debugfs_root;
  46. #endif
  47. static DEFINE_MUTEX(client_mutex);
  48. static LIST_HEAD(card_list);
  49. static LIST_HEAD(dai_list);
  50. static LIST_HEAD(platform_list);
  51. static LIST_HEAD(codec_list);
  52. static int snd_soc_register_card(struct snd_soc_card *card);
  53. static int snd_soc_unregister_card(struct snd_soc_card *card);
  54. static int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num);
  55. /*
  56. * This is a timeout to do a DAPM powerdown after a stream is closed().
  57. * It can be used to eliminate pops between different playback streams, e.g.
  58. * between two audio tracks.
  59. */
  60. static int pmdown_time = 5000;
  61. module_param(pmdown_time, int, 0);
  62. MODULE_PARM_DESC(pmdown_time, "DAPM stream powerdown time (msecs)");
  63. /*
  64. * This function forces any delayed work to be queued and run.
  65. */
  66. static int run_delayed_work(struct delayed_work *dwork)
  67. {
  68. int ret;
  69. /* cancel any work waiting to be queued. */
  70. ret = cancel_delayed_work(dwork);
  71. /* if there was any work waiting then we run it now and
  72. * wait for it's completion */
  73. if (ret) {
  74. schedule_delayed_work(dwork, 0);
  75. flush_scheduled_work();
  76. }
  77. return ret;
  78. }
  79. /* codec register dump */
  80. static ssize_t soc_codec_reg_show(struct snd_soc_codec *codec, char *buf)
  81. {
  82. int ret, i, step = 1, count = 0;
  83. if (!codec->driver->reg_cache_size)
  84. return 0;
  85. if (codec->driver->reg_cache_step)
  86. step = codec->driver->reg_cache_step;
  87. count += sprintf(buf, "%s registers\n", codec->name);
  88. for (i = 0; i < codec->driver->reg_cache_size; i += step) {
  89. if (codec->driver->readable_register && !codec->driver->readable_register(i))
  90. continue;
  91. count += sprintf(buf + count, "%2x: ", i);
  92. if (count >= PAGE_SIZE - 1)
  93. break;
  94. if (codec->driver->display_register) {
  95. count += codec->driver->display_register(codec, buf + count,
  96. PAGE_SIZE - count, i);
  97. } else {
  98. /* If the read fails it's almost certainly due to
  99. * the register being volatile and the device being
  100. * powered off.
  101. */
  102. ret = codec->driver->read(codec, i);
  103. if (ret >= 0)
  104. count += snprintf(buf + count,
  105. PAGE_SIZE - count,
  106. "%4x", ret);
  107. else
  108. count += snprintf(buf + count,
  109. PAGE_SIZE - count,
  110. "<no data: %d>", ret);
  111. }
  112. if (count >= PAGE_SIZE - 1)
  113. break;
  114. count += snprintf(buf + count, PAGE_SIZE - count, "\n");
  115. if (count >= PAGE_SIZE - 1)
  116. break;
  117. }
  118. /* Truncate count; min() would cause a warning */
  119. if (count >= PAGE_SIZE)
  120. count = PAGE_SIZE - 1;
  121. return count;
  122. }
  123. static ssize_t codec_reg_show(struct device *dev,
  124. struct device_attribute *attr, char *buf)
  125. {
  126. struct snd_soc_pcm_runtime *rtd =
  127. container_of(dev, struct snd_soc_pcm_runtime, dev);
  128. return soc_codec_reg_show(rtd->codec, buf);
  129. }
  130. static DEVICE_ATTR(codec_reg, 0444, codec_reg_show, NULL);
  131. static ssize_t pmdown_time_show(struct device *dev,
  132. struct device_attribute *attr, char *buf)
  133. {
  134. struct snd_soc_pcm_runtime *rtd =
  135. container_of(dev, struct snd_soc_pcm_runtime, dev);
  136. return sprintf(buf, "%ld\n", rtd->pmdown_time);
  137. }
  138. static ssize_t pmdown_time_set(struct device *dev,
  139. struct device_attribute *attr,
  140. const char *buf, size_t count)
  141. {
  142. struct snd_soc_pcm_runtime *rtd =
  143. container_of(dev, struct snd_soc_pcm_runtime, dev);
  144. int ret;
  145. ret = strict_strtol(buf, 10, &rtd->pmdown_time);
  146. if (ret)
  147. return ret;
  148. return count;
  149. }
  150. static DEVICE_ATTR(pmdown_time, 0644, pmdown_time_show, pmdown_time_set);
  151. #ifdef CONFIG_DEBUG_FS
  152. static int codec_reg_open_file(struct inode *inode, struct file *file)
  153. {
  154. file->private_data = inode->i_private;
  155. return 0;
  156. }
  157. static ssize_t codec_reg_read_file(struct file *file, char __user *user_buf,
  158. size_t count, loff_t *ppos)
  159. {
  160. ssize_t ret;
  161. struct snd_soc_codec *codec = file->private_data;
  162. char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
  163. if (!buf)
  164. return -ENOMEM;
  165. ret = soc_codec_reg_show(codec, buf);
  166. if (ret >= 0)
  167. ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
  168. kfree(buf);
  169. return ret;
  170. }
  171. static ssize_t codec_reg_write_file(struct file *file,
  172. const char __user *user_buf, size_t count, loff_t *ppos)
  173. {
  174. char buf[32];
  175. int buf_size;
  176. char *start = buf;
  177. unsigned long reg, value;
  178. int step = 1;
  179. struct snd_soc_codec *codec = file->private_data;
  180. buf_size = min(count, (sizeof(buf)-1));
  181. if (copy_from_user(buf, user_buf, buf_size))
  182. return -EFAULT;
  183. buf[buf_size] = 0;
  184. if (codec->driver->reg_cache_step)
  185. step = codec->driver->reg_cache_step;
  186. while (*start == ' ')
  187. start++;
  188. reg = simple_strtoul(start, &start, 16);
  189. if ((reg >= codec->driver->reg_cache_size) || (reg % step))
  190. return -EINVAL;
  191. while (*start == ' ')
  192. start++;
  193. if (strict_strtoul(start, 16, &value))
  194. return -EINVAL;
  195. codec->driver->write(codec, reg, value);
  196. return buf_size;
  197. }
  198. static const struct file_operations codec_reg_fops = {
  199. .open = codec_reg_open_file,
  200. .read = codec_reg_read_file,
  201. .write = codec_reg_write_file,
  202. .llseek = default_llseek,
  203. };
  204. static void soc_init_codec_debugfs(struct snd_soc_codec *codec)
  205. {
  206. struct dentry *debugfs_card_root = codec->card->debugfs_card_root;
  207. codec->debugfs_codec_root = debugfs_create_dir(codec->name,
  208. debugfs_card_root);
  209. if (!codec->debugfs_codec_root) {
  210. printk(KERN_WARNING
  211. "ASoC: Failed to create codec debugfs directory\n");
  212. return;
  213. }
  214. codec->debugfs_reg = debugfs_create_file("codec_reg", 0644,
  215. codec->debugfs_codec_root,
  216. codec, &codec_reg_fops);
  217. if (!codec->debugfs_reg)
  218. printk(KERN_WARNING
  219. "ASoC: Failed to create codec register debugfs file\n");
  220. codec->dapm.debugfs_dapm = debugfs_create_dir("dapm",
  221. codec->debugfs_codec_root);
  222. if (!codec->dapm.debugfs_dapm)
  223. printk(KERN_WARNING
  224. "Failed to create DAPM debugfs directory\n");
  225. snd_soc_dapm_debugfs_init(&codec->dapm);
  226. }
  227. static void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec)
  228. {
  229. debugfs_remove_recursive(codec->debugfs_codec_root);
  230. }
  231. static ssize_t codec_list_read_file(struct file *file, char __user *user_buf,
  232. size_t count, loff_t *ppos)
  233. {
  234. char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
  235. ssize_t len, ret = 0;
  236. struct snd_soc_codec *codec;
  237. if (!buf)
  238. return -ENOMEM;
  239. list_for_each_entry(codec, &codec_list, list) {
  240. len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n",
  241. codec->name);
  242. if (len >= 0)
  243. ret += len;
  244. if (ret > PAGE_SIZE) {
  245. ret = PAGE_SIZE;
  246. break;
  247. }
  248. }
  249. if (ret >= 0)
  250. ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
  251. kfree(buf);
  252. return ret;
  253. }
  254. static const struct file_operations codec_list_fops = {
  255. .read = codec_list_read_file,
  256. .llseek = default_llseek,/* read accesses f_pos */
  257. };
  258. static ssize_t dai_list_read_file(struct file *file, char __user *user_buf,
  259. size_t count, loff_t *ppos)
  260. {
  261. char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
  262. ssize_t len, ret = 0;
  263. struct snd_soc_dai *dai;
  264. if (!buf)
  265. return -ENOMEM;
  266. list_for_each_entry(dai, &dai_list, list) {
  267. len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", dai->name);
  268. if (len >= 0)
  269. ret += len;
  270. if (ret > PAGE_SIZE) {
  271. ret = PAGE_SIZE;
  272. break;
  273. }
  274. }
  275. ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
  276. kfree(buf);
  277. return ret;
  278. }
  279. static const struct file_operations dai_list_fops = {
  280. .read = dai_list_read_file,
  281. .llseek = default_llseek,/* read accesses f_pos */
  282. };
  283. static ssize_t platform_list_read_file(struct file *file,
  284. char __user *user_buf,
  285. size_t count, loff_t *ppos)
  286. {
  287. char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
  288. ssize_t len, ret = 0;
  289. struct snd_soc_platform *platform;
  290. if (!buf)
  291. return -ENOMEM;
  292. list_for_each_entry(platform, &platform_list, list) {
  293. len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n",
  294. platform->name);
  295. if (len >= 0)
  296. ret += len;
  297. if (ret > PAGE_SIZE) {
  298. ret = PAGE_SIZE;
  299. break;
  300. }
  301. }
  302. ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
  303. kfree(buf);
  304. return ret;
  305. }
  306. static const struct file_operations platform_list_fops = {
  307. .read = platform_list_read_file,
  308. .llseek = default_llseek,/* read accesses f_pos */
  309. };
  310. static void soc_init_card_debugfs(struct snd_soc_card *card)
  311. {
  312. card->debugfs_card_root = debugfs_create_dir(card->name,
  313. debugfs_root);
  314. if (!card->debugfs_card_root) {
  315. dev_warn(card->dev,
  316. "ASoC: Failed to create codec debugfs directory\n");
  317. return;
  318. }
  319. card->debugfs_pop_time = debugfs_create_u32("dapm_pop_time", 0644,
  320. card->debugfs_card_root,
  321. &card->pop_time);
  322. if (!card->debugfs_pop_time)
  323. dev_warn(card->dev,
  324. "Failed to create pop time debugfs file\n");
  325. }
  326. static void soc_cleanup_card_debugfs(struct snd_soc_card *card)
  327. {
  328. debugfs_remove_recursive(card->debugfs_card_root);
  329. }
  330. #else
  331. static inline void soc_init_codec_debugfs(struct snd_soc_codec *codec)
  332. {
  333. }
  334. static inline void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec)
  335. {
  336. }
  337. static inline void soc_init_card_debugfs(struct snd_soc_card *card)
  338. {
  339. }
  340. static inline void soc_cleanup_card_debugfs(struct snd_soc_card *card)
  341. {
  342. }
  343. #endif
  344. #ifdef CONFIG_SND_SOC_AC97_BUS
  345. /* unregister ac97 codec */
  346. static int soc_ac97_dev_unregister(struct snd_soc_codec *codec)
  347. {
  348. if (codec->ac97->dev.bus)
  349. device_unregister(&codec->ac97->dev);
  350. return 0;
  351. }
  352. /* stop no dev release warning */
  353. static void soc_ac97_device_release(struct device *dev){}
  354. /* register ac97 codec to bus */
  355. static int soc_ac97_dev_register(struct snd_soc_codec *codec)
  356. {
  357. int err;
  358. codec->ac97->dev.bus = &ac97_bus_type;
  359. codec->ac97->dev.parent = codec->card->dev;
  360. codec->ac97->dev.release = soc_ac97_device_release;
  361. dev_set_name(&codec->ac97->dev, "%d-%d:%s",
  362. codec->card->snd_card->number, 0, codec->name);
  363. err = device_register(&codec->ac97->dev);
  364. if (err < 0) {
  365. snd_printk(KERN_ERR "Can't register ac97 bus\n");
  366. codec->ac97->dev.bus = NULL;
  367. return err;
  368. }
  369. return 0;
  370. }
  371. #endif
  372. static int soc_pcm_apply_symmetry(struct snd_pcm_substream *substream)
  373. {
  374. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  375. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  376. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  377. int ret;
  378. if (codec_dai->driver->symmetric_rates || cpu_dai->driver->symmetric_rates ||
  379. rtd->dai_link->symmetric_rates) {
  380. dev_dbg(&rtd->dev, "Symmetry forces %dHz rate\n",
  381. rtd->rate);
  382. ret = snd_pcm_hw_constraint_minmax(substream->runtime,
  383. SNDRV_PCM_HW_PARAM_RATE,
  384. rtd->rate,
  385. rtd->rate);
  386. if (ret < 0) {
  387. dev_err(&rtd->dev,
  388. "Unable to apply rate symmetry constraint: %d\n", ret);
  389. return ret;
  390. }
  391. }
  392. return 0;
  393. }
  394. /*
  395. * Called by ALSA when a PCM substream is opened, the runtime->hw record is
  396. * then initialized and any private data can be allocated. This also calls
  397. * startup for the cpu DAI, platform, machine and codec DAI.
  398. */
  399. static int soc_pcm_open(struct snd_pcm_substream *substream)
  400. {
  401. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  402. struct snd_pcm_runtime *runtime = substream->runtime;
  403. struct snd_soc_platform *platform = rtd->platform;
  404. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  405. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  406. struct snd_soc_dai_driver *cpu_dai_drv = cpu_dai->driver;
  407. struct snd_soc_dai_driver *codec_dai_drv = codec_dai->driver;
  408. int ret = 0;
  409. mutex_lock(&pcm_mutex);
  410. /* startup the audio subsystem */
  411. if (cpu_dai->driver->ops->startup) {
  412. ret = cpu_dai->driver->ops->startup(substream, cpu_dai);
  413. if (ret < 0) {
  414. printk(KERN_ERR "asoc: can't open interface %s\n",
  415. cpu_dai->name);
  416. goto out;
  417. }
  418. }
  419. if (platform->driver->ops->open) {
  420. ret = platform->driver->ops->open(substream);
  421. if (ret < 0) {
  422. printk(KERN_ERR "asoc: can't open platform %s\n", platform->name);
  423. goto platform_err;
  424. }
  425. }
  426. if (codec_dai->driver->ops->startup) {
  427. ret = codec_dai->driver->ops->startup(substream, codec_dai);
  428. if (ret < 0) {
  429. printk(KERN_ERR "asoc: can't open codec %s\n",
  430. codec_dai->name);
  431. goto codec_dai_err;
  432. }
  433. }
  434. if (rtd->dai_link->ops && rtd->dai_link->ops->startup) {
  435. ret = rtd->dai_link->ops->startup(substream);
  436. if (ret < 0) {
  437. printk(KERN_ERR "asoc: %s startup failed\n", rtd->dai_link->name);
  438. goto machine_err;
  439. }
  440. }
  441. /* Check that the codec and cpu DAIs are compatible */
  442. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  443. runtime->hw.rate_min =
  444. max(codec_dai_drv->playback.rate_min,
  445. cpu_dai_drv->playback.rate_min);
  446. runtime->hw.rate_max =
  447. min(codec_dai_drv->playback.rate_max,
  448. cpu_dai_drv->playback.rate_max);
  449. runtime->hw.channels_min =
  450. max(codec_dai_drv->playback.channels_min,
  451. cpu_dai_drv->playback.channels_min);
  452. runtime->hw.channels_max =
  453. min(codec_dai_drv->playback.channels_max,
  454. cpu_dai_drv->playback.channels_max);
  455. runtime->hw.formats =
  456. codec_dai_drv->playback.formats & cpu_dai_drv->playback.formats;
  457. runtime->hw.rates =
  458. codec_dai_drv->playback.rates & cpu_dai_drv->playback.rates;
  459. if (codec_dai_drv->playback.rates
  460. & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS))
  461. runtime->hw.rates |= cpu_dai_drv->playback.rates;
  462. if (cpu_dai_drv->playback.rates
  463. & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS))
  464. runtime->hw.rates |= codec_dai_drv->playback.rates;
  465. } else {
  466. runtime->hw.rate_min =
  467. max(codec_dai_drv->capture.rate_min,
  468. cpu_dai_drv->capture.rate_min);
  469. runtime->hw.rate_max =
  470. min(codec_dai_drv->capture.rate_max,
  471. cpu_dai_drv->capture.rate_max);
  472. runtime->hw.channels_min =
  473. max(codec_dai_drv->capture.channels_min,
  474. cpu_dai_drv->capture.channels_min);
  475. runtime->hw.channels_max =
  476. min(codec_dai_drv->capture.channels_max,
  477. cpu_dai_drv->capture.channels_max);
  478. runtime->hw.formats =
  479. codec_dai_drv->capture.formats & cpu_dai_drv->capture.formats;
  480. runtime->hw.rates =
  481. codec_dai_drv->capture.rates & cpu_dai_drv->capture.rates;
  482. if (codec_dai_drv->capture.rates
  483. & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS))
  484. runtime->hw.rates |= cpu_dai_drv->capture.rates;
  485. if (cpu_dai_drv->capture.rates
  486. & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS))
  487. runtime->hw.rates |= codec_dai_drv->capture.rates;
  488. }
  489. snd_pcm_limit_hw_rates(runtime);
  490. if (!runtime->hw.rates) {
  491. printk(KERN_ERR "asoc: %s <-> %s No matching rates\n",
  492. codec_dai->name, cpu_dai->name);
  493. goto config_err;
  494. }
  495. if (!runtime->hw.formats) {
  496. printk(KERN_ERR "asoc: %s <-> %s No matching formats\n",
  497. codec_dai->name, cpu_dai->name);
  498. goto config_err;
  499. }
  500. if (!runtime->hw.channels_min || !runtime->hw.channels_max) {
  501. printk(KERN_ERR "asoc: %s <-> %s No matching channels\n",
  502. codec_dai->name, cpu_dai->name);
  503. goto config_err;
  504. }
  505. /* Symmetry only applies if we've already got an active stream. */
  506. if (cpu_dai->active || codec_dai->active) {
  507. ret = soc_pcm_apply_symmetry(substream);
  508. if (ret != 0)
  509. goto config_err;
  510. }
  511. pr_debug("asoc: %s <-> %s info:\n",
  512. codec_dai->name, cpu_dai->name);
  513. pr_debug("asoc: rate mask 0x%x\n", runtime->hw.rates);
  514. pr_debug("asoc: min ch %d max ch %d\n", runtime->hw.channels_min,
  515. runtime->hw.channels_max);
  516. pr_debug("asoc: min rate %d max rate %d\n", runtime->hw.rate_min,
  517. runtime->hw.rate_max);
  518. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  519. cpu_dai->playback_active++;
  520. codec_dai->playback_active++;
  521. } else {
  522. cpu_dai->capture_active++;
  523. codec_dai->capture_active++;
  524. }
  525. cpu_dai->active++;
  526. codec_dai->active++;
  527. rtd->codec->active++;
  528. mutex_unlock(&pcm_mutex);
  529. return 0;
  530. config_err:
  531. if (rtd->dai_link->ops && rtd->dai_link->ops->shutdown)
  532. rtd->dai_link->ops->shutdown(substream);
  533. machine_err:
  534. if (codec_dai->driver->ops->shutdown)
  535. codec_dai->driver->ops->shutdown(substream, codec_dai);
  536. codec_dai_err:
  537. if (platform->driver->ops->close)
  538. platform->driver->ops->close(substream);
  539. platform_err:
  540. if (cpu_dai->driver->ops->shutdown)
  541. cpu_dai->driver->ops->shutdown(substream, cpu_dai);
  542. out:
  543. mutex_unlock(&pcm_mutex);
  544. return ret;
  545. }
  546. /*
  547. * Power down the audio subsystem pmdown_time msecs after close is called.
  548. * This is to ensure there are no pops or clicks in between any music tracks
  549. * due to DAPM power cycling.
  550. */
  551. static void close_delayed_work(struct work_struct *work)
  552. {
  553. struct snd_soc_pcm_runtime *rtd =
  554. container_of(work, struct snd_soc_pcm_runtime, delayed_work.work);
  555. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  556. mutex_lock(&pcm_mutex);
  557. pr_debug("pop wq checking: %s status: %s waiting: %s\n",
  558. codec_dai->driver->playback.stream_name,
  559. codec_dai->playback_active ? "active" : "inactive",
  560. codec_dai->pop_wait ? "yes" : "no");
  561. /* are we waiting on this codec DAI stream */
  562. if (codec_dai->pop_wait == 1) {
  563. codec_dai->pop_wait = 0;
  564. snd_soc_dapm_stream_event(rtd,
  565. codec_dai->driver->playback.stream_name,
  566. SND_SOC_DAPM_STREAM_STOP);
  567. }
  568. mutex_unlock(&pcm_mutex);
  569. }
  570. /*
  571. * Called by ALSA when a PCM substream is closed. Private data can be
  572. * freed here. The cpu DAI, codec DAI, machine and platform are also
  573. * shutdown.
  574. */
  575. static int soc_codec_close(struct snd_pcm_substream *substream)
  576. {
  577. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  578. struct snd_soc_platform *platform = rtd->platform;
  579. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  580. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  581. struct snd_soc_codec *codec = rtd->codec;
  582. mutex_lock(&pcm_mutex);
  583. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  584. cpu_dai->playback_active--;
  585. codec_dai->playback_active--;
  586. } else {
  587. cpu_dai->capture_active--;
  588. codec_dai->capture_active--;
  589. }
  590. cpu_dai->active--;
  591. codec_dai->active--;
  592. codec->active--;
  593. /* Muting the DAC suppresses artifacts caused during digital
  594. * shutdown, for example from stopping clocks.
  595. */
  596. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  597. snd_soc_dai_digital_mute(codec_dai, 1);
  598. if (cpu_dai->driver->ops->shutdown)
  599. cpu_dai->driver->ops->shutdown(substream, cpu_dai);
  600. if (codec_dai->driver->ops->shutdown)
  601. codec_dai->driver->ops->shutdown(substream, codec_dai);
  602. if (rtd->dai_link->ops && rtd->dai_link->ops->shutdown)
  603. rtd->dai_link->ops->shutdown(substream);
  604. if (platform->driver->ops->close)
  605. platform->driver->ops->close(substream);
  606. cpu_dai->runtime = NULL;
  607. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  608. /* start delayed pop wq here for playback streams */
  609. codec_dai->pop_wait = 1;
  610. schedule_delayed_work(&rtd->delayed_work,
  611. msecs_to_jiffies(rtd->pmdown_time));
  612. } else {
  613. /* capture streams can be powered down now */
  614. snd_soc_dapm_stream_event(rtd,
  615. codec_dai->driver->capture.stream_name,
  616. SND_SOC_DAPM_STREAM_STOP);
  617. }
  618. mutex_unlock(&pcm_mutex);
  619. return 0;
  620. }
  621. /*
  622. * Called by ALSA when the PCM substream is prepared, can set format, sample
  623. * rate, etc. This function is non atomic and can be called multiple times,
  624. * it can refer to the runtime info.
  625. */
  626. static int soc_pcm_prepare(struct snd_pcm_substream *substream)
  627. {
  628. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  629. struct snd_soc_platform *platform = rtd->platform;
  630. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  631. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  632. int ret = 0;
  633. mutex_lock(&pcm_mutex);
  634. if (rtd->dai_link->ops && rtd->dai_link->ops->prepare) {
  635. ret = rtd->dai_link->ops->prepare(substream);
  636. if (ret < 0) {
  637. printk(KERN_ERR "asoc: machine prepare error\n");
  638. goto out;
  639. }
  640. }
  641. if (platform->driver->ops->prepare) {
  642. ret = platform->driver->ops->prepare(substream);
  643. if (ret < 0) {
  644. printk(KERN_ERR "asoc: platform prepare error\n");
  645. goto out;
  646. }
  647. }
  648. if (codec_dai->driver->ops->prepare) {
  649. ret = codec_dai->driver->ops->prepare(substream, codec_dai);
  650. if (ret < 0) {
  651. printk(KERN_ERR "asoc: codec DAI prepare error\n");
  652. goto out;
  653. }
  654. }
  655. if (cpu_dai->driver->ops->prepare) {
  656. ret = cpu_dai->driver->ops->prepare(substream, cpu_dai);
  657. if (ret < 0) {
  658. printk(KERN_ERR "asoc: cpu DAI prepare error\n");
  659. goto out;
  660. }
  661. }
  662. /* cancel any delayed stream shutdown that is pending */
  663. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK &&
  664. codec_dai->pop_wait) {
  665. codec_dai->pop_wait = 0;
  666. cancel_delayed_work(&rtd->delayed_work);
  667. }
  668. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  669. snd_soc_dapm_stream_event(rtd,
  670. codec_dai->driver->playback.stream_name,
  671. SND_SOC_DAPM_STREAM_START);
  672. else
  673. snd_soc_dapm_stream_event(rtd,
  674. codec_dai->driver->capture.stream_name,
  675. SND_SOC_DAPM_STREAM_START);
  676. snd_soc_dai_digital_mute(codec_dai, 0);
  677. out:
  678. mutex_unlock(&pcm_mutex);
  679. return ret;
  680. }
  681. /*
  682. * Called by ALSA when the hardware params are set by application. This
  683. * function can also be called multiple times and can allocate buffers
  684. * (using snd_pcm_lib_* ). It's non-atomic.
  685. */
  686. static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
  687. struct snd_pcm_hw_params *params)
  688. {
  689. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  690. struct snd_soc_platform *platform = rtd->platform;
  691. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  692. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  693. int ret = 0;
  694. mutex_lock(&pcm_mutex);
  695. if (rtd->dai_link->ops && rtd->dai_link->ops->hw_params) {
  696. ret = rtd->dai_link->ops->hw_params(substream, params);
  697. if (ret < 0) {
  698. printk(KERN_ERR "asoc: machine hw_params failed\n");
  699. goto out;
  700. }
  701. }
  702. if (codec_dai->driver->ops->hw_params) {
  703. ret = codec_dai->driver->ops->hw_params(substream, params, codec_dai);
  704. if (ret < 0) {
  705. printk(KERN_ERR "asoc: can't set codec %s hw params\n",
  706. codec_dai->name);
  707. goto codec_err;
  708. }
  709. }
  710. if (cpu_dai->driver->ops->hw_params) {
  711. ret = cpu_dai->driver->ops->hw_params(substream, params, cpu_dai);
  712. if (ret < 0) {
  713. printk(KERN_ERR "asoc: interface %s hw params failed\n",
  714. cpu_dai->name);
  715. goto interface_err;
  716. }
  717. }
  718. if (platform->driver->ops->hw_params) {
  719. ret = platform->driver->ops->hw_params(substream, params);
  720. if (ret < 0) {
  721. printk(KERN_ERR "asoc: platform %s hw params failed\n",
  722. platform->name);
  723. goto platform_err;
  724. }
  725. }
  726. rtd->rate = params_rate(params);
  727. out:
  728. mutex_unlock(&pcm_mutex);
  729. return ret;
  730. platform_err:
  731. if (cpu_dai->driver->ops->hw_free)
  732. cpu_dai->driver->ops->hw_free(substream, cpu_dai);
  733. interface_err:
  734. if (codec_dai->driver->ops->hw_free)
  735. codec_dai->driver->ops->hw_free(substream, codec_dai);
  736. codec_err:
  737. if (rtd->dai_link->ops && rtd->dai_link->ops->hw_free)
  738. rtd->dai_link->ops->hw_free(substream);
  739. mutex_unlock(&pcm_mutex);
  740. return ret;
  741. }
  742. /*
  743. * Frees resources allocated by hw_params, can be called multiple times
  744. */
  745. static int soc_pcm_hw_free(struct snd_pcm_substream *substream)
  746. {
  747. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  748. struct snd_soc_platform *platform = rtd->platform;
  749. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  750. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  751. struct snd_soc_codec *codec = rtd->codec;
  752. mutex_lock(&pcm_mutex);
  753. /* apply codec digital mute */
  754. if (!codec->active)
  755. snd_soc_dai_digital_mute(codec_dai, 1);
  756. /* free any machine hw params */
  757. if (rtd->dai_link->ops && rtd->dai_link->ops->hw_free)
  758. rtd->dai_link->ops->hw_free(substream);
  759. /* free any DMA resources */
  760. if (platform->driver->ops->hw_free)
  761. platform->driver->ops->hw_free(substream);
  762. /* now free hw params for the DAIs */
  763. if (codec_dai->driver->ops->hw_free)
  764. codec_dai->driver->ops->hw_free(substream, codec_dai);
  765. if (cpu_dai->driver->ops->hw_free)
  766. cpu_dai->driver->ops->hw_free(substream, cpu_dai);
  767. mutex_unlock(&pcm_mutex);
  768. return 0;
  769. }
  770. static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
  771. {
  772. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  773. struct snd_soc_platform *platform = rtd->platform;
  774. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  775. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  776. int ret;
  777. if (codec_dai->driver->ops->trigger) {
  778. ret = codec_dai->driver->ops->trigger(substream, cmd, codec_dai);
  779. if (ret < 0)
  780. return ret;
  781. }
  782. if (platform->driver->ops->trigger) {
  783. ret = platform->driver->ops->trigger(substream, cmd);
  784. if (ret < 0)
  785. return ret;
  786. }
  787. if (cpu_dai->driver->ops->trigger) {
  788. ret = cpu_dai->driver->ops->trigger(substream, cmd, cpu_dai);
  789. if (ret < 0)
  790. return ret;
  791. }
  792. return 0;
  793. }
  794. /*
  795. * soc level wrapper for pointer callback
  796. * If cpu_dai, codec_dai, platform driver has the delay callback, than
  797. * the runtime->delay will be updated accordingly.
  798. */
  799. static snd_pcm_uframes_t soc_pcm_pointer(struct snd_pcm_substream *substream)
  800. {
  801. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  802. struct snd_soc_platform *platform = rtd->platform;
  803. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  804. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  805. struct snd_pcm_runtime *runtime = substream->runtime;
  806. snd_pcm_uframes_t offset = 0;
  807. snd_pcm_sframes_t delay = 0;
  808. if (platform->driver->ops->pointer)
  809. offset = platform->driver->ops->pointer(substream);
  810. if (cpu_dai->driver->ops->delay)
  811. delay += cpu_dai->driver->ops->delay(substream, cpu_dai);
  812. if (codec_dai->driver->ops->delay)
  813. delay += codec_dai->driver->ops->delay(substream, codec_dai);
  814. if (platform->driver->delay)
  815. delay += platform->driver->delay(substream, codec_dai);
  816. runtime->delay = delay;
  817. return offset;
  818. }
  819. /* ASoC PCM operations */
  820. static struct snd_pcm_ops soc_pcm_ops = {
  821. .open = soc_pcm_open,
  822. .close = soc_codec_close,
  823. .hw_params = soc_pcm_hw_params,
  824. .hw_free = soc_pcm_hw_free,
  825. .prepare = soc_pcm_prepare,
  826. .trigger = soc_pcm_trigger,
  827. .pointer = soc_pcm_pointer,
  828. };
  829. #ifdef CONFIG_PM
  830. /* powers down audio subsystem for suspend */
  831. static int soc_suspend(struct device *dev)
  832. {
  833. struct platform_device *pdev = to_platform_device(dev);
  834. struct snd_soc_card *card = platform_get_drvdata(pdev);
  835. struct snd_soc_codec *codec;
  836. int i;
  837. /* If the initialization of this soc device failed, there is no codec
  838. * associated with it. Just bail out in this case.
  839. */
  840. if (list_empty(&card->codec_dev_list))
  841. return 0;
  842. /* Due to the resume being scheduled into a workqueue we could
  843. * suspend before that's finished - wait for it to complete.
  844. */
  845. snd_power_lock(card->snd_card);
  846. snd_power_wait(card->snd_card, SNDRV_CTL_POWER_D0);
  847. snd_power_unlock(card->snd_card);
  848. /* we're going to block userspace touching us until resume completes */
  849. snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D3hot);
  850. /* mute any active DACs */
  851. for (i = 0; i < card->num_rtd; i++) {
  852. struct snd_soc_dai *dai = card->rtd[i].codec_dai;
  853. struct snd_soc_dai_driver *drv = dai->driver;
  854. if (card->rtd[i].dai_link->ignore_suspend)
  855. continue;
  856. if (drv->ops->digital_mute && dai->playback_active)
  857. drv->ops->digital_mute(dai, 1);
  858. }
  859. /* suspend all pcms */
  860. for (i = 0; i < card->num_rtd; i++) {
  861. if (card->rtd[i].dai_link->ignore_suspend)
  862. continue;
  863. snd_pcm_suspend_all(card->rtd[i].pcm);
  864. }
  865. if (card->suspend_pre)
  866. card->suspend_pre(pdev, PMSG_SUSPEND);
  867. for (i = 0; i < card->num_rtd; i++) {
  868. struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
  869. struct snd_soc_platform *platform = card->rtd[i].platform;
  870. if (card->rtd[i].dai_link->ignore_suspend)
  871. continue;
  872. if (cpu_dai->driver->suspend && !cpu_dai->driver->ac97_control)
  873. cpu_dai->driver->suspend(cpu_dai);
  874. if (platform->driver->suspend && !platform->suspended) {
  875. platform->driver->suspend(cpu_dai);
  876. platform->suspended = 1;
  877. }
  878. }
  879. /* close any waiting streams and save state */
  880. for (i = 0; i < card->num_rtd; i++) {
  881. run_delayed_work(&card->rtd[i].delayed_work);
  882. card->rtd[i].codec->dapm.suspend_bias_level = card->rtd[i].codec->dapm.bias_level;
  883. }
  884. for (i = 0; i < card->num_rtd; i++) {
  885. struct snd_soc_dai_driver *driver = card->rtd[i].codec_dai->driver;
  886. if (card->rtd[i].dai_link->ignore_suspend)
  887. continue;
  888. if (driver->playback.stream_name != NULL)
  889. snd_soc_dapm_stream_event(&card->rtd[i], driver->playback.stream_name,
  890. SND_SOC_DAPM_STREAM_SUSPEND);
  891. if (driver->capture.stream_name != NULL)
  892. snd_soc_dapm_stream_event(&card->rtd[i], driver->capture.stream_name,
  893. SND_SOC_DAPM_STREAM_SUSPEND);
  894. }
  895. /* suspend all CODECs */
  896. list_for_each_entry(codec, &card->codec_dev_list, card_list) {
  897. /* If there are paths active then the CODEC will be held with
  898. * bias _ON and should not be suspended. */
  899. if (!codec->suspended && codec->driver->suspend) {
  900. switch (codec->dapm.bias_level) {
  901. case SND_SOC_BIAS_STANDBY:
  902. case SND_SOC_BIAS_OFF:
  903. codec->driver->suspend(codec, PMSG_SUSPEND);
  904. codec->suspended = 1;
  905. break;
  906. default:
  907. dev_dbg(codec->dev, "CODEC is on over suspend\n");
  908. break;
  909. }
  910. }
  911. }
  912. for (i = 0; i < card->num_rtd; i++) {
  913. struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
  914. if (card->rtd[i].dai_link->ignore_suspend)
  915. continue;
  916. if (cpu_dai->driver->suspend && cpu_dai->driver->ac97_control)
  917. cpu_dai->driver->suspend(cpu_dai);
  918. }
  919. if (card->suspend_post)
  920. card->suspend_post(pdev, PMSG_SUSPEND);
  921. return 0;
  922. }
  923. /* deferred resume work, so resume can complete before we finished
  924. * setting our codec back up, which can be very slow on I2C
  925. */
  926. static void soc_resume_deferred(struct work_struct *work)
  927. {
  928. struct snd_soc_card *card =
  929. container_of(work, struct snd_soc_card, deferred_resume_work);
  930. struct platform_device *pdev = to_platform_device(card->dev);
  931. struct snd_soc_codec *codec;
  932. int i;
  933. /* our power state is still SNDRV_CTL_POWER_D3hot from suspend time,
  934. * so userspace apps are blocked from touching us
  935. */
  936. dev_dbg(card->dev, "starting resume work\n");
  937. /* Bring us up into D2 so that DAPM starts enabling things */
  938. snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D2);
  939. if (card->resume_pre)
  940. card->resume_pre(pdev);
  941. /* resume AC97 DAIs */
  942. for (i = 0; i < card->num_rtd; i++) {
  943. struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
  944. if (card->rtd[i].dai_link->ignore_suspend)
  945. continue;
  946. if (cpu_dai->driver->resume && cpu_dai->driver->ac97_control)
  947. cpu_dai->driver->resume(cpu_dai);
  948. }
  949. list_for_each_entry(codec, &card->codec_dev_list, card_list) {
  950. /* If the CODEC was idle over suspend then it will have been
  951. * left with bias OFF or STANDBY and suspended so we must now
  952. * resume. Otherwise the suspend was suppressed.
  953. */
  954. if (codec->driver->resume && codec->suspended) {
  955. switch (codec->dapm.bias_level) {
  956. case SND_SOC_BIAS_STANDBY:
  957. case SND_SOC_BIAS_OFF:
  958. codec->driver->resume(codec);
  959. codec->suspended = 0;
  960. break;
  961. default:
  962. dev_dbg(codec->dev, "CODEC was on over suspend\n");
  963. break;
  964. }
  965. }
  966. }
  967. for (i = 0; i < card->num_rtd; i++) {
  968. struct snd_soc_dai_driver *driver = card->rtd[i].codec_dai->driver;
  969. if (card->rtd[i].dai_link->ignore_suspend)
  970. continue;
  971. if (driver->playback.stream_name != NULL)
  972. snd_soc_dapm_stream_event(&card->rtd[i], driver->playback.stream_name,
  973. SND_SOC_DAPM_STREAM_RESUME);
  974. if (driver->capture.stream_name != NULL)
  975. snd_soc_dapm_stream_event(&card->rtd[i], driver->capture.stream_name,
  976. SND_SOC_DAPM_STREAM_RESUME);
  977. }
  978. /* unmute any active DACs */
  979. for (i = 0; i < card->num_rtd; i++) {
  980. struct snd_soc_dai *dai = card->rtd[i].codec_dai;
  981. struct snd_soc_dai_driver *drv = dai->driver;
  982. if (card->rtd[i].dai_link->ignore_suspend)
  983. continue;
  984. if (drv->ops->digital_mute && dai->playback_active)
  985. drv->ops->digital_mute(dai, 0);
  986. }
  987. for (i = 0; i < card->num_rtd; i++) {
  988. struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
  989. struct snd_soc_platform *platform = card->rtd[i].platform;
  990. if (card->rtd[i].dai_link->ignore_suspend)
  991. continue;
  992. if (cpu_dai->driver->resume && !cpu_dai->driver->ac97_control)
  993. cpu_dai->driver->resume(cpu_dai);
  994. if (platform->driver->resume && platform->suspended) {
  995. platform->driver->resume(cpu_dai);
  996. platform->suspended = 0;
  997. }
  998. }
  999. if (card->resume_post)
  1000. card->resume_post(pdev);
  1001. dev_dbg(card->dev, "resume work completed\n");
  1002. /* userspace can access us now we are back as we were before */
  1003. snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D0);
  1004. }
  1005. /* powers up audio subsystem after a suspend */
  1006. static int soc_resume(struct device *dev)
  1007. {
  1008. struct platform_device *pdev = to_platform_device(dev);
  1009. struct snd_soc_card *card = platform_get_drvdata(pdev);
  1010. int i;
  1011. /* AC97 devices might have other drivers hanging off them so
  1012. * need to resume immediately. Other drivers don't have that
  1013. * problem and may take a substantial amount of time to resume
  1014. * due to I/O costs and anti-pop so handle them out of line.
  1015. */
  1016. for (i = 0; i < card->num_rtd; i++) {
  1017. struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
  1018. if (cpu_dai->driver->ac97_control) {
  1019. dev_dbg(dev, "Resuming AC97 immediately\n");
  1020. soc_resume_deferred(&card->deferred_resume_work);
  1021. } else {
  1022. dev_dbg(dev, "Scheduling resume work\n");
  1023. if (!schedule_work(&card->deferred_resume_work))
  1024. dev_err(dev, "resume work item may be lost\n");
  1025. }
  1026. }
  1027. return 0;
  1028. }
  1029. #else
  1030. #define soc_suspend NULL
  1031. #define soc_resume NULL
  1032. #endif
  1033. static struct snd_soc_dai_ops null_dai_ops = {
  1034. };
  1035. static int soc_bind_dai_link(struct snd_soc_card *card, int num)
  1036. {
  1037. struct snd_soc_dai_link *dai_link = &card->dai_link[num];
  1038. struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
  1039. struct snd_soc_codec *codec;
  1040. struct snd_soc_platform *platform;
  1041. struct snd_soc_dai *codec_dai, *cpu_dai;
  1042. if (rtd->complete)
  1043. return 1;
  1044. dev_dbg(card->dev, "binding %s at idx %d\n", dai_link->name, num);
  1045. /* do we already have the CPU DAI for this link ? */
  1046. if (rtd->cpu_dai) {
  1047. goto find_codec;
  1048. }
  1049. /* no, then find CPU DAI from registered DAIs*/
  1050. list_for_each_entry(cpu_dai, &dai_list, list) {
  1051. if (!strcmp(cpu_dai->name, dai_link->cpu_dai_name)) {
  1052. if (!try_module_get(cpu_dai->dev->driver->owner))
  1053. return -ENODEV;
  1054. rtd->cpu_dai = cpu_dai;
  1055. goto find_codec;
  1056. }
  1057. }
  1058. dev_dbg(card->dev, "CPU DAI %s not registered\n",
  1059. dai_link->cpu_dai_name);
  1060. find_codec:
  1061. /* do we already have the CODEC for this link ? */
  1062. if (rtd->codec) {
  1063. goto find_platform;
  1064. }
  1065. /* no, then find CODEC from registered CODECs*/
  1066. list_for_each_entry(codec, &codec_list, list) {
  1067. if (!strcmp(codec->name, dai_link->codec_name)) {
  1068. rtd->codec = codec;
  1069. if (!try_module_get(codec->dev->driver->owner))
  1070. return -ENODEV;
  1071. /* CODEC found, so find CODEC DAI from registered DAIs from this CODEC*/
  1072. list_for_each_entry(codec_dai, &dai_list, list) {
  1073. if (codec->dev == codec_dai->dev &&
  1074. !strcmp(codec_dai->name, dai_link->codec_dai_name)) {
  1075. rtd->codec_dai = codec_dai;
  1076. goto find_platform;
  1077. }
  1078. }
  1079. dev_dbg(card->dev, "CODEC DAI %s not registered\n",
  1080. dai_link->codec_dai_name);
  1081. goto find_platform;
  1082. }
  1083. }
  1084. dev_dbg(card->dev, "CODEC %s not registered\n",
  1085. dai_link->codec_name);
  1086. find_platform:
  1087. /* do we already have the CODEC DAI for this link ? */
  1088. if (rtd->platform) {
  1089. goto out;
  1090. }
  1091. /* no, then find CPU DAI from registered DAIs*/
  1092. list_for_each_entry(platform, &platform_list, list) {
  1093. if (!strcmp(platform->name, dai_link->platform_name)) {
  1094. if (!try_module_get(platform->dev->driver->owner))
  1095. return -ENODEV;
  1096. rtd->platform = platform;
  1097. goto out;
  1098. }
  1099. }
  1100. dev_dbg(card->dev, "platform %s not registered\n",
  1101. dai_link->platform_name);
  1102. return 0;
  1103. out:
  1104. /* mark rtd as complete if we found all 4 of our client devices */
  1105. if (rtd->codec && rtd->codec_dai && rtd->platform && rtd->cpu_dai) {
  1106. rtd->complete = 1;
  1107. card->num_rtd++;
  1108. }
  1109. return 1;
  1110. }
  1111. static void soc_remove_dai_link(struct snd_soc_card *card, int num)
  1112. {
  1113. struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
  1114. struct snd_soc_codec *codec = rtd->codec;
  1115. struct snd_soc_platform *platform = rtd->platform;
  1116. struct snd_soc_dai *codec_dai = rtd->codec_dai, *cpu_dai = rtd->cpu_dai;
  1117. int err;
  1118. /* unregister the rtd device */
  1119. if (rtd->dev_registered) {
  1120. device_remove_file(&rtd->dev, &dev_attr_pmdown_time);
  1121. device_unregister(&rtd->dev);
  1122. rtd->dev_registered = 0;
  1123. }
  1124. /* remove the CODEC DAI */
  1125. if (codec_dai && codec_dai->probed) {
  1126. if (codec_dai->driver->remove) {
  1127. err = codec_dai->driver->remove(codec_dai);
  1128. if (err < 0)
  1129. printk(KERN_ERR "asoc: failed to remove %s\n", codec_dai->name);
  1130. }
  1131. codec_dai->probed = 0;
  1132. list_del(&codec_dai->card_list);
  1133. }
  1134. /* remove the platform */
  1135. if (platform && platform->probed) {
  1136. if (platform->driver->remove) {
  1137. err = platform->driver->remove(platform);
  1138. if (err < 0)
  1139. printk(KERN_ERR "asoc: failed to remove %s\n", platform->name);
  1140. }
  1141. platform->probed = 0;
  1142. list_del(&platform->card_list);
  1143. module_put(platform->dev->driver->owner);
  1144. }
  1145. /* remove the CODEC */
  1146. if (codec && codec->probed) {
  1147. if (codec->driver->remove) {
  1148. err = codec->driver->remove(codec);
  1149. if (err < 0)
  1150. printk(KERN_ERR "asoc: failed to remove %s\n", codec->name);
  1151. }
  1152. /* Make sure all DAPM widgets are freed */
  1153. snd_soc_dapm_free(&codec->dapm);
  1154. soc_cleanup_codec_debugfs(codec);
  1155. device_remove_file(&rtd->dev, &dev_attr_codec_reg);
  1156. codec->probed = 0;
  1157. list_del(&codec->card_list);
  1158. module_put(codec->dev->driver->owner);
  1159. }
  1160. /* remove the cpu_dai */
  1161. if (cpu_dai && cpu_dai->probed) {
  1162. if (cpu_dai->driver->remove) {
  1163. err = cpu_dai->driver->remove(cpu_dai);
  1164. if (err < 0)
  1165. printk(KERN_ERR "asoc: failed to remove %s\n", cpu_dai->name);
  1166. }
  1167. cpu_dai->probed = 0;
  1168. list_del(&cpu_dai->card_list);
  1169. module_put(cpu_dai->dev->driver->owner);
  1170. }
  1171. }
  1172. static void soc_set_name_prefix(struct snd_soc_card *card,
  1173. struct snd_soc_codec *codec)
  1174. {
  1175. int i;
  1176. if (card->prefix_map == NULL)
  1177. return;
  1178. for (i = 0; i < card->num_prefixes; i++) {
  1179. struct snd_soc_prefix_map *map = &card->prefix_map[i];
  1180. if (map->dev_name && !strcmp(codec->name, map->dev_name)) {
  1181. codec->name_prefix = map->name_prefix;
  1182. break;
  1183. }
  1184. }
  1185. }
  1186. static void rtd_release(struct device *dev) {}
  1187. static int soc_probe_dai_link(struct snd_soc_card *card, int num)
  1188. {
  1189. struct snd_soc_dai_link *dai_link = &card->dai_link[num];
  1190. struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
  1191. struct snd_soc_codec *codec = rtd->codec;
  1192. struct snd_soc_platform *platform = rtd->platform;
  1193. struct snd_soc_dai *codec_dai = rtd->codec_dai, *cpu_dai = rtd->cpu_dai;
  1194. const char *temp;
  1195. int ret;
  1196. dev_dbg(card->dev, "probe %s dai link %d\n", card->name, num);
  1197. /* config components */
  1198. codec_dai->codec = codec;
  1199. codec->card = card;
  1200. cpu_dai->platform = platform;
  1201. rtd->card = card;
  1202. rtd->dev.parent = card->dev;
  1203. codec_dai->card = card;
  1204. cpu_dai->card = card;
  1205. /* set default power off timeout */
  1206. rtd->pmdown_time = pmdown_time;
  1207. /* probe the cpu_dai */
  1208. if (!cpu_dai->probed) {
  1209. if (cpu_dai->driver->probe) {
  1210. ret = cpu_dai->driver->probe(cpu_dai);
  1211. if (ret < 0) {
  1212. printk(KERN_ERR "asoc: failed to probe CPU DAI %s\n",
  1213. cpu_dai->name);
  1214. return ret;
  1215. }
  1216. }
  1217. cpu_dai->probed = 1;
  1218. /* mark cpu_dai as probed and add to card cpu_dai list */
  1219. list_add(&cpu_dai->card_list, &card->dai_dev_list);
  1220. }
  1221. /* probe the CODEC */
  1222. if (!codec->probed) {
  1223. codec->dapm.card = card;
  1224. soc_set_name_prefix(card, codec);
  1225. if (codec->driver->probe) {
  1226. ret = codec->driver->probe(codec);
  1227. if (ret < 0) {
  1228. printk(KERN_ERR "asoc: failed to probe CODEC %s\n",
  1229. codec->name);
  1230. return ret;
  1231. }
  1232. }
  1233. soc_init_codec_debugfs(codec);
  1234. /* mark codec as probed and add to card codec list */
  1235. codec->probed = 1;
  1236. list_add(&codec->card_list, &card->codec_dev_list);
  1237. }
  1238. /* probe the platform */
  1239. if (!platform->probed) {
  1240. if (platform->driver->probe) {
  1241. ret = platform->driver->probe(platform);
  1242. if (ret < 0) {
  1243. printk(KERN_ERR "asoc: failed to probe platform %s\n",
  1244. platform->name);
  1245. return ret;
  1246. }
  1247. }
  1248. /* mark platform as probed and add to card platform list */
  1249. platform->probed = 1;
  1250. list_add(&platform->card_list, &card->platform_dev_list);
  1251. }
  1252. /* probe the CODEC DAI */
  1253. if (!codec_dai->probed) {
  1254. if (codec_dai->driver->probe) {
  1255. ret = codec_dai->driver->probe(codec_dai);
  1256. if (ret < 0) {
  1257. printk(KERN_ERR "asoc: failed to probe CODEC DAI %s\n",
  1258. codec_dai->name);
  1259. return ret;
  1260. }
  1261. }
  1262. /* mark cpu_dai as probed and add to card cpu_dai list */
  1263. codec_dai->probed = 1;
  1264. list_add(&codec_dai->card_list, &card->dai_dev_list);
  1265. }
  1266. /* DAPM dai link stream work */
  1267. INIT_DELAYED_WORK(&rtd->delayed_work, close_delayed_work);
  1268. /* now that all clients have probed, initialise the DAI link */
  1269. if (dai_link->init) {
  1270. /* machine controls, routes and widgets are not prefixed */
  1271. temp = rtd->codec->name_prefix;
  1272. rtd->codec->name_prefix = NULL;
  1273. ret = dai_link->init(rtd);
  1274. if (ret < 0) {
  1275. printk(KERN_ERR "asoc: failed to init %s\n", dai_link->stream_name);
  1276. return ret;
  1277. }
  1278. rtd->codec->name_prefix = temp;
  1279. }
  1280. /* Make sure all DAPM widgets are instantiated */
  1281. snd_soc_dapm_new_widgets(&codec->dapm);
  1282. snd_soc_dapm_sync(&codec->dapm);
  1283. /* register the rtd device */
  1284. rtd->dev.release = rtd_release;
  1285. rtd->dev.init_name = dai_link->name;
  1286. ret = device_register(&rtd->dev);
  1287. if (ret < 0) {
  1288. printk(KERN_ERR "asoc: failed to register DAI runtime device %d\n", ret);
  1289. return ret;
  1290. }
  1291. rtd->dev_registered = 1;
  1292. ret = device_create_file(&rtd->dev, &dev_attr_pmdown_time);
  1293. if (ret < 0)
  1294. printk(KERN_WARNING "asoc: failed to add pmdown_time sysfs\n");
  1295. /* add DAPM sysfs entries for this codec */
  1296. ret = snd_soc_dapm_sys_add(&rtd->dev);
  1297. if (ret < 0)
  1298. printk(KERN_WARNING "asoc: failed to add codec dapm sysfs entries\n");
  1299. /* add codec sysfs entries */
  1300. ret = device_create_file(&rtd->dev, &dev_attr_codec_reg);
  1301. if (ret < 0)
  1302. printk(KERN_WARNING "asoc: failed to add codec sysfs files\n");
  1303. /* create the pcm */
  1304. ret = soc_new_pcm(rtd, num);
  1305. if (ret < 0) {
  1306. printk(KERN_ERR "asoc: can't create pcm %s\n", dai_link->stream_name);
  1307. return ret;
  1308. }
  1309. /* add platform data for AC97 devices */
  1310. if (rtd->codec_dai->driver->ac97_control)
  1311. snd_ac97_dev_add_pdata(codec->ac97, rtd->cpu_dai->ac97_pdata);
  1312. return 0;
  1313. }
  1314. #ifdef CONFIG_SND_SOC_AC97_BUS
  1315. static int soc_register_ac97_dai_link(struct snd_soc_pcm_runtime *rtd)
  1316. {
  1317. int ret;
  1318. /* Only instantiate AC97 if not already done by the adaptor
  1319. * for the generic AC97 subsystem.
  1320. */
  1321. if (rtd->codec_dai->driver->ac97_control && !rtd->codec->ac97_registered) {
  1322. /*
  1323. * It is possible that the AC97 device is already registered to
  1324. * the device subsystem. This happens when the device is created
  1325. * via snd_ac97_mixer(). Currently only SoC codec that does so
  1326. * is the generic AC97 glue but others migh emerge.
  1327. *
  1328. * In those cases we don't try to register the device again.
  1329. */
  1330. if (!rtd->codec->ac97_created)
  1331. return 0;
  1332. ret = soc_ac97_dev_register(rtd->codec);
  1333. if (ret < 0) {
  1334. printk(KERN_ERR "asoc: AC97 device register failed\n");
  1335. return ret;
  1336. }
  1337. rtd->codec->ac97_registered = 1;
  1338. }
  1339. return 0;
  1340. }
  1341. static void soc_unregister_ac97_dai_link(struct snd_soc_codec *codec)
  1342. {
  1343. if (codec->ac97_registered) {
  1344. soc_ac97_dev_unregister(codec);
  1345. codec->ac97_registered = 0;
  1346. }
  1347. }
  1348. #endif
  1349. static int soc_probe_aux_dev(struct snd_soc_card *card, int num)
  1350. {
  1351. struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num];
  1352. struct snd_soc_pcm_runtime *rtd = &card->rtd_aux[num];
  1353. struct snd_soc_codec *codec;
  1354. const char *temp;
  1355. int ret = -ENODEV;
  1356. /* find CODEC from registered CODECs*/
  1357. list_for_each_entry(codec, &codec_list, list) {
  1358. if (!strcmp(codec->name, aux_dev->codec_name)) {
  1359. if (codec->probed) {
  1360. dev_err(codec->dev,
  1361. "asoc: codec already probed");
  1362. ret = -EBUSY;
  1363. goto out;
  1364. }
  1365. goto found;
  1366. }
  1367. }
  1368. /* codec not found */
  1369. dev_err(card->dev, "asoc: codec %s not found", aux_dev->codec_name);
  1370. goto out;
  1371. found:
  1372. if (!try_module_get(codec->dev->driver->owner))
  1373. return -ENODEV;
  1374. codec->card = card;
  1375. codec->dapm.card = card;
  1376. soc_set_name_prefix(card, codec);
  1377. if (codec->driver->probe) {
  1378. ret = codec->driver->probe(codec);
  1379. if (ret < 0) {
  1380. dev_err(codec->dev, "asoc: failed to probe CODEC");
  1381. return ret;
  1382. }
  1383. }
  1384. soc_init_codec_debugfs(codec);
  1385. /* mark codec as probed and add to card codec list */
  1386. codec->probed = 1;
  1387. list_add(&codec->card_list, &card->codec_dev_list);
  1388. /* now that all clients have probed, initialise the DAI link */
  1389. if (aux_dev->init) {
  1390. /* machine controls, routes and widgets are not prefixed */
  1391. temp = codec->name_prefix;
  1392. codec->name_prefix = NULL;
  1393. ret = aux_dev->init(&codec->dapm);
  1394. if (ret < 0) {
  1395. dev_err(codec->dev,
  1396. "asoc: failed to init %s\n", aux_dev->name);
  1397. return ret;
  1398. }
  1399. codec->name_prefix = temp;
  1400. }
  1401. /* Make sure all DAPM widgets are instantiated */
  1402. snd_soc_dapm_new_widgets(&codec->dapm);
  1403. snd_soc_dapm_sync(&codec->dapm);
  1404. /* register the rtd device */
  1405. rtd->codec = codec;
  1406. rtd->card = card;
  1407. rtd->dev.parent = card->dev;
  1408. rtd->dev.release = rtd_release;
  1409. rtd->dev.init_name = aux_dev->name;
  1410. ret = device_register(&rtd->dev);
  1411. if (ret < 0) {
  1412. dev_err(codec->dev,
  1413. "asoc: failed to register aux runtime device %d\n",
  1414. ret);
  1415. return ret;
  1416. }
  1417. rtd->dev_registered = 1;
  1418. /* add DAPM sysfs entries for this codec */
  1419. ret = snd_soc_dapm_sys_add(&rtd->dev);
  1420. if (ret < 0)
  1421. dev_err(codec->dev,
  1422. "asoc: failed to add codec dapm sysfs entries\n");
  1423. /* add codec sysfs entries */
  1424. ret = device_create_file(&rtd->dev, &dev_attr_codec_reg);
  1425. if (ret < 0)
  1426. dev_err(codec->dev, "asoc: failed to add codec sysfs files\n");
  1427. out:
  1428. return ret;
  1429. }
  1430. static void soc_remove_aux_dev(struct snd_soc_card *card, int num)
  1431. {
  1432. struct snd_soc_pcm_runtime *rtd = &card->rtd_aux[num];
  1433. struct snd_soc_codec *codec = rtd->codec;
  1434. int err;
  1435. /* unregister the rtd device */
  1436. if (rtd->dev_registered) {
  1437. device_unregister(&rtd->dev);
  1438. rtd->dev_registered = 0;
  1439. }
  1440. /* remove the CODEC */
  1441. if (codec && codec->probed) {
  1442. if (codec->driver->remove) {
  1443. err = codec->driver->remove(codec);
  1444. if (err < 0)
  1445. dev_err(codec->dev,
  1446. "asoc: failed to remove %s\n",
  1447. codec->name);
  1448. }
  1449. /* Make sure all DAPM widgets are freed */
  1450. snd_soc_dapm_free(&codec->dapm);
  1451. soc_cleanup_codec_debugfs(codec);
  1452. device_remove_file(&rtd->dev, &dev_attr_codec_reg);
  1453. codec->probed = 0;
  1454. list_del(&codec->card_list);
  1455. module_put(codec->dev->driver->owner);
  1456. }
  1457. }
  1458. static void snd_soc_instantiate_card(struct snd_soc_card *card)
  1459. {
  1460. struct platform_device *pdev = to_platform_device(card->dev);
  1461. int ret, i;
  1462. mutex_lock(&card->mutex);
  1463. if (card->instantiated) {
  1464. mutex_unlock(&card->mutex);
  1465. return;
  1466. }
  1467. /* bind DAIs */
  1468. for (i = 0; i < card->num_links; i++)
  1469. soc_bind_dai_link(card, i);
  1470. /* bind completed ? */
  1471. if (card->num_rtd != card->num_links) {
  1472. mutex_unlock(&card->mutex);
  1473. return;
  1474. }
  1475. /* card bind complete so register a sound card */
  1476. ret = snd_card_create(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
  1477. card->owner, 0, &card->snd_card);
  1478. if (ret < 0) {
  1479. printk(KERN_ERR "asoc: can't create sound card for card %s\n",
  1480. card->name);
  1481. mutex_unlock(&card->mutex);
  1482. return;
  1483. }
  1484. card->snd_card->dev = card->dev;
  1485. #ifdef CONFIG_PM
  1486. /* deferred resume work */
  1487. INIT_WORK(&card->deferred_resume_work, soc_resume_deferred);
  1488. #endif
  1489. /* initialise the sound card only once */
  1490. if (card->probe) {
  1491. ret = card->probe(pdev);
  1492. if (ret < 0)
  1493. goto card_probe_error;
  1494. }
  1495. for (i = 0; i < card->num_links; i++) {
  1496. ret = soc_probe_dai_link(card, i);
  1497. if (ret < 0) {
  1498. pr_err("asoc: failed to instantiate card %s: %d\n",
  1499. card->name, ret);
  1500. goto probe_dai_err;
  1501. }
  1502. }
  1503. for (i = 0; i < card->num_aux_devs; i++) {
  1504. ret = soc_probe_aux_dev(card, i);
  1505. if (ret < 0) {
  1506. pr_err("asoc: failed to add auxiliary devices %s: %d\n",
  1507. card->name, ret);
  1508. goto probe_aux_dev_err;
  1509. }
  1510. }
  1511. snprintf(card->snd_card->shortname, sizeof(card->snd_card->shortname),
  1512. "%s", card->name);
  1513. snprintf(card->snd_card->longname, sizeof(card->snd_card->longname),
  1514. "%s", card->name);
  1515. ret = snd_card_register(card->snd_card);
  1516. if (ret < 0) {
  1517. printk(KERN_ERR "asoc: failed to register soundcard for %s\n", card->name);
  1518. goto probe_dai_err;
  1519. }
  1520. #ifdef CONFIG_SND_SOC_AC97_BUS
  1521. /* register any AC97 codecs */
  1522. for (i = 0; i < card->num_rtd; i++) {
  1523. ret = soc_register_ac97_dai_link(&card->rtd[i]);
  1524. if (ret < 0) {
  1525. printk(KERN_ERR "asoc: failed to register AC97 %s\n", card->name);
  1526. goto probe_dai_err;
  1527. }
  1528. }
  1529. #endif
  1530. card->instantiated = 1;
  1531. mutex_unlock(&card->mutex);
  1532. return;
  1533. probe_aux_dev_err:
  1534. for (i = 0; i < card->num_aux_devs; i++)
  1535. soc_remove_aux_dev(card, i);
  1536. probe_dai_err:
  1537. for (i = 0; i < card->num_links; i++)
  1538. soc_remove_dai_link(card, i);
  1539. card_probe_error:
  1540. if (card->remove)
  1541. card->remove(pdev);
  1542. snd_card_free(card->snd_card);
  1543. mutex_unlock(&card->mutex);
  1544. }
  1545. /*
  1546. * Attempt to initialise any uninitialised cards. Must be called with
  1547. * client_mutex.
  1548. */
  1549. static void snd_soc_instantiate_cards(void)
  1550. {
  1551. struct snd_soc_card *card;
  1552. list_for_each_entry(card, &card_list, list)
  1553. snd_soc_instantiate_card(card);
  1554. }
  1555. /* probes a new socdev */
  1556. static int soc_probe(struct platform_device *pdev)
  1557. {
  1558. struct snd_soc_card *card = platform_get_drvdata(pdev);
  1559. int ret = 0;
  1560. /* Bodge while we unpick instantiation */
  1561. card->dev = &pdev->dev;
  1562. INIT_LIST_HEAD(&card->dai_dev_list);
  1563. INIT_LIST_HEAD(&card->codec_dev_list);
  1564. INIT_LIST_HEAD(&card->platform_dev_list);
  1565. soc_init_card_debugfs(card);
  1566. ret = snd_soc_register_card(card);
  1567. if (ret != 0) {
  1568. dev_err(&pdev->dev, "Failed to register card\n");
  1569. return ret;
  1570. }
  1571. return 0;
  1572. }
  1573. /* removes a socdev */
  1574. static int soc_remove(struct platform_device *pdev)
  1575. {
  1576. struct snd_soc_card *card = platform_get_drvdata(pdev);
  1577. int i;
  1578. if (card->instantiated) {
  1579. /* make sure any delayed work runs */
  1580. for (i = 0; i < card->num_rtd; i++) {
  1581. struct snd_soc_pcm_runtime *rtd = &card->rtd[i];
  1582. run_delayed_work(&rtd->delayed_work);
  1583. }
  1584. /* remove auxiliary devices */
  1585. for (i = 0; i < card->num_aux_devs; i++)
  1586. soc_remove_aux_dev(card, i);
  1587. /* remove and free each DAI */
  1588. for (i = 0; i < card->num_rtd; i++)
  1589. soc_remove_dai_link(card, i);
  1590. soc_cleanup_card_debugfs(card);
  1591. /* remove the card */
  1592. if (card->remove)
  1593. card->remove(pdev);
  1594. kfree(card->rtd);
  1595. snd_card_free(card->snd_card);
  1596. }
  1597. snd_soc_unregister_card(card);
  1598. return 0;
  1599. }
  1600. static int soc_poweroff(struct device *dev)
  1601. {
  1602. struct platform_device *pdev = to_platform_device(dev);
  1603. struct snd_soc_card *card = platform_get_drvdata(pdev);
  1604. int i;
  1605. if (!card->instantiated)
  1606. return 0;
  1607. /* Flush out pmdown_time work - we actually do want to run it
  1608. * now, we're shutting down so no imminent restart. */
  1609. for (i = 0; i < card->num_rtd; i++) {
  1610. struct snd_soc_pcm_runtime *rtd = &card->rtd[i];
  1611. run_delayed_work(&rtd->delayed_work);
  1612. }
  1613. snd_soc_dapm_shutdown(card);
  1614. return 0;
  1615. }
  1616. static const struct dev_pm_ops soc_pm_ops = {
  1617. .suspend = soc_suspend,
  1618. .resume = soc_resume,
  1619. .poweroff = soc_poweroff,
  1620. };
  1621. /* ASoC platform driver */
  1622. static struct platform_driver soc_driver = {
  1623. .driver = {
  1624. .name = "soc-audio",
  1625. .owner = THIS_MODULE,
  1626. .pm = &soc_pm_ops,
  1627. },
  1628. .probe = soc_probe,
  1629. .remove = soc_remove,
  1630. };
  1631. /* create a new pcm */
  1632. static int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
  1633. {
  1634. struct snd_soc_codec *codec = rtd->codec;
  1635. struct snd_soc_platform *platform = rtd->platform;
  1636. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  1637. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  1638. struct snd_pcm *pcm;
  1639. char new_name[64];
  1640. int ret = 0, playback = 0, capture = 0;
  1641. /* check client and interface hw capabilities */
  1642. snprintf(new_name, sizeof(new_name), "%s %s-%d",
  1643. rtd->dai_link->stream_name, codec_dai->name, num);
  1644. if (codec_dai->driver->playback.channels_min)
  1645. playback = 1;
  1646. if (codec_dai->driver->capture.channels_min)
  1647. capture = 1;
  1648. dev_dbg(rtd->card->dev, "registered pcm #%d %s\n",num,new_name);
  1649. ret = snd_pcm_new(rtd->card->snd_card, new_name,
  1650. num, playback, capture, &pcm);
  1651. if (ret < 0) {
  1652. printk(KERN_ERR "asoc: can't create pcm for codec %s\n", codec->name);
  1653. return ret;
  1654. }
  1655. rtd->pcm = pcm;
  1656. pcm->private_data = rtd;
  1657. soc_pcm_ops.mmap = platform->driver->ops->mmap;
  1658. soc_pcm_ops.pointer = platform->driver->ops->pointer;
  1659. soc_pcm_ops.ioctl = platform->driver->ops->ioctl;
  1660. soc_pcm_ops.copy = platform->driver->ops->copy;
  1661. soc_pcm_ops.silence = platform->driver->ops->silence;
  1662. soc_pcm_ops.ack = platform->driver->ops->ack;
  1663. soc_pcm_ops.page = platform->driver->ops->page;
  1664. if (playback)
  1665. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &soc_pcm_ops);
  1666. if (capture)
  1667. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &soc_pcm_ops);
  1668. ret = platform->driver->pcm_new(rtd->card->snd_card, codec_dai, pcm);
  1669. if (ret < 0) {
  1670. printk(KERN_ERR "asoc: platform pcm constructor failed\n");
  1671. return ret;
  1672. }
  1673. pcm->private_free = platform->driver->pcm_free;
  1674. printk(KERN_INFO "asoc: %s <-> %s mapping ok\n", codec_dai->name,
  1675. cpu_dai->name);
  1676. return ret;
  1677. }
  1678. /**
  1679. * snd_soc_codec_volatile_register: Report if a register is volatile.
  1680. *
  1681. * @codec: CODEC to query.
  1682. * @reg: Register to query.
  1683. *
  1684. * Boolean function indiciating if a CODEC register is volatile.
  1685. */
  1686. int snd_soc_codec_volatile_register(struct snd_soc_codec *codec, int reg)
  1687. {
  1688. if (codec->driver->volatile_register)
  1689. return codec->driver->volatile_register(reg);
  1690. else
  1691. return 0;
  1692. }
  1693. EXPORT_SYMBOL_GPL(snd_soc_codec_volatile_register);
  1694. /**
  1695. * snd_soc_new_ac97_codec - initailise AC97 device
  1696. * @codec: audio codec
  1697. * @ops: AC97 bus operations
  1698. * @num: AC97 codec number
  1699. *
  1700. * Initialises AC97 codec resources for use by ad-hoc devices only.
  1701. */
  1702. int snd_soc_new_ac97_codec(struct snd_soc_codec *codec,
  1703. struct snd_ac97_bus_ops *ops, int num)
  1704. {
  1705. mutex_lock(&codec->mutex);
  1706. codec->ac97 = kzalloc(sizeof(struct snd_ac97), GFP_KERNEL);
  1707. if (codec->ac97 == NULL) {
  1708. mutex_unlock(&codec->mutex);
  1709. return -ENOMEM;
  1710. }
  1711. codec->ac97->bus = kzalloc(sizeof(struct snd_ac97_bus), GFP_KERNEL);
  1712. if (codec->ac97->bus == NULL) {
  1713. kfree(codec->ac97);
  1714. codec->ac97 = NULL;
  1715. mutex_unlock(&codec->mutex);
  1716. return -ENOMEM;
  1717. }
  1718. codec->ac97->bus->ops = ops;
  1719. codec->ac97->num = num;
  1720. /*
  1721. * Mark the AC97 device to be created by us. This way we ensure that the
  1722. * device will be registered with the device subsystem later on.
  1723. */
  1724. codec->ac97_created = 1;
  1725. mutex_unlock(&codec->mutex);
  1726. return 0;
  1727. }
  1728. EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec);
  1729. /**
  1730. * snd_soc_free_ac97_codec - free AC97 codec device
  1731. * @codec: audio codec
  1732. *
  1733. * Frees AC97 codec device resources.
  1734. */
  1735. void snd_soc_free_ac97_codec(struct snd_soc_codec *codec)
  1736. {
  1737. mutex_lock(&codec->mutex);
  1738. #ifdef CONFIG_SND_SOC_AC97_BUS
  1739. soc_unregister_ac97_dai_link(codec);
  1740. #endif
  1741. kfree(codec->ac97->bus);
  1742. kfree(codec->ac97);
  1743. codec->ac97 = NULL;
  1744. codec->ac97_created = 0;
  1745. mutex_unlock(&codec->mutex);
  1746. }
  1747. EXPORT_SYMBOL_GPL(snd_soc_free_ac97_codec);
  1748. unsigned int snd_soc_read(struct snd_soc_codec *codec, unsigned int reg)
  1749. {
  1750. unsigned int ret;
  1751. ret = codec->read(codec, reg);
  1752. dev_dbg(codec->dev, "read %x => %x\n", reg, ret);
  1753. trace_snd_soc_reg_read(codec, reg, ret);
  1754. return ret;
  1755. }
  1756. EXPORT_SYMBOL_GPL(snd_soc_read);
  1757. unsigned int snd_soc_write(struct snd_soc_codec *codec,
  1758. unsigned int reg, unsigned int val)
  1759. {
  1760. dev_dbg(codec->dev, "write %x = %x\n", reg, val);
  1761. trace_snd_soc_reg_write(codec, reg, val);
  1762. return codec->write(codec, reg, val);
  1763. }
  1764. EXPORT_SYMBOL_GPL(snd_soc_write);
  1765. /**
  1766. * snd_soc_update_bits - update codec register bits
  1767. * @codec: audio codec
  1768. * @reg: codec register
  1769. * @mask: register mask
  1770. * @value: new value
  1771. *
  1772. * Writes new register value.
  1773. *
  1774. * Returns 1 for change else 0.
  1775. */
  1776. int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg,
  1777. unsigned int mask, unsigned int value)
  1778. {
  1779. int change;
  1780. unsigned int old, new;
  1781. old = snd_soc_read(codec, reg);
  1782. new = (old & ~mask) | value;
  1783. change = old != new;
  1784. if (change)
  1785. snd_soc_write(codec, reg, new);
  1786. return change;
  1787. }
  1788. EXPORT_SYMBOL_GPL(snd_soc_update_bits);
  1789. /**
  1790. * snd_soc_update_bits_locked - update codec register bits
  1791. * @codec: audio codec
  1792. * @reg: codec register
  1793. * @mask: register mask
  1794. * @value: new value
  1795. *
  1796. * Writes new register value, and takes the codec mutex.
  1797. *
  1798. * Returns 1 for change else 0.
  1799. */
  1800. int snd_soc_update_bits_locked(struct snd_soc_codec *codec,
  1801. unsigned short reg, unsigned int mask,
  1802. unsigned int value)
  1803. {
  1804. int change;
  1805. mutex_lock(&codec->mutex);
  1806. change = snd_soc_update_bits(codec, reg, mask, value);
  1807. mutex_unlock(&codec->mutex);
  1808. return change;
  1809. }
  1810. EXPORT_SYMBOL_GPL(snd_soc_update_bits_locked);
  1811. /**
  1812. * snd_soc_test_bits - test register for change
  1813. * @codec: audio codec
  1814. * @reg: codec register
  1815. * @mask: register mask
  1816. * @value: new value
  1817. *
  1818. * Tests a register with a new value and checks if the new value is
  1819. * different from the old value.
  1820. *
  1821. * Returns 1 for change else 0.
  1822. */
  1823. int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned short reg,
  1824. unsigned int mask, unsigned int value)
  1825. {
  1826. int change;
  1827. unsigned int old, new;
  1828. old = snd_soc_read(codec, reg);
  1829. new = (old & ~mask) | value;
  1830. change = old != new;
  1831. return change;
  1832. }
  1833. EXPORT_SYMBOL_GPL(snd_soc_test_bits);
  1834. /**
  1835. * snd_soc_set_runtime_hwparams - set the runtime hardware parameters
  1836. * @substream: the pcm substream
  1837. * @hw: the hardware parameters
  1838. *
  1839. * Sets the substream runtime hardware parameters.
  1840. */
  1841. int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
  1842. const struct snd_pcm_hardware *hw)
  1843. {
  1844. struct snd_pcm_runtime *runtime = substream->runtime;
  1845. runtime->hw.info = hw->info;
  1846. runtime->hw.formats = hw->formats;
  1847. runtime->hw.period_bytes_min = hw->period_bytes_min;
  1848. runtime->hw.period_bytes_max = hw->period_bytes_max;
  1849. runtime->hw.periods_min = hw->periods_min;
  1850. runtime->hw.periods_max = hw->periods_max;
  1851. runtime->hw.buffer_bytes_max = hw->buffer_bytes_max;
  1852. runtime->hw.fifo_size = hw->fifo_size;
  1853. return 0;
  1854. }
  1855. EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hwparams);
  1856. /**
  1857. * snd_soc_cnew - create new control
  1858. * @_template: control template
  1859. * @data: control private data
  1860. * @long_name: control long name
  1861. *
  1862. * Create a new mixer control from a template control.
  1863. *
  1864. * Returns 0 for success, else error.
  1865. */
  1866. struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
  1867. void *data, char *long_name)
  1868. {
  1869. struct snd_kcontrol_new template;
  1870. memcpy(&template, _template, sizeof(template));
  1871. if (long_name)
  1872. template.name = long_name;
  1873. template.index = 0;
  1874. return snd_ctl_new1(&template, data);
  1875. }
  1876. EXPORT_SYMBOL_GPL(snd_soc_cnew);
  1877. /**
  1878. * snd_soc_add_controls - add an array of controls to a codec.
  1879. * Convienience function to add a list of controls. Many codecs were
  1880. * duplicating this code.
  1881. *
  1882. * @codec: codec to add controls to
  1883. * @controls: array of controls to add
  1884. * @num_controls: number of elements in the array
  1885. *
  1886. * Return 0 for success, else error.
  1887. */
  1888. int snd_soc_add_controls(struct snd_soc_codec *codec,
  1889. const struct snd_kcontrol_new *controls, int num_controls)
  1890. {
  1891. struct snd_card *card = codec->card->snd_card;
  1892. char prefixed_name[44], *name;
  1893. int err, i;
  1894. for (i = 0; i < num_controls; i++) {
  1895. const struct snd_kcontrol_new *control = &controls[i];
  1896. if (codec->name_prefix) {
  1897. snprintf(prefixed_name, sizeof(prefixed_name), "%s %s",
  1898. codec->name_prefix, control->name);
  1899. name = prefixed_name;
  1900. } else {
  1901. name = control->name;
  1902. }
  1903. err = snd_ctl_add(card, snd_soc_cnew(control, codec, name));
  1904. if (err < 0) {
  1905. dev_err(codec->dev, "%s: Failed to add %s: %d\n",
  1906. codec->name, name, err);
  1907. return err;
  1908. }
  1909. }
  1910. return 0;
  1911. }
  1912. EXPORT_SYMBOL_GPL(snd_soc_add_controls);
  1913. /**
  1914. * snd_soc_info_enum_double - enumerated double mixer info callback
  1915. * @kcontrol: mixer control
  1916. * @uinfo: control element information
  1917. *
  1918. * Callback to provide information about a double enumerated
  1919. * mixer control.
  1920. *
  1921. * Returns 0 for success.
  1922. */
  1923. int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
  1924. struct snd_ctl_elem_info *uinfo)
  1925. {
  1926. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  1927. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  1928. uinfo->count = e->shift_l == e->shift_r ? 1 : 2;
  1929. uinfo->value.enumerated.items = e->max;
  1930. if (uinfo->value.enumerated.item > e->max - 1)
  1931. uinfo->value.enumerated.item = e->max - 1;
  1932. strcpy(uinfo->value.enumerated.name,
  1933. e->texts[uinfo->value.enumerated.item]);
  1934. return 0;
  1935. }
  1936. EXPORT_SYMBOL_GPL(snd_soc_info_enum_double);
  1937. /**
  1938. * snd_soc_get_enum_double - enumerated double mixer get callback
  1939. * @kcontrol: mixer control
  1940. * @ucontrol: control element information
  1941. *
  1942. * Callback to get the value of a double enumerated mixer.
  1943. *
  1944. * Returns 0 for success.
  1945. */
  1946. int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
  1947. struct snd_ctl_elem_value *ucontrol)
  1948. {
  1949. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  1950. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  1951. unsigned int val, bitmask;
  1952. for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
  1953. ;
  1954. val = snd_soc_read(codec, e->reg);
  1955. ucontrol->value.enumerated.item[0]
  1956. = (val >> e->shift_l) & (bitmask - 1);
  1957. if (e->shift_l != e->shift_r)
  1958. ucontrol->value.enumerated.item[1] =
  1959. (val >> e->shift_r) & (bitmask - 1);
  1960. return 0;
  1961. }
  1962. EXPORT_SYMBOL_GPL(snd_soc_get_enum_double);
  1963. /**
  1964. * snd_soc_put_enum_double - enumerated double mixer put callback
  1965. * @kcontrol: mixer control
  1966. * @ucontrol: control element information
  1967. *
  1968. * Callback to set the value of a double enumerated mixer.
  1969. *
  1970. * Returns 0 for success.
  1971. */
  1972. int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
  1973. struct snd_ctl_elem_value *ucontrol)
  1974. {
  1975. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  1976. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  1977. unsigned int val;
  1978. unsigned int mask, bitmask;
  1979. for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
  1980. ;
  1981. if (ucontrol->value.enumerated.item[0] > e->max - 1)
  1982. return -EINVAL;
  1983. val = ucontrol->value.enumerated.item[0] << e->shift_l;
  1984. mask = (bitmask - 1) << e->shift_l;
  1985. if (e->shift_l != e->shift_r) {
  1986. if (ucontrol->value.enumerated.item[1] > e->max - 1)
  1987. return -EINVAL;
  1988. val |= ucontrol->value.enumerated.item[1] << e->shift_r;
  1989. mask |= (bitmask - 1) << e->shift_r;
  1990. }
  1991. return snd_soc_update_bits_locked(codec, e->reg, mask, val);
  1992. }
  1993. EXPORT_SYMBOL_GPL(snd_soc_put_enum_double);
  1994. /**
  1995. * snd_soc_get_value_enum_double - semi enumerated double mixer get callback
  1996. * @kcontrol: mixer control
  1997. * @ucontrol: control element information
  1998. *
  1999. * Callback to get the value of a double semi enumerated mixer.
  2000. *
  2001. * Semi enumerated mixer: the enumerated items are referred as values. Can be
  2002. * used for handling bitfield coded enumeration for example.
  2003. *
  2004. * Returns 0 for success.
  2005. */
  2006. int snd_soc_get_value_enum_double(struct snd_kcontrol *kcontrol,
  2007. struct snd_ctl_elem_value *ucontrol)
  2008. {
  2009. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  2010. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  2011. unsigned int reg_val, val, mux;
  2012. reg_val = snd_soc_read(codec, e->reg);
  2013. val = (reg_val >> e->shift_l) & e->mask;
  2014. for (mux = 0; mux < e->max; mux++) {
  2015. if (val == e->values[mux])
  2016. break;
  2017. }
  2018. ucontrol->value.enumerated.item[0] = mux;
  2019. if (e->shift_l != e->shift_r) {
  2020. val = (reg_val >> e->shift_r) & e->mask;
  2021. for (mux = 0; mux < e->max; mux++) {
  2022. if (val == e->values[mux])
  2023. break;
  2024. }
  2025. ucontrol->value.enumerated.item[1] = mux;
  2026. }
  2027. return 0;
  2028. }
  2029. EXPORT_SYMBOL_GPL(snd_soc_get_value_enum_double);
  2030. /**
  2031. * snd_soc_put_value_enum_double - semi enumerated double mixer put callback
  2032. * @kcontrol: mixer control
  2033. * @ucontrol: control element information
  2034. *
  2035. * Callback to set the value of a double semi enumerated mixer.
  2036. *
  2037. * Semi enumerated mixer: the enumerated items are referred as values. Can be
  2038. * used for handling bitfield coded enumeration for example.
  2039. *
  2040. * Returns 0 for success.
  2041. */
  2042. int snd_soc_put_value_enum_double(struct snd_kcontrol *kcontrol,
  2043. struct snd_ctl_elem_value *ucontrol)
  2044. {
  2045. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  2046. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  2047. unsigned int val;
  2048. unsigned int mask;
  2049. if (ucontrol->value.enumerated.item[0] > e->max - 1)
  2050. return -EINVAL;
  2051. val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l;
  2052. mask = e->mask << e->shift_l;
  2053. if (e->shift_l != e->shift_r) {
  2054. if (ucontrol->value.enumerated.item[1] > e->max - 1)
  2055. return -EINVAL;
  2056. val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r;
  2057. mask |= e->mask << e->shift_r;
  2058. }
  2059. return snd_soc_update_bits_locked(codec, e->reg, mask, val);
  2060. }
  2061. EXPORT_SYMBOL_GPL(snd_soc_put_value_enum_double);
  2062. /**
  2063. * snd_soc_info_enum_ext - external enumerated single mixer info callback
  2064. * @kcontrol: mixer control
  2065. * @uinfo: control element information
  2066. *
  2067. * Callback to provide information about an external enumerated
  2068. * single mixer.
  2069. *
  2070. * Returns 0 for success.
  2071. */
  2072. int snd_soc_info_enum_ext(struct snd_kcontrol *kcontrol,
  2073. struct snd_ctl_elem_info *uinfo)
  2074. {
  2075. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  2076. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  2077. uinfo->count = 1;
  2078. uinfo->value.enumerated.items = e->max;
  2079. if (uinfo->value.enumerated.item > e->max - 1)
  2080. uinfo->value.enumerated.item = e->max - 1;
  2081. strcpy(uinfo->value.enumerated.name,
  2082. e->texts[uinfo->value.enumerated.item]);
  2083. return 0;
  2084. }
  2085. EXPORT_SYMBOL_GPL(snd_soc_info_enum_ext);
  2086. /**
  2087. * snd_soc_info_volsw_ext - external single mixer info callback
  2088. * @kcontrol: mixer control
  2089. * @uinfo: control element information
  2090. *
  2091. * Callback to provide information about a single external mixer control.
  2092. *
  2093. * Returns 0 for success.
  2094. */
  2095. int snd_soc_info_volsw_ext(struct snd_kcontrol *kcontrol,
  2096. struct snd_ctl_elem_info *uinfo)
  2097. {
  2098. int max = kcontrol->private_value;
  2099. if (max == 1 && !strstr(kcontrol->id.name, " Volume"))
  2100. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  2101. else
  2102. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  2103. uinfo->count = 1;
  2104. uinfo->value.integer.min = 0;
  2105. uinfo->value.integer.max = max;
  2106. return 0;
  2107. }
  2108. EXPORT_SYMBOL_GPL(snd_soc_info_volsw_ext);
  2109. /**
  2110. * snd_soc_info_volsw - single mixer info callback
  2111. * @kcontrol: mixer control
  2112. * @uinfo: control element information
  2113. *
  2114. * Callback to provide information about a single mixer control.
  2115. *
  2116. * Returns 0 for success.
  2117. */
  2118. int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
  2119. struct snd_ctl_elem_info *uinfo)
  2120. {
  2121. struct soc_mixer_control *mc =
  2122. (struct soc_mixer_control *)kcontrol->private_value;
  2123. int platform_max;
  2124. unsigned int shift = mc->shift;
  2125. unsigned int rshift = mc->rshift;
  2126. if (!mc->platform_max)
  2127. mc->platform_max = mc->max;
  2128. platform_max = mc->platform_max;
  2129. if (platform_max == 1 && !strstr(kcontrol->id.name, " Volume"))
  2130. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  2131. else
  2132. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  2133. uinfo->count = shift == rshift ? 1 : 2;
  2134. uinfo->value.integer.min = 0;
  2135. uinfo->value.integer.max = platform_max;
  2136. return 0;
  2137. }
  2138. EXPORT_SYMBOL_GPL(snd_soc_info_volsw);
  2139. /**
  2140. * snd_soc_get_volsw - single mixer get callback
  2141. * @kcontrol: mixer control
  2142. * @ucontrol: control element information
  2143. *
  2144. * Callback to get the value of a single mixer control.
  2145. *
  2146. * Returns 0 for success.
  2147. */
  2148. int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
  2149. struct snd_ctl_elem_value *ucontrol)
  2150. {
  2151. struct soc_mixer_control *mc =
  2152. (struct soc_mixer_control *)kcontrol->private_value;
  2153. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  2154. unsigned int reg = mc->reg;
  2155. unsigned int shift = mc->shift;
  2156. unsigned int rshift = mc->rshift;
  2157. int max = mc->max;
  2158. unsigned int mask = (1 << fls(max)) - 1;
  2159. unsigned int invert = mc->invert;
  2160. ucontrol->value.integer.value[0] =
  2161. (snd_soc_read(codec, reg) >> shift) & mask;
  2162. if (shift != rshift)
  2163. ucontrol->value.integer.value[1] =
  2164. (snd_soc_read(codec, reg) >> rshift) & mask;
  2165. if (invert) {
  2166. ucontrol->value.integer.value[0] =
  2167. max - ucontrol->value.integer.value[0];
  2168. if (shift != rshift)
  2169. ucontrol->value.integer.value[1] =
  2170. max - ucontrol->value.integer.value[1];
  2171. }
  2172. return 0;
  2173. }
  2174. EXPORT_SYMBOL_GPL(snd_soc_get_volsw);
  2175. /**
  2176. * snd_soc_put_volsw - single mixer put callback
  2177. * @kcontrol: mixer control
  2178. * @ucontrol: control element information
  2179. *
  2180. * Callback to set the value of a single mixer control.
  2181. *
  2182. * Returns 0 for success.
  2183. */
  2184. int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
  2185. struct snd_ctl_elem_value *ucontrol)
  2186. {
  2187. struct soc_mixer_control *mc =
  2188. (struct soc_mixer_control *)kcontrol->private_value;
  2189. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  2190. unsigned int reg = mc->reg;
  2191. unsigned int shift = mc->shift;
  2192. unsigned int rshift = mc->rshift;
  2193. int max = mc->max;
  2194. unsigned int mask = (1 << fls(max)) - 1;
  2195. unsigned int invert = mc->invert;
  2196. unsigned int val, val2, val_mask;
  2197. val = (ucontrol->value.integer.value[0] & mask);
  2198. if (invert)
  2199. val = max - val;
  2200. val_mask = mask << shift;
  2201. val = val << shift;
  2202. if (shift != rshift) {
  2203. val2 = (ucontrol->value.integer.value[1] & mask);
  2204. if (invert)
  2205. val2 = max - val2;
  2206. val_mask |= mask << rshift;
  2207. val |= val2 << rshift;
  2208. }
  2209. return snd_soc_update_bits_locked(codec, reg, val_mask, val);
  2210. }
  2211. EXPORT_SYMBOL_GPL(snd_soc_put_volsw);
  2212. /**
  2213. * snd_soc_info_volsw_2r - double mixer info callback
  2214. * @kcontrol: mixer control
  2215. * @uinfo: control element information
  2216. *
  2217. * Callback to provide information about a double mixer control that
  2218. * spans 2 codec registers.
  2219. *
  2220. * Returns 0 for success.
  2221. */
  2222. int snd_soc_info_volsw_2r(struct snd_kcontrol *kcontrol,
  2223. struct snd_ctl_elem_info *uinfo)
  2224. {
  2225. struct soc_mixer_control *mc =
  2226. (struct soc_mixer_control *)kcontrol->private_value;
  2227. int platform_max;
  2228. if (!mc->platform_max)
  2229. mc->platform_max = mc->max;
  2230. platform_max = mc->platform_max;
  2231. if (platform_max == 1 && !strstr(kcontrol->id.name, " Volume"))
  2232. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  2233. else
  2234. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  2235. uinfo->count = 2;
  2236. uinfo->value.integer.min = 0;
  2237. uinfo->value.integer.max = platform_max;
  2238. return 0;
  2239. }
  2240. EXPORT_SYMBOL_GPL(snd_soc_info_volsw_2r);
  2241. /**
  2242. * snd_soc_get_volsw_2r - double mixer get callback
  2243. * @kcontrol: mixer control
  2244. * @ucontrol: control element information
  2245. *
  2246. * Callback to get the value of a double mixer control that spans 2 registers.
  2247. *
  2248. * Returns 0 for success.
  2249. */
  2250. int snd_soc_get_volsw_2r(struct snd_kcontrol *kcontrol,
  2251. struct snd_ctl_elem_value *ucontrol)
  2252. {
  2253. struct soc_mixer_control *mc =
  2254. (struct soc_mixer_control *)kcontrol->private_value;
  2255. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  2256. unsigned int reg = mc->reg;
  2257. unsigned int reg2 = mc->rreg;
  2258. unsigned int shift = mc->shift;
  2259. int max = mc->max;
  2260. unsigned int mask = (1 << fls(max)) - 1;
  2261. unsigned int invert = mc->invert;
  2262. ucontrol->value.integer.value[0] =
  2263. (snd_soc_read(codec, reg) >> shift) & mask;
  2264. ucontrol->value.integer.value[1] =
  2265. (snd_soc_read(codec, reg2) >> shift) & mask;
  2266. if (invert) {
  2267. ucontrol->value.integer.value[0] =
  2268. max - ucontrol->value.integer.value[0];
  2269. ucontrol->value.integer.value[1] =
  2270. max - ucontrol->value.integer.value[1];
  2271. }
  2272. return 0;
  2273. }
  2274. EXPORT_SYMBOL_GPL(snd_soc_get_volsw_2r);
  2275. /**
  2276. * snd_soc_put_volsw_2r - double mixer set callback
  2277. * @kcontrol: mixer control
  2278. * @ucontrol: control element information
  2279. *
  2280. * Callback to set the value of a double mixer control that spans 2 registers.
  2281. *
  2282. * Returns 0 for success.
  2283. */
  2284. int snd_soc_put_volsw_2r(struct snd_kcontrol *kcontrol,
  2285. struct snd_ctl_elem_value *ucontrol)
  2286. {
  2287. struct soc_mixer_control *mc =
  2288. (struct soc_mixer_control *)kcontrol->private_value;
  2289. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  2290. unsigned int reg = mc->reg;
  2291. unsigned int reg2 = mc->rreg;
  2292. unsigned int shift = mc->shift;
  2293. int max = mc->max;
  2294. unsigned int mask = (1 << fls(max)) - 1;
  2295. unsigned int invert = mc->invert;
  2296. int err;
  2297. unsigned int val, val2, val_mask;
  2298. val_mask = mask << shift;
  2299. val = (ucontrol->value.integer.value[0] & mask);
  2300. val2 = (ucontrol->value.integer.value[1] & mask);
  2301. if (invert) {
  2302. val = max - val;
  2303. val2 = max - val2;
  2304. }
  2305. val = val << shift;
  2306. val2 = val2 << shift;
  2307. err = snd_soc_update_bits_locked(codec, reg, val_mask, val);
  2308. if (err < 0)
  2309. return err;
  2310. err = snd_soc_update_bits_locked(codec, reg2, val_mask, val2);
  2311. return err;
  2312. }
  2313. EXPORT_SYMBOL_GPL(snd_soc_put_volsw_2r);
  2314. /**
  2315. * snd_soc_info_volsw_s8 - signed mixer info callback
  2316. * @kcontrol: mixer control
  2317. * @uinfo: control element information
  2318. *
  2319. * Callback to provide information about a signed mixer control.
  2320. *
  2321. * Returns 0 for success.
  2322. */
  2323. int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol,
  2324. struct snd_ctl_elem_info *uinfo)
  2325. {
  2326. struct soc_mixer_control *mc =
  2327. (struct soc_mixer_control *)kcontrol->private_value;
  2328. int platform_max;
  2329. int min = mc->min;
  2330. if (!mc->platform_max)
  2331. mc->platform_max = mc->max;
  2332. platform_max = mc->platform_max;
  2333. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  2334. uinfo->count = 2;
  2335. uinfo->value.integer.min = 0;
  2336. uinfo->value.integer.max = platform_max - min;
  2337. return 0;
  2338. }
  2339. EXPORT_SYMBOL_GPL(snd_soc_info_volsw_s8);
  2340. /**
  2341. * snd_soc_get_volsw_s8 - signed mixer get callback
  2342. * @kcontrol: mixer control
  2343. * @ucontrol: control element information
  2344. *
  2345. * Callback to get the value of a signed mixer control.
  2346. *
  2347. * Returns 0 for success.
  2348. */
  2349. int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol,
  2350. struct snd_ctl_elem_value *ucontrol)
  2351. {
  2352. struct soc_mixer_control *mc =
  2353. (struct soc_mixer_control *)kcontrol->private_value;
  2354. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  2355. unsigned int reg = mc->reg;
  2356. int min = mc->min;
  2357. int val = snd_soc_read(codec, reg);
  2358. ucontrol->value.integer.value[0] =
  2359. ((signed char)(val & 0xff))-min;
  2360. ucontrol->value.integer.value[1] =
  2361. ((signed char)((val >> 8) & 0xff))-min;
  2362. return 0;
  2363. }
  2364. EXPORT_SYMBOL_GPL(snd_soc_get_volsw_s8);
  2365. /**
  2366. * snd_soc_put_volsw_sgn - signed mixer put callback
  2367. * @kcontrol: mixer control
  2368. * @ucontrol: control element information
  2369. *
  2370. * Callback to set the value of a signed mixer control.
  2371. *
  2372. * Returns 0 for success.
  2373. */
  2374. int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol,
  2375. struct snd_ctl_elem_value *ucontrol)
  2376. {
  2377. struct soc_mixer_control *mc =
  2378. (struct soc_mixer_control *)kcontrol->private_value;
  2379. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  2380. unsigned int reg = mc->reg;
  2381. int min = mc->min;
  2382. unsigned int val;
  2383. val = (ucontrol->value.integer.value[0]+min) & 0xff;
  2384. val |= ((ucontrol->value.integer.value[1]+min) & 0xff) << 8;
  2385. return snd_soc_update_bits_locked(codec, reg, 0xffff, val);
  2386. }
  2387. EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8);
  2388. /**
  2389. * snd_soc_limit_volume - Set new limit to an existing volume control.
  2390. *
  2391. * @codec: where to look for the control
  2392. * @name: Name of the control
  2393. * @max: new maximum limit
  2394. *
  2395. * Return 0 for success, else error.
  2396. */
  2397. int snd_soc_limit_volume(struct snd_soc_codec *codec,
  2398. const char *name, int max)
  2399. {
  2400. struct snd_card *card = codec->card->snd_card;
  2401. struct snd_kcontrol *kctl;
  2402. struct soc_mixer_control *mc;
  2403. int found = 0;
  2404. int ret = -EINVAL;
  2405. /* Sanity check for name and max */
  2406. if (unlikely(!name || max <= 0))
  2407. return -EINVAL;
  2408. list_for_each_entry(kctl, &card->controls, list) {
  2409. if (!strncmp(kctl->id.name, name, sizeof(kctl->id.name))) {
  2410. found = 1;
  2411. break;
  2412. }
  2413. }
  2414. if (found) {
  2415. mc = (struct soc_mixer_control *)kctl->private_value;
  2416. if (max <= mc->max) {
  2417. mc->platform_max = max;
  2418. ret = 0;
  2419. }
  2420. }
  2421. return ret;
  2422. }
  2423. EXPORT_SYMBOL_GPL(snd_soc_limit_volume);
  2424. /**
  2425. * snd_soc_info_volsw_2r_sx - double with tlv and variable data size
  2426. * mixer info callback
  2427. * @kcontrol: mixer control
  2428. * @uinfo: control element information
  2429. *
  2430. * Returns 0 for success.
  2431. */
  2432. int snd_soc_info_volsw_2r_sx(struct snd_kcontrol *kcontrol,
  2433. struct snd_ctl_elem_info *uinfo)
  2434. {
  2435. struct soc_mixer_control *mc =
  2436. (struct soc_mixer_control *)kcontrol->private_value;
  2437. int max = mc->max;
  2438. int min = mc->min;
  2439. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  2440. uinfo->count = 2;
  2441. uinfo->value.integer.min = 0;
  2442. uinfo->value.integer.max = max-min;
  2443. return 0;
  2444. }
  2445. EXPORT_SYMBOL_GPL(snd_soc_info_volsw_2r_sx);
  2446. /**
  2447. * snd_soc_get_volsw_2r_sx - double with tlv and variable data size
  2448. * mixer get callback
  2449. * @kcontrol: mixer control
  2450. * @uinfo: control element information
  2451. *
  2452. * Returns 0 for success.
  2453. */
  2454. int snd_soc_get_volsw_2r_sx(struct snd_kcontrol *kcontrol,
  2455. struct snd_ctl_elem_value *ucontrol)
  2456. {
  2457. struct soc_mixer_control *mc =
  2458. (struct soc_mixer_control *)kcontrol->private_value;
  2459. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  2460. unsigned int mask = (1<<mc->shift)-1;
  2461. int min = mc->min;
  2462. int val = snd_soc_read(codec, mc->reg) & mask;
  2463. int valr = snd_soc_read(codec, mc->rreg) & mask;
  2464. ucontrol->value.integer.value[0] = ((val & 0xff)-min) & mask;
  2465. ucontrol->value.integer.value[1] = ((valr & 0xff)-min) & mask;
  2466. return 0;
  2467. }
  2468. EXPORT_SYMBOL_GPL(snd_soc_get_volsw_2r_sx);
  2469. /**
  2470. * snd_soc_put_volsw_2r_sx - double with tlv and variable data size
  2471. * mixer put callback
  2472. * @kcontrol: mixer control
  2473. * @uinfo: control element information
  2474. *
  2475. * Returns 0 for success.
  2476. */
  2477. int snd_soc_put_volsw_2r_sx(struct snd_kcontrol *kcontrol,
  2478. struct snd_ctl_elem_value *ucontrol)
  2479. {
  2480. struct soc_mixer_control *mc =
  2481. (struct soc_mixer_control *)kcontrol->private_value;
  2482. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  2483. unsigned int mask = (1<<mc->shift)-1;
  2484. int min = mc->min;
  2485. int ret;
  2486. unsigned int val, valr, oval, ovalr;
  2487. val = ((ucontrol->value.integer.value[0]+min) & 0xff);
  2488. val &= mask;
  2489. valr = ((ucontrol->value.integer.value[1]+min) & 0xff);
  2490. valr &= mask;
  2491. oval = snd_soc_read(codec, mc->reg) & mask;
  2492. ovalr = snd_soc_read(codec, mc->rreg) & mask;
  2493. ret = 0;
  2494. if (oval != val) {
  2495. ret = snd_soc_write(codec, mc->reg, val);
  2496. if (ret < 0)
  2497. return ret;
  2498. }
  2499. if (ovalr != valr) {
  2500. ret = snd_soc_write(codec, mc->rreg, valr);
  2501. if (ret < 0)
  2502. return ret;
  2503. }
  2504. return 0;
  2505. }
  2506. EXPORT_SYMBOL_GPL(snd_soc_put_volsw_2r_sx);
  2507. /**
  2508. * snd_soc_dai_set_sysclk - configure DAI system or master clock.
  2509. * @dai: DAI
  2510. * @clk_id: DAI specific clock ID
  2511. * @freq: new clock frequency in Hz
  2512. * @dir: new clock direction - input/output.
  2513. *
  2514. * Configures the DAI master (MCLK) or system (SYSCLK) clocking.
  2515. */
  2516. int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id,
  2517. unsigned int freq, int dir)
  2518. {
  2519. if (dai->driver && dai->driver->ops->set_sysclk)
  2520. return dai->driver->ops->set_sysclk(dai, clk_id, freq, dir);
  2521. else
  2522. return -EINVAL;
  2523. }
  2524. EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk);
  2525. /**
  2526. * snd_soc_dai_set_clkdiv - configure DAI clock dividers.
  2527. * @dai: DAI
  2528. * @div_id: DAI specific clock divider ID
  2529. * @div: new clock divisor.
  2530. *
  2531. * Configures the clock dividers. This is used to derive the best DAI bit and
  2532. * frame clocks from the system or master clock. It's best to set the DAI bit
  2533. * and frame clocks as low as possible to save system power.
  2534. */
  2535. int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai,
  2536. int div_id, int div)
  2537. {
  2538. if (dai->driver && dai->driver->ops->set_clkdiv)
  2539. return dai->driver->ops->set_clkdiv(dai, div_id, div);
  2540. else
  2541. return -EINVAL;
  2542. }
  2543. EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv);
  2544. /**
  2545. * snd_soc_dai_set_pll - configure DAI PLL.
  2546. * @dai: DAI
  2547. * @pll_id: DAI specific PLL ID
  2548. * @source: DAI specific source for the PLL
  2549. * @freq_in: PLL input clock frequency in Hz
  2550. * @freq_out: requested PLL output clock frequency in Hz
  2551. *
  2552. * Configures and enables PLL to generate output clock based on input clock.
  2553. */
  2554. int snd_soc_dai_set_pll(struct snd_soc_dai *dai, int pll_id, int source,
  2555. unsigned int freq_in, unsigned int freq_out)
  2556. {
  2557. if (dai->driver && dai->driver->ops->set_pll)
  2558. return dai->driver->ops->set_pll(dai, pll_id, source,
  2559. freq_in, freq_out);
  2560. else
  2561. return -EINVAL;
  2562. }
  2563. EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll);
  2564. /**
  2565. * snd_soc_dai_set_fmt - configure DAI hardware audio format.
  2566. * @dai: DAI
  2567. * @fmt: SND_SOC_DAIFMT_ format value.
  2568. *
  2569. * Configures the DAI hardware format and clocking.
  2570. */
  2571. int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
  2572. {
  2573. if (dai->driver && dai->driver->ops->set_fmt)
  2574. return dai->driver->ops->set_fmt(dai, fmt);
  2575. else
  2576. return -EINVAL;
  2577. }
  2578. EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt);
  2579. /**
  2580. * snd_soc_dai_set_tdm_slot - configure DAI TDM.
  2581. * @dai: DAI
  2582. * @tx_mask: bitmask representing active TX slots.
  2583. * @rx_mask: bitmask representing active RX slots.
  2584. * @slots: Number of slots in use.
  2585. * @slot_width: Width in bits for each slot.
  2586. *
  2587. * Configures a DAI for TDM operation. Both mask and slots are codec and DAI
  2588. * specific.
  2589. */
  2590. int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,
  2591. unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width)
  2592. {
  2593. if (dai->driver && dai->driver->ops->set_tdm_slot)
  2594. return dai->driver->ops->set_tdm_slot(dai, tx_mask, rx_mask,
  2595. slots, slot_width);
  2596. else
  2597. return -EINVAL;
  2598. }
  2599. EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot);
  2600. /**
  2601. * snd_soc_dai_set_channel_map - configure DAI audio channel map
  2602. * @dai: DAI
  2603. * @tx_num: how many TX channels
  2604. * @tx_slot: pointer to an array which imply the TX slot number channel
  2605. * 0~num-1 uses
  2606. * @rx_num: how many RX channels
  2607. * @rx_slot: pointer to an array which imply the RX slot number channel
  2608. * 0~num-1 uses
  2609. *
  2610. * configure the relationship between channel number and TDM slot number.
  2611. */
  2612. int snd_soc_dai_set_channel_map(struct snd_soc_dai *dai,
  2613. unsigned int tx_num, unsigned int *tx_slot,
  2614. unsigned int rx_num, unsigned int *rx_slot)
  2615. {
  2616. if (dai->driver && dai->driver->ops->set_channel_map)
  2617. return dai->driver->ops->set_channel_map(dai, tx_num, tx_slot,
  2618. rx_num, rx_slot);
  2619. else
  2620. return -EINVAL;
  2621. }
  2622. EXPORT_SYMBOL_GPL(snd_soc_dai_set_channel_map);
  2623. /**
  2624. * snd_soc_dai_set_tristate - configure DAI system or master clock.
  2625. * @dai: DAI
  2626. * @tristate: tristate enable
  2627. *
  2628. * Tristates the DAI so that others can use it.
  2629. */
  2630. int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate)
  2631. {
  2632. if (dai->driver && dai->driver->ops->set_tristate)
  2633. return dai->driver->ops->set_tristate(dai, tristate);
  2634. else
  2635. return -EINVAL;
  2636. }
  2637. EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate);
  2638. /**
  2639. * snd_soc_dai_digital_mute - configure DAI system or master clock.
  2640. * @dai: DAI
  2641. * @mute: mute enable
  2642. *
  2643. * Mutes the DAI DAC.
  2644. */
  2645. int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute)
  2646. {
  2647. if (dai->driver && dai->driver->ops->digital_mute)
  2648. return dai->driver->ops->digital_mute(dai, mute);
  2649. else
  2650. return -EINVAL;
  2651. }
  2652. EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute);
  2653. /**
  2654. * snd_soc_register_card - Register a card with the ASoC core
  2655. *
  2656. * @card: Card to register
  2657. *
  2658. * Note that currently this is an internal only function: it will be
  2659. * exposed to machine drivers after further backporting of ASoC v2
  2660. * registration APIs.
  2661. */
  2662. static int snd_soc_register_card(struct snd_soc_card *card)
  2663. {
  2664. int i;
  2665. if (!card->name || !card->dev)
  2666. return -EINVAL;
  2667. card->rtd = kzalloc(sizeof(struct snd_soc_pcm_runtime) *
  2668. (card->num_links + card->num_aux_devs),
  2669. GFP_KERNEL);
  2670. if (card->rtd == NULL)
  2671. return -ENOMEM;
  2672. card->rtd_aux = &card->rtd[card->num_links];
  2673. for (i = 0; i < card->num_links; i++)
  2674. card->rtd[i].dai_link = &card->dai_link[i];
  2675. INIT_LIST_HEAD(&card->list);
  2676. card->instantiated = 0;
  2677. mutex_init(&card->mutex);
  2678. mutex_lock(&client_mutex);
  2679. list_add(&card->list, &card_list);
  2680. snd_soc_instantiate_cards();
  2681. mutex_unlock(&client_mutex);
  2682. dev_dbg(card->dev, "Registered card '%s'\n", card->name);
  2683. return 0;
  2684. }
  2685. /**
  2686. * snd_soc_unregister_card - Unregister a card with the ASoC core
  2687. *
  2688. * @card: Card to unregister
  2689. *
  2690. * Note that currently this is an internal only function: it will be
  2691. * exposed to machine drivers after further backporting of ASoC v2
  2692. * registration APIs.
  2693. */
  2694. static int snd_soc_unregister_card(struct snd_soc_card *card)
  2695. {
  2696. mutex_lock(&client_mutex);
  2697. list_del(&card->list);
  2698. mutex_unlock(&client_mutex);
  2699. dev_dbg(card->dev, "Unregistered card '%s'\n", card->name);
  2700. return 0;
  2701. }
  2702. /*
  2703. * Simplify DAI link configuration by removing ".-1" from device names
  2704. * and sanitizing names.
  2705. */
  2706. static inline char *fmt_single_name(struct device *dev, int *id)
  2707. {
  2708. char *found, name[NAME_SIZE];
  2709. int id1, id2;
  2710. if (dev_name(dev) == NULL)
  2711. return NULL;
  2712. strncpy(name, dev_name(dev), NAME_SIZE);
  2713. /* are we a "%s.%d" name (platform and SPI components) */
  2714. found = strstr(name, dev->driver->name);
  2715. if (found) {
  2716. /* get ID */
  2717. if (sscanf(&found[strlen(dev->driver->name)], ".%d", id) == 1) {
  2718. /* discard ID from name if ID == -1 */
  2719. if (*id == -1)
  2720. found[strlen(dev->driver->name)] = '\0';
  2721. }
  2722. } else {
  2723. /* I2C component devices are named "bus-addr" */
  2724. if (sscanf(name, "%x-%x", &id1, &id2) == 2) {
  2725. char tmp[NAME_SIZE];
  2726. /* create unique ID number from I2C addr and bus */
  2727. *id = ((id1 & 0xffff) << 16) + id2;
  2728. /* sanitize component name for DAI link creation */
  2729. snprintf(tmp, NAME_SIZE, "%s.%s", dev->driver->name, name);
  2730. strncpy(name, tmp, NAME_SIZE);
  2731. } else
  2732. *id = 0;
  2733. }
  2734. return kstrdup(name, GFP_KERNEL);
  2735. }
  2736. /*
  2737. * Simplify DAI link naming for single devices with multiple DAIs by removing
  2738. * any ".-1" and using the DAI name (instead of device name).
  2739. */
  2740. static inline char *fmt_multiple_name(struct device *dev,
  2741. struct snd_soc_dai_driver *dai_drv)
  2742. {
  2743. if (dai_drv->name == NULL) {
  2744. printk(KERN_ERR "asoc: error - multiple DAI %s registered with no name\n",
  2745. dev_name(dev));
  2746. return NULL;
  2747. }
  2748. return kstrdup(dai_drv->name, GFP_KERNEL);
  2749. }
  2750. /**
  2751. * snd_soc_register_dai - Register a DAI with the ASoC core
  2752. *
  2753. * @dai: DAI to register
  2754. */
  2755. int snd_soc_register_dai(struct device *dev,
  2756. struct snd_soc_dai_driver *dai_drv)
  2757. {
  2758. struct snd_soc_dai *dai;
  2759. dev_dbg(dev, "dai register %s\n", dev_name(dev));
  2760. dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL);
  2761. if (dai == NULL)
  2762. return -ENOMEM;
  2763. /* create DAI component name */
  2764. dai->name = fmt_single_name(dev, &dai->id);
  2765. if (dai->name == NULL) {
  2766. kfree(dai);
  2767. return -ENOMEM;
  2768. }
  2769. dai->dev = dev;
  2770. dai->driver = dai_drv;
  2771. if (!dai->driver->ops)
  2772. dai->driver->ops = &null_dai_ops;
  2773. mutex_lock(&client_mutex);
  2774. list_add(&dai->list, &dai_list);
  2775. snd_soc_instantiate_cards();
  2776. mutex_unlock(&client_mutex);
  2777. pr_debug("Registered DAI '%s'\n", dai->name);
  2778. return 0;
  2779. }
  2780. EXPORT_SYMBOL_GPL(snd_soc_register_dai);
  2781. /**
  2782. * snd_soc_unregister_dai - Unregister a DAI from the ASoC core
  2783. *
  2784. * @dai: DAI to unregister
  2785. */
  2786. void snd_soc_unregister_dai(struct device *dev)
  2787. {
  2788. struct snd_soc_dai *dai;
  2789. list_for_each_entry(dai, &dai_list, list) {
  2790. if (dev == dai->dev)
  2791. goto found;
  2792. }
  2793. return;
  2794. found:
  2795. mutex_lock(&client_mutex);
  2796. list_del(&dai->list);
  2797. mutex_unlock(&client_mutex);
  2798. pr_debug("Unregistered DAI '%s'\n", dai->name);
  2799. kfree(dai->name);
  2800. kfree(dai);
  2801. }
  2802. EXPORT_SYMBOL_GPL(snd_soc_unregister_dai);
  2803. /**
  2804. * snd_soc_register_dais - Register multiple DAIs with the ASoC core
  2805. *
  2806. * @dai: Array of DAIs to register
  2807. * @count: Number of DAIs
  2808. */
  2809. int snd_soc_register_dais(struct device *dev,
  2810. struct snd_soc_dai_driver *dai_drv, size_t count)
  2811. {
  2812. struct snd_soc_dai *dai;
  2813. int i, ret = 0;
  2814. dev_dbg(dev, "dai register %s #%Zu\n", dev_name(dev), count);
  2815. for (i = 0; i < count; i++) {
  2816. dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL);
  2817. if (dai == NULL) {
  2818. ret = -ENOMEM;
  2819. goto err;
  2820. }
  2821. /* create DAI component name */
  2822. dai->name = fmt_multiple_name(dev, &dai_drv[i]);
  2823. if (dai->name == NULL) {
  2824. kfree(dai);
  2825. ret = -EINVAL;
  2826. goto err;
  2827. }
  2828. dai->dev = dev;
  2829. dai->driver = &dai_drv[i];
  2830. if (dai->driver->id)
  2831. dai->id = dai->driver->id;
  2832. else
  2833. dai->id = i;
  2834. if (!dai->driver->ops)
  2835. dai->driver->ops = &null_dai_ops;
  2836. mutex_lock(&client_mutex);
  2837. list_add(&dai->list, &dai_list);
  2838. mutex_unlock(&client_mutex);
  2839. pr_debug("Registered DAI '%s'\n", dai->name);
  2840. }
  2841. snd_soc_instantiate_cards();
  2842. return 0;
  2843. err:
  2844. for (i--; i >= 0; i--)
  2845. snd_soc_unregister_dai(dev);
  2846. return ret;
  2847. }
  2848. EXPORT_SYMBOL_GPL(snd_soc_register_dais);
  2849. /**
  2850. * snd_soc_unregister_dais - Unregister multiple DAIs from the ASoC core
  2851. *
  2852. * @dai: Array of DAIs to unregister
  2853. * @count: Number of DAIs
  2854. */
  2855. void snd_soc_unregister_dais(struct device *dev, size_t count)
  2856. {
  2857. int i;
  2858. for (i = 0; i < count; i++)
  2859. snd_soc_unregister_dai(dev);
  2860. }
  2861. EXPORT_SYMBOL_GPL(snd_soc_unregister_dais);
  2862. /**
  2863. * snd_soc_register_platform - Register a platform with the ASoC core
  2864. *
  2865. * @platform: platform to register
  2866. */
  2867. int snd_soc_register_platform(struct device *dev,
  2868. struct snd_soc_platform_driver *platform_drv)
  2869. {
  2870. struct snd_soc_platform *platform;
  2871. dev_dbg(dev, "platform register %s\n", dev_name(dev));
  2872. platform = kzalloc(sizeof(struct snd_soc_platform), GFP_KERNEL);
  2873. if (platform == NULL)
  2874. return -ENOMEM;
  2875. /* create platform component name */
  2876. platform->name = fmt_single_name(dev, &platform->id);
  2877. if (platform->name == NULL) {
  2878. kfree(platform);
  2879. return -ENOMEM;
  2880. }
  2881. platform->dev = dev;
  2882. platform->driver = platform_drv;
  2883. mutex_lock(&client_mutex);
  2884. list_add(&platform->list, &platform_list);
  2885. snd_soc_instantiate_cards();
  2886. mutex_unlock(&client_mutex);
  2887. pr_debug("Registered platform '%s'\n", platform->name);
  2888. return 0;
  2889. }
  2890. EXPORT_SYMBOL_GPL(snd_soc_register_platform);
  2891. /**
  2892. * snd_soc_unregister_platform - Unregister a platform from the ASoC core
  2893. *
  2894. * @platform: platform to unregister
  2895. */
  2896. void snd_soc_unregister_platform(struct device *dev)
  2897. {
  2898. struct snd_soc_platform *platform;
  2899. list_for_each_entry(platform, &platform_list, list) {
  2900. if (dev == platform->dev)
  2901. goto found;
  2902. }
  2903. return;
  2904. found:
  2905. mutex_lock(&client_mutex);
  2906. list_del(&platform->list);
  2907. mutex_unlock(&client_mutex);
  2908. pr_debug("Unregistered platform '%s'\n", platform->name);
  2909. kfree(platform->name);
  2910. kfree(platform);
  2911. }
  2912. EXPORT_SYMBOL_GPL(snd_soc_unregister_platform);
  2913. static u64 codec_format_map[] = {
  2914. SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE,
  2915. SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE,
  2916. SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE,
  2917. SNDRV_PCM_FMTBIT_U24_LE | SNDRV_PCM_FMTBIT_U24_BE,
  2918. SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE,
  2919. SNDRV_PCM_FMTBIT_U32_LE | SNDRV_PCM_FMTBIT_U32_BE,
  2920. SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_U24_3BE,
  2921. SNDRV_PCM_FMTBIT_U24_3LE | SNDRV_PCM_FMTBIT_U24_3BE,
  2922. SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE,
  2923. SNDRV_PCM_FMTBIT_U20_3LE | SNDRV_PCM_FMTBIT_U20_3BE,
  2924. SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S18_3BE,
  2925. SNDRV_PCM_FMTBIT_U18_3LE | SNDRV_PCM_FMTBIT_U18_3BE,
  2926. SNDRV_PCM_FMTBIT_FLOAT_LE | SNDRV_PCM_FMTBIT_FLOAT_BE,
  2927. SNDRV_PCM_FMTBIT_FLOAT64_LE | SNDRV_PCM_FMTBIT_FLOAT64_BE,
  2928. SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE
  2929. | SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE,
  2930. };
  2931. /* Fix up the DAI formats for endianness: codecs don't actually see
  2932. * the endianness of the data but we're using the CPU format
  2933. * definitions which do need to include endianness so we ensure that
  2934. * codec DAIs always have both big and little endian variants set.
  2935. */
  2936. static void fixup_codec_formats(struct snd_soc_pcm_stream *stream)
  2937. {
  2938. int i;
  2939. for (i = 0; i < ARRAY_SIZE(codec_format_map); i++)
  2940. if (stream->formats & codec_format_map[i])
  2941. stream->formats |= codec_format_map[i];
  2942. }
  2943. /**
  2944. * snd_soc_register_codec - Register a codec with the ASoC core
  2945. *
  2946. * @codec: codec to register
  2947. */
  2948. int snd_soc_register_codec(struct device *dev,
  2949. struct snd_soc_codec_driver *codec_drv,
  2950. struct snd_soc_dai_driver *dai_drv, int num_dai)
  2951. {
  2952. struct snd_soc_codec *codec;
  2953. int ret, i;
  2954. dev_dbg(dev, "codec register %s\n", dev_name(dev));
  2955. codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
  2956. if (codec == NULL)
  2957. return -ENOMEM;
  2958. /* create CODEC component name */
  2959. codec->name = fmt_single_name(dev, &codec->id);
  2960. if (codec->name == NULL) {
  2961. kfree(codec);
  2962. return -ENOMEM;
  2963. }
  2964. INIT_LIST_HEAD(&codec->dapm.widgets);
  2965. INIT_LIST_HEAD(&codec->dapm.paths);
  2966. codec->write = codec_drv->write;
  2967. codec->read = codec_drv->read;
  2968. codec->dapm.bias_level = SND_SOC_BIAS_OFF;
  2969. codec->dapm.dev = dev;
  2970. codec->dapm.codec = codec;
  2971. codec->dev = dev;
  2972. codec->driver = codec_drv;
  2973. codec->num_dai = num_dai;
  2974. mutex_init(&codec->mutex);
  2975. /* allocate CODEC register cache */
  2976. if (codec_drv->reg_cache_size && codec_drv->reg_word_size) {
  2977. ret = snd_soc_cache_init(codec);
  2978. if (ret < 0) {
  2979. dev_err(codec->dev, "Failed to set cache compression type: %d\n",
  2980. ret);
  2981. goto error_cache;
  2982. }
  2983. }
  2984. for (i = 0; i < num_dai; i++) {
  2985. fixup_codec_formats(&dai_drv[i].playback);
  2986. fixup_codec_formats(&dai_drv[i].capture);
  2987. }
  2988. /* register any DAIs */
  2989. if (num_dai) {
  2990. ret = snd_soc_register_dais(dev, dai_drv, num_dai);
  2991. if (ret < 0)
  2992. goto error_dais;
  2993. }
  2994. mutex_lock(&client_mutex);
  2995. list_add(&codec->list, &codec_list);
  2996. snd_soc_instantiate_cards();
  2997. mutex_unlock(&client_mutex);
  2998. pr_debug("Registered codec '%s'\n", codec->name);
  2999. return 0;
  3000. error_dais:
  3001. snd_soc_cache_exit(codec);
  3002. error_cache:
  3003. kfree(codec->name);
  3004. kfree(codec);
  3005. return ret;
  3006. }
  3007. EXPORT_SYMBOL_GPL(snd_soc_register_codec);
  3008. /**
  3009. * snd_soc_unregister_codec - Unregister a codec from the ASoC core
  3010. *
  3011. * @codec: codec to unregister
  3012. */
  3013. void snd_soc_unregister_codec(struct device *dev)
  3014. {
  3015. struct snd_soc_codec *codec;
  3016. int i;
  3017. list_for_each_entry(codec, &codec_list, list) {
  3018. if (dev == codec->dev)
  3019. goto found;
  3020. }
  3021. return;
  3022. found:
  3023. if (codec->num_dai)
  3024. for (i = 0; i < codec->num_dai; i++)
  3025. snd_soc_unregister_dai(dev);
  3026. mutex_lock(&client_mutex);
  3027. list_del(&codec->list);
  3028. mutex_unlock(&client_mutex);
  3029. pr_debug("Unregistered codec '%s'\n", codec->name);
  3030. snd_soc_cache_exit(codec);
  3031. kfree(codec->name);
  3032. kfree(codec);
  3033. }
  3034. EXPORT_SYMBOL_GPL(snd_soc_unregister_codec);
  3035. static int __init snd_soc_init(void)
  3036. {
  3037. #ifdef CONFIG_DEBUG_FS
  3038. debugfs_root = debugfs_create_dir("asoc", NULL);
  3039. if (IS_ERR(debugfs_root) || !debugfs_root) {
  3040. printk(KERN_WARNING
  3041. "ASoC: Failed to create debugfs directory\n");
  3042. debugfs_root = NULL;
  3043. }
  3044. if (!debugfs_create_file("codecs", 0444, debugfs_root, NULL,
  3045. &codec_list_fops))
  3046. pr_warn("ASoC: Failed to create CODEC list debugfs file\n");
  3047. if (!debugfs_create_file("dais", 0444, debugfs_root, NULL,
  3048. &dai_list_fops))
  3049. pr_warn("ASoC: Failed to create DAI list debugfs file\n");
  3050. if (!debugfs_create_file("platforms", 0444, debugfs_root, NULL,
  3051. &platform_list_fops))
  3052. pr_warn("ASoC: Failed to create platform list debugfs file\n");
  3053. #endif
  3054. return platform_driver_register(&soc_driver);
  3055. }
  3056. module_init(snd_soc_init);
  3057. static void __exit snd_soc_exit(void)
  3058. {
  3059. #ifdef CONFIG_DEBUG_FS
  3060. debugfs_remove_recursive(debugfs_root);
  3061. #endif
  3062. platform_driver_unregister(&soc_driver);
  3063. }
  3064. module_exit(snd_soc_exit);
  3065. /* Module information */
  3066. MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
  3067. MODULE_DESCRIPTION("ALSA SoC Core");
  3068. MODULE_LICENSE("GPL");
  3069. MODULE_ALIAS("platform:soc-audio");