rt5663.c 104 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * rt5663.c -- RT5663 ALSA SoC audio codec driver
  4. *
  5. * Copyright 2016 Realtek Semiconductor Corp.
  6. * Author: Jack Yu <[email protected]>
  7. */
  8. #include <linux/module.h>
  9. #include <linux/moduleparam.h>
  10. #include <linux/init.h>
  11. #include <linux/delay.h>
  12. #include <linux/pm.h>
  13. #include <linux/i2c.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/spi/spi.h>
  16. #include <linux/acpi.h>
  17. #include <linux/regulator/consumer.h>
  18. #include <linux/workqueue.h>
  19. #include <sound/core.h>
  20. #include <sound/pcm.h>
  21. #include <sound/pcm_params.h>
  22. #include <sound/jack.h>
  23. #include <sound/soc.h>
  24. #include <sound/soc-dapm.h>
  25. #include <sound/initval.h>
  26. #include <sound/tlv.h>
  27. #include "rt5663.h"
  28. #include "rl6231.h"
  29. #define RT5663_DEVICE_ID_2 0x6451
  30. #define RT5663_DEVICE_ID_1 0x6406
  31. #define RT5663_POWER_ON_DELAY_MS 300
  32. #define RT5663_SUPPLY_CURRENT_UA 500000
  33. enum {
  34. CODEC_VER_1,
  35. CODEC_VER_0,
  36. };
  37. struct impedance_mapping_table {
  38. unsigned int imp_min;
  39. unsigned int imp_max;
  40. unsigned int vol;
  41. unsigned int dc_offset_l_manual;
  42. unsigned int dc_offset_r_manual;
  43. unsigned int dc_offset_l_manual_mic;
  44. unsigned int dc_offset_r_manual_mic;
  45. };
  46. static const char *const rt5663_supply_names[] = {
  47. "avdd",
  48. "cpvdd",
  49. };
  50. struct rt5663_priv {
  51. struct snd_soc_component *component;
  52. struct rt5663_platform_data pdata;
  53. struct regmap *regmap;
  54. struct delayed_work jack_detect_work, jd_unplug_work;
  55. struct snd_soc_jack *hs_jack;
  56. struct timer_list btn_check_timer;
  57. struct impedance_mapping_table *imp_table;
  58. struct regulator_bulk_data supplies[ARRAY_SIZE(rt5663_supply_names)];
  59. int codec_ver;
  60. int sysclk;
  61. int sysclk_src;
  62. int lrck;
  63. int pll_src;
  64. int pll_in;
  65. int pll_out;
  66. int jack_type;
  67. };
  68. static const struct reg_sequence rt5663_patch_list[] = {
  69. { 0x002a, 0x8020 },
  70. { 0x0086, 0x0028 },
  71. { 0x0100, 0xa020 },
  72. { 0x0117, 0x0f28 },
  73. { 0x02fb, 0x8089 },
  74. };
  75. static const struct reg_default rt5663_v2_reg[] = {
  76. { 0x0000, 0x0000 },
  77. { 0x0001, 0xc8c8 },
  78. { 0x0002, 0x8080 },
  79. { 0x0003, 0x8000 },
  80. { 0x0004, 0xc80a },
  81. { 0x0005, 0x0000 },
  82. { 0x0006, 0x0000 },
  83. { 0x0007, 0x0000 },
  84. { 0x000a, 0x0000 },
  85. { 0x000b, 0x0000 },
  86. { 0x000c, 0x0000 },
  87. { 0x000d, 0x0000 },
  88. { 0x000f, 0x0808 },
  89. { 0x0010, 0x4000 },
  90. { 0x0011, 0x0000 },
  91. { 0x0012, 0x1404 },
  92. { 0x0013, 0x1000 },
  93. { 0x0014, 0xa00a },
  94. { 0x0015, 0x0404 },
  95. { 0x0016, 0x0404 },
  96. { 0x0017, 0x0011 },
  97. { 0x0018, 0xafaf },
  98. { 0x0019, 0xafaf },
  99. { 0x001a, 0xafaf },
  100. { 0x001b, 0x0011 },
  101. { 0x001c, 0x2f2f },
  102. { 0x001d, 0x2f2f },
  103. { 0x001e, 0x2f2f },
  104. { 0x001f, 0x0000 },
  105. { 0x0020, 0x0000 },
  106. { 0x0021, 0x0000 },
  107. { 0x0022, 0x5757 },
  108. { 0x0023, 0x0039 },
  109. { 0x0024, 0x000b },
  110. { 0x0026, 0xc0c0 },
  111. { 0x0027, 0xc0c0 },
  112. { 0x0028, 0xc0c0 },
  113. { 0x0029, 0x8080 },
  114. { 0x002a, 0xaaaa },
  115. { 0x002b, 0xaaaa },
  116. { 0x002c, 0xaba8 },
  117. { 0x002d, 0x0000 },
  118. { 0x002e, 0x0000 },
  119. { 0x002f, 0x0000 },
  120. { 0x0030, 0x0000 },
  121. { 0x0031, 0x5000 },
  122. { 0x0032, 0x0000 },
  123. { 0x0033, 0x0000 },
  124. { 0x0034, 0x0000 },
  125. { 0x0035, 0x0000 },
  126. { 0x003a, 0x0000 },
  127. { 0x003b, 0x0000 },
  128. { 0x003c, 0x00ff },
  129. { 0x003d, 0x0000 },
  130. { 0x003e, 0x00ff },
  131. { 0x003f, 0x0000 },
  132. { 0x0040, 0x0000 },
  133. { 0x0041, 0x00ff },
  134. { 0x0042, 0x0000 },
  135. { 0x0043, 0x00ff },
  136. { 0x0044, 0x0c0c },
  137. { 0x0049, 0xc00b },
  138. { 0x004a, 0x0000 },
  139. { 0x004b, 0x031f },
  140. { 0x004d, 0x0000 },
  141. { 0x004e, 0x001f },
  142. { 0x004f, 0x0000 },
  143. { 0x0050, 0x001f },
  144. { 0x0052, 0xf000 },
  145. { 0x0061, 0x0000 },
  146. { 0x0062, 0x0000 },
  147. { 0x0063, 0x003e },
  148. { 0x0064, 0x0000 },
  149. { 0x0065, 0x0000 },
  150. { 0x0066, 0x003f },
  151. { 0x0067, 0x0000 },
  152. { 0x006b, 0x0000 },
  153. { 0x006d, 0xff00 },
  154. { 0x006e, 0x2808 },
  155. { 0x006f, 0x000a },
  156. { 0x0070, 0x8000 },
  157. { 0x0071, 0x8000 },
  158. { 0x0072, 0x8000 },
  159. { 0x0073, 0x7000 },
  160. { 0x0074, 0x7770 },
  161. { 0x0075, 0x0002 },
  162. { 0x0076, 0x0001 },
  163. { 0x0078, 0x00f0 },
  164. { 0x0079, 0x0000 },
  165. { 0x007a, 0x0000 },
  166. { 0x007b, 0x0000 },
  167. { 0x007c, 0x0000 },
  168. { 0x007d, 0x0123 },
  169. { 0x007e, 0x4500 },
  170. { 0x007f, 0x8003 },
  171. { 0x0080, 0x0000 },
  172. { 0x0081, 0x0000 },
  173. { 0x0082, 0x0000 },
  174. { 0x0083, 0x0000 },
  175. { 0x0084, 0x0000 },
  176. { 0x0085, 0x0000 },
  177. { 0x0086, 0x0008 },
  178. { 0x0087, 0x0000 },
  179. { 0x0088, 0x0000 },
  180. { 0x0089, 0x0000 },
  181. { 0x008a, 0x0000 },
  182. { 0x008b, 0x0000 },
  183. { 0x008c, 0x0003 },
  184. { 0x008e, 0x0060 },
  185. { 0x008f, 0x1000 },
  186. { 0x0091, 0x0c26 },
  187. { 0x0092, 0x0073 },
  188. { 0x0093, 0x0000 },
  189. { 0x0094, 0x0080 },
  190. { 0x0098, 0x0000 },
  191. { 0x0099, 0x0000 },
  192. { 0x009a, 0x0007 },
  193. { 0x009f, 0x0000 },
  194. { 0x00a0, 0x0000 },
  195. { 0x00a1, 0x0002 },
  196. { 0x00a2, 0x0001 },
  197. { 0x00a3, 0x0002 },
  198. { 0x00a4, 0x0001 },
  199. { 0x00ae, 0x2040 },
  200. { 0x00af, 0x0000 },
  201. { 0x00b6, 0x0000 },
  202. { 0x00b7, 0x0000 },
  203. { 0x00b8, 0x0000 },
  204. { 0x00b9, 0x0000 },
  205. { 0x00ba, 0x0002 },
  206. { 0x00bb, 0x0000 },
  207. { 0x00be, 0x0000 },
  208. { 0x00c0, 0x0000 },
  209. { 0x00c1, 0x0aaa },
  210. { 0x00c2, 0xaa80 },
  211. { 0x00c3, 0x0003 },
  212. { 0x00c4, 0x0000 },
  213. { 0x00d0, 0x0000 },
  214. { 0x00d1, 0x2244 },
  215. { 0x00d2, 0x0000 },
  216. { 0x00d3, 0x3300 },
  217. { 0x00d4, 0x2200 },
  218. { 0x00d9, 0x0809 },
  219. { 0x00da, 0x0000 },
  220. { 0x00db, 0x0008 },
  221. { 0x00dc, 0x00c0 },
  222. { 0x00dd, 0x6724 },
  223. { 0x00de, 0x3131 },
  224. { 0x00df, 0x0008 },
  225. { 0x00e0, 0x4000 },
  226. { 0x00e1, 0x3131 },
  227. { 0x00e2, 0x600c },
  228. { 0x00ea, 0xb320 },
  229. { 0x00eb, 0x0000 },
  230. { 0x00ec, 0xb300 },
  231. { 0x00ed, 0x0000 },
  232. { 0x00ee, 0xb320 },
  233. { 0x00ef, 0x0000 },
  234. { 0x00f0, 0x0201 },
  235. { 0x00f1, 0x0ddd },
  236. { 0x00f2, 0x0ddd },
  237. { 0x00f6, 0x0000 },
  238. { 0x00f7, 0x0000 },
  239. { 0x00f8, 0x0000 },
  240. { 0x00fa, 0x0000 },
  241. { 0x00fb, 0x0000 },
  242. { 0x00fc, 0x0000 },
  243. { 0x00fd, 0x0000 },
  244. { 0x00fe, 0x10ec },
  245. { 0x00ff, 0x6451 },
  246. { 0x0100, 0xaaaa },
  247. { 0x0101, 0x000a },
  248. { 0x010a, 0xaaaa },
  249. { 0x010b, 0xa0a0 },
  250. { 0x010c, 0xaeae },
  251. { 0x010d, 0xaaaa },
  252. { 0x010e, 0xaaaa },
  253. { 0x010f, 0xaaaa },
  254. { 0x0110, 0xe002 },
  255. { 0x0111, 0xa602 },
  256. { 0x0112, 0xaaaa },
  257. { 0x0113, 0x2000 },
  258. { 0x0117, 0x0f00 },
  259. { 0x0125, 0x0420 },
  260. { 0x0132, 0x0000 },
  261. { 0x0133, 0x0000 },
  262. { 0x0136, 0x5555 },
  263. { 0x0137, 0x5540 },
  264. { 0x0138, 0x3700 },
  265. { 0x0139, 0x79a1 },
  266. { 0x013a, 0x2020 },
  267. { 0x013b, 0x2020 },
  268. { 0x013c, 0x2005 },
  269. { 0x013f, 0x0000 },
  270. { 0x0145, 0x0002 },
  271. { 0x0146, 0x0000 },
  272. { 0x0147, 0x0000 },
  273. { 0x0148, 0x0000 },
  274. { 0x0160, 0x4ec0 },
  275. { 0x0161, 0x0080 },
  276. { 0x0162, 0x0200 },
  277. { 0x0163, 0x0800 },
  278. { 0x0164, 0x0000 },
  279. { 0x0165, 0x0000 },
  280. { 0x0166, 0x0000 },
  281. { 0x0167, 0x000f },
  282. { 0x0168, 0x000f },
  283. { 0x0170, 0x4e80 },
  284. { 0x0171, 0x0080 },
  285. { 0x0172, 0x0200 },
  286. { 0x0173, 0x0800 },
  287. { 0x0174, 0x00ff },
  288. { 0x0175, 0x0000 },
  289. { 0x0190, 0x4131 },
  290. { 0x0191, 0x4131 },
  291. { 0x0192, 0x4131 },
  292. { 0x0193, 0x4131 },
  293. { 0x0194, 0x0000 },
  294. { 0x0195, 0x0000 },
  295. { 0x0196, 0x0000 },
  296. { 0x0197, 0x0000 },
  297. { 0x0198, 0x0000 },
  298. { 0x0199, 0x0000 },
  299. { 0x01a0, 0x1e64 },
  300. { 0x01a1, 0x06a3 },
  301. { 0x01a2, 0x0000 },
  302. { 0x01a3, 0x0000 },
  303. { 0x01a4, 0x0000 },
  304. { 0x01a5, 0x0000 },
  305. { 0x01a6, 0x0000 },
  306. { 0x01a7, 0x0000 },
  307. { 0x01a8, 0x0000 },
  308. { 0x01a9, 0x0000 },
  309. { 0x01aa, 0x0000 },
  310. { 0x01ab, 0x0000 },
  311. { 0x01b5, 0x0000 },
  312. { 0x01b6, 0x01c3 },
  313. { 0x01b7, 0x02a0 },
  314. { 0x01b8, 0x03e9 },
  315. { 0x01b9, 0x1389 },
  316. { 0x01ba, 0xc351 },
  317. { 0x01bb, 0x0009 },
  318. { 0x01bc, 0x0018 },
  319. { 0x01bd, 0x002a },
  320. { 0x01be, 0x004c },
  321. { 0x01bf, 0x0097 },
  322. { 0x01c0, 0x433d },
  323. { 0x01c1, 0x0000 },
  324. { 0x01c2, 0x0000 },
  325. { 0x01c3, 0x0000 },
  326. { 0x01c4, 0x0000 },
  327. { 0x01c5, 0x0000 },
  328. { 0x01c6, 0x0000 },
  329. { 0x01c7, 0x0000 },
  330. { 0x01c8, 0x40af },
  331. { 0x01c9, 0x0702 },
  332. { 0x01ca, 0x0000 },
  333. { 0x01cb, 0x0000 },
  334. { 0x01cc, 0x5757 },
  335. { 0x01cd, 0x5757 },
  336. { 0x01ce, 0x5757 },
  337. { 0x01cf, 0x5757 },
  338. { 0x01d0, 0x5757 },
  339. { 0x01d1, 0x5757 },
  340. { 0x01d2, 0x5757 },
  341. { 0x01d3, 0x5757 },
  342. { 0x01d4, 0x5757 },
  343. { 0x01d5, 0x5757 },
  344. { 0x01d6, 0x003c },
  345. { 0x01da, 0x0000 },
  346. { 0x01db, 0x0000 },
  347. { 0x01dc, 0x0000 },
  348. { 0x01de, 0x7c00 },
  349. { 0x01df, 0x0320 },
  350. { 0x01e0, 0x06a1 },
  351. { 0x01e1, 0x0000 },
  352. { 0x01e2, 0x0000 },
  353. { 0x01e3, 0x0000 },
  354. { 0x01e4, 0x0000 },
  355. { 0x01e5, 0x0000 },
  356. { 0x01e6, 0x0001 },
  357. { 0x01e7, 0x0000 },
  358. { 0x01e8, 0x0000 },
  359. { 0x01ea, 0x0000 },
  360. { 0x01eb, 0x0000 },
  361. { 0x01ec, 0x0000 },
  362. { 0x01ed, 0x0000 },
  363. { 0x01ee, 0x0000 },
  364. { 0x01ef, 0x0000 },
  365. { 0x01f0, 0x0000 },
  366. { 0x01f1, 0x0000 },
  367. { 0x01f2, 0x0000 },
  368. { 0x01f3, 0x0000 },
  369. { 0x01f4, 0x0000 },
  370. { 0x0200, 0x0000 },
  371. { 0x0201, 0x0000 },
  372. { 0x0202, 0x0000 },
  373. { 0x0203, 0x0000 },
  374. { 0x0204, 0x0000 },
  375. { 0x0205, 0x0000 },
  376. { 0x0206, 0x0000 },
  377. { 0x0207, 0x0000 },
  378. { 0x0208, 0x0000 },
  379. { 0x0210, 0x60b1 },
  380. { 0x0211, 0xa000 },
  381. { 0x0212, 0x024c },
  382. { 0x0213, 0xf7ff },
  383. { 0x0214, 0x024c },
  384. { 0x0215, 0x0102 },
  385. { 0x0216, 0x00a3 },
  386. { 0x0217, 0x0048 },
  387. { 0x0218, 0x92c0 },
  388. { 0x0219, 0x0000 },
  389. { 0x021a, 0x00c8 },
  390. { 0x021b, 0x0020 },
  391. { 0x02fa, 0x0000 },
  392. { 0x02fb, 0x0000 },
  393. { 0x02fc, 0x0000 },
  394. { 0x02ff, 0x0110 },
  395. { 0x0300, 0x001f },
  396. { 0x0301, 0x032c },
  397. { 0x0302, 0x5f21 },
  398. { 0x0303, 0x4000 },
  399. { 0x0304, 0x4000 },
  400. { 0x0305, 0x06d5 },
  401. { 0x0306, 0x8000 },
  402. { 0x0307, 0x0700 },
  403. { 0x0310, 0x4560 },
  404. { 0x0311, 0xa4a8 },
  405. { 0x0312, 0x7418 },
  406. { 0x0313, 0x0000 },
  407. { 0x0314, 0x0006 },
  408. { 0x0315, 0xffff },
  409. { 0x0316, 0xc400 },
  410. { 0x0317, 0x0000 },
  411. { 0x0330, 0x00a6 },
  412. { 0x0331, 0x04c3 },
  413. { 0x0332, 0x27c8 },
  414. { 0x0333, 0xbf50 },
  415. { 0x0334, 0x0045 },
  416. { 0x0335, 0x0007 },
  417. { 0x0336, 0x7418 },
  418. { 0x0337, 0x0501 },
  419. { 0x0338, 0x0000 },
  420. { 0x0339, 0x0010 },
  421. { 0x033a, 0x1010 },
  422. { 0x03c0, 0x7e00 },
  423. { 0x03c1, 0x8000 },
  424. { 0x03c2, 0x8000 },
  425. { 0x03c3, 0x8000 },
  426. { 0x03c4, 0x8000 },
  427. { 0x03c5, 0x8000 },
  428. { 0x03c6, 0x8000 },
  429. { 0x03c7, 0x8000 },
  430. { 0x03c8, 0x8000 },
  431. { 0x03c9, 0x8000 },
  432. { 0x03ca, 0x8000 },
  433. { 0x03cb, 0x8000 },
  434. { 0x03cc, 0x8000 },
  435. { 0x03d0, 0x0000 },
  436. { 0x03d1, 0x0000 },
  437. { 0x03d2, 0x0000 },
  438. { 0x03d3, 0x0000 },
  439. { 0x03d4, 0x2000 },
  440. { 0x03d5, 0x2000 },
  441. { 0x03d6, 0x0000 },
  442. { 0x03d7, 0x0000 },
  443. { 0x03d8, 0x2000 },
  444. { 0x03d9, 0x2000 },
  445. { 0x03da, 0x2000 },
  446. { 0x03db, 0x2000 },
  447. { 0x03dc, 0x0000 },
  448. { 0x03dd, 0x0000 },
  449. { 0x03de, 0x0000 },
  450. { 0x03df, 0x2000 },
  451. { 0x03e0, 0x0000 },
  452. { 0x03e1, 0x0000 },
  453. { 0x03e2, 0x0000 },
  454. { 0x03e3, 0x0000 },
  455. { 0x03e4, 0x0000 },
  456. { 0x03e5, 0x0000 },
  457. { 0x03e6, 0x0000 },
  458. { 0x03e7, 0x0000 },
  459. { 0x03e8, 0x0000 },
  460. { 0x03e9, 0x0000 },
  461. { 0x03ea, 0x0000 },
  462. { 0x03eb, 0x0000 },
  463. { 0x03ec, 0x0000 },
  464. { 0x03ed, 0x0000 },
  465. { 0x03ee, 0x0000 },
  466. { 0x03ef, 0x0000 },
  467. { 0x03f0, 0x0800 },
  468. { 0x03f1, 0x0800 },
  469. { 0x03f2, 0x0800 },
  470. { 0x03f3, 0x0800 },
  471. { 0x03fe, 0x0000 },
  472. { 0x03ff, 0x0000 },
  473. { 0x07f0, 0x0000 },
  474. { 0x07fa, 0x0000 },
  475. };
  476. static const struct reg_default rt5663_reg[] = {
  477. { 0x0000, 0x0000 },
  478. { 0x0002, 0x0008 },
  479. { 0x0005, 0x1000 },
  480. { 0x0006, 0x1000 },
  481. { 0x000a, 0x0000 },
  482. { 0x0010, 0x000f },
  483. { 0x0015, 0x42f1 },
  484. { 0x0016, 0x0000 },
  485. { 0x0018, 0x000b },
  486. { 0x0019, 0xafaf },
  487. { 0x001c, 0x2f2f },
  488. { 0x001f, 0x0000 },
  489. { 0x0022, 0x5757 },
  490. { 0x0023, 0x0039 },
  491. { 0x0026, 0xc0c0 },
  492. { 0x0029, 0x8080 },
  493. { 0x002a, 0x8020 },
  494. { 0x002c, 0x000c },
  495. { 0x002d, 0x0000 },
  496. { 0x0040, 0x0808 },
  497. { 0x0061, 0x0000 },
  498. { 0x0062, 0x0000 },
  499. { 0x0063, 0x003e },
  500. { 0x0064, 0x0000 },
  501. { 0x0065, 0x0000 },
  502. { 0x0066, 0x0000 },
  503. { 0x006b, 0x0000 },
  504. { 0x006e, 0x0000 },
  505. { 0x006f, 0x0000 },
  506. { 0x0070, 0x8020 },
  507. { 0x0073, 0x1000 },
  508. { 0x0074, 0xe400 },
  509. { 0x0075, 0x0002 },
  510. { 0x0076, 0x0001 },
  511. { 0x0077, 0x00f0 },
  512. { 0x0078, 0x0000 },
  513. { 0x0079, 0x0000 },
  514. { 0x007a, 0x0123 },
  515. { 0x007b, 0x8003 },
  516. { 0x0080, 0x0000 },
  517. { 0x0081, 0x0000 },
  518. { 0x0082, 0x0000 },
  519. { 0x0083, 0x0000 },
  520. { 0x0084, 0x0000 },
  521. { 0x0086, 0x0028 },
  522. { 0x0087, 0x0000 },
  523. { 0x008a, 0x0000 },
  524. { 0x008b, 0x0000 },
  525. { 0x008c, 0x0003 },
  526. { 0x008e, 0x0008 },
  527. { 0x008f, 0x1000 },
  528. { 0x0090, 0x0646 },
  529. { 0x0091, 0x0e3e },
  530. { 0x0092, 0x1071 },
  531. { 0x0093, 0x0000 },
  532. { 0x0094, 0x0080 },
  533. { 0x0097, 0x0000 },
  534. { 0x0098, 0x0000 },
  535. { 0x009a, 0x0000 },
  536. { 0x009f, 0x0000 },
  537. { 0x00ae, 0x6000 },
  538. { 0x00af, 0x0000 },
  539. { 0x00b6, 0x0000 },
  540. { 0x00b7, 0x0000 },
  541. { 0x00b8, 0x0000 },
  542. { 0x00ba, 0x0000 },
  543. { 0x00bb, 0x0000 },
  544. { 0x00be, 0x0000 },
  545. { 0x00bf, 0x0000 },
  546. { 0x00c0, 0x0000 },
  547. { 0x00c1, 0x0000 },
  548. { 0x00c5, 0x0000 },
  549. { 0x00cb, 0xa02f },
  550. { 0x00cc, 0x0000 },
  551. { 0x00cd, 0x0e02 },
  552. { 0x00d9, 0x08f9 },
  553. { 0x00db, 0x0008 },
  554. { 0x00dc, 0x00c0 },
  555. { 0x00dd, 0x6729 },
  556. { 0x00de, 0x3131 },
  557. { 0x00df, 0x0008 },
  558. { 0x00e0, 0x4000 },
  559. { 0x00e1, 0x3131 },
  560. { 0x00e2, 0x0043 },
  561. { 0x00e4, 0x400b },
  562. { 0x00e5, 0x8031 },
  563. { 0x00e6, 0x3080 },
  564. { 0x00e7, 0x4100 },
  565. { 0x00e8, 0x1400 },
  566. { 0x00e9, 0xe00a },
  567. { 0x00ea, 0x0404 },
  568. { 0x00eb, 0x0404 },
  569. { 0x00ec, 0xb320 },
  570. { 0x00ed, 0x0000 },
  571. { 0x00f4, 0x0000 },
  572. { 0x00f6, 0x0000 },
  573. { 0x00f8, 0x0000 },
  574. { 0x00fa, 0x8000 },
  575. { 0x00fd, 0x0001 },
  576. { 0x00fe, 0x10ec },
  577. { 0x00ff, 0x6406 },
  578. { 0x0100, 0xa020 },
  579. { 0x0108, 0x4444 },
  580. { 0x0109, 0x4444 },
  581. { 0x010a, 0xaaaa },
  582. { 0x010b, 0x00a0 },
  583. { 0x010c, 0x8aaa },
  584. { 0x010d, 0xaaaa },
  585. { 0x010e, 0x2aaa },
  586. { 0x010f, 0x002a },
  587. { 0x0110, 0xa0a4 },
  588. { 0x0111, 0x4602 },
  589. { 0x0112, 0x0101 },
  590. { 0x0113, 0x2000 },
  591. { 0x0114, 0x0000 },
  592. { 0x0116, 0x0000 },
  593. { 0x0117, 0x0f28 },
  594. { 0x0118, 0x0006 },
  595. { 0x0125, 0x2424 },
  596. { 0x0126, 0x5550 },
  597. { 0x0127, 0x0400 },
  598. { 0x0128, 0x7711 },
  599. { 0x0132, 0x0004 },
  600. { 0x0137, 0x5441 },
  601. { 0x0139, 0x79a1 },
  602. { 0x013a, 0x30c0 },
  603. { 0x013b, 0x2000 },
  604. { 0x013c, 0x2005 },
  605. { 0x013d, 0x30c0 },
  606. { 0x013e, 0x0000 },
  607. { 0x0140, 0x3700 },
  608. { 0x0141, 0x1f00 },
  609. { 0x0144, 0x0000 },
  610. { 0x0145, 0x0002 },
  611. { 0x0146, 0x0000 },
  612. { 0x0160, 0x0e80 },
  613. { 0x0161, 0x0080 },
  614. { 0x0162, 0x0200 },
  615. { 0x0163, 0x0800 },
  616. { 0x0164, 0x0000 },
  617. { 0x0165, 0x0000 },
  618. { 0x0166, 0x0000 },
  619. { 0x0167, 0x1417 },
  620. { 0x0168, 0x0017 },
  621. { 0x0169, 0x0017 },
  622. { 0x0180, 0x2000 },
  623. { 0x0181, 0x0000 },
  624. { 0x0182, 0x0000 },
  625. { 0x0183, 0x2000 },
  626. { 0x0184, 0x0000 },
  627. { 0x0185, 0x0000 },
  628. { 0x01b0, 0x4b30 },
  629. { 0x01b1, 0x0000 },
  630. { 0x01b2, 0xd870 },
  631. { 0x01b3, 0x0000 },
  632. { 0x01b4, 0x0030 },
  633. { 0x01b5, 0x5757 },
  634. { 0x01b6, 0x5757 },
  635. { 0x01b7, 0x5757 },
  636. { 0x01b8, 0x5757 },
  637. { 0x01c0, 0x433d },
  638. { 0x01c1, 0x0540 },
  639. { 0x01c2, 0x0000 },
  640. { 0x01c3, 0x0000 },
  641. { 0x01c4, 0x0000 },
  642. { 0x01c5, 0x0009 },
  643. { 0x01c6, 0x0018 },
  644. { 0x01c7, 0x002a },
  645. { 0x01c8, 0x004c },
  646. { 0x01c9, 0x0097 },
  647. { 0x01ca, 0x01c3 },
  648. { 0x01cb, 0x03e9 },
  649. { 0x01cc, 0x1389 },
  650. { 0x01cd, 0xc351 },
  651. { 0x01ce, 0x0000 },
  652. { 0x01cf, 0x0000 },
  653. { 0x01d0, 0x0000 },
  654. { 0x01d1, 0x0000 },
  655. { 0x01d2, 0x0000 },
  656. { 0x01d3, 0x003c },
  657. { 0x01d4, 0x5757 },
  658. { 0x01d5, 0x5757 },
  659. { 0x01d6, 0x5757 },
  660. { 0x01d7, 0x5757 },
  661. { 0x01d8, 0x5757 },
  662. { 0x01d9, 0x5757 },
  663. { 0x01da, 0x0000 },
  664. { 0x01db, 0x0000 },
  665. { 0x01dd, 0x0009 },
  666. { 0x01de, 0x7f00 },
  667. { 0x01df, 0x00c8 },
  668. { 0x01e0, 0x0691 },
  669. { 0x01e1, 0x0000 },
  670. { 0x01e2, 0x0000 },
  671. { 0x01e3, 0x0000 },
  672. { 0x01e4, 0x0000 },
  673. { 0x01e5, 0x0040 },
  674. { 0x01e6, 0x0000 },
  675. { 0x01e7, 0x0000 },
  676. { 0x01e8, 0x0000 },
  677. { 0x01ea, 0x0000 },
  678. { 0x01eb, 0x0000 },
  679. { 0x01ec, 0x0000 },
  680. { 0x01ed, 0x0000 },
  681. { 0x01ee, 0x0000 },
  682. { 0x01ef, 0x0000 },
  683. { 0x01f0, 0x0000 },
  684. { 0x01f1, 0x0000 },
  685. { 0x01f2, 0x0000 },
  686. { 0x0200, 0x0000 },
  687. { 0x0201, 0x2244 },
  688. { 0x0202, 0xaaaa },
  689. { 0x0250, 0x8010 },
  690. { 0x0251, 0x0000 },
  691. { 0x0252, 0x028a },
  692. { 0x02fa, 0x0000 },
  693. { 0x02fb, 0x8089 },
  694. { 0x02fc, 0x0300 },
  695. { 0x0300, 0x0000 },
  696. { 0x03d0, 0x0000 },
  697. { 0x03d1, 0x0000 },
  698. { 0x03d2, 0x0000 },
  699. { 0x03d3, 0x0000 },
  700. { 0x03d4, 0x2000 },
  701. { 0x03d5, 0x2000 },
  702. { 0x03d6, 0x0000 },
  703. { 0x03d7, 0x0000 },
  704. { 0x03d8, 0x2000 },
  705. { 0x03d9, 0x2000 },
  706. { 0x03da, 0x2000 },
  707. { 0x03db, 0x2000 },
  708. { 0x03dc, 0x0000 },
  709. { 0x03dd, 0x0000 },
  710. { 0x03de, 0x0000 },
  711. { 0x03df, 0x2000 },
  712. { 0x03e0, 0x0000 },
  713. { 0x03e1, 0x0000 },
  714. { 0x03e2, 0x0000 },
  715. { 0x03e3, 0x0000 },
  716. { 0x03e4, 0x0000 },
  717. { 0x03e5, 0x0000 },
  718. { 0x03e6, 0x0000 },
  719. { 0x03e7, 0x0000 },
  720. { 0x03e8, 0x0000 },
  721. { 0x03e9, 0x0000 },
  722. { 0x03ea, 0x0000 },
  723. { 0x03eb, 0x0000 },
  724. { 0x03ec, 0x0000 },
  725. { 0x03ed, 0x0000 },
  726. { 0x03ee, 0x0000 },
  727. { 0x03ef, 0x0000 },
  728. { 0x03f0, 0x0800 },
  729. { 0x03f1, 0x0800 },
  730. { 0x03f2, 0x0800 },
  731. { 0x03f3, 0x0800 },
  732. };
  733. static bool rt5663_volatile_register(struct device *dev, unsigned int reg)
  734. {
  735. switch (reg) {
  736. case RT5663_RESET:
  737. case RT5663_SIL_DET_CTL:
  738. case RT5663_HP_IMP_GAIN_2:
  739. case RT5663_AD_DA_MIXER:
  740. case RT5663_FRAC_DIV_2:
  741. case RT5663_MICBIAS_1:
  742. case RT5663_ASRC_11_2:
  743. case RT5663_ADC_EQ_1:
  744. case RT5663_INT_ST_1:
  745. case RT5663_INT_ST_2:
  746. case RT5663_GPIO_STA1:
  747. case RT5663_SIN_GEN_1:
  748. case RT5663_IL_CMD_1:
  749. case RT5663_IL_CMD_5:
  750. case RT5663_IL_CMD_PWRSAV1:
  751. case RT5663_EM_JACK_TYPE_1:
  752. case RT5663_EM_JACK_TYPE_2:
  753. case RT5663_EM_JACK_TYPE_3:
  754. case RT5663_JD_CTRL2:
  755. case RT5663_VENDOR_ID:
  756. case RT5663_VENDOR_ID_1:
  757. case RT5663_VENDOR_ID_2:
  758. case RT5663_PLL_INT_REG:
  759. case RT5663_SOFT_RAMP:
  760. case RT5663_STO_DRE_1:
  761. case RT5663_STO_DRE_5:
  762. case RT5663_STO_DRE_6:
  763. case RT5663_STO_DRE_7:
  764. case RT5663_MIC_DECRO_1:
  765. case RT5663_MIC_DECRO_4:
  766. case RT5663_HP_IMP_SEN_1:
  767. case RT5663_HP_IMP_SEN_3:
  768. case RT5663_HP_IMP_SEN_4:
  769. case RT5663_HP_IMP_SEN_5:
  770. case RT5663_HP_CALIB_1_1:
  771. case RT5663_HP_CALIB_9:
  772. case RT5663_HP_CALIB_ST1:
  773. case RT5663_HP_CALIB_ST2:
  774. case RT5663_HP_CALIB_ST3:
  775. case RT5663_HP_CALIB_ST4:
  776. case RT5663_HP_CALIB_ST5:
  777. case RT5663_HP_CALIB_ST6:
  778. case RT5663_HP_CALIB_ST7:
  779. case RT5663_HP_CALIB_ST8:
  780. case RT5663_HP_CALIB_ST9:
  781. case RT5663_ANA_JD:
  782. return true;
  783. default:
  784. return false;
  785. }
  786. }
  787. static bool rt5663_readable_register(struct device *dev, unsigned int reg)
  788. {
  789. switch (reg) {
  790. case RT5663_RESET:
  791. case RT5663_HP_OUT_EN:
  792. case RT5663_HP_LCH_DRE:
  793. case RT5663_HP_RCH_DRE:
  794. case RT5663_CALIB_BST:
  795. case RT5663_RECMIX:
  796. case RT5663_SIL_DET_CTL:
  797. case RT5663_PWR_SAV_SILDET:
  798. case RT5663_SIDETONE_CTL:
  799. case RT5663_STO1_DAC_DIG_VOL:
  800. case RT5663_STO1_ADC_DIG_VOL:
  801. case RT5663_STO1_BOOST:
  802. case RT5663_HP_IMP_GAIN_1:
  803. case RT5663_HP_IMP_GAIN_2:
  804. case RT5663_STO1_ADC_MIXER:
  805. case RT5663_AD_DA_MIXER:
  806. case RT5663_STO_DAC_MIXER:
  807. case RT5663_DIG_SIDE_MIXER:
  808. case RT5663_BYPASS_STO_DAC:
  809. case RT5663_CALIB_REC_MIX:
  810. case RT5663_PWR_DIG_1:
  811. case RT5663_PWR_DIG_2:
  812. case RT5663_PWR_ANLG_1:
  813. case RT5663_PWR_ANLG_2:
  814. case RT5663_PWR_ANLG_3:
  815. case RT5663_PWR_MIXER:
  816. case RT5663_SIG_CLK_DET:
  817. case RT5663_PRE_DIV_GATING_1:
  818. case RT5663_PRE_DIV_GATING_2:
  819. case RT5663_I2S1_SDP:
  820. case RT5663_ADDA_CLK_1:
  821. case RT5663_ADDA_RST:
  822. case RT5663_FRAC_DIV_1:
  823. case RT5663_FRAC_DIV_2:
  824. case RT5663_TDM_1:
  825. case RT5663_TDM_2:
  826. case RT5663_TDM_3:
  827. case RT5663_TDM_4:
  828. case RT5663_TDM_5:
  829. case RT5663_GLB_CLK:
  830. case RT5663_PLL_1:
  831. case RT5663_PLL_2:
  832. case RT5663_ASRC_1:
  833. case RT5663_ASRC_2:
  834. case RT5663_ASRC_4:
  835. case RT5663_DUMMY_REG:
  836. case RT5663_ASRC_8:
  837. case RT5663_ASRC_9:
  838. case RT5663_ASRC_11:
  839. case RT5663_DEPOP_1:
  840. case RT5663_DEPOP_2:
  841. case RT5663_DEPOP_3:
  842. case RT5663_HP_CHARGE_PUMP_1:
  843. case RT5663_HP_CHARGE_PUMP_2:
  844. case RT5663_MICBIAS_1:
  845. case RT5663_RC_CLK:
  846. case RT5663_ASRC_11_2:
  847. case RT5663_DUMMY_REG_2:
  848. case RT5663_REC_PATH_GAIN:
  849. case RT5663_AUTO_1MRC_CLK:
  850. case RT5663_ADC_EQ_1:
  851. case RT5663_ADC_EQ_2:
  852. case RT5663_IRQ_1:
  853. case RT5663_IRQ_2:
  854. case RT5663_IRQ_3:
  855. case RT5663_IRQ_4:
  856. case RT5663_IRQ_5:
  857. case RT5663_INT_ST_1:
  858. case RT5663_INT_ST_2:
  859. case RT5663_GPIO_1:
  860. case RT5663_GPIO_2:
  861. case RT5663_GPIO_STA1:
  862. case RT5663_SIN_GEN_1:
  863. case RT5663_SIN_GEN_2:
  864. case RT5663_SIN_GEN_3:
  865. case RT5663_SOF_VOL_ZC1:
  866. case RT5663_IL_CMD_1:
  867. case RT5663_IL_CMD_2:
  868. case RT5663_IL_CMD_3:
  869. case RT5663_IL_CMD_4:
  870. case RT5663_IL_CMD_5:
  871. case RT5663_IL_CMD_6:
  872. case RT5663_IL_CMD_7:
  873. case RT5663_IL_CMD_8:
  874. case RT5663_IL_CMD_PWRSAV1:
  875. case RT5663_IL_CMD_PWRSAV2:
  876. case RT5663_EM_JACK_TYPE_1:
  877. case RT5663_EM_JACK_TYPE_2:
  878. case RT5663_EM_JACK_TYPE_3:
  879. case RT5663_EM_JACK_TYPE_4:
  880. case RT5663_EM_JACK_TYPE_5:
  881. case RT5663_EM_JACK_TYPE_6:
  882. case RT5663_STO1_HPF_ADJ1:
  883. case RT5663_STO1_HPF_ADJ2:
  884. case RT5663_FAST_OFF_MICBIAS:
  885. case RT5663_JD_CTRL1:
  886. case RT5663_JD_CTRL2:
  887. case RT5663_DIG_MISC:
  888. case RT5663_VENDOR_ID:
  889. case RT5663_VENDOR_ID_1:
  890. case RT5663_VENDOR_ID_2:
  891. case RT5663_DIG_VOL_ZCD:
  892. case RT5663_ANA_BIAS_CUR_1:
  893. case RT5663_ANA_BIAS_CUR_2:
  894. case RT5663_ANA_BIAS_CUR_3:
  895. case RT5663_ANA_BIAS_CUR_4:
  896. case RT5663_ANA_BIAS_CUR_5:
  897. case RT5663_ANA_BIAS_CUR_6:
  898. case RT5663_BIAS_CUR_5:
  899. case RT5663_BIAS_CUR_6:
  900. case RT5663_BIAS_CUR_7:
  901. case RT5663_BIAS_CUR_8:
  902. case RT5663_DACREF_LDO:
  903. case RT5663_DUMMY_REG_3:
  904. case RT5663_BIAS_CUR_9:
  905. case RT5663_DUMMY_REG_4:
  906. case RT5663_VREFADJ_OP:
  907. case RT5663_VREF_RECMIX:
  908. case RT5663_CHARGE_PUMP_1:
  909. case RT5663_CHARGE_PUMP_1_2:
  910. case RT5663_CHARGE_PUMP_1_3:
  911. case RT5663_CHARGE_PUMP_2:
  912. case RT5663_DIG_IN_PIN1:
  913. case RT5663_PAD_DRV_CTL:
  914. case RT5663_PLL_INT_REG:
  915. case RT5663_CHOP_DAC_L:
  916. case RT5663_CHOP_ADC:
  917. case RT5663_CALIB_ADC:
  918. case RT5663_CHOP_DAC_R:
  919. case RT5663_DUMMY_CTL_DACLR:
  920. case RT5663_DUMMY_REG_5:
  921. case RT5663_SOFT_RAMP:
  922. case RT5663_TEST_MODE_1:
  923. case RT5663_TEST_MODE_2:
  924. case RT5663_TEST_MODE_3:
  925. case RT5663_STO_DRE_1:
  926. case RT5663_STO_DRE_2:
  927. case RT5663_STO_DRE_3:
  928. case RT5663_STO_DRE_4:
  929. case RT5663_STO_DRE_5:
  930. case RT5663_STO_DRE_6:
  931. case RT5663_STO_DRE_7:
  932. case RT5663_STO_DRE_8:
  933. case RT5663_STO_DRE_9:
  934. case RT5663_STO_DRE_10:
  935. case RT5663_MIC_DECRO_1:
  936. case RT5663_MIC_DECRO_2:
  937. case RT5663_MIC_DECRO_3:
  938. case RT5663_MIC_DECRO_4:
  939. case RT5663_MIC_DECRO_5:
  940. case RT5663_MIC_DECRO_6:
  941. case RT5663_HP_DECRO_1:
  942. case RT5663_HP_DECRO_2:
  943. case RT5663_HP_DECRO_3:
  944. case RT5663_HP_DECRO_4:
  945. case RT5663_HP_DECOUP:
  946. case RT5663_HP_IMP_SEN_MAP8:
  947. case RT5663_HP_IMP_SEN_MAP9:
  948. case RT5663_HP_IMP_SEN_MAP10:
  949. case RT5663_HP_IMP_SEN_MAP11:
  950. case RT5663_HP_IMP_SEN_1:
  951. case RT5663_HP_IMP_SEN_2:
  952. case RT5663_HP_IMP_SEN_3:
  953. case RT5663_HP_IMP_SEN_4:
  954. case RT5663_HP_IMP_SEN_5:
  955. case RT5663_HP_IMP_SEN_6:
  956. case RT5663_HP_IMP_SEN_7:
  957. case RT5663_HP_IMP_SEN_8:
  958. case RT5663_HP_IMP_SEN_9:
  959. case RT5663_HP_IMP_SEN_10:
  960. case RT5663_HP_IMP_SEN_11:
  961. case RT5663_HP_IMP_SEN_12:
  962. case RT5663_HP_IMP_SEN_13:
  963. case RT5663_HP_IMP_SEN_14:
  964. case RT5663_HP_IMP_SEN_15:
  965. case RT5663_HP_IMP_SEN_16:
  966. case RT5663_HP_IMP_SEN_17:
  967. case RT5663_HP_IMP_SEN_18:
  968. case RT5663_HP_IMP_SEN_19:
  969. case RT5663_HP_IMPSEN_DIG5:
  970. case RT5663_HP_IMPSEN_MAP1:
  971. case RT5663_HP_IMPSEN_MAP2:
  972. case RT5663_HP_IMPSEN_MAP3:
  973. case RT5663_HP_IMPSEN_MAP4:
  974. case RT5663_HP_IMPSEN_MAP5:
  975. case RT5663_HP_IMPSEN_MAP7:
  976. case RT5663_HP_LOGIC_1:
  977. case RT5663_HP_LOGIC_2:
  978. case RT5663_HP_CALIB_1:
  979. case RT5663_HP_CALIB_1_1:
  980. case RT5663_HP_CALIB_2:
  981. case RT5663_HP_CALIB_3:
  982. case RT5663_HP_CALIB_4:
  983. case RT5663_HP_CALIB_5:
  984. case RT5663_HP_CALIB_5_1:
  985. case RT5663_HP_CALIB_6:
  986. case RT5663_HP_CALIB_7:
  987. case RT5663_HP_CALIB_9:
  988. case RT5663_HP_CALIB_10:
  989. case RT5663_HP_CALIB_11:
  990. case RT5663_HP_CALIB_ST1:
  991. case RT5663_HP_CALIB_ST2:
  992. case RT5663_HP_CALIB_ST3:
  993. case RT5663_HP_CALIB_ST4:
  994. case RT5663_HP_CALIB_ST5:
  995. case RT5663_HP_CALIB_ST6:
  996. case RT5663_HP_CALIB_ST7:
  997. case RT5663_HP_CALIB_ST8:
  998. case RT5663_HP_CALIB_ST9:
  999. case RT5663_HP_AMP_DET:
  1000. case RT5663_DUMMY_REG_6:
  1001. case RT5663_HP_BIAS:
  1002. case RT5663_CBJ_1:
  1003. case RT5663_CBJ_2:
  1004. case RT5663_CBJ_3:
  1005. case RT5663_DUMMY_1:
  1006. case RT5663_DUMMY_2:
  1007. case RT5663_DUMMY_3:
  1008. case RT5663_ANA_JD:
  1009. case RT5663_ADC_LCH_LPF1_A1:
  1010. case RT5663_ADC_RCH_LPF1_A1:
  1011. case RT5663_ADC_LCH_LPF1_H0:
  1012. case RT5663_ADC_RCH_LPF1_H0:
  1013. case RT5663_ADC_LCH_BPF1_A1:
  1014. case RT5663_ADC_RCH_BPF1_A1:
  1015. case RT5663_ADC_LCH_BPF1_A2:
  1016. case RT5663_ADC_RCH_BPF1_A2:
  1017. case RT5663_ADC_LCH_BPF1_H0:
  1018. case RT5663_ADC_RCH_BPF1_H0:
  1019. case RT5663_ADC_LCH_BPF2_A1:
  1020. case RT5663_ADC_RCH_BPF2_A1:
  1021. case RT5663_ADC_LCH_BPF2_A2:
  1022. case RT5663_ADC_RCH_BPF2_A2:
  1023. case RT5663_ADC_LCH_BPF2_H0:
  1024. case RT5663_ADC_RCH_BPF2_H0:
  1025. case RT5663_ADC_LCH_BPF3_A1:
  1026. case RT5663_ADC_RCH_BPF3_A1:
  1027. case RT5663_ADC_LCH_BPF3_A2:
  1028. case RT5663_ADC_RCH_BPF3_A2:
  1029. case RT5663_ADC_LCH_BPF3_H0:
  1030. case RT5663_ADC_RCH_BPF3_H0:
  1031. case RT5663_ADC_LCH_BPF4_A1:
  1032. case RT5663_ADC_RCH_BPF4_A1:
  1033. case RT5663_ADC_LCH_BPF4_A2:
  1034. case RT5663_ADC_RCH_BPF4_A2:
  1035. case RT5663_ADC_LCH_BPF4_H0:
  1036. case RT5663_ADC_RCH_BPF4_H0:
  1037. case RT5663_ADC_LCH_HPF1_A1:
  1038. case RT5663_ADC_RCH_HPF1_A1:
  1039. case RT5663_ADC_LCH_HPF1_H0:
  1040. case RT5663_ADC_RCH_HPF1_H0:
  1041. case RT5663_ADC_EQ_PRE_VOL_L:
  1042. case RT5663_ADC_EQ_PRE_VOL_R:
  1043. case RT5663_ADC_EQ_POST_VOL_L:
  1044. case RT5663_ADC_EQ_POST_VOL_R:
  1045. return true;
  1046. default:
  1047. return false;
  1048. }
  1049. }
  1050. static bool rt5663_v2_volatile_register(struct device *dev, unsigned int reg)
  1051. {
  1052. switch (reg) {
  1053. case RT5663_RESET:
  1054. case RT5663_CBJ_TYPE_2:
  1055. case RT5663_PDM_OUT_CTL:
  1056. case RT5663_PDM_I2C_DATA_CTL1:
  1057. case RT5663_PDM_I2C_DATA_CTL4:
  1058. case RT5663_ALC_BK_GAIN:
  1059. case RT5663_PLL_2:
  1060. case RT5663_MICBIAS_1:
  1061. case RT5663_ADC_EQ_1:
  1062. case RT5663_INT_ST_1:
  1063. case RT5663_GPIO_STA2:
  1064. case RT5663_IL_CMD_1:
  1065. case RT5663_IL_CMD_5:
  1066. case RT5663_A_JD_CTRL:
  1067. case RT5663_JD_CTRL2:
  1068. case RT5663_VENDOR_ID:
  1069. case RT5663_VENDOR_ID_1:
  1070. case RT5663_VENDOR_ID_2:
  1071. case RT5663_STO_DRE_1:
  1072. case RT5663_STO_DRE_5:
  1073. case RT5663_STO_DRE_6:
  1074. case RT5663_STO_DRE_7:
  1075. case RT5663_MONO_DYNA_6:
  1076. case RT5663_STO1_SIL_DET:
  1077. case RT5663_MONOL_SIL_DET:
  1078. case RT5663_MONOR_SIL_DET:
  1079. case RT5663_STO2_DAC_SIL:
  1080. case RT5663_MONO_AMP_CAL_ST1:
  1081. case RT5663_MONO_AMP_CAL_ST2:
  1082. case RT5663_MONO_AMP_CAL_ST3:
  1083. case RT5663_MONO_AMP_CAL_ST4:
  1084. case RT5663_HP_IMP_SEN_2:
  1085. case RT5663_HP_IMP_SEN_3:
  1086. case RT5663_HP_IMP_SEN_4:
  1087. case RT5663_HP_IMP_SEN_10:
  1088. case RT5663_HP_CALIB_1:
  1089. case RT5663_HP_CALIB_10:
  1090. case RT5663_HP_CALIB_ST1:
  1091. case RT5663_HP_CALIB_ST4:
  1092. case RT5663_HP_CALIB_ST5:
  1093. case RT5663_HP_CALIB_ST6:
  1094. case RT5663_HP_CALIB_ST7:
  1095. case RT5663_HP_CALIB_ST8:
  1096. case RT5663_HP_CALIB_ST9:
  1097. case RT5663_HP_CALIB_ST10:
  1098. case RT5663_HP_CALIB_ST11:
  1099. return true;
  1100. default:
  1101. return false;
  1102. }
  1103. }
  1104. static bool rt5663_v2_readable_register(struct device *dev, unsigned int reg)
  1105. {
  1106. switch (reg) {
  1107. case RT5663_LOUT_CTRL:
  1108. case RT5663_HP_AMP_2:
  1109. case RT5663_MONO_OUT:
  1110. case RT5663_MONO_GAIN:
  1111. case RT5663_AEC_BST:
  1112. case RT5663_IN1_IN2:
  1113. case RT5663_IN3_IN4:
  1114. case RT5663_INL1_INR1:
  1115. case RT5663_CBJ_TYPE_2:
  1116. case RT5663_CBJ_TYPE_3:
  1117. case RT5663_CBJ_TYPE_4:
  1118. case RT5663_CBJ_TYPE_5:
  1119. case RT5663_CBJ_TYPE_8:
  1120. case RT5663_DAC3_DIG_VOL:
  1121. case RT5663_DAC3_CTRL:
  1122. case RT5663_MONO_ADC_DIG_VOL:
  1123. case RT5663_STO2_ADC_DIG_VOL:
  1124. case RT5663_MONO_ADC_BST_GAIN:
  1125. case RT5663_STO2_ADC_BST_GAIN:
  1126. case RT5663_SIDETONE_CTRL:
  1127. case RT5663_MONO1_ADC_MIXER:
  1128. case RT5663_STO2_ADC_MIXER:
  1129. case RT5663_MONO_DAC_MIXER:
  1130. case RT5663_DAC2_SRC_CTRL:
  1131. case RT5663_IF_3_4_DATA_CTL:
  1132. case RT5663_IF_5_DATA_CTL:
  1133. case RT5663_PDM_OUT_CTL:
  1134. case RT5663_PDM_I2C_DATA_CTL1:
  1135. case RT5663_PDM_I2C_DATA_CTL2:
  1136. case RT5663_PDM_I2C_DATA_CTL3:
  1137. case RT5663_PDM_I2C_DATA_CTL4:
  1138. case RT5663_RECMIX1_NEW:
  1139. case RT5663_RECMIX1L_0:
  1140. case RT5663_RECMIX1L:
  1141. case RT5663_RECMIX1R_0:
  1142. case RT5663_RECMIX1R:
  1143. case RT5663_RECMIX2_NEW:
  1144. case RT5663_RECMIX2_L_2:
  1145. case RT5663_RECMIX2_R:
  1146. case RT5663_RECMIX2_R_2:
  1147. case RT5663_CALIB_REC_LR:
  1148. case RT5663_ALC_BK_GAIN:
  1149. case RT5663_MONOMIX_GAIN:
  1150. case RT5663_MONOMIX_IN_GAIN:
  1151. case RT5663_OUT_MIXL_GAIN:
  1152. case RT5663_OUT_LMIX_IN_GAIN:
  1153. case RT5663_OUT_RMIX_IN_GAIN:
  1154. case RT5663_OUT_RMIX_IN_GAIN1:
  1155. case RT5663_LOUT_MIXER_CTRL:
  1156. case RT5663_PWR_VOL:
  1157. case RT5663_ADCDAC_RST:
  1158. case RT5663_I2S34_SDP:
  1159. case RT5663_I2S5_SDP:
  1160. case RT5663_TDM_6:
  1161. case RT5663_TDM_7:
  1162. case RT5663_TDM_8:
  1163. case RT5663_TDM_9:
  1164. case RT5663_ASRC_3:
  1165. case RT5663_ASRC_6:
  1166. case RT5663_ASRC_7:
  1167. case RT5663_PLL_TRK_13:
  1168. case RT5663_I2S_M_CLK_CTL:
  1169. case RT5663_FDIV_I2S34_M_CLK:
  1170. case RT5663_FDIV_I2S34_M_CLK2:
  1171. case RT5663_FDIV_I2S5_M_CLK:
  1172. case RT5663_FDIV_I2S5_M_CLK2:
  1173. case RT5663_V2_IRQ_4:
  1174. case RT5663_GPIO_3:
  1175. case RT5663_GPIO_4:
  1176. case RT5663_GPIO_STA2:
  1177. case RT5663_HP_AMP_DET1:
  1178. case RT5663_HP_AMP_DET2:
  1179. case RT5663_HP_AMP_DET3:
  1180. case RT5663_MID_BD_HP_AMP:
  1181. case RT5663_LOW_BD_HP_AMP:
  1182. case RT5663_SOF_VOL_ZC2:
  1183. case RT5663_ADC_STO2_ADJ1:
  1184. case RT5663_ADC_STO2_ADJ2:
  1185. case RT5663_A_JD_CTRL:
  1186. case RT5663_JD1_TRES_CTRL:
  1187. case RT5663_JD2_TRES_CTRL:
  1188. case RT5663_V2_JD_CTRL2:
  1189. case RT5663_DUM_REG_2:
  1190. case RT5663_DUM_REG_3:
  1191. case RT5663_VENDOR_ID:
  1192. case RT5663_VENDOR_ID_1:
  1193. case RT5663_VENDOR_ID_2:
  1194. case RT5663_DACADC_DIG_VOL2:
  1195. case RT5663_DIG_IN_PIN2:
  1196. case RT5663_PAD_DRV_CTL1:
  1197. case RT5663_SOF_RAM_DEPOP:
  1198. case RT5663_VOL_TEST:
  1199. case RT5663_TEST_MODE_4:
  1200. case RT5663_TEST_MODE_5:
  1201. case RT5663_STO_DRE_9:
  1202. case RT5663_MONO_DYNA_1:
  1203. case RT5663_MONO_DYNA_2:
  1204. case RT5663_MONO_DYNA_3:
  1205. case RT5663_MONO_DYNA_4:
  1206. case RT5663_MONO_DYNA_5:
  1207. case RT5663_MONO_DYNA_6:
  1208. case RT5663_STO1_SIL_DET:
  1209. case RT5663_MONOL_SIL_DET:
  1210. case RT5663_MONOR_SIL_DET:
  1211. case RT5663_STO2_DAC_SIL:
  1212. case RT5663_PWR_SAV_CTL1:
  1213. case RT5663_PWR_SAV_CTL2:
  1214. case RT5663_PWR_SAV_CTL3:
  1215. case RT5663_PWR_SAV_CTL4:
  1216. case RT5663_PWR_SAV_CTL5:
  1217. case RT5663_PWR_SAV_CTL6:
  1218. case RT5663_MONO_AMP_CAL1:
  1219. case RT5663_MONO_AMP_CAL2:
  1220. case RT5663_MONO_AMP_CAL3:
  1221. case RT5663_MONO_AMP_CAL4:
  1222. case RT5663_MONO_AMP_CAL5:
  1223. case RT5663_MONO_AMP_CAL6:
  1224. case RT5663_MONO_AMP_CAL7:
  1225. case RT5663_MONO_AMP_CAL_ST1:
  1226. case RT5663_MONO_AMP_CAL_ST2:
  1227. case RT5663_MONO_AMP_CAL_ST3:
  1228. case RT5663_MONO_AMP_CAL_ST4:
  1229. case RT5663_MONO_AMP_CAL_ST5:
  1230. case RT5663_V2_HP_IMP_SEN_13:
  1231. case RT5663_V2_HP_IMP_SEN_14:
  1232. case RT5663_V2_HP_IMP_SEN_6:
  1233. case RT5663_V2_HP_IMP_SEN_7:
  1234. case RT5663_V2_HP_IMP_SEN_8:
  1235. case RT5663_V2_HP_IMP_SEN_9:
  1236. case RT5663_V2_HP_IMP_SEN_10:
  1237. case RT5663_HP_LOGIC_3:
  1238. case RT5663_HP_CALIB_ST10:
  1239. case RT5663_HP_CALIB_ST11:
  1240. case RT5663_PRO_REG_TBL_4:
  1241. case RT5663_PRO_REG_TBL_5:
  1242. case RT5663_PRO_REG_TBL_6:
  1243. case RT5663_PRO_REG_TBL_7:
  1244. case RT5663_PRO_REG_TBL_8:
  1245. case RT5663_PRO_REG_TBL_9:
  1246. case RT5663_SAR_ADC_INL_1:
  1247. case RT5663_SAR_ADC_INL_2:
  1248. case RT5663_SAR_ADC_INL_3:
  1249. case RT5663_SAR_ADC_INL_4:
  1250. case RT5663_SAR_ADC_INL_5:
  1251. case RT5663_SAR_ADC_INL_6:
  1252. case RT5663_SAR_ADC_INL_7:
  1253. case RT5663_SAR_ADC_INL_8:
  1254. case RT5663_SAR_ADC_INL_9:
  1255. case RT5663_SAR_ADC_INL_10:
  1256. case RT5663_SAR_ADC_INL_11:
  1257. case RT5663_SAR_ADC_INL_12:
  1258. case RT5663_DRC_CTRL_1:
  1259. case RT5663_DRC1_CTRL_2:
  1260. case RT5663_DRC1_CTRL_3:
  1261. case RT5663_DRC1_CTRL_4:
  1262. case RT5663_DRC1_CTRL_5:
  1263. case RT5663_DRC1_CTRL_6:
  1264. case RT5663_DRC1_HD_CTRL_1:
  1265. case RT5663_DRC1_HD_CTRL_2:
  1266. case RT5663_DRC1_PRI_REG_1:
  1267. case RT5663_DRC1_PRI_REG_2:
  1268. case RT5663_DRC1_PRI_REG_3:
  1269. case RT5663_DRC1_PRI_REG_4:
  1270. case RT5663_DRC1_PRI_REG_5:
  1271. case RT5663_DRC1_PRI_REG_6:
  1272. case RT5663_DRC1_PRI_REG_7:
  1273. case RT5663_DRC1_PRI_REG_8:
  1274. case RT5663_ALC_PGA_CTL_1:
  1275. case RT5663_ALC_PGA_CTL_2:
  1276. case RT5663_ALC_PGA_CTL_3:
  1277. case RT5663_ALC_PGA_CTL_4:
  1278. case RT5663_ALC_PGA_CTL_5:
  1279. case RT5663_ALC_PGA_CTL_6:
  1280. case RT5663_ALC_PGA_CTL_7:
  1281. case RT5663_ALC_PGA_CTL_8:
  1282. case RT5663_ALC_PGA_REG_1:
  1283. case RT5663_ALC_PGA_REG_2:
  1284. case RT5663_ALC_PGA_REG_3:
  1285. case RT5663_ADC_EQ_RECOV_1:
  1286. case RT5663_ADC_EQ_RECOV_2:
  1287. case RT5663_ADC_EQ_RECOV_3:
  1288. case RT5663_ADC_EQ_RECOV_4:
  1289. case RT5663_ADC_EQ_RECOV_5:
  1290. case RT5663_ADC_EQ_RECOV_6:
  1291. case RT5663_ADC_EQ_RECOV_7:
  1292. case RT5663_ADC_EQ_RECOV_8:
  1293. case RT5663_ADC_EQ_RECOV_9:
  1294. case RT5663_ADC_EQ_RECOV_10:
  1295. case RT5663_ADC_EQ_RECOV_11:
  1296. case RT5663_ADC_EQ_RECOV_12:
  1297. case RT5663_ADC_EQ_RECOV_13:
  1298. case RT5663_VID_HIDDEN:
  1299. case RT5663_VID_CUSTOMER:
  1300. case RT5663_SCAN_MODE:
  1301. case RT5663_I2C_BYPA:
  1302. return true;
  1303. case RT5663_TDM_1:
  1304. case RT5663_DEPOP_3:
  1305. case RT5663_ASRC_11_2:
  1306. case RT5663_INT_ST_2:
  1307. case RT5663_GPIO_STA1:
  1308. case RT5663_SIN_GEN_1:
  1309. case RT5663_SIN_GEN_2:
  1310. case RT5663_SIN_GEN_3:
  1311. case RT5663_IL_CMD_PWRSAV1:
  1312. case RT5663_IL_CMD_PWRSAV2:
  1313. case RT5663_EM_JACK_TYPE_1:
  1314. case RT5663_EM_JACK_TYPE_2:
  1315. case RT5663_EM_JACK_TYPE_3:
  1316. case RT5663_EM_JACK_TYPE_4:
  1317. case RT5663_FAST_OFF_MICBIAS:
  1318. case RT5663_ANA_BIAS_CUR_1:
  1319. case RT5663_ANA_BIAS_CUR_2:
  1320. case RT5663_BIAS_CUR_9:
  1321. case RT5663_DUMMY_REG_4:
  1322. case RT5663_VREF_RECMIX:
  1323. case RT5663_CHARGE_PUMP_1_2:
  1324. case RT5663_CHARGE_PUMP_1_3:
  1325. case RT5663_CHARGE_PUMP_2:
  1326. case RT5663_CHOP_DAC_R:
  1327. case RT5663_DUMMY_CTL_DACLR:
  1328. case RT5663_DUMMY_REG_5:
  1329. case RT5663_SOFT_RAMP:
  1330. case RT5663_TEST_MODE_1:
  1331. case RT5663_STO_DRE_10:
  1332. case RT5663_MIC_DECRO_1:
  1333. case RT5663_MIC_DECRO_2:
  1334. case RT5663_MIC_DECRO_3:
  1335. case RT5663_MIC_DECRO_4:
  1336. case RT5663_MIC_DECRO_5:
  1337. case RT5663_MIC_DECRO_6:
  1338. case RT5663_HP_DECRO_1:
  1339. case RT5663_HP_DECRO_2:
  1340. case RT5663_HP_DECRO_3:
  1341. case RT5663_HP_DECRO_4:
  1342. case RT5663_HP_DECOUP:
  1343. case RT5663_HP_IMPSEN_MAP4:
  1344. case RT5663_HP_IMPSEN_MAP5:
  1345. case RT5663_HP_IMPSEN_MAP7:
  1346. case RT5663_HP_CALIB_1:
  1347. case RT5663_CBJ_1:
  1348. case RT5663_CBJ_2:
  1349. case RT5663_CBJ_3:
  1350. return false;
  1351. default:
  1352. return rt5663_readable_register(dev, reg);
  1353. }
  1354. }
  1355. static const DECLARE_TLV_DB_SCALE(rt5663_hp_vol_tlv, -2400, 150, 0);
  1356. static const DECLARE_TLV_DB_SCALE(rt5663_v2_hp_vol_tlv, -2250, 150, 0);
  1357. static const DECLARE_TLV_DB_SCALE(dac_vol_tlv, -6525, 75, 0);
  1358. static const DECLARE_TLV_DB_SCALE(adc_vol_tlv, -1725, 75, 0);
  1359. /* {0, +20, +24, +30, +35, +40, +44, +50, +52} dB */
  1360. static const DECLARE_TLV_DB_RANGE(in_bst_tlv,
  1361. 0, 0, TLV_DB_SCALE_ITEM(0, 0, 0),
  1362. 1, 1, TLV_DB_SCALE_ITEM(2000, 0, 0),
  1363. 2, 2, TLV_DB_SCALE_ITEM(2400, 0, 0),
  1364. 3, 5, TLV_DB_SCALE_ITEM(3000, 500, 0),
  1365. 6, 6, TLV_DB_SCALE_ITEM(4400, 0, 0),
  1366. 7, 7, TLV_DB_SCALE_ITEM(5000, 0, 0),
  1367. 8, 8, TLV_DB_SCALE_ITEM(5200, 0, 0)
  1368. );
  1369. /* Interface data select */
  1370. static const char * const rt5663_if1_adc_data_select[] = {
  1371. "L/R", "R/L", "L/L", "R/R"
  1372. };
  1373. static SOC_ENUM_SINGLE_DECL(rt5663_if1_adc_enum, RT5663_TDM_2,
  1374. RT5663_DATA_SWAP_ADCDAT1_SHIFT, rt5663_if1_adc_data_select);
  1375. static void rt5663_enable_push_button_irq(struct snd_soc_component *component,
  1376. bool enable)
  1377. {
  1378. struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component);
  1379. if (enable) {
  1380. snd_soc_component_update_bits(component, RT5663_IL_CMD_6,
  1381. RT5663_EN_4BTN_INL_MASK, RT5663_EN_4BTN_INL_EN);
  1382. /* reset in-line command */
  1383. snd_soc_component_update_bits(component, RT5663_IL_CMD_6,
  1384. RT5663_RESET_4BTN_INL_MASK,
  1385. RT5663_RESET_4BTN_INL_RESET);
  1386. snd_soc_component_update_bits(component, RT5663_IL_CMD_6,
  1387. RT5663_RESET_4BTN_INL_MASK,
  1388. RT5663_RESET_4BTN_INL_NOR);
  1389. switch (rt5663->codec_ver) {
  1390. case CODEC_VER_1:
  1391. snd_soc_component_update_bits(component, RT5663_IRQ_3,
  1392. RT5663_V2_EN_IRQ_INLINE_MASK,
  1393. RT5663_V2_EN_IRQ_INLINE_NOR);
  1394. break;
  1395. case CODEC_VER_0:
  1396. snd_soc_component_update_bits(component, RT5663_IRQ_2,
  1397. RT5663_EN_IRQ_INLINE_MASK,
  1398. RT5663_EN_IRQ_INLINE_NOR);
  1399. break;
  1400. default:
  1401. dev_err(component->dev, "Unknown CODEC Version\n");
  1402. }
  1403. } else {
  1404. switch (rt5663->codec_ver) {
  1405. case CODEC_VER_1:
  1406. snd_soc_component_update_bits(component, RT5663_IRQ_3,
  1407. RT5663_V2_EN_IRQ_INLINE_MASK,
  1408. RT5663_V2_EN_IRQ_INLINE_BYP);
  1409. break;
  1410. case CODEC_VER_0:
  1411. snd_soc_component_update_bits(component, RT5663_IRQ_2,
  1412. RT5663_EN_IRQ_INLINE_MASK,
  1413. RT5663_EN_IRQ_INLINE_BYP);
  1414. break;
  1415. default:
  1416. dev_err(component->dev, "Unknown CODEC Version\n");
  1417. }
  1418. snd_soc_component_update_bits(component, RT5663_IL_CMD_6,
  1419. RT5663_EN_4BTN_INL_MASK, RT5663_EN_4BTN_INL_DIS);
  1420. /* reset in-line command */
  1421. snd_soc_component_update_bits(component, RT5663_IL_CMD_6,
  1422. RT5663_RESET_4BTN_INL_MASK,
  1423. RT5663_RESET_4BTN_INL_RESET);
  1424. snd_soc_component_update_bits(component, RT5663_IL_CMD_6,
  1425. RT5663_RESET_4BTN_INL_MASK,
  1426. RT5663_RESET_4BTN_INL_NOR);
  1427. }
  1428. }
  1429. /**
  1430. * rt5663_v2_jack_detect - Detect headset.
  1431. * @component: SoC audio component device.
  1432. * @jack_insert: Jack insert or not.
  1433. *
  1434. * Detect whether is headset or not when jack inserted.
  1435. *
  1436. * Returns detect status.
  1437. */
  1438. static int rt5663_v2_jack_detect(struct snd_soc_component *component, int jack_insert)
  1439. {
  1440. struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
  1441. struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component);
  1442. int val, i = 0, sleep_time[5] = {300, 150, 100, 50, 30};
  1443. dev_dbg(component->dev, "%s jack_insert:%d\n", __func__, jack_insert);
  1444. if (jack_insert) {
  1445. snd_soc_component_write(component, RT5663_CBJ_TYPE_2, 0x8040);
  1446. snd_soc_component_write(component, RT5663_CBJ_TYPE_3, 0x1484);
  1447. snd_soc_dapm_force_enable_pin(dapm, "MICBIAS1");
  1448. snd_soc_dapm_force_enable_pin(dapm, "MICBIAS2");
  1449. snd_soc_dapm_force_enable_pin(dapm, "Mic Det Power");
  1450. snd_soc_dapm_force_enable_pin(dapm, "CBJ Power");
  1451. snd_soc_dapm_sync(dapm);
  1452. snd_soc_component_update_bits(component, RT5663_RC_CLK,
  1453. RT5663_DIG_1M_CLK_MASK, RT5663_DIG_1M_CLK_EN);
  1454. snd_soc_component_update_bits(component, RT5663_RECMIX, 0x8, 0x8);
  1455. while (i < 5) {
  1456. msleep(sleep_time[i]);
  1457. val = snd_soc_component_read(component, RT5663_CBJ_TYPE_2) & 0x0003;
  1458. if (val == 0x1 || val == 0x2 || val == 0x3)
  1459. break;
  1460. dev_dbg(component->dev, "%s: MX-0011 val=%x sleep %d\n",
  1461. __func__, val, sleep_time[i]);
  1462. i++;
  1463. }
  1464. dev_dbg(component->dev, "%s val = %d\n", __func__, val);
  1465. switch (val) {
  1466. case 1:
  1467. case 2:
  1468. rt5663->jack_type = SND_JACK_HEADSET;
  1469. rt5663_enable_push_button_irq(component, true);
  1470. break;
  1471. default:
  1472. snd_soc_dapm_disable_pin(dapm, "MICBIAS1");
  1473. snd_soc_dapm_disable_pin(dapm, "MICBIAS2");
  1474. snd_soc_dapm_disable_pin(dapm, "Mic Det Power");
  1475. snd_soc_dapm_disable_pin(dapm, "CBJ Power");
  1476. snd_soc_dapm_sync(dapm);
  1477. rt5663->jack_type = SND_JACK_HEADPHONE;
  1478. break;
  1479. }
  1480. } else {
  1481. snd_soc_component_update_bits(component, RT5663_RECMIX, 0x8, 0x0);
  1482. if (rt5663->jack_type == SND_JACK_HEADSET) {
  1483. rt5663_enable_push_button_irq(component, false);
  1484. snd_soc_dapm_disable_pin(dapm, "MICBIAS1");
  1485. snd_soc_dapm_disable_pin(dapm, "MICBIAS2");
  1486. snd_soc_dapm_disable_pin(dapm, "Mic Det Power");
  1487. snd_soc_dapm_disable_pin(dapm, "CBJ Power");
  1488. snd_soc_dapm_sync(dapm);
  1489. }
  1490. rt5663->jack_type = 0;
  1491. }
  1492. dev_dbg(component->dev, "jack_type = %d\n", rt5663->jack_type);
  1493. return rt5663->jack_type;
  1494. }
  1495. /**
  1496. * rt5663_jack_detect - Detect headset.
  1497. * @component: SoC audio component device.
  1498. * @jack_insert: Jack insert or not.
  1499. *
  1500. * Detect whether is headset or not when jack inserted.
  1501. *
  1502. * Returns detect status.
  1503. */
  1504. static int rt5663_jack_detect(struct snd_soc_component *component, int jack_insert)
  1505. {
  1506. struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component);
  1507. int val, i = 0;
  1508. dev_dbg(component->dev, "%s jack_insert:%d\n", __func__, jack_insert);
  1509. if (jack_insert) {
  1510. snd_soc_component_update_bits(component, RT5663_DIG_MISC,
  1511. RT5663_DIG_GATE_CTRL_MASK, RT5663_DIG_GATE_CTRL_EN);
  1512. snd_soc_component_update_bits(component, RT5663_HP_CHARGE_PUMP_1,
  1513. RT5663_SI_HP_MASK | RT5663_OSW_HP_L_MASK |
  1514. RT5663_OSW_HP_R_MASK, RT5663_SI_HP_EN |
  1515. RT5663_OSW_HP_L_DIS | RT5663_OSW_HP_R_DIS);
  1516. snd_soc_component_update_bits(component, RT5663_DUMMY_1,
  1517. RT5663_EMB_CLK_MASK | RT5663_HPA_CPL_BIAS_MASK |
  1518. RT5663_HPA_CPR_BIAS_MASK, RT5663_EMB_CLK_EN |
  1519. RT5663_HPA_CPL_BIAS_1 | RT5663_HPA_CPR_BIAS_1);
  1520. snd_soc_component_update_bits(component, RT5663_CBJ_1,
  1521. RT5663_INBUF_CBJ_BST1_MASK | RT5663_CBJ_SENSE_BST1_MASK,
  1522. RT5663_INBUF_CBJ_BST1_ON | RT5663_CBJ_SENSE_BST1_L);
  1523. snd_soc_component_update_bits(component, RT5663_IL_CMD_2,
  1524. RT5663_PWR_MIC_DET_MASK, RT5663_PWR_MIC_DET_ON);
  1525. /* BST1 power on for JD */
  1526. snd_soc_component_update_bits(component, RT5663_PWR_ANLG_2,
  1527. RT5663_PWR_BST1_MASK, RT5663_PWR_BST1_ON);
  1528. snd_soc_component_update_bits(component, RT5663_EM_JACK_TYPE_1,
  1529. RT5663_CBJ_DET_MASK | RT5663_EXT_JD_MASK |
  1530. RT5663_POL_EXT_JD_MASK, RT5663_CBJ_DET_EN |
  1531. RT5663_EXT_JD_EN | RT5663_POL_EXT_JD_EN);
  1532. snd_soc_component_update_bits(component, RT5663_PWR_ANLG_1,
  1533. RT5663_PWR_MB_MASK | RT5663_LDO1_DVO_MASK |
  1534. RT5663_AMP_HP_MASK, RT5663_PWR_MB |
  1535. RT5663_LDO1_DVO_0_9V | RT5663_AMP_HP_3X);
  1536. snd_soc_component_update_bits(component, RT5663_PWR_ANLG_1,
  1537. RT5663_PWR_VREF1_MASK | RT5663_PWR_VREF2_MASK |
  1538. RT5663_PWR_FV1_MASK | RT5663_PWR_FV2_MASK,
  1539. RT5663_PWR_VREF1 | RT5663_PWR_VREF2);
  1540. msleep(20);
  1541. snd_soc_component_update_bits(component, RT5663_PWR_ANLG_1,
  1542. RT5663_PWR_FV1_MASK | RT5663_PWR_FV2_MASK,
  1543. RT5663_PWR_FV1 | RT5663_PWR_FV2);
  1544. snd_soc_component_update_bits(component, RT5663_AUTO_1MRC_CLK,
  1545. RT5663_IRQ_POW_SAV_MASK, RT5663_IRQ_POW_SAV_EN);
  1546. snd_soc_component_update_bits(component, RT5663_IRQ_1,
  1547. RT5663_EN_IRQ_JD1_MASK, RT5663_EN_IRQ_JD1_EN);
  1548. snd_soc_component_update_bits(component, RT5663_EM_JACK_TYPE_1,
  1549. RT5663_EM_JD_MASK, RT5663_EM_JD_RST);
  1550. snd_soc_component_update_bits(component, RT5663_EM_JACK_TYPE_1,
  1551. RT5663_EM_JD_MASK, RT5663_EM_JD_NOR);
  1552. while (true) {
  1553. regmap_read(rt5663->regmap, RT5663_INT_ST_2, &val);
  1554. if (!(val & 0x80))
  1555. usleep_range(10000, 10005);
  1556. else
  1557. break;
  1558. if (i > 200)
  1559. break;
  1560. i++;
  1561. }
  1562. val = snd_soc_component_read(component, RT5663_EM_JACK_TYPE_2) & 0x0003;
  1563. dev_dbg(component->dev, "%s val = %d\n", __func__, val);
  1564. snd_soc_component_update_bits(component, RT5663_HP_CHARGE_PUMP_1,
  1565. RT5663_OSW_HP_L_MASK | RT5663_OSW_HP_R_MASK,
  1566. RT5663_OSW_HP_L_EN | RT5663_OSW_HP_R_EN);
  1567. switch (val) {
  1568. case 1:
  1569. case 2:
  1570. rt5663->jack_type = SND_JACK_HEADSET;
  1571. rt5663_enable_push_button_irq(component, true);
  1572. if (rt5663->pdata.impedance_sensing_num)
  1573. break;
  1574. if (rt5663->pdata.dc_offset_l_manual_mic) {
  1575. regmap_write(rt5663->regmap, RT5663_MIC_DECRO_2,
  1576. rt5663->pdata.dc_offset_l_manual_mic >>
  1577. 16);
  1578. regmap_write(rt5663->regmap, RT5663_MIC_DECRO_3,
  1579. rt5663->pdata.dc_offset_l_manual_mic &
  1580. 0xffff);
  1581. }
  1582. if (rt5663->pdata.dc_offset_r_manual_mic) {
  1583. regmap_write(rt5663->regmap, RT5663_MIC_DECRO_5,
  1584. rt5663->pdata.dc_offset_r_manual_mic >>
  1585. 16);
  1586. regmap_write(rt5663->regmap, RT5663_MIC_DECRO_6,
  1587. rt5663->pdata.dc_offset_r_manual_mic &
  1588. 0xffff);
  1589. }
  1590. break;
  1591. default:
  1592. rt5663->jack_type = SND_JACK_HEADPHONE;
  1593. snd_soc_component_update_bits(component,
  1594. RT5663_PWR_ANLG_1,
  1595. RT5663_PWR_MB_MASK | RT5663_PWR_VREF1_MASK |
  1596. RT5663_PWR_VREF2_MASK, 0);
  1597. if (rt5663->pdata.impedance_sensing_num)
  1598. break;
  1599. if (rt5663->pdata.dc_offset_l_manual) {
  1600. regmap_write(rt5663->regmap, RT5663_MIC_DECRO_2,
  1601. rt5663->pdata.dc_offset_l_manual >> 16);
  1602. regmap_write(rt5663->regmap, RT5663_MIC_DECRO_3,
  1603. rt5663->pdata.dc_offset_l_manual &
  1604. 0xffff);
  1605. }
  1606. if (rt5663->pdata.dc_offset_r_manual) {
  1607. regmap_write(rt5663->regmap, RT5663_MIC_DECRO_5,
  1608. rt5663->pdata.dc_offset_r_manual >> 16);
  1609. regmap_write(rt5663->regmap, RT5663_MIC_DECRO_6,
  1610. rt5663->pdata.dc_offset_r_manual &
  1611. 0xffff);
  1612. }
  1613. break;
  1614. }
  1615. } else {
  1616. if (rt5663->jack_type == SND_JACK_HEADSET)
  1617. rt5663_enable_push_button_irq(component, false);
  1618. rt5663->jack_type = 0;
  1619. snd_soc_component_update_bits(component, RT5663_PWR_ANLG_1,
  1620. RT5663_PWR_MB_MASK | RT5663_PWR_VREF1_MASK |
  1621. RT5663_PWR_VREF2_MASK, 0);
  1622. }
  1623. dev_dbg(component->dev, "jack_type = %d\n", rt5663->jack_type);
  1624. return rt5663->jack_type;
  1625. }
  1626. static int rt5663_impedance_sensing(struct snd_soc_component *component)
  1627. {
  1628. struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component);
  1629. unsigned int value, i, reg84, reg26, reg2fa, reg91, reg10, reg80;
  1630. for (i = 0; i < rt5663->pdata.impedance_sensing_num; i++) {
  1631. if (rt5663->imp_table[i].vol == 7)
  1632. break;
  1633. }
  1634. if (rt5663->jack_type == SND_JACK_HEADSET) {
  1635. snd_soc_component_write(component, RT5663_MIC_DECRO_2,
  1636. rt5663->imp_table[i].dc_offset_l_manual_mic >> 16);
  1637. snd_soc_component_write(component, RT5663_MIC_DECRO_3,
  1638. rt5663->imp_table[i].dc_offset_l_manual_mic & 0xffff);
  1639. snd_soc_component_write(component, RT5663_MIC_DECRO_5,
  1640. rt5663->imp_table[i].dc_offset_r_manual_mic >> 16);
  1641. snd_soc_component_write(component, RT5663_MIC_DECRO_6,
  1642. rt5663->imp_table[i].dc_offset_r_manual_mic & 0xffff);
  1643. } else {
  1644. snd_soc_component_write(component, RT5663_MIC_DECRO_2,
  1645. rt5663->imp_table[i].dc_offset_l_manual >> 16);
  1646. snd_soc_component_write(component, RT5663_MIC_DECRO_3,
  1647. rt5663->imp_table[i].dc_offset_l_manual & 0xffff);
  1648. snd_soc_component_write(component, RT5663_MIC_DECRO_5,
  1649. rt5663->imp_table[i].dc_offset_r_manual >> 16);
  1650. snd_soc_component_write(component, RT5663_MIC_DECRO_6,
  1651. rt5663->imp_table[i].dc_offset_r_manual & 0xffff);
  1652. }
  1653. reg84 = snd_soc_component_read(component, RT5663_ASRC_2);
  1654. reg26 = snd_soc_component_read(component, RT5663_STO1_ADC_MIXER);
  1655. reg2fa = snd_soc_component_read(component, RT5663_DUMMY_1);
  1656. reg91 = snd_soc_component_read(component, RT5663_HP_CHARGE_PUMP_1);
  1657. reg10 = snd_soc_component_read(component, RT5663_RECMIX);
  1658. reg80 = snd_soc_component_read(component, RT5663_GLB_CLK);
  1659. snd_soc_component_update_bits(component, RT5663_STO_DRE_1, 0x8000, 0);
  1660. snd_soc_component_write(component, RT5663_ASRC_2, 0);
  1661. snd_soc_component_write(component, RT5663_STO1_ADC_MIXER, 0x4040);
  1662. snd_soc_component_update_bits(component, RT5663_PWR_ANLG_1,
  1663. RT5663_PWR_VREF1_MASK | RT5663_PWR_VREF2_MASK |
  1664. RT5663_PWR_FV1_MASK | RT5663_PWR_FV2_MASK,
  1665. RT5663_PWR_VREF1 | RT5663_PWR_VREF2);
  1666. usleep_range(10000, 10005);
  1667. snd_soc_component_update_bits(component, RT5663_PWR_ANLG_1,
  1668. RT5663_PWR_FV1_MASK | RT5663_PWR_FV2_MASK,
  1669. RT5663_PWR_FV1 | RT5663_PWR_FV2);
  1670. snd_soc_component_update_bits(component, RT5663_GLB_CLK, RT5663_SCLK_SRC_MASK,
  1671. RT5663_SCLK_SRC_RCCLK);
  1672. snd_soc_component_update_bits(component, RT5663_RC_CLK, RT5663_DIG_25M_CLK_MASK,
  1673. RT5663_DIG_25M_CLK_EN);
  1674. snd_soc_component_update_bits(component, RT5663_ADDA_CLK_1, RT5663_I2S_PD1_MASK, 0);
  1675. snd_soc_component_write(component, RT5663_PRE_DIV_GATING_1, 0xff00);
  1676. snd_soc_component_write(component, RT5663_PRE_DIV_GATING_2, 0xfffc);
  1677. snd_soc_component_write(component, RT5663_HP_CHARGE_PUMP_1, 0x1232);
  1678. snd_soc_component_write(component, RT5663_HP_LOGIC_2, 0x0005);
  1679. snd_soc_component_write(component, RT5663_DEPOP_2, 0x3003);
  1680. snd_soc_component_update_bits(component, RT5663_DEPOP_1, 0x0030, 0x0030);
  1681. snd_soc_component_update_bits(component, RT5663_DEPOP_1, 0x0003, 0x0003);
  1682. snd_soc_component_update_bits(component, RT5663_PWR_DIG_2,
  1683. RT5663_PWR_ADC_S1F | RT5663_PWR_DAC_S1F,
  1684. RT5663_PWR_ADC_S1F | RT5663_PWR_DAC_S1F);
  1685. snd_soc_component_update_bits(component, RT5663_PWR_DIG_1,
  1686. RT5663_PWR_DAC_L1 | RT5663_PWR_DAC_R1 |
  1687. RT5663_PWR_LDO_DACREF_MASK | RT5663_PWR_ADC_L1 |
  1688. RT5663_PWR_ADC_R1,
  1689. RT5663_PWR_DAC_L1 | RT5663_PWR_DAC_R1 |
  1690. RT5663_PWR_LDO_DACREF_ON | RT5663_PWR_ADC_L1 |
  1691. RT5663_PWR_ADC_R1);
  1692. msleep(40);
  1693. snd_soc_component_update_bits(component, RT5663_PWR_ANLG_2,
  1694. RT5663_PWR_RECMIX1 | RT5663_PWR_RECMIX2,
  1695. RT5663_PWR_RECMIX1 | RT5663_PWR_RECMIX2);
  1696. msleep(30);
  1697. snd_soc_component_write(component, RT5663_HP_CHARGE_PUMP_2, 0x1371);
  1698. snd_soc_component_write(component, RT5663_STO_DAC_MIXER, 0);
  1699. snd_soc_component_write(component, RT5663_BYPASS_STO_DAC, 0x000c);
  1700. snd_soc_component_write(component, RT5663_HP_BIAS, 0xafaa);
  1701. snd_soc_component_write(component, RT5663_CHARGE_PUMP_1, 0x2224);
  1702. snd_soc_component_write(component, RT5663_HP_OUT_EN, 0x8088);
  1703. snd_soc_component_write(component, RT5663_CHOP_ADC, 0x3000);
  1704. snd_soc_component_write(component, RT5663_ADDA_RST, 0xc000);
  1705. snd_soc_component_write(component, RT5663_STO1_HPF_ADJ1, 0x3320);
  1706. snd_soc_component_write(component, RT5663_HP_CALIB_2, 0x00c9);
  1707. snd_soc_component_write(component, RT5663_DUMMY_1, 0x004c);
  1708. snd_soc_component_write(component, RT5663_ANA_BIAS_CUR_1, 0x7733);
  1709. snd_soc_component_write(component, RT5663_CHARGE_PUMP_2, 0x7777);
  1710. snd_soc_component_write(component, RT5663_STO_DRE_9, 0x0007);
  1711. snd_soc_component_write(component, RT5663_STO_DRE_10, 0x0007);
  1712. snd_soc_component_write(component, RT5663_DUMMY_2, 0x02a4);
  1713. snd_soc_component_write(component, RT5663_RECMIX, 0x0005);
  1714. snd_soc_component_write(component, RT5663_HP_IMP_SEN_1, 0x4334);
  1715. snd_soc_component_update_bits(component, RT5663_IRQ_3, 0x0004, 0x0004);
  1716. snd_soc_component_write(component, RT5663_HP_LOGIC_1, 0x2200);
  1717. snd_soc_component_update_bits(component, RT5663_DEPOP_1, 0x3000, 0x3000);
  1718. snd_soc_component_write(component, RT5663_HP_LOGIC_1, 0x6200);
  1719. for (i = 0; i < 100; i++) {
  1720. msleep(20);
  1721. if (snd_soc_component_read(component, RT5663_INT_ST_1) & 0x2)
  1722. break;
  1723. }
  1724. value = snd_soc_component_read(component, RT5663_HP_IMP_SEN_4);
  1725. snd_soc_component_update_bits(component, RT5663_DEPOP_1, 0x3000, 0);
  1726. snd_soc_component_write(component, RT5663_INT_ST_1, 0);
  1727. snd_soc_component_write(component, RT5663_HP_LOGIC_1, 0);
  1728. snd_soc_component_update_bits(component, RT5663_RC_CLK, RT5663_DIG_25M_CLK_MASK,
  1729. RT5663_DIG_25M_CLK_DIS);
  1730. snd_soc_component_write(component, RT5663_GLB_CLK, reg80);
  1731. snd_soc_component_write(component, RT5663_RECMIX, reg10);
  1732. snd_soc_component_write(component, RT5663_DUMMY_2, 0x00a4);
  1733. snd_soc_component_write(component, RT5663_DUMMY_1, reg2fa);
  1734. snd_soc_component_write(component, RT5663_HP_CALIB_2, 0x00c8);
  1735. snd_soc_component_write(component, RT5663_STO1_HPF_ADJ1, 0xb320);
  1736. snd_soc_component_write(component, RT5663_ADDA_RST, 0xe400);
  1737. snd_soc_component_write(component, RT5663_CHOP_ADC, 0x2000);
  1738. snd_soc_component_write(component, RT5663_HP_OUT_EN, 0x0008);
  1739. snd_soc_component_update_bits(component, RT5663_PWR_ANLG_2,
  1740. RT5663_PWR_RECMIX1 | RT5663_PWR_RECMIX2, 0);
  1741. snd_soc_component_update_bits(component, RT5663_PWR_DIG_1,
  1742. RT5663_PWR_DAC_L1 | RT5663_PWR_DAC_R1 |
  1743. RT5663_PWR_LDO_DACREF_MASK | RT5663_PWR_ADC_L1 |
  1744. RT5663_PWR_ADC_R1, 0);
  1745. snd_soc_component_update_bits(component, RT5663_PWR_DIG_2,
  1746. RT5663_PWR_ADC_S1F | RT5663_PWR_DAC_S1F, 0);
  1747. snd_soc_component_update_bits(component, RT5663_DEPOP_1, 0x0003, 0);
  1748. snd_soc_component_update_bits(component, RT5663_DEPOP_1, 0x0030, 0);
  1749. snd_soc_component_write(component, RT5663_HP_LOGIC_2, 0);
  1750. snd_soc_component_write(component, RT5663_HP_CHARGE_PUMP_1, reg91);
  1751. snd_soc_component_update_bits(component, RT5663_PWR_ANLG_1,
  1752. RT5663_PWR_VREF1_MASK | RT5663_PWR_VREF2_MASK, 0);
  1753. snd_soc_component_write(component, RT5663_STO1_ADC_MIXER, reg26);
  1754. snd_soc_component_write(component, RT5663_ASRC_2, reg84);
  1755. for (i = 0; i < rt5663->pdata.impedance_sensing_num; i++) {
  1756. if (value >= rt5663->imp_table[i].imp_min &&
  1757. value <= rt5663->imp_table[i].imp_max)
  1758. break;
  1759. }
  1760. snd_soc_component_update_bits(component, RT5663_STO_DRE_9, RT5663_DRE_GAIN_HP_MASK,
  1761. rt5663->imp_table[i].vol);
  1762. snd_soc_component_update_bits(component, RT5663_STO_DRE_10, RT5663_DRE_GAIN_HP_MASK,
  1763. rt5663->imp_table[i].vol);
  1764. if (rt5663->jack_type == SND_JACK_HEADSET) {
  1765. snd_soc_component_write(component, RT5663_MIC_DECRO_2,
  1766. rt5663->imp_table[i].dc_offset_l_manual_mic >> 16);
  1767. snd_soc_component_write(component, RT5663_MIC_DECRO_3,
  1768. rt5663->imp_table[i].dc_offset_l_manual_mic & 0xffff);
  1769. snd_soc_component_write(component, RT5663_MIC_DECRO_5,
  1770. rt5663->imp_table[i].dc_offset_r_manual_mic >> 16);
  1771. snd_soc_component_write(component, RT5663_MIC_DECRO_6,
  1772. rt5663->imp_table[i].dc_offset_r_manual_mic & 0xffff);
  1773. } else {
  1774. snd_soc_component_write(component, RT5663_MIC_DECRO_2,
  1775. rt5663->imp_table[i].dc_offset_l_manual >> 16);
  1776. snd_soc_component_write(component, RT5663_MIC_DECRO_3,
  1777. rt5663->imp_table[i].dc_offset_l_manual & 0xffff);
  1778. snd_soc_component_write(component, RT5663_MIC_DECRO_5,
  1779. rt5663->imp_table[i].dc_offset_r_manual >> 16);
  1780. snd_soc_component_write(component, RT5663_MIC_DECRO_6,
  1781. rt5663->imp_table[i].dc_offset_r_manual & 0xffff);
  1782. }
  1783. return 0;
  1784. }
  1785. static int rt5663_button_detect(struct snd_soc_component *component)
  1786. {
  1787. int btn_type, val;
  1788. val = snd_soc_component_read(component, RT5663_IL_CMD_5);
  1789. dev_dbg(component->dev, "%s: val=0x%x\n", __func__, val);
  1790. btn_type = val & 0xfff0;
  1791. snd_soc_component_write(component, RT5663_IL_CMD_5, val);
  1792. return btn_type;
  1793. }
  1794. static irqreturn_t rt5663_irq(int irq, void *data)
  1795. {
  1796. struct rt5663_priv *rt5663 = data;
  1797. dev_dbg(regmap_get_device(rt5663->regmap), "%s IRQ queue work\n",
  1798. __func__);
  1799. queue_delayed_work(system_wq, &rt5663->jack_detect_work,
  1800. msecs_to_jiffies(250));
  1801. return IRQ_HANDLED;
  1802. }
  1803. static int rt5663_set_jack_detect(struct snd_soc_component *component,
  1804. struct snd_soc_jack *hs_jack, void *data)
  1805. {
  1806. struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component);
  1807. rt5663->hs_jack = hs_jack;
  1808. rt5663_irq(0, rt5663);
  1809. return 0;
  1810. }
  1811. static bool rt5663_check_jd_status(struct snd_soc_component *component)
  1812. {
  1813. struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component);
  1814. int val = snd_soc_component_read(component, RT5663_INT_ST_1);
  1815. dev_dbg(component->dev, "%s val=%x\n", __func__, val);
  1816. /* JD1 */
  1817. switch (rt5663->codec_ver) {
  1818. case CODEC_VER_1:
  1819. return !(val & 0x2000);
  1820. case CODEC_VER_0:
  1821. return !(val & 0x1000);
  1822. default:
  1823. dev_err(component->dev, "Unknown CODEC Version\n");
  1824. }
  1825. return false;
  1826. }
  1827. static void rt5663_jack_detect_work(struct work_struct *work)
  1828. {
  1829. struct rt5663_priv *rt5663 =
  1830. container_of(work, struct rt5663_priv, jack_detect_work.work);
  1831. struct snd_soc_component *component = rt5663->component;
  1832. int btn_type, report = 0;
  1833. if (!component)
  1834. return;
  1835. if (rt5663_check_jd_status(component)) {
  1836. /* jack in */
  1837. if (rt5663->jack_type == 0) {
  1838. /* jack was out, report jack type */
  1839. switch (rt5663->codec_ver) {
  1840. case CODEC_VER_1:
  1841. report = rt5663_v2_jack_detect(
  1842. rt5663->component, 1);
  1843. break;
  1844. case CODEC_VER_0:
  1845. report = rt5663_jack_detect(rt5663->component, 1);
  1846. if (rt5663->pdata.impedance_sensing_num)
  1847. rt5663_impedance_sensing(rt5663->component);
  1848. break;
  1849. default:
  1850. dev_err(component->dev, "Unknown CODEC Version\n");
  1851. }
  1852. /* Delay the jack insert report to avoid pop noise */
  1853. msleep(30);
  1854. } else {
  1855. /* jack is already in, report button event */
  1856. report = SND_JACK_HEADSET;
  1857. btn_type = rt5663_button_detect(rt5663->component);
  1858. /**
  1859. * rt5663 can report three kinds of button behavior,
  1860. * one click, double click and hold. However,
  1861. * currently we will report button pressed/released
  1862. * event. So all the three button behaviors are
  1863. * treated as button pressed.
  1864. */
  1865. switch (btn_type) {
  1866. case 0x8000:
  1867. case 0x4000:
  1868. case 0x2000:
  1869. report |= SND_JACK_BTN_0;
  1870. break;
  1871. case 0x1000:
  1872. case 0x0800:
  1873. case 0x0400:
  1874. report |= SND_JACK_BTN_1;
  1875. break;
  1876. case 0x0200:
  1877. case 0x0100:
  1878. case 0x0080:
  1879. report |= SND_JACK_BTN_2;
  1880. break;
  1881. case 0x0040:
  1882. case 0x0020:
  1883. case 0x0010:
  1884. report |= SND_JACK_BTN_3;
  1885. break;
  1886. case 0x0000: /* unpressed */
  1887. break;
  1888. default:
  1889. btn_type = 0;
  1890. dev_err(rt5663->component->dev,
  1891. "Unexpected button code 0x%04x\n",
  1892. btn_type);
  1893. break;
  1894. }
  1895. /* button release or spurious interrput*/
  1896. if (btn_type == 0) {
  1897. report = rt5663->jack_type;
  1898. cancel_delayed_work_sync(
  1899. &rt5663->jd_unplug_work);
  1900. } else {
  1901. queue_delayed_work(system_wq,
  1902. &rt5663->jd_unplug_work,
  1903. msecs_to_jiffies(500));
  1904. }
  1905. }
  1906. } else {
  1907. /* jack out */
  1908. switch (rt5663->codec_ver) {
  1909. case CODEC_VER_1:
  1910. report = rt5663_v2_jack_detect(rt5663->component, 0);
  1911. break;
  1912. case CODEC_VER_0:
  1913. report = rt5663_jack_detect(rt5663->component, 0);
  1914. break;
  1915. default:
  1916. dev_err(component->dev, "Unknown CODEC Version\n");
  1917. }
  1918. }
  1919. dev_dbg(component->dev, "%s jack report: 0x%04x\n", __func__, report);
  1920. snd_soc_jack_report(rt5663->hs_jack, report, SND_JACK_HEADSET |
  1921. SND_JACK_BTN_0 | SND_JACK_BTN_1 |
  1922. SND_JACK_BTN_2 | SND_JACK_BTN_3);
  1923. }
  1924. static void rt5663_jd_unplug_work(struct work_struct *work)
  1925. {
  1926. struct rt5663_priv *rt5663 =
  1927. container_of(work, struct rt5663_priv, jd_unplug_work.work);
  1928. struct snd_soc_component *component = rt5663->component;
  1929. if (!component)
  1930. return;
  1931. if (!rt5663_check_jd_status(component)) {
  1932. /* jack out */
  1933. switch (rt5663->codec_ver) {
  1934. case CODEC_VER_1:
  1935. rt5663_v2_jack_detect(rt5663->component, 0);
  1936. break;
  1937. case CODEC_VER_0:
  1938. rt5663_jack_detect(rt5663->component, 0);
  1939. break;
  1940. default:
  1941. dev_err(component->dev, "Unknown CODEC Version\n");
  1942. }
  1943. snd_soc_jack_report(rt5663->hs_jack, 0, SND_JACK_HEADSET |
  1944. SND_JACK_BTN_0 | SND_JACK_BTN_1 |
  1945. SND_JACK_BTN_2 | SND_JACK_BTN_3);
  1946. } else {
  1947. queue_delayed_work(system_wq, &rt5663->jd_unplug_work,
  1948. msecs_to_jiffies(500));
  1949. }
  1950. }
  1951. static const struct snd_kcontrol_new rt5663_snd_controls[] = {
  1952. /* DAC Digital Volume */
  1953. SOC_DOUBLE_TLV("DAC Playback Volume", RT5663_STO1_DAC_DIG_VOL,
  1954. RT5663_DAC_L1_VOL_SHIFT + 1, RT5663_DAC_R1_VOL_SHIFT + 1,
  1955. 87, 0, dac_vol_tlv),
  1956. /* ADC Digital Volume Control */
  1957. SOC_DOUBLE("ADC Capture Switch", RT5663_STO1_ADC_DIG_VOL,
  1958. RT5663_ADC_L_MUTE_SHIFT, RT5663_ADC_R_MUTE_SHIFT, 1, 1),
  1959. SOC_DOUBLE_TLV("ADC Capture Volume", RT5663_STO1_ADC_DIG_VOL,
  1960. RT5663_ADC_L_VOL_SHIFT + 1, RT5663_ADC_R_VOL_SHIFT + 1,
  1961. 63, 0, adc_vol_tlv),
  1962. };
  1963. static const struct snd_kcontrol_new rt5663_v2_specific_controls[] = {
  1964. /* Headphone Output Volume */
  1965. SOC_DOUBLE_R_TLV("Headphone Playback Volume", RT5663_HP_LCH_DRE,
  1966. RT5663_HP_RCH_DRE, RT5663_GAIN_HP_SHIFT, 15, 1,
  1967. rt5663_v2_hp_vol_tlv),
  1968. /* Mic Boost Volume */
  1969. SOC_SINGLE_TLV("IN1 Capture Volume", RT5663_AEC_BST,
  1970. RT5663_GAIN_CBJ_SHIFT, 8, 0, in_bst_tlv),
  1971. };
  1972. static const struct snd_kcontrol_new rt5663_specific_controls[] = {
  1973. /* Mic Boost Volume*/
  1974. SOC_SINGLE_TLV("IN1 Capture Volume", RT5663_CBJ_2,
  1975. RT5663_GAIN_BST1_SHIFT, 8, 0, in_bst_tlv),
  1976. /* Data Swap for Slot0/1 in ADCDAT1 */
  1977. SOC_ENUM("IF1 ADC Data Swap", rt5663_if1_adc_enum),
  1978. };
  1979. static const struct snd_kcontrol_new rt5663_hpvol_controls[] = {
  1980. /* Headphone Output Volume */
  1981. SOC_DOUBLE_R_TLV("Headphone Playback Volume", RT5663_STO_DRE_9,
  1982. RT5663_STO_DRE_10, RT5663_DRE_GAIN_HP_SHIFT, 23, 1,
  1983. rt5663_hp_vol_tlv),
  1984. };
  1985. static int rt5663_is_sys_clk_from_pll(struct snd_soc_dapm_widget *w,
  1986. struct snd_soc_dapm_widget *sink)
  1987. {
  1988. unsigned int val;
  1989. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  1990. val = snd_soc_component_read(component, RT5663_GLB_CLK);
  1991. val &= RT5663_SCLK_SRC_MASK;
  1992. if (val == RT5663_SCLK_SRC_PLL1)
  1993. return 1;
  1994. else
  1995. return 0;
  1996. }
  1997. static int rt5663_is_using_asrc(struct snd_soc_dapm_widget *w,
  1998. struct snd_soc_dapm_widget *sink)
  1999. {
  2000. unsigned int reg, shift, val;
  2001. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  2002. struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component);
  2003. if (rt5663->codec_ver == CODEC_VER_1) {
  2004. switch (w->shift) {
  2005. case RT5663_ADC_STO1_ASRC_SHIFT:
  2006. reg = RT5663_ASRC_3;
  2007. shift = RT5663_V2_AD_STO1_TRACK_SHIFT;
  2008. break;
  2009. case RT5663_DAC_STO1_ASRC_SHIFT:
  2010. reg = RT5663_ASRC_2;
  2011. shift = RT5663_DA_STO1_TRACK_SHIFT;
  2012. break;
  2013. default:
  2014. return 0;
  2015. }
  2016. } else {
  2017. switch (w->shift) {
  2018. case RT5663_ADC_STO1_ASRC_SHIFT:
  2019. reg = RT5663_ASRC_2;
  2020. shift = RT5663_AD_STO1_TRACK_SHIFT;
  2021. break;
  2022. case RT5663_DAC_STO1_ASRC_SHIFT:
  2023. reg = RT5663_ASRC_2;
  2024. shift = RT5663_DA_STO1_TRACK_SHIFT;
  2025. break;
  2026. default:
  2027. return 0;
  2028. }
  2029. }
  2030. val = (snd_soc_component_read(component, reg) >> shift) & 0x7;
  2031. if (val)
  2032. return 1;
  2033. return 0;
  2034. }
  2035. static int rt5663_i2s_use_asrc(struct snd_soc_dapm_widget *source,
  2036. struct snd_soc_dapm_widget *sink)
  2037. {
  2038. struct snd_soc_component *component = snd_soc_dapm_to_component(source->dapm);
  2039. struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component);
  2040. int da_asrc_en, ad_asrc_en;
  2041. da_asrc_en = (snd_soc_component_read(component, RT5663_ASRC_2) &
  2042. RT5663_DA_STO1_TRACK_MASK) ? 1 : 0;
  2043. switch (rt5663->codec_ver) {
  2044. case CODEC_VER_1:
  2045. ad_asrc_en = (snd_soc_component_read(component, RT5663_ASRC_3) &
  2046. RT5663_V2_AD_STO1_TRACK_MASK) ? 1 : 0;
  2047. break;
  2048. case CODEC_VER_0:
  2049. ad_asrc_en = (snd_soc_component_read(component, RT5663_ASRC_2) &
  2050. RT5663_AD_STO1_TRACK_MASK) ? 1 : 0;
  2051. break;
  2052. default:
  2053. dev_err(component->dev, "Unknown CODEC Version\n");
  2054. return 1;
  2055. }
  2056. if (da_asrc_en || ad_asrc_en)
  2057. if (rt5663->sysclk > rt5663->lrck * 384)
  2058. return 1;
  2059. dev_err(component->dev, "sysclk < 384 x fs, disable i2s asrc\n");
  2060. return 0;
  2061. }
  2062. /**
  2063. * rt5663_sel_asrc_clk_src - select ASRC clock source for a set of filters
  2064. * @component: SoC audio component device.
  2065. * @filter_mask: mask of filters.
  2066. * @clk_src: clock source
  2067. *
  2068. * The ASRC function is for asynchronous MCLK and LRCK. Also, since RT5663 can
  2069. * only support standard 32fs or 64fs i2s format, ASRC should be enabled to
  2070. * support special i2s clock format such as Intel's 100fs(100 * sampling rate).
  2071. * ASRC function will track i2s clock and generate a corresponding system clock
  2072. * for codec. This function provides an API to select the clock source for a
  2073. * set of filters specified by the mask. And the codec driver will turn on ASRC
  2074. * for these filters if ASRC is selected as their clock source.
  2075. */
  2076. int rt5663_sel_asrc_clk_src(struct snd_soc_component *component,
  2077. unsigned int filter_mask, unsigned int clk_src)
  2078. {
  2079. struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component);
  2080. unsigned int asrc2_mask = 0;
  2081. unsigned int asrc2_value = 0;
  2082. unsigned int asrc3_mask = 0;
  2083. unsigned int asrc3_value = 0;
  2084. switch (clk_src) {
  2085. case RT5663_CLK_SEL_SYS:
  2086. case RT5663_CLK_SEL_I2S1_ASRC:
  2087. break;
  2088. default:
  2089. return -EINVAL;
  2090. }
  2091. if (filter_mask & RT5663_DA_STEREO_FILTER) {
  2092. asrc2_mask |= RT5663_DA_STO1_TRACK_MASK;
  2093. asrc2_value |= clk_src << RT5663_DA_STO1_TRACK_SHIFT;
  2094. }
  2095. if (filter_mask & RT5663_AD_STEREO_FILTER) {
  2096. switch (rt5663->codec_ver) {
  2097. case CODEC_VER_1:
  2098. asrc3_mask |= RT5663_V2_AD_STO1_TRACK_MASK;
  2099. asrc3_value |= clk_src << RT5663_V2_AD_STO1_TRACK_SHIFT;
  2100. break;
  2101. case CODEC_VER_0:
  2102. asrc2_mask |= RT5663_AD_STO1_TRACK_MASK;
  2103. asrc2_value |= clk_src << RT5663_AD_STO1_TRACK_SHIFT;
  2104. break;
  2105. default:
  2106. dev_err(component->dev, "Unknown CODEC Version\n");
  2107. }
  2108. }
  2109. if (asrc2_mask)
  2110. snd_soc_component_update_bits(component, RT5663_ASRC_2, asrc2_mask,
  2111. asrc2_value);
  2112. if (asrc3_mask)
  2113. snd_soc_component_update_bits(component, RT5663_ASRC_3, asrc3_mask,
  2114. asrc3_value);
  2115. return 0;
  2116. }
  2117. EXPORT_SYMBOL_GPL(rt5663_sel_asrc_clk_src);
  2118. /* Analog Mixer */
  2119. static const struct snd_kcontrol_new rt5663_recmix1l[] = {
  2120. SOC_DAPM_SINGLE("BST2 Switch", RT5663_RECMIX1L,
  2121. RT5663_RECMIX1L_BST2_SHIFT, 1, 1),
  2122. SOC_DAPM_SINGLE("BST1 CBJ Switch", RT5663_RECMIX1L,
  2123. RT5663_RECMIX1L_BST1_CBJ_SHIFT, 1, 1),
  2124. };
  2125. static const struct snd_kcontrol_new rt5663_recmix1r[] = {
  2126. SOC_DAPM_SINGLE("BST2 Switch", RT5663_RECMIX1R,
  2127. RT5663_RECMIX1R_BST2_SHIFT, 1, 1),
  2128. };
  2129. /* Digital Mixer */
  2130. static const struct snd_kcontrol_new rt5663_sto1_adc_l_mix[] = {
  2131. SOC_DAPM_SINGLE("ADC1 Switch", RT5663_STO1_ADC_MIXER,
  2132. RT5663_M_STO1_ADC_L1_SHIFT, 1, 1),
  2133. SOC_DAPM_SINGLE("ADC2 Switch", RT5663_STO1_ADC_MIXER,
  2134. RT5663_M_STO1_ADC_L2_SHIFT, 1, 1),
  2135. };
  2136. static const struct snd_kcontrol_new rt5663_sto1_adc_r_mix[] = {
  2137. SOC_DAPM_SINGLE("ADC1 Switch", RT5663_STO1_ADC_MIXER,
  2138. RT5663_M_STO1_ADC_R1_SHIFT, 1, 1),
  2139. SOC_DAPM_SINGLE("ADC2 Switch", RT5663_STO1_ADC_MIXER,
  2140. RT5663_M_STO1_ADC_R2_SHIFT, 1, 1),
  2141. };
  2142. static const struct snd_kcontrol_new rt5663_adda_l_mix[] = {
  2143. SOC_DAPM_SINGLE("ADC L Switch", RT5663_AD_DA_MIXER,
  2144. RT5663_M_ADCMIX_L_SHIFT, 1, 1),
  2145. SOC_DAPM_SINGLE("DAC L Switch", RT5663_AD_DA_MIXER,
  2146. RT5663_M_DAC1_L_SHIFT, 1, 1),
  2147. };
  2148. static const struct snd_kcontrol_new rt5663_adda_r_mix[] = {
  2149. SOC_DAPM_SINGLE("ADC R Switch", RT5663_AD_DA_MIXER,
  2150. RT5663_M_ADCMIX_R_SHIFT, 1, 1),
  2151. SOC_DAPM_SINGLE("DAC R Switch", RT5663_AD_DA_MIXER,
  2152. RT5663_M_DAC1_R_SHIFT, 1, 1),
  2153. };
  2154. static const struct snd_kcontrol_new rt5663_sto1_dac_l_mix[] = {
  2155. SOC_DAPM_SINGLE("DAC L Switch", RT5663_STO_DAC_MIXER,
  2156. RT5663_M_DAC_L1_STO_L_SHIFT, 1, 1),
  2157. };
  2158. static const struct snd_kcontrol_new rt5663_sto1_dac_r_mix[] = {
  2159. SOC_DAPM_SINGLE("DAC R Switch", RT5663_STO_DAC_MIXER,
  2160. RT5663_M_DAC_R1_STO_R_SHIFT, 1, 1),
  2161. };
  2162. /* Out Switch */
  2163. static const struct snd_kcontrol_new rt5663_hpo_switch =
  2164. SOC_DAPM_SINGLE_AUTODISABLE("Switch", RT5663_HP_AMP_2,
  2165. RT5663_EN_DAC_HPO_SHIFT, 1, 0);
  2166. /* Stereo ADC source */
  2167. static const char * const rt5663_sto1_adc_src[] = {
  2168. "ADC L", "ADC R"
  2169. };
  2170. static SOC_ENUM_SINGLE_DECL(rt5663_sto1_adcl_enum, RT5663_STO1_ADC_MIXER,
  2171. RT5663_STO1_ADC_L_SRC_SHIFT, rt5663_sto1_adc_src);
  2172. static const struct snd_kcontrol_new rt5663_sto1_adcl_mux =
  2173. SOC_DAPM_ENUM("STO1 ADC L Mux", rt5663_sto1_adcl_enum);
  2174. static SOC_ENUM_SINGLE_DECL(rt5663_sto1_adcr_enum, RT5663_STO1_ADC_MIXER,
  2175. RT5663_STO1_ADC_R_SRC_SHIFT, rt5663_sto1_adc_src);
  2176. static const struct snd_kcontrol_new rt5663_sto1_adcr_mux =
  2177. SOC_DAPM_ENUM("STO1 ADC R Mux", rt5663_sto1_adcr_enum);
  2178. /* RT5663: Analog DACL1 input source */
  2179. static const char * const rt5663_alg_dacl_src[] = {
  2180. "DAC L", "STO DAC MIXL"
  2181. };
  2182. static SOC_ENUM_SINGLE_DECL(rt5663_alg_dacl_enum, RT5663_BYPASS_STO_DAC,
  2183. RT5663_DACL1_SRC_SHIFT, rt5663_alg_dacl_src);
  2184. static const struct snd_kcontrol_new rt5663_alg_dacl_mux =
  2185. SOC_DAPM_ENUM("DAC L Mux", rt5663_alg_dacl_enum);
  2186. /* RT5663: Analog DACR1 input source */
  2187. static const char * const rt5663_alg_dacr_src[] = {
  2188. "DAC R", "STO DAC MIXR"
  2189. };
  2190. static SOC_ENUM_SINGLE_DECL(rt5663_alg_dacr_enum, RT5663_BYPASS_STO_DAC,
  2191. RT5663_DACR1_SRC_SHIFT, rt5663_alg_dacr_src);
  2192. static const struct snd_kcontrol_new rt5663_alg_dacr_mux =
  2193. SOC_DAPM_ENUM("DAC R Mux", rt5663_alg_dacr_enum);
  2194. static int rt5663_hp_event(struct snd_soc_dapm_widget *w,
  2195. struct snd_kcontrol *kcontrol, int event)
  2196. {
  2197. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  2198. struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component);
  2199. switch (event) {
  2200. case SND_SOC_DAPM_POST_PMU:
  2201. if (rt5663->codec_ver == CODEC_VER_1) {
  2202. snd_soc_component_update_bits(component, RT5663_HP_CHARGE_PUMP_1,
  2203. RT5663_SEL_PM_HP_SHIFT, RT5663_SEL_PM_HP_HIGH);
  2204. snd_soc_component_update_bits(component, RT5663_HP_LOGIC_2,
  2205. RT5663_HP_SIG_SRC1_MASK,
  2206. RT5663_HP_SIG_SRC1_SILENCE);
  2207. } else {
  2208. snd_soc_component_update_bits(component,
  2209. RT5663_DACREF_LDO, 0x3e0e, 0x3a0a);
  2210. snd_soc_component_write(component, RT5663_DEPOP_2, 0x3003);
  2211. snd_soc_component_update_bits(component, RT5663_HP_CHARGE_PUMP_1,
  2212. RT5663_OVCD_HP_MASK, RT5663_OVCD_HP_DIS);
  2213. snd_soc_component_write(component, RT5663_HP_CHARGE_PUMP_2, 0x1371);
  2214. snd_soc_component_write(component, RT5663_HP_BIAS, 0xabba);
  2215. snd_soc_component_write(component, RT5663_CHARGE_PUMP_1, 0x2224);
  2216. snd_soc_component_write(component, RT5663_ANA_BIAS_CUR_1, 0x7766);
  2217. snd_soc_component_write(component, RT5663_HP_BIAS, 0xafaa);
  2218. snd_soc_component_write(component, RT5663_CHARGE_PUMP_2, 0x7777);
  2219. snd_soc_component_update_bits(component, RT5663_STO_DRE_1, 0x8000,
  2220. 0x8000);
  2221. snd_soc_component_update_bits(component, RT5663_DEPOP_1, 0x3000,
  2222. 0x3000);
  2223. snd_soc_component_update_bits(component,
  2224. RT5663_DIG_VOL_ZCD, 0x00c0, 0x0080);
  2225. }
  2226. break;
  2227. case SND_SOC_DAPM_PRE_PMD:
  2228. if (rt5663->codec_ver == CODEC_VER_1) {
  2229. snd_soc_component_update_bits(component, RT5663_HP_LOGIC_2,
  2230. RT5663_HP_SIG_SRC1_MASK,
  2231. RT5663_HP_SIG_SRC1_REG);
  2232. } else {
  2233. snd_soc_component_update_bits(component, RT5663_DEPOP_1, 0x3000, 0x0);
  2234. snd_soc_component_update_bits(component, RT5663_HP_CHARGE_PUMP_1,
  2235. RT5663_OVCD_HP_MASK, RT5663_OVCD_HP_EN);
  2236. snd_soc_component_update_bits(component,
  2237. RT5663_DACREF_LDO, 0x3e0e, 0);
  2238. snd_soc_component_update_bits(component,
  2239. RT5663_DIG_VOL_ZCD, 0x00c0, 0);
  2240. }
  2241. break;
  2242. default:
  2243. return 0;
  2244. }
  2245. return 0;
  2246. }
  2247. static int rt5663_charge_pump_event(struct snd_soc_dapm_widget *w,
  2248. struct snd_kcontrol *kcontrol, int event)
  2249. {
  2250. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  2251. struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component);
  2252. switch (event) {
  2253. case SND_SOC_DAPM_PRE_PMU:
  2254. if (rt5663->codec_ver == CODEC_VER_0) {
  2255. snd_soc_component_update_bits(component, RT5663_DEPOP_1, 0x0030,
  2256. 0x0030);
  2257. snd_soc_component_update_bits(component, RT5663_DEPOP_1, 0x0003,
  2258. 0x0003);
  2259. }
  2260. break;
  2261. case SND_SOC_DAPM_POST_PMD:
  2262. if (rt5663->codec_ver == CODEC_VER_0) {
  2263. snd_soc_component_update_bits(component, RT5663_DEPOP_1, 0x0003, 0);
  2264. snd_soc_component_update_bits(component, RT5663_DEPOP_1, 0x0030, 0);
  2265. }
  2266. break;
  2267. default:
  2268. return 0;
  2269. }
  2270. return 0;
  2271. }
  2272. static int rt5663_bst2_power(struct snd_soc_dapm_widget *w,
  2273. struct snd_kcontrol *kcontrol, int event)
  2274. {
  2275. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  2276. switch (event) {
  2277. case SND_SOC_DAPM_POST_PMU:
  2278. snd_soc_component_update_bits(component, RT5663_PWR_ANLG_2,
  2279. RT5663_PWR_BST2_MASK | RT5663_PWR_BST2_OP_MASK,
  2280. RT5663_PWR_BST2 | RT5663_PWR_BST2_OP);
  2281. break;
  2282. case SND_SOC_DAPM_PRE_PMD:
  2283. snd_soc_component_update_bits(component, RT5663_PWR_ANLG_2,
  2284. RT5663_PWR_BST2_MASK | RT5663_PWR_BST2_OP_MASK, 0);
  2285. break;
  2286. default:
  2287. return 0;
  2288. }
  2289. return 0;
  2290. }
  2291. static int rt5663_pre_div_power(struct snd_soc_dapm_widget *w,
  2292. struct snd_kcontrol *kcontrol, int event)
  2293. {
  2294. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  2295. switch (event) {
  2296. case SND_SOC_DAPM_POST_PMU:
  2297. snd_soc_component_write(component, RT5663_PRE_DIV_GATING_1, 0xff00);
  2298. snd_soc_component_write(component, RT5663_PRE_DIV_GATING_2, 0xfffc);
  2299. break;
  2300. case SND_SOC_DAPM_PRE_PMD:
  2301. snd_soc_component_write(component, RT5663_PRE_DIV_GATING_1, 0x0000);
  2302. snd_soc_component_write(component, RT5663_PRE_DIV_GATING_2, 0x0000);
  2303. break;
  2304. default:
  2305. return 0;
  2306. }
  2307. return 0;
  2308. }
  2309. static const struct snd_soc_dapm_widget rt5663_dapm_widgets[] = {
  2310. SND_SOC_DAPM_SUPPLY("PLL", RT5663_PWR_ANLG_3, RT5663_PWR_PLL_SHIFT, 0,
  2311. NULL, 0),
  2312. /* micbias */
  2313. SND_SOC_DAPM_MICBIAS("MICBIAS1", RT5663_PWR_ANLG_2,
  2314. RT5663_PWR_MB1_SHIFT, 0),
  2315. SND_SOC_DAPM_MICBIAS("MICBIAS2", RT5663_PWR_ANLG_2,
  2316. RT5663_PWR_MB2_SHIFT, 0),
  2317. /* Input Lines */
  2318. SND_SOC_DAPM_INPUT("IN1P"),
  2319. SND_SOC_DAPM_INPUT("IN1N"),
  2320. /* REC Mixer Power */
  2321. SND_SOC_DAPM_SUPPLY("RECMIX1L Power", RT5663_PWR_ANLG_2,
  2322. RT5663_PWR_RECMIX1_SHIFT, 0, NULL, 0),
  2323. /* ADCs */
  2324. SND_SOC_DAPM_ADC("ADC L", NULL, SND_SOC_NOPM, 0, 0),
  2325. SND_SOC_DAPM_SUPPLY("ADC L Power", RT5663_PWR_DIG_1,
  2326. RT5663_PWR_ADC_L1_SHIFT, 0, NULL, 0),
  2327. SND_SOC_DAPM_SUPPLY("ADC Clock", RT5663_CHOP_ADC,
  2328. RT5663_CKGEN_ADCC_SHIFT, 0, NULL, 0),
  2329. /* ADC Mixer */
  2330. SND_SOC_DAPM_MIXER("STO1 ADC MIXL", SND_SOC_NOPM,
  2331. 0, 0, rt5663_sto1_adc_l_mix,
  2332. ARRAY_SIZE(rt5663_sto1_adc_l_mix)),
  2333. /* ADC Filter Power */
  2334. SND_SOC_DAPM_SUPPLY("STO1 ADC Filter", RT5663_PWR_DIG_2,
  2335. RT5663_PWR_ADC_S1F_SHIFT, 0, NULL, 0),
  2336. /* Digital Interface */
  2337. SND_SOC_DAPM_SUPPLY("I2S", RT5663_PWR_DIG_1, RT5663_PWR_I2S1_SHIFT, 0,
  2338. NULL, 0),
  2339. SND_SOC_DAPM_PGA("IF DAC", SND_SOC_NOPM, 0, 0, NULL, 0),
  2340. SND_SOC_DAPM_PGA("IF1 DAC1 L", SND_SOC_NOPM, 0, 0, NULL, 0),
  2341. SND_SOC_DAPM_PGA("IF1 DAC1 R", SND_SOC_NOPM, 0, 0, NULL, 0),
  2342. SND_SOC_DAPM_PGA("IF1 ADC1", SND_SOC_NOPM, 0, 0, NULL, 0),
  2343. SND_SOC_DAPM_PGA("IF ADC", SND_SOC_NOPM, 0, 0, NULL, 0),
  2344. /* Audio Interface */
  2345. SND_SOC_DAPM_AIF_IN("AIFRX", "AIF Playback", 0, SND_SOC_NOPM, 0, 0),
  2346. SND_SOC_DAPM_AIF_OUT("AIFTX", "AIF Capture", 0, SND_SOC_NOPM, 0, 0),
  2347. /* DAC mixer before sound effect */
  2348. SND_SOC_DAPM_MIXER("ADDA MIXL", SND_SOC_NOPM, 0, 0, rt5663_adda_l_mix,
  2349. ARRAY_SIZE(rt5663_adda_l_mix)),
  2350. SND_SOC_DAPM_MIXER("ADDA MIXR", SND_SOC_NOPM, 0, 0, rt5663_adda_r_mix,
  2351. ARRAY_SIZE(rt5663_adda_r_mix)),
  2352. SND_SOC_DAPM_PGA("DAC L1", SND_SOC_NOPM, 0, 0, NULL, 0),
  2353. SND_SOC_DAPM_PGA("DAC R1", SND_SOC_NOPM, 0, 0, NULL, 0),
  2354. /* DAC Mixer */
  2355. SND_SOC_DAPM_SUPPLY("STO1 DAC Filter", RT5663_PWR_DIG_2,
  2356. RT5663_PWR_DAC_S1F_SHIFT, 0, NULL, 0),
  2357. SND_SOC_DAPM_MIXER("STO1 DAC MIXL", SND_SOC_NOPM, 0, 0,
  2358. rt5663_sto1_dac_l_mix, ARRAY_SIZE(rt5663_sto1_dac_l_mix)),
  2359. SND_SOC_DAPM_MIXER("STO1 DAC MIXR", SND_SOC_NOPM, 0, 0,
  2360. rt5663_sto1_dac_r_mix, ARRAY_SIZE(rt5663_sto1_dac_r_mix)),
  2361. /* DACs */
  2362. SND_SOC_DAPM_SUPPLY("STO1 DAC L Power", RT5663_PWR_DIG_1,
  2363. RT5663_PWR_DAC_L1_SHIFT, 0, NULL, 0),
  2364. SND_SOC_DAPM_SUPPLY("STO1 DAC R Power", RT5663_PWR_DIG_1,
  2365. RT5663_PWR_DAC_R1_SHIFT, 0, NULL, 0),
  2366. SND_SOC_DAPM_DAC("DAC L", NULL, SND_SOC_NOPM, 0, 0),
  2367. SND_SOC_DAPM_DAC("DAC R", NULL, SND_SOC_NOPM, 0, 0),
  2368. /* Headphone*/
  2369. SND_SOC_DAPM_SUPPLY("HP Charge Pump", SND_SOC_NOPM, 0, 0,
  2370. rt5663_charge_pump_event, SND_SOC_DAPM_PRE_PMU |
  2371. SND_SOC_DAPM_POST_PMD),
  2372. SND_SOC_DAPM_PGA_S("HP Amp", 1, SND_SOC_NOPM, 0, 0, rt5663_hp_event,
  2373. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU),
  2374. /* Output Lines */
  2375. SND_SOC_DAPM_OUTPUT("HPOL"),
  2376. SND_SOC_DAPM_OUTPUT("HPOR"),
  2377. };
  2378. static const struct snd_soc_dapm_widget rt5663_v2_specific_dapm_widgets[] = {
  2379. SND_SOC_DAPM_SUPPLY("LDO2", RT5663_PWR_ANLG_3,
  2380. RT5663_PWR_LDO2_SHIFT, 0, NULL, 0),
  2381. SND_SOC_DAPM_SUPPLY("Mic Det Power", RT5663_PWR_VOL,
  2382. RT5663_V2_PWR_MIC_DET_SHIFT, 0, NULL, 0),
  2383. SND_SOC_DAPM_SUPPLY("LDO DAC", RT5663_PWR_DIG_1,
  2384. RT5663_PWR_LDO_DACREF_SHIFT, 0, NULL, 0),
  2385. /* ASRC */
  2386. SND_SOC_DAPM_SUPPLY("I2S ASRC", RT5663_ASRC_1,
  2387. RT5663_I2S1_ASRC_SHIFT, 0, NULL, 0),
  2388. SND_SOC_DAPM_SUPPLY("DAC ASRC", RT5663_ASRC_1,
  2389. RT5663_DAC_STO1_ASRC_SHIFT, 0, NULL, 0),
  2390. SND_SOC_DAPM_SUPPLY("ADC ASRC", RT5663_ASRC_1,
  2391. RT5663_ADC_STO1_ASRC_SHIFT, 0, NULL, 0),
  2392. /* Input Lines */
  2393. SND_SOC_DAPM_INPUT("IN2P"),
  2394. SND_SOC_DAPM_INPUT("IN2N"),
  2395. /* Boost */
  2396. SND_SOC_DAPM_PGA("BST1 CBJ", SND_SOC_NOPM, 0, 0, NULL, 0),
  2397. SND_SOC_DAPM_SUPPLY("CBJ Power", RT5663_PWR_ANLG_3,
  2398. RT5663_PWR_CBJ_SHIFT, 0, NULL, 0),
  2399. SND_SOC_DAPM_PGA("BST2", SND_SOC_NOPM, 0, 0, NULL, 0),
  2400. SND_SOC_DAPM_SUPPLY("BST2 Power", SND_SOC_NOPM, 0, 0,
  2401. rt5663_bst2_power, SND_SOC_DAPM_PRE_PMD |
  2402. SND_SOC_DAPM_POST_PMU),
  2403. /* REC Mixer */
  2404. SND_SOC_DAPM_MIXER("RECMIX1L", SND_SOC_NOPM, 0, 0, rt5663_recmix1l,
  2405. ARRAY_SIZE(rt5663_recmix1l)),
  2406. SND_SOC_DAPM_MIXER("RECMIX1R", SND_SOC_NOPM, 0, 0, rt5663_recmix1r,
  2407. ARRAY_SIZE(rt5663_recmix1r)),
  2408. SND_SOC_DAPM_SUPPLY("RECMIX1R Power", RT5663_PWR_ANLG_2,
  2409. RT5663_PWR_RECMIX2_SHIFT, 0, NULL, 0),
  2410. /* ADC */
  2411. SND_SOC_DAPM_ADC("ADC R", NULL, SND_SOC_NOPM, 0, 0),
  2412. SND_SOC_DAPM_SUPPLY("ADC R Power", RT5663_PWR_DIG_1,
  2413. RT5663_PWR_ADC_R1_SHIFT, 0, NULL, 0),
  2414. /* ADC Mux */
  2415. SND_SOC_DAPM_PGA("STO1 ADC L1", RT5663_STO1_ADC_MIXER,
  2416. RT5663_STO1_ADC_L1_SRC_SHIFT, 0, NULL, 0),
  2417. SND_SOC_DAPM_PGA("STO1 ADC R1", RT5663_STO1_ADC_MIXER,
  2418. RT5663_STO1_ADC_R1_SRC_SHIFT, 0, NULL, 0),
  2419. SND_SOC_DAPM_PGA("STO1 ADC L2", RT5663_STO1_ADC_MIXER,
  2420. RT5663_STO1_ADC_L2_SRC_SHIFT, 1, NULL, 0),
  2421. SND_SOC_DAPM_PGA("STO1 ADC R2", RT5663_STO1_ADC_MIXER,
  2422. RT5663_STO1_ADC_R2_SRC_SHIFT, 1, NULL, 0),
  2423. SND_SOC_DAPM_MUX("STO1 ADC L Mux", SND_SOC_NOPM, 0, 0,
  2424. &rt5663_sto1_adcl_mux),
  2425. SND_SOC_DAPM_MUX("STO1 ADC R Mux", SND_SOC_NOPM, 0, 0,
  2426. &rt5663_sto1_adcr_mux),
  2427. /* ADC Mix */
  2428. SND_SOC_DAPM_MIXER("STO1 ADC MIXR", SND_SOC_NOPM, 0, 0,
  2429. rt5663_sto1_adc_r_mix, ARRAY_SIZE(rt5663_sto1_adc_r_mix)),
  2430. /* Analog DAC Clock */
  2431. SND_SOC_DAPM_SUPPLY("DAC Clock", RT5663_CHOP_DAC_L,
  2432. RT5663_CKGEN_DAC1_SHIFT, 0, NULL, 0),
  2433. /* Headphone out */
  2434. SND_SOC_DAPM_SWITCH("HPO Playback", SND_SOC_NOPM, 0, 0,
  2435. &rt5663_hpo_switch),
  2436. };
  2437. static const struct snd_soc_dapm_widget rt5663_specific_dapm_widgets[] = {
  2438. /* System Clock Pre Divider Gating */
  2439. SND_SOC_DAPM_SUPPLY("Pre Div Power", SND_SOC_NOPM, 0, 0,
  2440. rt5663_pre_div_power, SND_SOC_DAPM_POST_PMU |
  2441. SND_SOC_DAPM_PRE_PMD),
  2442. /* LDO */
  2443. SND_SOC_DAPM_SUPPLY("LDO ADC", RT5663_PWR_DIG_1,
  2444. RT5663_PWR_LDO_DACREF_SHIFT, 0, NULL, 0),
  2445. /* ASRC */
  2446. SND_SOC_DAPM_SUPPLY("I2S ASRC", RT5663_ASRC_1,
  2447. RT5663_I2S1_ASRC_SHIFT, 0, NULL, 0),
  2448. SND_SOC_DAPM_SUPPLY("DAC ASRC", RT5663_ASRC_1,
  2449. RT5663_DAC_STO1_ASRC_SHIFT, 0, NULL, 0),
  2450. SND_SOC_DAPM_SUPPLY("ADC ASRC", RT5663_ASRC_1,
  2451. RT5663_ADC_STO1_ASRC_SHIFT, 0, NULL, 0),
  2452. /* Boost */
  2453. SND_SOC_DAPM_PGA("BST1", SND_SOC_NOPM, 0, 0, NULL, 0),
  2454. /* STO ADC */
  2455. SND_SOC_DAPM_PGA("STO1 ADC L1", SND_SOC_NOPM, 0, 0, NULL, 0),
  2456. SND_SOC_DAPM_PGA("STO1 ADC L2", SND_SOC_NOPM, 0, 0, NULL, 0),
  2457. /* Analog DAC source */
  2458. SND_SOC_DAPM_MUX("DAC L Mux", SND_SOC_NOPM, 0, 0, &rt5663_alg_dacl_mux),
  2459. SND_SOC_DAPM_MUX("DAC R Mux", SND_SOC_NOPM, 0, 0, &rt5663_alg_dacr_mux),
  2460. };
  2461. static const struct snd_soc_dapm_route rt5663_dapm_routes[] = {
  2462. /* PLL */
  2463. { "I2S", NULL, "PLL", rt5663_is_sys_clk_from_pll },
  2464. /* ASRC */
  2465. { "STO1 ADC Filter", NULL, "ADC ASRC", rt5663_is_using_asrc },
  2466. { "STO1 DAC Filter", NULL, "DAC ASRC", rt5663_is_using_asrc },
  2467. { "I2S", NULL, "I2S ASRC", rt5663_i2s_use_asrc },
  2468. { "ADC L", NULL, "ADC L Power" },
  2469. { "ADC L", NULL, "ADC Clock" },
  2470. { "STO1 ADC L2", NULL, "STO1 DAC MIXL" },
  2471. { "STO1 ADC MIXL", "ADC1 Switch", "STO1 ADC L1" },
  2472. { "STO1 ADC MIXL", "ADC2 Switch", "STO1 ADC L2" },
  2473. { "STO1 ADC MIXL", NULL, "STO1 ADC Filter" },
  2474. { "IF1 ADC1", NULL, "STO1 ADC MIXL" },
  2475. { "IF ADC", NULL, "IF1 ADC1" },
  2476. { "AIFTX", NULL, "IF ADC" },
  2477. { "AIFTX", NULL, "I2S" },
  2478. { "AIFRX", NULL, "I2S" },
  2479. { "IF DAC", NULL, "AIFRX" },
  2480. { "IF1 DAC1 L", NULL, "IF DAC" },
  2481. { "IF1 DAC1 R", NULL, "IF DAC" },
  2482. { "ADDA MIXL", "ADC L Switch", "STO1 ADC MIXL" },
  2483. { "ADDA MIXL", "DAC L Switch", "IF1 DAC1 L" },
  2484. { "ADDA MIXL", NULL, "STO1 DAC Filter" },
  2485. { "ADDA MIXL", NULL, "STO1 DAC L Power" },
  2486. { "ADDA MIXR", "DAC R Switch", "IF1 DAC1 R" },
  2487. { "ADDA MIXR", NULL, "STO1 DAC Filter" },
  2488. { "ADDA MIXR", NULL, "STO1 DAC R Power" },
  2489. { "DAC L1", NULL, "ADDA MIXL" },
  2490. { "DAC R1", NULL, "ADDA MIXR" },
  2491. { "STO1 DAC MIXL", "DAC L Switch", "DAC L1" },
  2492. { "STO1 DAC MIXL", NULL, "STO1 DAC L Power" },
  2493. { "STO1 DAC MIXL", NULL, "STO1 DAC Filter" },
  2494. { "STO1 DAC MIXR", "DAC R Switch", "DAC R1" },
  2495. { "STO1 DAC MIXR", NULL, "STO1 DAC R Power" },
  2496. { "STO1 DAC MIXR", NULL, "STO1 DAC Filter" },
  2497. { "HP Amp", NULL, "HP Charge Pump" },
  2498. { "HP Amp", NULL, "DAC L" },
  2499. { "HP Amp", NULL, "DAC R" },
  2500. };
  2501. static const struct snd_soc_dapm_route rt5663_v2_specific_dapm_routes[] = {
  2502. { "MICBIAS1", NULL, "LDO2" },
  2503. { "MICBIAS2", NULL, "LDO2" },
  2504. { "BST1 CBJ", NULL, "IN1P" },
  2505. { "BST1 CBJ", NULL, "IN1N" },
  2506. { "BST1 CBJ", NULL, "CBJ Power" },
  2507. { "BST2", NULL, "IN2P" },
  2508. { "BST2", NULL, "IN2N" },
  2509. { "BST2", NULL, "BST2 Power" },
  2510. { "RECMIX1L", "BST2 Switch", "BST2" },
  2511. { "RECMIX1L", "BST1 CBJ Switch", "BST1 CBJ" },
  2512. { "RECMIX1L", NULL, "RECMIX1L Power" },
  2513. { "RECMIX1R", "BST2 Switch", "BST2" },
  2514. { "RECMIX1R", NULL, "RECMIX1R Power" },
  2515. { "ADC L", NULL, "RECMIX1L" },
  2516. { "ADC R", NULL, "RECMIX1R" },
  2517. { "ADC R", NULL, "ADC R Power" },
  2518. { "ADC R", NULL, "ADC Clock" },
  2519. { "STO1 ADC L Mux", "ADC L", "ADC L" },
  2520. { "STO1 ADC L Mux", "ADC R", "ADC R" },
  2521. { "STO1 ADC L1", NULL, "STO1 ADC L Mux" },
  2522. { "STO1 ADC R Mux", "ADC L", "ADC L" },
  2523. { "STO1 ADC R Mux", "ADC R", "ADC R" },
  2524. { "STO1 ADC R1", NULL, "STO1 ADC R Mux" },
  2525. { "STO1 ADC R2", NULL, "STO1 DAC MIXR" },
  2526. { "STO1 ADC MIXR", "ADC1 Switch", "STO1 ADC R1" },
  2527. { "STO1 ADC MIXR", "ADC2 Switch", "STO1 ADC R2" },
  2528. { "STO1 ADC MIXR", NULL, "STO1 ADC Filter" },
  2529. { "IF1 ADC1", NULL, "STO1 ADC MIXR" },
  2530. { "ADDA MIXR", "ADC R Switch", "STO1 ADC MIXR" },
  2531. { "DAC L", NULL, "STO1 DAC MIXL" },
  2532. { "DAC L", NULL, "LDO DAC" },
  2533. { "DAC L", NULL, "DAC Clock" },
  2534. { "DAC R", NULL, "STO1 DAC MIXR" },
  2535. { "DAC R", NULL, "LDO DAC" },
  2536. { "DAC R", NULL, "DAC Clock" },
  2537. { "HPO Playback", "Switch", "HP Amp" },
  2538. { "HPOL", NULL, "HPO Playback" },
  2539. { "HPOR", NULL, "HPO Playback" },
  2540. };
  2541. static const struct snd_soc_dapm_route rt5663_specific_dapm_routes[] = {
  2542. { "I2S", NULL, "Pre Div Power" },
  2543. { "BST1", NULL, "IN1P" },
  2544. { "BST1", NULL, "IN1N" },
  2545. { "BST1", NULL, "RECMIX1L Power" },
  2546. { "ADC L", NULL, "BST1" },
  2547. { "STO1 ADC L1", NULL, "ADC L" },
  2548. { "DAC L Mux", "DAC L", "DAC L1" },
  2549. { "DAC L Mux", "STO DAC MIXL", "STO1 DAC MIXL" },
  2550. { "DAC R Mux", "DAC R", "DAC R1"},
  2551. { "DAC R Mux", "STO DAC MIXR", "STO1 DAC MIXR" },
  2552. { "DAC L", NULL, "DAC L Mux" },
  2553. { "DAC R", NULL, "DAC R Mux" },
  2554. { "HPOL", NULL, "HP Amp" },
  2555. { "HPOR", NULL, "HP Amp" },
  2556. };
  2557. static int rt5663_hw_params(struct snd_pcm_substream *substream,
  2558. struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
  2559. {
  2560. struct snd_soc_component *component = dai->component;
  2561. struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component);
  2562. unsigned int val_len = 0;
  2563. int pre_div;
  2564. rt5663->lrck = params_rate(params);
  2565. dev_dbg(dai->dev, "bclk is %dHz and sysclk is %dHz\n",
  2566. rt5663->lrck, rt5663->sysclk);
  2567. pre_div = rl6231_get_clk_info(rt5663->sysclk, rt5663->lrck);
  2568. if (pre_div < 0) {
  2569. dev_err(component->dev, "Unsupported clock setting %d for DAI %d\n",
  2570. rt5663->lrck, dai->id);
  2571. return -EINVAL;
  2572. }
  2573. dev_dbg(dai->dev, "pre_div is %d for iis %d\n", pre_div, dai->id);
  2574. switch (params_width(params)) {
  2575. case 8:
  2576. val_len = RT5663_I2S_DL_8;
  2577. break;
  2578. case 16:
  2579. val_len = RT5663_I2S_DL_16;
  2580. break;
  2581. case 20:
  2582. val_len = RT5663_I2S_DL_20;
  2583. break;
  2584. case 24:
  2585. val_len = RT5663_I2S_DL_24;
  2586. break;
  2587. default:
  2588. return -EINVAL;
  2589. }
  2590. snd_soc_component_update_bits(component, RT5663_I2S1_SDP,
  2591. RT5663_I2S_DL_MASK, val_len);
  2592. snd_soc_component_update_bits(component, RT5663_ADDA_CLK_1,
  2593. RT5663_I2S_PD1_MASK, pre_div << RT5663_I2S_PD1_SHIFT);
  2594. return 0;
  2595. }
  2596. static int rt5663_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
  2597. {
  2598. struct snd_soc_component *component = dai->component;
  2599. unsigned int reg_val = 0;
  2600. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  2601. case SND_SOC_DAIFMT_CBM_CFM:
  2602. break;
  2603. case SND_SOC_DAIFMT_CBS_CFS:
  2604. reg_val |= RT5663_I2S_MS_S;
  2605. break;
  2606. default:
  2607. return -EINVAL;
  2608. }
  2609. switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
  2610. case SND_SOC_DAIFMT_NB_NF:
  2611. break;
  2612. case SND_SOC_DAIFMT_IB_NF:
  2613. reg_val |= RT5663_I2S_BP_INV;
  2614. break;
  2615. default:
  2616. return -EINVAL;
  2617. }
  2618. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  2619. case SND_SOC_DAIFMT_I2S:
  2620. break;
  2621. case SND_SOC_DAIFMT_LEFT_J:
  2622. reg_val |= RT5663_I2S_DF_LEFT;
  2623. break;
  2624. case SND_SOC_DAIFMT_DSP_A:
  2625. reg_val |= RT5663_I2S_DF_PCM_A;
  2626. break;
  2627. case SND_SOC_DAIFMT_DSP_B:
  2628. reg_val |= RT5663_I2S_DF_PCM_B;
  2629. break;
  2630. default:
  2631. return -EINVAL;
  2632. }
  2633. snd_soc_component_update_bits(component, RT5663_I2S1_SDP, RT5663_I2S_MS_MASK |
  2634. RT5663_I2S_BP_MASK | RT5663_I2S_DF_MASK, reg_val);
  2635. return 0;
  2636. }
  2637. static int rt5663_set_dai_sysclk(struct snd_soc_dai *dai, int clk_id,
  2638. unsigned int freq, int dir)
  2639. {
  2640. struct snd_soc_component *component = dai->component;
  2641. struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component);
  2642. unsigned int reg_val = 0;
  2643. if (freq == rt5663->sysclk && clk_id == rt5663->sysclk_src)
  2644. return 0;
  2645. switch (clk_id) {
  2646. case RT5663_SCLK_S_MCLK:
  2647. reg_val |= RT5663_SCLK_SRC_MCLK;
  2648. break;
  2649. case RT5663_SCLK_S_PLL1:
  2650. reg_val |= RT5663_SCLK_SRC_PLL1;
  2651. break;
  2652. case RT5663_SCLK_S_RCCLK:
  2653. reg_val |= RT5663_SCLK_SRC_RCCLK;
  2654. break;
  2655. default:
  2656. dev_err(component->dev, "Invalid clock id (%d)\n", clk_id);
  2657. return -EINVAL;
  2658. }
  2659. snd_soc_component_update_bits(component, RT5663_GLB_CLK, RT5663_SCLK_SRC_MASK,
  2660. reg_val);
  2661. rt5663->sysclk = freq;
  2662. rt5663->sysclk_src = clk_id;
  2663. dev_dbg(component->dev, "Sysclk is %dHz and clock id is %d\n",
  2664. freq, clk_id);
  2665. return 0;
  2666. }
  2667. static int rt5663_set_dai_pll(struct snd_soc_dai *dai, int pll_id, int source,
  2668. unsigned int freq_in, unsigned int freq_out)
  2669. {
  2670. struct snd_soc_component *component = dai->component;
  2671. struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component);
  2672. struct rl6231_pll_code pll_code;
  2673. int ret;
  2674. int mask, shift, val;
  2675. if (source == rt5663->pll_src && freq_in == rt5663->pll_in &&
  2676. freq_out == rt5663->pll_out)
  2677. return 0;
  2678. if (!freq_in || !freq_out) {
  2679. dev_dbg(component->dev, "PLL disabled\n");
  2680. rt5663->pll_in = 0;
  2681. rt5663->pll_out = 0;
  2682. snd_soc_component_update_bits(component, RT5663_GLB_CLK,
  2683. RT5663_SCLK_SRC_MASK, RT5663_SCLK_SRC_MCLK);
  2684. return 0;
  2685. }
  2686. switch (rt5663->codec_ver) {
  2687. case CODEC_VER_1:
  2688. mask = RT5663_V2_PLL1_SRC_MASK;
  2689. shift = RT5663_V2_PLL1_SRC_SHIFT;
  2690. break;
  2691. case CODEC_VER_0:
  2692. mask = RT5663_PLL1_SRC_MASK;
  2693. shift = RT5663_PLL1_SRC_SHIFT;
  2694. break;
  2695. default:
  2696. dev_err(component->dev, "Unknown CODEC Version\n");
  2697. return -EINVAL;
  2698. }
  2699. switch (source) {
  2700. case RT5663_PLL1_S_MCLK:
  2701. val = 0x0;
  2702. break;
  2703. case RT5663_PLL1_S_BCLK1:
  2704. val = 0x1;
  2705. break;
  2706. default:
  2707. dev_err(component->dev, "Unknown PLL source %d\n", source);
  2708. return -EINVAL;
  2709. }
  2710. snd_soc_component_update_bits(component, RT5663_GLB_CLK, mask, (val << shift));
  2711. ret = rl6231_pll_calc(freq_in, freq_out, &pll_code);
  2712. if (ret < 0) {
  2713. dev_err(component->dev, "Unsupported input clock %d\n", freq_in);
  2714. return ret;
  2715. }
  2716. dev_dbg(component->dev, "bypass=%d m=%d n=%d k=%d\n", pll_code.m_bp,
  2717. (pll_code.m_bp ? 0 : pll_code.m_code), pll_code.n_code,
  2718. pll_code.k_code);
  2719. snd_soc_component_write(component, RT5663_PLL_1,
  2720. pll_code.n_code << RT5663_PLL_N_SHIFT | pll_code.k_code);
  2721. snd_soc_component_write(component, RT5663_PLL_2,
  2722. ((pll_code.m_bp ? 0 : pll_code.m_code) << RT5663_PLL_M_SHIFT) |
  2723. (pll_code.m_bp << RT5663_PLL_M_BP_SHIFT));
  2724. rt5663->pll_in = freq_in;
  2725. rt5663->pll_out = freq_out;
  2726. rt5663->pll_src = source;
  2727. return 0;
  2728. }
  2729. static int rt5663_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask,
  2730. unsigned int rx_mask, int slots, int slot_width)
  2731. {
  2732. struct snd_soc_component *component = dai->component;
  2733. struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component);
  2734. unsigned int val = 0, reg;
  2735. if (rx_mask || tx_mask)
  2736. val |= RT5663_TDM_MODE_TDM;
  2737. switch (slots) {
  2738. case 4:
  2739. val |= RT5663_TDM_IN_CH_4;
  2740. val |= RT5663_TDM_OUT_CH_4;
  2741. break;
  2742. case 6:
  2743. val |= RT5663_TDM_IN_CH_6;
  2744. val |= RT5663_TDM_OUT_CH_6;
  2745. break;
  2746. case 8:
  2747. val |= RT5663_TDM_IN_CH_8;
  2748. val |= RT5663_TDM_OUT_CH_8;
  2749. break;
  2750. case 2:
  2751. break;
  2752. default:
  2753. return -EINVAL;
  2754. }
  2755. switch (slot_width) {
  2756. case 20:
  2757. val |= RT5663_TDM_IN_LEN_20;
  2758. val |= RT5663_TDM_OUT_LEN_20;
  2759. break;
  2760. case 24:
  2761. val |= RT5663_TDM_IN_LEN_24;
  2762. val |= RT5663_TDM_OUT_LEN_24;
  2763. break;
  2764. case 32:
  2765. val |= RT5663_TDM_IN_LEN_32;
  2766. val |= RT5663_TDM_OUT_LEN_32;
  2767. break;
  2768. case 16:
  2769. break;
  2770. default:
  2771. return -EINVAL;
  2772. }
  2773. switch (rt5663->codec_ver) {
  2774. case CODEC_VER_1:
  2775. reg = RT5663_TDM_2;
  2776. break;
  2777. case CODEC_VER_0:
  2778. reg = RT5663_TDM_1;
  2779. break;
  2780. default:
  2781. dev_err(component->dev, "Unknown CODEC Version\n");
  2782. return -EINVAL;
  2783. }
  2784. snd_soc_component_update_bits(component, reg, RT5663_TDM_MODE_MASK |
  2785. RT5663_TDM_IN_CH_MASK | RT5663_TDM_OUT_CH_MASK |
  2786. RT5663_TDM_IN_LEN_MASK | RT5663_TDM_OUT_LEN_MASK, val);
  2787. return 0;
  2788. }
  2789. static int rt5663_set_bclk_ratio(struct snd_soc_dai *dai, unsigned int ratio)
  2790. {
  2791. struct snd_soc_component *component = dai->component;
  2792. struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component);
  2793. unsigned int reg;
  2794. dev_dbg(component->dev, "%s ratio = %d\n", __func__, ratio);
  2795. if (rt5663->codec_ver == CODEC_VER_1)
  2796. reg = RT5663_TDM_9;
  2797. else
  2798. reg = RT5663_TDM_5;
  2799. switch (ratio) {
  2800. case 32:
  2801. snd_soc_component_update_bits(component, reg,
  2802. RT5663_TDM_LENGTN_MASK,
  2803. RT5663_TDM_LENGTN_16);
  2804. break;
  2805. case 40:
  2806. snd_soc_component_update_bits(component, reg,
  2807. RT5663_TDM_LENGTN_MASK,
  2808. RT5663_TDM_LENGTN_20);
  2809. break;
  2810. case 48:
  2811. snd_soc_component_update_bits(component, reg,
  2812. RT5663_TDM_LENGTN_MASK,
  2813. RT5663_TDM_LENGTN_24);
  2814. break;
  2815. case 64:
  2816. snd_soc_component_update_bits(component, reg,
  2817. RT5663_TDM_LENGTN_MASK,
  2818. RT5663_TDM_LENGTN_32);
  2819. break;
  2820. default:
  2821. dev_err(component->dev, "Invalid ratio!\n");
  2822. return -EINVAL;
  2823. }
  2824. return 0;
  2825. }
  2826. static int rt5663_set_bias_level(struct snd_soc_component *component,
  2827. enum snd_soc_bias_level level)
  2828. {
  2829. struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component);
  2830. switch (level) {
  2831. case SND_SOC_BIAS_ON:
  2832. snd_soc_component_update_bits(component, RT5663_PWR_ANLG_1,
  2833. RT5663_PWR_FV1_MASK | RT5663_PWR_FV2_MASK,
  2834. RT5663_PWR_FV1 | RT5663_PWR_FV2);
  2835. break;
  2836. case SND_SOC_BIAS_PREPARE:
  2837. if (rt5663->codec_ver == CODEC_VER_1) {
  2838. snd_soc_component_update_bits(component, RT5663_DIG_MISC,
  2839. RT5663_DIG_GATE_CTRL_MASK,
  2840. RT5663_DIG_GATE_CTRL_EN);
  2841. snd_soc_component_update_bits(component, RT5663_SIG_CLK_DET,
  2842. RT5663_EN_ANA_CLK_DET_MASK |
  2843. RT5663_PWR_CLK_DET_MASK,
  2844. RT5663_EN_ANA_CLK_DET_AUTO |
  2845. RT5663_PWR_CLK_DET_EN);
  2846. }
  2847. break;
  2848. case SND_SOC_BIAS_STANDBY:
  2849. if (rt5663->codec_ver == CODEC_VER_1)
  2850. snd_soc_component_update_bits(component, RT5663_DIG_MISC,
  2851. RT5663_DIG_GATE_CTRL_MASK,
  2852. RT5663_DIG_GATE_CTRL_DIS);
  2853. snd_soc_component_update_bits(component, RT5663_PWR_ANLG_1,
  2854. RT5663_PWR_VREF1_MASK | RT5663_PWR_VREF2_MASK |
  2855. RT5663_PWR_FV1_MASK | RT5663_PWR_FV2_MASK |
  2856. RT5663_PWR_MB_MASK, RT5663_PWR_VREF1 |
  2857. RT5663_PWR_VREF2 | RT5663_PWR_MB);
  2858. usleep_range(10000, 10005);
  2859. if (rt5663->codec_ver == CODEC_VER_1) {
  2860. snd_soc_component_update_bits(component, RT5663_SIG_CLK_DET,
  2861. RT5663_EN_ANA_CLK_DET_MASK |
  2862. RT5663_PWR_CLK_DET_MASK,
  2863. RT5663_EN_ANA_CLK_DET_DIS |
  2864. RT5663_PWR_CLK_DET_DIS);
  2865. }
  2866. break;
  2867. case SND_SOC_BIAS_OFF:
  2868. if (rt5663->jack_type != SND_JACK_HEADSET)
  2869. snd_soc_component_update_bits(component,
  2870. RT5663_PWR_ANLG_1,
  2871. RT5663_PWR_VREF1_MASK | RT5663_PWR_VREF2_MASK |
  2872. RT5663_PWR_FV1 | RT5663_PWR_FV2 |
  2873. RT5663_PWR_MB_MASK, 0);
  2874. else
  2875. snd_soc_component_update_bits(component,
  2876. RT5663_PWR_ANLG_1,
  2877. RT5663_PWR_FV1_MASK | RT5663_PWR_FV2_MASK,
  2878. RT5663_PWR_FV1 | RT5663_PWR_FV2);
  2879. break;
  2880. default:
  2881. break;
  2882. }
  2883. return 0;
  2884. }
  2885. static int rt5663_probe(struct snd_soc_component *component)
  2886. {
  2887. struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
  2888. struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component);
  2889. rt5663->component = component;
  2890. switch (rt5663->codec_ver) {
  2891. case CODEC_VER_1:
  2892. snd_soc_dapm_new_controls(dapm,
  2893. rt5663_v2_specific_dapm_widgets,
  2894. ARRAY_SIZE(rt5663_v2_specific_dapm_widgets));
  2895. snd_soc_dapm_add_routes(dapm,
  2896. rt5663_v2_specific_dapm_routes,
  2897. ARRAY_SIZE(rt5663_v2_specific_dapm_routes));
  2898. snd_soc_add_component_controls(component, rt5663_v2_specific_controls,
  2899. ARRAY_SIZE(rt5663_v2_specific_controls));
  2900. break;
  2901. case CODEC_VER_0:
  2902. snd_soc_dapm_new_controls(dapm,
  2903. rt5663_specific_dapm_widgets,
  2904. ARRAY_SIZE(rt5663_specific_dapm_widgets));
  2905. snd_soc_dapm_add_routes(dapm,
  2906. rt5663_specific_dapm_routes,
  2907. ARRAY_SIZE(rt5663_specific_dapm_routes));
  2908. snd_soc_add_component_controls(component, rt5663_specific_controls,
  2909. ARRAY_SIZE(rt5663_specific_controls));
  2910. if (!rt5663->imp_table)
  2911. snd_soc_add_component_controls(component, rt5663_hpvol_controls,
  2912. ARRAY_SIZE(rt5663_hpvol_controls));
  2913. break;
  2914. }
  2915. return 0;
  2916. }
  2917. static void rt5663_remove(struct snd_soc_component *component)
  2918. {
  2919. struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component);
  2920. regmap_write(rt5663->regmap, RT5663_RESET, 0);
  2921. }
  2922. #ifdef CONFIG_PM
  2923. static int rt5663_suspend(struct snd_soc_component *component)
  2924. {
  2925. struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component);
  2926. regcache_cache_only(rt5663->regmap, true);
  2927. regcache_mark_dirty(rt5663->regmap);
  2928. return 0;
  2929. }
  2930. static int rt5663_resume(struct snd_soc_component *component)
  2931. {
  2932. struct rt5663_priv *rt5663 = snd_soc_component_get_drvdata(component);
  2933. regcache_cache_only(rt5663->regmap, false);
  2934. regcache_sync(rt5663->regmap);
  2935. rt5663_irq(0, rt5663);
  2936. return 0;
  2937. }
  2938. #else
  2939. #define rt5663_suspend NULL
  2940. #define rt5663_resume NULL
  2941. #endif
  2942. #define RT5663_STEREO_RATES SNDRV_PCM_RATE_8000_192000
  2943. #define RT5663_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
  2944. SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S8)
  2945. static const struct snd_soc_dai_ops rt5663_aif_dai_ops = {
  2946. .hw_params = rt5663_hw_params,
  2947. .set_fmt = rt5663_set_dai_fmt,
  2948. .set_sysclk = rt5663_set_dai_sysclk,
  2949. .set_pll = rt5663_set_dai_pll,
  2950. .set_tdm_slot = rt5663_set_tdm_slot,
  2951. .set_bclk_ratio = rt5663_set_bclk_ratio,
  2952. };
  2953. static struct snd_soc_dai_driver rt5663_dai[] = {
  2954. {
  2955. .name = "rt5663-aif",
  2956. .id = RT5663_AIF,
  2957. .playback = {
  2958. .stream_name = "AIF Playback",
  2959. .channels_min = 1,
  2960. .channels_max = 2,
  2961. .rates = RT5663_STEREO_RATES,
  2962. .formats = RT5663_FORMATS,
  2963. },
  2964. .capture = {
  2965. .stream_name = "AIF Capture",
  2966. .channels_min = 1,
  2967. .channels_max = 2,
  2968. .rates = RT5663_STEREO_RATES,
  2969. .formats = RT5663_FORMATS,
  2970. },
  2971. .ops = &rt5663_aif_dai_ops,
  2972. },
  2973. };
  2974. static const struct snd_soc_component_driver soc_component_dev_rt5663 = {
  2975. .probe = rt5663_probe,
  2976. .remove = rt5663_remove,
  2977. .suspend = rt5663_suspend,
  2978. .resume = rt5663_resume,
  2979. .set_bias_level = rt5663_set_bias_level,
  2980. .controls = rt5663_snd_controls,
  2981. .num_controls = ARRAY_SIZE(rt5663_snd_controls),
  2982. .dapm_widgets = rt5663_dapm_widgets,
  2983. .num_dapm_widgets = ARRAY_SIZE(rt5663_dapm_widgets),
  2984. .dapm_routes = rt5663_dapm_routes,
  2985. .num_dapm_routes = ARRAY_SIZE(rt5663_dapm_routes),
  2986. .set_jack = rt5663_set_jack_detect,
  2987. .use_pmdown_time = 1,
  2988. .endianness = 1,
  2989. };
  2990. static const struct regmap_config rt5663_v2_regmap = {
  2991. .reg_bits = 16,
  2992. .val_bits = 16,
  2993. .use_single_read = true,
  2994. .use_single_write = true,
  2995. .max_register = 0x07fa,
  2996. .volatile_reg = rt5663_v2_volatile_register,
  2997. .readable_reg = rt5663_v2_readable_register,
  2998. .cache_type = REGCACHE_RBTREE,
  2999. .reg_defaults = rt5663_v2_reg,
  3000. .num_reg_defaults = ARRAY_SIZE(rt5663_v2_reg),
  3001. };
  3002. static const struct regmap_config rt5663_regmap = {
  3003. .reg_bits = 16,
  3004. .val_bits = 16,
  3005. .use_single_read = true,
  3006. .use_single_write = true,
  3007. .max_register = 0x03f3,
  3008. .volatile_reg = rt5663_volatile_register,
  3009. .readable_reg = rt5663_readable_register,
  3010. .cache_type = REGCACHE_RBTREE,
  3011. .reg_defaults = rt5663_reg,
  3012. .num_reg_defaults = ARRAY_SIZE(rt5663_reg),
  3013. };
  3014. static const struct regmap_config temp_regmap = {
  3015. .name = "nocache",
  3016. .reg_bits = 16,
  3017. .val_bits = 16,
  3018. .use_single_read = true,
  3019. .use_single_write = true,
  3020. .max_register = 0x03f3,
  3021. .cache_type = REGCACHE_NONE,
  3022. };
  3023. static const struct i2c_device_id rt5663_i2c_id[] = {
  3024. { "rt5663", 0 },
  3025. {}
  3026. };
  3027. MODULE_DEVICE_TABLE(i2c, rt5663_i2c_id);
  3028. #if defined(CONFIG_OF)
  3029. static const struct of_device_id rt5663_of_match[] = {
  3030. { .compatible = "realtek,rt5663", },
  3031. {},
  3032. };
  3033. MODULE_DEVICE_TABLE(of, rt5663_of_match);
  3034. #endif
  3035. #ifdef CONFIG_ACPI
  3036. static const struct acpi_device_id rt5663_acpi_match[] = {
  3037. { "10EC5663", 0},
  3038. {},
  3039. };
  3040. MODULE_DEVICE_TABLE(acpi, rt5663_acpi_match);
  3041. #endif
  3042. static void rt5663_v2_calibrate(struct rt5663_priv *rt5663)
  3043. {
  3044. regmap_write(rt5663->regmap, RT5663_BIAS_CUR_8, 0xa402);
  3045. regmap_write(rt5663->regmap, RT5663_PWR_DIG_1, 0x0100);
  3046. regmap_write(rt5663->regmap, RT5663_RECMIX, 0x4040);
  3047. regmap_write(rt5663->regmap, RT5663_DIG_MISC, 0x0001);
  3048. regmap_write(rt5663->regmap, RT5663_RC_CLK, 0x0380);
  3049. regmap_write(rt5663->regmap, RT5663_GLB_CLK, 0x8000);
  3050. regmap_write(rt5663->regmap, RT5663_ADDA_CLK_1, 0x1000);
  3051. regmap_write(rt5663->regmap, RT5663_CHOP_DAC_L, 0x3030);
  3052. regmap_write(rt5663->regmap, RT5663_CALIB_ADC, 0x3c05);
  3053. regmap_write(rt5663->regmap, RT5663_PWR_ANLG_1, 0xa23e);
  3054. msleep(40);
  3055. regmap_write(rt5663->regmap, RT5663_PWR_ANLG_1, 0xf23e);
  3056. regmap_write(rt5663->regmap, RT5663_HP_CALIB_2, 0x0321);
  3057. regmap_write(rt5663->regmap, RT5663_HP_CALIB_1, 0xfc00);
  3058. msleep(500);
  3059. }
  3060. static void rt5663_calibrate(struct rt5663_priv *rt5663)
  3061. {
  3062. int value, count;
  3063. regmap_write(rt5663->regmap, RT5663_RESET, 0x0000);
  3064. msleep(20);
  3065. regmap_write(rt5663->regmap, RT5663_ANA_BIAS_CUR_4, 0x00a1);
  3066. regmap_write(rt5663->regmap, RT5663_RC_CLK, 0x0380);
  3067. regmap_write(rt5663->regmap, RT5663_GLB_CLK, 0x8000);
  3068. regmap_write(rt5663->regmap, RT5663_ADDA_CLK_1, 0x1000);
  3069. regmap_write(rt5663->regmap, RT5663_VREF_RECMIX, 0x0032);
  3070. regmap_write(rt5663->regmap, RT5663_HP_IMP_SEN_19, 0x000c);
  3071. regmap_write(rt5663->regmap, RT5663_DUMMY_1, 0x0324);
  3072. regmap_write(rt5663->regmap, RT5663_DIG_MISC, 0x8001);
  3073. regmap_write(rt5663->regmap, RT5663_VREFADJ_OP, 0x0f28);
  3074. regmap_write(rt5663->regmap, RT5663_PWR_ANLG_1, 0xa23b);
  3075. msleep(30);
  3076. regmap_write(rt5663->regmap, RT5663_PWR_ANLG_1, 0xf23b);
  3077. regmap_write(rt5663->regmap, RT5663_PWR_ANLG_2, 0x8000);
  3078. regmap_write(rt5663->regmap, RT5663_PWR_ANLG_3, 0x0008);
  3079. regmap_write(rt5663->regmap, RT5663_PRE_DIV_GATING_1, 0xffff);
  3080. regmap_write(rt5663->regmap, RT5663_PRE_DIV_GATING_2, 0xffff);
  3081. regmap_write(rt5663->regmap, RT5663_CBJ_1, 0x8c10);
  3082. regmap_write(rt5663->regmap, RT5663_IL_CMD_2, 0x00c1);
  3083. regmap_write(rt5663->regmap, RT5663_EM_JACK_TYPE_1, 0xb880);
  3084. regmap_write(rt5663->regmap, RT5663_EM_JACK_TYPE_2, 0x4110);
  3085. regmap_write(rt5663->regmap, RT5663_EM_JACK_TYPE_2, 0x4118);
  3086. count = 0;
  3087. while (true) {
  3088. regmap_read(rt5663->regmap, RT5663_INT_ST_2, &value);
  3089. if (!(value & 0x80))
  3090. usleep_range(10000, 10005);
  3091. else
  3092. break;
  3093. if (++count > 200)
  3094. break;
  3095. }
  3096. regmap_write(rt5663->regmap, RT5663_HP_IMP_SEN_19, 0x0000);
  3097. regmap_write(rt5663->regmap, RT5663_DEPOP_2, 0x3003);
  3098. regmap_write(rt5663->regmap, RT5663_DEPOP_1, 0x0038);
  3099. regmap_write(rt5663->regmap, RT5663_DEPOP_1, 0x003b);
  3100. regmap_write(rt5663->regmap, RT5663_PWR_DIG_2, 0x8400);
  3101. regmap_write(rt5663->regmap, RT5663_PWR_DIG_1, 0x8df8);
  3102. regmap_write(rt5663->regmap, RT5663_PWR_ANLG_2, 0x8003);
  3103. regmap_write(rt5663->regmap, RT5663_PWR_ANLG_3, 0x018c);
  3104. regmap_write(rt5663->regmap, RT5663_HP_CHARGE_PUMP_1, 0x1e32);
  3105. regmap_write(rt5663->regmap, RT5663_DUMMY_2, 0x8089);
  3106. regmap_write(rt5663->regmap, RT5663_DACREF_LDO, 0x3b0b);
  3107. msleep(40);
  3108. regmap_write(rt5663->regmap, RT5663_STO_DAC_MIXER, 0x0000);
  3109. regmap_write(rt5663->regmap, RT5663_BYPASS_STO_DAC, 0x000c);
  3110. regmap_write(rt5663->regmap, RT5663_HP_BIAS, 0xafaa);
  3111. regmap_write(rt5663->regmap, RT5663_CHARGE_PUMP_1, 0x2224);
  3112. regmap_write(rt5663->regmap, RT5663_HP_OUT_EN, 0x8088);
  3113. regmap_write(rt5663->regmap, RT5663_STO_DRE_9, 0x0017);
  3114. regmap_write(rt5663->regmap, RT5663_STO_DRE_10, 0x0017);
  3115. regmap_write(rt5663->regmap, RT5663_STO1_ADC_MIXER, 0x4040);
  3116. regmap_write(rt5663->regmap, RT5663_CHOP_ADC, 0x3000);
  3117. regmap_write(rt5663->regmap, RT5663_RECMIX, 0x0005);
  3118. regmap_write(rt5663->regmap, RT5663_ADDA_RST, 0xc000);
  3119. regmap_write(rt5663->regmap, RT5663_STO1_HPF_ADJ1, 0x3320);
  3120. regmap_write(rt5663->regmap, RT5663_HP_CALIB_2, 0x00c9);
  3121. regmap_write(rt5663->regmap, RT5663_DUMMY_1, 0x004c);
  3122. regmap_write(rt5663->regmap, RT5663_ANA_BIAS_CUR_1, 0x1111);
  3123. regmap_write(rt5663->regmap, RT5663_BIAS_CUR_8, 0x4402);
  3124. regmap_write(rt5663->regmap, RT5663_CHARGE_PUMP_2, 0x3311);
  3125. regmap_write(rt5663->regmap, RT5663_HP_CALIB_1, 0x0069);
  3126. regmap_write(rt5663->regmap, RT5663_HP_CALIB_3, 0x06ce);
  3127. regmap_write(rt5663->regmap, RT5663_HP_CALIB_1_1, 0x6800);
  3128. regmap_write(rt5663->regmap, RT5663_CHARGE_PUMP_2, 0x1100);
  3129. regmap_write(rt5663->regmap, RT5663_HP_CALIB_7, 0x0057);
  3130. regmap_write(rt5663->regmap, RT5663_HP_CALIB_1_1, 0xe800);
  3131. count = 0;
  3132. while (true) {
  3133. regmap_read(rt5663->regmap, RT5663_HP_CALIB_1_1, &value);
  3134. if (value & 0x8000)
  3135. usleep_range(10000, 10005);
  3136. else
  3137. break;
  3138. if (count > 200)
  3139. return;
  3140. count++;
  3141. }
  3142. regmap_write(rt5663->regmap, RT5663_HP_CALIB_1_1, 0x6200);
  3143. regmap_write(rt5663->regmap, RT5663_HP_CALIB_7, 0x0059);
  3144. regmap_write(rt5663->regmap, RT5663_HP_CALIB_1_1, 0xe200);
  3145. count = 0;
  3146. while (true) {
  3147. regmap_read(rt5663->regmap, RT5663_HP_CALIB_1_1, &value);
  3148. if (value & 0x8000)
  3149. usleep_range(10000, 10005);
  3150. else
  3151. break;
  3152. if (count > 200)
  3153. return;
  3154. count++;
  3155. }
  3156. regmap_write(rt5663->regmap, RT5663_EM_JACK_TYPE_1, 0xb8e0);
  3157. usleep_range(10000, 10005);
  3158. regmap_write(rt5663->regmap, RT5663_PWR_ANLG_1, 0x003b);
  3159. usleep_range(10000, 10005);
  3160. regmap_write(rt5663->regmap, RT5663_PWR_DIG_1, 0x0000);
  3161. usleep_range(10000, 10005);
  3162. regmap_write(rt5663->regmap, RT5663_DEPOP_1, 0x000b);
  3163. usleep_range(10000, 10005);
  3164. regmap_write(rt5663->regmap, RT5663_DEPOP_1, 0x0008);
  3165. usleep_range(10000, 10005);
  3166. regmap_write(rt5663->regmap, RT5663_PWR_ANLG_2, 0x0000);
  3167. usleep_range(10000, 10005);
  3168. }
  3169. static int rt5663_parse_dp(struct rt5663_priv *rt5663, struct device *dev)
  3170. {
  3171. int table_size;
  3172. int ret;
  3173. device_property_read_u32(dev, "realtek,dc_offset_l_manual",
  3174. &rt5663->pdata.dc_offset_l_manual);
  3175. device_property_read_u32(dev, "realtek,dc_offset_r_manual",
  3176. &rt5663->pdata.dc_offset_r_manual);
  3177. device_property_read_u32(dev, "realtek,dc_offset_l_manual_mic",
  3178. &rt5663->pdata.dc_offset_l_manual_mic);
  3179. device_property_read_u32(dev, "realtek,dc_offset_r_manual_mic",
  3180. &rt5663->pdata.dc_offset_r_manual_mic);
  3181. device_property_read_u32(dev, "realtek,impedance_sensing_num",
  3182. &rt5663->pdata.impedance_sensing_num);
  3183. if (rt5663->pdata.impedance_sensing_num) {
  3184. table_size = sizeof(struct impedance_mapping_table) *
  3185. rt5663->pdata.impedance_sensing_num;
  3186. rt5663->imp_table = devm_kzalloc(dev, table_size, GFP_KERNEL);
  3187. if (!rt5663->imp_table)
  3188. return -ENOMEM;
  3189. ret = device_property_read_u32_array(dev,
  3190. "realtek,impedance_sensing_table",
  3191. (u32 *)rt5663->imp_table, table_size);
  3192. if (ret)
  3193. return ret;
  3194. }
  3195. return 0;
  3196. }
  3197. static int rt5663_i2c_probe(struct i2c_client *i2c)
  3198. {
  3199. struct rt5663_platform_data *pdata = dev_get_platdata(&i2c->dev);
  3200. struct rt5663_priv *rt5663;
  3201. int ret, i;
  3202. unsigned int val;
  3203. struct regmap *regmap;
  3204. rt5663 = devm_kzalloc(&i2c->dev, sizeof(struct rt5663_priv),
  3205. GFP_KERNEL);
  3206. if (rt5663 == NULL)
  3207. return -ENOMEM;
  3208. i2c_set_clientdata(i2c, rt5663);
  3209. if (pdata)
  3210. rt5663->pdata = *pdata;
  3211. else {
  3212. ret = rt5663_parse_dp(rt5663, &i2c->dev);
  3213. if (ret)
  3214. return ret;
  3215. }
  3216. for (i = 0; i < ARRAY_SIZE(rt5663->supplies); i++)
  3217. rt5663->supplies[i].supply = rt5663_supply_names[i];
  3218. ret = devm_regulator_bulk_get(&i2c->dev,
  3219. ARRAY_SIZE(rt5663->supplies),
  3220. rt5663->supplies);
  3221. if (ret) {
  3222. dev_err(&i2c->dev, "Failed to request supplies: %d\n", ret);
  3223. return ret;
  3224. }
  3225. /* Set load for regulator. */
  3226. for (i = 0; i < ARRAY_SIZE(rt5663->supplies); i++) {
  3227. ret = regulator_set_load(rt5663->supplies[i].consumer,
  3228. RT5663_SUPPLY_CURRENT_UA);
  3229. if (ret < 0) {
  3230. dev_err(&i2c->dev,
  3231. "Failed to set regulator load on %s, ret: %d\n",
  3232. rt5663->supplies[i].supply, ret);
  3233. return ret;
  3234. }
  3235. }
  3236. ret = regulator_bulk_enable(ARRAY_SIZE(rt5663->supplies),
  3237. rt5663->supplies);
  3238. if (ret) {
  3239. dev_err(&i2c->dev, "Failed to enable supplies: %d\n", ret);
  3240. return ret;
  3241. }
  3242. msleep(RT5663_POWER_ON_DELAY_MS);
  3243. regmap = devm_regmap_init_i2c(i2c, &temp_regmap);
  3244. if (IS_ERR(regmap)) {
  3245. ret = PTR_ERR(regmap);
  3246. dev_err(&i2c->dev, "Failed to allocate temp register map: %d\n",
  3247. ret);
  3248. goto err_enable;
  3249. }
  3250. ret = regmap_read(regmap, RT5663_VENDOR_ID_2, &val);
  3251. if (ret || (val != RT5663_DEVICE_ID_2 && val != RT5663_DEVICE_ID_1)) {
  3252. dev_err(&i2c->dev,
  3253. "Device with ID register %#x is not rt5663, retry one time.\n",
  3254. val);
  3255. msleep(100);
  3256. regmap_read(regmap, RT5663_VENDOR_ID_2, &val);
  3257. }
  3258. switch (val) {
  3259. case RT5663_DEVICE_ID_2:
  3260. rt5663->regmap = devm_regmap_init_i2c(i2c, &rt5663_v2_regmap);
  3261. rt5663->codec_ver = CODEC_VER_1;
  3262. break;
  3263. case RT5663_DEVICE_ID_1:
  3264. rt5663->regmap = devm_regmap_init_i2c(i2c, &rt5663_regmap);
  3265. rt5663->codec_ver = CODEC_VER_0;
  3266. break;
  3267. default:
  3268. dev_err(&i2c->dev,
  3269. "Device with ID register %#x is not rt5663\n",
  3270. val);
  3271. ret = -ENODEV;
  3272. goto err_enable;
  3273. }
  3274. if (IS_ERR(rt5663->regmap)) {
  3275. ret = PTR_ERR(rt5663->regmap);
  3276. dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
  3277. ret);
  3278. goto err_enable;
  3279. }
  3280. /* reset and calibrate */
  3281. regmap_write(rt5663->regmap, RT5663_RESET, 0);
  3282. regcache_cache_bypass(rt5663->regmap, true);
  3283. switch (rt5663->codec_ver) {
  3284. case CODEC_VER_1:
  3285. rt5663_v2_calibrate(rt5663);
  3286. break;
  3287. case CODEC_VER_0:
  3288. rt5663_calibrate(rt5663);
  3289. break;
  3290. default:
  3291. dev_err(&i2c->dev, "%s:Unknown codec type\n", __func__);
  3292. }
  3293. regcache_cache_bypass(rt5663->regmap, false);
  3294. regmap_write(rt5663->regmap, RT5663_RESET, 0);
  3295. dev_dbg(&i2c->dev, "calibrate done\n");
  3296. switch (rt5663->codec_ver) {
  3297. case CODEC_VER_1:
  3298. break;
  3299. case CODEC_VER_0:
  3300. ret = regmap_register_patch(rt5663->regmap, rt5663_patch_list,
  3301. ARRAY_SIZE(rt5663_patch_list));
  3302. if (ret != 0)
  3303. dev_warn(&i2c->dev,
  3304. "Failed to apply regmap patch: %d\n", ret);
  3305. break;
  3306. default:
  3307. dev_err(&i2c->dev, "%s:Unknown codec type\n", __func__);
  3308. }
  3309. /* GPIO1 as IRQ */
  3310. regmap_update_bits(rt5663->regmap, RT5663_GPIO_1, RT5663_GP1_PIN_MASK,
  3311. RT5663_GP1_PIN_IRQ);
  3312. /* 4btn inline command debounce */
  3313. regmap_update_bits(rt5663->regmap, RT5663_IL_CMD_5,
  3314. RT5663_4BTN_CLK_DEB_MASK, RT5663_4BTN_CLK_DEB_65MS);
  3315. switch (rt5663->codec_ver) {
  3316. case CODEC_VER_1:
  3317. regmap_write(rt5663->regmap, RT5663_BIAS_CUR_8, 0xa402);
  3318. /* JD1 */
  3319. regmap_update_bits(rt5663->regmap, RT5663_AUTO_1MRC_CLK,
  3320. RT5663_IRQ_POW_SAV_MASK | RT5663_IRQ_POW_SAV_JD1_MASK,
  3321. RT5663_IRQ_POW_SAV_EN | RT5663_IRQ_POW_SAV_JD1_EN);
  3322. regmap_update_bits(rt5663->regmap, RT5663_PWR_ANLG_2,
  3323. RT5663_PWR_JD1_MASK, RT5663_PWR_JD1);
  3324. regmap_update_bits(rt5663->regmap, RT5663_IRQ_1,
  3325. RT5663_EN_CB_JD_MASK, RT5663_EN_CB_JD_EN);
  3326. regmap_update_bits(rt5663->regmap, RT5663_HP_LOGIC_2,
  3327. RT5663_HP_SIG_SRC1_MASK, RT5663_HP_SIG_SRC1_REG);
  3328. regmap_update_bits(rt5663->regmap, RT5663_RECMIX,
  3329. RT5663_VREF_BIAS_MASK | RT5663_CBJ_DET_MASK |
  3330. RT5663_DET_TYPE_MASK, RT5663_VREF_BIAS_REG |
  3331. RT5663_CBJ_DET_EN | RT5663_DET_TYPE_QFN);
  3332. /* Set GPIO4 and GPIO8 as input for combo jack */
  3333. regmap_update_bits(rt5663->regmap, RT5663_GPIO_2,
  3334. RT5663_GP4_PIN_CONF_MASK, RT5663_GP4_PIN_CONF_INPUT);
  3335. regmap_update_bits(rt5663->regmap, RT5663_GPIO_3,
  3336. RT5663_GP8_PIN_CONF_MASK, RT5663_GP8_PIN_CONF_INPUT);
  3337. regmap_update_bits(rt5663->regmap, RT5663_PWR_ANLG_1,
  3338. RT5663_LDO1_DVO_MASK | RT5663_AMP_HP_MASK,
  3339. RT5663_LDO1_DVO_0_9V | RT5663_AMP_HP_3X);
  3340. break;
  3341. case CODEC_VER_0:
  3342. regmap_update_bits(rt5663->regmap, RT5663_DIG_MISC,
  3343. RT5663_DIG_GATE_CTRL_MASK, RT5663_DIG_GATE_CTRL_EN);
  3344. regmap_update_bits(rt5663->regmap, RT5663_AUTO_1MRC_CLK,
  3345. RT5663_IRQ_MANUAL_MASK, RT5663_IRQ_MANUAL_EN);
  3346. regmap_update_bits(rt5663->regmap, RT5663_IRQ_1,
  3347. RT5663_EN_IRQ_JD1_MASK, RT5663_EN_IRQ_JD1_EN);
  3348. regmap_update_bits(rt5663->regmap, RT5663_GPIO_1,
  3349. RT5663_GPIO1_TYPE_MASK, RT5663_GPIO1_TYPE_EN);
  3350. regmap_write(rt5663->regmap, RT5663_VREF_RECMIX, 0x0032);
  3351. regmap_update_bits(rt5663->regmap, RT5663_GPIO_2,
  3352. RT5663_GP1_PIN_CONF_MASK | RT5663_SEL_GPIO1_MASK,
  3353. RT5663_GP1_PIN_CONF_OUTPUT | RT5663_SEL_GPIO1_EN);
  3354. regmap_update_bits(rt5663->regmap, RT5663_RECMIX,
  3355. RT5663_RECMIX1_BST1_MASK, RT5663_RECMIX1_BST1_ON);
  3356. regmap_update_bits(rt5663->regmap, RT5663_TDM_2,
  3357. RT5663_DATA_SWAP_ADCDAT1_MASK,
  3358. RT5663_DATA_SWAP_ADCDAT1_LL);
  3359. break;
  3360. default:
  3361. dev_err(&i2c->dev, "%s:Unknown codec type\n", __func__);
  3362. }
  3363. INIT_DELAYED_WORK(&rt5663->jack_detect_work, rt5663_jack_detect_work);
  3364. INIT_DELAYED_WORK(&rt5663->jd_unplug_work, rt5663_jd_unplug_work);
  3365. if (i2c->irq) {
  3366. ret = request_irq(i2c->irq, rt5663_irq,
  3367. IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING
  3368. | IRQF_ONESHOT, "rt5663", rt5663);
  3369. if (ret) {
  3370. dev_err(&i2c->dev, "%s Failed to reguest IRQ: %d\n",
  3371. __func__, ret);
  3372. goto err_enable;
  3373. }
  3374. }
  3375. ret = devm_snd_soc_register_component(&i2c->dev,
  3376. &soc_component_dev_rt5663,
  3377. rt5663_dai, ARRAY_SIZE(rt5663_dai));
  3378. if (ret)
  3379. goto err_enable;
  3380. return 0;
  3381. /*
  3382. * Error after enabling regulators should goto err_enable
  3383. * to disable regulators.
  3384. */
  3385. err_enable:
  3386. if (i2c->irq)
  3387. free_irq(i2c->irq, rt5663);
  3388. regulator_bulk_disable(ARRAY_SIZE(rt5663->supplies), rt5663->supplies);
  3389. return ret;
  3390. }
  3391. static void rt5663_i2c_remove(struct i2c_client *i2c)
  3392. {
  3393. struct rt5663_priv *rt5663 = i2c_get_clientdata(i2c);
  3394. if (i2c->irq)
  3395. free_irq(i2c->irq, rt5663);
  3396. regulator_bulk_disable(ARRAY_SIZE(rt5663->supplies), rt5663->supplies);
  3397. }
  3398. static void rt5663_i2c_shutdown(struct i2c_client *client)
  3399. {
  3400. struct rt5663_priv *rt5663 = i2c_get_clientdata(client);
  3401. regmap_write(rt5663->regmap, RT5663_RESET, 0);
  3402. }
  3403. static struct i2c_driver rt5663_i2c_driver = {
  3404. .driver = {
  3405. .name = "rt5663",
  3406. .acpi_match_table = ACPI_PTR(rt5663_acpi_match),
  3407. .of_match_table = of_match_ptr(rt5663_of_match),
  3408. },
  3409. .probe_new = rt5663_i2c_probe,
  3410. .remove = rt5663_i2c_remove,
  3411. .shutdown = rt5663_i2c_shutdown,
  3412. .id_table = rt5663_i2c_id,
  3413. };
  3414. module_i2c_driver(rt5663_i2c_driver);
  3415. MODULE_DESCRIPTION("ASoC RT5663 driver");
  3416. MODULE_AUTHOR("Jack Yu <[email protected]>");
  3417. MODULE_LICENSE("GPL v2");