wcd938x.c 83 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2018-2019, The Linux Foundation. All rights reserved.
  4. */
  5. #include <linux/module.h>
  6. #include <linux/slab.h>
  7. #include <linux/platform_device.h>
  8. #include <linux/device.h>
  9. #include <linux/delay.h>
  10. #include <linux/kernel.h>
  11. #include <linux/component.h>
  12. #include <sound/soc.h>
  13. #include <sound/tlv.h>
  14. #include <soc/soundwire.h>
  15. #include <linux/regmap.h>
  16. #include <sound/soc.h>
  17. #include <sound/soc-dapm.h>
  18. #include <asoc/wcdcal-hwdep.h>
  19. #include <asoc/msm-cdc-pinctrl.h>
  20. #include <asoc/msm-cdc-supply.h>
  21. #include <dt-bindings/sound/audio-codec-port-types.h>
  22. #include "internal.h"
  23. #include "wcd938x-registers.h"
  24. #define WCD938X_DRV_NAME "wcd938x_codec"
  25. #define NUM_SWRS_DT_PARAMS 5
  26. #define WCD938X_VERSION_1_0 1
  27. #define WCD938X_VERSION_ENTRY_SIZE 32
  28. #define ADC_MODE_VAL_HIFI 0x01
  29. #define ADC_MODE_VAL_LO_HIF 0x02
  30. #define ADC_MODE_VAL_NORMAL 0x03
  31. #define ADC_MODE_VAL_LP 0x05
  32. #define ADC_MODE_VAL_ULP1 0x09
  33. #define ADC_MODE_VAL_ULP2 0x0B
  34. enum {
  35. WCD9380 = 0,
  36. WCD9385 = 5,
  37. };
  38. enum {
  39. CODEC_TX = 0,
  40. CODEC_RX,
  41. };
  42. enum {
  43. WCD_ADC1 = 0,
  44. WCD_ADC2,
  45. WCD_ADC3,
  46. WCD_ADC4,
  47. ALLOW_BUCK_DISABLE,
  48. HPH_COMP_DELAY,
  49. HPH_PA_DELAY,
  50. };
  51. enum {
  52. ADC_MODE_INVALID = 0,
  53. ADC_MODE_HIFI,
  54. ADC_MODE_LO_HIF,
  55. ADC_MODE_NORMAL,
  56. ADC_MODE_LP,
  57. ADC_MODE_ULP1,
  58. ADC_MODE_ULP2,
  59. };
  60. static const DECLARE_TLV_DB_SCALE(line_gain, 0, 7, 1);
  61. static const DECLARE_TLV_DB_SCALE(analog_gain, 0, 25, 1);
  62. static int wcd938x_handle_post_irq(void *data);
  63. static int wcd938x_reset(struct device *dev);
  64. static int wcd938x_reset_low(struct device *dev);
  65. static const struct regmap_irq wcd938x_irqs[WCD938X_NUM_IRQS] = {
  66. REGMAP_IRQ_REG(WCD938X_IRQ_MBHC_BUTTON_PRESS_DET, 0, 0x01),
  67. REGMAP_IRQ_REG(WCD938X_IRQ_MBHC_BUTTON_RELEASE_DET, 0, 0x02),
  68. REGMAP_IRQ_REG(WCD938X_IRQ_MBHC_ELECT_INS_REM_DET, 0, 0x04),
  69. REGMAP_IRQ_REG(WCD938X_IRQ_MBHC_ELECT_INS_REM_LEG_DET, 0, 0x08),
  70. REGMAP_IRQ_REG(WCD938X_IRQ_MBHC_SW_DET, 0, 0x10),
  71. REGMAP_IRQ_REG(WCD938X_IRQ_HPHR_OCP_INT, 0, 0x20),
  72. REGMAP_IRQ_REG(WCD938X_IRQ_HPHR_CNP_INT, 0, 0x40),
  73. REGMAP_IRQ_REG(WCD938X_IRQ_HPHL_OCP_INT, 0, 0x80),
  74. REGMAP_IRQ_REG(WCD938X_IRQ_HPHL_CNP_INT, 1, 0x01),
  75. REGMAP_IRQ_REG(WCD938X_IRQ_EAR_CNP_INT, 1, 0x02),
  76. REGMAP_IRQ_REG(WCD938X_IRQ_EAR_SCD_INT, 1, 0x04),
  77. REGMAP_IRQ_REG(WCD938X_IRQ_AUX_CNP_INT, 1, 0x08),
  78. REGMAP_IRQ_REG(WCD938X_IRQ_AUX_SCD_INT, 1, 0x10),
  79. REGMAP_IRQ_REG(WCD938X_IRQ_HPHL_PDM_WD_INT, 1, 0x20),
  80. REGMAP_IRQ_REG(WCD938X_IRQ_HPHR_PDM_WD_INT, 1, 0x40),
  81. REGMAP_IRQ_REG(WCD938X_IRQ_AUX_PDM_WD_INT, 1, 0x80),
  82. REGMAP_IRQ_REG(WCD938X_IRQ_LDORT_SCD_INT, 2, 0x01),
  83. REGMAP_IRQ_REG(WCD938X_IRQ_MBHC_MOISTURE_INT, 2, 0x02),
  84. REGMAP_IRQ_REG(WCD938X_IRQ_HPHL_SURGE_DET_INT, 2, 0x04),
  85. REGMAP_IRQ_REG(WCD938X_IRQ_HPHR_SURGE_DET_INT, 2, 0x08),
  86. };
  87. static struct regmap_irq_chip wcd938x_regmap_irq_chip = {
  88. .name = "wcd938x",
  89. .irqs = wcd938x_irqs,
  90. .num_irqs = ARRAY_SIZE(wcd938x_irqs),
  91. .num_regs = 3,
  92. .status_base = WCD938X_DIGITAL_INTR_STATUS_0,
  93. .mask_base = WCD938X_DIGITAL_INTR_MASK_0,
  94. .type_base = WCD938X_DIGITAL_INTR_LEVEL_0,
  95. .ack_base = WCD938X_DIGITAL_INTR_CLEAR_0,
  96. .use_ack = 1,
  97. .runtime_pm = false,
  98. .handle_post_irq = wcd938x_handle_post_irq,
  99. .irq_drv_data = NULL,
  100. };
  101. static int wcd938x_handle_post_irq(void *data)
  102. {
  103. struct wcd938x_priv *wcd938x = data;
  104. u32 sts1 = 0, sts2 = 0, sts3 = 0;
  105. regmap_read(wcd938x->regmap, WCD938X_DIGITAL_INTR_STATUS_0, &sts1);
  106. regmap_read(wcd938x->regmap, WCD938X_DIGITAL_INTR_STATUS_1, &sts2);
  107. regmap_read(wcd938x->regmap, WCD938X_DIGITAL_INTR_STATUS_2, &sts3);
  108. wcd938x->tx_swr_dev->slave_irq_pending =
  109. ((sts1 || sts2 || sts3) ? true : false);
  110. return IRQ_HANDLED;
  111. }
  112. static int wcd938x_init_reg(struct snd_soc_component *component)
  113. {
  114. snd_soc_component_update_bits(component, WCD938X_SLEEP_CTL, 0x0E, 0x0E);
  115. snd_soc_component_update_bits(component, WCD938X_SLEEP_CTL, 0x80, 0x80);
  116. /* 1 msec delay as per HW requirement */
  117. usleep_range(1000, 1010);
  118. snd_soc_component_update_bits(component, WCD938X_SLEEP_CTL, 0x40, 0x40);
  119. /* 1 msec delay as per HW requirement */
  120. usleep_range(1000, 1010);
  121. snd_soc_component_update_bits(component, WCD938X_LDORXTX_CONFIG,
  122. 0x10, 0x00);
  123. snd_soc_component_update_bits(component, WCD938X_BIAS_VBG_FINE_ADJ,
  124. 0xF0, 0x80);
  125. snd_soc_component_update_bits(component, WCD938X_ANA_BIAS, 0x80, 0x80);
  126. snd_soc_component_update_bits(component, WCD938X_ANA_BIAS, 0x40, 0x40);
  127. /* 10 msec delay as per HW requirement */
  128. usleep_range(10000, 10010);
  129. snd_soc_component_update_bits(component, WCD938X_ANA_BIAS, 0x40, 0x00);
  130. snd_soc_component_update_bits(component, WCD938X_HPH_OCP_CTL,
  131. 0xFF, 0x3A);
  132. snd_soc_component_update_bits(component, WCD938X_RX_OCP_CTL,
  133. 0x0F, 0x02);
  134. snd_soc_component_update_bits(component, WCD938X_HPH_R_TEST,
  135. 0x01, 0x01);
  136. snd_soc_component_update_bits(component, WCD938X_HPH_L_TEST,
  137. 0x01, 0x01);
  138. snd_soc_component_update_bits(component,
  139. WCD938X_HPH_NEW_INT_RDAC_GAIN_CTL,
  140. 0xF0, 0x00);
  141. snd_soc_component_update_bits(component,
  142. WCD938X_HPH_NEW_INT_RDAC_HD2_CTL_L_NEW,
  143. 0x1F, 0x15);
  144. snd_soc_component_update_bits(component,
  145. WCD938X_HPH_NEW_INT_RDAC_HD2_CTL_R_NEW,
  146. 0x1F, 0x15);
  147. snd_soc_component_update_bits(component, WCD938X_HPH_REFBUFF_UHQA_CTL,
  148. 0xC0, 0x80);
  149. snd_soc_component_update_bits(component, WCD938X_DIGITAL_CDC_DMIC_CTL,
  150. 0x02, 0x02);
  151. return 0;
  152. }
  153. static int wcd938x_set_port_params(struct snd_soc_component *component,
  154. u8 slv_prt_type, u8 *port_id, u8 *num_ch,
  155. u8 *ch_mask, u32 *ch_rate,
  156. u8 *port_type, u8 path)
  157. {
  158. int i, j;
  159. u8 num_ports = 0;
  160. struct codec_port_info (*map)[MAX_PORT][MAX_CH_PER_PORT];
  161. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  162. switch (path) {
  163. case CODEC_RX:
  164. map = &wcd938x->rx_port_mapping;
  165. num_ports = wcd938x->num_rx_ports;
  166. break;
  167. case CODEC_TX:
  168. map = &wcd938x->tx_port_mapping;
  169. num_ports = wcd938x->num_tx_ports;
  170. break;
  171. default:
  172. dev_err(component->dev, "%s Invalid path selected %u\n",
  173. __func__, path);
  174. return -EINVAL;
  175. }
  176. for (i = 0; i <= num_ports; i++) {
  177. for (j = 0; j < MAX_CH_PER_PORT; j++) {
  178. if ((*map)[i][j].slave_port_type == slv_prt_type)
  179. goto found;
  180. }
  181. }
  182. found:
  183. if (i > num_ports || j == MAX_CH_PER_PORT) {
  184. dev_err(component->dev, "%s Failed to find slave port for type %u\n",
  185. __func__, slv_prt_type);
  186. return -EINVAL;
  187. }
  188. *port_id = i;
  189. *num_ch = (*map)[i][j].num_ch;
  190. *ch_mask = (*map)[i][j].ch_mask;
  191. *ch_rate = (*map)[i][j].ch_rate;
  192. *port_type = (*map)[i][j].master_port_type;
  193. return 0;
  194. }
  195. static int wcd938x_parse_port_mapping(struct device *dev,
  196. char *prop, u8 path)
  197. {
  198. u32 *dt_array, map_size, map_length;
  199. u32 port_num = 0, ch_mask, ch_rate, old_port_num = 0;
  200. u32 slave_port_type, master_port_type;
  201. u32 i, ch_iter = 0;
  202. int ret = 0;
  203. u8 *num_ports = NULL;
  204. struct codec_port_info (*map)[MAX_PORT][MAX_CH_PER_PORT];
  205. struct wcd938x_priv *wcd938x = dev_get_drvdata(dev);
  206. switch (path) {
  207. case CODEC_RX:
  208. map = &wcd938x->rx_port_mapping;
  209. num_ports = &wcd938x->num_rx_ports;
  210. break;
  211. case CODEC_TX:
  212. map = &wcd938x->tx_port_mapping;
  213. num_ports = &wcd938x->num_tx_ports;
  214. break;
  215. default:
  216. dev_err(dev, "%s Invalid path selected %u\n",
  217. __func__, path);
  218. return -EINVAL;
  219. }
  220. if (!of_find_property(dev->of_node, prop,
  221. &map_size)) {
  222. dev_err(dev, "missing port mapping prop %s\n", prop);
  223. ret = -EINVAL;
  224. goto err_port_map;
  225. }
  226. map_length = map_size / (NUM_SWRS_DT_PARAMS * sizeof(u32));
  227. dt_array = kzalloc(map_size, GFP_KERNEL);
  228. if (!dt_array) {
  229. ret = -ENOMEM;
  230. goto err_alloc;
  231. }
  232. ret = of_property_read_u32_array(dev->of_node, prop, dt_array,
  233. NUM_SWRS_DT_PARAMS * map_length);
  234. if (ret) {
  235. dev_err(dev, "%s: Failed to read port mapping from prop %s\n",
  236. __func__, prop);
  237. goto err_pdata_fail;
  238. }
  239. for (i = 0; i < map_length; i++) {
  240. port_num = dt_array[NUM_SWRS_DT_PARAMS * i];
  241. slave_port_type = dt_array[NUM_SWRS_DT_PARAMS * i + 1];
  242. ch_mask = dt_array[NUM_SWRS_DT_PARAMS * i + 2];
  243. ch_rate = dt_array[NUM_SWRS_DT_PARAMS * i + 3];
  244. master_port_type = dt_array[NUM_SWRS_DT_PARAMS * i + 4];
  245. if (port_num != old_port_num)
  246. ch_iter = 0;
  247. (*map)[port_num][ch_iter].slave_port_type = slave_port_type;
  248. (*map)[port_num][ch_iter].ch_mask = ch_mask;
  249. (*map)[port_num][ch_iter].master_port_type = master_port_type;
  250. (*map)[port_num][ch_iter].num_ch = __sw_hweight8(ch_mask);
  251. (*map)[port_num][ch_iter++].ch_rate = ch_rate;
  252. old_port_num = port_num;
  253. }
  254. *num_ports = port_num;
  255. kfree(dt_array);
  256. return 0;
  257. err_pdata_fail:
  258. kfree(dt_array);
  259. err_alloc:
  260. err_port_map:
  261. return ret;
  262. }
  263. static int wcd938x_tx_connect_port(struct snd_soc_component *component,
  264. u8 slv_port_type, u8 enable)
  265. {
  266. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  267. u8 port_id, num_ch, ch_mask, port_type;
  268. u32 ch_rate;
  269. u8 num_port = 1;
  270. int ret = 0;
  271. ret = wcd938x_set_port_params(component, slv_port_type, &port_id,
  272. &num_ch, &ch_mask, &ch_rate,
  273. &port_type, CODEC_TX);
  274. if (ret)
  275. return ret;
  276. if (enable)
  277. ret = swr_connect_port(wcd938x->tx_swr_dev, &port_id,
  278. num_port, &ch_mask, &ch_rate,
  279. &num_ch, &port_type);
  280. else
  281. ret = swr_disconnect_port(wcd938x->tx_swr_dev, &port_id,
  282. num_port, &ch_mask, &port_type);
  283. return ret;
  284. }
  285. static int wcd938x_rx_connect_port(struct snd_soc_component *component,
  286. u8 slv_port_type, u8 enable)
  287. {
  288. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  289. u8 port_id, num_ch, ch_mask, port_type;
  290. u32 ch_rate;
  291. u8 num_port = 1;
  292. int ret = 0;
  293. ret = wcd938x_set_port_params(component, slv_port_type, &port_id,
  294. &num_ch, &ch_mask, &ch_rate,
  295. &port_type, CODEC_RX);
  296. if (ret)
  297. return ret;
  298. if (enable)
  299. ret = swr_connect_port(wcd938x->rx_swr_dev, &port_id,
  300. num_port, &ch_mask, &ch_rate,
  301. &num_ch, &port_type);
  302. else
  303. ret = swr_disconnect_port(wcd938x->rx_swr_dev, &port_id,
  304. num_port, &ch_mask, &port_type);
  305. return ret;
  306. }
  307. static int wcd938x_rx_clk_enable(struct snd_soc_component *component)
  308. {
  309. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  310. if (wcd938x->rx_clk_cnt == 0) {
  311. snd_soc_component_update_bits(component,
  312. WCD938X_DIGITAL_CDC_ANA_CLK_CTL, 0x01, 0x01);
  313. snd_soc_component_update_bits(component,
  314. WCD938X_ANA_RX_SUPPLIES, 0x01, 0x01);
  315. snd_soc_component_update_bits(component,
  316. WCD938X_DIGITAL_CDC_RX0_CTL, 0x40, 0x00);
  317. snd_soc_component_update_bits(component,
  318. WCD938X_DIGITAL_CDC_RX1_CTL, 0x40, 0x00);
  319. snd_soc_component_update_bits(component,
  320. WCD938X_DIGITAL_CDC_RX2_CTL, 0x40, 0x00);
  321. snd_soc_component_update_bits(component,
  322. WCD938X_DIGITAL_CDC_ANA_CLK_CTL, 0x02, 0x02);
  323. }
  324. wcd938x->rx_clk_cnt++;
  325. return 0;
  326. }
  327. static int wcd938x_rx_clk_disable(struct snd_soc_component *component)
  328. {
  329. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  330. wcd938x->rx_clk_cnt--;
  331. if (wcd938x->rx_clk_cnt == 0) {
  332. snd_soc_component_update_bits(component,
  333. WCD938X_ANA_RX_SUPPLIES, 0x40, 0x00);
  334. snd_soc_component_update_bits(component,
  335. WCD938X_ANA_RX_SUPPLIES, 0x80, 0x00);
  336. snd_soc_component_update_bits(component,
  337. WCD938X_ANA_RX_SUPPLIES, 0x01, 0x00);
  338. snd_soc_component_update_bits(component,
  339. WCD938X_DIGITAL_CDC_ANA_CLK_CTL, 0x02, 0x00);
  340. snd_soc_component_update_bits(component,
  341. WCD938X_DIGITAL_CDC_ANA_CLK_CTL, 0x01, 0x00);
  342. }
  343. return 0;
  344. }
  345. /*
  346. * wcd938x_soc_get_mbhc: get wcd938x_mbhc handle of corresponding component
  347. * @component: handle to snd_soc_component *
  348. *
  349. * return wcd938x_mbhc handle or error code in case of failure
  350. */
  351. struct wcd938x_mbhc *wcd938x_soc_get_mbhc(struct snd_soc_component *component)
  352. {
  353. struct wcd938x_priv *wcd938x;
  354. if (!component) {
  355. pr_err("%s: Invalid params, NULL component\n", __func__);
  356. return NULL;
  357. }
  358. wcd938x = snd_soc_component_get_drvdata(component);
  359. if (!wcd938x) {
  360. pr_err("%s: wcd938x is NULL\n", __func__);
  361. return NULL;
  362. }
  363. return wcd938x->mbhc;
  364. }
  365. EXPORT_SYMBOL(wcd938x_soc_get_mbhc);
  366. static int wcd938x_codec_hphl_dac_event(struct snd_soc_dapm_widget *w,
  367. struct snd_kcontrol *kcontrol,
  368. int event)
  369. {
  370. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  371. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  372. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  373. w->name, event);
  374. switch (event) {
  375. case SND_SOC_DAPM_PRE_PMU:
  376. wcd938x_rx_clk_enable(component);
  377. snd_soc_component_update_bits(component,
  378. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0x01, 0x01);
  379. snd_soc_component_update_bits(component,
  380. WCD938X_DIGITAL_CDC_HPH_GAIN_CTL, 0x04, 0x04);
  381. snd_soc_component_update_bits(component,
  382. WCD938X_HPH_RDAC_CLK_CTL1, 0x80, 0x00);
  383. break;
  384. case SND_SOC_DAPM_POST_PMU:
  385. snd_soc_component_update_bits(component,
  386. WCD938X_HPH_NEW_INT_RDAC_HD2_CTL_L, 0x0F, 0x02);
  387. if (wcd938x->comp1_enable) {
  388. snd_soc_component_update_bits(component,
  389. WCD938X_DIGITAL_CDC_COMP_CTL_0, 0x02, 0x02);
  390. /* 5msec compander delay as per HW requirement */
  391. if (!wcd938x->comp2_enable ||
  392. (snd_soc_component_read32(component,
  393. WCD938X_DIGITAL_CDC_COMP_CTL_0) & 0x01))
  394. usleep_range(5000, 5010);
  395. snd_soc_component_update_bits(component,
  396. WCD938X_HPH_NEW_INT_HPH_TIMER1, 0x02, 0x00);
  397. } else {
  398. snd_soc_component_update_bits(component,
  399. WCD938X_DIGITAL_CDC_COMP_CTL_0,
  400. 0x02, 0x00);
  401. snd_soc_component_update_bits(component,
  402. WCD938X_HPH_L_EN, 0x20, 0x20);
  403. }
  404. break;
  405. case SND_SOC_DAPM_POST_PMD:
  406. snd_soc_component_update_bits(component,
  407. WCD938X_HPH_NEW_INT_RDAC_HD2_CTL_R,
  408. 0x0F, 0x01);
  409. break;
  410. }
  411. return 0;
  412. }
  413. static int wcd938x_codec_hphr_dac_event(struct snd_soc_dapm_widget *w,
  414. struct snd_kcontrol *kcontrol,
  415. int event)
  416. {
  417. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  418. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  419. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  420. w->name, event);
  421. switch (event) {
  422. case SND_SOC_DAPM_PRE_PMU:
  423. wcd938x_rx_clk_enable(component);
  424. snd_soc_component_update_bits(component,
  425. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0x02, 0x02);
  426. snd_soc_component_update_bits(component,
  427. WCD938X_DIGITAL_CDC_HPH_GAIN_CTL, 0x08, 0x08);
  428. snd_soc_component_update_bits(component,
  429. WCD938X_HPH_RDAC_CLK_CTL1, 0x80, 0x00);
  430. break;
  431. case SND_SOC_DAPM_POST_PMU:
  432. snd_soc_component_update_bits(component,
  433. WCD938X_HPH_NEW_INT_RDAC_HD2_CTL_R, 0x0F, 0x02);
  434. if (wcd938x->comp2_enable) {
  435. snd_soc_component_update_bits(component,
  436. WCD938X_DIGITAL_CDC_COMP_CTL_0, 0x01, 0x01);
  437. /* 5msec compander delay as per HW requirement */
  438. if (!wcd938x->comp1_enable ||
  439. (snd_soc_component_read32(component,
  440. WCD938X_DIGITAL_CDC_COMP_CTL_0) & 0x02))
  441. usleep_range(5000, 5010);
  442. snd_soc_component_update_bits(component,
  443. WCD938X_HPH_NEW_INT_HPH_TIMER1, 0x02, 0x00);
  444. } else {
  445. snd_soc_component_update_bits(component,
  446. WCD938X_DIGITAL_CDC_COMP_CTL_0,
  447. 0x01, 0x00);
  448. snd_soc_component_update_bits(component,
  449. WCD938X_HPH_R_EN, 0x20, 0x20);
  450. }
  451. break;
  452. case SND_SOC_DAPM_POST_PMD:
  453. snd_soc_component_update_bits(component,
  454. WCD938X_HPH_NEW_INT_RDAC_HD2_CTL_R,
  455. 0x0F, 0x01);
  456. break;
  457. }
  458. return 0;
  459. }
  460. static int wcd938x_codec_ear_dac_event(struct snd_soc_dapm_widget *w,
  461. struct snd_kcontrol *kcontrol,
  462. int event)
  463. {
  464. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  465. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  466. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  467. w->name, event);
  468. switch (event) {
  469. case SND_SOC_DAPM_PRE_PMU:
  470. wcd938x_rx_clk_enable(component);
  471. snd_soc_component_update_bits(component,
  472. WCD938X_DIGITAL_CDC_HPH_GAIN_CTL, 0x04, 0x04);
  473. snd_soc_component_update_bits(component,
  474. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0x01, 0x01);
  475. snd_soc_component_update_bits(component,
  476. WCD938X_DIGITAL_CDC_COMP_CTL_0, 0x02, 0x02);
  477. /* 5 msec delay as per HW requirement */
  478. usleep_range(5000, 5010);
  479. snd_soc_component_update_bits(component, WCD938X_FLYBACK_EN,
  480. 0x04, 0x00);
  481. wcd_cls_h_fsm(component, &wcd938x->clsh_info,
  482. WCD_CLSH_EVENT_PRE_DAC,
  483. WCD_CLSH_STATE_EAR,
  484. wcd938x->hph_mode);
  485. break;
  486. case SND_SOC_DAPM_POST_PMD:
  487. break;
  488. };
  489. return 0;
  490. }
  491. static int wcd938x_codec_aux_dac_event(struct snd_soc_dapm_widget *w,
  492. struct snd_kcontrol *kcontrol,
  493. int event)
  494. {
  495. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  496. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  497. int ret = 0;
  498. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  499. w->name, event);
  500. switch (event) {
  501. case SND_SOC_DAPM_PRE_PMU:
  502. wcd938x_rx_clk_enable(component);
  503. snd_soc_component_update_bits(component,
  504. WCD938X_DIGITAL_CDC_ANA_CLK_CTL, 0x04, 0x04);
  505. snd_soc_component_update_bits(component,
  506. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0x04, 0x04);
  507. snd_soc_component_update_bits(component,
  508. WCD938X_DIGITAL_CDC_AUX_GAIN_CTL, 0x01, 0x01);
  509. wcd_cls_h_fsm(component, &wcd938x->clsh_info,
  510. WCD_CLSH_EVENT_PRE_DAC,
  511. WCD_CLSH_STATE_AUX,
  512. wcd938x->hph_mode);
  513. break;
  514. case SND_SOC_DAPM_POST_PMD:
  515. wcd938x_rx_clk_disable(component);
  516. snd_soc_component_update_bits(component,
  517. WCD938X_DIGITAL_CDC_ANA_CLK_CTL, 0x04, 0x00);
  518. break;
  519. };
  520. return ret;
  521. }
  522. static int wcd938x_codec_enable_hphr_pa(struct snd_soc_dapm_widget *w,
  523. struct snd_kcontrol *kcontrol,
  524. int event)
  525. {
  526. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  527. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  528. int ret = 0;
  529. int hph_mode = wcd938x->hph_mode;
  530. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  531. w->name, event);
  532. switch (event) {
  533. case SND_SOC_DAPM_PRE_PMU:
  534. ret = swr_slvdev_datapath_control(wcd938x->rx_swr_dev,
  535. wcd938x->rx_swr_dev->dev_num,
  536. true);
  537. wcd_cls_h_fsm(component, &wcd938x->clsh_info,
  538. WCD_CLSH_EVENT_PRE_DAC,
  539. WCD_CLSH_STATE_HPHR,
  540. hph_mode);
  541. snd_soc_component_update_bits(component, WCD938X_ANA_HPH,
  542. 0x10, 0x10);
  543. /* 100 usec delay as per HW requirement */
  544. usleep_range(100, 110);
  545. set_bit(HPH_PA_DELAY, &wcd938x->status_mask);
  546. break;
  547. case SND_SOC_DAPM_POST_PMU:
  548. /*
  549. * 7ms sleep is required if compander is enabled as per
  550. * HW requirement. If compander is disabled, then
  551. * 20ms delay is required.
  552. */
  553. if (test_bit(HPH_PA_DELAY, &wcd938x->status_mask)) {
  554. if (!wcd938x->comp2_enable)
  555. usleep_range(20000, 20100);
  556. else
  557. usleep_range(7000, 7100);
  558. clear_bit(HPH_PA_DELAY, &wcd938x->status_mask);
  559. }
  560. snd_soc_component_update_bits(component,
  561. WCD938X_HPH_NEW_INT_HPH_TIMER1, 0x02, 0x02);
  562. if (hph_mode == CLS_AB || hph_mode == CLS_AB_HIFI)
  563. snd_soc_component_update_bits(component,
  564. WCD938X_ANA_RX_SUPPLIES, 0x02, 0x02);
  565. if (wcd938x->update_wcd_event)
  566. wcd938x->update_wcd_event(wcd938x->handle,
  567. WCD_BOLERO_EVT_RX_MUTE,
  568. (WCD_RX2 << 0x10));
  569. break;
  570. case SND_SOC_DAPM_PRE_PMD:
  571. if (wcd938x->update_wcd_event)
  572. wcd938x->update_wcd_event(wcd938x->handle,
  573. WCD_BOLERO_EVT_RX_MUTE,
  574. (WCD_RX2 << 0x10 | 0x1));
  575. blocking_notifier_call_chain(&wcd938x->mbhc->notifier,
  576. WCD_EVENT_PRE_HPHR_PA_OFF,
  577. &wcd938x->mbhc->wcd_mbhc);
  578. break;
  579. case SND_SOC_DAPM_POST_PMD:
  580. /* 7 msec delay as per HW requirement */
  581. usleep_range(7000, 7010);
  582. blocking_notifier_call_chain(&wcd938x->mbhc->notifier,
  583. WCD_EVENT_POST_HPHR_PA_OFF,
  584. &wcd938x->mbhc->wcd_mbhc);
  585. snd_soc_component_update_bits(component, WCD938X_ANA_HPH,
  586. 0x10, 0x00);
  587. wcd_cls_h_fsm(component, &wcd938x->clsh_info,
  588. WCD_CLSH_EVENT_POST_PA,
  589. WCD_CLSH_STATE_HPHR,
  590. hph_mode);
  591. break;
  592. };
  593. return ret;
  594. }
  595. static int wcd938x_codec_enable_hphl_pa(struct snd_soc_dapm_widget *w,
  596. struct snd_kcontrol *kcontrol,
  597. int event)
  598. {
  599. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  600. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  601. int ret = 0;
  602. int hph_mode = wcd938x->hph_mode;
  603. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  604. w->name, event);
  605. switch (event) {
  606. case SND_SOC_DAPM_PRE_PMU:
  607. ret = swr_slvdev_datapath_control(wcd938x->rx_swr_dev,
  608. wcd938x->rx_swr_dev->dev_num,
  609. true);
  610. wcd_cls_h_fsm(component, &wcd938x->clsh_info,
  611. WCD_CLSH_EVENT_PRE_DAC,
  612. WCD_CLSH_STATE_HPHL,
  613. hph_mode);
  614. snd_soc_component_update_bits(component, WCD938X_ANA_HPH,
  615. 0x20, 0x20);
  616. /* 100 usec delay as per HW requirement */
  617. usleep_range(100, 110);
  618. set_bit(HPH_PA_DELAY, &wcd938x->status_mask);
  619. break;
  620. case SND_SOC_DAPM_POST_PMU:
  621. /*
  622. * 7ms sleep is required if compander is enabled as per
  623. * HW requirement. If compander is disabled, then
  624. * 20ms delay is required.
  625. */
  626. if (test_bit(HPH_PA_DELAY, &wcd938x->status_mask)) {
  627. if (!wcd938x->comp1_enable)
  628. usleep_range(20000, 20100);
  629. else
  630. usleep_range(7000, 7100);
  631. clear_bit(HPH_PA_DELAY, &wcd938x->status_mask);
  632. }
  633. snd_soc_component_update_bits(component,
  634. WCD938X_HPH_NEW_INT_HPH_TIMER1, 0x02, 0x02);
  635. if (hph_mode == CLS_AB || hph_mode == CLS_AB_HIFI)
  636. snd_soc_component_update_bits(component,
  637. WCD938X_ANA_RX_SUPPLIES, 0x02, 0x02);
  638. if (wcd938x->update_wcd_event)
  639. wcd938x->update_wcd_event(wcd938x->handle,
  640. WCD_BOLERO_EVT_RX_MUTE,
  641. (WCD_RX1 << 0x10));
  642. break;
  643. case SND_SOC_DAPM_PRE_PMD:
  644. if (wcd938x->update_wcd_event)
  645. wcd938x->update_wcd_event(wcd938x->handle,
  646. WCD_BOLERO_EVT_RX_MUTE,
  647. (WCD_RX1 << 0x10 | 0x1));
  648. blocking_notifier_call_chain(&wcd938x->mbhc->notifier,
  649. WCD_EVENT_PRE_HPHL_PA_OFF,
  650. &wcd938x->mbhc->wcd_mbhc);
  651. break;
  652. case SND_SOC_DAPM_POST_PMD:
  653. /* 7 msec delay as per HW requirement */
  654. usleep_range(7000, 7010);
  655. blocking_notifier_call_chain(&wcd938x->mbhc->notifier,
  656. WCD_EVENT_POST_HPHL_PA_OFF,
  657. &wcd938x->mbhc->wcd_mbhc);
  658. snd_soc_component_update_bits(component, WCD938X_ANA_HPH,
  659. 0x20, 0x00);
  660. wcd_cls_h_fsm(component, &wcd938x->clsh_info,
  661. WCD_CLSH_EVENT_POST_PA,
  662. WCD_CLSH_STATE_HPHL,
  663. hph_mode);
  664. break;
  665. };
  666. return ret;
  667. }
  668. static int wcd938x_codec_enable_aux_pa(struct snd_soc_dapm_widget *w,
  669. struct snd_kcontrol *kcontrol,
  670. int event)
  671. {
  672. struct snd_soc_component *component =
  673. snd_soc_dapm_to_component(w->dapm);
  674. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  675. int hph_mode = wcd938x->hph_mode;
  676. int ret = 0;
  677. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  678. w->name, event);
  679. switch (event) {
  680. case SND_SOC_DAPM_PRE_PMU:
  681. ret = swr_slvdev_datapath_control(wcd938x->rx_swr_dev,
  682. wcd938x->rx_swr_dev->dev_num,
  683. true);
  684. break;
  685. case SND_SOC_DAPM_POST_PMU:
  686. /* 1 msec delay as per HW requirement */
  687. usleep_range(1000, 1010);
  688. if (hph_mode == CLS_AB || hph_mode == CLS_AB_HIFI)
  689. snd_soc_component_update_bits(component,
  690. WCD938X_ANA_RX_SUPPLIES,
  691. 0x20, 0x20);
  692. if (wcd938x->update_wcd_event)
  693. wcd938x->update_wcd_event(wcd938x->handle,
  694. WCD_BOLERO_EVT_RX_MUTE,
  695. (WCD_RX3 << 0x10));
  696. break;
  697. case SND_SOC_DAPM_PRE_PMD:
  698. if (wcd938x->update_wcd_event)
  699. wcd938x->update_wcd_event(wcd938x->handle,
  700. WCD_BOLERO_EVT_RX_MUTE,
  701. (WCD_RX3 << 0x10 | 0x1));
  702. break;
  703. case SND_SOC_DAPM_POST_PMD:
  704. /* 1 msec delay as per HW requirement */
  705. usleep_range(1000, 1010);
  706. wcd_cls_h_fsm(component, &wcd938x->clsh_info,
  707. WCD_CLSH_EVENT_POST_PA,
  708. WCD_CLSH_STATE_AUX,
  709. hph_mode);
  710. break;
  711. };
  712. return ret;
  713. }
  714. static int wcd938x_codec_enable_ear_pa(struct snd_soc_dapm_widget *w,
  715. struct snd_kcontrol *kcontrol,
  716. int event)
  717. {
  718. struct snd_soc_component *component =
  719. snd_soc_dapm_to_component(w->dapm);
  720. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  721. int hph_mode = wcd938x->hph_mode;
  722. int ret = 0;
  723. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  724. w->name, event);
  725. switch (event) {
  726. case SND_SOC_DAPM_PRE_PMU:
  727. ret = swr_slvdev_datapath_control(wcd938x->rx_swr_dev,
  728. wcd938x->rx_swr_dev->dev_num,
  729. true);
  730. break;
  731. case SND_SOC_DAPM_POST_PMU:
  732. /* 6 msec delay as per HW requirement */
  733. usleep_range(6000, 6010);
  734. if (hph_mode == CLS_AB || hph_mode == CLS_AB_HIFI)
  735. snd_soc_component_update_bits(component,
  736. WCD938X_ANA_RX_SUPPLIES,
  737. 0x02, 0x02);
  738. if (wcd938x->update_wcd_event)
  739. wcd938x->update_wcd_event(wcd938x->handle,
  740. WCD_BOLERO_EVT_RX_MUTE,
  741. (WCD_RX1 << 0x10));
  742. break;
  743. case SND_SOC_DAPM_PRE_PMD:
  744. if (wcd938x->update_wcd_event)
  745. wcd938x->update_wcd_event(wcd938x->handle,
  746. WCD_BOLERO_EVT_RX_MUTE,
  747. (WCD_RX1 << 0x10 | 0x1));
  748. break;
  749. case SND_SOC_DAPM_POST_PMD:
  750. /* 7 msec delay as per HW requirement */
  751. usleep_range(7000, 7010);
  752. wcd_cls_h_fsm(component, &wcd938x->clsh_info,
  753. WCD_CLSH_EVENT_POST_PA,
  754. WCD_CLSH_STATE_EAR,
  755. hph_mode);
  756. snd_soc_component_update_bits(component, WCD938X_FLYBACK_EN,
  757. 0x04, 0x04);
  758. break;
  759. };
  760. return ret;
  761. }
  762. static int wcd938x_enable_clsh(struct snd_soc_dapm_widget *w,
  763. struct snd_kcontrol *kcontrol,
  764. int event)
  765. {
  766. struct snd_soc_component *component =
  767. snd_soc_dapm_to_component(w->dapm);
  768. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  769. int mode = wcd938x->hph_mode;
  770. int ret = 0;
  771. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  772. w->name, event);
  773. if (mode == CLS_H_LOHIFI || mode == CLS_H_ULP ||
  774. mode == CLS_H_HIFI || mode == CLS_H_LP) {
  775. wcd938x_rx_connect_port(component, CLSH,
  776. SND_SOC_DAPM_EVENT_ON(event));
  777. }
  778. if (SND_SOC_DAPM_EVENT_OFF(event))
  779. ret = swr_slvdev_datapath_control(
  780. wcd938x->rx_swr_dev,
  781. wcd938x->rx_swr_dev->dev_num,
  782. false);
  783. return ret;
  784. }
  785. static int wcd938x_enable_rx1(struct snd_soc_dapm_widget *w,
  786. struct snd_kcontrol *kcontrol,
  787. int event)
  788. {
  789. struct snd_soc_component *component =
  790. snd_soc_dapm_to_component(w->dapm);
  791. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  792. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  793. w->name, event);
  794. switch (event) {
  795. case SND_SOC_DAPM_PRE_PMU:
  796. wcd938x_rx_connect_port(component, HPH_L, true);
  797. if (wcd938x->comp1_enable)
  798. wcd938x_rx_connect_port(component, COMP_L, true);
  799. break;
  800. case SND_SOC_DAPM_POST_PMD:
  801. wcd938x_rx_connect_port(component, HPH_L, false);
  802. if (wcd938x->comp1_enable)
  803. wcd938x_rx_connect_port(component, COMP_L, false);
  804. wcd938x_rx_clk_disable(component);
  805. snd_soc_component_update_bits(component,
  806. WCD938X_DIGITAL_CDC_DIG_CLK_CTL,
  807. 0x01, 0x00);
  808. break;
  809. };
  810. return 0;
  811. }
  812. static int wcd938x_enable_rx2(struct snd_soc_dapm_widget *w,
  813. struct snd_kcontrol *kcontrol, int event)
  814. {
  815. struct snd_soc_component *component =
  816. snd_soc_dapm_to_component(w->dapm);
  817. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  818. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  819. w->name, event);
  820. switch (event) {
  821. case SND_SOC_DAPM_PRE_PMU:
  822. wcd938x_rx_connect_port(component, HPH_R, true);
  823. if (wcd938x->comp2_enable)
  824. wcd938x_rx_connect_port(component, COMP_R, true);
  825. break;
  826. case SND_SOC_DAPM_POST_PMD:
  827. wcd938x_rx_connect_port(component, HPH_R, false);
  828. if (wcd938x->comp2_enable)
  829. wcd938x_rx_connect_port(component, COMP_R, false);
  830. wcd938x_rx_clk_disable(component);
  831. snd_soc_component_update_bits(component,
  832. WCD938X_DIGITAL_CDC_DIG_CLK_CTL,
  833. 0x02, 0x00);
  834. break;
  835. };
  836. return 0;
  837. }
  838. static int wcd938x_enable_rx3(struct snd_soc_dapm_widget *w,
  839. struct snd_kcontrol *kcontrol,
  840. int event)
  841. {
  842. struct snd_soc_component *component =
  843. snd_soc_dapm_to_component(w->dapm);
  844. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  845. w->name, event);
  846. switch (event) {
  847. case SND_SOC_DAPM_PRE_PMU:
  848. wcd938x_rx_connect_port(component, LO, true);
  849. break;
  850. case SND_SOC_DAPM_POST_PMD:
  851. wcd938x_rx_connect_port(component, LO, false);
  852. /* 6 msec delay as per HW requirement */
  853. usleep_range(6000, 6010);
  854. wcd938x_rx_clk_disable(component);
  855. snd_soc_component_update_bits(component,
  856. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0x04, 0x00);
  857. break;
  858. }
  859. return 0;
  860. }
  861. static int wcd938x_codec_enable_dmic(struct snd_soc_dapm_widget *w,
  862. struct snd_kcontrol *kcontrol,
  863. int event)
  864. {
  865. struct snd_soc_component *component =
  866. snd_soc_dapm_to_component(w->dapm);
  867. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  868. u16 dmic_clk_reg;
  869. s32 *dmic_clk_cnt;
  870. unsigned int dmic;
  871. char *wname;
  872. int ret = 0;
  873. wname = strpbrk(w->name, "012345");
  874. if (!wname) {
  875. dev_err(component->dev, "%s: widget not found\n", __func__);
  876. return -EINVAL;
  877. }
  878. ret = kstrtouint(wname, 10, &dmic);
  879. if (ret < 0) {
  880. dev_err(component->dev, "%s: Invalid DMIC line on the codec\n",
  881. __func__);
  882. return -EINVAL;
  883. }
  884. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  885. w->name, event);
  886. switch (dmic) {
  887. case 0:
  888. case 1:
  889. dmic_clk_cnt = &(wcd938x->dmic_0_1_clk_cnt);
  890. dmic_clk_reg = WCD938X_DIGITAL_CDC_DMIC1_CTL;
  891. break;
  892. case 2:
  893. case 3:
  894. dmic_clk_cnt = &(wcd938x->dmic_2_3_clk_cnt);
  895. dmic_clk_reg = WCD938X_DIGITAL_CDC_DMIC2_CTL;
  896. break;
  897. case 4:
  898. case 5:
  899. dmic_clk_cnt = &(wcd938x->dmic_4_5_clk_cnt);
  900. dmic_clk_reg = WCD938X_DIGITAL_CDC_DMIC3_CTL;
  901. break;
  902. case 6:
  903. case 7:
  904. dmic_clk_cnt = &(wcd938x->dmic_6_7_clk_cnt);
  905. dmic_clk_reg = WCD938X_DIGITAL_CDC_DMIC4_CTL;
  906. break;
  907. default:
  908. dev_err(component->dev, "%s: Invalid DMIC Selection\n",
  909. __func__);
  910. return -EINVAL;
  911. };
  912. dev_dbg(component->dev, "%s: event %d DMIC%d dmic_clk_cnt %d\n",
  913. __func__, event, dmic, *dmic_clk_cnt);
  914. switch (event) {
  915. case SND_SOC_DAPM_PRE_PMU:
  916. snd_soc_component_update_bits(component,
  917. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0x80, 0x80);
  918. /* enable clock scaling */
  919. snd_soc_component_update_bits(component,
  920. WCD938X_DIGITAL_CDC_DMIC_CTL, 0x06, 0x06);
  921. snd_soc_component_update_bits(component,
  922. dmic_clk_reg, 0x07, 0x02);
  923. snd_soc_component_update_bits(component,
  924. dmic_clk_reg, 0x08, 0x08);
  925. snd_soc_component_update_bits(component,
  926. dmic_clk_reg, 0x70, 0x20);
  927. wcd938x_tx_connect_port(component, DMIC0 + (w->shift), true);
  928. break;
  929. case SND_SOC_DAPM_POST_PMD:
  930. wcd938x_tx_connect_port(component, DMIC0 + (w->shift), false);
  931. break;
  932. };
  933. return 0;
  934. }
  935. /*
  936. * wcd938x_get_micb_vout_ctl_val: converts micbias from volts to register value
  937. * @micb_mv: micbias in mv
  938. *
  939. * return register value converted
  940. */
  941. int wcd938x_get_micb_vout_ctl_val(u32 micb_mv)
  942. {
  943. /* min micbias voltage is 1V and maximum is 2.85V */
  944. if (micb_mv < 1000 || micb_mv > 2850) {
  945. pr_err("%s: unsupported micbias voltage\n", __func__);
  946. return -EINVAL;
  947. }
  948. return (micb_mv - 1000) / 50;
  949. }
  950. EXPORT_SYMBOL(wcd938x_get_micb_vout_ctl_val);
  951. /*
  952. * wcd938x_mbhc_micb_adjust_voltage: adjust specific micbias voltage
  953. * @component: handle to snd_soc_component *
  954. * @req_volt: micbias voltage to be set
  955. * @micb_num: micbias to be set, e.g. micbias1 or micbias2
  956. *
  957. * return 0 if adjustment is success or error code in case of failure
  958. */
  959. int wcd938x_mbhc_micb_adjust_voltage(struct snd_soc_component *component,
  960. int req_volt, int micb_num)
  961. {
  962. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  963. int cur_vout_ctl, req_vout_ctl;
  964. int micb_reg, micb_val, micb_en;
  965. int ret = 0;
  966. switch (micb_num) {
  967. case MIC_BIAS_1:
  968. micb_reg = WCD938X_ANA_MICB1;
  969. break;
  970. case MIC_BIAS_2:
  971. micb_reg = WCD938X_ANA_MICB2;
  972. break;
  973. case MIC_BIAS_3:
  974. micb_reg = WCD938X_ANA_MICB3;
  975. break;
  976. case MIC_BIAS_4:
  977. micb_reg = WCD938X_ANA_MICB4;
  978. break;
  979. default:
  980. return -EINVAL;
  981. }
  982. mutex_lock(&wcd938x->micb_lock);
  983. /*
  984. * If requested micbias voltage is same as current micbias
  985. * voltage, then just return. Otherwise, adjust voltage as
  986. * per requested value. If micbias is already enabled, then
  987. * to avoid slow micbias ramp-up or down enable pull-up
  988. * momentarily, change the micbias value and then re-enable
  989. * micbias.
  990. */
  991. micb_val = snd_soc_component_read32(component, micb_reg);
  992. micb_en = (micb_val & 0xC0) >> 6;
  993. cur_vout_ctl = micb_val & 0x3F;
  994. req_vout_ctl = wcd938x_get_micb_vout_ctl_val(req_volt);
  995. if (req_vout_ctl < 0) {
  996. ret = -EINVAL;
  997. goto exit;
  998. }
  999. if (cur_vout_ctl == req_vout_ctl) {
  1000. ret = 0;
  1001. goto exit;
  1002. }
  1003. dev_dbg(component->dev, "%s: micb_num: %d, cur_mv: %d, req_mv: %d, micb_en: %d\n",
  1004. __func__, micb_num, WCD_VOUT_CTL_TO_MICB(cur_vout_ctl),
  1005. req_volt, micb_en);
  1006. if (micb_en == 0x1)
  1007. snd_soc_component_update_bits(component, micb_reg, 0xC0, 0x80);
  1008. snd_soc_component_update_bits(component, micb_reg, 0x3F, req_vout_ctl);
  1009. if (micb_en == 0x1) {
  1010. snd_soc_component_update_bits(component, micb_reg, 0xC0, 0x40);
  1011. /*
  1012. * Add 2ms delay as per HW requirement after enabling
  1013. * micbias
  1014. */
  1015. usleep_range(2000, 2100);
  1016. }
  1017. exit:
  1018. mutex_unlock(&wcd938x->micb_lock);
  1019. return ret;
  1020. }
  1021. EXPORT_SYMBOL(wcd938x_mbhc_micb_adjust_voltage);
  1022. static int wcd938x_tx_swr_ctrl(struct snd_soc_dapm_widget *w,
  1023. struct snd_kcontrol *kcontrol,
  1024. int event)
  1025. {
  1026. struct snd_soc_component *component =
  1027. snd_soc_dapm_to_component(w->dapm);
  1028. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  1029. int ret = 0;
  1030. switch (event) {
  1031. case SND_SOC_DAPM_PRE_PMU:
  1032. ret = swr_slvdev_datapath_control(wcd938x->tx_swr_dev,
  1033. wcd938x->tx_swr_dev->dev_num,
  1034. true);
  1035. break;
  1036. case SND_SOC_DAPM_POST_PMD:
  1037. ret = swr_slvdev_datapath_control(wcd938x->tx_swr_dev,
  1038. wcd938x->tx_swr_dev->dev_num,
  1039. false);
  1040. break;
  1041. };
  1042. return ret;
  1043. }
  1044. static int wcd938x_get_adc_mode(int val)
  1045. {
  1046. int ret = 0;
  1047. switch (val) {
  1048. case ADC_MODE_INVALID:
  1049. ret = ADC_MODE_VAL_NORMAL;
  1050. break;
  1051. case ADC_MODE_HIFI:
  1052. ret = ADC_MODE_VAL_HIFI;
  1053. break;
  1054. case ADC_MODE_LO_HIF:
  1055. ret = ADC_MODE_VAL_LO_HIF;
  1056. break;
  1057. case ADC_MODE_NORMAL:
  1058. ret = ADC_MODE_VAL_NORMAL;
  1059. break;
  1060. case ADC_MODE_LP:
  1061. ret = ADC_MODE_VAL_LP;
  1062. break;
  1063. case ADC_MODE_ULP1:
  1064. ret = ADC_MODE_VAL_ULP1;
  1065. break;
  1066. case ADC_MODE_ULP2:
  1067. ret = ADC_MODE_VAL_ULP2;
  1068. break;
  1069. default:
  1070. ret = -EINVAL;
  1071. pr_err("%s: invalid ADC mode value %d\n", __func__, val);
  1072. break;
  1073. }
  1074. return ret;
  1075. }
  1076. static int wcd938x_codec_enable_adc(struct snd_soc_dapm_widget *w,
  1077. struct snd_kcontrol *kcontrol,
  1078. int event){
  1079. int mode;
  1080. struct snd_soc_component *component =
  1081. snd_soc_dapm_to_component(w->dapm);
  1082. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  1083. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  1084. w->name, event);
  1085. switch (event) {
  1086. case SND_SOC_DAPM_PRE_PMU:
  1087. mode = wcd938x_get_adc_mode(wcd938x->tx_mode[w->shift]);
  1088. if (mode < 0) {
  1089. dev_info(component->dev,
  1090. "%s: invalid mode, setting to normal mode\n",
  1091. __func__);
  1092. mode = ADC_MODE_VAL_NORMAL;
  1093. }
  1094. snd_soc_component_update_bits(component,
  1095. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0x80, 0x80);
  1096. snd_soc_component_update_bits(component,
  1097. WCD938X_DIGITAL_CDC_ANA_CLK_CTL, 0x08, 0x08);
  1098. snd_soc_component_update_bits(component,
  1099. WCD938X_DIGITAL_CDC_ANA_CLK_CTL, 0x10, 0x10);
  1100. switch (w->shift) {
  1101. case 0:
  1102. snd_soc_component_update_bits(component,
  1103. WCD938X_DIGITAL_CDC_TX_ANA_MODE_0_1, 0x0F,
  1104. mode);
  1105. break;
  1106. case 1:
  1107. snd_soc_component_update_bits(component,
  1108. WCD938X_DIGITAL_CDC_TX_ANA_MODE_0_1, 0xF0,
  1109. mode << 4);
  1110. break;
  1111. case 2:
  1112. snd_soc_component_update_bits(component,
  1113. WCD938X_DIGITAL_CDC_TX_ANA_MODE_2_3, 0x0F,
  1114. mode);
  1115. break;
  1116. case 3:
  1117. snd_soc_component_update_bits(component,
  1118. WCD938X_DIGITAL_CDC_TX_ANA_MODE_2_3, 0xF0,
  1119. mode << 4);
  1120. break;
  1121. default:
  1122. break;
  1123. }
  1124. set_bit(w->shift, &wcd938x->status_mask);
  1125. wcd938x_tx_connect_port(component, ADC1 + (w->shift), true);
  1126. break;
  1127. case SND_SOC_DAPM_POST_PMD:
  1128. wcd938x_tx_connect_port(component, ADC1 + (w->shift), false);
  1129. snd_soc_component_update_bits(component,
  1130. WCD938X_DIGITAL_CDC_ANA_CLK_CTL, 0x08, 0x00);
  1131. clear_bit(w->shift, &wcd938x->status_mask);
  1132. break;
  1133. };
  1134. return 0;
  1135. }
  1136. int wcd938x_tx_channel_config(struct snd_soc_component *component,
  1137. int channel, int mode)
  1138. {
  1139. int reg = WCD938X_ANA_TX_CH2, mask = 0, val = 0;
  1140. int ret = 0;
  1141. switch (channel) {
  1142. case 0:
  1143. reg = WCD938X_ANA_TX_CH2;
  1144. mask = 0x40;
  1145. break;
  1146. case 1:
  1147. reg = WCD938X_ANA_TX_CH2;
  1148. mask = 0x20;
  1149. break;
  1150. case 2:
  1151. reg = WCD938X_ANA_TX_CH4;
  1152. mask = 0x40;
  1153. break;
  1154. case 3:
  1155. reg = WCD938X_ANA_TX_CH4;
  1156. mask = 0x20;
  1157. break;
  1158. default:
  1159. pr_err("%s: Invalid channel num %d\n", __func__, channel);
  1160. ret = -EINVAL;
  1161. break;
  1162. }
  1163. if (!mode)
  1164. val = 0x00;
  1165. else
  1166. val = mask;
  1167. if (!ret)
  1168. snd_soc_component_update_bits(component, reg, mask, val);
  1169. return ret;
  1170. }
  1171. static int wcd938x_enable_req(struct snd_soc_dapm_widget *w,
  1172. struct snd_kcontrol *kcontrol, int event)
  1173. {
  1174. struct snd_soc_component *component =
  1175. snd_soc_dapm_to_component(w->dapm);
  1176. int ret = 0;
  1177. dev_dbg(component->dev, "%s wname: %s event: %d\n", __func__,
  1178. w->name, event);
  1179. switch (event) {
  1180. case SND_SOC_DAPM_PRE_PMU:
  1181. snd_soc_component_update_bits(component,
  1182. WCD938X_DIGITAL_CDC_REQ_CTL, 0x02, 0x02);
  1183. snd_soc_component_update_bits(component,
  1184. WCD938X_DIGITAL_CDC_REQ_CTL, 0x01, 0x00);
  1185. ret = wcd938x_tx_channel_config(component, w->shift, 1);
  1186. snd_soc_component_update_bits(component,
  1187. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0x30, 0x30);
  1188. snd_soc_component_update_bits(component,
  1189. WCD938X_ANA_TX_CH1, 0x80, 0x80);
  1190. snd_soc_component_update_bits(component,
  1191. WCD938X_ANA_TX_CH2, 0x80, 0x80);
  1192. ret |= wcd938x_tx_channel_config(component, w->shift, 0);
  1193. break;
  1194. case SND_SOC_DAPM_POST_PMD:
  1195. snd_soc_component_update_bits(component,
  1196. WCD938X_ANA_TX_CH1, 0x80, 0x00);
  1197. snd_soc_component_update_bits(component,
  1198. WCD938X_ANA_TX_CH2, 0x80, 0x00);
  1199. snd_soc_component_update_bits(component,
  1200. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0x10, 0x00);
  1201. snd_soc_component_update_bits(component,
  1202. WCD938X_DIGITAL_CDC_ANA_CLK_CTL, 0x10, 0x00);
  1203. snd_soc_component_update_bits(component,
  1204. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0x80, 0x00);
  1205. break;
  1206. };
  1207. return ret;
  1208. }
  1209. int wcd938x_micbias_control(struct snd_soc_component *component,
  1210. int micb_num, int req, bool is_dapm)
  1211. {
  1212. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  1213. int micb_index = micb_num - 1;
  1214. u16 micb_reg;
  1215. int pre_off_event = 0, post_off_event = 0;
  1216. int post_on_event = 0, post_dapm_off = 0;
  1217. int post_dapm_on = 0;
  1218. if ((micb_index < 0) || (micb_index > WCD938X_MAX_MICBIAS - 1)) {
  1219. dev_err(component->dev,
  1220. "%s: Invalid micbias index, micb_ind:%d\n",
  1221. __func__, micb_index);
  1222. return -EINVAL;
  1223. }
  1224. if (NULL == wcd938x) {
  1225. dev_err(component->dev,
  1226. "%s: wcd938x private data is NULL\n", __func__);
  1227. return -EINVAL;
  1228. }
  1229. switch (micb_num) {
  1230. case MIC_BIAS_1:
  1231. micb_reg = WCD938X_ANA_MICB1;
  1232. break;
  1233. case MIC_BIAS_2:
  1234. micb_reg = WCD938X_ANA_MICB2;
  1235. pre_off_event = WCD_EVENT_PRE_MICBIAS_2_OFF;
  1236. post_off_event = WCD_EVENT_POST_MICBIAS_2_OFF;
  1237. post_on_event = WCD_EVENT_POST_MICBIAS_2_ON;
  1238. post_dapm_on = WCD_EVENT_POST_DAPM_MICBIAS_2_ON;
  1239. post_dapm_off = WCD_EVENT_POST_DAPM_MICBIAS_2_OFF;
  1240. break;
  1241. case MIC_BIAS_3:
  1242. micb_reg = WCD938X_ANA_MICB3;
  1243. break;
  1244. case MIC_BIAS_4:
  1245. micb_reg = WCD938X_ANA_MICB4;
  1246. break;
  1247. default:
  1248. dev_err(component->dev, "%s: Invalid micbias number: %d\n",
  1249. __func__, micb_num);
  1250. return -EINVAL;
  1251. };
  1252. mutex_lock(&wcd938x->micb_lock);
  1253. switch (req) {
  1254. case MICB_PULLUP_ENABLE:
  1255. wcd938x->pullup_ref[micb_index]++;
  1256. if ((wcd938x->pullup_ref[micb_index] == 1) &&
  1257. (wcd938x->micb_ref[micb_index] == 0))
  1258. snd_soc_component_update_bits(component, micb_reg,
  1259. 0xC0, 0x80);
  1260. break;
  1261. case MICB_PULLUP_DISABLE:
  1262. if (wcd938x->pullup_ref[micb_index] > 0)
  1263. wcd938x->pullup_ref[micb_index]--;
  1264. if ((wcd938x->pullup_ref[micb_index] == 0) &&
  1265. (wcd938x->micb_ref[micb_index] == 0))
  1266. snd_soc_component_update_bits(component, micb_reg,
  1267. 0xC0, 0x00);
  1268. break;
  1269. case MICB_ENABLE:
  1270. wcd938x->micb_ref[micb_index]++;
  1271. if (wcd938x->micb_ref[micb_index] == 1) {
  1272. snd_soc_component_update_bits(component,
  1273. WCD938X_DIGITAL_CDC_DIG_CLK_CTL, 0xE0, 0xE0);
  1274. snd_soc_component_update_bits(component,
  1275. WCD938X_DIGITAL_CDC_ANA_CLK_CTL, 0x10, 0x10);
  1276. snd_soc_component_update_bits(component,
  1277. WCD938X_DIGITAL_CDC_ANA_TX_CLK_CTL, 0x01, 0x01);
  1278. snd_soc_component_update_bits(component,
  1279. WCD938X_MICB1_TEST_CTL_2, 0x01, 0x01);
  1280. snd_soc_component_update_bits(component,
  1281. WCD938X_MICB2_TEST_CTL_2, 0x01, 0x01);
  1282. snd_soc_component_update_bits(component,
  1283. WCD938X_MICB3_TEST_CTL_2, 0x01, 0x01);
  1284. snd_soc_component_update_bits(component,
  1285. WCD938X_MICB4_TEST_CTL_2, 0x01, 0x01);
  1286. snd_soc_component_update_bits(component,
  1287. micb_reg, 0xC0, 0x40);
  1288. if (post_on_event)
  1289. blocking_notifier_call_chain(
  1290. &wcd938x->mbhc->notifier,
  1291. post_on_event,
  1292. &wcd938x->mbhc->wcd_mbhc);
  1293. }
  1294. if (is_dapm && post_dapm_on && wcd938x->mbhc)
  1295. blocking_notifier_call_chain(&wcd938x->mbhc->notifier,
  1296. post_dapm_on,
  1297. &wcd938x->mbhc->wcd_mbhc);
  1298. break;
  1299. case MICB_DISABLE:
  1300. if (wcd938x->micb_ref[micb_index] > 0)
  1301. wcd938x->micb_ref[micb_index]--;
  1302. if ((wcd938x->micb_ref[micb_index] == 0) &&
  1303. (wcd938x->pullup_ref[micb_index] > 0))
  1304. snd_soc_component_update_bits(component, micb_reg,
  1305. 0xC0, 0x80);
  1306. else if ((wcd938x->micb_ref[micb_index] == 0) &&
  1307. (wcd938x->pullup_ref[micb_index] == 0)) {
  1308. if (pre_off_event && wcd938x->mbhc)
  1309. blocking_notifier_call_chain(
  1310. &wcd938x->mbhc->notifier,
  1311. pre_off_event,
  1312. &wcd938x->mbhc->wcd_mbhc);
  1313. snd_soc_component_update_bits(component, micb_reg,
  1314. 0xC0, 0x00);
  1315. if (post_off_event && wcd938x->mbhc)
  1316. blocking_notifier_call_chain(
  1317. &wcd938x->mbhc->notifier,
  1318. post_off_event,
  1319. &wcd938x->mbhc->wcd_mbhc);
  1320. }
  1321. if (is_dapm && post_dapm_off && wcd938x->mbhc)
  1322. blocking_notifier_call_chain(&wcd938x->mbhc->notifier,
  1323. post_dapm_off,
  1324. &wcd938x->mbhc->wcd_mbhc);
  1325. break;
  1326. };
  1327. dev_dbg(component->dev,
  1328. "%s: micb_num:%d, micb_ref: %d, pullup_ref: %d\n",
  1329. __func__, micb_num, wcd938x->micb_ref[micb_index],
  1330. wcd938x->pullup_ref[micb_index]);
  1331. mutex_unlock(&wcd938x->micb_lock);
  1332. return 0;
  1333. }
  1334. EXPORT_SYMBOL(wcd938x_micbias_control);
  1335. static int wcd938x_get_logical_addr(struct swr_device *swr_dev)
  1336. {
  1337. int ret = 0;
  1338. uint8_t devnum = 0;
  1339. ret = swr_get_logical_dev_num(swr_dev, swr_dev->addr, &devnum);
  1340. if (ret) {
  1341. dev_err(&swr_dev->dev,
  1342. "%s get devnum %d for dev addr %lx failed\n",
  1343. __func__, devnum, swr_dev->addr);
  1344. swr_remove_device(swr_dev);
  1345. return ret;
  1346. }
  1347. swr_dev->dev_num = devnum;
  1348. return 0;
  1349. }
  1350. static int wcd938x_event_notify(struct notifier_block *block,
  1351. unsigned long val,
  1352. void *data)
  1353. {
  1354. u16 event = (val & 0xffff);
  1355. int ret = 0;
  1356. struct wcd938x_priv *wcd938x = dev_get_drvdata((struct device *)data);
  1357. struct snd_soc_component *component = wcd938x->component;
  1358. struct wcd_mbhc *mbhc;
  1359. switch (event) {
  1360. case BOLERO_WCD_EVT_TX_CH_HOLD_CLEAR:
  1361. if (test_bit(WCD_ADC1, &wcd938x->status_mask)) {
  1362. snd_soc_component_update_bits(component,
  1363. WCD938X_ANA_TX_CH2, 0x40, 0x00);
  1364. clear_bit(WCD_ADC1, &wcd938x->status_mask);
  1365. }
  1366. if (test_bit(WCD_ADC2, &wcd938x->status_mask)) {
  1367. snd_soc_component_update_bits(component,
  1368. WCD938X_ANA_TX_CH2, 0x20, 0x00);
  1369. clear_bit(WCD_ADC2, &wcd938x->status_mask);
  1370. }
  1371. if (test_bit(WCD_ADC3, &wcd938x->status_mask)) {
  1372. snd_soc_component_update_bits(component,
  1373. WCD938X_ANA_TX_CH4, 0x40, 0x00);
  1374. clear_bit(WCD_ADC3, &wcd938x->status_mask);
  1375. }
  1376. if (test_bit(WCD_ADC4, &wcd938x->status_mask)) {
  1377. snd_soc_component_update_bits(component,
  1378. WCD938X_ANA_TX_CH4, 0x20, 0x00);
  1379. clear_bit(WCD_ADC4, &wcd938x->status_mask);
  1380. }
  1381. break;
  1382. case BOLERO_WCD_EVT_PA_OFF_PRE_SSR:
  1383. snd_soc_component_update_bits(component, WCD938X_ANA_HPH,
  1384. 0xC0, 0x00);
  1385. snd_soc_component_update_bits(component, WCD938X_ANA_EAR,
  1386. 0x80, 0x00);
  1387. snd_soc_component_update_bits(component, WCD938X_AUX_AUXPA,
  1388. 0x80, 0x00);
  1389. break;
  1390. case BOLERO_WCD_EVT_SSR_DOWN:
  1391. mbhc = &wcd938x->mbhc->wcd_mbhc;
  1392. wcd938x_mbhc_ssr_down(wcd938x->mbhc, component);
  1393. wcd938x_reset_low(wcd938x->dev);
  1394. break;
  1395. case BOLERO_WCD_EVT_SSR_UP:
  1396. wcd938x_reset(wcd938x->dev);
  1397. wcd938x_get_logical_addr(wcd938x->tx_swr_dev);
  1398. wcd938x_get_logical_addr(wcd938x->rx_swr_dev);
  1399. regcache_mark_dirty(wcd938x->regmap);
  1400. regcache_sync(wcd938x->regmap);
  1401. /* Initialize MBHC module */
  1402. mbhc = &wcd938x->mbhc->wcd_mbhc;
  1403. ret = wcd938x_mbhc_post_ssr_init(wcd938x->mbhc, component);
  1404. if (ret) {
  1405. dev_err(component->dev, "%s: mbhc initialization failed\n",
  1406. __func__);
  1407. } else {
  1408. wcd938x_mbhc_hs_detect(component, mbhc->mbhc_cfg);
  1409. }
  1410. break;
  1411. case BOLERO_WCD_EVT_CLK_NOTIFY:
  1412. snd_soc_component_update_bits(component,
  1413. WCD938X_DIGITAL_TOP_CLK_CFG, 0x06,
  1414. ((val >> 0x10) << 0x01));
  1415. break;
  1416. default:
  1417. dev_dbg(component->dev, "%s: invalid event %d\n", __func__, event);
  1418. break;
  1419. }
  1420. return 0;
  1421. }
  1422. static int __wcd938x_codec_enable_micbias(struct snd_soc_dapm_widget *w,
  1423. int event)
  1424. {
  1425. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  1426. int micb_num;
  1427. dev_dbg(component->dev, "%s: wname: %s, event: %d\n",
  1428. __func__, w->name, event);
  1429. if (strnstr(w->name, "MIC BIAS1", sizeof("MIC BIAS1")))
  1430. micb_num = MIC_BIAS_1;
  1431. else if (strnstr(w->name, "MIC BIAS2", sizeof("MIC BIAS2")))
  1432. micb_num = MIC_BIAS_2;
  1433. else if (strnstr(w->name, "MIC BIAS3", sizeof("MIC BIAS3")))
  1434. micb_num = MIC_BIAS_3;
  1435. else if (strnstr(w->name, "MIC BIAS4", sizeof("MIC BIAS4")))
  1436. micb_num = MIC_BIAS_4;
  1437. else
  1438. return -EINVAL;
  1439. switch (event) {
  1440. case SND_SOC_DAPM_PRE_PMU:
  1441. wcd938x_micbias_control(component, micb_num,
  1442. MICB_ENABLE, true);
  1443. break;
  1444. case SND_SOC_DAPM_POST_PMU:
  1445. /* 1 msec delay as per HW requirement */
  1446. usleep_range(1000, 1100);
  1447. break;
  1448. case SND_SOC_DAPM_POST_PMD:
  1449. wcd938x_micbias_control(component, micb_num,
  1450. MICB_DISABLE, true);
  1451. break;
  1452. };
  1453. return 0;
  1454. }
  1455. static int wcd938x_codec_enable_micbias(struct snd_soc_dapm_widget *w,
  1456. struct snd_kcontrol *kcontrol,
  1457. int event)
  1458. {
  1459. return __wcd938x_codec_enable_micbias(w, event);
  1460. }
  1461. static inline int wcd938x_tx_path_get(const char *wname)
  1462. {
  1463. int ret = 0;
  1464. unsigned int path_num;
  1465. char *widget_name = NULL;
  1466. char *w_name = NULL;
  1467. char *path_num_char = NULL;
  1468. char *path_name = NULL;
  1469. widget_name = kstrndup(wname, 9, GFP_KERNEL);
  1470. if (!widget_name)
  1471. return -EINVAL;
  1472. w_name = widget_name;
  1473. path_name = strsep(&widget_name, " ");
  1474. if (!path_name) {
  1475. pr_err("%s: Invalid widget name = %s\n",
  1476. __func__, widget_name);
  1477. ret = -EINVAL;
  1478. goto err;
  1479. }
  1480. path_name = widget_name;
  1481. path_num_char = strpbrk(path_name, "0123");
  1482. if (!path_num_char) {
  1483. pr_err("%s: tx path index not found\n",
  1484. __func__);
  1485. ret = -EINVAL;
  1486. goto err;
  1487. }
  1488. ret = kstrtouint(path_num_char, 10, &path_num);
  1489. if (ret < 0)
  1490. pr_err("%s: Invalid tx path = %s\n",
  1491. __func__, w_name);
  1492. err:
  1493. kfree(w_name);
  1494. return ret;
  1495. }
  1496. static int wcd938x_tx_mode_get(struct snd_kcontrol *kcontrol,
  1497. struct snd_ctl_elem_value *ucontrol)
  1498. {
  1499. struct snd_soc_dapm_widget *widget =
  1500. snd_soc_dapm_kcontrol_widget(kcontrol);
  1501. struct snd_soc_component *component =
  1502. snd_soc_kcontrol_component(kcontrol);
  1503. struct wcd938x_priv *wcd938x = NULL;
  1504. int path = 0;
  1505. if (!component)
  1506. return -EINVAL;
  1507. wcd938x = snd_soc_component_get_drvdata(component);
  1508. if (!widget || !widget->name || !wcd938x)
  1509. return -EINVAL;
  1510. path = wcd938x_tx_path_get(widget->name);
  1511. if (path < 0 || path >= TX_ADC_MAX)
  1512. return -EINVAL;
  1513. ucontrol->value.integer.value[0] = wcd938x->tx_mode[path];
  1514. return 0;
  1515. }
  1516. static int wcd938x_tx_mode_put(struct snd_kcontrol *kcontrol,
  1517. struct snd_ctl_elem_value *ucontrol)
  1518. {
  1519. struct snd_soc_dapm_widget *widget =
  1520. snd_soc_dapm_kcontrol_widget(kcontrol);
  1521. struct snd_soc_component *component =
  1522. snd_soc_kcontrol_component(kcontrol);
  1523. struct wcd938x_priv *wcd938x = NULL;
  1524. u32 mode_val;
  1525. int path = 0;
  1526. if (!component)
  1527. return -EINVAL;
  1528. wcd938x = snd_soc_component_get_drvdata(component);
  1529. if (!widget || !widget->name || !wcd938x)
  1530. return -EINVAL;
  1531. path = wcd938x_tx_path_get(widget->name);
  1532. if (path < 0 || path >= TX_ADC_MAX)
  1533. return -EINVAL;
  1534. mode_val = ucontrol->value.enumerated.item[0];
  1535. dev_dbg(component->dev, "%s: mode: %d\n", __func__, mode_val);
  1536. wcd938x->tx_mode[path] = mode_val;
  1537. return 0;
  1538. }
  1539. static int wcd938x_rx_hph_mode_get(struct snd_kcontrol *kcontrol,
  1540. struct snd_ctl_elem_value *ucontrol)
  1541. {
  1542. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  1543. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  1544. ucontrol->value.integer.value[0] = wcd938x->hph_mode;
  1545. return 0;
  1546. }
  1547. static int wcd938x_rx_hph_mode_put(struct snd_kcontrol *kcontrol,
  1548. struct snd_ctl_elem_value *ucontrol)
  1549. {
  1550. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  1551. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  1552. u32 mode_val;
  1553. mode_val = ucontrol->value.enumerated.item[0];
  1554. dev_dbg(component->dev, "%s: mode: %d\n", __func__, mode_val);
  1555. if (mode_val == 0) {
  1556. dev_info(component->dev,
  1557. "%s:Invalid HPH Mode, default to class_AB\n",
  1558. __func__);
  1559. mode_val = 3; /* enum will be updated later */
  1560. }
  1561. wcd938x->hph_mode = mode_val;
  1562. return 0;
  1563. }
  1564. static int wcd938x_get_compander(struct snd_kcontrol *kcontrol,
  1565. struct snd_ctl_elem_value *ucontrol)
  1566. {
  1567. struct snd_soc_component *component =
  1568. snd_soc_kcontrol_component(kcontrol);
  1569. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  1570. bool hphr;
  1571. struct soc_multi_mixer_control *mc;
  1572. mc = (struct soc_multi_mixer_control *)(kcontrol->private_value);
  1573. hphr = mc->shift;
  1574. ucontrol->value.integer.value[0] = hphr ? wcd938x->comp2_enable :
  1575. wcd938x->comp1_enable;
  1576. return 0;
  1577. }
  1578. static int wcd938x_set_compander(struct snd_kcontrol *kcontrol,
  1579. struct snd_ctl_elem_value *ucontrol)
  1580. {
  1581. struct snd_soc_component *component =
  1582. snd_soc_kcontrol_component(kcontrol);
  1583. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  1584. int value = ucontrol->value.integer.value[0];
  1585. bool hphr;
  1586. struct soc_multi_mixer_control *mc;
  1587. mc = (struct soc_multi_mixer_control *)(kcontrol->private_value);
  1588. hphr = mc->shift;
  1589. if (hphr)
  1590. wcd938x->comp2_enable = value;
  1591. else
  1592. wcd938x->comp1_enable = value;
  1593. return 0;
  1594. }
  1595. static const char * const tx_mode_mux_text_wcd9380[] = {
  1596. "ADC_INVALID", "ADC_HIFI", "ADC_LO_HIF", "ADC_NORMAL", "ADC_LP",
  1597. };
  1598. static const struct soc_enum tx_mode_mux_enum_wcd9380 =
  1599. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(tx_mode_mux_text_wcd9380),
  1600. tx_mode_mux_text_wcd9380);
  1601. static const char * const tx_mode_mux_text[] = {
  1602. "ADC_INVALID", "ADC_HIFI", "ADC_LO_HIF", "ADC_NORMAL", "ADC_LP",
  1603. "ADC_ULP1", "ADC_ULP2",
  1604. };
  1605. static const struct soc_enum tx_mode_mux_enum =
  1606. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(tx_mode_mux_text),
  1607. tx_mode_mux_text);
  1608. static const char * const rx_hph_mode_mux_text[] = {
  1609. "CLS_H_INVALID", "CLS_H_HIFI", "CLS_H_LP", "CLS_AB", "CLS_H_LOHIFI",
  1610. "CLS_H_ULP", "CLS_AB_HIFI",
  1611. };
  1612. static const struct soc_enum rx_hph_mode_mux_enum =
  1613. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(rx_hph_mode_mux_text),
  1614. rx_hph_mode_mux_text);
  1615. static const struct snd_kcontrol_new wcd9380_snd_controls[] = {
  1616. SOC_ENUM_EXT("TX0 MODE", tx_mode_mux_enum_wcd9380,
  1617. wcd938x_tx_mode_get, wcd938x_tx_mode_put),
  1618. SOC_ENUM_EXT("TX1 MODE", tx_mode_mux_enum_wcd9380,
  1619. wcd938x_tx_mode_get, wcd938x_tx_mode_put),
  1620. SOC_ENUM_EXT("TX2 MODE", tx_mode_mux_enum_wcd9380,
  1621. wcd938x_tx_mode_get, wcd938x_tx_mode_put),
  1622. SOC_ENUM_EXT("TX3 MODE", tx_mode_mux_enum_wcd9380,
  1623. wcd938x_tx_mode_get, wcd938x_tx_mode_put),
  1624. };
  1625. static const struct snd_kcontrol_new wcd9385_snd_controls[] = {
  1626. SOC_ENUM_EXT("TX0 MODE", tx_mode_mux_enum,
  1627. wcd938x_tx_mode_get, wcd938x_tx_mode_put),
  1628. SOC_ENUM_EXT("TX1 MODE", tx_mode_mux_enum,
  1629. wcd938x_tx_mode_get, wcd938x_tx_mode_put),
  1630. SOC_ENUM_EXT("TX2 MODE", tx_mode_mux_enum,
  1631. wcd938x_tx_mode_get, wcd938x_tx_mode_put),
  1632. SOC_ENUM_EXT("TX3 MODE", tx_mode_mux_enum,
  1633. wcd938x_tx_mode_get, wcd938x_tx_mode_put),
  1634. };
  1635. static const struct snd_kcontrol_new wcd938x_snd_controls[] = {
  1636. SOC_ENUM_EXT("RX HPH Mode", rx_hph_mode_mux_enum,
  1637. wcd938x_rx_hph_mode_get, wcd938x_rx_hph_mode_put),
  1638. SOC_SINGLE_EXT("HPHL_COMP Switch", SND_SOC_NOPM, 0, 1, 0,
  1639. wcd938x_get_compander, wcd938x_set_compander),
  1640. SOC_SINGLE_EXT("HPHR_COMP Switch", SND_SOC_NOPM, 1, 1, 0,
  1641. wcd938x_get_compander, wcd938x_set_compander),
  1642. SOC_SINGLE_TLV("HPHL Volume", WCD938X_HPH_L_EN, 0, 20, 1, line_gain),
  1643. SOC_SINGLE_TLV("HPHR Volume", WCD938X_HPH_R_EN, 0, 20, 1, line_gain),
  1644. SOC_SINGLE_TLV("ADC1 Volume", WCD938X_ANA_TX_CH1, 0, 20, 0,
  1645. analog_gain),
  1646. SOC_SINGLE_TLV("ADC2 Volume", WCD938X_ANA_TX_CH2, 0, 20, 0,
  1647. analog_gain),
  1648. SOC_SINGLE_TLV("ADC3 Volume", WCD938X_ANA_TX_CH3, 0, 20, 0,
  1649. analog_gain),
  1650. SOC_SINGLE_TLV("ADC4 Volume", WCD938X_ANA_TX_CH4, 0, 20, 0,
  1651. analog_gain),
  1652. };
  1653. static const struct snd_kcontrol_new adc1_switch[] = {
  1654. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1655. };
  1656. static const struct snd_kcontrol_new adc2_switch[] = {
  1657. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1658. };
  1659. static const struct snd_kcontrol_new adc3_switch[] = {
  1660. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1661. };
  1662. static const struct snd_kcontrol_new adc4_switch[] = {
  1663. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1664. };
  1665. static const struct snd_kcontrol_new dmic1_switch[] = {
  1666. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1667. };
  1668. static const struct snd_kcontrol_new dmic2_switch[] = {
  1669. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1670. };
  1671. static const struct snd_kcontrol_new dmic3_switch[] = {
  1672. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1673. };
  1674. static const struct snd_kcontrol_new dmic4_switch[] = {
  1675. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1676. };
  1677. static const struct snd_kcontrol_new dmic5_switch[] = {
  1678. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1679. };
  1680. static const struct snd_kcontrol_new dmic6_switch[] = {
  1681. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1682. };
  1683. static const struct snd_kcontrol_new dmic7_switch[] = {
  1684. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1685. };
  1686. static const struct snd_kcontrol_new dmic8_switch[] = {
  1687. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1688. };
  1689. static const struct snd_kcontrol_new ear_rdac_switch[] = {
  1690. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1691. };
  1692. static const struct snd_kcontrol_new aux_rdac_switch[] = {
  1693. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1694. };
  1695. static const struct snd_kcontrol_new hphl_rdac_switch[] = {
  1696. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1697. };
  1698. static const struct snd_kcontrol_new hphr_rdac_switch[] = {
  1699. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1700. };
  1701. static const char * const adc2_mux_text[] = {
  1702. "INP2", "INP3"
  1703. };
  1704. static const struct soc_enum adc2_enum =
  1705. SOC_ENUM_SINGLE(WCD938X_TX_NEW_AMIC_MUX_CFG, 7,
  1706. ARRAY_SIZE(adc2_mux_text), adc2_mux_text);
  1707. static const struct snd_kcontrol_new tx_adc2_mux =
  1708. SOC_DAPM_ENUM("ADC2 MUX Mux", adc2_enum);
  1709. static const char * const adc3_mux_text[] = {
  1710. "INP4", "INP6"
  1711. };
  1712. static const struct soc_enum adc3_enum =
  1713. SOC_ENUM_SINGLE(WCD938X_TX_NEW_AMIC_MUX_CFG, 6,
  1714. ARRAY_SIZE(adc3_mux_text), adc3_mux_text);
  1715. static const struct snd_kcontrol_new tx_adc3_mux =
  1716. SOC_DAPM_ENUM("ADC3 MUX Mux", adc3_enum);
  1717. static const char * const adc4_mux_text[] = {
  1718. "INP5", "INP7"
  1719. };
  1720. static const struct soc_enum adc4_enum =
  1721. SOC_ENUM_SINGLE(WCD938X_TX_NEW_AMIC_MUX_CFG, 5,
  1722. ARRAY_SIZE(adc4_mux_text), adc4_mux_text);
  1723. static const struct snd_kcontrol_new tx_adc4_mux =
  1724. SOC_DAPM_ENUM("ADC4 MUX Mux", adc4_enum);
  1725. static const char * const rdac3_mux_text[] = {
  1726. "RX1", "RX3"
  1727. };
  1728. static const char * const hdr12_mux_text[] = {
  1729. "NO_HDR12", "HDR12"
  1730. };
  1731. static const struct soc_enum hdr12_enum =
  1732. SOC_ENUM_SINGLE(WCD938X_TX_NEW_AMIC_MUX_CFG, 4,
  1733. ARRAY_SIZE(hdr12_mux_text), hdr12_mux_text);
  1734. static const struct snd_kcontrol_new tx_hdr12_mux =
  1735. SOC_DAPM_ENUM("HDR12 MUX Mux", hdr12_enum);
  1736. static const char * const hdr34_mux_text[] = {
  1737. "NO_HDR34", "HDR34"
  1738. };
  1739. static const struct soc_enum hdr34_enum =
  1740. SOC_ENUM_SINGLE(WCD938X_TX_NEW_AMIC_MUX_CFG, 3,
  1741. ARRAY_SIZE(hdr34_mux_text), hdr34_mux_text);
  1742. static const struct snd_kcontrol_new tx_hdr34_mux =
  1743. SOC_DAPM_ENUM("HDR34 MUX Mux", hdr34_enum);
  1744. static const struct soc_enum rdac3_enum =
  1745. SOC_ENUM_SINGLE(WCD938X_DIGITAL_CDC_EAR_PATH_CTL, 0,
  1746. ARRAY_SIZE(rdac3_mux_text), rdac3_mux_text);
  1747. static const struct snd_kcontrol_new rx_rdac3_mux =
  1748. SOC_DAPM_ENUM("RDAC3_MUX Mux", rdac3_enum);
  1749. static const struct snd_soc_dapm_widget wcd938x_dapm_widgets[] = {
  1750. /*input widgets*/
  1751. SND_SOC_DAPM_INPUT("AMIC1"),
  1752. SND_SOC_DAPM_INPUT("AMIC2"),
  1753. SND_SOC_DAPM_INPUT("AMIC3"),
  1754. SND_SOC_DAPM_INPUT("AMIC4"),
  1755. SND_SOC_DAPM_INPUT("AMIC5"),
  1756. SND_SOC_DAPM_INPUT("AMIC6"),
  1757. SND_SOC_DAPM_INPUT("AMIC7"),
  1758. SND_SOC_DAPM_INPUT("IN1_HPHL"),
  1759. SND_SOC_DAPM_INPUT("IN2_HPHR"),
  1760. SND_SOC_DAPM_INPUT("IN3_AUX"),
  1761. /*tx widgets*/
  1762. SND_SOC_DAPM_ADC_E("ADC1", NULL, SND_SOC_NOPM, 0, 0,
  1763. wcd938x_codec_enable_adc,
  1764. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1765. SND_SOC_DAPM_ADC_E("ADC2", NULL, SND_SOC_NOPM, 1, 0,
  1766. wcd938x_codec_enable_adc,
  1767. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1768. SND_SOC_DAPM_ADC_E("ADC3", NULL, SND_SOC_NOPM, 2, 0,
  1769. wcd938x_codec_enable_adc,
  1770. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1771. SND_SOC_DAPM_ADC_E("ADC4", NULL, SND_SOC_NOPM, 3, 0,
  1772. wcd938x_codec_enable_adc,
  1773. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1774. SND_SOC_DAPM_ADC_E("DMIC1", NULL, SND_SOC_NOPM, 0, 0,
  1775. wcd938x_codec_enable_dmic,
  1776. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1777. SND_SOC_DAPM_ADC_E("DMIC2", NULL, SND_SOC_NOPM, 1, 0,
  1778. wcd938x_codec_enable_dmic,
  1779. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1780. SND_SOC_DAPM_ADC_E("DMIC3", NULL, SND_SOC_NOPM, 2, 0,
  1781. wcd938x_codec_enable_dmic,
  1782. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1783. SND_SOC_DAPM_ADC_E("DMIC4", NULL, SND_SOC_NOPM, 3, 0,
  1784. wcd938x_codec_enable_dmic,
  1785. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1786. SND_SOC_DAPM_ADC_E("DMIC5", NULL, SND_SOC_NOPM, 4, 0,
  1787. wcd938x_codec_enable_dmic,
  1788. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1789. SND_SOC_DAPM_ADC_E("DMIC6", NULL, SND_SOC_NOPM, 5, 0,
  1790. wcd938x_codec_enable_dmic,
  1791. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1792. SND_SOC_DAPM_ADC_E("DMIC7", NULL, SND_SOC_NOPM, 6, 0,
  1793. wcd938x_codec_enable_dmic,
  1794. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1795. SND_SOC_DAPM_ADC_E("DMIC8", NULL, SND_SOC_NOPM, 7, 0,
  1796. wcd938x_codec_enable_dmic,
  1797. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1798. SND_SOC_DAPM_MIXER_E("ADC1 REQ", SND_SOC_NOPM, 0, 0,
  1799. NULL, 0, wcd938x_enable_req,
  1800. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1801. SND_SOC_DAPM_MIXER_E("ADC2 REQ", SND_SOC_NOPM, 1, 0,
  1802. NULL, 0, wcd938x_enable_req,
  1803. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1804. SND_SOC_DAPM_MIXER_E("ADC3 REQ", SND_SOC_NOPM, 2, 0,
  1805. NULL, 0, wcd938x_enable_req,
  1806. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1807. SND_SOC_DAPM_MIXER_E("ADC4 REQ", SND_SOC_NOPM, 3, 0,
  1808. NULL, 0, wcd938x_enable_req,
  1809. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1810. SND_SOC_DAPM_MUX("ADC2 MUX", SND_SOC_NOPM, 0, 0,
  1811. &tx_adc2_mux),
  1812. SND_SOC_DAPM_MUX("ADC3 MUX", SND_SOC_NOPM, 0, 0,
  1813. &tx_adc3_mux),
  1814. SND_SOC_DAPM_MUX("ADC4 MUX", SND_SOC_NOPM, 0, 0,
  1815. &tx_adc4_mux),
  1816. SND_SOC_DAPM_MUX("HDR12 MUX", SND_SOC_NOPM, 0, 0,
  1817. &tx_hdr12_mux),
  1818. SND_SOC_DAPM_MUX("HDR34 MUX", SND_SOC_NOPM, 0, 0,
  1819. &tx_hdr34_mux),
  1820. /*tx mixers*/
  1821. SND_SOC_DAPM_MIXER_E("ADC1_MIXER", SND_SOC_NOPM, 0, 0,
  1822. adc1_switch, ARRAY_SIZE(adc1_switch),
  1823. wcd938x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  1824. SND_SOC_DAPM_POST_PMD),
  1825. SND_SOC_DAPM_MIXER_E("ADC2_MIXER", SND_SOC_NOPM, 0, 0,
  1826. adc2_switch, ARRAY_SIZE(adc2_switch),
  1827. wcd938x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  1828. SND_SOC_DAPM_POST_PMD),
  1829. SND_SOC_DAPM_MIXER_E("ADC3_MIXER", SND_SOC_NOPM, 0, 0, adc3_switch,
  1830. ARRAY_SIZE(adc3_switch), wcd938x_tx_swr_ctrl,
  1831. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1832. SND_SOC_DAPM_MIXER_E("ADC4_MIXER", SND_SOC_NOPM, 0, 0, adc4_switch,
  1833. ARRAY_SIZE(adc4_switch), wcd938x_tx_swr_ctrl,
  1834. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1835. SND_SOC_DAPM_MIXER_E("DMIC1_MIXER", SND_SOC_NOPM, 0,
  1836. 0, dmic1_switch, ARRAY_SIZE(dmic1_switch),
  1837. wcd938x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  1838. SND_SOC_DAPM_POST_PMD),
  1839. SND_SOC_DAPM_MIXER_E("DMIC2_MIXER", SND_SOC_NOPM, 0,
  1840. 0, dmic2_switch, ARRAY_SIZE(dmic2_switch),
  1841. wcd938x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  1842. SND_SOC_DAPM_POST_PMD),
  1843. SND_SOC_DAPM_MIXER_E("DMIC3_MIXER", SND_SOC_NOPM, 0,
  1844. 0, dmic3_switch, ARRAY_SIZE(dmic3_switch),
  1845. wcd938x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  1846. SND_SOC_DAPM_POST_PMD),
  1847. SND_SOC_DAPM_MIXER_E("DMIC4_MIXER", SND_SOC_NOPM, 0,
  1848. 0, dmic4_switch, ARRAY_SIZE(dmic4_switch),
  1849. wcd938x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  1850. SND_SOC_DAPM_POST_PMD),
  1851. SND_SOC_DAPM_MIXER_E("DMIC5_MIXER", SND_SOC_NOPM, 0,
  1852. 0, dmic5_switch, ARRAY_SIZE(dmic5_switch),
  1853. wcd938x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  1854. SND_SOC_DAPM_POST_PMD),
  1855. SND_SOC_DAPM_MIXER_E("DMIC6_MIXER", SND_SOC_NOPM, 0,
  1856. 0, dmic6_switch, ARRAY_SIZE(dmic6_switch),
  1857. wcd938x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  1858. SND_SOC_DAPM_POST_PMD),
  1859. SND_SOC_DAPM_MIXER_E("DMIC7_MIXER", SND_SOC_NOPM, 0,
  1860. 0, dmic7_switch, ARRAY_SIZE(dmic7_switch),
  1861. wcd938x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  1862. SND_SOC_DAPM_POST_PMD),
  1863. SND_SOC_DAPM_MIXER_E("DMIC8_MIXER", SND_SOC_NOPM, 0,
  1864. 0, dmic8_switch, ARRAY_SIZE(dmic8_switch),
  1865. wcd938x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  1866. SND_SOC_DAPM_POST_PMD),
  1867. /* micbias widgets*/
  1868. SND_SOC_DAPM_MICBIAS_E("MIC BIAS1", SND_SOC_NOPM, 0, 0,
  1869. wcd938x_codec_enable_micbias,
  1870. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1871. SND_SOC_DAPM_POST_PMD),
  1872. SND_SOC_DAPM_MICBIAS_E("MIC BIAS2", SND_SOC_NOPM, 0, 0,
  1873. wcd938x_codec_enable_micbias,
  1874. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1875. SND_SOC_DAPM_POST_PMD),
  1876. SND_SOC_DAPM_MICBIAS_E("MIC BIAS3", SND_SOC_NOPM, 0, 0,
  1877. wcd938x_codec_enable_micbias,
  1878. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1879. SND_SOC_DAPM_POST_PMD),
  1880. SND_SOC_DAPM_MICBIAS_E("MIC BIAS4", SND_SOC_NOPM, 0, 0,
  1881. wcd938x_codec_enable_micbias,
  1882. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1883. SND_SOC_DAPM_POST_PMD),
  1884. SND_SOC_DAPM_SUPPLY_S("CLS_H_PORT", 1, SND_SOC_NOPM, 0, 0,
  1885. wcd938x_enable_clsh,
  1886. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1887. /*rx widgets*/
  1888. SND_SOC_DAPM_PGA_E("EAR PGA", WCD938X_ANA_EAR, 7, 0, NULL, 0,
  1889. wcd938x_codec_enable_ear_pa,
  1890. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1891. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1892. SND_SOC_DAPM_PGA_E("AUX PGA", WCD938X_AUX_AUXPA, 7, 0, NULL, 0,
  1893. wcd938x_codec_enable_aux_pa,
  1894. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1895. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1896. SND_SOC_DAPM_PGA_E("HPHL PGA", WCD938X_ANA_HPH, 7, 0, NULL, 0,
  1897. wcd938x_codec_enable_hphl_pa,
  1898. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1899. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1900. SND_SOC_DAPM_PGA_E("HPHR PGA", WCD938X_ANA_HPH, 6, 0, NULL, 0,
  1901. wcd938x_codec_enable_hphr_pa,
  1902. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1903. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1904. SND_SOC_DAPM_DAC_E("RDAC1", NULL, SND_SOC_NOPM, 0, 0,
  1905. wcd938x_codec_hphl_dac_event,
  1906. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1907. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1908. SND_SOC_DAPM_DAC_E("RDAC2", NULL, SND_SOC_NOPM, 0, 0,
  1909. wcd938x_codec_hphr_dac_event,
  1910. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1911. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1912. SND_SOC_DAPM_DAC_E("RDAC3", NULL, SND_SOC_NOPM, 0, 0,
  1913. wcd938x_codec_ear_dac_event,
  1914. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1915. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1916. SND_SOC_DAPM_DAC_E("RDAC4", NULL, SND_SOC_NOPM, 0, 0,
  1917. wcd938x_codec_aux_dac_event,
  1918. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1919. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1920. SND_SOC_DAPM_MUX("RDAC3_MUX", SND_SOC_NOPM, 0, 0, &rx_rdac3_mux),
  1921. SND_SOC_DAPM_MIXER_E("RX1", SND_SOC_NOPM, 0, 0, NULL, 0,
  1922. wcd938x_enable_rx1, SND_SOC_DAPM_PRE_PMU |
  1923. SND_SOC_DAPM_POST_PMD),
  1924. SND_SOC_DAPM_MIXER_E("RX2", SND_SOC_NOPM, 0, 0, NULL, 0,
  1925. wcd938x_enable_rx2, SND_SOC_DAPM_PRE_PMU |
  1926. SND_SOC_DAPM_POST_PMD),
  1927. SND_SOC_DAPM_MIXER_E("RX3", SND_SOC_NOPM, 0, 0, NULL, 0,
  1928. wcd938x_enable_rx3, SND_SOC_DAPM_PRE_PMU |
  1929. SND_SOC_DAPM_POST_PMD),
  1930. /* rx mixer widgets*/
  1931. SND_SOC_DAPM_MIXER("EAR_RDAC", SND_SOC_NOPM, 0, 0,
  1932. ear_rdac_switch, ARRAY_SIZE(ear_rdac_switch)),
  1933. SND_SOC_DAPM_MIXER("AUX_RDAC", SND_SOC_NOPM, 0, 0,
  1934. aux_rdac_switch, ARRAY_SIZE(aux_rdac_switch)),
  1935. SND_SOC_DAPM_MIXER("HPHL_RDAC", SND_SOC_NOPM, 0, 0,
  1936. hphl_rdac_switch, ARRAY_SIZE(hphl_rdac_switch)),
  1937. SND_SOC_DAPM_MIXER("HPHR_RDAC", SND_SOC_NOPM, 0, 0,
  1938. hphr_rdac_switch, ARRAY_SIZE(hphr_rdac_switch)),
  1939. /*output widgets tx*/
  1940. SND_SOC_DAPM_OUTPUT("ADC1_OUTPUT"),
  1941. SND_SOC_DAPM_OUTPUT("ADC2_OUTPUT"),
  1942. SND_SOC_DAPM_OUTPUT("ADC3_OUTPUT"),
  1943. SND_SOC_DAPM_OUTPUT("ADC4_OUTPUT"),
  1944. SND_SOC_DAPM_OUTPUT("DMIC1_OUTPUT"),
  1945. SND_SOC_DAPM_OUTPUT("DMIC2_OUTPUT"),
  1946. SND_SOC_DAPM_OUTPUT("DMIC3_OUTPUT"),
  1947. SND_SOC_DAPM_OUTPUT("DMIC4_OUTPUT"),
  1948. SND_SOC_DAPM_OUTPUT("DMIC5_OUTPUT"),
  1949. SND_SOC_DAPM_OUTPUT("DMIC6_OUTPUT"),
  1950. SND_SOC_DAPM_OUTPUT("DMIC7_OUTPUT"),
  1951. SND_SOC_DAPM_OUTPUT("DMIC8_OUTPUT"),
  1952. /*output widgets rx*/
  1953. SND_SOC_DAPM_OUTPUT("EAR"),
  1954. SND_SOC_DAPM_OUTPUT("AUX"),
  1955. SND_SOC_DAPM_OUTPUT("HPHL"),
  1956. SND_SOC_DAPM_OUTPUT("HPHR"),
  1957. };
  1958. static const struct snd_soc_dapm_route wcd938x_audio_map[] = {
  1959. {"ADC1_OUTPUT", NULL, "ADC1_MIXER"},
  1960. {"ADC1_MIXER", "Switch", "ADC1 REQ"},
  1961. {"ADC1 REQ", NULL, "ADC1"},
  1962. {"ADC1", NULL, "AMIC1"},
  1963. {"ADC2_OUTPUT", NULL, "ADC2_MIXER"},
  1964. {"ADC2_MIXER", "Switch", "ADC2 REQ"},
  1965. {"ADC2 REQ", NULL, "ADC2"},
  1966. {"ADC2", NULL, "HDR12 MUX"},
  1967. {"HDR12 MUX", "NO_HDR12", "ADC2 MUX"},
  1968. {"HDR12 MUX", "HDR12", "AMIC1"},
  1969. {"ADC2 MUX", "INP3", "AMIC3"},
  1970. {"ADC2 MUX", "INP2", "AMIC2"},
  1971. {"ADC3_OUTPUT", NULL, "ADC3_MIXER"},
  1972. {"ADC3_MIXER", "Switch", "ADC3 REQ"},
  1973. {"ADC3 REQ", NULL, "ADC3"},
  1974. {"ADC3", NULL, "HDR34 MUX"},
  1975. {"HDR34 MUX", "NO_HDR34", "ADC3 MUX"},
  1976. {"HDR34 MUX", "HDR34", "AMIC5"},
  1977. {"ADC3 MUX", "INP4", "AMIC4"},
  1978. {"ADC3 MUX", "INP6", "AMIC6"},
  1979. {"ADC4_OUTPUT", NULL, "ADC4_MIXER"},
  1980. {"ADC4_MIXER", "Switch", "ADC4 REQ"},
  1981. {"ADC4 REQ", NULL, "ADC4"},
  1982. {"ADC4", NULL, "ADC4 MUX"},
  1983. {"ADC4 MUX", "INP5", "AMIC5"},
  1984. {"ADC4 MUX", "INP7", "AMIC7"},
  1985. {"DMIC1_OUTPUT", NULL, "DMIC1_MIXER"},
  1986. {"DMIC1_MIXER", "Switch", "DMIC1"},
  1987. {"DMIC2_OUTPUT", NULL, "DMIC2_MIXER"},
  1988. {"DMIC2_MIXER", "Switch", "DMIC2"},
  1989. {"DMIC3_OUTPUT", NULL, "DMIC3_MIXER"},
  1990. {"DMIC3_MIXER", "Switch", "DMIC3"},
  1991. {"DMIC4_OUTPUT", NULL, "DMIC4_MIXER"},
  1992. {"DMIC4_MIXER", "Switch", "DMIC4"},
  1993. {"DMIC5_OUTPUT", NULL, "DMIC5_MIXER"},
  1994. {"DMIC5_MIXER", "Switch", "DMIC5"},
  1995. {"DMIC6_OUTPUT", NULL, "DMIC6_MIXER"},
  1996. {"DMIC6_MIXER", "Switch", "DMIC6"},
  1997. {"DMIC7_OUTPUT", NULL, "DMIC7_MIXER"},
  1998. {"DMIC7_MIXER", "Switch", "DMIC7"},
  1999. {"DMIC8_OUTPUT", NULL, "DMIC8_MIXER"},
  2000. {"DMIC8_MIXER", "Switch", "DMIC8"},
  2001. {"IN1_HPHL", NULL, "CLS_H_PORT"},
  2002. {"RX1", NULL, "IN1_HPHL"},
  2003. {"RDAC1", NULL, "RX1"},
  2004. {"HPHL_RDAC", "Switch", "RDAC1"},
  2005. {"HPHL PGA", NULL, "HPHL_RDAC"},
  2006. {"HPHL", NULL, "HPHL PGA"},
  2007. {"IN2_HPHR", NULL, "CLS_H_PORT"},
  2008. {"RX2", NULL, "IN2_HPHR"},
  2009. {"RDAC2", NULL, "RX2"},
  2010. {"HPHR_RDAC", "Switch", "RDAC2"},
  2011. {"HPHR PGA", NULL, "HPHR_RDAC"},
  2012. {"HPHR", NULL, "HPHR PGA"},
  2013. {"IN3_AUX", NULL, "CLS_H_PORT"},
  2014. {"RX3", NULL, "IN3_AUX"},
  2015. {"RDAC4", NULL, "RX3"},
  2016. {"AUX_RDAC", "Switch", "RDAC4"},
  2017. {"AUX PGA", NULL, "AUX_RDAC"},
  2018. {"AUX", NULL, "AUX PGA"},
  2019. {"RDAC3_MUX", "RX3", "RX3"},
  2020. {"RDAC3_MUX", "RX1", "RX1"},
  2021. {"RDAC3", NULL, "RDAC3_MUX"},
  2022. {"EAR_RDAC", "Switch", "RDAC3"},
  2023. {"EAR PGA", NULL, "EAR_RDAC"},
  2024. {"EAR", NULL, "EAR PGA"},
  2025. };
  2026. static ssize_t wcd938x_version_read(struct snd_info_entry *entry,
  2027. void *file_private_data,
  2028. struct file *file,
  2029. char __user *buf, size_t count,
  2030. loff_t pos)
  2031. {
  2032. struct wcd938x_priv *priv;
  2033. char buffer[WCD938X_VERSION_ENTRY_SIZE];
  2034. int len = 0;
  2035. priv = (struct wcd938x_priv *) entry->private_data;
  2036. if (!priv) {
  2037. pr_err("%s: wcd938x priv is null\n", __func__);
  2038. return -EINVAL;
  2039. }
  2040. switch (priv->version) {
  2041. case WCD938X_VERSION_1_0:
  2042. len = snprintf(buffer, sizeof(buffer), "WCD938X_1_0\n");
  2043. break;
  2044. default:
  2045. len = snprintf(buffer, sizeof(buffer), "VER_UNDEFINED\n");
  2046. }
  2047. return simple_read_from_buffer(buf, count, &pos, buffer, len);
  2048. }
  2049. static struct snd_info_entry_ops wcd938x_info_ops = {
  2050. .read = wcd938x_version_read,
  2051. };
  2052. /*
  2053. * wcd938x_info_create_codec_entry - creates wcd938x module
  2054. * @codec_root: The parent directory
  2055. * @component: component instance
  2056. *
  2057. * Creates wcd938x module and version entry under the given
  2058. * parent directory.
  2059. *
  2060. * Return: 0 on success or negative error code on failure.
  2061. */
  2062. int wcd938x_info_create_codec_entry(struct snd_info_entry *codec_root,
  2063. struct snd_soc_component *component)
  2064. {
  2065. struct snd_info_entry *version_entry;
  2066. struct wcd938x_priv *priv;
  2067. struct snd_soc_card *card;
  2068. if (!codec_root || !component)
  2069. return -EINVAL;
  2070. priv = snd_soc_component_get_drvdata(component);
  2071. if (priv->entry) {
  2072. dev_dbg(priv->dev,
  2073. "%s:wcd938x module already created\n", __func__);
  2074. return 0;
  2075. }
  2076. card = component->card;
  2077. priv->entry = snd_info_create_subdir(codec_root->module,
  2078. "wcd938x", codec_root);
  2079. if (!priv->entry) {
  2080. dev_dbg(component->dev, "%s: failed to create wcd938x entry\n",
  2081. __func__);
  2082. return -ENOMEM;
  2083. }
  2084. version_entry = snd_info_create_card_entry(card->snd_card,
  2085. "version",
  2086. priv->entry);
  2087. if (!version_entry) {
  2088. dev_dbg(component->dev, "%s: failed to create wcd938x version entry\n",
  2089. __func__);
  2090. return -ENOMEM;
  2091. }
  2092. version_entry->private_data = priv;
  2093. version_entry->size = WCD938X_VERSION_ENTRY_SIZE;
  2094. version_entry->content = SNDRV_INFO_CONTENT_DATA;
  2095. version_entry->c.ops = &wcd938x_info_ops;
  2096. if (snd_info_register(version_entry) < 0) {
  2097. snd_info_free_entry(version_entry);
  2098. return -ENOMEM;
  2099. }
  2100. priv->version_entry = version_entry;
  2101. return 0;
  2102. }
  2103. EXPORT_SYMBOL(wcd938x_info_create_codec_entry);
  2104. static int wcd938x_soc_codec_probe(struct snd_soc_component *component)
  2105. {
  2106. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  2107. struct snd_soc_dapm_context *dapm =
  2108. snd_soc_component_get_dapm(component);
  2109. int variant;
  2110. int ret = -EINVAL;
  2111. dev_info(component->dev, "%s()\n", __func__);
  2112. wcd938x = snd_soc_component_get_drvdata(component);
  2113. if (!wcd938x)
  2114. return -EINVAL;
  2115. wcd938x->component = component;
  2116. snd_soc_component_init_regmap(component, wcd938x->regmap);
  2117. variant = (snd_soc_component_read32(component,
  2118. WCD938X_DIGITAL_EFUSE_REG_0) & 0x1E) >> 1;
  2119. wcd938x->variant = variant;
  2120. wcd938x->fw_data = devm_kzalloc(component->dev,
  2121. sizeof(*(wcd938x->fw_data)),
  2122. GFP_KERNEL);
  2123. if (!wcd938x->fw_data) {
  2124. dev_err(component->dev, "Failed to allocate fw_data\n");
  2125. ret = -ENOMEM;
  2126. goto err;
  2127. }
  2128. set_bit(WCD9XXX_MBHC_CAL, wcd938x->fw_data->cal_bit);
  2129. ret = wcd_cal_create_hwdep(wcd938x->fw_data,
  2130. WCD9XXX_CODEC_HWDEP_NODE, component);
  2131. if (ret < 0) {
  2132. dev_err(component->dev, "%s hwdep failed %d\n", __func__, ret);
  2133. goto err_hwdep;
  2134. }
  2135. ret = wcd938x_mbhc_init(&wcd938x->mbhc, component, wcd938x->fw_data);
  2136. if (ret) {
  2137. pr_err("%s: mbhc initialization failed\n", __func__);
  2138. goto err_hwdep;
  2139. }
  2140. snd_soc_dapm_ignore_suspend(dapm, "AMIC1");
  2141. snd_soc_dapm_ignore_suspend(dapm, "AMIC2");
  2142. snd_soc_dapm_ignore_suspend(dapm, "AMIC3");
  2143. snd_soc_dapm_ignore_suspend(dapm, "AMIC4");
  2144. snd_soc_dapm_ignore_suspend(dapm, "AMIC5");
  2145. snd_soc_dapm_ignore_suspend(dapm, "AMIC6");
  2146. snd_soc_dapm_ignore_suspend(dapm, "AMIC7");
  2147. snd_soc_dapm_ignore_suspend(dapm, "DMIC1_OUTPUT");
  2148. snd_soc_dapm_ignore_suspend(dapm, "DMIC2_OUTPUT");
  2149. snd_soc_dapm_ignore_suspend(dapm, "DMIC3_OUTPUT");
  2150. snd_soc_dapm_ignore_suspend(dapm, "DMIC4_OUTPUT");
  2151. snd_soc_dapm_ignore_suspend(dapm, "DMIC5_OUTPUT");
  2152. snd_soc_dapm_ignore_suspend(dapm, "DMIC6_OUTPUT");
  2153. snd_soc_dapm_ignore_suspend(dapm, "DMIC7_OUTPUT");
  2154. snd_soc_dapm_ignore_suspend(dapm, "DMIC8_OUTPUT");
  2155. snd_soc_dapm_ignore_suspend(dapm, "ADC1_OUTPUT");
  2156. snd_soc_dapm_ignore_suspend(dapm, "ADC2_OUTPUT");
  2157. snd_soc_dapm_ignore_suspend(dapm, "ADC3_OUTPUT");
  2158. snd_soc_dapm_ignore_suspend(dapm, "ADC4_OUTPUT");
  2159. snd_soc_dapm_ignore_suspend(dapm, "IN1_HPHL");
  2160. snd_soc_dapm_ignore_suspend(dapm, "IN2_HPHR");
  2161. snd_soc_dapm_ignore_suspend(dapm, "IN3_AUX");
  2162. snd_soc_dapm_ignore_suspend(dapm, "EAR");
  2163. snd_soc_dapm_ignore_suspend(dapm, "AUX");
  2164. snd_soc_dapm_ignore_suspend(dapm, "HPHL");
  2165. snd_soc_dapm_ignore_suspend(dapm, "HPHR");
  2166. snd_soc_dapm_sync(dapm);
  2167. wcd_cls_h_init(&wcd938x->clsh_info);
  2168. wcd938x_init_reg(component);
  2169. if (wcd938x->variant == WCD9380) {
  2170. ret = snd_soc_add_component_controls(component, wcd9380_snd_controls,
  2171. ARRAY_SIZE(wcd9380_snd_controls));
  2172. if (ret < 0) {
  2173. dev_err(component->dev,
  2174. "%s: Failed to add snd ctrls for variant: %d\n",
  2175. __func__, wcd938x->variant);
  2176. goto err_hwdep;
  2177. }
  2178. }
  2179. if (wcd938x->variant == WCD9385) {
  2180. ret = snd_soc_add_component_controls(component, wcd9385_snd_controls,
  2181. ARRAY_SIZE(wcd9385_snd_controls));
  2182. if (ret < 0) {
  2183. dev_err(component->dev,
  2184. "%s: Failed to add snd ctrls for variant: %d\n",
  2185. __func__, wcd938x->variant);
  2186. goto err_hwdep;
  2187. }
  2188. }
  2189. wcd938x->version = WCD938X_VERSION_1_0;
  2190. /* Register event notifier */
  2191. wcd938x->nblock.notifier_call = wcd938x_event_notify;
  2192. if (wcd938x->register_notifier) {
  2193. ret = wcd938x->register_notifier(wcd938x->handle,
  2194. &wcd938x->nblock,
  2195. true);
  2196. if (ret) {
  2197. dev_err(component->dev,
  2198. "%s: Failed to register notifier %d\n",
  2199. __func__, ret);
  2200. return ret;
  2201. }
  2202. }
  2203. return ret;
  2204. err_hwdep:
  2205. wcd938x->fw_data = NULL;
  2206. err:
  2207. return ret;
  2208. }
  2209. static void wcd938x_soc_codec_remove(struct snd_soc_component *component)
  2210. {
  2211. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  2212. if (!wcd938x) {
  2213. dev_err(component->dev, "%s: wcd938x is already NULL\n",
  2214. __func__);
  2215. return;
  2216. }
  2217. if (wcd938x->register_notifier)
  2218. wcd938x->register_notifier(wcd938x->handle,
  2219. &wcd938x->nblock,
  2220. false);
  2221. }
  2222. static struct snd_soc_component_driver soc_codec_dev_wcd938x = {
  2223. .name = WCD938X_DRV_NAME,
  2224. .probe = wcd938x_soc_codec_probe,
  2225. .remove = wcd938x_soc_codec_remove,
  2226. .controls = wcd938x_snd_controls,
  2227. .num_controls = ARRAY_SIZE(wcd938x_snd_controls),
  2228. .dapm_widgets = wcd938x_dapm_widgets,
  2229. .num_dapm_widgets = ARRAY_SIZE(wcd938x_dapm_widgets),
  2230. .dapm_routes = wcd938x_audio_map,
  2231. .num_dapm_routes = ARRAY_SIZE(wcd938x_audio_map),
  2232. };
  2233. static int wcd938x_reset(struct device *dev)
  2234. {
  2235. struct wcd938x_priv *wcd938x = NULL;
  2236. int rc = 0;
  2237. int value = 0;
  2238. if (!dev)
  2239. return -ENODEV;
  2240. wcd938x = dev_get_drvdata(dev);
  2241. if (!wcd938x)
  2242. return -EINVAL;
  2243. if (!wcd938x->rst_np) {
  2244. dev_err(dev, "%s: reset gpio device node not specified\n",
  2245. __func__);
  2246. return -EINVAL;
  2247. }
  2248. value = msm_cdc_pinctrl_get_state(wcd938x->rst_np);
  2249. if (value > 0)
  2250. return 0;
  2251. rc = msm_cdc_pinctrl_select_sleep_state(wcd938x->rst_np);
  2252. if (rc) {
  2253. dev_err(dev, "%s: wcd sleep state request fail!\n",
  2254. __func__);
  2255. return rc;
  2256. }
  2257. /* 20us sleep required after pulling the reset gpio to LOW */
  2258. usleep_range(20, 30);
  2259. rc = msm_cdc_pinctrl_select_active_state(wcd938x->rst_np);
  2260. if (rc) {
  2261. dev_err(dev, "%s: wcd active state request fail!\n",
  2262. __func__);
  2263. return rc;
  2264. }
  2265. /* 20us sleep required after pulling the reset gpio to HIGH */
  2266. usleep_range(20, 30);
  2267. return rc;
  2268. }
  2269. static int wcd938x_read_of_property_u32(struct device *dev, const char *name,
  2270. u32 *val)
  2271. {
  2272. int rc = 0;
  2273. rc = of_property_read_u32(dev->of_node, name, val);
  2274. if (rc)
  2275. dev_err(dev, "%s: Looking up %s property in node %s failed\n",
  2276. __func__, name, dev->of_node->full_name);
  2277. return rc;
  2278. }
  2279. static void wcd938x_dt_parse_micbias_info(struct device *dev,
  2280. struct wcd938x_micbias_setting *mb)
  2281. {
  2282. u32 prop_val = 0;
  2283. int rc = 0;
  2284. /* MB1 */
  2285. if (of_find_property(dev->of_node, "qcom,cdc-micbias1-mv",
  2286. NULL)) {
  2287. rc = wcd938x_read_of_property_u32(dev,
  2288. "qcom,cdc-micbias1-mv",
  2289. &prop_val);
  2290. if (!rc)
  2291. mb->micb1_mv = prop_val;
  2292. } else {
  2293. dev_info(dev, "%s: Micbias1 DT property not found\n",
  2294. __func__);
  2295. }
  2296. /* MB2 */
  2297. if (of_find_property(dev->of_node, "qcom,cdc-micbias2-mv",
  2298. NULL)) {
  2299. rc = wcd938x_read_of_property_u32(dev,
  2300. "qcom,cdc-micbias2-mv",
  2301. &prop_val);
  2302. if (!rc)
  2303. mb->micb2_mv = prop_val;
  2304. } else {
  2305. dev_info(dev, "%s: Micbias2 DT property not found\n",
  2306. __func__);
  2307. }
  2308. /* MB3 */
  2309. if (of_find_property(dev->of_node, "qcom,cdc-micbias3-mv",
  2310. NULL)) {
  2311. rc = wcd938x_read_of_property_u32(dev,
  2312. "qcom,cdc-micbias3-mv",
  2313. &prop_val);
  2314. if (!rc)
  2315. mb->micb3_mv = prop_val;
  2316. } else {
  2317. dev_info(dev, "%s: Micbias3 DT property not found\n",
  2318. __func__);
  2319. }
  2320. }
  2321. static int wcd938x_reset_low(struct device *dev)
  2322. {
  2323. struct wcd938x_priv *wcd938x = NULL;
  2324. int rc = 0;
  2325. if (!dev)
  2326. return -ENODEV;
  2327. wcd938x = dev_get_drvdata(dev);
  2328. if (!wcd938x)
  2329. return -EINVAL;
  2330. if (!wcd938x->rst_np) {
  2331. dev_err(dev, "%s: reset gpio device node not specified\n",
  2332. __func__);
  2333. return -EINVAL;
  2334. }
  2335. rc = msm_cdc_pinctrl_select_sleep_state(wcd938x->rst_np);
  2336. if (rc) {
  2337. dev_err(dev, "%s: wcd sleep state request fail!\n",
  2338. __func__);
  2339. return rc;
  2340. }
  2341. /* 20us sleep required after pulling the reset gpio to LOW */
  2342. usleep_range(20, 30);
  2343. return rc;
  2344. }
  2345. struct wcd938x_pdata *wcd938x_populate_dt_data(struct device *dev)
  2346. {
  2347. struct wcd938x_pdata *pdata = NULL;
  2348. pdata = devm_kzalloc(dev, sizeof(struct wcd938x_pdata),
  2349. GFP_KERNEL);
  2350. if (!pdata)
  2351. return NULL;
  2352. pdata->rst_np = of_parse_phandle(dev->of_node,
  2353. "qcom,wcd-rst-gpio-node", 0);
  2354. if (!pdata->rst_np) {
  2355. dev_err(dev, "%s: Looking up %s property in node %s failed\n",
  2356. __func__, "qcom,wcd-rst-gpio-node",
  2357. dev->of_node->full_name);
  2358. return NULL;
  2359. }
  2360. /* Parse power supplies */
  2361. msm_cdc_get_power_supplies(dev, &pdata->regulator,
  2362. &pdata->num_supplies);
  2363. if (!pdata->regulator || (pdata->num_supplies <= 0)) {
  2364. dev_err(dev, "%s: no power supplies defined for codec\n",
  2365. __func__);
  2366. return NULL;
  2367. }
  2368. pdata->rx_slave = of_parse_phandle(dev->of_node, "qcom,rx-slave", 0);
  2369. pdata->tx_slave = of_parse_phandle(dev->of_node, "qcom,tx-slave", 0);
  2370. wcd938x_dt_parse_micbias_info(dev, &pdata->micbias);
  2371. return pdata;
  2372. }
  2373. static int wcd938x_bind(struct device *dev)
  2374. {
  2375. int ret = 0, i = 0;
  2376. struct wcd938x_pdata *pdata = dev_get_platdata(dev);
  2377. struct wcd938x_priv *wcd938x = dev_get_drvdata(dev);
  2378. /*
  2379. * Add 5msec delay to provide sufficient time for
  2380. * soundwire auto enumeration of slave devices as
  2381. * as per HW requirement.
  2382. */
  2383. usleep_range(5000, 5010);
  2384. ret = component_bind_all(dev, wcd938x);
  2385. if (ret) {
  2386. dev_err(dev, "%s: Slave bind failed, ret = %d\n",
  2387. __func__, ret);
  2388. return ret;
  2389. }
  2390. wcd938x->rx_swr_dev = get_matching_swr_slave_device(pdata->rx_slave);
  2391. if (!wcd938x->rx_swr_dev) {
  2392. dev_err(dev, "%s: Could not find RX swr slave device\n",
  2393. __func__);
  2394. ret = -ENODEV;
  2395. goto err;
  2396. }
  2397. wcd938x->tx_swr_dev = get_matching_swr_slave_device(pdata->tx_slave);
  2398. if (!wcd938x->tx_swr_dev) {
  2399. dev_err(dev, "%s: Could not find TX swr slave device\n",
  2400. __func__);
  2401. ret = -ENODEV;
  2402. goto err;
  2403. }
  2404. wcd938x->regmap = devm_regmap_init_swr(wcd938x->tx_swr_dev,
  2405. &wcd938x_regmap_config);
  2406. if (!wcd938x->regmap) {
  2407. dev_err(dev, "%s: Regmap init failed\n",
  2408. __func__);
  2409. goto err;
  2410. }
  2411. /* Set all interupts as edge triggered */
  2412. for (i = 0; i < wcd938x_regmap_irq_chip.num_regs; i++)
  2413. regmap_write(wcd938x->regmap,
  2414. (WCD938X_DIGITAL_INTR_LEVEL_0 + i), 0);
  2415. wcd938x_regmap_irq_chip.irq_drv_data = wcd938x;
  2416. wcd938x->irq_info.wcd_regmap_irq_chip = &wcd938x_regmap_irq_chip;
  2417. wcd938x->irq_info.codec_name = "WCD938X";
  2418. wcd938x->irq_info.regmap = wcd938x->regmap;
  2419. wcd938x->irq_info.dev = dev;
  2420. ret = wcd_irq_init(&wcd938x->irq_info, &wcd938x->virq);
  2421. if (ret) {
  2422. dev_err(wcd938x->dev, "%s: IRQ init failed: %d\n",
  2423. __func__, ret);
  2424. goto err;
  2425. }
  2426. wcd938x->tx_swr_dev->slave_irq = wcd938x->virq;
  2427. ret = snd_soc_register_component(dev, &soc_codec_dev_wcd938x,
  2428. NULL, 0);
  2429. if (ret) {
  2430. dev_err(dev, "%s: Codec registration failed\n",
  2431. __func__);
  2432. goto err_irq;
  2433. }
  2434. return ret;
  2435. err_irq:
  2436. wcd_irq_exit(&wcd938x->irq_info, wcd938x->virq);
  2437. err:
  2438. component_unbind_all(dev, wcd938x);
  2439. return ret;
  2440. }
  2441. static void wcd938x_unbind(struct device *dev)
  2442. {
  2443. struct wcd938x_priv *wcd938x = dev_get_drvdata(dev);
  2444. wcd_irq_exit(&wcd938x->irq_info, wcd938x->virq);
  2445. snd_soc_unregister_component(dev);
  2446. component_unbind_all(dev, wcd938x);
  2447. }
  2448. static const struct of_device_id wcd938x_dt_match[] = {
  2449. { .compatible = "qcom,wcd938x-codec" },
  2450. {}
  2451. };
  2452. static const struct component_master_ops wcd938x_comp_ops = {
  2453. .bind = wcd938x_bind,
  2454. .unbind = wcd938x_unbind,
  2455. };
  2456. static int wcd938x_compare_of(struct device *dev, void *data)
  2457. {
  2458. return dev->of_node == data;
  2459. }
  2460. static void wcd938x_release_of(struct device *dev, void *data)
  2461. {
  2462. of_node_put(data);
  2463. }
  2464. static int wcd938x_add_slave_components(struct device *dev,
  2465. struct component_match **matchptr)
  2466. {
  2467. struct device_node *np, *rx_node, *tx_node;
  2468. np = dev->of_node;
  2469. rx_node = of_parse_phandle(np, "qcom,rx-slave", 0);
  2470. if (!rx_node) {
  2471. dev_err(dev, "%s: Rx-slave node not defined\n", __func__);
  2472. return -ENODEV;
  2473. }
  2474. of_node_get(rx_node);
  2475. component_match_add_release(dev, matchptr,
  2476. wcd938x_release_of,
  2477. wcd938x_compare_of,
  2478. rx_node);
  2479. tx_node = of_parse_phandle(np, "qcom,tx-slave", 0);
  2480. if (!tx_node) {
  2481. dev_err(dev, "%s: Tx-slave node not defined\n", __func__);
  2482. return -ENODEV;
  2483. }
  2484. of_node_get(tx_node);
  2485. component_match_add_release(dev, matchptr,
  2486. wcd938x_release_of,
  2487. wcd938x_compare_of,
  2488. tx_node);
  2489. return 0;
  2490. }
  2491. static int wcd938x_wakeup(void *handle, bool enable)
  2492. {
  2493. struct wcd938x_priv *priv;
  2494. if (!handle) {
  2495. pr_err("%s: NULL handle\n", __func__);
  2496. return -EINVAL;
  2497. }
  2498. priv = (struct wcd938x_priv *)handle;
  2499. if (!priv->tx_swr_dev) {
  2500. pr_err("%s: tx swr dev is NULL\n", __func__);
  2501. return -EINVAL;
  2502. }
  2503. if (enable)
  2504. return swr_device_wakeup_vote(priv->tx_swr_dev);
  2505. else
  2506. return swr_device_wakeup_unvote(priv->tx_swr_dev);
  2507. }
  2508. static int wcd938x_probe(struct platform_device *pdev)
  2509. {
  2510. struct component_match *match = NULL;
  2511. struct wcd938x_priv *wcd938x = NULL;
  2512. struct wcd938x_pdata *pdata = NULL;
  2513. struct wcd_ctrl_platform_data *plat_data = NULL;
  2514. struct device *dev = &pdev->dev;
  2515. int ret;
  2516. wcd938x = devm_kzalloc(dev, sizeof(struct wcd938x_priv),
  2517. GFP_KERNEL);
  2518. if (!wcd938x)
  2519. return -ENOMEM;
  2520. dev_set_drvdata(dev, wcd938x);
  2521. pdata = wcd938x_populate_dt_data(dev);
  2522. if (!pdata) {
  2523. dev_err(dev, "%s: Fail to obtain platform data\n", __func__);
  2524. return -EINVAL;
  2525. }
  2526. dev->platform_data = pdata;
  2527. wcd938x->rst_np = pdata->rst_np;
  2528. ret = msm_cdc_init_supplies(dev, &wcd938x->supplies,
  2529. pdata->regulator, pdata->num_supplies);
  2530. if (!wcd938x->supplies) {
  2531. dev_err(dev, "%s: Cannot init wcd supplies\n",
  2532. __func__);
  2533. return ret;
  2534. }
  2535. plat_data = dev_get_platdata(dev->parent);
  2536. if (!plat_data) {
  2537. dev_err(dev, "%s: platform data from parent is NULL\n",
  2538. __func__);
  2539. return -EINVAL;
  2540. }
  2541. wcd938x->handle = (void *)plat_data->handle;
  2542. if (!wcd938x->handle) {
  2543. dev_err(dev, "%s: handle is NULL\n", __func__);
  2544. return -EINVAL;
  2545. }
  2546. wcd938x->update_wcd_event = plat_data->update_wcd_event;
  2547. if (!wcd938x->update_wcd_event) {
  2548. dev_err(dev, "%s: update_wcd_event api is null!\n",
  2549. __func__);
  2550. return -EINVAL;
  2551. }
  2552. wcd938x->register_notifier = plat_data->register_notifier;
  2553. if (!wcd938x->register_notifier) {
  2554. dev_err(dev, "%s: register_notifier api is null!\n",
  2555. __func__);
  2556. return -EINVAL;
  2557. }
  2558. ret = msm_cdc_enable_static_supplies(&pdev->dev, wcd938x->supplies,
  2559. pdata->regulator,
  2560. pdata->num_supplies);
  2561. if (ret) {
  2562. dev_err(dev, "%s: wcd static supply enable failed!\n",
  2563. __func__);
  2564. return ret;
  2565. }
  2566. ret = wcd938x_parse_port_mapping(dev, "qcom,rx_swr_ch_map",
  2567. CODEC_RX);
  2568. ret |= wcd938x_parse_port_mapping(dev, "qcom,tx_swr_ch_map",
  2569. CODEC_TX);
  2570. if (ret) {
  2571. dev_err(dev, "Failed to read port mapping\n");
  2572. goto err;
  2573. }
  2574. ret = wcd938x_add_slave_components(dev, &match);
  2575. if (ret)
  2576. goto err;
  2577. wcd938x_reset(dev);
  2578. wcd938x->wakeup = wcd938x_wakeup;
  2579. return component_master_add_with_match(dev,
  2580. &wcd938x_comp_ops, match);
  2581. err:
  2582. return ret;
  2583. }
  2584. static int wcd938x_remove(struct platform_device *pdev)
  2585. {
  2586. component_master_del(&pdev->dev, &wcd938x_comp_ops);
  2587. dev_set_drvdata(&pdev->dev, NULL);
  2588. return 0;
  2589. }
  2590. #ifdef CONFIG_PM_SLEEP
  2591. static int wcd938x_suspend(struct device *dev)
  2592. {
  2593. return 0;
  2594. }
  2595. static int wcd938x_resume(struct device *dev)
  2596. {
  2597. return 0;
  2598. }
  2599. static const struct dev_pm_ops wcd938x_dev_pm_ops = {
  2600. SET_SYSTEM_SLEEP_PM_OPS(
  2601. wcd938x_suspend,
  2602. wcd938x_resume
  2603. )
  2604. };
  2605. #endif
  2606. static struct platform_driver wcd938x_codec_driver = {
  2607. .probe = wcd938x_probe,
  2608. .remove = wcd938x_remove,
  2609. .driver = {
  2610. .name = "wcd938x_codec",
  2611. .owner = THIS_MODULE,
  2612. .of_match_table = of_match_ptr(wcd938x_dt_match),
  2613. #ifdef CONFIG_PM_SLEEP
  2614. .pm = &wcd938x_dev_pm_ops,
  2615. #endif
  2616. .suppress_bind_attrs = true,
  2617. },
  2618. };
  2619. module_platform_driver(wcd938x_codec_driver);
  2620. MODULE_DESCRIPTION("WCD938X Codec driver");
  2621. MODULE_LICENSE("GPL v2");