wm8994.c 84 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086
  1. /*
  2. * wm8994.c -- WM8994 ALSA SoC Audio driver
  3. *
  4. * Copyright 2009 Wolfson Microelectronics plc
  5. *
  6. * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
  7. *
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/module.h>
  14. #include <linux/moduleparam.h>
  15. #include <linux/init.h>
  16. #include <linux/delay.h>
  17. #include <linux/pm.h>
  18. #include <linux/i2c.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/pm_runtime.h>
  21. #include <linux/regulator/consumer.h>
  22. #include <linux/slab.h>
  23. #include <sound/core.h>
  24. #include <sound/jack.h>
  25. #include <sound/pcm.h>
  26. #include <sound/pcm_params.h>
  27. #include <sound/soc.h>
  28. #include <sound/initval.h>
  29. #include <sound/tlv.h>
  30. #include <linux/mfd/wm8994/core.h>
  31. #include <linux/mfd/wm8994/registers.h>
  32. #include <linux/mfd/wm8994/pdata.h>
  33. #include <linux/mfd/wm8994/gpio.h>
  34. #include "wm8994.h"
  35. #include "wm_hubs.h"
  36. struct fll_config {
  37. int src;
  38. int in;
  39. int out;
  40. };
  41. #define WM8994_NUM_DRC 3
  42. #define WM8994_NUM_EQ 3
  43. static int wm8994_drc_base[] = {
  44. WM8994_AIF1_DRC1_1,
  45. WM8994_AIF1_DRC2_1,
  46. WM8994_AIF2_DRC_1,
  47. };
  48. static int wm8994_retune_mobile_base[] = {
  49. WM8994_AIF1_DAC1_EQ_GAINS_1,
  50. WM8994_AIF1_DAC2_EQ_GAINS_1,
  51. WM8994_AIF2_EQ_GAINS_1,
  52. };
  53. struct wm8994_micdet {
  54. struct snd_soc_jack *jack;
  55. int det;
  56. int shrt;
  57. };
  58. /* codec private data */
  59. struct wm8994_priv {
  60. struct wm_hubs_data hubs;
  61. enum snd_soc_control_type control_type;
  62. void *control_data;
  63. struct snd_soc_codec *codec;
  64. int sysclk[2];
  65. int sysclk_rate[2];
  66. int mclk[2];
  67. int aifclk[2];
  68. struct fll_config fll[2], fll_suspend[2];
  69. int dac_rates[2];
  70. int lrclk_shared[2];
  71. int mbc_ena[3];
  72. /* Platform dependant DRC configuration */
  73. const char **drc_texts;
  74. int drc_cfg[WM8994_NUM_DRC];
  75. struct soc_enum drc_enum;
  76. /* Platform dependant ReTune mobile configuration */
  77. int num_retune_mobile_texts;
  78. const char **retune_mobile_texts;
  79. int retune_mobile_cfg[WM8994_NUM_EQ];
  80. struct soc_enum retune_mobile_enum;
  81. struct wm8994_micdet micdet[2];
  82. wm8958_micdet_cb jack_cb;
  83. void *jack_cb_data;
  84. bool jack_is_mic;
  85. bool jack_is_video;
  86. int revision;
  87. struct wm8994_pdata *pdata;
  88. };
  89. static int wm8994_readable(unsigned int reg)
  90. {
  91. switch (reg) {
  92. case WM8994_GPIO_1:
  93. case WM8994_GPIO_2:
  94. case WM8994_GPIO_3:
  95. case WM8994_GPIO_4:
  96. case WM8994_GPIO_5:
  97. case WM8994_GPIO_6:
  98. case WM8994_GPIO_7:
  99. case WM8994_GPIO_8:
  100. case WM8994_GPIO_9:
  101. case WM8994_GPIO_10:
  102. case WM8994_GPIO_11:
  103. case WM8994_INTERRUPT_STATUS_1:
  104. case WM8994_INTERRUPT_STATUS_2:
  105. case WM8994_INTERRUPT_RAW_STATUS_2:
  106. return 1;
  107. default:
  108. break;
  109. }
  110. if (reg >= WM8994_CACHE_SIZE)
  111. return 0;
  112. return wm8994_access_masks[reg].readable != 0;
  113. }
  114. static int wm8994_volatile(unsigned int reg)
  115. {
  116. if (reg >= WM8994_CACHE_SIZE)
  117. return 1;
  118. switch (reg) {
  119. case WM8994_SOFTWARE_RESET:
  120. case WM8994_CHIP_REVISION:
  121. case WM8994_DC_SERVO_1:
  122. case WM8994_DC_SERVO_READBACK:
  123. case WM8994_RATE_STATUS:
  124. case WM8994_LDO_1:
  125. case WM8994_LDO_2:
  126. case WM8958_DSP2_EXECCONTROL:
  127. case WM8958_MIC_DETECT_3:
  128. return 1;
  129. default:
  130. return 0;
  131. }
  132. }
  133. static int wm8994_write(struct snd_soc_codec *codec, unsigned int reg,
  134. unsigned int value)
  135. {
  136. int ret;
  137. BUG_ON(reg > WM8994_MAX_REGISTER);
  138. if (!wm8994_volatile(reg)) {
  139. ret = snd_soc_cache_write(codec, reg, value);
  140. if (ret != 0)
  141. dev_err(codec->dev, "Cache write to %x failed: %d\n",
  142. reg, ret);
  143. }
  144. return wm8994_reg_write(codec->control_data, reg, value);
  145. }
  146. static unsigned int wm8994_read(struct snd_soc_codec *codec,
  147. unsigned int reg)
  148. {
  149. unsigned int val;
  150. int ret;
  151. BUG_ON(reg > WM8994_MAX_REGISTER);
  152. if (!wm8994_volatile(reg) && wm8994_readable(reg) &&
  153. reg < codec->driver->reg_cache_size) {
  154. ret = snd_soc_cache_read(codec, reg, &val);
  155. if (ret >= 0)
  156. return val;
  157. else
  158. dev_err(codec->dev, "Cache read from %x failed: %d\n",
  159. reg, ret);
  160. }
  161. return wm8994_reg_read(codec->control_data, reg);
  162. }
  163. static int configure_aif_clock(struct snd_soc_codec *codec, int aif)
  164. {
  165. struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
  166. int rate;
  167. int reg1 = 0;
  168. int offset;
  169. if (aif)
  170. offset = 4;
  171. else
  172. offset = 0;
  173. switch (wm8994->sysclk[aif]) {
  174. case WM8994_SYSCLK_MCLK1:
  175. rate = wm8994->mclk[0];
  176. break;
  177. case WM8994_SYSCLK_MCLK2:
  178. reg1 |= 0x8;
  179. rate = wm8994->mclk[1];
  180. break;
  181. case WM8994_SYSCLK_FLL1:
  182. reg1 |= 0x10;
  183. rate = wm8994->fll[0].out;
  184. break;
  185. case WM8994_SYSCLK_FLL2:
  186. reg1 |= 0x18;
  187. rate = wm8994->fll[1].out;
  188. break;
  189. default:
  190. return -EINVAL;
  191. }
  192. if (rate >= 13500000) {
  193. rate /= 2;
  194. reg1 |= WM8994_AIF1CLK_DIV;
  195. dev_dbg(codec->dev, "Dividing AIF%d clock to %dHz\n",
  196. aif + 1, rate);
  197. }
  198. if (rate && rate < 3000000)
  199. dev_warn(codec->dev, "AIF%dCLK is %dHz, should be >=3MHz for optimal performance\n",
  200. aif + 1, rate);
  201. wm8994->aifclk[aif] = rate;
  202. snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1 + offset,
  203. WM8994_AIF1CLK_SRC_MASK | WM8994_AIF1CLK_DIV,
  204. reg1);
  205. return 0;
  206. }
  207. static int configure_clock(struct snd_soc_codec *codec)
  208. {
  209. struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
  210. int old, new;
  211. /* Bring up the AIF clocks first */
  212. configure_aif_clock(codec, 0);
  213. configure_aif_clock(codec, 1);
  214. /* Then switch CLK_SYS over to the higher of them; a change
  215. * can only happen as a result of a clocking change which can
  216. * only be made outside of DAPM so we can safely redo the
  217. * clocking.
  218. */
  219. /* If they're equal it doesn't matter which is used */
  220. if (wm8994->aifclk[0] == wm8994->aifclk[1])
  221. return 0;
  222. if (wm8994->aifclk[0] < wm8994->aifclk[1])
  223. new = WM8994_SYSCLK_SRC;
  224. else
  225. new = 0;
  226. old = snd_soc_read(codec, WM8994_CLOCKING_1) & WM8994_SYSCLK_SRC;
  227. /* If there's no change then we're done. */
  228. if (old == new)
  229. return 0;
  230. snd_soc_update_bits(codec, WM8994_CLOCKING_1, WM8994_SYSCLK_SRC, new);
  231. snd_soc_dapm_sync(&codec->dapm);
  232. return 0;
  233. }
  234. static int check_clk_sys(struct snd_soc_dapm_widget *source,
  235. struct snd_soc_dapm_widget *sink)
  236. {
  237. int reg = snd_soc_read(source->codec, WM8994_CLOCKING_1);
  238. const char *clk;
  239. /* Check what we're currently using for CLK_SYS */
  240. if (reg & WM8994_SYSCLK_SRC)
  241. clk = "AIF2CLK";
  242. else
  243. clk = "AIF1CLK";
  244. return strcmp(source->name, clk) == 0;
  245. }
  246. static const char *sidetone_hpf_text[] = {
  247. "2.7kHz", "1.35kHz", "675Hz", "370Hz", "180Hz", "90Hz", "45Hz"
  248. };
  249. static const struct soc_enum sidetone_hpf =
  250. SOC_ENUM_SINGLE(WM8994_SIDETONE, 7, 7, sidetone_hpf_text);
  251. static const DECLARE_TLV_DB_SCALE(aif_tlv, 0, 600, 0);
  252. static const DECLARE_TLV_DB_SCALE(digital_tlv, -7200, 75, 1);
  253. static const DECLARE_TLV_DB_SCALE(st_tlv, -3600, 300, 0);
  254. static const DECLARE_TLV_DB_SCALE(wm8994_3d_tlv, -1600, 183, 0);
  255. static const DECLARE_TLV_DB_SCALE(eq_tlv, -1200, 100, 0);
  256. #define WM8994_DRC_SWITCH(xname, reg, shift) \
  257. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  258. .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
  259. .put = wm8994_put_drc_sw, \
  260. .private_value = SOC_SINGLE_VALUE(reg, shift, 1, 0) }
  261. static int wm8994_put_drc_sw(struct snd_kcontrol *kcontrol,
  262. struct snd_ctl_elem_value *ucontrol)
  263. {
  264. struct soc_mixer_control *mc =
  265. (struct soc_mixer_control *)kcontrol->private_value;
  266. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  267. int mask, ret;
  268. /* Can't enable both ADC and DAC paths simultaneously */
  269. if (mc->shift == WM8994_AIF1DAC1_DRC_ENA_SHIFT)
  270. mask = WM8994_AIF1ADC1L_DRC_ENA_MASK |
  271. WM8994_AIF1ADC1R_DRC_ENA_MASK;
  272. else
  273. mask = WM8994_AIF1DAC1_DRC_ENA_MASK;
  274. ret = snd_soc_read(codec, mc->reg);
  275. if (ret < 0)
  276. return ret;
  277. if (ret & mask)
  278. return -EINVAL;
  279. return snd_soc_put_volsw(kcontrol, ucontrol);
  280. }
  281. static void wm8994_set_drc(struct snd_soc_codec *codec, int drc)
  282. {
  283. struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
  284. struct wm8994_pdata *pdata = wm8994->pdata;
  285. int base = wm8994_drc_base[drc];
  286. int cfg = wm8994->drc_cfg[drc];
  287. int save, i;
  288. /* Save any enables; the configuration should clear them. */
  289. save = snd_soc_read(codec, base);
  290. save &= WM8994_AIF1DAC1_DRC_ENA | WM8994_AIF1ADC1L_DRC_ENA |
  291. WM8994_AIF1ADC1R_DRC_ENA;
  292. for (i = 0; i < WM8994_DRC_REGS; i++)
  293. snd_soc_update_bits(codec, base + i, 0xffff,
  294. pdata->drc_cfgs[cfg].regs[i]);
  295. snd_soc_update_bits(codec, base, WM8994_AIF1DAC1_DRC_ENA |
  296. WM8994_AIF1ADC1L_DRC_ENA |
  297. WM8994_AIF1ADC1R_DRC_ENA, save);
  298. }
  299. /* Icky as hell but saves code duplication */
  300. static int wm8994_get_drc(const char *name)
  301. {
  302. if (strcmp(name, "AIF1DRC1 Mode") == 0)
  303. return 0;
  304. if (strcmp(name, "AIF1DRC2 Mode") == 0)
  305. return 1;
  306. if (strcmp(name, "AIF2DRC Mode") == 0)
  307. return 2;
  308. return -EINVAL;
  309. }
  310. static int wm8994_put_drc_enum(struct snd_kcontrol *kcontrol,
  311. struct snd_ctl_elem_value *ucontrol)
  312. {
  313. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  314. struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
  315. struct wm8994_pdata *pdata = wm8994->pdata;
  316. int drc = wm8994_get_drc(kcontrol->id.name);
  317. int value = ucontrol->value.integer.value[0];
  318. if (drc < 0)
  319. return drc;
  320. if (value >= pdata->num_drc_cfgs)
  321. return -EINVAL;
  322. wm8994->drc_cfg[drc] = value;
  323. wm8994_set_drc(codec, drc);
  324. return 0;
  325. }
  326. static int wm8994_get_drc_enum(struct snd_kcontrol *kcontrol,
  327. struct snd_ctl_elem_value *ucontrol)
  328. {
  329. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  330. struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
  331. int drc = wm8994_get_drc(kcontrol->id.name);
  332. ucontrol->value.enumerated.item[0] = wm8994->drc_cfg[drc];
  333. return 0;
  334. }
  335. static void wm8994_set_retune_mobile(struct snd_soc_codec *codec, int block)
  336. {
  337. struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
  338. struct wm8994_pdata *pdata = wm8994->pdata;
  339. int base = wm8994_retune_mobile_base[block];
  340. int iface, best, best_val, save, i, cfg;
  341. if (!pdata || !wm8994->num_retune_mobile_texts)
  342. return;
  343. switch (block) {
  344. case 0:
  345. case 1:
  346. iface = 0;
  347. break;
  348. case 2:
  349. iface = 1;
  350. break;
  351. default:
  352. return;
  353. }
  354. /* Find the version of the currently selected configuration
  355. * with the nearest sample rate. */
  356. cfg = wm8994->retune_mobile_cfg[block];
  357. best = 0;
  358. best_val = INT_MAX;
  359. for (i = 0; i < pdata->num_retune_mobile_cfgs; i++) {
  360. if (strcmp(pdata->retune_mobile_cfgs[i].name,
  361. wm8994->retune_mobile_texts[cfg]) == 0 &&
  362. abs(pdata->retune_mobile_cfgs[i].rate
  363. - wm8994->dac_rates[iface]) < best_val) {
  364. best = i;
  365. best_val = abs(pdata->retune_mobile_cfgs[i].rate
  366. - wm8994->dac_rates[iface]);
  367. }
  368. }
  369. dev_dbg(codec->dev, "ReTune Mobile %d %s/%dHz for %dHz sample rate\n",
  370. block,
  371. pdata->retune_mobile_cfgs[best].name,
  372. pdata->retune_mobile_cfgs[best].rate,
  373. wm8994->dac_rates[iface]);
  374. /* The EQ will be disabled while reconfiguring it, remember the
  375. * current configuration.
  376. */
  377. save = snd_soc_read(codec, base);
  378. save &= WM8994_AIF1DAC1_EQ_ENA;
  379. for (i = 0; i < WM8994_EQ_REGS; i++)
  380. snd_soc_update_bits(codec, base + i, 0xffff,
  381. pdata->retune_mobile_cfgs[best].regs[i]);
  382. snd_soc_update_bits(codec, base, WM8994_AIF1DAC1_EQ_ENA, save);
  383. }
  384. /* Icky as hell but saves code duplication */
  385. static int wm8994_get_retune_mobile_block(const char *name)
  386. {
  387. if (strcmp(name, "AIF1.1 EQ Mode") == 0)
  388. return 0;
  389. if (strcmp(name, "AIF1.2 EQ Mode") == 0)
  390. return 1;
  391. if (strcmp(name, "AIF2 EQ Mode") == 0)
  392. return 2;
  393. return -EINVAL;
  394. }
  395. static int wm8994_put_retune_mobile_enum(struct snd_kcontrol *kcontrol,
  396. struct snd_ctl_elem_value *ucontrol)
  397. {
  398. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  399. struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
  400. struct wm8994_pdata *pdata = wm8994->pdata;
  401. int block = wm8994_get_retune_mobile_block(kcontrol->id.name);
  402. int value = ucontrol->value.integer.value[0];
  403. if (block < 0)
  404. return block;
  405. if (value >= pdata->num_retune_mobile_cfgs)
  406. return -EINVAL;
  407. wm8994->retune_mobile_cfg[block] = value;
  408. wm8994_set_retune_mobile(codec, block);
  409. return 0;
  410. }
  411. static int wm8994_get_retune_mobile_enum(struct snd_kcontrol *kcontrol,
  412. struct snd_ctl_elem_value *ucontrol)
  413. {
  414. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  415. struct wm8994_priv *wm8994 =snd_soc_codec_get_drvdata(codec);
  416. int block = wm8994_get_retune_mobile_block(kcontrol->id.name);
  417. ucontrol->value.enumerated.item[0] = wm8994->retune_mobile_cfg[block];
  418. return 0;
  419. }
  420. static const char *aif_chan_src_text[] = {
  421. "Left", "Right"
  422. };
  423. static const struct soc_enum aif1adcl_src =
  424. SOC_ENUM_SINGLE(WM8994_AIF1_CONTROL_1, 15, 2, aif_chan_src_text);
  425. static const struct soc_enum aif1adcr_src =
  426. SOC_ENUM_SINGLE(WM8994_AIF1_CONTROL_1, 14, 2, aif_chan_src_text);
  427. static const struct soc_enum aif2adcl_src =
  428. SOC_ENUM_SINGLE(WM8994_AIF2_CONTROL_1, 15, 2, aif_chan_src_text);
  429. static const struct soc_enum aif2adcr_src =
  430. SOC_ENUM_SINGLE(WM8994_AIF2_CONTROL_1, 14, 2, aif_chan_src_text);
  431. static const struct soc_enum aif1dacl_src =
  432. SOC_ENUM_SINGLE(WM8994_AIF1_CONTROL_2, 15, 2, aif_chan_src_text);
  433. static const struct soc_enum aif1dacr_src =
  434. SOC_ENUM_SINGLE(WM8994_AIF1_CONTROL_2, 14, 2, aif_chan_src_text);
  435. static const struct soc_enum aif2dacl_src =
  436. SOC_ENUM_SINGLE(WM8994_AIF2_CONTROL_2, 15, 2, aif_chan_src_text);
  437. static const struct soc_enum aif2dacr_src =
  438. SOC_ENUM_SINGLE(WM8994_AIF2_CONTROL_2, 14, 2, aif_chan_src_text);
  439. static void wm8958_mbc_apply(struct snd_soc_codec *codec, int mbc, int start)
  440. {
  441. struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
  442. int pwr_reg = snd_soc_read(codec, WM8994_POWER_MANAGEMENT_5);
  443. int ena, reg, aif;
  444. switch (mbc) {
  445. case 0:
  446. pwr_reg &= (WM8994_AIF1DAC1L_ENA | WM8994_AIF1DAC1R_ENA);
  447. aif = 0;
  448. break;
  449. case 1:
  450. pwr_reg &= (WM8994_AIF1DAC2L_ENA | WM8994_AIF1DAC2R_ENA);
  451. aif = 0;
  452. break;
  453. case 2:
  454. pwr_reg &= (WM8994_AIF2DACL_ENA | WM8994_AIF2DACR_ENA);
  455. aif = 1;
  456. break;
  457. default:
  458. BUG();
  459. return;
  460. }
  461. /* We can only enable the MBC if the AIF is enabled and we
  462. * want it to be enabled. */
  463. ena = pwr_reg && wm8994->mbc_ena[mbc];
  464. reg = snd_soc_read(codec, WM8958_DSP2_PROGRAM);
  465. dev_dbg(codec->dev, "MBC %d startup: %d, power: %x, DSP: %x\n",
  466. mbc, start, pwr_reg, reg);
  467. if (start && ena) {
  468. /* If the DSP is already running then noop */
  469. if (reg & WM8958_DSP2_ENA)
  470. return;
  471. /* Switch the clock over to the appropriate AIF */
  472. snd_soc_update_bits(codec, WM8994_CLOCKING_1,
  473. WM8958_DSP2CLK_SRC | WM8958_DSP2CLK_ENA,
  474. aif << WM8958_DSP2CLK_SRC_SHIFT |
  475. WM8958_DSP2CLK_ENA);
  476. snd_soc_update_bits(codec, WM8958_DSP2_PROGRAM,
  477. WM8958_DSP2_ENA, WM8958_DSP2_ENA);
  478. /* TODO: Apply any user specified MBC settings */
  479. /* Run the DSP */
  480. snd_soc_write(codec, WM8958_DSP2_EXECCONTROL,
  481. WM8958_DSP2_RUNR);
  482. /* And we're off! */
  483. snd_soc_update_bits(codec, WM8958_DSP2_CONFIG,
  484. WM8958_MBC_ENA | WM8958_MBC_SEL_MASK,
  485. mbc << WM8958_MBC_SEL_SHIFT |
  486. WM8958_MBC_ENA);
  487. } else {
  488. /* If the DSP is already stopped then noop */
  489. if (!(reg & WM8958_DSP2_ENA))
  490. return;
  491. snd_soc_update_bits(codec, WM8958_DSP2_CONFIG,
  492. WM8958_MBC_ENA, 0);
  493. snd_soc_update_bits(codec, WM8958_DSP2_PROGRAM,
  494. WM8958_DSP2_ENA, 0);
  495. snd_soc_update_bits(codec, WM8994_CLOCKING_1,
  496. WM8958_DSP2CLK_ENA, 0);
  497. }
  498. }
  499. static int wm8958_aif_ev(struct snd_soc_dapm_widget *w,
  500. struct snd_kcontrol *kcontrol, int event)
  501. {
  502. struct snd_soc_codec *codec = w->codec;
  503. int mbc;
  504. switch (w->shift) {
  505. case 13:
  506. case 12:
  507. mbc = 2;
  508. break;
  509. case 11:
  510. case 10:
  511. mbc = 1;
  512. break;
  513. case 9:
  514. case 8:
  515. mbc = 0;
  516. break;
  517. default:
  518. BUG();
  519. return -EINVAL;
  520. }
  521. switch (event) {
  522. case SND_SOC_DAPM_POST_PMU:
  523. wm8958_mbc_apply(codec, mbc, 1);
  524. break;
  525. case SND_SOC_DAPM_POST_PMD:
  526. wm8958_mbc_apply(codec, mbc, 0);
  527. break;
  528. }
  529. return 0;
  530. }
  531. static int wm8958_mbc_info(struct snd_kcontrol *kcontrol,
  532. struct snd_ctl_elem_info *uinfo)
  533. {
  534. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  535. uinfo->count = 1;
  536. uinfo->value.integer.min = 0;
  537. uinfo->value.integer.max = 1;
  538. return 0;
  539. }
  540. static int wm8958_mbc_get(struct snd_kcontrol *kcontrol,
  541. struct snd_ctl_elem_value *ucontrol)
  542. {
  543. int mbc = kcontrol->private_value;
  544. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  545. struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
  546. ucontrol->value.integer.value[0] = wm8994->mbc_ena[mbc];
  547. return 0;
  548. }
  549. static int wm8958_mbc_put(struct snd_kcontrol *kcontrol,
  550. struct snd_ctl_elem_value *ucontrol)
  551. {
  552. int mbc = kcontrol->private_value;
  553. int i;
  554. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  555. struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
  556. if (ucontrol->value.integer.value[0] > 1)
  557. return -EINVAL;
  558. for (i = 0; i < ARRAY_SIZE(wm8994->mbc_ena); i++) {
  559. if (mbc != i && wm8994->mbc_ena[i]) {
  560. dev_dbg(codec->dev, "MBC %d active already\n", mbc);
  561. return -EBUSY;
  562. }
  563. }
  564. wm8994->mbc_ena[mbc] = ucontrol->value.integer.value[0];
  565. wm8958_mbc_apply(codec, mbc, wm8994->mbc_ena[mbc]);
  566. return 0;
  567. }
  568. #define WM8958_MBC_SWITCH(xname, xval) {\
  569. .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  570. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  571. .info = wm8958_mbc_info, \
  572. .get = wm8958_mbc_get, .put = wm8958_mbc_put, \
  573. .private_value = xval }
  574. static const struct snd_kcontrol_new wm8994_snd_controls[] = {
  575. SOC_DOUBLE_R_TLV("AIF1ADC1 Volume", WM8994_AIF1_ADC1_LEFT_VOLUME,
  576. WM8994_AIF1_ADC1_RIGHT_VOLUME,
  577. 1, 119, 0, digital_tlv),
  578. SOC_DOUBLE_R_TLV("AIF1ADC2 Volume", WM8994_AIF1_ADC2_LEFT_VOLUME,
  579. WM8994_AIF1_ADC2_RIGHT_VOLUME,
  580. 1, 119, 0, digital_tlv),
  581. SOC_DOUBLE_R_TLV("AIF2ADC Volume", WM8994_AIF2_ADC_LEFT_VOLUME,
  582. WM8994_AIF2_ADC_RIGHT_VOLUME,
  583. 1, 119, 0, digital_tlv),
  584. SOC_ENUM("AIF1ADCL Source", aif1adcl_src),
  585. SOC_ENUM("AIF1ADCR Source", aif1adcr_src),
  586. SOC_ENUM("AIF2ADCL Source", aif1adcl_src),
  587. SOC_ENUM("AIF2ADCR Source", aif1adcr_src),
  588. SOC_ENUM("AIF1DACL Source", aif1dacl_src),
  589. SOC_ENUM("AIF1DACR Source", aif1dacr_src),
  590. SOC_ENUM("AIF2DACL Source", aif1dacl_src),
  591. SOC_ENUM("AIF2DACR Source", aif1dacr_src),
  592. SOC_DOUBLE_R_TLV("AIF1DAC1 Volume", WM8994_AIF1_DAC1_LEFT_VOLUME,
  593. WM8994_AIF1_DAC1_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
  594. SOC_DOUBLE_R_TLV("AIF1DAC2 Volume", WM8994_AIF1_DAC2_LEFT_VOLUME,
  595. WM8994_AIF1_DAC2_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
  596. SOC_DOUBLE_R_TLV("AIF2DAC Volume", WM8994_AIF2_DAC_LEFT_VOLUME,
  597. WM8994_AIF2_DAC_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
  598. SOC_SINGLE_TLV("AIF1 Boost Volume", WM8994_AIF1_CONTROL_2, 10, 3, 0, aif_tlv),
  599. SOC_SINGLE_TLV("AIF2 Boost Volume", WM8994_AIF2_CONTROL_2, 10, 3, 0, aif_tlv),
  600. SOC_SINGLE("AIF1DAC1 EQ Switch", WM8994_AIF1_DAC1_EQ_GAINS_1, 0, 1, 0),
  601. SOC_SINGLE("AIF1DAC2 EQ Switch", WM8994_AIF1_DAC2_EQ_GAINS_1, 0, 1, 0),
  602. SOC_SINGLE("AIF2 EQ Switch", WM8994_AIF2_EQ_GAINS_1, 0, 1, 0),
  603. WM8994_DRC_SWITCH("AIF1DAC1 DRC Switch", WM8994_AIF1_DRC1_1, 2),
  604. WM8994_DRC_SWITCH("AIF1ADC1L DRC Switch", WM8994_AIF1_DRC1_1, 1),
  605. WM8994_DRC_SWITCH("AIF1ADC1R DRC Switch", WM8994_AIF1_DRC1_1, 0),
  606. WM8994_DRC_SWITCH("AIF1DAC2 DRC Switch", WM8994_AIF1_DRC2_1, 2),
  607. WM8994_DRC_SWITCH("AIF1ADC2L DRC Switch", WM8994_AIF1_DRC2_1, 1),
  608. WM8994_DRC_SWITCH("AIF1ADC2R DRC Switch", WM8994_AIF1_DRC2_1, 0),
  609. WM8994_DRC_SWITCH("AIF2DAC DRC Switch", WM8994_AIF2_DRC_1, 2),
  610. WM8994_DRC_SWITCH("AIF2ADCL DRC Switch", WM8994_AIF2_DRC_1, 1),
  611. WM8994_DRC_SWITCH("AIF2ADCR DRC Switch", WM8994_AIF2_DRC_1, 0),
  612. SOC_SINGLE_TLV("DAC1 Right Sidetone Volume", WM8994_DAC1_MIXER_VOLUMES,
  613. 5, 12, 0, st_tlv),
  614. SOC_SINGLE_TLV("DAC1 Left Sidetone Volume", WM8994_DAC1_MIXER_VOLUMES,
  615. 0, 12, 0, st_tlv),
  616. SOC_SINGLE_TLV("DAC2 Right Sidetone Volume", WM8994_DAC2_MIXER_VOLUMES,
  617. 5, 12, 0, st_tlv),
  618. SOC_SINGLE_TLV("DAC2 Left Sidetone Volume", WM8994_DAC2_MIXER_VOLUMES,
  619. 0, 12, 0, st_tlv),
  620. SOC_ENUM("Sidetone HPF Mux", sidetone_hpf),
  621. SOC_SINGLE("Sidetone HPF Switch", WM8994_SIDETONE, 6, 1, 0),
  622. SOC_DOUBLE_R_TLV("DAC1 Volume", WM8994_DAC1_LEFT_VOLUME,
  623. WM8994_DAC1_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
  624. SOC_DOUBLE_R("DAC1 Switch", WM8994_DAC1_LEFT_VOLUME,
  625. WM8994_DAC1_RIGHT_VOLUME, 9, 1, 1),
  626. SOC_DOUBLE_R_TLV("DAC2 Volume", WM8994_DAC2_LEFT_VOLUME,
  627. WM8994_DAC2_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
  628. SOC_DOUBLE_R("DAC2 Switch", WM8994_DAC2_LEFT_VOLUME,
  629. WM8994_DAC2_RIGHT_VOLUME, 9, 1, 1),
  630. SOC_SINGLE_TLV("SPKL DAC2 Volume", WM8994_SPKMIXL_ATTENUATION,
  631. 6, 1, 1, wm_hubs_spkmix_tlv),
  632. SOC_SINGLE_TLV("SPKL DAC1 Volume", WM8994_SPKMIXL_ATTENUATION,
  633. 2, 1, 1, wm_hubs_spkmix_tlv),
  634. SOC_SINGLE_TLV("SPKR DAC2 Volume", WM8994_SPKMIXR_ATTENUATION,
  635. 6, 1, 1, wm_hubs_spkmix_tlv),
  636. SOC_SINGLE_TLV("SPKR DAC1 Volume", WM8994_SPKMIXR_ATTENUATION,
  637. 2, 1, 1, wm_hubs_spkmix_tlv),
  638. SOC_SINGLE_TLV("AIF1DAC1 3D Stereo Volume", WM8994_AIF1_DAC1_FILTERS_2,
  639. 10, 15, 0, wm8994_3d_tlv),
  640. SOC_SINGLE("AIF1DAC1 3D Stereo Switch", WM8994_AIF1_DAC2_FILTERS_2,
  641. 8, 1, 0),
  642. SOC_SINGLE_TLV("AIF1DAC2 3D Stereo Volume", WM8994_AIF1_DAC2_FILTERS_2,
  643. 10, 15, 0, wm8994_3d_tlv),
  644. SOC_SINGLE("AIF1DAC2 3D Stereo Switch", WM8994_AIF1_DAC2_FILTERS_2,
  645. 8, 1, 0),
  646. SOC_SINGLE_TLV("AIF2DAC 3D Stereo Volume", WM8994_AIF1_DAC1_FILTERS_2,
  647. 10, 15, 0, wm8994_3d_tlv),
  648. SOC_SINGLE("AIF2DAC 3D Stereo Switch", WM8994_AIF1_DAC2_FILTERS_2,
  649. 8, 1, 0),
  650. };
  651. static const struct snd_kcontrol_new wm8994_eq_controls[] = {
  652. SOC_SINGLE_TLV("AIF1DAC1 EQ1 Volume", WM8994_AIF1_DAC1_EQ_GAINS_1, 11, 31, 0,
  653. eq_tlv),
  654. SOC_SINGLE_TLV("AIF1DAC1 EQ2 Volume", WM8994_AIF1_DAC1_EQ_GAINS_1, 6, 31, 0,
  655. eq_tlv),
  656. SOC_SINGLE_TLV("AIF1DAC1 EQ3 Volume", WM8994_AIF1_DAC1_EQ_GAINS_1, 1, 31, 0,
  657. eq_tlv),
  658. SOC_SINGLE_TLV("AIF1DAC1 EQ4 Volume", WM8994_AIF1_DAC1_EQ_GAINS_2, 11, 31, 0,
  659. eq_tlv),
  660. SOC_SINGLE_TLV("AIF1DAC1 EQ5 Volume", WM8994_AIF1_DAC1_EQ_GAINS_2, 6, 31, 0,
  661. eq_tlv),
  662. SOC_SINGLE_TLV("AIF1DAC2 EQ1 Volume", WM8994_AIF1_DAC2_EQ_GAINS_1, 11, 31, 0,
  663. eq_tlv),
  664. SOC_SINGLE_TLV("AIF1DAC2 EQ2 Volume", WM8994_AIF1_DAC2_EQ_GAINS_1, 6, 31, 0,
  665. eq_tlv),
  666. SOC_SINGLE_TLV("AIF1DAC2 EQ3 Volume", WM8994_AIF1_DAC2_EQ_GAINS_1, 1, 31, 0,
  667. eq_tlv),
  668. SOC_SINGLE_TLV("AIF1DAC2 EQ4 Volume", WM8994_AIF1_DAC2_EQ_GAINS_2, 11, 31, 0,
  669. eq_tlv),
  670. SOC_SINGLE_TLV("AIF1DAC2 EQ5 Volume", WM8994_AIF1_DAC2_EQ_GAINS_2, 6, 31, 0,
  671. eq_tlv),
  672. SOC_SINGLE_TLV("AIF2 EQ1 Volume", WM8994_AIF2_EQ_GAINS_1, 11, 31, 0,
  673. eq_tlv),
  674. SOC_SINGLE_TLV("AIF2 EQ2 Volume", WM8994_AIF2_EQ_GAINS_1, 6, 31, 0,
  675. eq_tlv),
  676. SOC_SINGLE_TLV("AIF2 EQ3 Volume", WM8994_AIF2_EQ_GAINS_1, 1, 31, 0,
  677. eq_tlv),
  678. SOC_SINGLE_TLV("AIF2 EQ4 Volume", WM8994_AIF2_EQ_GAINS_2, 11, 31, 0,
  679. eq_tlv),
  680. SOC_SINGLE_TLV("AIF2 EQ5 Volume", WM8994_AIF2_EQ_GAINS_2, 6, 31, 0,
  681. eq_tlv),
  682. };
  683. static const struct snd_kcontrol_new wm8958_snd_controls[] = {
  684. SOC_SINGLE_TLV("AIF3 Boost Volume", WM8958_AIF3_CONTROL_2, 10, 3, 0, aif_tlv),
  685. WM8958_MBC_SWITCH("AIF1DAC1 MBC Switch", 0),
  686. WM8958_MBC_SWITCH("AIF1DAC2 MBC Switch", 1),
  687. WM8958_MBC_SWITCH("AIF2DAC MBC Switch", 2),
  688. };
  689. static int clk_sys_event(struct snd_soc_dapm_widget *w,
  690. struct snd_kcontrol *kcontrol, int event)
  691. {
  692. struct snd_soc_codec *codec = w->codec;
  693. switch (event) {
  694. case SND_SOC_DAPM_PRE_PMU:
  695. return configure_clock(codec);
  696. case SND_SOC_DAPM_POST_PMD:
  697. configure_clock(codec);
  698. break;
  699. }
  700. return 0;
  701. }
  702. static void wm8994_update_class_w(struct snd_soc_codec *codec)
  703. {
  704. struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
  705. int enable = 1;
  706. int source = 0; /* GCC flow analysis can't track enable */
  707. int reg, reg_r;
  708. /* Only support direct DAC->headphone paths */
  709. reg = snd_soc_read(codec, WM8994_OUTPUT_MIXER_1);
  710. if (!(reg & WM8994_DAC1L_TO_HPOUT1L)) {
  711. dev_vdbg(codec->dev, "HPL connected to output mixer\n");
  712. enable = 0;
  713. }
  714. reg = snd_soc_read(codec, WM8994_OUTPUT_MIXER_2);
  715. if (!(reg & WM8994_DAC1R_TO_HPOUT1R)) {
  716. dev_vdbg(codec->dev, "HPR connected to output mixer\n");
  717. enable = 0;
  718. }
  719. /* We also need the same setting for L/R and only one path */
  720. reg = snd_soc_read(codec, WM8994_DAC1_LEFT_MIXER_ROUTING);
  721. switch (reg) {
  722. case WM8994_AIF2DACL_TO_DAC1L:
  723. dev_vdbg(codec->dev, "Class W source AIF2DAC\n");
  724. source = 2 << WM8994_CP_DYN_SRC_SEL_SHIFT;
  725. break;
  726. case WM8994_AIF1DAC2L_TO_DAC1L:
  727. dev_vdbg(codec->dev, "Class W source AIF1DAC2\n");
  728. source = 1 << WM8994_CP_DYN_SRC_SEL_SHIFT;
  729. break;
  730. case WM8994_AIF1DAC1L_TO_DAC1L:
  731. dev_vdbg(codec->dev, "Class W source AIF1DAC1\n");
  732. source = 0 << WM8994_CP_DYN_SRC_SEL_SHIFT;
  733. break;
  734. default:
  735. dev_vdbg(codec->dev, "DAC mixer setting: %x\n", reg);
  736. enable = 0;
  737. break;
  738. }
  739. reg_r = snd_soc_read(codec, WM8994_DAC1_RIGHT_MIXER_ROUTING);
  740. if (reg_r != reg) {
  741. dev_vdbg(codec->dev, "Left and right DAC mixers different\n");
  742. enable = 0;
  743. }
  744. if (enable) {
  745. dev_dbg(codec->dev, "Class W enabled\n");
  746. snd_soc_update_bits(codec, WM8994_CLASS_W_1,
  747. WM8994_CP_DYN_PWR |
  748. WM8994_CP_DYN_SRC_SEL_MASK,
  749. source | WM8994_CP_DYN_PWR);
  750. wm8994->hubs.class_w = true;
  751. } else {
  752. dev_dbg(codec->dev, "Class W disabled\n");
  753. snd_soc_update_bits(codec, WM8994_CLASS_W_1,
  754. WM8994_CP_DYN_PWR, 0);
  755. wm8994->hubs.class_w = false;
  756. }
  757. }
  758. static const char *hp_mux_text[] = {
  759. "Mixer",
  760. "DAC",
  761. };
  762. #define WM8994_HP_ENUM(xname, xenum) \
  763. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  764. .info = snd_soc_info_enum_double, \
  765. .get = snd_soc_dapm_get_enum_double, \
  766. .put = wm8994_put_hp_enum, \
  767. .private_value = (unsigned long)&xenum }
  768. static int wm8994_put_hp_enum(struct snd_kcontrol *kcontrol,
  769. struct snd_ctl_elem_value *ucontrol)
  770. {
  771. struct snd_soc_dapm_widget *w = snd_kcontrol_chip(kcontrol);
  772. struct snd_soc_codec *codec = w->codec;
  773. int ret;
  774. ret = snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
  775. wm8994_update_class_w(codec);
  776. return ret;
  777. }
  778. static const struct soc_enum hpl_enum =
  779. SOC_ENUM_SINGLE(WM8994_OUTPUT_MIXER_1, 8, 2, hp_mux_text);
  780. static const struct snd_kcontrol_new hpl_mux =
  781. WM8994_HP_ENUM("Left Headphone Mux", hpl_enum);
  782. static const struct soc_enum hpr_enum =
  783. SOC_ENUM_SINGLE(WM8994_OUTPUT_MIXER_2, 8, 2, hp_mux_text);
  784. static const struct snd_kcontrol_new hpr_mux =
  785. WM8994_HP_ENUM("Right Headphone Mux", hpr_enum);
  786. static const char *adc_mux_text[] = {
  787. "ADC",
  788. "DMIC",
  789. };
  790. static const struct soc_enum adc_enum =
  791. SOC_ENUM_SINGLE(0, 0, 2, adc_mux_text);
  792. static const struct snd_kcontrol_new adcl_mux =
  793. SOC_DAPM_ENUM_VIRT("ADCL Mux", adc_enum);
  794. static const struct snd_kcontrol_new adcr_mux =
  795. SOC_DAPM_ENUM_VIRT("ADCR Mux", adc_enum);
  796. static const struct snd_kcontrol_new left_speaker_mixer[] = {
  797. SOC_DAPM_SINGLE("DAC2 Switch", WM8994_SPEAKER_MIXER, 9, 1, 0),
  798. SOC_DAPM_SINGLE("Input Switch", WM8994_SPEAKER_MIXER, 7, 1, 0),
  799. SOC_DAPM_SINGLE("IN1LP Switch", WM8994_SPEAKER_MIXER, 5, 1, 0),
  800. SOC_DAPM_SINGLE("Output Switch", WM8994_SPEAKER_MIXER, 3, 1, 0),
  801. SOC_DAPM_SINGLE("DAC1 Switch", WM8994_SPEAKER_MIXER, 1, 1, 0),
  802. };
  803. static const struct snd_kcontrol_new right_speaker_mixer[] = {
  804. SOC_DAPM_SINGLE("DAC2 Switch", WM8994_SPEAKER_MIXER, 8, 1, 0),
  805. SOC_DAPM_SINGLE("Input Switch", WM8994_SPEAKER_MIXER, 6, 1, 0),
  806. SOC_DAPM_SINGLE("IN1RP Switch", WM8994_SPEAKER_MIXER, 4, 1, 0),
  807. SOC_DAPM_SINGLE("Output Switch", WM8994_SPEAKER_MIXER, 2, 1, 0),
  808. SOC_DAPM_SINGLE("DAC1 Switch", WM8994_SPEAKER_MIXER, 0, 1, 0),
  809. };
  810. /* Debugging; dump chip status after DAPM transitions */
  811. static int post_ev(struct snd_soc_dapm_widget *w,
  812. struct snd_kcontrol *kcontrol, int event)
  813. {
  814. struct snd_soc_codec *codec = w->codec;
  815. dev_dbg(codec->dev, "SRC status: %x\n",
  816. snd_soc_read(codec,
  817. WM8994_RATE_STATUS));
  818. return 0;
  819. }
  820. static const struct snd_kcontrol_new aif1adc1l_mix[] = {
  821. SOC_DAPM_SINGLE("ADC/DMIC Switch", WM8994_AIF1_ADC1_LEFT_MIXER_ROUTING,
  822. 1, 1, 0),
  823. SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC1_LEFT_MIXER_ROUTING,
  824. 0, 1, 0),
  825. };
  826. static const struct snd_kcontrol_new aif1adc1r_mix[] = {
  827. SOC_DAPM_SINGLE("ADC/DMIC Switch", WM8994_AIF1_ADC1_RIGHT_MIXER_ROUTING,
  828. 1, 1, 0),
  829. SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC1_RIGHT_MIXER_ROUTING,
  830. 0, 1, 0),
  831. };
  832. static const struct snd_kcontrol_new aif1adc2l_mix[] = {
  833. SOC_DAPM_SINGLE("DMIC Switch", WM8994_AIF1_ADC2_LEFT_MIXER_ROUTING,
  834. 1, 1, 0),
  835. SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC2_LEFT_MIXER_ROUTING,
  836. 0, 1, 0),
  837. };
  838. static const struct snd_kcontrol_new aif1adc2r_mix[] = {
  839. SOC_DAPM_SINGLE("DMIC Switch", WM8994_AIF1_ADC2_RIGHT_MIXER_ROUTING,
  840. 1, 1, 0),
  841. SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC2_RIGHT_MIXER_ROUTING,
  842. 0, 1, 0),
  843. };
  844. static const struct snd_kcontrol_new aif2dac2l_mix[] = {
  845. SOC_DAPM_SINGLE("Right Sidetone Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
  846. 5, 1, 0),
  847. SOC_DAPM_SINGLE("Left Sidetone Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
  848. 4, 1, 0),
  849. SOC_DAPM_SINGLE("AIF2 Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
  850. 2, 1, 0),
  851. SOC_DAPM_SINGLE("AIF1.2 Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
  852. 1, 1, 0),
  853. SOC_DAPM_SINGLE("AIF1.1 Switch", WM8994_DAC2_LEFT_MIXER_ROUTING,
  854. 0, 1, 0),
  855. };
  856. static const struct snd_kcontrol_new aif2dac2r_mix[] = {
  857. SOC_DAPM_SINGLE("Right Sidetone Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
  858. 5, 1, 0),
  859. SOC_DAPM_SINGLE("Left Sidetone Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
  860. 4, 1, 0),
  861. SOC_DAPM_SINGLE("AIF2 Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
  862. 2, 1, 0),
  863. SOC_DAPM_SINGLE("AIF1.2 Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
  864. 1, 1, 0),
  865. SOC_DAPM_SINGLE("AIF1.1 Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING,
  866. 0, 1, 0),
  867. };
  868. #define WM8994_CLASS_W_SWITCH(xname, reg, shift, max, invert) \
  869. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  870. .info = snd_soc_info_volsw, \
  871. .get = snd_soc_dapm_get_volsw, .put = wm8994_put_class_w, \
  872. .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) }
  873. static int wm8994_put_class_w(struct snd_kcontrol *kcontrol,
  874. struct snd_ctl_elem_value *ucontrol)
  875. {
  876. struct snd_soc_dapm_widget *w = snd_kcontrol_chip(kcontrol);
  877. struct snd_soc_codec *codec = w->codec;
  878. int ret;
  879. ret = snd_soc_dapm_put_volsw(kcontrol, ucontrol);
  880. wm8994_update_class_w(codec);
  881. return ret;
  882. }
  883. static const struct snd_kcontrol_new dac1l_mix[] = {
  884. WM8994_CLASS_W_SWITCH("Right Sidetone Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
  885. 5, 1, 0),
  886. WM8994_CLASS_W_SWITCH("Left Sidetone Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
  887. 4, 1, 0),
  888. WM8994_CLASS_W_SWITCH("AIF2 Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
  889. 2, 1, 0),
  890. WM8994_CLASS_W_SWITCH("AIF1.2 Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
  891. 1, 1, 0),
  892. WM8994_CLASS_W_SWITCH("AIF1.1 Switch", WM8994_DAC1_LEFT_MIXER_ROUTING,
  893. 0, 1, 0),
  894. };
  895. static const struct snd_kcontrol_new dac1r_mix[] = {
  896. WM8994_CLASS_W_SWITCH("Right Sidetone Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
  897. 5, 1, 0),
  898. WM8994_CLASS_W_SWITCH("Left Sidetone Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
  899. 4, 1, 0),
  900. WM8994_CLASS_W_SWITCH("AIF2 Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
  901. 2, 1, 0),
  902. WM8994_CLASS_W_SWITCH("AIF1.2 Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
  903. 1, 1, 0),
  904. WM8994_CLASS_W_SWITCH("AIF1.1 Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING,
  905. 0, 1, 0),
  906. };
  907. static const char *sidetone_text[] = {
  908. "ADC/DMIC1", "DMIC2",
  909. };
  910. static const struct soc_enum sidetone1_enum =
  911. SOC_ENUM_SINGLE(WM8994_SIDETONE, 0, 2, sidetone_text);
  912. static const struct snd_kcontrol_new sidetone1_mux =
  913. SOC_DAPM_ENUM("Left Sidetone Mux", sidetone1_enum);
  914. static const struct soc_enum sidetone2_enum =
  915. SOC_ENUM_SINGLE(WM8994_SIDETONE, 1, 2, sidetone_text);
  916. static const struct snd_kcontrol_new sidetone2_mux =
  917. SOC_DAPM_ENUM("Right Sidetone Mux", sidetone2_enum);
  918. static const char *aif1dac_text[] = {
  919. "AIF1DACDAT", "AIF3DACDAT",
  920. };
  921. static const struct soc_enum aif1dac_enum =
  922. SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 0, 2, aif1dac_text);
  923. static const struct snd_kcontrol_new aif1dac_mux =
  924. SOC_DAPM_ENUM("AIF1DAC Mux", aif1dac_enum);
  925. static const char *aif2dac_text[] = {
  926. "AIF2DACDAT", "AIF3DACDAT",
  927. };
  928. static const struct soc_enum aif2dac_enum =
  929. SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 1, 2, aif2dac_text);
  930. static const struct snd_kcontrol_new aif2dac_mux =
  931. SOC_DAPM_ENUM("AIF2DAC Mux", aif2dac_enum);
  932. static const char *aif2adc_text[] = {
  933. "AIF2ADCDAT", "AIF3DACDAT",
  934. };
  935. static const struct soc_enum aif2adc_enum =
  936. SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 2, 2, aif2adc_text);
  937. static const struct snd_kcontrol_new aif2adc_mux =
  938. SOC_DAPM_ENUM("AIF2ADC Mux", aif2adc_enum);
  939. static const char *aif3adc_text[] = {
  940. "AIF1ADCDAT", "AIF2ADCDAT", "AIF2DACDAT", "Mono PCM",
  941. };
  942. static const struct soc_enum wm8994_aif3adc_enum =
  943. SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 3, 3, aif3adc_text);
  944. static const struct snd_kcontrol_new wm8994_aif3adc_mux =
  945. SOC_DAPM_ENUM("AIF3ADC Mux", wm8994_aif3adc_enum);
  946. static const struct soc_enum wm8958_aif3adc_enum =
  947. SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 3, 4, aif3adc_text);
  948. static const struct snd_kcontrol_new wm8958_aif3adc_mux =
  949. SOC_DAPM_ENUM("AIF3ADC Mux", wm8958_aif3adc_enum);
  950. static const char *mono_pcm_out_text[] = {
  951. "None", "AIF2ADCL", "AIF2ADCR",
  952. };
  953. static const struct soc_enum mono_pcm_out_enum =
  954. SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 9, 3, mono_pcm_out_text);
  955. static const struct snd_kcontrol_new mono_pcm_out_mux =
  956. SOC_DAPM_ENUM("Mono PCM Out Mux", mono_pcm_out_enum);
  957. static const char *aif2dac_src_text[] = {
  958. "AIF2", "AIF3",
  959. };
  960. /* Note that these two control shouldn't be simultaneously switched to AIF3 */
  961. static const struct soc_enum aif2dacl_src_enum =
  962. SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 7, 2, aif2dac_src_text);
  963. static const struct snd_kcontrol_new aif2dacl_src_mux =
  964. SOC_DAPM_ENUM("AIF2DACL Mux", aif2dacl_src_enum);
  965. static const struct soc_enum aif2dacr_src_enum =
  966. SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 8, 2, aif2dac_src_text);
  967. static const struct snd_kcontrol_new aif2dacr_src_mux =
  968. SOC_DAPM_ENUM("AIF2DACR Mux", aif2dacr_src_enum);
  969. static const struct snd_soc_dapm_widget wm8994_dapm_widgets[] = {
  970. SND_SOC_DAPM_INPUT("DMIC1DAT"),
  971. SND_SOC_DAPM_INPUT("DMIC2DAT"),
  972. SND_SOC_DAPM_INPUT("Clock"),
  973. SND_SOC_DAPM_SUPPLY("CLK_SYS", SND_SOC_NOPM, 0, 0, clk_sys_event,
  974. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
  975. SND_SOC_DAPM_SUPPLY("DSP1CLK", WM8994_CLOCKING_1, 3, 0, NULL, 0),
  976. SND_SOC_DAPM_SUPPLY("DSP2CLK", WM8994_CLOCKING_1, 2, 0, NULL, 0),
  977. SND_SOC_DAPM_SUPPLY("DSPINTCLK", WM8994_CLOCKING_1, 1, 0, NULL, 0),
  978. SND_SOC_DAPM_SUPPLY("AIF1CLK", WM8994_AIF1_CLOCKING_1, 0, 0, NULL, 0),
  979. SND_SOC_DAPM_SUPPLY("AIF2CLK", WM8994_AIF2_CLOCKING_1, 0, 0, NULL, 0),
  980. SND_SOC_DAPM_AIF_OUT("AIF1ADC1L", "AIF1 Capture",
  981. 0, WM8994_POWER_MANAGEMENT_4, 9, 0),
  982. SND_SOC_DAPM_AIF_OUT("AIF1ADC1R", "AIF1 Capture",
  983. 0, WM8994_POWER_MANAGEMENT_4, 8, 0),
  984. SND_SOC_DAPM_AIF_IN_E("AIF1DAC1L", NULL, 0,
  985. WM8994_POWER_MANAGEMENT_5, 9, 0, wm8958_aif_ev,
  986. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  987. SND_SOC_DAPM_AIF_IN_E("AIF1DAC1R", NULL, 0,
  988. WM8994_POWER_MANAGEMENT_5, 8, 0, wm8958_aif_ev,
  989. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  990. SND_SOC_DAPM_AIF_OUT("AIF1ADC2L", "AIF1 Capture",
  991. 0, WM8994_POWER_MANAGEMENT_4, 11, 0),
  992. SND_SOC_DAPM_AIF_OUT("AIF1ADC2R", "AIF1 Capture",
  993. 0, WM8994_POWER_MANAGEMENT_4, 10, 0),
  994. SND_SOC_DAPM_AIF_IN_E("AIF1DAC2L", NULL, 0,
  995. WM8994_POWER_MANAGEMENT_5, 11, 0, wm8958_aif_ev,
  996. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  997. SND_SOC_DAPM_AIF_IN_E("AIF1DAC2R", NULL, 0,
  998. WM8994_POWER_MANAGEMENT_5, 10, 0, wm8958_aif_ev,
  999. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  1000. SND_SOC_DAPM_MIXER("AIF1ADC1L Mixer", SND_SOC_NOPM, 0, 0,
  1001. aif1adc1l_mix, ARRAY_SIZE(aif1adc1l_mix)),
  1002. SND_SOC_DAPM_MIXER("AIF1ADC1R Mixer", SND_SOC_NOPM, 0, 0,
  1003. aif1adc1r_mix, ARRAY_SIZE(aif1adc1r_mix)),
  1004. SND_SOC_DAPM_MIXER("AIF1ADC2L Mixer", SND_SOC_NOPM, 0, 0,
  1005. aif1adc2l_mix, ARRAY_SIZE(aif1adc2l_mix)),
  1006. SND_SOC_DAPM_MIXER("AIF1ADC2R Mixer", SND_SOC_NOPM, 0, 0,
  1007. aif1adc2r_mix, ARRAY_SIZE(aif1adc2r_mix)),
  1008. SND_SOC_DAPM_MIXER("AIF2DAC2L Mixer", SND_SOC_NOPM, 0, 0,
  1009. aif2dac2l_mix, ARRAY_SIZE(aif2dac2l_mix)),
  1010. SND_SOC_DAPM_MIXER("AIF2DAC2R Mixer", SND_SOC_NOPM, 0, 0,
  1011. aif2dac2r_mix, ARRAY_SIZE(aif2dac2r_mix)),
  1012. SND_SOC_DAPM_MUX("Left Sidetone", SND_SOC_NOPM, 0, 0, &sidetone1_mux),
  1013. SND_SOC_DAPM_MUX("Right Sidetone", SND_SOC_NOPM, 0, 0, &sidetone2_mux),
  1014. SND_SOC_DAPM_MIXER("DAC1L Mixer", SND_SOC_NOPM, 0, 0,
  1015. dac1l_mix, ARRAY_SIZE(dac1l_mix)),
  1016. SND_SOC_DAPM_MIXER("DAC1R Mixer", SND_SOC_NOPM, 0, 0,
  1017. dac1r_mix, ARRAY_SIZE(dac1r_mix)),
  1018. SND_SOC_DAPM_AIF_OUT("AIF2ADCL", NULL, 0,
  1019. WM8994_POWER_MANAGEMENT_4, 13, 0),
  1020. SND_SOC_DAPM_AIF_OUT("AIF2ADCR", NULL, 0,
  1021. WM8994_POWER_MANAGEMENT_4, 12, 0),
  1022. SND_SOC_DAPM_AIF_IN_E("AIF2DACL", NULL, 0,
  1023. WM8994_POWER_MANAGEMENT_5, 13, 0, wm8958_aif_ev,
  1024. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
  1025. SND_SOC_DAPM_AIF_IN_E("AIF2DACR", NULL, 0,
  1026. WM8994_POWER_MANAGEMENT_5, 12, 0, wm8958_aif_ev,
  1027. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
  1028. SND_SOC_DAPM_AIF_IN("AIF1DACDAT", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0),
  1029. SND_SOC_DAPM_AIF_IN("AIF2DACDAT", "AIF2 Playback", 0, SND_SOC_NOPM, 0, 0),
  1030. SND_SOC_DAPM_AIF_OUT("AIF2ADCDAT", "AIF2 Capture", 0, SND_SOC_NOPM, 0, 0),
  1031. SND_SOC_DAPM_MUX("AIF1DAC Mux", SND_SOC_NOPM, 0, 0, &aif1dac_mux),
  1032. SND_SOC_DAPM_MUX("AIF2DAC Mux", SND_SOC_NOPM, 0, 0, &aif2dac_mux),
  1033. SND_SOC_DAPM_MUX("AIF2ADC Mux", SND_SOC_NOPM, 0, 0, &aif2adc_mux),
  1034. SND_SOC_DAPM_AIF_IN("AIF3DACDAT", "AIF3 Playback", 0, SND_SOC_NOPM, 0, 0),
  1035. SND_SOC_DAPM_AIF_IN("AIF3ADCDAT", "AIF3 Capture", 0, SND_SOC_NOPM, 0, 0),
  1036. SND_SOC_DAPM_SUPPLY("TOCLK", WM8994_CLOCKING_1, 4, 0, NULL, 0),
  1037. SND_SOC_DAPM_ADC("DMIC2L", NULL, WM8994_POWER_MANAGEMENT_4, 5, 0),
  1038. SND_SOC_DAPM_ADC("DMIC2R", NULL, WM8994_POWER_MANAGEMENT_4, 4, 0),
  1039. SND_SOC_DAPM_ADC("DMIC1L", NULL, WM8994_POWER_MANAGEMENT_4, 3, 0),
  1040. SND_SOC_DAPM_ADC("DMIC1R", NULL, WM8994_POWER_MANAGEMENT_4, 2, 0),
  1041. /* Power is done with the muxes since the ADC power also controls the
  1042. * downsampling chain, the chip will automatically manage the analogue
  1043. * specific portions.
  1044. */
  1045. SND_SOC_DAPM_ADC("ADCL", NULL, SND_SOC_NOPM, 1, 0),
  1046. SND_SOC_DAPM_ADC("ADCR", NULL, SND_SOC_NOPM, 0, 0),
  1047. SND_SOC_DAPM_MUX("ADCL Mux", WM8994_POWER_MANAGEMENT_4, 1, 0, &adcl_mux),
  1048. SND_SOC_DAPM_MUX("ADCR Mux", WM8994_POWER_MANAGEMENT_4, 0, 0, &adcr_mux),
  1049. SND_SOC_DAPM_DAC("DAC2L", NULL, WM8994_POWER_MANAGEMENT_5, 3, 0),
  1050. SND_SOC_DAPM_DAC("DAC2R", NULL, WM8994_POWER_MANAGEMENT_5, 2, 0),
  1051. SND_SOC_DAPM_DAC("DAC1L", NULL, WM8994_POWER_MANAGEMENT_5, 1, 0),
  1052. SND_SOC_DAPM_DAC("DAC1R", NULL, WM8994_POWER_MANAGEMENT_5, 0, 0),
  1053. SND_SOC_DAPM_MUX("Left Headphone Mux", SND_SOC_NOPM, 0, 0, &hpl_mux),
  1054. SND_SOC_DAPM_MUX("Right Headphone Mux", SND_SOC_NOPM, 0, 0, &hpr_mux),
  1055. SND_SOC_DAPM_MIXER("SPKL", WM8994_POWER_MANAGEMENT_3, 8, 0,
  1056. left_speaker_mixer, ARRAY_SIZE(left_speaker_mixer)),
  1057. SND_SOC_DAPM_MIXER("SPKR", WM8994_POWER_MANAGEMENT_3, 9, 0,
  1058. right_speaker_mixer, ARRAY_SIZE(right_speaker_mixer)),
  1059. SND_SOC_DAPM_POST("Debug log", post_ev),
  1060. };
  1061. static const struct snd_soc_dapm_widget wm8994_specific_dapm_widgets[] = {
  1062. SND_SOC_DAPM_MUX("AIF3ADC Mux", SND_SOC_NOPM, 0, 0, &wm8994_aif3adc_mux),
  1063. };
  1064. static const struct snd_soc_dapm_widget wm8958_dapm_widgets[] = {
  1065. SND_SOC_DAPM_MUX("Mono PCM Out Mux", SND_SOC_NOPM, 0, 0, &mono_pcm_out_mux),
  1066. SND_SOC_DAPM_MUX("AIF2DACL Mux", SND_SOC_NOPM, 0, 0, &aif2dacl_src_mux),
  1067. SND_SOC_DAPM_MUX("AIF2DACR Mux", SND_SOC_NOPM, 0, 0, &aif2dacr_src_mux),
  1068. SND_SOC_DAPM_MUX("AIF3ADC Mux", SND_SOC_NOPM, 0, 0, &wm8958_aif3adc_mux),
  1069. };
  1070. static const struct snd_soc_dapm_route intercon[] = {
  1071. { "CLK_SYS", NULL, "AIF1CLK", check_clk_sys },
  1072. { "CLK_SYS", NULL, "AIF2CLK", check_clk_sys },
  1073. { "DSP1CLK", NULL, "CLK_SYS" },
  1074. { "DSP2CLK", NULL, "CLK_SYS" },
  1075. { "DSPINTCLK", NULL, "CLK_SYS" },
  1076. { "AIF1ADC1L", NULL, "AIF1CLK" },
  1077. { "AIF1ADC1L", NULL, "DSP1CLK" },
  1078. { "AIF1ADC1R", NULL, "AIF1CLK" },
  1079. { "AIF1ADC1R", NULL, "DSP1CLK" },
  1080. { "AIF1ADC1R", NULL, "DSPINTCLK" },
  1081. { "AIF1DAC1L", NULL, "AIF1CLK" },
  1082. { "AIF1DAC1L", NULL, "DSP1CLK" },
  1083. { "AIF1DAC1R", NULL, "AIF1CLK" },
  1084. { "AIF1DAC1R", NULL, "DSP1CLK" },
  1085. { "AIF1DAC1R", NULL, "DSPINTCLK" },
  1086. { "AIF1ADC2L", NULL, "AIF1CLK" },
  1087. { "AIF1ADC2L", NULL, "DSP1CLK" },
  1088. { "AIF1ADC2R", NULL, "AIF1CLK" },
  1089. { "AIF1ADC2R", NULL, "DSP1CLK" },
  1090. { "AIF1ADC2R", NULL, "DSPINTCLK" },
  1091. { "AIF1DAC2L", NULL, "AIF1CLK" },
  1092. { "AIF1DAC2L", NULL, "DSP1CLK" },
  1093. { "AIF1DAC2R", NULL, "AIF1CLK" },
  1094. { "AIF1DAC2R", NULL, "DSP1CLK" },
  1095. { "AIF1DAC2R", NULL, "DSPINTCLK" },
  1096. { "AIF2ADCL", NULL, "AIF2CLK" },
  1097. { "AIF2ADCL", NULL, "DSP2CLK" },
  1098. { "AIF2ADCR", NULL, "AIF2CLK" },
  1099. { "AIF2ADCR", NULL, "DSP2CLK" },
  1100. { "AIF2ADCR", NULL, "DSPINTCLK" },
  1101. { "AIF2DACL", NULL, "AIF2CLK" },
  1102. { "AIF2DACL", NULL, "DSP2CLK" },
  1103. { "AIF2DACR", NULL, "AIF2CLK" },
  1104. { "AIF2DACR", NULL, "DSP2CLK" },
  1105. { "AIF2DACR", NULL, "DSPINTCLK" },
  1106. { "DMIC1L", NULL, "DMIC1DAT" },
  1107. { "DMIC1L", NULL, "CLK_SYS" },
  1108. { "DMIC1R", NULL, "DMIC1DAT" },
  1109. { "DMIC1R", NULL, "CLK_SYS" },
  1110. { "DMIC2L", NULL, "DMIC2DAT" },
  1111. { "DMIC2L", NULL, "CLK_SYS" },
  1112. { "DMIC2R", NULL, "DMIC2DAT" },
  1113. { "DMIC2R", NULL, "CLK_SYS" },
  1114. { "ADCL", NULL, "AIF1CLK" },
  1115. { "ADCL", NULL, "DSP1CLK" },
  1116. { "ADCL", NULL, "DSPINTCLK" },
  1117. { "ADCR", NULL, "AIF1CLK" },
  1118. { "ADCR", NULL, "DSP1CLK" },
  1119. { "ADCR", NULL, "DSPINTCLK" },
  1120. { "ADCL Mux", "ADC", "ADCL" },
  1121. { "ADCL Mux", "DMIC", "DMIC1L" },
  1122. { "ADCR Mux", "ADC", "ADCR" },
  1123. { "ADCR Mux", "DMIC", "DMIC1R" },
  1124. { "DAC1L", NULL, "AIF1CLK" },
  1125. { "DAC1L", NULL, "DSP1CLK" },
  1126. { "DAC1L", NULL, "DSPINTCLK" },
  1127. { "DAC1R", NULL, "AIF1CLK" },
  1128. { "DAC1R", NULL, "DSP1CLK" },
  1129. { "DAC1R", NULL, "DSPINTCLK" },
  1130. { "DAC2L", NULL, "AIF2CLK" },
  1131. { "DAC2L", NULL, "DSP2CLK" },
  1132. { "DAC2L", NULL, "DSPINTCLK" },
  1133. { "DAC2R", NULL, "AIF2DACR" },
  1134. { "DAC2R", NULL, "AIF2CLK" },
  1135. { "DAC2R", NULL, "DSP2CLK" },
  1136. { "DAC2R", NULL, "DSPINTCLK" },
  1137. { "TOCLK", NULL, "CLK_SYS" },
  1138. /* AIF1 outputs */
  1139. { "AIF1ADC1L", NULL, "AIF1ADC1L Mixer" },
  1140. { "AIF1ADC1L Mixer", "ADC/DMIC Switch", "ADCL Mux" },
  1141. { "AIF1ADC1L Mixer", "AIF2 Switch", "AIF2DACL" },
  1142. { "AIF1ADC1R", NULL, "AIF1ADC1R Mixer" },
  1143. { "AIF1ADC1R Mixer", "ADC/DMIC Switch", "ADCR Mux" },
  1144. { "AIF1ADC1R Mixer", "AIF2 Switch", "AIF2DACR" },
  1145. { "AIF1ADC2L", NULL, "AIF1ADC2L Mixer" },
  1146. { "AIF1ADC2L Mixer", "DMIC Switch", "DMIC2L" },
  1147. { "AIF1ADC2L Mixer", "AIF2 Switch", "AIF2DACL" },
  1148. { "AIF1ADC2R", NULL, "AIF1ADC2R Mixer" },
  1149. { "AIF1ADC2R Mixer", "DMIC Switch", "DMIC2R" },
  1150. { "AIF1ADC2R Mixer", "AIF2 Switch", "AIF2DACR" },
  1151. /* Pin level routing for AIF3 */
  1152. { "AIF1DAC1L", NULL, "AIF1DAC Mux" },
  1153. { "AIF1DAC1R", NULL, "AIF1DAC Mux" },
  1154. { "AIF1DAC2L", NULL, "AIF1DAC Mux" },
  1155. { "AIF1DAC2R", NULL, "AIF1DAC Mux" },
  1156. { "AIF1DAC Mux", "AIF1DACDAT", "AIF1DACDAT" },
  1157. { "AIF1DAC Mux", "AIF3DACDAT", "AIF3DACDAT" },
  1158. { "AIF2DAC Mux", "AIF2DACDAT", "AIF2DACDAT" },
  1159. { "AIF2DAC Mux", "AIF3DACDAT", "AIF3DACDAT" },
  1160. { "AIF2ADC Mux", "AIF2ADCDAT", "AIF2ADCL" },
  1161. { "AIF2ADC Mux", "AIF2ADCDAT", "AIF2ADCR" },
  1162. { "AIF2ADC Mux", "AIF3DACDAT", "AIF3ADCDAT" },
  1163. /* DAC1 inputs */
  1164. { "DAC1L", NULL, "DAC1L Mixer" },
  1165. { "DAC1L Mixer", "AIF2 Switch", "AIF2DACL" },
  1166. { "DAC1L Mixer", "AIF1.2 Switch", "AIF1DAC2L" },
  1167. { "DAC1L Mixer", "AIF1.1 Switch", "AIF1DAC1L" },
  1168. { "DAC1L Mixer", "Left Sidetone Switch", "Left Sidetone" },
  1169. { "DAC1L Mixer", "Right Sidetone Switch", "Right Sidetone" },
  1170. { "DAC1R", NULL, "DAC1R Mixer" },
  1171. { "DAC1R Mixer", "AIF2 Switch", "AIF2DACR" },
  1172. { "DAC1R Mixer", "AIF1.2 Switch", "AIF1DAC2R" },
  1173. { "DAC1R Mixer", "AIF1.1 Switch", "AIF1DAC1R" },
  1174. { "DAC1R Mixer", "Left Sidetone Switch", "Left Sidetone" },
  1175. { "DAC1R Mixer", "Right Sidetone Switch", "Right Sidetone" },
  1176. /* DAC2/AIF2 outputs */
  1177. { "AIF2ADCL", NULL, "AIF2DAC2L Mixer" },
  1178. { "DAC2L", NULL, "AIF2DAC2L Mixer" },
  1179. { "AIF2DAC2L Mixer", "AIF2 Switch", "AIF2DACL" },
  1180. { "AIF2DAC2L Mixer", "AIF1.2 Switch", "AIF1DAC2L" },
  1181. { "AIF2DAC2L Mixer", "AIF1.1 Switch", "AIF1DAC1L" },
  1182. { "AIF2DAC2L Mixer", "Left Sidetone Switch", "Left Sidetone" },
  1183. { "AIF2DAC2L Mixer", "Right Sidetone Switch", "Right Sidetone" },
  1184. { "AIF2ADCR", NULL, "AIF2DAC2R Mixer" },
  1185. { "DAC2R", NULL, "AIF2DAC2R Mixer" },
  1186. { "AIF2DAC2R Mixer", "AIF2 Switch", "AIF2DACR" },
  1187. { "AIF2DAC2R Mixer", "AIF1.2 Switch", "AIF1DAC2R" },
  1188. { "AIF2DAC2R Mixer", "AIF1.1 Switch", "AIF1DAC1R" },
  1189. { "AIF2DAC2R Mixer", "Left Sidetone Switch", "Left Sidetone" },
  1190. { "AIF2DAC2R Mixer", "Right Sidetone Switch", "Right Sidetone" },
  1191. { "AIF2ADCDAT", NULL, "AIF2ADC Mux" },
  1192. /* AIF3 output */
  1193. { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC1L" },
  1194. { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC1R" },
  1195. { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC2L" },
  1196. { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC2R" },
  1197. { "AIF3ADCDAT", "AIF2ADCDAT", "AIF2ADCL" },
  1198. { "AIF3ADCDAT", "AIF2ADCDAT", "AIF2ADCR" },
  1199. { "AIF3ADCDAT", "AIF2DACDAT", "AIF2DACL" },
  1200. { "AIF3ADCDAT", "AIF2DACDAT", "AIF2DACR" },
  1201. /* Sidetone */
  1202. { "Left Sidetone", "ADC/DMIC1", "ADCL Mux" },
  1203. { "Left Sidetone", "DMIC2", "DMIC2L" },
  1204. { "Right Sidetone", "ADC/DMIC1", "ADCR Mux" },
  1205. { "Right Sidetone", "DMIC2", "DMIC2R" },
  1206. /* Output stages */
  1207. { "Left Output Mixer", "DAC Switch", "DAC1L" },
  1208. { "Right Output Mixer", "DAC Switch", "DAC1R" },
  1209. { "SPKL", "DAC1 Switch", "DAC1L" },
  1210. { "SPKL", "DAC2 Switch", "DAC2L" },
  1211. { "SPKR", "DAC1 Switch", "DAC1R" },
  1212. { "SPKR", "DAC2 Switch", "DAC2R" },
  1213. { "Left Headphone Mux", "DAC", "DAC1L" },
  1214. { "Right Headphone Mux", "DAC", "DAC1R" },
  1215. };
  1216. static const struct snd_soc_dapm_route wm8994_intercon[] = {
  1217. { "AIF2DACL", NULL, "AIF2DAC Mux" },
  1218. { "AIF2DACR", NULL, "AIF2DAC Mux" },
  1219. };
  1220. static const struct snd_soc_dapm_route wm8958_intercon[] = {
  1221. { "AIF2DACL", NULL, "AIF2DACL Mux" },
  1222. { "AIF2DACR", NULL, "AIF2DACR Mux" },
  1223. { "AIF2DACL Mux", "AIF2", "AIF2DAC Mux" },
  1224. { "AIF2DACL Mux", "AIF3", "AIF3DACDAT" },
  1225. { "AIF2DACR Mux", "AIF2", "AIF2DAC Mux" },
  1226. { "AIF2DACR Mux", "AIF3", "AIF3DACDAT" },
  1227. { "Mono PCM Out Mux", "AIF2ADCL", "AIF2ADCL" },
  1228. { "Mono PCM Out Mux", "AIF2ADCR", "AIF2ADCR" },
  1229. { "AIF3ADC Mux", "Mono PCM", "Mono PCM Out Mux" },
  1230. };
  1231. /* The size in bits of the FLL divide multiplied by 10
  1232. * to allow rounding later */
  1233. #define FIXED_FLL_SIZE ((1 << 16) * 10)
  1234. struct fll_div {
  1235. u16 outdiv;
  1236. u16 n;
  1237. u16 k;
  1238. u16 clk_ref_div;
  1239. u16 fll_fratio;
  1240. };
  1241. static int wm8994_get_fll_config(struct fll_div *fll,
  1242. int freq_in, int freq_out)
  1243. {
  1244. u64 Kpart;
  1245. unsigned int K, Ndiv, Nmod;
  1246. pr_debug("FLL input=%dHz, output=%dHz\n", freq_in, freq_out);
  1247. /* Scale the input frequency down to <= 13.5MHz */
  1248. fll->clk_ref_div = 0;
  1249. while (freq_in > 13500000) {
  1250. fll->clk_ref_div++;
  1251. freq_in /= 2;
  1252. if (fll->clk_ref_div > 3)
  1253. return -EINVAL;
  1254. }
  1255. pr_debug("CLK_REF_DIV=%d, Fref=%dHz\n", fll->clk_ref_div, freq_in);
  1256. /* Scale the output to give 90MHz<=Fvco<=100MHz */
  1257. fll->outdiv = 3;
  1258. while (freq_out * (fll->outdiv + 1) < 90000000) {
  1259. fll->outdiv++;
  1260. if (fll->outdiv > 63)
  1261. return -EINVAL;
  1262. }
  1263. freq_out *= fll->outdiv + 1;
  1264. pr_debug("OUTDIV=%d, Fvco=%dHz\n", fll->outdiv, freq_out);
  1265. if (freq_in > 1000000) {
  1266. fll->fll_fratio = 0;
  1267. } else if (freq_in > 256000) {
  1268. fll->fll_fratio = 1;
  1269. freq_in *= 2;
  1270. } else if (freq_in > 128000) {
  1271. fll->fll_fratio = 2;
  1272. freq_in *= 4;
  1273. } else if (freq_in > 64000) {
  1274. fll->fll_fratio = 3;
  1275. freq_in *= 8;
  1276. } else {
  1277. fll->fll_fratio = 4;
  1278. freq_in *= 16;
  1279. }
  1280. pr_debug("FLL_FRATIO=%d, Fref=%dHz\n", fll->fll_fratio, freq_in);
  1281. /* Now, calculate N.K */
  1282. Ndiv = freq_out / freq_in;
  1283. fll->n = Ndiv;
  1284. Nmod = freq_out % freq_in;
  1285. pr_debug("Nmod=%d\n", Nmod);
  1286. /* Calculate fractional part - scale up so we can round. */
  1287. Kpart = FIXED_FLL_SIZE * (long long)Nmod;
  1288. do_div(Kpart, freq_in);
  1289. K = Kpart & 0xFFFFFFFF;
  1290. if ((K % 10) >= 5)
  1291. K += 5;
  1292. /* Move down to proper range now rounding is done */
  1293. fll->k = K / 10;
  1294. pr_debug("N=%x K=%x\n", fll->n, fll->k);
  1295. return 0;
  1296. }
  1297. static int _wm8994_set_fll(struct snd_soc_codec *codec, int id, int src,
  1298. unsigned int freq_in, unsigned int freq_out)
  1299. {
  1300. struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
  1301. int reg_offset, ret;
  1302. struct fll_div fll;
  1303. u16 reg, aif1, aif2;
  1304. aif1 = snd_soc_read(codec, WM8994_AIF1_CLOCKING_1)
  1305. & WM8994_AIF1CLK_ENA;
  1306. aif2 = snd_soc_read(codec, WM8994_AIF2_CLOCKING_1)
  1307. & WM8994_AIF2CLK_ENA;
  1308. switch (id) {
  1309. case WM8994_FLL1:
  1310. reg_offset = 0;
  1311. id = 0;
  1312. break;
  1313. case WM8994_FLL2:
  1314. reg_offset = 0x20;
  1315. id = 1;
  1316. break;
  1317. default:
  1318. return -EINVAL;
  1319. }
  1320. switch (src) {
  1321. case 0:
  1322. /* Allow no source specification when stopping */
  1323. if (freq_out)
  1324. return -EINVAL;
  1325. break;
  1326. case WM8994_FLL_SRC_MCLK1:
  1327. case WM8994_FLL_SRC_MCLK2:
  1328. case WM8994_FLL_SRC_LRCLK:
  1329. case WM8994_FLL_SRC_BCLK:
  1330. break;
  1331. default:
  1332. return -EINVAL;
  1333. }
  1334. /* Are we changing anything? */
  1335. if (wm8994->fll[id].src == src &&
  1336. wm8994->fll[id].in == freq_in && wm8994->fll[id].out == freq_out)
  1337. return 0;
  1338. /* If we're stopping the FLL redo the old config - no
  1339. * registers will actually be written but we avoid GCC flow
  1340. * analysis bugs spewing warnings.
  1341. */
  1342. if (freq_out)
  1343. ret = wm8994_get_fll_config(&fll, freq_in, freq_out);
  1344. else
  1345. ret = wm8994_get_fll_config(&fll, wm8994->fll[id].in,
  1346. wm8994->fll[id].out);
  1347. if (ret < 0)
  1348. return ret;
  1349. /* Gate the AIF clocks while we reclock */
  1350. snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1,
  1351. WM8994_AIF1CLK_ENA, 0);
  1352. snd_soc_update_bits(codec, WM8994_AIF2_CLOCKING_1,
  1353. WM8994_AIF2CLK_ENA, 0);
  1354. /* We always need to disable the FLL while reconfiguring */
  1355. snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_1 + reg_offset,
  1356. WM8994_FLL1_ENA, 0);
  1357. reg = (fll.outdiv << WM8994_FLL1_OUTDIV_SHIFT) |
  1358. (fll.fll_fratio << WM8994_FLL1_FRATIO_SHIFT);
  1359. snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_2 + reg_offset,
  1360. WM8994_FLL1_OUTDIV_MASK |
  1361. WM8994_FLL1_FRATIO_MASK, reg);
  1362. snd_soc_write(codec, WM8994_FLL1_CONTROL_3 + reg_offset, fll.k);
  1363. snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_4 + reg_offset,
  1364. WM8994_FLL1_N_MASK,
  1365. fll.n << WM8994_FLL1_N_SHIFT);
  1366. snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_5 + reg_offset,
  1367. WM8994_FLL1_REFCLK_DIV_MASK |
  1368. WM8994_FLL1_REFCLK_SRC_MASK,
  1369. (fll.clk_ref_div << WM8994_FLL1_REFCLK_DIV_SHIFT) |
  1370. (src - 1));
  1371. /* Enable (with fractional mode if required) */
  1372. if (freq_out) {
  1373. if (fll.k)
  1374. reg = WM8994_FLL1_ENA | WM8994_FLL1_FRAC;
  1375. else
  1376. reg = WM8994_FLL1_ENA;
  1377. snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_1 + reg_offset,
  1378. WM8994_FLL1_ENA | WM8994_FLL1_FRAC,
  1379. reg);
  1380. }
  1381. wm8994->fll[id].in = freq_in;
  1382. wm8994->fll[id].out = freq_out;
  1383. wm8994->fll[id].src = src;
  1384. /* Enable any gated AIF clocks */
  1385. snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1,
  1386. WM8994_AIF1CLK_ENA, aif1);
  1387. snd_soc_update_bits(codec, WM8994_AIF2_CLOCKING_1,
  1388. WM8994_AIF2CLK_ENA, aif2);
  1389. configure_clock(codec);
  1390. return 0;
  1391. }
  1392. static int opclk_divs[] = { 10, 20, 30, 40, 55, 60, 80, 120, 160 };
  1393. static int wm8994_set_fll(struct snd_soc_dai *dai, int id, int src,
  1394. unsigned int freq_in, unsigned int freq_out)
  1395. {
  1396. return _wm8994_set_fll(dai->codec, id, src, freq_in, freq_out);
  1397. }
  1398. static int wm8994_set_dai_sysclk(struct snd_soc_dai *dai,
  1399. int clk_id, unsigned int freq, int dir)
  1400. {
  1401. struct snd_soc_codec *codec = dai->codec;
  1402. struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
  1403. int i;
  1404. switch (dai->id) {
  1405. case 1:
  1406. case 2:
  1407. break;
  1408. default:
  1409. /* AIF3 shares clocking with AIF1/2 */
  1410. return -EINVAL;
  1411. }
  1412. switch (clk_id) {
  1413. case WM8994_SYSCLK_MCLK1:
  1414. wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_MCLK1;
  1415. wm8994->mclk[0] = freq;
  1416. dev_dbg(dai->dev, "AIF%d using MCLK1 at %uHz\n",
  1417. dai->id, freq);
  1418. break;
  1419. case WM8994_SYSCLK_MCLK2:
  1420. /* TODO: Set GPIO AF */
  1421. wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_MCLK2;
  1422. wm8994->mclk[1] = freq;
  1423. dev_dbg(dai->dev, "AIF%d using MCLK2 at %uHz\n",
  1424. dai->id, freq);
  1425. break;
  1426. case WM8994_SYSCLK_FLL1:
  1427. wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_FLL1;
  1428. dev_dbg(dai->dev, "AIF%d using FLL1\n", dai->id);
  1429. break;
  1430. case WM8994_SYSCLK_FLL2:
  1431. wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_FLL2;
  1432. dev_dbg(dai->dev, "AIF%d using FLL2\n", dai->id);
  1433. break;
  1434. case WM8994_SYSCLK_OPCLK:
  1435. /* Special case - a division (times 10) is given and
  1436. * no effect on main clocking.
  1437. */
  1438. if (freq) {
  1439. for (i = 0; i < ARRAY_SIZE(opclk_divs); i++)
  1440. if (opclk_divs[i] == freq)
  1441. break;
  1442. if (i == ARRAY_SIZE(opclk_divs))
  1443. return -EINVAL;
  1444. snd_soc_update_bits(codec, WM8994_CLOCKING_2,
  1445. WM8994_OPCLK_DIV_MASK, i);
  1446. snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_2,
  1447. WM8994_OPCLK_ENA, WM8994_OPCLK_ENA);
  1448. } else {
  1449. snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_2,
  1450. WM8994_OPCLK_ENA, 0);
  1451. }
  1452. default:
  1453. return -EINVAL;
  1454. }
  1455. configure_clock(codec);
  1456. return 0;
  1457. }
  1458. static int wm8994_set_bias_level(struct snd_soc_codec *codec,
  1459. enum snd_soc_bias_level level)
  1460. {
  1461. struct wm8994 *control = codec->control_data;
  1462. struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
  1463. switch (level) {
  1464. case SND_SOC_BIAS_ON:
  1465. break;
  1466. case SND_SOC_BIAS_PREPARE:
  1467. /* VMID=2x40k */
  1468. snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
  1469. WM8994_VMID_SEL_MASK, 0x2);
  1470. break;
  1471. case SND_SOC_BIAS_STANDBY:
  1472. if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
  1473. pm_runtime_get_sync(codec->dev);
  1474. /* Tweak DC servo and DSP configuration for
  1475. * improved performance. */
  1476. if (control->type == WM8994 && wm8994->revision < 4) {
  1477. /* Tweak DC servo and DSP configuration for
  1478. * improved performance. */
  1479. snd_soc_write(codec, 0x102, 0x3);
  1480. snd_soc_write(codec, 0x56, 0x3);
  1481. snd_soc_write(codec, 0x817, 0);
  1482. snd_soc_write(codec, 0x102, 0);
  1483. }
  1484. /* Discharge LINEOUT1 & 2 */
  1485. snd_soc_update_bits(codec, WM8994_ANTIPOP_1,
  1486. WM8994_LINEOUT1_DISCH |
  1487. WM8994_LINEOUT2_DISCH,
  1488. WM8994_LINEOUT1_DISCH |
  1489. WM8994_LINEOUT2_DISCH);
  1490. /* Startup bias, VMID ramp & buffer */
  1491. snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
  1492. WM8994_STARTUP_BIAS_ENA |
  1493. WM8994_VMID_BUF_ENA |
  1494. WM8994_VMID_RAMP_MASK,
  1495. WM8994_STARTUP_BIAS_ENA |
  1496. WM8994_VMID_BUF_ENA |
  1497. (0x11 << WM8994_VMID_RAMP_SHIFT));
  1498. /* Main bias enable, VMID=2x40k */
  1499. snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
  1500. WM8994_BIAS_ENA |
  1501. WM8994_VMID_SEL_MASK,
  1502. WM8994_BIAS_ENA | 0x2);
  1503. msleep(20);
  1504. }
  1505. /* VMID=2x500k */
  1506. snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
  1507. WM8994_VMID_SEL_MASK, 0x4);
  1508. break;
  1509. case SND_SOC_BIAS_OFF:
  1510. if (codec->dapm.bias_level == SND_SOC_BIAS_STANDBY) {
  1511. /* Switch over to startup biases */
  1512. snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
  1513. WM8994_BIAS_SRC |
  1514. WM8994_STARTUP_BIAS_ENA |
  1515. WM8994_VMID_BUF_ENA |
  1516. WM8994_VMID_RAMP_MASK,
  1517. WM8994_BIAS_SRC |
  1518. WM8994_STARTUP_BIAS_ENA |
  1519. WM8994_VMID_BUF_ENA |
  1520. (1 << WM8994_VMID_RAMP_SHIFT));
  1521. /* Disable main biases */
  1522. snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1,
  1523. WM8994_BIAS_ENA |
  1524. WM8994_VMID_SEL_MASK, 0);
  1525. /* Discharge line */
  1526. snd_soc_update_bits(codec, WM8994_ANTIPOP_1,
  1527. WM8994_LINEOUT1_DISCH |
  1528. WM8994_LINEOUT2_DISCH,
  1529. WM8994_LINEOUT1_DISCH |
  1530. WM8994_LINEOUT2_DISCH);
  1531. msleep(5);
  1532. /* Switch off startup biases */
  1533. snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
  1534. WM8994_BIAS_SRC |
  1535. WM8994_STARTUP_BIAS_ENA |
  1536. WM8994_VMID_BUF_ENA |
  1537. WM8994_VMID_RAMP_MASK, 0);
  1538. pm_runtime_put(codec->dev);
  1539. }
  1540. break;
  1541. }
  1542. codec->dapm.bias_level = level;
  1543. return 0;
  1544. }
  1545. static int wm8994_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
  1546. {
  1547. struct snd_soc_codec *codec = dai->codec;
  1548. struct wm8994 *control = codec->control_data;
  1549. int ms_reg;
  1550. int aif1_reg;
  1551. int ms = 0;
  1552. int aif1 = 0;
  1553. switch (dai->id) {
  1554. case 1:
  1555. ms_reg = WM8994_AIF1_MASTER_SLAVE;
  1556. aif1_reg = WM8994_AIF1_CONTROL_1;
  1557. break;
  1558. case 2:
  1559. ms_reg = WM8994_AIF2_MASTER_SLAVE;
  1560. aif1_reg = WM8994_AIF2_CONTROL_1;
  1561. break;
  1562. default:
  1563. return -EINVAL;
  1564. }
  1565. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  1566. case SND_SOC_DAIFMT_CBS_CFS:
  1567. break;
  1568. case SND_SOC_DAIFMT_CBM_CFM:
  1569. ms = WM8994_AIF1_MSTR;
  1570. break;
  1571. default:
  1572. return -EINVAL;
  1573. }
  1574. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  1575. case SND_SOC_DAIFMT_DSP_B:
  1576. aif1 |= WM8994_AIF1_LRCLK_INV;
  1577. case SND_SOC_DAIFMT_DSP_A:
  1578. aif1 |= 0x18;
  1579. break;
  1580. case SND_SOC_DAIFMT_I2S:
  1581. aif1 |= 0x10;
  1582. break;
  1583. case SND_SOC_DAIFMT_RIGHT_J:
  1584. break;
  1585. case SND_SOC_DAIFMT_LEFT_J:
  1586. aif1 |= 0x8;
  1587. break;
  1588. default:
  1589. return -EINVAL;
  1590. }
  1591. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  1592. case SND_SOC_DAIFMT_DSP_A:
  1593. case SND_SOC_DAIFMT_DSP_B:
  1594. /* frame inversion not valid for DSP modes */
  1595. switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
  1596. case SND_SOC_DAIFMT_NB_NF:
  1597. break;
  1598. case SND_SOC_DAIFMT_IB_NF:
  1599. aif1 |= WM8994_AIF1_BCLK_INV;
  1600. break;
  1601. default:
  1602. return -EINVAL;
  1603. }
  1604. break;
  1605. case SND_SOC_DAIFMT_I2S:
  1606. case SND_SOC_DAIFMT_RIGHT_J:
  1607. case SND_SOC_DAIFMT_LEFT_J:
  1608. switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
  1609. case SND_SOC_DAIFMT_NB_NF:
  1610. break;
  1611. case SND_SOC_DAIFMT_IB_IF:
  1612. aif1 |= WM8994_AIF1_BCLK_INV | WM8994_AIF1_LRCLK_INV;
  1613. break;
  1614. case SND_SOC_DAIFMT_IB_NF:
  1615. aif1 |= WM8994_AIF1_BCLK_INV;
  1616. break;
  1617. case SND_SOC_DAIFMT_NB_IF:
  1618. aif1 |= WM8994_AIF1_LRCLK_INV;
  1619. break;
  1620. default:
  1621. return -EINVAL;
  1622. }
  1623. break;
  1624. default:
  1625. return -EINVAL;
  1626. }
  1627. /* The AIF2 format configuration needs to be mirrored to AIF3
  1628. * on WM8958 if it's in use so just do it all the time. */
  1629. if (control->type == WM8958 && dai->id == 2)
  1630. snd_soc_update_bits(codec, WM8958_AIF3_CONTROL_1,
  1631. WM8994_AIF1_LRCLK_INV |
  1632. WM8958_AIF3_FMT_MASK, aif1);
  1633. snd_soc_update_bits(codec, aif1_reg,
  1634. WM8994_AIF1_BCLK_INV | WM8994_AIF1_LRCLK_INV |
  1635. WM8994_AIF1_FMT_MASK,
  1636. aif1);
  1637. snd_soc_update_bits(codec, ms_reg, WM8994_AIF1_MSTR,
  1638. ms);
  1639. return 0;
  1640. }
  1641. static struct {
  1642. int val, rate;
  1643. } srs[] = {
  1644. { 0, 8000 },
  1645. { 1, 11025 },
  1646. { 2, 12000 },
  1647. { 3, 16000 },
  1648. { 4, 22050 },
  1649. { 5, 24000 },
  1650. { 6, 32000 },
  1651. { 7, 44100 },
  1652. { 8, 48000 },
  1653. { 9, 88200 },
  1654. { 10, 96000 },
  1655. };
  1656. static int fs_ratios[] = {
  1657. 64, 128, 192, 256, 348, 512, 768, 1024, 1408, 1536
  1658. };
  1659. static int bclk_divs[] = {
  1660. 10, 15, 20, 30, 40, 50, 60, 80, 110, 120, 160, 220, 240, 320, 440, 480,
  1661. 640, 880, 960, 1280, 1760, 1920
  1662. };
  1663. static int wm8994_hw_params(struct snd_pcm_substream *substream,
  1664. struct snd_pcm_hw_params *params,
  1665. struct snd_soc_dai *dai)
  1666. {
  1667. struct snd_soc_codec *codec = dai->codec;
  1668. struct wm8994 *control = codec->control_data;
  1669. struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
  1670. int aif1_reg;
  1671. int bclk_reg;
  1672. int lrclk_reg;
  1673. int rate_reg;
  1674. int aif1 = 0;
  1675. int bclk = 0;
  1676. int lrclk = 0;
  1677. int rate_val = 0;
  1678. int id = dai->id - 1;
  1679. int i, cur_val, best_val, bclk_rate, best;
  1680. switch (dai->id) {
  1681. case 1:
  1682. aif1_reg = WM8994_AIF1_CONTROL_1;
  1683. bclk_reg = WM8994_AIF1_BCLK;
  1684. rate_reg = WM8994_AIF1_RATE;
  1685. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK ||
  1686. wm8994->lrclk_shared[0]) {
  1687. lrclk_reg = WM8994_AIF1DAC_LRCLK;
  1688. } else {
  1689. lrclk_reg = WM8994_AIF1ADC_LRCLK;
  1690. dev_dbg(codec->dev, "AIF1 using split LRCLK\n");
  1691. }
  1692. break;
  1693. case 2:
  1694. aif1_reg = WM8994_AIF2_CONTROL_1;
  1695. bclk_reg = WM8994_AIF2_BCLK;
  1696. rate_reg = WM8994_AIF2_RATE;
  1697. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK ||
  1698. wm8994->lrclk_shared[1]) {
  1699. lrclk_reg = WM8994_AIF2DAC_LRCLK;
  1700. } else {
  1701. lrclk_reg = WM8994_AIF2ADC_LRCLK;
  1702. dev_dbg(codec->dev, "AIF2 using split LRCLK\n");
  1703. }
  1704. break;
  1705. case 3:
  1706. switch (control->type) {
  1707. case WM8958:
  1708. aif1_reg = WM8958_AIF3_CONTROL_1;
  1709. break;
  1710. default:
  1711. return 0;
  1712. }
  1713. default:
  1714. return -EINVAL;
  1715. }
  1716. bclk_rate = params_rate(params) * 2;
  1717. switch (params_format(params)) {
  1718. case SNDRV_PCM_FORMAT_S16_LE:
  1719. bclk_rate *= 16;
  1720. break;
  1721. case SNDRV_PCM_FORMAT_S20_3LE:
  1722. bclk_rate *= 20;
  1723. aif1 |= 0x20;
  1724. break;
  1725. case SNDRV_PCM_FORMAT_S24_LE:
  1726. bclk_rate *= 24;
  1727. aif1 |= 0x40;
  1728. break;
  1729. case SNDRV_PCM_FORMAT_S32_LE:
  1730. bclk_rate *= 32;
  1731. aif1 |= 0x60;
  1732. break;
  1733. default:
  1734. return -EINVAL;
  1735. }
  1736. /* Try to find an appropriate sample rate; look for an exact match. */
  1737. for (i = 0; i < ARRAY_SIZE(srs); i++)
  1738. if (srs[i].rate == params_rate(params))
  1739. break;
  1740. if (i == ARRAY_SIZE(srs))
  1741. return -EINVAL;
  1742. rate_val |= srs[i].val << WM8994_AIF1_SR_SHIFT;
  1743. dev_dbg(dai->dev, "Sample rate is %dHz\n", srs[i].rate);
  1744. dev_dbg(dai->dev, "AIF%dCLK is %dHz, target BCLK %dHz\n",
  1745. dai->id, wm8994->aifclk[id], bclk_rate);
  1746. if (wm8994->aifclk[id] == 0) {
  1747. dev_err(dai->dev, "AIF%dCLK not configured\n", dai->id);
  1748. return -EINVAL;
  1749. }
  1750. /* AIFCLK/fs ratio; look for a close match in either direction */
  1751. best = 0;
  1752. best_val = abs((fs_ratios[0] * params_rate(params))
  1753. - wm8994->aifclk[id]);
  1754. for (i = 1; i < ARRAY_SIZE(fs_ratios); i++) {
  1755. cur_val = abs((fs_ratios[i] * params_rate(params))
  1756. - wm8994->aifclk[id]);
  1757. if (cur_val >= best_val)
  1758. continue;
  1759. best = i;
  1760. best_val = cur_val;
  1761. }
  1762. dev_dbg(dai->dev, "Selected AIF%dCLK/fs = %d\n",
  1763. dai->id, fs_ratios[best]);
  1764. rate_val |= best;
  1765. /* We may not get quite the right frequency if using
  1766. * approximate clocks so look for the closest match that is
  1767. * higher than the target (we need to ensure that there enough
  1768. * BCLKs to clock out the samples).
  1769. */
  1770. best = 0;
  1771. for (i = 0; i < ARRAY_SIZE(bclk_divs); i++) {
  1772. cur_val = (wm8994->aifclk[id] * 10 / bclk_divs[i]) - bclk_rate;
  1773. if (cur_val < 0) /* BCLK table is sorted */
  1774. break;
  1775. best = i;
  1776. }
  1777. bclk_rate = wm8994->aifclk[id] * 10 / bclk_divs[best];
  1778. dev_dbg(dai->dev, "Using BCLK_DIV %d for actual BCLK %dHz\n",
  1779. bclk_divs[best], bclk_rate);
  1780. bclk |= best << WM8994_AIF1_BCLK_DIV_SHIFT;
  1781. lrclk = bclk_rate / params_rate(params);
  1782. dev_dbg(dai->dev, "Using LRCLK rate %d for actual LRCLK %dHz\n",
  1783. lrclk, bclk_rate / lrclk);
  1784. snd_soc_update_bits(codec, aif1_reg, WM8994_AIF1_WL_MASK, aif1);
  1785. snd_soc_update_bits(codec, bclk_reg, WM8994_AIF1_BCLK_DIV_MASK, bclk);
  1786. snd_soc_update_bits(codec, lrclk_reg, WM8994_AIF1DAC_RATE_MASK,
  1787. lrclk);
  1788. snd_soc_update_bits(codec, rate_reg, WM8994_AIF1_SR_MASK |
  1789. WM8994_AIF1CLK_RATE_MASK, rate_val);
  1790. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  1791. switch (dai->id) {
  1792. case 1:
  1793. wm8994->dac_rates[0] = params_rate(params);
  1794. wm8994_set_retune_mobile(codec, 0);
  1795. wm8994_set_retune_mobile(codec, 1);
  1796. break;
  1797. case 2:
  1798. wm8994->dac_rates[1] = params_rate(params);
  1799. wm8994_set_retune_mobile(codec, 2);
  1800. break;
  1801. }
  1802. }
  1803. return 0;
  1804. }
  1805. static int wm8994_aif3_hw_params(struct snd_pcm_substream *substream,
  1806. struct snd_pcm_hw_params *params,
  1807. struct snd_soc_dai *dai)
  1808. {
  1809. struct snd_soc_codec *codec = dai->codec;
  1810. struct wm8994 *control = codec->control_data;
  1811. int aif1_reg;
  1812. int aif1 = 0;
  1813. switch (dai->id) {
  1814. case 3:
  1815. switch (control->type) {
  1816. case WM8958:
  1817. aif1_reg = WM8958_AIF3_CONTROL_1;
  1818. break;
  1819. default:
  1820. return 0;
  1821. }
  1822. default:
  1823. return 0;
  1824. }
  1825. switch (params_format(params)) {
  1826. case SNDRV_PCM_FORMAT_S16_LE:
  1827. break;
  1828. case SNDRV_PCM_FORMAT_S20_3LE:
  1829. aif1 |= 0x20;
  1830. break;
  1831. case SNDRV_PCM_FORMAT_S24_LE:
  1832. aif1 |= 0x40;
  1833. break;
  1834. case SNDRV_PCM_FORMAT_S32_LE:
  1835. aif1 |= 0x60;
  1836. break;
  1837. default:
  1838. return -EINVAL;
  1839. }
  1840. return snd_soc_update_bits(codec, aif1_reg, WM8994_AIF1_WL_MASK, aif1);
  1841. }
  1842. static int wm8994_aif_mute(struct snd_soc_dai *codec_dai, int mute)
  1843. {
  1844. struct snd_soc_codec *codec = codec_dai->codec;
  1845. int mute_reg;
  1846. int reg;
  1847. switch (codec_dai->id) {
  1848. case 1:
  1849. mute_reg = WM8994_AIF1_DAC1_FILTERS_1;
  1850. break;
  1851. case 2:
  1852. mute_reg = WM8994_AIF2_DAC_FILTERS_1;
  1853. break;
  1854. default:
  1855. return -EINVAL;
  1856. }
  1857. if (mute)
  1858. reg = WM8994_AIF1DAC1_MUTE;
  1859. else
  1860. reg = 0;
  1861. snd_soc_update_bits(codec, mute_reg, WM8994_AIF1DAC1_MUTE, reg);
  1862. return 0;
  1863. }
  1864. static int wm8994_set_tristate(struct snd_soc_dai *codec_dai, int tristate)
  1865. {
  1866. struct snd_soc_codec *codec = codec_dai->codec;
  1867. int reg, val, mask;
  1868. switch (codec_dai->id) {
  1869. case 1:
  1870. reg = WM8994_AIF1_MASTER_SLAVE;
  1871. mask = WM8994_AIF1_TRI;
  1872. break;
  1873. case 2:
  1874. reg = WM8994_AIF2_MASTER_SLAVE;
  1875. mask = WM8994_AIF2_TRI;
  1876. break;
  1877. case 3:
  1878. reg = WM8994_POWER_MANAGEMENT_6;
  1879. mask = WM8994_AIF3_TRI;
  1880. break;
  1881. default:
  1882. return -EINVAL;
  1883. }
  1884. if (tristate)
  1885. val = mask;
  1886. else
  1887. val = 0;
  1888. return snd_soc_update_bits(codec, reg, mask, reg);
  1889. }
  1890. #define WM8994_RATES SNDRV_PCM_RATE_8000_96000
  1891. #define WM8994_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
  1892. SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
  1893. static struct snd_soc_dai_ops wm8994_aif1_dai_ops = {
  1894. .set_sysclk = wm8994_set_dai_sysclk,
  1895. .set_fmt = wm8994_set_dai_fmt,
  1896. .hw_params = wm8994_hw_params,
  1897. .digital_mute = wm8994_aif_mute,
  1898. .set_pll = wm8994_set_fll,
  1899. .set_tristate = wm8994_set_tristate,
  1900. };
  1901. static struct snd_soc_dai_ops wm8994_aif2_dai_ops = {
  1902. .set_sysclk = wm8994_set_dai_sysclk,
  1903. .set_fmt = wm8994_set_dai_fmt,
  1904. .hw_params = wm8994_hw_params,
  1905. .digital_mute = wm8994_aif_mute,
  1906. .set_pll = wm8994_set_fll,
  1907. .set_tristate = wm8994_set_tristate,
  1908. };
  1909. static struct snd_soc_dai_ops wm8994_aif3_dai_ops = {
  1910. .hw_params = wm8994_aif3_hw_params,
  1911. .set_tristate = wm8994_set_tristate,
  1912. };
  1913. static struct snd_soc_dai_driver wm8994_dai[] = {
  1914. {
  1915. .name = "wm8994-aif1",
  1916. .id = 1,
  1917. .playback = {
  1918. .stream_name = "AIF1 Playback",
  1919. .channels_min = 2,
  1920. .channels_max = 2,
  1921. .rates = WM8994_RATES,
  1922. .formats = WM8994_FORMATS,
  1923. },
  1924. .capture = {
  1925. .stream_name = "AIF1 Capture",
  1926. .channels_min = 2,
  1927. .channels_max = 2,
  1928. .rates = WM8994_RATES,
  1929. .formats = WM8994_FORMATS,
  1930. },
  1931. .ops = &wm8994_aif1_dai_ops,
  1932. },
  1933. {
  1934. .name = "wm8994-aif2",
  1935. .id = 2,
  1936. .playback = {
  1937. .stream_name = "AIF2 Playback",
  1938. .channels_min = 2,
  1939. .channels_max = 2,
  1940. .rates = WM8994_RATES,
  1941. .formats = WM8994_FORMATS,
  1942. },
  1943. .capture = {
  1944. .stream_name = "AIF2 Capture",
  1945. .channels_min = 2,
  1946. .channels_max = 2,
  1947. .rates = WM8994_RATES,
  1948. .formats = WM8994_FORMATS,
  1949. },
  1950. .ops = &wm8994_aif2_dai_ops,
  1951. },
  1952. {
  1953. .name = "wm8994-aif3",
  1954. .id = 3,
  1955. .playback = {
  1956. .stream_name = "AIF3 Playback",
  1957. .channels_min = 2,
  1958. .channels_max = 2,
  1959. .rates = WM8994_RATES,
  1960. .formats = WM8994_FORMATS,
  1961. },
  1962. .capture = {
  1963. .stream_name = "AIF3 Capture",
  1964. .channels_min = 2,
  1965. .channels_max = 2,
  1966. .rates = WM8994_RATES,
  1967. .formats = WM8994_FORMATS,
  1968. },
  1969. .ops = &wm8994_aif3_dai_ops,
  1970. }
  1971. };
  1972. #ifdef CONFIG_PM
  1973. static int wm8994_suspend(struct snd_soc_codec *codec, pm_message_t state)
  1974. {
  1975. struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
  1976. int i, ret;
  1977. for (i = 0; i < ARRAY_SIZE(wm8994->fll); i++) {
  1978. memcpy(&wm8994->fll_suspend[i], &wm8994->fll[i],
  1979. sizeof(struct fll_config));
  1980. ret = _wm8994_set_fll(codec, i + 1, 0, 0, 0);
  1981. if (ret < 0)
  1982. dev_warn(codec->dev, "Failed to stop FLL%d: %d\n",
  1983. i + 1, ret);
  1984. }
  1985. wm8994_set_bias_level(codec, SND_SOC_BIAS_OFF);
  1986. return 0;
  1987. }
  1988. static int wm8994_resume(struct snd_soc_codec *codec)
  1989. {
  1990. struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
  1991. int i, ret;
  1992. /* Restore the registers */
  1993. ret = snd_soc_cache_sync(codec);
  1994. if (ret != 0)
  1995. dev_err(codec->dev, "Failed to sync cache: %d\n", ret);
  1996. wm8994_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
  1997. for (i = 0; i < ARRAY_SIZE(wm8994->fll); i++) {
  1998. if (!wm8994->fll_suspend[i].out)
  1999. continue;
  2000. ret = _wm8994_set_fll(codec, i + 1,
  2001. wm8994->fll_suspend[i].src,
  2002. wm8994->fll_suspend[i].in,
  2003. wm8994->fll_suspend[i].out);
  2004. if (ret < 0)
  2005. dev_warn(codec->dev, "Failed to restore FLL%d: %d\n",
  2006. i + 1, ret);
  2007. }
  2008. return 0;
  2009. }
  2010. #else
  2011. #define wm8994_suspend NULL
  2012. #define wm8994_resume NULL
  2013. #endif
  2014. static void wm8994_handle_retune_mobile_pdata(struct wm8994_priv *wm8994)
  2015. {
  2016. struct snd_soc_codec *codec = wm8994->codec;
  2017. struct wm8994_pdata *pdata = wm8994->pdata;
  2018. struct snd_kcontrol_new controls[] = {
  2019. SOC_ENUM_EXT("AIF1.1 EQ Mode",
  2020. wm8994->retune_mobile_enum,
  2021. wm8994_get_retune_mobile_enum,
  2022. wm8994_put_retune_mobile_enum),
  2023. SOC_ENUM_EXT("AIF1.2 EQ Mode",
  2024. wm8994->retune_mobile_enum,
  2025. wm8994_get_retune_mobile_enum,
  2026. wm8994_put_retune_mobile_enum),
  2027. SOC_ENUM_EXT("AIF2 EQ Mode",
  2028. wm8994->retune_mobile_enum,
  2029. wm8994_get_retune_mobile_enum,
  2030. wm8994_put_retune_mobile_enum),
  2031. };
  2032. int ret, i, j;
  2033. const char **t;
  2034. /* We need an array of texts for the enum API but the number
  2035. * of texts is likely to be less than the number of
  2036. * configurations due to the sample rate dependency of the
  2037. * configurations. */
  2038. wm8994->num_retune_mobile_texts = 0;
  2039. wm8994->retune_mobile_texts = NULL;
  2040. for (i = 0; i < pdata->num_retune_mobile_cfgs; i++) {
  2041. for (j = 0; j < wm8994->num_retune_mobile_texts; j++) {
  2042. if (strcmp(pdata->retune_mobile_cfgs[i].name,
  2043. wm8994->retune_mobile_texts[j]) == 0)
  2044. break;
  2045. }
  2046. if (j != wm8994->num_retune_mobile_texts)
  2047. continue;
  2048. /* Expand the array... */
  2049. t = krealloc(wm8994->retune_mobile_texts,
  2050. sizeof(char *) *
  2051. (wm8994->num_retune_mobile_texts + 1),
  2052. GFP_KERNEL);
  2053. if (t == NULL)
  2054. continue;
  2055. /* ...store the new entry... */
  2056. t[wm8994->num_retune_mobile_texts] =
  2057. pdata->retune_mobile_cfgs[i].name;
  2058. /* ...and remember the new version. */
  2059. wm8994->num_retune_mobile_texts++;
  2060. wm8994->retune_mobile_texts = t;
  2061. }
  2062. dev_dbg(codec->dev, "Allocated %d unique ReTune Mobile names\n",
  2063. wm8994->num_retune_mobile_texts);
  2064. wm8994->retune_mobile_enum.max = wm8994->num_retune_mobile_texts;
  2065. wm8994->retune_mobile_enum.texts = wm8994->retune_mobile_texts;
  2066. ret = snd_soc_add_controls(wm8994->codec, controls,
  2067. ARRAY_SIZE(controls));
  2068. if (ret != 0)
  2069. dev_err(wm8994->codec->dev,
  2070. "Failed to add ReTune Mobile controls: %d\n", ret);
  2071. }
  2072. static void wm8994_handle_pdata(struct wm8994_priv *wm8994)
  2073. {
  2074. struct snd_soc_codec *codec = wm8994->codec;
  2075. struct wm8994_pdata *pdata = wm8994->pdata;
  2076. int ret, i;
  2077. if (!pdata)
  2078. return;
  2079. wm_hubs_handle_analogue_pdata(codec, pdata->lineout1_diff,
  2080. pdata->lineout2_diff,
  2081. pdata->lineout1fb,
  2082. pdata->lineout2fb,
  2083. pdata->jd_scthr,
  2084. pdata->jd_thr,
  2085. pdata->micbias1_lvl,
  2086. pdata->micbias2_lvl);
  2087. dev_dbg(codec->dev, "%d DRC configurations\n", pdata->num_drc_cfgs);
  2088. if (pdata->num_drc_cfgs) {
  2089. struct snd_kcontrol_new controls[] = {
  2090. SOC_ENUM_EXT("AIF1DRC1 Mode", wm8994->drc_enum,
  2091. wm8994_get_drc_enum, wm8994_put_drc_enum),
  2092. SOC_ENUM_EXT("AIF1DRC2 Mode", wm8994->drc_enum,
  2093. wm8994_get_drc_enum, wm8994_put_drc_enum),
  2094. SOC_ENUM_EXT("AIF2DRC Mode", wm8994->drc_enum,
  2095. wm8994_get_drc_enum, wm8994_put_drc_enum),
  2096. };
  2097. /* We need an array of texts for the enum API */
  2098. wm8994->drc_texts = kmalloc(sizeof(char *)
  2099. * pdata->num_drc_cfgs, GFP_KERNEL);
  2100. if (!wm8994->drc_texts) {
  2101. dev_err(wm8994->codec->dev,
  2102. "Failed to allocate %d DRC config texts\n",
  2103. pdata->num_drc_cfgs);
  2104. return;
  2105. }
  2106. for (i = 0; i < pdata->num_drc_cfgs; i++)
  2107. wm8994->drc_texts[i] = pdata->drc_cfgs[i].name;
  2108. wm8994->drc_enum.max = pdata->num_drc_cfgs;
  2109. wm8994->drc_enum.texts = wm8994->drc_texts;
  2110. ret = snd_soc_add_controls(wm8994->codec, controls,
  2111. ARRAY_SIZE(controls));
  2112. if (ret != 0)
  2113. dev_err(wm8994->codec->dev,
  2114. "Failed to add DRC mode controls: %d\n", ret);
  2115. for (i = 0; i < WM8994_NUM_DRC; i++)
  2116. wm8994_set_drc(codec, i);
  2117. }
  2118. dev_dbg(codec->dev, "%d ReTune Mobile configurations\n",
  2119. pdata->num_retune_mobile_cfgs);
  2120. if (pdata->num_retune_mobile_cfgs)
  2121. wm8994_handle_retune_mobile_pdata(wm8994);
  2122. else
  2123. snd_soc_add_controls(wm8994->codec, wm8994_eq_controls,
  2124. ARRAY_SIZE(wm8994_eq_controls));
  2125. }
  2126. /**
  2127. * wm8994_mic_detect - Enable microphone detection via the WM8994 IRQ
  2128. *
  2129. * @codec: WM8994 codec
  2130. * @jack: jack to report detection events on
  2131. * @micbias: microphone bias to detect on
  2132. * @det: value to report for presence detection
  2133. * @shrt: value to report for short detection
  2134. *
  2135. * Enable microphone detection via IRQ on the WM8994. If GPIOs are
  2136. * being used to bring out signals to the processor then only platform
  2137. * data configuration is needed for WM8994 and processor GPIOs should
  2138. * be configured using snd_soc_jack_add_gpios() instead.
  2139. *
  2140. * Configuration of detection levels is available via the micbias1_lvl
  2141. * and micbias2_lvl platform data members.
  2142. */
  2143. int wm8994_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack,
  2144. int micbias, int det, int shrt)
  2145. {
  2146. struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
  2147. struct wm8994_micdet *micdet;
  2148. struct wm8994 *control = codec->control_data;
  2149. int reg;
  2150. if (control->type != WM8994)
  2151. return -EINVAL;
  2152. switch (micbias) {
  2153. case 1:
  2154. micdet = &wm8994->micdet[0];
  2155. break;
  2156. case 2:
  2157. micdet = &wm8994->micdet[1];
  2158. break;
  2159. default:
  2160. return -EINVAL;
  2161. }
  2162. dev_dbg(codec->dev, "Configuring microphone detection on %d: %x %x\n",
  2163. micbias, det, shrt);
  2164. /* Store the configuration */
  2165. micdet->jack = jack;
  2166. micdet->det = det;
  2167. micdet->shrt = shrt;
  2168. /* If either of the jacks is set up then enable detection */
  2169. if (wm8994->micdet[0].jack || wm8994->micdet[1].jack)
  2170. reg = WM8994_MICD_ENA;
  2171. else
  2172. reg = 0;
  2173. snd_soc_update_bits(codec, WM8994_MICBIAS, WM8994_MICD_ENA, reg);
  2174. return 0;
  2175. }
  2176. EXPORT_SYMBOL_GPL(wm8994_mic_detect);
  2177. static irqreturn_t wm8994_mic_irq(int irq, void *data)
  2178. {
  2179. struct wm8994_priv *priv = data;
  2180. struct snd_soc_codec *codec = priv->codec;
  2181. int reg;
  2182. int report;
  2183. reg = snd_soc_read(codec, WM8994_INTERRUPT_RAW_STATUS_2);
  2184. if (reg < 0) {
  2185. dev_err(codec->dev, "Failed to read microphone status: %d\n",
  2186. reg);
  2187. return IRQ_HANDLED;
  2188. }
  2189. dev_dbg(codec->dev, "Microphone status: %x\n", reg);
  2190. report = 0;
  2191. if (reg & WM8994_MIC1_DET_STS)
  2192. report |= priv->micdet[0].det;
  2193. if (reg & WM8994_MIC1_SHRT_STS)
  2194. report |= priv->micdet[0].shrt;
  2195. snd_soc_jack_report(priv->micdet[0].jack, report,
  2196. priv->micdet[0].det | priv->micdet[0].shrt);
  2197. report = 0;
  2198. if (reg & WM8994_MIC2_DET_STS)
  2199. report |= priv->micdet[1].det;
  2200. if (reg & WM8994_MIC2_SHRT_STS)
  2201. report |= priv->micdet[1].shrt;
  2202. snd_soc_jack_report(priv->micdet[1].jack, report,
  2203. priv->micdet[1].det | priv->micdet[1].shrt);
  2204. return IRQ_HANDLED;
  2205. }
  2206. /* Default microphone detection handler for WM8958 - the user can
  2207. * override this if they wish.
  2208. */
  2209. static void wm8958_default_micdet(u16 status, void *data)
  2210. {
  2211. struct snd_soc_codec *codec = data;
  2212. struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
  2213. int report = 0;
  2214. /* If nothing present then clear our statuses */
  2215. if (!(status & WM8958_MICD_STS)) {
  2216. wm8994->jack_is_video = false;
  2217. wm8994->jack_is_mic = false;
  2218. goto done;
  2219. }
  2220. /* Assume anything over 475 ohms is a microphone and remember
  2221. * that we've seen one (since buttons override it) */
  2222. if (status & 0x600)
  2223. wm8994->jack_is_mic = true;
  2224. if (wm8994->jack_is_mic)
  2225. report |= SND_JACK_MICROPHONE;
  2226. /* Video has an impedence of approximately 75 ohms; assume
  2227. * this isn't used as a button and remember it since buttons
  2228. * override it. */
  2229. if (status & 0x40)
  2230. wm8994->jack_is_video = true;
  2231. if (wm8994->jack_is_video)
  2232. report |= SND_JACK_VIDEOOUT;
  2233. /* Everything else is buttons; just assign slots */
  2234. if (status & 0x4)
  2235. report |= SND_JACK_BTN_0;
  2236. if (status & 0x8)
  2237. report |= SND_JACK_BTN_1;
  2238. if (status & 0x10)
  2239. report |= SND_JACK_BTN_2;
  2240. if (status & 0x20)
  2241. report |= SND_JACK_BTN_3;
  2242. if (status & 0x80)
  2243. report |= SND_JACK_BTN_4;
  2244. if (status & 0x100)
  2245. report |= SND_JACK_BTN_5;
  2246. done:
  2247. snd_soc_jack_report(wm8994->micdet[0].jack,
  2248. SND_JACK_BTN_0 | SND_JACK_BTN_1 | SND_JACK_BTN_2 |
  2249. SND_JACK_BTN_3 | SND_JACK_BTN_4 | SND_JACK_BTN_5 |
  2250. SND_JACK_MICROPHONE | SND_JACK_VIDEOOUT,
  2251. report);
  2252. }
  2253. /**
  2254. * wm8958_mic_detect - Enable microphone detection via the WM8958 IRQ
  2255. *
  2256. * @codec: WM8958 codec
  2257. * @jack: jack to report detection events on
  2258. *
  2259. * Enable microphone detection functionality for the WM8958. By
  2260. * default simple detection which supports the detection of up to 6
  2261. * buttons plus video and microphone functionality is supported.
  2262. *
  2263. * The WM8958 has an advanced jack detection facility which is able to
  2264. * support complex accessory detection, especially when used in
  2265. * conjunction with external circuitry. In order to provide maximum
  2266. * flexiblity a callback is provided which allows a completely custom
  2267. * detection algorithm.
  2268. */
  2269. int wm8958_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack,
  2270. wm8958_micdet_cb cb, void *cb_data)
  2271. {
  2272. struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
  2273. struct wm8994 *control = codec->control_data;
  2274. if (control->type != WM8958)
  2275. return -EINVAL;
  2276. if (jack) {
  2277. if (!cb) {
  2278. dev_dbg(codec->dev, "Using default micdet callback\n");
  2279. cb = wm8958_default_micdet;
  2280. cb_data = codec;
  2281. }
  2282. wm8994->micdet[0].jack = jack;
  2283. wm8994->jack_cb = cb;
  2284. wm8994->jack_cb_data = cb_data;
  2285. snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
  2286. WM8958_MICD_ENA, WM8958_MICD_ENA);
  2287. } else {
  2288. snd_soc_update_bits(codec, WM8958_MIC_DETECT_1,
  2289. WM8958_MICD_ENA, 0);
  2290. }
  2291. return 0;
  2292. }
  2293. EXPORT_SYMBOL_GPL(wm8958_mic_detect);
  2294. static irqreturn_t wm8958_mic_irq(int irq, void *data)
  2295. {
  2296. struct wm8994_priv *wm8994 = data;
  2297. struct snd_soc_codec *codec = wm8994->codec;
  2298. int reg;
  2299. reg = snd_soc_read(codec, WM8958_MIC_DETECT_3);
  2300. if (reg < 0) {
  2301. dev_err(codec->dev, "Failed to read mic detect status: %d\n",
  2302. reg);
  2303. return IRQ_NONE;
  2304. }
  2305. if (!(reg & WM8958_MICD_VALID)) {
  2306. dev_dbg(codec->dev, "Mic detect data not valid\n");
  2307. goto out;
  2308. }
  2309. if (wm8994->jack_cb)
  2310. wm8994->jack_cb(reg, wm8994->jack_cb_data);
  2311. else
  2312. dev_warn(codec->dev, "Accessory detection with no callback\n");
  2313. out:
  2314. return IRQ_HANDLED;
  2315. }
  2316. static int wm8994_codec_probe(struct snd_soc_codec *codec)
  2317. {
  2318. struct wm8994 *control;
  2319. struct wm8994_priv *wm8994;
  2320. struct snd_soc_dapm_context *dapm = &codec->dapm;
  2321. int ret, i;
  2322. codec->control_data = dev_get_drvdata(codec->dev->parent);
  2323. control = codec->control_data;
  2324. wm8994 = kzalloc(sizeof(struct wm8994_priv), GFP_KERNEL);
  2325. if (wm8994 == NULL)
  2326. return -ENOMEM;
  2327. snd_soc_codec_set_drvdata(codec, wm8994);
  2328. wm8994->pdata = dev_get_platdata(codec->dev->parent);
  2329. wm8994->codec = codec;
  2330. pm_runtime_enable(codec->dev);
  2331. pm_runtime_resume(codec->dev);
  2332. /* Read our current status back from the chip - we don't want to
  2333. * reset as this may interfere with the GPIO or LDO operation. */
  2334. for (i = 0; i < WM8994_CACHE_SIZE; i++) {
  2335. if (!wm8994_readable(i) || wm8994_volatile(i))
  2336. continue;
  2337. ret = wm8994_reg_read(codec->control_data, i);
  2338. if (ret <= 0)
  2339. continue;
  2340. ret = snd_soc_cache_write(codec, i, ret);
  2341. if (ret != 0) {
  2342. dev_err(codec->dev,
  2343. "Failed to initialise cache for 0x%x: %d\n",
  2344. i, ret);
  2345. goto err;
  2346. }
  2347. }
  2348. /* Set revision-specific configuration */
  2349. wm8994->revision = snd_soc_read(codec, WM8994_CHIP_REVISION);
  2350. switch (control->type) {
  2351. case WM8994:
  2352. switch (wm8994->revision) {
  2353. case 2:
  2354. case 3:
  2355. wm8994->hubs.dcs_codes = -5;
  2356. wm8994->hubs.hp_startup_mode = 1;
  2357. wm8994->hubs.dcs_readback_mode = 1;
  2358. break;
  2359. default:
  2360. wm8994->hubs.dcs_readback_mode = 1;
  2361. break;
  2362. }
  2363. case WM8958:
  2364. wm8994->hubs.dcs_readback_mode = 1;
  2365. break;
  2366. default:
  2367. break;
  2368. }
  2369. switch (control->type) {
  2370. case WM8994:
  2371. ret = wm8994_request_irq(codec->control_data,
  2372. WM8994_IRQ_MIC1_DET,
  2373. wm8994_mic_irq, "Mic 1 detect",
  2374. wm8994);
  2375. if (ret != 0)
  2376. dev_warn(codec->dev,
  2377. "Failed to request Mic1 detect IRQ: %d\n",
  2378. ret);
  2379. ret = wm8994_request_irq(codec->control_data,
  2380. WM8994_IRQ_MIC1_SHRT,
  2381. wm8994_mic_irq, "Mic 1 short",
  2382. wm8994);
  2383. if (ret != 0)
  2384. dev_warn(codec->dev,
  2385. "Failed to request Mic1 short IRQ: %d\n",
  2386. ret);
  2387. ret = wm8994_request_irq(codec->control_data,
  2388. WM8994_IRQ_MIC2_DET,
  2389. wm8994_mic_irq, "Mic 2 detect",
  2390. wm8994);
  2391. if (ret != 0)
  2392. dev_warn(codec->dev,
  2393. "Failed to request Mic2 detect IRQ: %d\n",
  2394. ret);
  2395. ret = wm8994_request_irq(codec->control_data,
  2396. WM8994_IRQ_MIC2_SHRT,
  2397. wm8994_mic_irq, "Mic 2 short",
  2398. wm8994);
  2399. if (ret != 0)
  2400. dev_warn(codec->dev,
  2401. "Failed to request Mic2 short IRQ: %d\n",
  2402. ret);
  2403. break;
  2404. case WM8958:
  2405. ret = wm8994_request_irq(codec->control_data,
  2406. WM8994_IRQ_MIC1_DET,
  2407. wm8958_mic_irq, "Mic detect",
  2408. wm8994);
  2409. if (ret != 0)
  2410. dev_warn(codec->dev,
  2411. "Failed to request Mic detect IRQ: %d\n",
  2412. ret);
  2413. break;
  2414. }
  2415. /* Remember if AIFnLRCLK is configured as a GPIO. This should be
  2416. * configured on init - if a system wants to do this dynamically
  2417. * at runtime we can deal with that then.
  2418. */
  2419. ret = wm8994_reg_read(codec->control_data, WM8994_GPIO_1);
  2420. if (ret < 0) {
  2421. dev_err(codec->dev, "Failed to read GPIO1 state: %d\n", ret);
  2422. goto err_irq;
  2423. }
  2424. if ((ret & WM8994_GPN_FN_MASK) != WM8994_GP_FN_PIN_SPECIFIC) {
  2425. wm8994->lrclk_shared[0] = 1;
  2426. wm8994_dai[0].symmetric_rates = 1;
  2427. } else {
  2428. wm8994->lrclk_shared[0] = 0;
  2429. }
  2430. ret = wm8994_reg_read(codec->control_data, WM8994_GPIO_6);
  2431. if (ret < 0) {
  2432. dev_err(codec->dev, "Failed to read GPIO6 state: %d\n", ret);
  2433. goto err_irq;
  2434. }
  2435. if ((ret & WM8994_GPN_FN_MASK) != WM8994_GP_FN_PIN_SPECIFIC) {
  2436. wm8994->lrclk_shared[1] = 1;
  2437. wm8994_dai[1].symmetric_rates = 1;
  2438. } else {
  2439. wm8994->lrclk_shared[1] = 0;
  2440. }
  2441. wm8994_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
  2442. /* Latch volume updates (right only; we always do left then right). */
  2443. snd_soc_update_bits(codec, WM8994_AIF1_DAC1_RIGHT_VOLUME,
  2444. WM8994_AIF1DAC1_VU, WM8994_AIF1DAC1_VU);
  2445. snd_soc_update_bits(codec, WM8994_AIF1_DAC2_RIGHT_VOLUME,
  2446. WM8994_AIF1DAC2_VU, WM8994_AIF1DAC2_VU);
  2447. snd_soc_update_bits(codec, WM8994_AIF2_DAC_RIGHT_VOLUME,
  2448. WM8994_AIF2DAC_VU, WM8994_AIF2DAC_VU);
  2449. snd_soc_update_bits(codec, WM8994_AIF1_ADC1_RIGHT_VOLUME,
  2450. WM8994_AIF1ADC1_VU, WM8994_AIF1ADC1_VU);
  2451. snd_soc_update_bits(codec, WM8994_AIF1_ADC2_RIGHT_VOLUME,
  2452. WM8994_AIF1ADC2_VU, WM8994_AIF1ADC2_VU);
  2453. snd_soc_update_bits(codec, WM8994_AIF2_ADC_RIGHT_VOLUME,
  2454. WM8994_AIF2ADC_VU, WM8994_AIF1ADC2_VU);
  2455. snd_soc_update_bits(codec, WM8994_DAC1_RIGHT_VOLUME,
  2456. WM8994_DAC1_VU, WM8994_DAC1_VU);
  2457. snd_soc_update_bits(codec, WM8994_DAC2_RIGHT_VOLUME,
  2458. WM8994_DAC2_VU, WM8994_DAC2_VU);
  2459. /* Set the low bit of the 3D stereo depth so TLV matches */
  2460. snd_soc_update_bits(codec, WM8994_AIF1_DAC1_FILTERS_2,
  2461. 1 << WM8994_AIF1DAC1_3D_GAIN_SHIFT,
  2462. 1 << WM8994_AIF1DAC1_3D_GAIN_SHIFT);
  2463. snd_soc_update_bits(codec, WM8994_AIF1_DAC2_FILTERS_2,
  2464. 1 << WM8994_AIF1DAC2_3D_GAIN_SHIFT,
  2465. 1 << WM8994_AIF1DAC2_3D_GAIN_SHIFT);
  2466. snd_soc_update_bits(codec, WM8994_AIF2_DAC_FILTERS_2,
  2467. 1 << WM8994_AIF2DAC_3D_GAIN_SHIFT,
  2468. 1 << WM8994_AIF2DAC_3D_GAIN_SHIFT);
  2469. /* Unconditionally enable AIF1 ADC TDM mode; it only affects
  2470. * behaviour on idle TDM clock cycles. */
  2471. snd_soc_update_bits(codec, WM8994_AIF1_CONTROL_1,
  2472. WM8994_AIF1ADC_TDM, WM8994_AIF1ADC_TDM);
  2473. wm8994_update_class_w(codec);
  2474. wm8994_handle_pdata(wm8994);
  2475. wm_hubs_add_analogue_controls(codec);
  2476. snd_soc_add_controls(codec, wm8994_snd_controls,
  2477. ARRAY_SIZE(wm8994_snd_controls));
  2478. snd_soc_dapm_new_controls(dapm, wm8994_dapm_widgets,
  2479. ARRAY_SIZE(wm8994_dapm_widgets));
  2480. switch (control->type) {
  2481. case WM8994:
  2482. snd_soc_dapm_new_controls(dapm, wm8994_specific_dapm_widgets,
  2483. ARRAY_SIZE(wm8994_specific_dapm_widgets));
  2484. break;
  2485. case WM8958:
  2486. snd_soc_add_controls(codec, wm8958_snd_controls,
  2487. ARRAY_SIZE(wm8958_snd_controls));
  2488. snd_soc_dapm_new_controls(dapm, wm8958_dapm_widgets,
  2489. ARRAY_SIZE(wm8958_dapm_widgets));
  2490. break;
  2491. }
  2492. wm_hubs_add_analogue_routes(codec, 0, 0);
  2493. snd_soc_dapm_add_routes(dapm, intercon, ARRAY_SIZE(intercon));
  2494. switch (control->type) {
  2495. case WM8994:
  2496. snd_soc_dapm_add_routes(dapm, wm8994_intercon,
  2497. ARRAY_SIZE(wm8994_intercon));
  2498. break;
  2499. case WM8958:
  2500. snd_soc_dapm_add_routes(dapm, wm8958_intercon,
  2501. ARRAY_SIZE(wm8958_intercon));
  2502. break;
  2503. }
  2504. return 0;
  2505. err_irq:
  2506. wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC2_SHRT, wm8994);
  2507. wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC2_DET, wm8994);
  2508. wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC1_SHRT, wm8994);
  2509. wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC1_DET, wm8994);
  2510. err:
  2511. kfree(wm8994);
  2512. return ret;
  2513. }
  2514. static int wm8994_codec_remove(struct snd_soc_codec *codec)
  2515. {
  2516. struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
  2517. struct wm8994 *control = codec->control_data;
  2518. wm8994_set_bias_level(codec, SND_SOC_BIAS_OFF);
  2519. pm_runtime_disable(codec->dev);
  2520. switch (control->type) {
  2521. case WM8994:
  2522. wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC2_SHRT,
  2523. wm8994);
  2524. wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC2_DET,
  2525. wm8994);
  2526. wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC1_SHRT,
  2527. wm8994);
  2528. wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC1_DET,
  2529. wm8994);
  2530. break;
  2531. case WM8958:
  2532. wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC1_DET,
  2533. wm8994);
  2534. break;
  2535. }
  2536. kfree(wm8994->retune_mobile_texts);
  2537. kfree(wm8994->drc_texts);
  2538. kfree(wm8994);
  2539. return 0;
  2540. }
  2541. static struct snd_soc_codec_driver soc_codec_dev_wm8994 = {
  2542. .probe = wm8994_codec_probe,
  2543. .remove = wm8994_codec_remove,
  2544. .suspend = wm8994_suspend,
  2545. .resume = wm8994_resume,
  2546. .read = wm8994_read,
  2547. .write = wm8994_write,
  2548. .readable_register = wm8994_readable,
  2549. .volatile_register = wm8994_volatile,
  2550. .set_bias_level = wm8994_set_bias_level,
  2551. .reg_cache_size = WM8994_CACHE_SIZE,
  2552. .reg_cache_default = wm8994_reg_defaults,
  2553. .reg_word_size = 2,
  2554. .compress_type = SND_SOC_RBTREE_COMPRESSION,
  2555. };
  2556. static int __devinit wm8994_probe(struct platform_device *pdev)
  2557. {
  2558. return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_wm8994,
  2559. wm8994_dai, ARRAY_SIZE(wm8994_dai));
  2560. }
  2561. static int __devexit wm8994_remove(struct platform_device *pdev)
  2562. {
  2563. snd_soc_unregister_codec(&pdev->dev);
  2564. return 0;
  2565. }
  2566. static struct platform_driver wm8994_codec_driver = {
  2567. .driver = {
  2568. .name = "wm8994-codec",
  2569. .owner = THIS_MODULE,
  2570. },
  2571. .probe = wm8994_probe,
  2572. .remove = __devexit_p(wm8994_remove),
  2573. };
  2574. static __init int wm8994_init(void)
  2575. {
  2576. return platform_driver_register(&wm8994_codec_driver);
  2577. }
  2578. module_init(wm8994_init);
  2579. static __exit void wm8994_exit(void)
  2580. {
  2581. platform_driver_unregister(&wm8994_codec_driver);
  2582. }
  2583. module_exit(wm8994_exit);
  2584. MODULE_DESCRIPTION("ASoC WM8994 driver");
  2585. MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
  2586. MODULE_LICENSE("GPL");
  2587. MODULE_ALIAS("platform:wm8994-codec");