rt5663.c 84 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219
  1. /*
  2. * rt5663.c -- RT5668/RT5663 ALSA SoC audio codec driver
  3. *
  4. * Copyright 2016 Realtek Semiconductor Corp.
  5. * Author: Jack Yu <jack.yu@realtek.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/module.h>
  12. #include <linux/moduleparam.h>
  13. #include <linux/init.h>
  14. #include <linux/delay.h>
  15. #include <linux/pm.h>
  16. #include <linux/i2c.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/spi/spi.h>
  19. #include <linux/acpi.h>
  20. #include <linux/workqueue.h>
  21. #include <sound/core.h>
  22. #include <sound/pcm.h>
  23. #include <sound/pcm_params.h>
  24. #include <sound/jack.h>
  25. #include <sound/soc.h>
  26. #include <sound/soc-dapm.h>
  27. #include <sound/initval.h>
  28. #include <sound/tlv.h>
  29. #include "rt5663.h"
  30. #include "rl6231.h"
  31. #define RT5668_DEVICE_ID 0x6451
  32. #define RT5663_DEVICE_ID 0x6406
  33. enum {
  34. CODEC_TYPE_RT5668,
  35. CODEC_TYPE_RT5663,
  36. };
  37. struct rt5663_priv {
  38. struct snd_soc_codec *codec;
  39. struct regmap *regmap;
  40. struct delayed_work jack_detect_work;
  41. struct snd_soc_jack *hs_jack;
  42. struct timer_list btn_check_timer;
  43. int codec_type;
  44. int sysclk;
  45. int sysclk_src;
  46. int lrck;
  47. int pll_src;
  48. int pll_in;
  49. int pll_out;
  50. int jack_type;
  51. };
  52. static const struct reg_default rt5668_reg[] = {
  53. { 0x0000, 0x0000 },
  54. { 0x0001, 0xc8c8 },
  55. { 0x0002, 0x8080 },
  56. { 0x0003, 0x8000 },
  57. { 0x0004, 0xc80a },
  58. { 0x0005, 0x0000 },
  59. { 0x0006, 0x0000 },
  60. { 0x0007, 0x0000 },
  61. { 0x000a, 0x0000 },
  62. { 0x000b, 0x0000 },
  63. { 0x000c, 0x0000 },
  64. { 0x000d, 0x0000 },
  65. { 0x000f, 0x0808 },
  66. { 0x0010, 0x4000 },
  67. { 0x0011, 0x0000 },
  68. { 0x0012, 0x1404 },
  69. { 0x0013, 0x1000 },
  70. { 0x0014, 0xa00a },
  71. { 0x0015, 0x0404 },
  72. { 0x0016, 0x0404 },
  73. { 0x0017, 0x0011 },
  74. { 0x0018, 0xafaf },
  75. { 0x0019, 0xafaf },
  76. { 0x001a, 0xafaf },
  77. { 0x001b, 0x0011 },
  78. { 0x001c, 0x2f2f },
  79. { 0x001d, 0x2f2f },
  80. { 0x001e, 0x2f2f },
  81. { 0x001f, 0x0000 },
  82. { 0x0020, 0x0000 },
  83. { 0x0021, 0x0000 },
  84. { 0x0022, 0x5757 },
  85. { 0x0023, 0x0039 },
  86. { 0x0024, 0x000b },
  87. { 0x0026, 0xc0c0 },
  88. { 0x0027, 0xc0c0 },
  89. { 0x0028, 0xc0c0 },
  90. { 0x0029, 0x8080 },
  91. { 0x002a, 0xaaaa },
  92. { 0x002b, 0xaaaa },
  93. { 0x002c, 0xaba8 },
  94. { 0x002d, 0x0000 },
  95. { 0x002e, 0x0000 },
  96. { 0x002f, 0x0000 },
  97. { 0x0030, 0x0000 },
  98. { 0x0031, 0x5000 },
  99. { 0x0032, 0x0000 },
  100. { 0x0033, 0x0000 },
  101. { 0x0034, 0x0000 },
  102. { 0x0035, 0x0000 },
  103. { 0x003a, 0x0000 },
  104. { 0x003b, 0x0000 },
  105. { 0x003c, 0x00ff },
  106. { 0x003d, 0x0000 },
  107. { 0x003e, 0x00ff },
  108. { 0x003f, 0x0000 },
  109. { 0x0040, 0x0000 },
  110. { 0x0041, 0x00ff },
  111. { 0x0042, 0x0000 },
  112. { 0x0043, 0x00ff },
  113. { 0x0044, 0x0c0c },
  114. { 0x0049, 0xc00b },
  115. { 0x004a, 0x0000 },
  116. { 0x004b, 0x031f },
  117. { 0x004d, 0x0000 },
  118. { 0x004e, 0x001f },
  119. { 0x004f, 0x0000 },
  120. { 0x0050, 0x001f },
  121. { 0x0052, 0xf000 },
  122. { 0x0061, 0x0000 },
  123. { 0x0062, 0x0000 },
  124. { 0x0063, 0x003e },
  125. { 0x0064, 0x0000 },
  126. { 0x0065, 0x0000 },
  127. { 0x0066, 0x003f },
  128. { 0x0067, 0x0000 },
  129. { 0x006b, 0x0000 },
  130. { 0x006d, 0xff00 },
  131. { 0x006e, 0x2808 },
  132. { 0x006f, 0x000a },
  133. { 0x0070, 0x8000 },
  134. { 0x0071, 0x8000 },
  135. { 0x0072, 0x8000 },
  136. { 0x0073, 0x7000 },
  137. { 0x0074, 0x7770 },
  138. { 0x0075, 0x0002 },
  139. { 0x0076, 0x0001 },
  140. { 0x0078, 0x00f0 },
  141. { 0x0079, 0x0000 },
  142. { 0x007a, 0x0000 },
  143. { 0x007b, 0x0000 },
  144. { 0x007c, 0x0000 },
  145. { 0x007d, 0x0123 },
  146. { 0x007e, 0x4500 },
  147. { 0x007f, 0x8003 },
  148. { 0x0080, 0x0000 },
  149. { 0x0081, 0x0000 },
  150. { 0x0082, 0x0000 },
  151. { 0x0083, 0x0000 },
  152. { 0x0084, 0x0000 },
  153. { 0x0085, 0x0000 },
  154. { 0x0086, 0x0008 },
  155. { 0x0087, 0x0000 },
  156. { 0x0088, 0x0000 },
  157. { 0x0089, 0x0000 },
  158. { 0x008a, 0x0000 },
  159. { 0x008b, 0x0000 },
  160. { 0x008c, 0x0003 },
  161. { 0x008e, 0x0060 },
  162. { 0x008f, 0x1000 },
  163. { 0x0091, 0x0c26 },
  164. { 0x0092, 0x0073 },
  165. { 0x0093, 0x0000 },
  166. { 0x0094, 0x0080 },
  167. { 0x0098, 0x0000 },
  168. { 0x0099, 0x0000 },
  169. { 0x009a, 0x0007 },
  170. { 0x009f, 0x0000 },
  171. { 0x00a0, 0x0000 },
  172. { 0x00a1, 0x0002 },
  173. { 0x00a2, 0x0001 },
  174. { 0x00a3, 0x0002 },
  175. { 0x00a4, 0x0001 },
  176. { 0x00ae, 0x2040 },
  177. { 0x00af, 0x0000 },
  178. { 0x00b6, 0x0000 },
  179. { 0x00b7, 0x0000 },
  180. { 0x00b8, 0x0000 },
  181. { 0x00b9, 0x0000 },
  182. { 0x00ba, 0x0002 },
  183. { 0x00bb, 0x0000 },
  184. { 0x00be, 0x0000 },
  185. { 0x00c0, 0x0000 },
  186. { 0x00c1, 0x0aaa },
  187. { 0x00c2, 0xaa80 },
  188. { 0x00c3, 0x0003 },
  189. { 0x00c4, 0x0000 },
  190. { 0x00d0, 0x0000 },
  191. { 0x00d1, 0x2244 },
  192. { 0x00d2, 0x0000 },
  193. { 0x00d3, 0x3300 },
  194. { 0x00d4, 0x2200 },
  195. { 0x00d9, 0x0809 },
  196. { 0x00da, 0x0000 },
  197. { 0x00db, 0x0008 },
  198. { 0x00dc, 0x00c0 },
  199. { 0x00dd, 0x6724 },
  200. { 0x00de, 0x3131 },
  201. { 0x00df, 0x0008 },
  202. { 0x00e0, 0x4000 },
  203. { 0x00e1, 0x3131 },
  204. { 0x00e2, 0x600c },
  205. { 0x00ea, 0xb320 },
  206. { 0x00eb, 0x0000 },
  207. { 0x00ec, 0xb300 },
  208. { 0x00ed, 0x0000 },
  209. { 0x00ee, 0xb320 },
  210. { 0x00ef, 0x0000 },
  211. { 0x00f0, 0x0201 },
  212. { 0x00f1, 0x0ddd },
  213. { 0x00f2, 0x0ddd },
  214. { 0x00f6, 0x0000 },
  215. { 0x00f7, 0x0000 },
  216. { 0x00f8, 0x0000 },
  217. { 0x00fa, 0x0000 },
  218. { 0x00fb, 0x0000 },
  219. { 0x00fc, 0x0000 },
  220. { 0x00fd, 0x0000 },
  221. { 0x00fe, 0x10ec },
  222. { 0x00ff, 0x6451 },
  223. { 0x0100, 0xaaaa },
  224. { 0x0101, 0x000a },
  225. { 0x010a, 0xaaaa },
  226. { 0x010b, 0xa0a0 },
  227. { 0x010c, 0xaeae },
  228. { 0x010d, 0xaaaa },
  229. { 0x010e, 0xaaaa },
  230. { 0x010f, 0xaaaa },
  231. { 0x0110, 0xe002 },
  232. { 0x0111, 0xa602 },
  233. { 0x0112, 0xaaaa },
  234. { 0x0113, 0x2000 },
  235. { 0x0117, 0x0f00 },
  236. { 0x0125, 0x0420 },
  237. { 0x0132, 0x0000 },
  238. { 0x0133, 0x0000 },
  239. { 0x0136, 0x5555 },
  240. { 0x0137, 0x5540 },
  241. { 0x0138, 0x3700 },
  242. { 0x0139, 0x79a1 },
  243. { 0x013a, 0x2020 },
  244. { 0x013b, 0x2020 },
  245. { 0x013c, 0x2005 },
  246. { 0x013f, 0x0000 },
  247. { 0x0145, 0x0002 },
  248. { 0x0146, 0x0000 },
  249. { 0x0147, 0x0000 },
  250. { 0x0148, 0x0000 },
  251. { 0x0160, 0x4ec0 },
  252. { 0x0161, 0x0080 },
  253. { 0x0162, 0x0200 },
  254. { 0x0163, 0x0800 },
  255. { 0x0164, 0x0000 },
  256. { 0x0165, 0x0000 },
  257. { 0x0166, 0x0000 },
  258. { 0x0167, 0x000f },
  259. { 0x0168, 0x000f },
  260. { 0x0170, 0x4e80 },
  261. { 0x0171, 0x0080 },
  262. { 0x0172, 0x0200 },
  263. { 0x0173, 0x0800 },
  264. { 0x0174, 0x00ff },
  265. { 0x0175, 0x0000 },
  266. { 0x0190, 0x4131 },
  267. { 0x0191, 0x4131 },
  268. { 0x0192, 0x4131 },
  269. { 0x0193, 0x4131 },
  270. { 0x0194, 0x0000 },
  271. { 0x0195, 0x0000 },
  272. { 0x0196, 0x0000 },
  273. { 0x0197, 0x0000 },
  274. { 0x0198, 0x0000 },
  275. { 0x0199, 0x0000 },
  276. { 0x01a0, 0x1e64 },
  277. { 0x01a1, 0x06a3 },
  278. { 0x01a2, 0x0000 },
  279. { 0x01a3, 0x0000 },
  280. { 0x01a4, 0x0000 },
  281. { 0x01a5, 0x0000 },
  282. { 0x01a6, 0x0000 },
  283. { 0x01a7, 0x0000 },
  284. { 0x01a8, 0x0000 },
  285. { 0x01a9, 0x0000 },
  286. { 0x01aa, 0x0000 },
  287. { 0x01ab, 0x0000 },
  288. { 0x01b5, 0x0000 },
  289. { 0x01b6, 0x01c3 },
  290. { 0x01b7, 0x02a0 },
  291. { 0x01b8, 0x03e9 },
  292. { 0x01b9, 0x1389 },
  293. { 0x01ba, 0xc351 },
  294. { 0x01bb, 0x0009 },
  295. { 0x01bc, 0x0018 },
  296. { 0x01bd, 0x002a },
  297. { 0x01be, 0x004c },
  298. { 0x01bf, 0x0097 },
  299. { 0x01c0, 0x433d },
  300. { 0x01c1, 0x0000 },
  301. { 0x01c2, 0x0000 },
  302. { 0x01c3, 0x0000 },
  303. { 0x01c4, 0x0000 },
  304. { 0x01c5, 0x0000 },
  305. { 0x01c6, 0x0000 },
  306. { 0x01c7, 0x0000 },
  307. { 0x01c8, 0x40af },
  308. { 0x01c9, 0x0702 },
  309. { 0x01ca, 0x0000 },
  310. { 0x01cb, 0x0000 },
  311. { 0x01cc, 0x5757 },
  312. { 0x01cd, 0x5757 },
  313. { 0x01ce, 0x5757 },
  314. { 0x01cf, 0x5757 },
  315. { 0x01d0, 0x5757 },
  316. { 0x01d1, 0x5757 },
  317. { 0x01d2, 0x5757 },
  318. { 0x01d3, 0x5757 },
  319. { 0x01d4, 0x5757 },
  320. { 0x01d5, 0x5757 },
  321. { 0x01d6, 0x003c },
  322. { 0x01da, 0x0000 },
  323. { 0x01db, 0x0000 },
  324. { 0x01dc, 0x0000 },
  325. { 0x01de, 0x7c00 },
  326. { 0x01df, 0x0320 },
  327. { 0x01e0, 0x06a1 },
  328. { 0x01e1, 0x0000 },
  329. { 0x01e2, 0x0000 },
  330. { 0x01e3, 0x0000 },
  331. { 0x01e4, 0x0000 },
  332. { 0x01e5, 0x0000 },
  333. { 0x01e6, 0x0001 },
  334. { 0x01e7, 0x0000 },
  335. { 0x01e8, 0x0000 },
  336. { 0x01ea, 0x0000 },
  337. { 0x01eb, 0x0000 },
  338. { 0x01ec, 0x0000 },
  339. { 0x01ed, 0x0000 },
  340. { 0x01ee, 0x0000 },
  341. { 0x01ef, 0x0000 },
  342. { 0x01f0, 0x0000 },
  343. { 0x01f1, 0x0000 },
  344. { 0x01f2, 0x0000 },
  345. { 0x01f3, 0x0000 },
  346. { 0x01f4, 0x0000 },
  347. { 0x0200, 0x0000 },
  348. { 0x0201, 0x0000 },
  349. { 0x0202, 0x0000 },
  350. { 0x0203, 0x0000 },
  351. { 0x0204, 0x0000 },
  352. { 0x0205, 0x0000 },
  353. { 0x0206, 0x0000 },
  354. { 0x0207, 0x0000 },
  355. { 0x0208, 0x0000 },
  356. { 0x0210, 0x60b1 },
  357. { 0x0211, 0xa000 },
  358. { 0x0212, 0x024c },
  359. { 0x0213, 0xf7ff },
  360. { 0x0214, 0x024c },
  361. { 0x0215, 0x0102 },
  362. { 0x0216, 0x00a3 },
  363. { 0x0217, 0x0048 },
  364. { 0x0218, 0x92c0 },
  365. { 0x0219, 0x0000 },
  366. { 0x021a, 0x00c8 },
  367. { 0x021b, 0x0020 },
  368. { 0x02fa, 0x0000 },
  369. { 0x02fb, 0x0000 },
  370. { 0x02fc, 0x0000 },
  371. { 0x02ff, 0x0110 },
  372. { 0x0300, 0x001f },
  373. { 0x0301, 0x032c },
  374. { 0x0302, 0x5f21 },
  375. { 0x0303, 0x4000 },
  376. { 0x0304, 0x4000 },
  377. { 0x0305, 0x06d5 },
  378. { 0x0306, 0x8000 },
  379. { 0x0307, 0x0700 },
  380. { 0x0310, 0x4560 },
  381. { 0x0311, 0xa4a8 },
  382. { 0x0312, 0x7418 },
  383. { 0x0313, 0x0000 },
  384. { 0x0314, 0x0006 },
  385. { 0x0315, 0xffff },
  386. { 0x0316, 0xc400 },
  387. { 0x0317, 0x0000 },
  388. { 0x0330, 0x00a6 },
  389. { 0x0331, 0x04c3 },
  390. { 0x0332, 0x27c8 },
  391. { 0x0333, 0xbf50 },
  392. { 0x0334, 0x0045 },
  393. { 0x0335, 0x0007 },
  394. { 0x0336, 0x7418 },
  395. { 0x0337, 0x0501 },
  396. { 0x0338, 0x0000 },
  397. { 0x0339, 0x0010 },
  398. { 0x033a, 0x1010 },
  399. { 0x03c0, 0x7e00 },
  400. { 0x03c1, 0x8000 },
  401. { 0x03c2, 0x8000 },
  402. { 0x03c3, 0x8000 },
  403. { 0x03c4, 0x8000 },
  404. { 0x03c5, 0x8000 },
  405. { 0x03c6, 0x8000 },
  406. { 0x03c7, 0x8000 },
  407. { 0x03c8, 0x8000 },
  408. { 0x03c9, 0x8000 },
  409. { 0x03ca, 0x8000 },
  410. { 0x03cb, 0x8000 },
  411. { 0x03cc, 0x8000 },
  412. { 0x03d0, 0x0000 },
  413. { 0x03d1, 0x0000 },
  414. { 0x03d2, 0x0000 },
  415. { 0x03d3, 0x0000 },
  416. { 0x03d4, 0x2000 },
  417. { 0x03d5, 0x2000 },
  418. { 0x03d6, 0x0000 },
  419. { 0x03d7, 0x0000 },
  420. { 0x03d8, 0x2000 },
  421. { 0x03d9, 0x2000 },
  422. { 0x03da, 0x2000 },
  423. { 0x03db, 0x2000 },
  424. { 0x03dc, 0x0000 },
  425. { 0x03dd, 0x0000 },
  426. { 0x03de, 0x0000 },
  427. { 0x03df, 0x2000 },
  428. { 0x03e0, 0x0000 },
  429. { 0x03e1, 0x0000 },
  430. { 0x03e2, 0x0000 },
  431. { 0x03e3, 0x0000 },
  432. { 0x03e4, 0x0000 },
  433. { 0x03e5, 0x0000 },
  434. { 0x03e6, 0x0000 },
  435. { 0x03e7, 0x0000 },
  436. { 0x03e8, 0x0000 },
  437. { 0x03e9, 0x0000 },
  438. { 0x03ea, 0x0000 },
  439. { 0x03eb, 0x0000 },
  440. { 0x03ec, 0x0000 },
  441. { 0x03ed, 0x0000 },
  442. { 0x03ee, 0x0000 },
  443. { 0x03ef, 0x0000 },
  444. { 0x03f0, 0x0800 },
  445. { 0x03f1, 0x0800 },
  446. { 0x03f2, 0x0800 },
  447. { 0x03f3, 0x0800 },
  448. { 0x03fe, 0x0000 },
  449. { 0x03ff, 0x0000 },
  450. { 0x07f0, 0x0000 },
  451. { 0x07fa, 0x0000 },
  452. };
  453. static const struct reg_default rt5663_reg[] = {
  454. { 0x0000, 0x0000 },
  455. { 0x0002, 0x0008 },
  456. { 0x0005, 0x1000 },
  457. { 0x0006, 0x1000 },
  458. { 0x000a, 0x0000 },
  459. { 0x0010, 0x000f },
  460. { 0x0015, 0x42c1 },
  461. { 0x0016, 0x0000 },
  462. { 0x0018, 0x000b },
  463. { 0x0019, 0xafaf },
  464. { 0x001c, 0x2f2f },
  465. { 0x001f, 0x0000 },
  466. { 0x0022, 0x5757 },
  467. { 0x0023, 0x0039 },
  468. { 0x0026, 0xc0c0 },
  469. { 0x0029, 0x8080 },
  470. { 0x002a, 0xa0a0 },
  471. { 0x002c, 0x000c },
  472. { 0x002d, 0x0000 },
  473. { 0x0040, 0x0808 },
  474. { 0x0061, 0x0000 },
  475. { 0x0062, 0x0000 },
  476. { 0x0063, 0x003e },
  477. { 0x0064, 0x0000 },
  478. { 0x0065, 0x0000 },
  479. { 0x0066, 0x0000 },
  480. { 0x006b, 0x0000 },
  481. { 0x006e, 0x0000 },
  482. { 0x006f, 0x0000 },
  483. { 0x0070, 0x8020 },
  484. { 0x0073, 0x1000 },
  485. { 0x0074, 0xe400 },
  486. { 0x0075, 0x0002 },
  487. { 0x0076, 0x0001 },
  488. { 0x0077, 0x00f0 },
  489. { 0x0078, 0x0000 },
  490. { 0x0079, 0x0000 },
  491. { 0x007a, 0x0123 },
  492. { 0x007b, 0x8003 },
  493. { 0x0080, 0x0000 },
  494. { 0x0081, 0x0000 },
  495. { 0x0082, 0x0000 },
  496. { 0x0083, 0x0000 },
  497. { 0x0084, 0x0000 },
  498. { 0x0086, 0x0008 },
  499. { 0x0087, 0x0000 },
  500. { 0x008a, 0x0000 },
  501. { 0x008b, 0x0000 },
  502. { 0x008c, 0x0003 },
  503. { 0x008e, 0x0004 },
  504. { 0x008f, 0x1000 },
  505. { 0x0090, 0x0646 },
  506. { 0x0091, 0x0e3e },
  507. { 0x0092, 0x1071 },
  508. { 0x0093, 0x0000 },
  509. { 0x0094, 0x0080 },
  510. { 0x0097, 0x0000 },
  511. { 0x0098, 0x0000 },
  512. { 0x009a, 0x0000 },
  513. { 0x009f, 0x0000 },
  514. { 0x00ae, 0x2000 },
  515. { 0x00af, 0x0000 },
  516. { 0x00b6, 0x0000 },
  517. { 0x00b7, 0x0000 },
  518. { 0x00b8, 0x0000 },
  519. { 0x00ba, 0x0000 },
  520. { 0x00bb, 0x0000 },
  521. { 0x00be, 0x0000 },
  522. { 0x00bf, 0x0000 },
  523. { 0x00c0, 0x0000 },
  524. { 0x00c1, 0x0000 },
  525. { 0x00c5, 0x0000 },
  526. { 0x00cb, 0xa02f },
  527. { 0x00cc, 0x0000 },
  528. { 0x00cd, 0x0e02 },
  529. { 0x00d9, 0x08f9 },
  530. { 0x00db, 0x0008 },
  531. { 0x00dc, 0x00c0 },
  532. { 0x00dd, 0x6724 },
  533. { 0x00de, 0x3131 },
  534. { 0x00df, 0x0008 },
  535. { 0x00e0, 0x4000 },
  536. { 0x00e1, 0x3131 },
  537. { 0x00e2, 0x0043 },
  538. { 0x00e4, 0x400b },
  539. { 0x00e5, 0x8031 },
  540. { 0x00e6, 0x3080 },
  541. { 0x00e7, 0x4100 },
  542. { 0x00e8, 0x1400 },
  543. { 0x00e9, 0xe00a },
  544. { 0x00ea, 0x0404 },
  545. { 0x00eb, 0x0404 },
  546. { 0x00ec, 0xb320 },
  547. { 0x00ed, 0x0000 },
  548. { 0x00f4, 0x0000 },
  549. { 0x00f6, 0x0000 },
  550. { 0x00f8, 0x0000 },
  551. { 0x00fa, 0x8000 },
  552. { 0x00fd, 0x0001 },
  553. { 0x00fe, 0x10ec },
  554. { 0x00ff, 0x6406 },
  555. { 0x0100, 0xa0a0 },
  556. { 0x0108, 0x4444 },
  557. { 0x0109, 0x4444 },
  558. { 0x010a, 0xaaaa },
  559. { 0x010b, 0x00a0 },
  560. { 0x010c, 0x8aaa },
  561. { 0x010d, 0xaaaa },
  562. { 0x010e, 0x2aaa },
  563. { 0x010f, 0x002a },
  564. { 0x0110, 0xa0a4 },
  565. { 0x0111, 0x4602 },
  566. { 0x0112, 0x0101 },
  567. { 0x0113, 0x2000 },
  568. { 0x0114, 0x0000 },
  569. { 0x0116, 0x0000 },
  570. { 0x0117, 0x0f00 },
  571. { 0x0118, 0x0006 },
  572. { 0x0125, 0x2224 },
  573. { 0x0126, 0x5550 },
  574. { 0x0127, 0x0400 },
  575. { 0x0128, 0x7711 },
  576. { 0x0132, 0x0004 },
  577. { 0x0137, 0x5441 },
  578. { 0x0139, 0x79a1 },
  579. { 0x013a, 0x30c0 },
  580. { 0x013b, 0x2000 },
  581. { 0x013c, 0x2005 },
  582. { 0x013d, 0x30c0 },
  583. { 0x013e, 0x0000 },
  584. { 0x0140, 0x3700 },
  585. { 0x0141, 0x1f00 },
  586. { 0x0144, 0x0000 },
  587. { 0x0145, 0x0002 },
  588. { 0x0146, 0x0000 },
  589. { 0x0160, 0x0e80 },
  590. { 0x0161, 0x0020 },
  591. { 0x0162, 0x0080 },
  592. { 0x0163, 0x0800 },
  593. { 0x0164, 0x0000 },
  594. { 0x0165, 0x0000 },
  595. { 0x0166, 0x0000 },
  596. { 0x0167, 0x1417 },
  597. { 0x0168, 0x0017 },
  598. { 0x0169, 0x0017 },
  599. { 0x0180, 0x2000 },
  600. { 0x0181, 0x0000 },
  601. { 0x0182, 0x0000 },
  602. { 0x0183, 0x2000 },
  603. { 0x0184, 0x0000 },
  604. { 0x0185, 0x0000 },
  605. { 0x01b0, 0x4b30 },
  606. { 0x01b1, 0x0000 },
  607. { 0x01b2, 0xd870 },
  608. { 0x01b3, 0x0000 },
  609. { 0x01b4, 0x0030 },
  610. { 0x01b5, 0x5757 },
  611. { 0x01b6, 0x5757 },
  612. { 0x01b7, 0x5757 },
  613. { 0x01b8, 0x5757 },
  614. { 0x01c0, 0x433d },
  615. { 0x01c1, 0x0540 },
  616. { 0x01c2, 0x0000 },
  617. { 0x01c3, 0x0000 },
  618. { 0x01c4, 0x0000 },
  619. { 0x01c5, 0x0009 },
  620. { 0x01c6, 0x0018 },
  621. { 0x01c7, 0x002a },
  622. { 0x01c8, 0x004c },
  623. { 0x01c9, 0x0097 },
  624. { 0x01ca, 0x01c3 },
  625. { 0x01cb, 0x03e9 },
  626. { 0x01cc, 0x1389 },
  627. { 0x01cd, 0xc351 },
  628. { 0x01ce, 0x0000 },
  629. { 0x01cf, 0x0000 },
  630. { 0x01d0, 0x0000 },
  631. { 0x01d1, 0x0000 },
  632. { 0x01d2, 0x0000 },
  633. { 0x01d3, 0x003c },
  634. { 0x01d4, 0x5757 },
  635. { 0x01d5, 0x5757 },
  636. { 0x01d6, 0x5757 },
  637. { 0x01d7, 0x5757 },
  638. { 0x01d8, 0x5757 },
  639. { 0x01d9, 0x5757 },
  640. { 0x01da, 0x0000 },
  641. { 0x01db, 0x0000 },
  642. { 0x01dd, 0x0009 },
  643. { 0x01de, 0x7f00 },
  644. { 0x01df, 0x00c8 },
  645. { 0x01e0, 0x0691 },
  646. { 0x01e1, 0x0000 },
  647. { 0x01e2, 0x0000 },
  648. { 0x01e3, 0x0000 },
  649. { 0x01e4, 0x0000 },
  650. { 0x01e5, 0x0040 },
  651. { 0x01e6, 0x0000 },
  652. { 0x01e7, 0x0000 },
  653. { 0x01e8, 0x0000 },
  654. { 0x01ea, 0x0000 },
  655. { 0x01eb, 0x0000 },
  656. { 0x01ec, 0x0000 },
  657. { 0x01ed, 0x0000 },
  658. { 0x01ee, 0x0000 },
  659. { 0x01ef, 0x0000 },
  660. { 0x01f0, 0x0000 },
  661. { 0x01f1, 0x0000 },
  662. { 0x01f2, 0x0000 },
  663. { 0x0200, 0x0000 },
  664. { 0x0201, 0x2244 },
  665. { 0x0202, 0xaaaa },
  666. { 0x0250, 0x8010 },
  667. { 0x0251, 0x0000 },
  668. { 0x0252, 0x028a },
  669. { 0x02fa, 0x0000 },
  670. { 0x02fb, 0x0000 },
  671. { 0x02fc, 0x0000 },
  672. { 0x0300, 0x0000 },
  673. { 0x03d0, 0x0000 },
  674. { 0x03d1, 0x0000 },
  675. { 0x03d2, 0x0000 },
  676. { 0x03d3, 0x0000 },
  677. { 0x03d4, 0x2000 },
  678. { 0x03d5, 0x2000 },
  679. { 0x03d6, 0x0000 },
  680. { 0x03d7, 0x0000 },
  681. { 0x03d8, 0x2000 },
  682. { 0x03d9, 0x2000 },
  683. { 0x03da, 0x2000 },
  684. { 0x03db, 0x2000 },
  685. { 0x03dc, 0x0000 },
  686. { 0x03dd, 0x0000 },
  687. { 0x03de, 0x0000 },
  688. { 0x03df, 0x2000 },
  689. { 0x03e0, 0x0000 },
  690. { 0x03e1, 0x0000 },
  691. { 0x03e2, 0x0000 },
  692. { 0x03e3, 0x0000 },
  693. { 0x03e4, 0x0000 },
  694. { 0x03e5, 0x0000 },
  695. { 0x03e6, 0x0000 },
  696. { 0x03e7, 0x0000 },
  697. { 0x03e8, 0x0000 },
  698. { 0x03e9, 0x0000 },
  699. { 0x03ea, 0x0000 },
  700. { 0x03eb, 0x0000 },
  701. { 0x03ec, 0x0000 },
  702. { 0x03ed, 0x0000 },
  703. { 0x03ee, 0x0000 },
  704. { 0x03ef, 0x0000 },
  705. { 0x03f0, 0x0800 },
  706. { 0x03f1, 0x0800 },
  707. { 0x03f2, 0x0800 },
  708. { 0x03f3, 0x0800 },
  709. };
  710. static bool rt5663_volatile_register(struct device *dev, unsigned int reg)
  711. {
  712. switch (reg) {
  713. case RT5663_RESET:
  714. case RT5663_SIL_DET_CTL:
  715. case RT5663_HP_IMP_GAIN_2:
  716. case RT5663_AD_DA_MIXER:
  717. case RT5663_FRAC_DIV_2:
  718. case RT5663_MICBIAS_1:
  719. case RT5663_ASRC_11_2:
  720. case RT5663_ADC_EQ_1:
  721. case RT5663_INT_ST_1:
  722. case RT5663_INT_ST_2:
  723. case RT5663_GPIO_STA:
  724. case RT5663_SIN_GEN_1:
  725. case RT5663_IL_CMD_1:
  726. case RT5663_IL_CMD_5:
  727. case RT5663_IL_CMD_PWRSAV1:
  728. case RT5663_EM_JACK_TYPE_1:
  729. case RT5663_EM_JACK_TYPE_2:
  730. case RT5663_EM_JACK_TYPE_3:
  731. case RT5663_JD_CTRL2:
  732. case RT5663_VENDOR_ID:
  733. case RT5663_VENDOR_ID_1:
  734. case RT5663_VENDOR_ID_2:
  735. case RT5663_PLL_INT_REG:
  736. case RT5663_SOFT_RAMP:
  737. case RT5663_STO_DRE_1:
  738. case RT5663_STO_DRE_5:
  739. case RT5663_STO_DRE_6:
  740. case RT5663_STO_DRE_7:
  741. case RT5663_MIC_DECRO_1:
  742. case RT5663_MIC_DECRO_4:
  743. case RT5663_HP_IMP_SEN_1:
  744. case RT5663_HP_IMP_SEN_3:
  745. case RT5663_HP_IMP_SEN_4:
  746. case RT5663_HP_IMP_SEN_5:
  747. case RT5663_HP_CALIB_1_1:
  748. case RT5663_HP_CALIB_9:
  749. case RT5663_HP_CALIB_ST1:
  750. case RT5663_HP_CALIB_ST2:
  751. case RT5663_HP_CALIB_ST3:
  752. case RT5663_HP_CALIB_ST4:
  753. case RT5663_HP_CALIB_ST5:
  754. case RT5663_HP_CALIB_ST6:
  755. case RT5663_HP_CALIB_ST7:
  756. case RT5663_HP_CALIB_ST8:
  757. case RT5663_HP_CALIB_ST9:
  758. case RT5663_ANA_JD:
  759. return true;
  760. default:
  761. return false;
  762. }
  763. }
  764. static bool rt5663_readable_register(struct device *dev, unsigned int reg)
  765. {
  766. switch (reg) {
  767. case RT5663_RESET:
  768. case RT5663_HP_OUT_EN:
  769. case RT5663_HP_LCH_DRE:
  770. case RT5663_HP_RCH_DRE:
  771. case RT5663_CALIB_BST:
  772. case RT5663_RECMIX:
  773. case RT5663_SIL_DET_CTL:
  774. case RT5663_PWR_SAV_SILDET:
  775. case RT5663_SIDETONE_CTL:
  776. case RT5663_STO1_DAC_DIG_VOL:
  777. case RT5663_STO1_ADC_DIG_VOL:
  778. case RT5663_STO1_BOOST:
  779. case RT5663_HP_IMP_GAIN_1:
  780. case RT5663_HP_IMP_GAIN_2:
  781. case RT5663_STO1_ADC_MIXER:
  782. case RT5663_AD_DA_MIXER:
  783. case RT5663_STO_DAC_MIXER:
  784. case RT5663_DIG_SIDE_MIXER:
  785. case RT5663_BYPASS_STO_DAC:
  786. case RT5663_CALIB_REC_MIX:
  787. case RT5663_PWR_DIG_1:
  788. case RT5663_PWR_DIG_2:
  789. case RT5663_PWR_ANLG_1:
  790. case RT5663_PWR_ANLG_2:
  791. case RT5663_PWR_ANLG_3:
  792. case RT5663_PWR_MIXER:
  793. case RT5663_SIG_CLK_DET:
  794. case RT5663_PRE_DIV_GATING_1:
  795. case RT5663_PRE_DIV_GATING_2:
  796. case RT5663_I2S1_SDP:
  797. case RT5663_ADDA_CLK_1:
  798. case RT5663_ADDA_RST:
  799. case RT5663_FRAC_DIV_1:
  800. case RT5663_FRAC_DIV_2:
  801. case RT5663_TDM_1:
  802. case RT5663_TDM_2:
  803. case RT5663_TDM_3:
  804. case RT5663_TDM_4:
  805. case RT5663_TDM_5:
  806. case RT5663_GLB_CLK:
  807. case RT5663_PLL_1:
  808. case RT5663_PLL_2:
  809. case RT5663_ASRC_1:
  810. case RT5663_ASRC_2:
  811. case RT5663_ASRC_4:
  812. case RT5663_DUMMY_REG:
  813. case RT5663_ASRC_8:
  814. case RT5663_ASRC_9:
  815. case RT5663_ASRC_11:
  816. case RT5663_DEPOP_1:
  817. case RT5663_DEPOP_2:
  818. case RT5663_DEPOP_3:
  819. case RT5663_HP_CHARGE_PUMP_1:
  820. case RT5663_HP_CHARGE_PUMP_2:
  821. case RT5663_MICBIAS_1:
  822. case RT5663_RC_CLK:
  823. case RT5663_ASRC_11_2:
  824. case RT5663_DUMMY_REG_2:
  825. case RT5663_REC_PATH_GAIN:
  826. case RT5663_AUTO_1MRC_CLK:
  827. case RT5663_ADC_EQ_1:
  828. case RT5663_ADC_EQ_2:
  829. case RT5663_IRQ_1:
  830. case RT5663_IRQ_2:
  831. case RT5663_IRQ_3:
  832. case RT5663_IRQ_4:
  833. case RT5663_IRQ_5:
  834. case RT5663_INT_ST_1:
  835. case RT5663_INT_ST_2:
  836. case RT5663_GPIO_1:
  837. case RT5663_GPIO_2:
  838. case RT5663_GPIO_STA:
  839. case RT5663_SIN_GEN_1:
  840. case RT5663_SIN_GEN_2:
  841. case RT5663_SIN_GEN_3:
  842. case RT5663_SOF_VOL_ZC1:
  843. case RT5663_IL_CMD_1:
  844. case RT5663_IL_CMD_2:
  845. case RT5663_IL_CMD_3:
  846. case RT5663_IL_CMD_4:
  847. case RT5663_IL_CMD_5:
  848. case RT5663_IL_CMD_6:
  849. case RT5663_IL_CMD_7:
  850. case RT5663_IL_CMD_8:
  851. case RT5663_IL_CMD_PWRSAV1:
  852. case RT5663_IL_CMD_PWRSAV2:
  853. case RT5663_EM_JACK_TYPE_1:
  854. case RT5663_EM_JACK_TYPE_2:
  855. case RT5663_EM_JACK_TYPE_3:
  856. case RT5663_EM_JACK_TYPE_4:
  857. case RT5663_EM_JACK_TYPE_5:
  858. case RT5663_EM_JACK_TYPE_6:
  859. case RT5663_STO1_HPF_ADJ1:
  860. case RT5663_STO1_HPF_ADJ2:
  861. case RT5663_FAST_OFF_MICBIAS:
  862. case RT5663_JD_CTRL1:
  863. case RT5663_JD_CTRL2:
  864. case RT5663_DIG_MISC:
  865. case RT5663_VENDOR_ID:
  866. case RT5663_VENDOR_ID_1:
  867. case RT5663_VENDOR_ID_2:
  868. case RT5663_DIG_VOL_ZCD:
  869. case RT5663_ANA_BIAS_CUR_1:
  870. case RT5663_ANA_BIAS_CUR_2:
  871. case RT5663_ANA_BIAS_CUR_3:
  872. case RT5663_ANA_BIAS_CUR_4:
  873. case RT5663_ANA_BIAS_CUR_5:
  874. case RT5663_ANA_BIAS_CUR_6:
  875. case RT5663_BIAS_CUR_5:
  876. case RT5663_BIAS_CUR_6:
  877. case RT5663_BIAS_CUR_7:
  878. case RT5663_BIAS_CUR_8:
  879. case RT5663_DACREF_LDO:
  880. case RT5663_DUMMY_REG_3:
  881. case RT5663_BIAS_CUR_9:
  882. case RT5663_DUMMY_REG_4:
  883. case RT5663_VREFADJ_OP:
  884. case RT5663_VREF_RECMIX:
  885. case RT5663_CHARGE_PUMP_1:
  886. case RT5663_CHARGE_PUMP_1_2:
  887. case RT5663_CHARGE_PUMP_1_3:
  888. case RT5663_CHARGE_PUMP_2:
  889. case RT5663_DIG_IN_PIN1:
  890. case RT5663_PAD_DRV_CTL:
  891. case RT5663_PLL_INT_REG:
  892. case RT5663_CHOP_DAC_L:
  893. case RT5663_CHOP_ADC:
  894. case RT5663_CALIB_ADC:
  895. case RT5663_CHOP_DAC_R:
  896. case RT5663_DUMMY_CTL_DACLR:
  897. case RT5663_DUMMY_REG_5:
  898. case RT5663_SOFT_RAMP:
  899. case RT5663_TEST_MODE_1:
  900. case RT5663_TEST_MODE_2:
  901. case RT5663_TEST_MODE_3:
  902. case RT5663_STO_DRE_1:
  903. case RT5663_STO_DRE_2:
  904. case RT5663_STO_DRE_3:
  905. case RT5663_STO_DRE_4:
  906. case RT5663_STO_DRE_5:
  907. case RT5663_STO_DRE_6:
  908. case RT5663_STO_DRE_7:
  909. case RT5663_STO_DRE_8:
  910. case RT5663_STO_DRE_9:
  911. case RT5663_STO_DRE_10:
  912. case RT5663_MIC_DECRO_1:
  913. case RT5663_MIC_DECRO_2:
  914. case RT5663_MIC_DECRO_3:
  915. case RT5663_MIC_DECRO_4:
  916. case RT5663_MIC_DECRO_5:
  917. case RT5663_MIC_DECRO_6:
  918. case RT5663_HP_DECRO_1:
  919. case RT5663_HP_DECRO_2:
  920. case RT5663_HP_DECRO_3:
  921. case RT5663_HP_DECRO_4:
  922. case RT5663_HP_DECOUP:
  923. case RT5663_HP_IMP_SEN_MAP8:
  924. case RT5663_HP_IMP_SEN_MAP9:
  925. case RT5663_HP_IMP_SEN_MAP10:
  926. case RT5663_HP_IMP_SEN_MAP11:
  927. case RT5663_HP_IMP_SEN_1:
  928. case RT5663_HP_IMP_SEN_2:
  929. case RT5663_HP_IMP_SEN_3:
  930. case RT5663_HP_IMP_SEN_4:
  931. case RT5663_HP_IMP_SEN_5:
  932. case RT5663_HP_IMP_SEN_6:
  933. case RT5663_HP_IMP_SEN_7:
  934. case RT5663_HP_IMP_SEN_8:
  935. case RT5663_HP_IMP_SEN_9:
  936. case RT5663_HP_IMP_SEN_10:
  937. case RT5663_HP_IMP_SEN_11:
  938. case RT5663_HP_IMP_SEN_12:
  939. case RT5663_HP_IMP_SEN_13:
  940. case RT5663_HP_IMP_SEN_14:
  941. case RT5663_HP_IMP_SEN_15:
  942. case RT5663_HP_IMP_SEN_16:
  943. case RT5663_HP_IMP_SEN_17:
  944. case RT5663_HP_IMP_SEN_18:
  945. case RT5663_HP_IMP_SEN_19:
  946. case RT5663_HP_IMPSEN_DIG5:
  947. case RT5663_HP_IMPSEN_MAP1:
  948. case RT5663_HP_IMPSEN_MAP2:
  949. case RT5663_HP_IMPSEN_MAP3:
  950. case RT5663_HP_IMPSEN_MAP4:
  951. case RT5663_HP_IMPSEN_MAP5:
  952. case RT5663_HP_IMPSEN_MAP7:
  953. case RT5663_HP_LOGIC_1:
  954. case RT5663_HP_LOGIC_2:
  955. case RT5663_HP_CALIB_1:
  956. case RT5663_HP_CALIB_1_1:
  957. case RT5663_HP_CALIB_2:
  958. case RT5663_HP_CALIB_3:
  959. case RT5663_HP_CALIB_4:
  960. case RT5663_HP_CALIB_5:
  961. case RT5663_HP_CALIB_5_1:
  962. case RT5663_HP_CALIB_6:
  963. case RT5663_HP_CALIB_7:
  964. case RT5663_HP_CALIB_9:
  965. case RT5663_HP_CALIB_10:
  966. case RT5663_HP_CALIB_11:
  967. case RT5663_HP_CALIB_ST1:
  968. case RT5663_HP_CALIB_ST2:
  969. case RT5663_HP_CALIB_ST3:
  970. case RT5663_HP_CALIB_ST4:
  971. case RT5663_HP_CALIB_ST5:
  972. case RT5663_HP_CALIB_ST6:
  973. case RT5663_HP_CALIB_ST7:
  974. case RT5663_HP_CALIB_ST8:
  975. case RT5663_HP_CALIB_ST9:
  976. case RT5663_HP_AMP_DET:
  977. case RT5663_DUMMY_REG_6:
  978. case RT5663_HP_BIAS:
  979. case RT5663_CBJ_1:
  980. case RT5663_CBJ_2:
  981. case RT5663_CBJ_3:
  982. case RT5663_DUMMY_1:
  983. case RT5663_DUMMY_2:
  984. case RT5663_DUMMY_3:
  985. case RT5663_ANA_JD:
  986. case RT5663_ADC_LCH_LPF1_A1:
  987. case RT5663_ADC_RCH_LPF1_A1:
  988. case RT5663_ADC_LCH_LPF1_H0:
  989. case RT5663_ADC_RCH_LPF1_H0:
  990. case RT5663_ADC_LCH_BPF1_A1:
  991. case RT5663_ADC_RCH_BPF1_A1:
  992. case RT5663_ADC_LCH_BPF1_A2:
  993. case RT5663_ADC_RCH_BPF1_A2:
  994. case RT5663_ADC_LCH_BPF1_H0:
  995. case RT5663_ADC_RCH_BPF1_H0:
  996. case RT5663_ADC_LCH_BPF2_A1:
  997. case RT5663_ADC_RCH_BPF2_A1:
  998. case RT5663_ADC_LCH_BPF2_A2:
  999. case RT5663_ADC_RCH_BPF2_A2:
  1000. case RT5663_ADC_LCH_BPF2_H0:
  1001. case RT5663_ADC_RCH_BPF2_H0:
  1002. case RT5663_ADC_LCH_BPF3_A1:
  1003. case RT5663_ADC_RCH_BPF3_A1:
  1004. case RT5663_ADC_LCH_BPF3_A2:
  1005. case RT5663_ADC_RCH_BPF3_A2:
  1006. case RT5663_ADC_LCH_BPF3_H0:
  1007. case RT5663_ADC_RCH_BPF3_H0:
  1008. case RT5663_ADC_LCH_BPF4_A1:
  1009. case RT5663_ADC_RCH_BPF4_A1:
  1010. case RT5663_ADC_LCH_BPF4_A2:
  1011. case RT5663_ADC_RCH_BPF4_A2:
  1012. case RT5663_ADC_LCH_BPF4_H0:
  1013. case RT5663_ADC_RCH_BPF4_H0:
  1014. case RT5663_ADC_LCH_HPF1_A1:
  1015. case RT5663_ADC_RCH_HPF1_A1:
  1016. case RT5663_ADC_LCH_HPF1_H0:
  1017. case RT5663_ADC_RCH_HPF1_H0:
  1018. case RT5663_ADC_EQ_PRE_VOL_L:
  1019. case RT5663_ADC_EQ_PRE_VOL_R:
  1020. case RT5663_ADC_EQ_POST_VOL_L:
  1021. case RT5663_ADC_EQ_POST_VOL_R:
  1022. return true;
  1023. default:
  1024. return false;
  1025. }
  1026. }
  1027. static bool rt5668_volatile_register(struct device *dev, unsigned int reg)
  1028. {
  1029. switch (reg) {
  1030. case RT5663_RESET:
  1031. case RT5668_CBJ_TYPE_2:
  1032. case RT5668_PDM_OUT_CTL:
  1033. case RT5668_PDM_I2C_DATA_CTL1:
  1034. case RT5668_PDM_I2C_DATA_CTL4:
  1035. case RT5668_ALC_BK_GAIN:
  1036. case RT5663_PLL_2:
  1037. case RT5663_MICBIAS_1:
  1038. case RT5663_ADC_EQ_1:
  1039. case RT5663_INT_ST_1:
  1040. case RT5668_GPIO_STA:
  1041. case RT5663_IL_CMD_1:
  1042. case RT5663_IL_CMD_5:
  1043. case RT5668_A_JD_CTRL:
  1044. case RT5663_JD_CTRL2:
  1045. case RT5663_VENDOR_ID:
  1046. case RT5663_VENDOR_ID_1:
  1047. case RT5663_VENDOR_ID_2:
  1048. case RT5663_STO_DRE_1:
  1049. case RT5663_STO_DRE_5:
  1050. case RT5663_STO_DRE_6:
  1051. case RT5663_STO_DRE_7:
  1052. case RT5668_MONO_DYNA_6:
  1053. case RT5668_STO1_SIL_DET:
  1054. case RT5668_MONOL_SIL_DET:
  1055. case RT5668_MONOR_SIL_DET:
  1056. case RT5668_STO2_DAC_SIL:
  1057. case RT5668_MONO_AMP_CAL_ST1:
  1058. case RT5668_MONO_AMP_CAL_ST2:
  1059. case RT5668_MONO_AMP_CAL_ST3:
  1060. case RT5668_MONO_AMP_CAL_ST4:
  1061. case RT5663_HP_IMP_SEN_2:
  1062. case RT5663_HP_IMP_SEN_3:
  1063. case RT5663_HP_IMP_SEN_4:
  1064. case RT5663_HP_IMP_SEN_10:
  1065. case RT5663_HP_CALIB_1:
  1066. case RT5663_HP_CALIB_10:
  1067. case RT5663_HP_CALIB_ST1:
  1068. case RT5663_HP_CALIB_ST4:
  1069. case RT5663_HP_CALIB_ST5:
  1070. case RT5663_HP_CALIB_ST6:
  1071. case RT5663_HP_CALIB_ST7:
  1072. case RT5663_HP_CALIB_ST8:
  1073. case RT5663_HP_CALIB_ST9:
  1074. case RT5668_HP_CALIB_ST10:
  1075. case RT5668_HP_CALIB_ST11:
  1076. return true;
  1077. default:
  1078. return false;
  1079. }
  1080. }
  1081. static bool rt5668_readable_register(struct device *dev, unsigned int reg)
  1082. {
  1083. switch (reg) {
  1084. case RT5668_LOUT_CTRL:
  1085. case RT5668_HP_AMP_2:
  1086. case RT5668_MONO_OUT:
  1087. case RT5668_MONO_GAIN:
  1088. case RT5668_AEC_BST:
  1089. case RT5668_IN1_IN2:
  1090. case RT5668_IN3_IN4:
  1091. case RT5668_INL1_INR1:
  1092. case RT5668_CBJ_TYPE_2:
  1093. case RT5668_CBJ_TYPE_3:
  1094. case RT5668_CBJ_TYPE_4:
  1095. case RT5668_CBJ_TYPE_5:
  1096. case RT5668_CBJ_TYPE_8:
  1097. case RT5668_DAC3_DIG_VOL:
  1098. case RT5668_DAC3_CTRL:
  1099. case RT5668_MONO_ADC_DIG_VOL:
  1100. case RT5668_STO2_ADC_DIG_VOL:
  1101. case RT5668_MONO_ADC_BST_GAIN:
  1102. case RT5668_STO2_ADC_BST_GAIN:
  1103. case RT5668_SIDETONE_CTRL:
  1104. case RT5668_MONO1_ADC_MIXER:
  1105. case RT5668_STO2_ADC_MIXER:
  1106. case RT5668_MONO_DAC_MIXER:
  1107. case RT5668_DAC2_SRC_CTRL:
  1108. case RT5668_IF_3_4_DATA_CTL:
  1109. case RT5668_IF_5_DATA_CTL:
  1110. case RT5668_PDM_OUT_CTL:
  1111. case RT5668_PDM_I2C_DATA_CTL1:
  1112. case RT5668_PDM_I2C_DATA_CTL2:
  1113. case RT5668_PDM_I2C_DATA_CTL3:
  1114. case RT5668_PDM_I2C_DATA_CTL4:
  1115. case RT5668_RECMIX1_NEW:
  1116. case RT5668_RECMIX1L_0:
  1117. case RT5668_RECMIX1L:
  1118. case RT5668_RECMIX1R_0:
  1119. case RT5668_RECMIX1R:
  1120. case RT5668_RECMIX2_NEW:
  1121. case RT5668_RECMIX2_L_2:
  1122. case RT5668_RECMIX2_R:
  1123. case RT5668_RECMIX2_R_2:
  1124. case RT5668_CALIB_REC_LR:
  1125. case RT5668_ALC_BK_GAIN:
  1126. case RT5668_MONOMIX_GAIN:
  1127. case RT5668_MONOMIX_IN_GAIN:
  1128. case RT5668_OUT_MIXL_GAIN:
  1129. case RT5668_OUT_LMIX_IN_GAIN:
  1130. case RT5668_OUT_RMIX_IN_GAIN:
  1131. case RT5668_OUT_RMIX_IN_GAIN1:
  1132. case RT5668_LOUT_MIXER_CTRL:
  1133. case RT5668_PWR_VOL:
  1134. case RT5668_ADCDAC_RST:
  1135. case RT5668_I2S34_SDP:
  1136. case RT5668_I2S5_SDP:
  1137. case RT5668_TDM_5:
  1138. case RT5668_TDM_6:
  1139. case RT5668_TDM_7:
  1140. case RT5668_TDM_8:
  1141. case RT5668_ASRC_3:
  1142. case RT5668_ASRC_6:
  1143. case RT5668_ASRC_7:
  1144. case RT5668_PLL_TRK_13:
  1145. case RT5668_I2S_M_CLK_CTL:
  1146. case RT5668_FDIV_I2S34_M_CLK:
  1147. case RT5668_FDIV_I2S34_M_CLK2:
  1148. case RT5668_FDIV_I2S5_M_CLK:
  1149. case RT5668_FDIV_I2S5_M_CLK2:
  1150. case RT5668_IRQ_4:
  1151. case RT5668_GPIO_3:
  1152. case RT5668_GPIO_4:
  1153. case RT5668_GPIO_STA:
  1154. case RT5668_HP_AMP_DET1:
  1155. case RT5668_HP_AMP_DET2:
  1156. case RT5668_HP_AMP_DET3:
  1157. case RT5668_MID_BD_HP_AMP:
  1158. case RT5668_LOW_BD_HP_AMP:
  1159. case RT5668_SOF_VOL_ZC2:
  1160. case RT5668_ADC_STO2_ADJ1:
  1161. case RT5668_ADC_STO2_ADJ2:
  1162. case RT5668_A_JD_CTRL:
  1163. case RT5668_JD1_TRES_CTRL:
  1164. case RT5668_JD2_TRES_CTRL:
  1165. case RT5668_JD_CTRL2:
  1166. case RT5668_DUM_REG_2:
  1167. case RT5668_DUM_REG_3:
  1168. case RT5663_VENDOR_ID:
  1169. case RT5663_VENDOR_ID_1:
  1170. case RT5663_VENDOR_ID_2:
  1171. case RT5668_DACADC_DIG_VOL2:
  1172. case RT5668_DIG_IN_PIN2:
  1173. case RT5668_PAD_DRV_CTL1:
  1174. case RT5668_SOF_RAM_DEPOP:
  1175. case RT5668_VOL_TEST:
  1176. case RT5668_TEST_MODE_3:
  1177. case RT5668_TEST_MODE_4:
  1178. case RT5663_STO_DRE_9:
  1179. case RT5668_MONO_DYNA_1:
  1180. case RT5668_MONO_DYNA_2:
  1181. case RT5668_MONO_DYNA_3:
  1182. case RT5668_MONO_DYNA_4:
  1183. case RT5668_MONO_DYNA_5:
  1184. case RT5668_MONO_DYNA_6:
  1185. case RT5668_STO1_SIL_DET:
  1186. case RT5668_MONOL_SIL_DET:
  1187. case RT5668_MONOR_SIL_DET:
  1188. case RT5668_STO2_DAC_SIL:
  1189. case RT5668_PWR_SAV_CTL1:
  1190. case RT5668_PWR_SAV_CTL2:
  1191. case RT5668_PWR_SAV_CTL3:
  1192. case RT5668_PWR_SAV_CTL4:
  1193. case RT5668_PWR_SAV_CTL5:
  1194. case RT5668_PWR_SAV_CTL6:
  1195. case RT5668_MONO_AMP_CAL1:
  1196. case RT5668_MONO_AMP_CAL2:
  1197. case RT5668_MONO_AMP_CAL3:
  1198. case RT5668_MONO_AMP_CAL4:
  1199. case RT5668_MONO_AMP_CAL5:
  1200. case RT5668_MONO_AMP_CAL6:
  1201. case RT5668_MONO_AMP_CAL7:
  1202. case RT5668_MONO_AMP_CAL_ST1:
  1203. case RT5668_MONO_AMP_CAL_ST2:
  1204. case RT5668_MONO_AMP_CAL_ST3:
  1205. case RT5668_MONO_AMP_CAL_ST4:
  1206. case RT5668_MONO_AMP_CAL_ST5:
  1207. case RT5668_HP_IMP_SEN_13:
  1208. case RT5668_HP_IMP_SEN_14:
  1209. case RT5668_HP_IMP_SEN_6:
  1210. case RT5668_HP_IMP_SEN_7:
  1211. case RT5668_HP_IMP_SEN_8:
  1212. case RT5668_HP_IMP_SEN_9:
  1213. case RT5668_HP_IMP_SEN_10:
  1214. case RT5668_HP_LOGIC_3:
  1215. case RT5668_HP_CALIB_ST10:
  1216. case RT5668_HP_CALIB_ST11:
  1217. case RT5668_PRO_REG_TBL_4:
  1218. case RT5668_PRO_REG_TBL_5:
  1219. case RT5668_PRO_REG_TBL_6:
  1220. case RT5668_PRO_REG_TBL_7:
  1221. case RT5668_PRO_REG_TBL_8:
  1222. case RT5668_PRO_REG_TBL_9:
  1223. case RT5668_SAR_ADC_INL_1:
  1224. case RT5668_SAR_ADC_INL_2:
  1225. case RT5668_SAR_ADC_INL_3:
  1226. case RT5668_SAR_ADC_INL_4:
  1227. case RT5668_SAR_ADC_INL_5:
  1228. case RT5668_SAR_ADC_INL_6:
  1229. case RT5668_SAR_ADC_INL_7:
  1230. case RT5668_SAR_ADC_INL_8:
  1231. case RT5668_SAR_ADC_INL_9:
  1232. case RT5668_SAR_ADC_INL_10:
  1233. case RT5668_SAR_ADC_INL_11:
  1234. case RT5668_SAR_ADC_INL_12:
  1235. case RT5668_DRC_CTRL_1:
  1236. case RT5668_DRC1_CTRL_2:
  1237. case RT5668_DRC1_CTRL_3:
  1238. case RT5668_DRC1_CTRL_4:
  1239. case RT5668_DRC1_CTRL_5:
  1240. case RT5668_DRC1_CTRL_6:
  1241. case RT5668_DRC1_HD_CTRL_1:
  1242. case RT5668_DRC1_HD_CTRL_2:
  1243. case RT5668_DRC1_PRI_REG_1:
  1244. case RT5668_DRC1_PRI_REG_2:
  1245. case RT5668_DRC1_PRI_REG_3:
  1246. case RT5668_DRC1_PRI_REG_4:
  1247. case RT5668_DRC1_PRI_REG_5:
  1248. case RT5668_DRC1_PRI_REG_6:
  1249. case RT5668_DRC1_PRI_REG_7:
  1250. case RT5668_DRC1_PRI_REG_8:
  1251. case RT5668_ALC_PGA_CTL_1:
  1252. case RT5668_ALC_PGA_CTL_2:
  1253. case RT5668_ALC_PGA_CTL_3:
  1254. case RT5668_ALC_PGA_CTL_4:
  1255. case RT5668_ALC_PGA_CTL_5:
  1256. case RT5668_ALC_PGA_CTL_6:
  1257. case RT5668_ALC_PGA_CTL_7:
  1258. case RT5668_ALC_PGA_CTL_8:
  1259. case RT5668_ALC_PGA_REG_1:
  1260. case RT5668_ALC_PGA_REG_2:
  1261. case RT5668_ALC_PGA_REG_3:
  1262. case RT5668_ADC_EQ_RECOV_1:
  1263. case RT5668_ADC_EQ_RECOV_2:
  1264. case RT5668_ADC_EQ_RECOV_3:
  1265. case RT5668_ADC_EQ_RECOV_4:
  1266. case RT5668_ADC_EQ_RECOV_5:
  1267. case RT5668_ADC_EQ_RECOV_6:
  1268. case RT5668_ADC_EQ_RECOV_7:
  1269. case RT5668_ADC_EQ_RECOV_8:
  1270. case RT5668_ADC_EQ_RECOV_9:
  1271. case RT5668_ADC_EQ_RECOV_10:
  1272. case RT5668_ADC_EQ_RECOV_11:
  1273. case RT5668_ADC_EQ_RECOV_12:
  1274. case RT5668_ADC_EQ_RECOV_13:
  1275. case RT5668_VID_HIDDEN:
  1276. case RT5668_VID_CUSTOMER:
  1277. case RT5668_SCAN_MODE:
  1278. case RT5668_I2C_BYPA:
  1279. return true;
  1280. case RT5663_TDM_1:
  1281. case RT5663_DEPOP_3:
  1282. case RT5663_ASRC_11_2:
  1283. case RT5663_INT_ST_2:
  1284. case RT5663_GPIO_STA:
  1285. case RT5663_SIN_GEN_1:
  1286. case RT5663_SIN_GEN_2:
  1287. case RT5663_SIN_GEN_3:
  1288. case RT5663_IL_CMD_PWRSAV1:
  1289. case RT5663_IL_CMD_PWRSAV2:
  1290. case RT5663_EM_JACK_TYPE_1:
  1291. case RT5663_EM_JACK_TYPE_2:
  1292. case RT5663_EM_JACK_TYPE_3:
  1293. case RT5663_EM_JACK_TYPE_4:
  1294. case RT5663_FAST_OFF_MICBIAS:
  1295. case RT5663_ANA_BIAS_CUR_1:
  1296. case RT5663_ANA_BIAS_CUR_2:
  1297. case RT5663_BIAS_CUR_9:
  1298. case RT5663_DUMMY_REG_4:
  1299. case RT5663_VREF_RECMIX:
  1300. case RT5663_CHARGE_PUMP_1_2:
  1301. case RT5663_CHARGE_PUMP_1_3:
  1302. case RT5663_CHARGE_PUMP_2:
  1303. case RT5663_CHOP_DAC_R:
  1304. case RT5663_DUMMY_CTL_DACLR:
  1305. case RT5663_DUMMY_REG_5:
  1306. case RT5663_SOFT_RAMP:
  1307. case RT5663_TEST_MODE_1:
  1308. case RT5663_STO_DRE_10:
  1309. case RT5663_MIC_DECRO_1:
  1310. case RT5663_MIC_DECRO_2:
  1311. case RT5663_MIC_DECRO_3:
  1312. case RT5663_MIC_DECRO_4:
  1313. case RT5663_MIC_DECRO_5:
  1314. case RT5663_MIC_DECRO_6:
  1315. case RT5663_HP_DECRO_1:
  1316. case RT5663_HP_DECRO_2:
  1317. case RT5663_HP_DECRO_3:
  1318. case RT5663_HP_DECRO_4:
  1319. case RT5663_HP_DECOUP:
  1320. case RT5663_HP_IMPSEN_MAP4:
  1321. case RT5663_HP_IMPSEN_MAP5:
  1322. case RT5663_HP_IMPSEN_MAP7:
  1323. case RT5663_HP_CALIB_1:
  1324. case RT5663_CBJ_1:
  1325. case RT5663_CBJ_2:
  1326. case RT5663_CBJ_3:
  1327. return false;
  1328. default:
  1329. return rt5663_readable_register(dev, reg);
  1330. }
  1331. }
  1332. static const DECLARE_TLV_DB_SCALE(rt5663_hp_vol_tlv, -2400, 150, 0);
  1333. static const DECLARE_TLV_DB_SCALE(rt5668_hp_vol_tlv, -2250, 150, 0);
  1334. static const DECLARE_TLV_DB_SCALE(dac_vol_tlv, -6525, 75, 0);
  1335. static const DECLARE_TLV_DB_SCALE(adc_vol_tlv, -1725, 75, 0);
  1336. /* {0, +20, +24, +30, +35, +40, +44, +50, +52} dB */
  1337. static const DECLARE_TLV_DB_RANGE(in_bst_tlv,
  1338. 0, 0, TLV_DB_SCALE_ITEM(0, 0, 0),
  1339. 1, 1, TLV_DB_SCALE_ITEM(2000, 0, 0),
  1340. 2, 2, TLV_DB_SCALE_ITEM(2400, 0, 0),
  1341. 3, 5, TLV_DB_SCALE_ITEM(3000, 500, 0),
  1342. 6, 6, TLV_DB_SCALE_ITEM(4400, 0, 0),
  1343. 7, 7, TLV_DB_SCALE_ITEM(5000, 0, 0),
  1344. 8, 8, TLV_DB_SCALE_ITEM(5200, 0, 0)
  1345. );
  1346. /* Interface data select */
  1347. static const char * const rt5663_if1_adc_data_select[] = {
  1348. "L/R", "R/L", "L/L", "R/R"
  1349. };
  1350. static SOC_ENUM_SINGLE_DECL(rt5663_if1_adc_enum, RT5663_TDM_2,
  1351. RT5663_DATA_SWAP_ADCDAT1_SHIFT, rt5663_if1_adc_data_select);
  1352. static void rt5663_enable_push_button_irq(struct snd_soc_codec *codec,
  1353. bool enable)
  1354. {
  1355. struct rt5663_priv *rt5663 = snd_soc_codec_get_drvdata(codec);
  1356. if (enable) {
  1357. snd_soc_update_bits(codec, RT5663_IL_CMD_6,
  1358. RT5668_EN_4BTN_INL_MASK, RT5668_EN_4BTN_INL_EN);
  1359. /* reset in-line command */
  1360. snd_soc_update_bits(codec, RT5663_IL_CMD_6,
  1361. RT5668_RESET_4BTN_INL_MASK,
  1362. RT5668_RESET_4BTN_INL_RESET);
  1363. snd_soc_update_bits(codec, RT5663_IL_CMD_6,
  1364. RT5668_RESET_4BTN_INL_MASK,
  1365. RT5668_RESET_4BTN_INL_NOR);
  1366. switch (rt5663->codec_type) {
  1367. case CODEC_TYPE_RT5668:
  1368. snd_soc_update_bits(codec, RT5663_IRQ_3,
  1369. RT5668_EN_IRQ_INLINE_MASK,
  1370. RT5668_EN_IRQ_INLINE_NOR);
  1371. break;
  1372. case CODEC_TYPE_RT5663:
  1373. snd_soc_update_bits(codec, RT5663_IRQ_2,
  1374. RT5663_EN_IRQ_INLINE_MASK,
  1375. RT5663_EN_IRQ_INLINE_NOR);
  1376. break;
  1377. default:
  1378. dev_err(codec->dev, "Unknown CODEC_TYPE\n");
  1379. }
  1380. } else {
  1381. switch (rt5663->codec_type) {
  1382. case CODEC_TYPE_RT5668:
  1383. snd_soc_update_bits(codec, RT5663_IRQ_3,
  1384. RT5668_EN_IRQ_INLINE_MASK,
  1385. RT5668_EN_IRQ_INLINE_BYP);
  1386. break;
  1387. case CODEC_TYPE_RT5663:
  1388. snd_soc_update_bits(codec, RT5663_IRQ_2,
  1389. RT5663_EN_IRQ_INLINE_MASK,
  1390. RT5663_EN_IRQ_INLINE_BYP);
  1391. break;
  1392. default:
  1393. dev_err(codec->dev, "Unknown CODEC_TYPE\n");
  1394. }
  1395. snd_soc_update_bits(codec, RT5663_IL_CMD_6,
  1396. RT5668_EN_4BTN_INL_MASK, RT5668_EN_4BTN_INL_DIS);
  1397. /* reset in-line command */
  1398. snd_soc_update_bits(codec, RT5663_IL_CMD_6,
  1399. RT5668_RESET_4BTN_INL_MASK,
  1400. RT5668_RESET_4BTN_INL_RESET);
  1401. snd_soc_update_bits(codec, RT5663_IL_CMD_6,
  1402. RT5668_RESET_4BTN_INL_MASK,
  1403. RT5668_RESET_4BTN_INL_NOR);
  1404. }
  1405. }
  1406. /**
  1407. * rt5668_jack_detect - Detect headset.
  1408. * @codec: SoC audio codec device.
  1409. * @jack_insert: Jack insert or not.
  1410. *
  1411. * Detect whether is headset or not when jack inserted.
  1412. *
  1413. * Returns detect status.
  1414. */
  1415. static int rt5668_jack_detect(struct snd_soc_codec *codec, int jack_insert)
  1416. {
  1417. struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
  1418. struct rt5663_priv *rt5668 = snd_soc_codec_get_drvdata(codec);
  1419. int val, i = 0, sleep_time[5] = {300, 150, 100, 50, 30};
  1420. dev_dbg(codec->dev, "%s jack_insert:%d\n", __func__, jack_insert);
  1421. if (jack_insert) {
  1422. snd_soc_write(codec, RT5668_CBJ_TYPE_2, 0x8040);
  1423. snd_soc_write(codec, RT5668_CBJ_TYPE_3, 0x1484);
  1424. snd_soc_dapm_force_enable_pin(dapm, "MICBIAS1");
  1425. snd_soc_dapm_force_enable_pin(dapm, "MICBIAS2");
  1426. snd_soc_dapm_force_enable_pin(dapm, "Mic Det Power");
  1427. snd_soc_dapm_force_enable_pin(dapm, "CBJ Power");
  1428. snd_soc_dapm_sync(dapm);
  1429. snd_soc_update_bits(codec, RT5663_RC_CLK,
  1430. RT5668_DIG_1M_CLK_MASK, RT5668_DIG_1M_CLK_EN);
  1431. snd_soc_update_bits(codec, RT5663_RECMIX, 0x8, 0x8);
  1432. while (i < 5) {
  1433. msleep(sleep_time[i]);
  1434. val = snd_soc_read(codec, RT5668_CBJ_TYPE_2) & 0x0003;
  1435. if (val == 0x1 || val == 0x2 || val == 0x3)
  1436. break;
  1437. dev_dbg(codec->dev, "%s: MX-0011 val=%x sleep %d\n",
  1438. __func__, val, sleep_time[i]);
  1439. i++;
  1440. }
  1441. dev_dbg(codec->dev, "%s val = %d\n", __func__, val);
  1442. switch (val) {
  1443. case 1:
  1444. case 2:
  1445. rt5668->jack_type = SND_JACK_HEADSET;
  1446. rt5663_enable_push_button_irq(codec, true);
  1447. break;
  1448. default:
  1449. snd_soc_dapm_disable_pin(dapm, "MICBIAS1");
  1450. snd_soc_dapm_disable_pin(dapm, "MICBIAS2");
  1451. snd_soc_dapm_disable_pin(dapm, "Mic Det Power");
  1452. snd_soc_dapm_disable_pin(dapm, "CBJ Power");
  1453. snd_soc_dapm_sync(dapm);
  1454. rt5668->jack_type = SND_JACK_HEADPHONE;
  1455. break;
  1456. }
  1457. } else {
  1458. snd_soc_update_bits(codec, RT5663_RECMIX, 0x8, 0x0);
  1459. if (rt5668->jack_type == SND_JACK_HEADSET) {
  1460. rt5663_enable_push_button_irq(codec, false);
  1461. snd_soc_dapm_disable_pin(dapm, "MICBIAS1");
  1462. snd_soc_dapm_disable_pin(dapm, "MICBIAS2");
  1463. snd_soc_dapm_disable_pin(dapm, "Mic Det Power");
  1464. snd_soc_dapm_disable_pin(dapm, "CBJ Power");
  1465. snd_soc_dapm_sync(dapm);
  1466. }
  1467. rt5668->jack_type = 0;
  1468. }
  1469. dev_dbg(codec->dev, "jack_type = %d\n", rt5668->jack_type);
  1470. return rt5668->jack_type;
  1471. }
  1472. /**
  1473. * rt5663_jack_detect - Detect headset.
  1474. * @codec: SoC audio codec device.
  1475. * @jack_insert: Jack insert or not.
  1476. *
  1477. * Detect whether is headset or not when jack inserted.
  1478. *
  1479. * Returns detect status.
  1480. */
  1481. static int rt5663_jack_detect(struct snd_soc_codec *codec, int jack_insert)
  1482. {
  1483. struct rt5663_priv *rt5663 = snd_soc_codec_get_drvdata(codec);
  1484. int val, i = 0, sleep_time[5] = {300, 150, 100, 50, 30};
  1485. dev_dbg(codec->dev, "%s jack_insert:%d\n", __func__, jack_insert);
  1486. if (jack_insert) {
  1487. snd_soc_update_bits(codec, RT5663_DIG_MISC,
  1488. RT5668_DIG_GATE_CTRL_MASK, RT5668_DIG_GATE_CTRL_EN);
  1489. snd_soc_update_bits(codec, RT5663_HP_CHARGE_PUMP_1,
  1490. RT5663_SI_HP_MASK | RT5668_OSW_HP_L_MASK |
  1491. RT5668_OSW_HP_R_MASK, RT5663_SI_HP_EN |
  1492. RT5668_OSW_HP_L_DIS | RT5668_OSW_HP_R_DIS);
  1493. snd_soc_update_bits(codec, RT5663_DUMMY_1,
  1494. RT5663_EMB_CLK_MASK | RT5663_HPA_CPL_BIAS_MASK |
  1495. RT5663_HPA_CPR_BIAS_MASK, RT5663_EMB_CLK_EN |
  1496. RT5663_HPA_CPL_BIAS_1 | RT5663_HPA_CPR_BIAS_1);
  1497. snd_soc_update_bits(codec, RT5663_CBJ_1,
  1498. RT5663_INBUF_CBJ_BST1_MASK | RT5663_CBJ_SENSE_BST1_MASK,
  1499. RT5663_INBUF_CBJ_BST1_ON | RT5663_CBJ_SENSE_BST1_L);
  1500. snd_soc_update_bits(codec, RT5663_IL_CMD_2,
  1501. RT5663_PWR_MIC_DET_MASK, RT5663_PWR_MIC_DET_ON);
  1502. /* BST1 power on for JD */
  1503. snd_soc_update_bits(codec, RT5663_PWR_ANLG_2,
  1504. RT5668_PWR_BST1_MASK, RT5668_PWR_BST1_ON);
  1505. snd_soc_update_bits(codec, RT5663_EM_JACK_TYPE_1,
  1506. RT5663_CBJ_DET_MASK | RT5663_EXT_JD_MASK |
  1507. RT5663_POL_EXT_JD_MASK, RT5663_CBJ_DET_EN |
  1508. RT5663_EXT_JD_EN | RT5663_POL_EXT_JD_EN);
  1509. snd_soc_update_bits(codec, RT5663_PWR_ANLG_1,
  1510. RT5668_PWR_MB_MASK | RT5668_LDO1_DVO_MASK |
  1511. RT5668_AMP_HP_MASK, RT5668_PWR_MB |
  1512. RT5668_LDO1_DVO_0_9V | RT5668_AMP_HP_3X);
  1513. snd_soc_update_bits(codec, RT5663_AUTO_1MRC_CLK,
  1514. RT5668_IRQ_POW_SAV_MASK, RT5668_IRQ_POW_SAV_EN);
  1515. snd_soc_update_bits(codec, RT5663_IRQ_1,
  1516. RT5663_EN_IRQ_JD1_MASK, RT5663_EN_IRQ_JD1_EN);
  1517. while (i < 5) {
  1518. msleep(sleep_time[i]);
  1519. val = snd_soc_read(codec, RT5663_EM_JACK_TYPE_2) &
  1520. 0x0003;
  1521. dev_dbg(codec->dev, "%s: MX-00e7 val=%x sleep %d\n",
  1522. __func__, val, sleep_time[i]);
  1523. i++;
  1524. if (val == 0x1 || val == 0x2 || val == 0x3)
  1525. break;
  1526. }
  1527. dev_dbg(codec->dev, "%s val = %d\n", __func__, val);
  1528. switch (val) {
  1529. case 1:
  1530. case 2:
  1531. rt5663->jack_type = SND_JACK_HEADSET;
  1532. rt5663_enable_push_button_irq(codec, true);
  1533. break;
  1534. default:
  1535. rt5663->jack_type = SND_JACK_HEADPHONE;
  1536. break;
  1537. }
  1538. } else {
  1539. if (rt5663->jack_type == SND_JACK_HEADSET)
  1540. rt5663_enable_push_button_irq(codec, false);
  1541. rt5663->jack_type = 0;
  1542. }
  1543. dev_dbg(codec->dev, "jack_type = %d\n", rt5663->jack_type);
  1544. return rt5663->jack_type;
  1545. }
  1546. static int rt5663_button_detect(struct snd_soc_codec *codec)
  1547. {
  1548. int btn_type, val;
  1549. val = snd_soc_read(codec, RT5663_IL_CMD_5);
  1550. dev_dbg(codec->dev, "%s: val=0x%x\n", __func__, val);
  1551. btn_type = val & 0xfff0;
  1552. snd_soc_write(codec, RT5663_IL_CMD_5, val);
  1553. return btn_type;
  1554. }
  1555. static irqreturn_t rt5663_irq(int irq, void *data)
  1556. {
  1557. struct rt5663_priv *rt5663 = data;
  1558. dev_dbg(rt5663->codec->dev, "%s IRQ queue work\n", __func__);
  1559. queue_delayed_work(system_wq, &rt5663->jack_detect_work,
  1560. msecs_to_jiffies(250));
  1561. return IRQ_HANDLED;
  1562. }
  1563. int rt5663_set_jack_detect(struct snd_soc_codec *codec,
  1564. struct snd_soc_jack *hs_jack)
  1565. {
  1566. struct rt5663_priv *rt5663 = snd_soc_codec_get_drvdata(codec);
  1567. rt5663->hs_jack = hs_jack;
  1568. rt5663_irq(0, rt5663);
  1569. return 0;
  1570. }
  1571. EXPORT_SYMBOL_GPL(rt5663_set_jack_detect);
  1572. static bool rt5663_check_jd_status(struct snd_soc_codec *codec)
  1573. {
  1574. struct rt5663_priv *rt5663 = snd_soc_codec_get_drvdata(codec);
  1575. int val = snd_soc_read(codec, RT5663_INT_ST_1);
  1576. dev_dbg(codec->dev, "%s val=%x\n", __func__, val);
  1577. /* JD1 */
  1578. switch (rt5663->codec_type) {
  1579. case CODEC_TYPE_RT5668:
  1580. return !(val & 0x2000);
  1581. case CODEC_TYPE_RT5663:
  1582. return !(val & 0x1000);
  1583. default:
  1584. dev_err(codec->dev, "Unknown CODEC_TYPE\n");
  1585. }
  1586. return false;
  1587. }
  1588. static void rt5663_jack_detect_work(struct work_struct *work)
  1589. {
  1590. struct rt5663_priv *rt5663 =
  1591. container_of(work, struct rt5663_priv, jack_detect_work.work);
  1592. struct snd_soc_codec *codec = rt5663->codec;
  1593. int btn_type, report = 0;
  1594. if (!codec)
  1595. return;
  1596. if (rt5663_check_jd_status(codec)) {
  1597. /* jack in */
  1598. if (rt5663->jack_type == 0) {
  1599. /* jack was out, report jack type */
  1600. switch (rt5663->codec_type) {
  1601. case CODEC_TYPE_RT5668:
  1602. report = rt5668_jack_detect(rt5663->codec, 1);
  1603. break;
  1604. case CODEC_TYPE_RT5663:
  1605. report = rt5663_jack_detect(rt5663->codec, 1);
  1606. break;
  1607. default:
  1608. dev_err(codec->dev, "Unknown CODEC_TYPE\n");
  1609. }
  1610. } else {
  1611. /* jack is already in, report button event */
  1612. report = SND_JACK_HEADSET;
  1613. btn_type = rt5663_button_detect(rt5663->codec);
  1614. /**
  1615. * rt5663 can report three kinds of button behavior,
  1616. * one click, double click and hold. However,
  1617. * currently we will report button pressed/released
  1618. * event. So all the three button behaviors are
  1619. * treated as button pressed.
  1620. */
  1621. switch (btn_type) {
  1622. case 0x8000:
  1623. case 0x4000:
  1624. case 0x2000:
  1625. report |= SND_JACK_BTN_0;
  1626. break;
  1627. case 0x1000:
  1628. case 0x0800:
  1629. case 0x0400:
  1630. report |= SND_JACK_BTN_1;
  1631. break;
  1632. case 0x0200:
  1633. case 0x0100:
  1634. case 0x0080:
  1635. report |= SND_JACK_BTN_2;
  1636. break;
  1637. case 0x0040:
  1638. case 0x0020:
  1639. case 0x0010:
  1640. report |= SND_JACK_BTN_3;
  1641. break;
  1642. case 0x0000: /* unpressed */
  1643. break;
  1644. default:
  1645. btn_type = 0;
  1646. dev_err(rt5663->codec->dev,
  1647. "Unexpected button code 0x%04x\n",
  1648. btn_type);
  1649. break;
  1650. }
  1651. /* button release or spurious interrput*/
  1652. if (btn_type == 0)
  1653. report = rt5663->jack_type;
  1654. }
  1655. } else {
  1656. /* jack out */
  1657. switch (rt5663->codec_type) {
  1658. case CODEC_TYPE_RT5668:
  1659. report = rt5668_jack_detect(rt5663->codec, 0);
  1660. break;
  1661. case CODEC_TYPE_RT5663:
  1662. report = rt5663_jack_detect(rt5663->codec, 0);
  1663. break;
  1664. default:
  1665. dev_err(codec->dev, "Unknown CODEC_TYPE\n");
  1666. }
  1667. }
  1668. dev_dbg(codec->dev, "%s jack report: 0x%04x\n", __func__, report);
  1669. snd_soc_jack_report(rt5663->hs_jack, report, SND_JACK_HEADSET |
  1670. SND_JACK_BTN_0 | SND_JACK_BTN_1 |
  1671. SND_JACK_BTN_2 | SND_JACK_BTN_3);
  1672. }
  1673. static const struct snd_kcontrol_new rt5663_snd_controls[] = {
  1674. /* DAC Digital Volume */
  1675. SOC_DOUBLE_TLV("DAC Playback Volume", RT5663_STO1_DAC_DIG_VOL,
  1676. RT5668_DAC_L1_VOL_SHIFT + 1, RT5668_DAC_R1_VOL_SHIFT + 1,
  1677. 87, 0, dac_vol_tlv),
  1678. /* ADC Digital Volume Control */
  1679. SOC_DOUBLE("ADC Capture Switch", RT5663_STO1_ADC_DIG_VOL,
  1680. RT5668_ADC_L_MUTE_SHIFT, RT5668_ADC_R_MUTE_SHIFT, 1, 1),
  1681. SOC_DOUBLE_TLV("ADC Capture Volume", RT5663_STO1_ADC_DIG_VOL,
  1682. RT5668_ADC_L_VOL_SHIFT + 1, RT5668_ADC_R_VOL_SHIFT + 1,
  1683. 63, 0, adc_vol_tlv),
  1684. };
  1685. static const struct snd_kcontrol_new rt5668_specific_controls[] = {
  1686. /* Headphone Output Volume */
  1687. SOC_DOUBLE_R_TLV("Headphone Playback Volume", RT5663_HP_LCH_DRE,
  1688. RT5663_HP_RCH_DRE, RT5668_GAIN_HP_SHIFT, 15, 1,
  1689. rt5668_hp_vol_tlv),
  1690. /* Mic Boost Volume */
  1691. SOC_SINGLE_TLV("IN1 Capture Volume", RT5668_AEC_BST,
  1692. RT5668_GAIN_CBJ_SHIFT, 8, 0, in_bst_tlv),
  1693. };
  1694. static const struct snd_kcontrol_new rt5663_specific_controls[] = {
  1695. /* Headphone Output Volume */
  1696. SOC_DOUBLE_R_TLV("Headphone Playback Volume", RT5663_STO_DRE_9,
  1697. RT5663_STO_DRE_10, RT5663_DRE_GAIN_HP_SHIFT, 23, 1,
  1698. rt5663_hp_vol_tlv),
  1699. /* Mic Boost Volume*/
  1700. SOC_SINGLE_TLV("IN1 Capture Volume", RT5663_CBJ_2,
  1701. RT5663_GAIN_BST1_SHIFT, 8, 0, in_bst_tlv),
  1702. /* Data Swap for Slot0/1 in ADCDAT1 */
  1703. SOC_ENUM("IF1 ADC Data Swap", rt5663_if1_adc_enum),
  1704. };
  1705. static int rt5663_is_sys_clk_from_pll(struct snd_soc_dapm_widget *w,
  1706. struct snd_soc_dapm_widget *sink)
  1707. {
  1708. unsigned int val;
  1709. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1710. val = snd_soc_read(codec, RT5663_GLB_CLK);
  1711. val &= RT5663_SCLK_SRC_MASK;
  1712. if (val == RT5663_SCLK_SRC_PLL1)
  1713. return 1;
  1714. else
  1715. return 0;
  1716. }
  1717. static int rt5663_is_using_asrc(struct snd_soc_dapm_widget *w,
  1718. struct snd_soc_dapm_widget *sink)
  1719. {
  1720. unsigned int reg, shift, val;
  1721. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1722. struct rt5663_priv *rt5663 = snd_soc_codec_get_drvdata(codec);
  1723. if (rt5663->codec_type == CODEC_TYPE_RT5668) {
  1724. switch (w->shift) {
  1725. case RT5668_ADC_STO1_ASRC_SHIFT:
  1726. reg = RT5668_ASRC_3;
  1727. shift = RT5668_AD_STO1_TRACK_SHIFT;
  1728. break;
  1729. case RT5668_DAC_STO1_ASRC_SHIFT:
  1730. reg = RT5663_ASRC_2;
  1731. shift = RT5668_DA_STO1_TRACK_SHIFT;
  1732. break;
  1733. default:
  1734. return 0;
  1735. }
  1736. } else {
  1737. switch (w->shift) {
  1738. case RT5663_ADC_STO1_ASRC_SHIFT:
  1739. reg = RT5663_ASRC_2;
  1740. shift = RT5663_AD_STO1_TRACK_SHIFT;
  1741. break;
  1742. case RT5663_DAC_STO1_ASRC_SHIFT:
  1743. reg = RT5663_ASRC_2;
  1744. shift = RT5663_DA_STO1_TRACK_SHIFT;
  1745. break;
  1746. default:
  1747. return 0;
  1748. }
  1749. }
  1750. val = (snd_soc_read(codec, reg) >> shift) & 0x7;
  1751. if (val)
  1752. return 1;
  1753. return 0;
  1754. }
  1755. static int rt5663_i2s_use_asrc(struct snd_soc_dapm_widget *source,
  1756. struct snd_soc_dapm_widget *sink)
  1757. {
  1758. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(source->dapm);
  1759. struct rt5663_priv *rt5663 = snd_soc_codec_get_drvdata(codec);
  1760. int da_asrc_en, ad_asrc_en;
  1761. da_asrc_en = (snd_soc_read(codec, RT5663_ASRC_2) &
  1762. RT5663_DA_STO1_TRACK_MASK) ? 1 : 0;
  1763. switch (rt5663->codec_type) {
  1764. case CODEC_TYPE_RT5668:
  1765. ad_asrc_en = (snd_soc_read(codec, RT5668_ASRC_3) &
  1766. RT5668_AD_STO1_TRACK_MASK) ? 1 : 0;
  1767. break;
  1768. case CODEC_TYPE_RT5663:
  1769. ad_asrc_en = (snd_soc_read(codec, RT5663_ASRC_2) &
  1770. RT5663_AD_STO1_TRACK_MASK) ? 1 : 0;
  1771. break;
  1772. default:
  1773. dev_err(codec->dev, "Unknown CODEC_TYPE\n");
  1774. return 1;
  1775. }
  1776. if (da_asrc_en || ad_asrc_en)
  1777. if (rt5663->sysclk > rt5663->lrck * 384)
  1778. return 1;
  1779. dev_err(codec->dev, "sysclk < 384 x fs, disable i2s asrc\n");
  1780. return 0;
  1781. }
  1782. /**
  1783. * rt5663_sel_asrc_clk_src - select ASRC clock source for a set of filters
  1784. * @codec: SoC audio codec device.
  1785. * @filter_mask: mask of filters.
  1786. * @clk_src: clock source
  1787. *
  1788. * The ASRC function is for asynchronous MCLK and LRCK. Also, since RT5668 can
  1789. * only support standard 32fs or 64fs i2s format, ASRC should be enabled to
  1790. * support special i2s clock format such as Intel's 100fs(100 * sampling rate).
  1791. * ASRC function will track i2s clock and generate a corresponding system clock
  1792. * for codec. This function provides an API to select the clock source for a
  1793. * set of filters specified by the mask. And the codec driver will turn on ASRC
  1794. * for these filters if ASRC is selected as their clock source.
  1795. */
  1796. int rt5663_sel_asrc_clk_src(struct snd_soc_codec *codec,
  1797. unsigned int filter_mask, unsigned int clk_src)
  1798. {
  1799. struct rt5663_priv *rt5668 = snd_soc_codec_get_drvdata(codec);
  1800. unsigned int asrc2_mask = 0;
  1801. unsigned int asrc2_value = 0;
  1802. unsigned int asrc3_mask = 0;
  1803. unsigned int asrc3_value = 0;
  1804. switch (clk_src) {
  1805. case RT5663_CLK_SEL_SYS:
  1806. case RT5663_CLK_SEL_I2S1_ASRC:
  1807. break;
  1808. default:
  1809. return -EINVAL;
  1810. }
  1811. if (filter_mask & RT5663_DA_STEREO_FILTER) {
  1812. asrc2_mask |= RT5668_DA_STO1_TRACK_MASK;
  1813. asrc2_value |= clk_src << RT5668_DA_STO1_TRACK_SHIFT;
  1814. }
  1815. if (filter_mask & RT5663_AD_STEREO_FILTER) {
  1816. switch (rt5668->codec_type) {
  1817. case CODEC_TYPE_RT5668:
  1818. asrc3_mask |= RT5668_AD_STO1_TRACK_MASK;
  1819. asrc3_value |= clk_src << RT5668_AD_STO1_TRACK_SHIFT;
  1820. break;
  1821. case CODEC_TYPE_RT5663:
  1822. asrc2_mask |= RT5663_AD_STO1_TRACK_MASK;
  1823. asrc2_value |= clk_src << RT5663_AD_STO1_TRACK_SHIFT;
  1824. break;
  1825. default:
  1826. dev_err(codec->dev, "Unknown CODEC_TYPE\n");
  1827. }
  1828. }
  1829. if (asrc2_mask)
  1830. snd_soc_update_bits(codec, RT5663_ASRC_2, asrc2_mask,
  1831. asrc2_value);
  1832. if (asrc3_mask)
  1833. snd_soc_update_bits(codec, RT5668_ASRC_3, asrc3_mask,
  1834. asrc3_value);
  1835. return 0;
  1836. }
  1837. EXPORT_SYMBOL_GPL(rt5663_sel_asrc_clk_src);
  1838. /* Analog Mixer */
  1839. static const struct snd_kcontrol_new rt5668_recmix1l[] = {
  1840. SOC_DAPM_SINGLE("BST2 Switch", RT5668_RECMIX1L,
  1841. RT5668_RECMIX1L_BST2_SHIFT, 1, 1),
  1842. SOC_DAPM_SINGLE("BST1 CBJ Switch", RT5668_RECMIX1L,
  1843. RT5668_RECMIX1L_BST1_CBJ_SHIFT, 1, 1),
  1844. };
  1845. static const struct snd_kcontrol_new rt5668_recmix1r[] = {
  1846. SOC_DAPM_SINGLE("BST2 Switch", RT5668_RECMIX1R,
  1847. RT5668_RECMIX1R_BST2_SHIFT, 1, 1),
  1848. };
  1849. /* Digital Mixer */
  1850. static const struct snd_kcontrol_new rt5663_sto1_adc_l_mix[] = {
  1851. SOC_DAPM_SINGLE("ADC1 Switch", RT5663_STO1_ADC_MIXER,
  1852. RT5668_M_STO1_ADC_L1_SHIFT, 1, 1),
  1853. SOC_DAPM_SINGLE("ADC2 Switch", RT5663_STO1_ADC_MIXER,
  1854. RT5668_M_STO1_ADC_L2_SHIFT, 1, 1),
  1855. };
  1856. static const struct snd_kcontrol_new rt5668_sto1_adc_r_mix[] = {
  1857. SOC_DAPM_SINGLE("ADC1 Switch", RT5663_STO1_ADC_MIXER,
  1858. RT5668_M_STO1_ADC_R1_SHIFT, 1, 1),
  1859. SOC_DAPM_SINGLE("ADC2 Switch", RT5663_STO1_ADC_MIXER,
  1860. RT5668_M_STO1_ADC_R2_SHIFT, 1, 1),
  1861. };
  1862. static const struct snd_kcontrol_new rt5663_adda_l_mix[] = {
  1863. SOC_DAPM_SINGLE("ADC L Switch", RT5663_AD_DA_MIXER,
  1864. RT5668_M_ADCMIX_L_SHIFT, 1, 1),
  1865. SOC_DAPM_SINGLE("DAC L Switch", RT5663_AD_DA_MIXER,
  1866. RT5668_M_DAC1_L_SHIFT, 1, 1),
  1867. };
  1868. static const struct snd_kcontrol_new rt5663_adda_r_mix[] = {
  1869. SOC_DAPM_SINGLE("ADC R Switch", RT5663_AD_DA_MIXER,
  1870. RT5668_M_ADCMIX_R_SHIFT, 1, 1),
  1871. SOC_DAPM_SINGLE("DAC R Switch", RT5663_AD_DA_MIXER,
  1872. RT5668_M_DAC1_R_SHIFT, 1, 1),
  1873. };
  1874. static const struct snd_kcontrol_new rt5663_sto1_dac_l_mix[] = {
  1875. SOC_DAPM_SINGLE("DAC L Switch", RT5663_STO_DAC_MIXER,
  1876. RT5668_M_DAC_L1_STO_L_SHIFT, 1, 1),
  1877. SOC_DAPM_SINGLE("DAC R Switch", RT5663_STO_DAC_MIXER,
  1878. RT5668_M_DAC_R1_STO_L_SHIFT, 1, 1),
  1879. };
  1880. static const struct snd_kcontrol_new rt5663_sto1_dac_r_mix[] = {
  1881. SOC_DAPM_SINGLE("DAC L Switch", RT5663_STO_DAC_MIXER,
  1882. RT5668_M_DAC_L1_STO_R_SHIFT, 1, 1),
  1883. SOC_DAPM_SINGLE("DAC R Switch", RT5663_STO_DAC_MIXER,
  1884. RT5668_M_DAC_R1_STO_R_SHIFT, 1, 1),
  1885. };
  1886. /* Out Switch */
  1887. static const struct snd_kcontrol_new rt5668_hpo_switch =
  1888. SOC_DAPM_SINGLE_AUTODISABLE("Switch", RT5668_HP_AMP_2,
  1889. RT5668_EN_DAC_HPO_SHIFT, 1, 0);
  1890. /* Stereo ADC source */
  1891. static const char * const rt5668_sto1_adc_src[] = {
  1892. "ADC L", "ADC R"
  1893. };
  1894. static SOC_ENUM_SINGLE_DECL(rt5668_sto1_adcl_enum, RT5663_STO1_ADC_MIXER,
  1895. RT5668_STO1_ADC_L_SRC_SHIFT, rt5668_sto1_adc_src);
  1896. static const struct snd_kcontrol_new rt5668_sto1_adcl_mux =
  1897. SOC_DAPM_ENUM("STO1 ADC L Mux", rt5668_sto1_adcl_enum);
  1898. static SOC_ENUM_SINGLE_DECL(rt5668_sto1_adcr_enum, RT5663_STO1_ADC_MIXER,
  1899. RT5668_STO1_ADC_R_SRC_SHIFT, rt5668_sto1_adc_src);
  1900. static const struct snd_kcontrol_new rt5668_sto1_adcr_mux =
  1901. SOC_DAPM_ENUM("STO1 ADC R Mux", rt5668_sto1_adcr_enum);
  1902. /* RT5663: Analog DACL1 input source */
  1903. static const char * const rt5663_alg_dacl_src[] = {
  1904. "DAC L", "STO DAC MIXL"
  1905. };
  1906. static SOC_ENUM_SINGLE_DECL(rt5663_alg_dacl_enum, RT5663_BYPASS_STO_DAC,
  1907. RT5663_DACL1_SRC_SHIFT, rt5663_alg_dacl_src);
  1908. static const struct snd_kcontrol_new rt5663_alg_dacl_mux =
  1909. SOC_DAPM_ENUM("DAC L Mux", rt5663_alg_dacl_enum);
  1910. /* RT5663: Analog DACR1 input source */
  1911. static const char * const rt5663_alg_dacr_src[] = {
  1912. "DAC R", "STO DAC MIXR"
  1913. };
  1914. static SOC_ENUM_SINGLE_DECL(rt5663_alg_dacr_enum, RT5663_BYPASS_STO_DAC,
  1915. RT5663_DACR1_SRC_SHIFT, rt5663_alg_dacr_src);
  1916. static const struct snd_kcontrol_new rt5663_alg_dacr_mux =
  1917. SOC_DAPM_ENUM("DAC R Mux", rt5663_alg_dacr_enum);
  1918. static int rt5663_hp_event(struct snd_soc_dapm_widget *w,
  1919. struct snd_kcontrol *kcontrol, int event)
  1920. {
  1921. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1922. struct rt5663_priv *rt5663 = snd_soc_codec_get_drvdata(codec);
  1923. switch (event) {
  1924. case SND_SOC_DAPM_POST_PMU:
  1925. if (rt5663->codec_type == CODEC_TYPE_RT5668) {
  1926. snd_soc_update_bits(codec, RT5663_HP_CHARGE_PUMP_1,
  1927. RT5668_SEL_PM_HP_SHIFT, RT5668_SEL_PM_HP_HIGH);
  1928. snd_soc_update_bits(codec, RT5663_HP_LOGIC_2,
  1929. RT5668_HP_SIG_SRC1_MASK,
  1930. RT5668_HP_SIG_SRC1_SILENCE);
  1931. } else {
  1932. snd_soc_write(codec, RT5663_DEPOP_2, 0x3003);
  1933. snd_soc_update_bits(codec, RT5663_DEPOP_1, 0x000b,
  1934. 0x000b);
  1935. snd_soc_update_bits(codec, RT5663_DEPOP_1, 0x0030,
  1936. 0x0030);
  1937. snd_soc_update_bits(codec, RT5663_HP_CHARGE_PUMP_1,
  1938. RT5668_OVCD_HP_MASK, RT5668_OVCD_HP_DIS);
  1939. snd_soc_write(codec, RT5663_HP_CHARGE_PUMP_2, 0x1371);
  1940. snd_soc_write(codec, RT5663_HP_BIAS, 0xabba);
  1941. snd_soc_write(codec, RT5663_CHARGE_PUMP_1, 0x2224);
  1942. snd_soc_write(codec, RT5663_ANA_BIAS_CUR_1, 0x7766);
  1943. snd_soc_write(codec, RT5663_HP_BIAS, 0xafaa);
  1944. snd_soc_write(codec, RT5663_CHARGE_PUMP_2, 0x7777);
  1945. snd_soc_update_bits(codec, RT5663_DEPOP_1, 0x3000,
  1946. 0x3000);
  1947. }
  1948. break;
  1949. case SND_SOC_DAPM_PRE_PMD:
  1950. if (rt5663->codec_type == CODEC_TYPE_RT5668) {
  1951. snd_soc_update_bits(codec, RT5663_HP_LOGIC_2,
  1952. RT5668_HP_SIG_SRC1_MASK,
  1953. RT5668_HP_SIG_SRC1_REG);
  1954. } else {
  1955. snd_soc_update_bits(codec, RT5663_DEPOP_1, 0x3000, 0x0);
  1956. snd_soc_update_bits(codec, RT5663_HP_CHARGE_PUMP_1,
  1957. RT5668_OVCD_HP_MASK, RT5668_OVCD_HP_EN);
  1958. snd_soc_update_bits(codec, RT5663_DEPOP_1, 0x0030, 0x0);
  1959. snd_soc_update_bits(codec, RT5663_DEPOP_1, 0x000b,
  1960. 0x000b);
  1961. }
  1962. break;
  1963. default:
  1964. return 0;
  1965. }
  1966. return 0;
  1967. }
  1968. static int rt5668_bst2_power(struct snd_soc_dapm_widget *w,
  1969. struct snd_kcontrol *kcontrol, int event)
  1970. {
  1971. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1972. switch (event) {
  1973. case SND_SOC_DAPM_POST_PMU:
  1974. snd_soc_update_bits(codec, RT5663_PWR_ANLG_2,
  1975. RT5668_PWR_BST2_MASK | RT5668_PWR_BST2_OP_MASK,
  1976. RT5668_PWR_BST2 | RT5668_PWR_BST2_OP);
  1977. break;
  1978. case SND_SOC_DAPM_PRE_PMD:
  1979. snd_soc_update_bits(codec, RT5663_PWR_ANLG_2,
  1980. RT5668_PWR_BST2_MASK | RT5668_PWR_BST2_OP_MASK, 0);
  1981. break;
  1982. default:
  1983. return 0;
  1984. }
  1985. return 0;
  1986. }
  1987. static int rt5663_pre_div_power(struct snd_soc_dapm_widget *w,
  1988. struct snd_kcontrol *kcontrol, int event)
  1989. {
  1990. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1991. switch (event) {
  1992. case SND_SOC_DAPM_POST_PMU:
  1993. snd_soc_write(codec, RT5663_PRE_DIV_GATING_1, 0xff00);
  1994. snd_soc_write(codec, RT5663_PRE_DIV_GATING_2, 0xfffc);
  1995. break;
  1996. case SND_SOC_DAPM_PRE_PMD:
  1997. snd_soc_write(codec, RT5663_PRE_DIV_GATING_1, 0x0000);
  1998. snd_soc_write(codec, RT5663_PRE_DIV_GATING_2, 0x0000);
  1999. break;
  2000. default:
  2001. return 0;
  2002. }
  2003. return 0;
  2004. }
  2005. static const struct snd_soc_dapm_widget rt5663_dapm_widgets[] = {
  2006. SND_SOC_DAPM_SUPPLY("PLL", RT5663_PWR_ANLG_3, RT5668_PWR_PLL_SHIFT, 0,
  2007. NULL, 0),
  2008. /* micbias */
  2009. SND_SOC_DAPM_MICBIAS("MICBIAS1", RT5663_PWR_ANLG_2,
  2010. RT5668_PWR_MB1_SHIFT, 0),
  2011. SND_SOC_DAPM_MICBIAS("MICBIAS2", RT5663_PWR_ANLG_2,
  2012. RT5668_PWR_MB2_SHIFT, 0),
  2013. /* Input Lines */
  2014. SND_SOC_DAPM_INPUT("IN1P"),
  2015. SND_SOC_DAPM_INPUT("IN1N"),
  2016. /* REC Mixer Power */
  2017. SND_SOC_DAPM_SUPPLY("RECMIX1L Power", RT5663_PWR_ANLG_2,
  2018. RT5668_PWR_RECMIX1_SHIFT, 0, NULL, 0),
  2019. /* ADCs */
  2020. SND_SOC_DAPM_ADC("ADC L", NULL, SND_SOC_NOPM, 0, 0),
  2021. SND_SOC_DAPM_SUPPLY("ADC L Power", RT5663_PWR_DIG_1,
  2022. RT5668_PWR_ADC_L1_SHIFT, 0, NULL, 0),
  2023. SND_SOC_DAPM_SUPPLY("ADC Clock", RT5663_CHOP_ADC,
  2024. RT5668_CKGEN_ADCC_SHIFT, 0, NULL, 0),
  2025. /* ADC Mixer */
  2026. SND_SOC_DAPM_MIXER("STO1 ADC MIXL", SND_SOC_NOPM,
  2027. 0, 0, rt5663_sto1_adc_l_mix,
  2028. ARRAY_SIZE(rt5663_sto1_adc_l_mix)),
  2029. /* ADC Filter Power */
  2030. SND_SOC_DAPM_SUPPLY("STO1 ADC Filter", RT5663_PWR_DIG_2,
  2031. RT5668_PWR_ADC_S1F_SHIFT, 0, NULL, 0),
  2032. /* Digital Interface */
  2033. SND_SOC_DAPM_SUPPLY("I2S", RT5663_PWR_DIG_1, RT5668_PWR_I2S1_SHIFT, 0,
  2034. NULL, 0),
  2035. SND_SOC_DAPM_PGA("IF DAC", SND_SOC_NOPM, 0, 0, NULL, 0),
  2036. SND_SOC_DAPM_PGA("IF1 DAC1 L", SND_SOC_NOPM, 0, 0, NULL, 0),
  2037. SND_SOC_DAPM_PGA("IF1 DAC1 R", SND_SOC_NOPM, 0, 0, NULL, 0),
  2038. SND_SOC_DAPM_PGA("IF1 ADC1", SND_SOC_NOPM, 0, 0, NULL, 0),
  2039. SND_SOC_DAPM_PGA("IF ADC", SND_SOC_NOPM, 0, 0, NULL, 0),
  2040. /* Audio Interface */
  2041. SND_SOC_DAPM_AIF_IN("AIFRX", "AIF Playback", 0, SND_SOC_NOPM, 0, 0),
  2042. SND_SOC_DAPM_AIF_OUT("AIFTX", "AIF Capture", 0, SND_SOC_NOPM, 0, 0),
  2043. /* DAC mixer before sound effect */
  2044. SND_SOC_DAPM_MIXER("ADDA MIXL", SND_SOC_NOPM, 0, 0, rt5663_adda_l_mix,
  2045. ARRAY_SIZE(rt5663_adda_l_mix)),
  2046. SND_SOC_DAPM_MIXER("ADDA MIXR", SND_SOC_NOPM, 0, 0, rt5663_adda_r_mix,
  2047. ARRAY_SIZE(rt5663_adda_r_mix)),
  2048. SND_SOC_DAPM_PGA("DAC L1", SND_SOC_NOPM, 0, 0, NULL, 0),
  2049. SND_SOC_DAPM_PGA("DAC R1", SND_SOC_NOPM, 0, 0, NULL, 0),
  2050. /* DAC Mixer */
  2051. SND_SOC_DAPM_SUPPLY("STO1 DAC Filter", RT5663_PWR_DIG_2,
  2052. RT5668_PWR_DAC_S1F_SHIFT, 0, NULL, 0),
  2053. SND_SOC_DAPM_MIXER("STO1 DAC MIXL", SND_SOC_NOPM, 0, 0,
  2054. rt5663_sto1_dac_l_mix, ARRAY_SIZE(rt5663_sto1_dac_l_mix)),
  2055. SND_SOC_DAPM_MIXER("STO1 DAC MIXR", SND_SOC_NOPM, 0, 0,
  2056. rt5663_sto1_dac_r_mix, ARRAY_SIZE(rt5663_sto1_dac_r_mix)),
  2057. /* DACs */
  2058. SND_SOC_DAPM_SUPPLY("STO1 DAC L Power", RT5663_PWR_DIG_1,
  2059. RT5668_PWR_DAC_L1_SHIFT, 0, NULL, 0),
  2060. SND_SOC_DAPM_SUPPLY("STO1 DAC R Power", RT5663_PWR_DIG_1,
  2061. RT5668_PWR_DAC_R1_SHIFT, 0, NULL, 0),
  2062. SND_SOC_DAPM_DAC("DAC L", NULL, SND_SOC_NOPM, 0, 0),
  2063. SND_SOC_DAPM_DAC("DAC R", NULL, SND_SOC_NOPM, 0, 0),
  2064. /* Headphone*/
  2065. SND_SOC_DAPM_PGA_S("HP Amp", 1, SND_SOC_NOPM, 0, 0, rt5663_hp_event,
  2066. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU),
  2067. /* Output Lines */
  2068. SND_SOC_DAPM_OUTPUT("HPOL"),
  2069. SND_SOC_DAPM_OUTPUT("HPOR"),
  2070. };
  2071. static const struct snd_soc_dapm_widget rt5668_specific_dapm_widgets[] = {
  2072. SND_SOC_DAPM_SUPPLY("LDO2", RT5663_PWR_ANLG_3,
  2073. RT5668_PWR_LDO2_SHIFT, 0, NULL, 0),
  2074. SND_SOC_DAPM_SUPPLY("Mic Det Power", RT5668_PWR_VOL,
  2075. RT5668_PWR_MIC_DET_SHIFT, 0, NULL, 0),
  2076. SND_SOC_DAPM_SUPPLY("LDO DAC", RT5663_PWR_DIG_1,
  2077. RT5668_PWR_LDO_DACREF_SHIFT, 0, NULL, 0),
  2078. /* ASRC */
  2079. SND_SOC_DAPM_SUPPLY("I2S ASRC", RT5663_ASRC_1,
  2080. RT5668_I2S1_ASRC_SHIFT, 0, NULL, 0),
  2081. SND_SOC_DAPM_SUPPLY("DAC ASRC", RT5663_ASRC_1,
  2082. RT5668_DAC_STO1_ASRC_SHIFT, 0, NULL, 0),
  2083. SND_SOC_DAPM_SUPPLY("ADC ASRC", RT5663_ASRC_1,
  2084. RT5668_ADC_STO1_ASRC_SHIFT, 0, NULL, 0),
  2085. /* Input Lines */
  2086. SND_SOC_DAPM_INPUT("IN2P"),
  2087. SND_SOC_DAPM_INPUT("IN2N"),
  2088. /* Boost */
  2089. SND_SOC_DAPM_PGA("BST1 CBJ", SND_SOC_NOPM, 0, 0, NULL, 0),
  2090. SND_SOC_DAPM_SUPPLY("CBJ Power", RT5663_PWR_ANLG_3,
  2091. RT5668_PWR_CBJ_SHIFT, 0, NULL, 0),
  2092. SND_SOC_DAPM_PGA("BST2", SND_SOC_NOPM, 0, 0, NULL, 0),
  2093. SND_SOC_DAPM_SUPPLY("BST2 Power", SND_SOC_NOPM, 0, 0,
  2094. rt5668_bst2_power, SND_SOC_DAPM_PRE_PMD |
  2095. SND_SOC_DAPM_POST_PMU),
  2096. /* REC Mixer */
  2097. SND_SOC_DAPM_MIXER("RECMIX1L", SND_SOC_NOPM, 0, 0, rt5668_recmix1l,
  2098. ARRAY_SIZE(rt5668_recmix1l)),
  2099. SND_SOC_DAPM_MIXER("RECMIX1R", SND_SOC_NOPM, 0, 0, rt5668_recmix1r,
  2100. ARRAY_SIZE(rt5668_recmix1r)),
  2101. SND_SOC_DAPM_SUPPLY("RECMIX1R Power", RT5663_PWR_ANLG_2,
  2102. RT5668_PWR_RECMIX2_SHIFT, 0, NULL, 0),
  2103. /* ADC */
  2104. SND_SOC_DAPM_ADC("ADC R", NULL, SND_SOC_NOPM, 0, 0),
  2105. SND_SOC_DAPM_SUPPLY("ADC R Power", RT5663_PWR_DIG_1,
  2106. RT5668_PWR_ADC_R1_SHIFT, 0, NULL, 0),
  2107. /* ADC Mux */
  2108. SND_SOC_DAPM_PGA("STO1 ADC L1", RT5663_STO1_ADC_MIXER,
  2109. RT5668_STO1_ADC_L1_SRC_SHIFT, 0, NULL, 0),
  2110. SND_SOC_DAPM_PGA("STO1 ADC R1", RT5663_STO1_ADC_MIXER,
  2111. RT5668_STO1_ADC_R1_SRC_SHIFT, 0, NULL, 0),
  2112. SND_SOC_DAPM_PGA("STO1 ADC L2", RT5663_STO1_ADC_MIXER,
  2113. RT5668_STO1_ADC_L2_SRC_SHIFT, 1, NULL, 0),
  2114. SND_SOC_DAPM_PGA("STO1 ADC R2", RT5663_STO1_ADC_MIXER,
  2115. RT5668_STO1_ADC_R2_SRC_SHIFT, 1, NULL, 0),
  2116. SND_SOC_DAPM_MUX("STO1 ADC L Mux", SND_SOC_NOPM, 0, 0,
  2117. &rt5668_sto1_adcl_mux),
  2118. SND_SOC_DAPM_MUX("STO1 ADC R Mux", SND_SOC_NOPM, 0, 0,
  2119. &rt5668_sto1_adcr_mux),
  2120. /* ADC Mix */
  2121. SND_SOC_DAPM_MIXER("STO1 ADC MIXR", SND_SOC_NOPM, 0, 0,
  2122. rt5668_sto1_adc_r_mix, ARRAY_SIZE(rt5668_sto1_adc_r_mix)),
  2123. /* Analog DAC Clock */
  2124. SND_SOC_DAPM_SUPPLY("DAC Clock", RT5663_CHOP_DAC_L,
  2125. RT5668_CKGEN_DAC1_SHIFT, 0, NULL, 0),
  2126. /* Headphone out */
  2127. SND_SOC_DAPM_SWITCH("HPO Playback", SND_SOC_NOPM, 0, 0,
  2128. &rt5668_hpo_switch),
  2129. };
  2130. static const struct snd_soc_dapm_widget rt5663_specific_dapm_widgets[] = {
  2131. /* System Clock Pre Divider Gating */
  2132. SND_SOC_DAPM_SUPPLY("Pre Div Power", SND_SOC_NOPM, 0, 0,
  2133. rt5663_pre_div_power, SND_SOC_DAPM_POST_PMU |
  2134. SND_SOC_DAPM_PRE_PMD),
  2135. /* LDO */
  2136. SND_SOC_DAPM_SUPPLY("LDO ADC", RT5663_PWR_DIG_1,
  2137. RT5668_PWR_LDO_DACREF_SHIFT, 0, NULL, 0),
  2138. /* ASRC */
  2139. SND_SOC_DAPM_SUPPLY("I2S ASRC", RT5663_ASRC_1,
  2140. RT5663_I2S1_ASRC_SHIFT, 0, NULL, 0),
  2141. SND_SOC_DAPM_SUPPLY("DAC ASRC", RT5663_ASRC_1,
  2142. RT5663_DAC_STO1_ASRC_SHIFT, 0, NULL, 0),
  2143. SND_SOC_DAPM_SUPPLY("ADC ASRC", RT5663_ASRC_1,
  2144. RT5663_ADC_STO1_ASRC_SHIFT, 0, NULL, 0),
  2145. /* Boost */
  2146. SND_SOC_DAPM_PGA("BST1", SND_SOC_NOPM, 0, 0, NULL, 0),
  2147. /* STO ADC */
  2148. SND_SOC_DAPM_PGA("STO1 ADC L1", SND_SOC_NOPM, 0, 0, NULL, 0),
  2149. SND_SOC_DAPM_PGA("STO1 ADC L2", SND_SOC_NOPM, 0, 0, NULL, 0),
  2150. /* Analog DAC source */
  2151. SND_SOC_DAPM_MUX("DAC L Mux", SND_SOC_NOPM, 0, 0, &rt5663_alg_dacl_mux),
  2152. SND_SOC_DAPM_MUX("DAC R Mux", SND_SOC_NOPM, 0, 0, &rt5663_alg_dacr_mux),
  2153. };
  2154. static const struct snd_soc_dapm_route rt5663_dapm_routes[] = {
  2155. /* PLL */
  2156. { "I2S", NULL, "PLL", rt5663_is_sys_clk_from_pll },
  2157. /* ASRC */
  2158. { "STO1 ADC Filter", NULL, "ADC ASRC", rt5663_is_using_asrc },
  2159. { "STO1 DAC Filter", NULL, "DAC ASRC", rt5663_is_using_asrc },
  2160. { "I2S", NULL, "I2S ASRC", rt5663_i2s_use_asrc },
  2161. { "ADC L", NULL, "ADC L Power" },
  2162. { "ADC L", NULL, "ADC Clock" },
  2163. { "STO1 ADC L2", NULL, "STO1 DAC MIXL" },
  2164. { "STO1 ADC MIXL", "ADC1 Switch", "STO1 ADC L1" },
  2165. { "STO1 ADC MIXL", "ADC2 Switch", "STO1 ADC L2" },
  2166. { "STO1 ADC MIXL", NULL, "STO1 ADC Filter" },
  2167. { "IF1 ADC1", NULL, "STO1 ADC MIXL" },
  2168. { "IF ADC", NULL, "IF1 ADC1" },
  2169. { "AIFTX", NULL, "IF ADC" },
  2170. { "AIFTX", NULL, "I2S" },
  2171. { "AIFRX", NULL, "I2S" },
  2172. { "IF DAC", NULL, "AIFRX" },
  2173. { "IF1 DAC1 L", NULL, "IF DAC" },
  2174. { "IF1 DAC1 R", NULL, "IF DAC" },
  2175. { "ADDA MIXL", "ADC L Switch", "STO1 ADC MIXL" },
  2176. { "ADDA MIXL", "DAC L Switch", "IF1 DAC1 L" },
  2177. { "ADDA MIXL", NULL, "STO1 DAC Filter" },
  2178. { "ADDA MIXL", NULL, "STO1 DAC L Power" },
  2179. { "ADDA MIXR", "DAC R Switch", "IF1 DAC1 R" },
  2180. { "ADDA MIXR", NULL, "STO1 DAC Filter" },
  2181. { "ADDA MIXR", NULL, "STO1 DAC R Power" },
  2182. { "DAC L1", NULL, "ADDA MIXL" },
  2183. { "DAC R1", NULL, "ADDA MIXR" },
  2184. { "STO1 DAC MIXL", "DAC L Switch", "DAC L1" },
  2185. { "STO1 DAC MIXL", "DAC R Switch", "DAC R1" },
  2186. { "STO1 DAC MIXL", NULL, "STO1 DAC L Power" },
  2187. { "STO1 DAC MIXL", NULL, "STO1 DAC Filter" },
  2188. { "STO1 DAC MIXR", "DAC R Switch", "DAC R1" },
  2189. { "STO1 DAC MIXR", "DAC L Switch", "DAC L1" },
  2190. { "STO1 DAC MIXR", NULL, "STO1 DAC R Power" },
  2191. { "STO1 DAC MIXR", NULL, "STO1 DAC Filter" },
  2192. { "HP Amp", NULL, "DAC L" },
  2193. { "HP Amp", NULL, "DAC R" },
  2194. };
  2195. static const struct snd_soc_dapm_route rt5668_specific_dapm_routes[] = {
  2196. { "MICBIAS1", NULL, "LDO2" },
  2197. { "MICBIAS2", NULL, "LDO2" },
  2198. { "BST1 CBJ", NULL, "IN1P" },
  2199. { "BST1 CBJ", NULL, "IN1N" },
  2200. { "BST1 CBJ", NULL, "CBJ Power" },
  2201. { "BST2", NULL, "IN2P" },
  2202. { "BST2", NULL, "IN2N" },
  2203. { "BST2", NULL, "BST2 Power" },
  2204. { "RECMIX1L", "BST2 Switch", "BST2" },
  2205. { "RECMIX1L", "BST1 CBJ Switch", "BST1 CBJ" },
  2206. { "RECMIX1L", NULL, "RECMIX1L Power" },
  2207. { "RECMIX1R", "BST2 Switch", "BST2" },
  2208. { "RECMIX1R", NULL, "RECMIX1R Power" },
  2209. { "ADC L", NULL, "RECMIX1L" },
  2210. { "ADC R", NULL, "RECMIX1R" },
  2211. { "ADC R", NULL, "ADC R Power" },
  2212. { "ADC R", NULL, "ADC Clock" },
  2213. { "STO1 ADC L Mux", "ADC L", "ADC L" },
  2214. { "STO1 ADC L Mux", "ADC R", "ADC R" },
  2215. { "STO1 ADC L1", NULL, "STO1 ADC L Mux" },
  2216. { "STO1 ADC R Mux", "ADC L", "ADC L" },
  2217. { "STO1 ADC R Mux", "ADC R", "ADC R" },
  2218. { "STO1 ADC R1", NULL, "STO1 ADC R Mux" },
  2219. { "STO1 ADC R2", NULL, "STO1 DAC MIXR" },
  2220. { "STO1 ADC MIXR", "ADC1 Switch", "STO1 ADC R1" },
  2221. { "STO1 ADC MIXR", "ADC2 Switch", "STO1 ADC R2" },
  2222. { "STO1 ADC MIXR", NULL, "STO1 ADC Filter" },
  2223. { "IF1 ADC1", NULL, "STO1 ADC MIXR" },
  2224. { "ADDA MIXR", "ADC R Switch", "STO1 ADC MIXR" },
  2225. { "DAC L", NULL, "STO1 DAC MIXL" },
  2226. { "DAC L", NULL, "LDO DAC" },
  2227. { "DAC L", NULL, "DAC Clock" },
  2228. { "DAC R", NULL, "STO1 DAC MIXR" },
  2229. { "DAC R", NULL, "LDO DAC" },
  2230. { "DAC R", NULL, "DAC Clock" },
  2231. { "HPO Playback", "Switch", "HP Amp" },
  2232. { "HPOL", NULL, "HPO Playback" },
  2233. { "HPOR", NULL, "HPO Playback" },
  2234. };
  2235. static const struct snd_soc_dapm_route rt5663_specific_dapm_routes[] = {
  2236. { "I2S", NULL, "Pre Div Power" },
  2237. { "BST1", NULL, "IN1P" },
  2238. { "BST1", NULL, "IN1N" },
  2239. { "BST1", NULL, "RECMIX1L Power" },
  2240. { "ADC L", NULL, "BST1" },
  2241. { "STO1 ADC L1", NULL, "ADC L" },
  2242. { "DAC L Mux", "DAC L", "DAC L1" },
  2243. { "DAC L Mux", "STO DAC MIXL", "STO1 DAC MIXL" },
  2244. { "DAC R Mux", "DAC R", "DAC R1"},
  2245. { "DAC R Mux", "STO DAC MIXR", "STO1 DAC MIXR" },
  2246. { "DAC L", NULL, "DAC L Mux" },
  2247. { "DAC R", NULL, "DAC R Mux" },
  2248. { "HPOL", NULL, "HP Amp" },
  2249. { "HPOR", NULL, "HP Amp" },
  2250. };
  2251. static int rt5663_hw_params(struct snd_pcm_substream *substream,
  2252. struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
  2253. {
  2254. struct snd_soc_codec *codec = dai->codec;
  2255. struct rt5663_priv *rt5663 = snd_soc_codec_get_drvdata(codec);
  2256. unsigned int val_len = 0;
  2257. int pre_div;
  2258. rt5663->lrck = params_rate(params);
  2259. dev_dbg(dai->dev, "bclk is %dHz and sysclk is %dHz\n",
  2260. rt5663->lrck, rt5663->sysclk);
  2261. pre_div = rl6231_get_clk_info(rt5663->sysclk, rt5663->lrck);
  2262. if (pre_div < 0) {
  2263. dev_err(codec->dev, "Unsupported clock setting %d for DAI %d\n",
  2264. rt5663->lrck, dai->id);
  2265. return -EINVAL;
  2266. }
  2267. dev_dbg(dai->dev, "pre_div is %d for iis %d\n", pre_div, dai->id);
  2268. switch (params_width(params)) {
  2269. case 8:
  2270. val_len = RT5668_I2S_DL_8;
  2271. break;
  2272. case 16:
  2273. val_len = RT5668_I2S_DL_16;
  2274. break;
  2275. case 20:
  2276. val_len = RT5668_I2S_DL_20;
  2277. break;
  2278. case 24:
  2279. val_len = RT5668_I2S_DL_24;
  2280. break;
  2281. default:
  2282. return -EINVAL;
  2283. }
  2284. snd_soc_update_bits(codec, RT5663_I2S1_SDP,
  2285. RT5668_I2S_DL_MASK, val_len);
  2286. snd_soc_update_bits(codec, RT5663_ADDA_CLK_1,
  2287. RT5668_I2S_PD1_MASK, pre_div << RT5668_I2S_PD1_SHIFT);
  2288. return 0;
  2289. }
  2290. static int rt5663_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
  2291. {
  2292. struct snd_soc_codec *codec = dai->codec;
  2293. unsigned int reg_val = 0;
  2294. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  2295. case SND_SOC_DAIFMT_CBM_CFM:
  2296. break;
  2297. case SND_SOC_DAIFMT_CBS_CFS:
  2298. reg_val |= RT5668_I2S_MS_S;
  2299. break;
  2300. default:
  2301. return -EINVAL;
  2302. }
  2303. switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
  2304. case SND_SOC_DAIFMT_NB_NF:
  2305. break;
  2306. case SND_SOC_DAIFMT_IB_NF:
  2307. reg_val |= RT5668_I2S_BP_INV;
  2308. break;
  2309. default:
  2310. return -EINVAL;
  2311. }
  2312. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  2313. case SND_SOC_DAIFMT_I2S:
  2314. break;
  2315. case SND_SOC_DAIFMT_LEFT_J:
  2316. reg_val |= RT5668_I2S_DF_LEFT;
  2317. break;
  2318. case SND_SOC_DAIFMT_DSP_A:
  2319. reg_val |= RT5668_I2S_DF_PCM_A;
  2320. break;
  2321. case SND_SOC_DAIFMT_DSP_B:
  2322. reg_val |= RT5668_I2S_DF_PCM_B;
  2323. break;
  2324. default:
  2325. return -EINVAL;
  2326. }
  2327. snd_soc_update_bits(codec, RT5663_I2S1_SDP, RT5668_I2S_MS_MASK |
  2328. RT5668_I2S_BP_MASK | RT5668_I2S_DF_MASK, reg_val);
  2329. return 0;
  2330. }
  2331. static int rt5663_set_dai_sysclk(struct snd_soc_dai *dai, int clk_id,
  2332. unsigned int freq, int dir)
  2333. {
  2334. struct snd_soc_codec *codec = dai->codec;
  2335. struct rt5663_priv *rt5663 = snd_soc_codec_get_drvdata(codec);
  2336. unsigned int reg_val = 0;
  2337. if (freq == rt5663->sysclk && clk_id == rt5663->sysclk_src)
  2338. return 0;
  2339. switch (clk_id) {
  2340. case RT5663_SCLK_S_MCLK:
  2341. reg_val |= RT5663_SCLK_SRC_MCLK;
  2342. break;
  2343. case RT5663_SCLK_S_PLL1:
  2344. reg_val |= RT5663_SCLK_SRC_PLL1;
  2345. break;
  2346. case RT5663_SCLK_S_RCCLK:
  2347. reg_val |= RT5663_SCLK_SRC_RCCLK;
  2348. break;
  2349. default:
  2350. dev_err(codec->dev, "Invalid clock id (%d)\n", clk_id);
  2351. return -EINVAL;
  2352. }
  2353. snd_soc_update_bits(codec, RT5663_GLB_CLK, RT5668_SCLK_SRC_MASK,
  2354. reg_val);
  2355. rt5663->sysclk = freq;
  2356. rt5663->sysclk_src = clk_id;
  2357. dev_dbg(codec->dev, "Sysclk is %dHz and clock id is %d\n",
  2358. freq, clk_id);
  2359. return 0;
  2360. }
  2361. static int rt5663_set_dai_pll(struct snd_soc_dai *dai, int pll_id, int source,
  2362. unsigned int freq_in, unsigned int freq_out)
  2363. {
  2364. struct snd_soc_codec *codec = dai->codec;
  2365. struct rt5663_priv *rt5663 = snd_soc_codec_get_drvdata(codec);
  2366. struct rl6231_pll_code pll_code;
  2367. int ret;
  2368. int mask, shift, val;
  2369. if (source == rt5663->pll_src && freq_in == rt5663->pll_in &&
  2370. freq_out == rt5663->pll_out)
  2371. return 0;
  2372. if (!freq_in || !freq_out) {
  2373. dev_dbg(codec->dev, "PLL disabled\n");
  2374. rt5663->pll_in = 0;
  2375. rt5663->pll_out = 0;
  2376. snd_soc_update_bits(codec, RT5663_GLB_CLK,
  2377. RT5663_SCLK_SRC_MASK, RT5663_SCLK_SRC_MCLK);
  2378. return 0;
  2379. }
  2380. switch (rt5663->codec_type) {
  2381. case CODEC_TYPE_RT5668:
  2382. mask = RT5668_PLL1_SRC_MASK;
  2383. shift = RT5668_PLL1_SRC_SHIFT;
  2384. break;
  2385. case CODEC_TYPE_RT5663:
  2386. mask = RT5663_PLL1_SRC_MASK;
  2387. shift = RT5663_PLL1_SRC_SHIFT;
  2388. break;
  2389. default:
  2390. dev_err(codec->dev, "Unknown CODEC_TYPE\n");
  2391. return -EINVAL;
  2392. }
  2393. switch (source) {
  2394. case RT5663_PLL1_S_MCLK:
  2395. val = 0x0;
  2396. break;
  2397. case RT5663_PLL1_S_BCLK1:
  2398. val = 0x1;
  2399. break;
  2400. default:
  2401. dev_err(codec->dev, "Unknown PLL source %d\n", source);
  2402. return -EINVAL;
  2403. }
  2404. snd_soc_update_bits(codec, RT5663_GLB_CLK, mask, (val << shift));
  2405. ret = rl6231_pll_calc(freq_in, freq_out, &pll_code);
  2406. if (ret < 0) {
  2407. dev_err(codec->dev, "Unsupport input clock %d\n", freq_in);
  2408. return ret;
  2409. }
  2410. dev_dbg(codec->dev, "bypass=%d m=%d n=%d k=%d\n", pll_code.m_bp,
  2411. (pll_code.m_bp ? 0 : pll_code.m_code), pll_code.n_code,
  2412. pll_code.k_code);
  2413. snd_soc_write(codec, RT5663_PLL_1,
  2414. pll_code.n_code << RT5668_PLL_N_SHIFT | pll_code.k_code);
  2415. snd_soc_write(codec, RT5663_PLL_2,
  2416. (pll_code.m_bp ? 0 : pll_code.m_code) << RT5668_PLL_M_SHIFT |
  2417. pll_code.m_bp << RT5668_PLL_M_BP_SHIFT);
  2418. rt5663->pll_in = freq_in;
  2419. rt5663->pll_out = freq_out;
  2420. rt5663->pll_src = source;
  2421. return 0;
  2422. }
  2423. static int rt5663_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask,
  2424. unsigned int rx_mask, int slots, int slot_width)
  2425. {
  2426. struct snd_soc_codec *codec = dai->codec;
  2427. struct rt5663_priv *rt5663 = snd_soc_codec_get_drvdata(codec);
  2428. unsigned int val = 0, reg;
  2429. if (rx_mask || tx_mask)
  2430. val |= RT5668_TDM_MODE_TDM;
  2431. switch (slots) {
  2432. case 4:
  2433. val |= RT5668_TDM_IN_CH_4;
  2434. val |= RT5668_TDM_OUT_CH_4;
  2435. break;
  2436. case 6:
  2437. val |= RT5668_TDM_IN_CH_6;
  2438. val |= RT5668_TDM_OUT_CH_6;
  2439. break;
  2440. case 8:
  2441. val |= RT5668_TDM_IN_CH_8;
  2442. val |= RT5668_TDM_OUT_CH_8;
  2443. break;
  2444. case 2:
  2445. break;
  2446. default:
  2447. return -EINVAL;
  2448. }
  2449. switch (slot_width) {
  2450. case 20:
  2451. val |= RT5668_TDM_IN_LEN_20;
  2452. val |= RT5668_TDM_OUT_LEN_20;
  2453. break;
  2454. case 24:
  2455. val |= RT5668_TDM_IN_LEN_24;
  2456. val |= RT5668_TDM_OUT_LEN_24;
  2457. break;
  2458. case 32:
  2459. val |= RT5668_TDM_IN_LEN_32;
  2460. val |= RT5668_TDM_OUT_LEN_32;
  2461. break;
  2462. case 16:
  2463. break;
  2464. default:
  2465. return -EINVAL;
  2466. }
  2467. switch (rt5663->codec_type) {
  2468. case CODEC_TYPE_RT5668:
  2469. reg = RT5663_TDM_2;
  2470. break;
  2471. case CODEC_TYPE_RT5663:
  2472. reg = RT5663_TDM_1;
  2473. break;
  2474. default:
  2475. dev_err(codec->dev, "Unknown CODEC_TYPE\n");
  2476. return -EINVAL;
  2477. }
  2478. snd_soc_update_bits(codec, reg, RT5668_TDM_MODE_MASK |
  2479. RT5668_TDM_IN_CH_MASK | RT5668_TDM_OUT_CH_MASK |
  2480. RT5668_TDM_IN_LEN_MASK | RT5668_TDM_OUT_LEN_MASK, val);
  2481. return 0;
  2482. }
  2483. static int rt5663_set_bclk_ratio(struct snd_soc_dai *dai, unsigned int ratio)
  2484. {
  2485. struct snd_soc_codec *codec = dai->codec;
  2486. struct rt5663_priv *rt5663 = snd_soc_codec_get_drvdata(codec);
  2487. unsigned int reg;
  2488. dev_dbg(codec->dev, "%s ratio = %d\n", __func__, ratio);
  2489. if (rt5663->codec_type == CODEC_TYPE_RT5668)
  2490. reg = RT5668_TDM_8;
  2491. else
  2492. reg = RT5663_TDM_5;
  2493. switch (ratio) {
  2494. case 32:
  2495. snd_soc_update_bits(codec, reg,
  2496. RT5663_TDM_LENGTN_MASK,
  2497. RT5663_TDM_LENGTN_16);
  2498. break;
  2499. case 40:
  2500. snd_soc_update_bits(codec, reg,
  2501. RT5663_TDM_LENGTN_MASK,
  2502. RT5663_TDM_LENGTN_20);
  2503. break;
  2504. case 48:
  2505. snd_soc_update_bits(codec, reg,
  2506. RT5663_TDM_LENGTN_MASK,
  2507. RT5663_TDM_LENGTN_24);
  2508. break;
  2509. case 64:
  2510. snd_soc_update_bits(codec, reg,
  2511. RT5663_TDM_LENGTN_MASK,
  2512. RT5663_TDM_LENGTN_32);
  2513. break;
  2514. default:
  2515. dev_err(codec->dev, "Invalid ratio!\n");
  2516. return -EINVAL;
  2517. }
  2518. return 0;
  2519. }
  2520. static int rt5663_set_bias_level(struct snd_soc_codec *codec,
  2521. enum snd_soc_bias_level level)
  2522. {
  2523. struct rt5663_priv *rt5663 = snd_soc_codec_get_drvdata(codec);
  2524. switch (level) {
  2525. case SND_SOC_BIAS_ON:
  2526. snd_soc_update_bits(codec, RT5663_PWR_ANLG_1,
  2527. RT5668_PWR_FV1_MASK | RT5668_PWR_FV2_MASK,
  2528. RT5668_PWR_FV1 | RT5668_PWR_FV2);
  2529. break;
  2530. case SND_SOC_BIAS_PREPARE:
  2531. if (rt5663->codec_type == CODEC_TYPE_RT5668) {
  2532. snd_soc_update_bits(codec, RT5663_DIG_MISC,
  2533. RT5668_DIG_GATE_CTRL_MASK,
  2534. RT5668_DIG_GATE_CTRL_EN);
  2535. snd_soc_update_bits(codec, RT5663_SIG_CLK_DET,
  2536. RT5668_EN_ANA_CLK_DET_MASK |
  2537. RT5668_PWR_CLK_DET_MASK,
  2538. RT5668_EN_ANA_CLK_DET_AUTO |
  2539. RT5668_PWR_CLK_DET_EN);
  2540. }
  2541. break;
  2542. case SND_SOC_BIAS_STANDBY:
  2543. if (rt5663->codec_type == CODEC_TYPE_RT5668)
  2544. snd_soc_update_bits(codec, RT5663_DIG_MISC,
  2545. RT5668_DIG_GATE_CTRL_MASK,
  2546. RT5668_DIG_GATE_CTRL_DIS);
  2547. snd_soc_update_bits(codec, RT5663_PWR_ANLG_1,
  2548. RT5668_PWR_VREF1_MASK | RT5668_PWR_VREF2_MASK |
  2549. RT5668_PWR_FV1_MASK | RT5668_PWR_FV2_MASK |
  2550. RT5668_PWR_MB_MASK, RT5668_PWR_VREF1 |
  2551. RT5668_PWR_VREF2 | RT5668_PWR_MB);
  2552. usleep_range(10000, 10005);
  2553. if (rt5663->codec_type == CODEC_TYPE_RT5668) {
  2554. snd_soc_update_bits(codec, RT5663_SIG_CLK_DET,
  2555. RT5668_EN_ANA_CLK_DET_MASK |
  2556. RT5668_PWR_CLK_DET_MASK,
  2557. RT5668_EN_ANA_CLK_DET_DIS |
  2558. RT5668_PWR_CLK_DET_DIS);
  2559. }
  2560. break;
  2561. case SND_SOC_BIAS_OFF:
  2562. snd_soc_update_bits(codec, RT5663_PWR_ANLG_1,
  2563. RT5668_PWR_VREF1_MASK | RT5668_PWR_VREF2_MASK |
  2564. RT5668_PWR_FV1 | RT5668_PWR_FV2, 0x0);
  2565. break;
  2566. default:
  2567. break;
  2568. }
  2569. return 0;
  2570. }
  2571. static int rt5663_probe(struct snd_soc_codec *codec)
  2572. {
  2573. struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
  2574. struct rt5663_priv *rt5663 = snd_soc_codec_get_drvdata(codec);
  2575. rt5663->codec = codec;
  2576. switch (rt5663->codec_type) {
  2577. case CODEC_TYPE_RT5668:
  2578. snd_soc_dapm_new_controls(dapm,
  2579. rt5668_specific_dapm_widgets,
  2580. ARRAY_SIZE(rt5668_specific_dapm_widgets));
  2581. snd_soc_dapm_add_routes(dapm,
  2582. rt5668_specific_dapm_routes,
  2583. ARRAY_SIZE(rt5668_specific_dapm_routes));
  2584. snd_soc_add_codec_controls(codec, rt5668_specific_controls,
  2585. ARRAY_SIZE(rt5668_specific_controls));
  2586. break;
  2587. case CODEC_TYPE_RT5663:
  2588. snd_soc_dapm_new_controls(dapm,
  2589. rt5663_specific_dapm_widgets,
  2590. ARRAY_SIZE(rt5663_specific_dapm_widgets));
  2591. snd_soc_dapm_add_routes(dapm,
  2592. rt5663_specific_dapm_routes,
  2593. ARRAY_SIZE(rt5663_specific_dapm_routes));
  2594. snd_soc_add_codec_controls(codec, rt5663_specific_controls,
  2595. ARRAY_SIZE(rt5663_specific_controls));
  2596. break;
  2597. }
  2598. return 0;
  2599. }
  2600. static int rt5663_remove(struct snd_soc_codec *codec)
  2601. {
  2602. struct rt5663_priv *rt5663 = snd_soc_codec_get_drvdata(codec);
  2603. regmap_write(rt5663->regmap, RT5663_RESET, 0);
  2604. return 0;
  2605. }
  2606. #ifdef CONFIG_PM
  2607. static int rt5663_suspend(struct snd_soc_codec *codec)
  2608. {
  2609. struct rt5663_priv *rt5663 = snd_soc_codec_get_drvdata(codec);
  2610. regcache_cache_only(rt5663->regmap, true);
  2611. regcache_mark_dirty(rt5663->regmap);
  2612. return 0;
  2613. }
  2614. static int rt5663_resume(struct snd_soc_codec *codec)
  2615. {
  2616. struct rt5663_priv *rt5663 = snd_soc_codec_get_drvdata(codec);
  2617. regcache_cache_only(rt5663->regmap, false);
  2618. regcache_sync(rt5663->regmap);
  2619. return 0;
  2620. }
  2621. #else
  2622. #define rt5663_suspend NULL
  2623. #define rt5663_resume NULL
  2624. #endif
  2625. #define RT5663_STEREO_RATES SNDRV_PCM_RATE_8000_192000
  2626. #define RT5663_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
  2627. SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S8)
  2628. static struct snd_soc_dai_ops rt5663_aif_dai_ops = {
  2629. .hw_params = rt5663_hw_params,
  2630. .set_fmt = rt5663_set_dai_fmt,
  2631. .set_sysclk = rt5663_set_dai_sysclk,
  2632. .set_pll = rt5663_set_dai_pll,
  2633. .set_tdm_slot = rt5663_set_tdm_slot,
  2634. .set_bclk_ratio = rt5663_set_bclk_ratio,
  2635. };
  2636. static struct snd_soc_dai_driver rt5663_dai[] = {
  2637. {
  2638. .name = "rt5663-aif",
  2639. .id = RT5663_AIF,
  2640. .playback = {
  2641. .stream_name = "AIF Playback",
  2642. .channels_min = 1,
  2643. .channels_max = 2,
  2644. .rates = RT5663_STEREO_RATES,
  2645. .formats = RT5663_FORMATS,
  2646. },
  2647. .capture = {
  2648. .stream_name = "AIF Capture",
  2649. .channels_min = 1,
  2650. .channels_max = 2,
  2651. .rates = RT5663_STEREO_RATES,
  2652. .formats = RT5663_FORMATS,
  2653. },
  2654. .ops = &rt5663_aif_dai_ops,
  2655. },
  2656. };
  2657. static struct snd_soc_codec_driver soc_codec_dev_rt5663 = {
  2658. .probe = rt5663_probe,
  2659. .remove = rt5663_remove,
  2660. .suspend = rt5663_suspend,
  2661. .resume = rt5663_resume,
  2662. .set_bias_level = rt5663_set_bias_level,
  2663. .idle_bias_off = true,
  2664. .component_driver = {
  2665. .controls = rt5663_snd_controls,
  2666. .num_controls = ARRAY_SIZE(rt5663_snd_controls),
  2667. .dapm_widgets = rt5663_dapm_widgets,
  2668. .num_dapm_widgets = ARRAY_SIZE(rt5663_dapm_widgets),
  2669. .dapm_routes = rt5663_dapm_routes,
  2670. .num_dapm_routes = ARRAY_SIZE(rt5663_dapm_routes),
  2671. }
  2672. };
  2673. static const struct regmap_config rt5668_regmap = {
  2674. .reg_bits = 16,
  2675. .val_bits = 16,
  2676. .use_single_rw = true,
  2677. .max_register = 0x07fa,
  2678. .volatile_reg = rt5668_volatile_register,
  2679. .readable_reg = rt5668_readable_register,
  2680. .cache_type = REGCACHE_RBTREE,
  2681. .reg_defaults = rt5668_reg,
  2682. .num_reg_defaults = ARRAY_SIZE(rt5668_reg),
  2683. };
  2684. static const struct regmap_config rt5663_regmap = {
  2685. .reg_bits = 16,
  2686. .val_bits = 16,
  2687. .use_single_rw = true,
  2688. .max_register = 0x03f3,
  2689. .volatile_reg = rt5663_volatile_register,
  2690. .readable_reg = rt5663_readable_register,
  2691. .cache_type = REGCACHE_RBTREE,
  2692. .reg_defaults = rt5663_reg,
  2693. .num_reg_defaults = ARRAY_SIZE(rt5663_reg),
  2694. };
  2695. static const struct regmap_config temp_regmap = {
  2696. .name = "nocache",
  2697. .reg_bits = 16,
  2698. .val_bits = 16,
  2699. .use_single_rw = true,
  2700. .max_register = 0x03f3,
  2701. .cache_type = REGCACHE_NONE,
  2702. };
  2703. static const struct i2c_device_id rt5663_i2c_id[] = {
  2704. { "rt5668", 0 },
  2705. { "rt5663", 0 },
  2706. {}
  2707. };
  2708. MODULE_DEVICE_TABLE(i2c, rt5663_i2c_id);
  2709. #if defined(CONFIG_OF)
  2710. static const struct of_device_id rt5663_of_match[] = {
  2711. { .compatible = "realtek,rt5668", },
  2712. { .compatible = "realtek,rt5663", },
  2713. {},
  2714. };
  2715. MODULE_DEVICE_TABLE(of, rt5663_of_match);
  2716. #endif
  2717. #ifdef CONFIG_ACPI
  2718. static struct acpi_device_id rt5663_acpi_match[] = {
  2719. { "10EC5668", 0},
  2720. { "10EC5663", 0},
  2721. {},
  2722. };
  2723. MODULE_DEVICE_TABLE(acpi, rt5663_acpi_match);
  2724. #endif
  2725. static void rt5668_calibrate(struct rt5663_priv *rt5668)
  2726. {
  2727. regmap_write(rt5668->regmap, RT5663_BIAS_CUR_8, 0xa402);
  2728. regmap_write(rt5668->regmap, RT5663_PWR_DIG_1, 0x0100);
  2729. regmap_write(rt5668->regmap, RT5663_RECMIX, 0x4040);
  2730. regmap_write(rt5668->regmap, RT5663_DIG_MISC, 0x0001);
  2731. regmap_write(rt5668->regmap, RT5663_RC_CLK, 0x0380);
  2732. regmap_write(rt5668->regmap, RT5663_GLB_CLK, 0x8000);
  2733. regmap_write(rt5668->regmap, RT5663_ADDA_CLK_1, 0x1000);
  2734. regmap_write(rt5668->regmap, RT5663_CHOP_DAC_L, 0x3030);
  2735. regmap_write(rt5668->regmap, RT5663_CALIB_ADC, 0x3c05);
  2736. regmap_write(rt5668->regmap, RT5663_PWR_ANLG_1, 0xa23e);
  2737. msleep(40);
  2738. regmap_write(rt5668->regmap, RT5663_PWR_ANLG_1, 0xf23e);
  2739. regmap_write(rt5668->regmap, RT5663_HP_CALIB_2, 0x0321);
  2740. regmap_write(rt5668->regmap, RT5663_HP_CALIB_1, 0xfc00);
  2741. msleep(500);
  2742. }
  2743. static void rt5663_calibrate(struct rt5663_priv *rt5668)
  2744. {
  2745. int value, count;
  2746. regmap_write(rt5668->regmap, RT5663_RC_CLK, 0x0280);
  2747. regmap_write(rt5668->regmap, RT5663_GLB_CLK, 0x8000);
  2748. regmap_write(rt5668->regmap, RT5663_DIG_MISC, 0x8001);
  2749. regmap_write(rt5668->regmap, RT5663_VREF_RECMIX, 0x0032);
  2750. regmap_write(rt5668->regmap, RT5663_PWR_ANLG_1, 0xa2be);
  2751. msleep(20);
  2752. regmap_write(rt5668->regmap, RT5663_PWR_ANLG_1, 0xf2be);
  2753. regmap_write(rt5668->regmap, RT5663_PWR_DIG_2, 0x8400);
  2754. regmap_write(rt5668->regmap, RT5663_CHOP_ADC, 0x3000);
  2755. regmap_write(rt5668->regmap, RT5663_DEPOP_1, 0x003b);
  2756. regmap_write(rt5668->regmap, RT5663_PWR_DIG_1, 0x8df8);
  2757. regmap_write(rt5668->regmap, RT5663_PWR_ANLG_2, 0x0003);
  2758. regmap_write(rt5668->regmap, RT5663_PWR_ANLG_3, 0x018c);
  2759. regmap_write(rt5668->regmap, RT5663_ADDA_CLK_1, 0x1111);
  2760. regmap_write(rt5668->regmap, RT5663_PRE_DIV_GATING_1, 0xffff);
  2761. regmap_write(rt5668->regmap, RT5663_PRE_DIV_GATING_2, 0xffff);
  2762. regmap_write(rt5668->regmap, RT5663_DEPOP_2, 0x3003);
  2763. regmap_write(rt5668->regmap, RT5663_DEPOP_1, 0x003b);
  2764. regmap_write(rt5668->regmap, RT5663_HP_CHARGE_PUMP_1, 0x1e32);
  2765. regmap_write(rt5668->regmap, RT5663_HP_CHARGE_PUMP_2, 0x1371);
  2766. regmap_write(rt5668->regmap, RT5663_DACREF_LDO, 0x3b0b);
  2767. regmap_write(rt5668->regmap, RT5663_STO_DAC_MIXER, 0x2080);
  2768. regmap_write(rt5668->regmap, RT5663_BYPASS_STO_DAC, 0x000c);
  2769. regmap_write(rt5668->regmap, RT5663_HP_BIAS, 0xabba);
  2770. regmap_write(rt5668->regmap, RT5663_CHARGE_PUMP_1, 0x2224);
  2771. regmap_write(rt5668->regmap, RT5663_HP_OUT_EN, 0x8088);
  2772. regmap_write(rt5668->regmap, RT5663_STO_DRE_9, 0x0017);
  2773. regmap_write(rt5668->regmap, RT5663_STO_DRE_10, 0x0017);
  2774. regmap_write(rt5668->regmap, RT5663_STO1_ADC_MIXER, 0x4040);
  2775. regmap_write(rt5668->regmap, RT5663_RECMIX, 0x0005);
  2776. regmap_write(rt5668->regmap, RT5663_ADDA_RST, 0xc000);
  2777. regmap_write(rt5668->regmap, RT5663_STO1_HPF_ADJ1, 0x3320);
  2778. regmap_write(rt5668->regmap, RT5663_HP_CALIB_2, 0x00c9);
  2779. regmap_write(rt5668->regmap, RT5663_DUMMY_1, 0x004c);
  2780. regmap_write(rt5668->regmap, RT5663_ANA_BIAS_CUR_1, 0x7766);
  2781. regmap_write(rt5668->regmap, RT5663_BIAS_CUR_8, 0x4702);
  2782. msleep(200);
  2783. regmap_write(rt5668->regmap, RT5663_HP_CALIB_1, 0x0069);
  2784. regmap_write(rt5668->regmap, RT5663_HP_CALIB_3, 0x06c2);
  2785. regmap_write(rt5668->regmap, RT5663_HP_CALIB_1_1, 0x7b00);
  2786. regmap_write(rt5668->regmap, RT5663_HP_CALIB_1_1, 0xfb00);
  2787. count = 0;
  2788. while (true) {
  2789. regmap_read(rt5668->regmap, RT5663_HP_CALIB_1_1, &value);
  2790. if (value & 0x8000)
  2791. usleep_range(10000, 10005);
  2792. else
  2793. break;
  2794. if (count > 200)
  2795. return;
  2796. count++;
  2797. }
  2798. }
  2799. static int rt5663_i2c_probe(struct i2c_client *i2c,
  2800. const struct i2c_device_id *id)
  2801. {
  2802. struct rt5663_priv *rt5663;
  2803. int ret;
  2804. unsigned int val;
  2805. struct regmap *regmap;
  2806. rt5663 = devm_kzalloc(&i2c->dev, sizeof(struct rt5663_priv),
  2807. GFP_KERNEL);
  2808. if (rt5663 == NULL)
  2809. return -ENOMEM;
  2810. i2c_set_clientdata(i2c, rt5663);
  2811. regmap = devm_regmap_init_i2c(i2c, &temp_regmap);
  2812. if (IS_ERR(regmap)) {
  2813. ret = PTR_ERR(regmap);
  2814. dev_err(&i2c->dev, "Failed to allocate temp register map: %d\n",
  2815. ret);
  2816. return ret;
  2817. }
  2818. regmap_read(regmap, RT5663_VENDOR_ID_2, &val);
  2819. switch (val) {
  2820. case RT5668_DEVICE_ID:
  2821. rt5663->regmap = devm_regmap_init_i2c(i2c, &rt5668_regmap);
  2822. rt5663->codec_type = CODEC_TYPE_RT5668;
  2823. break;
  2824. case RT5663_DEVICE_ID:
  2825. rt5663->regmap = devm_regmap_init_i2c(i2c, &rt5663_regmap);
  2826. rt5663->codec_type = CODEC_TYPE_RT5663;
  2827. break;
  2828. default:
  2829. dev_err(&i2c->dev,
  2830. "Device with ID register %#x is not rt5663 or rt5668\n",
  2831. val);
  2832. return -ENODEV;
  2833. }
  2834. if (IS_ERR(rt5663->regmap)) {
  2835. ret = PTR_ERR(rt5663->regmap);
  2836. dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
  2837. ret);
  2838. return ret;
  2839. }
  2840. /* reset and calibrate */
  2841. regmap_write(rt5663->regmap, RT5663_RESET, 0);
  2842. regcache_cache_bypass(rt5663->regmap, true);
  2843. switch (rt5663->codec_type) {
  2844. case CODEC_TYPE_RT5668:
  2845. rt5668_calibrate(rt5663);
  2846. break;
  2847. case CODEC_TYPE_RT5663:
  2848. rt5663_calibrate(rt5663);
  2849. break;
  2850. default:
  2851. dev_err(&i2c->dev, "%s:Unknown codec type\n", __func__);
  2852. }
  2853. regcache_cache_bypass(rt5663->regmap, false);
  2854. regmap_write(rt5663->regmap, RT5663_RESET, 0);
  2855. dev_dbg(&i2c->dev, "calibrate done\n");
  2856. /* GPIO1 as IRQ */
  2857. regmap_update_bits(rt5663->regmap, RT5663_GPIO_1, RT5668_GP1_PIN_MASK,
  2858. RT5668_GP1_PIN_IRQ);
  2859. /* 4btn inline command debounce */
  2860. regmap_update_bits(rt5663->regmap, RT5663_IL_CMD_5,
  2861. RT5668_4BTN_CLK_DEB_MASK, RT5668_4BTN_CLK_DEB_65MS);
  2862. switch (rt5663->codec_type) {
  2863. case CODEC_TYPE_RT5668:
  2864. regmap_write(rt5663->regmap, RT5663_BIAS_CUR_8, 0xa402);
  2865. /* JD1 */
  2866. regmap_update_bits(rt5663->regmap, RT5663_AUTO_1MRC_CLK,
  2867. RT5668_IRQ_POW_SAV_MASK | RT5668_IRQ_POW_SAV_JD1_MASK,
  2868. RT5668_IRQ_POW_SAV_EN | RT5668_IRQ_POW_SAV_JD1_EN);
  2869. regmap_update_bits(rt5663->regmap, RT5663_PWR_ANLG_2,
  2870. RT5668_PWR_JD1_MASK, RT5668_PWR_JD1);
  2871. regmap_update_bits(rt5663->regmap, RT5663_IRQ_1,
  2872. RT5668_EN_CB_JD_MASK, RT5668_EN_CB_JD_EN);
  2873. regmap_update_bits(rt5663->regmap, RT5663_HP_LOGIC_2,
  2874. RT5668_HP_SIG_SRC1_MASK, RT5668_HP_SIG_SRC1_REG);
  2875. regmap_update_bits(rt5663->regmap, RT5663_RECMIX,
  2876. RT5668_VREF_BIAS_MASK | RT5668_CBJ_DET_MASK |
  2877. RT5668_DET_TYPE_MASK, RT5668_VREF_BIAS_REG |
  2878. RT5668_CBJ_DET_EN | RT5668_DET_TYPE_QFN);
  2879. /* Set GPIO4 and GPIO8 as input for combo jack */
  2880. regmap_update_bits(rt5663->regmap, RT5663_GPIO_2,
  2881. RT5668_GP4_PIN_CONF_MASK, RT5668_GP4_PIN_CONF_INPUT);
  2882. regmap_update_bits(rt5663->regmap, RT5668_GPIO_3,
  2883. RT5668_GP8_PIN_CONF_MASK, RT5668_GP8_PIN_CONF_INPUT);
  2884. regmap_update_bits(rt5663->regmap, RT5663_PWR_ANLG_1,
  2885. RT5668_LDO1_DVO_MASK | RT5668_AMP_HP_MASK,
  2886. RT5668_LDO1_DVO_0_9V | RT5668_AMP_HP_3X);
  2887. break;
  2888. case CODEC_TYPE_RT5663:
  2889. regmap_write(rt5663->regmap, RT5663_VREF_RECMIX, 0x0032);
  2890. regmap_write(rt5663->regmap, RT5663_PWR_ANLG_1, 0xa2be);
  2891. msleep(20);
  2892. regmap_write(rt5663->regmap, RT5663_PWR_ANLG_1, 0xf2be);
  2893. regmap_update_bits(rt5663->regmap, RT5663_GPIO_2,
  2894. RT5663_GP1_PIN_CONF_MASK, RT5663_GP1_PIN_CONF_OUTPUT);
  2895. /* DACREF LDO control */
  2896. regmap_update_bits(rt5663->regmap, RT5663_DACREF_LDO, 0x3e0e,
  2897. 0x3a0a);
  2898. regmap_update_bits(rt5663->regmap, RT5663_RECMIX,
  2899. RT5663_RECMIX1_BST1_MASK, RT5663_RECMIX1_BST1_ON);
  2900. regmap_update_bits(rt5663->regmap, RT5663_TDM_2,
  2901. RT5663_DATA_SWAP_ADCDAT1_MASK,
  2902. RT5663_DATA_SWAP_ADCDAT1_LL);
  2903. break;
  2904. default:
  2905. dev_err(&i2c->dev, "%s:Unknown codec type\n", __func__);
  2906. }
  2907. INIT_DELAYED_WORK(&rt5663->jack_detect_work, rt5663_jack_detect_work);
  2908. if (i2c->irq) {
  2909. ret = request_irq(i2c->irq, rt5663_irq,
  2910. IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING
  2911. | IRQF_ONESHOT, "rt5663", rt5663);
  2912. if (ret)
  2913. dev_err(&i2c->dev, "%s Failed to reguest IRQ: %d\n",
  2914. __func__, ret);
  2915. }
  2916. ret = snd_soc_register_codec(&i2c->dev, &soc_codec_dev_rt5663,
  2917. rt5663_dai, ARRAY_SIZE(rt5663_dai));
  2918. if (ret) {
  2919. if (i2c->irq)
  2920. free_irq(i2c->irq, rt5663);
  2921. }
  2922. return ret;
  2923. }
  2924. static int rt5663_i2c_remove(struct i2c_client *i2c)
  2925. {
  2926. struct rt5663_priv *rt5663 = i2c_get_clientdata(i2c);
  2927. if (i2c->irq)
  2928. free_irq(i2c->irq, rt5663);
  2929. snd_soc_unregister_codec(&i2c->dev);
  2930. return 0;
  2931. }
  2932. static void rt5663_i2c_shutdown(struct i2c_client *client)
  2933. {
  2934. struct rt5663_priv *rt5663 = i2c_get_clientdata(client);
  2935. regmap_write(rt5663->regmap, RT5663_RESET, 0);
  2936. }
  2937. static struct i2c_driver rt5663_i2c_driver = {
  2938. .driver = {
  2939. .name = "rt5663",
  2940. .acpi_match_table = ACPI_PTR(rt5663_acpi_match),
  2941. .of_match_table = of_match_ptr(rt5663_of_match),
  2942. },
  2943. .probe = rt5663_i2c_probe,
  2944. .remove = rt5663_i2c_remove,
  2945. .shutdown = rt5663_i2c_shutdown,
  2946. .id_table = rt5663_i2c_id,
  2947. };
  2948. module_i2c_driver(rt5663_i2c_driver);
  2949. MODULE_DESCRIPTION("ASoC RT5663 driver");
  2950. MODULE_AUTHOR("Jack Yu <jack.yu@realtek.com>");
  2951. MODULE_LICENSE("GPL v2");