msm8x10-wcd.c 110 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908
  1. /* Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/init.h>
  14. #include <linux/firmware.h>
  15. #include <linux/slab.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/device.h>
  18. #include <linux/printk.h>
  19. #include <linux/ratelimit.h>
  20. #include <linux/debugfs.h>
  21. #include <linux/io.h>
  22. #include <linux/bitops.h>
  23. #include <linux/delay.h>
  24. #include <linux/pm_runtime.h>
  25. #include <linux/kernel.h>
  26. #include <linux/gpio.h>
  27. #include <linux/i2c.h>
  28. #include <linux/of_gpio.h>
  29. #include <linux/regulator/consumer.h>
  30. #include <linux/mfd/wcd9xxx/pdata.h>
  31. #include <sound/pcm.h>
  32. #include <sound/pcm_params.h>
  33. #include <sound/soc.h>
  34. #include <sound/soc-dapm.h>
  35. #include <sound/tlv.h>
  36. #include <mach/qdsp6v2/apr.h>
  37. #include <mach/subsystem_notif.h>
  38. #include <sound/q6core.h>
  39. #include "msm8x10-wcd.h"
  40. #include "wcd9xxx-resmgr.h"
  41. #include "msm8x10_wcd_registers.h"
  42. #include "wcd9xxx-common.h"
  43. #define MSM8X10_WCD_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
  44. SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000)
  45. #define MSM8X10_WCD_FORMATS (SNDRV_PCM_FMTBIT_S16_LE)
  46. #define NUM_DECIMATORS 2
  47. #define NUM_INTERPOLATORS 3
  48. #define BITS_PER_REG 8
  49. #define MSM8X10_WCD_TX_PORT_NUMBER 4
  50. #define DAPM_MICBIAS_EXTERNAL_STANDALONE "MIC BIAS External Standalone"
  51. #define MSM8X10_WCD_I2S_MASTER_MODE_MASK 0x08
  52. #define MSM8X10_DINO_CODEC_BASE_ADDR 0xFE043000
  53. #define MSM8X10_DINO_CODEC_REG_SIZE 0x200
  54. #define MSM8x10_TLMM_CDC_PULL_CTL 0xFD512050
  55. #define HELICON_CORE_0_I2C_ADDR 0x0d
  56. #define HELICON_CORE_1_I2C_ADDR 0x77
  57. #define HELICON_CORE_2_I2C_ADDR 0x66
  58. #define HELICON_CORE_3_I2C_ADDR 0x55
  59. #define MAX_MSM8X10_WCD_DEVICE 4
  60. #define CODEC_DT_MAX_PROP_SIZE 40
  61. #define MAX_ON_DEMAND_SUPPLY_NAME_LENGTH 64
  62. #define HELICON_MCLK_CLK_9P6MHZ 9600000
  63. /*
  64. * Multiplication factor to compute impedance on codec
  65. * This is computed from (Vx / (m*Ical)) = (10mV/(180*30uA))
  66. */
  67. #define MSM8X10_WCD_ZDET_MUL_FACTOR 1852
  68. /* RX_HPH_CNP_WG_TIME increases by 0.24ms */
  69. #define MSM8X10_WCD_WG_TIME_FACTOR_US 240
  70. enum {
  71. MSM8X10_WCD_I2C_TOP_LEVEL = 0,
  72. MSM8X10_WCD_I2C_ANALOG,
  73. MSM8X10_WCD_I2C_DIGITAL_1,
  74. MSM8X10_WCD_I2C_DIGITAL_2,
  75. };
  76. enum {
  77. AIF1_PB = 0,
  78. AIF1_CAP,
  79. NUM_CODEC_DAIS,
  80. };
  81. enum {
  82. RX_MIX1_INP_SEL_ZERO = 0,
  83. RX_MIX1_INP_SEL_IIR1,
  84. RX_MIX1_INP_SEL_IIR2,
  85. RX_MIX1_INP_SEL_RX1,
  86. RX_MIX1_INP_SEL_RX2,
  87. RX_MIX1_INP_SEL_RX3,
  88. };
  89. static const DECLARE_TLV_DB_SCALE(digital_gain, 0, 1, 0);
  90. static const DECLARE_TLV_DB_SCALE(line_gain, 0, 7, 1);
  91. static const DECLARE_TLV_DB_SCALE(analog_gain, 0, 25, 1);
  92. static struct snd_soc_dai_driver msm8x10_wcd_i2s_dai[];
  93. static const DECLARE_TLV_DB_SCALE(aux_pga_gain, 0, 2, 0);
  94. #define MSM8X10_WCD_ACQUIRE_LOCK(x) do { \
  95. mutex_lock_nested(&x, SINGLE_DEPTH_NESTING); \
  96. } while (0)
  97. #define MSM8X10_WCD_RELEASE_LOCK(x) do { mutex_unlock(&x); } while (0)
  98. /* Codec supports 2 IIR filters */
  99. enum {
  100. IIR1 = 0,
  101. IIR2,
  102. IIR_MAX,
  103. };
  104. /* Codec supports 5 bands */
  105. enum {
  106. BAND1 = 0,
  107. BAND2,
  108. BAND3,
  109. BAND4,
  110. BAND5,
  111. BAND_MAX,
  112. };
  113. enum msm8x10_wcd_bandgap_type {
  114. MSM8X10_WCD_BANDGAP_OFF = 0,
  115. MSM8X10_WCD_BANDGAP_AUDIO_MODE,
  116. MSM8X10_WCD_BANDGAP_MBHC_MODE,
  117. };
  118. enum {
  119. ON_DEMAND_MICBIAS = 0,
  120. ON_DEMAND_CP,
  121. ON_DEMAND_SUPPLIES_MAX,
  122. };
  123. /*
  124. * The delay list is per codec HW specification.
  125. * Please add delay in the list in the future instead
  126. * of magic number
  127. */
  128. enum {
  129. CODEC_DELAY_1_MS = 1000,
  130. CODEC_DELAY_1_1_MS = 1100,
  131. };
  132. struct hpf_work {
  133. struct msm8x10_wcd_priv *msm8x10_wcd;
  134. u32 decimator;
  135. u8 tx_hpf_cut_of_freq;
  136. struct delayed_work dwork;
  137. };
  138. static struct hpf_work tx_hpf_work[NUM_DECIMATORS];
  139. struct on_demand_supply {
  140. struct regulator *supply;
  141. atomic_t ref;
  142. };
  143. static char on_demand_supply_name[][MAX_ON_DEMAND_SUPPLY_NAME_LENGTH] = {
  144. "cdc-vdd-mic-bias",
  145. "cdc-vdda-cp",
  146. };
  147. static int on_demand_regulator_control(struct on_demand_supply *supply,
  148. bool enable,
  149. u8 shift);
  150. struct msm8x10_wcd_priv {
  151. struct snd_soc_codec *codec;
  152. u32 adc_count;
  153. u32 rx_bias_count;
  154. s32 dmic_1_2_clk_cnt;
  155. struct on_demand_supply on_demand_list[ON_DEMAND_SUPPLIES_MAX];
  156. /* resmgr module */
  157. struct wcd9xxx_resmgr resmgr;
  158. /* mbhc module */
  159. struct wcd9xxx_mbhc mbhc;
  160. struct wcd9xxx_mbhc_config *mbhc_cfg;
  161. /*
  162. * list used to save/restore registers at start and
  163. * end of impedance measurement
  164. */
  165. struct list_head reg_save_restore;
  166. u32 micb_en_count;
  167. };
  168. static unsigned short rx_digital_gain_reg[] = {
  169. MSM8X10_WCD_A_CDC_RX1_VOL_CTL_B2_CTL,
  170. MSM8X10_WCD_A_CDC_RX2_VOL_CTL_B2_CTL,
  171. MSM8X10_WCD_A_CDC_RX3_VOL_CTL_B2_CTL,
  172. };
  173. static unsigned short tx_digital_gain_reg[] = {
  174. MSM8X10_WCD_A_CDC_TX1_VOL_CTL_GAIN,
  175. MSM8X10_WCD_A_CDC_TX2_VOL_CTL_GAIN,
  176. };
  177. struct msm8x10_wcd_i2c {
  178. struct i2c_client *client;
  179. struct i2c_msg xfer_msg[2];
  180. struct mutex xfer_lock;
  181. int mod_id;
  182. };
  183. static int msm8x10_wcd_dt_parse_vreg_info(struct device *dev,
  184. struct msm8x10_wcd_regulator *vreg,
  185. const char *vreg_name, bool ondemand);
  186. static int msm8x10_wcd_dt_parse_micbias_info(struct device *dev,
  187. struct wcd9xxx_micbias_setting *micbias);
  188. static struct msm8x10_wcd_pdata *msm8x10_wcd_populate_dt_pdata(
  189. struct device *dev);
  190. struct msm8x10_wcd_i2c msm8x10_wcd_modules[MAX_MSM8X10_WCD_DEVICE];
  191. static void *adsp_state_notifier;
  192. static struct snd_soc_codec *registered_codec;
  193. #define ADSP_STATE_READY_TIMEOUT_MS 2000
  194. static int get_i2c_msm8x10_wcd_device_info(u16 reg,
  195. struct msm8x10_wcd_i2c **msm8x10_wcd)
  196. {
  197. int rtn = 0;
  198. int value = ((reg & 0x0f00) >> 8) & 0x000f;
  199. switch (value) {
  200. case 0:
  201. case 1:
  202. *msm8x10_wcd = &msm8x10_wcd_modules[value];
  203. break;
  204. default:
  205. rtn = -EINVAL;
  206. break;
  207. }
  208. return rtn;
  209. }
  210. static int msm8x10_wcd_abh_write_device(struct msm8x10_wcd *msm8x10_wcd,
  211. u16 reg, u8 *value, u32 bytes)
  212. {
  213. u32 temp = ((u32)(*value)) & 0x000000FF;
  214. u32 offset = (((u32)(reg)) ^ 0x00000400) & 0x00000FFF;
  215. iowrite32(temp, (msm8x10_wcd->pdino_base+offset));
  216. return 0;
  217. }
  218. static int msm8x10_wcd_abh_read_device(struct msm8x10_wcd *msm8x10_wcd,
  219. u16 reg, u32 bytes, u8 *value)
  220. {
  221. u32 temp;
  222. u32 offset = (((u32)(reg)) ^ 0x00000400) & 0x00000FFF;
  223. temp = ioread32((msm8x10_wcd->pdino_base+offset));
  224. *value = (u8)temp;
  225. return 0;
  226. }
  227. static int msm8x10_wcd_i2c_write_device(u16 reg, u8 *value, u32 bytes)
  228. {
  229. struct i2c_msg *msg;
  230. int ret;
  231. u8 reg_addr = 0;
  232. u8 data[bytes + 1];
  233. struct msm8x10_wcd_i2c *msm8x10_wcd = NULL;
  234. ret = get_i2c_msm8x10_wcd_device_info(reg, &msm8x10_wcd);
  235. if (ret) {
  236. pr_err("%s: Invalid register address\n", __func__);
  237. return ret;
  238. }
  239. if (msm8x10_wcd == NULL || msm8x10_wcd->client == NULL) {
  240. pr_err("%s: Failed to get device info\n", __func__);
  241. return -ENODEV;
  242. }
  243. reg_addr = (u8)reg;
  244. msg = &msm8x10_wcd->xfer_msg[0];
  245. msg->addr = msm8x10_wcd->client->addr;
  246. msg->len = bytes + 1;
  247. msg->flags = 0;
  248. data[0] = reg;
  249. data[1] = *value;
  250. msg->buf = data;
  251. ret = i2c_transfer(msm8x10_wcd->client->adapter,
  252. msm8x10_wcd->xfer_msg, 1);
  253. /* Try again if the write fails */
  254. if (ret != 1) {
  255. ret = i2c_transfer(msm8x10_wcd->client->adapter,
  256. msm8x10_wcd->xfer_msg, 1);
  257. if (ret != 1) {
  258. pr_err("failed to write the device\n");
  259. return ret;
  260. }
  261. }
  262. return 0;
  263. }
  264. int msm8x10_wcd_i2c_read_device(u32 reg, u32 bytes, u8 *dest)
  265. {
  266. struct i2c_msg *msg;
  267. int ret = 0;
  268. u8 reg_addr = 0;
  269. struct msm8x10_wcd_i2c *msm8x10_wcd = NULL;
  270. u8 i = 0;
  271. ret = get_i2c_msm8x10_wcd_device_info(reg, &msm8x10_wcd);
  272. if (ret) {
  273. pr_err("%s: Invalid register address\n", __func__);
  274. return ret;
  275. }
  276. if (msm8x10_wcd == NULL || msm8x10_wcd->client == NULL) {
  277. pr_err("%s: Failed to get device info\n", __func__);
  278. return -ENODEV;
  279. }
  280. for (i = 0; i < bytes; i++) {
  281. reg_addr = (u8)reg++;
  282. msg = &msm8x10_wcd->xfer_msg[0];
  283. msg->addr = msm8x10_wcd->client->addr;
  284. msg->len = 1;
  285. msg->flags = 0;
  286. msg->buf = &reg_addr;
  287. msg = &msm8x10_wcd->xfer_msg[1];
  288. msg->addr = msm8x10_wcd->client->addr;
  289. msg->len = 1;
  290. msg->flags = I2C_M_RD;
  291. msg->buf = dest++;
  292. ret = i2c_transfer(msm8x10_wcd->client->adapter,
  293. msm8x10_wcd->xfer_msg, 2);
  294. /* Try again if read fails first time */
  295. if (ret != 2) {
  296. ret = i2c_transfer(msm8x10_wcd->client->adapter,
  297. msm8x10_wcd->xfer_msg, 2);
  298. if (ret != 2) {
  299. pr_err("failed to read msm8x10_wcd register\n");
  300. return ret;
  301. }
  302. }
  303. }
  304. return 0;
  305. }
  306. int msm8x10_wcd_i2c_read(unsigned short reg, int bytes, void *dest)
  307. {
  308. return msm8x10_wcd_i2c_read_device(reg, bytes, dest);
  309. }
  310. int msm8x10_wcd_i2c_write(unsigned short reg, int bytes, void *src)
  311. {
  312. return msm8x10_wcd_i2c_write_device(reg, src, bytes);
  313. }
  314. static unsigned short msm8x10_wcd_mask_reg(unsigned short reg)
  315. {
  316. if (reg >= 0x3C0 && reg <= 0x3DF)
  317. reg = reg & 0x00FF;
  318. return reg;
  319. }
  320. static int __msm8x10_wcd_reg_read(struct msm8x10_wcd *msm8x10_wcd,
  321. unsigned short reg)
  322. {
  323. int ret = -EINVAL;
  324. u8 temp;
  325. reg = msm8x10_wcd_mask_reg(reg);
  326. /* check if use I2C interface for Helicon or AHB for Dino */
  327. mutex_lock(&msm8x10_wcd->io_lock);
  328. if (MSM8X10_WCD_IS_HELICON_REG(reg))
  329. ret = msm8x10_wcd_i2c_read(reg, 1, &temp);
  330. else if (MSM8X10_WCD_IS_DINO_REG(reg))
  331. ret = msm8x10_wcd_abh_read_device(msm8x10_wcd, reg, 1, &temp);
  332. mutex_unlock(&msm8x10_wcd->io_lock);
  333. if (ret < 0) {
  334. dev_err(msm8x10_wcd->dev,
  335. "%s: codec read failed for reg 0x%x\n",
  336. __func__, reg);
  337. return ret;
  338. } else {
  339. dev_dbg(msm8x10_wcd->dev, "Read 0x%02x from 0x%x\n",
  340. temp, reg);
  341. }
  342. return temp;
  343. }
  344. static int __msm8x10_wcd_bulk_write(struct msm8x10_wcd *msm8x10_wcd,
  345. unsigned short reg, int count, u8 *buf)
  346. {
  347. int ret = -EINVAL;
  348. mutex_lock(&msm8x10_wcd->io_lock);
  349. if (MSM8X10_WCD_IS_HELICON_REG(reg))
  350. ret = msm8x10_wcd_i2c_write(reg, count, buf);
  351. else if (MSM8X10_WCD_IS_DINO_REG(reg))
  352. ret = msm8x10_wcd_abh_write_device(msm8x10_wcd, reg,
  353. buf, count);
  354. if (ret < 0)
  355. dev_err(msm8x10_wcd->dev,
  356. "%s: codec bulk write failed\n", __func__);
  357. mutex_unlock(&msm8x10_wcd->io_lock);
  358. return ret;
  359. }
  360. int msm8x10_wcd_bulk_write(struct wcd9xxx_core_resource *core_res,
  361. unsigned short reg, int count, u8 *buf)
  362. {
  363. struct msm8x10_wcd *msm8x10_wcd =
  364. (struct msm8x10_wcd *) core_res->parent;
  365. return __msm8x10_wcd_bulk_write(msm8x10_wcd, reg, count, buf);
  366. }
  367. EXPORT_SYMBOL(msm8x10_wcd_bulk_write);
  368. int msm8x10_wcd_reg_read(struct wcd9xxx_core_resource *core_res,
  369. unsigned short reg)
  370. {
  371. struct msm8x10_wcd *msm8x10_wcd = core_res->parent;
  372. return __msm8x10_wcd_reg_read(msm8x10_wcd, reg);
  373. }
  374. EXPORT_SYMBOL(msm8x10_wcd_reg_read);
  375. static int __msm8x10_wcd_bulk_read(struct msm8x10_wcd *msm8x10_wcd,
  376. unsigned short reg, int count, u8 *buf)
  377. {
  378. int ret = -EINVAL;
  379. mutex_lock(&msm8x10_wcd->io_lock);
  380. if (MSM8X10_WCD_IS_HELICON_REG(reg))
  381. ret = msm8x10_wcd_i2c_read(reg, count, buf);
  382. else if (MSM8X10_WCD_IS_DINO_REG(reg))
  383. ret = msm8x10_wcd_abh_read_device(msm8x10_wcd, reg,
  384. count, buf);
  385. mutex_unlock(&msm8x10_wcd->io_lock);
  386. if (ret < 0)
  387. dev_err(msm8x10_wcd->dev,
  388. "%s: codec bulk read failed\n", __func__);
  389. return ret;
  390. }
  391. int msm8x10_wcd_bulk_read(struct wcd9xxx_core_resource *core_res,
  392. unsigned short reg, int count, u8 *buf)
  393. {
  394. struct msm8x10_wcd *msm8x10_wcd =
  395. (struct msm8x10_wcd *) core_res->parent;
  396. return __msm8x10_wcd_bulk_read(msm8x10_wcd, reg, count, buf);
  397. }
  398. EXPORT_SYMBOL(msm8x10_wcd_bulk_read);
  399. static int __msm8x10_wcd_reg_write(struct msm8x10_wcd *msm8x10_wcd,
  400. unsigned short reg, u8 val)
  401. {
  402. int ret = -EINVAL;
  403. reg = msm8x10_wcd_mask_reg(reg);
  404. /* check if use I2C interface for Helicon or AHB for Dino */
  405. mutex_lock(&msm8x10_wcd->io_lock);
  406. if (MSM8X10_WCD_IS_HELICON_REG(reg))
  407. ret = msm8x10_wcd_i2c_write(reg, 1, &val);
  408. else if (MSM8X10_WCD_IS_DINO_REG(reg))
  409. ret = msm8x10_wcd_abh_write_device(msm8x10_wcd, reg, &val, 1);
  410. mutex_unlock(&msm8x10_wcd->io_lock);
  411. if (ret < 0)
  412. dev_err(msm8x10_wcd->dev,
  413. "%s: codec write to reg 0x%x failed\n",
  414. __func__, reg);
  415. else
  416. dev_dbg(msm8x10_wcd->dev,
  417. "%s: Write 0x%x to 0x%x\n",
  418. __func__, val, reg);
  419. return ret;
  420. }
  421. int msm8x10_wcd_reg_write(struct wcd9xxx_core_resource *core_res,
  422. unsigned short reg, u8 val)
  423. {
  424. struct msm8x10_wcd *msm8x10_wcd = core_res->parent;
  425. return __msm8x10_wcd_reg_write(msm8x10_wcd, reg, val);
  426. }
  427. EXPORT_SYMBOL(msm8x10_wcd_reg_write);
  428. static bool msm8x10_wcd_is_digital_gain_register(unsigned int reg)
  429. {
  430. bool rtn = false;
  431. switch (reg) {
  432. case MSM8X10_WCD_A_CDC_RX1_VOL_CTL_B2_CTL:
  433. case MSM8X10_WCD_A_CDC_RX2_VOL_CTL_B2_CTL:
  434. case MSM8X10_WCD_A_CDC_RX3_VOL_CTL_B2_CTL:
  435. case MSM8X10_WCD_A_CDC_TX1_VOL_CTL_GAIN:
  436. case MSM8X10_WCD_A_CDC_TX2_VOL_CTL_GAIN:
  437. rtn = true;
  438. break;
  439. default:
  440. break;
  441. }
  442. return rtn;
  443. }
  444. static int msm8x10_wcd_volatile(struct snd_soc_codec *codec, unsigned int reg)
  445. {
  446. /*
  447. * Registers lower than 0x100 are top level registers which can be
  448. * written by the Taiko core driver.
  449. */
  450. if ((reg >= MSM8X10_WCD_A_CDC_MBHC_EN_CTL) || (reg < 0x100))
  451. return 1;
  452. /* IIR Coeff registers are not cacheable */
  453. if ((reg >= MSM8X10_WCD_A_CDC_IIR1_COEF_B1_CTL) &&
  454. (reg <= MSM8X10_WCD_A_CDC_IIR2_COEF_B2_CTL))
  455. return 1;
  456. /*
  457. * Digital gain register is not cacheable so we have to write
  458. * the setting even it is the same
  459. */
  460. if (msm8x10_wcd_is_digital_gain_register(reg))
  461. return 1;
  462. /* HPH status registers */
  463. if (reg == MSM8X10_WCD_A_RX_HPH_L_STATUS ||
  464. reg == MSM8X10_WCD_A_RX_HPH_R_STATUS)
  465. return 1;
  466. if (reg == MSM8X10_WCD_A_MBHC_INSERT_DET_STATUS)
  467. return 1;
  468. return 0;
  469. }
  470. static int msm8x10_wcd_readable(struct snd_soc_codec *ssc, unsigned int reg)
  471. {
  472. return msm8x10_wcd_reg_readable[reg];
  473. }
  474. static int msm8x10_wcd_write(struct snd_soc_codec *codec, unsigned int reg,
  475. unsigned int value)
  476. {
  477. int ret;
  478. dev_dbg(codec->dev, "%s: Write to reg 0x%x\n", __func__, reg);
  479. if (reg == SND_SOC_NOPM)
  480. return 0;
  481. BUG_ON(reg > MSM8X10_WCD_MAX_REGISTER);
  482. if (!msm8x10_wcd_volatile(codec, reg)) {
  483. ret = snd_soc_cache_write(codec, reg, value);
  484. if (ret != 0)
  485. dev_err(codec->dev, "Cache write to %x failed: %d\n",
  486. reg, ret);
  487. }
  488. return __msm8x10_wcd_reg_write(codec->control_data, reg, (u8)value);
  489. }
  490. static unsigned int msm8x10_wcd_read(struct snd_soc_codec *codec,
  491. unsigned int reg)
  492. {
  493. unsigned int val;
  494. int ret;
  495. dev_dbg(codec->dev, "%s: Read from reg 0x%x\n", __func__, reg);
  496. if (reg == SND_SOC_NOPM)
  497. return 0;
  498. BUG_ON(reg > MSM8X10_WCD_MAX_REGISTER);
  499. if (!msm8x10_wcd_volatile(codec, reg) &&
  500. msm8x10_wcd_readable(codec, reg) &&
  501. reg < codec->driver->reg_cache_size) {
  502. ret = snd_soc_cache_read(codec, reg, &val);
  503. if (ret >= 0) {
  504. return val;
  505. } else
  506. dev_err(codec->dev, "Cache read from %x failed: %d\n",
  507. reg, ret);
  508. }
  509. val = __msm8x10_wcd_reg_read(codec->control_data, reg);
  510. return val;
  511. }
  512. static int msm8x10_wcd_dt_parse_vreg_info(struct device *dev,
  513. struct msm8x10_wcd_regulator *vreg, const char *vreg_name,
  514. bool ondemand)
  515. {
  516. int len, ret = 0;
  517. const __be32 *prop;
  518. char prop_name[CODEC_DT_MAX_PROP_SIZE];
  519. struct device_node *regnode = NULL;
  520. u32 prop_val;
  521. snprintf(prop_name, CODEC_DT_MAX_PROP_SIZE, "%s-supply",
  522. vreg_name);
  523. regnode = of_parse_phandle(dev->of_node, prop_name, 0);
  524. if (!regnode) {
  525. dev_err(dev, "Looking up %s property in node %s failed\n",
  526. prop_name, dev->of_node->full_name);
  527. return -ENODEV;
  528. }
  529. dev_dbg(dev, "Looking up %s property in node %s\n",
  530. prop_name, dev->of_node->full_name);
  531. vreg->name = vreg_name;
  532. vreg->ondemand = ondemand;
  533. snprintf(prop_name, CODEC_DT_MAX_PROP_SIZE,
  534. "qcom,%s-voltage", vreg_name);
  535. prop = of_get_property(dev->of_node, prop_name, &len);
  536. if (!prop || (len != (2 * sizeof(__be32)))) {
  537. dev_err(dev, "%s %s property\n",
  538. prop ? "invalid format" : "no", prop_name);
  539. return -EINVAL;
  540. } else {
  541. vreg->min_uV = be32_to_cpup(&prop[0]);
  542. vreg->max_uV = be32_to_cpup(&prop[1]);
  543. }
  544. snprintf(prop_name, CODEC_DT_MAX_PROP_SIZE,
  545. "qcom,%s-current", vreg_name);
  546. ret = of_property_read_u32(dev->of_node, prop_name, &prop_val);
  547. if (ret) {
  548. dev_err(dev, "Looking up %s property in node %s failed",
  549. prop_name, dev->of_node->full_name);
  550. return -EFAULT;
  551. }
  552. vreg->optimum_uA = prop_val;
  553. dev_info(dev, "%s: vol=[%d %d]uV, curr=[%d]uA, ond %d\n\n", vreg->name,
  554. vreg->min_uV, vreg->max_uV, vreg->optimum_uA, vreg->ondemand);
  555. return 0;
  556. }
  557. static int msm8x10_wcd_dt_parse_micbias_info(struct device *dev,
  558. struct wcd9xxx_micbias_setting *micbias)
  559. {
  560. int ret = 0;
  561. char prop_name[CODEC_DT_MAX_PROP_SIZE];
  562. u32 prop_val;
  563. snprintf(prop_name, CODEC_DT_MAX_PROP_SIZE,
  564. "qcom,cdc-micbias-ldoh-v");
  565. ret = of_property_read_u32(dev->of_node, prop_name,
  566. &prop_val);
  567. if (ret) {
  568. dev_err(dev, "Looking up %s property in node %s failed",
  569. prop_name, dev->of_node->full_name);
  570. return -ENODEV;
  571. }
  572. micbias->ldoh_v = (u8) prop_val;
  573. snprintf(prop_name, CODEC_DT_MAX_PROP_SIZE,
  574. "qcom,cdc-micbias-cfilt-mv");
  575. ret = of_property_read_u32(dev->of_node, prop_name,
  576. &micbias->cfilt1_mv);
  577. if (ret) {
  578. dev_err(dev, "Looking up %s property in node %s failed",
  579. prop_name, dev->of_node->full_name);
  580. return -ENODEV;
  581. }
  582. snprintf(prop_name, CODEC_DT_MAX_PROP_SIZE,
  583. "qcom,cdc-micbias-cfilt-sel");
  584. ret = of_property_read_u32(dev->of_node, prop_name, &prop_val);
  585. if (ret) {
  586. dev_err(dev, "Looking up %s property in node %s failed",
  587. prop_name, dev->of_node->full_name);
  588. return -ENODEV;
  589. }
  590. micbias->bias1_cfilt_sel = (u8)prop_val;
  591. /* micbias external cap */
  592. micbias->bias1_cap_mode =
  593. (of_property_read_bool(dev->of_node, "qcom,cdc-micbias1-ext-cap") ?
  594. MICBIAS_EXT_BYP_CAP : MICBIAS_NO_EXT_BYP_CAP);
  595. dev_dbg(dev, "ldoh_v %u cfilt1_mv %u\n",
  596. (u32)micbias->ldoh_v, (u32)micbias->cfilt1_mv);
  597. dev_dbg(dev, "bias1_cfilt_sel %u\n", (u32)micbias->bias1_cfilt_sel);
  598. dev_dbg(dev, "bias1_ext_cap %d\n", micbias->bias1_cap_mode);
  599. return 0;
  600. }
  601. static struct msm8x10_wcd_pdata *msm8x10_wcd_populate_dt_pdata(
  602. struct device *dev)
  603. {
  604. struct msm8x10_wcd_pdata *pdata;
  605. int ret, static_cnt, ond_cnt, idx, i;
  606. const char *name = NULL;
  607. const char *static_prop_name = "qcom,cdc-static-supplies";
  608. const char *ond_prop_name = "qcom,cdc-on-demand-supplies";
  609. pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
  610. if (!pdata) {
  611. dev_err(dev, "could not allocate memory for platform data\n");
  612. return NULL;
  613. }
  614. static_cnt = of_property_count_strings(dev->of_node, static_prop_name);
  615. if (IS_ERR_VALUE(static_cnt)) {
  616. dev_err(dev, "%s: Failed to get static supplies %d\n", __func__,
  617. static_cnt);
  618. ret = -EINVAL;
  619. goto err;
  620. }
  621. /* On-demand supply list is an optional property */
  622. ond_cnt = of_property_count_strings(dev->of_node, ond_prop_name);
  623. if (IS_ERR_VALUE(ond_cnt))
  624. ond_cnt = 0;
  625. BUG_ON(static_cnt <= 0 || ond_cnt < 0);
  626. if ((static_cnt + ond_cnt) > ARRAY_SIZE(pdata->regulator)) {
  627. dev_err(dev, "%s: Num of supplies %u > max supported %u\n",
  628. __func__, static_cnt, ARRAY_SIZE(pdata->regulator));
  629. ret = -EINVAL;
  630. goto err;
  631. }
  632. for (idx = 0; idx < static_cnt; idx++) {
  633. ret = of_property_read_string_index(dev->of_node,
  634. static_prop_name, idx,
  635. &name);
  636. if (ret) {
  637. dev_err(dev, "%s: of read string %s idx %d error %d\n",
  638. __func__, static_prop_name, idx, ret);
  639. goto err;
  640. }
  641. dev_dbg(dev, "%s: Found static cdc supply %s\n", __func__,
  642. name);
  643. ret = msm8x10_wcd_dt_parse_vreg_info(dev,
  644. &pdata->regulator[idx],
  645. name, false);
  646. if (ret)
  647. goto err;
  648. }
  649. for (i = 0; i < ond_cnt; i++, idx++) {
  650. ret = of_property_read_string_index(dev->of_node, ond_prop_name,
  651. i, &name);
  652. if (ret)
  653. goto err;
  654. dev_dbg(dev, "%s: Found on-demand cdc supply %s\n", __func__,
  655. name);
  656. ret = msm8x10_wcd_dt_parse_vreg_info(dev,
  657. &pdata->regulator[idx],
  658. name, true);
  659. if (ret)
  660. goto err;
  661. }
  662. ret = msm8x10_wcd_dt_parse_micbias_info(dev, &pdata->micbias);
  663. if (ret)
  664. goto err;
  665. return pdata;
  666. err:
  667. devm_kfree(dev, pdata);
  668. dev_err(dev, "%s: Failed to populate DT data ret = %d\n",
  669. __func__, ret);
  670. return NULL;
  671. }
  672. static int on_demand_regulator_control(struct on_demand_supply *supply,
  673. bool enable,
  674. u8 shift)
  675. {
  676. int ret = 0;
  677. if (!supply || !supply->supply)
  678. return 0;
  679. if (enable) {
  680. if (atomic_inc_return(&supply->ref) == 1)
  681. ret = regulator_enable(supply->supply);
  682. if (ret)
  683. pr_err("%s: Failed to enable %s\n",
  684. __func__,
  685. on_demand_supply_name[shift]);
  686. } else {
  687. if (atomic_read(&supply->ref) == 0) {
  688. pr_debug("%s: %s supply has been disabled.\n",
  689. __func__, on_demand_supply_name[shift]);
  690. return 0;
  691. }
  692. if (atomic_dec_return(&supply->ref) == 0)
  693. ret = regulator_disable(supply->supply);
  694. if (ret)
  695. pr_err("%s: Failed to disable %s\n",
  696. __func__,
  697. on_demand_supply_name[shift]);
  698. }
  699. return ret;
  700. }
  701. static int msm8x10_wcd_codec_enable_on_demand_supply(
  702. struct snd_soc_dapm_widget *w,
  703. struct snd_kcontrol *kcontrol, int event)
  704. {
  705. int ret = 0;
  706. struct snd_soc_codec *codec = w->codec;
  707. struct msm8x10_wcd_priv *msm8x10_wcd = snd_soc_codec_get_drvdata(codec);
  708. struct on_demand_supply *supply;
  709. if (w->shift >= ON_DEMAND_SUPPLIES_MAX) {
  710. ret = -EINVAL;
  711. goto out;
  712. }
  713. dev_dbg(codec->dev, "%s: supply: %s event: %d ref: %d\n",
  714. __func__, on_demand_supply_name[w->shift], event,
  715. atomic_read(&msm8x10_wcd->on_demand_list[w->shift].ref));
  716. supply = &msm8x10_wcd->on_demand_list[w->shift];
  717. WARN_ONCE(!supply->supply, "%s isn't defined\n",
  718. on_demand_supply_name[w->shift]);
  719. if (!supply->supply)
  720. goto out;
  721. switch (event) {
  722. case SND_SOC_DAPM_PRE_PMU:
  723. ret = on_demand_regulator_control(supply,
  724. true,
  725. w->shift);
  726. break;
  727. case SND_SOC_DAPM_POST_PMD:
  728. ret = on_demand_regulator_control(supply,
  729. false,
  730. w->shift);
  731. break;
  732. default:
  733. break;
  734. }
  735. out:
  736. return ret;
  737. }
  738. static int msm8x10_wcd_codec_enable_charge_pump(struct snd_soc_dapm_widget *w,
  739. struct snd_kcontrol *kcontrol, int event)
  740. {
  741. struct snd_soc_codec *codec = w->codec;
  742. dev_dbg(codec->dev, "%s: event = %d\n", __func__, event);
  743. switch (event) {
  744. case SND_SOC_DAPM_POST_PMU:
  745. /* Enable charge pump clock*/
  746. snd_soc_update_bits(codec, MSM8X10_WCD_A_CDC_CLK_OTHR_CTL,
  747. 0x01, 0x01);
  748. snd_soc_update_bits(codec, MSM8X10_WCD_A_CDC_CLSG_CTL,
  749. 0x08, 0x08);
  750. usleep_range(200, 300);
  751. snd_soc_update_bits(codec, MSM8X10_WCD_A_CP_STATIC,
  752. 0x10, 0x00);
  753. break;
  754. case SND_SOC_DAPM_PRE_PMD:
  755. snd_soc_update_bits(codec,
  756. MSM8X10_WCD_A_CDC_CLK_OTHR_RESET_B1_CTL,
  757. 0x01, 0x01);
  758. usleep_range(20, 100);
  759. snd_soc_update_bits(codec,
  760. MSM8X10_WCD_A_CP_STATIC, 0x08, 0x08);
  761. snd_soc_update_bits(codec,
  762. MSM8X10_WCD_A_CP_STATIC, 0x10, 0x10);
  763. snd_soc_update_bits(codec,
  764. MSM8X10_WCD_A_CDC_CLSG_CTL, 0x08, 0x00);
  765. snd_soc_update_bits(codec,
  766. MSM8X10_WCD_A_CDC_CLK_OTHR_CTL, 0x01,
  767. 0x00);
  768. snd_soc_update_bits(codec,
  769. MSM8X10_WCD_A_CDC_CLK_OTHR_RESET_B1_CTL,
  770. 0x01, 0x00);
  771. snd_soc_update_bits(codec,
  772. MSM8X10_WCD_A_CP_STATIC, 0x08, 0x00);
  773. break;
  774. default:
  775. break;
  776. }
  777. return 0;
  778. }
  779. static int msm8x10_wcd_pa_gain_get(struct snd_kcontrol *kcontrol,
  780. struct snd_ctl_elem_value *ucontrol)
  781. {
  782. u8 ear_pa_gain;
  783. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  784. ear_pa_gain = snd_soc_read(codec, MSM8X10_WCD_A_RX_EAR_GAIN);
  785. ear_pa_gain = ear_pa_gain >> 5;
  786. if (ear_pa_gain == 0x00) {
  787. ucontrol->value.integer.value[0] = 0;
  788. } else if (ear_pa_gain == 0x04) {
  789. ucontrol->value.integer.value[0] = 1;
  790. } else {
  791. dev_err(codec->dev, "%s: ERROR: Unsupported Ear Gain = 0x%x\n",
  792. __func__, ear_pa_gain);
  793. return -EINVAL;
  794. }
  795. dev_dbg(codec->dev, "%s: ear_pa_gain = 0x%x\n", __func__, ear_pa_gain);
  796. return 0;
  797. }
  798. static int msm8x10_wcd_pa_gain_put(struct snd_kcontrol *kcontrol,
  799. struct snd_ctl_elem_value *ucontrol)
  800. {
  801. u8 ear_pa_gain;
  802. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  803. dev_dbg(codec->dev, "%s: ucontrol->value.integer.value[0] = %ld\n",
  804. __func__, ucontrol->value.integer.value[0]);
  805. switch (ucontrol->value.integer.value[0]) {
  806. case 0:
  807. ear_pa_gain = 0x00;
  808. break;
  809. case 1:
  810. ear_pa_gain = 0x80;
  811. break;
  812. default:
  813. return -EINVAL;
  814. }
  815. snd_soc_update_bits(codec, MSM8X10_WCD_A_RX_EAR_GAIN,
  816. 0xE0, ear_pa_gain);
  817. return 0;
  818. }
  819. static int msm8x10_wcd_get_iir_enable_audio_mixer(
  820. struct snd_kcontrol *kcontrol,
  821. struct snd_ctl_elem_value *ucontrol)
  822. {
  823. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  824. int iir_idx = ((struct soc_multi_mixer_control *)
  825. kcontrol->private_value)->reg;
  826. int band_idx = ((struct soc_multi_mixer_control *)
  827. kcontrol->private_value)->shift;
  828. ucontrol->value.integer.value[0] =
  829. (snd_soc_read(codec,
  830. (MSM8X10_WCD_A_CDC_IIR1_CTL + 64 * iir_idx)) &
  831. (1 << band_idx)) != 0;
  832. dev_dbg(codec->dev, "%s: IIR #%d band #%d enable %d\n", __func__,
  833. iir_idx, band_idx,
  834. (uint32_t)ucontrol->value.integer.value[0]);
  835. return 0;
  836. }
  837. static int msm8x10_wcd_put_iir_enable_audio_mixer(
  838. struct snd_kcontrol *kcontrol,
  839. struct snd_ctl_elem_value *ucontrol)
  840. {
  841. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  842. int iir_idx = ((struct soc_multi_mixer_control *)
  843. kcontrol->private_value)->reg;
  844. int band_idx = ((struct soc_multi_mixer_control *)
  845. kcontrol->private_value)->shift;
  846. int value = ucontrol->value.integer.value[0];
  847. /* Mask first 5 bits, 6-8 are reserved */
  848. snd_soc_update_bits(codec, (MSM8X10_WCD_A_CDC_IIR1_CTL + 64 * iir_idx),
  849. (1 << band_idx), (value << band_idx));
  850. dev_dbg(codec->dev, "%s: IIR #%d band #%d enable %d\n", __func__,
  851. iir_idx, band_idx,
  852. ((snd_soc_read(codec, (MSM8X10_WCD_A_CDC_IIR1_CTL + 64 * iir_idx)) &
  853. (1 << band_idx)) != 0));
  854. return 0;
  855. }
  856. static uint32_t get_iir_band_coeff(struct snd_soc_codec *codec,
  857. int iir_idx, int band_idx,
  858. int coeff_idx)
  859. {
  860. uint32_t value = 0;
  861. /* Address does not automatically update if reading */
  862. snd_soc_write(codec,
  863. (MSM8X10_WCD_A_CDC_IIR1_COEF_B1_CTL + 64 * iir_idx),
  864. ((band_idx * BAND_MAX + coeff_idx)
  865. * sizeof(uint32_t)) & 0x7F);
  866. value |= snd_soc_read(codec,
  867. (MSM8X10_WCD_A_CDC_IIR1_COEF_B2_CTL + 64 * iir_idx));
  868. snd_soc_write(codec,
  869. (MSM8X10_WCD_A_CDC_IIR1_COEF_B1_CTL + 64 * iir_idx),
  870. ((band_idx * BAND_MAX + coeff_idx)
  871. * sizeof(uint32_t) + 1) & 0x7F);
  872. value |= (snd_soc_read(codec,
  873. (MSM8X10_WCD_A_CDC_IIR1_COEF_B2_CTL + 64 * iir_idx)) << 8);
  874. snd_soc_write(codec,
  875. (MSM8X10_WCD_A_CDC_IIR1_COEF_B1_CTL + 64 * iir_idx),
  876. ((band_idx * BAND_MAX + coeff_idx)
  877. * sizeof(uint32_t) + 2) & 0x7F);
  878. value |= (snd_soc_read(codec,
  879. (MSM8X10_WCD_A_CDC_IIR1_COEF_B2_CTL + 64 * iir_idx)) << 16);
  880. snd_soc_write(codec,
  881. (MSM8X10_WCD_A_CDC_IIR1_COEF_B1_CTL + 64 * iir_idx),
  882. ((band_idx * BAND_MAX + coeff_idx)
  883. * sizeof(uint32_t) + 3) & 0x7F);
  884. /* Mask bits top 2 bits since they are reserved */
  885. value |= ((snd_soc_read(codec,
  886. (MSM8X10_WCD_A_CDC_IIR1_COEF_B2_CTL + 64 * iir_idx)) & 0x3f) << 24);
  887. return value;
  888. }
  889. static int msm8x10_wcd_get_iir_band_audio_mixer(
  890. struct snd_kcontrol *kcontrol,
  891. struct snd_ctl_elem_value *ucontrol)
  892. {
  893. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  894. int iir_idx = ((struct soc_multi_mixer_control *)
  895. kcontrol->private_value)->reg;
  896. int band_idx = ((struct soc_multi_mixer_control *)
  897. kcontrol->private_value)->shift;
  898. ucontrol->value.integer.value[0] =
  899. get_iir_band_coeff(codec, iir_idx, band_idx, 0);
  900. ucontrol->value.integer.value[1] =
  901. get_iir_band_coeff(codec, iir_idx, band_idx, 1);
  902. ucontrol->value.integer.value[2] =
  903. get_iir_band_coeff(codec, iir_idx, band_idx, 2);
  904. ucontrol->value.integer.value[3] =
  905. get_iir_band_coeff(codec, iir_idx, band_idx, 3);
  906. ucontrol->value.integer.value[4] =
  907. get_iir_band_coeff(codec, iir_idx, band_idx, 4);
  908. dev_dbg(codec->dev, "%s: IIR #%d band #%d b0 = 0x%x\n"
  909. "%s: IIR #%d band #%d b1 = 0x%x\n"
  910. "%s: IIR #%d band #%d b2 = 0x%x\n"
  911. "%s: IIR #%d band #%d a1 = 0x%x\n"
  912. "%s: IIR #%d band #%d a2 = 0x%x\n",
  913. __func__, iir_idx, band_idx,
  914. (uint32_t)ucontrol->value.integer.value[0],
  915. __func__, iir_idx, band_idx,
  916. (uint32_t)ucontrol->value.integer.value[1],
  917. __func__, iir_idx, band_idx,
  918. (uint32_t)ucontrol->value.integer.value[2],
  919. __func__, iir_idx, band_idx,
  920. (uint32_t)ucontrol->value.integer.value[3],
  921. __func__, iir_idx, band_idx,
  922. (uint32_t)ucontrol->value.integer.value[4]);
  923. return 0;
  924. }
  925. static void set_iir_band_coeff(struct snd_soc_codec *codec,
  926. int iir_idx, int band_idx,
  927. uint32_t value)
  928. {
  929. snd_soc_write(codec,
  930. (MSM8X10_WCD_A_CDC_IIR1_COEF_B2_CTL + 64 * iir_idx),
  931. (value & 0xFF));
  932. snd_soc_write(codec,
  933. (MSM8X10_WCD_A_CDC_IIR1_COEF_B2_CTL + 64 * iir_idx),
  934. (value >> 8) & 0xFF);
  935. snd_soc_write(codec,
  936. (MSM8X10_WCD_A_CDC_IIR1_COEF_B2_CTL + 64 * iir_idx),
  937. (value >> 16) & 0xFF);
  938. /* Mask top 2 bits, 7-8 are reserved */
  939. snd_soc_write(codec,
  940. (MSM8X10_WCD_A_CDC_IIR1_COEF_B2_CTL + 64 * iir_idx),
  941. (value >> 24) & 0x3F);
  942. }
  943. static int msm8x10_wcd_put_iir_band_audio_mixer(
  944. struct snd_kcontrol *kcontrol,
  945. struct snd_ctl_elem_value *ucontrol)
  946. {
  947. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  948. int iir_idx = ((struct soc_multi_mixer_control *)
  949. kcontrol->private_value)->reg;
  950. int band_idx = ((struct soc_multi_mixer_control *)
  951. kcontrol->private_value)->shift;
  952. /* Mask top bit it is reserved */
  953. /* Updates addr automatically for each B2 write */
  954. snd_soc_write(codec,
  955. (MSM8X10_WCD_A_CDC_IIR1_COEF_B1_CTL + 64 * iir_idx),
  956. (band_idx * BAND_MAX * sizeof(uint32_t)) & 0x7F);
  957. set_iir_band_coeff(codec, iir_idx, band_idx,
  958. ucontrol->value.integer.value[0]);
  959. set_iir_band_coeff(codec, iir_idx, band_idx,
  960. ucontrol->value.integer.value[1]);
  961. set_iir_band_coeff(codec, iir_idx, band_idx,
  962. ucontrol->value.integer.value[2]);
  963. set_iir_band_coeff(codec, iir_idx, band_idx,
  964. ucontrol->value.integer.value[3]);
  965. set_iir_band_coeff(codec, iir_idx, band_idx,
  966. ucontrol->value.integer.value[4]);
  967. dev_dbg(codec->dev, "%s: IIR #%d band #%d b0 = 0x%x\n"
  968. "%s: IIR #%d band #%d b1 = 0x%x\n"
  969. "%s: IIR #%d band #%d b2 = 0x%x\n"
  970. "%s: IIR #%d band #%d a1 = 0x%x\n"
  971. "%s: IIR #%d band #%d a2 = 0x%x\n",
  972. __func__, iir_idx, band_idx,
  973. get_iir_band_coeff(codec, iir_idx, band_idx, 0),
  974. __func__, iir_idx, band_idx,
  975. get_iir_band_coeff(codec, iir_idx, band_idx, 1),
  976. __func__, iir_idx, band_idx,
  977. get_iir_band_coeff(codec, iir_idx, band_idx, 2),
  978. __func__, iir_idx, band_idx,
  979. get_iir_band_coeff(codec, iir_idx, band_idx, 3),
  980. __func__, iir_idx, band_idx,
  981. get_iir_band_coeff(codec, iir_idx, band_idx, 4));
  982. return 0;
  983. }
  984. static const char * const msm8x10_wcd_ear_pa_gain_text[] = {
  985. "POS_6_DB", "POS_2_DB"};
  986. static const struct soc_enum msm8x10_wcd_ear_pa_gain_enum[] = {
  987. SOC_ENUM_SINGLE_EXT(2, msm8x10_wcd_ear_pa_gain_text),
  988. };
  989. /*cut of frequency for high pass filter*/
  990. static const char * const cf_text[] = {
  991. "MIN_3DB_4Hz", "MIN_3DB_75Hz", "MIN_3DB_150Hz"
  992. };
  993. static const struct soc_enum cf_dec1_enum =
  994. SOC_ENUM_SINGLE(MSM8X10_WCD_A_CDC_TX1_MUX_CTL, 4, 3, cf_text);
  995. static const struct soc_enum cf_dec2_enum =
  996. SOC_ENUM_SINGLE(MSM8X10_WCD_A_CDC_TX2_MUX_CTL, 4, 3, cf_text);
  997. static const struct soc_enum cf_rxmix1_enum =
  998. SOC_ENUM_SINGLE(MSM8X10_WCD_A_CDC_RX1_B4_CTL, 0, 3, cf_text);
  999. static const struct soc_enum cf_rxmix2_enum =
  1000. SOC_ENUM_SINGLE(MSM8X10_WCD_A_CDC_RX2_B4_CTL, 0, 3, cf_text);
  1001. static const struct soc_enum cf_rxmix3_enum =
  1002. SOC_ENUM_SINGLE(MSM8X10_WCD_A_CDC_RX3_B4_CTL, 0, 3, cf_text);
  1003. static const struct snd_kcontrol_new msm8x10_wcd_snd_controls[] = {
  1004. SOC_ENUM_EXT("EAR PA Gain", msm8x10_wcd_ear_pa_gain_enum[0],
  1005. msm8x10_wcd_pa_gain_get, msm8x10_wcd_pa_gain_put),
  1006. SOC_SINGLE_TLV("LINEOUT Volume", MSM8X10_WCD_A_RX_LINE_1_GAIN,
  1007. 0, 12, 1, line_gain),
  1008. SOC_SINGLE_TLV("HPHL Volume", MSM8X10_WCD_A_RX_HPH_L_GAIN,
  1009. 0, 12, 1, line_gain),
  1010. SOC_SINGLE_TLV("HPHR Volume", MSM8X10_WCD_A_RX_HPH_R_GAIN,
  1011. 0, 12, 1, line_gain),
  1012. SOC_SINGLE_S8_TLV("RX1 Digital Volume",
  1013. MSM8X10_WCD_A_CDC_RX1_VOL_CTL_B2_CTL,
  1014. -84, 40, digital_gain),
  1015. SOC_SINGLE_S8_TLV("RX2 Digital Volume",
  1016. MSM8X10_WCD_A_CDC_RX2_VOL_CTL_B2_CTL,
  1017. -84, 40, digital_gain),
  1018. SOC_SINGLE_S8_TLV("RX3 Digital Volume",
  1019. MSM8X10_WCD_A_CDC_RX3_VOL_CTL_B2_CTL,
  1020. -84, 40, digital_gain),
  1021. SOC_SINGLE_S8_TLV("DEC1 Volume",
  1022. MSM8X10_WCD_A_CDC_TX1_VOL_CTL_GAIN,
  1023. -84, 40, digital_gain),
  1024. SOC_SINGLE_S8_TLV("DEC2 Volume",
  1025. MSM8X10_WCD_A_CDC_TX2_VOL_CTL_GAIN,
  1026. -84, 40, digital_gain),
  1027. SOC_SINGLE_TLV("ADC1 Volume", MSM8X10_WCD_A_TX_1_EN, 2,
  1028. 19, 0, analog_gain),
  1029. SOC_SINGLE_TLV("ADC2 Volume", MSM8X10_WCD_A_TX_2_EN, 2,
  1030. 19, 0, analog_gain),
  1031. SOC_SINGLE_TLV("ADC3 Volume", MSM8X10_WCD_A_TX_3_EN, 2,
  1032. 19, 0, analog_gain),
  1033. SOC_SINGLE_S8_TLV("IIR1 INP1 Volume",
  1034. MSM8X10_WCD_A_CDC_IIR1_GAIN_B1_CTL,
  1035. -84, 40, digital_gain),
  1036. SOC_SINGLE_S8_TLV("IIR1 INP2 Volume",
  1037. MSM8X10_WCD_A_CDC_IIR1_GAIN_B2_CTL,
  1038. -84, 40, digital_gain),
  1039. SOC_SINGLE_S8_TLV("IIR1 INP3 Volume",
  1040. MSM8X10_WCD_A_CDC_IIR1_GAIN_B3_CTL,
  1041. -84, 40, digital_gain),
  1042. SOC_SINGLE_S8_TLV("IIR1 INP4 Volume",
  1043. MSM8X10_WCD_A_CDC_IIR1_GAIN_B4_CTL,
  1044. -84, 40, digital_gain),
  1045. SOC_ENUM("TX1 HPF cut off", cf_dec1_enum),
  1046. SOC_ENUM("TX2 HPF cut off", cf_dec2_enum),
  1047. SOC_SINGLE("TX1 HPF Switch", MSM8X10_WCD_A_CDC_TX1_MUX_CTL, 3, 1, 0),
  1048. SOC_SINGLE("TX2 HPF Switch", MSM8X10_WCD_A_CDC_TX2_MUX_CTL, 3, 1, 0),
  1049. SOC_SINGLE("RX1 HPF Switch", MSM8X10_WCD_A_CDC_RX1_B5_CTL, 2, 1, 0),
  1050. SOC_SINGLE("RX2 HPF Switch", MSM8X10_WCD_A_CDC_RX2_B5_CTL, 2, 1, 0),
  1051. SOC_SINGLE("RX3 HPF Switch", MSM8X10_WCD_A_CDC_RX3_B5_CTL, 2, 1, 0),
  1052. SOC_ENUM("RX1 HPF cut off", cf_rxmix1_enum),
  1053. SOC_ENUM("RX2 HPF cut off", cf_rxmix2_enum),
  1054. SOC_ENUM("RX3 HPF cut off", cf_rxmix3_enum),
  1055. SOC_SINGLE_EXT("IIR1 Enable Band1", IIR1, BAND1, 1, 0,
  1056. msm8x10_wcd_get_iir_enable_audio_mixer,
  1057. msm8x10_wcd_put_iir_enable_audio_mixer),
  1058. SOC_SINGLE_EXT("IIR1 Enable Band2", IIR1, BAND2, 1, 0,
  1059. msm8x10_wcd_get_iir_enable_audio_mixer,
  1060. msm8x10_wcd_put_iir_enable_audio_mixer),
  1061. SOC_SINGLE_EXT("IIR1 Enable Band3", IIR1, BAND3, 1, 0,
  1062. msm8x10_wcd_get_iir_enable_audio_mixer,
  1063. msm8x10_wcd_put_iir_enable_audio_mixer),
  1064. SOC_SINGLE_EXT("IIR1 Enable Band4", IIR1, BAND4, 1, 0,
  1065. msm8x10_wcd_get_iir_enable_audio_mixer,
  1066. msm8x10_wcd_put_iir_enable_audio_mixer),
  1067. SOC_SINGLE_EXT("IIR1 Enable Band5", IIR1, BAND5, 1, 0,
  1068. msm8x10_wcd_get_iir_enable_audio_mixer,
  1069. msm8x10_wcd_put_iir_enable_audio_mixer),
  1070. SOC_SINGLE_EXT("IIR2 Enable Band1", IIR2, BAND1, 1, 0,
  1071. msm8x10_wcd_get_iir_enable_audio_mixer,
  1072. msm8x10_wcd_put_iir_enable_audio_mixer),
  1073. SOC_SINGLE_EXT("IIR2 Enable Band2", IIR2, BAND2, 1, 0,
  1074. msm8x10_wcd_get_iir_enable_audio_mixer,
  1075. msm8x10_wcd_put_iir_enable_audio_mixer),
  1076. SOC_SINGLE_EXT("IIR2 Enable Band3", IIR2, BAND3, 1, 0,
  1077. msm8x10_wcd_get_iir_enable_audio_mixer,
  1078. msm8x10_wcd_put_iir_enable_audio_mixer),
  1079. SOC_SINGLE_EXT("IIR2 Enable Band4", IIR2, BAND4, 1, 0,
  1080. msm8x10_wcd_get_iir_enable_audio_mixer,
  1081. msm8x10_wcd_put_iir_enable_audio_mixer),
  1082. SOC_SINGLE_EXT("IIR2 Enable Band5", IIR2, BAND5, 1, 0,
  1083. msm8x10_wcd_get_iir_enable_audio_mixer,
  1084. msm8x10_wcd_put_iir_enable_audio_mixer),
  1085. SOC_SINGLE_MULTI_EXT("IIR1 Band1", IIR1, BAND1, 255, 0, 5,
  1086. msm8x10_wcd_get_iir_band_audio_mixer,
  1087. msm8x10_wcd_put_iir_band_audio_mixer),
  1088. SOC_SINGLE_MULTI_EXT("IIR1 Band2", IIR1, BAND2, 255, 0, 5,
  1089. msm8x10_wcd_get_iir_band_audio_mixer,
  1090. msm8x10_wcd_put_iir_band_audio_mixer),
  1091. SOC_SINGLE_MULTI_EXT("IIR1 Band3", IIR1, BAND3, 255, 0, 5,
  1092. msm8x10_wcd_get_iir_band_audio_mixer,
  1093. msm8x10_wcd_put_iir_band_audio_mixer),
  1094. SOC_SINGLE_MULTI_EXT("IIR1 Band4", IIR1, BAND4, 255, 0, 5,
  1095. msm8x10_wcd_get_iir_band_audio_mixer,
  1096. msm8x10_wcd_put_iir_band_audio_mixer),
  1097. SOC_SINGLE_MULTI_EXT("IIR1 Band5", IIR1, BAND5, 255, 0, 5,
  1098. msm8x10_wcd_get_iir_band_audio_mixer,
  1099. msm8x10_wcd_put_iir_band_audio_mixer),
  1100. SOC_SINGLE_MULTI_EXT("IIR2 Band1", IIR2, BAND1, 255, 0, 5,
  1101. msm8x10_wcd_get_iir_band_audio_mixer,
  1102. msm8x10_wcd_put_iir_band_audio_mixer),
  1103. SOC_SINGLE_MULTI_EXT("IIR2 Band2", IIR2, BAND2, 255, 0, 5,
  1104. msm8x10_wcd_get_iir_band_audio_mixer,
  1105. msm8x10_wcd_put_iir_band_audio_mixer),
  1106. SOC_SINGLE_MULTI_EXT("IIR2 Band3", IIR2, BAND3, 255, 0, 5,
  1107. msm8x10_wcd_get_iir_band_audio_mixer,
  1108. msm8x10_wcd_put_iir_band_audio_mixer),
  1109. SOC_SINGLE_MULTI_EXT("IIR2 Band4", IIR2, BAND4, 255, 0, 5,
  1110. msm8x10_wcd_get_iir_band_audio_mixer,
  1111. msm8x10_wcd_put_iir_band_audio_mixer),
  1112. SOC_SINGLE_MULTI_EXT("IIR2 Band5", IIR2, BAND5, 255, 0, 5,
  1113. msm8x10_wcd_get_iir_band_audio_mixer,
  1114. msm8x10_wcd_put_iir_band_audio_mixer),
  1115. };
  1116. static const char * const rx_mix1_text[] = {
  1117. "ZERO", "IIR1", "IIR2", "RX1", "RX2", "RX3"
  1118. };
  1119. static const char * const rx_mix2_text[] = {
  1120. "ZERO", "IIR1", "IIR2"
  1121. };
  1122. static const char * const dec_mux_text[] = {
  1123. "ZERO", "ADC1", "ADC2", "DMIC1", "DMIC2"
  1124. };
  1125. static const char * const adc2_mux_text[] = {
  1126. "ZERO", "INP2", "INP3"
  1127. };
  1128. static const char * const iir1_inp1_text[] = {
  1129. "ZERO", "DEC1", "DEC2", "RX1", "RX2", "RX3"
  1130. };
  1131. /*
  1132. * There is only one bit to select RX2 (0) or RX3 (1) so add 'ZERO' won't
  1133. * cause any issue to select the right input, but it eliminates that lineout
  1134. * is powered-up when HPH is enabled if the 'ZERO" is used in the disable
  1135. * sequence for lineout.
  1136. */
  1137. static const char * const rx_rdac4_text[] = {
  1138. "ZERO", "RX3", "RX2"
  1139. };
  1140. static const char * const rx_rdac3_text[] = {
  1141. "RX1", "RX2"
  1142. };
  1143. static const struct soc_enum rx_mix1_inp1_chain_enum =
  1144. SOC_ENUM_SINGLE(MSM8X10_WCD_A_CDC_CONN_RX1_B1_CTL, 0, 6, rx_mix1_text);
  1145. static const struct soc_enum rx_mix1_inp2_chain_enum =
  1146. SOC_ENUM_SINGLE(MSM8X10_WCD_A_CDC_CONN_RX1_B1_CTL, 3, 6, rx_mix1_text);
  1147. static const struct soc_enum rx_mix1_inp3_chain_enum =
  1148. SOC_ENUM_SINGLE(MSM8X10_WCD_A_CDC_CONN_RX1_B2_CTL, 0, 6, rx_mix1_text);
  1149. static const struct soc_enum rx2_mix1_inp1_chain_enum =
  1150. SOC_ENUM_SINGLE(MSM8X10_WCD_A_CDC_CONN_RX2_B1_CTL, 0, 6, rx_mix1_text);
  1151. static const struct soc_enum rx2_mix1_inp2_chain_enum =
  1152. SOC_ENUM_SINGLE(MSM8X10_WCD_A_CDC_CONN_RX2_B1_CTL, 3, 6, rx_mix1_text);
  1153. static const struct soc_enum rx3_mix1_inp1_chain_enum =
  1154. SOC_ENUM_SINGLE(MSM8X10_WCD_A_CDC_CONN_RX3_B1_CTL, 0, 6, rx_mix1_text);
  1155. static const struct soc_enum rx3_mix1_inp2_chain_enum =
  1156. SOC_ENUM_SINGLE(MSM8X10_WCD_A_CDC_CONN_RX3_B1_CTL, 3, 6, rx_mix1_text);
  1157. static const struct soc_enum rx1_mix2_inp1_chain_enum =
  1158. SOC_ENUM_SINGLE(MSM8X10_WCD_A_CDC_CONN_RX1_B3_CTL, 0, 3, rx_mix2_text);
  1159. static const struct soc_enum rx2_mix2_inp1_chain_enum =
  1160. SOC_ENUM_SINGLE(MSM8X10_WCD_A_CDC_CONN_RX2_B3_CTL, 0, 3, rx_mix2_text);
  1161. static const struct soc_enum dec1_mux_enum =
  1162. SOC_ENUM_SINGLE(MSM8X10_WCD_A_CDC_CONN_TX_B1_CTL, 0, 5, dec_mux_text);
  1163. static const struct soc_enum dec2_mux_enum =
  1164. SOC_ENUM_SINGLE(MSM8X10_WCD_A_CDC_CONN_TX_B1_CTL, 3, 5, dec_mux_text);
  1165. static const struct soc_enum iir1_inp1_mux_enum =
  1166. SOC_ENUM_SINGLE(MSM8X10_WCD_A_CDC_CONN_EQ1_B1_CTL, 0, 6,
  1167. iir1_inp1_text);
  1168. static const struct soc_enum rx_rdac4_enum =
  1169. SOC_ENUM_SINGLE(MSM8X10_WCD_A_CDC_CONN_LO_DAC_CTL, 0, 3,
  1170. rx_rdac4_text);
  1171. static const struct soc_enum rx_rdac3_enum =
  1172. SOC_ENUM_SINGLE(MSM8X10_WCD_A_CDC_CONN_HPHR_DAC_CTL, 0, 2,
  1173. rx_rdac3_text);
  1174. static const struct soc_enum adc2_enum =
  1175. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(adc2_mux_text), adc2_mux_text);
  1176. static const struct snd_kcontrol_new rx_mix1_inp1_mux =
  1177. SOC_DAPM_ENUM("RX1 MIX1 INP1 Mux", rx_mix1_inp1_chain_enum);
  1178. static const struct snd_kcontrol_new rx_mix1_inp2_mux =
  1179. SOC_DAPM_ENUM("RX1 MIX1 INP2 Mux", rx_mix1_inp2_chain_enum);
  1180. static const struct snd_kcontrol_new rx_mix1_inp3_mux =
  1181. SOC_DAPM_ENUM("RX1 MIX1 INP3 Mux", rx_mix1_inp3_chain_enum);
  1182. static const struct snd_kcontrol_new rx2_mix1_inp1_mux =
  1183. SOC_DAPM_ENUM("RX2 MIX1 INP1 Mux", rx2_mix1_inp1_chain_enum);
  1184. static const struct snd_kcontrol_new rx2_mix1_inp2_mux =
  1185. SOC_DAPM_ENUM("RX2 MIX1 INP2 Mux", rx2_mix1_inp2_chain_enum);
  1186. static const struct snd_kcontrol_new rx3_mix1_inp1_mux =
  1187. SOC_DAPM_ENUM("RX3 MIX1 INP1 Mux", rx3_mix1_inp1_chain_enum);
  1188. static const struct snd_kcontrol_new rx3_mix1_inp2_mux =
  1189. SOC_DAPM_ENUM("RX3 MIX1 INP2 Mux", rx3_mix1_inp2_chain_enum);
  1190. static const struct snd_kcontrol_new rx1_mix2_inp1_mux =
  1191. SOC_DAPM_ENUM("RX1 MIX2 INP1 Mux", rx1_mix2_inp1_chain_enum);
  1192. static const struct snd_kcontrol_new rx2_mix2_inp1_mux =
  1193. SOC_DAPM_ENUM("RX2 MIX2 INP1 Mux", rx2_mix2_inp1_chain_enum);
  1194. static const struct snd_kcontrol_new rx_dac4_mux =
  1195. SOC_DAPM_ENUM("RDAC4 MUX Mux", rx_rdac4_enum);
  1196. static const struct snd_kcontrol_new rx_dac3_mux =
  1197. SOC_DAPM_ENUM("RDAC3 MUX Mux", rx_rdac3_enum);
  1198. static const struct snd_kcontrol_new tx_adc2_mux =
  1199. SOC_DAPM_ENUM("ADC2 MUX Mux", adc2_enum);
  1200. static int msm8x10_wcd_put_dec_enum(struct snd_kcontrol *kcontrol,
  1201. struct snd_ctl_elem_value *ucontrol)
  1202. {
  1203. struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
  1204. struct snd_soc_dapm_widget *w = wlist->widgets[0];
  1205. struct snd_soc_codec *codec = w->codec;
  1206. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  1207. unsigned int dec_mux, decimator;
  1208. char *dec_name = NULL;
  1209. char *widget_name = NULL;
  1210. char *temp;
  1211. u16 tx_mux_ctl_reg;
  1212. u8 adc_dmic_sel = 0x0;
  1213. int ret = 0;
  1214. if (ucontrol->value.enumerated.item[0] > e->max - 1)
  1215. return -EINVAL;
  1216. dec_mux = ucontrol->value.enumerated.item[0];
  1217. widget_name = kstrndup(w->name, 15, GFP_KERNEL);
  1218. if (!widget_name)
  1219. return -ENOMEM;
  1220. temp = widget_name;
  1221. dec_name = strsep(&widget_name, " ");
  1222. widget_name = temp;
  1223. if (!dec_name) {
  1224. dev_err(codec->dev, "%s: Invalid decimator = %s\n",
  1225. __func__, w->name);
  1226. ret = -EINVAL;
  1227. goto out;
  1228. }
  1229. ret = kstrtouint(strpbrk(dec_name, "12"), 10, &decimator);
  1230. if (ret < 0) {
  1231. dev_err(codec->dev, "%s: Invalid decimator = %s\n",
  1232. __func__, dec_name);
  1233. ret = -EINVAL;
  1234. goto out;
  1235. }
  1236. dev_dbg(w->dapm->dev, "%s(): widget = %s decimator = %u dec_mux = %u\n"
  1237. , __func__, w->name, decimator, dec_mux);
  1238. switch (decimator) {
  1239. case 1:
  1240. case 2:
  1241. if ((dec_mux == 3) || (dec_mux == 4))
  1242. adc_dmic_sel = 0x1;
  1243. else
  1244. adc_dmic_sel = 0x0;
  1245. break;
  1246. default:
  1247. dev_err(codec->dev, "%s: Invalid Decimator = %u\n",
  1248. __func__, decimator);
  1249. ret = -EINVAL;
  1250. goto out;
  1251. }
  1252. tx_mux_ctl_reg = MSM8X10_WCD_A_CDC_TX1_MUX_CTL + 32 * (decimator - 1);
  1253. snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x1, adc_dmic_sel);
  1254. ret = snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
  1255. out:
  1256. kfree(widget_name);
  1257. return ret;
  1258. }
  1259. #define MSM8X10_WCD_DEC_ENUM(xname, xenum) \
  1260. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  1261. .info = snd_soc_info_enum_double, \
  1262. .get = snd_soc_dapm_get_enum_double, \
  1263. .put = msm8x10_wcd_put_dec_enum, \
  1264. .private_value = (unsigned long)&xenum }
  1265. static const struct snd_kcontrol_new dec1_mux =
  1266. MSM8X10_WCD_DEC_ENUM("DEC1 MUX Mux", dec1_mux_enum);
  1267. static const struct snd_kcontrol_new dec2_mux =
  1268. MSM8X10_WCD_DEC_ENUM("DEC2 MUX Mux", dec2_mux_enum);
  1269. static const struct snd_kcontrol_new iir1_inp1_mux =
  1270. SOC_DAPM_ENUM("IIR1 INP1 Mux", iir1_inp1_mux_enum);
  1271. static const struct snd_kcontrol_new dac1_switch[] = {
  1272. SOC_DAPM_SINGLE("Switch", MSM8X10_WCD_A_RX_EAR_EN, 5, 1, 0)
  1273. };
  1274. static const struct snd_kcontrol_new hphl_switch[] = {
  1275. SOC_DAPM_SINGLE("Switch", MSM8X10_WCD_A_RX_HPH_L_DAC_CTL, 6, 1, 0)
  1276. };
  1277. static const struct snd_kcontrol_new spkr_switch[] = {
  1278. SOC_DAPM_SINGLE("Switch", MSM8X10_WCD_A_SPKR_DRV_DAC_CTL, 2, 1, 0)
  1279. };
  1280. static void msm8x10_wcd_codec_enable_adc_block(struct snd_soc_codec *codec,
  1281. int enable)
  1282. {
  1283. struct msm8x10_wcd_priv *wcd8x10 = snd_soc_codec_get_drvdata(codec);
  1284. dev_dbg(codec->dev, "%s %d\n", __func__, enable);
  1285. if (enable) {
  1286. wcd8x10->adc_count++;
  1287. snd_soc_update_bits(codec,
  1288. MSM8X10_WCD_A_CDC_ANA_CLK_CTL,
  1289. 0x20, 0x20);
  1290. } else
  1291. wcd8x10->adc_count--;
  1292. }
  1293. static int msm8x10_wcd_codec_enable_adc(struct snd_soc_dapm_widget *w,
  1294. struct snd_kcontrol *kcontrol, int event)
  1295. {
  1296. struct snd_soc_codec *codec = w->codec;
  1297. u16 adc_reg;
  1298. u8 init_bit_shift;
  1299. dev_dbg(codec->dev, "%s %d\n", __func__, event);
  1300. adc_reg = MSM8X10_WCD_A_TX_1_2_TEST_CTL;
  1301. if (w->reg == MSM8X10_WCD_A_TX_1_EN)
  1302. init_bit_shift = 7;
  1303. else if ((w->reg == MSM8X10_WCD_A_TX_2_EN) ||
  1304. (w->reg == MSM8X10_WCD_A_TX_3_EN))
  1305. init_bit_shift = 6;
  1306. else {
  1307. dev_err(codec->dev, "%s: Error, invalid adc register\n",
  1308. __func__);
  1309. return -EINVAL;
  1310. }
  1311. switch (event) {
  1312. case SND_SOC_DAPM_PRE_PMU:
  1313. msm8x10_wcd_codec_enable_adc_block(codec, 1);
  1314. snd_soc_update_bits(codec, adc_reg, 1 << init_bit_shift,
  1315. 1 << init_bit_shift);
  1316. usleep_range(CODEC_DELAY_1_MS, CODEC_DELAY_1_1_MS);
  1317. break;
  1318. case SND_SOC_DAPM_POST_PMU:
  1319. snd_soc_update_bits(codec, adc_reg, 1 << init_bit_shift, 0x00);
  1320. usleep_range(CODEC_DELAY_1_MS, CODEC_DELAY_1_1_MS);
  1321. break;
  1322. case SND_SOC_DAPM_POST_PMD:
  1323. msm8x10_wcd_codec_enable_adc_block(codec, 0);
  1324. break;
  1325. }
  1326. return 0;
  1327. }
  1328. static int msm8x10_wcd_codec_enable_lineout(struct snd_soc_dapm_widget *w,
  1329. struct snd_kcontrol *kcontrol, int event)
  1330. {
  1331. struct snd_soc_codec *codec = w->codec;
  1332. u16 lineout_gain_reg;
  1333. dev_dbg(codec->dev, "%s %d %s\n", __func__, event, w->name);
  1334. switch (w->shift) {
  1335. case 0:
  1336. lineout_gain_reg = MSM8X10_WCD_A_RX_LINE_1_GAIN;
  1337. break;
  1338. default:
  1339. dev_err(codec->dev,
  1340. "%s: Error, incorrect lineout register value\n",
  1341. __func__);
  1342. return -EINVAL;
  1343. }
  1344. switch (event) {
  1345. case SND_SOC_DAPM_PRE_PMU:
  1346. snd_soc_update_bits(codec, lineout_gain_reg, 0x40, 0x40);
  1347. break;
  1348. case SND_SOC_DAPM_POST_PMU:
  1349. dev_dbg(codec->dev, "%s: sleeping 16 ms after %s PA turn on\n",
  1350. __func__, w->name);
  1351. usleep_range(16000, 16100);
  1352. break;
  1353. case SND_SOC_DAPM_POST_PMD:
  1354. snd_soc_update_bits(codec, lineout_gain_reg, 0x40, 0x00);
  1355. break;
  1356. }
  1357. return 0;
  1358. }
  1359. static int msm8x10_wcd_codec_enable_spk_pa(struct snd_soc_dapm_widget *w,
  1360. struct snd_kcontrol *kcontrol, int event)
  1361. {
  1362. dev_dbg(w->codec->dev, "%s %d %s\n", __func__, event, w->name);
  1363. #if defined(CONFIG_MACH_KANAS3G_CTC)
  1364. switch (event) {
  1365. case SND_SOC_DAPM_PRE_PMU:
  1366. dev_dbg(w->codec->dev, "Before power on PA,sleep 5 ms\n");
  1367. msleep(15);
  1368. break;
  1369. case SND_SOC_DAPM_POST_PMD:
  1370. dev_dbg(w->codec->dev, "after power down PA,sleep 5 ms\n");
  1371. msleep(15);
  1372. break;
  1373. default:
  1374. break;
  1375. }
  1376. #endif
  1377. return 0;
  1378. }
  1379. static int msm8x10_wcd_codec_enable_dmic(struct snd_soc_dapm_widget *w,
  1380. struct snd_kcontrol *kcontrol, int event)
  1381. {
  1382. struct snd_soc_codec *codec = w->codec;
  1383. struct msm8x10_wcd_priv *msm8x10_wcd = snd_soc_codec_get_drvdata(codec);
  1384. u8 dmic_clk_en;
  1385. u16 dmic_clk_reg;
  1386. s32 *dmic_clk_cnt;
  1387. unsigned int dmic;
  1388. int ret;
  1389. ret = kstrtouint(strpbrk(w->name, "12"), 10, &dmic);
  1390. if (ret < 0) {
  1391. dev_err(codec->dev,
  1392. "%s: Invalid DMIC line on the codec\n", __func__);
  1393. return -EINVAL;
  1394. }
  1395. switch (dmic) {
  1396. case 1:
  1397. case 2:
  1398. dmic_clk_en = 0x01;
  1399. dmic_clk_cnt = &(msm8x10_wcd->dmic_1_2_clk_cnt);
  1400. dmic_clk_reg = MSM8X10_WCD_A_CDC_CLK_DMIC_B1_CTL;
  1401. dev_dbg(codec->dev,
  1402. "%s() event %d DMIC%d dmic_1_2_clk_cnt %d\n",
  1403. __func__, event, dmic, *dmic_clk_cnt);
  1404. break;
  1405. default:
  1406. dev_err(codec->dev, "%s: Invalid DMIC Selection\n", __func__);
  1407. return -EINVAL;
  1408. }
  1409. switch (event) {
  1410. case SND_SOC_DAPM_PRE_PMU:
  1411. (*dmic_clk_cnt)++;
  1412. if (*dmic_clk_cnt == 1)
  1413. snd_soc_update_bits(codec, dmic_clk_reg,
  1414. dmic_clk_en, dmic_clk_en);
  1415. break;
  1416. case SND_SOC_DAPM_POST_PMD:
  1417. (*dmic_clk_cnt)--;
  1418. if (*dmic_clk_cnt == 0)
  1419. snd_soc_update_bits(codec, dmic_clk_reg,
  1420. dmic_clk_en, 0);
  1421. break;
  1422. }
  1423. return 0;
  1424. }
  1425. static int msm8x10_wcd_codec_enable_micbias(struct snd_soc_dapm_widget *w,
  1426. struct snd_kcontrol *kcontrol, int event)
  1427. {
  1428. struct snd_soc_codec *codec = w->codec;
  1429. struct msm8x10_wcd_priv *msm8x10_wcd = snd_soc_codec_get_drvdata(codec);
  1430. u16 micb_int_reg;
  1431. char *internal1_text = "Internal1";
  1432. char *internal2_text = "Internal2";
  1433. char *internal3_text = "Internal3";
  1434. char *external_text = "External";
  1435. enum wcd9xxx_notify_event e_post_off, e_pre_on, e_post_on;
  1436. dev_dbg(codec->dev, "%s %d\n", __func__, event);
  1437. if ((strnstr(w->name, internal1_text, 30)) ||
  1438. (strnstr(w->name, internal2_text, 30)) ||
  1439. (strnstr(w->name, internal3_text, 30)) ||
  1440. (strnstr(w->name, external_text, 30))) {
  1441. micb_int_reg = MSM8X10_WCD_A_MICB_1_INT_RBIAS;
  1442. e_pre_on = WCD9XXX_EVENT_PRE_MICBIAS_1_ON;
  1443. e_post_on = WCD9XXX_EVENT_POST_MICBIAS_1_ON;
  1444. e_post_off = WCD9XXX_EVENT_POST_MICBIAS_1_OFF;
  1445. } else {
  1446. dev_err(codec->dev,
  1447. "%s: Error, invalid micbias %s\n", __func__, w->name);
  1448. return -EINVAL;
  1449. }
  1450. switch (event) {
  1451. case SND_SOC_DAPM_PRE_PMU:
  1452. /* Let MBHC module know micbias is about to turn ON */
  1453. wcd9xxx_resmgr_notifier_call(&msm8x10_wcd->resmgr, e_pre_on);
  1454. if (strnstr(w->name, internal1_text, 30))
  1455. snd_soc_update_bits(codec, micb_int_reg, 0x80, 0x80);
  1456. else if (strnstr(w->name, internal2_text, 30))
  1457. snd_soc_update_bits(codec, micb_int_reg, 0x10, 0x10);
  1458. else if (strnstr(w->name, internal3_text, 30))
  1459. snd_soc_update_bits(codec, micb_int_reg, 0x2, 0x2);
  1460. /* Always pull up TxFe for TX2 to Micbias */
  1461. snd_soc_update_bits(codec, micb_int_reg, 0x04, 0x04);
  1462. if (++msm8x10_wcd->micb_en_count == 1)
  1463. snd_soc_update_bits(codec, MSM8X10_WCD_A_MICB_1_CTL,
  1464. 0x80, 0x80);
  1465. pr_debug("%s micb_en_count : %d", __func__,
  1466. msm8x10_wcd->micb_en_count);
  1467. break;
  1468. case SND_SOC_DAPM_POST_PMU:
  1469. usleep_range(20000, 20100);
  1470. /* Let MBHC module know so micbias is on */
  1471. wcd9xxx_resmgr_notifier_call(&msm8x10_wcd->resmgr, e_post_on);
  1472. break;
  1473. case SND_SOC_DAPM_POST_PMD:
  1474. if (--msm8x10_wcd->micb_en_count == 0)
  1475. snd_soc_update_bits(codec, MSM8X10_WCD_A_MICB_1_CTL,
  1476. 0x80, 0x00);
  1477. pr_debug("%s micb_en_count : %d", __func__,
  1478. msm8x10_wcd->micb_en_count);
  1479. /* Let MBHC module know so micbias switch to be off */
  1480. wcd9xxx_resmgr_notifier_call(&msm8x10_wcd->resmgr, e_post_off);
  1481. if (strnstr(w->name, internal1_text, 30))
  1482. snd_soc_update_bits(codec, micb_int_reg, 0x80, 0x00);
  1483. else if (strnstr(w->name, internal2_text, 30))
  1484. snd_soc_update_bits(codec, micb_int_reg, 0x10, 0x00);
  1485. else if (strnstr(w->name, internal3_text, 30))
  1486. snd_soc_update_bits(codec, micb_int_reg, 0x2, 0x0);
  1487. /* Disable pull up TxFe for TX2 to Micbias */
  1488. snd_soc_update_bits(codec, micb_int_reg, 0x04, 0x00);
  1489. break;
  1490. }
  1491. return 0;
  1492. }
  1493. static void tx_hpf_corner_freq_callback(struct work_struct *work)
  1494. {
  1495. struct delayed_work *hpf_delayed_work;
  1496. struct hpf_work *hpf_work;
  1497. struct msm8x10_wcd_priv *msm8x10_wcd;
  1498. struct snd_soc_codec *codec;
  1499. u16 tx_mux_ctl_reg;
  1500. u8 hpf_cut_of_freq;
  1501. hpf_delayed_work = to_delayed_work(work);
  1502. hpf_work = container_of(hpf_delayed_work, struct hpf_work, dwork);
  1503. msm8x10_wcd = hpf_work->msm8x10_wcd;
  1504. codec = hpf_work->msm8x10_wcd->codec;
  1505. hpf_cut_of_freq = hpf_work->tx_hpf_cut_of_freq;
  1506. tx_mux_ctl_reg = MSM8X10_WCD_A_CDC_TX1_MUX_CTL +
  1507. (hpf_work->decimator - 1) * 32;
  1508. dev_info(codec->dev, "%s(): decimator %u hpf_cut_of_freq 0x%x\n",
  1509. __func__, hpf_work->decimator, (unsigned int)hpf_cut_of_freq);
  1510. snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x30, hpf_cut_of_freq << 4);
  1511. }
  1512. #define TX_MUX_CTL_CUT_OFF_FREQ_MASK 0x30
  1513. #define CF_MIN_3DB_4HZ 0x0
  1514. #define CF_MIN_3DB_75HZ 0x1
  1515. #define CF_MIN_3DB_150HZ 0x2
  1516. static int msm8x10_wcd_codec_enable_dec(struct snd_soc_dapm_widget *w,
  1517. struct snd_kcontrol *kcontrol, int event)
  1518. {
  1519. struct snd_soc_codec *codec = w->codec;
  1520. unsigned int decimator;
  1521. char *dec_name = NULL;
  1522. char *widget_name = NULL;
  1523. char *temp;
  1524. int ret = 0;
  1525. u16 dec_reset_reg, tx_vol_ctl_reg, tx_mux_ctl_reg;
  1526. u8 dec_hpf_cut_of_freq;
  1527. int offset;
  1528. dev_dbg(codec->dev, "%s %d\n", __func__, event);
  1529. widget_name = kstrndup(w->name, 15, GFP_KERNEL);
  1530. if (!widget_name)
  1531. return -ENOMEM;
  1532. temp = widget_name;
  1533. dec_name = strsep(&widget_name, " ");
  1534. widget_name = temp;
  1535. if (!dec_name) {
  1536. dev_err(codec->dev,
  1537. "%s: Invalid decimator = %s\n", __func__, w->name);
  1538. ret = -EINVAL;
  1539. goto out;
  1540. }
  1541. ret = kstrtouint(strpbrk(dec_name, "12"), 10, &decimator);
  1542. if (ret < 0) {
  1543. dev_err(codec->dev,
  1544. "%s: Invalid decimator = %s\n", __func__, dec_name);
  1545. ret = -EINVAL;
  1546. goto out;
  1547. }
  1548. dev_dbg(codec->dev,
  1549. "%s(): widget = %s dec_name = %s decimator = %u\n", __func__,
  1550. w->name, dec_name, decimator);
  1551. if (w->reg == MSM8X10_WCD_A_CDC_CLK_TX_CLK_EN_B1_CTL) {
  1552. dec_reset_reg = MSM8X10_WCD_A_CDC_CLK_TX_RESET_B1_CTL;
  1553. offset = 0;
  1554. } else {
  1555. dev_err(codec->dev, "%s: Error, incorrect dec\n", __func__);
  1556. ret = -EINVAL;
  1557. goto out;
  1558. }
  1559. tx_vol_ctl_reg = MSM8X10_WCD_A_CDC_TX1_VOL_CTL_CFG +
  1560. 32 * (decimator - 1);
  1561. tx_mux_ctl_reg = MSM8X10_WCD_A_CDC_TX1_MUX_CTL +
  1562. 32 * (decimator - 1);
  1563. switch (event) {
  1564. case SND_SOC_DAPM_PRE_PMU:
  1565. /* Enableable TX digital mute */
  1566. snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x01, 0x01);
  1567. snd_soc_update_bits(codec, dec_reset_reg, 1 << w->shift,
  1568. 1 << w->shift);
  1569. snd_soc_update_bits(codec, dec_reset_reg, 1 << w->shift, 0x0);
  1570. dec_hpf_cut_of_freq = snd_soc_read(codec, tx_mux_ctl_reg);
  1571. dec_hpf_cut_of_freq = (dec_hpf_cut_of_freq & 0x30) >> 4;
  1572. tx_hpf_work[decimator - 1].tx_hpf_cut_of_freq =
  1573. dec_hpf_cut_of_freq;
  1574. if ((dec_hpf_cut_of_freq != CF_MIN_3DB_150HZ)) {
  1575. /* set cut of freq to CF_MIN_3DB_150HZ (0x1); */
  1576. snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x30,
  1577. CF_MIN_3DB_150HZ << 4);
  1578. }
  1579. /* enable HPF */
  1580. snd_soc_update_bits(codec, tx_mux_ctl_reg , 0x08, 0x00);
  1581. break;
  1582. case SND_SOC_DAPM_POST_PMU:
  1583. /* Disable TX digital mute */
  1584. snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x01, 0x00);
  1585. if (tx_hpf_work[decimator - 1].tx_hpf_cut_of_freq !=
  1586. CF_MIN_3DB_150HZ) {
  1587. schedule_delayed_work(&tx_hpf_work[decimator - 1].dwork,
  1588. msecs_to_jiffies(300));
  1589. }
  1590. /* apply the digital gain after the decimator is enabled*/
  1591. if ((w->shift) < ARRAY_SIZE(tx_digital_gain_reg))
  1592. snd_soc_write(codec,
  1593. tx_digital_gain_reg[w->shift + offset],
  1594. snd_soc_read(codec,
  1595. tx_digital_gain_reg[w->shift + offset])
  1596. );
  1597. break;
  1598. case SND_SOC_DAPM_PRE_PMD:
  1599. snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x01, 0x01);
  1600. cancel_delayed_work_sync(&tx_hpf_work[decimator - 1].dwork);
  1601. break;
  1602. case SND_SOC_DAPM_POST_PMD:
  1603. snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x08, 0x08);
  1604. snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x30,
  1605. (tx_hpf_work[decimator - 1].tx_hpf_cut_of_freq) << 4);
  1606. break;
  1607. }
  1608. out:
  1609. kfree(widget_name);
  1610. return ret;
  1611. }
  1612. static int msm8x10_wcd_codec_enable_interpolator(struct snd_soc_dapm_widget *w,
  1613. struct snd_kcontrol *kcontrol,
  1614. int event)
  1615. {
  1616. struct snd_soc_codec *codec = w->codec;
  1617. dev_dbg(codec->dev, "%s %d %s\n", __func__, event, w->name);
  1618. switch (event) {
  1619. case SND_SOC_DAPM_PRE_PMU:
  1620. snd_soc_update_bits(codec, MSM8X10_WCD_A_CDC_CLK_RX_RESET_CTL,
  1621. 1 << w->shift, 1 << w->shift);
  1622. snd_soc_update_bits(codec, MSM8X10_WCD_A_CDC_CLK_RX_RESET_CTL,
  1623. 1 << w->shift, 0x0);
  1624. break;
  1625. case SND_SOC_DAPM_POST_PMU:
  1626. /* apply the digital gain after the interpolator is enabled*/
  1627. if ((w->shift) < ARRAY_SIZE(rx_digital_gain_reg))
  1628. snd_soc_write(codec,
  1629. rx_digital_gain_reg[w->shift],
  1630. snd_soc_read(codec,
  1631. rx_digital_gain_reg[w->shift])
  1632. );
  1633. break;
  1634. }
  1635. return 0;
  1636. }
  1637. /* The register address is the same as other codec so it can use resmgr */
  1638. static int msm8x10_wcd_codec_enable_rx_bias(struct snd_soc_dapm_widget *w,
  1639. struct snd_kcontrol *kcontrol, int event)
  1640. {
  1641. struct snd_soc_codec *codec = w->codec;
  1642. struct msm8x10_wcd_priv *msm8x10_wcd = snd_soc_codec_get_drvdata(codec);
  1643. msm8x10_wcd->resmgr.codec = codec;
  1644. dev_dbg(codec->dev, "%s %d\n", __func__, event);
  1645. switch (event) {
  1646. case SND_SOC_DAPM_PRE_PMU:
  1647. wcd9xxx_resmgr_enable_rx_bias(&msm8x10_wcd->resmgr, 1);
  1648. break;
  1649. case SND_SOC_DAPM_POST_PMD:
  1650. wcd9xxx_resmgr_enable_rx_bias(&msm8x10_wcd->resmgr, 0);
  1651. break;
  1652. }
  1653. return 0;
  1654. }
  1655. static int msm8x10_wcd_hphr_dac_event(struct snd_soc_dapm_widget *w,
  1656. struct snd_kcontrol *kcontrol, int event)
  1657. {
  1658. struct snd_soc_codec *codec = w->codec;
  1659. dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event);
  1660. switch (event) {
  1661. case SND_SOC_DAPM_PRE_PMU:
  1662. snd_soc_update_bits(codec, w->reg, 0x40, 0x40);
  1663. break;
  1664. case SND_SOC_DAPM_POST_PMD:
  1665. snd_soc_update_bits(codec, w->reg, 0x40, 0x00);
  1666. break;
  1667. }
  1668. return 0;
  1669. }
  1670. static int msm8x10_wcd_hph_pa_event(struct snd_soc_dapm_widget *w,
  1671. struct snd_kcontrol *kcontrol, int event)
  1672. {
  1673. struct snd_soc_codec *codec = w->codec;
  1674. struct msm8x10_wcd_priv *msm8x10_wcd = snd_soc_codec_get_drvdata(codec);
  1675. enum wcd9xxx_notify_event e_pre_on, e_post_off;
  1676. dev_dbg(codec->dev, "%s: %s event = %d\n", __func__, w->name, event);
  1677. if (w->shift == 5) {
  1678. e_pre_on = WCD9XXX_EVENT_PRE_HPHR_PA_ON;
  1679. e_post_off = WCD9XXX_EVENT_POST_HPHR_PA_OFF;
  1680. } else if (w->shift == 4) {
  1681. e_pre_on = WCD9XXX_EVENT_PRE_HPHL_PA_ON;
  1682. e_post_off = WCD9XXX_EVENT_POST_HPHL_PA_OFF;
  1683. } else {
  1684. dev_err(codec->dev,
  1685. "%s: Invalid w->shift %d\n", __func__, w->shift);
  1686. return -EINVAL;
  1687. }
  1688. switch (event) {
  1689. case SND_SOC_DAPM_PRE_PMU:
  1690. /* Let MBHC module know PA is turning on */
  1691. wcd9xxx_resmgr_notifier_call(&msm8x10_wcd->resmgr, e_pre_on);
  1692. break;
  1693. case SND_SOC_DAPM_POST_PMU:
  1694. usleep_range(10000, 10100);
  1695. break;
  1696. case SND_SOC_DAPM_POST_PMD:
  1697. /* Let MBHC module know PA turned off */
  1698. wcd9xxx_resmgr_notifier_call(&msm8x10_wcd->resmgr, e_post_off);
  1699. dev_dbg(codec->dev,
  1700. "%s: sleep 10 ms after %s PA disable.\n", __func__,
  1701. w->name);
  1702. usleep_range(10000, 10100);
  1703. break;
  1704. }
  1705. return 0;
  1706. }
  1707. static int msm8x10_wcd_lineout_dac_event(struct snd_soc_dapm_widget *w,
  1708. struct snd_kcontrol *kcontrol, int event)
  1709. {
  1710. struct snd_soc_codec *codec = w->codec;
  1711. dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event);
  1712. switch (event) {
  1713. case SND_SOC_DAPM_PRE_PMU:
  1714. snd_soc_update_bits(codec, w->reg, 0x40, 0x40);
  1715. break;
  1716. case SND_SOC_DAPM_POST_PMD:
  1717. snd_soc_update_bits(codec, w->reg, 0x40, 0x00);
  1718. break;
  1719. }
  1720. return 0;
  1721. }
  1722. static const struct snd_soc_dapm_route audio_map[] = {
  1723. {"RX_I2S_CLK", NULL, "CDC_CONN"},
  1724. {"I2S RX1", NULL, "RX_I2S_CLK"},
  1725. {"I2S RX2", NULL, "RX_I2S_CLK"},
  1726. {"I2S RX3", NULL, "RX_I2S_CLK"},
  1727. {"I2S TX1", NULL, "TX_I2S_CLK"},
  1728. {"I2S TX2", NULL, "TX_I2S_CLK"},
  1729. {"I2S TX1", NULL, "DEC1 MUX"},
  1730. {"I2S TX2", NULL, "DEC2 MUX"},
  1731. /* Earpiece (RX MIX1) */
  1732. {"EAR", NULL, "EAR PA"},
  1733. {"EAR PA", NULL, "DAC1"},
  1734. {"DAC1", NULL, "CP"},
  1735. /* Clocks for playback path */
  1736. {"DAC1", NULL, "EAR CLK"},
  1737. {"HPHL DAC", NULL, "HPHL CLK"},
  1738. {"HPHR DAC", NULL, "HPHR CLK"},
  1739. {"SPK DAC", NULL, "SPK CLK"},
  1740. {"LINEOUT DAC", NULL, "LINEOUT CLK"},
  1741. /* Headset (RX MIX1 and RX MIX2) */
  1742. {"HEADPHONE", NULL, "HPHL"},
  1743. {"HEADPHONE", NULL, "HPHR"},
  1744. {"HPHL", NULL, "HPHL DAC"},
  1745. {"HPHR", NULL, "HPHR DAC"},
  1746. {"HPHL DAC", NULL, "CP"},
  1747. {"HPHR DAC", NULL, "CP"},
  1748. {"SPK DAC", NULL, "CP"},
  1749. {"DAC1", "Switch", "RX1 CHAIN"},
  1750. {"HPHL DAC", "Switch", "RX1 CHAIN"},
  1751. {"HPHR DAC", NULL, "RDAC3 MUX"},
  1752. {"RDAC3 MUX", "RX1", "RX1 CHAIN"},
  1753. {"RDAC3 MUX", "RX2", "RX2 CHAIN"},
  1754. {"LINEOUT", NULL, "LINEOUT PA"},
  1755. {"SPK_OUT", NULL, "SPK PA"},
  1756. {"LINEOUT PA", NULL, "CP"},
  1757. {"LINEOUT PA", NULL, "LINEOUT DAC"},
  1758. {"LINEOUT DAC", NULL, "RDAC4 MUX"},
  1759. {"RDAC4 MUX", "RX2", "RX2 CHAIN"},
  1760. {"RDAC4 MUX", "RX3", "RX3 CHAIN"},
  1761. {"CP", NULL, "CP_REGULATOR"},
  1762. {"CP", NULL, "RX_BIAS"},
  1763. {"SPK PA", NULL, "SPK DAC"},
  1764. {"SPK DAC", "Switch", "RX3 CHAIN"},
  1765. {"RX1 CHAIN", NULL, "RX1 CLK"},
  1766. {"RX2 CHAIN", NULL, "RX2 CLK"},
  1767. {"RX3 CHAIN", NULL, "RX3 CLK"},
  1768. {"RX1 CHAIN", NULL, "RX1 MIX2"},
  1769. {"RX2 CHAIN", NULL, "RX2 MIX2"},
  1770. {"RX3 CHAIN", NULL, "RX3 MIX1"},
  1771. {"RX1 MIX1", NULL, "RX1 MIX1 INP1"},
  1772. {"RX1 MIX1", NULL, "RX1 MIX1 INP2"},
  1773. {"RX1 MIX1", NULL, "RX1 MIX1 INP3"},
  1774. {"RX2 MIX1", NULL, "RX2 MIX1 INP1"},
  1775. {"RX2 MIX1", NULL, "RX2 MIX1 INP2"},
  1776. {"RX3 MIX1", NULL, "RX3 MIX1 INP1"},
  1777. {"RX3 MIX1", NULL, "RX3 MIX1 INP2"},
  1778. {"RX1 MIX2", NULL, "RX1 MIX1"},
  1779. {"RX1 MIX2", NULL, "RX1 MIX2 INP1"},
  1780. {"RX2 MIX2", NULL, "RX2 MIX1"},
  1781. {"RX2 MIX2", NULL, "RX2 MIX2 INP1"},
  1782. {"RX1 MIX1 INP1", "RX1", "I2S RX1"},
  1783. {"RX1 MIX1 INP1", "RX2", "I2S RX2"},
  1784. {"RX1 MIX1 INP1", "RX3", "I2S RX3"},
  1785. {"RX1 MIX1 INP1", "IIR1", "IIR1"},
  1786. {"RX1 MIX1 INP2", "RX1", "I2S RX1"},
  1787. {"RX1 MIX1 INP2", "RX2", "I2S RX2"},
  1788. {"RX1 MIX1 INP2", "RX3", "I2S RX3"},
  1789. {"RX1 MIX1 INP2", "IIR1", "IIR1"},
  1790. {"RX1 MIX1 INP3", "RX1", "I2S RX1"},
  1791. {"RX1 MIX1 INP3", "RX2", "I2S RX2"},
  1792. {"RX1 MIX1 INP3", "RX3", "I2S RX3"},
  1793. {"RX2 MIX1 INP1", "RX1", "I2S RX1"},
  1794. {"RX2 MIX1 INP1", "RX2", "I2S RX2"},
  1795. {"RX2 MIX1 INP1", "RX3", "I2S RX3"},
  1796. {"RX2 MIX1 INP1", "IIR1", "IIR1"},
  1797. {"RX2 MIX1 INP2", "RX1", "I2S RX1"},
  1798. {"RX2 MIX1 INP2", "RX2", "I2S RX2"},
  1799. {"RX2 MIX1 INP2", "RX3", "I2S RX3"},
  1800. {"RX2 MIX1 INP2", "IIR1", "IIR1"},
  1801. {"RX3 MIX1 INP1", "RX1", "I2S RX1"},
  1802. {"RX3 MIX1 INP1", "RX2", "I2S RX2"},
  1803. {"RX3 MIX1 INP1", "RX3", "I2S RX3"},
  1804. {"RX3 MIX1 INP1", "IIR1", "IIR1"},
  1805. {"RX3 MIX1 INP2", "RX1", "I2S RX1"},
  1806. {"RX3 MIX1 INP2", "RX2", "I2S RX2"},
  1807. {"RX3 MIX1 INP2", "RX3", "I2S RX3"},
  1808. {"RX3 MIX1 INP2", "IIR1", "IIR1"},
  1809. {"RX1 MIX2 INP1", "IIR1", "IIR1"},
  1810. {"RX2 MIX2 INP1", "IIR1", "IIR1"},
  1811. /* Decimator Inputs */
  1812. {"DEC1 MUX", "DMIC1", "DMIC1"},
  1813. {"DEC1 MUX", "DMIC2", "DMIC2"},
  1814. {"DEC1 MUX", "ADC1", "ADC1"},
  1815. {"DEC1 MUX", "ADC2", "ADC2"},
  1816. {"DEC1 MUX", NULL, "CDC_CONN"},
  1817. {"DEC2 MUX", "DMIC1", "DMIC1"},
  1818. {"DEC2 MUX", "DMIC2", "DMIC2"},
  1819. {"DEC2 MUX", "ADC1", "ADC1"},
  1820. {"DEC2 MUX", "ADC2", "ADC2"},
  1821. {"DEC2 MUX", NULL, "CDC_CONN"},
  1822. {"ADC2", NULL, "ADC2 MUX"},
  1823. {"ADC2 MUX", "INP2", "ADC2_INP2"},
  1824. {"ADC2 MUX", "INP3", "ADC2_INP3"},
  1825. /* ADC Connections */
  1826. {"ADC1", NULL, "AMIC1"},
  1827. {"ADC2_INP2", NULL, "AMIC2"},
  1828. {"ADC2_INP3", NULL, "AMIC3"},
  1829. {"IIR1", NULL, "IIR1 INP1 MUX"},
  1830. {"IIR1 INP1 MUX", "DEC1", "DEC1 MUX"},
  1831. {"IIR1 INP1 MUX", "DEC2", "DEC2 MUX"},
  1832. {"MIC BIAS Internal1", NULL, "INT_LDO_H"},
  1833. {"MIC BIAS Internal2", NULL, "INT_LDO_H"},
  1834. {"MIC BIAS External", NULL, "INT_LDO_H"},
  1835. {"MIC BIAS Internal1", NULL, "MICBIAS_REGULATOR"},
  1836. {"MIC BIAS Internal2", NULL, "MICBIAS_REGULATOR"},
  1837. {"MIC BIAS External", NULL, "MICBIAS_REGULATOR"},
  1838. };
  1839. static int msm8x10_wcd_startup(struct snd_pcm_substream *substream,
  1840. struct snd_soc_dai *dai)
  1841. {
  1842. dev_dbg(dai->codec->dev, "%s(): substream = %s stream = %d\n",
  1843. __func__,
  1844. substream->name, substream->stream);
  1845. return 0;
  1846. }
  1847. static void msm8x10_wcd_shutdown(struct snd_pcm_substream *substream,
  1848. struct snd_soc_dai *dai)
  1849. {
  1850. dev_dbg(dai->codec->dev,
  1851. "%s(): substream = %s stream = %d\n" , __func__,
  1852. substream->name, substream->stream);
  1853. }
  1854. int msm8x10_wcd_mclk_enable(struct snd_soc_codec *codec,
  1855. int mclk_enable, bool dapm)
  1856. {
  1857. struct msm8x10_wcd_priv *msm8x10_wcd = snd_soc_codec_get_drvdata(codec);
  1858. dev_dbg(codec->dev, "%s: mclk_enable = %u, dapm = %d\n",
  1859. __func__, mclk_enable, dapm);
  1860. WCD9XXX_BG_CLK_LOCK(&msm8x10_wcd->resmgr);
  1861. if (mclk_enable) {
  1862. wcd9xxx_resmgr_get_bandgap(&msm8x10_wcd->resmgr,
  1863. WCD9XXX_BANDGAP_AUDIO_MODE);
  1864. wcd9xxx_resmgr_get_clk_block(&msm8x10_wcd->resmgr,
  1865. WCD9XXX_CLK_MCLK);
  1866. } else {
  1867. wcd9xxx_resmgr_put_clk_block(&msm8x10_wcd->resmgr,
  1868. WCD9XXX_CLK_MCLK);
  1869. wcd9xxx_resmgr_put_bandgap(&msm8x10_wcd->resmgr,
  1870. WCD9XXX_BANDGAP_AUDIO_MODE);
  1871. }
  1872. WCD9XXX_BG_CLK_UNLOCK(&msm8x10_wcd->resmgr);
  1873. return 0;
  1874. }
  1875. static int msm8x10_wcd_set_dai_sysclk(struct snd_soc_dai *dai,
  1876. int clk_id, unsigned int freq, int dir)
  1877. {
  1878. dev_dbg(dai->codec->dev, "%s\n", __func__);
  1879. return 0;
  1880. }
  1881. static int msm8x10_wcd_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
  1882. {
  1883. dev_dbg(dai->codec->dev, "%s\n", __func__);
  1884. return 0;
  1885. }
  1886. static int msm8x10_wcd_set_channel_map(struct snd_soc_dai *dai,
  1887. unsigned int tx_num, unsigned int *tx_slot,
  1888. unsigned int rx_num, unsigned int *rx_slot)
  1889. {
  1890. dev_dbg(dai->codec->dev, "%s\n", __func__);
  1891. return 0;
  1892. }
  1893. static int msm8x10_wcd_get_channel_map(struct snd_soc_dai *dai,
  1894. unsigned int *tx_num, unsigned int *tx_slot,
  1895. unsigned int *rx_num, unsigned int *rx_slot)
  1896. {
  1897. dev_dbg(dai->codec->dev, "%s\n", __func__);
  1898. return 0;
  1899. }
  1900. static int msm8x10_wcd_set_interpolator_rate(struct snd_soc_dai *dai,
  1901. u8 rx_fs_rate_reg_val, u32 sample_rate)
  1902. {
  1903. return 0;
  1904. }
  1905. static int msm8x10_wcd_set_decimator_rate(struct snd_soc_dai *dai,
  1906. u8 tx_fs_rate_reg_val, u32 sample_rate)
  1907. {
  1908. return 0;
  1909. }
  1910. static int msm8x10_wcd_hw_params(struct snd_pcm_substream *substream,
  1911. struct snd_pcm_hw_params *params,
  1912. struct snd_soc_dai *dai)
  1913. {
  1914. u8 tx_fs_rate, rx_fs_rate;
  1915. int ret;
  1916. dev_dbg(dai->codec->dev,
  1917. "%s: dai_name = %s DAI-ID %x rate %d num_ch %d\n", __func__,
  1918. dai->name, dai->id, params_rate(params),
  1919. params_channels(params));
  1920. switch (params_rate(params)) {
  1921. case 8000:
  1922. tx_fs_rate = 0x00;
  1923. rx_fs_rate = 0x00;
  1924. break;
  1925. case 16000:
  1926. tx_fs_rate = 0x01;
  1927. rx_fs_rate = 0x20;
  1928. break;
  1929. case 32000:
  1930. tx_fs_rate = 0x02;
  1931. rx_fs_rate = 0x40;
  1932. break;
  1933. case 48000:
  1934. tx_fs_rate = 0x03;
  1935. rx_fs_rate = 0x60;
  1936. break;
  1937. case 96000:
  1938. tx_fs_rate = 0x04;
  1939. rx_fs_rate = 0x80;
  1940. break;
  1941. case 192000:
  1942. tx_fs_rate = 0x05;
  1943. rx_fs_rate = 0xA0;
  1944. break;
  1945. default:
  1946. dev_err(dai->codec->dev,
  1947. "%s: Invalid sampling rate %d\n", __func__,
  1948. params_rate(params));
  1949. return -EINVAL;
  1950. }
  1951. switch (substream->stream) {
  1952. case SNDRV_PCM_STREAM_CAPTURE:
  1953. ret = msm8x10_wcd_set_decimator_rate(dai, tx_fs_rate,
  1954. params_rate(params));
  1955. if (ret < 0) {
  1956. dev_err(dai->codec->dev,
  1957. "%s: set decimator rate failed %d\n", __func__,
  1958. ret);
  1959. return ret;
  1960. }
  1961. break;
  1962. case SNDRV_PCM_STREAM_PLAYBACK:
  1963. ret = msm8x10_wcd_set_interpolator_rate(dai, rx_fs_rate,
  1964. params_rate(params));
  1965. if (ret < 0) {
  1966. dev_err(dai->codec->dev,
  1967. "%s: set decimator rate failed %d\n", __func__,
  1968. ret);
  1969. return ret;
  1970. }
  1971. break;
  1972. default:
  1973. dev_err(dai->codec->dev,
  1974. "%s: Invalid stream type %d\n", __func__,
  1975. substream->stream);
  1976. return -EINVAL;
  1977. }
  1978. return 0;
  1979. }
  1980. static struct snd_soc_dai_ops msm8x10_wcd_dai_ops = {
  1981. .startup = msm8x10_wcd_startup,
  1982. .shutdown = msm8x10_wcd_shutdown,
  1983. .hw_params = msm8x10_wcd_hw_params,
  1984. .set_sysclk = msm8x10_wcd_set_dai_sysclk,
  1985. .set_fmt = msm8x10_wcd_set_dai_fmt,
  1986. .set_channel_map = msm8x10_wcd_set_channel_map,
  1987. .get_channel_map = msm8x10_wcd_get_channel_map,
  1988. };
  1989. static struct snd_soc_dai_driver msm8x10_wcd_i2s_dai[] = {
  1990. {
  1991. .name = "msm8x10_wcd_i2s_rx1",
  1992. .id = AIF1_PB,
  1993. .playback = {
  1994. .stream_name = "AIF1 Playback",
  1995. .rates = MSM8X10_WCD_RATES,
  1996. .formats = MSM8X10_WCD_FORMATS,
  1997. .rate_max = 192000,
  1998. .rate_min = 8000,
  1999. .channels_min = 1,
  2000. .channels_max = 3,
  2001. },
  2002. .ops = &msm8x10_wcd_dai_ops,
  2003. },
  2004. {
  2005. .name = "msm8x10_wcd_i2s_tx1",
  2006. .id = AIF1_CAP,
  2007. .capture = {
  2008. .stream_name = "AIF1 Capture",
  2009. .rates = MSM8X10_WCD_RATES,
  2010. .formats = MSM8X10_WCD_FORMATS,
  2011. .rate_max = 192000,
  2012. .rate_min = 8000,
  2013. .channels_min = 1,
  2014. .channels_max = 4,
  2015. },
  2016. .ops = &msm8x10_wcd_dai_ops,
  2017. },
  2018. };
  2019. static int msm8x10_wcd_codec_enable_ear_pa(struct snd_soc_dapm_widget *w,
  2020. struct snd_kcontrol *kcontrol, int event)
  2021. {
  2022. switch (event) {
  2023. case SND_SOC_DAPM_PRE_PMU:
  2024. snd_soc_update_bits(w->codec, MSM8X10_WCD_A_CDC_ANA_CLK_CTL,
  2025. 0x4, 0x4);
  2026. break;
  2027. case SND_SOC_DAPM_POST_PMU:
  2028. dev_dbg(w->codec->dev,
  2029. "%s: Sleeping 20ms after enabling EAR PA\n",
  2030. __func__);
  2031. msleep(20);
  2032. break;
  2033. case SND_SOC_DAPM_POST_PMD:
  2034. dev_dbg(w->codec->dev,
  2035. "%s: Sleeping 20ms after disabling EAR PA\n",
  2036. __func__);
  2037. snd_soc_update_bits(w->codec, MSM8X10_WCD_A_CDC_ANA_CLK_CTL,
  2038. 0x4, 0x0);
  2039. msleep(20);
  2040. break;
  2041. }
  2042. return 0;
  2043. }
  2044. static const struct snd_soc_dapm_widget msm8x10_wcd_dapm_widgets[] = {
  2045. /*RX stuff */
  2046. SND_SOC_DAPM_OUTPUT("EAR"),
  2047. SND_SOC_DAPM_PGA_E("EAR PA", MSM8X10_WCD_A_RX_EAR_EN, 4, 0, NULL, 0,
  2048. msm8x10_wcd_codec_enable_ear_pa, SND_SOC_DAPM_PRE_PMU |
  2049. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  2050. SND_SOC_DAPM_MIXER("DAC1", MSM8X10_WCD_A_RX_EAR_EN, 6, 0, dac1_switch,
  2051. ARRAY_SIZE(dac1_switch)),
  2052. SND_SOC_DAPM_AIF_IN("I2S RX1", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0),
  2053. SND_SOC_DAPM_AIF_IN("I2S RX2", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0),
  2054. SND_SOC_DAPM_AIF_IN("I2S RX3", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0),
  2055. SND_SOC_DAPM_SUPPLY("INT_LDO_H", SND_SOC_NOPM, 1, 0, NULL, 0),
  2056. SND_SOC_DAPM_OUTPUT("HEADPHONE"),
  2057. SND_SOC_DAPM_PGA_E("HPHL", MSM8X10_WCD_A_RX_HPH_CNP_EN,
  2058. 5, 0, NULL, 0,
  2059. msm8x10_wcd_hph_pa_event, SND_SOC_DAPM_PRE_PMU |
  2060. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  2061. SND_SOC_DAPM_MIXER("HPHL DAC", MSM8X10_WCD_A_RX_HPH_L_DAC_CTL,
  2062. 7, 0,
  2063. hphl_switch, ARRAY_SIZE(hphl_switch)),
  2064. SND_SOC_DAPM_PGA_E("HPHR", MSM8X10_WCD_A_RX_HPH_CNP_EN,
  2065. 4, 0, NULL, 0,
  2066. msm8x10_wcd_hph_pa_event, SND_SOC_DAPM_PRE_PMU |
  2067. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  2068. SND_SOC_DAPM_DAC_E("HPHR DAC", NULL, MSM8X10_WCD_A_RX_HPH_R_DAC_CTL,
  2069. 7, 0,
  2070. msm8x10_wcd_hphr_dac_event,
  2071. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2072. SND_SOC_DAPM_MIXER("SPK DAC", SND_SOC_NOPM, 0, 0,
  2073. spkr_switch, ARRAY_SIZE(spkr_switch)),
  2074. /* Speaker */
  2075. SND_SOC_DAPM_OUTPUT("LINEOUT"),
  2076. SND_SOC_DAPM_OUTPUT("SPK_OUT"),
  2077. SND_SOC_DAPM_PGA_E("LINEOUT PA", MSM8X10_WCD_A_RX_LINE_CNP_EN,
  2078. 0, 0, NULL, 0, msm8x10_wcd_codec_enable_lineout,
  2079. SND_SOC_DAPM_PRE_PMU |
  2080. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  2081. SND_SOC_DAPM_PGA_E("SPK PA", MSM8X10_WCD_A_SPKR_DRV_EN,
  2082. 7, 0 , NULL, 0, msm8x10_wcd_codec_enable_spk_pa,
  2083. SND_SOC_DAPM_PRE_PMU |
  2084. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  2085. SND_SOC_DAPM_DAC_E("LINEOUT DAC", NULL,
  2086. MSM8X10_WCD_A_RX_LINE_1_DAC_CTL, 7, 0,
  2087. msm8x10_wcd_lineout_dac_event,
  2088. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2089. SND_SOC_DAPM_MIXER("RX1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  2090. SND_SOC_DAPM_MIXER("RX2 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  2091. SND_SOC_DAPM_MIXER_E("RX1 MIX2",
  2092. MSM8X10_WCD_A_CDC_CLK_RX_B1_CTL, 0, 0, NULL,
  2093. 0, msm8x10_wcd_codec_enable_interpolator, SND_SOC_DAPM_PRE_PMU |
  2094. SND_SOC_DAPM_POST_PMU),
  2095. SND_SOC_DAPM_MIXER_E("RX2 MIX2",
  2096. MSM8X10_WCD_A_CDC_CLK_RX_B1_CTL, 1, 0, NULL,
  2097. 0, msm8x10_wcd_codec_enable_interpolator, SND_SOC_DAPM_PRE_PMU |
  2098. SND_SOC_DAPM_POST_PMU),
  2099. SND_SOC_DAPM_MIXER_E("RX3 MIX1",
  2100. MSM8X10_WCD_A_CDC_CLK_RX_B1_CTL, 2, 0, NULL,
  2101. 0, msm8x10_wcd_codec_enable_interpolator, SND_SOC_DAPM_PRE_PMU |
  2102. SND_SOC_DAPM_POST_PMU),
  2103. SND_SOC_DAPM_SUPPLY("RX1 CLK", MSM8X10_WCD_A_CDC_DIG_CLK_CTL,
  2104. 0, 0, NULL, 0),
  2105. SND_SOC_DAPM_SUPPLY("RX2 CLK", MSM8X10_WCD_A_CDC_DIG_CLK_CTL,
  2106. 1, 0, NULL, 0),
  2107. SND_SOC_DAPM_SUPPLY("RX3 CLK", MSM8X10_WCD_A_CDC_DIG_CLK_CTL,
  2108. 2, 0, NULL, 0),
  2109. SND_SOC_DAPM_MIXER("RX1 CHAIN", MSM8X10_WCD_A_CDC_RX1_B6_CTL,
  2110. 5, 0, NULL, 0),
  2111. SND_SOC_DAPM_MIXER("RX2 CHAIN", MSM8X10_WCD_A_CDC_RX2_B6_CTL,
  2112. 5, 0, NULL, 0),
  2113. SND_SOC_DAPM_MIXER("RX3 CHAIN", MSM8X10_WCD_A_CDC_RX3_B6_CTL,
  2114. 5, 0, NULL, 0),
  2115. SND_SOC_DAPM_SUPPLY("HPHR CLK", MSM8X10_WCD_A_CDC_ANA_CLK_CTL,
  2116. 0, 0, NULL, 0),
  2117. SND_SOC_DAPM_SUPPLY("HPHL CLK", MSM8X10_WCD_A_CDC_ANA_CLK_CTL,
  2118. 1, 0, NULL, 0),
  2119. SND_SOC_DAPM_SUPPLY("EAR CLK", MSM8X10_WCD_A_CDC_ANA_CLK_CTL,
  2120. 6, 0, NULL, 0),
  2121. SND_SOC_DAPM_SUPPLY("LINEOUT CLK", MSM8X10_WCD_A_CDC_ANA_CLK_CTL,
  2122. 3, 0, NULL, 0),
  2123. SND_SOC_DAPM_SUPPLY("SPK CLK", MSM8X10_WCD_A_CDC_ANA_CLK_CTL,
  2124. 4, 0, NULL, 0),
  2125. SND_SOC_DAPM_MUX("RX1 MIX1 INP1", SND_SOC_NOPM, 0, 0,
  2126. &rx_mix1_inp1_mux),
  2127. SND_SOC_DAPM_MUX("RX1 MIX1 INP2", SND_SOC_NOPM, 0, 0,
  2128. &rx_mix1_inp2_mux),
  2129. SND_SOC_DAPM_MUX("RX1 MIX1 INP3", SND_SOC_NOPM, 0, 0,
  2130. &rx_mix1_inp3_mux),
  2131. SND_SOC_DAPM_MUX("RX2 MIX1 INP1", SND_SOC_NOPM, 0, 0,
  2132. &rx2_mix1_inp1_mux),
  2133. SND_SOC_DAPM_MUX("RX2 MIX1 INP2", SND_SOC_NOPM, 0, 0,
  2134. &rx2_mix1_inp2_mux),
  2135. SND_SOC_DAPM_MUX("RX3 MIX1 INP1", SND_SOC_NOPM, 0, 0,
  2136. &rx3_mix1_inp1_mux),
  2137. SND_SOC_DAPM_MUX("RX3 MIX1 INP2", SND_SOC_NOPM, 0, 0,
  2138. &rx3_mix1_inp2_mux),
  2139. SND_SOC_DAPM_MUX("RX1 MIX2 INP1", SND_SOC_NOPM, 0, 0,
  2140. &rx1_mix2_inp1_mux),
  2141. SND_SOC_DAPM_MUX("RX2 MIX2 INP1", SND_SOC_NOPM, 0, 0,
  2142. &rx2_mix2_inp1_mux),
  2143. SND_SOC_DAPM_MUX("RDAC4 MUX", SND_SOC_NOPM, 0, 0,
  2144. &rx_dac4_mux),
  2145. SND_SOC_DAPM_MUX("RDAC3 MUX", SND_SOC_NOPM, 0, 0,
  2146. &rx_dac3_mux),
  2147. SND_SOC_DAPM_SUPPLY("MICBIAS_REGULATOR", SND_SOC_NOPM,
  2148. ON_DEMAND_MICBIAS, 0,
  2149. msm8x10_wcd_codec_enable_on_demand_supply,
  2150. SND_SOC_DAPM_PRE_PMU |
  2151. SND_SOC_DAPM_POST_PMD),
  2152. SND_SOC_DAPM_SUPPLY("CP_REGULATOR", SND_SOC_NOPM,
  2153. ON_DEMAND_CP, 0,
  2154. msm8x10_wcd_codec_enable_on_demand_supply,
  2155. SND_SOC_DAPM_PRE_PMU |
  2156. SND_SOC_DAPM_POST_PMD),
  2157. SND_SOC_DAPM_SUPPLY("CP", MSM8X10_WCD_A_CP_EN, 0, 0,
  2158. msm8x10_wcd_codec_enable_charge_pump, SND_SOC_DAPM_POST_PMU |
  2159. SND_SOC_DAPM_PRE_PMD),
  2160. SND_SOC_DAPM_SUPPLY("RX_BIAS", SND_SOC_NOPM, 0, 0,
  2161. msm8x10_wcd_codec_enable_rx_bias, SND_SOC_DAPM_PRE_PMU |
  2162. SND_SOC_DAPM_POST_PMD),
  2163. /* TX */
  2164. SND_SOC_DAPM_SUPPLY("CDC_CONN", MSM8X10_WCD_A_CDC_CLK_OTHR_CTL,
  2165. 2, 0, NULL, 0),
  2166. SND_SOC_DAPM_INPUT("AMIC1"),
  2167. SND_SOC_DAPM_MICBIAS_E("MIC BIAS Internal1",
  2168. SND_SOC_NOPM, 7, 0,
  2169. msm8x10_wcd_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
  2170. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  2171. #if defined(CONFIG_SEC_HEAT_PROJECT) /*Remove Intenal mic bias2*/
  2172. SND_SOC_DAPM_MICBIAS_E("MIC BIAS Internal2",
  2173. 0, 0, 0,
  2174. 0, SND_SOC_DAPM_PRE_PMU |
  2175. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  2176. #else
  2177. SND_SOC_DAPM_MICBIAS_E("MIC BIAS Internal2",
  2178. SND_SOC_NOPM, 7, 0,
  2179. msm8x10_wcd_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
  2180. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  2181. #endif
  2182. SND_SOC_DAPM_MICBIAS_E("MIC BIAS Internal3",
  2183. SND_SOC_NOPM, 7, 0,
  2184. msm8x10_wcd_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
  2185. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  2186. SND_SOC_DAPM_MICBIAS_E("MIC BIAS External",
  2187. SND_SOC_NOPM, 7, 0,
  2188. msm8x10_wcd_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
  2189. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  2190. SND_SOC_DAPM_MICBIAS_E(DAPM_MICBIAS_EXTERNAL_STANDALONE,
  2191. SND_SOC_NOPM,
  2192. 7, 0, msm8x10_wcd_codec_enable_micbias,
  2193. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2194. SND_SOC_DAPM_POST_PMD),
  2195. SND_SOC_DAPM_ADC_E("ADC1", NULL, MSM8X10_WCD_A_TX_1_EN, 7, 0,
  2196. msm8x10_wcd_codec_enable_adc, SND_SOC_DAPM_PRE_PMU |
  2197. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  2198. SND_SOC_DAPM_ADC_E("ADC2_INP2", NULL, MSM8X10_WCD_A_TX_2_EN, 7, 0,
  2199. msm8x10_wcd_codec_enable_adc, SND_SOC_DAPM_PRE_PMU |
  2200. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  2201. SND_SOC_DAPM_ADC_E("ADC2_INP3", NULL, MSM8X10_WCD_A_TX_3_EN, 7, 0,
  2202. msm8x10_wcd_codec_enable_adc, SND_SOC_DAPM_PRE_PMU |
  2203. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  2204. SND_SOC_DAPM_MIXER("ADC2", SND_SOC_NOPM, 0, 0, NULL, 0),
  2205. SND_SOC_DAPM_MUX("ADC2 MUX", SND_SOC_NOPM, 0, 0,
  2206. &tx_adc2_mux),
  2207. SND_SOC_DAPM_INPUT("AMIC3"),
  2208. SND_SOC_DAPM_MUX_E("DEC1 MUX",
  2209. MSM8X10_WCD_A_CDC_CLK_TX_CLK_EN_B1_CTL, 0, 0,
  2210. &dec1_mux, msm8x10_wcd_codec_enable_dec,
  2211. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2212. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  2213. SND_SOC_DAPM_MUX_E("DEC2 MUX",
  2214. MSM8X10_WCD_A_CDC_CLK_TX_CLK_EN_B1_CTL, 1, 0,
  2215. &dec2_mux, msm8x10_wcd_codec_enable_dec,
  2216. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2217. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  2218. SND_SOC_DAPM_INPUT("AMIC2"),
  2219. SND_SOC_DAPM_AIF_OUT("I2S TX1", "AIF1 Capture", 0, SND_SOC_NOPM,
  2220. 0, 0),
  2221. SND_SOC_DAPM_AIF_OUT("I2S TX2", "AIF1 Capture", 0, SND_SOC_NOPM,
  2222. 0, 0),
  2223. SND_SOC_DAPM_AIF_OUT("I2S TX3", "AIF1 Capture", 0, SND_SOC_NOPM,
  2224. 0, 0),
  2225. /* Digital Mic Inputs */
  2226. SND_SOC_DAPM_ADC_E("DMIC1", NULL, SND_SOC_NOPM, 0, 0,
  2227. msm8x10_wcd_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  2228. SND_SOC_DAPM_POST_PMD),
  2229. SND_SOC_DAPM_ADC_E("DMIC2", NULL, SND_SOC_NOPM, 0, 0,
  2230. msm8x10_wcd_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  2231. SND_SOC_DAPM_POST_PMD),
  2232. /* Sidetone */
  2233. SND_SOC_DAPM_MUX("IIR1 INP1 MUX", SND_SOC_NOPM, 0, 0, &iir1_inp1_mux),
  2234. SND_SOC_DAPM_PGA("IIR1", MSM8X10_WCD_A_CDC_CLK_SD_CTL, 0, 0, NULL, 0),
  2235. SND_SOC_DAPM_SUPPLY("RX_I2S_CLK", MSM8X10_WCD_A_CDC_CLK_RX_I2S_CTL,
  2236. 4, 0, NULL, 0),
  2237. SND_SOC_DAPM_SUPPLY("TX_I2S_CLK", MSM8X10_WCD_A_CDC_CLK_TX_I2S_CTL, 4,
  2238. 0, NULL, 0),
  2239. };
  2240. static const struct msm8x10_wcd_reg_mask_val msm8x10_wcd_reg_defaults[] = {
  2241. /* set MCLk to 9.6 */
  2242. MSM8X10_WCD_REG_VAL(MSM8X10_WCD_A_CHIP_CTL, 0x00),
  2243. /* EAR PA deafults */
  2244. MSM8X10_WCD_REG_VAL(MSM8X10_WCD_A_RX_EAR_CMBUFF, 0x05),
  2245. /* RX deafults */
  2246. MSM8X10_WCD_REG_VAL(MSM8X10_WCD_A_CDC_RX1_B5_CTL, 0x78),
  2247. MSM8X10_WCD_REG_VAL(MSM8X10_WCD_A_CDC_RX2_B5_CTL, 0x78),
  2248. MSM8X10_WCD_REG_VAL(MSM8X10_WCD_A_CDC_RX3_B5_CTL, 0x78),
  2249. /* RX1 and RX2 defaults */
  2250. MSM8X10_WCD_REG_VAL(MSM8X10_WCD_A_CDC_RX1_B6_CTL, 0xA0),
  2251. MSM8X10_WCD_REG_VAL(MSM8X10_WCD_A_CDC_RX2_B6_CTL, 0xA0),
  2252. /* RX3 to RX7 defaults */
  2253. MSM8X10_WCD_REG_VAL(MSM8X10_WCD_A_CDC_RX3_B6_CTL, 0x80),
  2254. /* Reduce HPH DAC bias to 70% */
  2255. MSM8X10_WCD_REG_VAL(MSM8X10_WCD_A_RX_HPH_BIAS_PA, 0x7A),
  2256. /*Reduce EAR DAC bias to 70% */
  2257. MSM8X10_WCD_REG_VAL(MSM8X10_WCD_A_RX_EAR_BIAS_PA, 0x76),
  2258. /* Reduce LINE DAC bias to 70% */
  2259. MSM8X10_WCD_REG_VAL(MSM8X10_WCD_A_RX_LINE_BIAS_PA, 0x78),
  2260. /* Disable internal biasing path which can cause leakage */
  2261. MSM8X10_WCD_REG_VAL(MSM8X10_WCD_A_BIAS_CURR_CTL_2, 0x04),
  2262. #if defined(CONFIG_MACH_CS02VE)||defined(CONFIG_MACH_KYLEVE2_CTC) || defined(CONFIG_SEC_HEAT_PROJECT)
  2263. MSM8X10_WCD_REG_VAL(MSM8X10_WCD_A_MICB_CFILT_1_VAL, 0x9C),
  2264. #else
  2265. #endif
  2266. /* Enable pulldown to reduce leakage */
  2267. #if defined(CONFIG_MACH_CS02VE)||defined(CONFIG_MACH_KYLEVE2_CTC) || defined(CONFIG_SEC_HEAT_PROJECT)
  2268. MSM8X10_WCD_REG_VAL(MSM8X10_WCD_A_MICB_1_CTL, 0x92),
  2269. #else
  2270. MSM8X10_WCD_REG_VAL(MSM8X10_WCD_A_MICB_1_CTL, 0x82),
  2271. #endif
  2272. MSM8X10_WCD_REG_VAL(MSM8X10_WCD_A_TX_COM_BIAS, 0xE0),
  2273. /* Keep the same default gain settings for TX paths */
  2274. MSM8X10_WCD_REG_VAL(MSM8X10_WCD_A_TX_1_EN, 0x32),
  2275. MSM8X10_WCD_REG_VAL(MSM8X10_WCD_A_TX_2_EN, 0x32),
  2276. MSM8X10_WCD_REG_VAL(MSM8X10_WCD_A_TX_3_EN, 0x30),
  2277. /* ClassG fine tuning setting for 16 ohm HPH */
  2278. MSM8X10_WCD_REG_VAL(MSM8X10_WCD_A_CDC_CLSG_FREQ_THRESH_B1_CTL, 0x05),
  2279. MSM8X10_WCD_REG_VAL(MSM8X10_WCD_A_CDC_CLSG_FREQ_THRESH_B2_CTL, 0x0C),
  2280. MSM8X10_WCD_REG_VAL(MSM8X10_WCD_A_CDC_CLSG_FREQ_THRESH_B3_CTL, 0x1A),
  2281. MSM8X10_WCD_REG_VAL(MSM8X10_WCD_A_CDC_CLSG_FREQ_THRESH_B4_CTL, 0x47),
  2282. MSM8X10_WCD_REG_VAL(MSM8X10_WCD_A_CDC_CLSG_GAIN_THRESH_CTL, 0x23),
  2283. /* Always set TXD_CLK_EN bit to reduce the leakage */
  2284. MSM8X10_WCD_REG_VAL(MSM8X10_WCD_A_CDC_DIG_CLK_CTL, 0x10),
  2285. /* Always disable clock gating for MCLK to mbhc clock gate */
  2286. MSM8X10_WCD_REG_VAL(MSM8X10_WCD_A_CDC_ANA_CLK_CTL, 0x20),
  2287. MSM8X10_WCD_REG_VAL(MSM8X10_WCD_A_CDC_DIG_CLK_CTL, 0x10),
  2288. };
  2289. static void msm8x10_wcd_update_reg_defaults(struct snd_soc_codec *codec)
  2290. {
  2291. u32 i;
  2292. for (i = 0; i < ARRAY_SIZE(msm8x10_wcd_reg_defaults); i++)
  2293. snd_soc_write(codec, msm8x10_wcd_reg_defaults[i].reg,
  2294. msm8x10_wcd_reg_defaults[i].val);
  2295. }
  2296. static const struct msm8x10_wcd_reg_mask_val
  2297. msm8x10_wcd_codec_reg_init_val[] = {
  2298. /* Initialize current threshold to 350MA
  2299. * number of wait and run cycles to 4096
  2300. */
  2301. #if defined(CONFIG_MACH_CS02VE)||defined(CONFIG_MACH_KYLEVE2_CTC) || defined(CONFIG_SEC_HEAT_PROJECT)
  2302. {MSM8X10_WCD_A_RX_HPH_OCP_CTL, 0xFF, 0x6B},
  2303. #else
  2304. {MSM8X10_WCD_A_RX_HPH_OCP_CTL, 0xE1, 0x61},
  2305. #endif
  2306. {MSM8X10_WCD_A_RX_COM_OCP_COUNT, 0xFF, 0xFF},
  2307. {MSM8X10_WCD_A_RX_HPH_L_TEST, 0x01, 0x01},
  2308. {MSM8X10_WCD_A_RX_HPH_R_TEST, 0x01, 0x01},
  2309. /* Initialize gain registers to use register gain */
  2310. {MSM8X10_WCD_A_RX_HPH_L_GAIN, 0x20, 0x20},
  2311. {MSM8X10_WCD_A_RX_HPH_R_GAIN, 0x20, 0x20},
  2312. {MSM8X10_WCD_A_RX_LINE_1_GAIN, 0x20, 0x20},
  2313. /*enable HPF filter for TX paths */
  2314. {MSM8X10_WCD_A_CDC_TX1_MUX_CTL, 0x8, 0x0},
  2315. {MSM8X10_WCD_A_CDC_TX2_MUX_CTL, 0x8, 0x0},
  2316. /* config Decimator for DMIC CLK_MODE_1(3.2Mhz@9.6Mhz mclk) */
  2317. {MSM8X10_WCD_A_CDC_TX1_DMIC_CTL, 0x7, 0x1},
  2318. {MSM8X10_WCD_A_CDC_TX2_DMIC_CTL, 0x7, 0x1},
  2319. /* config DMIC clk to CLK_MODE_1 (3.2Mhz@9.6Mhz mclk) */
  2320. {MSM8X10_WCD_A_CDC_CLK_DMIC_B1_CTL, 0xEE, 0x22},
  2321. /* Disable REF_EN for MSM8X10_WCD_A_SPKR_DRV_DAC_CTL */
  2322. {MSM8X10_WCD_A_SPKR_DRV_DAC_CTL, 0x04, 0x00},
  2323. };
  2324. static void msm8x10_wcd_codec_init_reg(struct snd_soc_codec *codec)
  2325. {
  2326. u32 i;
  2327. for (i = 0; i < ARRAY_SIZE(msm8x10_wcd_codec_reg_init_val); i++)
  2328. snd_soc_update_bits(codec,
  2329. msm8x10_wcd_codec_reg_init_val[i].reg,
  2330. msm8x10_wcd_codec_reg_init_val[i].mask,
  2331. msm8x10_wcd_codec_reg_init_val[i].val);
  2332. }
  2333. static void msm8x10_wcd_enable_mux_bias_block(
  2334. struct snd_soc_codec *codec)
  2335. {
  2336. snd_soc_update_bits(codec, WCD9XXX_A_MBHC_SCALING_MUX_1,
  2337. 0x80, 0x00);
  2338. }
  2339. static void msm8x10_wcd_put_cfilt_fast_mode(
  2340. struct snd_soc_codec *codec,
  2341. struct wcd9xxx_mbhc *mbhc)
  2342. {
  2343. snd_soc_update_bits(codec, mbhc->mbhc_bias_regs.cfilt_ctl,
  2344. 0x30, 0x30);
  2345. }
  2346. static void msm8x10_wcd_codec_specific_cal_setup(
  2347. struct snd_soc_codec *codec,
  2348. struct wcd9xxx_mbhc *mbhc)
  2349. {
  2350. snd_soc_update_bits(codec, WCD9XXX_A_CDC_MBHC_B1_CTL,
  2351. 0x04, 0x04);
  2352. snd_soc_update_bits(codec, WCD9XXX_A_TX_7_MBHC_EN,
  2353. 0xE0, 0xE0);
  2354. }
  2355. static struct wcd9xxx_cfilt_mode msm8x10_wcd_switch_cfilt_mode(
  2356. struct wcd9xxx_mbhc *mbhc, bool fast)
  2357. {
  2358. struct snd_soc_codec *codec = mbhc->codec;
  2359. struct wcd9xxx_cfilt_mode cfilt_mode;
  2360. if (fast)
  2361. cfilt_mode.reg_mode_val = WCD9XXX_CFILT_EXT_PRCHG_EN;
  2362. else
  2363. cfilt_mode.reg_mode_val = WCD9XXX_CFILT_EXT_PRCHG_DSBL;
  2364. cfilt_mode.cur_mode_val =
  2365. snd_soc_read(codec, mbhc->mbhc_bias_regs.cfilt_ctl) & 0x30;
  2366. cfilt_mode.reg_mask = 0x30;
  2367. return cfilt_mode;
  2368. }
  2369. static void msm8x10_wcd_select_cfilt(struct snd_soc_codec *codec,
  2370. struct wcd9xxx_mbhc *mbhc)
  2371. {
  2372. snd_soc_update_bits(codec,
  2373. mbhc->mbhc_bias_regs.ctl_reg, 0x60, 0x00);
  2374. }
  2375. enum wcd9xxx_cdc_type msm8x10_wcd_get_cdc_type(void)
  2376. {
  2377. return WCD9XXX_CDC_TYPE_HELICON;
  2378. }
  2379. static void msm8x10_wcd_mbhc_clk_gate(struct snd_soc_codec *codec,
  2380. bool on)
  2381. {
  2382. snd_soc_update_bits(codec, MSM8X10_WCD_A_CDC_TOP_CLK_CTL, 0x10, 0x10);
  2383. }
  2384. static void msm8x10_wcd_mbhc_txfe(struct snd_soc_codec *codec, bool on)
  2385. {
  2386. snd_soc_update_bits(codec, MSM8X10_WCD_A_TX_7_MBHC_EN_ATEST_CTRL,
  2387. 0x80, on ? 0x80 : 0x00);
  2388. }
  2389. static int msm8x10_wcd_enable_ext_mb_source(struct snd_soc_codec *codec,
  2390. bool turn_on,
  2391. bool use_dapm)
  2392. {
  2393. int ret = 0;
  2394. if (use_dapm) {
  2395. if (turn_on)
  2396. ret = snd_soc_dapm_force_enable_pin(&codec->dapm,
  2397. "MICBIAS_REGULATOR");
  2398. else
  2399. ret = snd_soc_dapm_disable_pin(&codec->dapm,
  2400. "MICBIAS_REGULATOR");
  2401. snd_soc_dapm_sync(&codec->dapm);
  2402. } else {
  2403. struct on_demand_supply *supply;
  2404. struct msm8x10_wcd_priv *msm8x10_wcd =
  2405. snd_soc_codec_get_drvdata(codec);
  2406. supply = &msm8x10_wcd->on_demand_list[ON_DEMAND_MICBIAS];
  2407. if (!supply || !supply->supply || !msm8x10_wcd)
  2408. return 0;
  2409. ret = on_demand_regulator_control(supply,
  2410. turn_on,
  2411. ON_DEMAND_MICBIAS);
  2412. }
  2413. if (ret)
  2414. dev_err(codec->dev, "%s: Failed to %s external micbias source\n",
  2415. __func__, turn_on ? "enable" : "disabled");
  2416. else
  2417. dev_dbg(codec->dev, "%s: %s external micbias source\n",
  2418. __func__, turn_on ? "Enabled" : "Disabled");
  2419. return ret;
  2420. }
  2421. #ifndef CONFIG_SAMSUNG_JACK
  2422. static int msm8x10_wcd_enable_mbhc_micbias(struct snd_soc_codec *codec,
  2423. bool enable,
  2424. enum wcd9xxx_micbias_num micb_num)
  2425. {
  2426. int rc;
  2427. if (micb_num != MBHC_MICBIAS1) {
  2428. rc = -EINVAL;
  2429. goto err;
  2430. }
  2431. if (enable)
  2432. rc = snd_soc_dapm_force_enable_pin(&codec->dapm,
  2433. DAPM_MICBIAS_EXTERNAL_STANDALONE);
  2434. else {
  2435. rc = snd_soc_dapm_disable_pin(&codec->dapm,
  2436. DAPM_MICBIAS_EXTERNAL_STANDALONE);
  2437. }
  2438. snd_soc_dapm_sync(&codec->dapm);
  2439. err:
  2440. if (rc)
  2441. pr_debug("%s: Failed to force %s micbias", __func__,
  2442. enable ? "enable" : "disable");
  2443. else
  2444. pr_debug("%s: Trying force %s micbias", __func__,
  2445. enable ? "enable" : "disable");
  2446. return rc;
  2447. }
  2448. #endif
  2449. static void msm8x10_wcd_micb_internal(struct snd_soc_codec *codec, bool on)
  2450. {
  2451. snd_soc_update_bits(codec, MSM8X10_WCD_A_MICB_1_INT_RBIAS,
  2452. 0x1C, on ? 0x14 : 0x00);
  2453. }
  2454. static void msm8x10_wcd_enable_mb_vddio(struct snd_soc_codec *codec, bool on)
  2455. {
  2456. snd_soc_update_bits(codec, MSM8X10_WCD_A_MICB_CFILT_1_CTL,
  2457. 0x40, on ? 0x40 : 0x00);
  2458. }
  2459. static void msm8x10_wcd_prepare_hph_pa(struct snd_soc_codec *codec,
  2460. struct list_head *lh)
  2461. {
  2462. int i;
  2463. u32 delay;
  2464. const struct wcd9xxx_reg_mask_val reg_set_paon[] = {
  2465. {MSM8X10_WCD_A_CDC_RX1_B6_CTL, 0xFF, 0x01},
  2466. {MSM8X10_WCD_A_CDC_RX2_B6_CTL, 0xFF, 0x01},
  2467. {MSM8X10_WCD_A_RX_HPH_L_GAIN, 0xFF, 0x2C},
  2468. {MSM8X10_WCD_A_RX_HPH_R_GAIN, 0xFF, 0x2C},
  2469. {MSM8X10_WCD_A_CDC_CLK_RX_B1_CTL, 0xFF, 0x01},
  2470. {MSM8X10_WCD_A_RX_COM_BIAS, 0xFF, 0x80},
  2471. {MSM8X10_WCD_A_CP_EN, 0xFF, 0xE7},
  2472. {MSM8X10_WCD_A_CP_STATIC, 0xFF, 0x13},
  2473. {MSM8X10_WCD_A_CP_STATIC, 0xFF, 0x1B},
  2474. {MSM8X10_WCD_A_CDC_RX2_B6_CTL, 0xFF, 0x01},
  2475. {MSM8X10_WCD_A_CDC_CLK_RX_B1_CTL, 0xFF, 0x03},
  2476. {MSM8X10_WCD_A_CDC_ANA_CLK_CTL, 0xFF, 0x22},
  2477. {MSM8X10_WCD_A_CDC_ANA_CLK_CTL, 0xFF, 0x23},
  2478. {MSM8X10_WCD_A_RX_HPH_CNP_WG_CTL, 0xFF, 0xDA},
  2479. {MSM8X10_WCD_A_CDC_DIG_CLK_CTL, 0xFF, 0x01},
  2480. {MSM8X10_WCD_A_CDC_DIG_CLK_CTL, 0xFF, 0x03},
  2481. {MSM8X10_WCD_A_RX_HPH_CHOP_CTL, 0xFF, 0xA4},
  2482. {MSM8X10_WCD_A_RX_HPH_OCP_CTL, 0xFF, 0x67},
  2483. {MSM8X10_WCD_A_RX_HPH_L_TEST, 0x01, 0x00},
  2484. {MSM8X10_WCD_A_RX_HPH_R_TEST, 0x01, 0x00},
  2485. {MSM8X10_WCD_A_RX_HPH_BIAS_WG_OCP, 0xFF, 0x1A},
  2486. {MSM8X10_WCD_A_RX_HPH_CNP_WG_CTL, 0xFF, 0xDB},
  2487. {MSM8X10_WCD_A_RX_HPH_CNP_WG_TIME, 0xFF, 0xDB},
  2488. {MSM8X10_WCD_A_RX_HPH_L_DAC_CTL, 0xFF, 0x40},
  2489. {MSM8X10_WCD_A_RX_HPH_L_DAC_CTL, 0xFF, 0xC0},
  2490. {MSM8X10_WCD_A_RX_HPH_R_DAC_CTL, 0xFF, 0x40},
  2491. {MSM8X10_WCD_A_RX_HPH_R_DAC_CTL, 0xFF, 0xC0},
  2492. {MSM8X10_WCD_A_RX_HPH_L_DAC_CTL, 0x03, 0x01},
  2493. {MSM8X10_WCD_A_RX_HPH_R_DAC_CTL, 0x03, 0x01},
  2494. };
  2495. for (i = 0; i < ARRAY_SIZE(reg_set_paon); i++) {
  2496. delay = 0;
  2497. wcd9xxx_soc_update_bits_push(codec, lh,
  2498. reg_set_paon[i].reg,
  2499. reg_set_paon[i].mask,
  2500. reg_set_paon[i].val, delay);
  2501. }
  2502. dev_dbg(codec->dev, "%s: PAs are prepared\n", __func__);
  2503. return;
  2504. }
  2505. static int msm8x10_wcd_enable_static_pa(struct snd_soc_codec *codec,
  2506. bool enable)
  2507. {
  2508. int wg_time = snd_soc_read(codec, WCD9XXX_A_RX_HPH_CNP_WG_TIME) *
  2509. MSM8X10_WCD_WG_TIME_FACTOR_US;
  2510. wg_time += (int) (wg_time * 35) / 100;
  2511. snd_soc_update_bits(codec, MSM8X10_WCD_A_RX_HPH_CNP_EN, 0x30,
  2512. enable ? 0x30 : 0x0);
  2513. /* Wait for wave gen time to avoid pop noise */
  2514. usleep_range(wg_time, wg_time + WCD9XXX_USLEEP_RANGE_MARGIN_US);
  2515. snd_soc_update_bits(codec, MSM8X10_WCD_A_CDC_RX1_B6_CTL, 0xFF, 0x00);
  2516. snd_soc_update_bits(codec, MSM8X10_WCD_A_CDC_RX2_B6_CTL, 0xFF, 0x00);
  2517. dev_dbg(codec->dev, "%s: PAs are %s as static mode (wg_time %d)\n",
  2518. __func__, enable ? "enabled" : "disabled", wg_time);
  2519. return 0;
  2520. }
  2521. static int msm8x10_wcd_setup_zdet(struct wcd9xxx_mbhc *mbhc,
  2522. enum mbhc_impedance_detect_stages stage)
  2523. {
  2524. int ret = 0;
  2525. struct snd_soc_codec *codec = mbhc->codec;
  2526. struct msm8x10_wcd_priv *wcd_priv = snd_soc_codec_get_drvdata(codec);
  2527. const int mux_wait_us = 25;
  2528. #define __wr(reg, mask, value) \
  2529. do { \
  2530. ret = wcd9xxx_soc_update_bits_push(codec, \
  2531. &wcd_priv->reg_save_restore, \
  2532. reg, mask, value, 0); \
  2533. if (ret < 0) \
  2534. return ret; \
  2535. } while (0)
  2536. switch (stage) {
  2537. case PRE_MEAS:
  2538. dev_dbg(codec->dev, "%s: PRE_MEAS\n", __func__);
  2539. INIT_LIST_HEAD(&wcd_priv->reg_save_restore);
  2540. /* Configure PA */
  2541. msm8x10_wcd_prepare_hph_pa(mbhc->codec,
  2542. &wcd_priv->reg_save_restore);
  2543. /* Setup MBHC */
  2544. __wr(WCD9XXX_A_MBHC_SCALING_MUX_1, 0x7F, 0x40);
  2545. __wr(WCD9XXX_A_MBHC_SCALING_MUX_2, 0xFF, 0xF0);
  2546. __wr(0x171, 0xFF, 0x90);
  2547. __wr(WCD9XXX_A_TX_7_MBHC_EN, 0xFF, 0xF0);
  2548. __wr(WCD9XXX_A_CDC_MBHC_TIMER_B4_CTL, 0xFF, 0x45);
  2549. __wr(WCD9XXX_A_CDC_MBHC_TIMER_B5_CTL, 0xFF, 0x80);
  2550. __wr(WCD9XXX_A_CDC_MBHC_CLK_CTL, 0xFF, 0x0A);
  2551. snd_soc_write(codec, WCD9XXX_A_CDC_MBHC_EN_CTL, 0x2);
  2552. __wr(WCD9XXX_A_CDC_MBHC_CLK_CTL, 0xFF, 0x02);
  2553. /* Enable Impedance Detection */
  2554. __wr(WCD9XXX_A_MBHC_HPH, 0xFF, 0xC8);
  2555. /*
  2556. * CnP setup for 0mV
  2557. * Route static data as input to noise shaper
  2558. */
  2559. __wr(MSM8X10_WCD_A_CDC_RX1_B3_CTL, 0xFF, 0x02);
  2560. __wr(MSM8X10_WCD_A_CDC_RX2_B3_CTL, 0xFF, 0x02);
  2561. snd_soc_update_bits(codec, WCD9XXX_A_RX_HPH_L_TEST,
  2562. 0x02, 0x00);
  2563. snd_soc_update_bits(codec, WCD9XXX_A_RX_HPH_R_TEST,
  2564. 0x02, 0x00);
  2565. /* Reset the HPHL static data pointer */
  2566. __wr(MSM8X10_WCD_A_CDC_RX1_B2_CTL, 0xFF, 0x00);
  2567. /* Four consecutive writes to set 0V as static data input */
  2568. snd_soc_write(codec, MSM8X10_WCD_A_CDC_RX1_B1_CTL, 0x00);
  2569. snd_soc_write(codec, MSM8X10_WCD_A_CDC_RX1_B1_CTL, 0x00);
  2570. snd_soc_write(codec, MSM8X10_WCD_A_CDC_RX1_B1_CTL, 0x00);
  2571. snd_soc_write(codec, MSM8X10_WCD_A_CDC_RX1_B1_CTL, 0x00);
  2572. /* Reset the HPHR static data pointer */
  2573. __wr(MSM8X10_WCD_A_CDC_RX2_B2_CTL, 0xFF, 0x00);
  2574. /* Four consecutive writes to set 0V as static data input */
  2575. snd_soc_write(codec, MSM8X10_WCD_A_CDC_RX2_B1_CTL, 0x00);
  2576. snd_soc_write(codec, MSM8X10_WCD_A_CDC_RX2_B1_CTL, 0x00);
  2577. snd_soc_write(codec, MSM8X10_WCD_A_CDC_RX2_B1_CTL, 0x00);
  2578. snd_soc_write(codec, MSM8X10_WCD_A_CDC_RX2_B1_CTL, 0x00);
  2579. /* Enable the HPHL and HPHR PA */
  2580. msm8x10_wcd_enable_static_pa(mbhc->codec, true);
  2581. break;
  2582. case POST_MEAS:
  2583. dev_dbg(codec->dev, "%s: POST_MEAS\n", __func__);
  2584. /* Turn off ICAL */
  2585. snd_soc_write(codec, WCD9XXX_A_MBHC_SCALING_MUX_2, 0xF0);
  2586. msm8x10_wcd_enable_static_pa(mbhc->codec, false);
  2587. /*
  2588. * Setup CnP wavegen to ramp to the desired
  2589. * output using a 40ms ramp
  2590. */
  2591. /* CnP wavegen current to 0.5uA */
  2592. snd_soc_write(codec, WCD9XXX_A_RX_HPH_BIAS_WG_OCP, 0x1A);
  2593. /* Set the current division ratio to 2000 */
  2594. snd_soc_write(codec, WCD9XXX_A_RX_HPH_CNP_WG_CTL, 0xDF);
  2595. /* Set the wavegen timer to max (60msec) */
  2596. snd_soc_write(codec, WCD9XXX_A_RX_HPH_CNP_WG_TIME, 0xA0);
  2597. /* Set the CnP reference current to sc_bias */
  2598. snd_soc_write(codec, WCD9XXX_A_RX_HPH_OCP_CTL, 0x6D);
  2599. snd_soc_write(codec, MSM8X10_WCD_A_CDC_RX1_B2_CTL, 0x00);
  2600. /* Four consecutive writes to set -10mV as static data input */
  2601. snd_soc_write(codec, MSM8X10_WCD_A_CDC_RX1_B1_CTL, 0x00);
  2602. snd_soc_write(codec, MSM8X10_WCD_A_CDC_RX1_B1_CTL, 0x1F);
  2603. snd_soc_write(codec, MSM8X10_WCD_A_CDC_RX1_B1_CTL, 0xE3);
  2604. snd_soc_write(codec, MSM8X10_WCD_A_CDC_RX1_B1_CTL, 0x08);
  2605. snd_soc_write(codec, MSM8X10_WCD_A_CDC_RX2_B2_CTL, 0x00);
  2606. /* Four consecutive writes to set -10mV as static data input */
  2607. snd_soc_write(codec, MSM8X10_WCD_A_CDC_RX2_B1_CTL, 0x00);
  2608. snd_soc_write(codec, MSM8X10_WCD_A_CDC_RX2_B1_CTL, 0x1F);
  2609. snd_soc_write(codec, MSM8X10_WCD_A_CDC_RX2_B1_CTL, 0xE3);
  2610. snd_soc_write(codec, MSM8X10_WCD_A_CDC_RX2_B1_CTL, 0x08);
  2611. snd_soc_update_bits(codec, WCD9XXX_A_RX_HPH_L_TEST,
  2612. 0x02, 0x02);
  2613. snd_soc_update_bits(codec, WCD9XXX_A_RX_HPH_R_TEST,
  2614. 0x02, 0x02);
  2615. /* Enable the HPHL and HPHR PA and wait for 60mS */
  2616. msm8x10_wcd_enable_static_pa(mbhc->codec, true);
  2617. snd_soc_update_bits(codec, WCD9XXX_A_MBHC_SCALING_MUX_1,
  2618. 0x7F, 0x40);
  2619. usleep_range(mux_wait_us,
  2620. mux_wait_us + WCD9XXX_USLEEP_RANGE_MARGIN_US);
  2621. break;
  2622. case PA_DISABLE:
  2623. dev_dbg(codec->dev, "%s: PA_DISABLE\n", __func__);
  2624. msm8x10_wcd_enable_static_pa(mbhc->codec, false);
  2625. wcd9xxx_restore_registers(codec, &wcd_priv->reg_save_restore);
  2626. break;
  2627. }
  2628. #undef __wr
  2629. return ret;
  2630. }
  2631. static void msm8x10_wcd_compute_impedance(s16 *l, s16 *r, uint32_t *zl,
  2632. uint32_t *zr)
  2633. {
  2634. int zln, zld;
  2635. int zrn, zrd;
  2636. int rl = 0, rr = 0;
  2637. zln = (l[1] - l[0]) * MSM8X10_WCD_ZDET_MUL_FACTOR;
  2638. zld = (l[2] - l[0]);
  2639. if (zld)
  2640. rl = zln / zld;
  2641. zrn = (r[1] - r[0]) * MSM8X10_WCD_ZDET_MUL_FACTOR;
  2642. zrd = (r[2] - r[0]);
  2643. if (zrd)
  2644. rr = zrn / zrd;
  2645. *zl = rl;
  2646. *zr = rr;
  2647. }
  2648. static const struct wcd9xxx_mbhc_cb mbhc_cb = {
  2649. .enable_mux_bias_block = msm8x10_wcd_enable_mux_bias_block,
  2650. .cfilt_fast_mode = msm8x10_wcd_put_cfilt_fast_mode,
  2651. .codec_specific_cal = msm8x10_wcd_codec_specific_cal_setup,
  2652. .switch_cfilt_mode = msm8x10_wcd_switch_cfilt_mode,
  2653. .select_cfilt = msm8x10_wcd_select_cfilt,
  2654. .get_cdc_type = msm8x10_wcd_get_cdc_type,
  2655. .enable_clock_gate = msm8x10_wcd_mbhc_clk_gate,
  2656. .enable_mbhc_txfe = msm8x10_wcd_mbhc_txfe,
  2657. .enable_mb_source = msm8x10_wcd_enable_ext_mb_source,
  2658. .setup_int_rbias = msm8x10_wcd_micb_internal,
  2659. .pull_mb_to_vddio = msm8x10_wcd_enable_mb_vddio,
  2660. .setup_zdet = msm8x10_wcd_setup_zdet,
  2661. .compute_impedance = msm8x10_wcd_compute_impedance,
  2662. };
  2663. int msm8x10_wcd_hs_detect(struct snd_soc_codec *codec,
  2664. struct wcd9xxx_mbhc_config *mbhc_cfg)
  2665. {
  2666. #ifndef CONFIG_SAMSUNG_JACK
  2667. struct msm8x10_wcd_priv *wcd = snd_soc_codec_get_drvdata(codec);
  2668. if (!wcd) {
  2669. dev_err(codec->dev, "%s: Invalid private data for codec\n",
  2670. __func__);
  2671. return -EINVAL;
  2672. }
  2673. wcd->mbhc_cfg = mbhc_cfg;
  2674. wcd9xxx_mbhc_start(&wcd->mbhc, wcd->mbhc_cfg);
  2675. #endif
  2676. return 0;
  2677. }
  2678. EXPORT_SYMBOL_GPL(msm8x10_wcd_hs_detect);
  2679. static int msm8x10_wcd_bringup(struct snd_soc_codec *codec)
  2680. {
  2681. snd_soc_write(codec, MSM8X10_WCD_A_CDC_RST_CTL, 0x02);
  2682. snd_soc_write(codec, MSM8X10_WCD_A_CHIP_CTL, 0x00);
  2683. usleep_range(5000, 5000);
  2684. snd_soc_write(codec, MSM8X10_WCD_A_CDC_RST_CTL, 0x03);
  2685. return 0;
  2686. }
  2687. static struct regulator *wcd8x10_wcd_codec_find_regulator(
  2688. const struct msm8x10_wcd *msm8x10,
  2689. const char *name)
  2690. {
  2691. int i;
  2692. for (i = 0; i < msm8x10->num_of_supplies; i++) {
  2693. if (msm8x10->supplies[i].supply &&
  2694. !strncmp(msm8x10->supplies[i].supply, name, strlen(name)))
  2695. return msm8x10->supplies[i].consumer;
  2696. }
  2697. return NULL;
  2698. }
  2699. static int msm8x10_wcd_device_down(struct snd_soc_codec *codec)
  2700. {
  2701. dev_dbg(codec->dev, "%s: device down!\n", __func__);
  2702. snd_soc_card_change_online_state(codec->card, 0);
  2703. return 0;
  2704. }
  2705. static const struct wcd9xxx_mbhc_intr cdc_intr_ids = {
  2706. .poll_plug_rem = MSM8X10_WCD_IRQ_MBHC_REMOVAL,
  2707. .shortavg_complete = MSM8X10_WCD_IRQ_MBHC_SHORT_TERM,
  2708. .potential_button_press = MSM8X10_WCD_IRQ_MBHC_PRESS,
  2709. .button_release = MSM8X10_WCD_IRQ_MBHC_RELEASE,
  2710. .dce_est_complete = MSM8X10_WCD_IRQ_MBHC_POTENTIAL,
  2711. .insertion = MSM8X10_WCD_IRQ_MBHC_INSERTION,
  2712. .hph_left_ocp = MSM8X10_WCD_IRQ_HPH_PA_OCPL_FAULT,
  2713. .hph_right_ocp = MSM8X10_WCD_IRQ_HPH_PA_OCPR_FAULT,
  2714. .hs_jack_switch = MSM8X10_WCD_IRQ_MBHC_HS_DET,
  2715. };
  2716. static int msm8x10_wcd_device_up(struct snd_soc_codec *codec)
  2717. {
  2718. int ret = 0;
  2719. struct msm8x10_wcd_priv *msm8x10_wcd_priv =
  2720. snd_soc_codec_get_drvdata(codec);
  2721. dev_err(codec->dev, "%s: device up!\n", __func__);
  2722. snd_soc_card_change_online_state(codec->card, 1);
  2723. /* delay is required to make sure sound card state updated */
  2724. usleep_range(5000, 5100);
  2725. mutex_lock(&codec->mutex);
  2726. msm8x10_wcd_bringup(codec);
  2727. msm8x10_wcd_update_reg_defaults(codec);
  2728. msm8x10_wcd_codec_init_reg(codec);
  2729. wcd9xxx_resmgr_post_ssr(&msm8x10_wcd_priv->resmgr);
  2730. wcd9xxx_mbhc_deinit(&msm8x10_wcd_priv->mbhc);
  2731. ret = wcd9xxx_mbhc_init(&msm8x10_wcd_priv->mbhc,
  2732. &msm8x10_wcd_priv->resmgr,
  2733. codec, msm8x10_wcd_enable_mbhc_micbias,
  2734. &mbhc_cb, &cdc_intr_ids,
  2735. HELICON_MCLK_CLK_9P6MHZ, true);
  2736. if (ret)
  2737. dev_err(codec->dev, "%s: Failed to initialize mbhc\n",
  2738. __func__);
  2739. else
  2740. wcd9xxx_mbhc_start(&msm8x10_wcd_priv->mbhc,
  2741. msm8x10_wcd_priv->mbhc.mbhc_cfg);
  2742. mutex_unlock(&codec->mutex);
  2743. return 0;
  2744. }
  2745. static int adsp_state_callback(struct notifier_block *nb, unsigned long value,
  2746. void *priv)
  2747. {
  2748. bool timedout;
  2749. unsigned long timeout;
  2750. if (value == SUBSYS_BEFORE_SHUTDOWN)
  2751. msm8x10_wcd_device_down(registered_codec);
  2752. else if (value == SUBSYS_AFTER_POWERUP) {
  2753. pr_debug("%s: ADSP is about to power up. bring up codec\n",
  2754. __func__);
  2755. timeout = jiffies +
  2756. msecs_to_jiffies(ADSP_STATE_READY_TIMEOUT_MS);
  2757. while (!(timedout = time_after(jiffies, timeout))) {
  2758. if (!q6core_is_adsp_ready()) {
  2759. pr_debug("%s: ADSP isn't ready\n", __func__);
  2760. } else {
  2761. pr_debug("%s: ADSP is ready\n", __func__);
  2762. msm8x10_wcd_device_up(registered_codec);
  2763. break;
  2764. }
  2765. }
  2766. }
  2767. return NOTIFY_OK;
  2768. }
  2769. static struct notifier_block adsp_state_notifier_block = {
  2770. .notifier_call = adsp_state_callback,
  2771. .priority = -INT_MAX,
  2772. };
  2773. static int msm8x10_wcd_handle_pdata(struct snd_soc_codec *codec,
  2774. struct msm8x10_wcd_pdata *pdata)
  2775. {
  2776. int k1, rc = 0;
  2777. struct msm8x10_wcd_priv *msm8x10_wcd_priv;
  2778. msm8x10_wcd_priv = snd_soc_codec_get_drvdata(codec);
  2779. /* Make sure settings are correct */
  2780. if (pdata->micbias.ldoh_v > WCD9XXX_LDOH_3P0_V ||
  2781. pdata->micbias.bias1_cfilt_sel > WCD9XXX_CFILT1_SEL) {
  2782. rc = -EINVAL;
  2783. goto done;
  2784. }
  2785. /* figure out k value */
  2786. k1 = wcd9xxx_resmgr_get_k_val(&msm8x10_wcd_priv->resmgr,
  2787. pdata->micbias.cfilt1_mv);
  2788. if (IS_ERR_VALUE(k1)) {
  2789. rc = -EINVAL;
  2790. goto done;
  2791. }
  2792. /* Set voltage level */
  2793. snd_soc_update_bits(codec, MSM8X10_WCD_A_MICB_CFILT_1_VAL,
  2794. 0xFC, (k1 << 2));
  2795. /* update micbias capless mode */
  2796. snd_soc_update_bits(codec, MSM8X10_WCD_A_MICB_1_CTL, 0x10,
  2797. pdata->micbias.bias1_cap_mode << 4);
  2798. done:
  2799. return rc;
  2800. }
  2801. static int msm8x10_wcd_codec_probe(struct snd_soc_codec *codec)
  2802. {
  2803. struct msm8x10_wcd_priv *msm8x10_wcd_priv;
  2804. struct msm8x10_wcd *msm8x10_wcd;
  2805. struct wcd9xxx_core_resource *core_res;
  2806. int i, ret = 0;
  2807. struct msm8x10_wcd_pdata *pdata;
  2808. dev_dbg(codec->dev, "%s()\n", __func__);
  2809. msm8x10_wcd_priv = devm_kzalloc(codec->dev,
  2810. sizeof(struct msm8x10_wcd_priv), GFP_KERNEL);
  2811. if (!msm8x10_wcd_priv) {
  2812. dev_err(codec->dev, "Failed to allocate private data\n");
  2813. return -ENOMEM;
  2814. }
  2815. for (i = 0 ; i < NUM_DECIMATORS; i++) {
  2816. tx_hpf_work[i].msm8x10_wcd = msm8x10_wcd_priv;
  2817. tx_hpf_work[i].decimator = i + 1;
  2818. INIT_DELAYED_WORK(&tx_hpf_work[i].dwork,
  2819. tx_hpf_corner_freq_callback);
  2820. }
  2821. codec->control_data = dev_get_drvdata(codec->dev);
  2822. snd_soc_codec_set_drvdata(codec, msm8x10_wcd_priv);
  2823. msm8x10_wcd_priv->codec = codec;
  2824. /* map digital codec registers once */
  2825. msm8x10_wcd = codec->control_data;
  2826. msm8x10_wcd->pdino_base = ioremap(MSM8X10_DINO_CODEC_BASE_ADDR,
  2827. MSM8X10_DINO_CODEC_REG_SIZE);
  2828. pdata = dev_get_platdata(msm8x10_wcd->dev);
  2829. if (!pdata) {
  2830. dev_err(msm8x10_wcd->dev, "%s: platform data not found\n",
  2831. __func__);
  2832. }
  2833. /* codec resmgr module init */
  2834. msm8x10_wcd = codec->control_data;
  2835. core_res = &msm8x10_wcd->wcd9xxx_res;
  2836. ret = wcd9xxx_resmgr_init(&msm8x10_wcd_priv->resmgr,
  2837. codec, core_res, NULL, &pdata->micbias,
  2838. NULL, WCD9XXX_CDC_TYPE_HELICON);
  2839. if (ret) {
  2840. dev_err(codec->dev,
  2841. "%s: wcd9xxx init failed %d\n",
  2842. __func__, ret);
  2843. goto exit_probe;
  2844. }
  2845. msm8x10_wcd_bringup(codec);
  2846. msm8x10_wcd_codec_init_reg(codec);
  2847. msm8x10_wcd_update_reg_defaults(codec);
  2848. msm8x10_wcd_priv->on_demand_list[ON_DEMAND_CP].supply =
  2849. wcd8x10_wcd_codec_find_regulator(
  2850. codec->control_data,
  2851. on_demand_supply_name[ON_DEMAND_CP]);
  2852. atomic_set(&msm8x10_wcd_priv->on_demand_list[ON_DEMAND_CP].ref, 0);
  2853. msm8x10_wcd_priv->on_demand_list[ON_DEMAND_MICBIAS].supply =
  2854. wcd8x10_wcd_codec_find_regulator(
  2855. codec->control_data,
  2856. on_demand_supply_name[ON_DEMAND_MICBIAS]);
  2857. atomic_set(&msm8x10_wcd_priv->on_demand_list[ON_DEMAND_MICBIAS].ref, 0);
  2858. #ifndef CONFIG_SAMSUNG_JACK
  2859. msm8x10_wcd_priv->micb_en_count = 0;
  2860. ret = wcd9xxx_mbhc_init(&msm8x10_wcd_priv->mbhc,
  2861. &msm8x10_wcd_priv->resmgr,
  2862. codec, msm8x10_wcd_enable_mbhc_micbias,
  2863. &mbhc_cb, &cdc_intr_ids,
  2864. HELICON_MCLK_CLK_9P6MHZ, true);
  2865. if (ret) {
  2866. dev_err(msm8x10_wcd->dev, "%s: Failed to initialize mbhc\n",
  2867. __func__);
  2868. goto exit_probe;
  2869. }
  2870. #endif
  2871. /* Handle the Pdata */
  2872. ret = msm8x10_wcd_handle_pdata(codec, pdata);
  2873. if (IS_ERR_VALUE(ret))
  2874. dev_err(msm8x10_wcd->dev, "%s: Bad Pdata\n", __func__);
  2875. registered_codec = codec;
  2876. adsp_state_notifier =
  2877. subsys_notif_register_notifier("adsp",
  2878. &adsp_state_notifier_block);
  2879. if (!adsp_state_notifier) {
  2880. pr_err("%s: Failed to register adsp state notifier\n",
  2881. __func__);
  2882. registered_codec = NULL;
  2883. return -ENOMEM;
  2884. }
  2885. return 0;
  2886. exit_probe:
  2887. return ret;
  2888. }
  2889. static int msm8x10_wcd_codec_remove(struct snd_soc_codec *codec)
  2890. {
  2891. struct msm8x10_wcd_priv *pwcd_priv = snd_soc_codec_get_drvdata(codec);
  2892. struct msm8x10_wcd *msm8x10_wcd = pwcd_priv->codec->control_data;
  2893. pwcd_priv->on_demand_list[ON_DEMAND_CP].supply = NULL;
  2894. atomic_set(&pwcd_priv->on_demand_list[ON_DEMAND_CP].ref, 0);
  2895. pwcd_priv->on_demand_list[ON_DEMAND_MICBIAS].supply = NULL;
  2896. atomic_set(&pwcd_priv->on_demand_list[ON_DEMAND_MICBIAS].ref, 0);
  2897. /* cleanup resmgr */
  2898. wcd9xxx_resmgr_deinit(&pwcd_priv->resmgr);
  2899. iounmap(msm8x10_wcd->pdino_base);
  2900. return 0;
  2901. }
  2902. static struct snd_soc_codec_driver soc_codec_dev_msm8x10_wcd = {
  2903. .probe = msm8x10_wcd_codec_probe,
  2904. .remove = msm8x10_wcd_codec_remove,
  2905. .read = msm8x10_wcd_read,
  2906. .write = msm8x10_wcd_write,
  2907. .readable_register = msm8x10_wcd_readable,
  2908. .volatile_register = msm8x10_wcd_volatile,
  2909. .reg_cache_size = MSM8X10_WCD_CACHE_SIZE,
  2910. .reg_cache_default = msm8x10_wcd_reset_reg_defaults,
  2911. .reg_word_size = 1,
  2912. .controls = msm8x10_wcd_snd_controls,
  2913. .num_controls = ARRAY_SIZE(msm8x10_wcd_snd_controls),
  2914. .dapm_widgets = msm8x10_wcd_dapm_widgets,
  2915. .num_dapm_widgets = ARRAY_SIZE(msm8x10_wcd_dapm_widgets),
  2916. .dapm_routes = audio_map,
  2917. .num_dapm_routes = ARRAY_SIZE(audio_map),
  2918. };
  2919. static int msm8x10_wcd_init_supplies(struct msm8x10_wcd *msm8x10,
  2920. struct msm8x10_wcd_pdata *pdata)
  2921. {
  2922. int ret;
  2923. int i;
  2924. msm8x10->supplies = kzalloc(sizeof(struct regulator_bulk_data) *
  2925. ARRAY_SIZE(pdata->regulator),
  2926. GFP_KERNEL);
  2927. if (!msm8x10->supplies) {
  2928. ret = -ENOMEM;
  2929. goto err;
  2930. }
  2931. msm8x10->num_of_supplies = 0;
  2932. if (ARRAY_SIZE(pdata->regulator) > MAX_REGULATOR) {
  2933. dev_err(msm8x10->dev, "%s: Array Size out of bound\n",
  2934. __func__);
  2935. ret = -EINVAL;
  2936. goto err;
  2937. }
  2938. for (i = 0; i < ARRAY_SIZE(pdata->regulator); i++) {
  2939. if (pdata->regulator[i].name) {
  2940. msm8x10->supplies[i].supply = pdata->regulator[i].name;
  2941. msm8x10->num_of_supplies++;
  2942. }
  2943. }
  2944. ret = regulator_bulk_get(msm8x10->dev, msm8x10->num_of_supplies,
  2945. msm8x10->supplies);
  2946. if (ret != 0) {
  2947. dev_err(msm8x10->dev, "Failed to get supplies: err = %d\n",
  2948. ret);
  2949. goto err_supplies;
  2950. }
  2951. for (i = 0; i < msm8x10->num_of_supplies; i++) {
  2952. if (regulator_count_voltages(msm8x10->supplies[i].consumer) <=
  2953. 0)
  2954. continue;
  2955. ret = regulator_set_voltage(msm8x10->supplies[i].consumer,
  2956. pdata->regulator[i].min_uV,
  2957. pdata->regulator[i].max_uV);
  2958. if (ret) {
  2959. dev_err(msm8x10->dev, "%s: Setting regulator voltage failed for regulator %s err = %d\n",
  2960. __func__, msm8x10->supplies[i].supply, ret);
  2961. goto err_get;
  2962. }
  2963. ret = regulator_set_optimum_mode(msm8x10->supplies[i].consumer,
  2964. pdata->regulator[i].optimum_uA);
  2965. if (ret < 0) {
  2966. dev_err(msm8x10->dev, "%s: Setting regulator optimum mode failed for regulator %s err = %d\n",
  2967. __func__, msm8x10->supplies[i].supply, ret);
  2968. goto err_get;
  2969. } else {
  2970. ret = 0;
  2971. }
  2972. }
  2973. return ret;
  2974. err_get:
  2975. regulator_bulk_free(msm8x10->num_of_supplies, msm8x10->supplies);
  2976. err_supplies:
  2977. kfree(msm8x10->supplies);
  2978. err:
  2979. return ret;
  2980. }
  2981. static int msm8x10_wcd_enable_static_supplies(struct msm8x10_wcd *msm8x10,
  2982. struct msm8x10_wcd_pdata *pdata)
  2983. {
  2984. int i;
  2985. int ret = 0;
  2986. for (i = 0; i < msm8x10->num_of_supplies; i++) {
  2987. if (pdata->regulator[i].ondemand)
  2988. continue;
  2989. ret = regulator_enable(msm8x10->supplies[i].consumer);
  2990. if (ret) {
  2991. pr_err("%s: Failed to enable %s\n", __func__,
  2992. msm8x10->supplies[i].supply);
  2993. break;
  2994. } else {
  2995. pr_debug("%s: Enabled regulator %s\n", __func__,
  2996. msm8x10->supplies[i].supply);
  2997. }
  2998. }
  2999. while (ret && --i)
  3000. if (!pdata->regulator[i].ondemand)
  3001. regulator_disable(msm8x10->supplies[i].consumer);
  3002. return ret;
  3003. }
  3004. static void msm8x10_wcd_disable_supplies(struct msm8x10_wcd *msm8x10,
  3005. struct msm8x10_wcd_pdata *pdata)
  3006. {
  3007. int i;
  3008. regulator_bulk_disable(msm8x10->num_of_supplies,
  3009. msm8x10->supplies);
  3010. for (i = 0; i < msm8x10->num_of_supplies; i++) {
  3011. if (regulator_count_voltages(msm8x10->supplies[i].consumer) <=
  3012. 0)
  3013. continue;
  3014. regulator_set_voltage(msm8x10->supplies[i].consumer, 0,
  3015. pdata->regulator[i].max_uV);
  3016. regulator_set_optimum_mode(msm8x10->supplies[i].consumer, 0);
  3017. }
  3018. regulator_bulk_free(msm8x10->num_of_supplies, msm8x10->supplies);
  3019. kfree(msm8x10->supplies);
  3020. }
  3021. static int msm8x10_wcd_pads_config(void)
  3022. {
  3023. void __iomem *ppull = ioremap(MSM8x10_TLMM_CDC_PULL_CTL, 4);
  3024. /* Set I2C pads as pull up and rest of pads as no pull */
  3025. iowrite32(0x03C00000, ppull);
  3026. usleep_range(100, 200);
  3027. iounmap(ppull);
  3028. return 0;
  3029. }
  3030. static int msm8x10_wcd_clk_init(void)
  3031. {
  3032. void __iomem *pdig1 = ioremap(MSM8X10_DINO_LPASS_DIGCODEC_CFG_RCGR, 4);
  3033. void __iomem *pdig2 = ioremap(MSM8X10_DINO_LPASS_DIGCODEC_M, 4);
  3034. void __iomem *pdig3 = ioremap(MSM8X10_DINO_LPASS_DIGCODEC_N, 4);
  3035. void __iomem *pdig4 = ioremap(MSM8X10_DINO_LPASS_DIGCODEC_D, 4);
  3036. void __iomem *pdig5 = ioremap(MSM8X10_DINO_LPASS_DIGCODEC_CBCR, 4);
  3037. void __iomem *pdig6 = ioremap(MSM8X10_DINO_LPASS_DIGCODEC_CMD_RCGR, 4);
  3038. /* Div-2 */
  3039. iowrite32(0x3, pdig1);
  3040. iowrite32(0x0, pdig2);
  3041. iowrite32(0x0, pdig3);
  3042. iowrite32(0x0, pdig4);
  3043. /* Digital codec clock enable */
  3044. iowrite32(0x1, pdig5);
  3045. /* Set the update bit to make the settings go through */
  3046. iowrite32(0x1, pdig6);
  3047. usleep_range(100, 200);
  3048. iounmap(pdig1);
  3049. iounmap(pdig2);
  3050. iounmap(pdig3);
  3051. iounmap(pdig4);
  3052. iounmap(pdig5);
  3053. iounmap(pdig6);
  3054. return 0;
  3055. }
  3056. static int msm8x10_wcd_device_init(struct msm8x10_wcd *msm8x10)
  3057. {
  3058. mutex_init(&msm8x10->io_lock);
  3059. mutex_init(&msm8x10->xfer_lock);
  3060. msm8x10_wcd_pads_config();
  3061. msm8x10_wcd_clk_init();
  3062. return 0;
  3063. }
  3064. static struct intr_data interrupt_table[] = {
  3065. {MSM8X10_WCD_IRQ_MBHC_INSERTION, true},
  3066. {MSM8X10_WCD_IRQ_MBHC_POTENTIAL, true},
  3067. {MSM8X10_WCD_IRQ_MBHC_RELEASE, true},
  3068. {MSM8X10_WCD_IRQ_MBHC_PRESS, true},
  3069. {MSM8X10_WCD_IRQ_MBHC_SHORT_TERM, true},
  3070. {MSM8X10_WCD_IRQ_MBHC_REMOVAL, true},
  3071. {MSM8X10_WCD_IRQ_MBHC_HS_DET, true},
  3072. {MSM8X10_WCD_IRQ_RESERVED_0, false},
  3073. {MSM8X10_WCD_IRQ_PA_STARTUP, false},
  3074. {MSM8X10_WCD_IRQ_BG_PRECHARGE, false},
  3075. {MSM8X10_WCD_IRQ_RESERVED_1, false},
  3076. {MSM8X10_WCD_IRQ_EAR_PA_OCPL_FAULT, false},
  3077. {MSM8X10_WCD_IRQ_EAR_PA_STARTUP, false},
  3078. {MSM8X10_WCD_IRQ_SPKR_PA_OCPL_FAULT, false},
  3079. {MSM8X10_WCD_IRQ_SPKR_CLIP_FAULT, false},
  3080. {MSM8X10_WCD_IRQ_RESERVED_2, false},
  3081. {MSM8X10_WCD_IRQ_HPH_L_PA_STARTUP, false},
  3082. {MSM8X10_WCD_IRQ_HPH_R_PA_STARTUP, false},
  3083. {MSM8X10_WCD_IRQ_HPH_PA_OCPL_FAULT, false},
  3084. {MSM8X10_WCD_IRQ_HPH_PA_OCPR_FAULT, false},
  3085. {MSM8X10_WCD_IRQ_RESERVED_3, false},
  3086. {MSM8X10_WCD_IRQ_RESERVED_4, false},
  3087. {MSM8X10_WCD_IRQ_RESERVED_5, false},
  3088. {MSM8X10_WCD_IRQ_RESERVED_6, false},
  3089. };
  3090. static int __devinit msm8x10_wcd_i2c_probe(struct i2c_client *client,
  3091. const struct i2c_device_id *id)
  3092. {
  3093. int ret = 0;
  3094. struct msm8x10_wcd *msm8x10 = NULL;
  3095. struct msm8x10_wcd_pdata *pdata;
  3096. static int device_id;
  3097. struct device *dev;
  3098. enum apr_subsys_state q6_state;
  3099. struct wcd9xxx_core_resource *core_res;
  3100. dev_dbg(&client->dev, "%s(%d):slave addr = 0x%x device_id = %d\n",
  3101. __func__, __LINE__, client->addr, device_id);
  3102. switch (client->addr) {
  3103. case HELICON_CORE_0_I2C_ADDR:
  3104. msm8x10_wcd_modules[0].client = client;
  3105. break;
  3106. case HELICON_CORE_1_I2C_ADDR:
  3107. msm8x10_wcd_modules[1].client = client;
  3108. goto rtn;
  3109. case HELICON_CORE_2_I2C_ADDR:
  3110. msm8x10_wcd_modules[2].client = client;
  3111. goto rtn;
  3112. case HELICON_CORE_3_I2C_ADDR:
  3113. msm8x10_wcd_modules[3].client = client;
  3114. goto rtn;
  3115. default:
  3116. ret = -EINVAL;
  3117. goto rtn;
  3118. }
  3119. q6_state = apr_get_q6_state();
  3120. if ((q6_state == APR_SUBSYS_DOWN) &&
  3121. (client->addr == HELICON_CORE_0_I2C_ADDR)) {
  3122. dev_info(&client->dev, "defering %s, adsp_state %d\n", __func__,
  3123. q6_state);
  3124. return -EPROBE_DEFER;
  3125. } else
  3126. dev_info(&client->dev, "adsp is ready\n");
  3127. dev_dbg(&client->dev, "%s(%d):slave addr = 0x%x device_id = %d\n",
  3128. __func__, __LINE__, client->addr, device_id);
  3129. if (client->addr != HELICON_CORE_0_I2C_ADDR)
  3130. goto rtn;
  3131. dev_set_name(&client->dev, "%s", MSM8X10_CODEC_NAME);
  3132. dev = &client->dev;
  3133. if (client->dev.of_node) {
  3134. dev_dbg(&client->dev, "%s:Platform data from device tree\n",
  3135. __func__);
  3136. pdata = msm8x10_wcd_populate_dt_pdata(&client->dev);
  3137. if (!pdata) {
  3138. dev_err(&client->dev, "%s: Failed to parse pdata from device tree\n",
  3139. __func__);
  3140. goto rtn;
  3141. }
  3142. client->dev.platform_data = pdata;
  3143. } else {
  3144. dev_dbg(&client->dev, "%s:Platform data from board file\n",
  3145. __func__);
  3146. pdata = client->dev.platform_data;
  3147. }
  3148. msm8x10 = kzalloc(sizeof(struct msm8x10_wcd), GFP_KERNEL);
  3149. if (msm8x10 == NULL) {
  3150. dev_err(&client->dev,
  3151. "%s: error, allocation failed\n", __func__);
  3152. ret = -ENOMEM;
  3153. goto rtn;
  3154. }
  3155. msm8x10->dev = &client->dev;
  3156. msm8x10->read_dev = __msm8x10_wcd_reg_read;
  3157. msm8x10->write_dev = __msm8x10_wcd_reg_write;
  3158. ret = msm8x10_wcd_init_supplies(msm8x10, pdata);
  3159. if (ret) {
  3160. dev_err(&client->dev, "%s: Fail to enable Codec supplies\n",
  3161. __func__);
  3162. goto err_codec;
  3163. }
  3164. ret = msm8x10_wcd_enable_static_supplies(msm8x10, pdata);
  3165. if (ret) {
  3166. pr_err("%s: Fail to enable Codec pre-reset supplies\n",
  3167. __func__);
  3168. goto err_codec;
  3169. }
  3170. usleep_range(5, 5);
  3171. ret = msm8x10_wcd_device_init(msm8x10);
  3172. if (ret) {
  3173. dev_err(&client->dev,
  3174. "%s:msm8x10_wcd_device_init failed with error %d\n",
  3175. __func__, ret);
  3176. goto err_supplies;
  3177. }
  3178. dev_set_drvdata(&client->dev, msm8x10);
  3179. core_res = &msm8x10->wcd9xxx_res;
  3180. core_res->parent = msm8x10;
  3181. core_res->dev = msm8x10->dev;
  3182. core_res->intr_table = interrupt_table;
  3183. core_res->intr_table_size = ARRAY_SIZE(interrupt_table);
  3184. wcd9xxx_core_res_init(core_res,
  3185. MSM8X10_WCD_NUM_IRQS,
  3186. MSM8X10_WCD_NUM_IRQ_REGS,
  3187. msm8x10_wcd_reg_read,
  3188. msm8x10_wcd_reg_write,
  3189. msm8x10_wcd_bulk_read,
  3190. msm8x10_wcd_bulk_write);
  3191. if (wcd9xxx_core_irq_init(core_res)) {
  3192. dev_err(msm8x10->dev,
  3193. "%s: irq initialization failed\n", __func__);
  3194. } else {
  3195. dev_info(msm8x10->dev,
  3196. "%s: irq initialization passed\n", __func__);
  3197. }
  3198. ret = snd_soc_register_codec(&client->dev, &soc_codec_dev_msm8x10_wcd,
  3199. msm8x10_wcd_i2s_dai,
  3200. ARRAY_SIZE(msm8x10_wcd_i2s_dai));
  3201. if (ret) {
  3202. dev_err(&client->dev,
  3203. "%s:snd_soc_register_codec failed with error %d\n",
  3204. __func__, ret);
  3205. } else {
  3206. wcd9xxx_set_intf_type(WCD9XXX_INTERFACE_TYPE_I2C);
  3207. goto rtn;
  3208. }
  3209. err_supplies:
  3210. msm8x10_wcd_disable_supplies(msm8x10, pdata);
  3211. err_codec:
  3212. kfree(msm8x10);
  3213. rtn:
  3214. return ret;
  3215. }
  3216. static void msm8x10_wcd_device_exit(struct msm8x10_wcd *msm8x10)
  3217. {
  3218. mutex_destroy(&msm8x10->io_lock);
  3219. mutex_destroy(&msm8x10->xfer_lock);
  3220. kfree(msm8x10);
  3221. }
  3222. static int __devexit msm8x10_wcd_i2c_remove(struct i2c_client *client)
  3223. {
  3224. struct msm8x10_wcd *msm8x10 = dev_get_drvdata(&client->dev);
  3225. msm8x10_wcd_device_exit(msm8x10);
  3226. return 0;
  3227. }
  3228. static struct i2c_device_id msm8x10_wcd_id_table[] = {
  3229. {"msm8x10-wcd-i2c", MSM8X10_WCD_I2C_TOP_LEVEL},
  3230. {"msm8x10-wcd-i2c", MSM8X10_WCD_I2C_ANALOG},
  3231. {"msm8x10-wcd-i2c", MSM8X10_WCD_I2C_DIGITAL_1},
  3232. {"msm8x10-wcd-i2c", MSM8X10_WCD_I2C_DIGITAL_2},
  3233. {}
  3234. };
  3235. static struct of_device_id msm8x10_wcd_of_match[] = {
  3236. { .compatible = "qcom,msm8x10-wcd-i2c",},
  3237. { },
  3238. };
  3239. #ifdef CONFIG_PM
  3240. static int msm8x10_wcd_i2c_resume(struct device *dev)
  3241. {
  3242. struct i2c_client *client = to_i2c_client(dev);
  3243. struct msm8x10_wcd_priv *priv = i2c_get_clientdata(client);
  3244. struct msm8x10_wcd *msm8x10;
  3245. int ret = 0;
  3246. if (client->addr == HELICON_CORE_0_I2C_ADDR) {
  3247. if (!priv || !priv->codec || !priv->codec->control_data) {
  3248. ret = -EINVAL;
  3249. dev_err(dev, "%s: Invalid client data\n", __func__);
  3250. goto rtn;
  3251. }
  3252. msm8x10 = priv->codec->control_data;
  3253. return wcd9xxx_core_res_resume(&msm8x10->wcd9xxx_res);
  3254. }
  3255. rtn:
  3256. return 0;
  3257. }
  3258. static int msm8x10_wcd_i2c_suspend(struct device *dev)
  3259. {
  3260. struct i2c_client *client = to_i2c_client(dev);
  3261. struct msm8x10_wcd_priv *priv = i2c_get_clientdata(client);
  3262. struct msm8x10_wcd *msm8x10;
  3263. int ret = 0;
  3264. if (client->addr == HELICON_CORE_0_I2C_ADDR) {
  3265. if (!priv || !priv->codec || !priv->codec->control_data) {
  3266. ret = -EINVAL;
  3267. dev_err(dev, "%s: Invalid client data\n", __func__);
  3268. goto rtn;
  3269. }
  3270. msm8x10 = priv->codec->control_data;
  3271. return wcd9xxx_core_res_suspend(&msm8x10->wcd9xxx_res,
  3272. PMSG_SUSPEND);
  3273. }
  3274. rtn:
  3275. return ret;
  3276. }
  3277. static SIMPLE_DEV_PM_OPS(msm8x1_wcd_pm_ops, msm8x10_wcd_i2c_suspend,
  3278. msm8x10_wcd_i2c_resume);
  3279. #endif
  3280. static struct i2c_driver msm8x10_wcd_i2c_driver = {
  3281. .driver = {
  3282. .owner = THIS_MODULE,
  3283. .name = "msm8x10-wcd-i2c-core",
  3284. .of_match_table = msm8x10_wcd_of_match,
  3285. #ifdef CONFIG_PM
  3286. .pm = &msm8x1_wcd_pm_ops,
  3287. #endif
  3288. },
  3289. .id_table = msm8x10_wcd_id_table,
  3290. .probe = msm8x10_wcd_i2c_probe,
  3291. .remove = __devexit_p(msm8x10_wcd_i2c_remove),
  3292. };
  3293. static int __init msm8x10_wcd_codec_init(void)
  3294. {
  3295. int ret;
  3296. pr_debug("%s:\n", __func__);
  3297. wcd9xxx_set_intf_type(WCD9XXX_INTERFACE_TYPE_PROBING);
  3298. ret = i2c_add_driver(&msm8x10_wcd_i2c_driver);
  3299. if (ret != 0)
  3300. pr_err("%s: Failed to add msm8x10 wcd I2C driver - error %d\n",
  3301. __func__, ret);
  3302. return ret;
  3303. }
  3304. static void __exit msm8x10_wcd_codec_exit(void)
  3305. {
  3306. i2c_del_driver(&msm8x10_wcd_i2c_driver);
  3307. }
  3308. module_init(msm8x10_wcd_codec_init);
  3309. module_exit(msm8x10_wcd_codec_exit);
  3310. MODULE_DESCRIPTION("MSM8x10 Audio codec driver");
  3311. MODULE_LICENSE("GPL v2");
  3312. MODULE_DEVICE_TABLE(i2c, msm8x10_wcd_id_table);