12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908 |
- /* Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 and
- * only version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- */
- #include <linux/module.h>
- #include <linux/init.h>
- #include <linux/firmware.h>
- #include <linux/slab.h>
- #include <linux/platform_device.h>
- #include <linux/device.h>
- #include <linux/printk.h>
- #include <linux/ratelimit.h>
- #include <linux/debugfs.h>
- #include <linux/io.h>
- #include <linux/bitops.h>
- #include <linux/delay.h>
- #include <linux/pm_runtime.h>
- #include <linux/kernel.h>
- #include <linux/gpio.h>
- #include <linux/i2c.h>
- #include <linux/of_gpio.h>
- #include <linux/regulator/consumer.h>
- #include <linux/mfd/wcd9xxx/pdata.h>
- #include <sound/pcm.h>
- #include <sound/pcm_params.h>
- #include <sound/soc.h>
- #include <sound/soc-dapm.h>
- #include <sound/tlv.h>
- #include <mach/qdsp6v2/apr.h>
- #include <mach/subsystem_notif.h>
- #include <sound/q6core.h>
- #include "msm8x10-wcd.h"
- #include "wcd9xxx-resmgr.h"
- #include "msm8x10_wcd_registers.h"
- #include "wcd9xxx-common.h"
- #define MSM8X10_WCD_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
- SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000)
- #define MSM8X10_WCD_FORMATS (SNDRV_PCM_FMTBIT_S16_LE)
- #define NUM_DECIMATORS 2
- #define NUM_INTERPOLATORS 3
- #define BITS_PER_REG 8
- #define MSM8X10_WCD_TX_PORT_NUMBER 4
- #define DAPM_MICBIAS_EXTERNAL_STANDALONE "MIC BIAS External Standalone"
- #define MSM8X10_WCD_I2S_MASTER_MODE_MASK 0x08
- #define MSM8X10_DINO_CODEC_BASE_ADDR 0xFE043000
- #define MSM8X10_DINO_CODEC_REG_SIZE 0x200
- #define MSM8x10_TLMM_CDC_PULL_CTL 0xFD512050
- #define HELICON_CORE_0_I2C_ADDR 0x0d
- #define HELICON_CORE_1_I2C_ADDR 0x77
- #define HELICON_CORE_2_I2C_ADDR 0x66
- #define HELICON_CORE_3_I2C_ADDR 0x55
- #define MAX_MSM8X10_WCD_DEVICE 4
- #define CODEC_DT_MAX_PROP_SIZE 40
- #define MAX_ON_DEMAND_SUPPLY_NAME_LENGTH 64
- #define HELICON_MCLK_CLK_9P6MHZ 9600000
- /*
- * Multiplication factor to compute impedance on codec
- * This is computed from (Vx / (m*Ical)) = (10mV/(180*30uA))
- */
- #define MSM8X10_WCD_ZDET_MUL_FACTOR 1852
- /* RX_HPH_CNP_WG_TIME increases by 0.24ms */
- #define MSM8X10_WCD_WG_TIME_FACTOR_US 240
- enum {
- MSM8X10_WCD_I2C_TOP_LEVEL = 0,
- MSM8X10_WCD_I2C_ANALOG,
- MSM8X10_WCD_I2C_DIGITAL_1,
- MSM8X10_WCD_I2C_DIGITAL_2,
- };
- enum {
- AIF1_PB = 0,
- AIF1_CAP,
- NUM_CODEC_DAIS,
- };
- enum {
- RX_MIX1_INP_SEL_ZERO = 0,
- RX_MIX1_INP_SEL_IIR1,
- RX_MIX1_INP_SEL_IIR2,
- RX_MIX1_INP_SEL_RX1,
- RX_MIX1_INP_SEL_RX2,
- RX_MIX1_INP_SEL_RX3,
- };
- static const DECLARE_TLV_DB_SCALE(digital_gain, 0, 1, 0);
- static const DECLARE_TLV_DB_SCALE(line_gain, 0, 7, 1);
- static const DECLARE_TLV_DB_SCALE(analog_gain, 0, 25, 1);
- static struct snd_soc_dai_driver msm8x10_wcd_i2s_dai[];
- static const DECLARE_TLV_DB_SCALE(aux_pga_gain, 0, 2, 0);
- #define MSM8X10_WCD_ACQUIRE_LOCK(x) do { \
- mutex_lock_nested(&x, SINGLE_DEPTH_NESTING); \
- } while (0)
- #define MSM8X10_WCD_RELEASE_LOCK(x) do { mutex_unlock(&x); } while (0)
- /* Codec supports 2 IIR filters */
- enum {
- IIR1 = 0,
- IIR2,
- IIR_MAX,
- };
- /* Codec supports 5 bands */
- enum {
- BAND1 = 0,
- BAND2,
- BAND3,
- BAND4,
- BAND5,
- BAND_MAX,
- };
- enum msm8x10_wcd_bandgap_type {
- MSM8X10_WCD_BANDGAP_OFF = 0,
- MSM8X10_WCD_BANDGAP_AUDIO_MODE,
- MSM8X10_WCD_BANDGAP_MBHC_MODE,
- };
- enum {
- ON_DEMAND_MICBIAS = 0,
- ON_DEMAND_CP,
- ON_DEMAND_SUPPLIES_MAX,
- };
- /*
- * The delay list is per codec HW specification.
- * Please add delay in the list in the future instead
- * of magic number
- */
- enum {
- CODEC_DELAY_1_MS = 1000,
- CODEC_DELAY_1_1_MS = 1100,
- };
- struct hpf_work {
- struct msm8x10_wcd_priv *msm8x10_wcd;
- u32 decimator;
- u8 tx_hpf_cut_of_freq;
- struct delayed_work dwork;
- };
- static struct hpf_work tx_hpf_work[NUM_DECIMATORS];
- struct on_demand_supply {
- struct regulator *supply;
- atomic_t ref;
- };
- static char on_demand_supply_name[][MAX_ON_DEMAND_SUPPLY_NAME_LENGTH] = {
- "cdc-vdd-mic-bias",
- "cdc-vdda-cp",
- };
- static int on_demand_regulator_control(struct on_demand_supply *supply,
- bool enable,
- u8 shift);
- struct msm8x10_wcd_priv {
- struct snd_soc_codec *codec;
- u32 adc_count;
- u32 rx_bias_count;
- s32 dmic_1_2_clk_cnt;
- struct on_demand_supply on_demand_list[ON_DEMAND_SUPPLIES_MAX];
- /* resmgr module */
- struct wcd9xxx_resmgr resmgr;
- /* mbhc module */
- struct wcd9xxx_mbhc mbhc;
- struct wcd9xxx_mbhc_config *mbhc_cfg;
- /*
- * list used to save/restore registers at start and
- * end of impedance measurement
- */
- struct list_head reg_save_restore;
- u32 micb_en_count;
- };
- static unsigned short rx_digital_gain_reg[] = {
- MSM8X10_WCD_A_CDC_RX1_VOL_CTL_B2_CTL,
- MSM8X10_WCD_A_CDC_RX2_VOL_CTL_B2_CTL,
- MSM8X10_WCD_A_CDC_RX3_VOL_CTL_B2_CTL,
- };
- static unsigned short tx_digital_gain_reg[] = {
- MSM8X10_WCD_A_CDC_TX1_VOL_CTL_GAIN,
- MSM8X10_WCD_A_CDC_TX2_VOL_CTL_GAIN,
- };
- struct msm8x10_wcd_i2c {
- struct i2c_client *client;
- struct i2c_msg xfer_msg[2];
- struct mutex xfer_lock;
- int mod_id;
- };
- static int msm8x10_wcd_dt_parse_vreg_info(struct device *dev,
- struct msm8x10_wcd_regulator *vreg,
- const char *vreg_name, bool ondemand);
- static int msm8x10_wcd_dt_parse_micbias_info(struct device *dev,
- struct wcd9xxx_micbias_setting *micbias);
- static struct msm8x10_wcd_pdata *msm8x10_wcd_populate_dt_pdata(
- struct device *dev);
- struct msm8x10_wcd_i2c msm8x10_wcd_modules[MAX_MSM8X10_WCD_DEVICE];
- static void *adsp_state_notifier;
- static struct snd_soc_codec *registered_codec;
- #define ADSP_STATE_READY_TIMEOUT_MS 2000
- static int get_i2c_msm8x10_wcd_device_info(u16 reg,
- struct msm8x10_wcd_i2c **msm8x10_wcd)
- {
- int rtn = 0;
- int value = ((reg & 0x0f00) >> 8) & 0x000f;
- switch (value) {
- case 0:
- case 1:
- *msm8x10_wcd = &msm8x10_wcd_modules[value];
- break;
- default:
- rtn = -EINVAL;
- break;
- }
- return rtn;
- }
- static int msm8x10_wcd_abh_write_device(struct msm8x10_wcd *msm8x10_wcd,
- u16 reg, u8 *value, u32 bytes)
- {
- u32 temp = ((u32)(*value)) & 0x000000FF;
- u32 offset = (((u32)(reg)) ^ 0x00000400) & 0x00000FFF;
- iowrite32(temp, (msm8x10_wcd->pdino_base+offset));
- return 0;
- }
- static int msm8x10_wcd_abh_read_device(struct msm8x10_wcd *msm8x10_wcd,
- u16 reg, u32 bytes, u8 *value)
- {
- u32 temp;
- u32 offset = (((u32)(reg)) ^ 0x00000400) & 0x00000FFF;
- temp = ioread32((msm8x10_wcd->pdino_base+offset));
- *value = (u8)temp;
- return 0;
- }
- static int msm8x10_wcd_i2c_write_device(u16 reg, u8 *value, u32 bytes)
- {
- struct i2c_msg *msg;
- int ret;
- u8 reg_addr = 0;
- u8 data[bytes + 1];
- struct msm8x10_wcd_i2c *msm8x10_wcd = NULL;
- ret = get_i2c_msm8x10_wcd_device_info(reg, &msm8x10_wcd);
- if (ret) {
- pr_err("%s: Invalid register address\n", __func__);
- return ret;
- }
- if (msm8x10_wcd == NULL || msm8x10_wcd->client == NULL) {
- pr_err("%s: Failed to get device info\n", __func__);
- return -ENODEV;
- }
- reg_addr = (u8)reg;
- msg = &msm8x10_wcd->xfer_msg[0];
- msg->addr = msm8x10_wcd->client->addr;
- msg->len = bytes + 1;
- msg->flags = 0;
- data[0] = reg;
- data[1] = *value;
- msg->buf = data;
- ret = i2c_transfer(msm8x10_wcd->client->adapter,
- msm8x10_wcd->xfer_msg, 1);
- /* Try again if the write fails */
- if (ret != 1) {
- ret = i2c_transfer(msm8x10_wcd->client->adapter,
- msm8x10_wcd->xfer_msg, 1);
- if (ret != 1) {
- pr_err("failed to write the device\n");
- return ret;
- }
- }
- return 0;
- }
- int msm8x10_wcd_i2c_read_device(u32 reg, u32 bytes, u8 *dest)
- {
- struct i2c_msg *msg;
- int ret = 0;
- u8 reg_addr = 0;
- struct msm8x10_wcd_i2c *msm8x10_wcd = NULL;
- u8 i = 0;
- ret = get_i2c_msm8x10_wcd_device_info(reg, &msm8x10_wcd);
- if (ret) {
- pr_err("%s: Invalid register address\n", __func__);
- return ret;
- }
- if (msm8x10_wcd == NULL || msm8x10_wcd->client == NULL) {
- pr_err("%s: Failed to get device info\n", __func__);
- return -ENODEV;
- }
- for (i = 0; i < bytes; i++) {
- reg_addr = (u8)reg++;
- msg = &msm8x10_wcd->xfer_msg[0];
- msg->addr = msm8x10_wcd->client->addr;
- msg->len = 1;
- msg->flags = 0;
- msg->buf = ®_addr;
- msg = &msm8x10_wcd->xfer_msg[1];
- msg->addr = msm8x10_wcd->client->addr;
- msg->len = 1;
- msg->flags = I2C_M_RD;
- msg->buf = dest++;
- ret = i2c_transfer(msm8x10_wcd->client->adapter,
- msm8x10_wcd->xfer_msg, 2);
- /* Try again if read fails first time */
- if (ret != 2) {
- ret = i2c_transfer(msm8x10_wcd->client->adapter,
- msm8x10_wcd->xfer_msg, 2);
- if (ret != 2) {
- pr_err("failed to read msm8x10_wcd register\n");
- return ret;
- }
- }
- }
- return 0;
- }
- int msm8x10_wcd_i2c_read(unsigned short reg, int bytes, void *dest)
- {
- return msm8x10_wcd_i2c_read_device(reg, bytes, dest);
- }
- int msm8x10_wcd_i2c_write(unsigned short reg, int bytes, void *src)
- {
- return msm8x10_wcd_i2c_write_device(reg, src, bytes);
- }
- static unsigned short msm8x10_wcd_mask_reg(unsigned short reg)
- {
- if (reg >= 0x3C0 && reg <= 0x3DF)
- reg = reg & 0x00FF;
- return reg;
- }
- static int __msm8x10_wcd_reg_read(struct msm8x10_wcd *msm8x10_wcd,
- unsigned short reg)
- {
- int ret = -EINVAL;
- u8 temp;
- reg = msm8x10_wcd_mask_reg(reg);
- /* check if use I2C interface for Helicon or AHB for Dino */
- mutex_lock(&msm8x10_wcd->io_lock);
- if (MSM8X10_WCD_IS_HELICON_REG(reg))
- ret = msm8x10_wcd_i2c_read(reg, 1, &temp);
- else if (MSM8X10_WCD_IS_DINO_REG(reg))
- ret = msm8x10_wcd_abh_read_device(msm8x10_wcd, reg, 1, &temp);
- mutex_unlock(&msm8x10_wcd->io_lock);
- if (ret < 0) {
- dev_err(msm8x10_wcd->dev,
- "%s: codec read failed for reg 0x%x\n",
- __func__, reg);
- return ret;
- } else {
- dev_dbg(msm8x10_wcd->dev, "Read 0x%02x from 0x%x\n",
- temp, reg);
- }
- return temp;
- }
- static int __msm8x10_wcd_bulk_write(struct msm8x10_wcd *msm8x10_wcd,
- unsigned short reg, int count, u8 *buf)
- {
- int ret = -EINVAL;
- mutex_lock(&msm8x10_wcd->io_lock);
- if (MSM8X10_WCD_IS_HELICON_REG(reg))
- ret = msm8x10_wcd_i2c_write(reg, count, buf);
- else if (MSM8X10_WCD_IS_DINO_REG(reg))
- ret = msm8x10_wcd_abh_write_device(msm8x10_wcd, reg,
- buf, count);
- if (ret < 0)
- dev_err(msm8x10_wcd->dev,
- "%s: codec bulk write failed\n", __func__);
- mutex_unlock(&msm8x10_wcd->io_lock);
- return ret;
- }
- int msm8x10_wcd_bulk_write(struct wcd9xxx_core_resource *core_res,
- unsigned short reg, int count, u8 *buf)
- {
- struct msm8x10_wcd *msm8x10_wcd =
- (struct msm8x10_wcd *) core_res->parent;
- return __msm8x10_wcd_bulk_write(msm8x10_wcd, reg, count, buf);
- }
- EXPORT_SYMBOL(msm8x10_wcd_bulk_write);
- int msm8x10_wcd_reg_read(struct wcd9xxx_core_resource *core_res,
- unsigned short reg)
- {
- struct msm8x10_wcd *msm8x10_wcd = core_res->parent;
- return __msm8x10_wcd_reg_read(msm8x10_wcd, reg);
- }
- EXPORT_SYMBOL(msm8x10_wcd_reg_read);
- static int __msm8x10_wcd_bulk_read(struct msm8x10_wcd *msm8x10_wcd,
- unsigned short reg, int count, u8 *buf)
- {
- int ret = -EINVAL;
- mutex_lock(&msm8x10_wcd->io_lock);
- if (MSM8X10_WCD_IS_HELICON_REG(reg))
- ret = msm8x10_wcd_i2c_read(reg, count, buf);
- else if (MSM8X10_WCD_IS_DINO_REG(reg))
- ret = msm8x10_wcd_abh_read_device(msm8x10_wcd, reg,
- count, buf);
- mutex_unlock(&msm8x10_wcd->io_lock);
- if (ret < 0)
- dev_err(msm8x10_wcd->dev,
- "%s: codec bulk read failed\n", __func__);
- return ret;
- }
- int msm8x10_wcd_bulk_read(struct wcd9xxx_core_resource *core_res,
- unsigned short reg, int count, u8 *buf)
- {
- struct msm8x10_wcd *msm8x10_wcd =
- (struct msm8x10_wcd *) core_res->parent;
- return __msm8x10_wcd_bulk_read(msm8x10_wcd, reg, count, buf);
- }
- EXPORT_SYMBOL(msm8x10_wcd_bulk_read);
- static int __msm8x10_wcd_reg_write(struct msm8x10_wcd *msm8x10_wcd,
- unsigned short reg, u8 val)
- {
- int ret = -EINVAL;
- reg = msm8x10_wcd_mask_reg(reg);
- /* check if use I2C interface for Helicon or AHB for Dino */
- mutex_lock(&msm8x10_wcd->io_lock);
- if (MSM8X10_WCD_IS_HELICON_REG(reg))
- ret = msm8x10_wcd_i2c_write(reg, 1, &val);
- else if (MSM8X10_WCD_IS_DINO_REG(reg))
- ret = msm8x10_wcd_abh_write_device(msm8x10_wcd, reg, &val, 1);
- mutex_unlock(&msm8x10_wcd->io_lock);
- if (ret < 0)
- dev_err(msm8x10_wcd->dev,
- "%s: codec write to reg 0x%x failed\n",
- __func__, reg);
- else
- dev_dbg(msm8x10_wcd->dev,
- "%s: Write 0x%x to 0x%x\n",
- __func__, val, reg);
- return ret;
- }
- int msm8x10_wcd_reg_write(struct wcd9xxx_core_resource *core_res,
- unsigned short reg, u8 val)
- {
- struct msm8x10_wcd *msm8x10_wcd = core_res->parent;
- return __msm8x10_wcd_reg_write(msm8x10_wcd, reg, val);
- }
- EXPORT_SYMBOL(msm8x10_wcd_reg_write);
- static bool msm8x10_wcd_is_digital_gain_register(unsigned int reg)
- {
- bool rtn = false;
- switch (reg) {
- case MSM8X10_WCD_A_CDC_RX1_VOL_CTL_B2_CTL:
- case MSM8X10_WCD_A_CDC_RX2_VOL_CTL_B2_CTL:
- case MSM8X10_WCD_A_CDC_RX3_VOL_CTL_B2_CTL:
- case MSM8X10_WCD_A_CDC_TX1_VOL_CTL_GAIN:
- case MSM8X10_WCD_A_CDC_TX2_VOL_CTL_GAIN:
- rtn = true;
- break;
- default:
- break;
- }
- return rtn;
- }
- static int msm8x10_wcd_volatile(struct snd_soc_codec *codec, unsigned int reg)
- {
- /*
- * Registers lower than 0x100 are top level registers which can be
- * written by the Taiko core driver.
- */
- if ((reg >= MSM8X10_WCD_A_CDC_MBHC_EN_CTL) || (reg < 0x100))
- return 1;
- /* IIR Coeff registers are not cacheable */
- if ((reg >= MSM8X10_WCD_A_CDC_IIR1_COEF_B1_CTL) &&
- (reg <= MSM8X10_WCD_A_CDC_IIR2_COEF_B2_CTL))
- return 1;
- /*
- * Digital gain register is not cacheable so we have to write
- * the setting even it is the same
- */
- if (msm8x10_wcd_is_digital_gain_register(reg))
- return 1;
- /* HPH status registers */
- if (reg == MSM8X10_WCD_A_RX_HPH_L_STATUS ||
- reg == MSM8X10_WCD_A_RX_HPH_R_STATUS)
- return 1;
- if (reg == MSM8X10_WCD_A_MBHC_INSERT_DET_STATUS)
- return 1;
- return 0;
- }
- static int msm8x10_wcd_readable(struct snd_soc_codec *ssc, unsigned int reg)
- {
- return msm8x10_wcd_reg_readable[reg];
- }
- static int msm8x10_wcd_write(struct snd_soc_codec *codec, unsigned int reg,
- unsigned int value)
- {
- int ret;
- dev_dbg(codec->dev, "%s: Write to reg 0x%x\n", __func__, reg);
- if (reg == SND_SOC_NOPM)
- return 0;
- BUG_ON(reg > MSM8X10_WCD_MAX_REGISTER);
- if (!msm8x10_wcd_volatile(codec, reg)) {
- ret = snd_soc_cache_write(codec, reg, value);
- if (ret != 0)
- dev_err(codec->dev, "Cache write to %x failed: %d\n",
- reg, ret);
- }
- return __msm8x10_wcd_reg_write(codec->control_data, reg, (u8)value);
- }
- static unsigned int msm8x10_wcd_read(struct snd_soc_codec *codec,
- unsigned int reg)
- {
- unsigned int val;
- int ret;
- dev_dbg(codec->dev, "%s: Read from reg 0x%x\n", __func__, reg);
- if (reg == SND_SOC_NOPM)
- return 0;
- BUG_ON(reg > MSM8X10_WCD_MAX_REGISTER);
- if (!msm8x10_wcd_volatile(codec, reg) &&
- msm8x10_wcd_readable(codec, reg) &&
- reg < codec->driver->reg_cache_size) {
- ret = snd_soc_cache_read(codec, reg, &val);
- if (ret >= 0) {
- return val;
- } else
- dev_err(codec->dev, "Cache read from %x failed: %d\n",
- reg, ret);
- }
- val = __msm8x10_wcd_reg_read(codec->control_data, reg);
- return val;
- }
- static int msm8x10_wcd_dt_parse_vreg_info(struct device *dev,
- struct msm8x10_wcd_regulator *vreg, const char *vreg_name,
- bool ondemand)
- {
- int len, ret = 0;
- const __be32 *prop;
- char prop_name[CODEC_DT_MAX_PROP_SIZE];
- struct device_node *regnode = NULL;
- u32 prop_val;
- snprintf(prop_name, CODEC_DT_MAX_PROP_SIZE, "%s-supply",
- vreg_name);
- regnode = of_parse_phandle(dev->of_node, prop_name, 0);
- if (!regnode) {
- dev_err(dev, "Looking up %s property in node %s failed\n",
- prop_name, dev->of_node->full_name);
- return -ENODEV;
- }
- dev_dbg(dev, "Looking up %s property in node %s\n",
- prop_name, dev->of_node->full_name);
- vreg->name = vreg_name;
- vreg->ondemand = ondemand;
- snprintf(prop_name, CODEC_DT_MAX_PROP_SIZE,
- "qcom,%s-voltage", vreg_name);
- prop = of_get_property(dev->of_node, prop_name, &len);
- if (!prop || (len != (2 * sizeof(__be32)))) {
- dev_err(dev, "%s %s property\n",
- prop ? "invalid format" : "no", prop_name);
- return -EINVAL;
- } else {
- vreg->min_uV = be32_to_cpup(&prop[0]);
- vreg->max_uV = be32_to_cpup(&prop[1]);
- }
- snprintf(prop_name, CODEC_DT_MAX_PROP_SIZE,
- "qcom,%s-current", vreg_name);
- ret = of_property_read_u32(dev->of_node, prop_name, &prop_val);
- if (ret) {
- dev_err(dev, "Looking up %s property in node %s failed",
- prop_name, dev->of_node->full_name);
- return -EFAULT;
- }
- vreg->optimum_uA = prop_val;
- dev_info(dev, "%s: vol=[%d %d]uV, curr=[%d]uA, ond %d\n\n", vreg->name,
- vreg->min_uV, vreg->max_uV, vreg->optimum_uA, vreg->ondemand);
- return 0;
- }
- static int msm8x10_wcd_dt_parse_micbias_info(struct device *dev,
- struct wcd9xxx_micbias_setting *micbias)
- {
- int ret = 0;
- char prop_name[CODEC_DT_MAX_PROP_SIZE];
- u32 prop_val;
- snprintf(prop_name, CODEC_DT_MAX_PROP_SIZE,
- "qcom,cdc-micbias-ldoh-v");
- ret = of_property_read_u32(dev->of_node, prop_name,
- &prop_val);
- if (ret) {
- dev_err(dev, "Looking up %s property in node %s failed",
- prop_name, dev->of_node->full_name);
- return -ENODEV;
- }
- micbias->ldoh_v = (u8) prop_val;
- snprintf(prop_name, CODEC_DT_MAX_PROP_SIZE,
- "qcom,cdc-micbias-cfilt-mv");
- ret = of_property_read_u32(dev->of_node, prop_name,
- &micbias->cfilt1_mv);
- if (ret) {
- dev_err(dev, "Looking up %s property in node %s failed",
- prop_name, dev->of_node->full_name);
- return -ENODEV;
- }
- snprintf(prop_name, CODEC_DT_MAX_PROP_SIZE,
- "qcom,cdc-micbias-cfilt-sel");
- ret = of_property_read_u32(dev->of_node, prop_name, &prop_val);
- if (ret) {
- dev_err(dev, "Looking up %s property in node %s failed",
- prop_name, dev->of_node->full_name);
- return -ENODEV;
- }
- micbias->bias1_cfilt_sel = (u8)prop_val;
- /* micbias external cap */
- micbias->bias1_cap_mode =
- (of_property_read_bool(dev->of_node, "qcom,cdc-micbias1-ext-cap") ?
- MICBIAS_EXT_BYP_CAP : MICBIAS_NO_EXT_BYP_CAP);
- dev_dbg(dev, "ldoh_v %u cfilt1_mv %u\n",
- (u32)micbias->ldoh_v, (u32)micbias->cfilt1_mv);
- dev_dbg(dev, "bias1_cfilt_sel %u\n", (u32)micbias->bias1_cfilt_sel);
- dev_dbg(dev, "bias1_ext_cap %d\n", micbias->bias1_cap_mode);
- return 0;
- }
- static struct msm8x10_wcd_pdata *msm8x10_wcd_populate_dt_pdata(
- struct device *dev)
- {
- struct msm8x10_wcd_pdata *pdata;
- int ret, static_cnt, ond_cnt, idx, i;
- const char *name = NULL;
- const char *static_prop_name = "qcom,cdc-static-supplies";
- const char *ond_prop_name = "qcom,cdc-on-demand-supplies";
- pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
- if (!pdata) {
- dev_err(dev, "could not allocate memory for platform data\n");
- return NULL;
- }
- static_cnt = of_property_count_strings(dev->of_node, static_prop_name);
- if (IS_ERR_VALUE(static_cnt)) {
- dev_err(dev, "%s: Failed to get static supplies %d\n", __func__,
- static_cnt);
- ret = -EINVAL;
- goto err;
- }
- /* On-demand supply list is an optional property */
- ond_cnt = of_property_count_strings(dev->of_node, ond_prop_name);
- if (IS_ERR_VALUE(ond_cnt))
- ond_cnt = 0;
- BUG_ON(static_cnt <= 0 || ond_cnt < 0);
- if ((static_cnt + ond_cnt) > ARRAY_SIZE(pdata->regulator)) {
- dev_err(dev, "%s: Num of supplies %u > max supported %u\n",
- __func__, static_cnt, ARRAY_SIZE(pdata->regulator));
- ret = -EINVAL;
- goto err;
- }
- for (idx = 0; idx < static_cnt; idx++) {
- ret = of_property_read_string_index(dev->of_node,
- static_prop_name, idx,
- &name);
- if (ret) {
- dev_err(dev, "%s: of read string %s idx %d error %d\n",
- __func__, static_prop_name, idx, ret);
- goto err;
- }
- dev_dbg(dev, "%s: Found static cdc supply %s\n", __func__,
- name);
- ret = msm8x10_wcd_dt_parse_vreg_info(dev,
- &pdata->regulator[idx],
- name, false);
- if (ret)
- goto err;
- }
- for (i = 0; i < ond_cnt; i++, idx++) {
- ret = of_property_read_string_index(dev->of_node, ond_prop_name,
- i, &name);
- if (ret)
- goto err;
- dev_dbg(dev, "%s: Found on-demand cdc supply %s\n", __func__,
- name);
- ret = msm8x10_wcd_dt_parse_vreg_info(dev,
- &pdata->regulator[idx],
- name, true);
- if (ret)
- goto err;
- }
- ret = msm8x10_wcd_dt_parse_micbias_info(dev, &pdata->micbias);
- if (ret)
- goto err;
- return pdata;
- err:
- devm_kfree(dev, pdata);
- dev_err(dev, "%s: Failed to populate DT data ret = %d\n",
- __func__, ret);
- return NULL;
- }
- static int on_demand_regulator_control(struct on_demand_supply *supply,
- bool enable,
- u8 shift)
- {
- int ret = 0;
- if (!supply || !supply->supply)
- return 0;
- if (enable) {
- if (atomic_inc_return(&supply->ref) == 1)
- ret = regulator_enable(supply->supply);
- if (ret)
- pr_err("%s: Failed to enable %s\n",
- __func__,
- on_demand_supply_name[shift]);
- } else {
- if (atomic_read(&supply->ref) == 0) {
- pr_debug("%s: %s supply has been disabled.\n",
- __func__, on_demand_supply_name[shift]);
- return 0;
- }
- if (atomic_dec_return(&supply->ref) == 0)
- ret = regulator_disable(supply->supply);
- if (ret)
- pr_err("%s: Failed to disable %s\n",
- __func__,
- on_demand_supply_name[shift]);
- }
- return ret;
- }
- static int msm8x10_wcd_codec_enable_on_demand_supply(
- struct snd_soc_dapm_widget *w,
- struct snd_kcontrol *kcontrol, int event)
- {
- int ret = 0;
- struct snd_soc_codec *codec = w->codec;
- struct msm8x10_wcd_priv *msm8x10_wcd = snd_soc_codec_get_drvdata(codec);
- struct on_demand_supply *supply;
- if (w->shift >= ON_DEMAND_SUPPLIES_MAX) {
- ret = -EINVAL;
- goto out;
- }
- dev_dbg(codec->dev, "%s: supply: %s event: %d ref: %d\n",
- __func__, on_demand_supply_name[w->shift], event,
- atomic_read(&msm8x10_wcd->on_demand_list[w->shift].ref));
- supply = &msm8x10_wcd->on_demand_list[w->shift];
- WARN_ONCE(!supply->supply, "%s isn't defined\n",
- on_demand_supply_name[w->shift]);
- if (!supply->supply)
- goto out;
- switch (event) {
- case SND_SOC_DAPM_PRE_PMU:
- ret = on_demand_regulator_control(supply,
- true,
- w->shift);
- break;
- case SND_SOC_DAPM_POST_PMD:
- ret = on_demand_regulator_control(supply,
- false,
- w->shift);
- break;
- default:
- break;
- }
- out:
- return ret;
- }
- static int msm8x10_wcd_codec_enable_charge_pump(struct snd_soc_dapm_widget *w,
- struct snd_kcontrol *kcontrol, int event)
- {
- struct snd_soc_codec *codec = w->codec;
- dev_dbg(codec->dev, "%s: event = %d\n", __func__, event);
- switch (event) {
- case SND_SOC_DAPM_POST_PMU:
- /* Enable charge pump clock*/
- snd_soc_update_bits(codec, MSM8X10_WCD_A_CDC_CLK_OTHR_CTL,
- 0x01, 0x01);
- snd_soc_update_bits(codec, MSM8X10_WCD_A_CDC_CLSG_CTL,
- 0x08, 0x08);
- usleep_range(200, 300);
- snd_soc_update_bits(codec, MSM8X10_WCD_A_CP_STATIC,
- 0x10, 0x00);
- break;
- case SND_SOC_DAPM_PRE_PMD:
- snd_soc_update_bits(codec,
- MSM8X10_WCD_A_CDC_CLK_OTHR_RESET_B1_CTL,
- 0x01, 0x01);
- usleep_range(20, 100);
- snd_soc_update_bits(codec,
- MSM8X10_WCD_A_CP_STATIC, 0x08, 0x08);
- snd_soc_update_bits(codec,
- MSM8X10_WCD_A_CP_STATIC, 0x10, 0x10);
- snd_soc_update_bits(codec,
- MSM8X10_WCD_A_CDC_CLSG_CTL, 0x08, 0x00);
- snd_soc_update_bits(codec,
- MSM8X10_WCD_A_CDC_CLK_OTHR_CTL, 0x01,
- 0x00);
- snd_soc_update_bits(codec,
- MSM8X10_WCD_A_CDC_CLK_OTHR_RESET_B1_CTL,
- 0x01, 0x00);
- snd_soc_update_bits(codec,
- MSM8X10_WCD_A_CP_STATIC, 0x08, 0x00);
- break;
- default:
- break;
- }
- return 0;
- }
- static int msm8x10_wcd_pa_gain_get(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- u8 ear_pa_gain;
- struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
- ear_pa_gain = snd_soc_read(codec, MSM8X10_WCD_A_RX_EAR_GAIN);
- ear_pa_gain = ear_pa_gain >> 5;
- if (ear_pa_gain == 0x00) {
- ucontrol->value.integer.value[0] = 0;
- } else if (ear_pa_gain == 0x04) {
- ucontrol->value.integer.value[0] = 1;
- } else {
- dev_err(codec->dev, "%s: ERROR: Unsupported Ear Gain = 0x%x\n",
- __func__, ear_pa_gain);
- return -EINVAL;
- }
- dev_dbg(codec->dev, "%s: ear_pa_gain = 0x%x\n", __func__, ear_pa_gain);
- return 0;
- }
- static int msm8x10_wcd_pa_gain_put(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- u8 ear_pa_gain;
- struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
- dev_dbg(codec->dev, "%s: ucontrol->value.integer.value[0] = %ld\n",
- __func__, ucontrol->value.integer.value[0]);
- switch (ucontrol->value.integer.value[0]) {
- case 0:
- ear_pa_gain = 0x00;
- break;
- case 1:
- ear_pa_gain = 0x80;
- break;
- default:
- return -EINVAL;
- }
- snd_soc_update_bits(codec, MSM8X10_WCD_A_RX_EAR_GAIN,
- 0xE0, ear_pa_gain);
- return 0;
- }
- static int msm8x10_wcd_get_iir_enable_audio_mixer(
- struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
- int iir_idx = ((struct soc_multi_mixer_control *)
- kcontrol->private_value)->reg;
- int band_idx = ((struct soc_multi_mixer_control *)
- kcontrol->private_value)->shift;
- ucontrol->value.integer.value[0] =
- (snd_soc_read(codec,
- (MSM8X10_WCD_A_CDC_IIR1_CTL + 64 * iir_idx)) &
- (1 << band_idx)) != 0;
- dev_dbg(codec->dev, "%s: IIR #%d band #%d enable %d\n", __func__,
- iir_idx, band_idx,
- (uint32_t)ucontrol->value.integer.value[0]);
- return 0;
- }
- static int msm8x10_wcd_put_iir_enable_audio_mixer(
- struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
- int iir_idx = ((struct soc_multi_mixer_control *)
- kcontrol->private_value)->reg;
- int band_idx = ((struct soc_multi_mixer_control *)
- kcontrol->private_value)->shift;
- int value = ucontrol->value.integer.value[0];
- /* Mask first 5 bits, 6-8 are reserved */
- snd_soc_update_bits(codec, (MSM8X10_WCD_A_CDC_IIR1_CTL + 64 * iir_idx),
- (1 << band_idx), (value << band_idx));
- dev_dbg(codec->dev, "%s: IIR #%d band #%d enable %d\n", __func__,
- iir_idx, band_idx,
- ((snd_soc_read(codec, (MSM8X10_WCD_A_CDC_IIR1_CTL + 64 * iir_idx)) &
- (1 << band_idx)) != 0));
- return 0;
- }
- static uint32_t get_iir_band_coeff(struct snd_soc_codec *codec,
- int iir_idx, int band_idx,
- int coeff_idx)
- {
- uint32_t value = 0;
- /* Address does not automatically update if reading */
- snd_soc_write(codec,
- (MSM8X10_WCD_A_CDC_IIR1_COEF_B1_CTL + 64 * iir_idx),
- ((band_idx * BAND_MAX + coeff_idx)
- * sizeof(uint32_t)) & 0x7F);
- value |= snd_soc_read(codec,
- (MSM8X10_WCD_A_CDC_IIR1_COEF_B2_CTL + 64 * iir_idx));
- snd_soc_write(codec,
- (MSM8X10_WCD_A_CDC_IIR1_COEF_B1_CTL + 64 * iir_idx),
- ((band_idx * BAND_MAX + coeff_idx)
- * sizeof(uint32_t) + 1) & 0x7F);
- value |= (snd_soc_read(codec,
- (MSM8X10_WCD_A_CDC_IIR1_COEF_B2_CTL + 64 * iir_idx)) << 8);
- snd_soc_write(codec,
- (MSM8X10_WCD_A_CDC_IIR1_COEF_B1_CTL + 64 * iir_idx),
- ((band_idx * BAND_MAX + coeff_idx)
- * sizeof(uint32_t) + 2) & 0x7F);
- value |= (snd_soc_read(codec,
- (MSM8X10_WCD_A_CDC_IIR1_COEF_B2_CTL + 64 * iir_idx)) << 16);
- snd_soc_write(codec,
- (MSM8X10_WCD_A_CDC_IIR1_COEF_B1_CTL + 64 * iir_idx),
- ((band_idx * BAND_MAX + coeff_idx)
- * sizeof(uint32_t) + 3) & 0x7F);
- /* Mask bits top 2 bits since they are reserved */
- value |= ((snd_soc_read(codec,
- (MSM8X10_WCD_A_CDC_IIR1_COEF_B2_CTL + 64 * iir_idx)) & 0x3f) << 24);
- return value;
- }
- static int msm8x10_wcd_get_iir_band_audio_mixer(
- struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
- int iir_idx = ((struct soc_multi_mixer_control *)
- kcontrol->private_value)->reg;
- int band_idx = ((struct soc_multi_mixer_control *)
- kcontrol->private_value)->shift;
- ucontrol->value.integer.value[0] =
- get_iir_band_coeff(codec, iir_idx, band_idx, 0);
- ucontrol->value.integer.value[1] =
- get_iir_band_coeff(codec, iir_idx, band_idx, 1);
- ucontrol->value.integer.value[2] =
- get_iir_band_coeff(codec, iir_idx, band_idx, 2);
- ucontrol->value.integer.value[3] =
- get_iir_band_coeff(codec, iir_idx, band_idx, 3);
- ucontrol->value.integer.value[4] =
- get_iir_band_coeff(codec, iir_idx, band_idx, 4);
- dev_dbg(codec->dev, "%s: IIR #%d band #%d b0 = 0x%x\n"
- "%s: IIR #%d band #%d b1 = 0x%x\n"
- "%s: IIR #%d band #%d b2 = 0x%x\n"
- "%s: IIR #%d band #%d a1 = 0x%x\n"
- "%s: IIR #%d band #%d a2 = 0x%x\n",
- __func__, iir_idx, band_idx,
- (uint32_t)ucontrol->value.integer.value[0],
- __func__, iir_idx, band_idx,
- (uint32_t)ucontrol->value.integer.value[1],
- __func__, iir_idx, band_idx,
- (uint32_t)ucontrol->value.integer.value[2],
- __func__, iir_idx, band_idx,
- (uint32_t)ucontrol->value.integer.value[3],
- __func__, iir_idx, band_idx,
- (uint32_t)ucontrol->value.integer.value[4]);
- return 0;
- }
- static void set_iir_band_coeff(struct snd_soc_codec *codec,
- int iir_idx, int band_idx,
- uint32_t value)
- {
- snd_soc_write(codec,
- (MSM8X10_WCD_A_CDC_IIR1_COEF_B2_CTL + 64 * iir_idx),
- (value & 0xFF));
- snd_soc_write(codec,
- (MSM8X10_WCD_A_CDC_IIR1_COEF_B2_CTL + 64 * iir_idx),
- (value >> 8) & 0xFF);
- snd_soc_write(codec,
- (MSM8X10_WCD_A_CDC_IIR1_COEF_B2_CTL + 64 * iir_idx),
- (value >> 16) & 0xFF);
- /* Mask top 2 bits, 7-8 are reserved */
- snd_soc_write(codec,
- (MSM8X10_WCD_A_CDC_IIR1_COEF_B2_CTL + 64 * iir_idx),
- (value >> 24) & 0x3F);
- }
- static int msm8x10_wcd_put_iir_band_audio_mixer(
- struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
- int iir_idx = ((struct soc_multi_mixer_control *)
- kcontrol->private_value)->reg;
- int band_idx = ((struct soc_multi_mixer_control *)
- kcontrol->private_value)->shift;
- /* Mask top bit it is reserved */
- /* Updates addr automatically for each B2 write */
- snd_soc_write(codec,
- (MSM8X10_WCD_A_CDC_IIR1_COEF_B1_CTL + 64 * iir_idx),
- (band_idx * BAND_MAX * sizeof(uint32_t)) & 0x7F);
- set_iir_band_coeff(codec, iir_idx, band_idx,
- ucontrol->value.integer.value[0]);
- set_iir_band_coeff(codec, iir_idx, band_idx,
- ucontrol->value.integer.value[1]);
- set_iir_band_coeff(codec, iir_idx, band_idx,
- ucontrol->value.integer.value[2]);
- set_iir_band_coeff(codec, iir_idx, band_idx,
- ucontrol->value.integer.value[3]);
- set_iir_band_coeff(codec, iir_idx, band_idx,
- ucontrol->value.integer.value[4]);
- dev_dbg(codec->dev, "%s: IIR #%d band #%d b0 = 0x%x\n"
- "%s: IIR #%d band #%d b1 = 0x%x\n"
- "%s: IIR #%d band #%d b2 = 0x%x\n"
- "%s: IIR #%d band #%d a1 = 0x%x\n"
- "%s: IIR #%d band #%d a2 = 0x%x\n",
- __func__, iir_idx, band_idx,
- get_iir_band_coeff(codec, iir_idx, band_idx, 0),
- __func__, iir_idx, band_idx,
- get_iir_band_coeff(codec, iir_idx, band_idx, 1),
- __func__, iir_idx, band_idx,
- get_iir_band_coeff(codec, iir_idx, band_idx, 2),
- __func__, iir_idx, band_idx,
- get_iir_band_coeff(codec, iir_idx, band_idx, 3),
- __func__, iir_idx, band_idx,
- get_iir_band_coeff(codec, iir_idx, band_idx, 4));
- return 0;
- }
- static const char * const msm8x10_wcd_ear_pa_gain_text[] = {
- "POS_6_DB", "POS_2_DB"};
- static const struct soc_enum msm8x10_wcd_ear_pa_gain_enum[] = {
- SOC_ENUM_SINGLE_EXT(2, msm8x10_wcd_ear_pa_gain_text),
- };
- /*cut of frequency for high pass filter*/
- static const char * const cf_text[] = {
- "MIN_3DB_4Hz", "MIN_3DB_75Hz", "MIN_3DB_150Hz"
- };
- static const struct soc_enum cf_dec1_enum =
- SOC_ENUM_SINGLE(MSM8X10_WCD_A_CDC_TX1_MUX_CTL, 4, 3, cf_text);
- static const struct soc_enum cf_dec2_enum =
- SOC_ENUM_SINGLE(MSM8X10_WCD_A_CDC_TX2_MUX_CTL, 4, 3, cf_text);
- static const struct soc_enum cf_rxmix1_enum =
- SOC_ENUM_SINGLE(MSM8X10_WCD_A_CDC_RX1_B4_CTL, 0, 3, cf_text);
- static const struct soc_enum cf_rxmix2_enum =
- SOC_ENUM_SINGLE(MSM8X10_WCD_A_CDC_RX2_B4_CTL, 0, 3, cf_text);
- static const struct soc_enum cf_rxmix3_enum =
- SOC_ENUM_SINGLE(MSM8X10_WCD_A_CDC_RX3_B4_CTL, 0, 3, cf_text);
- static const struct snd_kcontrol_new msm8x10_wcd_snd_controls[] = {
- SOC_ENUM_EXT("EAR PA Gain", msm8x10_wcd_ear_pa_gain_enum[0],
- msm8x10_wcd_pa_gain_get, msm8x10_wcd_pa_gain_put),
- SOC_SINGLE_TLV("LINEOUT Volume", MSM8X10_WCD_A_RX_LINE_1_GAIN,
- 0, 12, 1, line_gain),
- SOC_SINGLE_TLV("HPHL Volume", MSM8X10_WCD_A_RX_HPH_L_GAIN,
- 0, 12, 1, line_gain),
- SOC_SINGLE_TLV("HPHR Volume", MSM8X10_WCD_A_RX_HPH_R_GAIN,
- 0, 12, 1, line_gain),
- SOC_SINGLE_S8_TLV("RX1 Digital Volume",
- MSM8X10_WCD_A_CDC_RX1_VOL_CTL_B2_CTL,
- -84, 40, digital_gain),
- SOC_SINGLE_S8_TLV("RX2 Digital Volume",
- MSM8X10_WCD_A_CDC_RX2_VOL_CTL_B2_CTL,
- -84, 40, digital_gain),
- SOC_SINGLE_S8_TLV("RX3 Digital Volume",
- MSM8X10_WCD_A_CDC_RX3_VOL_CTL_B2_CTL,
- -84, 40, digital_gain),
- SOC_SINGLE_S8_TLV("DEC1 Volume",
- MSM8X10_WCD_A_CDC_TX1_VOL_CTL_GAIN,
- -84, 40, digital_gain),
- SOC_SINGLE_S8_TLV("DEC2 Volume",
- MSM8X10_WCD_A_CDC_TX2_VOL_CTL_GAIN,
- -84, 40, digital_gain),
- SOC_SINGLE_TLV("ADC1 Volume", MSM8X10_WCD_A_TX_1_EN, 2,
- 19, 0, analog_gain),
- SOC_SINGLE_TLV("ADC2 Volume", MSM8X10_WCD_A_TX_2_EN, 2,
- 19, 0, analog_gain),
- SOC_SINGLE_TLV("ADC3 Volume", MSM8X10_WCD_A_TX_3_EN, 2,
- 19, 0, analog_gain),
- SOC_SINGLE_S8_TLV("IIR1 INP1 Volume",
- MSM8X10_WCD_A_CDC_IIR1_GAIN_B1_CTL,
- -84, 40, digital_gain),
- SOC_SINGLE_S8_TLV("IIR1 INP2 Volume",
- MSM8X10_WCD_A_CDC_IIR1_GAIN_B2_CTL,
- -84, 40, digital_gain),
- SOC_SINGLE_S8_TLV("IIR1 INP3 Volume",
- MSM8X10_WCD_A_CDC_IIR1_GAIN_B3_CTL,
- -84, 40, digital_gain),
- SOC_SINGLE_S8_TLV("IIR1 INP4 Volume",
- MSM8X10_WCD_A_CDC_IIR1_GAIN_B4_CTL,
- -84, 40, digital_gain),
- SOC_ENUM("TX1 HPF cut off", cf_dec1_enum),
- SOC_ENUM("TX2 HPF cut off", cf_dec2_enum),
- SOC_SINGLE("TX1 HPF Switch", MSM8X10_WCD_A_CDC_TX1_MUX_CTL, 3, 1, 0),
- SOC_SINGLE("TX2 HPF Switch", MSM8X10_WCD_A_CDC_TX2_MUX_CTL, 3, 1, 0),
- SOC_SINGLE("RX1 HPF Switch", MSM8X10_WCD_A_CDC_RX1_B5_CTL, 2, 1, 0),
- SOC_SINGLE("RX2 HPF Switch", MSM8X10_WCD_A_CDC_RX2_B5_CTL, 2, 1, 0),
- SOC_SINGLE("RX3 HPF Switch", MSM8X10_WCD_A_CDC_RX3_B5_CTL, 2, 1, 0),
- SOC_ENUM("RX1 HPF cut off", cf_rxmix1_enum),
- SOC_ENUM("RX2 HPF cut off", cf_rxmix2_enum),
- SOC_ENUM("RX3 HPF cut off", cf_rxmix3_enum),
- SOC_SINGLE_EXT("IIR1 Enable Band1", IIR1, BAND1, 1, 0,
- msm8x10_wcd_get_iir_enable_audio_mixer,
- msm8x10_wcd_put_iir_enable_audio_mixer),
- SOC_SINGLE_EXT("IIR1 Enable Band2", IIR1, BAND2, 1, 0,
- msm8x10_wcd_get_iir_enable_audio_mixer,
- msm8x10_wcd_put_iir_enable_audio_mixer),
- SOC_SINGLE_EXT("IIR1 Enable Band3", IIR1, BAND3, 1, 0,
- msm8x10_wcd_get_iir_enable_audio_mixer,
- msm8x10_wcd_put_iir_enable_audio_mixer),
- SOC_SINGLE_EXT("IIR1 Enable Band4", IIR1, BAND4, 1, 0,
- msm8x10_wcd_get_iir_enable_audio_mixer,
- msm8x10_wcd_put_iir_enable_audio_mixer),
- SOC_SINGLE_EXT("IIR1 Enable Band5", IIR1, BAND5, 1, 0,
- msm8x10_wcd_get_iir_enable_audio_mixer,
- msm8x10_wcd_put_iir_enable_audio_mixer),
- SOC_SINGLE_EXT("IIR2 Enable Band1", IIR2, BAND1, 1, 0,
- msm8x10_wcd_get_iir_enable_audio_mixer,
- msm8x10_wcd_put_iir_enable_audio_mixer),
- SOC_SINGLE_EXT("IIR2 Enable Band2", IIR2, BAND2, 1, 0,
- msm8x10_wcd_get_iir_enable_audio_mixer,
- msm8x10_wcd_put_iir_enable_audio_mixer),
- SOC_SINGLE_EXT("IIR2 Enable Band3", IIR2, BAND3, 1, 0,
- msm8x10_wcd_get_iir_enable_audio_mixer,
- msm8x10_wcd_put_iir_enable_audio_mixer),
- SOC_SINGLE_EXT("IIR2 Enable Band4", IIR2, BAND4, 1, 0,
- msm8x10_wcd_get_iir_enable_audio_mixer,
- msm8x10_wcd_put_iir_enable_audio_mixer),
- SOC_SINGLE_EXT("IIR2 Enable Band5", IIR2, BAND5, 1, 0,
- msm8x10_wcd_get_iir_enable_audio_mixer,
- msm8x10_wcd_put_iir_enable_audio_mixer),
- SOC_SINGLE_MULTI_EXT("IIR1 Band1", IIR1, BAND1, 255, 0, 5,
- msm8x10_wcd_get_iir_band_audio_mixer,
- msm8x10_wcd_put_iir_band_audio_mixer),
- SOC_SINGLE_MULTI_EXT("IIR1 Band2", IIR1, BAND2, 255, 0, 5,
- msm8x10_wcd_get_iir_band_audio_mixer,
- msm8x10_wcd_put_iir_band_audio_mixer),
- SOC_SINGLE_MULTI_EXT("IIR1 Band3", IIR1, BAND3, 255, 0, 5,
- msm8x10_wcd_get_iir_band_audio_mixer,
- msm8x10_wcd_put_iir_band_audio_mixer),
- SOC_SINGLE_MULTI_EXT("IIR1 Band4", IIR1, BAND4, 255, 0, 5,
- msm8x10_wcd_get_iir_band_audio_mixer,
- msm8x10_wcd_put_iir_band_audio_mixer),
- SOC_SINGLE_MULTI_EXT("IIR1 Band5", IIR1, BAND5, 255, 0, 5,
- msm8x10_wcd_get_iir_band_audio_mixer,
- msm8x10_wcd_put_iir_band_audio_mixer),
- SOC_SINGLE_MULTI_EXT("IIR2 Band1", IIR2, BAND1, 255, 0, 5,
- msm8x10_wcd_get_iir_band_audio_mixer,
- msm8x10_wcd_put_iir_band_audio_mixer),
- SOC_SINGLE_MULTI_EXT("IIR2 Band2", IIR2, BAND2, 255, 0, 5,
- msm8x10_wcd_get_iir_band_audio_mixer,
- msm8x10_wcd_put_iir_band_audio_mixer),
- SOC_SINGLE_MULTI_EXT("IIR2 Band3", IIR2, BAND3, 255, 0, 5,
- msm8x10_wcd_get_iir_band_audio_mixer,
- msm8x10_wcd_put_iir_band_audio_mixer),
- SOC_SINGLE_MULTI_EXT("IIR2 Band4", IIR2, BAND4, 255, 0, 5,
- msm8x10_wcd_get_iir_band_audio_mixer,
- msm8x10_wcd_put_iir_band_audio_mixer),
- SOC_SINGLE_MULTI_EXT("IIR2 Band5", IIR2, BAND5, 255, 0, 5,
- msm8x10_wcd_get_iir_band_audio_mixer,
- msm8x10_wcd_put_iir_band_audio_mixer),
- };
- static const char * const rx_mix1_text[] = {
- "ZERO", "IIR1", "IIR2", "RX1", "RX2", "RX3"
- };
- static const char * const rx_mix2_text[] = {
- "ZERO", "IIR1", "IIR2"
- };
- static const char * const dec_mux_text[] = {
- "ZERO", "ADC1", "ADC2", "DMIC1", "DMIC2"
- };
- static const char * const adc2_mux_text[] = {
- "ZERO", "INP2", "INP3"
- };
- static const char * const iir1_inp1_text[] = {
- "ZERO", "DEC1", "DEC2", "RX1", "RX2", "RX3"
- };
- /*
- * There is only one bit to select RX2 (0) or RX3 (1) so add 'ZERO' won't
- * cause any issue to select the right input, but it eliminates that lineout
- * is powered-up when HPH is enabled if the 'ZERO" is used in the disable
- * sequence for lineout.
- */
- static const char * const rx_rdac4_text[] = {
- "ZERO", "RX3", "RX2"
- };
- static const char * const rx_rdac3_text[] = {
- "RX1", "RX2"
- };
- static const struct soc_enum rx_mix1_inp1_chain_enum =
- SOC_ENUM_SINGLE(MSM8X10_WCD_A_CDC_CONN_RX1_B1_CTL, 0, 6, rx_mix1_text);
- static const struct soc_enum rx_mix1_inp2_chain_enum =
- SOC_ENUM_SINGLE(MSM8X10_WCD_A_CDC_CONN_RX1_B1_CTL, 3, 6, rx_mix1_text);
- static const struct soc_enum rx_mix1_inp3_chain_enum =
- SOC_ENUM_SINGLE(MSM8X10_WCD_A_CDC_CONN_RX1_B2_CTL, 0, 6, rx_mix1_text);
- static const struct soc_enum rx2_mix1_inp1_chain_enum =
- SOC_ENUM_SINGLE(MSM8X10_WCD_A_CDC_CONN_RX2_B1_CTL, 0, 6, rx_mix1_text);
- static const struct soc_enum rx2_mix1_inp2_chain_enum =
- SOC_ENUM_SINGLE(MSM8X10_WCD_A_CDC_CONN_RX2_B1_CTL, 3, 6, rx_mix1_text);
- static const struct soc_enum rx3_mix1_inp1_chain_enum =
- SOC_ENUM_SINGLE(MSM8X10_WCD_A_CDC_CONN_RX3_B1_CTL, 0, 6, rx_mix1_text);
- static const struct soc_enum rx3_mix1_inp2_chain_enum =
- SOC_ENUM_SINGLE(MSM8X10_WCD_A_CDC_CONN_RX3_B1_CTL, 3, 6, rx_mix1_text);
- static const struct soc_enum rx1_mix2_inp1_chain_enum =
- SOC_ENUM_SINGLE(MSM8X10_WCD_A_CDC_CONN_RX1_B3_CTL, 0, 3, rx_mix2_text);
- static const struct soc_enum rx2_mix2_inp1_chain_enum =
- SOC_ENUM_SINGLE(MSM8X10_WCD_A_CDC_CONN_RX2_B3_CTL, 0, 3, rx_mix2_text);
- static const struct soc_enum dec1_mux_enum =
- SOC_ENUM_SINGLE(MSM8X10_WCD_A_CDC_CONN_TX_B1_CTL, 0, 5, dec_mux_text);
- static const struct soc_enum dec2_mux_enum =
- SOC_ENUM_SINGLE(MSM8X10_WCD_A_CDC_CONN_TX_B1_CTL, 3, 5, dec_mux_text);
- static const struct soc_enum iir1_inp1_mux_enum =
- SOC_ENUM_SINGLE(MSM8X10_WCD_A_CDC_CONN_EQ1_B1_CTL, 0, 6,
- iir1_inp1_text);
- static const struct soc_enum rx_rdac4_enum =
- SOC_ENUM_SINGLE(MSM8X10_WCD_A_CDC_CONN_LO_DAC_CTL, 0, 3,
- rx_rdac4_text);
- static const struct soc_enum rx_rdac3_enum =
- SOC_ENUM_SINGLE(MSM8X10_WCD_A_CDC_CONN_HPHR_DAC_CTL, 0, 2,
- rx_rdac3_text);
- static const struct soc_enum adc2_enum =
- SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(adc2_mux_text), adc2_mux_text);
- static const struct snd_kcontrol_new rx_mix1_inp1_mux =
- SOC_DAPM_ENUM("RX1 MIX1 INP1 Mux", rx_mix1_inp1_chain_enum);
- static const struct snd_kcontrol_new rx_mix1_inp2_mux =
- SOC_DAPM_ENUM("RX1 MIX1 INP2 Mux", rx_mix1_inp2_chain_enum);
- static const struct snd_kcontrol_new rx_mix1_inp3_mux =
- SOC_DAPM_ENUM("RX1 MIX1 INP3 Mux", rx_mix1_inp3_chain_enum);
- static const struct snd_kcontrol_new rx2_mix1_inp1_mux =
- SOC_DAPM_ENUM("RX2 MIX1 INP1 Mux", rx2_mix1_inp1_chain_enum);
- static const struct snd_kcontrol_new rx2_mix1_inp2_mux =
- SOC_DAPM_ENUM("RX2 MIX1 INP2 Mux", rx2_mix1_inp2_chain_enum);
- static const struct snd_kcontrol_new rx3_mix1_inp1_mux =
- SOC_DAPM_ENUM("RX3 MIX1 INP1 Mux", rx3_mix1_inp1_chain_enum);
- static const struct snd_kcontrol_new rx3_mix1_inp2_mux =
- SOC_DAPM_ENUM("RX3 MIX1 INP2 Mux", rx3_mix1_inp2_chain_enum);
- static const struct snd_kcontrol_new rx1_mix2_inp1_mux =
- SOC_DAPM_ENUM("RX1 MIX2 INP1 Mux", rx1_mix2_inp1_chain_enum);
- static const struct snd_kcontrol_new rx2_mix2_inp1_mux =
- SOC_DAPM_ENUM("RX2 MIX2 INP1 Mux", rx2_mix2_inp1_chain_enum);
- static const struct snd_kcontrol_new rx_dac4_mux =
- SOC_DAPM_ENUM("RDAC4 MUX Mux", rx_rdac4_enum);
- static const struct snd_kcontrol_new rx_dac3_mux =
- SOC_DAPM_ENUM("RDAC3 MUX Mux", rx_rdac3_enum);
- static const struct snd_kcontrol_new tx_adc2_mux =
- SOC_DAPM_ENUM("ADC2 MUX Mux", adc2_enum);
- static int msm8x10_wcd_put_dec_enum(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
- struct snd_soc_dapm_widget *w = wlist->widgets[0];
- struct snd_soc_codec *codec = w->codec;
- struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
- unsigned int dec_mux, decimator;
- char *dec_name = NULL;
- char *widget_name = NULL;
- char *temp;
- u16 tx_mux_ctl_reg;
- u8 adc_dmic_sel = 0x0;
- int ret = 0;
- if (ucontrol->value.enumerated.item[0] > e->max - 1)
- return -EINVAL;
- dec_mux = ucontrol->value.enumerated.item[0];
- widget_name = kstrndup(w->name, 15, GFP_KERNEL);
- if (!widget_name)
- return -ENOMEM;
- temp = widget_name;
- dec_name = strsep(&widget_name, " ");
- widget_name = temp;
- if (!dec_name) {
- dev_err(codec->dev, "%s: Invalid decimator = %s\n",
- __func__, w->name);
- ret = -EINVAL;
- goto out;
- }
- ret = kstrtouint(strpbrk(dec_name, "12"), 10, &decimator);
- if (ret < 0) {
- dev_err(codec->dev, "%s: Invalid decimator = %s\n",
- __func__, dec_name);
- ret = -EINVAL;
- goto out;
- }
- dev_dbg(w->dapm->dev, "%s(): widget = %s decimator = %u dec_mux = %u\n"
- , __func__, w->name, decimator, dec_mux);
- switch (decimator) {
- case 1:
- case 2:
- if ((dec_mux == 3) || (dec_mux == 4))
- adc_dmic_sel = 0x1;
- else
- adc_dmic_sel = 0x0;
- break;
- default:
- dev_err(codec->dev, "%s: Invalid Decimator = %u\n",
- __func__, decimator);
- ret = -EINVAL;
- goto out;
- }
- tx_mux_ctl_reg = MSM8X10_WCD_A_CDC_TX1_MUX_CTL + 32 * (decimator - 1);
- snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x1, adc_dmic_sel);
- ret = snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
- out:
- kfree(widget_name);
- return ret;
- }
- #define MSM8X10_WCD_DEC_ENUM(xname, xenum) \
- { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
- .info = snd_soc_info_enum_double, \
- .get = snd_soc_dapm_get_enum_double, \
- .put = msm8x10_wcd_put_dec_enum, \
- .private_value = (unsigned long)&xenum }
- static const struct snd_kcontrol_new dec1_mux =
- MSM8X10_WCD_DEC_ENUM("DEC1 MUX Mux", dec1_mux_enum);
- static const struct snd_kcontrol_new dec2_mux =
- MSM8X10_WCD_DEC_ENUM("DEC2 MUX Mux", dec2_mux_enum);
- static const struct snd_kcontrol_new iir1_inp1_mux =
- SOC_DAPM_ENUM("IIR1 INP1 Mux", iir1_inp1_mux_enum);
- static const struct snd_kcontrol_new dac1_switch[] = {
- SOC_DAPM_SINGLE("Switch", MSM8X10_WCD_A_RX_EAR_EN, 5, 1, 0)
- };
- static const struct snd_kcontrol_new hphl_switch[] = {
- SOC_DAPM_SINGLE("Switch", MSM8X10_WCD_A_RX_HPH_L_DAC_CTL, 6, 1, 0)
- };
- static const struct snd_kcontrol_new spkr_switch[] = {
- SOC_DAPM_SINGLE("Switch", MSM8X10_WCD_A_SPKR_DRV_DAC_CTL, 2, 1, 0)
- };
- static void msm8x10_wcd_codec_enable_adc_block(struct snd_soc_codec *codec,
- int enable)
- {
- struct msm8x10_wcd_priv *wcd8x10 = snd_soc_codec_get_drvdata(codec);
- dev_dbg(codec->dev, "%s %d\n", __func__, enable);
- if (enable) {
- wcd8x10->adc_count++;
- snd_soc_update_bits(codec,
- MSM8X10_WCD_A_CDC_ANA_CLK_CTL,
- 0x20, 0x20);
- } else
- wcd8x10->adc_count--;
- }
- static int msm8x10_wcd_codec_enable_adc(struct snd_soc_dapm_widget *w,
- struct snd_kcontrol *kcontrol, int event)
- {
- struct snd_soc_codec *codec = w->codec;
- u16 adc_reg;
- u8 init_bit_shift;
- dev_dbg(codec->dev, "%s %d\n", __func__, event);
- adc_reg = MSM8X10_WCD_A_TX_1_2_TEST_CTL;
- if (w->reg == MSM8X10_WCD_A_TX_1_EN)
- init_bit_shift = 7;
- else if ((w->reg == MSM8X10_WCD_A_TX_2_EN) ||
- (w->reg == MSM8X10_WCD_A_TX_3_EN))
- init_bit_shift = 6;
- else {
- dev_err(codec->dev, "%s: Error, invalid adc register\n",
- __func__);
- return -EINVAL;
- }
- switch (event) {
- case SND_SOC_DAPM_PRE_PMU:
- msm8x10_wcd_codec_enable_adc_block(codec, 1);
- snd_soc_update_bits(codec, adc_reg, 1 << init_bit_shift,
- 1 << init_bit_shift);
- usleep_range(CODEC_DELAY_1_MS, CODEC_DELAY_1_1_MS);
- break;
- case SND_SOC_DAPM_POST_PMU:
- snd_soc_update_bits(codec, adc_reg, 1 << init_bit_shift, 0x00);
- usleep_range(CODEC_DELAY_1_MS, CODEC_DELAY_1_1_MS);
- break;
- case SND_SOC_DAPM_POST_PMD:
- msm8x10_wcd_codec_enable_adc_block(codec, 0);
- break;
- }
- return 0;
- }
- static int msm8x10_wcd_codec_enable_lineout(struct snd_soc_dapm_widget *w,
- struct snd_kcontrol *kcontrol, int event)
- {
- struct snd_soc_codec *codec = w->codec;
- u16 lineout_gain_reg;
- dev_dbg(codec->dev, "%s %d %s\n", __func__, event, w->name);
- switch (w->shift) {
- case 0:
- lineout_gain_reg = MSM8X10_WCD_A_RX_LINE_1_GAIN;
- break;
- default:
- dev_err(codec->dev,
- "%s: Error, incorrect lineout register value\n",
- __func__);
- return -EINVAL;
- }
- switch (event) {
- case SND_SOC_DAPM_PRE_PMU:
- snd_soc_update_bits(codec, lineout_gain_reg, 0x40, 0x40);
- break;
- case SND_SOC_DAPM_POST_PMU:
- dev_dbg(codec->dev, "%s: sleeping 16 ms after %s PA turn on\n",
- __func__, w->name);
- usleep_range(16000, 16100);
- break;
- case SND_SOC_DAPM_POST_PMD:
- snd_soc_update_bits(codec, lineout_gain_reg, 0x40, 0x00);
- break;
- }
- return 0;
- }
- static int msm8x10_wcd_codec_enable_spk_pa(struct snd_soc_dapm_widget *w,
- struct snd_kcontrol *kcontrol, int event)
- {
- dev_dbg(w->codec->dev, "%s %d %s\n", __func__, event, w->name);
- #if defined(CONFIG_MACH_KANAS3G_CTC)
- switch (event) {
- case SND_SOC_DAPM_PRE_PMU:
- dev_dbg(w->codec->dev, "Before power on PA,sleep 5 ms\n");
- msleep(15);
- break;
- case SND_SOC_DAPM_POST_PMD:
- dev_dbg(w->codec->dev, "after power down PA,sleep 5 ms\n");
- msleep(15);
- break;
- default:
- break;
- }
- #endif
-
- return 0;
- }
- static int msm8x10_wcd_codec_enable_dmic(struct snd_soc_dapm_widget *w,
- struct snd_kcontrol *kcontrol, int event)
- {
- struct snd_soc_codec *codec = w->codec;
- struct msm8x10_wcd_priv *msm8x10_wcd = snd_soc_codec_get_drvdata(codec);
- u8 dmic_clk_en;
- u16 dmic_clk_reg;
- s32 *dmic_clk_cnt;
- unsigned int dmic;
- int ret;
- ret = kstrtouint(strpbrk(w->name, "12"), 10, &dmic);
- if (ret < 0) {
- dev_err(codec->dev,
- "%s: Invalid DMIC line on the codec\n", __func__);
- return -EINVAL;
- }
- switch (dmic) {
- case 1:
- case 2:
- dmic_clk_en = 0x01;
- dmic_clk_cnt = &(msm8x10_wcd->dmic_1_2_clk_cnt);
- dmic_clk_reg = MSM8X10_WCD_A_CDC_CLK_DMIC_B1_CTL;
- dev_dbg(codec->dev,
- "%s() event %d DMIC%d dmic_1_2_clk_cnt %d\n",
- __func__, event, dmic, *dmic_clk_cnt);
- break;
- default:
- dev_err(codec->dev, "%s: Invalid DMIC Selection\n", __func__);
- return -EINVAL;
- }
- switch (event) {
- case SND_SOC_DAPM_PRE_PMU:
- (*dmic_clk_cnt)++;
- if (*dmic_clk_cnt == 1)
- snd_soc_update_bits(codec, dmic_clk_reg,
- dmic_clk_en, dmic_clk_en);
- break;
- case SND_SOC_DAPM_POST_PMD:
- (*dmic_clk_cnt)--;
- if (*dmic_clk_cnt == 0)
- snd_soc_update_bits(codec, dmic_clk_reg,
- dmic_clk_en, 0);
- break;
- }
- return 0;
- }
- static int msm8x10_wcd_codec_enable_micbias(struct snd_soc_dapm_widget *w,
- struct snd_kcontrol *kcontrol, int event)
- {
- struct snd_soc_codec *codec = w->codec;
- struct msm8x10_wcd_priv *msm8x10_wcd = snd_soc_codec_get_drvdata(codec);
- u16 micb_int_reg;
- char *internal1_text = "Internal1";
- char *internal2_text = "Internal2";
- char *internal3_text = "Internal3";
- char *external_text = "External";
- enum wcd9xxx_notify_event e_post_off, e_pre_on, e_post_on;
- dev_dbg(codec->dev, "%s %d\n", __func__, event);
- if ((strnstr(w->name, internal1_text, 30)) ||
- (strnstr(w->name, internal2_text, 30)) ||
- (strnstr(w->name, internal3_text, 30)) ||
- (strnstr(w->name, external_text, 30))) {
- micb_int_reg = MSM8X10_WCD_A_MICB_1_INT_RBIAS;
- e_pre_on = WCD9XXX_EVENT_PRE_MICBIAS_1_ON;
- e_post_on = WCD9XXX_EVENT_POST_MICBIAS_1_ON;
- e_post_off = WCD9XXX_EVENT_POST_MICBIAS_1_OFF;
- } else {
- dev_err(codec->dev,
- "%s: Error, invalid micbias %s\n", __func__, w->name);
- return -EINVAL;
- }
- switch (event) {
- case SND_SOC_DAPM_PRE_PMU:
- /* Let MBHC module know micbias is about to turn ON */
- wcd9xxx_resmgr_notifier_call(&msm8x10_wcd->resmgr, e_pre_on);
- if (strnstr(w->name, internal1_text, 30))
- snd_soc_update_bits(codec, micb_int_reg, 0x80, 0x80);
- else if (strnstr(w->name, internal2_text, 30))
- snd_soc_update_bits(codec, micb_int_reg, 0x10, 0x10);
- else if (strnstr(w->name, internal3_text, 30))
- snd_soc_update_bits(codec, micb_int_reg, 0x2, 0x2);
- /* Always pull up TxFe for TX2 to Micbias */
- snd_soc_update_bits(codec, micb_int_reg, 0x04, 0x04);
- if (++msm8x10_wcd->micb_en_count == 1)
- snd_soc_update_bits(codec, MSM8X10_WCD_A_MICB_1_CTL,
- 0x80, 0x80);
- pr_debug("%s micb_en_count : %d", __func__,
- msm8x10_wcd->micb_en_count);
- break;
- case SND_SOC_DAPM_POST_PMU:
- usleep_range(20000, 20100);
- /* Let MBHC module know so micbias is on */
- wcd9xxx_resmgr_notifier_call(&msm8x10_wcd->resmgr, e_post_on);
- break;
- case SND_SOC_DAPM_POST_PMD:
- if (--msm8x10_wcd->micb_en_count == 0)
- snd_soc_update_bits(codec, MSM8X10_WCD_A_MICB_1_CTL,
- 0x80, 0x00);
- pr_debug("%s micb_en_count : %d", __func__,
- msm8x10_wcd->micb_en_count);
- /* Let MBHC module know so micbias switch to be off */
- wcd9xxx_resmgr_notifier_call(&msm8x10_wcd->resmgr, e_post_off);
- if (strnstr(w->name, internal1_text, 30))
- snd_soc_update_bits(codec, micb_int_reg, 0x80, 0x00);
- else if (strnstr(w->name, internal2_text, 30))
- snd_soc_update_bits(codec, micb_int_reg, 0x10, 0x00);
- else if (strnstr(w->name, internal3_text, 30))
- snd_soc_update_bits(codec, micb_int_reg, 0x2, 0x0);
- /* Disable pull up TxFe for TX2 to Micbias */
- snd_soc_update_bits(codec, micb_int_reg, 0x04, 0x00);
- break;
- }
- return 0;
- }
- static void tx_hpf_corner_freq_callback(struct work_struct *work)
- {
- struct delayed_work *hpf_delayed_work;
- struct hpf_work *hpf_work;
- struct msm8x10_wcd_priv *msm8x10_wcd;
- struct snd_soc_codec *codec;
- u16 tx_mux_ctl_reg;
- u8 hpf_cut_of_freq;
- hpf_delayed_work = to_delayed_work(work);
- hpf_work = container_of(hpf_delayed_work, struct hpf_work, dwork);
- msm8x10_wcd = hpf_work->msm8x10_wcd;
- codec = hpf_work->msm8x10_wcd->codec;
- hpf_cut_of_freq = hpf_work->tx_hpf_cut_of_freq;
- tx_mux_ctl_reg = MSM8X10_WCD_A_CDC_TX1_MUX_CTL +
- (hpf_work->decimator - 1) * 32;
- dev_info(codec->dev, "%s(): decimator %u hpf_cut_of_freq 0x%x\n",
- __func__, hpf_work->decimator, (unsigned int)hpf_cut_of_freq);
- snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x30, hpf_cut_of_freq << 4);
- }
- #define TX_MUX_CTL_CUT_OFF_FREQ_MASK 0x30
- #define CF_MIN_3DB_4HZ 0x0
- #define CF_MIN_3DB_75HZ 0x1
- #define CF_MIN_3DB_150HZ 0x2
- static int msm8x10_wcd_codec_enable_dec(struct snd_soc_dapm_widget *w,
- struct snd_kcontrol *kcontrol, int event)
- {
- struct snd_soc_codec *codec = w->codec;
- unsigned int decimator;
- char *dec_name = NULL;
- char *widget_name = NULL;
- char *temp;
- int ret = 0;
- u16 dec_reset_reg, tx_vol_ctl_reg, tx_mux_ctl_reg;
- u8 dec_hpf_cut_of_freq;
- int offset;
- dev_dbg(codec->dev, "%s %d\n", __func__, event);
- widget_name = kstrndup(w->name, 15, GFP_KERNEL);
- if (!widget_name)
- return -ENOMEM;
- temp = widget_name;
- dec_name = strsep(&widget_name, " ");
- widget_name = temp;
- if (!dec_name) {
- dev_err(codec->dev,
- "%s: Invalid decimator = %s\n", __func__, w->name);
- ret = -EINVAL;
- goto out;
- }
- ret = kstrtouint(strpbrk(dec_name, "12"), 10, &decimator);
- if (ret < 0) {
- dev_err(codec->dev,
- "%s: Invalid decimator = %s\n", __func__, dec_name);
- ret = -EINVAL;
- goto out;
- }
- dev_dbg(codec->dev,
- "%s(): widget = %s dec_name = %s decimator = %u\n", __func__,
- w->name, dec_name, decimator);
- if (w->reg == MSM8X10_WCD_A_CDC_CLK_TX_CLK_EN_B1_CTL) {
- dec_reset_reg = MSM8X10_WCD_A_CDC_CLK_TX_RESET_B1_CTL;
- offset = 0;
- } else {
- dev_err(codec->dev, "%s: Error, incorrect dec\n", __func__);
- ret = -EINVAL;
- goto out;
- }
- tx_vol_ctl_reg = MSM8X10_WCD_A_CDC_TX1_VOL_CTL_CFG +
- 32 * (decimator - 1);
- tx_mux_ctl_reg = MSM8X10_WCD_A_CDC_TX1_MUX_CTL +
- 32 * (decimator - 1);
- switch (event) {
- case SND_SOC_DAPM_PRE_PMU:
- /* Enableable TX digital mute */
- snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x01, 0x01);
- snd_soc_update_bits(codec, dec_reset_reg, 1 << w->shift,
- 1 << w->shift);
- snd_soc_update_bits(codec, dec_reset_reg, 1 << w->shift, 0x0);
- dec_hpf_cut_of_freq = snd_soc_read(codec, tx_mux_ctl_reg);
- dec_hpf_cut_of_freq = (dec_hpf_cut_of_freq & 0x30) >> 4;
- tx_hpf_work[decimator - 1].tx_hpf_cut_of_freq =
- dec_hpf_cut_of_freq;
- if ((dec_hpf_cut_of_freq != CF_MIN_3DB_150HZ)) {
- /* set cut of freq to CF_MIN_3DB_150HZ (0x1); */
- snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x30,
- CF_MIN_3DB_150HZ << 4);
- }
- /* enable HPF */
- snd_soc_update_bits(codec, tx_mux_ctl_reg , 0x08, 0x00);
- break;
- case SND_SOC_DAPM_POST_PMU:
- /* Disable TX digital mute */
- snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x01, 0x00);
- if (tx_hpf_work[decimator - 1].tx_hpf_cut_of_freq !=
- CF_MIN_3DB_150HZ) {
- schedule_delayed_work(&tx_hpf_work[decimator - 1].dwork,
- msecs_to_jiffies(300));
- }
- /* apply the digital gain after the decimator is enabled*/
- if ((w->shift) < ARRAY_SIZE(tx_digital_gain_reg))
- snd_soc_write(codec,
- tx_digital_gain_reg[w->shift + offset],
- snd_soc_read(codec,
- tx_digital_gain_reg[w->shift + offset])
- );
- break;
- case SND_SOC_DAPM_PRE_PMD:
- snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x01, 0x01);
- cancel_delayed_work_sync(&tx_hpf_work[decimator - 1].dwork);
- break;
- case SND_SOC_DAPM_POST_PMD:
- snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x08, 0x08);
- snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x30,
- (tx_hpf_work[decimator - 1].tx_hpf_cut_of_freq) << 4);
- break;
- }
- out:
- kfree(widget_name);
- return ret;
- }
- static int msm8x10_wcd_codec_enable_interpolator(struct snd_soc_dapm_widget *w,
- struct snd_kcontrol *kcontrol,
- int event)
- {
- struct snd_soc_codec *codec = w->codec;
- dev_dbg(codec->dev, "%s %d %s\n", __func__, event, w->name);
- switch (event) {
- case SND_SOC_DAPM_PRE_PMU:
- snd_soc_update_bits(codec, MSM8X10_WCD_A_CDC_CLK_RX_RESET_CTL,
- 1 << w->shift, 1 << w->shift);
- snd_soc_update_bits(codec, MSM8X10_WCD_A_CDC_CLK_RX_RESET_CTL,
- 1 << w->shift, 0x0);
- break;
- case SND_SOC_DAPM_POST_PMU:
- /* apply the digital gain after the interpolator is enabled*/
- if ((w->shift) < ARRAY_SIZE(rx_digital_gain_reg))
- snd_soc_write(codec,
- rx_digital_gain_reg[w->shift],
- snd_soc_read(codec,
- rx_digital_gain_reg[w->shift])
- );
- break;
- }
- return 0;
- }
- /* The register address is the same as other codec so it can use resmgr */
- static int msm8x10_wcd_codec_enable_rx_bias(struct snd_soc_dapm_widget *w,
- struct snd_kcontrol *kcontrol, int event)
- {
- struct snd_soc_codec *codec = w->codec;
- struct msm8x10_wcd_priv *msm8x10_wcd = snd_soc_codec_get_drvdata(codec);
- msm8x10_wcd->resmgr.codec = codec;
- dev_dbg(codec->dev, "%s %d\n", __func__, event);
- switch (event) {
- case SND_SOC_DAPM_PRE_PMU:
- wcd9xxx_resmgr_enable_rx_bias(&msm8x10_wcd->resmgr, 1);
- break;
- case SND_SOC_DAPM_POST_PMD:
- wcd9xxx_resmgr_enable_rx_bias(&msm8x10_wcd->resmgr, 0);
- break;
- }
- return 0;
- }
- static int msm8x10_wcd_hphr_dac_event(struct snd_soc_dapm_widget *w,
- struct snd_kcontrol *kcontrol, int event)
- {
- struct snd_soc_codec *codec = w->codec;
- dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event);
- switch (event) {
- case SND_SOC_DAPM_PRE_PMU:
- snd_soc_update_bits(codec, w->reg, 0x40, 0x40);
- break;
- case SND_SOC_DAPM_POST_PMD:
- snd_soc_update_bits(codec, w->reg, 0x40, 0x00);
- break;
- }
- return 0;
- }
- static int msm8x10_wcd_hph_pa_event(struct snd_soc_dapm_widget *w,
- struct snd_kcontrol *kcontrol, int event)
- {
- struct snd_soc_codec *codec = w->codec;
- struct msm8x10_wcd_priv *msm8x10_wcd = snd_soc_codec_get_drvdata(codec);
- enum wcd9xxx_notify_event e_pre_on, e_post_off;
- dev_dbg(codec->dev, "%s: %s event = %d\n", __func__, w->name, event);
- if (w->shift == 5) {
- e_pre_on = WCD9XXX_EVENT_PRE_HPHR_PA_ON;
- e_post_off = WCD9XXX_EVENT_POST_HPHR_PA_OFF;
- } else if (w->shift == 4) {
- e_pre_on = WCD9XXX_EVENT_PRE_HPHL_PA_ON;
- e_post_off = WCD9XXX_EVENT_POST_HPHL_PA_OFF;
- } else {
- dev_err(codec->dev,
- "%s: Invalid w->shift %d\n", __func__, w->shift);
- return -EINVAL;
- }
- switch (event) {
- case SND_SOC_DAPM_PRE_PMU:
- /* Let MBHC module know PA is turning on */
- wcd9xxx_resmgr_notifier_call(&msm8x10_wcd->resmgr, e_pre_on);
- break;
- case SND_SOC_DAPM_POST_PMU:
- usleep_range(10000, 10100);
- break;
- case SND_SOC_DAPM_POST_PMD:
- /* Let MBHC module know PA turned off */
- wcd9xxx_resmgr_notifier_call(&msm8x10_wcd->resmgr, e_post_off);
- dev_dbg(codec->dev,
- "%s: sleep 10 ms after %s PA disable.\n", __func__,
- w->name);
- usleep_range(10000, 10100);
- break;
- }
- return 0;
- }
- static int msm8x10_wcd_lineout_dac_event(struct snd_soc_dapm_widget *w,
- struct snd_kcontrol *kcontrol, int event)
- {
- struct snd_soc_codec *codec = w->codec;
- dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event);
- switch (event) {
- case SND_SOC_DAPM_PRE_PMU:
- snd_soc_update_bits(codec, w->reg, 0x40, 0x40);
- break;
- case SND_SOC_DAPM_POST_PMD:
- snd_soc_update_bits(codec, w->reg, 0x40, 0x00);
- break;
- }
- return 0;
- }
- static const struct snd_soc_dapm_route audio_map[] = {
- {"RX_I2S_CLK", NULL, "CDC_CONN"},
- {"I2S RX1", NULL, "RX_I2S_CLK"},
- {"I2S RX2", NULL, "RX_I2S_CLK"},
- {"I2S RX3", NULL, "RX_I2S_CLK"},
- {"I2S TX1", NULL, "TX_I2S_CLK"},
- {"I2S TX2", NULL, "TX_I2S_CLK"},
- {"I2S TX1", NULL, "DEC1 MUX"},
- {"I2S TX2", NULL, "DEC2 MUX"},
- /* Earpiece (RX MIX1) */
- {"EAR", NULL, "EAR PA"},
- {"EAR PA", NULL, "DAC1"},
- {"DAC1", NULL, "CP"},
- /* Clocks for playback path */
- {"DAC1", NULL, "EAR CLK"},
- {"HPHL DAC", NULL, "HPHL CLK"},
- {"HPHR DAC", NULL, "HPHR CLK"},
- {"SPK DAC", NULL, "SPK CLK"},
- {"LINEOUT DAC", NULL, "LINEOUT CLK"},
- /* Headset (RX MIX1 and RX MIX2) */
- {"HEADPHONE", NULL, "HPHL"},
- {"HEADPHONE", NULL, "HPHR"},
- {"HPHL", NULL, "HPHL DAC"},
- {"HPHR", NULL, "HPHR DAC"},
- {"HPHL DAC", NULL, "CP"},
- {"HPHR DAC", NULL, "CP"},
- {"SPK DAC", NULL, "CP"},
- {"DAC1", "Switch", "RX1 CHAIN"},
- {"HPHL DAC", "Switch", "RX1 CHAIN"},
- {"HPHR DAC", NULL, "RDAC3 MUX"},
- {"RDAC3 MUX", "RX1", "RX1 CHAIN"},
- {"RDAC3 MUX", "RX2", "RX2 CHAIN"},
- {"LINEOUT", NULL, "LINEOUT PA"},
- {"SPK_OUT", NULL, "SPK PA"},
- {"LINEOUT PA", NULL, "CP"},
- {"LINEOUT PA", NULL, "LINEOUT DAC"},
- {"LINEOUT DAC", NULL, "RDAC4 MUX"},
- {"RDAC4 MUX", "RX2", "RX2 CHAIN"},
- {"RDAC4 MUX", "RX3", "RX3 CHAIN"},
- {"CP", NULL, "CP_REGULATOR"},
- {"CP", NULL, "RX_BIAS"},
- {"SPK PA", NULL, "SPK DAC"},
- {"SPK DAC", "Switch", "RX3 CHAIN"},
- {"RX1 CHAIN", NULL, "RX1 CLK"},
- {"RX2 CHAIN", NULL, "RX2 CLK"},
- {"RX3 CHAIN", NULL, "RX3 CLK"},
- {"RX1 CHAIN", NULL, "RX1 MIX2"},
- {"RX2 CHAIN", NULL, "RX2 MIX2"},
- {"RX3 CHAIN", NULL, "RX3 MIX1"},
- {"RX1 MIX1", NULL, "RX1 MIX1 INP1"},
- {"RX1 MIX1", NULL, "RX1 MIX1 INP2"},
- {"RX1 MIX1", NULL, "RX1 MIX1 INP3"},
- {"RX2 MIX1", NULL, "RX2 MIX1 INP1"},
- {"RX2 MIX1", NULL, "RX2 MIX1 INP2"},
- {"RX3 MIX1", NULL, "RX3 MIX1 INP1"},
- {"RX3 MIX1", NULL, "RX3 MIX1 INP2"},
- {"RX1 MIX2", NULL, "RX1 MIX1"},
- {"RX1 MIX2", NULL, "RX1 MIX2 INP1"},
- {"RX2 MIX2", NULL, "RX2 MIX1"},
- {"RX2 MIX2", NULL, "RX2 MIX2 INP1"},
- {"RX1 MIX1 INP1", "RX1", "I2S RX1"},
- {"RX1 MIX1 INP1", "RX2", "I2S RX2"},
- {"RX1 MIX1 INP1", "RX3", "I2S RX3"},
- {"RX1 MIX1 INP1", "IIR1", "IIR1"},
- {"RX1 MIX1 INP2", "RX1", "I2S RX1"},
- {"RX1 MIX1 INP2", "RX2", "I2S RX2"},
- {"RX1 MIX1 INP2", "RX3", "I2S RX3"},
- {"RX1 MIX1 INP2", "IIR1", "IIR1"},
- {"RX1 MIX1 INP3", "RX1", "I2S RX1"},
- {"RX1 MIX1 INP3", "RX2", "I2S RX2"},
- {"RX1 MIX1 INP3", "RX3", "I2S RX3"},
- {"RX2 MIX1 INP1", "RX1", "I2S RX1"},
- {"RX2 MIX1 INP1", "RX2", "I2S RX2"},
- {"RX2 MIX1 INP1", "RX3", "I2S RX3"},
- {"RX2 MIX1 INP1", "IIR1", "IIR1"},
- {"RX2 MIX1 INP2", "RX1", "I2S RX1"},
- {"RX2 MIX1 INP2", "RX2", "I2S RX2"},
- {"RX2 MIX1 INP2", "RX3", "I2S RX3"},
- {"RX2 MIX1 INP2", "IIR1", "IIR1"},
- {"RX3 MIX1 INP1", "RX1", "I2S RX1"},
- {"RX3 MIX1 INP1", "RX2", "I2S RX2"},
- {"RX3 MIX1 INP1", "RX3", "I2S RX3"},
- {"RX3 MIX1 INP1", "IIR1", "IIR1"},
- {"RX3 MIX1 INP2", "RX1", "I2S RX1"},
- {"RX3 MIX1 INP2", "RX2", "I2S RX2"},
- {"RX3 MIX1 INP2", "RX3", "I2S RX3"},
- {"RX3 MIX1 INP2", "IIR1", "IIR1"},
- {"RX1 MIX2 INP1", "IIR1", "IIR1"},
- {"RX2 MIX2 INP1", "IIR1", "IIR1"},
- /* Decimator Inputs */
- {"DEC1 MUX", "DMIC1", "DMIC1"},
- {"DEC1 MUX", "DMIC2", "DMIC2"},
- {"DEC1 MUX", "ADC1", "ADC1"},
- {"DEC1 MUX", "ADC2", "ADC2"},
- {"DEC1 MUX", NULL, "CDC_CONN"},
- {"DEC2 MUX", "DMIC1", "DMIC1"},
- {"DEC2 MUX", "DMIC2", "DMIC2"},
- {"DEC2 MUX", "ADC1", "ADC1"},
- {"DEC2 MUX", "ADC2", "ADC2"},
- {"DEC2 MUX", NULL, "CDC_CONN"},
- {"ADC2", NULL, "ADC2 MUX"},
- {"ADC2 MUX", "INP2", "ADC2_INP2"},
- {"ADC2 MUX", "INP3", "ADC2_INP3"},
- /* ADC Connections */
- {"ADC1", NULL, "AMIC1"},
- {"ADC2_INP2", NULL, "AMIC2"},
- {"ADC2_INP3", NULL, "AMIC3"},
- {"IIR1", NULL, "IIR1 INP1 MUX"},
- {"IIR1 INP1 MUX", "DEC1", "DEC1 MUX"},
- {"IIR1 INP1 MUX", "DEC2", "DEC2 MUX"},
- {"MIC BIAS Internal1", NULL, "INT_LDO_H"},
- {"MIC BIAS Internal2", NULL, "INT_LDO_H"},
- {"MIC BIAS External", NULL, "INT_LDO_H"},
- {"MIC BIAS Internal1", NULL, "MICBIAS_REGULATOR"},
- {"MIC BIAS Internal2", NULL, "MICBIAS_REGULATOR"},
- {"MIC BIAS External", NULL, "MICBIAS_REGULATOR"},
- };
- static int msm8x10_wcd_startup(struct snd_pcm_substream *substream,
- struct snd_soc_dai *dai)
- {
- dev_dbg(dai->codec->dev, "%s(): substream = %s stream = %d\n",
- __func__,
- substream->name, substream->stream);
- return 0;
- }
- static void msm8x10_wcd_shutdown(struct snd_pcm_substream *substream,
- struct snd_soc_dai *dai)
- {
- dev_dbg(dai->codec->dev,
- "%s(): substream = %s stream = %d\n" , __func__,
- substream->name, substream->stream);
- }
- int msm8x10_wcd_mclk_enable(struct snd_soc_codec *codec,
- int mclk_enable, bool dapm)
- {
- struct msm8x10_wcd_priv *msm8x10_wcd = snd_soc_codec_get_drvdata(codec);
- dev_dbg(codec->dev, "%s: mclk_enable = %u, dapm = %d\n",
- __func__, mclk_enable, dapm);
- WCD9XXX_BG_CLK_LOCK(&msm8x10_wcd->resmgr);
- if (mclk_enable) {
- wcd9xxx_resmgr_get_bandgap(&msm8x10_wcd->resmgr,
- WCD9XXX_BANDGAP_AUDIO_MODE);
- wcd9xxx_resmgr_get_clk_block(&msm8x10_wcd->resmgr,
- WCD9XXX_CLK_MCLK);
- } else {
- wcd9xxx_resmgr_put_clk_block(&msm8x10_wcd->resmgr,
- WCD9XXX_CLK_MCLK);
- wcd9xxx_resmgr_put_bandgap(&msm8x10_wcd->resmgr,
- WCD9XXX_BANDGAP_AUDIO_MODE);
- }
- WCD9XXX_BG_CLK_UNLOCK(&msm8x10_wcd->resmgr);
- return 0;
- }
- static int msm8x10_wcd_set_dai_sysclk(struct snd_soc_dai *dai,
- int clk_id, unsigned int freq, int dir)
- {
- dev_dbg(dai->codec->dev, "%s\n", __func__);
- return 0;
- }
- static int msm8x10_wcd_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
- {
- dev_dbg(dai->codec->dev, "%s\n", __func__);
- return 0;
- }
- static int msm8x10_wcd_set_channel_map(struct snd_soc_dai *dai,
- unsigned int tx_num, unsigned int *tx_slot,
- unsigned int rx_num, unsigned int *rx_slot)
- {
- dev_dbg(dai->codec->dev, "%s\n", __func__);
- return 0;
- }
- static int msm8x10_wcd_get_channel_map(struct snd_soc_dai *dai,
- unsigned int *tx_num, unsigned int *tx_slot,
- unsigned int *rx_num, unsigned int *rx_slot)
- {
- dev_dbg(dai->codec->dev, "%s\n", __func__);
- return 0;
- }
- static int msm8x10_wcd_set_interpolator_rate(struct snd_soc_dai *dai,
- u8 rx_fs_rate_reg_val, u32 sample_rate)
- {
- return 0;
- }
- static int msm8x10_wcd_set_decimator_rate(struct snd_soc_dai *dai,
- u8 tx_fs_rate_reg_val, u32 sample_rate)
- {
- return 0;
- }
- static int msm8x10_wcd_hw_params(struct snd_pcm_substream *substream,
- struct snd_pcm_hw_params *params,
- struct snd_soc_dai *dai)
- {
- u8 tx_fs_rate, rx_fs_rate;
- int ret;
- dev_dbg(dai->codec->dev,
- "%s: dai_name = %s DAI-ID %x rate %d num_ch %d\n", __func__,
- dai->name, dai->id, params_rate(params),
- params_channels(params));
- switch (params_rate(params)) {
- case 8000:
- tx_fs_rate = 0x00;
- rx_fs_rate = 0x00;
- break;
- case 16000:
- tx_fs_rate = 0x01;
- rx_fs_rate = 0x20;
- break;
- case 32000:
- tx_fs_rate = 0x02;
- rx_fs_rate = 0x40;
- break;
- case 48000:
- tx_fs_rate = 0x03;
- rx_fs_rate = 0x60;
- break;
- case 96000:
- tx_fs_rate = 0x04;
- rx_fs_rate = 0x80;
- break;
- case 192000:
- tx_fs_rate = 0x05;
- rx_fs_rate = 0xA0;
- break;
- default:
- dev_err(dai->codec->dev,
- "%s: Invalid sampling rate %d\n", __func__,
- params_rate(params));
- return -EINVAL;
- }
- switch (substream->stream) {
- case SNDRV_PCM_STREAM_CAPTURE:
- ret = msm8x10_wcd_set_decimator_rate(dai, tx_fs_rate,
- params_rate(params));
- if (ret < 0) {
- dev_err(dai->codec->dev,
- "%s: set decimator rate failed %d\n", __func__,
- ret);
- return ret;
- }
- break;
- case SNDRV_PCM_STREAM_PLAYBACK:
- ret = msm8x10_wcd_set_interpolator_rate(dai, rx_fs_rate,
- params_rate(params));
- if (ret < 0) {
- dev_err(dai->codec->dev,
- "%s: set decimator rate failed %d\n", __func__,
- ret);
- return ret;
- }
- break;
- default:
- dev_err(dai->codec->dev,
- "%s: Invalid stream type %d\n", __func__,
- substream->stream);
- return -EINVAL;
- }
- return 0;
- }
- static struct snd_soc_dai_ops msm8x10_wcd_dai_ops = {
- .startup = msm8x10_wcd_startup,
- .shutdown = msm8x10_wcd_shutdown,
- .hw_params = msm8x10_wcd_hw_params,
- .set_sysclk = msm8x10_wcd_set_dai_sysclk,
- .set_fmt = msm8x10_wcd_set_dai_fmt,
- .set_channel_map = msm8x10_wcd_set_channel_map,
- .get_channel_map = msm8x10_wcd_get_channel_map,
- };
- static struct snd_soc_dai_driver msm8x10_wcd_i2s_dai[] = {
- {
- .name = "msm8x10_wcd_i2s_rx1",
- .id = AIF1_PB,
- .playback = {
- .stream_name = "AIF1 Playback",
- .rates = MSM8X10_WCD_RATES,
- .formats = MSM8X10_WCD_FORMATS,
- .rate_max = 192000,
- .rate_min = 8000,
- .channels_min = 1,
- .channels_max = 3,
- },
- .ops = &msm8x10_wcd_dai_ops,
- },
- {
- .name = "msm8x10_wcd_i2s_tx1",
- .id = AIF1_CAP,
- .capture = {
- .stream_name = "AIF1 Capture",
- .rates = MSM8X10_WCD_RATES,
- .formats = MSM8X10_WCD_FORMATS,
- .rate_max = 192000,
- .rate_min = 8000,
- .channels_min = 1,
- .channels_max = 4,
- },
- .ops = &msm8x10_wcd_dai_ops,
- },
- };
- static int msm8x10_wcd_codec_enable_ear_pa(struct snd_soc_dapm_widget *w,
- struct snd_kcontrol *kcontrol, int event)
- {
- switch (event) {
- case SND_SOC_DAPM_PRE_PMU:
- snd_soc_update_bits(w->codec, MSM8X10_WCD_A_CDC_ANA_CLK_CTL,
- 0x4, 0x4);
- break;
- case SND_SOC_DAPM_POST_PMU:
- dev_dbg(w->codec->dev,
- "%s: Sleeping 20ms after enabling EAR PA\n",
- __func__);
- msleep(20);
- break;
- case SND_SOC_DAPM_POST_PMD:
- dev_dbg(w->codec->dev,
- "%s: Sleeping 20ms after disabling EAR PA\n",
- __func__);
- snd_soc_update_bits(w->codec, MSM8X10_WCD_A_CDC_ANA_CLK_CTL,
- 0x4, 0x0);
- msleep(20);
- break;
- }
- return 0;
- }
- static const struct snd_soc_dapm_widget msm8x10_wcd_dapm_widgets[] = {
- /*RX stuff */
- SND_SOC_DAPM_OUTPUT("EAR"),
- SND_SOC_DAPM_PGA_E("EAR PA", MSM8X10_WCD_A_RX_EAR_EN, 4, 0, NULL, 0,
- msm8x10_wcd_codec_enable_ear_pa, SND_SOC_DAPM_PRE_PMU |
- SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
- SND_SOC_DAPM_MIXER("DAC1", MSM8X10_WCD_A_RX_EAR_EN, 6, 0, dac1_switch,
- ARRAY_SIZE(dac1_switch)),
- SND_SOC_DAPM_AIF_IN("I2S RX1", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0),
- SND_SOC_DAPM_AIF_IN("I2S RX2", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0),
- SND_SOC_DAPM_AIF_IN("I2S RX3", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0),
- SND_SOC_DAPM_SUPPLY("INT_LDO_H", SND_SOC_NOPM, 1, 0, NULL, 0),
- SND_SOC_DAPM_OUTPUT("HEADPHONE"),
- SND_SOC_DAPM_PGA_E("HPHL", MSM8X10_WCD_A_RX_HPH_CNP_EN,
- 5, 0, NULL, 0,
- msm8x10_wcd_hph_pa_event, SND_SOC_DAPM_PRE_PMU |
- SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
- SND_SOC_DAPM_MIXER("HPHL DAC", MSM8X10_WCD_A_RX_HPH_L_DAC_CTL,
- 7, 0,
- hphl_switch, ARRAY_SIZE(hphl_switch)),
- SND_SOC_DAPM_PGA_E("HPHR", MSM8X10_WCD_A_RX_HPH_CNP_EN,
- 4, 0, NULL, 0,
- msm8x10_wcd_hph_pa_event, SND_SOC_DAPM_PRE_PMU |
- SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
- SND_SOC_DAPM_DAC_E("HPHR DAC", NULL, MSM8X10_WCD_A_RX_HPH_R_DAC_CTL,
- 7, 0,
- msm8x10_wcd_hphr_dac_event,
- SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
- SND_SOC_DAPM_MIXER("SPK DAC", SND_SOC_NOPM, 0, 0,
- spkr_switch, ARRAY_SIZE(spkr_switch)),
- /* Speaker */
- SND_SOC_DAPM_OUTPUT("LINEOUT"),
- SND_SOC_DAPM_OUTPUT("SPK_OUT"),
- SND_SOC_DAPM_PGA_E("LINEOUT PA", MSM8X10_WCD_A_RX_LINE_CNP_EN,
- 0, 0, NULL, 0, msm8x10_wcd_codec_enable_lineout,
- SND_SOC_DAPM_PRE_PMU |
- SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
- SND_SOC_DAPM_PGA_E("SPK PA", MSM8X10_WCD_A_SPKR_DRV_EN,
- 7, 0 , NULL, 0, msm8x10_wcd_codec_enable_spk_pa,
- SND_SOC_DAPM_PRE_PMU |
- SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
- SND_SOC_DAPM_DAC_E("LINEOUT DAC", NULL,
- MSM8X10_WCD_A_RX_LINE_1_DAC_CTL, 7, 0,
- msm8x10_wcd_lineout_dac_event,
- SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
- SND_SOC_DAPM_MIXER("RX1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
- SND_SOC_DAPM_MIXER("RX2 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
- SND_SOC_DAPM_MIXER_E("RX1 MIX2",
- MSM8X10_WCD_A_CDC_CLK_RX_B1_CTL, 0, 0, NULL,
- 0, msm8x10_wcd_codec_enable_interpolator, SND_SOC_DAPM_PRE_PMU |
- SND_SOC_DAPM_POST_PMU),
- SND_SOC_DAPM_MIXER_E("RX2 MIX2",
- MSM8X10_WCD_A_CDC_CLK_RX_B1_CTL, 1, 0, NULL,
- 0, msm8x10_wcd_codec_enable_interpolator, SND_SOC_DAPM_PRE_PMU |
- SND_SOC_DAPM_POST_PMU),
- SND_SOC_DAPM_MIXER_E("RX3 MIX1",
- MSM8X10_WCD_A_CDC_CLK_RX_B1_CTL, 2, 0, NULL,
- 0, msm8x10_wcd_codec_enable_interpolator, SND_SOC_DAPM_PRE_PMU |
- SND_SOC_DAPM_POST_PMU),
- SND_SOC_DAPM_SUPPLY("RX1 CLK", MSM8X10_WCD_A_CDC_DIG_CLK_CTL,
- 0, 0, NULL, 0),
- SND_SOC_DAPM_SUPPLY("RX2 CLK", MSM8X10_WCD_A_CDC_DIG_CLK_CTL,
- 1, 0, NULL, 0),
- SND_SOC_DAPM_SUPPLY("RX3 CLK", MSM8X10_WCD_A_CDC_DIG_CLK_CTL,
- 2, 0, NULL, 0),
- SND_SOC_DAPM_MIXER("RX1 CHAIN", MSM8X10_WCD_A_CDC_RX1_B6_CTL,
- 5, 0, NULL, 0),
- SND_SOC_DAPM_MIXER("RX2 CHAIN", MSM8X10_WCD_A_CDC_RX2_B6_CTL,
- 5, 0, NULL, 0),
- SND_SOC_DAPM_MIXER("RX3 CHAIN", MSM8X10_WCD_A_CDC_RX3_B6_CTL,
- 5, 0, NULL, 0),
- SND_SOC_DAPM_SUPPLY("HPHR CLK", MSM8X10_WCD_A_CDC_ANA_CLK_CTL,
- 0, 0, NULL, 0),
- SND_SOC_DAPM_SUPPLY("HPHL CLK", MSM8X10_WCD_A_CDC_ANA_CLK_CTL,
- 1, 0, NULL, 0),
- SND_SOC_DAPM_SUPPLY("EAR CLK", MSM8X10_WCD_A_CDC_ANA_CLK_CTL,
- 6, 0, NULL, 0),
- SND_SOC_DAPM_SUPPLY("LINEOUT CLK", MSM8X10_WCD_A_CDC_ANA_CLK_CTL,
- 3, 0, NULL, 0),
- SND_SOC_DAPM_SUPPLY("SPK CLK", MSM8X10_WCD_A_CDC_ANA_CLK_CTL,
- 4, 0, NULL, 0),
- SND_SOC_DAPM_MUX("RX1 MIX1 INP1", SND_SOC_NOPM, 0, 0,
- &rx_mix1_inp1_mux),
- SND_SOC_DAPM_MUX("RX1 MIX1 INP2", SND_SOC_NOPM, 0, 0,
- &rx_mix1_inp2_mux),
- SND_SOC_DAPM_MUX("RX1 MIX1 INP3", SND_SOC_NOPM, 0, 0,
- &rx_mix1_inp3_mux),
- SND_SOC_DAPM_MUX("RX2 MIX1 INP1", SND_SOC_NOPM, 0, 0,
- &rx2_mix1_inp1_mux),
- SND_SOC_DAPM_MUX("RX2 MIX1 INP2", SND_SOC_NOPM, 0, 0,
- &rx2_mix1_inp2_mux),
- SND_SOC_DAPM_MUX("RX3 MIX1 INP1", SND_SOC_NOPM, 0, 0,
- &rx3_mix1_inp1_mux),
- SND_SOC_DAPM_MUX("RX3 MIX1 INP2", SND_SOC_NOPM, 0, 0,
- &rx3_mix1_inp2_mux),
- SND_SOC_DAPM_MUX("RX1 MIX2 INP1", SND_SOC_NOPM, 0, 0,
- &rx1_mix2_inp1_mux),
- SND_SOC_DAPM_MUX("RX2 MIX2 INP1", SND_SOC_NOPM, 0, 0,
- &rx2_mix2_inp1_mux),
- SND_SOC_DAPM_MUX("RDAC4 MUX", SND_SOC_NOPM, 0, 0,
- &rx_dac4_mux),
- SND_SOC_DAPM_MUX("RDAC3 MUX", SND_SOC_NOPM, 0, 0,
- &rx_dac3_mux),
- SND_SOC_DAPM_SUPPLY("MICBIAS_REGULATOR", SND_SOC_NOPM,
- ON_DEMAND_MICBIAS, 0,
- msm8x10_wcd_codec_enable_on_demand_supply,
- SND_SOC_DAPM_PRE_PMU |
- SND_SOC_DAPM_POST_PMD),
- SND_SOC_DAPM_SUPPLY("CP_REGULATOR", SND_SOC_NOPM,
- ON_DEMAND_CP, 0,
- msm8x10_wcd_codec_enable_on_demand_supply,
- SND_SOC_DAPM_PRE_PMU |
- SND_SOC_DAPM_POST_PMD),
- SND_SOC_DAPM_SUPPLY("CP", MSM8X10_WCD_A_CP_EN, 0, 0,
- msm8x10_wcd_codec_enable_charge_pump, SND_SOC_DAPM_POST_PMU |
- SND_SOC_DAPM_PRE_PMD),
- SND_SOC_DAPM_SUPPLY("RX_BIAS", SND_SOC_NOPM, 0, 0,
- msm8x10_wcd_codec_enable_rx_bias, SND_SOC_DAPM_PRE_PMU |
- SND_SOC_DAPM_POST_PMD),
- /* TX */
- SND_SOC_DAPM_SUPPLY("CDC_CONN", MSM8X10_WCD_A_CDC_CLK_OTHR_CTL,
- 2, 0, NULL, 0),
- SND_SOC_DAPM_INPUT("AMIC1"),
- SND_SOC_DAPM_MICBIAS_E("MIC BIAS Internal1",
- SND_SOC_NOPM, 7, 0,
- msm8x10_wcd_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
- SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
- #if defined(CONFIG_SEC_HEAT_PROJECT) /*Remove Intenal mic bias2*/
- SND_SOC_DAPM_MICBIAS_E("MIC BIAS Internal2",
- 0, 0, 0,
- 0, SND_SOC_DAPM_PRE_PMU |
- SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
- #else
- SND_SOC_DAPM_MICBIAS_E("MIC BIAS Internal2",
- SND_SOC_NOPM, 7, 0,
- msm8x10_wcd_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
- SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
- #endif
- SND_SOC_DAPM_MICBIAS_E("MIC BIAS Internal3",
- SND_SOC_NOPM, 7, 0,
- msm8x10_wcd_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
- SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
- SND_SOC_DAPM_MICBIAS_E("MIC BIAS External",
- SND_SOC_NOPM, 7, 0,
- msm8x10_wcd_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU |
- SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
- SND_SOC_DAPM_MICBIAS_E(DAPM_MICBIAS_EXTERNAL_STANDALONE,
- SND_SOC_NOPM,
- 7, 0, msm8x10_wcd_codec_enable_micbias,
- SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
- SND_SOC_DAPM_POST_PMD),
- SND_SOC_DAPM_ADC_E("ADC1", NULL, MSM8X10_WCD_A_TX_1_EN, 7, 0,
- msm8x10_wcd_codec_enable_adc, SND_SOC_DAPM_PRE_PMU |
- SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
- SND_SOC_DAPM_ADC_E("ADC2_INP2", NULL, MSM8X10_WCD_A_TX_2_EN, 7, 0,
- msm8x10_wcd_codec_enable_adc, SND_SOC_DAPM_PRE_PMU |
- SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
- SND_SOC_DAPM_ADC_E("ADC2_INP3", NULL, MSM8X10_WCD_A_TX_3_EN, 7, 0,
- msm8x10_wcd_codec_enable_adc, SND_SOC_DAPM_PRE_PMU |
- SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
- SND_SOC_DAPM_MIXER("ADC2", SND_SOC_NOPM, 0, 0, NULL, 0),
- SND_SOC_DAPM_MUX("ADC2 MUX", SND_SOC_NOPM, 0, 0,
- &tx_adc2_mux),
- SND_SOC_DAPM_INPUT("AMIC3"),
- SND_SOC_DAPM_MUX_E("DEC1 MUX",
- MSM8X10_WCD_A_CDC_CLK_TX_CLK_EN_B1_CTL, 0, 0,
- &dec1_mux, msm8x10_wcd_codec_enable_dec,
- SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
- SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
- SND_SOC_DAPM_MUX_E("DEC2 MUX",
- MSM8X10_WCD_A_CDC_CLK_TX_CLK_EN_B1_CTL, 1, 0,
- &dec2_mux, msm8x10_wcd_codec_enable_dec,
- SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
- SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
- SND_SOC_DAPM_INPUT("AMIC2"),
- SND_SOC_DAPM_AIF_OUT("I2S TX1", "AIF1 Capture", 0, SND_SOC_NOPM,
- 0, 0),
- SND_SOC_DAPM_AIF_OUT("I2S TX2", "AIF1 Capture", 0, SND_SOC_NOPM,
- 0, 0),
- SND_SOC_DAPM_AIF_OUT("I2S TX3", "AIF1 Capture", 0, SND_SOC_NOPM,
- 0, 0),
- /* Digital Mic Inputs */
- SND_SOC_DAPM_ADC_E("DMIC1", NULL, SND_SOC_NOPM, 0, 0,
- msm8x10_wcd_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
- SND_SOC_DAPM_POST_PMD),
- SND_SOC_DAPM_ADC_E("DMIC2", NULL, SND_SOC_NOPM, 0, 0,
- msm8x10_wcd_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU |
- SND_SOC_DAPM_POST_PMD),
- /* Sidetone */
- SND_SOC_DAPM_MUX("IIR1 INP1 MUX", SND_SOC_NOPM, 0, 0, &iir1_inp1_mux),
- SND_SOC_DAPM_PGA("IIR1", MSM8X10_WCD_A_CDC_CLK_SD_CTL, 0, 0, NULL, 0),
- SND_SOC_DAPM_SUPPLY("RX_I2S_CLK", MSM8X10_WCD_A_CDC_CLK_RX_I2S_CTL,
- 4, 0, NULL, 0),
- SND_SOC_DAPM_SUPPLY("TX_I2S_CLK", MSM8X10_WCD_A_CDC_CLK_TX_I2S_CTL, 4,
- 0, NULL, 0),
- };
- static const struct msm8x10_wcd_reg_mask_val msm8x10_wcd_reg_defaults[] = {
- /* set MCLk to 9.6 */
- MSM8X10_WCD_REG_VAL(MSM8X10_WCD_A_CHIP_CTL, 0x00),
- /* EAR PA deafults */
- MSM8X10_WCD_REG_VAL(MSM8X10_WCD_A_RX_EAR_CMBUFF, 0x05),
- /* RX deafults */
- MSM8X10_WCD_REG_VAL(MSM8X10_WCD_A_CDC_RX1_B5_CTL, 0x78),
- MSM8X10_WCD_REG_VAL(MSM8X10_WCD_A_CDC_RX2_B5_CTL, 0x78),
- MSM8X10_WCD_REG_VAL(MSM8X10_WCD_A_CDC_RX3_B5_CTL, 0x78),
- /* RX1 and RX2 defaults */
- MSM8X10_WCD_REG_VAL(MSM8X10_WCD_A_CDC_RX1_B6_CTL, 0xA0),
- MSM8X10_WCD_REG_VAL(MSM8X10_WCD_A_CDC_RX2_B6_CTL, 0xA0),
- /* RX3 to RX7 defaults */
- MSM8X10_WCD_REG_VAL(MSM8X10_WCD_A_CDC_RX3_B6_CTL, 0x80),
- /* Reduce HPH DAC bias to 70% */
- MSM8X10_WCD_REG_VAL(MSM8X10_WCD_A_RX_HPH_BIAS_PA, 0x7A),
- /*Reduce EAR DAC bias to 70% */
- MSM8X10_WCD_REG_VAL(MSM8X10_WCD_A_RX_EAR_BIAS_PA, 0x76),
- /* Reduce LINE DAC bias to 70% */
- MSM8X10_WCD_REG_VAL(MSM8X10_WCD_A_RX_LINE_BIAS_PA, 0x78),
- /* Disable internal biasing path which can cause leakage */
- MSM8X10_WCD_REG_VAL(MSM8X10_WCD_A_BIAS_CURR_CTL_2, 0x04),
- #if defined(CONFIG_MACH_CS02VE)||defined(CONFIG_MACH_KYLEVE2_CTC) || defined(CONFIG_SEC_HEAT_PROJECT)
- MSM8X10_WCD_REG_VAL(MSM8X10_WCD_A_MICB_CFILT_1_VAL, 0x9C),
- #else
- #endif
- /* Enable pulldown to reduce leakage */
- #if defined(CONFIG_MACH_CS02VE)||defined(CONFIG_MACH_KYLEVE2_CTC) || defined(CONFIG_SEC_HEAT_PROJECT)
- MSM8X10_WCD_REG_VAL(MSM8X10_WCD_A_MICB_1_CTL, 0x92),
- #else
- MSM8X10_WCD_REG_VAL(MSM8X10_WCD_A_MICB_1_CTL, 0x82),
- #endif
- MSM8X10_WCD_REG_VAL(MSM8X10_WCD_A_TX_COM_BIAS, 0xE0),
- /* Keep the same default gain settings for TX paths */
- MSM8X10_WCD_REG_VAL(MSM8X10_WCD_A_TX_1_EN, 0x32),
- MSM8X10_WCD_REG_VAL(MSM8X10_WCD_A_TX_2_EN, 0x32),
- MSM8X10_WCD_REG_VAL(MSM8X10_WCD_A_TX_3_EN, 0x30),
- /* ClassG fine tuning setting for 16 ohm HPH */
- MSM8X10_WCD_REG_VAL(MSM8X10_WCD_A_CDC_CLSG_FREQ_THRESH_B1_CTL, 0x05),
- MSM8X10_WCD_REG_VAL(MSM8X10_WCD_A_CDC_CLSG_FREQ_THRESH_B2_CTL, 0x0C),
- MSM8X10_WCD_REG_VAL(MSM8X10_WCD_A_CDC_CLSG_FREQ_THRESH_B3_CTL, 0x1A),
- MSM8X10_WCD_REG_VAL(MSM8X10_WCD_A_CDC_CLSG_FREQ_THRESH_B4_CTL, 0x47),
- MSM8X10_WCD_REG_VAL(MSM8X10_WCD_A_CDC_CLSG_GAIN_THRESH_CTL, 0x23),
- /* Always set TXD_CLK_EN bit to reduce the leakage */
- MSM8X10_WCD_REG_VAL(MSM8X10_WCD_A_CDC_DIG_CLK_CTL, 0x10),
- /* Always disable clock gating for MCLK to mbhc clock gate */
- MSM8X10_WCD_REG_VAL(MSM8X10_WCD_A_CDC_ANA_CLK_CTL, 0x20),
- MSM8X10_WCD_REG_VAL(MSM8X10_WCD_A_CDC_DIG_CLK_CTL, 0x10),
- };
- static void msm8x10_wcd_update_reg_defaults(struct snd_soc_codec *codec)
- {
- u32 i;
- for (i = 0; i < ARRAY_SIZE(msm8x10_wcd_reg_defaults); i++)
- snd_soc_write(codec, msm8x10_wcd_reg_defaults[i].reg,
- msm8x10_wcd_reg_defaults[i].val);
- }
- static const struct msm8x10_wcd_reg_mask_val
- msm8x10_wcd_codec_reg_init_val[] = {
- /* Initialize current threshold to 350MA
- * number of wait and run cycles to 4096
- */
- #if defined(CONFIG_MACH_CS02VE)||defined(CONFIG_MACH_KYLEVE2_CTC) || defined(CONFIG_SEC_HEAT_PROJECT)
- {MSM8X10_WCD_A_RX_HPH_OCP_CTL, 0xFF, 0x6B},
- #else
- {MSM8X10_WCD_A_RX_HPH_OCP_CTL, 0xE1, 0x61},
- #endif
- {MSM8X10_WCD_A_RX_COM_OCP_COUNT, 0xFF, 0xFF},
- {MSM8X10_WCD_A_RX_HPH_L_TEST, 0x01, 0x01},
- {MSM8X10_WCD_A_RX_HPH_R_TEST, 0x01, 0x01},
- /* Initialize gain registers to use register gain */
- {MSM8X10_WCD_A_RX_HPH_L_GAIN, 0x20, 0x20},
- {MSM8X10_WCD_A_RX_HPH_R_GAIN, 0x20, 0x20},
- {MSM8X10_WCD_A_RX_LINE_1_GAIN, 0x20, 0x20},
- /*enable HPF filter for TX paths */
- {MSM8X10_WCD_A_CDC_TX1_MUX_CTL, 0x8, 0x0},
- {MSM8X10_WCD_A_CDC_TX2_MUX_CTL, 0x8, 0x0},
- /* config Decimator for DMIC CLK_MODE_1(3.2Mhz@9.6Mhz mclk) */
- {MSM8X10_WCD_A_CDC_TX1_DMIC_CTL, 0x7, 0x1},
- {MSM8X10_WCD_A_CDC_TX2_DMIC_CTL, 0x7, 0x1},
- /* config DMIC clk to CLK_MODE_1 (3.2Mhz@9.6Mhz mclk) */
- {MSM8X10_WCD_A_CDC_CLK_DMIC_B1_CTL, 0xEE, 0x22},
- /* Disable REF_EN for MSM8X10_WCD_A_SPKR_DRV_DAC_CTL */
- {MSM8X10_WCD_A_SPKR_DRV_DAC_CTL, 0x04, 0x00},
- };
- static void msm8x10_wcd_codec_init_reg(struct snd_soc_codec *codec)
- {
- u32 i;
- for (i = 0; i < ARRAY_SIZE(msm8x10_wcd_codec_reg_init_val); i++)
- snd_soc_update_bits(codec,
- msm8x10_wcd_codec_reg_init_val[i].reg,
- msm8x10_wcd_codec_reg_init_val[i].mask,
- msm8x10_wcd_codec_reg_init_val[i].val);
- }
- static void msm8x10_wcd_enable_mux_bias_block(
- struct snd_soc_codec *codec)
- {
- snd_soc_update_bits(codec, WCD9XXX_A_MBHC_SCALING_MUX_1,
- 0x80, 0x00);
- }
- static void msm8x10_wcd_put_cfilt_fast_mode(
- struct snd_soc_codec *codec,
- struct wcd9xxx_mbhc *mbhc)
- {
- snd_soc_update_bits(codec, mbhc->mbhc_bias_regs.cfilt_ctl,
- 0x30, 0x30);
- }
- static void msm8x10_wcd_codec_specific_cal_setup(
- struct snd_soc_codec *codec,
- struct wcd9xxx_mbhc *mbhc)
- {
- snd_soc_update_bits(codec, WCD9XXX_A_CDC_MBHC_B1_CTL,
- 0x04, 0x04);
- snd_soc_update_bits(codec, WCD9XXX_A_TX_7_MBHC_EN,
- 0xE0, 0xE0);
- }
- static struct wcd9xxx_cfilt_mode msm8x10_wcd_switch_cfilt_mode(
- struct wcd9xxx_mbhc *mbhc, bool fast)
- {
- struct snd_soc_codec *codec = mbhc->codec;
- struct wcd9xxx_cfilt_mode cfilt_mode;
- if (fast)
- cfilt_mode.reg_mode_val = WCD9XXX_CFILT_EXT_PRCHG_EN;
- else
- cfilt_mode.reg_mode_val = WCD9XXX_CFILT_EXT_PRCHG_DSBL;
- cfilt_mode.cur_mode_val =
- snd_soc_read(codec, mbhc->mbhc_bias_regs.cfilt_ctl) & 0x30;
- cfilt_mode.reg_mask = 0x30;
- return cfilt_mode;
- }
- static void msm8x10_wcd_select_cfilt(struct snd_soc_codec *codec,
- struct wcd9xxx_mbhc *mbhc)
- {
- snd_soc_update_bits(codec,
- mbhc->mbhc_bias_regs.ctl_reg, 0x60, 0x00);
- }
- enum wcd9xxx_cdc_type msm8x10_wcd_get_cdc_type(void)
- {
- return WCD9XXX_CDC_TYPE_HELICON;
- }
- static void msm8x10_wcd_mbhc_clk_gate(struct snd_soc_codec *codec,
- bool on)
- {
- snd_soc_update_bits(codec, MSM8X10_WCD_A_CDC_TOP_CLK_CTL, 0x10, 0x10);
- }
- static void msm8x10_wcd_mbhc_txfe(struct snd_soc_codec *codec, bool on)
- {
- snd_soc_update_bits(codec, MSM8X10_WCD_A_TX_7_MBHC_EN_ATEST_CTRL,
- 0x80, on ? 0x80 : 0x00);
- }
- static int msm8x10_wcd_enable_ext_mb_source(struct snd_soc_codec *codec,
- bool turn_on,
- bool use_dapm)
- {
- int ret = 0;
- if (use_dapm) {
- if (turn_on)
- ret = snd_soc_dapm_force_enable_pin(&codec->dapm,
- "MICBIAS_REGULATOR");
- else
- ret = snd_soc_dapm_disable_pin(&codec->dapm,
- "MICBIAS_REGULATOR");
- snd_soc_dapm_sync(&codec->dapm);
- } else {
- struct on_demand_supply *supply;
- struct msm8x10_wcd_priv *msm8x10_wcd =
- snd_soc_codec_get_drvdata(codec);
- supply = &msm8x10_wcd->on_demand_list[ON_DEMAND_MICBIAS];
- if (!supply || !supply->supply || !msm8x10_wcd)
- return 0;
- ret = on_demand_regulator_control(supply,
- turn_on,
- ON_DEMAND_MICBIAS);
- }
- if (ret)
- dev_err(codec->dev, "%s: Failed to %s external micbias source\n",
- __func__, turn_on ? "enable" : "disabled");
- else
- dev_dbg(codec->dev, "%s: %s external micbias source\n",
- __func__, turn_on ? "Enabled" : "Disabled");
- return ret;
- }
- #ifndef CONFIG_SAMSUNG_JACK
- static int msm8x10_wcd_enable_mbhc_micbias(struct snd_soc_codec *codec,
- bool enable,
- enum wcd9xxx_micbias_num micb_num)
- {
- int rc;
- if (micb_num != MBHC_MICBIAS1) {
- rc = -EINVAL;
- goto err;
- }
- if (enable)
- rc = snd_soc_dapm_force_enable_pin(&codec->dapm,
- DAPM_MICBIAS_EXTERNAL_STANDALONE);
- else {
- rc = snd_soc_dapm_disable_pin(&codec->dapm,
- DAPM_MICBIAS_EXTERNAL_STANDALONE);
- }
- snd_soc_dapm_sync(&codec->dapm);
- err:
- if (rc)
- pr_debug("%s: Failed to force %s micbias", __func__,
- enable ? "enable" : "disable");
- else
- pr_debug("%s: Trying force %s micbias", __func__,
- enable ? "enable" : "disable");
- return rc;
- }
- #endif
- static void msm8x10_wcd_micb_internal(struct snd_soc_codec *codec, bool on)
- {
- snd_soc_update_bits(codec, MSM8X10_WCD_A_MICB_1_INT_RBIAS,
- 0x1C, on ? 0x14 : 0x00);
- }
- static void msm8x10_wcd_enable_mb_vddio(struct snd_soc_codec *codec, bool on)
- {
- snd_soc_update_bits(codec, MSM8X10_WCD_A_MICB_CFILT_1_CTL,
- 0x40, on ? 0x40 : 0x00);
- }
- static void msm8x10_wcd_prepare_hph_pa(struct snd_soc_codec *codec,
- struct list_head *lh)
- {
- int i;
- u32 delay;
- const struct wcd9xxx_reg_mask_val reg_set_paon[] = {
- {MSM8X10_WCD_A_CDC_RX1_B6_CTL, 0xFF, 0x01},
- {MSM8X10_WCD_A_CDC_RX2_B6_CTL, 0xFF, 0x01},
- {MSM8X10_WCD_A_RX_HPH_L_GAIN, 0xFF, 0x2C},
- {MSM8X10_WCD_A_RX_HPH_R_GAIN, 0xFF, 0x2C},
- {MSM8X10_WCD_A_CDC_CLK_RX_B1_CTL, 0xFF, 0x01},
- {MSM8X10_WCD_A_RX_COM_BIAS, 0xFF, 0x80},
- {MSM8X10_WCD_A_CP_EN, 0xFF, 0xE7},
- {MSM8X10_WCD_A_CP_STATIC, 0xFF, 0x13},
- {MSM8X10_WCD_A_CP_STATIC, 0xFF, 0x1B},
- {MSM8X10_WCD_A_CDC_RX2_B6_CTL, 0xFF, 0x01},
- {MSM8X10_WCD_A_CDC_CLK_RX_B1_CTL, 0xFF, 0x03},
- {MSM8X10_WCD_A_CDC_ANA_CLK_CTL, 0xFF, 0x22},
- {MSM8X10_WCD_A_CDC_ANA_CLK_CTL, 0xFF, 0x23},
- {MSM8X10_WCD_A_RX_HPH_CNP_WG_CTL, 0xFF, 0xDA},
- {MSM8X10_WCD_A_CDC_DIG_CLK_CTL, 0xFF, 0x01},
- {MSM8X10_WCD_A_CDC_DIG_CLK_CTL, 0xFF, 0x03},
- {MSM8X10_WCD_A_RX_HPH_CHOP_CTL, 0xFF, 0xA4},
- {MSM8X10_WCD_A_RX_HPH_OCP_CTL, 0xFF, 0x67},
- {MSM8X10_WCD_A_RX_HPH_L_TEST, 0x01, 0x00},
- {MSM8X10_WCD_A_RX_HPH_R_TEST, 0x01, 0x00},
- {MSM8X10_WCD_A_RX_HPH_BIAS_WG_OCP, 0xFF, 0x1A},
- {MSM8X10_WCD_A_RX_HPH_CNP_WG_CTL, 0xFF, 0xDB},
- {MSM8X10_WCD_A_RX_HPH_CNP_WG_TIME, 0xFF, 0xDB},
- {MSM8X10_WCD_A_RX_HPH_L_DAC_CTL, 0xFF, 0x40},
- {MSM8X10_WCD_A_RX_HPH_L_DAC_CTL, 0xFF, 0xC0},
- {MSM8X10_WCD_A_RX_HPH_R_DAC_CTL, 0xFF, 0x40},
- {MSM8X10_WCD_A_RX_HPH_R_DAC_CTL, 0xFF, 0xC0},
- {MSM8X10_WCD_A_RX_HPH_L_DAC_CTL, 0x03, 0x01},
- {MSM8X10_WCD_A_RX_HPH_R_DAC_CTL, 0x03, 0x01},
- };
- for (i = 0; i < ARRAY_SIZE(reg_set_paon); i++) {
- delay = 0;
- wcd9xxx_soc_update_bits_push(codec, lh,
- reg_set_paon[i].reg,
- reg_set_paon[i].mask,
- reg_set_paon[i].val, delay);
- }
- dev_dbg(codec->dev, "%s: PAs are prepared\n", __func__);
- return;
- }
- static int msm8x10_wcd_enable_static_pa(struct snd_soc_codec *codec,
- bool enable)
- {
- int wg_time = snd_soc_read(codec, WCD9XXX_A_RX_HPH_CNP_WG_TIME) *
- MSM8X10_WCD_WG_TIME_FACTOR_US;
- wg_time += (int) (wg_time * 35) / 100;
- snd_soc_update_bits(codec, MSM8X10_WCD_A_RX_HPH_CNP_EN, 0x30,
- enable ? 0x30 : 0x0);
- /* Wait for wave gen time to avoid pop noise */
- usleep_range(wg_time, wg_time + WCD9XXX_USLEEP_RANGE_MARGIN_US);
- snd_soc_update_bits(codec, MSM8X10_WCD_A_CDC_RX1_B6_CTL, 0xFF, 0x00);
- snd_soc_update_bits(codec, MSM8X10_WCD_A_CDC_RX2_B6_CTL, 0xFF, 0x00);
- dev_dbg(codec->dev, "%s: PAs are %s as static mode (wg_time %d)\n",
- __func__, enable ? "enabled" : "disabled", wg_time);
- return 0;
- }
- static int msm8x10_wcd_setup_zdet(struct wcd9xxx_mbhc *mbhc,
- enum mbhc_impedance_detect_stages stage)
- {
- int ret = 0;
- struct snd_soc_codec *codec = mbhc->codec;
- struct msm8x10_wcd_priv *wcd_priv = snd_soc_codec_get_drvdata(codec);
- const int mux_wait_us = 25;
- #define __wr(reg, mask, value) \
- do { \
- ret = wcd9xxx_soc_update_bits_push(codec, \
- &wcd_priv->reg_save_restore, \
- reg, mask, value, 0); \
- if (ret < 0) \
- return ret; \
- } while (0)
- switch (stage) {
- case PRE_MEAS:
- dev_dbg(codec->dev, "%s: PRE_MEAS\n", __func__);
- INIT_LIST_HEAD(&wcd_priv->reg_save_restore);
- /* Configure PA */
- msm8x10_wcd_prepare_hph_pa(mbhc->codec,
- &wcd_priv->reg_save_restore);
- /* Setup MBHC */
- __wr(WCD9XXX_A_MBHC_SCALING_MUX_1, 0x7F, 0x40);
- __wr(WCD9XXX_A_MBHC_SCALING_MUX_2, 0xFF, 0xF0);
- __wr(0x171, 0xFF, 0x90);
- __wr(WCD9XXX_A_TX_7_MBHC_EN, 0xFF, 0xF0);
- __wr(WCD9XXX_A_CDC_MBHC_TIMER_B4_CTL, 0xFF, 0x45);
- __wr(WCD9XXX_A_CDC_MBHC_TIMER_B5_CTL, 0xFF, 0x80);
- __wr(WCD9XXX_A_CDC_MBHC_CLK_CTL, 0xFF, 0x0A);
- snd_soc_write(codec, WCD9XXX_A_CDC_MBHC_EN_CTL, 0x2);
- __wr(WCD9XXX_A_CDC_MBHC_CLK_CTL, 0xFF, 0x02);
- /* Enable Impedance Detection */
- __wr(WCD9XXX_A_MBHC_HPH, 0xFF, 0xC8);
- /*
- * CnP setup for 0mV
- * Route static data as input to noise shaper
- */
- __wr(MSM8X10_WCD_A_CDC_RX1_B3_CTL, 0xFF, 0x02);
- __wr(MSM8X10_WCD_A_CDC_RX2_B3_CTL, 0xFF, 0x02);
- snd_soc_update_bits(codec, WCD9XXX_A_RX_HPH_L_TEST,
- 0x02, 0x00);
- snd_soc_update_bits(codec, WCD9XXX_A_RX_HPH_R_TEST,
- 0x02, 0x00);
- /* Reset the HPHL static data pointer */
- __wr(MSM8X10_WCD_A_CDC_RX1_B2_CTL, 0xFF, 0x00);
- /* Four consecutive writes to set 0V as static data input */
- snd_soc_write(codec, MSM8X10_WCD_A_CDC_RX1_B1_CTL, 0x00);
- snd_soc_write(codec, MSM8X10_WCD_A_CDC_RX1_B1_CTL, 0x00);
- snd_soc_write(codec, MSM8X10_WCD_A_CDC_RX1_B1_CTL, 0x00);
- snd_soc_write(codec, MSM8X10_WCD_A_CDC_RX1_B1_CTL, 0x00);
- /* Reset the HPHR static data pointer */
- __wr(MSM8X10_WCD_A_CDC_RX2_B2_CTL, 0xFF, 0x00);
- /* Four consecutive writes to set 0V as static data input */
- snd_soc_write(codec, MSM8X10_WCD_A_CDC_RX2_B1_CTL, 0x00);
- snd_soc_write(codec, MSM8X10_WCD_A_CDC_RX2_B1_CTL, 0x00);
- snd_soc_write(codec, MSM8X10_WCD_A_CDC_RX2_B1_CTL, 0x00);
- snd_soc_write(codec, MSM8X10_WCD_A_CDC_RX2_B1_CTL, 0x00);
- /* Enable the HPHL and HPHR PA */
- msm8x10_wcd_enable_static_pa(mbhc->codec, true);
- break;
- case POST_MEAS:
- dev_dbg(codec->dev, "%s: POST_MEAS\n", __func__);
- /* Turn off ICAL */
- snd_soc_write(codec, WCD9XXX_A_MBHC_SCALING_MUX_2, 0xF0);
- msm8x10_wcd_enable_static_pa(mbhc->codec, false);
- /*
- * Setup CnP wavegen to ramp to the desired
- * output using a 40ms ramp
- */
- /* CnP wavegen current to 0.5uA */
- snd_soc_write(codec, WCD9XXX_A_RX_HPH_BIAS_WG_OCP, 0x1A);
- /* Set the current division ratio to 2000 */
- snd_soc_write(codec, WCD9XXX_A_RX_HPH_CNP_WG_CTL, 0xDF);
- /* Set the wavegen timer to max (60msec) */
- snd_soc_write(codec, WCD9XXX_A_RX_HPH_CNP_WG_TIME, 0xA0);
- /* Set the CnP reference current to sc_bias */
- snd_soc_write(codec, WCD9XXX_A_RX_HPH_OCP_CTL, 0x6D);
- snd_soc_write(codec, MSM8X10_WCD_A_CDC_RX1_B2_CTL, 0x00);
- /* Four consecutive writes to set -10mV as static data input */
- snd_soc_write(codec, MSM8X10_WCD_A_CDC_RX1_B1_CTL, 0x00);
- snd_soc_write(codec, MSM8X10_WCD_A_CDC_RX1_B1_CTL, 0x1F);
- snd_soc_write(codec, MSM8X10_WCD_A_CDC_RX1_B1_CTL, 0xE3);
- snd_soc_write(codec, MSM8X10_WCD_A_CDC_RX1_B1_CTL, 0x08);
- snd_soc_write(codec, MSM8X10_WCD_A_CDC_RX2_B2_CTL, 0x00);
- /* Four consecutive writes to set -10mV as static data input */
- snd_soc_write(codec, MSM8X10_WCD_A_CDC_RX2_B1_CTL, 0x00);
- snd_soc_write(codec, MSM8X10_WCD_A_CDC_RX2_B1_CTL, 0x1F);
- snd_soc_write(codec, MSM8X10_WCD_A_CDC_RX2_B1_CTL, 0xE3);
- snd_soc_write(codec, MSM8X10_WCD_A_CDC_RX2_B1_CTL, 0x08);
- snd_soc_update_bits(codec, WCD9XXX_A_RX_HPH_L_TEST,
- 0x02, 0x02);
- snd_soc_update_bits(codec, WCD9XXX_A_RX_HPH_R_TEST,
- 0x02, 0x02);
- /* Enable the HPHL and HPHR PA and wait for 60mS */
- msm8x10_wcd_enable_static_pa(mbhc->codec, true);
- snd_soc_update_bits(codec, WCD9XXX_A_MBHC_SCALING_MUX_1,
- 0x7F, 0x40);
- usleep_range(mux_wait_us,
- mux_wait_us + WCD9XXX_USLEEP_RANGE_MARGIN_US);
- break;
- case PA_DISABLE:
- dev_dbg(codec->dev, "%s: PA_DISABLE\n", __func__);
- msm8x10_wcd_enable_static_pa(mbhc->codec, false);
- wcd9xxx_restore_registers(codec, &wcd_priv->reg_save_restore);
- break;
- }
- #undef __wr
- return ret;
- }
- static void msm8x10_wcd_compute_impedance(s16 *l, s16 *r, uint32_t *zl,
- uint32_t *zr)
- {
- int zln, zld;
- int zrn, zrd;
- int rl = 0, rr = 0;
- zln = (l[1] - l[0]) * MSM8X10_WCD_ZDET_MUL_FACTOR;
- zld = (l[2] - l[0]);
- if (zld)
- rl = zln / zld;
- zrn = (r[1] - r[0]) * MSM8X10_WCD_ZDET_MUL_FACTOR;
- zrd = (r[2] - r[0]);
- if (zrd)
- rr = zrn / zrd;
- *zl = rl;
- *zr = rr;
- }
- static const struct wcd9xxx_mbhc_cb mbhc_cb = {
- .enable_mux_bias_block = msm8x10_wcd_enable_mux_bias_block,
- .cfilt_fast_mode = msm8x10_wcd_put_cfilt_fast_mode,
- .codec_specific_cal = msm8x10_wcd_codec_specific_cal_setup,
- .switch_cfilt_mode = msm8x10_wcd_switch_cfilt_mode,
- .select_cfilt = msm8x10_wcd_select_cfilt,
- .get_cdc_type = msm8x10_wcd_get_cdc_type,
- .enable_clock_gate = msm8x10_wcd_mbhc_clk_gate,
- .enable_mbhc_txfe = msm8x10_wcd_mbhc_txfe,
- .enable_mb_source = msm8x10_wcd_enable_ext_mb_source,
- .setup_int_rbias = msm8x10_wcd_micb_internal,
- .pull_mb_to_vddio = msm8x10_wcd_enable_mb_vddio,
- .setup_zdet = msm8x10_wcd_setup_zdet,
- .compute_impedance = msm8x10_wcd_compute_impedance,
- };
- int msm8x10_wcd_hs_detect(struct snd_soc_codec *codec,
- struct wcd9xxx_mbhc_config *mbhc_cfg)
- {
- #ifndef CONFIG_SAMSUNG_JACK
- struct msm8x10_wcd_priv *wcd = snd_soc_codec_get_drvdata(codec);
- if (!wcd) {
- dev_err(codec->dev, "%s: Invalid private data for codec\n",
- __func__);
- return -EINVAL;
- }
- wcd->mbhc_cfg = mbhc_cfg;
- wcd9xxx_mbhc_start(&wcd->mbhc, wcd->mbhc_cfg);
- #endif
- return 0;
- }
- EXPORT_SYMBOL_GPL(msm8x10_wcd_hs_detect);
- static int msm8x10_wcd_bringup(struct snd_soc_codec *codec)
- {
- snd_soc_write(codec, MSM8X10_WCD_A_CDC_RST_CTL, 0x02);
- snd_soc_write(codec, MSM8X10_WCD_A_CHIP_CTL, 0x00);
- usleep_range(5000, 5000);
- snd_soc_write(codec, MSM8X10_WCD_A_CDC_RST_CTL, 0x03);
- return 0;
- }
- static struct regulator *wcd8x10_wcd_codec_find_regulator(
- const struct msm8x10_wcd *msm8x10,
- const char *name)
- {
- int i;
- for (i = 0; i < msm8x10->num_of_supplies; i++) {
- if (msm8x10->supplies[i].supply &&
- !strncmp(msm8x10->supplies[i].supply, name, strlen(name)))
- return msm8x10->supplies[i].consumer;
- }
- return NULL;
- }
- static int msm8x10_wcd_device_down(struct snd_soc_codec *codec)
- {
- dev_dbg(codec->dev, "%s: device down!\n", __func__);
- snd_soc_card_change_online_state(codec->card, 0);
- return 0;
- }
- static const struct wcd9xxx_mbhc_intr cdc_intr_ids = {
- .poll_plug_rem = MSM8X10_WCD_IRQ_MBHC_REMOVAL,
- .shortavg_complete = MSM8X10_WCD_IRQ_MBHC_SHORT_TERM,
- .potential_button_press = MSM8X10_WCD_IRQ_MBHC_PRESS,
- .button_release = MSM8X10_WCD_IRQ_MBHC_RELEASE,
- .dce_est_complete = MSM8X10_WCD_IRQ_MBHC_POTENTIAL,
- .insertion = MSM8X10_WCD_IRQ_MBHC_INSERTION,
- .hph_left_ocp = MSM8X10_WCD_IRQ_HPH_PA_OCPL_FAULT,
- .hph_right_ocp = MSM8X10_WCD_IRQ_HPH_PA_OCPR_FAULT,
- .hs_jack_switch = MSM8X10_WCD_IRQ_MBHC_HS_DET,
- };
- static int msm8x10_wcd_device_up(struct snd_soc_codec *codec)
- {
- int ret = 0;
- struct msm8x10_wcd_priv *msm8x10_wcd_priv =
- snd_soc_codec_get_drvdata(codec);
- dev_err(codec->dev, "%s: device up!\n", __func__);
- snd_soc_card_change_online_state(codec->card, 1);
- /* delay is required to make sure sound card state updated */
- usleep_range(5000, 5100);
- mutex_lock(&codec->mutex);
- msm8x10_wcd_bringup(codec);
- msm8x10_wcd_update_reg_defaults(codec);
- msm8x10_wcd_codec_init_reg(codec);
- wcd9xxx_resmgr_post_ssr(&msm8x10_wcd_priv->resmgr);
- wcd9xxx_mbhc_deinit(&msm8x10_wcd_priv->mbhc);
- ret = wcd9xxx_mbhc_init(&msm8x10_wcd_priv->mbhc,
- &msm8x10_wcd_priv->resmgr,
- codec, msm8x10_wcd_enable_mbhc_micbias,
- &mbhc_cb, &cdc_intr_ids,
- HELICON_MCLK_CLK_9P6MHZ, true);
- if (ret)
- dev_err(codec->dev, "%s: Failed to initialize mbhc\n",
- __func__);
- else
- wcd9xxx_mbhc_start(&msm8x10_wcd_priv->mbhc,
- msm8x10_wcd_priv->mbhc.mbhc_cfg);
- mutex_unlock(&codec->mutex);
- return 0;
- }
- static int adsp_state_callback(struct notifier_block *nb, unsigned long value,
- void *priv)
- {
- bool timedout;
- unsigned long timeout;
- if (value == SUBSYS_BEFORE_SHUTDOWN)
- msm8x10_wcd_device_down(registered_codec);
- else if (value == SUBSYS_AFTER_POWERUP) {
- pr_debug("%s: ADSP is about to power up. bring up codec\n",
- __func__);
- timeout = jiffies +
- msecs_to_jiffies(ADSP_STATE_READY_TIMEOUT_MS);
- while (!(timedout = time_after(jiffies, timeout))) {
- if (!q6core_is_adsp_ready()) {
- pr_debug("%s: ADSP isn't ready\n", __func__);
- } else {
- pr_debug("%s: ADSP is ready\n", __func__);
- msm8x10_wcd_device_up(registered_codec);
- break;
- }
- }
- }
- return NOTIFY_OK;
- }
- static struct notifier_block adsp_state_notifier_block = {
- .notifier_call = adsp_state_callback,
- .priority = -INT_MAX,
- };
- static int msm8x10_wcd_handle_pdata(struct snd_soc_codec *codec,
- struct msm8x10_wcd_pdata *pdata)
- {
- int k1, rc = 0;
- struct msm8x10_wcd_priv *msm8x10_wcd_priv;
- msm8x10_wcd_priv = snd_soc_codec_get_drvdata(codec);
- /* Make sure settings are correct */
- if (pdata->micbias.ldoh_v > WCD9XXX_LDOH_3P0_V ||
- pdata->micbias.bias1_cfilt_sel > WCD9XXX_CFILT1_SEL) {
- rc = -EINVAL;
- goto done;
- }
- /* figure out k value */
- k1 = wcd9xxx_resmgr_get_k_val(&msm8x10_wcd_priv->resmgr,
- pdata->micbias.cfilt1_mv);
- if (IS_ERR_VALUE(k1)) {
- rc = -EINVAL;
- goto done;
- }
- /* Set voltage level */
- snd_soc_update_bits(codec, MSM8X10_WCD_A_MICB_CFILT_1_VAL,
- 0xFC, (k1 << 2));
- /* update micbias capless mode */
- snd_soc_update_bits(codec, MSM8X10_WCD_A_MICB_1_CTL, 0x10,
- pdata->micbias.bias1_cap_mode << 4);
- done:
- return rc;
- }
- static int msm8x10_wcd_codec_probe(struct snd_soc_codec *codec)
- {
- struct msm8x10_wcd_priv *msm8x10_wcd_priv;
- struct msm8x10_wcd *msm8x10_wcd;
- struct wcd9xxx_core_resource *core_res;
- int i, ret = 0;
- struct msm8x10_wcd_pdata *pdata;
- dev_dbg(codec->dev, "%s()\n", __func__);
- msm8x10_wcd_priv = devm_kzalloc(codec->dev,
- sizeof(struct msm8x10_wcd_priv), GFP_KERNEL);
- if (!msm8x10_wcd_priv) {
- dev_err(codec->dev, "Failed to allocate private data\n");
- return -ENOMEM;
- }
- for (i = 0 ; i < NUM_DECIMATORS; i++) {
- tx_hpf_work[i].msm8x10_wcd = msm8x10_wcd_priv;
- tx_hpf_work[i].decimator = i + 1;
- INIT_DELAYED_WORK(&tx_hpf_work[i].dwork,
- tx_hpf_corner_freq_callback);
- }
- codec->control_data = dev_get_drvdata(codec->dev);
- snd_soc_codec_set_drvdata(codec, msm8x10_wcd_priv);
- msm8x10_wcd_priv->codec = codec;
- /* map digital codec registers once */
- msm8x10_wcd = codec->control_data;
- msm8x10_wcd->pdino_base = ioremap(MSM8X10_DINO_CODEC_BASE_ADDR,
- MSM8X10_DINO_CODEC_REG_SIZE);
- pdata = dev_get_platdata(msm8x10_wcd->dev);
- if (!pdata) {
- dev_err(msm8x10_wcd->dev, "%s: platform data not found\n",
- __func__);
- }
- /* codec resmgr module init */
- msm8x10_wcd = codec->control_data;
- core_res = &msm8x10_wcd->wcd9xxx_res;
- ret = wcd9xxx_resmgr_init(&msm8x10_wcd_priv->resmgr,
- codec, core_res, NULL, &pdata->micbias,
- NULL, WCD9XXX_CDC_TYPE_HELICON);
- if (ret) {
- dev_err(codec->dev,
- "%s: wcd9xxx init failed %d\n",
- __func__, ret);
- goto exit_probe;
- }
- msm8x10_wcd_bringup(codec);
- msm8x10_wcd_codec_init_reg(codec);
- msm8x10_wcd_update_reg_defaults(codec);
- msm8x10_wcd_priv->on_demand_list[ON_DEMAND_CP].supply =
- wcd8x10_wcd_codec_find_regulator(
- codec->control_data,
- on_demand_supply_name[ON_DEMAND_CP]);
- atomic_set(&msm8x10_wcd_priv->on_demand_list[ON_DEMAND_CP].ref, 0);
- msm8x10_wcd_priv->on_demand_list[ON_DEMAND_MICBIAS].supply =
- wcd8x10_wcd_codec_find_regulator(
- codec->control_data,
- on_demand_supply_name[ON_DEMAND_MICBIAS]);
- atomic_set(&msm8x10_wcd_priv->on_demand_list[ON_DEMAND_MICBIAS].ref, 0);
- #ifndef CONFIG_SAMSUNG_JACK
- msm8x10_wcd_priv->micb_en_count = 0;
- ret = wcd9xxx_mbhc_init(&msm8x10_wcd_priv->mbhc,
- &msm8x10_wcd_priv->resmgr,
- codec, msm8x10_wcd_enable_mbhc_micbias,
- &mbhc_cb, &cdc_intr_ids,
- HELICON_MCLK_CLK_9P6MHZ, true);
- if (ret) {
- dev_err(msm8x10_wcd->dev, "%s: Failed to initialize mbhc\n",
- __func__);
- goto exit_probe;
- }
- #endif
- /* Handle the Pdata */
- ret = msm8x10_wcd_handle_pdata(codec, pdata);
- if (IS_ERR_VALUE(ret))
- dev_err(msm8x10_wcd->dev, "%s: Bad Pdata\n", __func__);
- registered_codec = codec;
- adsp_state_notifier =
- subsys_notif_register_notifier("adsp",
- &adsp_state_notifier_block);
- if (!adsp_state_notifier) {
- pr_err("%s: Failed to register adsp state notifier\n",
- __func__);
- registered_codec = NULL;
- return -ENOMEM;
- }
- return 0;
- exit_probe:
- return ret;
- }
- static int msm8x10_wcd_codec_remove(struct snd_soc_codec *codec)
- {
- struct msm8x10_wcd_priv *pwcd_priv = snd_soc_codec_get_drvdata(codec);
- struct msm8x10_wcd *msm8x10_wcd = pwcd_priv->codec->control_data;
- pwcd_priv->on_demand_list[ON_DEMAND_CP].supply = NULL;
- atomic_set(&pwcd_priv->on_demand_list[ON_DEMAND_CP].ref, 0);
- pwcd_priv->on_demand_list[ON_DEMAND_MICBIAS].supply = NULL;
- atomic_set(&pwcd_priv->on_demand_list[ON_DEMAND_MICBIAS].ref, 0);
- /* cleanup resmgr */
- wcd9xxx_resmgr_deinit(&pwcd_priv->resmgr);
- iounmap(msm8x10_wcd->pdino_base);
- return 0;
- }
- static struct snd_soc_codec_driver soc_codec_dev_msm8x10_wcd = {
- .probe = msm8x10_wcd_codec_probe,
- .remove = msm8x10_wcd_codec_remove,
- .read = msm8x10_wcd_read,
- .write = msm8x10_wcd_write,
- .readable_register = msm8x10_wcd_readable,
- .volatile_register = msm8x10_wcd_volatile,
- .reg_cache_size = MSM8X10_WCD_CACHE_SIZE,
- .reg_cache_default = msm8x10_wcd_reset_reg_defaults,
- .reg_word_size = 1,
- .controls = msm8x10_wcd_snd_controls,
- .num_controls = ARRAY_SIZE(msm8x10_wcd_snd_controls),
- .dapm_widgets = msm8x10_wcd_dapm_widgets,
- .num_dapm_widgets = ARRAY_SIZE(msm8x10_wcd_dapm_widgets),
- .dapm_routes = audio_map,
- .num_dapm_routes = ARRAY_SIZE(audio_map),
- };
- static int msm8x10_wcd_init_supplies(struct msm8x10_wcd *msm8x10,
- struct msm8x10_wcd_pdata *pdata)
- {
- int ret;
- int i;
- msm8x10->supplies = kzalloc(sizeof(struct regulator_bulk_data) *
- ARRAY_SIZE(pdata->regulator),
- GFP_KERNEL);
- if (!msm8x10->supplies) {
- ret = -ENOMEM;
- goto err;
- }
- msm8x10->num_of_supplies = 0;
- if (ARRAY_SIZE(pdata->regulator) > MAX_REGULATOR) {
- dev_err(msm8x10->dev, "%s: Array Size out of bound\n",
- __func__);
- ret = -EINVAL;
- goto err;
- }
- for (i = 0; i < ARRAY_SIZE(pdata->regulator); i++) {
- if (pdata->regulator[i].name) {
- msm8x10->supplies[i].supply = pdata->regulator[i].name;
- msm8x10->num_of_supplies++;
- }
- }
- ret = regulator_bulk_get(msm8x10->dev, msm8x10->num_of_supplies,
- msm8x10->supplies);
- if (ret != 0) {
- dev_err(msm8x10->dev, "Failed to get supplies: err = %d\n",
- ret);
- goto err_supplies;
- }
- for (i = 0; i < msm8x10->num_of_supplies; i++) {
- if (regulator_count_voltages(msm8x10->supplies[i].consumer) <=
- 0)
- continue;
- ret = regulator_set_voltage(msm8x10->supplies[i].consumer,
- pdata->regulator[i].min_uV,
- pdata->regulator[i].max_uV);
- if (ret) {
- dev_err(msm8x10->dev, "%s: Setting regulator voltage failed for regulator %s err = %d\n",
- __func__, msm8x10->supplies[i].supply, ret);
- goto err_get;
- }
- ret = regulator_set_optimum_mode(msm8x10->supplies[i].consumer,
- pdata->regulator[i].optimum_uA);
- if (ret < 0) {
- dev_err(msm8x10->dev, "%s: Setting regulator optimum mode failed for regulator %s err = %d\n",
- __func__, msm8x10->supplies[i].supply, ret);
- goto err_get;
- } else {
- ret = 0;
- }
- }
- return ret;
- err_get:
- regulator_bulk_free(msm8x10->num_of_supplies, msm8x10->supplies);
- err_supplies:
- kfree(msm8x10->supplies);
- err:
- return ret;
- }
- static int msm8x10_wcd_enable_static_supplies(struct msm8x10_wcd *msm8x10,
- struct msm8x10_wcd_pdata *pdata)
- {
- int i;
- int ret = 0;
- for (i = 0; i < msm8x10->num_of_supplies; i++) {
- if (pdata->regulator[i].ondemand)
- continue;
- ret = regulator_enable(msm8x10->supplies[i].consumer);
- if (ret) {
- pr_err("%s: Failed to enable %s\n", __func__,
- msm8x10->supplies[i].supply);
- break;
- } else {
- pr_debug("%s: Enabled regulator %s\n", __func__,
- msm8x10->supplies[i].supply);
- }
- }
- while (ret && --i)
- if (!pdata->regulator[i].ondemand)
- regulator_disable(msm8x10->supplies[i].consumer);
- return ret;
- }
- static void msm8x10_wcd_disable_supplies(struct msm8x10_wcd *msm8x10,
- struct msm8x10_wcd_pdata *pdata)
- {
- int i;
- regulator_bulk_disable(msm8x10->num_of_supplies,
- msm8x10->supplies);
- for (i = 0; i < msm8x10->num_of_supplies; i++) {
- if (regulator_count_voltages(msm8x10->supplies[i].consumer) <=
- 0)
- continue;
- regulator_set_voltage(msm8x10->supplies[i].consumer, 0,
- pdata->regulator[i].max_uV);
- regulator_set_optimum_mode(msm8x10->supplies[i].consumer, 0);
- }
- regulator_bulk_free(msm8x10->num_of_supplies, msm8x10->supplies);
- kfree(msm8x10->supplies);
- }
- static int msm8x10_wcd_pads_config(void)
- {
- void __iomem *ppull = ioremap(MSM8x10_TLMM_CDC_PULL_CTL, 4);
- /* Set I2C pads as pull up and rest of pads as no pull */
- iowrite32(0x03C00000, ppull);
- usleep_range(100, 200);
- iounmap(ppull);
- return 0;
- }
- static int msm8x10_wcd_clk_init(void)
- {
- void __iomem *pdig1 = ioremap(MSM8X10_DINO_LPASS_DIGCODEC_CFG_RCGR, 4);
- void __iomem *pdig2 = ioremap(MSM8X10_DINO_LPASS_DIGCODEC_M, 4);
- void __iomem *pdig3 = ioremap(MSM8X10_DINO_LPASS_DIGCODEC_N, 4);
- void __iomem *pdig4 = ioremap(MSM8X10_DINO_LPASS_DIGCODEC_D, 4);
- void __iomem *pdig5 = ioremap(MSM8X10_DINO_LPASS_DIGCODEC_CBCR, 4);
- void __iomem *pdig6 = ioremap(MSM8X10_DINO_LPASS_DIGCODEC_CMD_RCGR, 4);
- /* Div-2 */
- iowrite32(0x3, pdig1);
- iowrite32(0x0, pdig2);
- iowrite32(0x0, pdig3);
- iowrite32(0x0, pdig4);
- /* Digital codec clock enable */
- iowrite32(0x1, pdig5);
- /* Set the update bit to make the settings go through */
- iowrite32(0x1, pdig6);
- usleep_range(100, 200);
- iounmap(pdig1);
- iounmap(pdig2);
- iounmap(pdig3);
- iounmap(pdig4);
- iounmap(pdig5);
- iounmap(pdig6);
- return 0;
- }
- static int msm8x10_wcd_device_init(struct msm8x10_wcd *msm8x10)
- {
- mutex_init(&msm8x10->io_lock);
- mutex_init(&msm8x10->xfer_lock);
- msm8x10_wcd_pads_config();
- msm8x10_wcd_clk_init();
- return 0;
- }
- static struct intr_data interrupt_table[] = {
- {MSM8X10_WCD_IRQ_MBHC_INSERTION, true},
- {MSM8X10_WCD_IRQ_MBHC_POTENTIAL, true},
- {MSM8X10_WCD_IRQ_MBHC_RELEASE, true},
- {MSM8X10_WCD_IRQ_MBHC_PRESS, true},
- {MSM8X10_WCD_IRQ_MBHC_SHORT_TERM, true},
- {MSM8X10_WCD_IRQ_MBHC_REMOVAL, true},
- {MSM8X10_WCD_IRQ_MBHC_HS_DET, true},
- {MSM8X10_WCD_IRQ_RESERVED_0, false},
- {MSM8X10_WCD_IRQ_PA_STARTUP, false},
- {MSM8X10_WCD_IRQ_BG_PRECHARGE, false},
- {MSM8X10_WCD_IRQ_RESERVED_1, false},
- {MSM8X10_WCD_IRQ_EAR_PA_OCPL_FAULT, false},
- {MSM8X10_WCD_IRQ_EAR_PA_STARTUP, false},
- {MSM8X10_WCD_IRQ_SPKR_PA_OCPL_FAULT, false},
- {MSM8X10_WCD_IRQ_SPKR_CLIP_FAULT, false},
- {MSM8X10_WCD_IRQ_RESERVED_2, false},
- {MSM8X10_WCD_IRQ_HPH_L_PA_STARTUP, false},
- {MSM8X10_WCD_IRQ_HPH_R_PA_STARTUP, false},
- {MSM8X10_WCD_IRQ_HPH_PA_OCPL_FAULT, false},
- {MSM8X10_WCD_IRQ_HPH_PA_OCPR_FAULT, false},
- {MSM8X10_WCD_IRQ_RESERVED_3, false},
- {MSM8X10_WCD_IRQ_RESERVED_4, false},
- {MSM8X10_WCD_IRQ_RESERVED_5, false},
- {MSM8X10_WCD_IRQ_RESERVED_6, false},
- };
- static int __devinit msm8x10_wcd_i2c_probe(struct i2c_client *client,
- const struct i2c_device_id *id)
- {
- int ret = 0;
- struct msm8x10_wcd *msm8x10 = NULL;
- struct msm8x10_wcd_pdata *pdata;
- static int device_id;
- struct device *dev;
- enum apr_subsys_state q6_state;
- struct wcd9xxx_core_resource *core_res;
- dev_dbg(&client->dev, "%s(%d):slave addr = 0x%x device_id = %d\n",
- __func__, __LINE__, client->addr, device_id);
- switch (client->addr) {
- case HELICON_CORE_0_I2C_ADDR:
- msm8x10_wcd_modules[0].client = client;
- break;
- case HELICON_CORE_1_I2C_ADDR:
- msm8x10_wcd_modules[1].client = client;
- goto rtn;
- case HELICON_CORE_2_I2C_ADDR:
- msm8x10_wcd_modules[2].client = client;
- goto rtn;
- case HELICON_CORE_3_I2C_ADDR:
- msm8x10_wcd_modules[3].client = client;
- goto rtn;
- default:
- ret = -EINVAL;
- goto rtn;
- }
- q6_state = apr_get_q6_state();
- if ((q6_state == APR_SUBSYS_DOWN) &&
- (client->addr == HELICON_CORE_0_I2C_ADDR)) {
- dev_info(&client->dev, "defering %s, adsp_state %d\n", __func__,
- q6_state);
- return -EPROBE_DEFER;
- } else
- dev_info(&client->dev, "adsp is ready\n");
- dev_dbg(&client->dev, "%s(%d):slave addr = 0x%x device_id = %d\n",
- __func__, __LINE__, client->addr, device_id);
- if (client->addr != HELICON_CORE_0_I2C_ADDR)
- goto rtn;
- dev_set_name(&client->dev, "%s", MSM8X10_CODEC_NAME);
- dev = &client->dev;
- if (client->dev.of_node) {
- dev_dbg(&client->dev, "%s:Platform data from device tree\n",
- __func__);
- pdata = msm8x10_wcd_populate_dt_pdata(&client->dev);
- if (!pdata) {
- dev_err(&client->dev, "%s: Failed to parse pdata from device tree\n",
- __func__);
- goto rtn;
- }
- client->dev.platform_data = pdata;
- } else {
- dev_dbg(&client->dev, "%s:Platform data from board file\n",
- __func__);
- pdata = client->dev.platform_data;
- }
- msm8x10 = kzalloc(sizeof(struct msm8x10_wcd), GFP_KERNEL);
- if (msm8x10 == NULL) {
- dev_err(&client->dev,
- "%s: error, allocation failed\n", __func__);
- ret = -ENOMEM;
- goto rtn;
- }
- msm8x10->dev = &client->dev;
- msm8x10->read_dev = __msm8x10_wcd_reg_read;
- msm8x10->write_dev = __msm8x10_wcd_reg_write;
- ret = msm8x10_wcd_init_supplies(msm8x10, pdata);
- if (ret) {
- dev_err(&client->dev, "%s: Fail to enable Codec supplies\n",
- __func__);
- goto err_codec;
- }
- ret = msm8x10_wcd_enable_static_supplies(msm8x10, pdata);
- if (ret) {
- pr_err("%s: Fail to enable Codec pre-reset supplies\n",
- __func__);
- goto err_codec;
- }
- usleep_range(5, 5);
- ret = msm8x10_wcd_device_init(msm8x10);
- if (ret) {
- dev_err(&client->dev,
- "%s:msm8x10_wcd_device_init failed with error %d\n",
- __func__, ret);
- goto err_supplies;
- }
- dev_set_drvdata(&client->dev, msm8x10);
- core_res = &msm8x10->wcd9xxx_res;
- core_res->parent = msm8x10;
- core_res->dev = msm8x10->dev;
- core_res->intr_table = interrupt_table;
- core_res->intr_table_size = ARRAY_SIZE(interrupt_table);
- wcd9xxx_core_res_init(core_res,
- MSM8X10_WCD_NUM_IRQS,
- MSM8X10_WCD_NUM_IRQ_REGS,
- msm8x10_wcd_reg_read,
- msm8x10_wcd_reg_write,
- msm8x10_wcd_bulk_read,
- msm8x10_wcd_bulk_write);
- if (wcd9xxx_core_irq_init(core_res)) {
- dev_err(msm8x10->dev,
- "%s: irq initialization failed\n", __func__);
- } else {
- dev_info(msm8x10->dev,
- "%s: irq initialization passed\n", __func__);
- }
- ret = snd_soc_register_codec(&client->dev, &soc_codec_dev_msm8x10_wcd,
- msm8x10_wcd_i2s_dai,
- ARRAY_SIZE(msm8x10_wcd_i2s_dai));
- if (ret) {
- dev_err(&client->dev,
- "%s:snd_soc_register_codec failed with error %d\n",
- __func__, ret);
- } else {
- wcd9xxx_set_intf_type(WCD9XXX_INTERFACE_TYPE_I2C);
- goto rtn;
- }
- err_supplies:
- msm8x10_wcd_disable_supplies(msm8x10, pdata);
- err_codec:
- kfree(msm8x10);
- rtn:
- return ret;
- }
- static void msm8x10_wcd_device_exit(struct msm8x10_wcd *msm8x10)
- {
- mutex_destroy(&msm8x10->io_lock);
- mutex_destroy(&msm8x10->xfer_lock);
- kfree(msm8x10);
- }
- static int __devexit msm8x10_wcd_i2c_remove(struct i2c_client *client)
- {
- struct msm8x10_wcd *msm8x10 = dev_get_drvdata(&client->dev);
- msm8x10_wcd_device_exit(msm8x10);
- return 0;
- }
- static struct i2c_device_id msm8x10_wcd_id_table[] = {
- {"msm8x10-wcd-i2c", MSM8X10_WCD_I2C_TOP_LEVEL},
- {"msm8x10-wcd-i2c", MSM8X10_WCD_I2C_ANALOG},
- {"msm8x10-wcd-i2c", MSM8X10_WCD_I2C_DIGITAL_1},
- {"msm8x10-wcd-i2c", MSM8X10_WCD_I2C_DIGITAL_2},
- {}
- };
- static struct of_device_id msm8x10_wcd_of_match[] = {
- { .compatible = "qcom,msm8x10-wcd-i2c",},
- { },
- };
- #ifdef CONFIG_PM
- static int msm8x10_wcd_i2c_resume(struct device *dev)
- {
- struct i2c_client *client = to_i2c_client(dev);
- struct msm8x10_wcd_priv *priv = i2c_get_clientdata(client);
- struct msm8x10_wcd *msm8x10;
- int ret = 0;
- if (client->addr == HELICON_CORE_0_I2C_ADDR) {
- if (!priv || !priv->codec || !priv->codec->control_data) {
- ret = -EINVAL;
- dev_err(dev, "%s: Invalid client data\n", __func__);
- goto rtn;
- }
- msm8x10 = priv->codec->control_data;
- return wcd9xxx_core_res_resume(&msm8x10->wcd9xxx_res);
- }
- rtn:
- return 0;
- }
- static int msm8x10_wcd_i2c_suspend(struct device *dev)
- {
- struct i2c_client *client = to_i2c_client(dev);
- struct msm8x10_wcd_priv *priv = i2c_get_clientdata(client);
- struct msm8x10_wcd *msm8x10;
- int ret = 0;
- if (client->addr == HELICON_CORE_0_I2C_ADDR) {
- if (!priv || !priv->codec || !priv->codec->control_data) {
- ret = -EINVAL;
- dev_err(dev, "%s: Invalid client data\n", __func__);
- goto rtn;
- }
- msm8x10 = priv->codec->control_data;
- return wcd9xxx_core_res_suspend(&msm8x10->wcd9xxx_res,
- PMSG_SUSPEND);
- }
- rtn:
- return ret;
- }
- static SIMPLE_DEV_PM_OPS(msm8x1_wcd_pm_ops, msm8x10_wcd_i2c_suspend,
- msm8x10_wcd_i2c_resume);
- #endif
- static struct i2c_driver msm8x10_wcd_i2c_driver = {
- .driver = {
- .owner = THIS_MODULE,
- .name = "msm8x10-wcd-i2c-core",
- .of_match_table = msm8x10_wcd_of_match,
- #ifdef CONFIG_PM
- .pm = &msm8x1_wcd_pm_ops,
- #endif
- },
- .id_table = msm8x10_wcd_id_table,
- .probe = msm8x10_wcd_i2c_probe,
- .remove = __devexit_p(msm8x10_wcd_i2c_remove),
- };
- static int __init msm8x10_wcd_codec_init(void)
- {
- int ret;
- pr_debug("%s:\n", __func__);
- wcd9xxx_set_intf_type(WCD9XXX_INTERFACE_TYPE_PROBING);
- ret = i2c_add_driver(&msm8x10_wcd_i2c_driver);
- if (ret != 0)
- pr_err("%s: Failed to add msm8x10 wcd I2C driver - error %d\n",
- __func__, ret);
- return ret;
- }
- static void __exit msm8x10_wcd_codec_exit(void)
- {
- i2c_del_driver(&msm8x10_wcd_i2c_driver);
- }
- module_init(msm8x10_wcd_codec_init);
- module_exit(msm8x10_wcd_codec_exit);
- MODULE_DESCRIPTION("MSM8x10 Audio codec driver");
- MODULE_LICENSE("GPL v2");
- MODULE_DEVICE_TABLE(i2c, msm8x10_wcd_id_table);
|