wm8996.c 92 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110
  1. /*
  2. * wm8996.c - WM8996 audio codec interface
  3. *
  4. * Copyright 2011-2 Wolfson Microelectronics PLC.
  5. * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation; either version 2 of the License, or (at your
  10. * option) any later version.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/moduleparam.h>
  14. #include <linux/init.h>
  15. #include <linux/completion.h>
  16. #include <linux/delay.h>
  17. #include <linux/pm.h>
  18. #include <linux/gcd.h>
  19. #include <linux/gpio/driver.h>
  20. #include <linux/gpio.h>
  21. #include <linux/i2c.h>
  22. #include <linux/regmap.h>
  23. #include <linux/regulator/consumer.h>
  24. #include <linux/slab.h>
  25. #include <linux/workqueue.h>
  26. #include <sound/core.h>
  27. #include <sound/jack.h>
  28. #include <sound/pcm.h>
  29. #include <sound/pcm_params.h>
  30. #include <sound/soc.h>
  31. #include <sound/initval.h>
  32. #include <sound/tlv.h>
  33. #include <trace/events/asoc.h>
  34. #include <sound/wm8996.h>
  35. #include "wm8996.h"
  36. #define WM8996_AIFS 2
  37. #define HPOUT1L 1
  38. #define HPOUT1R 2
  39. #define HPOUT2L 4
  40. #define HPOUT2R 8
  41. #define WM8996_NUM_SUPPLIES 3
  42. static const char *wm8996_supply_names[WM8996_NUM_SUPPLIES] = {
  43. "DBVDD",
  44. "AVDD1",
  45. "AVDD2",
  46. };
  47. struct wm8996_priv {
  48. struct device *dev;
  49. struct regmap *regmap;
  50. struct snd_soc_codec *codec;
  51. int ldo1ena;
  52. int sysclk;
  53. int sysclk_src;
  54. int fll_src;
  55. int fll_fref;
  56. int fll_fout;
  57. struct completion fll_lock;
  58. u16 dcs_pending;
  59. struct completion dcs_done;
  60. u16 hpout_ena;
  61. u16 hpout_pending;
  62. struct regulator_bulk_data supplies[WM8996_NUM_SUPPLIES];
  63. struct notifier_block disable_nb[WM8996_NUM_SUPPLIES];
  64. int bg_ena;
  65. struct wm8996_pdata pdata;
  66. int rx_rate[WM8996_AIFS];
  67. int bclk_rate[WM8996_AIFS];
  68. /* Platform dependant ReTune mobile configuration */
  69. int num_retune_mobile_texts;
  70. const char **retune_mobile_texts;
  71. int retune_mobile_cfg[2];
  72. struct soc_enum retune_mobile_enum;
  73. struct snd_soc_jack *jack;
  74. bool detecting;
  75. bool jack_mic;
  76. int jack_flips;
  77. wm8996_polarity_fn polarity_cb;
  78. #ifdef CONFIG_GPIOLIB
  79. struct gpio_chip gpio_chip;
  80. #endif
  81. };
  82. /* We can't use the same notifier block for more than one supply and
  83. * there's no way I can see to get from a callback to the caller
  84. * except container_of().
  85. */
  86. #define WM8996_REGULATOR_EVENT(n) \
  87. static int wm8996_regulator_event_##n(struct notifier_block *nb, \
  88. unsigned long event, void *data) \
  89. { \
  90. struct wm8996_priv *wm8996 = container_of(nb, struct wm8996_priv, \
  91. disable_nb[n]); \
  92. if (event & REGULATOR_EVENT_DISABLE) { \
  93. regcache_mark_dirty(wm8996->regmap); \
  94. } \
  95. return 0; \
  96. }
  97. WM8996_REGULATOR_EVENT(0)
  98. WM8996_REGULATOR_EVENT(1)
  99. WM8996_REGULATOR_EVENT(2)
  100. static const struct reg_default wm8996_reg[] = {
  101. { WM8996_POWER_MANAGEMENT_1, 0x0 },
  102. { WM8996_POWER_MANAGEMENT_2, 0x0 },
  103. { WM8996_POWER_MANAGEMENT_3, 0x0 },
  104. { WM8996_POWER_MANAGEMENT_4, 0x0 },
  105. { WM8996_POWER_MANAGEMENT_5, 0x0 },
  106. { WM8996_POWER_MANAGEMENT_6, 0x0 },
  107. { WM8996_POWER_MANAGEMENT_7, 0x10 },
  108. { WM8996_POWER_MANAGEMENT_8, 0x0 },
  109. { WM8996_LEFT_LINE_INPUT_VOLUME, 0x0 },
  110. { WM8996_RIGHT_LINE_INPUT_VOLUME, 0x0 },
  111. { WM8996_LINE_INPUT_CONTROL, 0x0 },
  112. { WM8996_DAC1_HPOUT1_VOLUME, 0x88 },
  113. { WM8996_DAC2_HPOUT2_VOLUME, 0x88 },
  114. { WM8996_DAC1_LEFT_VOLUME, 0x2c0 },
  115. { WM8996_DAC1_RIGHT_VOLUME, 0x2c0 },
  116. { WM8996_DAC2_LEFT_VOLUME, 0x2c0 },
  117. { WM8996_DAC2_RIGHT_VOLUME, 0x2c0 },
  118. { WM8996_OUTPUT1_LEFT_VOLUME, 0x80 },
  119. { WM8996_OUTPUT1_RIGHT_VOLUME, 0x80 },
  120. { WM8996_OUTPUT2_LEFT_VOLUME, 0x80 },
  121. { WM8996_OUTPUT2_RIGHT_VOLUME, 0x80 },
  122. { WM8996_MICBIAS_1, 0x39 },
  123. { WM8996_MICBIAS_2, 0x39 },
  124. { WM8996_LDO_1, 0x3 },
  125. { WM8996_LDO_2, 0x13 },
  126. { WM8996_ACCESSORY_DETECT_MODE_1, 0x4 },
  127. { WM8996_ACCESSORY_DETECT_MODE_2, 0x0 },
  128. { WM8996_HEADPHONE_DETECT_1, 0x20 },
  129. { WM8996_HEADPHONE_DETECT_2, 0x0 },
  130. { WM8996_MIC_DETECT_1, 0x7600 },
  131. { WM8996_MIC_DETECT_2, 0xbf },
  132. { WM8996_CHARGE_PUMP_1, 0x1f25 },
  133. { WM8996_CHARGE_PUMP_2, 0xab19 },
  134. { WM8996_DC_SERVO_1, 0x0 },
  135. { WM8996_DC_SERVO_3, 0x0 },
  136. { WM8996_DC_SERVO_5, 0x2a2a },
  137. { WM8996_DC_SERVO_6, 0x0 },
  138. { WM8996_DC_SERVO_7, 0x0 },
  139. { WM8996_ANALOGUE_HP_1, 0x0 },
  140. { WM8996_ANALOGUE_HP_2, 0x0 },
  141. { WM8996_CONTROL_INTERFACE_1, 0x8004 },
  142. { WM8996_WRITE_SEQUENCER_CTRL_1, 0x0 },
  143. { WM8996_WRITE_SEQUENCER_CTRL_2, 0x0 },
  144. { WM8996_AIF_CLOCKING_1, 0x0 },
  145. { WM8996_AIF_CLOCKING_2, 0x0 },
  146. { WM8996_CLOCKING_1, 0x10 },
  147. { WM8996_CLOCKING_2, 0x0 },
  148. { WM8996_AIF_RATE, 0x83 },
  149. { WM8996_FLL_CONTROL_1, 0x0 },
  150. { WM8996_FLL_CONTROL_2, 0x0 },
  151. { WM8996_FLL_CONTROL_3, 0x0 },
  152. { WM8996_FLL_CONTROL_4, 0x5dc0 },
  153. { WM8996_FLL_CONTROL_5, 0xc84 },
  154. { WM8996_FLL_EFS_1, 0x0 },
  155. { WM8996_FLL_EFS_2, 0x2 },
  156. { WM8996_AIF1_CONTROL, 0x0 },
  157. { WM8996_AIF1_BCLK, 0x0 },
  158. { WM8996_AIF1_TX_LRCLK_1, 0x80 },
  159. { WM8996_AIF1_TX_LRCLK_2, 0x8 },
  160. { WM8996_AIF1_RX_LRCLK_1, 0x80 },
  161. { WM8996_AIF1_RX_LRCLK_2, 0x0 },
  162. { WM8996_AIF1TX_DATA_CONFIGURATION_1, 0x1818 },
  163. { WM8996_AIF1TX_DATA_CONFIGURATION_2, 0 },
  164. { WM8996_AIF1RX_DATA_CONFIGURATION, 0x1818 },
  165. { WM8996_AIF1TX_CHANNEL_0_CONFIGURATION, 0x0 },
  166. { WM8996_AIF1TX_CHANNEL_1_CONFIGURATION, 0x0 },
  167. { WM8996_AIF1TX_CHANNEL_2_CONFIGURATION, 0x0 },
  168. { WM8996_AIF1TX_CHANNEL_3_CONFIGURATION, 0x0 },
  169. { WM8996_AIF1TX_CHANNEL_4_CONFIGURATION, 0x0 },
  170. { WM8996_AIF1TX_CHANNEL_5_CONFIGURATION, 0x0 },
  171. { WM8996_AIF1RX_CHANNEL_0_CONFIGURATION, 0x0 },
  172. { WM8996_AIF1RX_CHANNEL_1_CONFIGURATION, 0x0 },
  173. { WM8996_AIF1RX_CHANNEL_2_CONFIGURATION, 0x0 },
  174. { WM8996_AIF1RX_CHANNEL_3_CONFIGURATION, 0x0 },
  175. { WM8996_AIF1RX_CHANNEL_4_CONFIGURATION, 0x0 },
  176. { WM8996_AIF1RX_CHANNEL_5_CONFIGURATION, 0x0 },
  177. { WM8996_AIF1RX_MONO_CONFIGURATION, 0x0 },
  178. { WM8996_AIF1TX_TEST, 0x7 },
  179. { WM8996_AIF2_CONTROL, 0x0 },
  180. { WM8996_AIF2_BCLK, 0x0 },
  181. { WM8996_AIF2_TX_LRCLK_1, 0x80 },
  182. { WM8996_AIF2_TX_LRCLK_2, 0x8 },
  183. { WM8996_AIF2_RX_LRCLK_1, 0x80 },
  184. { WM8996_AIF2_RX_LRCLK_2, 0x0 },
  185. { WM8996_AIF2TX_DATA_CONFIGURATION_1, 0x1818 },
  186. { WM8996_AIF2RX_DATA_CONFIGURATION, 0x1818 },
  187. { WM8996_AIF2RX_DATA_CONFIGURATION, 0x0 },
  188. { WM8996_AIF2TX_CHANNEL_0_CONFIGURATION, 0x0 },
  189. { WM8996_AIF2TX_CHANNEL_1_CONFIGURATION, 0x0 },
  190. { WM8996_AIF2RX_CHANNEL_0_CONFIGURATION, 0x0 },
  191. { WM8996_AIF2RX_CHANNEL_1_CONFIGURATION, 0x0 },
  192. { WM8996_AIF2RX_MONO_CONFIGURATION, 0x0 },
  193. { WM8996_AIF2TX_TEST, 0x1 },
  194. { WM8996_DSP1_TX_LEFT_VOLUME, 0xc0 },
  195. { WM8996_DSP1_TX_RIGHT_VOLUME, 0xc0 },
  196. { WM8996_DSP1_RX_LEFT_VOLUME, 0xc0 },
  197. { WM8996_DSP1_RX_RIGHT_VOLUME, 0xc0 },
  198. { WM8996_DSP1_TX_FILTERS, 0x2000 },
  199. { WM8996_DSP1_RX_FILTERS_1, 0x200 },
  200. { WM8996_DSP1_RX_FILTERS_2, 0x10 },
  201. { WM8996_DSP1_DRC_1, 0x98 },
  202. { WM8996_DSP1_DRC_2, 0x845 },
  203. { WM8996_DSP1_RX_EQ_GAINS_1, 0x6318 },
  204. { WM8996_DSP1_RX_EQ_GAINS_2, 0x6300 },
  205. { WM8996_DSP1_RX_EQ_BAND_1_A, 0xfca },
  206. { WM8996_DSP1_RX_EQ_BAND_1_B, 0x400 },
  207. { WM8996_DSP1_RX_EQ_BAND_1_PG, 0xd8 },
  208. { WM8996_DSP1_RX_EQ_BAND_2_A, 0x1eb5 },
  209. { WM8996_DSP1_RX_EQ_BAND_2_B, 0xf145 },
  210. { WM8996_DSP1_RX_EQ_BAND_2_C, 0xb75 },
  211. { WM8996_DSP1_RX_EQ_BAND_2_PG, 0x1c5 },
  212. { WM8996_DSP1_RX_EQ_BAND_3_A, 0x1c58 },
  213. { WM8996_DSP1_RX_EQ_BAND_3_B, 0xf373 },
  214. { WM8996_DSP1_RX_EQ_BAND_3_C, 0xa54 },
  215. { WM8996_DSP1_RX_EQ_BAND_3_PG, 0x558 },
  216. { WM8996_DSP1_RX_EQ_BAND_4_A, 0x168e },
  217. { WM8996_DSP1_RX_EQ_BAND_4_B, 0xf829 },
  218. { WM8996_DSP1_RX_EQ_BAND_4_C, 0x7ad },
  219. { WM8996_DSP1_RX_EQ_BAND_4_PG, 0x1103 },
  220. { WM8996_DSP1_RX_EQ_BAND_5_A, 0x564 },
  221. { WM8996_DSP1_RX_EQ_BAND_5_B, 0x559 },
  222. { WM8996_DSP1_RX_EQ_BAND_5_PG, 0x4000 },
  223. { WM8996_DSP2_TX_LEFT_VOLUME, 0xc0 },
  224. { WM8996_DSP2_TX_RIGHT_VOLUME, 0xc0 },
  225. { WM8996_DSP2_RX_LEFT_VOLUME, 0xc0 },
  226. { WM8996_DSP2_RX_RIGHT_VOLUME, 0xc0 },
  227. { WM8996_DSP2_TX_FILTERS, 0x2000 },
  228. { WM8996_DSP2_RX_FILTERS_1, 0x200 },
  229. { WM8996_DSP2_RX_FILTERS_2, 0x10 },
  230. { WM8996_DSP2_DRC_1, 0x98 },
  231. { WM8996_DSP2_DRC_2, 0x845 },
  232. { WM8996_DSP2_RX_EQ_GAINS_1, 0x6318 },
  233. { WM8996_DSP2_RX_EQ_GAINS_2, 0x6300 },
  234. { WM8996_DSP2_RX_EQ_BAND_1_A, 0xfca },
  235. { WM8996_DSP2_RX_EQ_BAND_1_B, 0x400 },
  236. { WM8996_DSP2_RX_EQ_BAND_1_PG, 0xd8 },
  237. { WM8996_DSP2_RX_EQ_BAND_2_A, 0x1eb5 },
  238. { WM8996_DSP2_RX_EQ_BAND_2_B, 0xf145 },
  239. { WM8996_DSP2_RX_EQ_BAND_2_C, 0xb75 },
  240. { WM8996_DSP2_RX_EQ_BAND_2_PG, 0x1c5 },
  241. { WM8996_DSP2_RX_EQ_BAND_3_A, 0x1c58 },
  242. { WM8996_DSP2_RX_EQ_BAND_3_B, 0xf373 },
  243. { WM8996_DSP2_RX_EQ_BAND_3_C, 0xa54 },
  244. { WM8996_DSP2_RX_EQ_BAND_3_PG, 0x558 },
  245. { WM8996_DSP2_RX_EQ_BAND_4_A, 0x168e },
  246. { WM8996_DSP2_RX_EQ_BAND_4_B, 0xf829 },
  247. { WM8996_DSP2_RX_EQ_BAND_4_C, 0x7ad },
  248. { WM8996_DSP2_RX_EQ_BAND_4_PG, 0x1103 },
  249. { WM8996_DSP2_RX_EQ_BAND_5_A, 0x564 },
  250. { WM8996_DSP2_RX_EQ_BAND_5_B, 0x559 },
  251. { WM8996_DSP2_RX_EQ_BAND_5_PG, 0x4000 },
  252. { WM8996_DAC1_MIXER_VOLUMES, 0x0 },
  253. { WM8996_DAC1_LEFT_MIXER_ROUTING, 0x0 },
  254. { WM8996_DAC1_RIGHT_MIXER_ROUTING, 0x0 },
  255. { WM8996_DAC2_MIXER_VOLUMES, 0x0 },
  256. { WM8996_DAC2_LEFT_MIXER_ROUTING, 0x0 },
  257. { WM8996_DAC2_RIGHT_MIXER_ROUTING, 0x0 },
  258. { WM8996_DSP1_TX_LEFT_MIXER_ROUTING, 0x0 },
  259. { WM8996_DSP1_TX_RIGHT_MIXER_ROUTING, 0x0 },
  260. { WM8996_DSP2_TX_LEFT_MIXER_ROUTING, 0x0 },
  261. { WM8996_DSP2_TX_RIGHT_MIXER_ROUTING, 0x0 },
  262. { WM8996_DSP_TX_MIXER_SELECT, 0x0 },
  263. { WM8996_DAC_SOFTMUTE, 0x0 },
  264. { WM8996_OVERSAMPLING, 0xd },
  265. { WM8996_SIDETONE, 0x1040 },
  266. { WM8996_GPIO_1, 0xa101 },
  267. { WM8996_GPIO_2, 0xa101 },
  268. { WM8996_GPIO_3, 0xa101 },
  269. { WM8996_GPIO_4, 0xa101 },
  270. { WM8996_GPIO_5, 0xa101 },
  271. { WM8996_PULL_CONTROL_1, 0x0 },
  272. { WM8996_PULL_CONTROL_2, 0x140 },
  273. { WM8996_INTERRUPT_STATUS_1_MASK, 0x1f },
  274. { WM8996_INTERRUPT_STATUS_2_MASK, 0x1ecf },
  275. { WM8996_LEFT_PDM_SPEAKER, 0x0 },
  276. { WM8996_RIGHT_PDM_SPEAKER, 0x1 },
  277. { WM8996_PDM_SPEAKER_MUTE_SEQUENCE, 0x69 },
  278. { WM8996_PDM_SPEAKER_VOLUME, 0x66 },
  279. };
  280. static const DECLARE_TLV_DB_SCALE(inpga_tlv, 0, 100, 0);
  281. static const DECLARE_TLV_DB_SCALE(sidetone_tlv, -3600, 150, 0);
  282. static const DECLARE_TLV_DB_SCALE(digital_tlv, -7200, 75, 1);
  283. static const DECLARE_TLV_DB_SCALE(out_digital_tlv, -1200, 150, 0);
  284. static const DECLARE_TLV_DB_SCALE(out_tlv, -900, 75, 0);
  285. static const DECLARE_TLV_DB_SCALE(spk_tlv, -900, 150, 0);
  286. static const DECLARE_TLV_DB_SCALE(eq_tlv, -1200, 100, 0);
  287. static const DECLARE_TLV_DB_SCALE(threedstereo_tlv, -1600, 183, 1);
  288. static const char *sidetone_hpf_text[] = {
  289. "2.9kHz", "1.5kHz", "735Hz", "403Hz", "196Hz", "98Hz", "49Hz"
  290. };
  291. static SOC_ENUM_SINGLE_DECL(sidetone_hpf,
  292. WM8996_SIDETONE, 7, sidetone_hpf_text);
  293. static const char *hpf_mode_text[] = {
  294. "HiFi", "Custom", "Voice"
  295. };
  296. static SOC_ENUM_SINGLE_DECL(dsp1tx_hpf_mode,
  297. WM8996_DSP1_TX_FILTERS, 3, hpf_mode_text);
  298. static SOC_ENUM_SINGLE_DECL(dsp2tx_hpf_mode,
  299. WM8996_DSP2_TX_FILTERS, 3, hpf_mode_text);
  300. static const char *hpf_cutoff_text[] = {
  301. "50Hz", "75Hz", "100Hz", "150Hz", "200Hz", "300Hz", "400Hz"
  302. };
  303. static SOC_ENUM_SINGLE_DECL(dsp1tx_hpf_cutoff,
  304. WM8996_DSP1_TX_FILTERS, 0, hpf_cutoff_text);
  305. static SOC_ENUM_SINGLE_DECL(dsp2tx_hpf_cutoff,
  306. WM8996_DSP2_TX_FILTERS, 0, hpf_cutoff_text);
  307. static void wm8996_set_retune_mobile(struct snd_soc_codec *codec, int block)
  308. {
  309. struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec);
  310. struct wm8996_pdata *pdata = &wm8996->pdata;
  311. int base, best, best_val, save, i, cfg, iface;
  312. if (!wm8996->num_retune_mobile_texts)
  313. return;
  314. switch (block) {
  315. case 0:
  316. base = WM8996_DSP1_RX_EQ_GAINS_1;
  317. if (snd_soc_read(codec, WM8996_POWER_MANAGEMENT_8) &
  318. WM8996_DSP1RX_SRC)
  319. iface = 1;
  320. else
  321. iface = 0;
  322. break;
  323. case 1:
  324. base = WM8996_DSP1_RX_EQ_GAINS_2;
  325. if (snd_soc_read(codec, WM8996_POWER_MANAGEMENT_8) &
  326. WM8996_DSP2RX_SRC)
  327. iface = 1;
  328. else
  329. iface = 0;
  330. break;
  331. default:
  332. return;
  333. }
  334. /* Find the version of the currently selected configuration
  335. * with the nearest sample rate. */
  336. cfg = wm8996->retune_mobile_cfg[block];
  337. best = 0;
  338. best_val = INT_MAX;
  339. for (i = 0; i < pdata->num_retune_mobile_cfgs; i++) {
  340. if (strcmp(pdata->retune_mobile_cfgs[i].name,
  341. wm8996->retune_mobile_texts[cfg]) == 0 &&
  342. abs(pdata->retune_mobile_cfgs[i].rate
  343. - wm8996->rx_rate[iface]) < best_val) {
  344. best = i;
  345. best_val = abs(pdata->retune_mobile_cfgs[i].rate
  346. - wm8996->rx_rate[iface]);
  347. }
  348. }
  349. dev_dbg(codec->dev, "ReTune Mobile %d %s/%dHz for %dHz sample rate\n",
  350. block,
  351. pdata->retune_mobile_cfgs[best].name,
  352. pdata->retune_mobile_cfgs[best].rate,
  353. wm8996->rx_rate[iface]);
  354. /* The EQ will be disabled while reconfiguring it, remember the
  355. * current configuration.
  356. */
  357. save = snd_soc_read(codec, base);
  358. save &= WM8996_DSP1RX_EQ_ENA;
  359. for (i = 0; i < ARRAY_SIZE(pdata->retune_mobile_cfgs[best].regs); i++)
  360. snd_soc_update_bits(codec, base + i, 0xffff,
  361. pdata->retune_mobile_cfgs[best].regs[i]);
  362. snd_soc_update_bits(codec, base, WM8996_DSP1RX_EQ_ENA, save);
  363. }
  364. /* Icky as hell but saves code duplication */
  365. static int wm8996_get_retune_mobile_block(const char *name)
  366. {
  367. if (strcmp(name, "DSP1 EQ Mode") == 0)
  368. return 0;
  369. if (strcmp(name, "DSP2 EQ Mode") == 0)
  370. return 1;
  371. return -EINVAL;
  372. }
  373. static int wm8996_put_retune_mobile_enum(struct snd_kcontrol *kcontrol,
  374. struct snd_ctl_elem_value *ucontrol)
  375. {
  376. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  377. struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec);
  378. struct wm8996_pdata *pdata = &wm8996->pdata;
  379. int block = wm8996_get_retune_mobile_block(kcontrol->id.name);
  380. int value = ucontrol->value.enumerated.item[0];
  381. if (block < 0)
  382. return block;
  383. if (value >= pdata->num_retune_mobile_cfgs)
  384. return -EINVAL;
  385. wm8996->retune_mobile_cfg[block] = value;
  386. wm8996_set_retune_mobile(codec, block);
  387. return 0;
  388. }
  389. static int wm8996_get_retune_mobile_enum(struct snd_kcontrol *kcontrol,
  390. struct snd_ctl_elem_value *ucontrol)
  391. {
  392. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  393. struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec);
  394. int block = wm8996_get_retune_mobile_block(kcontrol->id.name);
  395. if (block < 0)
  396. return block;
  397. ucontrol->value.enumerated.item[0] = wm8996->retune_mobile_cfg[block];
  398. return 0;
  399. }
  400. static const struct snd_kcontrol_new wm8996_snd_controls[] = {
  401. SOC_DOUBLE_R_TLV("Capture Volume", WM8996_LEFT_LINE_INPUT_VOLUME,
  402. WM8996_RIGHT_LINE_INPUT_VOLUME, 0, 31, 0, inpga_tlv),
  403. SOC_DOUBLE_R("Capture ZC Switch", WM8996_LEFT_LINE_INPUT_VOLUME,
  404. WM8996_RIGHT_LINE_INPUT_VOLUME, 5, 1, 0),
  405. SOC_DOUBLE_TLV("DAC1 Sidetone Volume", WM8996_DAC1_MIXER_VOLUMES,
  406. 0, 5, 24, 0, sidetone_tlv),
  407. SOC_DOUBLE_TLV("DAC2 Sidetone Volume", WM8996_DAC2_MIXER_VOLUMES,
  408. 0, 5, 24, 0, sidetone_tlv),
  409. SOC_SINGLE("Sidetone LPF Switch", WM8996_SIDETONE, 12, 1, 0),
  410. SOC_ENUM("Sidetone HPF Cut-off", sidetone_hpf),
  411. SOC_SINGLE("Sidetone HPF Switch", WM8996_SIDETONE, 6, 1, 0),
  412. SOC_DOUBLE_R_TLV("DSP1 Capture Volume", WM8996_DSP1_TX_LEFT_VOLUME,
  413. WM8996_DSP1_TX_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
  414. SOC_DOUBLE_R_TLV("DSP2 Capture Volume", WM8996_DSP2_TX_LEFT_VOLUME,
  415. WM8996_DSP2_TX_RIGHT_VOLUME, 1, 96, 0, digital_tlv),
  416. SOC_SINGLE("DSP1 Capture Notch Filter Switch", WM8996_DSP1_TX_FILTERS,
  417. 13, 1, 0),
  418. SOC_DOUBLE("DSP1 Capture HPF Switch", WM8996_DSP1_TX_FILTERS, 12, 11, 1, 0),
  419. SOC_ENUM("DSP1 Capture HPF Mode", dsp1tx_hpf_mode),
  420. SOC_ENUM("DSP1 Capture HPF Cutoff", dsp1tx_hpf_cutoff),
  421. SOC_SINGLE("DSP2 Capture Notch Filter Switch", WM8996_DSP2_TX_FILTERS,
  422. 13, 1, 0),
  423. SOC_DOUBLE("DSP2 Capture HPF Switch", WM8996_DSP2_TX_FILTERS, 12, 11, 1, 0),
  424. SOC_ENUM("DSP2 Capture HPF Mode", dsp2tx_hpf_mode),
  425. SOC_ENUM("DSP2 Capture HPF Cutoff", dsp2tx_hpf_cutoff),
  426. SOC_DOUBLE_R_TLV("DSP1 Playback Volume", WM8996_DSP1_RX_LEFT_VOLUME,
  427. WM8996_DSP1_RX_RIGHT_VOLUME, 1, 112, 0, digital_tlv),
  428. SOC_SINGLE("DSP1 Playback Switch", WM8996_DSP1_RX_FILTERS_1, 9, 1, 1),
  429. SOC_DOUBLE_R_TLV("DSP2 Playback Volume", WM8996_DSP2_RX_LEFT_VOLUME,
  430. WM8996_DSP2_RX_RIGHT_VOLUME, 1, 112, 0, digital_tlv),
  431. SOC_SINGLE("DSP2 Playback Switch", WM8996_DSP2_RX_FILTERS_1, 9, 1, 1),
  432. SOC_DOUBLE_R_TLV("DAC1 Volume", WM8996_DAC1_LEFT_VOLUME,
  433. WM8996_DAC1_RIGHT_VOLUME, 1, 112, 0, digital_tlv),
  434. SOC_DOUBLE_R("DAC1 Switch", WM8996_DAC1_LEFT_VOLUME,
  435. WM8996_DAC1_RIGHT_VOLUME, 9, 1, 1),
  436. SOC_DOUBLE_R_TLV("DAC2 Volume", WM8996_DAC2_LEFT_VOLUME,
  437. WM8996_DAC2_RIGHT_VOLUME, 1, 112, 0, digital_tlv),
  438. SOC_DOUBLE_R("DAC2 Switch", WM8996_DAC2_LEFT_VOLUME,
  439. WM8996_DAC2_RIGHT_VOLUME, 9, 1, 1),
  440. SOC_SINGLE("Speaker High Performance Switch", WM8996_OVERSAMPLING, 3, 1, 0),
  441. SOC_SINGLE("DMIC High Performance Switch", WM8996_OVERSAMPLING, 2, 1, 0),
  442. SOC_SINGLE("ADC High Performance Switch", WM8996_OVERSAMPLING, 1, 1, 0),
  443. SOC_SINGLE("DAC High Performance Switch", WM8996_OVERSAMPLING, 0, 1, 0),
  444. SOC_SINGLE("DAC Soft Mute Switch", WM8996_DAC_SOFTMUTE, 1, 1, 0),
  445. SOC_SINGLE("DAC Slow Soft Mute Switch", WM8996_DAC_SOFTMUTE, 0, 1, 0),
  446. SOC_SINGLE("DSP1 3D Stereo Switch", WM8996_DSP1_RX_FILTERS_2, 8, 1, 0),
  447. SOC_SINGLE("DSP2 3D Stereo Switch", WM8996_DSP2_RX_FILTERS_2, 8, 1, 0),
  448. SOC_SINGLE_TLV("DSP1 3D Stereo Volume", WM8996_DSP1_RX_FILTERS_2, 10, 15,
  449. 0, threedstereo_tlv),
  450. SOC_SINGLE_TLV("DSP2 3D Stereo Volume", WM8996_DSP2_RX_FILTERS_2, 10, 15,
  451. 0, threedstereo_tlv),
  452. SOC_DOUBLE_TLV("Digital Output 1 Volume", WM8996_DAC1_HPOUT1_VOLUME, 0, 4,
  453. 8, 0, out_digital_tlv),
  454. SOC_DOUBLE_TLV("Digital Output 2 Volume", WM8996_DAC2_HPOUT2_VOLUME, 0, 4,
  455. 8, 0, out_digital_tlv),
  456. SOC_DOUBLE_R_TLV("Output 1 Volume", WM8996_OUTPUT1_LEFT_VOLUME,
  457. WM8996_OUTPUT1_RIGHT_VOLUME, 0, 12, 0, out_tlv),
  458. SOC_DOUBLE_R("Output 1 ZC Switch", WM8996_OUTPUT1_LEFT_VOLUME,
  459. WM8996_OUTPUT1_RIGHT_VOLUME, 7, 1, 0),
  460. SOC_DOUBLE_R_TLV("Output 2 Volume", WM8996_OUTPUT2_LEFT_VOLUME,
  461. WM8996_OUTPUT2_RIGHT_VOLUME, 0, 12, 0, out_tlv),
  462. SOC_DOUBLE_R("Output 2 ZC Switch", WM8996_OUTPUT2_LEFT_VOLUME,
  463. WM8996_OUTPUT2_RIGHT_VOLUME, 7, 1, 0),
  464. SOC_DOUBLE_TLV("Speaker Volume", WM8996_PDM_SPEAKER_VOLUME, 0, 4, 8, 0,
  465. spk_tlv),
  466. SOC_DOUBLE_R("Speaker Switch", WM8996_LEFT_PDM_SPEAKER,
  467. WM8996_RIGHT_PDM_SPEAKER, 3, 1, 1),
  468. SOC_DOUBLE_R("Speaker ZC Switch", WM8996_LEFT_PDM_SPEAKER,
  469. WM8996_RIGHT_PDM_SPEAKER, 2, 1, 0),
  470. SOC_SINGLE("DSP1 EQ Switch", WM8996_DSP1_RX_EQ_GAINS_1, 0, 1, 0),
  471. SOC_SINGLE("DSP2 EQ Switch", WM8996_DSP2_RX_EQ_GAINS_1, 0, 1, 0),
  472. SOC_SINGLE("DSP1 DRC TXL Switch", WM8996_DSP1_DRC_1, 0, 1, 0),
  473. SOC_SINGLE("DSP1 DRC TXR Switch", WM8996_DSP1_DRC_1, 1, 1, 0),
  474. SOC_SINGLE("DSP1 DRC RX Switch", WM8996_DSP1_DRC_1, 2, 1, 0),
  475. SND_SOC_BYTES_MASK("DSP1 DRC", WM8996_DSP1_DRC_1, 5,
  476. WM8996_DSP1RX_DRC_ENA | WM8996_DSP1TXL_DRC_ENA |
  477. WM8996_DSP1TXR_DRC_ENA),
  478. SOC_SINGLE("DSP2 DRC TXL Switch", WM8996_DSP2_DRC_1, 0, 1, 0),
  479. SOC_SINGLE("DSP2 DRC TXR Switch", WM8996_DSP2_DRC_1, 1, 1, 0),
  480. SOC_SINGLE("DSP2 DRC RX Switch", WM8996_DSP2_DRC_1, 2, 1, 0),
  481. SND_SOC_BYTES_MASK("DSP2 DRC", WM8996_DSP2_DRC_1, 5,
  482. WM8996_DSP2RX_DRC_ENA | WM8996_DSP2TXL_DRC_ENA |
  483. WM8996_DSP2TXR_DRC_ENA),
  484. };
  485. static const struct snd_kcontrol_new wm8996_eq_controls[] = {
  486. SOC_SINGLE_TLV("DSP1 EQ B1 Volume", WM8996_DSP1_RX_EQ_GAINS_1, 11, 31, 0,
  487. eq_tlv),
  488. SOC_SINGLE_TLV("DSP1 EQ B2 Volume", WM8996_DSP1_RX_EQ_GAINS_1, 6, 31, 0,
  489. eq_tlv),
  490. SOC_SINGLE_TLV("DSP1 EQ B3 Volume", WM8996_DSP1_RX_EQ_GAINS_1, 1, 31, 0,
  491. eq_tlv),
  492. SOC_SINGLE_TLV("DSP1 EQ B4 Volume", WM8996_DSP1_RX_EQ_GAINS_2, 11, 31, 0,
  493. eq_tlv),
  494. SOC_SINGLE_TLV("DSP1 EQ B5 Volume", WM8996_DSP1_RX_EQ_GAINS_2, 6, 31, 0,
  495. eq_tlv),
  496. SOC_SINGLE_TLV("DSP2 EQ B1 Volume", WM8996_DSP2_RX_EQ_GAINS_1, 11, 31, 0,
  497. eq_tlv),
  498. SOC_SINGLE_TLV("DSP2 EQ B2 Volume", WM8996_DSP2_RX_EQ_GAINS_1, 6, 31, 0,
  499. eq_tlv),
  500. SOC_SINGLE_TLV("DSP2 EQ B3 Volume", WM8996_DSP2_RX_EQ_GAINS_1, 1, 31, 0,
  501. eq_tlv),
  502. SOC_SINGLE_TLV("DSP2 EQ B4 Volume", WM8996_DSP2_RX_EQ_GAINS_2, 11, 31, 0,
  503. eq_tlv),
  504. SOC_SINGLE_TLV("DSP2 EQ B5 Volume", WM8996_DSP2_RX_EQ_GAINS_2, 6, 31, 0,
  505. eq_tlv),
  506. };
  507. static void wm8996_bg_enable(struct snd_soc_codec *codec)
  508. {
  509. struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec);
  510. wm8996->bg_ena++;
  511. if (wm8996->bg_ena == 1) {
  512. snd_soc_update_bits(codec, WM8996_POWER_MANAGEMENT_1,
  513. WM8996_BG_ENA, WM8996_BG_ENA);
  514. msleep(2);
  515. }
  516. }
  517. static void wm8996_bg_disable(struct snd_soc_codec *codec)
  518. {
  519. struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec);
  520. wm8996->bg_ena--;
  521. if (!wm8996->bg_ena)
  522. snd_soc_update_bits(codec, WM8996_POWER_MANAGEMENT_1,
  523. WM8996_BG_ENA, 0);
  524. }
  525. static int bg_event(struct snd_soc_dapm_widget *w,
  526. struct snd_kcontrol *kcontrol, int event)
  527. {
  528. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  529. int ret = 0;
  530. switch (event) {
  531. case SND_SOC_DAPM_PRE_PMU:
  532. wm8996_bg_enable(codec);
  533. break;
  534. case SND_SOC_DAPM_POST_PMD:
  535. wm8996_bg_disable(codec);
  536. break;
  537. default:
  538. WARN(1, "Invalid event %d\n", event);
  539. ret = -EINVAL;
  540. }
  541. return ret;
  542. }
  543. static int cp_event(struct snd_soc_dapm_widget *w,
  544. struct snd_kcontrol *kcontrol, int event)
  545. {
  546. switch (event) {
  547. case SND_SOC_DAPM_POST_PMU:
  548. msleep(5);
  549. break;
  550. default:
  551. WARN(1, "Invalid event %d\n", event);
  552. }
  553. return 0;
  554. }
  555. static int rmv_short_event(struct snd_soc_dapm_widget *w,
  556. struct snd_kcontrol *kcontrol, int event)
  557. {
  558. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  559. struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec);
  560. /* Record which outputs we enabled */
  561. switch (event) {
  562. case SND_SOC_DAPM_PRE_PMD:
  563. wm8996->hpout_pending &= ~w->shift;
  564. break;
  565. case SND_SOC_DAPM_PRE_PMU:
  566. wm8996->hpout_pending |= w->shift;
  567. break;
  568. default:
  569. WARN(1, "Invalid event %d\n", event);
  570. return -EINVAL;
  571. }
  572. return 0;
  573. }
  574. static void wait_for_dc_servo(struct snd_soc_codec *codec, u16 mask)
  575. {
  576. struct i2c_client *i2c = to_i2c_client(codec->dev);
  577. struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec);
  578. int ret;
  579. unsigned long timeout = 200;
  580. snd_soc_write(codec, WM8996_DC_SERVO_2, mask);
  581. /* Use the interrupt if possible */
  582. do {
  583. if (i2c->irq) {
  584. timeout = wait_for_completion_timeout(&wm8996->dcs_done,
  585. msecs_to_jiffies(200));
  586. if (timeout == 0)
  587. dev_err(codec->dev, "DC servo timed out\n");
  588. } else {
  589. msleep(1);
  590. timeout--;
  591. }
  592. ret = snd_soc_read(codec, WM8996_DC_SERVO_2);
  593. dev_dbg(codec->dev, "DC servo state: %x\n", ret);
  594. } while (timeout && ret & mask);
  595. if (timeout == 0)
  596. dev_err(codec->dev, "DC servo timed out for %x\n", mask);
  597. else
  598. dev_dbg(codec->dev, "DC servo complete for %x\n", mask);
  599. }
  600. static void wm8996_seq_notifier(struct snd_soc_dapm_context *dapm,
  601. enum snd_soc_dapm_type event, int subseq)
  602. {
  603. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(dapm);
  604. struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec);
  605. u16 val, mask;
  606. /* Complete any pending DC servo starts */
  607. if (wm8996->dcs_pending) {
  608. dev_dbg(codec->dev, "Starting DC servo for %x\n",
  609. wm8996->dcs_pending);
  610. /* Trigger a startup sequence */
  611. wait_for_dc_servo(codec, wm8996->dcs_pending
  612. << WM8996_DCS_TRIG_STARTUP_0_SHIFT);
  613. wm8996->dcs_pending = 0;
  614. }
  615. if (wm8996->hpout_pending != wm8996->hpout_ena) {
  616. dev_dbg(codec->dev, "Applying RMV_SHORTs %x->%x\n",
  617. wm8996->hpout_ena, wm8996->hpout_pending);
  618. val = 0;
  619. mask = 0;
  620. if (wm8996->hpout_pending & HPOUT1L) {
  621. val |= WM8996_HPOUT1L_RMV_SHORT | WM8996_HPOUT1L_OUTP;
  622. mask |= WM8996_HPOUT1L_RMV_SHORT | WM8996_HPOUT1L_OUTP;
  623. } else {
  624. mask |= WM8996_HPOUT1L_RMV_SHORT |
  625. WM8996_HPOUT1L_OUTP |
  626. WM8996_HPOUT1L_DLY;
  627. }
  628. if (wm8996->hpout_pending & HPOUT1R) {
  629. val |= WM8996_HPOUT1R_RMV_SHORT | WM8996_HPOUT1R_OUTP;
  630. mask |= WM8996_HPOUT1R_RMV_SHORT | WM8996_HPOUT1R_OUTP;
  631. } else {
  632. mask |= WM8996_HPOUT1R_RMV_SHORT |
  633. WM8996_HPOUT1R_OUTP |
  634. WM8996_HPOUT1R_DLY;
  635. }
  636. snd_soc_update_bits(codec, WM8996_ANALOGUE_HP_1, mask, val);
  637. val = 0;
  638. mask = 0;
  639. if (wm8996->hpout_pending & HPOUT2L) {
  640. val |= WM8996_HPOUT2L_RMV_SHORT | WM8996_HPOUT2L_OUTP;
  641. mask |= WM8996_HPOUT2L_RMV_SHORT | WM8996_HPOUT2L_OUTP;
  642. } else {
  643. mask |= WM8996_HPOUT2L_RMV_SHORT |
  644. WM8996_HPOUT2L_OUTP |
  645. WM8996_HPOUT2L_DLY;
  646. }
  647. if (wm8996->hpout_pending & HPOUT2R) {
  648. val |= WM8996_HPOUT2R_RMV_SHORT | WM8996_HPOUT2R_OUTP;
  649. mask |= WM8996_HPOUT2R_RMV_SHORT | WM8996_HPOUT2R_OUTP;
  650. } else {
  651. mask |= WM8996_HPOUT2R_RMV_SHORT |
  652. WM8996_HPOUT2R_OUTP |
  653. WM8996_HPOUT2R_DLY;
  654. }
  655. snd_soc_update_bits(codec, WM8996_ANALOGUE_HP_2, mask, val);
  656. wm8996->hpout_ena = wm8996->hpout_pending;
  657. }
  658. }
  659. static int dcs_start(struct snd_soc_dapm_widget *w,
  660. struct snd_kcontrol *kcontrol, int event)
  661. {
  662. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  663. struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec);
  664. switch (event) {
  665. case SND_SOC_DAPM_POST_PMU:
  666. wm8996->dcs_pending |= 1 << w->shift;
  667. break;
  668. default:
  669. WARN(1, "Invalid event %d\n", event);
  670. return -EINVAL;
  671. }
  672. return 0;
  673. }
  674. static const char *sidetone_text[] = {
  675. "IN1", "IN2",
  676. };
  677. static SOC_ENUM_SINGLE_DECL(left_sidetone_enum,
  678. WM8996_SIDETONE, 0, sidetone_text);
  679. static const struct snd_kcontrol_new left_sidetone =
  680. SOC_DAPM_ENUM("Left Sidetone", left_sidetone_enum);
  681. static SOC_ENUM_SINGLE_DECL(right_sidetone_enum,
  682. WM8996_SIDETONE, 1, sidetone_text);
  683. static const struct snd_kcontrol_new right_sidetone =
  684. SOC_DAPM_ENUM("Right Sidetone", right_sidetone_enum);
  685. static const char *spk_text[] = {
  686. "DAC1L", "DAC1R", "DAC2L", "DAC2R"
  687. };
  688. static SOC_ENUM_SINGLE_DECL(spkl_enum,
  689. WM8996_LEFT_PDM_SPEAKER, 0, spk_text);
  690. static const struct snd_kcontrol_new spkl_mux =
  691. SOC_DAPM_ENUM("SPKL", spkl_enum);
  692. static SOC_ENUM_SINGLE_DECL(spkr_enum,
  693. WM8996_RIGHT_PDM_SPEAKER, 0, spk_text);
  694. static const struct snd_kcontrol_new spkr_mux =
  695. SOC_DAPM_ENUM("SPKR", spkr_enum);
  696. static const char *dsp1rx_text[] = {
  697. "AIF1", "AIF2"
  698. };
  699. static SOC_ENUM_SINGLE_DECL(dsp1rx_enum,
  700. WM8996_POWER_MANAGEMENT_8, 0, dsp1rx_text);
  701. static const struct snd_kcontrol_new dsp1rx =
  702. SOC_DAPM_ENUM("DSP1RX", dsp1rx_enum);
  703. static const char *dsp2rx_text[] = {
  704. "AIF2", "AIF1"
  705. };
  706. static SOC_ENUM_SINGLE_DECL(dsp2rx_enum,
  707. WM8996_POWER_MANAGEMENT_8, 4, dsp2rx_text);
  708. static const struct snd_kcontrol_new dsp2rx =
  709. SOC_DAPM_ENUM("DSP2RX", dsp2rx_enum);
  710. static const char *aif2tx_text[] = {
  711. "DSP2", "DSP1", "AIF1"
  712. };
  713. static SOC_ENUM_SINGLE_DECL(aif2tx_enum,
  714. WM8996_POWER_MANAGEMENT_8, 6, aif2tx_text);
  715. static const struct snd_kcontrol_new aif2tx =
  716. SOC_DAPM_ENUM("AIF2TX", aif2tx_enum);
  717. static const char *inmux_text[] = {
  718. "ADC", "DMIC1", "DMIC2"
  719. };
  720. static SOC_ENUM_SINGLE_DECL(in1_enum,
  721. WM8996_POWER_MANAGEMENT_7, 0, inmux_text);
  722. static const struct snd_kcontrol_new in1_mux =
  723. SOC_DAPM_ENUM("IN1 Mux", in1_enum);
  724. static SOC_ENUM_SINGLE_DECL(in2_enum,
  725. WM8996_POWER_MANAGEMENT_7, 4, inmux_text);
  726. static const struct snd_kcontrol_new in2_mux =
  727. SOC_DAPM_ENUM("IN2 Mux", in2_enum);
  728. static const struct snd_kcontrol_new dac2r_mix[] = {
  729. SOC_DAPM_SINGLE("Right Sidetone Switch", WM8996_DAC2_RIGHT_MIXER_ROUTING,
  730. 5, 1, 0),
  731. SOC_DAPM_SINGLE("Left Sidetone Switch", WM8996_DAC2_RIGHT_MIXER_ROUTING,
  732. 4, 1, 0),
  733. SOC_DAPM_SINGLE("DSP2 Switch", WM8996_DAC2_RIGHT_MIXER_ROUTING, 1, 1, 0),
  734. SOC_DAPM_SINGLE("DSP1 Switch", WM8996_DAC2_RIGHT_MIXER_ROUTING, 0, 1, 0),
  735. };
  736. static const struct snd_kcontrol_new dac2l_mix[] = {
  737. SOC_DAPM_SINGLE("Right Sidetone Switch", WM8996_DAC2_LEFT_MIXER_ROUTING,
  738. 5, 1, 0),
  739. SOC_DAPM_SINGLE("Left Sidetone Switch", WM8996_DAC2_LEFT_MIXER_ROUTING,
  740. 4, 1, 0),
  741. SOC_DAPM_SINGLE("DSP2 Switch", WM8996_DAC2_LEFT_MIXER_ROUTING, 1, 1, 0),
  742. SOC_DAPM_SINGLE("DSP1 Switch", WM8996_DAC2_LEFT_MIXER_ROUTING, 0, 1, 0),
  743. };
  744. static const struct snd_kcontrol_new dac1r_mix[] = {
  745. SOC_DAPM_SINGLE("Right Sidetone Switch", WM8996_DAC1_RIGHT_MIXER_ROUTING,
  746. 5, 1, 0),
  747. SOC_DAPM_SINGLE("Left Sidetone Switch", WM8996_DAC1_RIGHT_MIXER_ROUTING,
  748. 4, 1, 0),
  749. SOC_DAPM_SINGLE("DSP2 Switch", WM8996_DAC1_RIGHT_MIXER_ROUTING, 1, 1, 0),
  750. SOC_DAPM_SINGLE("DSP1 Switch", WM8996_DAC1_RIGHT_MIXER_ROUTING, 0, 1, 0),
  751. };
  752. static const struct snd_kcontrol_new dac1l_mix[] = {
  753. SOC_DAPM_SINGLE("Right Sidetone Switch", WM8996_DAC1_LEFT_MIXER_ROUTING,
  754. 5, 1, 0),
  755. SOC_DAPM_SINGLE("Left Sidetone Switch", WM8996_DAC1_LEFT_MIXER_ROUTING,
  756. 4, 1, 0),
  757. SOC_DAPM_SINGLE("DSP2 Switch", WM8996_DAC1_LEFT_MIXER_ROUTING, 1, 1, 0),
  758. SOC_DAPM_SINGLE("DSP1 Switch", WM8996_DAC1_LEFT_MIXER_ROUTING, 0, 1, 0),
  759. };
  760. static const struct snd_kcontrol_new dsp1txl[] = {
  761. SOC_DAPM_SINGLE("IN1 Switch", WM8996_DSP1_TX_LEFT_MIXER_ROUTING,
  762. 1, 1, 0),
  763. SOC_DAPM_SINGLE("DAC Switch", WM8996_DSP1_TX_LEFT_MIXER_ROUTING,
  764. 0, 1, 0),
  765. };
  766. static const struct snd_kcontrol_new dsp1txr[] = {
  767. SOC_DAPM_SINGLE("IN1 Switch", WM8996_DSP1_TX_RIGHT_MIXER_ROUTING,
  768. 1, 1, 0),
  769. SOC_DAPM_SINGLE("DAC Switch", WM8996_DSP1_TX_RIGHT_MIXER_ROUTING,
  770. 0, 1, 0),
  771. };
  772. static const struct snd_kcontrol_new dsp2txl[] = {
  773. SOC_DAPM_SINGLE("IN1 Switch", WM8996_DSP2_TX_LEFT_MIXER_ROUTING,
  774. 1, 1, 0),
  775. SOC_DAPM_SINGLE("DAC Switch", WM8996_DSP2_TX_LEFT_MIXER_ROUTING,
  776. 0, 1, 0),
  777. };
  778. static const struct snd_kcontrol_new dsp2txr[] = {
  779. SOC_DAPM_SINGLE("IN1 Switch", WM8996_DSP2_TX_RIGHT_MIXER_ROUTING,
  780. 1, 1, 0),
  781. SOC_DAPM_SINGLE("DAC Switch", WM8996_DSP2_TX_RIGHT_MIXER_ROUTING,
  782. 0, 1, 0),
  783. };
  784. static const struct snd_soc_dapm_widget wm8996_dapm_widgets[] = {
  785. SND_SOC_DAPM_INPUT("IN1LN"),
  786. SND_SOC_DAPM_INPUT("IN1LP"),
  787. SND_SOC_DAPM_INPUT("IN1RN"),
  788. SND_SOC_DAPM_INPUT("IN1RP"),
  789. SND_SOC_DAPM_INPUT("IN2LN"),
  790. SND_SOC_DAPM_INPUT("IN2LP"),
  791. SND_SOC_DAPM_INPUT("IN2RN"),
  792. SND_SOC_DAPM_INPUT("IN2RP"),
  793. SND_SOC_DAPM_INPUT("DMIC1DAT"),
  794. SND_SOC_DAPM_INPUT("DMIC2DAT"),
  795. SND_SOC_DAPM_REGULATOR_SUPPLY("CPVDD", 20, 0),
  796. SND_SOC_DAPM_SUPPLY_S("SYSCLK", 1, WM8996_AIF_CLOCKING_1, 0, 0, NULL, 0),
  797. SND_SOC_DAPM_SUPPLY_S("SYSDSPCLK", 2, WM8996_CLOCKING_1, 1, 0, NULL, 0),
  798. SND_SOC_DAPM_SUPPLY_S("AIFCLK", 2, WM8996_CLOCKING_1, 2, 0, NULL, 0),
  799. SND_SOC_DAPM_SUPPLY_S("Charge Pump", 2, WM8996_CHARGE_PUMP_1, 15, 0, cp_event,
  800. SND_SOC_DAPM_POST_PMU),
  801. SND_SOC_DAPM_SUPPLY("Bandgap", SND_SOC_NOPM, 0, 0, bg_event,
  802. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  803. SND_SOC_DAPM_SUPPLY("LDO2", WM8996_POWER_MANAGEMENT_2, 1, 0, NULL, 0),
  804. SND_SOC_DAPM_SUPPLY("MICB1 Audio", WM8996_MICBIAS_1, 4, 1, NULL, 0),
  805. SND_SOC_DAPM_SUPPLY("MICB2 Audio", WM8996_MICBIAS_2, 4, 1, NULL, 0),
  806. SND_SOC_DAPM_MICBIAS("MICB2", WM8996_POWER_MANAGEMENT_1, 9, 0),
  807. SND_SOC_DAPM_MICBIAS("MICB1", WM8996_POWER_MANAGEMENT_1, 8, 0),
  808. SND_SOC_DAPM_PGA("IN1L PGA", WM8996_POWER_MANAGEMENT_2, 5, 0, NULL, 0),
  809. SND_SOC_DAPM_PGA("IN1R PGA", WM8996_POWER_MANAGEMENT_2, 4, 0, NULL, 0),
  810. SND_SOC_DAPM_MUX("IN1L Mux", WM8996_POWER_MANAGEMENT_7, 2, 0, &in1_mux),
  811. SND_SOC_DAPM_MUX("IN1R Mux", WM8996_POWER_MANAGEMENT_7, 3, 0, &in1_mux),
  812. SND_SOC_DAPM_MUX("IN2L Mux", WM8996_POWER_MANAGEMENT_7, 6, 0, &in2_mux),
  813. SND_SOC_DAPM_MUX("IN2R Mux", WM8996_POWER_MANAGEMENT_7, 7, 0, &in2_mux),
  814. SND_SOC_DAPM_SUPPLY("DMIC2", WM8996_POWER_MANAGEMENT_7, 9, 0, NULL, 0),
  815. SND_SOC_DAPM_SUPPLY("DMIC1", WM8996_POWER_MANAGEMENT_7, 8, 0, NULL, 0),
  816. SND_SOC_DAPM_ADC("DMIC2L", NULL, WM8996_POWER_MANAGEMENT_3, 5, 0),
  817. SND_SOC_DAPM_ADC("DMIC2R", NULL, WM8996_POWER_MANAGEMENT_3, 4, 0),
  818. SND_SOC_DAPM_ADC("DMIC1L", NULL, WM8996_POWER_MANAGEMENT_3, 3, 0),
  819. SND_SOC_DAPM_ADC("DMIC1R", NULL, WM8996_POWER_MANAGEMENT_3, 2, 0),
  820. SND_SOC_DAPM_ADC("ADCL", NULL, WM8996_POWER_MANAGEMENT_3, 1, 0),
  821. SND_SOC_DAPM_ADC("ADCR", NULL, WM8996_POWER_MANAGEMENT_3, 0, 0),
  822. SND_SOC_DAPM_MUX("Left Sidetone", SND_SOC_NOPM, 0, 0, &left_sidetone),
  823. SND_SOC_DAPM_MUX("Right Sidetone", SND_SOC_NOPM, 0, 0, &right_sidetone),
  824. SND_SOC_DAPM_AIF_IN("DSP2RXL", NULL, 0, WM8996_POWER_MANAGEMENT_3, 11, 0),
  825. SND_SOC_DAPM_AIF_IN("DSP2RXR", NULL, 1, WM8996_POWER_MANAGEMENT_3, 10, 0),
  826. SND_SOC_DAPM_AIF_IN("DSP1RXL", NULL, 0, WM8996_POWER_MANAGEMENT_3, 9, 0),
  827. SND_SOC_DAPM_AIF_IN("DSP1RXR", NULL, 1, WM8996_POWER_MANAGEMENT_3, 8, 0),
  828. SND_SOC_DAPM_MIXER("DSP2TXL", WM8996_POWER_MANAGEMENT_5, 11, 0,
  829. dsp2txl, ARRAY_SIZE(dsp2txl)),
  830. SND_SOC_DAPM_MIXER("DSP2TXR", WM8996_POWER_MANAGEMENT_5, 10, 0,
  831. dsp2txr, ARRAY_SIZE(dsp2txr)),
  832. SND_SOC_DAPM_MIXER("DSP1TXL", WM8996_POWER_MANAGEMENT_5, 9, 0,
  833. dsp1txl, ARRAY_SIZE(dsp1txl)),
  834. SND_SOC_DAPM_MIXER("DSP1TXR", WM8996_POWER_MANAGEMENT_5, 8, 0,
  835. dsp1txr, ARRAY_SIZE(dsp1txr)),
  836. SND_SOC_DAPM_MIXER("DAC2L Mixer", SND_SOC_NOPM, 0, 0,
  837. dac2l_mix, ARRAY_SIZE(dac2l_mix)),
  838. SND_SOC_DAPM_MIXER("DAC2R Mixer", SND_SOC_NOPM, 0, 0,
  839. dac2r_mix, ARRAY_SIZE(dac2r_mix)),
  840. SND_SOC_DAPM_MIXER("DAC1L Mixer", SND_SOC_NOPM, 0, 0,
  841. dac1l_mix, ARRAY_SIZE(dac1l_mix)),
  842. SND_SOC_DAPM_MIXER("DAC1R Mixer", SND_SOC_NOPM, 0, 0,
  843. dac1r_mix, ARRAY_SIZE(dac1r_mix)),
  844. SND_SOC_DAPM_DAC("DAC2L", NULL, WM8996_POWER_MANAGEMENT_5, 3, 0),
  845. SND_SOC_DAPM_DAC("DAC2R", NULL, WM8996_POWER_MANAGEMENT_5, 2, 0),
  846. SND_SOC_DAPM_DAC("DAC1L", NULL, WM8996_POWER_MANAGEMENT_5, 1, 0),
  847. SND_SOC_DAPM_DAC("DAC1R", NULL, WM8996_POWER_MANAGEMENT_5, 0, 0),
  848. SND_SOC_DAPM_AIF_IN("AIF2RX1", NULL, 0, WM8996_POWER_MANAGEMENT_4, 9, 0),
  849. SND_SOC_DAPM_AIF_IN("AIF2RX0", NULL, 1, WM8996_POWER_MANAGEMENT_4, 8, 0),
  850. SND_SOC_DAPM_AIF_OUT("AIF2TX1", NULL, 0, WM8996_POWER_MANAGEMENT_6, 9, 0),
  851. SND_SOC_DAPM_AIF_OUT("AIF2TX0", NULL, 1, WM8996_POWER_MANAGEMENT_6, 8, 0),
  852. SND_SOC_DAPM_AIF_IN("AIF1RX5", NULL, 5, WM8996_POWER_MANAGEMENT_4, 5, 0),
  853. SND_SOC_DAPM_AIF_IN("AIF1RX4", NULL, 4, WM8996_POWER_MANAGEMENT_4, 4, 0),
  854. SND_SOC_DAPM_AIF_IN("AIF1RX3", NULL, 3, WM8996_POWER_MANAGEMENT_4, 3, 0),
  855. SND_SOC_DAPM_AIF_IN("AIF1RX2", NULL, 2, WM8996_POWER_MANAGEMENT_4, 2, 0),
  856. SND_SOC_DAPM_AIF_IN("AIF1RX1", NULL, 1, WM8996_POWER_MANAGEMENT_4, 1, 0),
  857. SND_SOC_DAPM_AIF_IN("AIF1RX0", NULL, 0, WM8996_POWER_MANAGEMENT_4, 0, 0),
  858. SND_SOC_DAPM_AIF_OUT("AIF1TX5", NULL, 5, WM8996_POWER_MANAGEMENT_6, 5, 0),
  859. SND_SOC_DAPM_AIF_OUT("AIF1TX4", NULL, 4, WM8996_POWER_MANAGEMENT_6, 4, 0),
  860. SND_SOC_DAPM_AIF_OUT("AIF1TX3", NULL, 3, WM8996_POWER_MANAGEMENT_6, 3, 0),
  861. SND_SOC_DAPM_AIF_OUT("AIF1TX2", NULL, 2, WM8996_POWER_MANAGEMENT_6, 2, 0),
  862. SND_SOC_DAPM_AIF_OUT("AIF1TX1", NULL, 1, WM8996_POWER_MANAGEMENT_6, 1, 0),
  863. SND_SOC_DAPM_AIF_OUT("AIF1TX0", NULL, 0, WM8996_POWER_MANAGEMENT_6, 0, 0),
  864. /* We route as stereo pairs so define some dummy widgets to squash
  865. * things down for now. RXA = 0,1, RXB = 2,3 and so on */
  866. SND_SOC_DAPM_PGA("AIF1RXA", SND_SOC_NOPM, 0, 0, NULL, 0),
  867. SND_SOC_DAPM_PGA("AIF1RXB", SND_SOC_NOPM, 0, 0, NULL, 0),
  868. SND_SOC_DAPM_PGA("AIF1RXC", SND_SOC_NOPM, 0, 0, NULL, 0),
  869. SND_SOC_DAPM_PGA("AIF2RX", SND_SOC_NOPM, 0, 0, NULL, 0),
  870. SND_SOC_DAPM_PGA("DSP2TX", SND_SOC_NOPM, 0, 0, NULL, 0),
  871. SND_SOC_DAPM_MUX("DSP1RX", SND_SOC_NOPM, 0, 0, &dsp1rx),
  872. SND_SOC_DAPM_MUX("DSP2RX", SND_SOC_NOPM, 0, 0, &dsp2rx),
  873. SND_SOC_DAPM_MUX("AIF2TX", SND_SOC_NOPM, 0, 0, &aif2tx),
  874. SND_SOC_DAPM_MUX("SPKL", SND_SOC_NOPM, 0, 0, &spkl_mux),
  875. SND_SOC_DAPM_MUX("SPKR", SND_SOC_NOPM, 0, 0, &spkr_mux),
  876. SND_SOC_DAPM_PGA("SPKL PGA", WM8996_LEFT_PDM_SPEAKER, 4, 0, NULL, 0),
  877. SND_SOC_DAPM_PGA("SPKR PGA", WM8996_RIGHT_PDM_SPEAKER, 4, 0, NULL, 0),
  878. SND_SOC_DAPM_PGA_S("HPOUT2L PGA", 0, WM8996_POWER_MANAGEMENT_1, 7, 0, NULL, 0),
  879. SND_SOC_DAPM_PGA_S("HPOUT2L_DLY", 1, WM8996_ANALOGUE_HP_2, 5, 0, NULL, 0),
  880. SND_SOC_DAPM_PGA_S("HPOUT2L_DCS", 2, WM8996_DC_SERVO_1, 2, 0, dcs_start,
  881. SND_SOC_DAPM_POST_PMU),
  882. SND_SOC_DAPM_PGA_S("HPOUT2L_RMV_SHORT", 3, SND_SOC_NOPM, HPOUT2L, 0,
  883. rmv_short_event,
  884. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
  885. SND_SOC_DAPM_PGA_S("HPOUT2R PGA", 0, WM8996_POWER_MANAGEMENT_1, 6, 0,NULL, 0),
  886. SND_SOC_DAPM_PGA_S("HPOUT2R_DLY", 1, WM8996_ANALOGUE_HP_2, 1, 0, NULL, 0),
  887. SND_SOC_DAPM_PGA_S("HPOUT2R_DCS", 2, WM8996_DC_SERVO_1, 3, 0, dcs_start,
  888. SND_SOC_DAPM_POST_PMU),
  889. SND_SOC_DAPM_PGA_S("HPOUT2R_RMV_SHORT", 3, SND_SOC_NOPM, HPOUT2R, 0,
  890. rmv_short_event,
  891. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
  892. SND_SOC_DAPM_PGA_S("HPOUT1L PGA", 0, WM8996_POWER_MANAGEMENT_1, 5, 0, NULL, 0),
  893. SND_SOC_DAPM_PGA_S("HPOUT1L_DLY", 1, WM8996_ANALOGUE_HP_1, 5, 0, NULL, 0),
  894. SND_SOC_DAPM_PGA_S("HPOUT1L_DCS", 2, WM8996_DC_SERVO_1, 0, 0, dcs_start,
  895. SND_SOC_DAPM_POST_PMU),
  896. SND_SOC_DAPM_PGA_S("HPOUT1L_RMV_SHORT", 3, SND_SOC_NOPM, HPOUT1L, 0,
  897. rmv_short_event,
  898. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
  899. SND_SOC_DAPM_PGA_S("HPOUT1R PGA", 0, WM8996_POWER_MANAGEMENT_1, 4, 0, NULL, 0),
  900. SND_SOC_DAPM_PGA_S("HPOUT1R_DLY", 1, WM8996_ANALOGUE_HP_1, 1, 0, NULL, 0),
  901. SND_SOC_DAPM_PGA_S("HPOUT1R_DCS", 2, WM8996_DC_SERVO_1, 1, 0, dcs_start,
  902. SND_SOC_DAPM_POST_PMU),
  903. SND_SOC_DAPM_PGA_S("HPOUT1R_RMV_SHORT", 3, SND_SOC_NOPM, HPOUT1R, 0,
  904. rmv_short_event,
  905. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
  906. SND_SOC_DAPM_OUTPUT("HPOUT1L"),
  907. SND_SOC_DAPM_OUTPUT("HPOUT1R"),
  908. SND_SOC_DAPM_OUTPUT("HPOUT2L"),
  909. SND_SOC_DAPM_OUTPUT("HPOUT2R"),
  910. SND_SOC_DAPM_OUTPUT("SPKDAT"),
  911. };
  912. static const struct snd_soc_dapm_route wm8996_dapm_routes[] = {
  913. { "AIFCLK", NULL, "SYSCLK" },
  914. { "SYSDSPCLK", NULL, "SYSCLK" },
  915. { "Charge Pump", NULL, "SYSCLK" },
  916. { "Charge Pump", NULL, "CPVDD" },
  917. { "MICB1", NULL, "LDO2" },
  918. { "MICB1", NULL, "MICB1 Audio" },
  919. { "MICB1", NULL, "Bandgap" },
  920. { "MICB2", NULL, "LDO2" },
  921. { "MICB2", NULL, "MICB2 Audio" },
  922. { "MICB2", NULL, "Bandgap" },
  923. { "AIF1RX0", NULL, "AIF1 Playback" },
  924. { "AIF1RX1", NULL, "AIF1 Playback" },
  925. { "AIF1RX2", NULL, "AIF1 Playback" },
  926. { "AIF1RX3", NULL, "AIF1 Playback" },
  927. { "AIF1RX4", NULL, "AIF1 Playback" },
  928. { "AIF1RX5", NULL, "AIF1 Playback" },
  929. { "AIF2RX0", NULL, "AIF2 Playback" },
  930. { "AIF2RX1", NULL, "AIF2 Playback" },
  931. { "AIF1 Capture", NULL, "AIF1TX0" },
  932. { "AIF1 Capture", NULL, "AIF1TX1" },
  933. { "AIF1 Capture", NULL, "AIF1TX2" },
  934. { "AIF1 Capture", NULL, "AIF1TX3" },
  935. { "AIF1 Capture", NULL, "AIF1TX4" },
  936. { "AIF1 Capture", NULL, "AIF1TX5" },
  937. { "AIF2 Capture", NULL, "AIF2TX0" },
  938. { "AIF2 Capture", NULL, "AIF2TX1" },
  939. { "IN1L PGA", NULL, "IN2LN" },
  940. { "IN1L PGA", NULL, "IN2LP" },
  941. { "IN1L PGA", NULL, "IN1LN" },
  942. { "IN1L PGA", NULL, "IN1LP" },
  943. { "IN1L PGA", NULL, "Bandgap" },
  944. { "IN1R PGA", NULL, "IN2RN" },
  945. { "IN1R PGA", NULL, "IN2RP" },
  946. { "IN1R PGA", NULL, "IN1RN" },
  947. { "IN1R PGA", NULL, "IN1RP" },
  948. { "IN1R PGA", NULL, "Bandgap" },
  949. { "ADCL", NULL, "IN1L PGA" },
  950. { "ADCR", NULL, "IN1R PGA" },
  951. { "DMIC1L", NULL, "DMIC1DAT" },
  952. { "DMIC1R", NULL, "DMIC1DAT" },
  953. { "DMIC2L", NULL, "DMIC2DAT" },
  954. { "DMIC2R", NULL, "DMIC2DAT" },
  955. { "DMIC2L", NULL, "DMIC2" },
  956. { "DMIC2R", NULL, "DMIC2" },
  957. { "DMIC1L", NULL, "DMIC1" },
  958. { "DMIC1R", NULL, "DMIC1" },
  959. { "IN1L Mux", "ADC", "ADCL" },
  960. { "IN1L Mux", "DMIC1", "DMIC1L" },
  961. { "IN1L Mux", "DMIC2", "DMIC2L" },
  962. { "IN1R Mux", "ADC", "ADCR" },
  963. { "IN1R Mux", "DMIC1", "DMIC1R" },
  964. { "IN1R Mux", "DMIC2", "DMIC2R" },
  965. { "IN2L Mux", "ADC", "ADCL" },
  966. { "IN2L Mux", "DMIC1", "DMIC1L" },
  967. { "IN2L Mux", "DMIC2", "DMIC2L" },
  968. { "IN2R Mux", "ADC", "ADCR" },
  969. { "IN2R Mux", "DMIC1", "DMIC1R" },
  970. { "IN2R Mux", "DMIC2", "DMIC2R" },
  971. { "Left Sidetone", "IN1", "IN1L Mux" },
  972. { "Left Sidetone", "IN2", "IN2L Mux" },
  973. { "Right Sidetone", "IN1", "IN1R Mux" },
  974. { "Right Sidetone", "IN2", "IN2R Mux" },
  975. { "DSP1TXL", "IN1 Switch", "IN1L Mux" },
  976. { "DSP1TXR", "IN1 Switch", "IN1R Mux" },
  977. { "DSP2TXL", "IN1 Switch", "IN2L Mux" },
  978. { "DSP2TXR", "IN1 Switch", "IN2R Mux" },
  979. { "AIF1TX0", NULL, "DSP1TXL" },
  980. { "AIF1TX1", NULL, "DSP1TXR" },
  981. { "AIF1TX2", NULL, "DSP2TXL" },
  982. { "AIF1TX3", NULL, "DSP2TXR" },
  983. { "AIF1TX4", NULL, "AIF2RX0" },
  984. { "AIF1TX5", NULL, "AIF2RX1" },
  985. { "AIF1RX0", NULL, "AIFCLK" },
  986. { "AIF1RX1", NULL, "AIFCLK" },
  987. { "AIF1RX2", NULL, "AIFCLK" },
  988. { "AIF1RX3", NULL, "AIFCLK" },
  989. { "AIF1RX4", NULL, "AIFCLK" },
  990. { "AIF1RX5", NULL, "AIFCLK" },
  991. { "AIF2RX0", NULL, "AIFCLK" },
  992. { "AIF2RX1", NULL, "AIFCLK" },
  993. { "AIF1TX0", NULL, "AIFCLK" },
  994. { "AIF1TX1", NULL, "AIFCLK" },
  995. { "AIF1TX2", NULL, "AIFCLK" },
  996. { "AIF1TX3", NULL, "AIFCLK" },
  997. { "AIF1TX4", NULL, "AIFCLK" },
  998. { "AIF1TX5", NULL, "AIFCLK" },
  999. { "AIF2TX0", NULL, "AIFCLK" },
  1000. { "AIF2TX1", NULL, "AIFCLK" },
  1001. { "DSP1RXL", NULL, "SYSDSPCLK" },
  1002. { "DSP1RXR", NULL, "SYSDSPCLK" },
  1003. { "DSP2RXL", NULL, "SYSDSPCLK" },
  1004. { "DSP2RXR", NULL, "SYSDSPCLK" },
  1005. { "DSP1TXL", NULL, "SYSDSPCLK" },
  1006. { "DSP1TXR", NULL, "SYSDSPCLK" },
  1007. { "DSP2TXL", NULL, "SYSDSPCLK" },
  1008. { "DSP2TXR", NULL, "SYSDSPCLK" },
  1009. { "AIF1RXA", NULL, "AIF1RX0" },
  1010. { "AIF1RXA", NULL, "AIF1RX1" },
  1011. { "AIF1RXB", NULL, "AIF1RX2" },
  1012. { "AIF1RXB", NULL, "AIF1RX3" },
  1013. { "AIF1RXC", NULL, "AIF1RX4" },
  1014. { "AIF1RXC", NULL, "AIF1RX5" },
  1015. { "AIF2RX", NULL, "AIF2RX0" },
  1016. { "AIF2RX", NULL, "AIF2RX1" },
  1017. { "AIF2TX", "DSP2", "DSP2TX" },
  1018. { "AIF2TX", "DSP1", "DSP1RX" },
  1019. { "AIF2TX", "AIF1", "AIF1RXC" },
  1020. { "DSP1RXL", NULL, "DSP1RX" },
  1021. { "DSP1RXR", NULL, "DSP1RX" },
  1022. { "DSP2RXL", NULL, "DSP2RX" },
  1023. { "DSP2RXR", NULL, "DSP2RX" },
  1024. { "DSP2TX", NULL, "DSP2TXL" },
  1025. { "DSP2TX", NULL, "DSP2TXR" },
  1026. { "DSP1RX", "AIF1", "AIF1RXA" },
  1027. { "DSP1RX", "AIF2", "AIF2RX" },
  1028. { "DSP2RX", "AIF1", "AIF1RXB" },
  1029. { "DSP2RX", "AIF2", "AIF2RX" },
  1030. { "DAC2L Mixer", "DSP2 Switch", "DSP2RXL" },
  1031. { "DAC2L Mixer", "DSP1 Switch", "DSP1RXL" },
  1032. { "DAC2L Mixer", "Right Sidetone Switch", "Right Sidetone" },
  1033. { "DAC2L Mixer", "Left Sidetone Switch", "Left Sidetone" },
  1034. { "DAC2R Mixer", "DSP2 Switch", "DSP2RXR" },
  1035. { "DAC2R Mixer", "DSP1 Switch", "DSP1RXR" },
  1036. { "DAC2R Mixer", "Right Sidetone Switch", "Right Sidetone" },
  1037. { "DAC2R Mixer", "Left Sidetone Switch", "Left Sidetone" },
  1038. { "DAC1L Mixer", "DSP2 Switch", "DSP2RXL" },
  1039. { "DAC1L Mixer", "DSP1 Switch", "DSP1RXL" },
  1040. { "DAC1L Mixer", "Right Sidetone Switch", "Right Sidetone" },
  1041. { "DAC1L Mixer", "Left Sidetone Switch", "Left Sidetone" },
  1042. { "DAC1R Mixer", "DSP2 Switch", "DSP2RXR" },
  1043. { "DAC1R Mixer", "DSP1 Switch", "DSP1RXR" },
  1044. { "DAC1R Mixer", "Right Sidetone Switch", "Right Sidetone" },
  1045. { "DAC1R Mixer", "Left Sidetone Switch", "Left Sidetone" },
  1046. { "DAC1L", NULL, "DAC1L Mixer" },
  1047. { "DAC1R", NULL, "DAC1R Mixer" },
  1048. { "DAC2L", NULL, "DAC2L Mixer" },
  1049. { "DAC2R", NULL, "DAC2R Mixer" },
  1050. { "HPOUT2L PGA", NULL, "Charge Pump" },
  1051. { "HPOUT2L PGA", NULL, "Bandgap" },
  1052. { "HPOUT2L PGA", NULL, "DAC2L" },
  1053. { "HPOUT2L_DLY", NULL, "HPOUT2L PGA" },
  1054. { "HPOUT2L_DCS", NULL, "HPOUT2L_DLY" },
  1055. { "HPOUT2L_RMV_SHORT", NULL, "HPOUT2L_DCS" },
  1056. { "HPOUT2R PGA", NULL, "Charge Pump" },
  1057. { "HPOUT2R PGA", NULL, "Bandgap" },
  1058. { "HPOUT2R PGA", NULL, "DAC2R" },
  1059. { "HPOUT2R_DLY", NULL, "HPOUT2R PGA" },
  1060. { "HPOUT2R_DCS", NULL, "HPOUT2R_DLY" },
  1061. { "HPOUT2R_RMV_SHORT", NULL, "HPOUT2R_DCS" },
  1062. { "HPOUT1L PGA", NULL, "Charge Pump" },
  1063. { "HPOUT1L PGA", NULL, "Bandgap" },
  1064. { "HPOUT1L PGA", NULL, "DAC1L" },
  1065. { "HPOUT1L_DLY", NULL, "HPOUT1L PGA" },
  1066. { "HPOUT1L_DCS", NULL, "HPOUT1L_DLY" },
  1067. { "HPOUT1L_RMV_SHORT", NULL, "HPOUT1L_DCS" },
  1068. { "HPOUT1R PGA", NULL, "Charge Pump" },
  1069. { "HPOUT1R PGA", NULL, "Bandgap" },
  1070. { "HPOUT1R PGA", NULL, "DAC1R" },
  1071. { "HPOUT1R_DLY", NULL, "HPOUT1R PGA" },
  1072. { "HPOUT1R_DCS", NULL, "HPOUT1R_DLY" },
  1073. { "HPOUT1R_RMV_SHORT", NULL, "HPOUT1R_DCS" },
  1074. { "HPOUT2L", NULL, "HPOUT2L_RMV_SHORT" },
  1075. { "HPOUT2R", NULL, "HPOUT2R_RMV_SHORT" },
  1076. { "HPOUT1L", NULL, "HPOUT1L_RMV_SHORT" },
  1077. { "HPOUT1R", NULL, "HPOUT1R_RMV_SHORT" },
  1078. { "SPKL", "DAC1L", "DAC1L" },
  1079. { "SPKL", "DAC1R", "DAC1R" },
  1080. { "SPKL", "DAC2L", "DAC2L" },
  1081. { "SPKL", "DAC2R", "DAC2R" },
  1082. { "SPKR", "DAC1L", "DAC1L" },
  1083. { "SPKR", "DAC1R", "DAC1R" },
  1084. { "SPKR", "DAC2L", "DAC2L" },
  1085. { "SPKR", "DAC2R", "DAC2R" },
  1086. { "SPKL PGA", NULL, "SPKL" },
  1087. { "SPKR PGA", NULL, "SPKR" },
  1088. { "SPKDAT", NULL, "SPKL PGA" },
  1089. { "SPKDAT", NULL, "SPKR PGA" },
  1090. };
  1091. static bool wm8996_readable_register(struct device *dev, unsigned int reg)
  1092. {
  1093. /* Due to the sparseness of the register map the compiler
  1094. * output from an explicit switch statement ends up being much
  1095. * more efficient than a table.
  1096. */
  1097. switch (reg) {
  1098. case WM8996_SOFTWARE_RESET:
  1099. case WM8996_POWER_MANAGEMENT_1:
  1100. case WM8996_POWER_MANAGEMENT_2:
  1101. case WM8996_POWER_MANAGEMENT_3:
  1102. case WM8996_POWER_MANAGEMENT_4:
  1103. case WM8996_POWER_MANAGEMENT_5:
  1104. case WM8996_POWER_MANAGEMENT_6:
  1105. case WM8996_POWER_MANAGEMENT_7:
  1106. case WM8996_POWER_MANAGEMENT_8:
  1107. case WM8996_LEFT_LINE_INPUT_VOLUME:
  1108. case WM8996_RIGHT_LINE_INPUT_VOLUME:
  1109. case WM8996_LINE_INPUT_CONTROL:
  1110. case WM8996_DAC1_HPOUT1_VOLUME:
  1111. case WM8996_DAC2_HPOUT2_VOLUME:
  1112. case WM8996_DAC1_LEFT_VOLUME:
  1113. case WM8996_DAC1_RIGHT_VOLUME:
  1114. case WM8996_DAC2_LEFT_VOLUME:
  1115. case WM8996_DAC2_RIGHT_VOLUME:
  1116. case WM8996_OUTPUT1_LEFT_VOLUME:
  1117. case WM8996_OUTPUT1_RIGHT_VOLUME:
  1118. case WM8996_OUTPUT2_LEFT_VOLUME:
  1119. case WM8996_OUTPUT2_RIGHT_VOLUME:
  1120. case WM8996_MICBIAS_1:
  1121. case WM8996_MICBIAS_2:
  1122. case WM8996_LDO_1:
  1123. case WM8996_LDO_2:
  1124. case WM8996_ACCESSORY_DETECT_MODE_1:
  1125. case WM8996_ACCESSORY_DETECT_MODE_2:
  1126. case WM8996_HEADPHONE_DETECT_1:
  1127. case WM8996_HEADPHONE_DETECT_2:
  1128. case WM8996_MIC_DETECT_1:
  1129. case WM8996_MIC_DETECT_2:
  1130. case WM8996_MIC_DETECT_3:
  1131. case WM8996_CHARGE_PUMP_1:
  1132. case WM8996_CHARGE_PUMP_2:
  1133. case WM8996_DC_SERVO_1:
  1134. case WM8996_DC_SERVO_2:
  1135. case WM8996_DC_SERVO_3:
  1136. case WM8996_DC_SERVO_5:
  1137. case WM8996_DC_SERVO_6:
  1138. case WM8996_DC_SERVO_7:
  1139. case WM8996_DC_SERVO_READBACK_0:
  1140. case WM8996_ANALOGUE_HP_1:
  1141. case WM8996_ANALOGUE_HP_2:
  1142. case WM8996_CHIP_REVISION:
  1143. case WM8996_CONTROL_INTERFACE_1:
  1144. case WM8996_WRITE_SEQUENCER_CTRL_1:
  1145. case WM8996_WRITE_SEQUENCER_CTRL_2:
  1146. case WM8996_AIF_CLOCKING_1:
  1147. case WM8996_AIF_CLOCKING_2:
  1148. case WM8996_CLOCKING_1:
  1149. case WM8996_CLOCKING_2:
  1150. case WM8996_AIF_RATE:
  1151. case WM8996_FLL_CONTROL_1:
  1152. case WM8996_FLL_CONTROL_2:
  1153. case WM8996_FLL_CONTROL_3:
  1154. case WM8996_FLL_CONTROL_4:
  1155. case WM8996_FLL_CONTROL_5:
  1156. case WM8996_FLL_CONTROL_6:
  1157. case WM8996_FLL_EFS_1:
  1158. case WM8996_FLL_EFS_2:
  1159. case WM8996_AIF1_CONTROL:
  1160. case WM8996_AIF1_BCLK:
  1161. case WM8996_AIF1_TX_LRCLK_1:
  1162. case WM8996_AIF1_TX_LRCLK_2:
  1163. case WM8996_AIF1_RX_LRCLK_1:
  1164. case WM8996_AIF1_RX_LRCLK_2:
  1165. case WM8996_AIF1TX_DATA_CONFIGURATION_1:
  1166. case WM8996_AIF1TX_DATA_CONFIGURATION_2:
  1167. case WM8996_AIF1RX_DATA_CONFIGURATION:
  1168. case WM8996_AIF1TX_CHANNEL_0_CONFIGURATION:
  1169. case WM8996_AIF1TX_CHANNEL_1_CONFIGURATION:
  1170. case WM8996_AIF1TX_CHANNEL_2_CONFIGURATION:
  1171. case WM8996_AIF1TX_CHANNEL_3_CONFIGURATION:
  1172. case WM8996_AIF1TX_CHANNEL_4_CONFIGURATION:
  1173. case WM8996_AIF1TX_CHANNEL_5_CONFIGURATION:
  1174. case WM8996_AIF1RX_CHANNEL_0_CONFIGURATION:
  1175. case WM8996_AIF1RX_CHANNEL_1_CONFIGURATION:
  1176. case WM8996_AIF1RX_CHANNEL_2_CONFIGURATION:
  1177. case WM8996_AIF1RX_CHANNEL_3_CONFIGURATION:
  1178. case WM8996_AIF1RX_CHANNEL_4_CONFIGURATION:
  1179. case WM8996_AIF1RX_CHANNEL_5_CONFIGURATION:
  1180. case WM8996_AIF1RX_MONO_CONFIGURATION:
  1181. case WM8996_AIF1TX_TEST:
  1182. case WM8996_AIF2_CONTROL:
  1183. case WM8996_AIF2_BCLK:
  1184. case WM8996_AIF2_TX_LRCLK_1:
  1185. case WM8996_AIF2_TX_LRCLK_2:
  1186. case WM8996_AIF2_RX_LRCLK_1:
  1187. case WM8996_AIF2_RX_LRCLK_2:
  1188. case WM8996_AIF2TX_DATA_CONFIGURATION_1:
  1189. case WM8996_AIF2TX_DATA_CONFIGURATION_2:
  1190. case WM8996_AIF2RX_DATA_CONFIGURATION:
  1191. case WM8996_AIF2TX_CHANNEL_0_CONFIGURATION:
  1192. case WM8996_AIF2TX_CHANNEL_1_CONFIGURATION:
  1193. case WM8996_AIF2RX_CHANNEL_0_CONFIGURATION:
  1194. case WM8996_AIF2RX_CHANNEL_1_CONFIGURATION:
  1195. case WM8996_AIF2RX_MONO_CONFIGURATION:
  1196. case WM8996_AIF2TX_TEST:
  1197. case WM8996_DSP1_TX_LEFT_VOLUME:
  1198. case WM8996_DSP1_TX_RIGHT_VOLUME:
  1199. case WM8996_DSP1_RX_LEFT_VOLUME:
  1200. case WM8996_DSP1_RX_RIGHT_VOLUME:
  1201. case WM8996_DSP1_TX_FILTERS:
  1202. case WM8996_DSP1_RX_FILTERS_1:
  1203. case WM8996_DSP1_RX_FILTERS_2:
  1204. case WM8996_DSP1_DRC_1:
  1205. case WM8996_DSP1_DRC_2:
  1206. case WM8996_DSP1_DRC_3:
  1207. case WM8996_DSP1_DRC_4:
  1208. case WM8996_DSP1_DRC_5:
  1209. case WM8996_DSP1_RX_EQ_GAINS_1:
  1210. case WM8996_DSP1_RX_EQ_GAINS_2:
  1211. case WM8996_DSP1_RX_EQ_BAND_1_A:
  1212. case WM8996_DSP1_RX_EQ_BAND_1_B:
  1213. case WM8996_DSP1_RX_EQ_BAND_1_PG:
  1214. case WM8996_DSP1_RX_EQ_BAND_2_A:
  1215. case WM8996_DSP1_RX_EQ_BAND_2_B:
  1216. case WM8996_DSP1_RX_EQ_BAND_2_C:
  1217. case WM8996_DSP1_RX_EQ_BAND_2_PG:
  1218. case WM8996_DSP1_RX_EQ_BAND_3_A:
  1219. case WM8996_DSP1_RX_EQ_BAND_3_B:
  1220. case WM8996_DSP1_RX_EQ_BAND_3_C:
  1221. case WM8996_DSP1_RX_EQ_BAND_3_PG:
  1222. case WM8996_DSP1_RX_EQ_BAND_4_A:
  1223. case WM8996_DSP1_RX_EQ_BAND_4_B:
  1224. case WM8996_DSP1_RX_EQ_BAND_4_C:
  1225. case WM8996_DSP1_RX_EQ_BAND_4_PG:
  1226. case WM8996_DSP1_RX_EQ_BAND_5_A:
  1227. case WM8996_DSP1_RX_EQ_BAND_5_B:
  1228. case WM8996_DSP1_RX_EQ_BAND_5_PG:
  1229. case WM8996_DSP2_TX_LEFT_VOLUME:
  1230. case WM8996_DSP2_TX_RIGHT_VOLUME:
  1231. case WM8996_DSP2_RX_LEFT_VOLUME:
  1232. case WM8996_DSP2_RX_RIGHT_VOLUME:
  1233. case WM8996_DSP2_TX_FILTERS:
  1234. case WM8996_DSP2_RX_FILTERS_1:
  1235. case WM8996_DSP2_RX_FILTERS_2:
  1236. case WM8996_DSP2_DRC_1:
  1237. case WM8996_DSP2_DRC_2:
  1238. case WM8996_DSP2_DRC_3:
  1239. case WM8996_DSP2_DRC_4:
  1240. case WM8996_DSP2_DRC_5:
  1241. case WM8996_DSP2_RX_EQ_GAINS_1:
  1242. case WM8996_DSP2_RX_EQ_GAINS_2:
  1243. case WM8996_DSP2_RX_EQ_BAND_1_A:
  1244. case WM8996_DSP2_RX_EQ_BAND_1_B:
  1245. case WM8996_DSP2_RX_EQ_BAND_1_PG:
  1246. case WM8996_DSP2_RX_EQ_BAND_2_A:
  1247. case WM8996_DSP2_RX_EQ_BAND_2_B:
  1248. case WM8996_DSP2_RX_EQ_BAND_2_C:
  1249. case WM8996_DSP2_RX_EQ_BAND_2_PG:
  1250. case WM8996_DSP2_RX_EQ_BAND_3_A:
  1251. case WM8996_DSP2_RX_EQ_BAND_3_B:
  1252. case WM8996_DSP2_RX_EQ_BAND_3_C:
  1253. case WM8996_DSP2_RX_EQ_BAND_3_PG:
  1254. case WM8996_DSP2_RX_EQ_BAND_4_A:
  1255. case WM8996_DSP2_RX_EQ_BAND_4_B:
  1256. case WM8996_DSP2_RX_EQ_BAND_4_C:
  1257. case WM8996_DSP2_RX_EQ_BAND_4_PG:
  1258. case WM8996_DSP2_RX_EQ_BAND_5_A:
  1259. case WM8996_DSP2_RX_EQ_BAND_5_B:
  1260. case WM8996_DSP2_RX_EQ_BAND_5_PG:
  1261. case WM8996_DAC1_MIXER_VOLUMES:
  1262. case WM8996_DAC1_LEFT_MIXER_ROUTING:
  1263. case WM8996_DAC1_RIGHT_MIXER_ROUTING:
  1264. case WM8996_DAC2_MIXER_VOLUMES:
  1265. case WM8996_DAC2_LEFT_MIXER_ROUTING:
  1266. case WM8996_DAC2_RIGHT_MIXER_ROUTING:
  1267. case WM8996_DSP1_TX_LEFT_MIXER_ROUTING:
  1268. case WM8996_DSP1_TX_RIGHT_MIXER_ROUTING:
  1269. case WM8996_DSP2_TX_LEFT_MIXER_ROUTING:
  1270. case WM8996_DSP2_TX_RIGHT_MIXER_ROUTING:
  1271. case WM8996_DSP_TX_MIXER_SELECT:
  1272. case WM8996_DAC_SOFTMUTE:
  1273. case WM8996_OVERSAMPLING:
  1274. case WM8996_SIDETONE:
  1275. case WM8996_GPIO_1:
  1276. case WM8996_GPIO_2:
  1277. case WM8996_GPIO_3:
  1278. case WM8996_GPIO_4:
  1279. case WM8996_GPIO_5:
  1280. case WM8996_PULL_CONTROL_1:
  1281. case WM8996_PULL_CONTROL_2:
  1282. case WM8996_INTERRUPT_STATUS_1:
  1283. case WM8996_INTERRUPT_STATUS_2:
  1284. case WM8996_INTERRUPT_RAW_STATUS_2:
  1285. case WM8996_INTERRUPT_STATUS_1_MASK:
  1286. case WM8996_INTERRUPT_STATUS_2_MASK:
  1287. case WM8996_INTERRUPT_CONTROL:
  1288. case WM8996_LEFT_PDM_SPEAKER:
  1289. case WM8996_RIGHT_PDM_SPEAKER:
  1290. case WM8996_PDM_SPEAKER_MUTE_SEQUENCE:
  1291. case WM8996_PDM_SPEAKER_VOLUME:
  1292. return 1;
  1293. default:
  1294. return 0;
  1295. }
  1296. }
  1297. static bool wm8996_volatile_register(struct device *dev, unsigned int reg)
  1298. {
  1299. switch (reg) {
  1300. case WM8996_SOFTWARE_RESET:
  1301. case WM8996_CHIP_REVISION:
  1302. case WM8996_LDO_1:
  1303. case WM8996_LDO_2:
  1304. case WM8996_INTERRUPT_STATUS_1:
  1305. case WM8996_INTERRUPT_STATUS_2:
  1306. case WM8996_INTERRUPT_RAW_STATUS_2:
  1307. case WM8996_DC_SERVO_READBACK_0:
  1308. case WM8996_DC_SERVO_2:
  1309. case WM8996_DC_SERVO_6:
  1310. case WM8996_DC_SERVO_7:
  1311. case WM8996_FLL_CONTROL_6:
  1312. case WM8996_MIC_DETECT_3:
  1313. case WM8996_HEADPHONE_DETECT_1:
  1314. case WM8996_HEADPHONE_DETECT_2:
  1315. return 1;
  1316. default:
  1317. return 0;
  1318. }
  1319. }
  1320. static const int bclk_divs[] = {
  1321. 1, 2, 3, 4, 6, 8, 12, 16, 24, 32, 48, 64, 96
  1322. };
  1323. static void wm8996_update_bclk(struct snd_soc_codec *codec)
  1324. {
  1325. struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec);
  1326. int aif, best, cur_val, bclk_rate, bclk_reg, i;
  1327. /* Don't bother if we're in a low frequency idle mode that
  1328. * can't support audio.
  1329. */
  1330. if (wm8996->sysclk < 64000)
  1331. return;
  1332. for (aif = 0; aif < WM8996_AIFS; aif++) {
  1333. switch (aif) {
  1334. case 0:
  1335. bclk_reg = WM8996_AIF1_BCLK;
  1336. break;
  1337. case 1:
  1338. bclk_reg = WM8996_AIF2_BCLK;
  1339. break;
  1340. }
  1341. bclk_rate = wm8996->bclk_rate[aif];
  1342. /* Pick a divisor for BCLK as close as we can get to ideal */
  1343. best = 0;
  1344. for (i = 0; i < ARRAY_SIZE(bclk_divs); i++) {
  1345. cur_val = (wm8996->sysclk / bclk_divs[i]) - bclk_rate;
  1346. if (cur_val < 0) /* BCLK table is sorted */
  1347. break;
  1348. best = i;
  1349. }
  1350. bclk_rate = wm8996->sysclk / bclk_divs[best];
  1351. dev_dbg(codec->dev, "Using BCLK_DIV %d for actual BCLK %dHz\n",
  1352. bclk_divs[best], bclk_rate);
  1353. snd_soc_update_bits(codec, bclk_reg,
  1354. WM8996_AIF1_BCLK_DIV_MASK, best);
  1355. }
  1356. }
  1357. static int wm8996_set_bias_level(struct snd_soc_codec *codec,
  1358. enum snd_soc_bias_level level)
  1359. {
  1360. struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec);
  1361. int ret;
  1362. switch (level) {
  1363. case SND_SOC_BIAS_ON:
  1364. break;
  1365. case SND_SOC_BIAS_PREPARE:
  1366. /* Put the MICBIASes into regulating mode */
  1367. snd_soc_update_bits(codec, WM8996_MICBIAS_1,
  1368. WM8996_MICB1_MODE, 0);
  1369. snd_soc_update_bits(codec, WM8996_MICBIAS_2,
  1370. WM8996_MICB2_MODE, 0);
  1371. break;
  1372. case SND_SOC_BIAS_STANDBY:
  1373. if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
  1374. ret = regulator_bulk_enable(ARRAY_SIZE(wm8996->supplies),
  1375. wm8996->supplies);
  1376. if (ret != 0) {
  1377. dev_err(codec->dev,
  1378. "Failed to enable supplies: %d\n",
  1379. ret);
  1380. return ret;
  1381. }
  1382. if (wm8996->pdata.ldo_ena >= 0) {
  1383. gpio_set_value_cansleep(wm8996->pdata.ldo_ena,
  1384. 1);
  1385. msleep(5);
  1386. }
  1387. regcache_cache_only(wm8996->regmap, false);
  1388. regcache_sync(wm8996->regmap);
  1389. }
  1390. /* Bypass the MICBIASes for lowest power */
  1391. snd_soc_update_bits(codec, WM8996_MICBIAS_1,
  1392. WM8996_MICB1_MODE, WM8996_MICB1_MODE);
  1393. snd_soc_update_bits(codec, WM8996_MICBIAS_2,
  1394. WM8996_MICB2_MODE, WM8996_MICB2_MODE);
  1395. break;
  1396. case SND_SOC_BIAS_OFF:
  1397. regcache_cache_only(wm8996->regmap, true);
  1398. if (wm8996->pdata.ldo_ena >= 0) {
  1399. gpio_set_value_cansleep(wm8996->pdata.ldo_ena, 0);
  1400. regcache_cache_only(wm8996->regmap, true);
  1401. }
  1402. regulator_bulk_disable(ARRAY_SIZE(wm8996->supplies),
  1403. wm8996->supplies);
  1404. break;
  1405. }
  1406. return 0;
  1407. }
  1408. static int wm8996_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
  1409. {
  1410. struct snd_soc_codec *codec = dai->codec;
  1411. int aifctrl = 0;
  1412. int bclk = 0;
  1413. int lrclk_tx = 0;
  1414. int lrclk_rx = 0;
  1415. int aifctrl_reg, bclk_reg, lrclk_tx_reg, lrclk_rx_reg;
  1416. switch (dai->id) {
  1417. case 0:
  1418. aifctrl_reg = WM8996_AIF1_CONTROL;
  1419. bclk_reg = WM8996_AIF1_BCLK;
  1420. lrclk_tx_reg = WM8996_AIF1_TX_LRCLK_2;
  1421. lrclk_rx_reg = WM8996_AIF1_RX_LRCLK_2;
  1422. break;
  1423. case 1:
  1424. aifctrl_reg = WM8996_AIF2_CONTROL;
  1425. bclk_reg = WM8996_AIF2_BCLK;
  1426. lrclk_tx_reg = WM8996_AIF2_TX_LRCLK_2;
  1427. lrclk_rx_reg = WM8996_AIF2_RX_LRCLK_2;
  1428. break;
  1429. default:
  1430. WARN(1, "Invalid dai id %d\n", dai->id);
  1431. return -EINVAL;
  1432. }
  1433. switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
  1434. case SND_SOC_DAIFMT_NB_NF:
  1435. break;
  1436. case SND_SOC_DAIFMT_IB_NF:
  1437. bclk |= WM8996_AIF1_BCLK_INV;
  1438. break;
  1439. case SND_SOC_DAIFMT_NB_IF:
  1440. lrclk_tx |= WM8996_AIF1TX_LRCLK_INV;
  1441. lrclk_rx |= WM8996_AIF1RX_LRCLK_INV;
  1442. break;
  1443. case SND_SOC_DAIFMT_IB_IF:
  1444. bclk |= WM8996_AIF1_BCLK_INV;
  1445. lrclk_tx |= WM8996_AIF1TX_LRCLK_INV;
  1446. lrclk_rx |= WM8996_AIF1RX_LRCLK_INV;
  1447. break;
  1448. }
  1449. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  1450. case SND_SOC_DAIFMT_CBS_CFS:
  1451. break;
  1452. case SND_SOC_DAIFMT_CBS_CFM:
  1453. lrclk_tx |= WM8996_AIF1TX_LRCLK_MSTR;
  1454. lrclk_rx |= WM8996_AIF1RX_LRCLK_MSTR;
  1455. break;
  1456. case SND_SOC_DAIFMT_CBM_CFS:
  1457. bclk |= WM8996_AIF1_BCLK_MSTR;
  1458. break;
  1459. case SND_SOC_DAIFMT_CBM_CFM:
  1460. bclk |= WM8996_AIF1_BCLK_MSTR;
  1461. lrclk_tx |= WM8996_AIF1TX_LRCLK_MSTR;
  1462. lrclk_rx |= WM8996_AIF1RX_LRCLK_MSTR;
  1463. break;
  1464. default:
  1465. return -EINVAL;
  1466. }
  1467. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  1468. case SND_SOC_DAIFMT_DSP_A:
  1469. break;
  1470. case SND_SOC_DAIFMT_DSP_B:
  1471. aifctrl |= 1;
  1472. break;
  1473. case SND_SOC_DAIFMT_I2S:
  1474. aifctrl |= 2;
  1475. break;
  1476. case SND_SOC_DAIFMT_LEFT_J:
  1477. aifctrl |= 3;
  1478. break;
  1479. default:
  1480. return -EINVAL;
  1481. }
  1482. snd_soc_update_bits(codec, aifctrl_reg, WM8996_AIF1_FMT_MASK, aifctrl);
  1483. snd_soc_update_bits(codec, bclk_reg,
  1484. WM8996_AIF1_BCLK_INV | WM8996_AIF1_BCLK_MSTR,
  1485. bclk);
  1486. snd_soc_update_bits(codec, lrclk_tx_reg,
  1487. WM8996_AIF1TX_LRCLK_INV |
  1488. WM8996_AIF1TX_LRCLK_MSTR,
  1489. lrclk_tx);
  1490. snd_soc_update_bits(codec, lrclk_rx_reg,
  1491. WM8996_AIF1RX_LRCLK_INV |
  1492. WM8996_AIF1RX_LRCLK_MSTR,
  1493. lrclk_rx);
  1494. return 0;
  1495. }
  1496. static const int dsp_divs[] = {
  1497. 48000, 32000, 16000, 8000
  1498. };
  1499. static int wm8996_hw_params(struct snd_pcm_substream *substream,
  1500. struct snd_pcm_hw_params *params,
  1501. struct snd_soc_dai *dai)
  1502. {
  1503. struct snd_soc_codec *codec = dai->codec;
  1504. struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec);
  1505. int bits, i, bclk_rate, best;
  1506. int aifdata = 0;
  1507. int lrclk = 0;
  1508. int dsp = 0;
  1509. int aifdata_reg, lrclk_reg, dsp_shift;
  1510. switch (dai->id) {
  1511. case 0:
  1512. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK ||
  1513. (snd_soc_read(codec, WM8996_GPIO_1)) & WM8996_GP1_FN_MASK) {
  1514. aifdata_reg = WM8996_AIF1RX_DATA_CONFIGURATION;
  1515. lrclk_reg = WM8996_AIF1_RX_LRCLK_1;
  1516. } else {
  1517. aifdata_reg = WM8996_AIF1TX_DATA_CONFIGURATION_1;
  1518. lrclk_reg = WM8996_AIF1_TX_LRCLK_1;
  1519. }
  1520. dsp_shift = 0;
  1521. break;
  1522. case 1:
  1523. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK ||
  1524. (snd_soc_read(codec, WM8996_GPIO_2)) & WM8996_GP2_FN_MASK) {
  1525. aifdata_reg = WM8996_AIF2RX_DATA_CONFIGURATION;
  1526. lrclk_reg = WM8996_AIF2_RX_LRCLK_1;
  1527. } else {
  1528. aifdata_reg = WM8996_AIF2TX_DATA_CONFIGURATION_1;
  1529. lrclk_reg = WM8996_AIF2_TX_LRCLK_1;
  1530. }
  1531. dsp_shift = WM8996_DSP2_DIV_SHIFT;
  1532. break;
  1533. default:
  1534. WARN(1, "Invalid dai id %d\n", dai->id);
  1535. return -EINVAL;
  1536. }
  1537. bclk_rate = snd_soc_params_to_bclk(params);
  1538. if (bclk_rate < 0) {
  1539. dev_err(codec->dev, "Unsupported BCLK rate: %d\n", bclk_rate);
  1540. return bclk_rate;
  1541. }
  1542. wm8996->bclk_rate[dai->id] = bclk_rate;
  1543. wm8996->rx_rate[dai->id] = params_rate(params);
  1544. /* Needs looking at for TDM */
  1545. bits = params_width(params);
  1546. if (bits < 0)
  1547. return bits;
  1548. aifdata |= (bits << WM8996_AIF1TX_WL_SHIFT) | bits;
  1549. best = 0;
  1550. for (i = 0; i < ARRAY_SIZE(dsp_divs); i++) {
  1551. if (abs(dsp_divs[i] - params_rate(params)) <
  1552. abs(dsp_divs[best] - params_rate(params)))
  1553. best = i;
  1554. }
  1555. dsp |= i << dsp_shift;
  1556. wm8996_update_bclk(codec);
  1557. lrclk = bclk_rate / params_rate(params);
  1558. dev_dbg(dai->dev, "Using LRCLK rate %d for actual LRCLK %dHz\n",
  1559. lrclk, bclk_rate / lrclk);
  1560. snd_soc_update_bits(codec, aifdata_reg,
  1561. WM8996_AIF1TX_WL_MASK |
  1562. WM8996_AIF1TX_SLOT_LEN_MASK,
  1563. aifdata);
  1564. snd_soc_update_bits(codec, lrclk_reg, WM8996_AIF1RX_RATE_MASK,
  1565. lrclk);
  1566. snd_soc_update_bits(codec, WM8996_AIF_CLOCKING_2,
  1567. WM8996_DSP1_DIV_MASK << dsp_shift, dsp);
  1568. return 0;
  1569. }
  1570. static int wm8996_set_sysclk(struct snd_soc_dai *dai,
  1571. int clk_id, unsigned int freq, int dir)
  1572. {
  1573. struct snd_soc_codec *codec = dai->codec;
  1574. struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec);
  1575. int lfclk = 0;
  1576. int ratediv = 0;
  1577. int sync = WM8996_REG_SYNC;
  1578. int src;
  1579. int old;
  1580. if (freq == wm8996->sysclk && clk_id == wm8996->sysclk_src)
  1581. return 0;
  1582. /* Disable SYSCLK while we reconfigure */
  1583. old = snd_soc_read(codec, WM8996_AIF_CLOCKING_1) & WM8996_SYSCLK_ENA;
  1584. snd_soc_update_bits(codec, WM8996_AIF_CLOCKING_1,
  1585. WM8996_SYSCLK_ENA, 0);
  1586. switch (clk_id) {
  1587. case WM8996_SYSCLK_MCLK1:
  1588. wm8996->sysclk = freq;
  1589. src = 0;
  1590. break;
  1591. case WM8996_SYSCLK_MCLK2:
  1592. wm8996->sysclk = freq;
  1593. src = 1;
  1594. break;
  1595. case WM8996_SYSCLK_FLL:
  1596. wm8996->sysclk = freq;
  1597. src = 2;
  1598. break;
  1599. default:
  1600. dev_err(codec->dev, "Unsupported clock source %d\n", clk_id);
  1601. return -EINVAL;
  1602. }
  1603. switch (wm8996->sysclk) {
  1604. case 5644800:
  1605. case 6144000:
  1606. snd_soc_update_bits(codec, WM8996_AIF_RATE,
  1607. WM8996_SYSCLK_RATE, 0);
  1608. break;
  1609. case 22579200:
  1610. case 24576000:
  1611. ratediv = WM8996_SYSCLK_DIV;
  1612. wm8996->sysclk /= 2;
  1613. case 11289600:
  1614. case 12288000:
  1615. snd_soc_update_bits(codec, WM8996_AIF_RATE,
  1616. WM8996_SYSCLK_RATE, WM8996_SYSCLK_RATE);
  1617. break;
  1618. case 32000:
  1619. case 32768:
  1620. lfclk = WM8996_LFCLK_ENA;
  1621. sync = 0;
  1622. break;
  1623. default:
  1624. dev_warn(codec->dev, "Unsupported clock rate %dHz\n",
  1625. wm8996->sysclk);
  1626. return -EINVAL;
  1627. }
  1628. wm8996_update_bclk(codec);
  1629. snd_soc_update_bits(codec, WM8996_AIF_CLOCKING_1,
  1630. WM8996_SYSCLK_SRC_MASK | WM8996_SYSCLK_DIV_MASK,
  1631. src << WM8996_SYSCLK_SRC_SHIFT | ratediv);
  1632. snd_soc_update_bits(codec, WM8996_CLOCKING_1, WM8996_LFCLK_ENA, lfclk);
  1633. snd_soc_update_bits(codec, WM8996_CONTROL_INTERFACE_1,
  1634. WM8996_REG_SYNC, sync);
  1635. snd_soc_update_bits(codec, WM8996_AIF_CLOCKING_1,
  1636. WM8996_SYSCLK_ENA, old);
  1637. wm8996->sysclk_src = clk_id;
  1638. return 0;
  1639. }
  1640. struct _fll_div {
  1641. u16 fll_fratio;
  1642. u16 fll_outdiv;
  1643. u16 fll_refclk_div;
  1644. u16 fll_loop_gain;
  1645. u16 fll_ref_freq;
  1646. u16 n;
  1647. u16 theta;
  1648. u16 lambda;
  1649. };
  1650. static struct {
  1651. unsigned int min;
  1652. unsigned int max;
  1653. u16 fll_fratio;
  1654. int ratio;
  1655. } fll_fratios[] = {
  1656. { 0, 64000, 4, 16 },
  1657. { 64000, 128000, 3, 8 },
  1658. { 128000, 256000, 2, 4 },
  1659. { 256000, 1000000, 1, 2 },
  1660. { 1000000, 13500000, 0, 1 },
  1661. };
  1662. static int fll_factors(struct _fll_div *fll_div, unsigned int Fref,
  1663. unsigned int Fout)
  1664. {
  1665. unsigned int target;
  1666. unsigned int div;
  1667. unsigned int fratio, gcd_fll;
  1668. int i;
  1669. /* Fref must be <=13.5MHz */
  1670. div = 1;
  1671. fll_div->fll_refclk_div = 0;
  1672. while ((Fref / div) > 13500000) {
  1673. div *= 2;
  1674. fll_div->fll_refclk_div++;
  1675. if (div > 8) {
  1676. pr_err("Can't scale %dMHz input down to <=13.5MHz\n",
  1677. Fref);
  1678. return -EINVAL;
  1679. }
  1680. }
  1681. pr_debug("FLL Fref=%u Fout=%u\n", Fref, Fout);
  1682. /* Apply the division for our remaining calculations */
  1683. Fref /= div;
  1684. if (Fref >= 3000000)
  1685. fll_div->fll_loop_gain = 5;
  1686. else
  1687. fll_div->fll_loop_gain = 0;
  1688. if (Fref >= 48000)
  1689. fll_div->fll_ref_freq = 0;
  1690. else
  1691. fll_div->fll_ref_freq = 1;
  1692. /* Fvco should be 90-100MHz; don't check the upper bound */
  1693. div = 2;
  1694. while (Fout * div < 90000000) {
  1695. div++;
  1696. if (div > 64) {
  1697. pr_err("Unable to find FLL_OUTDIV for Fout=%uHz\n",
  1698. Fout);
  1699. return -EINVAL;
  1700. }
  1701. }
  1702. target = Fout * div;
  1703. fll_div->fll_outdiv = div - 1;
  1704. pr_debug("FLL Fvco=%dHz\n", target);
  1705. /* Find an appropraite FLL_FRATIO and factor it out of the target */
  1706. for (i = 0; i < ARRAY_SIZE(fll_fratios); i++) {
  1707. if (fll_fratios[i].min <= Fref && Fref <= fll_fratios[i].max) {
  1708. fll_div->fll_fratio = fll_fratios[i].fll_fratio;
  1709. fratio = fll_fratios[i].ratio;
  1710. break;
  1711. }
  1712. }
  1713. if (i == ARRAY_SIZE(fll_fratios)) {
  1714. pr_err("Unable to find FLL_FRATIO for Fref=%uHz\n", Fref);
  1715. return -EINVAL;
  1716. }
  1717. fll_div->n = target / (fratio * Fref);
  1718. if (target % Fref == 0) {
  1719. fll_div->theta = 0;
  1720. fll_div->lambda = 0;
  1721. } else {
  1722. gcd_fll = gcd(target, fratio * Fref);
  1723. fll_div->theta = (target - (fll_div->n * fratio * Fref))
  1724. / gcd_fll;
  1725. fll_div->lambda = (fratio * Fref) / gcd_fll;
  1726. }
  1727. pr_debug("FLL N=%x THETA=%x LAMBDA=%x\n",
  1728. fll_div->n, fll_div->theta, fll_div->lambda);
  1729. pr_debug("FLL_FRATIO=%x FLL_OUTDIV=%x FLL_REFCLK_DIV=%x\n",
  1730. fll_div->fll_fratio, fll_div->fll_outdiv,
  1731. fll_div->fll_refclk_div);
  1732. return 0;
  1733. }
  1734. static int wm8996_set_fll(struct snd_soc_codec *codec, int fll_id, int source,
  1735. unsigned int Fref, unsigned int Fout)
  1736. {
  1737. struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec);
  1738. struct i2c_client *i2c = to_i2c_client(codec->dev);
  1739. struct _fll_div fll_div;
  1740. unsigned long timeout, time_left;
  1741. int ret, reg, retry;
  1742. /* Any change? */
  1743. if (source == wm8996->fll_src && Fref == wm8996->fll_fref &&
  1744. Fout == wm8996->fll_fout)
  1745. return 0;
  1746. if (Fout == 0) {
  1747. dev_dbg(codec->dev, "FLL disabled\n");
  1748. wm8996->fll_fref = 0;
  1749. wm8996->fll_fout = 0;
  1750. snd_soc_update_bits(codec, WM8996_FLL_CONTROL_1,
  1751. WM8996_FLL_ENA, 0);
  1752. wm8996_bg_disable(codec);
  1753. return 0;
  1754. }
  1755. ret = fll_factors(&fll_div, Fref, Fout);
  1756. if (ret != 0)
  1757. return ret;
  1758. switch (source) {
  1759. case WM8996_FLL_MCLK1:
  1760. reg = 0;
  1761. break;
  1762. case WM8996_FLL_MCLK2:
  1763. reg = 1;
  1764. break;
  1765. case WM8996_FLL_DACLRCLK1:
  1766. reg = 2;
  1767. break;
  1768. case WM8996_FLL_BCLK1:
  1769. reg = 3;
  1770. break;
  1771. default:
  1772. dev_err(codec->dev, "Unknown FLL source %d\n", ret);
  1773. return -EINVAL;
  1774. }
  1775. reg |= fll_div.fll_refclk_div << WM8996_FLL_REFCLK_DIV_SHIFT;
  1776. reg |= fll_div.fll_ref_freq << WM8996_FLL_REF_FREQ_SHIFT;
  1777. snd_soc_update_bits(codec, WM8996_FLL_CONTROL_5,
  1778. WM8996_FLL_REFCLK_DIV_MASK | WM8996_FLL_REF_FREQ |
  1779. WM8996_FLL_REFCLK_SRC_MASK, reg);
  1780. reg = 0;
  1781. if (fll_div.theta || fll_div.lambda)
  1782. reg |= WM8996_FLL_EFS_ENA | (3 << WM8996_FLL_LFSR_SEL_SHIFT);
  1783. else
  1784. reg |= 1 << WM8996_FLL_LFSR_SEL_SHIFT;
  1785. snd_soc_write(codec, WM8996_FLL_EFS_2, reg);
  1786. snd_soc_update_bits(codec, WM8996_FLL_CONTROL_2,
  1787. WM8996_FLL_OUTDIV_MASK |
  1788. WM8996_FLL_FRATIO_MASK,
  1789. (fll_div.fll_outdiv << WM8996_FLL_OUTDIV_SHIFT) |
  1790. (fll_div.fll_fratio));
  1791. snd_soc_write(codec, WM8996_FLL_CONTROL_3, fll_div.theta);
  1792. snd_soc_update_bits(codec, WM8996_FLL_CONTROL_4,
  1793. WM8996_FLL_N_MASK | WM8996_FLL_LOOP_GAIN_MASK,
  1794. (fll_div.n << WM8996_FLL_N_SHIFT) |
  1795. fll_div.fll_loop_gain);
  1796. snd_soc_write(codec, WM8996_FLL_EFS_1, fll_div.lambda);
  1797. /* Enable the bandgap if it's not already enabled */
  1798. ret = snd_soc_read(codec, WM8996_FLL_CONTROL_1);
  1799. if (!(ret & WM8996_FLL_ENA))
  1800. wm8996_bg_enable(codec);
  1801. /* Clear any pending completions (eg, from failed startups) */
  1802. try_wait_for_completion(&wm8996->fll_lock);
  1803. snd_soc_update_bits(codec, WM8996_FLL_CONTROL_1,
  1804. WM8996_FLL_ENA, WM8996_FLL_ENA);
  1805. /* The FLL supports live reconfiguration - kick that in case we were
  1806. * already enabled.
  1807. */
  1808. snd_soc_write(codec, WM8996_FLL_CONTROL_6, WM8996_FLL_SWITCH_CLK);
  1809. /* Wait for the FLL to lock, using the interrupt if possible */
  1810. if (Fref > 1000000)
  1811. timeout = usecs_to_jiffies(300);
  1812. else
  1813. timeout = msecs_to_jiffies(2);
  1814. /* Allow substantially longer if we've actually got the IRQ, poll
  1815. * at a slightly higher rate if we don't.
  1816. */
  1817. if (i2c->irq)
  1818. timeout *= 10;
  1819. else
  1820. /* ensure timeout of atleast 1 jiffies */
  1821. timeout = timeout/2 ? : 1;
  1822. for (retry = 0; retry < 10; retry++) {
  1823. time_left = wait_for_completion_timeout(&wm8996->fll_lock,
  1824. timeout);
  1825. if (time_left != 0) {
  1826. WARN_ON(!i2c->irq);
  1827. ret = 1;
  1828. break;
  1829. }
  1830. ret = snd_soc_read(codec, WM8996_INTERRUPT_RAW_STATUS_2);
  1831. if (ret & WM8996_FLL_LOCK_STS)
  1832. break;
  1833. }
  1834. if (retry == 10) {
  1835. dev_err(codec->dev, "Timed out waiting for FLL\n");
  1836. ret = -ETIMEDOUT;
  1837. }
  1838. dev_dbg(codec->dev, "FLL configured for %dHz->%dHz\n", Fref, Fout);
  1839. wm8996->fll_fref = Fref;
  1840. wm8996->fll_fout = Fout;
  1841. wm8996->fll_src = source;
  1842. return ret;
  1843. }
  1844. #ifdef CONFIG_GPIOLIB
  1845. static void wm8996_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
  1846. {
  1847. struct wm8996_priv *wm8996 = gpiochip_get_data(chip);
  1848. regmap_update_bits(wm8996->regmap, WM8996_GPIO_1 + offset,
  1849. WM8996_GP1_LVL, !!value << WM8996_GP1_LVL_SHIFT);
  1850. }
  1851. static int wm8996_gpio_direction_out(struct gpio_chip *chip,
  1852. unsigned offset, int value)
  1853. {
  1854. struct wm8996_priv *wm8996 = gpiochip_get_data(chip);
  1855. int val;
  1856. val = (1 << WM8996_GP1_FN_SHIFT) | (!!value << WM8996_GP1_LVL_SHIFT);
  1857. return regmap_update_bits(wm8996->regmap, WM8996_GPIO_1 + offset,
  1858. WM8996_GP1_FN_MASK | WM8996_GP1_DIR |
  1859. WM8996_GP1_LVL, val);
  1860. }
  1861. static int wm8996_gpio_get(struct gpio_chip *chip, unsigned offset)
  1862. {
  1863. struct wm8996_priv *wm8996 = gpiochip_get_data(chip);
  1864. unsigned int reg;
  1865. int ret;
  1866. ret = regmap_read(wm8996->regmap, WM8996_GPIO_1 + offset, &reg);
  1867. if (ret < 0)
  1868. return ret;
  1869. return (reg & WM8996_GP1_LVL) != 0;
  1870. }
  1871. static int wm8996_gpio_direction_in(struct gpio_chip *chip, unsigned offset)
  1872. {
  1873. struct wm8996_priv *wm8996 = gpiochip_get_data(chip);
  1874. return regmap_update_bits(wm8996->regmap, WM8996_GPIO_1 + offset,
  1875. WM8996_GP1_FN_MASK | WM8996_GP1_DIR,
  1876. (1 << WM8996_GP1_FN_SHIFT) |
  1877. (1 << WM8996_GP1_DIR_SHIFT));
  1878. }
  1879. static const struct gpio_chip wm8996_template_chip = {
  1880. .label = "wm8996",
  1881. .owner = THIS_MODULE,
  1882. .direction_output = wm8996_gpio_direction_out,
  1883. .set = wm8996_gpio_set,
  1884. .direction_input = wm8996_gpio_direction_in,
  1885. .get = wm8996_gpio_get,
  1886. .can_sleep = 1,
  1887. };
  1888. static void wm8996_init_gpio(struct wm8996_priv *wm8996)
  1889. {
  1890. int ret;
  1891. wm8996->gpio_chip = wm8996_template_chip;
  1892. wm8996->gpio_chip.ngpio = 5;
  1893. wm8996->gpio_chip.parent = wm8996->dev;
  1894. if (wm8996->pdata.gpio_base)
  1895. wm8996->gpio_chip.base = wm8996->pdata.gpio_base;
  1896. else
  1897. wm8996->gpio_chip.base = -1;
  1898. ret = gpiochip_add_data(&wm8996->gpio_chip, wm8996);
  1899. if (ret != 0)
  1900. dev_err(wm8996->dev, "Failed to add GPIOs: %d\n", ret);
  1901. }
  1902. static void wm8996_free_gpio(struct wm8996_priv *wm8996)
  1903. {
  1904. gpiochip_remove(&wm8996->gpio_chip);
  1905. }
  1906. #else
  1907. static void wm8996_init_gpio(struct wm8996_priv *wm8996)
  1908. {
  1909. }
  1910. static void wm8996_free_gpio(struct wm8996_priv *wm8996)
  1911. {
  1912. }
  1913. #endif
  1914. /**
  1915. * wm8996_detect - Enable default WM8996 jack detection
  1916. *
  1917. * The WM8996 has advanced accessory detection support for headsets.
  1918. * This function provides a default implementation which integrates
  1919. * the majority of this functionality with minimal user configuration.
  1920. *
  1921. * This will detect headset, headphone and short circuit button and
  1922. * will also detect inverted microphone ground connections and update
  1923. * the polarity of the connections.
  1924. */
  1925. int wm8996_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack,
  1926. wm8996_polarity_fn polarity_cb)
  1927. {
  1928. struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec);
  1929. struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
  1930. wm8996->jack = jack;
  1931. wm8996->detecting = true;
  1932. wm8996->polarity_cb = polarity_cb;
  1933. wm8996->jack_flips = 0;
  1934. if (wm8996->polarity_cb)
  1935. wm8996->polarity_cb(codec, 0);
  1936. /* Clear discarge to avoid noise during detection */
  1937. snd_soc_update_bits(codec, WM8996_MICBIAS_1,
  1938. WM8996_MICB1_DISCH, 0);
  1939. snd_soc_update_bits(codec, WM8996_MICBIAS_2,
  1940. WM8996_MICB2_DISCH, 0);
  1941. /* LDO2 powers the microphones, SYSCLK clocks detection */
  1942. snd_soc_dapm_mutex_lock(dapm);
  1943. snd_soc_dapm_force_enable_pin_unlocked(dapm, "LDO2");
  1944. snd_soc_dapm_force_enable_pin_unlocked(dapm, "SYSCLK");
  1945. snd_soc_dapm_mutex_unlock(dapm);
  1946. /* We start off just enabling microphone detection - even a
  1947. * plain headphone will trigger detection.
  1948. */
  1949. snd_soc_update_bits(codec, WM8996_MIC_DETECT_1,
  1950. WM8996_MICD_ENA, WM8996_MICD_ENA);
  1951. /* Slowest detection rate, gives debounce for initial detection */
  1952. snd_soc_update_bits(codec, WM8996_MIC_DETECT_1,
  1953. WM8996_MICD_RATE_MASK,
  1954. WM8996_MICD_RATE_MASK);
  1955. /* Enable interrupts and we're off */
  1956. snd_soc_update_bits(codec, WM8996_INTERRUPT_STATUS_2_MASK,
  1957. WM8996_IM_MICD_EINT | WM8996_HP_DONE_EINT, 0);
  1958. return 0;
  1959. }
  1960. EXPORT_SYMBOL_GPL(wm8996_detect);
  1961. static void wm8996_hpdet_irq(struct snd_soc_codec *codec)
  1962. {
  1963. struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
  1964. struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec);
  1965. int val, reg, report;
  1966. /* Assume headphone in error conditions; we need to report
  1967. * something or we stall our state machine.
  1968. */
  1969. report = SND_JACK_HEADPHONE;
  1970. reg = snd_soc_read(codec, WM8996_HEADPHONE_DETECT_2);
  1971. if (reg < 0) {
  1972. dev_err(codec->dev, "Failed to read HPDET status\n");
  1973. goto out;
  1974. }
  1975. if (!(reg & WM8996_HP_DONE)) {
  1976. dev_err(codec->dev, "Got HPDET IRQ but HPDET is busy\n");
  1977. goto out;
  1978. }
  1979. val = reg & WM8996_HP_LVL_MASK;
  1980. dev_dbg(codec->dev, "HPDET measured %d ohms\n", val);
  1981. /* If we've got high enough impedence then report as line,
  1982. * otherwise assume headphone.
  1983. */
  1984. if (val >= 126)
  1985. report = SND_JACK_LINEOUT;
  1986. else
  1987. report = SND_JACK_HEADPHONE;
  1988. out:
  1989. if (wm8996->jack_mic)
  1990. report |= SND_JACK_MICROPHONE;
  1991. snd_soc_jack_report(wm8996->jack, report,
  1992. SND_JACK_LINEOUT | SND_JACK_HEADSET);
  1993. wm8996->detecting = false;
  1994. /* If the output isn't running re-clamp it */
  1995. if (!(snd_soc_read(codec, WM8996_POWER_MANAGEMENT_1) &
  1996. (WM8996_HPOUT1L_ENA | WM8996_HPOUT1R_RMV_SHORT)))
  1997. snd_soc_update_bits(codec, WM8996_ANALOGUE_HP_1,
  1998. WM8996_HPOUT1L_RMV_SHORT |
  1999. WM8996_HPOUT1R_RMV_SHORT, 0);
  2000. /* Go back to looking at the microphone */
  2001. snd_soc_update_bits(codec, WM8996_ACCESSORY_DETECT_MODE_1,
  2002. WM8996_JD_MODE_MASK, 0);
  2003. snd_soc_update_bits(codec, WM8996_MIC_DETECT_1, WM8996_MICD_ENA,
  2004. WM8996_MICD_ENA);
  2005. snd_soc_dapm_disable_pin(dapm, "Bandgap");
  2006. snd_soc_dapm_sync(dapm);
  2007. }
  2008. static void wm8996_hpdet_start(struct snd_soc_codec *codec)
  2009. {
  2010. struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
  2011. /* Unclamp the output, we can't measure while we're shorting it */
  2012. snd_soc_update_bits(codec, WM8996_ANALOGUE_HP_1,
  2013. WM8996_HPOUT1L_RMV_SHORT |
  2014. WM8996_HPOUT1R_RMV_SHORT,
  2015. WM8996_HPOUT1L_RMV_SHORT |
  2016. WM8996_HPOUT1R_RMV_SHORT);
  2017. /* We need bandgap for HPDET */
  2018. snd_soc_dapm_force_enable_pin(dapm, "Bandgap");
  2019. snd_soc_dapm_sync(dapm);
  2020. /* Go into headphone detect left mode */
  2021. snd_soc_update_bits(codec, WM8996_MIC_DETECT_1, WM8996_MICD_ENA, 0);
  2022. snd_soc_update_bits(codec, WM8996_ACCESSORY_DETECT_MODE_1,
  2023. WM8996_JD_MODE_MASK, 1);
  2024. /* Trigger a measurement */
  2025. snd_soc_update_bits(codec, WM8996_HEADPHONE_DETECT_1,
  2026. WM8996_HP_POLL, WM8996_HP_POLL);
  2027. }
  2028. static void wm8996_report_headphone(struct snd_soc_codec *codec)
  2029. {
  2030. dev_dbg(codec->dev, "Headphone detected\n");
  2031. wm8996_hpdet_start(codec);
  2032. /* Increase the detection rate a bit for responsiveness. */
  2033. snd_soc_update_bits(codec, WM8996_MIC_DETECT_1,
  2034. WM8996_MICD_RATE_MASK |
  2035. WM8996_MICD_BIAS_STARTTIME_MASK,
  2036. 7 << WM8996_MICD_RATE_SHIFT |
  2037. 7 << WM8996_MICD_BIAS_STARTTIME_SHIFT);
  2038. }
  2039. static void wm8996_micd(struct snd_soc_codec *codec)
  2040. {
  2041. struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec);
  2042. int val, reg;
  2043. val = snd_soc_read(codec, WM8996_MIC_DETECT_3);
  2044. dev_dbg(codec->dev, "Microphone event: %x\n", val);
  2045. if (!(val & WM8996_MICD_VALID)) {
  2046. dev_warn(codec->dev, "Microphone detection state invalid\n");
  2047. return;
  2048. }
  2049. /* No accessory, reset everything and report removal */
  2050. if (!(val & WM8996_MICD_STS)) {
  2051. dev_dbg(codec->dev, "Jack removal detected\n");
  2052. wm8996->jack_mic = false;
  2053. wm8996->detecting = true;
  2054. wm8996->jack_flips = 0;
  2055. snd_soc_jack_report(wm8996->jack, 0,
  2056. SND_JACK_LINEOUT | SND_JACK_HEADSET |
  2057. SND_JACK_BTN_0);
  2058. snd_soc_update_bits(codec, WM8996_MIC_DETECT_1,
  2059. WM8996_MICD_RATE_MASK |
  2060. WM8996_MICD_BIAS_STARTTIME_MASK,
  2061. WM8996_MICD_RATE_MASK |
  2062. 9 << WM8996_MICD_BIAS_STARTTIME_SHIFT);
  2063. return;
  2064. }
  2065. /* If the measurement is very high we've got a microphone,
  2066. * either we just detected one or if we already reported then
  2067. * we've got a button release event.
  2068. */
  2069. if (val & 0x400) {
  2070. if (wm8996->detecting) {
  2071. dev_dbg(codec->dev, "Microphone detected\n");
  2072. wm8996->jack_mic = true;
  2073. wm8996_hpdet_start(codec);
  2074. /* Increase poll rate to give better responsiveness
  2075. * for buttons */
  2076. snd_soc_update_bits(codec, WM8996_MIC_DETECT_1,
  2077. WM8996_MICD_RATE_MASK |
  2078. WM8996_MICD_BIAS_STARTTIME_MASK,
  2079. 5 << WM8996_MICD_RATE_SHIFT |
  2080. 7 << WM8996_MICD_BIAS_STARTTIME_SHIFT);
  2081. } else {
  2082. dev_dbg(codec->dev, "Mic button up\n");
  2083. snd_soc_jack_report(wm8996->jack, 0, SND_JACK_BTN_0);
  2084. }
  2085. return;
  2086. }
  2087. /* If we detected a lower impedence during initial startup
  2088. * then we probably have the wrong polarity, flip it. Don't
  2089. * do this for the lowest impedences to speed up detection of
  2090. * plain headphones. If both polarities report a low
  2091. * impedence then give up and report headphones.
  2092. */
  2093. if (wm8996->detecting && (val & 0x3f0)) {
  2094. wm8996->jack_flips++;
  2095. if (wm8996->jack_flips > 1) {
  2096. wm8996_report_headphone(codec);
  2097. return;
  2098. }
  2099. reg = snd_soc_read(codec, WM8996_ACCESSORY_DETECT_MODE_2);
  2100. reg ^= WM8996_HPOUT1FB_SRC | WM8996_MICD_SRC |
  2101. WM8996_MICD_BIAS_SRC;
  2102. snd_soc_update_bits(codec, WM8996_ACCESSORY_DETECT_MODE_2,
  2103. WM8996_HPOUT1FB_SRC | WM8996_MICD_SRC |
  2104. WM8996_MICD_BIAS_SRC, reg);
  2105. if (wm8996->polarity_cb)
  2106. wm8996->polarity_cb(codec,
  2107. (reg & WM8996_MICD_SRC) != 0);
  2108. dev_dbg(codec->dev, "Set microphone polarity to %d\n",
  2109. (reg & WM8996_MICD_SRC) != 0);
  2110. return;
  2111. }
  2112. /* Don't distinguish between buttons, just report any low
  2113. * impedence as BTN_0.
  2114. */
  2115. if (val & 0x3fc) {
  2116. if (wm8996->jack_mic) {
  2117. dev_dbg(codec->dev, "Mic button detected\n");
  2118. snd_soc_jack_report(wm8996->jack, SND_JACK_BTN_0,
  2119. SND_JACK_BTN_0);
  2120. } else if (wm8996->detecting) {
  2121. wm8996_report_headphone(codec);
  2122. }
  2123. }
  2124. }
  2125. static irqreturn_t wm8996_irq(int irq, void *data)
  2126. {
  2127. struct snd_soc_codec *codec = data;
  2128. struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec);
  2129. int irq_val;
  2130. irq_val = snd_soc_read(codec, WM8996_INTERRUPT_STATUS_2);
  2131. if (irq_val < 0) {
  2132. dev_err(codec->dev, "Failed to read IRQ status: %d\n",
  2133. irq_val);
  2134. return IRQ_NONE;
  2135. }
  2136. irq_val &= ~snd_soc_read(codec, WM8996_INTERRUPT_STATUS_2_MASK);
  2137. if (!irq_val)
  2138. return IRQ_NONE;
  2139. snd_soc_write(codec, WM8996_INTERRUPT_STATUS_2, irq_val);
  2140. if (irq_val & (WM8996_DCS_DONE_01_EINT | WM8996_DCS_DONE_23_EINT)) {
  2141. dev_dbg(codec->dev, "DC servo IRQ\n");
  2142. complete(&wm8996->dcs_done);
  2143. }
  2144. if (irq_val & WM8996_FIFOS_ERR_EINT)
  2145. dev_err(codec->dev, "Digital core FIFO error\n");
  2146. if (irq_val & WM8996_FLL_LOCK_EINT) {
  2147. dev_dbg(codec->dev, "FLL locked\n");
  2148. complete(&wm8996->fll_lock);
  2149. }
  2150. if (irq_val & WM8996_MICD_EINT)
  2151. wm8996_micd(codec);
  2152. if (irq_val & WM8996_HP_DONE_EINT)
  2153. wm8996_hpdet_irq(codec);
  2154. return IRQ_HANDLED;
  2155. }
  2156. static irqreturn_t wm8996_edge_irq(int irq, void *data)
  2157. {
  2158. irqreturn_t ret = IRQ_NONE;
  2159. irqreturn_t val;
  2160. do {
  2161. val = wm8996_irq(irq, data);
  2162. if (val != IRQ_NONE)
  2163. ret = val;
  2164. } while (val != IRQ_NONE);
  2165. return ret;
  2166. }
  2167. static void wm8996_retune_mobile_pdata(struct snd_soc_codec *codec)
  2168. {
  2169. struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec);
  2170. struct wm8996_pdata *pdata = &wm8996->pdata;
  2171. struct snd_kcontrol_new controls[] = {
  2172. SOC_ENUM_EXT("DSP1 EQ Mode",
  2173. wm8996->retune_mobile_enum,
  2174. wm8996_get_retune_mobile_enum,
  2175. wm8996_put_retune_mobile_enum),
  2176. SOC_ENUM_EXT("DSP2 EQ Mode",
  2177. wm8996->retune_mobile_enum,
  2178. wm8996_get_retune_mobile_enum,
  2179. wm8996_put_retune_mobile_enum),
  2180. };
  2181. int ret, i, j;
  2182. const char **t;
  2183. /* We need an array of texts for the enum API but the number
  2184. * of texts is likely to be less than the number of
  2185. * configurations due to the sample rate dependency of the
  2186. * configurations. */
  2187. wm8996->num_retune_mobile_texts = 0;
  2188. wm8996->retune_mobile_texts = NULL;
  2189. for (i = 0; i < pdata->num_retune_mobile_cfgs; i++) {
  2190. for (j = 0; j < wm8996->num_retune_mobile_texts; j++) {
  2191. if (strcmp(pdata->retune_mobile_cfgs[i].name,
  2192. wm8996->retune_mobile_texts[j]) == 0)
  2193. break;
  2194. }
  2195. if (j != wm8996->num_retune_mobile_texts)
  2196. continue;
  2197. /* Expand the array... */
  2198. t = krealloc(wm8996->retune_mobile_texts,
  2199. sizeof(char *) *
  2200. (wm8996->num_retune_mobile_texts + 1),
  2201. GFP_KERNEL);
  2202. if (t == NULL)
  2203. continue;
  2204. /* ...store the new entry... */
  2205. t[wm8996->num_retune_mobile_texts] =
  2206. pdata->retune_mobile_cfgs[i].name;
  2207. /* ...and remember the new version. */
  2208. wm8996->num_retune_mobile_texts++;
  2209. wm8996->retune_mobile_texts = t;
  2210. }
  2211. dev_dbg(codec->dev, "Allocated %d unique ReTune Mobile names\n",
  2212. wm8996->num_retune_mobile_texts);
  2213. wm8996->retune_mobile_enum.items = wm8996->num_retune_mobile_texts;
  2214. wm8996->retune_mobile_enum.texts = wm8996->retune_mobile_texts;
  2215. ret = snd_soc_add_codec_controls(codec, controls, ARRAY_SIZE(controls));
  2216. if (ret != 0)
  2217. dev_err(codec->dev,
  2218. "Failed to add ReTune Mobile controls: %d\n", ret);
  2219. }
  2220. static const struct regmap_config wm8996_regmap = {
  2221. .reg_bits = 16,
  2222. .val_bits = 16,
  2223. .max_register = WM8996_MAX_REGISTER,
  2224. .reg_defaults = wm8996_reg,
  2225. .num_reg_defaults = ARRAY_SIZE(wm8996_reg),
  2226. .volatile_reg = wm8996_volatile_register,
  2227. .readable_reg = wm8996_readable_register,
  2228. .cache_type = REGCACHE_RBTREE,
  2229. };
  2230. static int wm8996_probe(struct snd_soc_codec *codec)
  2231. {
  2232. int ret;
  2233. struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec);
  2234. struct i2c_client *i2c = to_i2c_client(codec->dev);
  2235. int irq_flags;
  2236. wm8996->codec = codec;
  2237. init_completion(&wm8996->dcs_done);
  2238. init_completion(&wm8996->fll_lock);
  2239. if (wm8996->pdata.num_retune_mobile_cfgs)
  2240. wm8996_retune_mobile_pdata(codec);
  2241. else
  2242. snd_soc_add_codec_controls(codec, wm8996_eq_controls,
  2243. ARRAY_SIZE(wm8996_eq_controls));
  2244. if (i2c->irq) {
  2245. if (wm8996->pdata.irq_flags)
  2246. irq_flags = wm8996->pdata.irq_flags;
  2247. else
  2248. irq_flags = IRQF_TRIGGER_LOW;
  2249. irq_flags |= IRQF_ONESHOT;
  2250. if (irq_flags & (IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING))
  2251. ret = request_threaded_irq(i2c->irq, NULL,
  2252. wm8996_edge_irq,
  2253. irq_flags, "wm8996", codec);
  2254. else
  2255. ret = request_threaded_irq(i2c->irq, NULL, wm8996_irq,
  2256. irq_flags, "wm8996", codec);
  2257. if (ret == 0) {
  2258. /* Unmask the interrupt */
  2259. snd_soc_update_bits(codec, WM8996_INTERRUPT_CONTROL,
  2260. WM8996_IM_IRQ, 0);
  2261. /* Enable error reporting and DC servo status */
  2262. snd_soc_update_bits(codec,
  2263. WM8996_INTERRUPT_STATUS_2_MASK,
  2264. WM8996_IM_DCS_DONE_23_EINT |
  2265. WM8996_IM_DCS_DONE_01_EINT |
  2266. WM8996_IM_FLL_LOCK_EINT |
  2267. WM8996_IM_FIFOS_ERR_EINT,
  2268. 0);
  2269. } else {
  2270. dev_err(codec->dev, "Failed to request IRQ: %d\n",
  2271. ret);
  2272. return ret;
  2273. }
  2274. }
  2275. return 0;
  2276. }
  2277. static int wm8996_remove(struct snd_soc_codec *codec)
  2278. {
  2279. struct i2c_client *i2c = to_i2c_client(codec->dev);
  2280. snd_soc_update_bits(codec, WM8996_INTERRUPT_CONTROL,
  2281. WM8996_IM_IRQ, WM8996_IM_IRQ);
  2282. if (i2c->irq)
  2283. free_irq(i2c->irq, codec);
  2284. return 0;
  2285. }
  2286. static const struct snd_soc_codec_driver soc_codec_dev_wm8996 = {
  2287. .probe = wm8996_probe,
  2288. .remove = wm8996_remove,
  2289. .set_bias_level = wm8996_set_bias_level,
  2290. .idle_bias_off = true,
  2291. .seq_notifier = wm8996_seq_notifier,
  2292. .component_driver = {
  2293. .controls = wm8996_snd_controls,
  2294. .num_controls = ARRAY_SIZE(wm8996_snd_controls),
  2295. .dapm_widgets = wm8996_dapm_widgets,
  2296. .num_dapm_widgets = ARRAY_SIZE(wm8996_dapm_widgets),
  2297. .dapm_routes = wm8996_dapm_routes,
  2298. .num_dapm_routes = ARRAY_SIZE(wm8996_dapm_routes),
  2299. },
  2300. .set_pll = wm8996_set_fll,
  2301. };
  2302. #define WM8996_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
  2303. SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 |\
  2304. SNDRV_PCM_RATE_48000)
  2305. #define WM8996_FORMATS (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE |\
  2306. SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S24_LE |\
  2307. SNDRV_PCM_FMTBIT_S32_LE)
  2308. static const struct snd_soc_dai_ops wm8996_dai_ops = {
  2309. .set_fmt = wm8996_set_fmt,
  2310. .hw_params = wm8996_hw_params,
  2311. .set_sysclk = wm8996_set_sysclk,
  2312. };
  2313. static struct snd_soc_dai_driver wm8996_dai[] = {
  2314. {
  2315. .name = "wm8996-aif1",
  2316. .playback = {
  2317. .stream_name = "AIF1 Playback",
  2318. .channels_min = 1,
  2319. .channels_max = 6,
  2320. .rates = WM8996_RATES,
  2321. .formats = WM8996_FORMATS,
  2322. .sig_bits = 24,
  2323. },
  2324. .capture = {
  2325. .stream_name = "AIF1 Capture",
  2326. .channels_min = 1,
  2327. .channels_max = 6,
  2328. .rates = WM8996_RATES,
  2329. .formats = WM8996_FORMATS,
  2330. .sig_bits = 24,
  2331. },
  2332. .ops = &wm8996_dai_ops,
  2333. },
  2334. {
  2335. .name = "wm8996-aif2",
  2336. .playback = {
  2337. .stream_name = "AIF2 Playback",
  2338. .channels_min = 1,
  2339. .channels_max = 2,
  2340. .rates = WM8996_RATES,
  2341. .formats = WM8996_FORMATS,
  2342. .sig_bits = 24,
  2343. },
  2344. .capture = {
  2345. .stream_name = "AIF2 Capture",
  2346. .channels_min = 1,
  2347. .channels_max = 2,
  2348. .rates = WM8996_RATES,
  2349. .formats = WM8996_FORMATS,
  2350. .sig_bits = 24,
  2351. },
  2352. .ops = &wm8996_dai_ops,
  2353. },
  2354. };
  2355. static int wm8996_i2c_probe(struct i2c_client *i2c,
  2356. const struct i2c_device_id *id)
  2357. {
  2358. struct wm8996_priv *wm8996;
  2359. int ret, i;
  2360. unsigned int reg;
  2361. wm8996 = devm_kzalloc(&i2c->dev, sizeof(struct wm8996_priv),
  2362. GFP_KERNEL);
  2363. if (wm8996 == NULL)
  2364. return -ENOMEM;
  2365. i2c_set_clientdata(i2c, wm8996);
  2366. wm8996->dev = &i2c->dev;
  2367. if (dev_get_platdata(&i2c->dev))
  2368. memcpy(&wm8996->pdata, dev_get_platdata(&i2c->dev),
  2369. sizeof(wm8996->pdata));
  2370. if (wm8996->pdata.ldo_ena > 0) {
  2371. ret = gpio_request_one(wm8996->pdata.ldo_ena,
  2372. GPIOF_OUT_INIT_LOW, "WM8996 ENA");
  2373. if (ret < 0) {
  2374. dev_err(&i2c->dev, "Failed to request GPIO %d: %d\n",
  2375. wm8996->pdata.ldo_ena, ret);
  2376. goto err;
  2377. }
  2378. }
  2379. for (i = 0; i < ARRAY_SIZE(wm8996->supplies); i++)
  2380. wm8996->supplies[i].supply = wm8996_supply_names[i];
  2381. ret = devm_regulator_bulk_get(&i2c->dev, ARRAY_SIZE(wm8996->supplies),
  2382. wm8996->supplies);
  2383. if (ret != 0) {
  2384. dev_err(&i2c->dev, "Failed to request supplies: %d\n", ret);
  2385. goto err_gpio;
  2386. }
  2387. wm8996->disable_nb[0].notifier_call = wm8996_regulator_event_0;
  2388. wm8996->disable_nb[1].notifier_call = wm8996_regulator_event_1;
  2389. wm8996->disable_nb[2].notifier_call = wm8996_regulator_event_2;
  2390. /* This should really be moved into the regulator core */
  2391. for (i = 0; i < ARRAY_SIZE(wm8996->supplies); i++) {
  2392. ret = regulator_register_notifier(wm8996->supplies[i].consumer,
  2393. &wm8996->disable_nb[i]);
  2394. if (ret != 0) {
  2395. dev_err(&i2c->dev,
  2396. "Failed to register regulator notifier: %d\n",
  2397. ret);
  2398. }
  2399. }
  2400. ret = regulator_bulk_enable(ARRAY_SIZE(wm8996->supplies),
  2401. wm8996->supplies);
  2402. if (ret != 0) {
  2403. dev_err(&i2c->dev, "Failed to enable supplies: %d\n", ret);
  2404. goto err_gpio;
  2405. }
  2406. if (wm8996->pdata.ldo_ena > 0) {
  2407. gpio_set_value_cansleep(wm8996->pdata.ldo_ena, 1);
  2408. msleep(5);
  2409. }
  2410. wm8996->regmap = devm_regmap_init_i2c(i2c, &wm8996_regmap);
  2411. if (IS_ERR(wm8996->regmap)) {
  2412. ret = PTR_ERR(wm8996->regmap);
  2413. dev_err(&i2c->dev, "regmap_init() failed: %d\n", ret);
  2414. goto err_enable;
  2415. }
  2416. ret = regmap_read(wm8996->regmap, WM8996_SOFTWARE_RESET, &reg);
  2417. if (ret < 0) {
  2418. dev_err(&i2c->dev, "Failed to read ID register: %d\n", ret);
  2419. goto err_regmap;
  2420. }
  2421. if (reg != 0x8915) {
  2422. dev_err(&i2c->dev, "Device is not a WM8996, ID %x\n", reg);
  2423. ret = -EINVAL;
  2424. goto err_regmap;
  2425. }
  2426. ret = regmap_read(wm8996->regmap, WM8996_CHIP_REVISION, &reg);
  2427. if (ret < 0) {
  2428. dev_err(&i2c->dev, "Failed to read device revision: %d\n",
  2429. ret);
  2430. goto err_regmap;
  2431. }
  2432. dev_info(&i2c->dev, "revision %c\n",
  2433. (reg & WM8996_CHIP_REV_MASK) + 'A');
  2434. if (wm8996->pdata.ldo_ena > 0) {
  2435. gpio_set_value_cansleep(wm8996->pdata.ldo_ena, 0);
  2436. regcache_cache_only(wm8996->regmap, true);
  2437. } else {
  2438. ret = regmap_write(wm8996->regmap, WM8996_SOFTWARE_RESET,
  2439. 0x8915);
  2440. if (ret != 0) {
  2441. dev_err(&i2c->dev, "Failed to issue reset: %d\n", ret);
  2442. goto err_regmap;
  2443. }
  2444. }
  2445. regulator_bulk_disable(ARRAY_SIZE(wm8996->supplies), wm8996->supplies);
  2446. /* Apply platform data settings */
  2447. regmap_update_bits(wm8996->regmap, WM8996_LINE_INPUT_CONTROL,
  2448. WM8996_INL_MODE_MASK | WM8996_INR_MODE_MASK,
  2449. wm8996->pdata.inl_mode << WM8996_INL_MODE_SHIFT |
  2450. wm8996->pdata.inr_mode);
  2451. for (i = 0; i < ARRAY_SIZE(wm8996->pdata.gpio_default); i++) {
  2452. if (!wm8996->pdata.gpio_default[i])
  2453. continue;
  2454. regmap_write(wm8996->regmap, WM8996_GPIO_1 + i,
  2455. wm8996->pdata.gpio_default[i] & 0xffff);
  2456. }
  2457. if (wm8996->pdata.spkmute_seq)
  2458. regmap_update_bits(wm8996->regmap,
  2459. WM8996_PDM_SPEAKER_MUTE_SEQUENCE,
  2460. WM8996_SPK_MUTE_ENDIAN |
  2461. WM8996_SPK_MUTE_SEQ1_MASK,
  2462. wm8996->pdata.spkmute_seq);
  2463. regmap_update_bits(wm8996->regmap, WM8996_ACCESSORY_DETECT_MODE_2,
  2464. WM8996_MICD_BIAS_SRC | WM8996_HPOUT1FB_SRC |
  2465. WM8996_MICD_SRC, wm8996->pdata.micdet_def);
  2466. /* Latch volume update bits */
  2467. regmap_update_bits(wm8996->regmap, WM8996_LEFT_LINE_INPUT_VOLUME,
  2468. WM8996_IN1_VU, WM8996_IN1_VU);
  2469. regmap_update_bits(wm8996->regmap, WM8996_RIGHT_LINE_INPUT_VOLUME,
  2470. WM8996_IN1_VU, WM8996_IN1_VU);
  2471. regmap_update_bits(wm8996->regmap, WM8996_DAC1_LEFT_VOLUME,
  2472. WM8996_DAC1_VU, WM8996_DAC1_VU);
  2473. regmap_update_bits(wm8996->regmap, WM8996_DAC1_RIGHT_VOLUME,
  2474. WM8996_DAC1_VU, WM8996_DAC1_VU);
  2475. regmap_update_bits(wm8996->regmap, WM8996_DAC2_LEFT_VOLUME,
  2476. WM8996_DAC2_VU, WM8996_DAC2_VU);
  2477. regmap_update_bits(wm8996->regmap, WM8996_DAC2_RIGHT_VOLUME,
  2478. WM8996_DAC2_VU, WM8996_DAC2_VU);
  2479. regmap_update_bits(wm8996->regmap, WM8996_OUTPUT1_LEFT_VOLUME,
  2480. WM8996_DAC1_VU, WM8996_DAC1_VU);
  2481. regmap_update_bits(wm8996->regmap, WM8996_OUTPUT1_RIGHT_VOLUME,
  2482. WM8996_DAC1_VU, WM8996_DAC1_VU);
  2483. regmap_update_bits(wm8996->regmap, WM8996_OUTPUT2_LEFT_VOLUME,
  2484. WM8996_DAC2_VU, WM8996_DAC2_VU);
  2485. regmap_update_bits(wm8996->regmap, WM8996_OUTPUT2_RIGHT_VOLUME,
  2486. WM8996_DAC2_VU, WM8996_DAC2_VU);
  2487. regmap_update_bits(wm8996->regmap, WM8996_DSP1_TX_LEFT_VOLUME,
  2488. WM8996_DSP1TX_VU, WM8996_DSP1TX_VU);
  2489. regmap_update_bits(wm8996->regmap, WM8996_DSP1_TX_RIGHT_VOLUME,
  2490. WM8996_DSP1TX_VU, WM8996_DSP1TX_VU);
  2491. regmap_update_bits(wm8996->regmap, WM8996_DSP2_TX_LEFT_VOLUME,
  2492. WM8996_DSP2TX_VU, WM8996_DSP2TX_VU);
  2493. regmap_update_bits(wm8996->regmap, WM8996_DSP2_TX_RIGHT_VOLUME,
  2494. WM8996_DSP2TX_VU, WM8996_DSP2TX_VU);
  2495. regmap_update_bits(wm8996->regmap, WM8996_DSP1_RX_LEFT_VOLUME,
  2496. WM8996_DSP1RX_VU, WM8996_DSP1RX_VU);
  2497. regmap_update_bits(wm8996->regmap, WM8996_DSP1_RX_RIGHT_VOLUME,
  2498. WM8996_DSP1RX_VU, WM8996_DSP1RX_VU);
  2499. regmap_update_bits(wm8996->regmap, WM8996_DSP2_RX_LEFT_VOLUME,
  2500. WM8996_DSP2RX_VU, WM8996_DSP2RX_VU);
  2501. regmap_update_bits(wm8996->regmap, WM8996_DSP2_RX_RIGHT_VOLUME,
  2502. WM8996_DSP2RX_VU, WM8996_DSP2RX_VU);
  2503. /* No support currently for the underclocked TDM modes and
  2504. * pick a default TDM layout with each channel pair working with
  2505. * slots 0 and 1. */
  2506. regmap_update_bits(wm8996->regmap,
  2507. WM8996_AIF1RX_CHANNEL_0_CONFIGURATION,
  2508. WM8996_AIF1RX_CHAN0_SLOTS_MASK |
  2509. WM8996_AIF1RX_CHAN0_START_SLOT_MASK,
  2510. 1 << WM8996_AIF1RX_CHAN0_SLOTS_SHIFT | 0);
  2511. regmap_update_bits(wm8996->regmap,
  2512. WM8996_AIF1RX_CHANNEL_1_CONFIGURATION,
  2513. WM8996_AIF1RX_CHAN1_SLOTS_MASK |
  2514. WM8996_AIF1RX_CHAN1_START_SLOT_MASK,
  2515. 1 << WM8996_AIF1RX_CHAN1_SLOTS_SHIFT | 1);
  2516. regmap_update_bits(wm8996->regmap,
  2517. WM8996_AIF1RX_CHANNEL_2_CONFIGURATION,
  2518. WM8996_AIF1RX_CHAN2_SLOTS_MASK |
  2519. WM8996_AIF1RX_CHAN2_START_SLOT_MASK,
  2520. 1 << WM8996_AIF1RX_CHAN2_SLOTS_SHIFT | 0);
  2521. regmap_update_bits(wm8996->regmap,
  2522. WM8996_AIF1RX_CHANNEL_3_CONFIGURATION,
  2523. WM8996_AIF1RX_CHAN3_SLOTS_MASK |
  2524. WM8996_AIF1RX_CHAN0_START_SLOT_MASK,
  2525. 1 << WM8996_AIF1RX_CHAN3_SLOTS_SHIFT | 1);
  2526. regmap_update_bits(wm8996->regmap,
  2527. WM8996_AIF1RX_CHANNEL_4_CONFIGURATION,
  2528. WM8996_AIF1RX_CHAN4_SLOTS_MASK |
  2529. WM8996_AIF1RX_CHAN0_START_SLOT_MASK,
  2530. 1 << WM8996_AIF1RX_CHAN4_SLOTS_SHIFT | 0);
  2531. regmap_update_bits(wm8996->regmap,
  2532. WM8996_AIF1RX_CHANNEL_5_CONFIGURATION,
  2533. WM8996_AIF1RX_CHAN5_SLOTS_MASK |
  2534. WM8996_AIF1RX_CHAN0_START_SLOT_MASK,
  2535. 1 << WM8996_AIF1RX_CHAN5_SLOTS_SHIFT | 1);
  2536. regmap_update_bits(wm8996->regmap,
  2537. WM8996_AIF2RX_CHANNEL_0_CONFIGURATION,
  2538. WM8996_AIF2RX_CHAN0_SLOTS_MASK |
  2539. WM8996_AIF2RX_CHAN0_START_SLOT_MASK,
  2540. 1 << WM8996_AIF2RX_CHAN0_SLOTS_SHIFT | 0);
  2541. regmap_update_bits(wm8996->regmap,
  2542. WM8996_AIF2RX_CHANNEL_1_CONFIGURATION,
  2543. WM8996_AIF2RX_CHAN1_SLOTS_MASK |
  2544. WM8996_AIF2RX_CHAN1_START_SLOT_MASK,
  2545. 1 << WM8996_AIF2RX_CHAN1_SLOTS_SHIFT | 1);
  2546. regmap_update_bits(wm8996->regmap,
  2547. WM8996_AIF1TX_CHANNEL_0_CONFIGURATION,
  2548. WM8996_AIF1TX_CHAN0_SLOTS_MASK |
  2549. WM8996_AIF1TX_CHAN0_START_SLOT_MASK,
  2550. 1 << WM8996_AIF1TX_CHAN0_SLOTS_SHIFT | 0);
  2551. regmap_update_bits(wm8996->regmap,
  2552. WM8996_AIF1TX_CHANNEL_1_CONFIGURATION,
  2553. WM8996_AIF1TX_CHAN1_SLOTS_MASK |
  2554. WM8996_AIF1TX_CHAN0_START_SLOT_MASK,
  2555. 1 << WM8996_AIF1TX_CHAN1_SLOTS_SHIFT | 1);
  2556. regmap_update_bits(wm8996->regmap,
  2557. WM8996_AIF1TX_CHANNEL_2_CONFIGURATION,
  2558. WM8996_AIF1TX_CHAN2_SLOTS_MASK |
  2559. WM8996_AIF1TX_CHAN0_START_SLOT_MASK,
  2560. 1 << WM8996_AIF1TX_CHAN2_SLOTS_SHIFT | 0);
  2561. regmap_update_bits(wm8996->regmap,
  2562. WM8996_AIF1TX_CHANNEL_3_CONFIGURATION,
  2563. WM8996_AIF1TX_CHAN3_SLOTS_MASK |
  2564. WM8996_AIF1TX_CHAN0_START_SLOT_MASK,
  2565. 1 << WM8996_AIF1TX_CHAN3_SLOTS_SHIFT | 1);
  2566. regmap_update_bits(wm8996->regmap,
  2567. WM8996_AIF1TX_CHANNEL_4_CONFIGURATION,
  2568. WM8996_AIF1TX_CHAN4_SLOTS_MASK |
  2569. WM8996_AIF1TX_CHAN0_START_SLOT_MASK,
  2570. 1 << WM8996_AIF1TX_CHAN4_SLOTS_SHIFT | 0);
  2571. regmap_update_bits(wm8996->regmap,
  2572. WM8996_AIF1TX_CHANNEL_5_CONFIGURATION,
  2573. WM8996_AIF1TX_CHAN5_SLOTS_MASK |
  2574. WM8996_AIF1TX_CHAN0_START_SLOT_MASK,
  2575. 1 << WM8996_AIF1TX_CHAN5_SLOTS_SHIFT | 1);
  2576. regmap_update_bits(wm8996->regmap,
  2577. WM8996_AIF2TX_CHANNEL_0_CONFIGURATION,
  2578. WM8996_AIF2TX_CHAN0_SLOTS_MASK |
  2579. WM8996_AIF2TX_CHAN0_START_SLOT_MASK,
  2580. 1 << WM8996_AIF2TX_CHAN0_SLOTS_SHIFT | 0);
  2581. regmap_update_bits(wm8996->regmap,
  2582. WM8996_AIF1TX_CHANNEL_1_CONFIGURATION,
  2583. WM8996_AIF2TX_CHAN1_SLOTS_MASK |
  2584. WM8996_AIF2TX_CHAN1_START_SLOT_MASK,
  2585. 1 << WM8996_AIF1TX_CHAN1_SLOTS_SHIFT | 1);
  2586. /* If the TX LRCLK pins are not in LRCLK mode configure the
  2587. * AIFs to source their clocks from the RX LRCLKs.
  2588. */
  2589. ret = regmap_read(wm8996->regmap, WM8996_GPIO_1, &reg);
  2590. if (ret != 0) {
  2591. dev_err(&i2c->dev, "Failed to read GPIO1: %d\n", ret);
  2592. goto err_regmap;
  2593. }
  2594. if (reg & WM8996_GP1_FN_MASK)
  2595. regmap_update_bits(wm8996->regmap, WM8996_AIF1_TX_LRCLK_2,
  2596. WM8996_AIF1TX_LRCLK_MODE,
  2597. WM8996_AIF1TX_LRCLK_MODE);
  2598. ret = regmap_read(wm8996->regmap, WM8996_GPIO_2, &reg);
  2599. if (ret != 0) {
  2600. dev_err(&i2c->dev, "Failed to read GPIO2: %d\n", ret);
  2601. goto err_regmap;
  2602. }
  2603. if (reg & WM8996_GP2_FN_MASK)
  2604. regmap_update_bits(wm8996->regmap, WM8996_AIF2_TX_LRCLK_2,
  2605. WM8996_AIF2TX_LRCLK_MODE,
  2606. WM8996_AIF2TX_LRCLK_MODE);
  2607. wm8996_init_gpio(wm8996);
  2608. ret = snd_soc_register_codec(&i2c->dev,
  2609. &soc_codec_dev_wm8996, wm8996_dai,
  2610. ARRAY_SIZE(wm8996_dai));
  2611. if (ret < 0)
  2612. goto err_gpiolib;
  2613. return ret;
  2614. err_gpiolib:
  2615. wm8996_free_gpio(wm8996);
  2616. err_regmap:
  2617. err_enable:
  2618. if (wm8996->pdata.ldo_ena > 0)
  2619. gpio_set_value_cansleep(wm8996->pdata.ldo_ena, 0);
  2620. regulator_bulk_disable(ARRAY_SIZE(wm8996->supplies), wm8996->supplies);
  2621. err_gpio:
  2622. if (wm8996->pdata.ldo_ena > 0)
  2623. gpio_free(wm8996->pdata.ldo_ena);
  2624. err:
  2625. return ret;
  2626. }
  2627. static int wm8996_i2c_remove(struct i2c_client *client)
  2628. {
  2629. struct wm8996_priv *wm8996 = i2c_get_clientdata(client);
  2630. int i;
  2631. snd_soc_unregister_codec(&client->dev);
  2632. wm8996_free_gpio(wm8996);
  2633. if (wm8996->pdata.ldo_ena > 0) {
  2634. gpio_set_value_cansleep(wm8996->pdata.ldo_ena, 0);
  2635. gpio_free(wm8996->pdata.ldo_ena);
  2636. }
  2637. for (i = 0; i < ARRAY_SIZE(wm8996->supplies); i++)
  2638. regulator_unregister_notifier(wm8996->supplies[i].consumer,
  2639. &wm8996->disable_nb[i]);
  2640. return 0;
  2641. }
  2642. static const struct i2c_device_id wm8996_i2c_id[] = {
  2643. { "wm8996", 0 },
  2644. { }
  2645. };
  2646. MODULE_DEVICE_TABLE(i2c, wm8996_i2c_id);
  2647. static struct i2c_driver wm8996_i2c_driver = {
  2648. .driver = {
  2649. .name = "wm8996",
  2650. },
  2651. .probe = wm8996_i2c_probe,
  2652. .remove = wm8996_i2c_remove,
  2653. .id_table = wm8996_i2c_id,
  2654. };
  2655. module_i2c_driver(wm8996_i2c_driver);
  2656. MODULE_DESCRIPTION("ASoC WM8996 driver");
  2657. MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
  2658. MODULE_LICENSE("GPL");