aqt1000.c 95 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370
  1. /* Copyright (c) 2018, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/module.h>
  14. #include <linux/init.h>
  15. #include <linux/firmware.h>
  16. #include <linux/slab.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/device.h>
  19. #include <linux/printk.h>
  20. #include <linux/ratelimit.h>
  21. #include <linux/debugfs.h>
  22. #include <linux/wait.h>
  23. #include <linux/bitops.h>
  24. #include <linux/clk.h>
  25. #include <linux/delay.h>
  26. #include <linux/pm_runtime.h>
  27. #include <linux/gpio.h>
  28. #include <linux/regmap.h>
  29. #include <linux/regulator/consumer.h>
  30. #include <sound/pcm.h>
  31. #include <sound/pcm_params.h>
  32. #include <sound/soc.h>
  33. #include <sound/soc-dapm.h>
  34. #include <sound/tlv.h>
  35. #include <sound/info.h>
  36. #include "aqt1000-registers.h"
  37. #include "aqt1000.h"
  38. #include "aqt1000-api.h"
  39. #include "aqt1000-routing.h"
  40. #include "../wcdcal-hwdep.h"
  41. #include "aqt1000-internal.h"
  42. #define AQT1000_TX_UNMUTE_DELAY_MS 40
  43. #define TX_HPF_CUT_OFF_FREQ_MASK 0x60
  44. #define CF_MIN_3DB_4HZ 0x0
  45. #define CF_MIN_3DB_75HZ 0x1
  46. #define CF_MIN_3DB_150HZ 0x2
  47. #define AQT_VERSION_ENTRY_SIZE 17
  48. #define AQT_VOUT_CTL_TO_MICB(x) (1000 + x *50)
  49. static struct interp_sample_rate sr_val_tbl[] = {
  50. {8000, 0x0}, {16000, 0x1}, {32000, 0x3}, {48000, 0x4}, {96000, 0x5},
  51. {192000, 0x6}, {384000, 0x7}, {44100, 0x9}, {88200, 0xA},
  52. {176400, 0xB}, {352800, 0xC},
  53. };
  54. static int tx_unmute_delay = AQT1000_TX_UNMUTE_DELAY_MS;
  55. module_param(tx_unmute_delay, int, 0664);
  56. MODULE_PARM_DESC(tx_unmute_delay, "delay to unmute the tx path");
  57. static void aqt_codec_set_tx_hold(struct snd_soc_codec *, u16, bool);
  58. /* Cutoff frequency for high pass filter */
  59. static const char * const cf_text[] = {
  60. "CF_NEG_3DB_4HZ", "CF_NEG_3DB_75HZ", "CF_NEG_3DB_150HZ"
  61. };
  62. static const char * const rx_cf_text[] = {
  63. "CF_NEG_3DB_4HZ", "CF_NEG_3DB_75HZ", "CF_NEG_3DB_150HZ",
  64. "CF_NEG_3DB_0P48HZ"
  65. };
  66. struct aqt1000_anc_header {
  67. u32 reserved[3];
  68. u32 num_anc_slots;
  69. };
  70. static SOC_ENUM_SINGLE_DECL(cf_dec0_enum, AQT1000_CDC_TX0_TX_PATH_CFG0, 5,
  71. cf_text);
  72. static SOC_ENUM_SINGLE_DECL(cf_dec1_enum, AQT1000_CDC_TX1_TX_PATH_CFG0, 5,
  73. cf_text);
  74. static SOC_ENUM_SINGLE_DECL(cf_dec2_enum, AQT1000_CDC_TX2_TX_PATH_CFG0, 5,
  75. cf_text);
  76. static SOC_ENUM_SINGLE_DECL(cf_int1_1_enum, AQT1000_CDC_RX1_RX_PATH_CFG2, 0,
  77. rx_cf_text);
  78. static SOC_ENUM_SINGLE_DECL(cf_int1_2_enum, AQT1000_CDC_RX1_RX_PATH_MIX_CFG, 2,
  79. rx_cf_text);
  80. static SOC_ENUM_SINGLE_DECL(cf_int2_1_enum, AQT1000_CDC_RX2_RX_PATH_CFG2, 0,
  81. rx_cf_text);
  82. static SOC_ENUM_SINGLE_DECL(cf_int2_2_enum, AQT1000_CDC_RX2_RX_PATH_MIX_CFG, 2,
  83. rx_cf_text);
  84. static const DECLARE_TLV_DB_SCALE(hph_gain, -3000, 150, 0);
  85. static const DECLARE_TLV_DB_SCALE(analog_gain, 0, 150, 0);
  86. static const DECLARE_TLV_DB_SCALE(digital_gain, 0, 1, 0);
  87. static int aqt_get_anc_slot(struct snd_kcontrol *kcontrol,
  88. struct snd_ctl_elem_value *ucontrol)
  89. {
  90. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  91. struct aqt1000 *aqt = snd_soc_codec_get_drvdata(codec);
  92. ucontrol->value.integer.value[0] = aqt->anc_slot;
  93. return 0;
  94. }
  95. static int aqt_put_anc_slot(struct snd_kcontrol *kcontrol,
  96. struct snd_ctl_elem_value *ucontrol)
  97. {
  98. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  99. struct aqt1000 *aqt = snd_soc_codec_get_drvdata(codec);
  100. aqt->anc_slot = ucontrol->value.integer.value[0];
  101. return 0;
  102. }
  103. static int aqt_get_anc_func(struct snd_kcontrol *kcontrol,
  104. struct snd_ctl_elem_value *ucontrol)
  105. {
  106. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  107. struct aqt1000 *aqt = snd_soc_codec_get_drvdata(codec);
  108. ucontrol->value.integer.value[0] = (aqt->anc_func == true ? 1 : 0);
  109. return 0;
  110. }
  111. static int aqt_put_anc_func(struct snd_kcontrol *kcontrol,
  112. struct snd_ctl_elem_value *ucontrol)
  113. {
  114. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  115. struct aqt1000 *aqt = snd_soc_codec_get_drvdata(codec);
  116. struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
  117. mutex_lock(&aqt->codec_mutex);
  118. aqt->anc_func = (!ucontrol->value.integer.value[0] ? false : true);
  119. dev_dbg(codec->dev, "%s: anc_func %x", __func__, aqt->anc_func);
  120. if (aqt->anc_func == true) {
  121. snd_soc_dapm_enable_pin(dapm, "ANC HPHL PA");
  122. snd_soc_dapm_enable_pin(dapm, "ANC HPHR PA");
  123. snd_soc_dapm_enable_pin(dapm, "ANC HPHL");
  124. snd_soc_dapm_enable_pin(dapm, "ANC HPHR");
  125. snd_soc_dapm_disable_pin(dapm, "HPHL PA");
  126. snd_soc_dapm_disable_pin(dapm, "HPHR PA");
  127. snd_soc_dapm_disable_pin(dapm, "HPHL");
  128. snd_soc_dapm_disable_pin(dapm, "HPHR");
  129. } else {
  130. snd_soc_dapm_disable_pin(dapm, "ANC HPHL PA");
  131. snd_soc_dapm_disable_pin(dapm, "ANC HPHR PA");
  132. snd_soc_dapm_disable_pin(dapm, "ANC HPHL");
  133. snd_soc_dapm_disable_pin(dapm, "ANC HPHR");
  134. snd_soc_dapm_enable_pin(dapm, "HPHL");
  135. snd_soc_dapm_enable_pin(dapm, "HPHR");
  136. snd_soc_dapm_enable_pin(dapm, "HPHL PA");
  137. snd_soc_dapm_enable_pin(dapm, "HPHR PA");
  138. }
  139. mutex_unlock(&aqt->codec_mutex);
  140. snd_soc_dapm_sync(dapm);
  141. return 0;
  142. }
  143. static const char *const aqt_anc_func_text[] = {"OFF", "ON"};
  144. static const struct soc_enum aqt_anc_func_enum =
  145. SOC_ENUM_SINGLE_EXT(2, aqt_anc_func_text);
  146. static int aqt_rx_hph_mode_get(struct snd_kcontrol *kcontrol,
  147. struct snd_ctl_elem_value *ucontrol)
  148. {
  149. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  150. struct aqt1000 *aqt = snd_soc_codec_get_drvdata(codec);
  151. ucontrol->value.integer.value[0] = aqt->hph_mode;
  152. return 0;
  153. }
  154. static int aqt_rx_hph_mode_put(struct snd_kcontrol *kcontrol,
  155. struct snd_ctl_elem_value *ucontrol)
  156. {
  157. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  158. struct aqt1000 *aqt = snd_soc_codec_get_drvdata(codec);
  159. u32 mode_val;
  160. mode_val = ucontrol->value.enumerated.item[0];
  161. dev_dbg(codec->dev, "%s: mode: %d\n", __func__, mode_val);
  162. if (mode_val == 0) {
  163. dev_warn(codec->dev, "%s:Invalid HPH Mode, default to Cls-H LOHiFi\n",
  164. __func__);
  165. mode_val = CLS_H_LOHIFI;
  166. }
  167. aqt->hph_mode = mode_val;
  168. return 0;
  169. }
  170. static const char * const rx_hph_mode_mux_text[] = {
  171. "CLS_H_INVALID", "CLS_H_HIFI", "CLS_H_LP", "CLS_AB", "CLS_H_LOHIFI",
  172. "CLS_H_ULP", "CLS_AB_HIFI",
  173. };
  174. static const struct soc_enum rx_hph_mode_mux_enum =
  175. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(rx_hph_mode_mux_text),
  176. rx_hph_mode_mux_text);
  177. static int aqt_iir_enable_audio_mixer_get(struct snd_kcontrol *kcontrol,
  178. struct snd_ctl_elem_value *ucontrol)
  179. {
  180. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  181. int band_idx = ((struct soc_multi_mixer_control *)
  182. kcontrol->private_value)->shift;
  183. ucontrol->value.integer.value[0] = (snd_soc_read(codec,
  184. AQT1000_CDC_SIDETONE_IIR0_IIR_CTL) &
  185. (1 << band_idx)) != 0;
  186. dev_dbg(codec->dev, "%s: IIR0 band #%d enable %d\n", __func__,
  187. band_idx, (uint32_t)ucontrol->value.integer.value[0]);
  188. return 0;
  189. }
  190. static int aqt_iir_enable_audio_mixer_put(struct snd_kcontrol *kcontrol,
  191. struct snd_ctl_elem_value *ucontrol)
  192. {
  193. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  194. int band_idx = ((struct soc_multi_mixer_control *)
  195. kcontrol->private_value)->shift;
  196. bool iir_band_en_status;
  197. int value = ucontrol->value.integer.value[0];
  198. /* Mask first 5 bits, 6-8 are reserved */
  199. snd_soc_update_bits(codec, AQT1000_CDC_SIDETONE_IIR0_IIR_CTL,
  200. (1 << band_idx), (value << band_idx));
  201. iir_band_en_status = ((snd_soc_read(codec,
  202. AQT1000_CDC_SIDETONE_IIR0_IIR_CTL) &
  203. (1 << band_idx)) != 0);
  204. dev_dbg(codec->dev, "%s: IIR0 band #%d enable %d\n", __func__,
  205. band_idx, iir_band_en_status);
  206. return 0;
  207. }
  208. static uint32_t aqt_get_iir_band_coeff(struct snd_soc_codec *codec,
  209. int band_idx, int coeff_idx)
  210. {
  211. uint32_t value = 0;
  212. /* Address does not automatically update if reading */
  213. snd_soc_write(codec,
  214. AQT1000_CDC_SIDETONE_IIR0_IIR_COEF_B1_CTL,
  215. ((band_idx * BAND_MAX + coeff_idx)
  216. * sizeof(uint32_t)) & 0x7F);
  217. value |= snd_soc_read(codec, AQT1000_CDC_SIDETONE_IIR0_IIR_COEF_B2_CTL);
  218. snd_soc_write(codec, AQT1000_CDC_SIDETONE_IIR0_IIR_COEF_B1_CTL,
  219. ((band_idx * BAND_MAX + coeff_idx)
  220. * sizeof(uint32_t) + 1) & 0x7F);
  221. value |= (snd_soc_read(codec,
  222. AQT1000_CDC_SIDETONE_IIR0_IIR_COEF_B2_CTL) << 8);
  223. snd_soc_write(codec,
  224. AQT1000_CDC_SIDETONE_IIR0_IIR_COEF_B1_CTL,
  225. ((band_idx * BAND_MAX + coeff_idx)
  226. * sizeof(uint32_t) + 2) & 0x7F);
  227. value |= (snd_soc_read(codec,
  228. AQT1000_CDC_SIDETONE_IIR0_IIR_COEF_B2_CTL) << 16);
  229. snd_soc_write(codec,
  230. AQT1000_CDC_SIDETONE_IIR0_IIR_COEF_B1_CTL,
  231. ((band_idx * BAND_MAX + coeff_idx)
  232. * sizeof(uint32_t) + 3) & 0x7F);
  233. /* Mask bits top 2 bits since they are reserved */
  234. value |= ((snd_soc_read(codec,
  235. AQT1000_CDC_SIDETONE_IIR0_IIR_COEF_B2_CTL)
  236. & 0x3F) << 24);
  237. return value;
  238. }
  239. static int aqt_iir_band_audio_mixer_get(struct snd_kcontrol *kcontrol,
  240. struct snd_ctl_elem_value *ucontrol)
  241. {
  242. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  243. int band_idx = ((struct soc_multi_mixer_control *)
  244. kcontrol->private_value)->shift;
  245. ucontrol->value.integer.value[0] =
  246. aqt_get_iir_band_coeff(codec, band_idx, 0);
  247. ucontrol->value.integer.value[1] =
  248. aqt_get_iir_band_coeff(codec, band_idx, 1);
  249. ucontrol->value.integer.value[2] =
  250. aqt_get_iir_band_coeff(codec, band_idx, 2);
  251. ucontrol->value.integer.value[3] =
  252. aqt_get_iir_band_coeff(codec, band_idx, 3);
  253. ucontrol->value.integer.value[4] =
  254. aqt_get_iir_band_coeff(codec, band_idx, 4);
  255. dev_dbg(codec->dev, "%s: IIR band #%d b0 = 0x%x\n"
  256. "%s: IIR band #%d b1 = 0x%x\n"
  257. "%s: IIR band #%d b2 = 0x%x\n"
  258. "%s: IIR band #%d a1 = 0x%x\n"
  259. "%s: IIR band #%d a2 = 0x%x\n",
  260. __func__, band_idx,
  261. (uint32_t)ucontrol->value.integer.value[0],
  262. __func__, band_idx,
  263. (uint32_t)ucontrol->value.integer.value[1],
  264. __func__, band_idx,
  265. (uint32_t)ucontrol->value.integer.value[2],
  266. __func__, band_idx,
  267. (uint32_t)ucontrol->value.integer.value[3],
  268. __func__, band_idx,
  269. (uint32_t)ucontrol->value.integer.value[4]);
  270. return 0;
  271. }
  272. static void aqt_set_iir_band_coeff(struct snd_soc_codec *codec,
  273. int band_idx, uint32_t value)
  274. {
  275. snd_soc_write(codec,
  276. (AQT1000_CDC_SIDETONE_IIR0_IIR_COEF_B2_CTL),
  277. (value & 0xFF));
  278. snd_soc_write(codec,
  279. (AQT1000_CDC_SIDETONE_IIR0_IIR_COEF_B2_CTL),
  280. (value >> 8) & 0xFF);
  281. snd_soc_write(codec,
  282. (AQT1000_CDC_SIDETONE_IIR0_IIR_COEF_B2_CTL),
  283. (value >> 16) & 0xFF);
  284. /* Mask top 2 bits, 7-8 are reserved */
  285. snd_soc_write(codec,
  286. (AQT1000_CDC_SIDETONE_IIR0_IIR_COEF_B2_CTL),
  287. (value >> 24) & 0x3F);
  288. }
  289. static int aqt_iir_band_audio_mixer_put(struct snd_kcontrol *kcontrol,
  290. struct snd_ctl_elem_value *ucontrol)
  291. {
  292. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  293. int band_idx = ((struct soc_multi_mixer_control *)
  294. kcontrol->private_value)->shift;
  295. int coeff_idx;
  296. /*
  297. * Mask top bit it is reserved
  298. * Updates addr automatically for each B2 write
  299. */
  300. snd_soc_write(codec,
  301. (AQT1000_CDC_SIDETONE_IIR0_IIR_COEF_B1_CTL),
  302. (band_idx * BAND_MAX * sizeof(uint32_t)) & 0x7F);
  303. for (coeff_idx = 0; coeff_idx < AQT1000_CDC_SIDETONE_IIR_COEFF_MAX;
  304. coeff_idx++) {
  305. aqt_set_iir_band_coeff(codec, band_idx,
  306. ucontrol->value.integer.value[coeff_idx]);
  307. }
  308. dev_dbg(codec->dev, "%s: IIR band #%d b0 = 0x%x\n"
  309. "%s: IIR band #%d b1 = 0x%x\n"
  310. "%s: IIR band #%d b2 = 0x%x\n"
  311. "%s: IIR band #%d a1 = 0x%x\n"
  312. "%s: IIR band #%d a2 = 0x%x\n",
  313. __func__, band_idx,
  314. aqt_get_iir_band_coeff(codec, band_idx, 0),
  315. __func__, band_idx,
  316. aqt_get_iir_band_coeff(codec, band_idx, 1),
  317. __func__, band_idx,
  318. aqt_get_iir_band_coeff(codec, band_idx, 2),
  319. __func__, band_idx,
  320. aqt_get_iir_band_coeff(codec, band_idx, 3),
  321. __func__, band_idx,
  322. aqt_get_iir_band_coeff(codec, band_idx, 4));
  323. return 0;
  324. }
  325. static int aqt_compander_get(struct snd_kcontrol *kcontrol,
  326. struct snd_ctl_elem_value *ucontrol)
  327. {
  328. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  329. int comp = ((struct soc_multi_mixer_control *)
  330. kcontrol->private_value)->shift;
  331. struct aqt1000 *aqt = snd_soc_codec_get_drvdata(codec);
  332. ucontrol->value.integer.value[0] = aqt->comp_enabled[comp];
  333. return 0;
  334. }
  335. static int aqt_compander_put(struct snd_kcontrol *kcontrol,
  336. struct snd_ctl_elem_value *ucontrol)
  337. {
  338. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  339. struct aqt1000 *aqt = snd_soc_codec_get_drvdata(codec);
  340. int comp = ((struct soc_multi_mixer_control *)
  341. kcontrol->private_value)->shift;
  342. int value = ucontrol->value.integer.value[0];
  343. dev_dbg(codec->dev, "%s: Compander %d enable current %d, new %d\n",
  344. __func__, comp + 1, aqt->comp_enabled[comp], value);
  345. aqt->comp_enabled[comp] = value;
  346. /* Any specific register configuration for compander */
  347. switch (comp) {
  348. case COMPANDER_1:
  349. /* Set Gain Source Select based on compander enable/disable */
  350. snd_soc_update_bits(codec, AQT1000_HPH_L_EN, 0x20,
  351. (value ? 0x00:0x20));
  352. break;
  353. case COMPANDER_2:
  354. snd_soc_update_bits(codec, AQT1000_HPH_R_EN, 0x20,
  355. (value ? 0x00:0x20));
  356. break;
  357. default:
  358. /*
  359. * if compander is not enabled for any interpolator,
  360. * it does not cause any audio failure, so do not
  361. * return error in this case, but just print a log
  362. */
  363. dev_warn(codec->dev, "%s: unknown compander: %d\n",
  364. __func__, comp);
  365. };
  366. return 0;
  367. }
  368. static int aqt_hph_asrc_mode_put(struct snd_kcontrol *kcontrol,
  369. struct snd_ctl_elem_value *ucontrol)
  370. {
  371. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  372. struct aqt1000 *aqt = snd_soc_codec_get_drvdata(codec);
  373. int index = -EINVAL;
  374. if (!strcmp(kcontrol->id.name, "AQT ASRC0 Output Mode"))
  375. index = ASRC0;
  376. if (!strcmp(kcontrol->id.name, "AQT ASRC1 Output Mode"))
  377. index = ASRC1;
  378. if (aqt && (index >= 0) && (index < ASRC_MAX))
  379. aqt->asrc_output_mode[index] =
  380. ucontrol->value.integer.value[0];
  381. return 0;
  382. }
  383. static int aqt_hph_asrc_mode_get(struct snd_kcontrol *kcontrol,
  384. struct snd_ctl_elem_value *ucontrol)
  385. {
  386. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  387. struct aqt1000 *aqt = snd_soc_codec_get_drvdata(codec);
  388. int val = 0;
  389. int index = -EINVAL;
  390. if (!strcmp(kcontrol->id.name, "AQT ASRC0 Output Mode"))
  391. index = ASRC0;
  392. if (!strcmp(kcontrol->id.name, "AQT ASRC1 Output Mode"))
  393. index = ASRC1;
  394. if (aqt && (index >= 0) && (index < ASRC_MAX))
  395. val = aqt->asrc_output_mode[index];
  396. ucontrol->value.integer.value[0] = val;
  397. return 0;
  398. }
  399. static const char * const asrc_mode_text[] = {
  400. "INT", "FRAC"
  401. };
  402. static SOC_ENUM_SINGLE_EXT_DECL(asrc_mode_enum, asrc_mode_text);
  403. static int aqt_hph_idle_detect_get(struct snd_kcontrol *kcontrol,
  404. struct snd_ctl_elem_value *ucontrol)
  405. {
  406. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  407. struct aqt1000 *aqt = snd_soc_codec_get_drvdata(codec);
  408. int val = 0;
  409. if (aqt)
  410. val = aqt->idle_det_cfg.hph_idle_detect_en;
  411. ucontrol->value.integer.value[0] = val;
  412. return 0;
  413. }
  414. static int aqt_hph_idle_detect_put(struct snd_kcontrol *kcontrol,
  415. struct snd_ctl_elem_value *ucontrol)
  416. {
  417. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  418. struct aqt1000 *aqt = snd_soc_codec_get_drvdata(codec);
  419. if (aqt)
  420. aqt->idle_det_cfg.hph_idle_detect_en =
  421. ucontrol->value.integer.value[0];
  422. return 0;
  423. }
  424. static const char * const hph_idle_detect_text[] = {
  425. "OFF", "ON"
  426. };
  427. static SOC_ENUM_SINGLE_EXT_DECL(hph_idle_detect_enum, hph_idle_detect_text);
  428. static int aqt_amic_pwr_lvl_get(struct snd_kcontrol *kcontrol,
  429. struct snd_ctl_elem_value *ucontrol)
  430. {
  431. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  432. u16 amic_reg = 0;
  433. if (!strcmp(kcontrol->id.name, "AQT AMIC_1_2 PWR MODE"))
  434. amic_reg = AQT1000_ANA_AMIC1;
  435. if (!strcmp(kcontrol->id.name, "AQT AMIC_3 PWR MODE"))
  436. amic_reg = AQT1000_ANA_AMIC3;
  437. if (amic_reg)
  438. ucontrol->value.integer.value[0] =
  439. (snd_soc_read(codec, amic_reg) &
  440. AQT1000_AMIC_PWR_LVL_MASK) >>
  441. AQT1000_AMIC_PWR_LVL_SHIFT;
  442. return 0;
  443. }
  444. static int aqt_amic_pwr_lvl_put(struct snd_kcontrol *kcontrol,
  445. struct snd_ctl_elem_value *ucontrol)
  446. {
  447. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  448. u32 mode_val;
  449. u16 amic_reg = 0;
  450. mode_val = ucontrol->value.enumerated.item[0];
  451. dev_dbg(codec->dev, "%s: mode: %d\n", __func__, mode_val);
  452. if (!strcmp(kcontrol->id.name, "AQT AMIC_1_2 PWR MODE"))
  453. amic_reg = AQT1000_ANA_AMIC1;
  454. if (!strcmp(kcontrol->id.name, "AQT AMIC_3 PWR MODE"))
  455. amic_reg = AQT1000_ANA_AMIC3;
  456. if (amic_reg)
  457. snd_soc_update_bits(codec, amic_reg, AQT1000_AMIC_PWR_LVL_MASK,
  458. mode_val << AQT1000_AMIC_PWR_LVL_SHIFT);
  459. return 0;
  460. }
  461. static const char * const amic_pwr_lvl_text[] = {
  462. "LOW_PWR", "DEFAULT", "HIGH_PERF", "HYBRID"
  463. };
  464. static SOC_ENUM_SINGLE_EXT_DECL(amic_pwr_lvl_enum, amic_pwr_lvl_text);
  465. static const struct snd_kcontrol_new aqt_snd_controls[] = {
  466. SOC_SINGLE_TLV("AQT HPHL Volume", AQT1000_HPH_L_EN, 0, 24, 1, hph_gain),
  467. SOC_SINGLE_TLV("AQT HPHR Volume", AQT1000_HPH_R_EN, 0, 24, 1, hph_gain),
  468. SOC_SINGLE_TLV("AQT ADC1 Volume", AQT1000_ANA_AMIC1, 0, 20, 0,
  469. analog_gain),
  470. SOC_SINGLE_TLV("AQT ADC2 Volume", AQT1000_ANA_AMIC2, 0, 20, 0,
  471. analog_gain),
  472. SOC_SINGLE_TLV("AQT ADC3 Volume", AQT1000_ANA_AMIC3, 0, 20, 0,
  473. analog_gain),
  474. SOC_SINGLE_SX_TLV("AQT RX1 Digital Volume", AQT1000_CDC_RX1_RX_VOL_CTL,
  475. 0, -84, 40, digital_gain),
  476. SOC_SINGLE_SX_TLV("AQT RX2 Digital Volume", AQT1000_CDC_RX2_RX_VOL_CTL,
  477. 0, -84, 40, digital_gain),
  478. SOC_SINGLE_SX_TLV("AQT DEC0 Volume", AQT1000_CDC_TX0_TX_VOL_CTL, 0,
  479. -84, 40, digital_gain),
  480. SOC_SINGLE_SX_TLV("AQT DEC1 Volume", AQT1000_CDC_TX1_TX_VOL_CTL, 0,
  481. -84, 40, digital_gain),
  482. SOC_SINGLE_SX_TLV("AQT DEC2 Volume", AQT1000_CDC_TX2_TX_VOL_CTL, 0,
  483. -84, 40, digital_gain),
  484. SOC_SINGLE_SX_TLV("AQT IIR0 INP0 Volume",
  485. AQT1000_CDC_SIDETONE_IIR0_IIR_GAIN_B1_CTL, 0, -84, 40,
  486. digital_gain),
  487. SOC_SINGLE_SX_TLV("AQT IIR0 INP1 Volume",
  488. AQT1000_CDC_SIDETONE_IIR0_IIR_GAIN_B2_CTL, 0, -84, 40,
  489. digital_gain),
  490. SOC_SINGLE_SX_TLV("AQT IIR0 INP2 Volume",
  491. AQT1000_CDC_SIDETONE_IIR0_IIR_GAIN_B3_CTL, 0, -84, 40,
  492. digital_gain),
  493. SOC_SINGLE_SX_TLV("AQT IIR0 INP3 Volume",
  494. AQT1000_CDC_SIDETONE_IIR0_IIR_GAIN_B4_CTL, 0, -84, 40,
  495. digital_gain),
  496. SOC_SINGLE_EXT("AQT ANC Slot", SND_SOC_NOPM, 0, 100, 0,
  497. aqt_get_anc_slot, aqt_put_anc_slot),
  498. SOC_ENUM_EXT("AQT ANC Function", aqt_anc_func_enum, aqt_get_anc_func,
  499. aqt_put_anc_func),
  500. SOC_ENUM("AQT TX0 HPF cut off", cf_dec0_enum),
  501. SOC_ENUM("AQT TX1 HPF cut off", cf_dec1_enum),
  502. SOC_ENUM("AQT TX2 HPF cut off", cf_dec2_enum),
  503. SOC_ENUM("AQT RX INT1_1 HPF cut off", cf_int1_1_enum),
  504. SOC_ENUM("AQT RX INT1_2 HPF cut off", cf_int1_2_enum),
  505. SOC_ENUM("AQT RX INT2_1 HPF cut off", cf_int2_1_enum),
  506. SOC_ENUM("AQT RX INT2_2 HPF cut off", cf_int2_2_enum),
  507. SOC_ENUM_EXT("AQT RX HPH Mode", rx_hph_mode_mux_enum,
  508. aqt_rx_hph_mode_get, aqt_rx_hph_mode_put),
  509. SOC_SINGLE_EXT("AQT IIR0 Enable Band1", IIR0, BAND1, 1, 0,
  510. aqt_iir_enable_audio_mixer_get,
  511. aqt_iir_enable_audio_mixer_put),
  512. SOC_SINGLE_EXT("AQT IIR0 Enable Band2", IIR0, BAND2, 1, 0,
  513. aqt_iir_enable_audio_mixer_get,
  514. aqt_iir_enable_audio_mixer_put),
  515. SOC_SINGLE_EXT("AQT IIR0 Enable Band3", IIR0, BAND3, 1, 0,
  516. aqt_iir_enable_audio_mixer_get,
  517. aqt_iir_enable_audio_mixer_put),
  518. SOC_SINGLE_EXT("AQT IIR0 Enable Band4", IIR0, BAND4, 1, 0,
  519. aqt_iir_enable_audio_mixer_get,
  520. aqt_iir_enable_audio_mixer_put),
  521. SOC_SINGLE_EXT("AQT IIR0 Enable Band5", IIR0, BAND5, 1, 0,
  522. aqt_iir_enable_audio_mixer_get,
  523. aqt_iir_enable_audio_mixer_put),
  524. SOC_SINGLE_MULTI_EXT("AQT IIR0 Band1", IIR0, BAND1, 255, 0, 5,
  525. aqt_iir_band_audio_mixer_get, aqt_iir_band_audio_mixer_put),
  526. SOC_SINGLE_MULTI_EXT("AQT IIR0 Band2", IIR0, BAND2, 255, 0, 5,
  527. aqt_iir_band_audio_mixer_get, aqt_iir_band_audio_mixer_put),
  528. SOC_SINGLE_MULTI_EXT("AQT IIR0 Band3", IIR0, BAND3, 255, 0, 5,
  529. aqt_iir_band_audio_mixer_get, aqt_iir_band_audio_mixer_put),
  530. SOC_SINGLE_MULTI_EXT("AQT IIR0 Band4", IIR0, BAND4, 255, 0, 5,
  531. aqt_iir_band_audio_mixer_get, aqt_iir_band_audio_mixer_put),
  532. SOC_SINGLE_MULTI_EXT("AQT IIR0 Band5", IIR0, BAND5, 255, 0, 5,
  533. aqt_iir_band_audio_mixer_get, aqt_iir_band_audio_mixer_put),
  534. SOC_SINGLE_EXT("AQT COMP1 Switch", SND_SOC_NOPM, COMPANDER_1, 1, 0,
  535. aqt_compander_get, aqt_compander_put),
  536. SOC_SINGLE_EXT("AQT COMP2 Switch", SND_SOC_NOPM, COMPANDER_2, 1, 0,
  537. aqt_compander_get, aqt_compander_put),
  538. SOC_ENUM_EXT("AQT ASRC0 Output Mode", asrc_mode_enum,
  539. aqt_hph_asrc_mode_get, aqt_hph_asrc_mode_put),
  540. SOC_ENUM_EXT("AQT ASRC1 Output Mode", asrc_mode_enum,
  541. aqt_hph_asrc_mode_get, aqt_hph_asrc_mode_put),
  542. SOC_ENUM_EXT("AQT HPH Idle Detect", hph_idle_detect_enum,
  543. aqt_hph_idle_detect_get, aqt_hph_idle_detect_put),
  544. SOC_ENUM_EXT("AQT AMIC_1_2 PWR MODE", amic_pwr_lvl_enum,
  545. aqt_amic_pwr_lvl_get, aqt_amic_pwr_lvl_put),
  546. SOC_ENUM_EXT("AQT AMIC_3 PWR MODE", amic_pwr_lvl_enum,
  547. aqt_amic_pwr_lvl_get, aqt_amic_pwr_lvl_put),
  548. };
  549. static int aqt_codec_enable_rx_bias(struct snd_soc_dapm_widget *w,
  550. struct snd_kcontrol *kcontrol, int event)
  551. {
  552. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  553. struct aqt1000 *aqt = snd_soc_codec_get_drvdata(codec);
  554. dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event);
  555. switch (event) {
  556. case SND_SOC_DAPM_PRE_PMU:
  557. aqt->rx_bias_count++;
  558. if (aqt->rx_bias_count == 1) {
  559. snd_soc_update_bits(codec, AQT1000_ANA_RX_SUPPLIES,
  560. 0x01, 0x01);
  561. }
  562. break;
  563. case SND_SOC_DAPM_POST_PMD:
  564. aqt->rx_bias_count--;
  565. if (!aqt->rx_bias_count)
  566. snd_soc_update_bits(codec, AQT1000_ANA_RX_SUPPLIES,
  567. 0x01, 0x00);
  568. break;
  569. };
  570. dev_dbg(codec->dev, "%s: Current RX BIAS user count: %d\n", __func__,
  571. aqt->rx_bias_count);
  572. return 0;
  573. }
  574. /*
  575. * aqt_mbhc_micb_adjust_voltage: adjust specific micbias voltage
  576. * @codec: handle to snd_soc_codec *
  577. * @req_volt: micbias voltage to be set
  578. * @micb_num: micbias to be set, e.g. micbias1 or micbias2
  579. *
  580. * return 0 if adjustment is success or error code in case of failure
  581. */
  582. int aqt_mbhc_micb_adjust_voltage(struct snd_soc_codec *codec,
  583. int req_volt, int micb_num)
  584. {
  585. struct aqt1000 *aqt;
  586. int cur_vout_ctl, req_vout_ctl;
  587. int micb_reg, micb_val, micb_en;
  588. int ret = 0;
  589. if (!codec) {
  590. pr_err("%s: Invalid codec pointer\n", __func__);
  591. return -EINVAL;
  592. }
  593. if (micb_num != MIC_BIAS_1)
  594. return -EINVAL;
  595. else
  596. micb_reg = AQT1000_ANA_MICB1;
  597. aqt = snd_soc_codec_get_drvdata(codec);
  598. mutex_lock(&aqt->micb_lock);
  599. /*
  600. * If requested micbias voltage is same as current micbias
  601. * voltage, then just return. Otherwise, adjust voltage as
  602. * per requested value. If micbias is already enabled, then
  603. * to avoid slow micbias ramp-up or down enable pull-up
  604. * momentarily, change the micbias value and then re-enable
  605. * micbias.
  606. */
  607. micb_val = snd_soc_read(codec, micb_reg);
  608. micb_en = (micb_val & 0xC0) >> 6;
  609. cur_vout_ctl = micb_val & 0x3F;
  610. req_vout_ctl = aqt_get_micb_vout_ctl_val(req_volt);
  611. if (req_vout_ctl < 0) {
  612. ret = -EINVAL;
  613. goto exit;
  614. }
  615. if (cur_vout_ctl == req_vout_ctl) {
  616. ret = 0;
  617. goto exit;
  618. }
  619. dev_dbg(codec->dev, "%s: micb_num: %d, cur_mv: %d, req_mv: %d, micb_en: %d\n",
  620. __func__, micb_num, AQT_VOUT_CTL_TO_MICB(cur_vout_ctl),
  621. req_volt, micb_en);
  622. if (micb_en == 0x1)
  623. snd_soc_update_bits(codec, micb_reg, 0xC0, 0x80);
  624. snd_soc_update_bits(codec, micb_reg, 0x3F, req_vout_ctl);
  625. if (micb_en == 0x1) {
  626. snd_soc_update_bits(codec, micb_reg, 0xC0, 0x40);
  627. /*
  628. * Add 2ms delay as per HW requirement after enabling
  629. * micbias
  630. */
  631. usleep_range(2000, 2100);
  632. }
  633. exit:
  634. mutex_unlock(&aqt->micb_lock);
  635. return ret;
  636. }
  637. EXPORT_SYMBOL(aqt_mbhc_micb_adjust_voltage);
  638. /*
  639. * aqt_micbias_control: enable/disable micbias
  640. * @codec: handle to snd_soc_codec *
  641. * @micb_num: micbias to be enabled/disabled, e.g. micbias1 or micbias2
  642. * @req: control requested, enable/disable or pullup enable/disable
  643. * @is_dapm: triggered by dapm or not
  644. *
  645. * return 0 if control is success or error code in case of failure
  646. */
  647. int aqt_micbias_control(struct snd_soc_codec *codec,
  648. int micb_num, int req, bool is_dapm)
  649. {
  650. struct aqt1000 *aqt = snd_soc_codec_get_drvdata(codec);
  651. u16 micb_reg;
  652. int pre_off_event = 0, post_off_event = 0;
  653. int post_on_event = 0, post_dapm_off = 0;
  654. int post_dapm_on = 0;
  655. int ret = 0;
  656. switch (micb_num) {
  657. case MIC_BIAS_1:
  658. micb_reg = AQT1000_ANA_MICB1;
  659. pre_off_event = AQT_EVENT_PRE_MICBIAS_1_OFF;
  660. post_off_event = AQT_EVENT_POST_MICBIAS_1_OFF;
  661. post_on_event = AQT_EVENT_POST_MICBIAS_1_ON;
  662. post_dapm_on = AQT_EVENT_POST_DAPM_MICBIAS_1_ON;
  663. post_dapm_off = AQT_EVENT_POST_DAPM_MICBIAS_1_OFF;
  664. break;
  665. default:
  666. dev_err(codec->dev, "%s: Invalid micbias number: %d\n",
  667. __func__, micb_num);
  668. return -EINVAL;
  669. }
  670. mutex_lock(&aqt->micb_lock);
  671. switch (req) {
  672. case MICB_PULLUP_ENABLE:
  673. aqt->pullup_ref++;
  674. if ((aqt->pullup_ref == 1) &&
  675. (aqt->micb_ref == 0))
  676. snd_soc_update_bits(codec, micb_reg, 0xC0, 0x80);
  677. break;
  678. case MICB_PULLUP_DISABLE:
  679. if (aqt->pullup_ref > 0)
  680. aqt->pullup_ref--;
  681. if ((aqt->pullup_ref == 0) &&
  682. (aqt->micb_ref == 0))
  683. snd_soc_update_bits(codec, micb_reg, 0xC0, 0x00);
  684. break;
  685. case MICB_ENABLE:
  686. aqt->micb_ref++;
  687. if (aqt->micb_ref == 1) {
  688. snd_soc_update_bits(codec, micb_reg, 0xC0, 0x40);
  689. }
  690. break;
  691. case MICB_DISABLE:
  692. if (aqt->micb_ref > 0)
  693. aqt->micb_ref--;
  694. if ((aqt->micb_ref == 0) &&
  695. (aqt->pullup_ref > 0))
  696. snd_soc_update_bits(codec, micb_reg, 0xC0, 0x80);
  697. else if ((aqt->micb_ref == 0) &&
  698. (aqt->pullup_ref == 0)) {
  699. snd_soc_update_bits(codec, micb_reg, 0xC0, 0x00);
  700. }
  701. break;
  702. default:
  703. dev_err(codec->dev, "%s: Invalid micbias request: %d\n",
  704. __func__, req);
  705. ret = -EINVAL;
  706. break;
  707. };
  708. if (!ret)
  709. dev_dbg(codec->dev,
  710. "%s: micb_num:%d, micb_ref: %d, pullup_ref: %d\n",
  711. __func__, micb_num, aqt->micb_ref, aqt->pullup_ref);
  712. mutex_unlock(&aqt->micb_lock);
  713. return ret;
  714. }
  715. EXPORT_SYMBOL(aqt_micbias_control);
  716. static int __aqt_codec_enable_micbias(struct snd_soc_dapm_widget *w,
  717. int event)
  718. {
  719. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  720. int micb_num;
  721. dev_dbg(codec->dev, "%s: wname: %s, event: %d\n",
  722. __func__, w->name, event);
  723. if (strnstr(w->name, "AQT MIC BIAS1", sizeof("AQT MIC BIAS1")))
  724. micb_num = MIC_BIAS_1;
  725. else
  726. return -EINVAL;
  727. switch (event) {
  728. case SND_SOC_DAPM_PRE_PMU:
  729. /*
  730. * MIC BIAS can also be requested by MBHC,
  731. * so use ref count to handle micbias pullup
  732. * and enable requests
  733. */
  734. aqt_micbias_control(codec, micb_num, MICB_ENABLE, true);
  735. break;
  736. case SND_SOC_DAPM_POST_PMU:
  737. /* wait for cnp time */
  738. usleep_range(1000, 1100);
  739. break;
  740. case SND_SOC_DAPM_POST_PMD:
  741. aqt_micbias_control(codec, micb_num, MICB_DISABLE, true);
  742. break;
  743. };
  744. return 0;
  745. }
  746. static int aqt_codec_enable_micbias(struct snd_soc_dapm_widget *w,
  747. struct snd_kcontrol *kcontrol, int event)
  748. {
  749. return __aqt_codec_enable_micbias(w, event);
  750. }
  751. static int aqt_codec_enable_i2s_block(struct snd_soc_codec *codec)
  752. {
  753. struct aqt1000 *aqt = snd_soc_codec_get_drvdata(codec);
  754. mutex_lock(&aqt->i2s_lock);
  755. if (++aqt->i2s_users == 1)
  756. snd_soc_update_bits(codec, AQT1000_I2S_I2S_0_CTL, 0x01, 0x01);
  757. mutex_unlock(&aqt->i2s_lock);
  758. return 0;
  759. }
  760. static int aqt_codec_disable_i2s_block(struct snd_soc_codec *codec)
  761. {
  762. struct aqt1000 *aqt = snd_soc_codec_get_drvdata(codec);
  763. mutex_lock(&aqt->i2s_lock);
  764. if (--aqt->i2s_users == 0)
  765. snd_soc_update_bits(codec, AQT1000_I2S_I2S_0_CTL, 0x01, 0x00);
  766. if (aqt->i2s_users < 0)
  767. dev_warn(codec->dev, "%s: i2s_users count (%d) < 0\n",
  768. __func__, aqt->i2s_users);
  769. mutex_unlock(&aqt->i2s_lock);
  770. return 0;
  771. }
  772. static int aqt_codec_enable_i2s_tx(struct snd_soc_dapm_widget *w,
  773. struct snd_kcontrol *kcontrol,
  774. int event)
  775. {
  776. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  777. switch (event) {
  778. case SND_SOC_DAPM_PRE_PMU:
  779. aqt_codec_enable_i2s_block(codec);
  780. break;
  781. case SND_SOC_DAPM_POST_PMD:
  782. aqt_codec_disable_i2s_block(codec);
  783. break;
  784. }
  785. dev_dbg(codec->dev, "%s: event: %d\n", __func__, event);
  786. return 0;
  787. }
  788. static int aqt_codec_enable_i2s_rx(struct snd_soc_dapm_widget *w,
  789. struct snd_kcontrol *kcontrol,
  790. int event)
  791. {
  792. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  793. switch (event) {
  794. case SND_SOC_DAPM_PRE_PMU:
  795. aqt_codec_enable_i2s_block(codec);
  796. break;
  797. case SND_SOC_DAPM_POST_PMD:
  798. aqt_codec_disable_i2s_block(codec);
  799. break;
  800. }
  801. dev_dbg(codec->dev, "%s: event: %d\n", __func__, event);
  802. return 0;
  803. }
  804. static const char * const tx_mux_text[] = {
  805. "ZERO", "DEC_L", "DEC_R", "DEC_V",
  806. };
  807. AQT_DAPM_ENUM(tx0, AQT1000_CDC_IF_ROUTER_TX_MUX_CFG0, 0, tx_mux_text);
  808. AQT_DAPM_ENUM(tx1, AQT1000_CDC_IF_ROUTER_TX_MUX_CFG0, 2, tx_mux_text);
  809. static const char * const tx_adc_mux_text[] = {
  810. "AMIC", "ANC_FB0", "ANC_FB1",
  811. };
  812. AQT_DAPM_ENUM(tx_adc0, AQT1000_CDC_TX_INP_MUX_ADC_MUX0_CFG1, 0,
  813. tx_adc_mux_text);
  814. AQT_DAPM_ENUM(tx_adc1, AQT1000_CDC_TX_INP_MUX_ADC_MUX1_CFG1, 0,
  815. tx_adc_mux_text);
  816. AQT_DAPM_ENUM(tx_adc2, AQT1000_CDC_TX_INP_MUX_ADC_MUX2_CFG1, 0,
  817. tx_adc_mux_text);
  818. static int aqt_find_amic_input(struct snd_soc_codec *codec, int adc_mux_n)
  819. {
  820. u8 mask;
  821. u16 adc_mux_in_reg = 0, amic_mux_sel_reg = 0;
  822. bool is_amic;
  823. if (adc_mux_n > 2)
  824. return 0;
  825. if (adc_mux_n < 3) {
  826. adc_mux_in_reg = AQT1000_CDC_TX_INP_MUX_ADC_MUX0_CFG1 +
  827. adc_mux_n;
  828. mask = 0x03;
  829. amic_mux_sel_reg = AQT1000_CDC_TX_INP_MUX_ADC_MUX0_CFG0 +
  830. 2 * adc_mux_n;
  831. }
  832. is_amic = (((snd_soc_read(codec, adc_mux_in_reg) & mask)) == 0);
  833. if (!is_amic)
  834. return 0;
  835. return snd_soc_read(codec, amic_mux_sel_reg) & 0x07;
  836. }
  837. static u16 aqt_codec_get_amic_pwlvl_reg(struct snd_soc_codec *codec, int amic)
  838. {
  839. u16 pwr_level_reg = 0;
  840. switch (amic) {
  841. case 1:
  842. case 2:
  843. pwr_level_reg = AQT1000_ANA_AMIC1;
  844. break;
  845. case 3:
  846. pwr_level_reg = AQT1000_ANA_AMIC3;
  847. break;
  848. default:
  849. dev_dbg(codec->dev, "%s: invalid amic: %d\n",
  850. __func__, amic);
  851. break;
  852. }
  853. return pwr_level_reg;
  854. }
  855. static void aqt_tx_hpf_corner_freq_callback(struct work_struct *work)
  856. {
  857. struct delayed_work *hpf_delayed_work;
  858. struct hpf_work *hpf_work;
  859. struct aqt1000 *aqt;
  860. struct snd_soc_codec *codec;
  861. u16 dec_cfg_reg, amic_reg, go_bit_reg;
  862. u8 hpf_cut_off_freq;
  863. int amic_n;
  864. hpf_delayed_work = to_delayed_work(work);
  865. hpf_work = container_of(hpf_delayed_work, struct hpf_work, dwork);
  866. aqt = hpf_work->aqt;
  867. codec = aqt->codec;
  868. hpf_cut_off_freq = hpf_work->hpf_cut_off_freq;
  869. dec_cfg_reg = AQT1000_CDC_TX0_TX_PATH_CFG0 + 16 * hpf_work->decimator;
  870. go_bit_reg = dec_cfg_reg + 7;
  871. dev_dbg(codec->dev, "%s: decimator %u hpf_cut_of_freq 0x%x\n",
  872. __func__, hpf_work->decimator, hpf_cut_off_freq);
  873. amic_n = aqt_find_amic_input(codec, hpf_work->decimator);
  874. if (amic_n) {
  875. amic_reg = AQT1000_ANA_AMIC1 + amic_n - 1;
  876. aqt_codec_set_tx_hold(codec, amic_reg, false);
  877. }
  878. snd_soc_update_bits(codec, dec_cfg_reg, TX_HPF_CUT_OFF_FREQ_MASK,
  879. hpf_cut_off_freq << 5);
  880. snd_soc_update_bits(codec, go_bit_reg, 0x02, 0x02);
  881. /* Minimum 1 clk cycle delay is required as per HW spec */
  882. usleep_range(1000, 1010);
  883. snd_soc_update_bits(codec, go_bit_reg, 0x02, 0x00);
  884. }
  885. static void aqt_tx_mute_update_callback(struct work_struct *work)
  886. {
  887. struct tx_mute_work *tx_mute_dwork;
  888. struct aqt1000 *aqt;
  889. struct delayed_work *delayed_work;
  890. struct snd_soc_codec *codec;
  891. u16 tx_vol_ctl_reg, hpf_gate_reg;
  892. delayed_work = to_delayed_work(work);
  893. tx_mute_dwork = container_of(delayed_work, struct tx_mute_work, dwork);
  894. aqt = tx_mute_dwork->aqt;
  895. codec = aqt->codec;
  896. tx_vol_ctl_reg = AQT1000_CDC_TX0_TX_PATH_CTL +
  897. 16 * tx_mute_dwork->decimator;
  898. hpf_gate_reg = AQT1000_CDC_TX0_TX_PATH_SEC2 +
  899. 16 * tx_mute_dwork->decimator;
  900. snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x10, 0x00);
  901. }
  902. static int aqt_codec_enable_dec(struct snd_soc_dapm_widget *w,
  903. struct snd_kcontrol *kcontrol, int event)
  904. {
  905. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  906. struct aqt1000 *aqt = snd_soc_codec_get_drvdata(codec);
  907. char *widget_name = NULL;
  908. char *dec = NULL;
  909. unsigned int decimator = 0;
  910. u8 amic_n = 0;
  911. u16 tx_vol_ctl_reg, pwr_level_reg = 0, dec_cfg_reg, hpf_gate_reg;
  912. u16 tx_gain_ctl_reg;
  913. int ret = 0;
  914. u8 hpf_cut_off_freq;
  915. dev_dbg(codec->dev, "%s: event: %d\n", __func__, event);
  916. widget_name = kstrndup(w->name, 15, GFP_KERNEL);
  917. if (!widget_name)
  918. return -ENOMEM;
  919. dec = strpbrk(widget_name, "012");
  920. if (!dec) {
  921. dev_err(codec->dev, "%s: decimator index not found\n",
  922. __func__);
  923. ret = -EINVAL;
  924. goto out;
  925. }
  926. ret = kstrtouint(dec, 10, &decimator);
  927. if (ret < 0) {
  928. dev_err(codec->dev, "%s: Invalid decimator = %s\n",
  929. __func__, widget_name);
  930. ret = -EINVAL;
  931. goto out;
  932. }
  933. dev_dbg(codec->dev, "%s(): widget = %s decimator = %u\n", __func__,
  934. w->name, decimator);
  935. tx_vol_ctl_reg = AQT1000_CDC_TX0_TX_PATH_CTL + 16 * decimator;
  936. hpf_gate_reg = AQT1000_CDC_TX0_TX_PATH_SEC2 + 16 * decimator;
  937. dec_cfg_reg = AQT1000_CDC_TX0_TX_PATH_CFG0 + 16 * decimator;
  938. tx_gain_ctl_reg = AQT1000_CDC_TX0_TX_VOL_CTL + 16 * decimator;
  939. amic_n = aqt_find_amic_input(codec, decimator);
  940. switch (event) {
  941. case SND_SOC_DAPM_PRE_PMU:
  942. if (amic_n)
  943. pwr_level_reg = aqt_codec_get_amic_pwlvl_reg(codec,
  944. amic_n);
  945. if (pwr_level_reg) {
  946. switch ((snd_soc_read(codec, pwr_level_reg) &
  947. AQT1000_AMIC_PWR_LVL_MASK) >>
  948. AQT1000_AMIC_PWR_LVL_SHIFT) {
  949. case AQT1000_AMIC_PWR_LEVEL_LP:
  950. snd_soc_update_bits(codec, dec_cfg_reg,
  951. AQT1000_DEC_PWR_LVL_MASK,
  952. AQT1000_DEC_PWR_LVL_LP);
  953. break;
  954. case AQT1000_AMIC_PWR_LEVEL_HP:
  955. snd_soc_update_bits(codec, dec_cfg_reg,
  956. AQT1000_DEC_PWR_LVL_MASK,
  957. AQT1000_DEC_PWR_LVL_HP);
  958. break;
  959. case AQT1000_AMIC_PWR_LEVEL_DEFAULT:
  960. default:
  961. snd_soc_update_bits(codec, dec_cfg_reg,
  962. AQT1000_DEC_PWR_LVL_MASK,
  963. AQT1000_DEC_PWR_LVL_DF);
  964. break;
  965. }
  966. }
  967. /* Enable TX PGA Mute */
  968. snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x10, 0x10);
  969. break;
  970. case SND_SOC_DAPM_POST_PMU:
  971. hpf_cut_off_freq = (snd_soc_read(codec, dec_cfg_reg) &
  972. TX_HPF_CUT_OFF_FREQ_MASK) >> 5;
  973. aqt->tx_hpf_work[decimator].hpf_cut_off_freq =
  974. hpf_cut_off_freq;
  975. if (hpf_cut_off_freq != CF_MIN_3DB_150HZ) {
  976. snd_soc_update_bits(codec, dec_cfg_reg,
  977. TX_HPF_CUT_OFF_FREQ_MASK,
  978. CF_MIN_3DB_150HZ << 5);
  979. snd_soc_update_bits(codec, hpf_gate_reg, 0x02, 0x02);
  980. /*
  981. * Minimum 1 clk cycle delay is required as per
  982. * HW spec.
  983. */
  984. usleep_range(1000, 1010);
  985. snd_soc_update_bits(codec, hpf_gate_reg, 0x02, 0x00);
  986. }
  987. /* schedule work queue to Remove Mute */
  988. schedule_delayed_work(&aqt->tx_mute_dwork[decimator].dwork,
  989. msecs_to_jiffies(tx_unmute_delay));
  990. if (aqt->tx_hpf_work[decimator].hpf_cut_off_freq !=
  991. CF_MIN_3DB_150HZ)
  992. schedule_delayed_work(
  993. &aqt->tx_hpf_work[decimator].dwork,
  994. msecs_to_jiffies(300));
  995. /* apply gain after decimator is enabled */
  996. snd_soc_write(codec, tx_gain_ctl_reg,
  997. snd_soc_read(codec, tx_gain_ctl_reg));
  998. break;
  999. case SND_SOC_DAPM_PRE_PMD:
  1000. hpf_cut_off_freq =
  1001. aqt->tx_hpf_work[decimator].hpf_cut_off_freq;
  1002. snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x10, 0x10);
  1003. if (cancel_delayed_work_sync(
  1004. &aqt->tx_hpf_work[decimator].dwork)) {
  1005. if (hpf_cut_off_freq != CF_MIN_3DB_150HZ) {
  1006. snd_soc_update_bits(codec, dec_cfg_reg,
  1007. TX_HPF_CUT_OFF_FREQ_MASK,
  1008. hpf_cut_off_freq << 5);
  1009. snd_soc_update_bits(codec, hpf_gate_reg,
  1010. 0x02, 0x02);
  1011. /*
  1012. * Minimum 1 clk cycle delay is required as per
  1013. * HW spec.
  1014. */
  1015. usleep_range(1000, 1010);
  1016. snd_soc_update_bits(codec, hpf_gate_reg,
  1017. 0x02, 0x00);
  1018. }
  1019. }
  1020. cancel_delayed_work_sync(
  1021. &aqt->tx_mute_dwork[decimator].dwork);
  1022. break;
  1023. case SND_SOC_DAPM_POST_PMD:
  1024. snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x10, 0x00);
  1025. snd_soc_update_bits(codec, dec_cfg_reg,
  1026. AQT1000_DEC_PWR_LVL_MASK,
  1027. AQT1000_DEC_PWR_LVL_DF);
  1028. break;
  1029. }
  1030. out:
  1031. kfree(widget_name);
  1032. return ret;
  1033. }
  1034. static const char * const tx_amic_text[] = {
  1035. "ZERO", "ADC_L", "ADC_R", "ADC_V",
  1036. };
  1037. AQT_DAPM_ENUM(tx_amic0, AQT1000_CDC_TX_INP_MUX_ADC_MUX0_CFG0, 0, tx_amic_text);
  1038. AQT_DAPM_ENUM(tx_amic1, AQT1000_CDC_TX_INP_MUX_ADC_MUX1_CFG0, 0, tx_amic_text);
  1039. AQT_DAPM_ENUM(tx_amic2, AQT1000_CDC_TX_INP_MUX_ADC_MUX2_CFG0, 0, tx_amic_text);
  1040. AQT_DAPM_ENUM(tx_amic10, AQT1000_CDC_TX_INP_MUX_ADC_MUX10_CFG0, 0,
  1041. tx_amic_text);
  1042. AQT_DAPM_ENUM(tx_amic11, AQT1000_CDC_TX_INP_MUX_ADC_MUX11_CFG0, 0,
  1043. tx_amic_text);
  1044. AQT_DAPM_ENUM(tx_amic12, AQT1000_CDC_TX_INP_MUX_ADC_MUX12_CFG0, 0,
  1045. tx_amic_text);
  1046. AQT_DAPM_ENUM(tx_amic13, AQT1000_CDC_TX_INP_MUX_ADC_MUX13_CFG0, 0,
  1047. tx_amic_text);
  1048. static int aqt_codec_enable_adc(struct snd_soc_dapm_widget *w,
  1049. struct snd_kcontrol *kcontrol, int event)
  1050. {
  1051. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1052. switch (event) {
  1053. case SND_SOC_DAPM_PRE_PMU:
  1054. aqt_codec_set_tx_hold(codec, w->reg, true);
  1055. break;
  1056. default:
  1057. break;
  1058. }
  1059. return 0;
  1060. }
  1061. static const struct snd_kcontrol_new anc_hphl_pa_switch =
  1062. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0);
  1063. static const struct snd_kcontrol_new anc_hphr_pa_switch =
  1064. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0);
  1065. static int aqt_config_compander(struct snd_soc_codec *codec, int interp_n,
  1066. int event)
  1067. {
  1068. struct aqt1000 *aqt = snd_soc_codec_get_drvdata(codec);
  1069. int comp;
  1070. u16 comp_ctl0_reg, rx_path_cfg0_reg;
  1071. comp = interp_n;
  1072. dev_dbg(codec->dev, "%s: event %d compander %d, enabled %d\n",
  1073. __func__, event, comp, aqt->comp_enabled[comp]);
  1074. if (!aqt->comp_enabled[comp])
  1075. return 0;
  1076. comp_ctl0_reg = AQT1000_CDC_COMPANDER1_CTL0 + (comp * 8);
  1077. rx_path_cfg0_reg = AQT1000_CDC_RX1_RX_PATH_CFG0 + (comp * 20);
  1078. if (SND_SOC_DAPM_EVENT_ON(event)) {
  1079. /* Enable Compander Clock */
  1080. snd_soc_update_bits(codec, comp_ctl0_reg, 0x01, 0x01);
  1081. snd_soc_update_bits(codec, comp_ctl0_reg, 0x02, 0x02);
  1082. snd_soc_update_bits(codec, comp_ctl0_reg, 0x02, 0x00);
  1083. snd_soc_update_bits(codec, rx_path_cfg0_reg, 0x02, 0x02);
  1084. }
  1085. if (SND_SOC_DAPM_EVENT_OFF(event)) {
  1086. snd_soc_update_bits(codec, rx_path_cfg0_reg, 0x02, 0x00);
  1087. snd_soc_update_bits(codec, comp_ctl0_reg, 0x04, 0x04);
  1088. snd_soc_update_bits(codec, comp_ctl0_reg, 0x02, 0x02);
  1089. snd_soc_update_bits(codec, comp_ctl0_reg, 0x02, 0x00);
  1090. snd_soc_update_bits(codec, comp_ctl0_reg, 0x01, 0x00);
  1091. snd_soc_update_bits(codec, comp_ctl0_reg, 0x04, 0x00);
  1092. }
  1093. return 0;
  1094. }
  1095. static void aqt_codec_idle_detect_control(struct snd_soc_codec *codec,
  1096. int interp, int event)
  1097. {
  1098. int reg = 0, mask, val;
  1099. struct aqt1000 *aqt = snd_soc_codec_get_drvdata(codec);
  1100. if (!aqt->idle_det_cfg.hph_idle_detect_en)
  1101. return;
  1102. if (interp == INTERP_HPHL) {
  1103. reg = AQT1000_CDC_RX_IDLE_DET_PATH_CTL;
  1104. mask = 0x01;
  1105. val = 0x01;
  1106. }
  1107. if (interp == INTERP_HPHR) {
  1108. reg = AQT1000_CDC_RX_IDLE_DET_PATH_CTL;
  1109. mask = 0x02;
  1110. val = 0x02;
  1111. }
  1112. if (reg && SND_SOC_DAPM_EVENT_ON(event))
  1113. snd_soc_update_bits(codec, reg, mask, val);
  1114. if (reg && SND_SOC_DAPM_EVENT_OFF(event)) {
  1115. snd_soc_update_bits(codec, reg, mask, 0x00);
  1116. aqt->idle_det_cfg.hph_idle_thr = 0;
  1117. snd_soc_write(codec, AQT1000_CDC_RX_IDLE_DET_CFG3, 0x0);
  1118. }
  1119. }
  1120. static void aqt_codec_hphdelay_lutbypass(struct snd_soc_codec *codec,
  1121. u16 interp_idx, int event)
  1122. {
  1123. struct aqt1000 *aqt = snd_soc_codec_get_drvdata(codec);
  1124. u8 hph_dly_mask;
  1125. u16 hph_lut_bypass_reg = 0;
  1126. u16 hph_comp_ctrl7 = 0;
  1127. switch (interp_idx) {
  1128. case INTERP_HPHL:
  1129. hph_dly_mask = 1;
  1130. hph_lut_bypass_reg = AQT1000_CDC_TOP_HPHL_COMP_LUT;
  1131. hph_comp_ctrl7 = AQT1000_CDC_COMPANDER1_CTL7;
  1132. break;
  1133. case INTERP_HPHR:
  1134. hph_dly_mask = 2;
  1135. hph_lut_bypass_reg = AQT1000_CDC_TOP_HPHR_COMP_LUT;
  1136. hph_comp_ctrl7 = AQT1000_CDC_COMPANDER2_CTL7;
  1137. break;
  1138. default:
  1139. break;
  1140. }
  1141. if (hph_lut_bypass_reg && SND_SOC_DAPM_EVENT_ON(event)) {
  1142. snd_soc_update_bits(codec, AQT1000_CDC_CLSH_TEST0,
  1143. hph_dly_mask, 0x0);
  1144. snd_soc_update_bits(codec, hph_lut_bypass_reg, 0x80, 0x80);
  1145. if (aqt->hph_mode == CLS_H_ULP)
  1146. snd_soc_update_bits(codec, hph_comp_ctrl7, 0x20, 0x20);
  1147. }
  1148. if (hph_lut_bypass_reg && SND_SOC_DAPM_EVENT_OFF(event)) {
  1149. snd_soc_update_bits(codec, AQT1000_CDC_CLSH_TEST0,
  1150. hph_dly_mask, hph_dly_mask);
  1151. snd_soc_update_bits(codec, hph_lut_bypass_reg, 0x80, 0x00);
  1152. snd_soc_update_bits(codec, hph_comp_ctrl7, 0x20, 0x0);
  1153. }
  1154. }
  1155. static int aqt_codec_enable_interp_clk(struct snd_soc_codec *codec,
  1156. int event, int interp_idx)
  1157. {
  1158. struct aqt1000 *aqt;
  1159. u16 main_reg, dsm_reg;
  1160. if (!codec) {
  1161. pr_err("%s: codec is NULL\n", __func__);
  1162. return -EINVAL;
  1163. }
  1164. aqt = snd_soc_codec_get_drvdata(codec);
  1165. main_reg = AQT1000_CDC_RX1_RX_PATH_CTL + (interp_idx * 20);
  1166. dsm_reg = AQT1000_CDC_RX1_RX_PATH_DSMDEM_CTL + (interp_idx * 20);
  1167. if (SND_SOC_DAPM_EVENT_ON(event)) {
  1168. if (aqt->main_clk_users[interp_idx] == 0) {
  1169. /* Main path PGA mute enable */
  1170. snd_soc_update_bits(codec, main_reg, 0x10, 0x10);
  1171. /* Clk enable */
  1172. snd_soc_update_bits(codec, dsm_reg, 0x01, 0x01);
  1173. snd_soc_update_bits(codec, main_reg, 0x20, 0x20);
  1174. aqt_codec_idle_detect_control(codec, interp_idx,
  1175. event);
  1176. aqt_codec_hphdelay_lutbypass(codec, interp_idx,
  1177. event);
  1178. aqt_config_compander(codec, interp_idx, event);
  1179. }
  1180. aqt->main_clk_users[interp_idx]++;
  1181. }
  1182. if (SND_SOC_DAPM_EVENT_OFF(event)) {
  1183. aqt->main_clk_users[interp_idx]--;
  1184. if (aqt->main_clk_users[interp_idx] <= 0) {
  1185. aqt->main_clk_users[interp_idx] = 0;
  1186. aqt_config_compander(codec, interp_idx, event);
  1187. aqt_codec_hphdelay_lutbypass(codec, interp_idx,
  1188. event);
  1189. aqt_codec_idle_detect_control(codec, interp_idx,
  1190. event);
  1191. /* Clk Disable */
  1192. snd_soc_update_bits(codec, main_reg, 0x20, 0x00);
  1193. snd_soc_update_bits(codec, dsm_reg, 0x01, 0x00);
  1194. /* Reset enable and disable */
  1195. snd_soc_update_bits(codec, main_reg, 0x40, 0x40);
  1196. snd_soc_update_bits(codec, main_reg, 0x40, 0x00);
  1197. /* Reset rate to 48K*/
  1198. snd_soc_update_bits(codec, main_reg, 0x0F, 0x04);
  1199. }
  1200. }
  1201. dev_dbg(codec->dev, "%s event %d main_clk_users %d\n",
  1202. __func__, event, aqt->main_clk_users[interp_idx]);
  1203. return aqt->main_clk_users[interp_idx];
  1204. }
  1205. static int aqt_anc_out_switch_cb(struct snd_soc_dapm_widget *w,
  1206. struct snd_kcontrol *kcontrol, int event)
  1207. {
  1208. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1209. aqt_codec_enable_interp_clk(codec, event, w->shift);
  1210. return 0;
  1211. }
  1212. static const char * const anc0_fb_mux_text[] = {
  1213. "ZERO", "ANC_IN_HPHL",
  1214. };
  1215. static const char * const anc1_fb_mux_text[] = {
  1216. "ZERO", "ANC_IN_HPHR",
  1217. };
  1218. AQT_DAPM_ENUM(anc0_fb, AQT1000_CDC_RX_INP_MUX_ANC_CFG0, 0, anc0_fb_mux_text);
  1219. AQT_DAPM_ENUM(anc1_fb, AQT1000_CDC_RX_INP_MUX_ANC_CFG0, 3, anc1_fb_mux_text);
  1220. static const char *const rx_int1_1_mux_text[] = {
  1221. "ZERO", "MAIN_DMA_L", "I2S0_L", "I2S0_R", "DEC_L", "DEC_R", "DEC_V",
  1222. "SHADOW_I2S0_L", "MAIN_DMA_R"
  1223. };
  1224. static const char *const rx_int1_2_mux_text[] = {
  1225. "ZERO", "MIX_DMA_L", "I2S0_L", "I2S0_R", "DEC_L", "DEC_R", "DEC_V",
  1226. "IIR0", "MIX_DMA_R"
  1227. };
  1228. static const char *const rx_int2_1_mux_text[] = {
  1229. "ZERO", "MAIN_DMA_R", "I2S0_L", "I2S0_R", "DEC_L", "DEC_R", "DEC_V",
  1230. "SHADOW_I2S0_R", "MAIN_DMA_L"
  1231. };
  1232. static const char *const rx_int2_2_mux_text[] = {
  1233. "ZERO", "MIX_DMA_R", "I2S0_L", "I2S0_R", "DEC_L", "DEC_R", "DEC_V",
  1234. "IIR0", "MIX_DMA_L"
  1235. };
  1236. AQT_DAPM_ENUM(rx_int1_1, AQT1000_CDC_RX_INP_MUX_RX_INT1_CFG0, 0,
  1237. rx_int1_1_mux_text);
  1238. AQT_DAPM_ENUM(rx_int1_2, AQT1000_CDC_RX_INP_MUX_RX_INT1_CFG1, 0,
  1239. rx_int1_2_mux_text);
  1240. AQT_DAPM_ENUM(rx_int2_1, AQT1000_CDC_RX_INP_MUX_RX_INT2_CFG0, 0,
  1241. rx_int2_1_mux_text);
  1242. AQT_DAPM_ENUM(rx_int2_2, AQT1000_CDC_RX_INP_MUX_RX_INT2_CFG1, 0,
  1243. rx_int2_2_mux_text);
  1244. static int aqt_codec_set_idle_detect_thr(struct snd_soc_codec *codec,
  1245. int interp, int path_type)
  1246. {
  1247. int port_id[4] = { 0, 0, 0, 0 };
  1248. int *port_ptr, num_ports;
  1249. int bit_width = 0;
  1250. int mux_reg = 0, mux_reg_val = 0;
  1251. struct aqt1000 *aqt = snd_soc_codec_get_drvdata(codec);
  1252. int idle_thr;
  1253. if ((interp != INTERP_HPHL) && (interp != INTERP_HPHR))
  1254. return 0;
  1255. if (!aqt->idle_det_cfg.hph_idle_detect_en)
  1256. return 0;
  1257. port_ptr = &port_id[0];
  1258. num_ports = 0;
  1259. if (path_type == INTERP_MIX_PATH) {
  1260. if (interp == INTERP_HPHL)
  1261. mux_reg = AQT1000_CDC_RX_INP_MUX_RX_INT1_CFG1;
  1262. else
  1263. mux_reg = AQT1000_CDC_RX_INP_MUX_RX_INT2_CFG1;
  1264. }
  1265. if (path_type == INTERP_MAIN_PATH) {
  1266. if (interp == INTERP_HPHL)
  1267. mux_reg = AQT1000_CDC_RX_INP_MUX_RX_INT1_CFG0;
  1268. else
  1269. mux_reg = AQT1000_CDC_RX_INP_MUX_RX_INT2_CFG0;
  1270. }
  1271. mux_reg_val = snd_soc_read(codec, mux_reg);
  1272. /* Read bit width from I2S reg if mux is set to I2S0_L or I2S0_R */
  1273. if (mux_reg_val == 0x02 || mux_reg_val == 0x03)
  1274. bit_width = ((snd_soc_read(codec, AQT1000_I2S_I2S_0_CTL) &
  1275. 0x40) >> 6);
  1276. switch (bit_width) {
  1277. case 1: /* 16 bit */
  1278. idle_thr = 0xff; /* F16 */
  1279. break;
  1280. case 0: /* 32 bit */
  1281. default:
  1282. idle_thr = 0x03; /* F22 */
  1283. break;
  1284. }
  1285. dev_dbg(codec->dev, "%s: (new) idle_thr: %d, (cur) idle_thr: %d\n",
  1286. __func__, idle_thr, aqt->idle_det_cfg.hph_idle_thr);
  1287. if ((aqt->idle_det_cfg.hph_idle_thr == 0) ||
  1288. (idle_thr < aqt->idle_det_cfg.hph_idle_thr)) {
  1289. snd_soc_write(codec, AQT1000_CDC_RX_IDLE_DET_CFG3, idle_thr);
  1290. aqt->idle_det_cfg.hph_idle_thr = idle_thr;
  1291. }
  1292. return 0;
  1293. }
  1294. static int aqt_codec_enable_main_path(struct snd_soc_dapm_widget *w,
  1295. struct snd_kcontrol *kcontrol,
  1296. int event)
  1297. {
  1298. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1299. u16 gain_reg = 0;
  1300. int val = 0;
  1301. dev_dbg(codec->dev, "%s %d %s\n", __func__, event, w->name);
  1302. if (w->shift >= AQT1000_NUM_INTERPOLATORS) {
  1303. dev_err(codec->dev, "%s: Invalid Interpolator value %d for name %s\n",
  1304. __func__, w->shift, w->name);
  1305. return -EINVAL;
  1306. };
  1307. gain_reg = AQT1000_CDC_RX1_RX_VOL_CTL + (w->shift *
  1308. AQT1000_RX_PATH_CTL_OFFSET);
  1309. switch (event) {
  1310. case SND_SOC_DAPM_PRE_PMU:
  1311. aqt_codec_enable_interp_clk(codec, event, w->shift);
  1312. break;
  1313. case SND_SOC_DAPM_POST_PMU:
  1314. aqt_codec_set_idle_detect_thr(codec, w->shift,
  1315. INTERP_MAIN_PATH);
  1316. /* apply gain after int clk is enabled */
  1317. val = snd_soc_read(codec, gain_reg);
  1318. snd_soc_write(codec, gain_reg, val);
  1319. break;
  1320. case SND_SOC_DAPM_POST_PMD:
  1321. aqt_codec_enable_interp_clk(codec, event, w->shift);
  1322. break;
  1323. };
  1324. return 0;
  1325. }
  1326. static int aqt_codec_enable_mix_path(struct snd_soc_dapm_widget *w,
  1327. struct snd_kcontrol *kcontrol,
  1328. int event)
  1329. {
  1330. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1331. u16 gain_reg = 0;
  1332. u16 mix_reg = 0;
  1333. if (w->shift >= AQT1000_NUM_INTERPOLATORS) {
  1334. dev_err(codec->dev, "%s: Invalid Interpolator value %d for name %s\n",
  1335. __func__, w->shift, w->name);
  1336. return -EINVAL;
  1337. };
  1338. gain_reg = AQT1000_CDC_RX1_RX_VOL_MIX_CTL +
  1339. (w->shift * AQT1000_RX_PATH_CTL_OFFSET);
  1340. mix_reg = AQT1000_CDC_RX1_RX_PATH_MIX_CTL +
  1341. (w->shift * AQT1000_RX_PATH_CTL_OFFSET);
  1342. switch (event) {
  1343. case SND_SOC_DAPM_PRE_PMU:
  1344. aqt_codec_enable_interp_clk(codec, event, w->shift);
  1345. /* Clk enable */
  1346. snd_soc_update_bits(codec, mix_reg, 0x20, 0x20);
  1347. break;
  1348. case SND_SOC_DAPM_POST_PMU:
  1349. aqt_codec_set_idle_detect_thr(codec, w->shift,
  1350. INTERP_MIX_PATH);
  1351. break;
  1352. case SND_SOC_DAPM_POST_PMD:
  1353. /* Clk Disable */
  1354. snd_soc_update_bits(codec, mix_reg, 0x20, 0x00);
  1355. aqt_codec_enable_interp_clk(codec, event, w->shift);
  1356. /* Reset enable and disable */
  1357. snd_soc_update_bits(codec, mix_reg, 0x40, 0x40);
  1358. snd_soc_update_bits(codec, mix_reg, 0x40, 0x00);
  1359. break;
  1360. };
  1361. dev_dbg(codec->dev, "%s event %d name %s\n", __func__, event, w->name);
  1362. return 0;
  1363. }
  1364. static const char * const rx_int1_1_interp_mux_text[] = {
  1365. "ZERO", "RX INT1_1 MUX",
  1366. };
  1367. static const char * const rx_int2_1_interp_mux_text[] = {
  1368. "ZERO", "RX INT2_1 MUX",
  1369. };
  1370. static const char * const rx_int1_2_interp_mux_text[] = {
  1371. "ZERO", "RX INT1_2 MUX",
  1372. };
  1373. static const char * const rx_int2_2_interp_mux_text[] = {
  1374. "ZERO", "RX INT2_2 MUX",
  1375. };
  1376. AQT_DAPM_ENUM(rx_int1_1_interp, SND_SOC_NOPM, 0, rx_int1_1_interp_mux_text);
  1377. AQT_DAPM_ENUM(rx_int2_1_interp, SND_SOC_NOPM, 0, rx_int2_1_interp_mux_text);
  1378. AQT_DAPM_ENUM(rx_int1_2_interp, SND_SOC_NOPM, 0, rx_int1_2_interp_mux_text);
  1379. AQT_DAPM_ENUM(rx_int2_2_interp, SND_SOC_NOPM, 0, rx_int2_2_interp_mux_text);
  1380. static const char * const asrc0_mux_text[] = {
  1381. "ZERO", "ASRC_IN_HPHL",
  1382. };
  1383. static const char * const asrc1_mux_text[] = {
  1384. "ZERO", "ASRC_IN_HPHR",
  1385. };
  1386. AQT_DAPM_ENUM(asrc0, AQT1000_CDC_RX_INP_MUX_SPLINE_ASRC_CFG0, 0,
  1387. asrc0_mux_text);
  1388. AQT_DAPM_ENUM(asrc1, AQT1000_CDC_RX_INP_MUX_SPLINE_ASRC_CFG0, 2,
  1389. asrc1_mux_text);
  1390. static int aqt_get_asrc_mode(struct aqt1000 *aqt, int asrc,
  1391. u8 main_sr, u8 mix_sr)
  1392. {
  1393. u8 asrc_output_mode;
  1394. int asrc_mode = CONV_88P2K_TO_384K;
  1395. if ((asrc < 0) || (asrc >= ASRC_MAX))
  1396. return 0;
  1397. asrc_output_mode = aqt->asrc_output_mode[asrc];
  1398. if (asrc_output_mode) {
  1399. /*
  1400. * If Mix sample rate is < 96KHz, use 96K to 352.8K
  1401. * conversion, or else use 384K to 352.8K conversion
  1402. */
  1403. if (mix_sr < 5)
  1404. asrc_mode = CONV_96K_TO_352P8K;
  1405. else
  1406. asrc_mode = CONV_384K_TO_352P8K;
  1407. } else {
  1408. /* Integer main and Fractional mix path */
  1409. if (main_sr < 8 && mix_sr > 9) {
  1410. asrc_mode = CONV_352P8K_TO_384K;
  1411. } else if (main_sr > 8 && mix_sr < 8) {
  1412. /* Fractional main and Integer mix path */
  1413. if (mix_sr < 5)
  1414. asrc_mode = CONV_96K_TO_352P8K;
  1415. else
  1416. asrc_mode = CONV_384K_TO_352P8K;
  1417. } else if (main_sr < 8 && mix_sr < 8) {
  1418. /* Integer main and Integer mix path */
  1419. asrc_mode = CONV_96K_TO_384K;
  1420. }
  1421. }
  1422. return asrc_mode;
  1423. }
  1424. static int aqt_codec_enable_asrc_resampler(struct snd_soc_dapm_widget *w,
  1425. struct snd_kcontrol *kcontrol,
  1426. int event)
  1427. {
  1428. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1429. struct aqt1000 *aqt = snd_soc_codec_get_drvdata(codec);
  1430. int asrc = 0, ret = 0;
  1431. u8 cfg;
  1432. u16 cfg_reg = 0;
  1433. u16 ctl_reg = 0;
  1434. u16 clk_reg = 0;
  1435. u16 asrc_ctl = 0;
  1436. u16 mix_ctl_reg = 0;
  1437. u16 paired_reg = 0;
  1438. u8 main_sr, mix_sr, asrc_mode = 0;
  1439. cfg = snd_soc_read(codec, AQT1000_CDC_RX_INP_MUX_SPLINE_ASRC_CFG0);
  1440. if (!(cfg & 0xFF)) {
  1441. dev_err(codec->dev, "%s: ASRC%u input not selected\n",
  1442. __func__, w->shift);
  1443. return -EINVAL;
  1444. }
  1445. switch (w->shift) {
  1446. case ASRC0:
  1447. if ((cfg & 0x03) == 0x01) {
  1448. cfg_reg = AQT1000_CDC_RX1_RX_PATH_CFG0;
  1449. ctl_reg = AQT1000_CDC_RX1_RX_PATH_CTL;
  1450. clk_reg = AQT1000_MIXING_ASRC0_CLK_RST_CTL;
  1451. paired_reg = AQT1000_MIXING_ASRC1_CLK_RST_CTL;
  1452. asrc_ctl = AQT1000_MIXING_ASRC0_CTL1;
  1453. }
  1454. break;
  1455. case ASRC1:
  1456. if ((cfg & 0x0C) == 0x4) {
  1457. cfg_reg = AQT1000_CDC_RX2_RX_PATH_CFG0;
  1458. ctl_reg = AQT1000_CDC_RX2_RX_PATH_CTL;
  1459. clk_reg = AQT1000_MIXING_ASRC1_CLK_RST_CTL;
  1460. paired_reg = AQT1000_MIXING_ASRC0_CLK_RST_CTL;
  1461. asrc_ctl = AQT1000_MIXING_ASRC1_CTL1;
  1462. }
  1463. break;
  1464. default:
  1465. dev_err(codec->dev, "%s: Invalid asrc:%u\n", __func__,
  1466. w->shift);
  1467. ret = -EINVAL;
  1468. break;
  1469. };
  1470. if ((cfg_reg == 0) || (ctl_reg == 0) || (clk_reg == 0) ||
  1471. (asrc_ctl == 0) || ret)
  1472. goto done;
  1473. switch (event) {
  1474. case SND_SOC_DAPM_PRE_PMU:
  1475. if ((snd_soc_read(codec, clk_reg) & 0x02) ||
  1476. (snd_soc_read(codec, paired_reg) & 0x02)) {
  1477. snd_soc_update_bits(codec, clk_reg, 0x02, 0x00);
  1478. snd_soc_update_bits(codec, paired_reg, 0x02, 0x00);
  1479. }
  1480. snd_soc_update_bits(codec, cfg_reg, 0x80, 0x80);
  1481. snd_soc_update_bits(codec, clk_reg, 0x01, 0x01);
  1482. main_sr = snd_soc_read(codec, ctl_reg) & 0x0F;
  1483. mix_ctl_reg = ctl_reg + 5;
  1484. mix_sr = snd_soc_read(codec, mix_ctl_reg) & 0x0F;
  1485. asrc_mode = aqt_get_asrc_mode(aqt, asrc,
  1486. main_sr, mix_sr);
  1487. dev_dbg(codec->dev, "%s: main_sr:%d mix_sr:%d asrc_mode %d\n",
  1488. __func__, main_sr, mix_sr, asrc_mode);
  1489. snd_soc_update_bits(codec, asrc_ctl, 0x07, asrc_mode);
  1490. break;
  1491. case SND_SOC_DAPM_POST_PMD:
  1492. snd_soc_update_bits(codec, asrc_ctl, 0x07, 0x00);
  1493. snd_soc_update_bits(codec, cfg_reg, 0x80, 0x00);
  1494. snd_soc_update_bits(codec, clk_reg, 0x03, 0x02);
  1495. break;
  1496. };
  1497. done:
  1498. return ret;
  1499. }
  1500. static int aqt_codec_enable_anc(struct snd_soc_dapm_widget *w,
  1501. struct snd_kcontrol *kcontrol, int event)
  1502. {
  1503. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1504. struct aqt1000 *aqt = snd_soc_codec_get_drvdata(codec);
  1505. const char *filename;
  1506. const struct firmware *fw;
  1507. int i;
  1508. int ret = 0;
  1509. int num_anc_slots;
  1510. struct aqt1000_anc_header *anc_head;
  1511. struct firmware_cal *hwdep_cal = NULL;
  1512. u32 anc_writes_size = 0;
  1513. u32 anc_cal_size = 0;
  1514. int anc_size_remaining;
  1515. u32 *anc_ptr;
  1516. u16 reg;
  1517. u8 mask, val;
  1518. size_t cal_size;
  1519. const void *data;
  1520. if (!aqt->anc_func)
  1521. return 0;
  1522. switch (event) {
  1523. case SND_SOC_DAPM_PRE_PMU:
  1524. hwdep_cal = wcdcal_get_fw_cal(aqt->fw_data, WCD9XXX_ANC_CAL);
  1525. if (hwdep_cal) {
  1526. data = hwdep_cal->data;
  1527. cal_size = hwdep_cal->size;
  1528. dev_dbg(codec->dev, "%s: using hwdep calibration, cal_size %zd",
  1529. __func__, cal_size);
  1530. } else {
  1531. filename = "AQT1000/AQT1000_anc.bin";
  1532. ret = request_firmware(&fw, filename, codec->dev);
  1533. if (ret < 0) {
  1534. dev_err(codec->dev, "%s: Failed to acquire ANC data: %d\n",
  1535. __func__, ret);
  1536. return ret;
  1537. }
  1538. if (!fw) {
  1539. dev_err(codec->dev, "%s: Failed to get anc fw\n",
  1540. __func__);
  1541. return -ENODEV;
  1542. }
  1543. data = fw->data;
  1544. cal_size = fw->size;
  1545. dev_dbg(codec->dev, "%s: using request_firmware calibration\n",
  1546. __func__);
  1547. }
  1548. if (cal_size < sizeof(struct aqt1000_anc_header)) {
  1549. dev_err(codec->dev, "%s: Invalid cal_size %zd\n",
  1550. __func__, cal_size);
  1551. ret = -EINVAL;
  1552. goto err;
  1553. }
  1554. /* First number is the number of register writes */
  1555. anc_head = (struct aqt1000_anc_header *)(data);
  1556. anc_ptr = (u32 *)(data + sizeof(struct aqt1000_anc_header));
  1557. anc_size_remaining = cal_size -
  1558. sizeof(struct aqt1000_anc_header);
  1559. num_anc_slots = anc_head->num_anc_slots;
  1560. if (aqt->anc_slot >= num_anc_slots) {
  1561. dev_err(codec->dev, "%s: Invalid ANC slot selected\n",
  1562. __func__);
  1563. ret = -EINVAL;
  1564. goto err;
  1565. }
  1566. for (i = 0; i < num_anc_slots; i++) {
  1567. if (anc_size_remaining < AQT1000_PACKED_REG_SIZE) {
  1568. dev_err(codec->dev, "%s: Invalid register format\n",
  1569. __func__);
  1570. ret = -EINVAL;
  1571. goto err;
  1572. }
  1573. anc_writes_size = (u32)(*anc_ptr);
  1574. anc_size_remaining -= sizeof(u32);
  1575. anc_ptr += 1;
  1576. if ((anc_writes_size * AQT1000_PACKED_REG_SIZE) >
  1577. anc_size_remaining) {
  1578. dev_err(codec->dev, "%s: Invalid register format\n",
  1579. __func__);
  1580. ret = -EINVAL;
  1581. goto err;
  1582. }
  1583. if (aqt->anc_slot == i)
  1584. break;
  1585. anc_size_remaining -= (anc_writes_size *
  1586. AQT1000_PACKED_REG_SIZE);
  1587. anc_ptr += anc_writes_size;
  1588. }
  1589. if (i == num_anc_slots) {
  1590. dev_err(codec->dev, "%s: Selected ANC slot not present\n",
  1591. __func__);
  1592. ret = -EINVAL;
  1593. goto err;
  1594. }
  1595. i = 0;
  1596. anc_cal_size = anc_writes_size;
  1597. /* Rate converter clk enable and set bypass mode */
  1598. if (!strcmp(w->name, "AQT RX INT1 DAC")) {
  1599. snd_soc_update_bits(codec,
  1600. AQT1000_CDC_ANC0_RC_COMMON_CTL,
  1601. 0x05, 0x05);
  1602. snd_soc_update_bits(codec,
  1603. AQT1000_CDC_ANC0_FIFO_COMMON_CTL,
  1604. 0x66, 0x66);
  1605. anc_writes_size = anc_cal_size / 2;
  1606. snd_soc_update_bits(codec,
  1607. AQT1000_CDC_ANC0_CLK_RESET_CTL, 0x39, 0x39);
  1608. } else if (!strcmp(w->name, "AQT RX INT2 DAC")) {
  1609. snd_soc_update_bits(codec,
  1610. AQT1000_CDC_ANC1_RC_COMMON_CTL,
  1611. 0x05, 0x05);
  1612. snd_soc_update_bits(codec,
  1613. AQT1000_CDC_ANC1_FIFO_COMMON_CTL,
  1614. 0x66, 0x66);
  1615. i = anc_cal_size / 2;
  1616. snd_soc_update_bits(codec,
  1617. AQT1000_CDC_ANC1_CLK_RESET_CTL, 0x39, 0x39);
  1618. }
  1619. for (; i < anc_writes_size; i++) {
  1620. AQT1000_CODEC_UNPACK_ENTRY(anc_ptr[i], reg, mask, val);
  1621. snd_soc_write(codec, reg, (val & mask));
  1622. }
  1623. if (!strcmp(w->name, "AQT RX INT1 DAC"))
  1624. snd_soc_update_bits(codec,
  1625. AQT1000_CDC_ANC0_CLK_RESET_CTL, 0x08, 0x08);
  1626. else if (!strcmp(w->name, "AQT RX INT2 DAC"))
  1627. snd_soc_update_bits(codec,
  1628. AQT1000_CDC_ANC1_CLK_RESET_CTL, 0x08, 0x08);
  1629. if (!hwdep_cal)
  1630. release_firmware(fw);
  1631. break;
  1632. case SND_SOC_DAPM_POST_PMU:
  1633. /* Remove ANC Rx from reset */
  1634. snd_soc_update_bits(codec,
  1635. AQT1000_CDC_ANC0_CLK_RESET_CTL,
  1636. 0x08, 0x00);
  1637. snd_soc_update_bits(codec,
  1638. AQT1000_CDC_ANC1_CLK_RESET_CTL,
  1639. 0x08, 0x00);
  1640. break;
  1641. case SND_SOC_DAPM_POST_PMD:
  1642. snd_soc_update_bits(codec, AQT1000_CDC_ANC0_RC_COMMON_CTL,
  1643. 0x05, 0x00);
  1644. if (!strcmp(w->name, "AQT ANC HPHL PA")) {
  1645. snd_soc_update_bits(codec, AQT1000_CDC_ANC0_MODE_1_CTL,
  1646. 0x30, 0x00);
  1647. /* 50 msec sleep is needed to avoid click and pop as
  1648. * per HW requirement
  1649. */
  1650. msleep(50);
  1651. snd_soc_update_bits(codec, AQT1000_CDC_ANC0_MODE_1_CTL,
  1652. 0x01, 0x00);
  1653. snd_soc_update_bits(codec,
  1654. AQT1000_CDC_ANC0_CLK_RESET_CTL,
  1655. 0x38, 0x38);
  1656. snd_soc_update_bits(codec,
  1657. AQT1000_CDC_ANC0_CLK_RESET_CTL,
  1658. 0x07, 0x00);
  1659. snd_soc_update_bits(codec,
  1660. AQT1000_CDC_ANC0_CLK_RESET_CTL,
  1661. 0x38, 0x00);
  1662. } else if (!strcmp(w->name, "AQT ANC HPHR PA")) {
  1663. snd_soc_update_bits(codec, AQT1000_CDC_ANC1_MODE_1_CTL,
  1664. 0x30, 0x00);
  1665. /* 50 msec sleep is needed to avoid click and pop as
  1666. * per HW requirement
  1667. */
  1668. msleep(50);
  1669. snd_soc_update_bits(codec, AQT1000_CDC_ANC1_MODE_1_CTL,
  1670. 0x01, 0x00);
  1671. snd_soc_update_bits(codec,
  1672. AQT1000_CDC_ANC1_CLK_RESET_CTL,
  1673. 0x38, 0x38);
  1674. snd_soc_update_bits(codec,
  1675. AQT1000_CDC_ANC1_CLK_RESET_CTL,
  1676. 0x07, 0x00);
  1677. snd_soc_update_bits(codec,
  1678. AQT1000_CDC_ANC1_CLK_RESET_CTL,
  1679. 0x38, 0x00);
  1680. }
  1681. break;
  1682. }
  1683. return 0;
  1684. err:
  1685. if (!hwdep_cal)
  1686. release_firmware(fw);
  1687. return ret;
  1688. }
  1689. static void aqt_codec_override(struct snd_soc_codec *codec, int mode,
  1690. int event)
  1691. {
  1692. if (mode == CLS_AB || mode == CLS_AB_HIFI) {
  1693. switch (event) {
  1694. case SND_SOC_DAPM_PRE_PMU:
  1695. case SND_SOC_DAPM_POST_PMU:
  1696. snd_soc_update_bits(codec,
  1697. AQT1000_ANA_RX_SUPPLIES, 0x02, 0x02);
  1698. break;
  1699. case SND_SOC_DAPM_POST_PMD:
  1700. snd_soc_update_bits(codec,
  1701. AQT1000_ANA_RX_SUPPLIES, 0x02, 0x00);
  1702. break;
  1703. }
  1704. }
  1705. }
  1706. static void aqt_codec_set_tx_hold(struct snd_soc_codec *codec,
  1707. u16 amic_reg, bool set)
  1708. {
  1709. u8 mask = 0x20;
  1710. u8 val;
  1711. if (amic_reg == AQT1000_ANA_AMIC1 ||
  1712. amic_reg == AQT1000_ANA_AMIC3)
  1713. mask = 0x40;
  1714. val = set ? mask : 0x00;
  1715. switch (amic_reg) {
  1716. case AQT1000_ANA_AMIC1:
  1717. case AQT1000_ANA_AMIC2:
  1718. snd_soc_update_bits(codec, AQT1000_ANA_AMIC2, mask, val);
  1719. break;
  1720. case AQT1000_ANA_AMIC3:
  1721. snd_soc_update_bits(codec, AQT1000_ANA_AMIC3_HPF, mask, val);
  1722. break;
  1723. default:
  1724. dev_dbg(codec->dev, "%s: invalid amic: %d\n",
  1725. __func__, amic_reg);
  1726. break;
  1727. }
  1728. }
  1729. static void aqt_codec_clear_anc_tx_hold(struct aqt1000 *aqt)
  1730. {
  1731. if (test_and_clear_bit(ANC_MIC_AMIC1, &aqt->status_mask))
  1732. aqt_codec_set_tx_hold(aqt->codec, AQT1000_ANA_AMIC1, false);
  1733. if (test_and_clear_bit(ANC_MIC_AMIC2, &aqt->status_mask))
  1734. aqt_codec_set_tx_hold(aqt->codec, AQT1000_ANA_AMIC2, false);
  1735. if (test_and_clear_bit(ANC_MIC_AMIC3, &aqt->status_mask))
  1736. aqt_codec_set_tx_hold(aqt->codec, AQT1000_ANA_AMIC3, false);
  1737. }
  1738. static const char * const rx_int_dem_inp_mux_text[] = {
  1739. "NORMAL_DSM_OUT", "CLSH_DSM_OUT",
  1740. };
  1741. static int aqt_int_dem_inp_mux_put(struct snd_kcontrol *kcontrol,
  1742. struct snd_ctl_elem_value *ucontrol)
  1743. {
  1744. struct snd_soc_dapm_widget *widget =
  1745. snd_soc_dapm_kcontrol_widget(kcontrol);
  1746. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm);
  1747. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  1748. unsigned int val;
  1749. unsigned short look_ahead_dly_reg = AQT1000_CDC_RX1_RX_PATH_CFG0;
  1750. val = ucontrol->value.enumerated.item[0];
  1751. if (val >= e->items)
  1752. return -EINVAL;
  1753. dev_dbg(codec->dev, "%s: wname: %s, val: 0x%x\n", __func__,
  1754. widget->name, val);
  1755. if (e->reg == AQT1000_CDC_RX1_RX_PATH_SEC0)
  1756. look_ahead_dly_reg = AQT1000_CDC_RX1_RX_PATH_CFG0;
  1757. else if (e->reg == AQT1000_CDC_RX2_RX_PATH_SEC0)
  1758. look_ahead_dly_reg = AQT1000_CDC_RX2_RX_PATH_CFG0;
  1759. /* Set Look Ahead Delay */
  1760. snd_soc_update_bits(codec, look_ahead_dly_reg,
  1761. 0x08, (val ? 0x08 : 0x00));
  1762. /* Set DEM INP Select */
  1763. return snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
  1764. }
  1765. AQT_DAPM_ENUM_EXT(rx_int1_dem, AQT1000_CDC_RX1_RX_PATH_SEC0, 0,
  1766. rx_int_dem_inp_mux_text, snd_soc_dapm_get_enum_double,
  1767. aqt_int_dem_inp_mux_put);
  1768. AQT_DAPM_ENUM_EXT(rx_int2_dem, AQT1000_CDC_RX2_RX_PATH_SEC0, 0,
  1769. rx_int_dem_inp_mux_text, snd_soc_dapm_get_enum_double,
  1770. aqt_int_dem_inp_mux_put);
  1771. static int aqt_codec_hphl_dac_event(struct snd_soc_dapm_widget *w,
  1772. struct snd_kcontrol *kcontrol,
  1773. int event)
  1774. {
  1775. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1776. struct aqt1000 *aqt = snd_soc_codec_get_drvdata(codec);
  1777. int hph_mode = aqt->hph_mode;
  1778. u8 dem_inp;
  1779. int ret = 0;
  1780. dev_dbg(codec->dev, "%s wname: %s event: %d hph_mode: %d\n", __func__,
  1781. w->name, event, hph_mode);
  1782. switch (event) {
  1783. case SND_SOC_DAPM_PRE_PMU:
  1784. if (aqt->anc_func) {
  1785. ret = aqt_codec_enable_anc(w, kcontrol, event);
  1786. /* 40 msec delay is needed to avoid click and pop */
  1787. msleep(40);
  1788. }
  1789. /* Read DEM INP Select */
  1790. dem_inp = snd_soc_read(codec, AQT1000_CDC_RX1_RX_PATH_SEC0) &
  1791. 0x03;
  1792. if (((hph_mode == CLS_H_HIFI) || (hph_mode == CLS_H_LOHIFI) ||
  1793. (hph_mode == CLS_H_LP)) && (dem_inp != 0x01)) {
  1794. dev_err(codec->dev, "%s: DEM Input not set correctly, hph_mode: %d\n",
  1795. __func__, hph_mode);
  1796. return -EINVAL;
  1797. }
  1798. /* Disable AutoChop timer during power up */
  1799. snd_soc_update_bits(codec, AQT1000_HPH_NEW_INT_HPH_TIMER1,
  1800. 0x02, 0x00);
  1801. aqt_clsh_fsm(codec, &aqt->clsh_d,
  1802. AQT_CLSH_EVENT_PRE_DAC,
  1803. AQT_CLSH_STATE_HPHL,
  1804. hph_mode);
  1805. if (aqt->anc_func)
  1806. snd_soc_update_bits(codec,
  1807. AQT1000_CDC_RX1_RX_PATH_CFG0,
  1808. 0x10, 0x10);
  1809. break;
  1810. case SND_SOC_DAPM_POST_PMD:
  1811. /* 1000us required as per HW requirement */
  1812. usleep_range(1000, 1100);
  1813. aqt_clsh_fsm(codec, &aqt->clsh_d,
  1814. AQT_CLSH_EVENT_POST_PA,
  1815. AQT_CLSH_STATE_HPHL,
  1816. hph_mode);
  1817. break;
  1818. default:
  1819. break;
  1820. };
  1821. return ret;
  1822. }
  1823. static int aqt_codec_hphr_dac_event(struct snd_soc_dapm_widget *w,
  1824. struct snd_kcontrol *kcontrol,
  1825. int event)
  1826. {
  1827. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1828. struct aqt1000 *aqt = snd_soc_codec_get_drvdata(codec);
  1829. int hph_mode = aqt->hph_mode;
  1830. u8 dem_inp;
  1831. int ret = 0;
  1832. dev_dbg(codec->dev, "%s wname: %s event: %d hph_mode: %d\n", __func__,
  1833. w->name, event, hph_mode);
  1834. switch (event) {
  1835. case SND_SOC_DAPM_PRE_PMU:
  1836. if (aqt->anc_func) {
  1837. ret = aqt_codec_enable_anc(w, kcontrol, event);
  1838. /* 40 msec delay is needed to avoid click and pop */
  1839. msleep(40);
  1840. }
  1841. /* Read DEM INP Select */
  1842. dem_inp = snd_soc_read(codec, AQT1000_CDC_RX2_RX_PATH_SEC0) &
  1843. 0x03;
  1844. if (((hph_mode == CLS_H_HIFI) || (hph_mode == CLS_H_LOHIFI) ||
  1845. (hph_mode == CLS_H_LP)) && (dem_inp != 0x01)) {
  1846. dev_err(codec->dev, "%s: DEM Input not set correctly, hph_mode: %d\n",
  1847. __func__, hph_mode);
  1848. return -EINVAL;
  1849. }
  1850. /* Disable AutoChop timer during power up */
  1851. snd_soc_update_bits(codec, AQT1000_HPH_NEW_INT_HPH_TIMER1,
  1852. 0x02, 0x00);
  1853. aqt_clsh_fsm(codec, &aqt->clsh_d,
  1854. AQT_CLSH_EVENT_PRE_DAC,
  1855. AQT_CLSH_STATE_HPHR,
  1856. hph_mode);
  1857. if (aqt->anc_func)
  1858. snd_soc_update_bits(codec,
  1859. AQT1000_CDC_RX2_RX_PATH_CFG0,
  1860. 0x10, 0x10);
  1861. break;
  1862. case SND_SOC_DAPM_POST_PMD:
  1863. /* 1000us required as per HW requirement */
  1864. usleep_range(1000, 1100);
  1865. aqt_clsh_fsm(codec, &aqt->clsh_d,
  1866. AQT_CLSH_EVENT_POST_PA,
  1867. AQT_CLSH_STATE_HPHR,
  1868. hph_mode);
  1869. break;
  1870. default:
  1871. break;
  1872. };
  1873. return 0;
  1874. }
  1875. static int aqt_codec_enable_hphr_pa(struct snd_soc_dapm_widget *w,
  1876. struct snd_kcontrol *kcontrol,
  1877. int event)
  1878. {
  1879. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1880. struct aqt1000 *aqt = snd_soc_codec_get_drvdata(codec);
  1881. int ret = 0;
  1882. dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event);
  1883. switch (event) {
  1884. case SND_SOC_DAPM_PRE_PMU:
  1885. if ((!(strcmp(w->name, "AQT ANC HPHR PA"))) &&
  1886. (test_bit(HPH_PA_DELAY, &aqt->status_mask)))
  1887. snd_soc_update_bits(codec, AQT1000_ANA_HPH, 0xC0, 0xC0);
  1888. set_bit(HPH_PA_DELAY, &aqt->status_mask);
  1889. break;
  1890. case SND_SOC_DAPM_POST_PMU:
  1891. if ((!(strcmp(w->name, "AQT ANC HPHR PA")))) {
  1892. if ((snd_soc_read(codec, AQT1000_ANA_HPH) & 0xC0)
  1893. != 0xC0)
  1894. /*
  1895. * If PA_EN is not set (potentially in ANC case)
  1896. * then do nothing for POST_PMU and let left
  1897. * channel handle everything.
  1898. */
  1899. break;
  1900. }
  1901. /*
  1902. * 7ms sleep is required after PA is enabled as per
  1903. * HW requirement. If compander is disabled, then
  1904. * 20ms delay is needed.
  1905. */
  1906. if (test_bit(HPH_PA_DELAY, &aqt->status_mask)) {
  1907. if (!aqt->comp_enabled[COMPANDER_2])
  1908. usleep_range(20000, 20100);
  1909. else
  1910. usleep_range(7000, 7100);
  1911. clear_bit(HPH_PA_DELAY, &aqt->status_mask);
  1912. }
  1913. if (aqt->anc_func) {
  1914. /* Clear Tx FE HOLD if both PAs are enabled */
  1915. if ((snd_soc_read(aqt->codec, AQT1000_ANA_HPH) &
  1916. 0xC0) == 0xC0)
  1917. aqt_codec_clear_anc_tx_hold(aqt);
  1918. }
  1919. snd_soc_update_bits(codec, AQT1000_HPH_R_TEST, 0x01, 0x01);
  1920. /* Remove mute */
  1921. snd_soc_update_bits(codec, AQT1000_CDC_RX2_RX_PATH_CTL,
  1922. 0x10, 0x00);
  1923. /* Enable GM3 boost */
  1924. snd_soc_update_bits(codec, AQT1000_HPH_CNP_WG_CTL,
  1925. 0x80, 0x80);
  1926. /* Enable AutoChop timer at the end of power up */
  1927. snd_soc_update_bits(codec, AQT1000_HPH_NEW_INT_HPH_TIMER1,
  1928. 0x02, 0x02);
  1929. /* Remove mix path mute if it is enabled */
  1930. if ((snd_soc_read(codec, AQT1000_CDC_RX2_RX_PATH_MIX_CTL)) &
  1931. 0x10)
  1932. snd_soc_update_bits(codec,
  1933. AQT1000_CDC_RX2_RX_PATH_MIX_CTL,
  1934. 0x10, 0x00);
  1935. if (!(strcmp(w->name, "AQT ANC HPHR PA"))) {
  1936. dev_dbg(codec->dev,
  1937. "%s:Do everything needed for left channel\n",
  1938. __func__);
  1939. /* Do everything needed for left channel */
  1940. snd_soc_update_bits(codec, AQT1000_HPH_L_TEST,
  1941. 0x01, 0x01);
  1942. /* Remove mute */
  1943. snd_soc_update_bits(codec, AQT1000_CDC_RX1_RX_PATH_CTL,
  1944. 0x10, 0x00);
  1945. /* Remove mix path mute if it is enabled */
  1946. if ((snd_soc_read(codec,
  1947. AQT1000_CDC_RX1_RX_PATH_MIX_CTL)) &
  1948. 0x10)
  1949. snd_soc_update_bits(codec,
  1950. AQT1000_CDC_RX1_RX_PATH_MIX_CTL,
  1951. 0x10, 0x00);
  1952. /* Remove ANC Rx from reset */
  1953. ret = aqt_codec_enable_anc(w, kcontrol, event);
  1954. }
  1955. aqt_codec_override(codec, aqt->hph_mode, event);
  1956. break;
  1957. case SND_SOC_DAPM_PRE_PMD:
  1958. snd_soc_update_bits(codec, AQT1000_HPH_R_TEST, 0x01, 0x00);
  1959. snd_soc_update_bits(codec, AQT1000_CDC_RX2_RX_PATH_CTL,
  1960. 0x10, 0x10);
  1961. snd_soc_update_bits(codec, AQT1000_CDC_RX2_RX_PATH_MIX_CTL,
  1962. 0x10, 0x10);
  1963. if (!(strcmp(w->name, "AQT ANC HPHR PA")))
  1964. snd_soc_update_bits(codec, AQT1000_ANA_HPH, 0x40, 0x00);
  1965. break;
  1966. case SND_SOC_DAPM_POST_PMD:
  1967. /*
  1968. * 5ms sleep is required after PA disable. If compander is
  1969. * disabled, then 20ms delay is needed after PA disable.
  1970. */
  1971. if (!aqt->comp_enabled[COMPANDER_2])
  1972. usleep_range(20000, 20100);
  1973. else
  1974. usleep_range(5000, 5100);
  1975. aqt_codec_override(codec, aqt->hph_mode, event);
  1976. if (!(strcmp(w->name, "AQT ANC HPHR PA"))) {
  1977. ret = aqt_codec_enable_anc(w, kcontrol, event);
  1978. snd_soc_update_bits(codec,
  1979. AQT1000_CDC_RX2_RX_PATH_CFG0,
  1980. 0x10, 0x00);
  1981. }
  1982. break;
  1983. };
  1984. return ret;
  1985. }
  1986. static int aqt_codec_enable_hphl_pa(struct snd_soc_dapm_widget *w,
  1987. struct snd_kcontrol *kcontrol,
  1988. int event)
  1989. {
  1990. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1991. struct aqt1000 *aqt = snd_soc_codec_get_drvdata(codec);
  1992. int ret = 0;
  1993. dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event);
  1994. switch (event) {
  1995. case SND_SOC_DAPM_PRE_PMU:
  1996. if ((!(strcmp(w->name, "AQT ANC HPHL PA"))) &&
  1997. (test_bit(HPH_PA_DELAY, &aqt->status_mask)))
  1998. snd_soc_update_bits(codec, AQT1000_ANA_HPH,
  1999. 0xC0, 0xC0);
  2000. set_bit(HPH_PA_DELAY, &aqt->status_mask);
  2001. break;
  2002. case SND_SOC_DAPM_POST_PMU:
  2003. if (!(strcmp(w->name, "AQT ANC HPHL PA"))) {
  2004. if ((snd_soc_read(codec, AQT1000_ANA_HPH) & 0xC0)
  2005. != 0xC0)
  2006. /*
  2007. * If PA_EN is not set (potentially in ANC
  2008. * case) then do nothing for POST_PMU and
  2009. * let right channel handle everything.
  2010. */
  2011. break;
  2012. }
  2013. /*
  2014. * 7ms sleep is required after PA is enabled as per
  2015. * HW requirement. If compander is disabled, then
  2016. * 20ms delay is needed.
  2017. */
  2018. if (test_bit(HPH_PA_DELAY, &aqt->status_mask)) {
  2019. if (!aqt->comp_enabled[COMPANDER_1])
  2020. usleep_range(20000, 20100);
  2021. else
  2022. usleep_range(7000, 7100);
  2023. clear_bit(HPH_PA_DELAY, &aqt->status_mask);
  2024. }
  2025. if (aqt->anc_func) {
  2026. /* Clear Tx FE HOLD if both PAs are enabled */
  2027. if ((snd_soc_read(aqt->codec, AQT1000_ANA_HPH) &
  2028. 0xC0) == 0xC0)
  2029. aqt_codec_clear_anc_tx_hold(aqt);
  2030. }
  2031. snd_soc_update_bits(codec, AQT1000_HPH_L_TEST, 0x01, 0x01);
  2032. /* Remove Mute on primary path */
  2033. snd_soc_update_bits(codec, AQT1000_CDC_RX1_RX_PATH_CTL,
  2034. 0x10, 0x00);
  2035. /* Enable GM3 boost */
  2036. snd_soc_update_bits(codec, AQT1000_HPH_CNP_WG_CTL,
  2037. 0x80, 0x80);
  2038. /* Enable AutoChop timer at the end of power up */
  2039. snd_soc_update_bits(codec, AQT1000_HPH_NEW_INT_HPH_TIMER1,
  2040. 0x02, 0x02);
  2041. /* Remove mix path mute if it is enabled */
  2042. if ((snd_soc_read(codec, AQT1000_CDC_RX1_RX_PATH_MIX_CTL)) &
  2043. 0x10)
  2044. snd_soc_update_bits(codec,
  2045. AQT1000_CDC_RX1_RX_PATH_MIX_CTL,
  2046. 0x10, 0x00);
  2047. if (!(strcmp(w->name, "AQT ANC HPHL PA"))) {
  2048. dev_dbg(codec->dev,
  2049. "%s:Do everything needed for right channel\n",
  2050. __func__);
  2051. /* Do everything needed for right channel */
  2052. snd_soc_update_bits(codec, AQT1000_HPH_R_TEST,
  2053. 0x01, 0x01);
  2054. /* Remove mute */
  2055. snd_soc_update_bits(codec, AQT1000_CDC_RX2_RX_PATH_CTL,
  2056. 0x10, 0x00);
  2057. /* Remove mix path mute if it is enabled */
  2058. if ((snd_soc_read(codec,
  2059. AQT1000_CDC_RX2_RX_PATH_MIX_CTL)) &
  2060. 0x10)
  2061. snd_soc_update_bits(codec,
  2062. AQT1000_CDC_RX2_RX_PATH_MIX_CTL,
  2063. 0x10, 0x00);
  2064. /* Remove ANC Rx from reset */
  2065. ret = aqt_codec_enable_anc(w, kcontrol, event);
  2066. }
  2067. aqt_codec_override(codec, aqt->hph_mode, event);
  2068. break;
  2069. case SND_SOC_DAPM_PRE_PMD:
  2070. snd_soc_update_bits(codec, AQT1000_HPH_L_TEST, 0x01, 0x00);
  2071. snd_soc_update_bits(codec, AQT1000_CDC_RX1_RX_PATH_CTL,
  2072. 0x10, 0x10);
  2073. snd_soc_update_bits(codec, AQT1000_CDC_RX1_RX_PATH_MIX_CTL,
  2074. 0x10, 0x10);
  2075. if (!(strcmp(w->name, "AQT ANC HPHL PA")))
  2076. snd_soc_update_bits(codec, AQT1000_ANA_HPH,
  2077. 0x80, 0x00);
  2078. break;
  2079. case SND_SOC_DAPM_POST_PMD:
  2080. /*
  2081. * 5ms sleep is required after PA disable. If compander is
  2082. * disabled, then 20ms delay is needed after PA disable.
  2083. */
  2084. if (!aqt->comp_enabled[COMPANDER_1])
  2085. usleep_range(20000, 20100);
  2086. else
  2087. usleep_range(5000, 5100);
  2088. aqt_codec_override(codec, aqt->hph_mode, event);
  2089. if (!(strcmp(w->name, "AQT ANC HPHL PA"))) {
  2090. ret = aqt_codec_enable_anc(w, kcontrol, event);
  2091. snd_soc_update_bits(codec,
  2092. AQT1000_CDC_RX1_RX_PATH_CFG0, 0x10, 0x00);
  2093. }
  2094. break;
  2095. };
  2096. return ret;
  2097. }
  2098. static int aqt_codec_set_iir_gain(struct snd_soc_dapm_widget *w,
  2099. struct snd_kcontrol *kcontrol, int event)
  2100. {
  2101. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  2102. dev_dbg(codec->dev, "%s: event = %d\n", __func__, event);
  2103. switch (event) {
  2104. case SND_SOC_DAPM_POST_PMU: /* fall through */
  2105. case SND_SOC_DAPM_PRE_PMD:
  2106. if (strnstr(w->name, "AQT IIR0", sizeof("AQT IIR0"))) {
  2107. snd_soc_write(codec,
  2108. AQT1000_CDC_SIDETONE_IIR0_IIR_GAIN_B1_CTL,
  2109. snd_soc_read(codec,
  2110. AQT1000_CDC_SIDETONE_IIR0_IIR_GAIN_B1_CTL));
  2111. snd_soc_write(codec,
  2112. AQT1000_CDC_SIDETONE_IIR0_IIR_GAIN_B2_CTL,
  2113. snd_soc_read(codec,
  2114. AQT1000_CDC_SIDETONE_IIR0_IIR_GAIN_B2_CTL));
  2115. snd_soc_write(codec,
  2116. AQT1000_CDC_SIDETONE_IIR0_IIR_GAIN_B3_CTL,
  2117. snd_soc_read(codec,
  2118. AQT1000_CDC_SIDETONE_IIR0_IIR_GAIN_B3_CTL));
  2119. snd_soc_write(codec,
  2120. AQT1000_CDC_SIDETONE_IIR0_IIR_GAIN_B4_CTL,
  2121. snd_soc_read(codec,
  2122. AQT1000_CDC_SIDETONE_IIR0_IIR_GAIN_B4_CTL));
  2123. }
  2124. break;
  2125. }
  2126. return 0;
  2127. }
  2128. static int aqt_enable_native_supply(struct snd_soc_dapm_widget *w,
  2129. struct snd_kcontrol *kcontrol, int event)
  2130. {
  2131. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  2132. struct aqt1000 *aqt = snd_soc_codec_get_drvdata(codec);
  2133. switch (event) {
  2134. case SND_SOC_DAPM_PRE_PMU:
  2135. if (++aqt->native_clk_users == 1) {
  2136. snd_soc_update_bits(codec, AQT1000_CLK_SYS_PLL_ENABLES,
  2137. 0x01, 0x01);
  2138. /* 100usec is needed as per HW requirement */
  2139. usleep_range(100, 120);
  2140. snd_soc_update_bits(codec,
  2141. AQT1000_CDC_CLK_RST_CTRL_MCLK_CONTROL,
  2142. 0x02, 0x02);
  2143. snd_soc_update_bits(codec,
  2144. AQT1000_CDC_CLK_RST_CTRL_FS_CNT_CONTROL,
  2145. 0x10, 0x10);
  2146. }
  2147. break;
  2148. case SND_SOC_DAPM_PRE_PMD:
  2149. if (aqt->native_clk_users &&
  2150. (--aqt->native_clk_users == 0)) {
  2151. snd_soc_update_bits(codec,
  2152. AQT1000_CDC_CLK_RST_CTRL_FS_CNT_CONTROL,
  2153. 0x10, 0x00);
  2154. snd_soc_update_bits(codec,
  2155. AQT1000_CDC_CLK_RST_CTRL_MCLK_CONTROL,
  2156. 0x02, 0x00);
  2157. snd_soc_update_bits(codec, AQT1000_CLK_SYS_PLL_ENABLES,
  2158. 0x01, 0x00);
  2159. }
  2160. break;
  2161. }
  2162. dev_dbg(codec->dev, "%s: native_clk_users: %d, event: %d\n",
  2163. __func__, aqt->native_clk_users, event);
  2164. return 0;
  2165. }
  2166. static const char * const native_mux_text[] = {
  2167. "OFF", "ON",
  2168. };
  2169. AQT_DAPM_ENUM(int1_1_native, SND_SOC_NOPM, 0, native_mux_text);
  2170. AQT_DAPM_ENUM(int2_1_native, SND_SOC_NOPM, 0, native_mux_text);
  2171. static int aif_cap_mixer_get(struct snd_kcontrol *kcontrol,
  2172. struct snd_ctl_elem_value *ucontrol)
  2173. {
  2174. return 0;
  2175. }
  2176. static int aif_cap_mixer_put(struct snd_kcontrol *kcontrol,
  2177. struct snd_ctl_elem_value *ucontrol)
  2178. {
  2179. return 0;
  2180. }
  2181. static const struct snd_kcontrol_new aif1_cap_mixer[] = {
  2182. SOC_SINGLE_EXT("TX0", SND_SOC_NOPM, AQT_TX0, 1, 0,
  2183. aif_cap_mixer_get, aif_cap_mixer_put),
  2184. SOC_SINGLE_EXT("TX1", SND_SOC_NOPM, AQT_TX1, 1, 0,
  2185. aif_cap_mixer_get, aif_cap_mixer_put),
  2186. };
  2187. static const struct snd_soc_dapm_widget aqt_dapm_widgets[] = {
  2188. SND_SOC_DAPM_AIF_OUT_E("AQT AIF1 CAP", "AQT AIF1 Capture", 0,
  2189. SND_SOC_NOPM, AIF1_CAP, 0, aqt_codec_enable_i2s_tx,
  2190. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2191. SND_SOC_DAPM_MIXER("AQT AIF1 CAP Mixer", SND_SOC_NOPM, AIF1_CAP, 0,
  2192. aif1_cap_mixer, ARRAY_SIZE(aif1_cap_mixer)),
  2193. AQT_DAPM_MUX("AQT TX0_MUX", 0, tx0),
  2194. AQT_DAPM_MUX("AQT TX1_MUX", 0, tx1),
  2195. SND_SOC_DAPM_MUX_E("AQT ADC0 MUX", AQT1000_CDC_TX0_TX_PATH_CTL, 5, 0,
  2196. &tx_adc0_mux, aqt_codec_enable_dec,
  2197. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2198. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  2199. SND_SOC_DAPM_MUX_E("AQT ADC1 MUX", AQT1000_CDC_TX1_TX_PATH_CTL, 5, 0,
  2200. &tx_adc1_mux, aqt_codec_enable_dec,
  2201. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2202. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  2203. SND_SOC_DAPM_MUX_E("AQT ADC2 MUX", AQT1000_CDC_TX2_TX_PATH_CTL, 5, 0,
  2204. &tx_adc2_mux, aqt_codec_enable_dec,
  2205. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2206. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  2207. AQT_DAPM_MUX("AQT AMIC0_MUX", 0, tx_amic0),
  2208. AQT_DAPM_MUX("AQT AMIC1_MUX", 0, tx_amic1),
  2209. AQT_DAPM_MUX("AQT AMIC2_MUX", 0, tx_amic2),
  2210. SND_SOC_DAPM_ADC_E("AQT ADC_L", NULL, AQT1000_ANA_AMIC1, 7, 0,
  2211. aqt_codec_enable_adc, SND_SOC_DAPM_PRE_PMU),
  2212. SND_SOC_DAPM_ADC_E("AQT ADC_R", NULL, AQT1000_ANA_AMIC2, 7, 0,
  2213. aqt_codec_enable_adc, SND_SOC_DAPM_PRE_PMU),
  2214. SND_SOC_DAPM_ADC_E("AQT ADC_V", NULL, AQT1000_ANA_AMIC3, 7, 0,
  2215. aqt_codec_enable_adc, SND_SOC_DAPM_PRE_PMU),
  2216. AQT_DAPM_MUX("AQT AMIC10_MUX", 0, tx_amic10),
  2217. AQT_DAPM_MUX("AQT AMIC11_MUX", 0, tx_amic11),
  2218. AQT_DAPM_MUX("AQT AMIC12_MUX", 0, tx_amic12),
  2219. AQT_DAPM_MUX("AQT AMIC13_MUX", 0, tx_amic13),
  2220. SND_SOC_DAPM_SWITCH_E("AQT ANC OUT HPHL Enable", SND_SOC_NOPM,
  2221. INTERP_HPHL, 0, &anc_hphl_pa_switch, aqt_anc_out_switch_cb,
  2222. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
  2223. SND_SOC_DAPM_SWITCH_E("AQT ANC OUT HPHR Enable", SND_SOC_NOPM,
  2224. INTERP_HPHR, 0, &anc_hphr_pa_switch, aqt_anc_out_switch_cb,
  2225. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
  2226. SND_SOC_DAPM_MIXER("AQT RX INT1 MIX2", SND_SOC_NOPM, 0, 0, NULL, 0),
  2227. SND_SOC_DAPM_MIXER("AQT RX INT2 MIX2", SND_SOC_NOPM, 0, 0, NULL, 0),
  2228. AQT_DAPM_MUX("AQT ANC0 FB MUX", 0, anc0_fb),
  2229. AQT_DAPM_MUX("AQT ANC1 FB MUX", 0, anc1_fb),
  2230. SND_SOC_DAPM_INPUT("AQT AMIC1"),
  2231. SND_SOC_DAPM_INPUT("AQT AMIC2"),
  2232. SND_SOC_DAPM_INPUT("AQT AMIC3"),
  2233. SND_SOC_DAPM_MIXER("AQT I2S_L RX", SND_SOC_NOPM, 0, 0, NULL, 0),
  2234. SND_SOC_DAPM_MIXER("AQT I2S_R RX", SND_SOC_NOPM, 0, 0, NULL, 0),
  2235. SND_SOC_DAPM_AIF_IN_E("AQT AIF1 PB", "AQT AIF1 Playback", 0,
  2236. SND_SOC_NOPM, AIF1_PB, 0, aqt_codec_enable_i2s_rx,
  2237. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2238. SND_SOC_DAPM_MUX_E("AQT RX INT1_1 MUX", SND_SOC_NOPM, INTERP_HPHL, 0,
  2239. &rx_int1_1_mux, aqt_codec_enable_main_path,
  2240. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2241. SND_SOC_DAPM_POST_PMD),
  2242. SND_SOC_DAPM_MUX_E("AQT RX INT2_1 MUX", SND_SOC_NOPM, INTERP_HPHR, 0,
  2243. &rx_int2_1_mux, aqt_codec_enable_main_path,
  2244. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2245. SND_SOC_DAPM_POST_PMD),
  2246. SND_SOC_DAPM_MUX_E("AQT RX INT1_2 MUX", SND_SOC_NOPM, INTERP_HPHL, 0,
  2247. &rx_int1_2_mux, aqt_codec_enable_mix_path,
  2248. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2249. SND_SOC_DAPM_POST_PMD),
  2250. SND_SOC_DAPM_MUX_E("AQT RX INT2_2 MUX", SND_SOC_NOPM, INTERP_HPHR, 0,
  2251. &rx_int2_2_mux, aqt_codec_enable_mix_path,
  2252. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2253. SND_SOC_DAPM_POST_PMD),
  2254. AQT_DAPM_MUX("AQT RX INT1_1 INTERP", 0, rx_int1_1_interp),
  2255. AQT_DAPM_MUX("AQT RX INT1_2 INTERP", 0, rx_int1_2_interp),
  2256. AQT_DAPM_MUX("AQT RX INT2_1 INTERP", 0, rx_int2_1_interp),
  2257. AQT_DAPM_MUX("AQT RX INT2_2 INTERP", 0, rx_int2_2_interp),
  2258. SND_SOC_DAPM_MIXER("AQT RX INT1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  2259. SND_SOC_DAPM_MIXER("AQT RX INT2 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  2260. SND_SOC_DAPM_MUX_E("AQT ASRC0 MUX", SND_SOC_NOPM, ASRC0, 0,
  2261. &asrc0_mux, aqt_codec_enable_asrc_resampler,
  2262. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2263. SND_SOC_DAPM_MUX_E("AQT ASRC1 MUX", SND_SOC_NOPM, ASRC1, 0,
  2264. &asrc1_mux, aqt_codec_enable_asrc_resampler,
  2265. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2266. AQT_DAPM_MUX("AQT RX INT1 DEM MUX", 0, rx_int1_dem),
  2267. AQT_DAPM_MUX("AQT RX INT2 DEM MUX", 0, rx_int2_dem),
  2268. SND_SOC_DAPM_DAC_E("AQT RX INT1 DAC", NULL, AQT1000_ANA_HPH,
  2269. 5, 0, aqt_codec_hphl_dac_event,
  2270. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2271. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  2272. SND_SOC_DAPM_DAC_E("AQT RX INT2 DAC", NULL, AQT1000_ANA_HPH,
  2273. 4, 0, aqt_codec_hphr_dac_event,
  2274. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2275. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  2276. SND_SOC_DAPM_PGA_E("AQT HPHL PA", AQT1000_ANA_HPH, 7, 0, NULL, 0,
  2277. aqt_codec_enable_hphl_pa,
  2278. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2279. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  2280. SND_SOC_DAPM_PGA_E("AQT HPHR PA", AQT1000_ANA_HPH, 6, 0, NULL, 0,
  2281. aqt_codec_enable_hphr_pa,
  2282. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2283. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  2284. SND_SOC_DAPM_PGA_E("AQT ANC HPHL PA", SND_SOC_NOPM, 0, 0, NULL, 0,
  2285. aqt_codec_enable_hphl_pa,
  2286. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2287. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  2288. SND_SOC_DAPM_PGA_E("AQT ANC HPHR PA", SND_SOC_NOPM, 0, 0, NULL, 0,
  2289. aqt_codec_enable_hphr_pa,
  2290. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2291. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  2292. SND_SOC_DAPM_OUTPUT("AQT HPHL"),
  2293. SND_SOC_DAPM_OUTPUT("AQT HPHR"),
  2294. SND_SOC_DAPM_OUTPUT("AQT ANC HPHL"),
  2295. SND_SOC_DAPM_OUTPUT("AQT ANC HPHR"),
  2296. SND_SOC_DAPM_MIXER_E("AQT IIR0", AQT1000_CDC_SIDETONE_IIR0_IIR_PATH_CTL,
  2297. 4, 0, NULL, 0, aqt_codec_set_iir_gain,
  2298. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
  2299. SND_SOC_DAPM_MIXER("AQT SRC0",
  2300. AQT1000_CDC_SIDETONE_SRC0_ST_SRC_PATH_CTL,
  2301. 4, 0, NULL, 0),
  2302. SND_SOC_DAPM_MICBIAS_E("AQT MIC BIAS1", SND_SOC_NOPM, 0, 0,
  2303. aqt_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
  2304. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  2305. SND_SOC_DAPM_SUPPLY("AQT RX_BIAS", SND_SOC_NOPM, 0, 0,
  2306. aqt_codec_enable_rx_bias,
  2307. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2308. SND_SOC_DAPM_SUPPLY("AQT RX INT1 NATIVE SUPPLY", SND_SOC_NOPM,
  2309. INTERP_HPHL, 0, aqt_enable_native_supply,
  2310. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
  2311. SND_SOC_DAPM_SUPPLY("AQT RX INT2 NATIVE SUPPLY", SND_SOC_NOPM,
  2312. INTERP_HPHR, 0, aqt_enable_native_supply,
  2313. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
  2314. AQT_DAPM_MUX("AQT RX INT1_1 NATIVE MUX", 0, int1_1_native),
  2315. AQT_DAPM_MUX("AQT RX INT2_1 NATIVE MUX", 0, int2_1_native),
  2316. };
  2317. static int aqt_startup(struct snd_pcm_substream *substream,
  2318. struct snd_soc_dai *dai)
  2319. {
  2320. pr_debug("%s(): substream = %s stream = %d\n", __func__,
  2321. substream->name, substream->stream);
  2322. return 0;
  2323. }
  2324. static void aqt_shutdown(struct snd_pcm_substream *substream,
  2325. struct snd_soc_dai *dai)
  2326. {
  2327. pr_debug("%s(): substream = %s stream = %d\n", __func__,
  2328. substream->name, substream->stream);
  2329. }
  2330. static int aqt_set_decimator_rate(struct snd_soc_dai *dai,
  2331. u32 sample_rate)
  2332. {
  2333. struct snd_soc_codec *codec = dai->codec;
  2334. u8 tx_fs_rate = 0;
  2335. u8 tx_mux_sel = 0, tx0_mux_sel = 0, tx1_mux_sel = 0;
  2336. u16 tx_path_ctl_reg = 0;
  2337. switch (sample_rate) {
  2338. case 8000:
  2339. tx_fs_rate = 0;
  2340. break;
  2341. case 16000:
  2342. tx_fs_rate = 1;
  2343. break;
  2344. case 32000:
  2345. tx_fs_rate = 3;
  2346. break;
  2347. case 48000:
  2348. tx_fs_rate = 4;
  2349. break;
  2350. case 96000:
  2351. tx_fs_rate = 5;
  2352. break;
  2353. case 192000:
  2354. tx_fs_rate = 6;
  2355. break;
  2356. default:
  2357. dev_err(codec->dev, "%s: Invalid TX sample rate: %d\n",
  2358. __func__, sample_rate);
  2359. return -EINVAL;
  2360. };
  2361. /* Find which decimator path is enabled */
  2362. tx_mux_sel = snd_soc_read(codec, AQT1000_CDC_IF_ROUTER_TX_MUX_CFG0);
  2363. tx0_mux_sel = (tx_mux_sel & 0x03);
  2364. tx1_mux_sel = (tx_mux_sel & 0xC0);
  2365. if (tx0_mux_sel) {
  2366. tx_path_ctl_reg = AQT1000_CDC_TX0_TX_PATH_CTL +
  2367. ((tx0_mux_sel - 1) * 16);
  2368. snd_soc_update_bits(codec, tx_path_ctl_reg, 0x0F, tx_fs_rate);
  2369. }
  2370. if (tx1_mux_sel) {
  2371. tx_path_ctl_reg = AQT1000_CDC_TX0_TX_PATH_CTL +
  2372. ((tx1_mux_sel - 1) * 16);
  2373. snd_soc_update_bits(codec, tx_path_ctl_reg, 0x0F, tx_fs_rate);
  2374. }
  2375. return 0;
  2376. }
  2377. static int aqt_set_interpolator_rate(struct snd_soc_dai *dai,
  2378. u32 sample_rate)
  2379. {
  2380. struct snd_soc_codec *codec = dai->codec;
  2381. int rate_val = 0;
  2382. int i;
  2383. for (i = 0; i < ARRAY_SIZE(sr_val_tbl); i++) {
  2384. if (sample_rate == sr_val_tbl[i].sample_rate) {
  2385. rate_val = sr_val_tbl[i].rate_val;
  2386. break;
  2387. }
  2388. }
  2389. if ((i == ARRAY_SIZE(sr_val_tbl)) || (rate_val < 0)) {
  2390. dev_err(codec->dev, "%s: Unsupported sample rate: %d\n",
  2391. __func__, sample_rate);
  2392. return -EINVAL;
  2393. }
  2394. /* TODO - Set the rate only to enabled path */
  2395. /* Set Primary interpolator rate */
  2396. snd_soc_update_bits(codec, AQT1000_CDC_RX1_RX_PATH_CTL,
  2397. 0x0F, (u8)rate_val);
  2398. snd_soc_update_bits(codec, AQT1000_CDC_RX2_RX_PATH_CTL,
  2399. 0x0F, (u8)rate_val);
  2400. /* Set mixing path interpolator rate */
  2401. snd_soc_update_bits(codec, AQT1000_CDC_RX1_RX_PATH_MIX_CTL,
  2402. 0x0F, (u8)rate_val);
  2403. snd_soc_update_bits(codec, AQT1000_CDC_RX2_RX_PATH_MIX_CTL,
  2404. 0x0F, (u8)rate_val);
  2405. return 0;
  2406. }
  2407. static int aqt_prepare(struct snd_pcm_substream *substream,
  2408. struct snd_soc_dai *dai)
  2409. {
  2410. pr_debug("%s(): substream = %s stream = %d\n", __func__,
  2411. substream->name, substream->stream);
  2412. return 0;
  2413. }
  2414. static int aqt_hw_params(struct snd_pcm_substream *substream,
  2415. struct snd_pcm_hw_params *params,
  2416. struct snd_soc_dai *dai)
  2417. {
  2418. struct aqt1000 *aqt = snd_soc_codec_get_drvdata(dai->codec);
  2419. int ret = 0;
  2420. dev_dbg(aqt->dev, "%s: dai_name = %s DAI-ID %x rate %d num_ch %d\n",
  2421. __func__, dai->name, dai->id, params_rate(params),
  2422. params_channels(params));
  2423. switch (substream->stream) {
  2424. case SNDRV_PCM_STREAM_PLAYBACK:
  2425. ret = aqt_set_interpolator_rate(dai, params_rate(params));
  2426. if (ret) {
  2427. dev_err(aqt->dev, "%s: cannot set sample rate: %u\n",
  2428. __func__, params_rate(params));
  2429. return ret;
  2430. }
  2431. switch (params_width(params)) {
  2432. case 16:
  2433. aqt->dai[dai->id].bit_width = 16;
  2434. break;
  2435. case 24:
  2436. aqt->dai[dai->id].bit_width = 24;
  2437. break;
  2438. case 32:
  2439. aqt->dai[dai->id].bit_width = 32;
  2440. break;
  2441. default:
  2442. return -EINVAL;
  2443. }
  2444. aqt->dai[dai->id].rate = params_rate(params);
  2445. break;
  2446. case SNDRV_PCM_STREAM_CAPTURE:
  2447. ret = aqt_set_decimator_rate(dai, params_rate(params));
  2448. if (ret) {
  2449. dev_err(aqt->dev,
  2450. "%s: cannot set TX Decimator rate: %d\n",
  2451. __func__, ret);
  2452. return ret;
  2453. }
  2454. switch (params_width(params)) {
  2455. case 16:
  2456. aqt->dai[dai->id].bit_width = 16;
  2457. break;
  2458. case 24:
  2459. aqt->dai[dai->id].bit_width = 24;
  2460. break;
  2461. default:
  2462. dev_err(aqt->dev, "%s: Invalid format 0x%x\n",
  2463. __func__, params_width(params));
  2464. return -EINVAL;
  2465. };
  2466. aqt->dai[dai->id].rate = params_rate(params);
  2467. break;
  2468. default:
  2469. dev_err(aqt->dev, "%s: Invalid stream type %d\n", __func__,
  2470. substream->stream);
  2471. return -EINVAL;
  2472. };
  2473. return 0;
  2474. }
  2475. static struct snd_soc_dai_ops aqt_dai_ops = {
  2476. .startup = aqt_startup,
  2477. .shutdown = aqt_shutdown,
  2478. .hw_params = aqt_hw_params,
  2479. .prepare = aqt_prepare,
  2480. };
  2481. struct snd_soc_dai_driver aqt_dai[] = {
  2482. {
  2483. .name = "aqt_rx1",
  2484. .id = AIF1_PB,
  2485. .playback = {
  2486. .stream_name = "AQT AIF1 Playback",
  2487. .rates = AQT1000_RATES_MASK | AQT1000_FRAC_RATES_MASK,
  2488. .formats = AQT1000_FORMATS_S16_S24_S32_LE,
  2489. .rate_min = 8000,
  2490. .rate_max = 384000,
  2491. .channels_min = 1,
  2492. .channels_max = 2,
  2493. },
  2494. .ops = &aqt_dai_ops,
  2495. },
  2496. {
  2497. .name = "aqt_tx1",
  2498. .id = AIF1_CAP,
  2499. .capture = {
  2500. .stream_name = "AQT AIF1 Capture",
  2501. .rates = AQT1000_RATES_MASK,
  2502. .formats = AQT1000_FORMATS_S16_S24_LE,
  2503. .rate_min = 8000,
  2504. .rate_max = 192000,
  2505. .channels_min = 1,
  2506. .channels_max = 2,
  2507. },
  2508. .ops = &aqt_dai_ops,
  2509. },
  2510. };
  2511. static int aqt_enable_mclk(struct aqt1000 *aqt)
  2512. {
  2513. struct snd_soc_codec *codec = aqt->codec;
  2514. /* Enable mclk requires master bias to be enabled first */
  2515. if (aqt->master_bias_users <= 0) {
  2516. dev_err(aqt->dev,
  2517. "%s: Cannot turn on MCLK, BG is not enabled\n",
  2518. __func__);
  2519. return -EINVAL;
  2520. }
  2521. if (++aqt->mclk_users == 1) {
  2522. /* Set clock div 2 */
  2523. snd_soc_update_bits(codec,
  2524. AQT1000_CLK_SYS_MCLK1_PRG, 0x0C, 0x04);
  2525. snd_soc_update_bits(codec,
  2526. AQT1000_CLK_SYS_MCLK1_PRG, 0x10, 0x10);
  2527. snd_soc_update_bits(codec,
  2528. AQT1000_CDC_CLK_RST_CTRL_FS_CNT_CONTROL,
  2529. 0x01, 0x01);
  2530. snd_soc_update_bits(codec,
  2531. AQT1000_CDC_CLK_RST_CTRL_MCLK_CONTROL,
  2532. 0x01, 0x01);
  2533. /*
  2534. * 10us sleep is required after clock is enabled
  2535. * as per HW requirement
  2536. */
  2537. usleep_range(10, 15);
  2538. }
  2539. dev_dbg(aqt->dev, "%s: mclk_users: %d\n", __func__, aqt->mclk_users);
  2540. return 0;
  2541. }
  2542. static int aqt_disable_mclk(struct aqt1000 *aqt)
  2543. {
  2544. struct snd_soc_codec *codec = aqt->codec;
  2545. if (aqt->mclk_users <= 0) {
  2546. dev_err(aqt->dev, "%s: No mclk users, cannot disable mclk\n",
  2547. __func__);
  2548. return -EINVAL;
  2549. }
  2550. if (--aqt->mclk_users == 0) {
  2551. snd_soc_update_bits(codec,
  2552. AQT1000_CDC_CLK_RST_CTRL_MCLK_CONTROL,
  2553. 0x01, 0x00);
  2554. snd_soc_update_bits(codec,
  2555. AQT1000_CDC_CLK_RST_CTRL_FS_CNT_CONTROL,
  2556. 0x01, 0x00);
  2557. snd_soc_update_bits(codec,
  2558. AQT1000_CLK_SYS_MCLK1_PRG, 0x10, 0x00);
  2559. }
  2560. dev_dbg(codec->dev, "%s: mclk_users: %d\n", __func__, aqt->mclk_users);
  2561. return 0;
  2562. }
  2563. static int aqt_enable_master_bias(struct aqt1000 *aqt)
  2564. {
  2565. struct snd_soc_codec *codec = aqt->codec;
  2566. mutex_lock(&aqt->master_bias_lock);
  2567. aqt->master_bias_users++;
  2568. if (aqt->master_bias_users == 1) {
  2569. snd_soc_update_bits(codec, AQT1000_ANA_BIAS, 0x80, 0x80);
  2570. snd_soc_update_bits(codec, AQT1000_ANA_BIAS, 0x40, 0x40);
  2571. /*
  2572. * 1ms delay is required after pre-charge is enabled
  2573. * as per HW requirement
  2574. */
  2575. usleep_range(1000, 1100);
  2576. snd_soc_update_bits(codec, AQT1000_ANA_BIAS, 0x40, 0x00);
  2577. }
  2578. mutex_unlock(&aqt->master_bias_lock);
  2579. return 0;
  2580. }
  2581. static int aqt_disable_master_bias(struct aqt1000 *aqt)
  2582. {
  2583. struct snd_soc_codec *codec = aqt->codec;
  2584. mutex_lock(&aqt->master_bias_lock);
  2585. if (aqt->master_bias_users <= 0) {
  2586. mutex_unlock(&aqt->master_bias_lock);
  2587. return -EINVAL;
  2588. }
  2589. aqt->master_bias_users--;
  2590. if (aqt->master_bias_users == 0)
  2591. snd_soc_update_bits(codec, AQT1000_ANA_BIAS, 0x80, 0x00);
  2592. mutex_unlock(&aqt->master_bias_lock);
  2593. return 0;
  2594. }
  2595. static int aqt_cdc_req_mclk_enable(struct aqt1000 *aqt,
  2596. bool enable)
  2597. {
  2598. int ret = 0;
  2599. if (enable) {
  2600. ret = clk_prepare_enable(aqt->ext_clk);
  2601. if (ret) {
  2602. dev_err(aqt->dev, "%s: ext clk enable failed\n",
  2603. __func__);
  2604. goto done;
  2605. }
  2606. /* Get BG */
  2607. aqt_enable_master_bias(aqt);
  2608. /* Get MCLK */
  2609. aqt_enable_mclk(aqt);
  2610. } else {
  2611. /* put MCLK */
  2612. aqt_disable_mclk(aqt);
  2613. /* put BG */
  2614. if (aqt_disable_master_bias(aqt))
  2615. dev_err(aqt->dev, "%s: master bias disable failed\n",
  2616. __func__);
  2617. clk_disable_unprepare(aqt->ext_clk);
  2618. }
  2619. done:
  2620. return ret;
  2621. }
  2622. static int __aqt_cdc_mclk_enable_locked(struct aqt1000 *aqt,
  2623. bool enable)
  2624. {
  2625. int ret = 0;
  2626. dev_dbg(aqt->dev, "%s: mclk_enable = %u\n", __func__, enable);
  2627. if (enable)
  2628. ret = aqt_cdc_req_mclk_enable(aqt, true);
  2629. else
  2630. aqt_cdc_req_mclk_enable(aqt, false);
  2631. return ret;
  2632. }
  2633. static int __aqt_cdc_mclk_enable(struct aqt1000 *aqt,
  2634. bool enable)
  2635. {
  2636. int ret;
  2637. mutex_lock(&aqt->cdc_bg_clk_lock);
  2638. ret = __aqt_cdc_mclk_enable_locked(aqt, enable);
  2639. mutex_unlock(&aqt->cdc_bg_clk_lock);
  2640. return ret;
  2641. }
  2642. /**
  2643. * aqt_cdc_mclk_enable - Enable/disable codec mclk
  2644. *
  2645. * @codec: codec instance
  2646. * @enable: Indicates clk enable or disable
  2647. *
  2648. * Returns 0 on Success and error on failure
  2649. */
  2650. int aqt_cdc_mclk_enable(struct snd_soc_codec *codec, bool enable)
  2651. {
  2652. struct aqt1000 *aqt = snd_soc_codec_get_drvdata(codec);
  2653. return __aqt_cdc_mclk_enable(aqt, enable);
  2654. }
  2655. EXPORT_SYMBOL(aqt_cdc_mclk_enable);
  2656. /*
  2657. * aqt_get_micb_vout_ctl_val: converts micbias from volts to register value
  2658. * @micb_mv: micbias in mv
  2659. *
  2660. * return register value converted
  2661. */
  2662. int aqt_get_micb_vout_ctl_val(u32 micb_mv)
  2663. {
  2664. /* min micbias voltage is 1V and maximum is 2.85V */
  2665. if (micb_mv < 1000 || micb_mv > 2850) {
  2666. pr_err("%s: unsupported micbias voltage\n", __func__);
  2667. return -EINVAL;
  2668. }
  2669. return (micb_mv - 1000) / 50;
  2670. }
  2671. EXPORT_SYMBOL(aqt_get_micb_vout_ctl_val);
  2672. static int aqt_set_micbias(struct aqt1000 *aqt,
  2673. struct aqt1000_pdata *pdata)
  2674. {
  2675. struct snd_soc_codec *codec = aqt->codec;
  2676. int vout_ctl_1;
  2677. if (!pdata) {
  2678. dev_err(codec->dev, "%s: NULL pdata\n", __func__);
  2679. return -ENODEV;
  2680. }
  2681. /* set micbias voltage */
  2682. vout_ctl_1 = aqt_get_micb_vout_ctl_val(pdata->micbias.micb1_mv);
  2683. if (vout_ctl_1 < 0)
  2684. return -EINVAL;
  2685. snd_soc_update_bits(codec, AQT1000_ANA_MICB1, 0x3F, vout_ctl_1);
  2686. return 0;
  2687. }
  2688. static ssize_t aqt_codec_version_read(struct snd_info_entry *entry,
  2689. void *file_private_data,
  2690. struct file *file,
  2691. char __user *buf, size_t count,
  2692. loff_t pos)
  2693. {
  2694. char buffer[AQT_VERSION_ENTRY_SIZE];
  2695. int len = 0;
  2696. len = snprintf(buffer, sizeof(buffer), "AQT1000_1_0\n");
  2697. return simple_read_from_buffer(buf, count, &pos, buffer, len);
  2698. }
  2699. static struct snd_info_entry_ops aqt_codec_info_ops = {
  2700. .read = aqt_codec_version_read,
  2701. };
  2702. /*
  2703. * aqt_codec_info_create_codec_entry - creates aqt1000 module
  2704. * @codec_root: The parent directory
  2705. * @codec: Codec instance
  2706. *
  2707. * Creates aqt1000 module and version entry under the given
  2708. * parent directory.
  2709. *
  2710. * Return: 0 on success or negative error code on failure.
  2711. */
  2712. int aqt_codec_info_create_codec_entry(struct snd_info_entry *codec_root,
  2713. struct snd_soc_codec *codec)
  2714. {
  2715. struct snd_info_entry *version_entry;
  2716. struct aqt1000 *aqt;
  2717. struct snd_soc_card *card;
  2718. if (!codec_root || !codec)
  2719. return -EINVAL;
  2720. aqt = snd_soc_codec_get_drvdata(codec);
  2721. if (!aqt) {
  2722. dev_dbg(codec->dev, "%s: aqt is NULL\n", __func__);
  2723. return _EINVAL;
  2724. }
  2725. card = codec->component.card;
  2726. aqt->entry = snd_info_create_subdir(codec_root->module,
  2727. "aqt1000", codec_root);
  2728. if (!aqt->entry) {
  2729. dev_dbg(codec->dev, "%s: failed to create aqt1000 entry\n",
  2730. __func__);
  2731. return -ENOMEM;
  2732. }
  2733. version_entry = snd_info_create_card_entry(card->snd_card,
  2734. "version",
  2735. aqt->entry);
  2736. if (!version_entry) {
  2737. dev_dbg(codec->dev, "%s: failed to create aqt1000 version entry\n",
  2738. __func__);
  2739. return -ENOMEM;
  2740. }
  2741. version_entry->private_data = aqt;
  2742. version_entry->size = AQT_VERSION_ENTRY_SIZE;
  2743. version_entry->content = SNDRV_INFO_CONTENT_DATA;
  2744. version_entry->c.ops = &aqt_codec_info_ops;
  2745. if (snd_info_register(version_entry) < 0) {
  2746. snd_info_free_entry(version_entry);
  2747. return -ENOMEM;
  2748. }
  2749. aqt->version_entry = version_entry;
  2750. return 0;
  2751. }
  2752. EXPORT_SYMBOL(aqt_codec_info_create_codec_entry);
  2753. static const struct aqt_reg_mask_val aqt_codec_reg_init[] = {
  2754. {AQT1000_CHIP_CFG0_CLK_CFG_MCLK, 0x04, 0x00},
  2755. {AQT1000_CHIP_CFG0_EFUSE_CTL, 0x01, 0x01},
  2756. };
  2757. static const struct aqt_reg_mask_val aqt_codec_reg_update[] = {
  2758. {AQT1000_CDC_CLK_RST_CTRL_MCLK_CONTROL, 0x01, 0x01},
  2759. {AQT1000_CDC_CLK_RST_CTRL_FS_CNT_CONTROL, 0x01, 0x01},
  2760. {AQT1000_CHIP_CFG0_CLK_CTL_CDC_DIG, 0x01, 0x01},
  2761. {AQT1000_LDOH_MODE, 0x1F, 0x0B},
  2762. {AQT1000_MICB1_TEST_CTL_2, 0x07, 0x01},
  2763. {AQT1000_MICB1_MISC_MICB1_INM_RES_BIAS, 0x03, 0x02},
  2764. {AQT1000_MICB1_MISC_MICB1_INM_RES_BIAS, 0x0C, 0x08},
  2765. {AQT1000_MICB1_MISC_MICB1_INM_RES_BIAS, 0x30, 0x20},
  2766. {AQT1000_CDC_TX0_TX_PATH_CFG1, 0x01, 0x00},
  2767. {AQT1000_CDC_TX1_TX_PATH_CFG1, 0x01, 0x00},
  2768. {AQT1000_CDC_TX2_TX_PATH_CFG1, 0x01, 0x00},
  2769. };
  2770. static void aqt_codec_init_reg(struct aqt1000 *priv)
  2771. {
  2772. struct snd_soc_codec *codec = priv->codec;
  2773. u32 i;
  2774. for (i = 0; i < ARRAY_SIZE(aqt_codec_reg_init); i++)
  2775. snd_soc_update_bits(codec,
  2776. aqt_codec_reg_init[i].reg,
  2777. aqt_codec_reg_init[i].mask,
  2778. aqt_codec_reg_init[i].val);
  2779. }
  2780. static void aqt_codec_update_reg(struct aqt1000 *priv)
  2781. {
  2782. struct snd_soc_codec *codec = priv->codec;
  2783. u32 i;
  2784. for (i = 0; i < ARRAY_SIZE(aqt_codec_reg_update); i++)
  2785. snd_soc_update_bits(codec,
  2786. aqt_codec_reg_update[i].reg,
  2787. aqt_codec_reg_update[i].mask,
  2788. aqt_codec_reg_update[i].val);
  2789. }
  2790. static int aqt_soc_codec_probe(struct snd_soc_codec *codec)
  2791. {
  2792. struct aqt1000 *aqt;
  2793. struct aqt1000_pdata *pdata;
  2794. struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
  2795. int i, ret = 0;
  2796. dev_dbg(codec->dev, "%s()\n", __func__);
  2797. aqt = snd_soc_codec_get_drvdata(codec);
  2798. mutex_init(&aqt->codec_mutex);
  2799. mutex_init(&aqt->i2s_lock);
  2800. /* Class-H Init */
  2801. aqt_clsh_init(&aqt->clsh_d);
  2802. /* Default HPH Mode to Class-H Low HiFi */
  2803. aqt->hph_mode = CLS_H_LOHIFI;
  2804. aqt->fw_data = devm_kzalloc(codec->dev, sizeof(*(aqt->fw_data)),
  2805. GFP_KERNEL);
  2806. if (!aqt->fw_data)
  2807. goto err;
  2808. set_bit(WCD9XXX_ANC_CAL, aqt->fw_data->cal_bit);
  2809. set_bit(WCD9XXX_MBHC_CAL, aqt->fw_data->cal_bit);
  2810. ret = wcd_cal_create_hwdep(aqt->fw_data,
  2811. AQT1000_CODEC_HWDEP_NODE, codec);
  2812. if (ret < 0) {
  2813. dev_err(codec->dev, "%s hwdep failed %d\n", __func__, ret);
  2814. goto err_hwdep;
  2815. }
  2816. aqt->codec = codec;
  2817. for (i = 0; i < COMPANDER_MAX; i++)
  2818. aqt->comp_enabled[i] = 0;
  2819. aqt_cdc_mclk_enable(codec, true);
  2820. aqt_codec_init_reg(aqt);
  2821. aqt_cdc_mclk_enable(codec, false);
  2822. /* Add 100usec delay as per HW requirement */
  2823. usleep_range(100, 110);
  2824. aqt_codec_update_reg(aqt);
  2825. pdata = dev_get_platdata(codec->dev);
  2826. /* If 1.8v is supplied externally, then disable internal 1.8v supply */
  2827. for (i = 0; i < pdata->num_supplies; i++) {
  2828. if (!strcmp(pdata->regulator->name, "aqt_vdd1p8")) {
  2829. snd_soc_update_bits(codec, AQT1000_BUCK_5V_EN_CTL,
  2830. 0x03, 0x00);
  2831. dev_dbg(codec->dev, "%s: Disabled internal supply\n",
  2832. __func__);
  2833. break;
  2834. }
  2835. }
  2836. aqt_set_micbias(aqt, pdata);
  2837. snd_soc_dapm_add_routes(dapm, aqt_audio_map,
  2838. ARRAY_SIZE(aqt_audio_map));
  2839. for (i = 0; i < NUM_CODEC_DAIS; i++) {
  2840. INIT_LIST_HEAD(&aqt->dai[i].ch_list);
  2841. init_waitqueue_head(&aqt->dai[i].dai_wait);
  2842. }
  2843. for (i = 0; i < AQT1000_NUM_DECIMATORS; i++) {
  2844. aqt->tx_hpf_work[i].aqt = aqt;
  2845. aqt->tx_hpf_work[i].decimator = i;
  2846. INIT_DELAYED_WORK(&aqt->tx_hpf_work[i].dwork,
  2847. aqt_tx_hpf_corner_freq_callback);
  2848. aqt->tx_mute_dwork[i].aqt = aqt;
  2849. aqt->tx_mute_dwork[i].decimator = i;
  2850. INIT_DELAYED_WORK(&aqt->tx_mute_dwork[i].dwork,
  2851. aqt_tx_mute_update_callback);
  2852. }
  2853. mutex_lock(&aqt->codec_mutex);
  2854. snd_soc_dapm_disable_pin(dapm, "AQT ANC HPHL PA");
  2855. snd_soc_dapm_disable_pin(dapm, "AQT ANC HPHR PA");
  2856. snd_soc_dapm_disable_pin(dapm, "AQT ANC HPHL");
  2857. snd_soc_dapm_disable_pin(dapm, "AQT ANC HPHR");
  2858. mutex_unlock(&aqt->codec_mutex);
  2859. snd_soc_dapm_ignore_suspend(dapm, "AQT AIF1 Playback");
  2860. snd_soc_dapm_ignore_suspend(dapm, "AQT AIF1 Capture");
  2861. snd_soc_dapm_sync(dapm);
  2862. return ret;
  2863. err_hwdep:
  2864. devm_kfree(codec->dev, aqt->fw_data);
  2865. aqt->fw_data = NULL;
  2866. err:
  2867. mutex_destroy(&aqt->i2s_lock);
  2868. mutex_destroy(&aqt->codec_mutex);
  2869. return ret;
  2870. }
  2871. static int aqt_soc_codec_remove(struct snd_soc_codec *codec)
  2872. {
  2873. struct aqt1000 *aqt = snd_soc_codec_get_drvdata(codec);
  2874. mutex_destroy(&aqt->i2s_lock);
  2875. mutex_destroy(&aqt->codec_mutex);
  2876. return 0;
  2877. }
  2878. static struct regmap *aqt_get_regmap(struct device *dev)
  2879. {
  2880. struct aqt1000 *control = dev_get_drvdata(dev);
  2881. return control->regmap;
  2882. }
  2883. struct snd_soc_codec_driver snd_cdc_dev_aqt = {
  2884. .probe = aqt_soc_codec_probe,
  2885. .remove = aqt_soc_codec_remove,
  2886. .get_regmap = aqt_get_regmap,
  2887. .component_driver = {
  2888. .controls = aqt_snd_controls,
  2889. .num_controls = ARRAY_SIZE(aqt_snd_controls),
  2890. .dapm_widgets = aqt_dapm_widgets,
  2891. .num_dapm_widgets = ARRAY_SIZE(aqt_dapm_widgets),
  2892. .dapm_routes = aqt_audio_map,
  2893. .num_dapm_routes = ARRAY_SIZE(aqt_audio_map),
  2894. },
  2895. };
  2896. /*
  2897. * aqt_register_codec: Register the device to ASoC
  2898. * @dev: device
  2899. *
  2900. * return 0 success or error code in case of failure
  2901. */
  2902. int aqt_register_codec(struct device *dev)
  2903. {
  2904. return snd_soc_register_codec(dev, &snd_cdc_dev_aqt, aqt_dai,
  2905. ARRAY_SIZE(aqt_dai));
  2906. }
  2907. EXPORT_SYMBOL(aqt_register_codec);