wcd938x.c 84 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984
  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. wcd938x_init_reg(component);
  1400. regcache_mark_dirty(wcd938x->regmap);
  1401. regcache_sync(wcd938x->regmap);
  1402. /* Initialize MBHC module */
  1403. mbhc = &wcd938x->mbhc->wcd_mbhc;
  1404. ret = wcd938x_mbhc_post_ssr_init(wcd938x->mbhc, component);
  1405. if (ret) {
  1406. dev_err(component->dev, "%s: mbhc initialization failed\n",
  1407. __func__);
  1408. } else {
  1409. wcd938x_mbhc_hs_detect(component, mbhc->mbhc_cfg);
  1410. }
  1411. break;
  1412. case BOLERO_WCD_EVT_CLK_NOTIFY:
  1413. snd_soc_component_update_bits(component,
  1414. WCD938X_DIGITAL_TOP_CLK_CFG, 0x06,
  1415. ((val >> 0x10) << 0x01));
  1416. break;
  1417. default:
  1418. dev_dbg(component->dev, "%s: invalid event %d\n", __func__, event);
  1419. break;
  1420. }
  1421. return 0;
  1422. }
  1423. static int __wcd938x_codec_enable_micbias(struct snd_soc_dapm_widget *w,
  1424. int event)
  1425. {
  1426. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  1427. int micb_num;
  1428. dev_dbg(component->dev, "%s: wname: %s, event: %d\n",
  1429. __func__, w->name, event);
  1430. if (strnstr(w->name, "MIC BIAS1", sizeof("MIC BIAS1")))
  1431. micb_num = MIC_BIAS_1;
  1432. else if (strnstr(w->name, "MIC BIAS2", sizeof("MIC BIAS2")))
  1433. micb_num = MIC_BIAS_2;
  1434. else if (strnstr(w->name, "MIC BIAS3", sizeof("MIC BIAS3")))
  1435. micb_num = MIC_BIAS_3;
  1436. else if (strnstr(w->name, "MIC BIAS4", sizeof("MIC BIAS4")))
  1437. micb_num = MIC_BIAS_4;
  1438. else
  1439. return -EINVAL;
  1440. switch (event) {
  1441. case SND_SOC_DAPM_PRE_PMU:
  1442. wcd938x_micbias_control(component, micb_num,
  1443. MICB_ENABLE, true);
  1444. break;
  1445. case SND_SOC_DAPM_POST_PMU:
  1446. /* 1 msec delay as per HW requirement */
  1447. usleep_range(1000, 1100);
  1448. break;
  1449. case SND_SOC_DAPM_POST_PMD:
  1450. wcd938x_micbias_control(component, micb_num,
  1451. MICB_DISABLE, true);
  1452. break;
  1453. };
  1454. return 0;
  1455. }
  1456. static int wcd938x_codec_enable_micbias(struct snd_soc_dapm_widget *w,
  1457. struct snd_kcontrol *kcontrol,
  1458. int event)
  1459. {
  1460. return __wcd938x_codec_enable_micbias(w, event);
  1461. }
  1462. static inline int wcd938x_tx_path_get(const char *wname)
  1463. {
  1464. int ret = 0;
  1465. unsigned int path_num;
  1466. char *widget_name = NULL;
  1467. char *w_name = NULL;
  1468. char *path_num_char = NULL;
  1469. char *path_name = NULL;
  1470. widget_name = kstrndup(wname, 9, GFP_KERNEL);
  1471. if (!widget_name)
  1472. return -EINVAL;
  1473. w_name = widget_name;
  1474. path_name = strsep(&widget_name, " ");
  1475. if (!path_name) {
  1476. pr_err("%s: Invalid widget name = %s\n",
  1477. __func__, widget_name);
  1478. ret = -EINVAL;
  1479. goto err;
  1480. }
  1481. path_name = widget_name;
  1482. path_num_char = strpbrk(path_name, "0123");
  1483. if (!path_num_char) {
  1484. pr_err("%s: tx path index not found\n",
  1485. __func__);
  1486. ret = -EINVAL;
  1487. goto err;
  1488. }
  1489. ret = kstrtouint(path_num_char, 10, &path_num);
  1490. if (ret < 0)
  1491. pr_err("%s: Invalid tx path = %s\n",
  1492. __func__, w_name);
  1493. err:
  1494. kfree(w_name);
  1495. return ret;
  1496. }
  1497. static int wcd938x_tx_mode_get(struct snd_kcontrol *kcontrol,
  1498. struct snd_ctl_elem_value *ucontrol)
  1499. {
  1500. struct snd_soc_dapm_widget *widget =
  1501. snd_soc_dapm_kcontrol_widget(kcontrol);
  1502. struct snd_soc_component *component =
  1503. snd_soc_kcontrol_component(kcontrol);
  1504. struct wcd938x_priv *wcd938x = NULL;
  1505. int path = 0;
  1506. if (!component)
  1507. return -EINVAL;
  1508. wcd938x = snd_soc_component_get_drvdata(component);
  1509. if (!widget || !widget->name || !wcd938x)
  1510. return -EINVAL;
  1511. path = wcd938x_tx_path_get(widget->name);
  1512. if (path < 0 || path >= TX_ADC_MAX)
  1513. return -EINVAL;
  1514. ucontrol->value.integer.value[0] = wcd938x->tx_mode[path];
  1515. return 0;
  1516. }
  1517. static int wcd938x_tx_mode_put(struct snd_kcontrol *kcontrol,
  1518. struct snd_ctl_elem_value *ucontrol)
  1519. {
  1520. struct snd_soc_dapm_widget *widget =
  1521. snd_soc_dapm_kcontrol_widget(kcontrol);
  1522. struct snd_soc_component *component =
  1523. snd_soc_kcontrol_component(kcontrol);
  1524. struct wcd938x_priv *wcd938x = NULL;
  1525. u32 mode_val;
  1526. int path = 0;
  1527. if (!component)
  1528. return -EINVAL;
  1529. wcd938x = snd_soc_component_get_drvdata(component);
  1530. if (!widget || !widget->name || !wcd938x)
  1531. return -EINVAL;
  1532. path = wcd938x_tx_path_get(widget->name);
  1533. if (path < 0 || path >= TX_ADC_MAX)
  1534. return -EINVAL;
  1535. mode_val = ucontrol->value.enumerated.item[0];
  1536. dev_dbg(component->dev, "%s: mode: %d\n", __func__, mode_val);
  1537. wcd938x->tx_mode[path] = mode_val;
  1538. return 0;
  1539. }
  1540. static int wcd938x_rx_hph_mode_get(struct snd_kcontrol *kcontrol,
  1541. struct snd_ctl_elem_value *ucontrol)
  1542. {
  1543. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  1544. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  1545. ucontrol->value.integer.value[0] = wcd938x->hph_mode;
  1546. return 0;
  1547. }
  1548. static int wcd938x_rx_hph_mode_put(struct snd_kcontrol *kcontrol,
  1549. struct snd_ctl_elem_value *ucontrol)
  1550. {
  1551. struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
  1552. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  1553. u32 mode_val;
  1554. mode_val = ucontrol->value.enumerated.item[0];
  1555. dev_dbg(component->dev, "%s: mode: %d\n", __func__, mode_val);
  1556. if (mode_val == 0) {
  1557. dev_info(component->dev,
  1558. "%s:Invalid HPH Mode, default to class_AB\n",
  1559. __func__);
  1560. mode_val = 3; /* enum will be updated later */
  1561. }
  1562. wcd938x->hph_mode = mode_val;
  1563. return 0;
  1564. }
  1565. static int wcd938x_get_compander(struct snd_kcontrol *kcontrol,
  1566. struct snd_ctl_elem_value *ucontrol)
  1567. {
  1568. struct snd_soc_component *component =
  1569. snd_soc_kcontrol_component(kcontrol);
  1570. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  1571. bool hphr;
  1572. struct soc_multi_mixer_control *mc;
  1573. mc = (struct soc_multi_mixer_control *)(kcontrol->private_value);
  1574. hphr = mc->shift;
  1575. ucontrol->value.integer.value[0] = hphr ? wcd938x->comp2_enable :
  1576. wcd938x->comp1_enable;
  1577. return 0;
  1578. }
  1579. static int wcd938x_set_compander(struct snd_kcontrol *kcontrol,
  1580. struct snd_ctl_elem_value *ucontrol)
  1581. {
  1582. struct snd_soc_component *component =
  1583. snd_soc_kcontrol_component(kcontrol);
  1584. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  1585. int value = ucontrol->value.integer.value[0];
  1586. bool hphr;
  1587. struct soc_multi_mixer_control *mc;
  1588. mc = (struct soc_multi_mixer_control *)(kcontrol->private_value);
  1589. hphr = mc->shift;
  1590. if (hphr)
  1591. wcd938x->comp2_enable = value;
  1592. else
  1593. wcd938x->comp1_enable = value;
  1594. return 0;
  1595. }
  1596. static const char * const tx_mode_mux_text_wcd9380[] = {
  1597. "ADC_INVALID", "ADC_HIFI", "ADC_LO_HIF", "ADC_NORMAL", "ADC_LP",
  1598. };
  1599. static const struct soc_enum tx_mode_mux_enum_wcd9380 =
  1600. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(tx_mode_mux_text_wcd9380),
  1601. tx_mode_mux_text_wcd9380);
  1602. static const char * const tx_mode_mux_text[] = {
  1603. "ADC_INVALID", "ADC_HIFI", "ADC_LO_HIF", "ADC_NORMAL", "ADC_LP",
  1604. "ADC_ULP1", "ADC_ULP2",
  1605. };
  1606. static const struct soc_enum tx_mode_mux_enum =
  1607. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(tx_mode_mux_text),
  1608. tx_mode_mux_text);
  1609. static const char * const rx_hph_mode_mux_text[] = {
  1610. "CLS_H_INVALID", "CLS_H_HIFI", "CLS_H_LP", "CLS_AB", "CLS_H_LOHIFI",
  1611. "CLS_H_ULP", "CLS_AB_HIFI",
  1612. };
  1613. static const struct soc_enum rx_hph_mode_mux_enum =
  1614. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(rx_hph_mode_mux_text),
  1615. rx_hph_mode_mux_text);
  1616. static const struct snd_kcontrol_new wcd9380_snd_controls[] = {
  1617. SOC_ENUM_EXT("TX0 MODE", tx_mode_mux_enum_wcd9380,
  1618. wcd938x_tx_mode_get, wcd938x_tx_mode_put),
  1619. SOC_ENUM_EXT("TX1 MODE", tx_mode_mux_enum_wcd9380,
  1620. wcd938x_tx_mode_get, wcd938x_tx_mode_put),
  1621. SOC_ENUM_EXT("TX2 MODE", tx_mode_mux_enum_wcd9380,
  1622. wcd938x_tx_mode_get, wcd938x_tx_mode_put),
  1623. SOC_ENUM_EXT("TX3 MODE", tx_mode_mux_enum_wcd9380,
  1624. wcd938x_tx_mode_get, wcd938x_tx_mode_put),
  1625. };
  1626. static const struct snd_kcontrol_new wcd9385_snd_controls[] = {
  1627. SOC_ENUM_EXT("TX0 MODE", tx_mode_mux_enum,
  1628. wcd938x_tx_mode_get, wcd938x_tx_mode_put),
  1629. SOC_ENUM_EXT("TX1 MODE", tx_mode_mux_enum,
  1630. wcd938x_tx_mode_get, wcd938x_tx_mode_put),
  1631. SOC_ENUM_EXT("TX2 MODE", tx_mode_mux_enum,
  1632. wcd938x_tx_mode_get, wcd938x_tx_mode_put),
  1633. SOC_ENUM_EXT("TX3 MODE", tx_mode_mux_enum,
  1634. wcd938x_tx_mode_get, wcd938x_tx_mode_put),
  1635. };
  1636. static const struct snd_kcontrol_new wcd938x_snd_controls[] = {
  1637. SOC_ENUM_EXT("RX HPH Mode", rx_hph_mode_mux_enum,
  1638. wcd938x_rx_hph_mode_get, wcd938x_rx_hph_mode_put),
  1639. SOC_SINGLE_EXT("HPHL_COMP Switch", SND_SOC_NOPM, 0, 1, 0,
  1640. wcd938x_get_compander, wcd938x_set_compander),
  1641. SOC_SINGLE_EXT("HPHR_COMP Switch", SND_SOC_NOPM, 1, 1, 0,
  1642. wcd938x_get_compander, wcd938x_set_compander),
  1643. SOC_SINGLE_TLV("HPHL Volume", WCD938X_HPH_L_EN, 0, 20, 1, line_gain),
  1644. SOC_SINGLE_TLV("HPHR Volume", WCD938X_HPH_R_EN, 0, 20, 1, line_gain),
  1645. SOC_SINGLE_TLV("ADC1 Volume", WCD938X_ANA_TX_CH1, 0, 20, 0,
  1646. analog_gain),
  1647. SOC_SINGLE_TLV("ADC2 Volume", WCD938X_ANA_TX_CH2, 0, 20, 0,
  1648. analog_gain),
  1649. SOC_SINGLE_TLV("ADC3 Volume", WCD938X_ANA_TX_CH3, 0, 20, 0,
  1650. analog_gain),
  1651. SOC_SINGLE_TLV("ADC4 Volume", WCD938X_ANA_TX_CH4, 0, 20, 0,
  1652. analog_gain),
  1653. };
  1654. static const struct snd_kcontrol_new adc1_switch[] = {
  1655. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1656. };
  1657. static const struct snd_kcontrol_new adc2_switch[] = {
  1658. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1659. };
  1660. static const struct snd_kcontrol_new adc3_switch[] = {
  1661. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1662. };
  1663. static const struct snd_kcontrol_new adc4_switch[] = {
  1664. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1665. };
  1666. static const struct snd_kcontrol_new dmic1_switch[] = {
  1667. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1668. };
  1669. static const struct snd_kcontrol_new dmic2_switch[] = {
  1670. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1671. };
  1672. static const struct snd_kcontrol_new dmic3_switch[] = {
  1673. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1674. };
  1675. static const struct snd_kcontrol_new dmic4_switch[] = {
  1676. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1677. };
  1678. static const struct snd_kcontrol_new dmic5_switch[] = {
  1679. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1680. };
  1681. static const struct snd_kcontrol_new dmic6_switch[] = {
  1682. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1683. };
  1684. static const struct snd_kcontrol_new dmic7_switch[] = {
  1685. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1686. };
  1687. static const struct snd_kcontrol_new dmic8_switch[] = {
  1688. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1689. };
  1690. static const struct snd_kcontrol_new ear_rdac_switch[] = {
  1691. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1692. };
  1693. static const struct snd_kcontrol_new aux_rdac_switch[] = {
  1694. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1695. };
  1696. static const struct snd_kcontrol_new hphl_rdac_switch[] = {
  1697. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1698. };
  1699. static const struct snd_kcontrol_new hphr_rdac_switch[] = {
  1700. SOC_DAPM_SINGLE("Switch", SND_SOC_NOPM, 0, 1, 0)
  1701. };
  1702. static const char * const adc2_mux_text[] = {
  1703. "INP2", "INP3"
  1704. };
  1705. static const struct soc_enum adc2_enum =
  1706. SOC_ENUM_SINGLE(WCD938X_TX_NEW_AMIC_MUX_CFG, 7,
  1707. ARRAY_SIZE(adc2_mux_text), adc2_mux_text);
  1708. static const struct snd_kcontrol_new tx_adc2_mux =
  1709. SOC_DAPM_ENUM("ADC2 MUX Mux", adc2_enum);
  1710. static const char * const adc3_mux_text[] = {
  1711. "INP4", "INP6"
  1712. };
  1713. static const struct soc_enum adc3_enum =
  1714. SOC_ENUM_SINGLE(WCD938X_TX_NEW_AMIC_MUX_CFG, 6,
  1715. ARRAY_SIZE(adc3_mux_text), adc3_mux_text);
  1716. static const struct snd_kcontrol_new tx_adc3_mux =
  1717. SOC_DAPM_ENUM("ADC3 MUX Mux", adc3_enum);
  1718. static const char * const adc4_mux_text[] = {
  1719. "INP5", "INP7"
  1720. };
  1721. static const struct soc_enum adc4_enum =
  1722. SOC_ENUM_SINGLE(WCD938X_TX_NEW_AMIC_MUX_CFG, 5,
  1723. ARRAY_SIZE(adc4_mux_text), adc4_mux_text);
  1724. static const struct snd_kcontrol_new tx_adc4_mux =
  1725. SOC_DAPM_ENUM("ADC4 MUX Mux", adc4_enum);
  1726. static const char * const rdac3_mux_text[] = {
  1727. "RX1", "RX3"
  1728. };
  1729. static const char * const hdr12_mux_text[] = {
  1730. "NO_HDR12", "HDR12"
  1731. };
  1732. static const struct soc_enum hdr12_enum =
  1733. SOC_ENUM_SINGLE(WCD938X_TX_NEW_AMIC_MUX_CFG, 4,
  1734. ARRAY_SIZE(hdr12_mux_text), hdr12_mux_text);
  1735. static const struct snd_kcontrol_new tx_hdr12_mux =
  1736. SOC_DAPM_ENUM("HDR12 MUX Mux", hdr12_enum);
  1737. static const char * const hdr34_mux_text[] = {
  1738. "NO_HDR34", "HDR34"
  1739. };
  1740. static const struct soc_enum hdr34_enum =
  1741. SOC_ENUM_SINGLE(WCD938X_TX_NEW_AMIC_MUX_CFG, 3,
  1742. ARRAY_SIZE(hdr34_mux_text), hdr34_mux_text);
  1743. static const struct snd_kcontrol_new tx_hdr34_mux =
  1744. SOC_DAPM_ENUM("HDR34 MUX Mux", hdr34_enum);
  1745. static const struct soc_enum rdac3_enum =
  1746. SOC_ENUM_SINGLE(WCD938X_DIGITAL_CDC_EAR_PATH_CTL, 0,
  1747. ARRAY_SIZE(rdac3_mux_text), rdac3_mux_text);
  1748. static const struct snd_kcontrol_new rx_rdac3_mux =
  1749. SOC_DAPM_ENUM("RDAC3_MUX Mux", rdac3_enum);
  1750. static const struct snd_soc_dapm_widget wcd938x_dapm_widgets[] = {
  1751. /*input widgets*/
  1752. SND_SOC_DAPM_INPUT("AMIC1"),
  1753. SND_SOC_DAPM_INPUT("AMIC2"),
  1754. SND_SOC_DAPM_INPUT("AMIC3"),
  1755. SND_SOC_DAPM_INPUT("AMIC4"),
  1756. SND_SOC_DAPM_INPUT("AMIC5"),
  1757. SND_SOC_DAPM_INPUT("AMIC6"),
  1758. SND_SOC_DAPM_INPUT("AMIC7"),
  1759. SND_SOC_DAPM_INPUT("IN1_HPHL"),
  1760. SND_SOC_DAPM_INPUT("IN2_HPHR"),
  1761. SND_SOC_DAPM_INPUT("IN3_AUX"),
  1762. /*tx widgets*/
  1763. SND_SOC_DAPM_ADC_E("ADC1", NULL, SND_SOC_NOPM, 0, 0,
  1764. wcd938x_codec_enable_adc,
  1765. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1766. SND_SOC_DAPM_ADC_E("ADC2", NULL, SND_SOC_NOPM, 1, 0,
  1767. wcd938x_codec_enable_adc,
  1768. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1769. SND_SOC_DAPM_ADC_E("ADC3", NULL, SND_SOC_NOPM, 2, 0,
  1770. wcd938x_codec_enable_adc,
  1771. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1772. SND_SOC_DAPM_ADC_E("ADC4", NULL, SND_SOC_NOPM, 3, 0,
  1773. wcd938x_codec_enable_adc,
  1774. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1775. SND_SOC_DAPM_ADC_E("DMIC1", NULL, SND_SOC_NOPM, 0, 0,
  1776. wcd938x_codec_enable_dmic,
  1777. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1778. SND_SOC_DAPM_ADC_E("DMIC2", NULL, SND_SOC_NOPM, 1, 0,
  1779. wcd938x_codec_enable_dmic,
  1780. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1781. SND_SOC_DAPM_ADC_E("DMIC3", NULL, SND_SOC_NOPM, 2, 0,
  1782. wcd938x_codec_enable_dmic,
  1783. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1784. SND_SOC_DAPM_ADC_E("DMIC4", NULL, SND_SOC_NOPM, 3, 0,
  1785. wcd938x_codec_enable_dmic,
  1786. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1787. SND_SOC_DAPM_ADC_E("DMIC5", NULL, SND_SOC_NOPM, 4, 0,
  1788. wcd938x_codec_enable_dmic,
  1789. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1790. SND_SOC_DAPM_ADC_E("DMIC6", NULL, SND_SOC_NOPM, 5, 0,
  1791. wcd938x_codec_enable_dmic,
  1792. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1793. SND_SOC_DAPM_ADC_E("DMIC7", NULL, SND_SOC_NOPM, 6, 0,
  1794. wcd938x_codec_enable_dmic,
  1795. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1796. SND_SOC_DAPM_ADC_E("DMIC8", NULL, SND_SOC_NOPM, 7, 0,
  1797. wcd938x_codec_enable_dmic,
  1798. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1799. SND_SOC_DAPM_MIXER_E("ADC1 REQ", SND_SOC_NOPM, 0, 0,
  1800. NULL, 0, wcd938x_enable_req,
  1801. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1802. SND_SOC_DAPM_MIXER_E("ADC2 REQ", SND_SOC_NOPM, 1, 0,
  1803. NULL, 0, wcd938x_enable_req,
  1804. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1805. SND_SOC_DAPM_MIXER_E("ADC3 REQ", SND_SOC_NOPM, 2, 0,
  1806. NULL, 0, wcd938x_enable_req,
  1807. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1808. SND_SOC_DAPM_MIXER_E("ADC4 REQ", SND_SOC_NOPM, 3, 0,
  1809. NULL, 0, wcd938x_enable_req,
  1810. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1811. SND_SOC_DAPM_MUX("ADC2 MUX", SND_SOC_NOPM, 0, 0,
  1812. &tx_adc2_mux),
  1813. SND_SOC_DAPM_MUX("ADC3 MUX", SND_SOC_NOPM, 0, 0,
  1814. &tx_adc3_mux),
  1815. SND_SOC_DAPM_MUX("ADC4 MUX", SND_SOC_NOPM, 0, 0,
  1816. &tx_adc4_mux),
  1817. SND_SOC_DAPM_MUX("HDR12 MUX", SND_SOC_NOPM, 0, 0,
  1818. &tx_hdr12_mux),
  1819. SND_SOC_DAPM_MUX("HDR34 MUX", SND_SOC_NOPM, 0, 0,
  1820. &tx_hdr34_mux),
  1821. /*tx mixers*/
  1822. SND_SOC_DAPM_MIXER_E("ADC1_MIXER", SND_SOC_NOPM, 0, 0,
  1823. adc1_switch, ARRAY_SIZE(adc1_switch),
  1824. wcd938x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  1825. SND_SOC_DAPM_POST_PMD),
  1826. SND_SOC_DAPM_MIXER_E("ADC2_MIXER", SND_SOC_NOPM, 0, 0,
  1827. adc2_switch, ARRAY_SIZE(adc2_switch),
  1828. wcd938x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  1829. SND_SOC_DAPM_POST_PMD),
  1830. SND_SOC_DAPM_MIXER_E("ADC3_MIXER", SND_SOC_NOPM, 0, 0, adc3_switch,
  1831. ARRAY_SIZE(adc3_switch), wcd938x_tx_swr_ctrl,
  1832. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1833. SND_SOC_DAPM_MIXER_E("ADC4_MIXER", SND_SOC_NOPM, 0, 0, adc4_switch,
  1834. ARRAY_SIZE(adc4_switch), wcd938x_tx_swr_ctrl,
  1835. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1836. SND_SOC_DAPM_MIXER_E("DMIC1_MIXER", SND_SOC_NOPM, 0,
  1837. 0, dmic1_switch, ARRAY_SIZE(dmic1_switch),
  1838. wcd938x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  1839. SND_SOC_DAPM_POST_PMD),
  1840. SND_SOC_DAPM_MIXER_E("DMIC2_MIXER", SND_SOC_NOPM, 0,
  1841. 0, dmic2_switch, ARRAY_SIZE(dmic2_switch),
  1842. wcd938x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  1843. SND_SOC_DAPM_POST_PMD),
  1844. SND_SOC_DAPM_MIXER_E("DMIC3_MIXER", SND_SOC_NOPM, 0,
  1845. 0, dmic3_switch, ARRAY_SIZE(dmic3_switch),
  1846. wcd938x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  1847. SND_SOC_DAPM_POST_PMD),
  1848. SND_SOC_DAPM_MIXER_E("DMIC4_MIXER", SND_SOC_NOPM, 0,
  1849. 0, dmic4_switch, ARRAY_SIZE(dmic4_switch),
  1850. wcd938x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  1851. SND_SOC_DAPM_POST_PMD),
  1852. SND_SOC_DAPM_MIXER_E("DMIC5_MIXER", SND_SOC_NOPM, 0,
  1853. 0, dmic5_switch, ARRAY_SIZE(dmic5_switch),
  1854. wcd938x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  1855. SND_SOC_DAPM_POST_PMD),
  1856. SND_SOC_DAPM_MIXER_E("DMIC6_MIXER", SND_SOC_NOPM, 0,
  1857. 0, dmic6_switch, ARRAY_SIZE(dmic6_switch),
  1858. wcd938x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  1859. SND_SOC_DAPM_POST_PMD),
  1860. SND_SOC_DAPM_MIXER_E("DMIC7_MIXER", SND_SOC_NOPM, 0,
  1861. 0, dmic7_switch, ARRAY_SIZE(dmic7_switch),
  1862. wcd938x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  1863. SND_SOC_DAPM_POST_PMD),
  1864. SND_SOC_DAPM_MIXER_E("DMIC8_MIXER", SND_SOC_NOPM, 0,
  1865. 0, dmic8_switch, ARRAY_SIZE(dmic8_switch),
  1866. wcd938x_tx_swr_ctrl, SND_SOC_DAPM_PRE_PMU |
  1867. SND_SOC_DAPM_POST_PMD),
  1868. /* micbias widgets*/
  1869. SND_SOC_DAPM_MICBIAS_E("MIC BIAS1", SND_SOC_NOPM, 0, 0,
  1870. wcd938x_codec_enable_micbias,
  1871. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1872. SND_SOC_DAPM_POST_PMD),
  1873. SND_SOC_DAPM_MICBIAS_E("MIC BIAS2", SND_SOC_NOPM, 0, 0,
  1874. wcd938x_codec_enable_micbias,
  1875. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1876. SND_SOC_DAPM_POST_PMD),
  1877. SND_SOC_DAPM_MICBIAS_E("MIC BIAS3", SND_SOC_NOPM, 0, 0,
  1878. wcd938x_codec_enable_micbias,
  1879. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1880. SND_SOC_DAPM_POST_PMD),
  1881. SND_SOC_DAPM_MICBIAS_E("MIC BIAS4", SND_SOC_NOPM, 0, 0,
  1882. wcd938x_codec_enable_micbias,
  1883. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1884. SND_SOC_DAPM_POST_PMD),
  1885. SND_SOC_DAPM_SUPPLY_S("CLS_H_PORT", 1, SND_SOC_NOPM, 0, 0,
  1886. wcd938x_enable_clsh,
  1887. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1888. /*rx widgets*/
  1889. SND_SOC_DAPM_PGA_E("EAR PGA", WCD938X_ANA_EAR, 7, 0, NULL, 0,
  1890. wcd938x_codec_enable_ear_pa,
  1891. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1892. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1893. SND_SOC_DAPM_PGA_E("AUX PGA", WCD938X_AUX_AUXPA, 7, 0, NULL, 0,
  1894. wcd938x_codec_enable_aux_pa,
  1895. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1896. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1897. SND_SOC_DAPM_PGA_E("HPHL PGA", WCD938X_ANA_HPH, 7, 0, NULL, 0,
  1898. wcd938x_codec_enable_hphl_pa,
  1899. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1900. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1901. SND_SOC_DAPM_PGA_E("HPHR PGA", WCD938X_ANA_HPH, 6, 0, NULL, 0,
  1902. wcd938x_codec_enable_hphr_pa,
  1903. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1904. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1905. SND_SOC_DAPM_DAC_E("RDAC1", NULL, SND_SOC_NOPM, 0, 0,
  1906. wcd938x_codec_hphl_dac_event,
  1907. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1908. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1909. SND_SOC_DAPM_DAC_E("RDAC2", NULL, SND_SOC_NOPM, 0, 0,
  1910. wcd938x_codec_hphr_dac_event,
  1911. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1912. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1913. SND_SOC_DAPM_DAC_E("RDAC3", NULL, SND_SOC_NOPM, 0, 0,
  1914. wcd938x_codec_ear_dac_event,
  1915. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1916. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1917. SND_SOC_DAPM_DAC_E("RDAC4", NULL, SND_SOC_NOPM, 0, 0,
  1918. wcd938x_codec_aux_dac_event,
  1919. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1920. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1921. SND_SOC_DAPM_MUX("RDAC3_MUX", SND_SOC_NOPM, 0, 0, &rx_rdac3_mux),
  1922. SND_SOC_DAPM_MIXER_E("RX1", SND_SOC_NOPM, 0, 0, NULL, 0,
  1923. wcd938x_enable_rx1, SND_SOC_DAPM_PRE_PMU |
  1924. SND_SOC_DAPM_POST_PMD),
  1925. SND_SOC_DAPM_MIXER_E("RX2", SND_SOC_NOPM, 0, 0, NULL, 0,
  1926. wcd938x_enable_rx2, SND_SOC_DAPM_PRE_PMU |
  1927. SND_SOC_DAPM_POST_PMD),
  1928. SND_SOC_DAPM_MIXER_E("RX3", SND_SOC_NOPM, 0, 0, NULL, 0,
  1929. wcd938x_enable_rx3, SND_SOC_DAPM_PRE_PMU |
  1930. SND_SOC_DAPM_POST_PMD),
  1931. /* rx mixer widgets*/
  1932. SND_SOC_DAPM_MIXER("EAR_RDAC", SND_SOC_NOPM, 0, 0,
  1933. ear_rdac_switch, ARRAY_SIZE(ear_rdac_switch)),
  1934. SND_SOC_DAPM_MIXER("AUX_RDAC", SND_SOC_NOPM, 0, 0,
  1935. aux_rdac_switch, ARRAY_SIZE(aux_rdac_switch)),
  1936. SND_SOC_DAPM_MIXER("HPHL_RDAC", SND_SOC_NOPM, 0, 0,
  1937. hphl_rdac_switch, ARRAY_SIZE(hphl_rdac_switch)),
  1938. SND_SOC_DAPM_MIXER("HPHR_RDAC", SND_SOC_NOPM, 0, 0,
  1939. hphr_rdac_switch, ARRAY_SIZE(hphr_rdac_switch)),
  1940. /*output widgets tx*/
  1941. SND_SOC_DAPM_OUTPUT("ADC1_OUTPUT"),
  1942. SND_SOC_DAPM_OUTPUT("ADC2_OUTPUT"),
  1943. SND_SOC_DAPM_OUTPUT("ADC3_OUTPUT"),
  1944. SND_SOC_DAPM_OUTPUT("ADC4_OUTPUT"),
  1945. SND_SOC_DAPM_OUTPUT("DMIC1_OUTPUT"),
  1946. SND_SOC_DAPM_OUTPUT("DMIC2_OUTPUT"),
  1947. SND_SOC_DAPM_OUTPUT("DMIC3_OUTPUT"),
  1948. SND_SOC_DAPM_OUTPUT("DMIC4_OUTPUT"),
  1949. SND_SOC_DAPM_OUTPUT("DMIC5_OUTPUT"),
  1950. SND_SOC_DAPM_OUTPUT("DMIC6_OUTPUT"),
  1951. SND_SOC_DAPM_OUTPUT("DMIC7_OUTPUT"),
  1952. SND_SOC_DAPM_OUTPUT("DMIC8_OUTPUT"),
  1953. /*output widgets rx*/
  1954. SND_SOC_DAPM_OUTPUT("EAR"),
  1955. SND_SOC_DAPM_OUTPUT("AUX"),
  1956. SND_SOC_DAPM_OUTPUT("HPHL"),
  1957. SND_SOC_DAPM_OUTPUT("HPHR"),
  1958. };
  1959. static const struct snd_soc_dapm_route wcd938x_audio_map[] = {
  1960. {"ADC1_OUTPUT", NULL, "ADC1_MIXER"},
  1961. {"ADC1_MIXER", "Switch", "ADC1 REQ"},
  1962. {"ADC1 REQ", NULL, "ADC1"},
  1963. {"ADC1", NULL, "AMIC1"},
  1964. {"ADC2_OUTPUT", NULL, "ADC2_MIXER"},
  1965. {"ADC2_MIXER", "Switch", "ADC2 REQ"},
  1966. {"ADC2 REQ", NULL, "ADC2"},
  1967. {"ADC2", NULL, "HDR12 MUX"},
  1968. {"HDR12 MUX", "NO_HDR12", "ADC2 MUX"},
  1969. {"HDR12 MUX", "HDR12", "AMIC1"},
  1970. {"ADC2 MUX", "INP3", "AMIC3"},
  1971. {"ADC2 MUX", "INP2", "AMIC2"},
  1972. {"ADC3_OUTPUT", NULL, "ADC3_MIXER"},
  1973. {"ADC3_MIXER", "Switch", "ADC3 REQ"},
  1974. {"ADC3 REQ", NULL, "ADC3"},
  1975. {"ADC3", NULL, "HDR34 MUX"},
  1976. {"HDR34 MUX", "NO_HDR34", "ADC3 MUX"},
  1977. {"HDR34 MUX", "HDR34", "AMIC5"},
  1978. {"ADC3 MUX", "INP4", "AMIC4"},
  1979. {"ADC3 MUX", "INP6", "AMIC6"},
  1980. {"ADC4_OUTPUT", NULL, "ADC4_MIXER"},
  1981. {"ADC4_MIXER", "Switch", "ADC4 REQ"},
  1982. {"ADC4 REQ", NULL, "ADC4"},
  1983. {"ADC4", NULL, "ADC4 MUX"},
  1984. {"ADC4 MUX", "INP5", "AMIC5"},
  1985. {"ADC4 MUX", "INP7", "AMIC7"},
  1986. {"DMIC1_OUTPUT", NULL, "DMIC1_MIXER"},
  1987. {"DMIC1_MIXER", "Switch", "DMIC1"},
  1988. {"DMIC2_OUTPUT", NULL, "DMIC2_MIXER"},
  1989. {"DMIC2_MIXER", "Switch", "DMIC2"},
  1990. {"DMIC3_OUTPUT", NULL, "DMIC3_MIXER"},
  1991. {"DMIC3_MIXER", "Switch", "DMIC3"},
  1992. {"DMIC4_OUTPUT", NULL, "DMIC4_MIXER"},
  1993. {"DMIC4_MIXER", "Switch", "DMIC4"},
  1994. {"DMIC5_OUTPUT", NULL, "DMIC5_MIXER"},
  1995. {"DMIC5_MIXER", "Switch", "DMIC5"},
  1996. {"DMIC6_OUTPUT", NULL, "DMIC6_MIXER"},
  1997. {"DMIC6_MIXER", "Switch", "DMIC6"},
  1998. {"DMIC7_OUTPUT", NULL, "DMIC7_MIXER"},
  1999. {"DMIC7_MIXER", "Switch", "DMIC7"},
  2000. {"DMIC8_OUTPUT", NULL, "DMIC8_MIXER"},
  2001. {"DMIC8_MIXER", "Switch", "DMIC8"},
  2002. {"IN1_HPHL", NULL, "CLS_H_PORT"},
  2003. {"RX1", NULL, "IN1_HPHL"},
  2004. {"RDAC1", NULL, "RX1"},
  2005. {"HPHL_RDAC", "Switch", "RDAC1"},
  2006. {"HPHL PGA", NULL, "HPHL_RDAC"},
  2007. {"HPHL", NULL, "HPHL PGA"},
  2008. {"IN2_HPHR", NULL, "CLS_H_PORT"},
  2009. {"RX2", NULL, "IN2_HPHR"},
  2010. {"RDAC2", NULL, "RX2"},
  2011. {"HPHR_RDAC", "Switch", "RDAC2"},
  2012. {"HPHR PGA", NULL, "HPHR_RDAC"},
  2013. {"HPHR", NULL, "HPHR PGA"},
  2014. {"IN3_AUX", NULL, "CLS_H_PORT"},
  2015. {"RX3", NULL, "IN3_AUX"},
  2016. {"RDAC4", NULL, "RX3"},
  2017. {"AUX_RDAC", "Switch", "RDAC4"},
  2018. {"AUX PGA", NULL, "AUX_RDAC"},
  2019. {"AUX", NULL, "AUX PGA"},
  2020. {"RDAC3_MUX", "RX3", "RX3"},
  2021. {"RDAC3_MUX", "RX1", "RX1"},
  2022. {"RDAC3", NULL, "RDAC3_MUX"},
  2023. {"EAR_RDAC", "Switch", "RDAC3"},
  2024. {"EAR PGA", NULL, "EAR_RDAC"},
  2025. {"EAR", NULL, "EAR PGA"},
  2026. };
  2027. static ssize_t wcd938x_version_read(struct snd_info_entry *entry,
  2028. void *file_private_data,
  2029. struct file *file,
  2030. char __user *buf, size_t count,
  2031. loff_t pos)
  2032. {
  2033. struct wcd938x_priv *priv;
  2034. char buffer[WCD938X_VERSION_ENTRY_SIZE];
  2035. int len = 0;
  2036. priv = (struct wcd938x_priv *) entry->private_data;
  2037. if (!priv) {
  2038. pr_err("%s: wcd938x priv is null\n", __func__);
  2039. return -EINVAL;
  2040. }
  2041. switch (priv->version) {
  2042. case WCD938X_VERSION_1_0:
  2043. len = snprintf(buffer, sizeof(buffer), "WCD938X_1_0\n");
  2044. break;
  2045. default:
  2046. len = snprintf(buffer, sizeof(buffer), "VER_UNDEFINED\n");
  2047. }
  2048. return simple_read_from_buffer(buf, count, &pos, buffer, len);
  2049. }
  2050. static struct snd_info_entry_ops wcd938x_info_ops = {
  2051. .read = wcd938x_version_read,
  2052. };
  2053. /*
  2054. * wcd938x_info_create_codec_entry - creates wcd938x module
  2055. * @codec_root: The parent directory
  2056. * @component: component instance
  2057. *
  2058. * Creates wcd938x module and version entry under the given
  2059. * parent directory.
  2060. *
  2061. * Return: 0 on success or negative error code on failure.
  2062. */
  2063. int wcd938x_info_create_codec_entry(struct snd_info_entry *codec_root,
  2064. struct snd_soc_component *component)
  2065. {
  2066. struct snd_info_entry *version_entry;
  2067. struct wcd938x_priv *priv;
  2068. struct snd_soc_card *card;
  2069. if (!codec_root || !component)
  2070. return -EINVAL;
  2071. priv = snd_soc_component_get_drvdata(component);
  2072. if (priv->entry) {
  2073. dev_dbg(priv->dev,
  2074. "%s:wcd938x module already created\n", __func__);
  2075. return 0;
  2076. }
  2077. card = component->card;
  2078. priv->entry = snd_info_create_subdir(codec_root->module,
  2079. "wcd938x", codec_root);
  2080. if (!priv->entry) {
  2081. dev_dbg(component->dev, "%s: failed to create wcd938x entry\n",
  2082. __func__);
  2083. return -ENOMEM;
  2084. }
  2085. version_entry = snd_info_create_card_entry(card->snd_card,
  2086. "version",
  2087. priv->entry);
  2088. if (!version_entry) {
  2089. dev_dbg(component->dev, "%s: failed to create wcd938x version entry\n",
  2090. __func__);
  2091. return -ENOMEM;
  2092. }
  2093. version_entry->private_data = priv;
  2094. version_entry->size = WCD938X_VERSION_ENTRY_SIZE;
  2095. version_entry->content = SNDRV_INFO_CONTENT_DATA;
  2096. version_entry->c.ops = &wcd938x_info_ops;
  2097. if (snd_info_register(version_entry) < 0) {
  2098. snd_info_free_entry(version_entry);
  2099. return -ENOMEM;
  2100. }
  2101. priv->version_entry = version_entry;
  2102. return 0;
  2103. }
  2104. EXPORT_SYMBOL(wcd938x_info_create_codec_entry);
  2105. static int wcd938x_soc_codec_probe(struct snd_soc_component *component)
  2106. {
  2107. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  2108. struct snd_soc_dapm_context *dapm =
  2109. snd_soc_component_get_dapm(component);
  2110. int variant;
  2111. int ret = -EINVAL;
  2112. dev_info(component->dev, "%s()\n", __func__);
  2113. wcd938x = snd_soc_component_get_drvdata(component);
  2114. if (!wcd938x)
  2115. return -EINVAL;
  2116. wcd938x->component = component;
  2117. snd_soc_component_init_regmap(component, wcd938x->regmap);
  2118. variant = (snd_soc_component_read32(component,
  2119. WCD938X_DIGITAL_EFUSE_REG_0) & 0x1E) >> 1;
  2120. wcd938x->variant = variant;
  2121. wcd938x->fw_data = devm_kzalloc(component->dev,
  2122. sizeof(*(wcd938x->fw_data)),
  2123. GFP_KERNEL);
  2124. if (!wcd938x->fw_data) {
  2125. dev_err(component->dev, "Failed to allocate fw_data\n");
  2126. ret = -ENOMEM;
  2127. goto err;
  2128. }
  2129. set_bit(WCD9XXX_MBHC_CAL, wcd938x->fw_data->cal_bit);
  2130. ret = wcd_cal_create_hwdep(wcd938x->fw_data,
  2131. WCD9XXX_CODEC_HWDEP_NODE, component);
  2132. if (ret < 0) {
  2133. dev_err(component->dev, "%s hwdep failed %d\n", __func__, ret);
  2134. goto err_hwdep;
  2135. }
  2136. ret = wcd938x_mbhc_init(&wcd938x->mbhc, component, wcd938x->fw_data);
  2137. if (ret) {
  2138. pr_err("%s: mbhc initialization failed\n", __func__);
  2139. goto err_hwdep;
  2140. }
  2141. snd_soc_dapm_ignore_suspend(dapm, "AMIC1");
  2142. snd_soc_dapm_ignore_suspend(dapm, "AMIC2");
  2143. snd_soc_dapm_ignore_suspend(dapm, "AMIC3");
  2144. snd_soc_dapm_ignore_suspend(dapm, "AMIC4");
  2145. snd_soc_dapm_ignore_suspend(dapm, "AMIC5");
  2146. snd_soc_dapm_ignore_suspend(dapm, "AMIC6");
  2147. snd_soc_dapm_ignore_suspend(dapm, "AMIC7");
  2148. snd_soc_dapm_ignore_suspend(dapm, "DMIC1_OUTPUT");
  2149. snd_soc_dapm_ignore_suspend(dapm, "DMIC2_OUTPUT");
  2150. snd_soc_dapm_ignore_suspend(dapm, "DMIC3_OUTPUT");
  2151. snd_soc_dapm_ignore_suspend(dapm, "DMIC4_OUTPUT");
  2152. snd_soc_dapm_ignore_suspend(dapm, "DMIC5_OUTPUT");
  2153. snd_soc_dapm_ignore_suspend(dapm, "DMIC6_OUTPUT");
  2154. snd_soc_dapm_ignore_suspend(dapm, "DMIC7_OUTPUT");
  2155. snd_soc_dapm_ignore_suspend(dapm, "DMIC8_OUTPUT");
  2156. snd_soc_dapm_ignore_suspend(dapm, "ADC1_OUTPUT");
  2157. snd_soc_dapm_ignore_suspend(dapm, "ADC2_OUTPUT");
  2158. snd_soc_dapm_ignore_suspend(dapm, "ADC3_OUTPUT");
  2159. snd_soc_dapm_ignore_suspend(dapm, "ADC4_OUTPUT");
  2160. snd_soc_dapm_ignore_suspend(dapm, "IN1_HPHL");
  2161. snd_soc_dapm_ignore_suspend(dapm, "IN2_HPHR");
  2162. snd_soc_dapm_ignore_suspend(dapm, "IN3_AUX");
  2163. snd_soc_dapm_ignore_suspend(dapm, "EAR");
  2164. snd_soc_dapm_ignore_suspend(dapm, "AUX");
  2165. snd_soc_dapm_ignore_suspend(dapm, "HPHL");
  2166. snd_soc_dapm_ignore_suspend(dapm, "HPHR");
  2167. snd_soc_dapm_sync(dapm);
  2168. wcd_cls_h_init(&wcd938x->clsh_info);
  2169. wcd938x_init_reg(component);
  2170. if (wcd938x->variant == WCD9380) {
  2171. ret = snd_soc_add_component_controls(component, wcd9380_snd_controls,
  2172. ARRAY_SIZE(wcd9380_snd_controls));
  2173. if (ret < 0) {
  2174. dev_err(component->dev,
  2175. "%s: Failed to add snd ctrls for variant: %d\n",
  2176. __func__, wcd938x->variant);
  2177. goto err_hwdep;
  2178. }
  2179. }
  2180. if (wcd938x->variant == WCD9385) {
  2181. ret = snd_soc_add_component_controls(component, wcd9385_snd_controls,
  2182. ARRAY_SIZE(wcd9385_snd_controls));
  2183. if (ret < 0) {
  2184. dev_err(component->dev,
  2185. "%s: Failed to add snd ctrls for variant: %d\n",
  2186. __func__, wcd938x->variant);
  2187. goto err_hwdep;
  2188. }
  2189. }
  2190. wcd938x->version = WCD938X_VERSION_1_0;
  2191. /* Register event notifier */
  2192. wcd938x->nblock.notifier_call = wcd938x_event_notify;
  2193. if (wcd938x->register_notifier) {
  2194. ret = wcd938x->register_notifier(wcd938x->handle,
  2195. &wcd938x->nblock,
  2196. true);
  2197. if (ret) {
  2198. dev_err(component->dev,
  2199. "%s: Failed to register notifier %d\n",
  2200. __func__, ret);
  2201. return ret;
  2202. }
  2203. }
  2204. return ret;
  2205. err_hwdep:
  2206. wcd938x->fw_data = NULL;
  2207. err:
  2208. return ret;
  2209. }
  2210. static void wcd938x_soc_codec_remove(struct snd_soc_component *component)
  2211. {
  2212. struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
  2213. if (!wcd938x) {
  2214. dev_err(component->dev, "%s: wcd938x is already NULL\n",
  2215. __func__);
  2216. return;
  2217. }
  2218. if (wcd938x->register_notifier)
  2219. wcd938x->register_notifier(wcd938x->handle,
  2220. &wcd938x->nblock,
  2221. false);
  2222. }
  2223. static struct snd_soc_component_driver soc_codec_dev_wcd938x = {
  2224. .name = WCD938X_DRV_NAME,
  2225. .probe = wcd938x_soc_codec_probe,
  2226. .remove = wcd938x_soc_codec_remove,
  2227. .controls = wcd938x_snd_controls,
  2228. .num_controls = ARRAY_SIZE(wcd938x_snd_controls),
  2229. .dapm_widgets = wcd938x_dapm_widgets,
  2230. .num_dapm_widgets = ARRAY_SIZE(wcd938x_dapm_widgets),
  2231. .dapm_routes = wcd938x_audio_map,
  2232. .num_dapm_routes = ARRAY_SIZE(wcd938x_audio_map),
  2233. };
  2234. static int wcd938x_reset(struct device *dev)
  2235. {
  2236. struct wcd938x_priv *wcd938x = NULL;
  2237. int rc = 0;
  2238. int value = 0;
  2239. if (!dev)
  2240. return -ENODEV;
  2241. wcd938x = dev_get_drvdata(dev);
  2242. if (!wcd938x)
  2243. return -EINVAL;
  2244. if (!wcd938x->rst_np) {
  2245. dev_err(dev, "%s: reset gpio device node not specified\n",
  2246. __func__);
  2247. return -EINVAL;
  2248. }
  2249. value = msm_cdc_pinctrl_get_state(wcd938x->rst_np);
  2250. if (value > 0)
  2251. return 0;
  2252. rc = msm_cdc_pinctrl_select_sleep_state(wcd938x->rst_np);
  2253. if (rc) {
  2254. dev_err(dev, "%s: wcd sleep state request fail!\n",
  2255. __func__);
  2256. return rc;
  2257. }
  2258. /* 20us sleep required after pulling the reset gpio to LOW */
  2259. usleep_range(20, 30);
  2260. rc = msm_cdc_pinctrl_select_active_state(wcd938x->rst_np);
  2261. if (rc) {
  2262. dev_err(dev, "%s: wcd active state request fail!\n",
  2263. __func__);
  2264. return rc;
  2265. }
  2266. /* 20us sleep required after pulling the reset gpio to HIGH */
  2267. usleep_range(20, 30);
  2268. return rc;
  2269. }
  2270. static int wcd938x_read_of_property_u32(struct device *dev, const char *name,
  2271. u32 *val)
  2272. {
  2273. int rc = 0;
  2274. rc = of_property_read_u32(dev->of_node, name, val);
  2275. if (rc)
  2276. dev_err(dev, "%s: Looking up %s property in node %s failed\n",
  2277. __func__, name, dev->of_node->full_name);
  2278. return rc;
  2279. }
  2280. static void wcd938x_dt_parse_micbias_info(struct device *dev,
  2281. struct wcd938x_micbias_setting *mb)
  2282. {
  2283. u32 prop_val = 0;
  2284. int rc = 0;
  2285. /* MB1 */
  2286. if (of_find_property(dev->of_node, "qcom,cdc-micbias1-mv",
  2287. NULL)) {
  2288. rc = wcd938x_read_of_property_u32(dev,
  2289. "qcom,cdc-micbias1-mv",
  2290. &prop_val);
  2291. if (!rc)
  2292. mb->micb1_mv = prop_val;
  2293. } else {
  2294. dev_info(dev, "%s: Micbias1 DT property not found\n",
  2295. __func__);
  2296. }
  2297. /* MB2 */
  2298. if (of_find_property(dev->of_node, "qcom,cdc-micbias2-mv",
  2299. NULL)) {
  2300. rc = wcd938x_read_of_property_u32(dev,
  2301. "qcom,cdc-micbias2-mv",
  2302. &prop_val);
  2303. if (!rc)
  2304. mb->micb2_mv = prop_val;
  2305. } else {
  2306. dev_info(dev, "%s: Micbias2 DT property not found\n",
  2307. __func__);
  2308. }
  2309. /* MB3 */
  2310. if (of_find_property(dev->of_node, "qcom,cdc-micbias3-mv",
  2311. NULL)) {
  2312. rc = wcd938x_read_of_property_u32(dev,
  2313. "qcom,cdc-micbias3-mv",
  2314. &prop_val);
  2315. if (!rc)
  2316. mb->micb3_mv = prop_val;
  2317. } else {
  2318. dev_info(dev, "%s: Micbias3 DT property not found\n",
  2319. __func__);
  2320. }
  2321. }
  2322. static int wcd938x_reset_low(struct device *dev)
  2323. {
  2324. struct wcd938x_priv *wcd938x = NULL;
  2325. int rc = 0;
  2326. if (!dev)
  2327. return -ENODEV;
  2328. wcd938x = dev_get_drvdata(dev);
  2329. if (!wcd938x)
  2330. return -EINVAL;
  2331. if (!wcd938x->rst_np) {
  2332. dev_err(dev, "%s: reset gpio device node not specified\n",
  2333. __func__);
  2334. return -EINVAL;
  2335. }
  2336. rc = msm_cdc_pinctrl_select_sleep_state(wcd938x->rst_np);
  2337. if (rc) {
  2338. dev_err(dev, "%s: wcd sleep state request fail!\n",
  2339. __func__);
  2340. return rc;
  2341. }
  2342. /* 20us sleep required after pulling the reset gpio to LOW */
  2343. usleep_range(20, 30);
  2344. return rc;
  2345. }
  2346. struct wcd938x_pdata *wcd938x_populate_dt_data(struct device *dev)
  2347. {
  2348. struct wcd938x_pdata *pdata = NULL;
  2349. pdata = devm_kzalloc(dev, sizeof(struct wcd938x_pdata),
  2350. GFP_KERNEL);
  2351. if (!pdata)
  2352. return NULL;
  2353. pdata->rst_np = of_parse_phandle(dev->of_node,
  2354. "qcom,wcd-rst-gpio-node", 0);
  2355. if (!pdata->rst_np) {
  2356. dev_err(dev, "%s: Looking up %s property in node %s failed\n",
  2357. __func__, "qcom,wcd-rst-gpio-node",
  2358. dev->of_node->full_name);
  2359. return NULL;
  2360. }
  2361. /* Parse power supplies */
  2362. msm_cdc_get_power_supplies(dev, &pdata->regulator,
  2363. &pdata->num_supplies);
  2364. if (!pdata->regulator || (pdata->num_supplies <= 0)) {
  2365. dev_err(dev, "%s: no power supplies defined for codec\n",
  2366. __func__);
  2367. return NULL;
  2368. }
  2369. pdata->rx_slave = of_parse_phandle(dev->of_node, "qcom,rx-slave", 0);
  2370. pdata->tx_slave = of_parse_phandle(dev->of_node, "qcom,tx-slave", 0);
  2371. wcd938x_dt_parse_micbias_info(dev, &pdata->micbias);
  2372. return pdata;
  2373. }
  2374. static int wcd938x_bind(struct device *dev)
  2375. {
  2376. int ret = 0, i = 0;
  2377. struct wcd938x_pdata *pdata = dev_get_platdata(dev);
  2378. struct wcd938x_priv *wcd938x = dev_get_drvdata(dev);
  2379. /*
  2380. * Add 5msec delay to provide sufficient time for
  2381. * soundwire auto enumeration of slave devices as
  2382. * as per HW requirement.
  2383. */
  2384. usleep_range(5000, 5010);
  2385. ret = component_bind_all(dev, wcd938x);
  2386. if (ret) {
  2387. dev_err(dev, "%s: Slave bind failed, ret = %d\n",
  2388. __func__, ret);
  2389. return ret;
  2390. }
  2391. wcd938x->rx_swr_dev = get_matching_swr_slave_device(pdata->rx_slave);
  2392. if (!wcd938x->rx_swr_dev) {
  2393. dev_err(dev, "%s: Could not find RX swr slave device\n",
  2394. __func__);
  2395. ret = -ENODEV;
  2396. goto err;
  2397. }
  2398. wcd938x->tx_swr_dev = get_matching_swr_slave_device(pdata->tx_slave);
  2399. if (!wcd938x->tx_swr_dev) {
  2400. dev_err(dev, "%s: Could not find TX swr slave device\n",
  2401. __func__);
  2402. ret = -ENODEV;
  2403. goto err;
  2404. }
  2405. wcd938x->regmap = devm_regmap_init_swr(wcd938x->tx_swr_dev,
  2406. &wcd938x_regmap_config);
  2407. if (!wcd938x->regmap) {
  2408. dev_err(dev, "%s: Regmap init failed\n",
  2409. __func__);
  2410. goto err;
  2411. }
  2412. /* Set all interupts as edge triggered */
  2413. for (i = 0; i < wcd938x_regmap_irq_chip.num_regs; i++)
  2414. regmap_write(wcd938x->regmap,
  2415. (WCD938X_DIGITAL_INTR_LEVEL_0 + i), 0);
  2416. wcd938x_regmap_irq_chip.irq_drv_data = wcd938x;
  2417. wcd938x->irq_info.wcd_regmap_irq_chip = &wcd938x_regmap_irq_chip;
  2418. wcd938x->irq_info.codec_name = "WCD938X";
  2419. wcd938x->irq_info.regmap = wcd938x->regmap;
  2420. wcd938x->irq_info.dev = dev;
  2421. ret = wcd_irq_init(&wcd938x->irq_info, &wcd938x->virq);
  2422. if (ret) {
  2423. dev_err(wcd938x->dev, "%s: IRQ init failed: %d\n",
  2424. __func__, ret);
  2425. goto err;
  2426. }
  2427. wcd938x->tx_swr_dev->slave_irq = wcd938x->virq;
  2428. ret = snd_soc_register_component(dev, &soc_codec_dev_wcd938x,
  2429. NULL, 0);
  2430. if (ret) {
  2431. dev_err(dev, "%s: Codec registration failed\n",
  2432. __func__);
  2433. goto err_irq;
  2434. }
  2435. return ret;
  2436. err_irq:
  2437. wcd_irq_exit(&wcd938x->irq_info, wcd938x->virq);
  2438. err:
  2439. component_unbind_all(dev, wcd938x);
  2440. return ret;
  2441. }
  2442. static void wcd938x_unbind(struct device *dev)
  2443. {
  2444. struct wcd938x_priv *wcd938x = dev_get_drvdata(dev);
  2445. wcd_irq_exit(&wcd938x->irq_info, wcd938x->virq);
  2446. snd_soc_unregister_component(dev);
  2447. component_unbind_all(dev, wcd938x);
  2448. }
  2449. static const struct of_device_id wcd938x_dt_match[] = {
  2450. { .compatible = "qcom,wcd938x-codec" },
  2451. {}
  2452. };
  2453. static const struct component_master_ops wcd938x_comp_ops = {
  2454. .bind = wcd938x_bind,
  2455. .unbind = wcd938x_unbind,
  2456. };
  2457. static int wcd938x_compare_of(struct device *dev, void *data)
  2458. {
  2459. return dev->of_node == data;
  2460. }
  2461. static void wcd938x_release_of(struct device *dev, void *data)
  2462. {
  2463. of_node_put(data);
  2464. }
  2465. static int wcd938x_add_slave_components(struct device *dev,
  2466. struct component_match **matchptr)
  2467. {
  2468. struct device_node *np, *rx_node, *tx_node;
  2469. np = dev->of_node;
  2470. rx_node = of_parse_phandle(np, "qcom,rx-slave", 0);
  2471. if (!rx_node) {
  2472. dev_err(dev, "%s: Rx-slave node not defined\n", __func__);
  2473. return -ENODEV;
  2474. }
  2475. of_node_get(rx_node);
  2476. component_match_add_release(dev, matchptr,
  2477. wcd938x_release_of,
  2478. wcd938x_compare_of,
  2479. rx_node);
  2480. tx_node = of_parse_phandle(np, "qcom,tx-slave", 0);
  2481. if (!tx_node) {
  2482. dev_err(dev, "%s: Tx-slave node not defined\n", __func__);
  2483. return -ENODEV;
  2484. }
  2485. of_node_get(tx_node);
  2486. component_match_add_release(dev, matchptr,
  2487. wcd938x_release_of,
  2488. wcd938x_compare_of,
  2489. tx_node);
  2490. return 0;
  2491. }
  2492. static int wcd938x_wakeup(void *handle, bool enable)
  2493. {
  2494. struct wcd938x_priv *priv;
  2495. if (!handle) {
  2496. pr_err("%s: NULL handle\n", __func__);
  2497. return -EINVAL;
  2498. }
  2499. priv = (struct wcd938x_priv *)handle;
  2500. if (!priv->tx_swr_dev) {
  2501. pr_err("%s: tx swr dev is NULL\n", __func__);
  2502. return -EINVAL;
  2503. }
  2504. if (enable)
  2505. return swr_device_wakeup_vote(priv->tx_swr_dev);
  2506. else
  2507. return swr_device_wakeup_unvote(priv->tx_swr_dev);
  2508. }
  2509. static int wcd938x_probe(struct platform_device *pdev)
  2510. {
  2511. struct component_match *match = NULL;
  2512. struct wcd938x_priv *wcd938x = NULL;
  2513. struct wcd938x_pdata *pdata = NULL;
  2514. struct wcd_ctrl_platform_data *plat_data = NULL;
  2515. struct device *dev = &pdev->dev;
  2516. int ret;
  2517. wcd938x = devm_kzalloc(dev, sizeof(struct wcd938x_priv),
  2518. GFP_KERNEL);
  2519. if (!wcd938x)
  2520. return -ENOMEM;
  2521. dev_set_drvdata(dev, wcd938x);
  2522. wcd938x->dev = dev;
  2523. pdata = wcd938x_populate_dt_data(dev);
  2524. if (!pdata) {
  2525. dev_err(dev, "%s: Fail to obtain platform data\n", __func__);
  2526. return -EINVAL;
  2527. }
  2528. dev->platform_data = pdata;
  2529. wcd938x->rst_np = pdata->rst_np;
  2530. ret = msm_cdc_init_supplies(dev, &wcd938x->supplies,
  2531. pdata->regulator, pdata->num_supplies);
  2532. if (!wcd938x->supplies) {
  2533. dev_err(dev, "%s: Cannot init wcd supplies\n",
  2534. __func__);
  2535. return ret;
  2536. }
  2537. plat_data = dev_get_platdata(dev->parent);
  2538. if (!plat_data) {
  2539. dev_err(dev, "%s: platform data from parent is NULL\n",
  2540. __func__);
  2541. return -EINVAL;
  2542. }
  2543. wcd938x->handle = (void *)plat_data->handle;
  2544. if (!wcd938x->handle) {
  2545. dev_err(dev, "%s: handle is NULL\n", __func__);
  2546. return -EINVAL;
  2547. }
  2548. wcd938x->update_wcd_event = plat_data->update_wcd_event;
  2549. if (!wcd938x->update_wcd_event) {
  2550. dev_err(dev, "%s: update_wcd_event api is null!\n",
  2551. __func__);
  2552. return -EINVAL;
  2553. }
  2554. wcd938x->register_notifier = plat_data->register_notifier;
  2555. if (!wcd938x->register_notifier) {
  2556. dev_err(dev, "%s: register_notifier api is null!\n",
  2557. __func__);
  2558. return -EINVAL;
  2559. }
  2560. ret = msm_cdc_enable_static_supplies(&pdev->dev, wcd938x->supplies,
  2561. pdata->regulator,
  2562. pdata->num_supplies);
  2563. if (ret) {
  2564. dev_err(dev, "%s: wcd static supply enable failed!\n",
  2565. __func__);
  2566. return ret;
  2567. }
  2568. ret = wcd938x_parse_port_mapping(dev, "qcom,rx_swr_ch_map",
  2569. CODEC_RX);
  2570. ret |= wcd938x_parse_port_mapping(dev, "qcom,tx_swr_ch_map",
  2571. CODEC_TX);
  2572. if (ret) {
  2573. dev_err(dev, "Failed to read port mapping\n");
  2574. goto err;
  2575. }
  2576. ret = wcd938x_add_slave_components(dev, &match);
  2577. if (ret)
  2578. goto err;
  2579. wcd938x_reset(dev);
  2580. wcd938x->wakeup = wcd938x_wakeup;
  2581. return component_master_add_with_match(dev,
  2582. &wcd938x_comp_ops, match);
  2583. err:
  2584. return ret;
  2585. }
  2586. static int wcd938x_remove(struct platform_device *pdev)
  2587. {
  2588. component_master_del(&pdev->dev, &wcd938x_comp_ops);
  2589. dev_set_drvdata(&pdev->dev, NULL);
  2590. return 0;
  2591. }
  2592. #ifdef CONFIG_PM_SLEEP
  2593. static int wcd938x_suspend(struct device *dev)
  2594. {
  2595. return 0;
  2596. }
  2597. static int wcd938x_resume(struct device *dev)
  2598. {
  2599. return 0;
  2600. }
  2601. static const struct dev_pm_ops wcd938x_dev_pm_ops = {
  2602. SET_SYSTEM_SLEEP_PM_OPS(
  2603. wcd938x_suspend,
  2604. wcd938x_resume
  2605. )
  2606. };
  2607. #endif
  2608. static struct platform_driver wcd938x_codec_driver = {
  2609. .probe = wcd938x_probe,
  2610. .remove = wcd938x_remove,
  2611. .driver = {
  2612. .name = "wcd938x_codec",
  2613. .owner = THIS_MODULE,
  2614. .of_match_table = of_match_ptr(wcd938x_dt_match),
  2615. #ifdef CONFIG_PM_SLEEP
  2616. .pm = &wcd938x_dev_pm_ops,
  2617. #endif
  2618. .suppress_bind_attrs = true,
  2619. },
  2620. };
  2621. module_platform_driver(wcd938x_codec_driver);
  2622. MODULE_DESCRIPTION("WCD938X Codec driver");
  2623. MODULE_LICENSE("GPL v2");