rx-macro.c 84 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765
  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/module.h>
  13. #include <linux/init.h>
  14. #include <linux/io.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/clk.h>
  17. #include <sound/soc.h>
  18. #include <sound/pcm.h>
  19. #include <sound/pcm_params.h>
  20. #include <sound/soc-dapm.h>
  21. #include <sound/tlv.h>
  22. #include <soc/swr-wcd.h>
  23. #include "bolero-cdc.h"
  24. #include "bolero-cdc-registers.h"
  25. #include "../msm-cdc-pinctrl.h"
  26. #define RX_MACRO_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
  27. SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 |\
  28. SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000 |\
  29. SNDRV_PCM_RATE_384000)
  30. /* Fractional Rates */
  31. #define RX_MACRO_FRAC_RATES (SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_88200 |\
  32. SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_352800)
  33. #define RX_MACRO_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\
  34. SNDRV_PCM_FMTBIT_S24_LE |\
  35. SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE)
  36. #define RX_MACRO_ECHO_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
  37. SNDRV_PCM_RATE_48000)
  38. #define RX_MACRO_ECHO_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\
  39. SNDRV_PCM_FMTBIT_S24_LE |\
  40. SNDRV_PCM_FMTBIT_S24_3LE)
  41. #define RX_MACRO_MAX_OFFSET 0x1000
  42. #define RX_MACRO_MAX_DMA_CH_PER_PORT 2
  43. #define RX_SWR_STRING_LEN 80
  44. #define RX_MACRO_CHILD_DEVICES_MAX 3
  45. #define RX_MACRO_INTERP_MUX_NUM_INPUTS 3
  46. #define RX_MACRO_SIDETONE_IIR_COEFF_MAX 5
  47. #define STRING(name) #name
  48. #define RX_MACRO_DAPM_ENUM(name, reg, offset, text) \
  49. static SOC_ENUM_SINGLE_DECL(name##_enum, reg, offset, text); \
  50. static const struct snd_kcontrol_new name##_mux = \
  51. SOC_DAPM_ENUM(STRING(name), name##_enum)
  52. #define RX_MACRO_DAPM_ENUM_EXT(name, reg, offset, text, getname, putname) \
  53. static SOC_ENUM_SINGLE_DECL(name##_enum, reg, offset, text); \
  54. static const struct snd_kcontrol_new name##_mux = \
  55. SOC_DAPM_ENUM_EXT(STRING(name), name##_enum, getname, putname)
  56. #define RX_MACRO_DAPM_MUX(name, shift, kctl) \
  57. SND_SOC_DAPM_MUX(name, SND_SOC_NOPM, shift, 0, &kctl##_mux)
  58. #define RX_MACRO_RX_PATH_OFFSET 0x80
  59. #define RX_MACRO_COMP_OFFSET 0x40
  60. enum {
  61. INTERP_HPHL,
  62. INTERP_HPHR,
  63. INTERP_AUX,
  64. INTERP_MAX
  65. };
  66. enum {
  67. RX_MACRO_RX0,
  68. RX_MACRO_RX1,
  69. RX_MACRO_RX2,
  70. RX_MACRO_RX3,
  71. RX_MACRO_RX4,
  72. RX_MACRO_RX5,
  73. RX_MACRO_PORTS_MAX
  74. };
  75. enum {
  76. RX_MACRO_COMP1, /* HPH_L */
  77. RX_MACRO_COMP2, /* HPH_R */
  78. RX_MACRO_COMP_MAX
  79. };
  80. enum {
  81. INTn_1_INP_SEL_ZERO = 0,
  82. INTn_1_INP_SEL_DEC0,
  83. INTn_1_INP_SEL_DEC1,
  84. INTn_1_INP_SEL_IIR0,
  85. INTn_1_INP_SEL_IIR1,
  86. INTn_1_INP_SEL_RX0,
  87. INTn_1_INP_SEL_RX1,
  88. INTn_1_INP_SEL_RX2,
  89. INTn_1_INP_SEL_RX3,
  90. INTn_1_INP_SEL_RX4,
  91. INTn_1_INP_SEL_RX5,
  92. };
  93. enum {
  94. INTn_2_INP_SEL_ZERO = 0,
  95. INTn_2_INP_SEL_RX0,
  96. INTn_2_INP_SEL_RX1,
  97. INTn_2_INP_SEL_RX2,
  98. INTn_2_INP_SEL_RX3,
  99. INTn_2_INP_SEL_RX4,
  100. INTn_2_INP_SEL_RX5,
  101. };
  102. enum {
  103. INTERP_MAIN_PATH,
  104. INTERP_MIX_PATH,
  105. };
  106. /* Codec supports 2 IIR filters */
  107. enum {
  108. IIR0 = 0,
  109. IIR1,
  110. IIR_MAX,
  111. };
  112. /* Each IIR has 5 Filter Stages */
  113. enum {
  114. BAND1 = 0,
  115. BAND2,
  116. BAND3,
  117. BAND4,
  118. BAND5,
  119. BAND_MAX,
  120. };
  121. struct rx_macro_idle_detect_config {
  122. u8 hph_idle_thr;
  123. u8 hph_idle_detect_en;
  124. };
  125. struct interp_sample_rate {
  126. int sample_rate;
  127. int rate_val;
  128. };
  129. static struct interp_sample_rate sr_val_tbl[] = {
  130. {8000, 0x0}, {16000, 0x1}, {32000, 0x3}, {48000, 0x4}, {96000, 0x5},
  131. {192000, 0x6}, {384000, 0x7}, {44100, 0x9}, {88200, 0xA},
  132. {176400, 0xB}, {352800, 0xC},
  133. };
  134. static int rx_macro_hw_params(struct snd_pcm_substream *substream,
  135. struct snd_pcm_hw_params *params,
  136. struct snd_soc_dai *dai);
  137. static int rx_macro_get_channel_map(struct snd_soc_dai *dai,
  138. unsigned int *tx_num, unsigned int *tx_slot,
  139. unsigned int *rx_num, unsigned int *rx_slot);
  140. static int rx_macro_int_dem_inp_mux_put(struct snd_kcontrol *kcontrol,
  141. struct snd_ctl_elem_value *ucontrol);
  142. static int rx_macro_mux_get(struct snd_kcontrol *kcontrol,
  143. struct snd_ctl_elem_value *ucontrol);
  144. static int rx_macro_mux_put(struct snd_kcontrol *kcontrol,
  145. struct snd_ctl_elem_value *ucontrol);
  146. static int rx_macro_enable_interp_clk(struct snd_soc_codec *codec,
  147. int event, int interp_idx);
  148. /* Hold instance to soundwire platform device */
  149. struct rx_swr_ctrl_data {
  150. struct platform_device *rx_swr_pdev;
  151. };
  152. struct rx_swr_ctrl_platform_data {
  153. void *handle; /* holds codec private data */
  154. int (*read)(void *handle, int reg);
  155. int (*write)(void *handle, int reg, int val);
  156. int (*bulk_write)(void *handle, u32 *reg, u32 *val, size_t len);
  157. int (*clk)(void *handle, bool enable);
  158. int (*handle_irq)(void *handle,
  159. irqreturn_t (*swrm_irq_handler)(int irq,
  160. void *data),
  161. void *swrm_handle,
  162. int action);
  163. };
  164. enum {
  165. RX_MACRO_AIF_INVALID = 0,
  166. RX_MACRO_AIF1_PB,
  167. RX_MACRO_AIF2_PB,
  168. RX_MACRO_AIF3_PB,
  169. RX_MACRO_AIF4_PB,
  170. RX_MACRO_MAX_DAIS,
  171. };
  172. enum {
  173. RX_MACRO_AIF1_CAP = 0,
  174. RX_MACRO_AIF2_CAP,
  175. RX_MACRO_AIF3_CAP,
  176. RX_MACRO_MAX_AIF_CAP_DAIS
  177. };
  178. /*
  179. * @dev: rx macro device pointer
  180. * @comp_enabled: compander enable mixer value set
  181. * @prim_int_users: Users of interpolator
  182. * @rx_mclk_users: RX MCLK users count
  183. * @vi_feed_value: VI sense mask
  184. * @swr_clk_lock: to lock swr master clock operations
  185. * @swr_ctrl_data: SoundWire data structure
  186. * @swr_plat_data: Soundwire platform data
  187. * @rx_macro_add_child_devices_work: work for adding child devices
  188. * @rx_swr_gpio_p: used by pinctrl API
  189. * @rx_core_clk: MCLK for rx macro
  190. * @rx_npl_clk: NPL clock for RX soundwire
  191. * @codec: codec handle
  192. */
  193. struct rx_macro_priv {
  194. struct device *dev;
  195. int comp_enabled[RX_MACRO_COMP_MAX];
  196. /* Main path clock users count */
  197. int main_clk_users[INTERP_MAX];
  198. int rx_port_value[RX_MACRO_PORTS_MAX];
  199. u16 prim_int_users[INTERP_MAX];
  200. int rx_mclk_users;
  201. int swr_clk_users;
  202. int clsh_users;
  203. int rx_mclk_cnt;
  204. bool is_native_on;
  205. bool is_ear_mode_on;
  206. u16 mclk_mux;
  207. struct mutex mclk_lock;
  208. struct mutex swr_clk_lock;
  209. struct rx_swr_ctrl_data *swr_ctrl_data;
  210. struct rx_swr_ctrl_platform_data swr_plat_data;
  211. struct work_struct rx_macro_add_child_devices_work;
  212. struct device_node *rx_swr_gpio_p;
  213. struct clk *rx_core_clk;
  214. struct clk *rx_npl_clk;
  215. struct snd_soc_codec *codec;
  216. unsigned long active_ch_mask[RX_MACRO_MAX_DAIS];
  217. unsigned long active_ch_cnt[RX_MACRO_MAX_DAIS];
  218. u16 bit_width[RX_MACRO_MAX_DAIS];
  219. char __iomem *rx_io_base;
  220. char __iomem *rx_mclk_mode_muxsel;
  221. struct rx_macro_idle_detect_config idle_det_cfg;
  222. u8 sidetone_coeff_array[IIR_MAX][BAND_MAX]
  223. [RX_MACRO_SIDETONE_IIR_COEFF_MAX * 4];
  224. struct platform_device *pdev_child_devices
  225. [RX_MACRO_CHILD_DEVICES_MAX];
  226. int child_count;
  227. };
  228. static struct snd_soc_dai_driver rx_macro_dai[];
  229. static const DECLARE_TLV_DB_SCALE(digital_gain, 0, 1, 0);
  230. static const char * const rx_int_mix_mux_text[] = {
  231. "ZERO", "RX0", "RX1", "RX2", "RX3", "RX4", "RX5"
  232. };
  233. static const char * const rx_prim_mix_text[] = {
  234. "ZERO", "DEC0", "DEC1", "IIR0", "IIR1", "RX0", "RX1", "RX2",
  235. "RX3", "RX4", "RX5"
  236. };
  237. static const char * const rx_sidetone_mix_text[] = {
  238. "ZERO", "SRC0", "SRC1", "SRC_SUM"
  239. };
  240. static const char * const rx_echo_mux_text[] = {
  241. "ZERO", "RX_MIX0", "RX_MIX1", "RX_MIX2"
  242. };
  243. static const char * const iir_inp_mux_text[] = {
  244. "ZERO", "DEC0", "DEC1", "DEC2", "DEC3",
  245. "RX0", "RX1", "RX2", "RX3", "RX4", "RX5"
  246. };
  247. static const char * const rx_int_dem_inp_mux_text[] = {
  248. "NORMAL_DSM_OUT", "CLSH_DSM_OUT",
  249. };
  250. static const char * const rx_int0_1_interp_mux_text[] = {
  251. "ZERO", "RX INT0_1 MIX1",
  252. };
  253. static const char * const rx_int1_1_interp_mux_text[] = {
  254. "ZERO", "RX INT1_1 MIX1",
  255. };
  256. static const char * const rx_int2_1_interp_mux_text[] = {
  257. "ZERO", "RX INT2_1 MIX1",
  258. };
  259. static const char * const rx_int0_2_interp_mux_text[] = {
  260. "ZERO", "RX INT0_2 MUX",
  261. };
  262. static const char * const rx_int1_2_interp_mux_text[] = {
  263. "ZERO", "RX INT1_2 MUX",
  264. };
  265. static const char * const rx_int2_2_interp_mux_text[] = {
  266. "ZERO", "RX INT2_2 MUX",
  267. };
  268. static const char *const rx_macro_mux_text[] = {
  269. "ZERO", "AIF1_PB", "AIF2_PB", "AIF3_PB", "AIF4_PB"
  270. };
  271. static const char *const rx_macro_native_text[] = {"OFF", "ON"};
  272. static const struct soc_enum rx_macro_native_enum =
  273. SOC_ENUM_SINGLE_EXT(2, rx_macro_native_text);
  274. static const char *const rx_macro_ear_mode_text[] = {"OFF", "ON"};
  275. static const struct soc_enum rx_macro_ear_mode_enum =
  276. SOC_ENUM_SINGLE_EXT(2, rx_macro_ear_mode_text);
  277. RX_MACRO_DAPM_ENUM(rx_int0_2, BOLERO_CDC_RX_INP_MUX_RX_INT0_CFG1, 0,
  278. rx_int_mix_mux_text);
  279. RX_MACRO_DAPM_ENUM(rx_int1_2, BOLERO_CDC_RX_INP_MUX_RX_INT1_CFG1, 0,
  280. rx_int_mix_mux_text);
  281. RX_MACRO_DAPM_ENUM(rx_int2_2, BOLERO_CDC_RX_INP_MUX_RX_INT2_CFG1, 0,
  282. rx_int_mix_mux_text);
  283. RX_MACRO_DAPM_ENUM(rx_int0_1_mix_inp0, BOLERO_CDC_RX_INP_MUX_RX_INT0_CFG0, 0,
  284. rx_prim_mix_text);
  285. RX_MACRO_DAPM_ENUM(rx_int0_1_mix_inp1, BOLERO_CDC_RX_INP_MUX_RX_INT0_CFG0, 4,
  286. rx_prim_mix_text);
  287. RX_MACRO_DAPM_ENUM(rx_int0_1_mix_inp2, BOLERO_CDC_RX_INP_MUX_RX_INT0_CFG1, 4,
  288. rx_prim_mix_text);
  289. RX_MACRO_DAPM_ENUM(rx_int1_1_mix_inp0, BOLERO_CDC_RX_INP_MUX_RX_INT1_CFG0, 0,
  290. rx_prim_mix_text);
  291. RX_MACRO_DAPM_ENUM(rx_int1_1_mix_inp1, BOLERO_CDC_RX_INP_MUX_RX_INT1_CFG0, 4,
  292. rx_prim_mix_text);
  293. RX_MACRO_DAPM_ENUM(rx_int1_1_mix_inp2, BOLERO_CDC_RX_INP_MUX_RX_INT1_CFG1, 4,
  294. rx_prim_mix_text);
  295. RX_MACRO_DAPM_ENUM(rx_int2_1_mix_inp0, BOLERO_CDC_RX_INP_MUX_RX_INT2_CFG0, 0,
  296. rx_prim_mix_text);
  297. RX_MACRO_DAPM_ENUM(rx_int2_1_mix_inp1, BOLERO_CDC_RX_INP_MUX_RX_INT2_CFG0, 4,
  298. rx_prim_mix_text);
  299. RX_MACRO_DAPM_ENUM(rx_int2_1_mix_inp2, BOLERO_CDC_RX_INP_MUX_RX_INT2_CFG1, 4,
  300. rx_prim_mix_text);
  301. RX_MACRO_DAPM_ENUM(rx_int0_mix2_inp, BOLERO_CDC_RX_INP_MUX_SIDETONE_SRC_CFG0, 2,
  302. rx_sidetone_mix_text);
  303. RX_MACRO_DAPM_ENUM(rx_int1_mix2_inp, BOLERO_CDC_RX_INP_MUX_SIDETONE_SRC_CFG0, 4,
  304. rx_sidetone_mix_text);
  305. RX_MACRO_DAPM_ENUM(rx_int2_mix2_inp, BOLERO_CDC_RX_INP_MUX_SIDETONE_SRC_CFG0, 6,
  306. rx_sidetone_mix_text);
  307. RX_MACRO_DAPM_ENUM(rx_mix_tx0, BOLERO_CDC_RX_INP_MUX_RX_MIX_CFG4, 4,
  308. rx_echo_mux_text);
  309. RX_MACRO_DAPM_ENUM(rx_mix_tx1, BOLERO_CDC_RX_INP_MUX_RX_MIX_CFG4, 0,
  310. rx_echo_mux_text);
  311. RX_MACRO_DAPM_ENUM(rx_mix_tx2, BOLERO_CDC_RX_INP_MUX_RX_MIX_CFG4, 0,
  312. rx_echo_mux_text);
  313. RX_MACRO_DAPM_ENUM(iir0_inp0, BOLERO_CDC_RX_IIR_INP_MUX_IIR0_MIX_CFG0, 0,
  314. iir_inp_mux_text);
  315. RX_MACRO_DAPM_ENUM(iir0_inp1, BOLERO_CDC_RX_IIR_INP_MUX_IIR0_MIX_CFG1, 0,
  316. iir_inp_mux_text);
  317. RX_MACRO_DAPM_ENUM(iir0_inp2, BOLERO_CDC_RX_IIR_INP_MUX_IIR0_MIX_CFG2, 0,
  318. iir_inp_mux_text);
  319. RX_MACRO_DAPM_ENUM(iir0_inp3, BOLERO_CDC_RX_IIR_INP_MUX_IIR0_MIX_CFG3, 0,
  320. iir_inp_mux_text);
  321. RX_MACRO_DAPM_ENUM(iir1_inp0, BOLERO_CDC_RX_IIR_INP_MUX_IIR1_MIX_CFG0, 0,
  322. iir_inp_mux_text);
  323. RX_MACRO_DAPM_ENUM(iir1_inp1, BOLERO_CDC_RX_IIR_INP_MUX_IIR1_MIX_CFG1, 0,
  324. iir_inp_mux_text);
  325. RX_MACRO_DAPM_ENUM(iir1_inp2, BOLERO_CDC_RX_IIR_INP_MUX_IIR1_MIX_CFG2, 0,
  326. iir_inp_mux_text);
  327. RX_MACRO_DAPM_ENUM(iir1_inp3, BOLERO_CDC_RX_IIR_INP_MUX_IIR1_MIX_CFG3, 0,
  328. iir_inp_mux_text);
  329. RX_MACRO_DAPM_ENUM(rx_int0_1_interp, SND_SOC_NOPM, 0,
  330. rx_int0_1_interp_mux_text);
  331. RX_MACRO_DAPM_ENUM(rx_int1_1_interp, SND_SOC_NOPM, 0,
  332. rx_int1_1_interp_mux_text);
  333. RX_MACRO_DAPM_ENUM(rx_int2_1_interp, SND_SOC_NOPM, 0,
  334. rx_int2_1_interp_mux_text);
  335. RX_MACRO_DAPM_ENUM(rx_int0_2_interp, SND_SOC_NOPM, 0,
  336. rx_int0_2_interp_mux_text);
  337. RX_MACRO_DAPM_ENUM(rx_int1_2_interp, SND_SOC_NOPM, 0,
  338. rx_int1_2_interp_mux_text);
  339. RX_MACRO_DAPM_ENUM(rx_int2_2_interp, SND_SOC_NOPM, 0,
  340. rx_int2_2_interp_mux_text);
  341. RX_MACRO_DAPM_ENUM_EXT(rx_int0_dem_inp, BOLERO_CDC_RX_RX0_RX_PATH_CFG1, 0,
  342. rx_int_dem_inp_mux_text, snd_soc_dapm_get_enum_double,
  343. rx_macro_int_dem_inp_mux_put);
  344. RX_MACRO_DAPM_ENUM_EXT(rx_int1_dem_inp, BOLERO_CDC_RX_RX1_RX_PATH_CFG1, 0,
  345. rx_int_dem_inp_mux_text, snd_soc_dapm_get_enum_double,
  346. rx_macro_int_dem_inp_mux_put);
  347. RX_MACRO_DAPM_ENUM_EXT(rx_macro_rx0, SND_SOC_NOPM, 0, rx_macro_mux_text,
  348. rx_macro_mux_get, rx_macro_mux_put);
  349. RX_MACRO_DAPM_ENUM_EXT(rx_macro_rx1, SND_SOC_NOPM, 0, rx_macro_mux_text,
  350. rx_macro_mux_get, rx_macro_mux_put);
  351. RX_MACRO_DAPM_ENUM_EXT(rx_macro_rx2, SND_SOC_NOPM, 0, rx_macro_mux_text,
  352. rx_macro_mux_get, rx_macro_mux_put);
  353. RX_MACRO_DAPM_ENUM_EXT(rx_macro_rx3, SND_SOC_NOPM, 0, rx_macro_mux_text,
  354. rx_macro_mux_get, rx_macro_mux_put);
  355. RX_MACRO_DAPM_ENUM_EXT(rx_macro_rx4, SND_SOC_NOPM, 0, rx_macro_mux_text,
  356. rx_macro_mux_get, rx_macro_mux_put);
  357. RX_MACRO_DAPM_ENUM_EXT(rx_macro_rx5, SND_SOC_NOPM, 0, rx_macro_mux_text,
  358. rx_macro_mux_get, rx_macro_mux_put);
  359. static struct snd_soc_dai_ops rx_macro_dai_ops = {
  360. .hw_params = rx_macro_hw_params,
  361. .get_channel_map = rx_macro_get_channel_map,
  362. };
  363. static struct snd_soc_dai_driver rx_macro_dai[] = {
  364. {
  365. .name = "rx_macro_rx1",
  366. .id = RX_MACRO_AIF1_PB,
  367. .playback = {
  368. .stream_name = "RX_MACRO_AIF1 Playback",
  369. .rates = RX_MACRO_RATES | RX_MACRO_FRAC_RATES,
  370. .formats = RX_MACRO_FORMATS,
  371. .rate_max = 384000,
  372. .rate_min = 8000,
  373. .channels_min = 1,
  374. .channels_max = 2,
  375. },
  376. .ops = &rx_macro_dai_ops,
  377. },
  378. {
  379. .name = "rx_macro_rx2",
  380. .id = RX_MACRO_AIF2_PB,
  381. .playback = {
  382. .stream_name = "RX_MACRO_AIF2 Playback",
  383. .rates = RX_MACRO_RATES | RX_MACRO_FRAC_RATES,
  384. .formats = RX_MACRO_FORMATS,
  385. .rate_max = 384000,
  386. .rate_min = 8000,
  387. .channels_min = 1,
  388. .channels_max = 2,
  389. },
  390. .ops = &rx_macro_dai_ops,
  391. },
  392. {
  393. .name = "rx_macro_rx3",
  394. .id = RX_MACRO_AIF3_PB,
  395. .playback = {
  396. .stream_name = "RX_MACRO_AIF3 Playback",
  397. .rates = RX_MACRO_RATES | RX_MACRO_FRAC_RATES,
  398. .formats = RX_MACRO_FORMATS,
  399. .rate_max = 384000,
  400. .rate_min = 8000,
  401. .channels_min = 1,
  402. .channels_max = 2,
  403. },
  404. .ops = &rx_macro_dai_ops,
  405. },
  406. {
  407. .name = "rx_macro_rx4",
  408. .id = RX_MACRO_AIF4_PB,
  409. .playback = {
  410. .stream_name = "RX_MACRO_AIF4 Playback",
  411. .rates = RX_MACRO_RATES | RX_MACRO_FRAC_RATES,
  412. .formats = RX_MACRO_FORMATS,
  413. .rate_max = 384000,
  414. .rate_min = 8000,
  415. .channels_min = 1,
  416. .channels_max = 2,
  417. },
  418. .ops = &rx_macro_dai_ops,
  419. },
  420. };
  421. static bool rx_macro_get_data(struct snd_soc_codec *codec,
  422. struct device **rx_dev,
  423. struct rx_macro_priv **rx_priv,
  424. const char *func_name)
  425. {
  426. *rx_dev = bolero_get_device_ptr(codec->dev, RX_MACRO);
  427. if (!(*rx_dev)) {
  428. dev_err(codec->dev,
  429. "%s: null device for macro!\n", func_name);
  430. return false;
  431. }
  432. *rx_priv = dev_get_drvdata((*rx_dev));
  433. if (!(*rx_priv)) {
  434. dev_err(codec->dev,
  435. "%s: priv is null for macro!\n", func_name);
  436. return false;
  437. }
  438. if (!(*rx_priv)->codec) {
  439. dev_err(codec->dev,
  440. "%s: tx_priv codec is not initialized!\n", func_name);
  441. return false;
  442. }
  443. return true;
  444. }
  445. static int rx_macro_int_dem_inp_mux_put(struct snd_kcontrol *kcontrol,
  446. struct snd_ctl_elem_value *ucontrol)
  447. {
  448. struct snd_soc_dapm_widget *widget =
  449. snd_soc_dapm_kcontrol_widget(kcontrol);
  450. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm);
  451. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  452. unsigned int val = 0;
  453. unsigned short look_ahead_dly_reg =
  454. BOLERO_CDC_RX_RX0_RX_PATH_CFG0;
  455. val = ucontrol->value.enumerated.item[0];
  456. if (val >= e->items)
  457. return -EINVAL;
  458. dev_dbg(codec->dev, "%s: wname: %s, val: 0x%x\n", __func__,
  459. widget->name, val);
  460. if (e->reg == BOLERO_CDC_RX_RX0_RX_PATH_CFG1)
  461. look_ahead_dly_reg = BOLERO_CDC_RX_RX0_RX_PATH_CFG0;
  462. else if (e->reg == BOLERO_CDC_RX_RX1_RX_PATH_CFG1)
  463. look_ahead_dly_reg = BOLERO_CDC_RX_RX1_RX_PATH_CFG0;
  464. /* Set Look Ahead Delay */
  465. snd_soc_update_bits(codec, look_ahead_dly_reg,
  466. 0x08, (val ? 0x08 : 0x00));
  467. /* Set DEM INP Select */
  468. return snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
  469. }
  470. static int rx_macro_set_prim_interpolator_rate(struct snd_soc_dai *dai,
  471. u8 rate_reg_val,
  472. u32 sample_rate)
  473. {
  474. u8 int_1_mix1_inp = 0;
  475. u32 j = 0, port = 0;
  476. u16 int_mux_cfg0 = 0, int_mux_cfg1 = 0;
  477. u16 int_fs_reg = 0;
  478. u8 int_mux_cfg0_val = 0, int_mux_cfg1_val = 0;
  479. u8 inp0_sel = 0, inp1_sel = 0, inp2_sel = 0;
  480. struct snd_soc_codec *codec = dai->codec;
  481. struct device *rx_dev = NULL;
  482. struct rx_macro_priv *rx_priv = NULL;
  483. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  484. return -EINVAL;
  485. for_each_set_bit(port, &rx_priv->active_ch_mask[dai->id],
  486. RX_MACRO_PORTS_MAX) {
  487. int_1_mix1_inp = port;
  488. if ((int_1_mix1_inp < RX_MACRO_RX0) ||
  489. (int_1_mix1_inp > RX_MACRO_PORTS_MAX)) {
  490. pr_err("%s: Invalid RX port, Dai ID is %d\n",
  491. __func__, dai->id);
  492. return -EINVAL;
  493. }
  494. int_mux_cfg0 = BOLERO_CDC_RX_INP_MUX_RX_INT0_CFG0;
  495. /*
  496. * Loop through all interpolator MUX inputs and find out
  497. * to which interpolator input, the rx port
  498. * is connected
  499. */
  500. for (j = 0; j < INTERP_MAX; j++) {
  501. int_mux_cfg1 = int_mux_cfg0 + 4;
  502. int_mux_cfg0_val = snd_soc_read(codec, int_mux_cfg0);
  503. int_mux_cfg1_val = snd_soc_read(codec, int_mux_cfg1);
  504. inp0_sel = int_mux_cfg0_val & 0x07;
  505. inp1_sel = (int_mux_cfg0_val >> 4) & 0x038;
  506. inp2_sel = (int_mux_cfg1_val >> 4) & 0x038;
  507. if ((inp0_sel == int_1_mix1_inp) ||
  508. (inp1_sel == int_1_mix1_inp) ||
  509. (inp2_sel == int_1_mix1_inp)) {
  510. int_fs_reg = BOLERO_CDC_RX_RX0_RX_PATH_CTL +
  511. 0x80 * j;
  512. pr_debug("%s: AIF_PB DAI(%d) connected to INT%u_1\n",
  513. __func__, dai->id, j);
  514. pr_debug("%s: set INT%u_1 sample rate to %u\n",
  515. __func__, j, sample_rate);
  516. /* sample_rate is in Hz */
  517. snd_soc_update_bits(codec, int_fs_reg,
  518. 0x0F, rate_reg_val);
  519. }
  520. int_mux_cfg0 += 8;
  521. }
  522. }
  523. return 0;
  524. }
  525. static int rx_macro_set_mix_interpolator_rate(struct snd_soc_dai *dai,
  526. u8 rate_reg_val,
  527. u32 sample_rate)
  528. {
  529. u8 int_2_inp = 0;
  530. u32 j = 0, port = 0;
  531. u16 int_mux_cfg1 = 0, int_fs_reg = 0;
  532. u8 int_mux_cfg1_val = 0;
  533. struct snd_soc_codec *codec = dai->codec;
  534. struct device *rx_dev = NULL;
  535. struct rx_macro_priv *rx_priv = NULL;
  536. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  537. return -EINVAL;
  538. for_each_set_bit(port, &rx_priv->active_ch_mask[dai->id],
  539. RX_MACRO_PORTS_MAX) {
  540. int_2_inp = port;
  541. if ((int_2_inp < RX_MACRO_RX0) ||
  542. (int_2_inp > RX_MACRO_PORTS_MAX)) {
  543. pr_err("%s: Invalid RX port, Dai ID is %d\n",
  544. __func__, dai->id);
  545. return -EINVAL;
  546. }
  547. int_mux_cfg1 = BOLERO_CDC_RX_INP_MUX_RX_INT0_CFG1;
  548. for (j = 0; j < INTERP_MAX; j++) {
  549. int_mux_cfg1_val = snd_soc_read(codec, int_mux_cfg1) &
  550. 0x07;
  551. if (int_mux_cfg1_val == int_2_inp) {
  552. int_fs_reg = BOLERO_CDC_RX_RX0_RX_PATH_MIX_CTL +
  553. 0x80 * j;
  554. pr_debug("%s: AIF_PB DAI(%d) connected to INT%u_2\n",
  555. __func__, dai->id, j);
  556. pr_debug("%s: set INT%u_2 sample rate to %u\n",
  557. __func__, j, sample_rate);
  558. snd_soc_update_bits(codec, int_fs_reg,
  559. 0x0F, rate_reg_val);
  560. }
  561. int_mux_cfg1 += 8;
  562. }
  563. }
  564. return 0;
  565. }
  566. static int rx_macro_set_interpolator_rate(struct snd_soc_dai *dai,
  567. u32 sample_rate)
  568. {
  569. struct snd_soc_codec *codec = dai->codec;
  570. int rate_val = 0;
  571. int i = 0, ret = 0;
  572. for (i = 0; i < ARRAY_SIZE(sr_val_tbl); i++) {
  573. if (sample_rate == sr_val_tbl[i].sample_rate) {
  574. rate_val = sr_val_tbl[i].rate_val;
  575. break;
  576. }
  577. }
  578. if ((i == ARRAY_SIZE(sr_val_tbl)) || (rate_val < 0)) {
  579. dev_err(codec->dev, "%s: Unsupported sample rate: %d\n",
  580. __func__, sample_rate);
  581. return -EINVAL;
  582. }
  583. ret = rx_macro_set_prim_interpolator_rate(dai, (u8)rate_val, sample_rate);
  584. if (ret)
  585. return ret;
  586. ret = rx_macro_set_mix_interpolator_rate(dai, (u8)rate_val, sample_rate);
  587. if (ret)
  588. return ret;
  589. return ret;
  590. }
  591. static int rx_macro_hw_params(struct snd_pcm_substream *substream,
  592. struct snd_pcm_hw_params *params,
  593. struct snd_soc_dai *dai)
  594. {
  595. struct snd_soc_codec *codec = dai->codec;
  596. int ret = 0;
  597. struct device *rx_dev = NULL;
  598. struct rx_macro_priv *rx_priv = NULL;
  599. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  600. return -EINVAL;
  601. dev_dbg(codec->dev,
  602. "%s: dai_name = %s DAI-ID %x rate %d num_ch %d\n", __func__,
  603. dai->name, dai->id, params_rate(params),
  604. params_channels(params));
  605. switch (substream->stream) {
  606. case SNDRV_PCM_STREAM_PLAYBACK:
  607. ret = rx_macro_set_interpolator_rate(dai, params_rate(params));
  608. if (ret) {
  609. pr_err("%s: cannot set sample rate: %u\n",
  610. __func__, params_rate(params));
  611. return ret;
  612. }
  613. rx_priv->bit_width[dai->id] = params_width(params);
  614. break;
  615. case SNDRV_PCM_STREAM_CAPTURE:
  616. default:
  617. break;
  618. }
  619. return 0;
  620. }
  621. static int rx_macro_get_channel_map(struct snd_soc_dai *dai,
  622. unsigned int *tx_num, unsigned int *tx_slot,
  623. unsigned int *rx_num, unsigned int *rx_slot)
  624. {
  625. struct snd_soc_codec *codec = dai->codec;
  626. struct device *rx_dev = NULL;
  627. struct rx_macro_priv *rx_priv = NULL;
  628. unsigned int temp = 0, ch_mask = 0;
  629. u16 i = 0;
  630. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  631. return -EINVAL;
  632. switch (dai->id) {
  633. case RX_MACRO_AIF1_PB:
  634. case RX_MACRO_AIF2_PB:
  635. case RX_MACRO_AIF3_PB:
  636. case RX_MACRO_AIF4_PB:
  637. for_each_set_bit(temp, &rx_priv->active_ch_mask[dai->id],
  638. RX_MACRO_PORTS_MAX) {
  639. ch_mask |= (1 << i);
  640. if (++i == RX_MACRO_MAX_DMA_CH_PER_PORT)
  641. break;
  642. }
  643. *rx_slot = ch_mask;
  644. *rx_num = rx_priv->active_ch_cnt[dai->id];
  645. break;
  646. default:
  647. dev_err(rx_dev, "%s: Invalid AIF\n", __func__);
  648. break;
  649. }
  650. return 0;
  651. }
  652. static int rx_macro_mclk_enable(struct rx_macro_priv *rx_priv,
  653. bool mclk_enable, bool dapm)
  654. {
  655. struct regmap *regmap = dev_get_regmap(rx_priv->dev->parent, NULL);
  656. int ret = 0, mclk_mux = MCLK_MUX0;
  657. dev_dbg(rx_priv->dev, "%s: mclk_enable = %u, dapm = %d clk_users= %d\n",
  658. __func__, mclk_enable, dapm, rx_priv->rx_mclk_users);
  659. if(rx_priv->is_native_on)
  660. mclk_mux = MCLK_MUX1;
  661. mutex_lock(&rx_priv->mclk_lock);
  662. if (mclk_enable) {
  663. if (rx_priv->rx_mclk_users == 0) {
  664. ret = bolero_request_clock(rx_priv->dev,
  665. RX_MACRO, mclk_mux, true);
  666. if (ret < 0) {
  667. dev_err(rx_priv->dev,
  668. "%s: rx request clock enable failed\n",
  669. __func__);
  670. goto exit;
  671. }
  672. rx_priv->mclk_mux = mclk_mux;
  673. regcache_mark_dirty(regmap);
  674. regcache_sync_region(regmap,
  675. RX_START_OFFSET,
  676. RX_MAX_OFFSET);
  677. regmap_update_bits(regmap,
  678. BOLERO_CDC_RX_CLK_RST_CTRL_MCLK_CONTROL,
  679. 0x01, 0x01);
  680. regmap_update_bits(regmap,
  681. BOLERO_CDC_RX_CLK_RST_CTRL_MCLK_CONTROL,
  682. 0x02, 0x02);
  683. regmap_update_bits(regmap,
  684. BOLERO_CDC_RX_CLK_RST_CTRL_FS_CNT_CONTROL,
  685. 0x01, 0x01);
  686. }
  687. rx_priv->rx_mclk_users++;
  688. } else {
  689. if (rx_priv->rx_mclk_users <= 0) {
  690. dev_err(rx_priv->dev, "%s: clock already disabled\n",
  691. __func__);
  692. rx_priv->rx_mclk_users = 0;
  693. goto exit;
  694. }
  695. rx_priv->rx_mclk_users--;
  696. if (rx_priv->rx_mclk_users == 0) {
  697. regmap_update_bits(regmap,
  698. BOLERO_CDC_RX_CLK_RST_CTRL_FS_CNT_CONTROL,
  699. 0x01, 0x00);
  700. regmap_update_bits(regmap,
  701. BOLERO_CDC_RX_CLK_RST_CTRL_MCLK_CONTROL,
  702. 0x01, 0x00);
  703. bolero_request_clock(rx_priv->dev,
  704. RX_MACRO, mclk_mux, false);
  705. rx_priv->mclk_mux = MCLK_MUX0;
  706. }
  707. }
  708. exit:
  709. mutex_unlock(&rx_priv->mclk_lock);
  710. return ret;
  711. }
  712. static int rx_macro_mclk_event(struct snd_soc_dapm_widget *w,
  713. struct snd_kcontrol *kcontrol, int event)
  714. {
  715. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  716. int ret = 0;
  717. struct device *rx_dev = NULL;
  718. struct rx_macro_priv *rx_priv = NULL;
  719. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  720. return -EINVAL;
  721. dev_dbg(rx_dev, "%s: event = %d\n", __func__, event);
  722. switch (event) {
  723. case SND_SOC_DAPM_PRE_PMU:
  724. /* if swr_clk_users > 0, call device down */
  725. if (rx_priv->swr_clk_users > 0) {
  726. if ((rx_priv->mclk_mux == MCLK_MUX0 &&
  727. rx_priv->is_native_on) ||
  728. (rx_priv->mclk_mux == MCLK_MUX1 &&
  729. !rx_priv->is_native_on)) {
  730. swrm_wcd_notify(
  731. rx_priv->swr_ctrl_data[0].rx_swr_pdev,
  732. SWR_DEVICE_DOWN, NULL);
  733. }
  734. }
  735. ret = rx_macro_mclk_enable(rx_priv, 1, true);
  736. break;
  737. case SND_SOC_DAPM_POST_PMD:
  738. ret = rx_macro_mclk_enable(rx_priv, 0, true);
  739. break;
  740. default:
  741. dev_err(rx_priv->dev,
  742. "%s: invalid DAPM event %d\n", __func__, event);
  743. ret = -EINVAL;
  744. }
  745. return ret;
  746. }
  747. static int rx_macro_mclk_ctrl(struct device *dev, bool enable)
  748. {
  749. struct rx_macro_priv *rx_priv = dev_get_drvdata(dev);
  750. int ret = 0;
  751. if (enable) {
  752. ret = clk_prepare_enable(rx_priv->rx_core_clk);
  753. if (ret < 0) {
  754. dev_err(dev, "%s:rx mclk enable failed\n", __func__);
  755. return ret;
  756. }
  757. ret = clk_prepare_enable(rx_priv->rx_npl_clk);
  758. if (ret < 0) {
  759. clk_disable_unprepare(rx_priv->rx_core_clk);
  760. dev_err(dev, "%s:rx npl_clk enable failed\n",
  761. __func__);
  762. return ret;
  763. }
  764. if (rx_priv->rx_mclk_cnt++ == 0)
  765. iowrite32(0x1, rx_priv->rx_mclk_mode_muxsel);
  766. } else {
  767. if (rx_priv->rx_mclk_cnt <= 0) {
  768. dev_dbg(dev, "%s:rx mclk already disabled\n", __func__);
  769. rx_priv->rx_mclk_cnt = 0;
  770. return 0;
  771. }
  772. if (--rx_priv->rx_mclk_cnt == 0)
  773. iowrite32(0x0, rx_priv->rx_mclk_mode_muxsel);
  774. clk_disable_unprepare(rx_priv->rx_npl_clk);
  775. clk_disable_unprepare(rx_priv->rx_core_clk);
  776. }
  777. return 0;
  778. }
  779. static int rx_macro_find_playback_dai_id_for_port(int port_id,
  780. struct rx_macro_priv *rx_priv)
  781. {
  782. int i = 0;
  783. for (i = RX_MACRO_AIF1_PB; i < RX_MACRO_MAX_DAIS; i++) {
  784. if (test_bit(port_id, &rx_priv->active_ch_mask[i]))
  785. return i;
  786. }
  787. return -EINVAL;
  788. }
  789. static int rx_macro_set_idle_detect_thr(struct snd_soc_codec *codec,
  790. struct rx_macro_priv *rx_priv,
  791. int interp, int path_type)
  792. {
  793. int port_id[4] = { 0, 0, 0, 0 };
  794. int *port_ptr = NULL;
  795. int num_ports = 0;
  796. int bit_width = 0, i = 0;
  797. int mux_reg = 0, mux_reg_val = 0;
  798. int dai_id = 0, idle_thr = 0;
  799. if ((interp != INTERP_HPHL) && (interp != INTERP_HPHR))
  800. return 0;
  801. if (!rx_priv->idle_det_cfg.hph_idle_detect_en)
  802. return 0;
  803. port_ptr = &port_id[0];
  804. num_ports = 0;
  805. /*
  806. * Read interpolator MUX input registers and find
  807. * which cdc_dma port is connected and store the port
  808. * numbers in port_id array.
  809. */
  810. if (path_type == INTERP_MIX_PATH) {
  811. mux_reg = BOLERO_CDC_RX_INP_MUX_RX_INT0_CFG1 +
  812. 2 * interp;
  813. mux_reg_val = snd_soc_read(codec, mux_reg) & 0x0f;
  814. if ((mux_reg_val >= INTn_2_INP_SEL_RX0) &&
  815. (mux_reg_val <= INTn_2_INP_SEL_RX5)) {
  816. *port_ptr++ = mux_reg_val - 1;
  817. num_ports++;
  818. }
  819. }
  820. if (path_type == INTERP_MAIN_PATH) {
  821. mux_reg = BOLERO_CDC_RX_INP_MUX_RX_INT1_CFG0 +
  822. 2 * (interp - 1);
  823. mux_reg_val = snd_soc_read(codec, mux_reg) & 0x0f;
  824. i = RX_MACRO_INTERP_MUX_NUM_INPUTS;
  825. while (i) {
  826. if ((mux_reg_val >= INTn_1_INP_SEL_RX0) &&
  827. (mux_reg_val <= INTn_1_INP_SEL_RX5)) {
  828. *port_ptr++ = mux_reg_val -
  829. INTn_1_INP_SEL_RX0;
  830. num_ports++;
  831. }
  832. mux_reg_val = (snd_soc_read(codec, mux_reg) &
  833. 0xf0) >> 4;
  834. mux_reg += 1;
  835. i--;
  836. }
  837. }
  838. dev_dbg(codec->dev, "%s: num_ports: %d, ports[%d %d %d %d]\n",
  839. __func__, num_ports, port_id[0], port_id[1],
  840. port_id[2], port_id[3]);
  841. i = 0;
  842. while (num_ports) {
  843. dai_id = rx_macro_find_playback_dai_id_for_port(port_id[i++],
  844. rx_priv);
  845. if ((dai_id >= 0) && (dai_id < RX_MACRO_MAX_DAIS)) {
  846. dev_dbg(codec->dev, "%s: dai_id: %d bit_width: %d\n",
  847. __func__, dai_id,
  848. rx_priv->bit_width[dai_id]);
  849. if (rx_priv->bit_width[dai_id] > bit_width)
  850. bit_width = rx_priv->bit_width[dai_id];
  851. }
  852. num_ports--;
  853. }
  854. switch (bit_width) {
  855. case 16:
  856. idle_thr = 0xff; /* F16 */
  857. break;
  858. case 24:
  859. case 32:
  860. idle_thr = 0x03; /* F22 */
  861. break;
  862. default:
  863. idle_thr = 0x00;
  864. break;
  865. }
  866. dev_dbg(codec->dev, "%s: (new) idle_thr: %d, (cur) idle_thr: %d\n",
  867. __func__, idle_thr, rx_priv->idle_det_cfg.hph_idle_thr);
  868. if ((rx_priv->idle_det_cfg.hph_idle_thr == 0) ||
  869. (idle_thr < rx_priv->idle_det_cfg.hph_idle_thr)) {
  870. snd_soc_write(codec, BOLERO_CDC_RX_IDLE_DETECT_CFG3, idle_thr);
  871. rx_priv->idle_det_cfg.hph_idle_thr = idle_thr;
  872. }
  873. return 0;
  874. }
  875. static int rx_macro_enable_mix_path(struct snd_soc_dapm_widget *w,
  876. struct snd_kcontrol *kcontrol, int event)
  877. {
  878. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  879. u16 gain_reg = 0, mix_reg = 0;
  880. struct device *rx_dev = NULL;
  881. struct rx_macro_priv *rx_priv = NULL;
  882. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  883. return -EINVAL;
  884. if (w->shift >= INTERP_MAX) {
  885. dev_err(codec->dev, "%s: Invalid Interpolator value %d for name %s\n",
  886. __func__, w->shift, w->name);
  887. return -EINVAL;
  888. }
  889. gain_reg = BOLERO_CDC_RX_RX0_RX_VOL_MIX_CTL +
  890. (w->shift * RX_MACRO_RX_PATH_OFFSET);
  891. mix_reg = BOLERO_CDC_RX_RX0_RX_PATH_MIX_CTL +
  892. (w->shift * RX_MACRO_RX_PATH_OFFSET);
  893. dev_dbg(codec->dev, "%s %d %s\n", __func__, event, w->name);
  894. switch (event) {
  895. case SND_SOC_DAPM_PRE_PMU:
  896. rx_macro_set_idle_detect_thr(codec, rx_priv, w->shift,
  897. INTERP_MIX_PATH);
  898. rx_macro_enable_interp_clk(codec, event, w->shift);
  899. /* Clk enable */
  900. snd_soc_update_bits(codec, mix_reg, 0x20, 0x20);
  901. break;
  902. case SND_SOC_DAPM_POST_PMU:
  903. snd_soc_write(codec, gain_reg,
  904. snd_soc_read(codec, gain_reg));
  905. snd_soc_update_bits(codec, mix_reg, 0x10, 0x00);
  906. break;
  907. case SND_SOC_DAPM_POST_PMD:
  908. /* Clk Disable */
  909. snd_soc_update_bits(codec, mix_reg, 0x20, 0x00);
  910. rx_macro_enable_interp_clk(codec, event, w->shift);
  911. /* Reset enable and disable */
  912. snd_soc_update_bits(codec, mix_reg, 0x40, 0x40);
  913. snd_soc_update_bits(codec, mix_reg, 0x40, 0x00);
  914. break;
  915. }
  916. return 0;
  917. }
  918. static int rx_macro_enable_main_path(struct snd_soc_dapm_widget *w,
  919. struct snd_kcontrol *kcontrol,
  920. int event)
  921. {
  922. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  923. u16 gain_reg = 0;
  924. u16 reg = 0;
  925. struct device *rx_dev = NULL;
  926. struct rx_macro_priv *rx_priv = NULL;
  927. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  928. return -EINVAL;
  929. dev_dbg(codec->dev, "%s %d %s\n", __func__, event, w->name);
  930. if (w->shift >= INTERP_MAX) {
  931. dev_err(codec->dev, "%s: Invalid Interpolator value %d for name %s\n",
  932. __func__, w->shift, w->name);
  933. return -EINVAL;
  934. }
  935. reg = BOLERO_CDC_RX_RX0_RX_PATH_CTL + (w->shift *
  936. RX_MACRO_RX_PATH_OFFSET);
  937. gain_reg = BOLERO_CDC_RX_RX0_RX_VOL_CTL + (w->shift *
  938. RX_MACRO_RX_PATH_OFFSET);
  939. switch (event) {
  940. case SND_SOC_DAPM_PRE_PMU:
  941. rx_macro_set_idle_detect_thr(codec, rx_priv, w->shift,
  942. INTERP_MAIN_PATH);
  943. rx_macro_enable_interp_clk(codec, event, w->shift);
  944. break;
  945. case SND_SOC_DAPM_POST_PMU:
  946. snd_soc_write(codec, gain_reg,
  947. snd_soc_read(codec, gain_reg));
  948. snd_soc_update_bits(codec, reg, 0x10, 0x00);
  949. break;
  950. case SND_SOC_DAPM_POST_PMD:
  951. rx_macro_enable_interp_clk(codec, event, w->shift);
  952. break;
  953. }
  954. return 0;
  955. }
  956. static int rx_macro_config_compander(struct snd_soc_codec *codec,
  957. struct rx_macro_priv *rx_priv,
  958. int interp_n, int event)
  959. {
  960. int comp = 0;
  961. u16 comp_ctl0_reg = 0, rx_path_cfg0_reg = 0;
  962. /* AUX does not have compander */
  963. if (interp_n == INTERP_AUX)
  964. return 0;
  965. comp = interp_n;
  966. dev_dbg(codec->dev, "%s: event %d compander %d, enabled %d\n",
  967. __func__, event, comp + 1, rx_priv->comp_enabled[comp]);
  968. if (!rx_priv->comp_enabled[comp])
  969. return 0;
  970. comp_ctl0_reg = BOLERO_CDC_RX_COMPANDER0_CTL0 +
  971. (comp * RX_MACRO_COMP_OFFSET);
  972. rx_path_cfg0_reg = BOLERO_CDC_RX_RX0_RX_PATH_CFG0 +
  973. (comp * RX_MACRO_RX_PATH_OFFSET);
  974. if (SND_SOC_DAPM_EVENT_ON(event)) {
  975. /* Enable Compander Clock */
  976. snd_soc_update_bits(codec, comp_ctl0_reg, 0x01, 0x01);
  977. snd_soc_update_bits(codec, comp_ctl0_reg, 0x02, 0x02);
  978. snd_soc_update_bits(codec, comp_ctl0_reg, 0x02, 0x00);
  979. snd_soc_update_bits(codec, rx_path_cfg0_reg, 0x02, 0x02);
  980. }
  981. if (SND_SOC_DAPM_EVENT_OFF(event)) {
  982. snd_soc_update_bits(codec, comp_ctl0_reg, 0x04, 0x04);
  983. snd_soc_update_bits(codec, rx_path_cfg0_reg, 0x02, 0x00);
  984. snd_soc_update_bits(codec, comp_ctl0_reg, 0x02, 0x02);
  985. snd_soc_update_bits(codec, comp_ctl0_reg, 0x02, 0x00);
  986. snd_soc_update_bits(codec, comp_ctl0_reg, 0x01, 0x00);
  987. snd_soc_update_bits(codec, comp_ctl0_reg, 0x04, 0x00);
  988. }
  989. return 0;
  990. }
  991. static inline void
  992. rx_macro_enable_clsh_block(struct rx_macro_priv *rx_priv, bool enable)
  993. {
  994. if ((enable && ++rx_priv->clsh_users == 1) ||
  995. (!enable && --rx_priv->clsh_users == 0))
  996. snd_soc_update_bits(rx_priv->codec,
  997. BOLERO_CDC_RX_CLSH_CRC, 0x01,
  998. (u8) enable);
  999. if (rx_priv->clsh_users < 0)
  1000. rx_priv->clsh_users = 0;
  1001. dev_dbg(rx_priv->dev, "%s: clsh_users %d, enable %d", __func__,
  1002. rx_priv->clsh_users, enable);
  1003. }
  1004. static int rx_macro_config_classh(struct snd_soc_codec *codec,
  1005. struct rx_macro_priv *rx_priv,
  1006. int interp_n, int event)
  1007. {
  1008. if (SND_SOC_DAPM_EVENT_OFF(event)) {
  1009. rx_macro_enable_clsh_block(rx_priv, false);
  1010. return 0;
  1011. }
  1012. if (!SND_SOC_DAPM_EVENT_ON(event))
  1013. return 0;
  1014. rx_macro_enable_clsh_block(rx_priv, true);
  1015. if (interp_n == INTERP_HPHL ||
  1016. interp_n == INTERP_HPHR) {
  1017. /*
  1018. * These K1 values depend on the Headphone Impedance
  1019. * For now it is assumed to be 16 ohm
  1020. */
  1021. snd_soc_update_bits(codec, BOLERO_CDC_RX_CLSH_K1_LSB,
  1022. 0xFF, 0xC0);
  1023. snd_soc_update_bits(codec, BOLERO_CDC_RX_CLSH_K1_MSB,
  1024. 0x0F, 0x00);
  1025. }
  1026. switch (interp_n) {
  1027. case INTERP_HPHL:
  1028. if (rx_priv->is_ear_mode_on)
  1029. snd_soc_update_bits(codec,
  1030. BOLERO_CDC_RX_CLSH_HPH_V_PA,
  1031. 0x3F, 0x39);
  1032. else
  1033. snd_soc_update_bits(codec,
  1034. BOLERO_CDC_RX_CLSH_HPH_V_PA,
  1035. 0x3F, 0x1C);
  1036. snd_soc_update_bits(codec, BOLERO_CDC_RX_CLSH_DECAY_CTRL,
  1037. 0x07, 0x00);
  1038. snd_soc_update_bits(codec, BOLERO_CDC_RX_RX0_RX_PATH_CFG0,
  1039. 0x40, 0x40);
  1040. break;
  1041. case INTERP_HPHR:
  1042. snd_soc_update_bits(codec, BOLERO_CDC_RX_CLSH_HPH_V_PA,
  1043. 0x3F, 0x1C);
  1044. snd_soc_update_bits(codec, BOLERO_CDC_RX_CLSH_DECAY_CTRL,
  1045. 0x07, 0x00);
  1046. snd_soc_update_bits(codec, BOLERO_CDC_RX_RX1_RX_PATH_CFG0,
  1047. 0x40, 0x40);
  1048. break;
  1049. case INTERP_AUX:
  1050. snd_soc_update_bits(codec, BOLERO_CDC_RX_RX2_RX_PATH_CFG0,
  1051. 0x10, 0x10);
  1052. break;
  1053. }
  1054. return 0;
  1055. }
  1056. static void rx_macro_hd2_control(struct snd_soc_codec *codec,
  1057. u16 interp_idx, int event)
  1058. {
  1059. u16 hd2_scale_reg = 0;
  1060. u16 hd2_enable_reg = 0;
  1061. switch (interp_idx) {
  1062. case INTERP_HPHL:
  1063. hd2_scale_reg = BOLERO_CDC_RX_RX1_RX_PATH_SEC3;
  1064. hd2_enable_reg = BOLERO_CDC_RX_RX1_RX_PATH_CFG0;
  1065. break;
  1066. case INTERP_HPHR:
  1067. hd2_scale_reg = BOLERO_CDC_RX_RX2_RX_PATH_SEC3;
  1068. hd2_enable_reg = BOLERO_CDC_RX_RX2_RX_PATH_CFG0;
  1069. break;
  1070. }
  1071. if (hd2_enable_reg && SND_SOC_DAPM_EVENT_ON(event)) {
  1072. snd_soc_update_bits(codec, hd2_scale_reg, 0x3C, 0x14);
  1073. snd_soc_update_bits(codec, hd2_enable_reg, 0x04, 0x04);
  1074. }
  1075. if (hd2_enable_reg && SND_SOC_DAPM_EVENT_OFF(event)) {
  1076. snd_soc_update_bits(codec, hd2_enable_reg, 0x04, 0x00);
  1077. snd_soc_update_bits(codec, hd2_scale_reg, 0x3C, 0x00);
  1078. }
  1079. }
  1080. static int rx_macro_get_compander(struct snd_kcontrol *kcontrol,
  1081. struct snd_ctl_elem_value *ucontrol)
  1082. {
  1083. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  1084. int comp = ((struct soc_multi_mixer_control *)
  1085. kcontrol->private_value)->shift;
  1086. struct device *rx_dev = NULL;
  1087. struct rx_macro_priv *rx_priv = NULL;
  1088. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  1089. return -EINVAL;
  1090. ucontrol->value.integer.value[0] = rx_priv->comp_enabled[comp];
  1091. return 0;
  1092. }
  1093. static int rx_macro_set_compander(struct snd_kcontrol *kcontrol,
  1094. struct snd_ctl_elem_value *ucontrol)
  1095. {
  1096. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  1097. int comp = ((struct soc_multi_mixer_control *)
  1098. kcontrol->private_value)->shift;
  1099. int value = ucontrol->value.integer.value[0];
  1100. struct device *rx_dev = NULL;
  1101. struct rx_macro_priv *rx_priv = NULL;
  1102. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  1103. return -EINVAL;
  1104. dev_dbg(codec->dev, "%s: Compander %d enable current %d, new %d\n",
  1105. __func__, comp + 1, rx_priv->comp_enabled[comp], value);
  1106. rx_priv->comp_enabled[comp] = value;
  1107. return 0;
  1108. }
  1109. static int rx_macro_mux_get(struct snd_kcontrol *kcontrol,
  1110. struct snd_ctl_elem_value *ucontrol)
  1111. {
  1112. struct snd_soc_dapm_widget *widget =
  1113. snd_soc_dapm_kcontrol_widget(kcontrol);
  1114. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm);
  1115. struct device *rx_dev = NULL;
  1116. struct rx_macro_priv *rx_priv = NULL;
  1117. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  1118. return -EINVAL;
  1119. ucontrol->value.integer.value[0] =
  1120. rx_priv->rx_port_value[widget->shift];
  1121. return 0;
  1122. }
  1123. static int rx_macro_mux_put(struct snd_kcontrol *kcontrol,
  1124. struct snd_ctl_elem_value *ucontrol)
  1125. {
  1126. struct snd_soc_dapm_widget *widget =
  1127. snd_soc_dapm_kcontrol_widget(kcontrol);
  1128. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm);
  1129. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  1130. struct snd_soc_dapm_update *update = NULL;
  1131. u32 rx_port_value = ucontrol->value.integer.value[0];
  1132. u32 aif_rst = 0;
  1133. struct device *rx_dev = NULL;
  1134. struct rx_macro_priv *rx_priv = NULL;
  1135. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  1136. return -EINVAL;
  1137. aif_rst = rx_priv->rx_port_value[widget->shift];
  1138. if (!rx_port_value) {
  1139. if (aif_rst == 0) {
  1140. dev_err(rx_dev, "%s:AIF reset already\n", __func__);
  1141. return 0;
  1142. }
  1143. }
  1144. rx_priv->rx_port_value[widget->shift] = rx_port_value;
  1145. switch (rx_port_value) {
  1146. case 0:
  1147. clear_bit(widget->shift,
  1148. &rx_priv->active_ch_mask[aif_rst]);
  1149. rx_priv->active_ch_cnt[aif_rst]--;
  1150. break;
  1151. case 1:
  1152. case 2:
  1153. case 3:
  1154. case 4:
  1155. set_bit(widget->shift,
  1156. &rx_priv->active_ch_mask[rx_port_value]);
  1157. rx_priv->active_ch_cnt[rx_port_value]++;
  1158. break;
  1159. default:
  1160. dev_err(codec->dev,
  1161. "%s:Invalid AIF_ID for RX_MACRO MUX\n", __func__);
  1162. goto err;
  1163. }
  1164. snd_soc_dapm_mux_update_power(widget->dapm, kcontrol,
  1165. rx_port_value, e, update);
  1166. return 0;
  1167. err:
  1168. return -EINVAL;
  1169. }
  1170. static int rx_macro_get_native(struct snd_kcontrol *kcontrol,
  1171. struct snd_ctl_elem_value *ucontrol)
  1172. {
  1173. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  1174. struct device *rx_dev = NULL;
  1175. struct rx_macro_priv *rx_priv = NULL;
  1176. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  1177. return -EINVAL;
  1178. ucontrol->value.integer.value[0] =
  1179. (rx_priv->is_native_on == true ? 1 : 0);
  1180. return 0;
  1181. }
  1182. static int rx_macro_put_native(struct snd_kcontrol *kcontrol,
  1183. struct snd_ctl_elem_value *ucontrol)
  1184. {
  1185. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  1186. struct device *rx_dev = NULL;
  1187. struct rx_macro_priv *rx_priv = NULL;
  1188. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  1189. return -EINVAL;
  1190. rx_priv->is_native_on =
  1191. (!ucontrol->value.integer.value[0] ? false : true);
  1192. return 0;
  1193. }
  1194. static int rx_macro_get_ear_mode(struct snd_kcontrol *kcontrol,
  1195. struct snd_ctl_elem_value *ucontrol)
  1196. {
  1197. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  1198. struct device *rx_dev = NULL;
  1199. struct rx_macro_priv *rx_priv = NULL;
  1200. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  1201. return -EINVAL;
  1202. ucontrol->value.integer.value[0] = rx_priv->is_ear_mode_on;
  1203. return 0;
  1204. }
  1205. static int rx_macro_put_ear_mode(struct snd_kcontrol *kcontrol,
  1206. struct snd_ctl_elem_value *ucontrol)
  1207. {
  1208. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  1209. struct device *rx_dev = NULL;
  1210. struct rx_macro_priv *rx_priv = NULL;
  1211. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  1212. return -EINVAL;
  1213. rx_priv->is_ear_mode_on =
  1214. (!ucontrol->value.integer.value[0] ? false : true);
  1215. return 0;
  1216. }
  1217. static void rx_macro_idle_detect_control(struct snd_soc_codec *codec,
  1218. struct rx_macro_priv *rx_priv,
  1219. int interp, int event)
  1220. {
  1221. int reg = 0, mask = 0, val = 0;
  1222. if (!rx_priv->idle_det_cfg.hph_idle_detect_en)
  1223. return;
  1224. if (interp == INTERP_HPHL) {
  1225. reg = BOLERO_CDC_RX_IDLE_DETECT_PATH_CTL;
  1226. mask = 0x01;
  1227. val = 0x01;
  1228. }
  1229. if (interp == INTERP_HPHR) {
  1230. reg = BOLERO_CDC_RX_IDLE_DETECT_PATH_CTL;
  1231. mask = 0x02;
  1232. val = 0x02;
  1233. }
  1234. if (reg && SND_SOC_DAPM_EVENT_ON(event))
  1235. snd_soc_update_bits(codec, reg, mask, val);
  1236. if (reg && SND_SOC_DAPM_EVENT_OFF(event)) {
  1237. snd_soc_update_bits(codec, reg, mask, 0x00);
  1238. rx_priv->idle_det_cfg.hph_idle_thr = 0;
  1239. snd_soc_write(codec, BOLERO_CDC_RX_IDLE_DETECT_CFG3, 0x0);
  1240. }
  1241. }
  1242. static void rx_macro_hphdelay_lutbypass(struct snd_soc_codec *codec,
  1243. struct rx_macro_priv *rx_priv,
  1244. u16 interp_idx, int event)
  1245. {
  1246. u8 hph_dly_mask = 0;
  1247. u16 hph_lut_bypass_reg = 0;
  1248. u16 hph_comp_ctrl7 = 0;
  1249. switch (interp_idx) {
  1250. case INTERP_HPHL:
  1251. hph_dly_mask = 1;
  1252. hph_lut_bypass_reg = BOLERO_CDC_RX_TOP_HPHL_COMP_LUT;
  1253. hph_comp_ctrl7 = BOLERO_CDC_RX_COMPANDER0_CTL7;
  1254. break;
  1255. case INTERP_HPHR:
  1256. hph_dly_mask = 2;
  1257. hph_lut_bypass_reg = BOLERO_CDC_RX_TOP_HPHR_COMP_LUT;
  1258. hph_comp_ctrl7 = BOLERO_CDC_RX_COMPANDER1_CTL7;
  1259. break;
  1260. default:
  1261. break;
  1262. }
  1263. if (hph_lut_bypass_reg && SND_SOC_DAPM_EVENT_ON(event)) {
  1264. snd_soc_update_bits(codec, BOLERO_CDC_RX_CLSH_TEST0,
  1265. hph_dly_mask, 0x0);
  1266. if (interp_idx == INTERP_HPHL) {
  1267. if (rx_priv->is_ear_mode_on)
  1268. snd_soc_update_bits(codec,
  1269. BOLERO_CDC_RX_RX0_RX_PATH_CFG1,
  1270. 0x02, 0x02);
  1271. else
  1272. snd_soc_update_bits(codec,
  1273. hph_lut_bypass_reg,
  1274. 0x80, 0x80);
  1275. } else {
  1276. snd_soc_update_bits(codec,
  1277. hph_lut_bypass_reg,
  1278. 0x80, 0x80);
  1279. }
  1280. }
  1281. if (hph_lut_bypass_reg && SND_SOC_DAPM_EVENT_OFF(event)) {
  1282. snd_soc_update_bits(codec, BOLERO_CDC_RX_CLSH_TEST0,
  1283. hph_dly_mask, hph_dly_mask);
  1284. snd_soc_update_bits(codec, BOLERO_CDC_RX_RX0_RX_PATH_CFG1,
  1285. 0x02, 0x00);
  1286. snd_soc_update_bits(codec, hph_lut_bypass_reg, 0x80, 0x00);
  1287. snd_soc_update_bits(codec, hph_comp_ctrl7, 0x20, 0x0);
  1288. }
  1289. }
  1290. static int rx_macro_enable_interp_clk(struct snd_soc_codec *codec,
  1291. int event, int interp_idx)
  1292. {
  1293. u16 main_reg = 0;
  1294. struct device *rx_dev = NULL;
  1295. struct rx_macro_priv *rx_priv = NULL;
  1296. if (!codec) {
  1297. pr_err("%s: codec is NULL\n", __func__);
  1298. return -EINVAL;
  1299. }
  1300. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  1301. return -EINVAL;
  1302. main_reg = BOLERO_CDC_RX_RX0_RX_PATH_CTL +
  1303. (interp_idx * RX_MACRO_RX_PATH_OFFSET);
  1304. if (SND_SOC_DAPM_EVENT_ON(event)) {
  1305. if (rx_priv->main_clk_users[interp_idx] == 0) {
  1306. /* Main path PGA mute enable */
  1307. snd_soc_update_bits(codec, main_reg, 0x10, 0x10);
  1308. /* Clk enable */
  1309. snd_soc_update_bits(codec, main_reg, 0x20, 0x20);
  1310. rx_macro_idle_detect_control(codec, rx_priv,
  1311. interp_idx, event);
  1312. rx_macro_hd2_control(codec, interp_idx, event);
  1313. rx_macro_hphdelay_lutbypass(codec, rx_priv, interp_idx,
  1314. event);
  1315. rx_macro_config_compander(codec, rx_priv,
  1316. interp_idx, event);
  1317. rx_macro_config_classh(codec, rx_priv,
  1318. interp_idx, event);
  1319. }
  1320. rx_priv->main_clk_users[interp_idx]++;
  1321. }
  1322. if (SND_SOC_DAPM_EVENT_OFF(event)) {
  1323. rx_priv->main_clk_users[interp_idx]--;
  1324. if (rx_priv->main_clk_users[interp_idx] <= 0) {
  1325. rx_priv->main_clk_users[interp_idx] = 0;
  1326. rx_macro_config_classh(codec, rx_priv,
  1327. interp_idx, event);
  1328. rx_macro_config_compander(codec, rx_priv,
  1329. interp_idx, event);
  1330. rx_macro_hphdelay_lutbypass(codec, rx_priv, interp_idx,
  1331. event);
  1332. rx_macro_hd2_control(codec, interp_idx, event);
  1333. rx_macro_idle_detect_control(codec, rx_priv,
  1334. interp_idx, event);
  1335. /* Clk Disable */
  1336. snd_soc_update_bits(codec, main_reg, 0x20, 0x00);
  1337. /* Reset enable and disable */
  1338. snd_soc_update_bits(codec, main_reg, 0x40, 0x40);
  1339. snd_soc_update_bits(codec, main_reg, 0x40, 0x00);
  1340. /* Reset rate to 48K*/
  1341. snd_soc_update_bits(codec, main_reg, 0x0F, 0x04);
  1342. }
  1343. }
  1344. dev_dbg(codec->dev, "%s event %d main_clk_users %d\n",
  1345. __func__, event, rx_priv->main_clk_users[interp_idx]);
  1346. return rx_priv->main_clk_users[interp_idx];
  1347. }
  1348. static int rx_macro_enable_rx_path_clk(struct snd_soc_dapm_widget *w,
  1349. struct snd_kcontrol *kcontrol, int event)
  1350. {
  1351. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1352. u16 sidetone_reg = 0;
  1353. dev_dbg(codec->dev, "%s %d %d\n", __func__, event, w->shift);
  1354. sidetone_reg = BOLERO_CDC_RX_RX0_RX_PATH_CFG1 +
  1355. RX_MACRO_RX_PATH_OFFSET * (w->shift);
  1356. switch (event) {
  1357. case SND_SOC_DAPM_PRE_PMU:
  1358. rx_macro_enable_interp_clk(codec, event, w->shift);
  1359. snd_soc_update_bits(codec, sidetone_reg, 0x10, 0x10);
  1360. break;
  1361. case SND_SOC_DAPM_POST_PMD:
  1362. snd_soc_update_bits(codec, sidetone_reg, 0x10, 0x00);
  1363. rx_macro_enable_interp_clk(codec, event, w->shift);
  1364. break;
  1365. default:
  1366. break;
  1367. };
  1368. return 0;
  1369. }
  1370. static void rx_macro_restore_iir_coeff(struct rx_macro_priv *rx_priv, int iir_idx,
  1371. int band_idx)
  1372. {
  1373. u16 reg_add = 0, coeff_idx = 0, idx = 0;
  1374. struct regmap *regmap = dev_get_regmap(rx_priv->dev->parent, NULL);
  1375. regmap_write(regmap,
  1376. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B1_CTL + 0x80 * iir_idx),
  1377. (band_idx * BAND_MAX * sizeof(uint32_t)) & 0x7F);
  1378. reg_add = BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B2_CTL + 0x80 * iir_idx;
  1379. /* 5 coefficients per band and 4 writes per coefficient */
  1380. for (coeff_idx = 0; coeff_idx < RX_MACRO_SIDETONE_IIR_COEFF_MAX;
  1381. coeff_idx++) {
  1382. /* Four 8 bit values(one 32 bit) per coefficient */
  1383. regmap_write(regmap, reg_add,
  1384. rx_priv->sidetone_coeff_array[iir_idx][band_idx][idx++]);
  1385. regmap_write(regmap, reg_add,
  1386. rx_priv->sidetone_coeff_array[iir_idx][band_idx][idx++]);
  1387. regmap_write(regmap, reg_add,
  1388. rx_priv->sidetone_coeff_array[iir_idx][band_idx][idx++]);
  1389. regmap_write(regmap, reg_add,
  1390. rx_priv->sidetone_coeff_array[iir_idx][band_idx][idx++]);
  1391. }
  1392. }
  1393. static int rx_macro_iir_enable_audio_mixer_get(struct snd_kcontrol *kcontrol,
  1394. struct snd_ctl_elem_value *ucontrol)
  1395. {
  1396. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  1397. int iir_idx = ((struct soc_multi_mixer_control *)
  1398. kcontrol->private_value)->reg;
  1399. int band_idx = ((struct soc_multi_mixer_control *)
  1400. kcontrol->private_value)->shift;
  1401. /* IIR filter band registers are at integer multiples of 0x80 */
  1402. u16 iir_reg = BOLERO_CDC_RX_SIDETONE_IIR0_IIR_CTL + 0x80 * iir_idx;
  1403. ucontrol->value.integer.value[0] = (snd_soc_read(codec, iir_reg) &
  1404. (1 << band_idx)) != 0;
  1405. dev_dbg(codec->dev, "%s: IIR #%d band #%d enable %d\n", __func__,
  1406. iir_idx, band_idx,
  1407. (uint32_t)ucontrol->value.integer.value[0]);
  1408. return 0;
  1409. }
  1410. static int rx_macro_iir_enable_audio_mixer_put(struct snd_kcontrol *kcontrol,
  1411. struct snd_ctl_elem_value *ucontrol)
  1412. {
  1413. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  1414. int iir_idx = ((struct soc_multi_mixer_control *)
  1415. kcontrol->private_value)->reg;
  1416. int band_idx = ((struct soc_multi_mixer_control *)
  1417. kcontrol->private_value)->shift;
  1418. bool iir_band_en_status = 0;
  1419. int value = ucontrol->value.integer.value[0];
  1420. u16 iir_reg = BOLERO_CDC_RX_SIDETONE_IIR0_IIR_CTL + 0x80 * iir_idx;
  1421. struct device *rx_dev = NULL;
  1422. struct rx_macro_priv *rx_priv = NULL;
  1423. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  1424. return -EINVAL;
  1425. rx_macro_restore_iir_coeff(rx_priv, iir_idx, band_idx);
  1426. /* Mask first 5 bits, 6-8 are reserved */
  1427. snd_soc_update_bits(codec, iir_reg, (1 << band_idx),
  1428. (value << band_idx));
  1429. iir_band_en_status = ((snd_soc_read(codec, iir_reg) &
  1430. (1 << band_idx)) != 0);
  1431. dev_dbg(codec->dev, "%s: IIR #%d band #%d enable %d\n", __func__,
  1432. iir_idx, band_idx, iir_band_en_status);
  1433. return 0;
  1434. }
  1435. static uint32_t get_iir_band_coeff(struct snd_soc_codec *codec,
  1436. int iir_idx, int band_idx,
  1437. int coeff_idx)
  1438. {
  1439. uint32_t value = 0;
  1440. /* Address does not automatically update if reading */
  1441. snd_soc_write(codec,
  1442. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B1_CTL + 0x80 * iir_idx),
  1443. ((band_idx * BAND_MAX + coeff_idx)
  1444. * sizeof(uint32_t)) & 0x7F);
  1445. value |= snd_soc_read(codec,
  1446. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B2_CTL + 0x80 * iir_idx));
  1447. snd_soc_write(codec,
  1448. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B1_CTL + 0x80 * iir_idx),
  1449. ((band_idx * BAND_MAX + coeff_idx)
  1450. * sizeof(uint32_t) + 1) & 0x7F);
  1451. value |= (snd_soc_read(codec,
  1452. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B2_CTL +
  1453. 0x80 * iir_idx)) << 8);
  1454. snd_soc_write(codec,
  1455. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B1_CTL + 0x80 * iir_idx),
  1456. ((band_idx * BAND_MAX + coeff_idx)
  1457. * sizeof(uint32_t) + 2) & 0x7F);
  1458. value |= (snd_soc_read(codec,
  1459. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B2_CTL +
  1460. 0x80 * iir_idx)) << 16);
  1461. snd_soc_write(codec,
  1462. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B1_CTL + 0x80 * iir_idx),
  1463. ((band_idx * BAND_MAX + coeff_idx)
  1464. * sizeof(uint32_t) + 3) & 0x7F);
  1465. /* Mask bits top 2 bits since they are reserved */
  1466. value |= ((snd_soc_read(codec,
  1467. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B2_CTL +
  1468. 16 * iir_idx)) & 0x3F) << 24);
  1469. return value;
  1470. }
  1471. static int rx_macro_iir_band_audio_mixer_get(struct snd_kcontrol *kcontrol,
  1472. struct snd_ctl_elem_value *ucontrol)
  1473. {
  1474. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  1475. int iir_idx = ((struct soc_multi_mixer_control *)
  1476. kcontrol->private_value)->reg;
  1477. int band_idx = ((struct soc_multi_mixer_control *)
  1478. kcontrol->private_value)->shift;
  1479. ucontrol->value.integer.value[0] =
  1480. get_iir_band_coeff(codec, iir_idx, band_idx, 0);
  1481. ucontrol->value.integer.value[1] =
  1482. get_iir_band_coeff(codec, iir_idx, band_idx, 1);
  1483. ucontrol->value.integer.value[2] =
  1484. get_iir_band_coeff(codec, iir_idx, band_idx, 2);
  1485. ucontrol->value.integer.value[3] =
  1486. get_iir_band_coeff(codec, iir_idx, band_idx, 3);
  1487. ucontrol->value.integer.value[4] =
  1488. get_iir_band_coeff(codec, iir_idx, band_idx, 4);
  1489. dev_dbg(codec->dev, "%s: IIR #%d band #%d b0 = 0x%x\n"
  1490. "%s: IIR #%d band #%d b1 = 0x%x\n"
  1491. "%s: IIR #%d band #%d b2 = 0x%x\n"
  1492. "%s: IIR #%d band #%d a1 = 0x%x\n"
  1493. "%s: IIR #%d band #%d a2 = 0x%x\n",
  1494. __func__, iir_idx, band_idx,
  1495. (uint32_t)ucontrol->value.integer.value[0],
  1496. __func__, iir_idx, band_idx,
  1497. (uint32_t)ucontrol->value.integer.value[1],
  1498. __func__, iir_idx, band_idx,
  1499. (uint32_t)ucontrol->value.integer.value[2],
  1500. __func__, iir_idx, band_idx,
  1501. (uint32_t)ucontrol->value.integer.value[3],
  1502. __func__, iir_idx, band_idx,
  1503. (uint32_t)ucontrol->value.integer.value[4]);
  1504. return 0;
  1505. }
  1506. static void set_iir_band_coeff(struct snd_soc_codec *codec,
  1507. int iir_idx, int band_idx,
  1508. uint32_t value)
  1509. {
  1510. snd_soc_write(codec,
  1511. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B2_CTL + 0x80 * iir_idx),
  1512. (value & 0xFF));
  1513. snd_soc_write(codec,
  1514. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B2_CTL + 0x80 * iir_idx),
  1515. (value >> 8) & 0xFF);
  1516. snd_soc_write(codec,
  1517. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B2_CTL + 0x80 * iir_idx),
  1518. (value >> 16) & 0xFF);
  1519. /* Mask top 2 bits, 7-8 are reserved */
  1520. snd_soc_write(codec,
  1521. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B2_CTL + 0x80 * iir_idx),
  1522. (value >> 24) & 0x3F);
  1523. }
  1524. static int rx_macro_iir_band_audio_mixer_put(struct snd_kcontrol *kcontrol,
  1525. struct snd_ctl_elem_value *ucontrol)
  1526. {
  1527. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  1528. int iir_idx = ((struct soc_multi_mixer_control *)
  1529. kcontrol->private_value)->reg;
  1530. int band_idx = ((struct soc_multi_mixer_control *)
  1531. kcontrol->private_value)->shift;
  1532. int coeff_idx, idx = 0;
  1533. struct device *rx_dev = NULL;
  1534. struct rx_macro_priv *rx_priv = NULL;
  1535. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  1536. return -EINVAL;
  1537. /*
  1538. * Mask top bit it is reserved
  1539. * Updates addr automatically for each B2 write
  1540. */
  1541. snd_soc_write(codec,
  1542. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B1_CTL + 16 * iir_idx),
  1543. (band_idx * BAND_MAX * sizeof(uint32_t)) & 0x7F);
  1544. /* Store the coefficients in sidetone coeff array */
  1545. for (coeff_idx = 0; coeff_idx < RX_MACRO_SIDETONE_IIR_COEFF_MAX;
  1546. coeff_idx++) {
  1547. uint32_t value = ucontrol->value.integer.value[coeff_idx];
  1548. set_iir_band_coeff(codec, iir_idx, band_idx, value);
  1549. /* Four 8 bit values(one 32 bit) per coefficient */
  1550. rx_priv->sidetone_coeff_array[iir_idx][band_idx][idx++] =
  1551. (value & 0xFF);
  1552. rx_priv->sidetone_coeff_array[iir_idx][band_idx][idx++] =
  1553. (value >> 8) & 0xFF;
  1554. rx_priv->sidetone_coeff_array[iir_idx][band_idx][idx++] =
  1555. (value >> 16) & 0xFF;
  1556. rx_priv->sidetone_coeff_array[iir_idx][band_idx][idx++] =
  1557. (value >> 24) & 0xFF;
  1558. }
  1559. pr_debug("%s: IIR #%d band #%d b0 = 0x%x\n"
  1560. "%s: IIR #%d band #%d b1 = 0x%x\n"
  1561. "%s: IIR #%d band #%d b2 = 0x%x\n"
  1562. "%s: IIR #%d band #%d a1 = 0x%x\n"
  1563. "%s: IIR #%d band #%d a2 = 0x%x\n",
  1564. __func__, iir_idx, band_idx,
  1565. get_iir_band_coeff(codec, iir_idx, band_idx, 0),
  1566. __func__, iir_idx, band_idx,
  1567. get_iir_band_coeff(codec, iir_idx, band_idx, 1),
  1568. __func__, iir_idx, band_idx,
  1569. get_iir_band_coeff(codec, iir_idx, band_idx, 2),
  1570. __func__, iir_idx, band_idx,
  1571. get_iir_band_coeff(codec, iir_idx, band_idx, 3),
  1572. __func__, iir_idx, band_idx,
  1573. get_iir_band_coeff(codec, iir_idx, band_idx, 4));
  1574. return 0;
  1575. }
  1576. static int rx_macro_set_iir_gain(struct snd_soc_dapm_widget *w,
  1577. struct snd_kcontrol *kcontrol, int event)
  1578. {
  1579. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1580. dev_dbg(codec->dev, "%s: event = %d\n", __func__, event);
  1581. switch (event) {
  1582. case SND_SOC_DAPM_POST_PMU: /* fall through */
  1583. case SND_SOC_DAPM_PRE_PMD:
  1584. if (strnstr(w->name, "IIR0", sizeof("IIR0"))) {
  1585. snd_soc_write(codec,
  1586. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B1_CTL,
  1587. snd_soc_read(codec,
  1588. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B1_CTL));
  1589. snd_soc_write(codec,
  1590. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B2_CTL,
  1591. snd_soc_read(codec,
  1592. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B2_CTL));
  1593. snd_soc_write(codec,
  1594. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B3_CTL,
  1595. snd_soc_read(codec,
  1596. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B3_CTL));
  1597. snd_soc_write(codec,
  1598. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B4_CTL,
  1599. snd_soc_read(codec,
  1600. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B4_CTL));
  1601. } else {
  1602. snd_soc_write(codec,
  1603. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B1_CTL,
  1604. snd_soc_read(codec,
  1605. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B1_CTL));
  1606. snd_soc_write(codec,
  1607. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B2_CTL,
  1608. snd_soc_read(codec,
  1609. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B2_CTL));
  1610. snd_soc_write(codec,
  1611. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B3_CTL,
  1612. snd_soc_read(codec,
  1613. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B3_CTL));
  1614. snd_soc_write(codec,
  1615. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B4_CTL,
  1616. snd_soc_read(codec,
  1617. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B4_CTL));
  1618. }
  1619. break;
  1620. }
  1621. return 0;
  1622. }
  1623. static const struct snd_kcontrol_new rx_macro_snd_controls[] = {
  1624. SOC_SINGLE_SX_TLV("RX_RX0 Digital Volume",
  1625. BOLERO_CDC_RX_RX0_RX_VOL_CTL,
  1626. 0, -84, 40, digital_gain),
  1627. SOC_SINGLE_SX_TLV("RX_RX1 Digital Volume",
  1628. BOLERO_CDC_RX_RX1_RX_VOL_CTL,
  1629. 0, -84, 40, digital_gain),
  1630. SOC_SINGLE_SX_TLV("RX_RX2 Digital Volume",
  1631. BOLERO_CDC_RX_RX2_RX_VOL_CTL,
  1632. 0, -84, 40, digital_gain),
  1633. SOC_SINGLE_SX_TLV("RX_RX0 Mix Digital Volume",
  1634. BOLERO_CDC_RX_RX0_RX_VOL_MIX_CTL, 0, -84, 40, digital_gain),
  1635. SOC_SINGLE_SX_TLV("RX_RX1 Mix Digital Volume",
  1636. BOLERO_CDC_RX_RX1_RX_VOL_MIX_CTL, 0, -84, 40, digital_gain),
  1637. SOC_SINGLE_SX_TLV("RX_RX2 Mix Digital Volume",
  1638. BOLERO_CDC_RX_RX2_RX_VOL_MIX_CTL, 0, -84, 40, digital_gain),
  1639. SOC_SINGLE_EXT("RX_COMP1 Switch", SND_SOC_NOPM, RX_MACRO_COMP1, 1, 0,
  1640. rx_macro_get_compander, rx_macro_set_compander),
  1641. SOC_SINGLE_EXT("RX_COMP2 Switch", SND_SOC_NOPM, RX_MACRO_COMP2, 1, 0,
  1642. rx_macro_get_compander, rx_macro_set_compander),
  1643. SOC_ENUM_EXT("RX_Native", rx_macro_native_enum, rx_macro_get_native,
  1644. rx_macro_put_native),
  1645. SOC_ENUM_EXT("RX_EAR Mode", rx_macro_ear_mode_enum,
  1646. rx_macro_get_ear_mode, rx_macro_put_ear_mode),
  1647. SOC_SINGLE_SX_TLV("IIR0 INP0 Volume",
  1648. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B1_CTL, 0, -84, 40,
  1649. digital_gain),
  1650. SOC_SINGLE_SX_TLV("IIR0 INP1 Volume",
  1651. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B2_CTL, 0, -84, 40,
  1652. digital_gain),
  1653. SOC_SINGLE_SX_TLV("IIR0 INP2 Volume",
  1654. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B3_CTL, 0, -84, 40,
  1655. digital_gain),
  1656. SOC_SINGLE_SX_TLV("IIR0 INP3 Volume",
  1657. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B4_CTL, 0, -84, 40,
  1658. digital_gain),
  1659. SOC_SINGLE_SX_TLV("IIR1 INP0 Volume",
  1660. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B1_CTL, 0, -84, 40,
  1661. digital_gain),
  1662. SOC_SINGLE_SX_TLV("IIR1 INP1 Volume",
  1663. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B2_CTL, 0, -84, 40,
  1664. digital_gain),
  1665. SOC_SINGLE_SX_TLV("IIR1 INP2 Volume",
  1666. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B3_CTL, 0, -84, 40,
  1667. digital_gain),
  1668. SOC_SINGLE_SX_TLV("IIR1 INP3 Volume",
  1669. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B4_CTL, 0, -84, 40,
  1670. digital_gain),
  1671. SOC_SINGLE_EXT("IIR0 Enable Band1", IIR0, BAND1, 1, 0,
  1672. rx_macro_iir_enable_audio_mixer_get,
  1673. rx_macro_iir_enable_audio_mixer_put),
  1674. SOC_SINGLE_EXT("IIR0 Enable Band2", IIR0, BAND2, 1, 0,
  1675. rx_macro_iir_enable_audio_mixer_get,
  1676. rx_macro_iir_enable_audio_mixer_put),
  1677. SOC_SINGLE_EXT("IIR0 Enable Band3", IIR0, BAND3, 1, 0,
  1678. rx_macro_iir_enable_audio_mixer_get,
  1679. rx_macro_iir_enable_audio_mixer_put),
  1680. SOC_SINGLE_EXT("IIR0 Enable Band4", IIR0, BAND4, 1, 0,
  1681. rx_macro_iir_enable_audio_mixer_get,
  1682. rx_macro_iir_enable_audio_mixer_put),
  1683. SOC_SINGLE_EXT("IIR0 Enable Band5", IIR0, BAND5, 1, 0,
  1684. rx_macro_iir_enable_audio_mixer_get,
  1685. rx_macro_iir_enable_audio_mixer_put),
  1686. SOC_SINGLE_EXT("IIR1 Enable Band1", IIR1, BAND1, 1, 0,
  1687. rx_macro_iir_enable_audio_mixer_get,
  1688. rx_macro_iir_enable_audio_mixer_put),
  1689. SOC_SINGLE_EXT("IIR1 Enable Band2", IIR1, BAND2, 1, 0,
  1690. rx_macro_iir_enable_audio_mixer_get,
  1691. rx_macro_iir_enable_audio_mixer_put),
  1692. SOC_SINGLE_EXT("IIR1 Enable Band3", IIR1, BAND3, 1, 0,
  1693. rx_macro_iir_enable_audio_mixer_get,
  1694. rx_macro_iir_enable_audio_mixer_put),
  1695. SOC_SINGLE_EXT("IIR1 Enable Band4", IIR1, BAND4, 1, 0,
  1696. rx_macro_iir_enable_audio_mixer_get,
  1697. rx_macro_iir_enable_audio_mixer_put),
  1698. SOC_SINGLE_EXT("IIR1 Enable Band5", IIR1, BAND5, 1, 0,
  1699. rx_macro_iir_enable_audio_mixer_get,
  1700. rx_macro_iir_enable_audio_mixer_put),
  1701. SOC_SINGLE_MULTI_EXT("IIR0 Band1", IIR0, BAND1, 255, 0, 5,
  1702. rx_macro_iir_band_audio_mixer_get,
  1703. rx_macro_iir_band_audio_mixer_put),
  1704. SOC_SINGLE_MULTI_EXT("IIR0 Band2", IIR0, BAND2, 255, 0, 5,
  1705. rx_macro_iir_band_audio_mixer_get,
  1706. rx_macro_iir_band_audio_mixer_put),
  1707. SOC_SINGLE_MULTI_EXT("IIR0 Band3", IIR0, BAND3, 255, 0, 5,
  1708. rx_macro_iir_band_audio_mixer_get,
  1709. rx_macro_iir_band_audio_mixer_put),
  1710. SOC_SINGLE_MULTI_EXT("IIR0 Band4", IIR0, BAND4, 255, 0, 5,
  1711. rx_macro_iir_band_audio_mixer_get,
  1712. rx_macro_iir_band_audio_mixer_put),
  1713. SOC_SINGLE_MULTI_EXT("IIR0 Band5", IIR0, BAND5, 255, 0, 5,
  1714. rx_macro_iir_band_audio_mixer_get,
  1715. rx_macro_iir_band_audio_mixer_put),
  1716. SOC_SINGLE_MULTI_EXT("IIR1 Band1", IIR1, BAND1, 255, 0, 5,
  1717. rx_macro_iir_band_audio_mixer_get,
  1718. rx_macro_iir_band_audio_mixer_put),
  1719. SOC_SINGLE_MULTI_EXT("IIR1 Band2", IIR1, BAND2, 255, 0, 5,
  1720. rx_macro_iir_band_audio_mixer_get,
  1721. rx_macro_iir_band_audio_mixer_put),
  1722. SOC_SINGLE_MULTI_EXT("IIR1 Band3", IIR1, BAND3, 255, 0, 5,
  1723. rx_macro_iir_band_audio_mixer_get,
  1724. rx_macro_iir_band_audio_mixer_put),
  1725. SOC_SINGLE_MULTI_EXT("IIR1 Band4", IIR1, BAND4, 255, 0, 5,
  1726. rx_macro_iir_band_audio_mixer_get,
  1727. rx_macro_iir_band_audio_mixer_put),
  1728. SOC_SINGLE_MULTI_EXT("IIR1 Band5", IIR1, BAND5, 255, 0, 5,
  1729. rx_macro_iir_band_audio_mixer_get,
  1730. rx_macro_iir_band_audio_mixer_put),
  1731. };
  1732. static const struct snd_soc_dapm_widget rx_macro_dapm_widgets[] = {
  1733. SND_SOC_DAPM_AIF_IN("RX AIF1 PB", "RX_MACRO_AIF1 Playback", 0,
  1734. SND_SOC_NOPM, 0, 0),
  1735. SND_SOC_DAPM_AIF_IN("RX AIF2 PB", "RX_MACRO_AIF2 Playback", 0,
  1736. SND_SOC_NOPM, 0, 0),
  1737. SND_SOC_DAPM_AIF_IN("RX AIF3 PB", "RX_MACRO_AIF3 Playback", 0,
  1738. SND_SOC_NOPM, 0, 0),
  1739. SND_SOC_DAPM_AIF_IN("RX AIF4 PB", "RX_MACRO_AIF4 Playback", 0,
  1740. SND_SOC_NOPM, 0, 0),
  1741. RX_MACRO_DAPM_MUX("RX_MACRO RX0 MUX", RX_MACRO_RX0, rx_macro_rx0),
  1742. RX_MACRO_DAPM_MUX("RX_MACRO RX1 MUX", RX_MACRO_RX1, rx_macro_rx1),
  1743. RX_MACRO_DAPM_MUX("RX_MACRO RX2 MUX", RX_MACRO_RX2, rx_macro_rx2),
  1744. RX_MACRO_DAPM_MUX("RX_MACRO RX3 MUX", RX_MACRO_RX3, rx_macro_rx3),
  1745. RX_MACRO_DAPM_MUX("RX_MACRO RX4 MUX", RX_MACRO_RX4, rx_macro_rx4),
  1746. RX_MACRO_DAPM_MUX("RX_MACRO RX5 MUX", RX_MACRO_RX5, rx_macro_rx5),
  1747. SND_SOC_DAPM_MIXER("RX_RX0", SND_SOC_NOPM, 0, 0, NULL, 0),
  1748. SND_SOC_DAPM_MIXER("RX_RX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  1749. SND_SOC_DAPM_MIXER("RX_RX2", SND_SOC_NOPM, 0, 0, NULL, 0),
  1750. SND_SOC_DAPM_MIXER("RX_RX3", SND_SOC_NOPM, 0, 0, NULL, 0),
  1751. SND_SOC_DAPM_MIXER("RX_RX4", SND_SOC_NOPM, 0, 0, NULL, 0),
  1752. SND_SOC_DAPM_MIXER("RX_RX5", SND_SOC_NOPM, 0, 0, NULL, 0),
  1753. RX_MACRO_DAPM_MUX("IIR0 INP0 MUX", 0, iir0_inp0),
  1754. RX_MACRO_DAPM_MUX("IIR0 INP1 MUX", 0, iir0_inp1),
  1755. RX_MACRO_DAPM_MUX("IIR0 INP2 MUX", 0, iir0_inp2),
  1756. RX_MACRO_DAPM_MUX("IIR0 INP3 MUX", 0, iir0_inp3),
  1757. RX_MACRO_DAPM_MUX("IIR1 INP0 MUX", 0, iir1_inp0),
  1758. RX_MACRO_DAPM_MUX("IIR1 INP1 MUX", 0, iir1_inp1),
  1759. RX_MACRO_DAPM_MUX("IIR1 INP2 MUX", 0, iir1_inp2),
  1760. RX_MACRO_DAPM_MUX("IIR1 INP3 MUX", 0, iir1_inp3),
  1761. SND_SOC_DAPM_MIXER_E("IIR0", BOLERO_CDC_RX_SIDETONE_IIR0_IIR_PATH_CTL,
  1762. 4, 0, NULL, 0, rx_macro_set_iir_gain,
  1763. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
  1764. SND_SOC_DAPM_MIXER_E("IIR1", BOLERO_CDC_RX_SIDETONE_IIR1_IIR_PATH_CTL,
  1765. 4, 0, NULL, 0, rx_macro_set_iir_gain,
  1766. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
  1767. SND_SOC_DAPM_MIXER("SRC0", BOLERO_CDC_RX_SIDETONE_SRC0_ST_SRC_PATH_CTL,
  1768. 4, 0, NULL, 0),
  1769. SND_SOC_DAPM_MIXER("SRC1", BOLERO_CDC_RX_SIDETONE_SRC1_ST_SRC_PATH_CTL,
  1770. 4, 0, NULL, 0),
  1771. RX_MACRO_DAPM_MUX("RX MIX TX0 MUX", 0, rx_mix_tx0),
  1772. RX_MACRO_DAPM_MUX("RX MIX TX1 MUX", 0, rx_mix_tx1),
  1773. RX_MACRO_DAPM_MUX("RX MIX TX2 MUX", 0, rx_mix_tx2),
  1774. RX_MACRO_DAPM_MUX("RX INT0 DEM MUX", 0, rx_int0_dem_inp),
  1775. RX_MACRO_DAPM_MUX("RX INT1 DEM MUX", 0, rx_int1_dem_inp),
  1776. SND_SOC_DAPM_MUX_E("RX INT0_2 MUX", SND_SOC_NOPM, INTERP_HPHL, 0,
  1777. &rx_int0_2_mux, rx_macro_enable_mix_path,
  1778. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1779. SND_SOC_DAPM_POST_PMD),
  1780. SND_SOC_DAPM_MUX_E("RX INT1_2 MUX", SND_SOC_NOPM, INTERP_HPHR, 0,
  1781. &rx_int1_2_mux, rx_macro_enable_mix_path,
  1782. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1783. SND_SOC_DAPM_POST_PMD),
  1784. SND_SOC_DAPM_MUX_E("RX INT2_2 MUX", SND_SOC_NOPM, INTERP_AUX, 0,
  1785. &rx_int2_2_mux, rx_macro_enable_mix_path,
  1786. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1787. SND_SOC_DAPM_POST_PMD),
  1788. RX_MACRO_DAPM_MUX("RX INT0_1 MIX1 INP0", 0, rx_int0_1_mix_inp0),
  1789. RX_MACRO_DAPM_MUX("RX INT0_1 MIX1 INP1", 0, rx_int0_1_mix_inp1),
  1790. RX_MACRO_DAPM_MUX("RX INT0_1 MIX1 INP2", 0, rx_int0_1_mix_inp2),
  1791. RX_MACRO_DAPM_MUX("RX INT1_1 MIX1 INP0", 0, rx_int1_1_mix_inp0),
  1792. RX_MACRO_DAPM_MUX("RX INT1_1 MIX1 INP1", 0, rx_int1_1_mix_inp1),
  1793. RX_MACRO_DAPM_MUX("RX INT1_1 MIX1 INP2", 0, rx_int1_1_mix_inp2),
  1794. RX_MACRO_DAPM_MUX("RX INT2_1 MIX1 INP0", 0, rx_int2_1_mix_inp0),
  1795. RX_MACRO_DAPM_MUX("RX INT2_1 MIX1 INP1", 0, rx_int2_1_mix_inp1),
  1796. RX_MACRO_DAPM_MUX("RX INT2_1 MIX1 INP2", 0, rx_int2_1_mix_inp2),
  1797. SND_SOC_DAPM_MUX_E("RX INT0_1 INTERP", SND_SOC_NOPM, INTERP_HPHL, 0,
  1798. &rx_int0_1_interp_mux, rx_macro_enable_main_path,
  1799. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1800. SND_SOC_DAPM_POST_PMD),
  1801. SND_SOC_DAPM_MUX_E("RX INT1_1 INTERP", SND_SOC_NOPM, INTERP_HPHR, 0,
  1802. &rx_int1_1_interp_mux, rx_macro_enable_main_path,
  1803. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1804. SND_SOC_DAPM_POST_PMD),
  1805. SND_SOC_DAPM_MUX_E("RX INT2_1 INTERP", SND_SOC_NOPM, INTERP_AUX, 0,
  1806. &rx_int2_1_interp_mux, rx_macro_enable_main_path,
  1807. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1808. SND_SOC_DAPM_POST_PMD),
  1809. RX_MACRO_DAPM_MUX("RX INT0_2 INTERP", 0, rx_int0_2_interp),
  1810. RX_MACRO_DAPM_MUX("RX INT1_2 INTERP", 0, rx_int1_2_interp),
  1811. RX_MACRO_DAPM_MUX("RX INT2_2 INTERP", 0, rx_int2_2_interp),
  1812. SND_SOC_DAPM_MIXER("RX INT0_1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  1813. SND_SOC_DAPM_MIXER("RX INT0 SEC MIX", SND_SOC_NOPM, 0, 0, NULL, 0),
  1814. SND_SOC_DAPM_MIXER("RX INT1_1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  1815. SND_SOC_DAPM_MIXER("RX INT1 SEC MIX", SND_SOC_NOPM, 0, 0, NULL, 0),
  1816. SND_SOC_DAPM_MIXER("RX INT2_1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  1817. SND_SOC_DAPM_MIXER("RX INT2 SEC MIX", SND_SOC_NOPM, 0, 0, NULL, 0),
  1818. SND_SOC_DAPM_MUX_E("RX INT0 MIX2 INP", SND_SOC_NOPM, INTERP_HPHL,
  1819. 0, &rx_int0_mix2_inp_mux, rx_macro_enable_rx_path_clk,
  1820. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1821. SND_SOC_DAPM_MUX_E("RX INT1 MIX2 INP", SND_SOC_NOPM, INTERP_HPHR,
  1822. 0, &rx_int1_mix2_inp_mux, rx_macro_enable_rx_path_clk,
  1823. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1824. SND_SOC_DAPM_MUX_E("RX INT2 MIX2 INP", SND_SOC_NOPM, INTERP_AUX,
  1825. 0, &rx_int2_mix2_inp_mux, rx_macro_enable_rx_path_clk,
  1826. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1827. SND_SOC_DAPM_MIXER("RX INT0 MIX2", SND_SOC_NOPM, 0, 0, NULL, 0),
  1828. SND_SOC_DAPM_MIXER("RX INT1 MIX2", SND_SOC_NOPM, 0, 0, NULL, 0),
  1829. SND_SOC_DAPM_MIXER("RX INT2 MIX2", SND_SOC_NOPM, 0, 0, NULL, 0),
  1830. SND_SOC_DAPM_OUTPUT("HPHL_OUT"),
  1831. SND_SOC_DAPM_OUTPUT("HPHR_OUT"),
  1832. SND_SOC_DAPM_OUTPUT("AUX_OUT"),
  1833. SND_SOC_DAPM_INPUT("RX_TX DEC0_INP"),
  1834. SND_SOC_DAPM_INPUT("RX_TX DEC1_INP"),
  1835. SND_SOC_DAPM_INPUT("RX_TX DEC2_INP"),
  1836. SND_SOC_DAPM_INPUT("RX_TX DEC3_INP"),
  1837. SND_SOC_DAPM_SUPPLY_S("RX_MCLK", 0, SND_SOC_NOPM, 0, 0,
  1838. rx_macro_mclk_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1839. };
  1840. static const struct snd_soc_dapm_route rx_audio_map[] = {
  1841. {"RX AIF1 PB", NULL, "RX_MCLK"},
  1842. {"RX AIF2 PB", NULL, "RX_MCLK"},
  1843. {"RX AIF3 PB", NULL, "RX_MCLK"},
  1844. {"RX AIF4 PB", NULL, "RX_MCLK"},
  1845. {"RX_MACRO RX0 MUX", "AIF1_PB", "RX AIF1 PB"},
  1846. {"RX_MACRO RX1 MUX", "AIF1_PB", "RX AIF1 PB"},
  1847. {"RX_MACRO RX2 MUX", "AIF1_PB", "RX AIF1 PB"},
  1848. {"RX_MACRO RX3 MUX", "AIF1_PB", "RX AIF1 PB"},
  1849. {"RX_MACRO RX4 MUX", "AIF1_PB", "RX AIF1 PB"},
  1850. {"RX_MACRO RX5 MUX", "AIF1_PB", "RX AIF1 PB"},
  1851. {"RX_MACRO RX0 MUX", "AIF2_PB", "RX AIF2 PB"},
  1852. {"RX_MACRO RX1 MUX", "AIF2_PB", "RX AIF2 PB"},
  1853. {"RX_MACRO RX2 MUX", "AIF2_PB", "RX AIF2 PB"},
  1854. {"RX_MACRO RX3 MUX", "AIF2_PB", "RX AIF2 PB"},
  1855. {"RX_MACRO RX4 MUX", "AIF2_PB", "RX AIF2 PB"},
  1856. {"RX_MACRO RX5 MUX", "AIF2_PB", "RX AIF2 PB"},
  1857. {"RX_MACRO RX0 MUX", "AIF3_PB", "RX AIF3 PB"},
  1858. {"RX_MACRO RX1 MUX", "AIF3_PB", "RX AIF3 PB"},
  1859. {"RX_MACRO RX2 MUX", "AIF3_PB", "RX AIF3 PB"},
  1860. {"RX_MACRO RX3 MUX", "AIF3_PB", "RX AIF3 PB"},
  1861. {"RX_MACRO RX4 MUX", "AIF3_PB", "RX AIF3 PB"},
  1862. {"RX_MACRO RX5 MUX", "AIF3_PB", "RX AIF3 PB"},
  1863. {"RX_MACRO RX0 MUX", "AIF4_PB", "RX AIF4 PB"},
  1864. {"RX_MACRO RX1 MUX", "AIF4_PB", "RX AIF4 PB"},
  1865. {"RX_MACRO RX2 MUX", "AIF4_PB", "RX AIF4 PB"},
  1866. {"RX_MACRO RX3 MUX", "AIF4_PB", "RX AIF4 PB"},
  1867. {"RX_MACRO RX4 MUX", "AIF4_PB", "RX AIF4 PB"},
  1868. {"RX_MACRO RX5 MUX", "AIF4_PB", "RX AIF4 PB"},
  1869. {"RX_RX0", NULL, "RX_MACRO RX0 MUX"},
  1870. {"RX_RX1", NULL, "RX_MACRO RX1 MUX"},
  1871. {"RX_RX2", NULL, "RX_MACRO RX2 MUX"},
  1872. {"RX_RX3", NULL, "RX_MACRO RX3 MUX"},
  1873. {"RX_RX4", NULL, "RX_MACRO RX4 MUX"},
  1874. {"RX_RX5", NULL, "RX_MACRO RX5 MUX"},
  1875. {"RX INT0_1 MIX1 INP0", "RX0", "RX_RX0"},
  1876. {"RX INT0_1 MIX1 INP0", "RX1", "RX_RX1"},
  1877. {"RX INT0_1 MIX1 INP0", "RX2", "RX_RX2"},
  1878. {"RX INT0_1 MIX1 INP0", "RX3", "RX_RX3"},
  1879. {"RX INT0_1 MIX1 INP0", "RX4", "RX_RX4"},
  1880. {"RX INT0_1 MIX1 INP0", "RX5", "RX_RX5"},
  1881. {"RX INT0_1 MIX1 INP0", "IIR0", "IIR0"},
  1882. {"RX INT0_1 MIX1 INP0", "IIR1", "IIR1"},
  1883. {"RX INT0_1 MIX1 INP1", "RX0", "RX_RX0"},
  1884. {"RX INT0_1 MIX1 INP1", "RX1", "RX_RX1"},
  1885. {"RX INT0_1 MIX1 INP1", "RX2", "RX_RX2"},
  1886. {"RX INT0_1 MIX1 INP1", "RX3", "RX_RX3"},
  1887. {"RX INT0_1 MIX1 INP1", "RX4", "RX_RX4"},
  1888. {"RX INT0_1 MIX1 INP1", "RX5", "RX_RX5"},
  1889. {"RX INT0_1 MIX1 INP1", "IIR0", "IIR0"},
  1890. {"RX INT0_1 MIX1 INP1", "IIR1", "IIR1"},
  1891. {"RX INT0_1 MIX1 INP2", "RX0", "RX_RX0"},
  1892. {"RX INT0_1 MIX1 INP2", "RX1", "RX_RX1"},
  1893. {"RX INT0_1 MIX1 INP2", "RX2", "RX_RX2"},
  1894. {"RX INT0_1 MIX1 INP2", "RX3", "RX_RX3"},
  1895. {"RX INT0_1 MIX1 INP2", "RX4", "RX_RX4"},
  1896. {"RX INT0_1 MIX1 INP2", "RX5", "RX_RX5"},
  1897. {"RX INT0_1 MIX1 INP2", "IIR0", "IIR0"},
  1898. {"RX INT0_1 MIX1 INP2", "IIR1", "IIR1"},
  1899. {"RX INT1_1 MIX1 INP0", "RX0", "RX_RX0"},
  1900. {"RX INT1_1 MIX1 INP0", "RX1", "RX_RX1"},
  1901. {"RX INT1_1 MIX1 INP0", "RX2", "RX_RX2"},
  1902. {"RX INT1_1 MIX1 INP0", "RX3", "RX_RX3"},
  1903. {"RX INT1_1 MIX1 INP0", "RX4", "RX_RX4"},
  1904. {"RX INT1_1 MIX1 INP0", "RX5", "RX_RX5"},
  1905. {"RX INT1_1 MIX1 INP0", "IIR0", "IIR0"},
  1906. {"RX INT1_1 MIX1 INP0", "IIR1", "IIR1"},
  1907. {"RX INT1_1 MIX1 INP1", "RX0", "RX_RX0"},
  1908. {"RX INT1_1 MIX1 INP1", "RX1", "RX_RX1"},
  1909. {"RX INT1_1 MIX1 INP1", "RX2", "RX_RX2"},
  1910. {"RX INT1_1 MIX1 INP1", "RX3", "RX_RX3"},
  1911. {"RX INT1_1 MIX1 INP1", "RX4", "RX_RX4"},
  1912. {"RX INT1_1 MIX1 INP1", "RX5", "RX_RX5"},
  1913. {"RX INT1_1 MIX1 INP1", "IIR0", "IIR0"},
  1914. {"RX INT1_1 MIX1 INP1", "IIR1", "IIR1"},
  1915. {"RX INT1_1 MIX1 INP2", "RX0", "RX_RX0"},
  1916. {"RX INT1_1 MIX1 INP2", "RX1", "RX_RX1"},
  1917. {"RX INT1_1 MIX1 INP2", "RX2", "RX_RX2"},
  1918. {"RX INT1_1 MIX1 INP2", "RX3", "RX_RX3"},
  1919. {"RX INT1_1 MIX1 INP2", "RX4", "RX_RX4"},
  1920. {"RX INT1_1 MIX1 INP2", "RX5", "RX_RX5"},
  1921. {"RX INT1_1 MIX1 INP2", "IIR0", "IIR0"},
  1922. {"RX INT1_1 MIX1 INP2", "IIR1", "IIR1"},
  1923. {"RX INT2_1 MIX1 INP0", "RX0", "RX_RX0"},
  1924. {"RX INT2_1 MIX1 INP0", "RX1", "RX_RX1"},
  1925. {"RX INT2_1 MIX1 INP0", "RX2", "RX_RX2"},
  1926. {"RX INT2_1 MIX1 INP0", "RX3", "RX_RX3"},
  1927. {"RX INT2_1 MIX1 INP0", "RX4", "RX_RX4"},
  1928. {"RX INT2_1 MIX1 INP0", "RX5", "RX_RX5"},
  1929. {"RX INT2_1 MIX1 INP0", "IIR0", "IIR0"},
  1930. {"RX INT2_1 MIX1 INP0", "IIR1", "IIR1"},
  1931. {"RX INT2_1 MIX1 INP1", "RX0", "RX_RX0"},
  1932. {"RX INT2_1 MIX1 INP1", "RX1", "RX_RX1"},
  1933. {"RX INT2_1 MIX1 INP1", "RX2", "RX_RX2"},
  1934. {"RX INT2_1 MIX1 INP1", "RX3", "RX_RX3"},
  1935. {"RX INT2_1 MIX1 INP1", "RX4", "RX_RX4"},
  1936. {"RX INT2_1 MIX1 INP1", "RX5", "RX_RX5"},
  1937. {"RX INT2_1 MIX1 INP1", "IIR0", "IIR0"},
  1938. {"RX INT2_1 MIX1 INP1", "IIR1", "IIR1"},
  1939. {"RX INT2_1 MIX1 INP2", "RX0", "RX_RX0"},
  1940. {"RX INT2_1 MIX1 INP2", "RX1", "RX_RX1"},
  1941. {"RX INT2_1 MIX1 INP2", "RX2", "RX_RX2"},
  1942. {"RX INT2_1 MIX1 INP2", "RX3", "RX_RX3"},
  1943. {"RX INT2_1 MIX1 INP2", "RX4", "RX_RX4"},
  1944. {"RX INT2_1 MIX1 INP2", "RX5", "RX_RX5"},
  1945. {"RX INT2_1 MIX1 INP2", "IIR0", "IIR0"},
  1946. {"RX INT2_1 MIX1 INP2", "IIR1", "IIR1"},
  1947. {"RX INT0_1 MIX1", NULL, "RX INT0_1 MIX1 INP0"},
  1948. {"RX INT0_1 MIX1", NULL, "RX INT0_1 MIX1 INP1"},
  1949. {"RX INT0_1 MIX1", NULL, "RX INT0_1 MIX1 INP2"},
  1950. {"RX INT1_1 MIX1", NULL, "RX INT1_1 MIX1 INP0"},
  1951. {"RX INT1_1 MIX1", NULL, "RX INT1_1 MIX1 INP1"},
  1952. {"RX INT1_1 MIX1", NULL, "RX INT1_1 MIX1 INP2"},
  1953. {"RX INT2_1 MIX1", NULL, "RX INT2_1 MIX1 INP0"},
  1954. {"RX INT2_1 MIX1", NULL, "RX INT2_1 MIX1 INP1"},
  1955. {"RX INT2_1 MIX1", NULL, "RX INT2_1 MIX1 INP2"},
  1956. /* Mixing path INT0 */
  1957. {"RX INT0_2 MUX", "RX0", "RX_RX0"},
  1958. {"RX INT0_2 MUX", "RX1", "RX_RX1"},
  1959. {"RX INT0_2 MUX", "RX2", "RX_RX2"},
  1960. {"RX INT0_2 MUX", "RX3", "RX_RX3"},
  1961. {"RX INT0_2 MUX", "RX4", "RX_RX4"},
  1962. {"RX INT0_2 MUX", "RX5", "RX_RX5"},
  1963. {"RX INT0_2 INTERP", NULL, "RX INT0_2 MUX"},
  1964. {"RX INT0 SEC MIX", NULL, "RX INT0_2 INTERP"},
  1965. /* Mixing path INT1 */
  1966. {"RX INT1_2 MUX", "RX0", "RX_RX0"},
  1967. {"RX INT1_2 MUX", "RX1", "RX_RX1"},
  1968. {"RX INT1_2 MUX", "RX2", "RX_RX2"},
  1969. {"RX INT1_2 MUX", "RX3", "RX_RX3"},
  1970. {"RX INT1_2 MUX", "RX4", "RX_RX4"},
  1971. {"RX INT1_2 MUX", "RX5", "RX_RX5"},
  1972. {"RX INT1_2 INTERP", NULL, "RX INT1_2 MUX"},
  1973. {"RX INT1 SEC MIX", NULL, "RX INT1_2 INTERP"},
  1974. /* Mixing path INT2 */
  1975. {"RX INT2_2 MUX", "RX0", "RX_RX0"},
  1976. {"RX INT2_2 MUX", "RX1", "RX_RX1"},
  1977. {"RX INT2_2 MUX", "RX2", "RX_RX2"},
  1978. {"RX INT2_2 MUX", "RX3", "RX_RX3"},
  1979. {"RX INT2_2 MUX", "RX4", "RX_RX4"},
  1980. {"RX INT2_2 MUX", "RX5", "RX_RX5"},
  1981. {"RX INT2_2 INTERP", NULL, "RX INT2_2 MUX"},
  1982. {"RX INT2 SEC MIX", NULL, "RX INT2_2 INTERP"},
  1983. {"RX INT0_1 INTERP", NULL, "RX INT0_1 MIX1"},
  1984. {"RX INT0 SEC MIX", NULL, "RX INT0_1 INTERP"},
  1985. {"RX INT0 MIX2", NULL, "RX INT0 SEC MIX"},
  1986. {"RX INT0 MIX2", NULL, "RX INT0 MIX2 INP"},
  1987. {"RX INT0 DEM MUX", "CLSH_DSM_OUT", "RX INT0 MIX2"},
  1988. {"HPHL_OUT", NULL, "RX INT0 DEM MUX"},
  1989. {"HPHL_OUT", NULL, "RX_MCLK"},
  1990. {"RX INT1_1 INTERP", NULL, "RX INT1_1 MIX1"},
  1991. {"RX INT1 SEC MIX", NULL, "RX INT1_1 INTERP"},
  1992. {"RX INT1 MIX2", NULL, "RX INT1 SEC MIX"},
  1993. {"RX INT1 MIX2", NULL, "RX INT1 MIX2 INP"},
  1994. {"RX INT1 DEM MUX", "CLSH_DSM_OUT", "RX INT1 MIX2"},
  1995. {"HPHR_OUT", NULL, "RX INT1 DEM MUX"},
  1996. {"HPHR_OUT", NULL, "RX_MCLK"},
  1997. {"RX INT2_1 INTERP", NULL, "RX INT2_1 MIX1"},
  1998. {"RX INT2 SEC MIX", NULL, "RX INT2_1 INTERP"},
  1999. {"RX INT2 MIX2", NULL, "RX INT2 SEC MIX"},
  2000. {"RX INT2 MIX2", NULL, "RX INT2 MIX2 INP"},
  2001. {"AUX_OUT", NULL, "RX INT2 MIX2"},
  2002. {"AUX_OUT", NULL, "RX_MCLK"},
  2003. {"IIR0", NULL, "RX_MCLK"},
  2004. {"IIR0", NULL, "IIR0 INP0 MUX"},
  2005. {"IIR0 INP0 MUX", "DEC0", "RX_TX DEC0_INP"},
  2006. {"IIR0 INP0 MUX", "DEC1", "RX_TX DEC1_INP"},
  2007. {"IIR0 INP0 MUX", "DEC2", "RX_TX DEC2_INP"},
  2008. {"IIR0 INP0 MUX", "DEC3", "RX_TX DEC3_INP"},
  2009. {"IIR0 INP0 MUX", "RX0", "RX_RX0"},
  2010. {"IIR0 INP0 MUX", "RX1", "RX_RX1"},
  2011. {"IIR0 INP0 MUX", "RX2", "RX_RX2"},
  2012. {"IIR0 INP0 MUX", "RX3", "RX_RX3"},
  2013. {"IIR0 INP0 MUX", "RX4", "RX_RX4"},
  2014. {"IIR0 INP0 MUX", "RX5", "RX_RX5"},
  2015. {"IIR0", NULL, "IIR0 INP1 MUX"},
  2016. {"IIR0 INP1 MUX", "DEC0", "RX_TX DEC0_INP"},
  2017. {"IIR0 INP1 MUX", "DEC1", "RX_TX DEC1_INP"},
  2018. {"IIR0 INP1 MUX", "DEC2", "RX_TX DEC2_INP"},
  2019. {"IIR0 INP1 MUX", "DEC3", "RX_TX DEC3_INP"},
  2020. {"IIR0 INP1 MUX", "RX0", "RX_RX0"},
  2021. {"IIR0 INP1 MUX", "RX1", "RX_RX1"},
  2022. {"IIR0 INP1 MUX", "RX2", "RX_RX2"},
  2023. {"IIR0 INP1 MUX", "RX3", "RX_RX3"},
  2024. {"IIR0 INP1 MUX", "RX4", "RX_RX4"},
  2025. {"IIR0 INP1 MUX", "RX5", "RX_RX5"},
  2026. {"IIR0", NULL, "IIR0 INP2 MUX"},
  2027. {"IIR0 INP2 MUX", "DEC0", "RX_TX DEC0_INP"},
  2028. {"IIR0 INP2 MUX", "DEC1", "RX_TX DEC1_INP"},
  2029. {"IIR0 INP2 MUX", "DEC2", "RX_TX DEC2_INP"},
  2030. {"IIR0 INP2 MUX", "DEC3", "RX_TX DEC3_INP"},
  2031. {"IIR0 INP2 MUX", "RX0", "RX_RX0"},
  2032. {"IIR0 INP2 MUX", "RX1", "RX_RX1"},
  2033. {"IIR0 INP2 MUX", "RX2", "RX_RX2"},
  2034. {"IIR0 INP2 MUX", "RX3", "RX_RX3"},
  2035. {"IIR0 INP2 MUX", "RX4", "RX_RX4"},
  2036. {"IIR0 INP2 MUX", "RX5", "RX_RX5"},
  2037. {"IIR0", NULL, "IIR0 INP3 MUX"},
  2038. {"IIR0 INP3 MUX", "DEC0", "RX_TX DEC0_INP"},
  2039. {"IIR0 INP3 MUX", "DEC1", "RX_TX DEC1_INP"},
  2040. {"IIR0 INP3 MUX", "DEC2", "RX_TX DEC2_INP"},
  2041. {"IIR0 INP3 MUX", "DEC3", "RX_TX DEC3_INP"},
  2042. {"IIR0 INP3 MUX", "RX0", "RX_RX0"},
  2043. {"IIR0 INP3 MUX", "RX1", "RX_RX1"},
  2044. {"IIR0 INP3 MUX", "RX2", "RX_RX2"},
  2045. {"IIR0 INP3 MUX", "RX3", "RX_RX3"},
  2046. {"IIR0 INP3 MUX", "RX4", "RX_RX4"},
  2047. {"IIR0 INP3 MUX", "RX5", "RX_RX5"},
  2048. {"IIR1", NULL, "RX_MCLK"},
  2049. {"IIR1", NULL, "IIR1 INP0 MUX"},
  2050. {"IIR1 INP0 MUX", "DEC0", "RX_TX DEC0_INP"},
  2051. {"IIR1 INP0 MUX", "DEC1", "RX_TX DEC1_INP"},
  2052. {"IIR1 INP0 MUX", "DEC2", "RX_TX DEC2_INP"},
  2053. {"IIR1 INP0 MUX", "DEC3", "RX_TX DEC3_INP"},
  2054. {"IIR1 INP0 MUX", "RX0", "RX_RX0"},
  2055. {"IIR1 INP0 MUX", "RX1", "RX_RX1"},
  2056. {"IIR1 INP0 MUX", "RX2", "RX_RX2"},
  2057. {"IIR1 INP0 MUX", "RX3", "RX_RX3"},
  2058. {"IIR1 INP0 MUX", "RX4", "RX_RX4"},
  2059. {"IIR1 INP0 MUX", "RX5", "RX_RX5"},
  2060. {"IIR1", NULL, "IIR1 INP1 MUX"},
  2061. {"IIR1 INP1 MUX", "DEC0", "RX_TX DEC0_INP"},
  2062. {"IIR1 INP1 MUX", "DEC1", "RX_TX DEC1_INP"},
  2063. {"IIR1 INP1 MUX", "DEC2", "RX_TX DEC2_INP"},
  2064. {"IIR1 INP1 MUX", "DEC3", "RX_TX DEC3_INP"},
  2065. {"IIR1 INP1 MUX", "RX0", "RX_RX0"},
  2066. {"IIR1 INP1 MUX", "RX1", "RX_RX1"},
  2067. {"IIR1 INP1 MUX", "RX2", "RX_RX2"},
  2068. {"IIR1 INP1 MUX", "RX3", "RX_RX3"},
  2069. {"IIR1 INP1 MUX", "RX4", "RX_RX4"},
  2070. {"IIR1 INP1 MUX", "RX5", "RX_RX5"},
  2071. {"IIR1", NULL, "IIR1 INP2 MUX"},
  2072. {"IIR1 INP2 MUX", "DEC0", "RX_TX DEC0_INP"},
  2073. {"IIR1 INP2 MUX", "DEC1", "RX_TX DEC1_INP"},
  2074. {"IIR1 INP2 MUX", "DEC2", "RX_TX DEC2_INP"},
  2075. {"IIR1 INP2 MUX", "DEC3", "RX_TX DEC3_INP"},
  2076. {"IIR1 INP2 MUX", "RX0", "RX_RX0"},
  2077. {"IIR1 INP2 MUX", "RX1", "RX_RX1"},
  2078. {"IIR1 INP2 MUX", "RX2", "RX_RX2"},
  2079. {"IIR1 INP2 MUX", "RX3", "RX_RX3"},
  2080. {"IIR1 INP2 MUX", "RX4", "RX_RX4"},
  2081. {"IIR1 INP2 MUX", "RX5", "RX_RX5"},
  2082. {"IIR1", NULL, "IIR1 INP3 MUX"},
  2083. {"IIR1 INP3 MUX", "DEC0", "RX_TX DEC0_INP"},
  2084. {"IIR1 INP3 MUX", "DEC1", "RX_TX DEC1_INP"},
  2085. {"IIR1 INP3 MUX", "DEC2", "RX_TX DEC2_INP"},
  2086. {"IIR1 INP3 MUX", "DEC3", "RX_TX DEC3_INP"},
  2087. {"IIR1 INP3 MUX", "RX0", "RX_RX0"},
  2088. {"IIR1 INP3 MUX", "RX1", "RX_RX1"},
  2089. {"IIR1 INP3 MUX", "RX2", "RX_RX2"},
  2090. {"IIR1 INP3 MUX", "RX3", "RX_RX3"},
  2091. {"IIR1 INP3 MUX", "RX4", "RX_RX4"},
  2092. {"IIR1 INP3 MUX", "RX5", "RX_RX5"},
  2093. {"SRC0", NULL, "IIR0"},
  2094. {"SRC1", NULL, "IIR1"},
  2095. {"RX INT0 MIX2 INP", "SRC0", "SRC0"},
  2096. {"RX INT0 MIX2 INP", "SRC1", "SRC1"},
  2097. {"RX INT1 MIX2 INP", "SRC0", "SRC0"},
  2098. {"RX INT1 MIX2 INP", "SRC1", "SRC1"},
  2099. {"RX INT2 MIX2 INP", "SRC0", "SRC0"},
  2100. {"RX INT2 MIX2 INP", "SRC1", "SRC1"},
  2101. };
  2102. static int rx_swrm_clock(void *handle, bool enable)
  2103. {
  2104. struct rx_macro_priv *rx_priv = (struct rx_macro_priv *) handle;
  2105. struct regmap *regmap = dev_get_regmap(rx_priv->dev->parent, NULL);
  2106. int ret = 0;
  2107. mutex_lock(&rx_priv->swr_clk_lock);
  2108. dev_dbg(rx_priv->dev, "%s: swrm clock %s\n",
  2109. __func__, (enable ? "enable" : "disable"));
  2110. if (enable) {
  2111. if (rx_priv->swr_clk_users == 0) {
  2112. ret = rx_macro_mclk_enable(rx_priv, 1, true);
  2113. if (ret < 0) {
  2114. dev_err(rx_priv->dev,
  2115. "%s: rx request clock enable failed\n",
  2116. __func__);
  2117. goto exit;
  2118. }
  2119. regmap_update_bits(regmap,
  2120. BOLERO_CDC_RX_CLK_RST_CTRL_SWR_CONTROL,
  2121. 0x02, 0x02);
  2122. regmap_update_bits(regmap,
  2123. BOLERO_CDC_RX_CLK_RST_CTRL_SWR_CONTROL,
  2124. 0x01, 0x01);
  2125. regmap_update_bits(regmap,
  2126. BOLERO_CDC_RX_CLK_RST_CTRL_SWR_CONTROL,
  2127. 0x02, 0x00);
  2128. msm_cdc_pinctrl_select_active_state(
  2129. rx_priv->rx_swr_gpio_p);
  2130. }
  2131. rx_priv->swr_clk_users++;
  2132. } else {
  2133. if (rx_priv->swr_clk_users <= 0) {
  2134. dev_err(rx_priv->dev,
  2135. "%s: rx swrm clock users already reset\n",
  2136. __func__);
  2137. rx_priv->swr_clk_users = 0;
  2138. goto exit;
  2139. }
  2140. rx_priv->swr_clk_users--;
  2141. if (rx_priv->swr_clk_users == 0) {
  2142. regmap_update_bits(regmap,
  2143. BOLERO_CDC_RX_CLK_RST_CTRL_SWR_CONTROL,
  2144. 0x01, 0x00);
  2145. msm_cdc_pinctrl_select_sleep_state(
  2146. rx_priv->rx_swr_gpio_p);
  2147. rx_macro_mclk_enable(rx_priv, 0, true);
  2148. }
  2149. }
  2150. dev_dbg(rx_priv->dev, "%s: swrm clock users %d\n",
  2151. __func__, rx_priv->swr_clk_users);
  2152. exit:
  2153. mutex_unlock(&rx_priv->swr_clk_lock);
  2154. return ret;
  2155. }
  2156. static int rx_macro_init(struct snd_soc_codec *codec)
  2157. {
  2158. struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
  2159. int ret = 0;
  2160. struct device *rx_dev = NULL;
  2161. struct rx_macro_priv *rx_priv = NULL;
  2162. rx_dev = bolero_get_device_ptr(codec->dev, RX_MACRO);
  2163. if (!rx_dev) {
  2164. dev_err(codec->dev,
  2165. "%s: null device for macro!\n", __func__);
  2166. return -EINVAL;
  2167. }
  2168. rx_priv = dev_get_drvdata(rx_dev);
  2169. if (!rx_priv) {
  2170. dev_err(codec->dev,
  2171. "%s: priv is null for macro!\n", __func__);
  2172. return -EINVAL;
  2173. }
  2174. ret = snd_soc_dapm_new_controls(dapm, rx_macro_dapm_widgets,
  2175. ARRAY_SIZE(rx_macro_dapm_widgets));
  2176. if (ret < 0) {
  2177. dev_err(rx_dev, "%s: failed to add controls\n", __func__);
  2178. return ret;
  2179. }
  2180. ret = snd_soc_dapm_add_routes(dapm, rx_audio_map,
  2181. ARRAY_SIZE(rx_audio_map));
  2182. if (ret < 0) {
  2183. dev_err(rx_dev, "%s: failed to add routes\n", __func__);
  2184. return ret;
  2185. }
  2186. ret = snd_soc_dapm_new_widgets(dapm->card);
  2187. if (ret < 0) {
  2188. dev_err(rx_dev, "%s: failed to add widgets\n", __func__);
  2189. return ret;
  2190. }
  2191. ret = snd_soc_add_codec_controls(codec, rx_macro_snd_controls,
  2192. ARRAY_SIZE(rx_macro_snd_controls));
  2193. if (ret < 0) {
  2194. dev_err(rx_dev, "%s: failed to add snd_ctls\n", __func__);
  2195. return ret;
  2196. }
  2197. snd_soc_update_bits(codec, BOLERO_CDC_RX_RX0_RX_PATH_DSM_CTL, 0x01, 0x01);
  2198. snd_soc_update_bits(codec, BOLERO_CDC_RX_RX1_RX_PATH_DSM_CTL, 0x01, 0x01);
  2199. snd_soc_update_bits(codec, BOLERO_CDC_RX_RX2_RX_PATH_DSM_CTL, 0x01, 0x01);
  2200. snd_soc_update_bits(codec, BOLERO_CDC_RX_RX0_RX_PATH_SEC7, 0x07, 0x02);
  2201. snd_soc_update_bits(codec, BOLERO_CDC_RX_RX1_RX_PATH_SEC7, 0x07, 0x02);
  2202. snd_soc_update_bits(codec, BOLERO_CDC_RX_RX2_RX_PATH_SEC7, 0x07, 0x02);
  2203. snd_soc_update_bits(codec, BOLERO_CDC_RX_RX0_RX_PATH_CFG3, 0x03, 0x02);
  2204. snd_soc_update_bits(codec, BOLERO_CDC_RX_RX1_RX_PATH_CFG3, 0x03, 0x02);
  2205. snd_soc_update_bits(codec, BOLERO_CDC_RX_RX2_RX_PATH_CFG3, 0x03, 0x02);
  2206. rx_priv->codec = codec;
  2207. return 0;
  2208. }
  2209. static int rx_macro_deinit(struct snd_soc_codec *codec)
  2210. {
  2211. struct device *rx_dev = NULL;
  2212. struct rx_macro_priv *rx_priv = NULL;
  2213. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  2214. return -EINVAL;
  2215. rx_priv->codec = NULL;
  2216. return 0;
  2217. }
  2218. static void rx_macro_add_child_devices(struct work_struct *work)
  2219. {
  2220. struct rx_macro_priv *rx_priv = NULL;
  2221. struct platform_device *pdev = NULL;
  2222. struct device_node *node = NULL;
  2223. struct rx_swr_ctrl_data *swr_ctrl_data = NULL, *temp = NULL;
  2224. int ret = 0;
  2225. u16 count = 0, ctrl_num = 0;
  2226. struct rx_swr_ctrl_platform_data *platdata = NULL;
  2227. char plat_dev_name[RX_SWR_STRING_LEN] = "";
  2228. bool rx_swr_master_node = false;
  2229. rx_priv = container_of(work, struct rx_macro_priv,
  2230. rx_macro_add_child_devices_work);
  2231. if (!rx_priv) {
  2232. pr_err("%s: Memory for rx_priv does not exist\n",
  2233. __func__);
  2234. return;
  2235. }
  2236. if (!rx_priv->dev) {
  2237. pr_err("%s: RX device does not exist\n", __func__);
  2238. return;
  2239. }
  2240. if(!rx_priv->dev->of_node) {
  2241. dev_err(rx_priv->dev,
  2242. "%s: DT node for RX dev does not exist\n", __func__);
  2243. return;
  2244. }
  2245. platdata = &rx_priv->swr_plat_data;
  2246. rx_priv->child_count = 0;
  2247. for_each_available_child_of_node(rx_priv->dev->of_node, node) {
  2248. rx_swr_master_node = false;
  2249. if (strnstr(node->name, "rx_swr_master",
  2250. strlen("rx_swr_master")) != NULL)
  2251. rx_swr_master_node = true;
  2252. if(rx_swr_master_node)
  2253. strlcpy(plat_dev_name, "rx_swr_ctrl",
  2254. (RX_SWR_STRING_LEN - 1));
  2255. else
  2256. strlcpy(plat_dev_name, node->name,
  2257. (RX_SWR_STRING_LEN - 1));
  2258. pdev = platform_device_alloc(plat_dev_name, -1);
  2259. if (!pdev) {
  2260. dev_err(rx_priv->dev, "%s: pdev memory alloc failed\n",
  2261. __func__);
  2262. ret = -ENOMEM;
  2263. goto err;
  2264. }
  2265. pdev->dev.parent = rx_priv->dev;
  2266. pdev->dev.of_node = node;
  2267. if (rx_swr_master_node) {
  2268. ret = platform_device_add_data(pdev, platdata,
  2269. sizeof(*platdata));
  2270. if (ret) {
  2271. dev_err(&pdev->dev,
  2272. "%s: cannot add plat data ctrl:%d\n",
  2273. __func__, ctrl_num);
  2274. goto fail_pdev_add;
  2275. }
  2276. }
  2277. ret = platform_device_add(pdev);
  2278. if (ret) {
  2279. dev_err(&pdev->dev,
  2280. "%s: Cannot add platform device\n",
  2281. __func__);
  2282. goto fail_pdev_add;
  2283. }
  2284. if (rx_swr_master_node) {
  2285. temp = krealloc(swr_ctrl_data,
  2286. (ctrl_num + 1) * sizeof(
  2287. struct rx_swr_ctrl_data),
  2288. GFP_KERNEL);
  2289. if (!temp) {
  2290. ret = -ENOMEM;
  2291. goto fail_pdev_add;
  2292. }
  2293. swr_ctrl_data = temp;
  2294. swr_ctrl_data[ctrl_num].rx_swr_pdev = pdev;
  2295. ctrl_num++;
  2296. dev_dbg(&pdev->dev,
  2297. "%s: Added soundwire ctrl device(s)\n",
  2298. __func__);
  2299. rx_priv->swr_ctrl_data = swr_ctrl_data;
  2300. }
  2301. if (rx_priv->child_count < RX_MACRO_CHILD_DEVICES_MAX)
  2302. rx_priv->pdev_child_devices[
  2303. rx_priv->child_count++] = pdev;
  2304. else
  2305. goto err;
  2306. }
  2307. return;
  2308. fail_pdev_add:
  2309. for (count = 0; count < rx_priv->child_count; count++)
  2310. platform_device_put(rx_priv->pdev_child_devices[count]);
  2311. err:
  2312. return;
  2313. }
  2314. static void rx_macro_init_ops(struct macro_ops *ops, char __iomem *rx_io_base)
  2315. {
  2316. memset(ops, 0, sizeof(struct macro_ops));
  2317. ops->init = rx_macro_init;
  2318. ops->exit = rx_macro_deinit;
  2319. ops->io_base = rx_io_base;
  2320. ops->dai_ptr = rx_macro_dai;
  2321. ops->num_dais = ARRAY_SIZE(rx_macro_dai);
  2322. ops->mclk_fn = rx_macro_mclk_ctrl;
  2323. }
  2324. static int rx_macro_probe(struct platform_device *pdev)
  2325. {
  2326. struct macro_ops ops = {0};
  2327. struct rx_macro_priv *rx_priv = NULL;
  2328. u32 rx_base_addr = 0, muxsel = 0;
  2329. char __iomem *rx_io_base = NULL, *muxsel_io = NULL;
  2330. int ret = 0;
  2331. struct clk *rx_core_clk = NULL, *rx_npl_clk = NULL;
  2332. rx_priv = devm_kzalloc(&pdev->dev, sizeof(struct rx_macro_priv),
  2333. GFP_KERNEL);
  2334. if (!rx_priv)
  2335. return -ENOMEM;
  2336. rx_priv->dev = &pdev->dev;
  2337. ret = of_property_read_u32(pdev->dev.of_node, "reg",
  2338. &rx_base_addr);
  2339. if (ret) {
  2340. dev_err(&pdev->dev, "%s: could not find %s entry in dt\n",
  2341. __func__, "reg");
  2342. return ret;
  2343. }
  2344. ret = of_property_read_u32(pdev->dev.of_node, "qcom,rx_mclk_mode_muxsel",
  2345. &muxsel);
  2346. if (ret) {
  2347. dev_err(&pdev->dev, "%s: could not find %s entry in dt\n",
  2348. __func__, "reg");
  2349. return ret;
  2350. }
  2351. rx_priv->rx_swr_gpio_p = of_parse_phandle(pdev->dev.of_node,
  2352. "qcom,rx-swr-gpios", 0);
  2353. if (!rx_priv->rx_swr_gpio_p) {
  2354. dev_err(&pdev->dev, "%s: swr_gpios handle not provided!\n",
  2355. __func__);
  2356. return -EINVAL;
  2357. }
  2358. rx_io_base = devm_ioremap(&pdev->dev, rx_base_addr,
  2359. RX_MACRO_MAX_OFFSET);
  2360. if (!rx_io_base) {
  2361. dev_err(&pdev->dev, "%s: ioremap failed\n", __func__);
  2362. return -ENOMEM;
  2363. }
  2364. rx_priv->rx_io_base = rx_io_base;
  2365. muxsel_io = devm_ioremap(&pdev->dev, muxsel, 0x4);
  2366. if (!muxsel_io) {
  2367. dev_err(&pdev->dev, "%s: ioremap failed for muxsel\n",
  2368. __func__);
  2369. return -ENOMEM;
  2370. }
  2371. rx_priv->rx_mclk_mode_muxsel = muxsel_io;
  2372. INIT_WORK(&rx_priv->rx_macro_add_child_devices_work,
  2373. rx_macro_add_child_devices);
  2374. rx_priv->swr_plat_data.handle = (void *) rx_priv;
  2375. rx_priv->swr_plat_data.read = NULL;
  2376. rx_priv->swr_plat_data.write = NULL;
  2377. rx_priv->swr_plat_data.bulk_write = NULL;
  2378. rx_priv->swr_plat_data.clk = rx_swrm_clock;
  2379. rx_priv->swr_plat_data.handle_irq = NULL;
  2380. /* Register MCLK for rx macro */
  2381. rx_core_clk = devm_clk_get(&pdev->dev, "rx_core_clk");
  2382. if (IS_ERR(rx_core_clk)) {
  2383. ret = PTR_ERR(rx_core_clk);
  2384. dev_err(&pdev->dev, "%s: clk get %s failed %d\n",
  2385. __func__, "rx_core_clk", ret);
  2386. return ret;
  2387. }
  2388. rx_priv->rx_core_clk = rx_core_clk;
  2389. /* Register npl clk for soundwire */
  2390. rx_npl_clk = devm_clk_get(&pdev->dev, "rx_npl_clk");
  2391. if (IS_ERR(rx_npl_clk)) {
  2392. ret = PTR_ERR(rx_npl_clk);
  2393. dev_err(&pdev->dev, "%s: clk get %s failed %d\n",
  2394. __func__, "rx_npl_clk", ret);
  2395. return ret;
  2396. }
  2397. rx_priv->rx_npl_clk = rx_npl_clk;
  2398. dev_set_drvdata(&pdev->dev, rx_priv);
  2399. mutex_init(&rx_priv->mclk_lock);
  2400. mutex_init(&rx_priv->swr_clk_lock);
  2401. rx_macro_init_ops(&ops, rx_io_base);
  2402. ret = bolero_register_macro(&pdev->dev, RX_MACRO, &ops);
  2403. if (ret) {
  2404. dev_err(&pdev->dev,
  2405. "%s: register macro failed\n", __func__);
  2406. goto err_reg_macro;
  2407. }
  2408. schedule_work(&rx_priv->rx_macro_add_child_devices_work);
  2409. return 0;
  2410. err_reg_macro:
  2411. mutex_destroy(&rx_priv->mclk_lock);
  2412. mutex_destroy(&rx_priv->swr_clk_lock);
  2413. return ret;
  2414. }
  2415. static int rx_macro_remove(struct platform_device *pdev)
  2416. {
  2417. struct rx_macro_priv *rx_priv = NULL;
  2418. u16 count = 0;
  2419. rx_priv = dev_get_drvdata(&pdev->dev);
  2420. if (!rx_priv)
  2421. return -EINVAL;
  2422. for (count = 0; count < rx_priv->child_count &&
  2423. count < RX_MACRO_CHILD_DEVICES_MAX; count++)
  2424. platform_device_unregister(rx_priv->pdev_child_devices[count]);
  2425. bolero_unregister_macro(&pdev->dev, RX_MACRO);
  2426. mutex_destroy(&rx_priv->mclk_lock);
  2427. mutex_destroy(&rx_priv->swr_clk_lock);
  2428. kfree(rx_priv->swr_ctrl_data);
  2429. return 0;
  2430. }
  2431. static const struct of_device_id rx_macro_dt_match[] = {
  2432. {.compatible = "qcom,rx-macro"},
  2433. {}
  2434. };
  2435. static struct platform_driver rx_macro_driver = {
  2436. .driver = {
  2437. .name = "rx_macro",
  2438. .owner = THIS_MODULE,
  2439. .of_match_table = rx_macro_dt_match,
  2440. },
  2441. .probe = rx_macro_probe,
  2442. .remove = rx_macro_remove,
  2443. };
  2444. module_platform_driver(rx_macro_driver);
  2445. MODULE_DESCRIPTION("RX macro driver");
  2446. MODULE_LICENSE("GPL v2");