12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362 |
- // SPDX-License-Identifier: GPL-2.0-only
- /* Copyright (c) 2018-2021, The Linux Foundation. All rights reserved.
- * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
- */
- #include <linux/module.h>
- #include <linux/init.h>
- #include <linux/io.h>
- #include <linux/platform_device.h>
- #include <linux/clk.h>
- #include <linux/pm_runtime.h>
- #include <sound/soc.h>
- #include <sound/soc-dapm.h>
- #include <sound/tlv.h>
- #include <soc/swr-common.h>
- #include <soc/swr-wcd.h>
- #include <asoc/msm-cdc-pinctrl.h>
- #include "bolero-cdc.h"
- #include "bolero-cdc-registers.h"
- #include "wsa-macro.h"
- #include "bolero-clk-rsc.h"
- #define AUTO_SUSPEND_DELAY 50 /* delay in msec */
- #define WSA_MACRO_MAX_OFFSET 0x1000
- #define WSA_MACRO_RX_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
- SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 |\
- SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000)
- #define WSA_MACRO_RX_MIX_RATES (SNDRV_PCM_RATE_48000 |\
- SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000)
- #define WSA_MACRO_RX_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\
- SNDRV_PCM_FMTBIT_S24_LE |\
- SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE)
- #define WSA_MACRO_ECHO_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
- SNDRV_PCM_RATE_48000)
- #define WSA_MACRO_ECHO_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\
- SNDRV_PCM_FMTBIT_S24_LE |\
- SNDRV_PCM_FMTBIT_S24_3LE)
- #define NUM_INTERPOLATORS 2
- #define WSA_MACRO_MUX_INP_SHFT 0x3
- #define WSA_MACRO_MUX_INP_MASK1 0x07
- #define WSA_MACRO_MUX_INP_MASK2 0x38
- #define WSA_MACRO_MUX_CFG_OFFSET 0x8
- #define WSA_MACRO_MUX_CFG1_OFFSET 0x4
- #define WSA_MACRO_RX_COMP_OFFSET 0x40
- #define WSA_MACRO_RX_SOFTCLIP_OFFSET 0x40
- #define WSA_MACRO_RX_PATH_OFFSET 0x80
- #define WSA_MACRO_RX_PATH_CFG3_OFFSET 0x10
- #define WSA_MACRO_RX_PATH_DSMDEM_OFFSET 0x4C
- #define WSA_MACRO_FS_RATE_MASK 0x0F
- #define WSA_MACRO_EC_MIX_TX0_MASK 0x03
- #define WSA_MACRO_EC_MIX_TX1_MASK 0x18
- #define WSA_MACRO_MAX_DMA_CH_PER_PORT 0x2
- enum {
- WSA_MACRO_RX0 = 0,
- WSA_MACRO_RX1,
- WSA_MACRO_RX_MIX,
- WSA_MACRO_RX_MIX0 = WSA_MACRO_RX_MIX,
- WSA_MACRO_RX_MIX1,
- WSA_MACRO_RX_MAX,
- };
- enum {
- WSA_MACRO_TX0 = 0,
- WSA_MACRO_TX1,
- WSA_MACRO_TX_MAX,
- };
- enum {
- WSA_MACRO_EC0_MUX = 0,
- WSA_MACRO_EC1_MUX,
- WSA_MACRO_EC_MUX_MAX,
- };
- enum {
- WSA_MACRO_COMP1, /* SPK_L */
- WSA_MACRO_COMP2, /* SPK_R */
- WSA_MACRO_COMP_MAX
- };
- enum {
- WSA_MACRO_SOFTCLIP0, /* RX0 */
- WSA_MACRO_SOFTCLIP1, /* RX1 */
- WSA_MACRO_SOFTCLIP_MAX
- };
- enum {
- INTn_1_INP_SEL_ZERO = 0,
- INTn_1_INP_SEL_RX0,
- INTn_1_INP_SEL_RX1,
- INTn_1_INP_SEL_RX2,
- INTn_1_INP_SEL_RX3,
- INTn_1_INP_SEL_DEC0,
- INTn_1_INP_SEL_DEC1,
- };
- enum {
- INTn_2_INP_SEL_ZERO = 0,
- INTn_2_INP_SEL_RX0,
- INTn_2_INP_SEL_RX1,
- INTn_2_INP_SEL_RX2,
- INTn_2_INP_SEL_RX3,
- };
- struct interp_sample_rate {
- int sample_rate;
- int rate_val;
- };
- /*
- * Structure used to update codec
- * register defaults after reset
- */
- struct wsa_macro_reg_mask_val {
- u16 reg;
- u8 mask;
- u8 val;
- };
- static struct interp_sample_rate int_prim_sample_rate_val[] = {
- {8000, 0x0}, /* 8K */
- {16000, 0x1}, /* 16K */
- {24000, -EINVAL},/* 24K */
- {32000, 0x3}, /* 32K */
- {48000, 0x4}, /* 48K */
- {96000, 0x5}, /* 96K */
- {192000, 0x6}, /* 192K */
- {384000, 0x7}, /* 384K */
- {44100, 0x8}, /* 44.1K */
- };
- static struct interp_sample_rate int_mix_sample_rate_val[] = {
- {48000, 0x4}, /* 48K */
- {96000, 0x5}, /* 96K */
- {192000, 0x6}, /* 192K */
- };
- #define WSA_MACRO_SWR_STRING_LEN 80
- static int wsa_macro_core_vote(void *handle, bool enable);
- static int wsa_macro_hw_params(struct snd_pcm_substream *substream,
- struct snd_pcm_hw_params *params,
- struct snd_soc_dai *dai);
- static int wsa_macro_get_channel_map(struct snd_soc_dai *dai,
- unsigned int *tx_num, unsigned int *tx_slot,
- unsigned int *rx_num, unsigned int *rx_slot);
- static int wsa_macro_mute_stream(struct snd_soc_dai *dai, int mute, int stream);
- /* Hold instance to soundwire platform device */
- struct wsa_macro_swr_ctrl_data {
- struct platform_device *wsa_swr_pdev;
- };
- struct wsa_macro_swr_ctrl_platform_data {
- void *handle; /* holds codec private data */
- int (*read)(void *handle, int reg);
- int (*write)(void *handle, int reg, int val);
- int (*bulk_write)(void *handle, u32 *reg, u32 *val, size_t len);
- int (*clk)(void *handle, bool enable);
- int (*core_vote)(void *handle, bool enable);
- int (*handle_irq)(void *handle,
- irqreturn_t (*swrm_irq_handler)(int irq,
- void *data),
- void *swrm_handle,
- int action);
- };
- struct wsa_macro_bcl_pmic_params {
- u8 id;
- u8 sid;
- u8 ppid;
- };
- enum {
- WSA_MACRO_AIF_INVALID = 0,
- WSA_MACRO_AIF1_PB,
- WSA_MACRO_AIF_MIX1_PB,
- WSA_MACRO_AIF_VI,
- WSA_MACRO_AIF_ECHO,
- WSA_MACRO_MAX_DAIS,
- };
- #define WSA_MACRO_CHILD_DEVICES_MAX 3
- /*
- * @dev: wsa macro device pointer
- * @comp_enabled: compander enable mixer value set
- * @ec_hq: echo HQ enable mixer value set
- * @prim_int_users: Users of interpolator
- * @wsa_mclk_users: WSA MCLK users count
- * @swr_clk_users: SWR clk users count
- * @vi_feed_value: VI sense mask
- * @mclk_lock: to lock mclk operations
- * @swr_clk_lock: to lock swr master clock operations
- * @swr_ctrl_data: SoundWire data structure
- * @swr_plat_data: Soundwire platform data
- * @wsa_macro_add_child_devices_work: work for adding child devices
- * @wsa_swr_gpio_p: used by pinctrl API
- * @component: codec handle
- * @rx_0_count: RX0 interpolation users
- * @rx_1_count: RX1 interpolation users
- * @active_ch_mask: channel mask for all AIF DAIs
- * @rx_port_value: mixer ctl value of WSA RX MUXes
- * @wsa_io_base: Base address of WSA macro addr space
- */
- struct wsa_macro_priv {
- struct device *dev;
- int comp_enabled[WSA_MACRO_COMP_MAX];
- int ec_hq[WSA_MACRO_RX1 + 1];
- u16 prim_int_users[WSA_MACRO_RX1 + 1];
- u16 wsa_mclk_users;
- u16 swr_clk_users;
- bool dapm_mclk_enable;
- bool reset_swr;
- unsigned int vi_feed_value;
- struct mutex mclk_lock;
- struct mutex swr_clk_lock;
- struct wsa_macro_swr_ctrl_data *swr_ctrl_data;
- struct wsa_macro_swr_ctrl_platform_data swr_plat_data;
- struct work_struct wsa_macro_add_child_devices_work;
- struct device_node *wsa_swr_gpio_p;
- struct snd_soc_component *component;
- int rx_0_count;
- int rx_1_count;
- unsigned long active_ch_mask[WSA_MACRO_MAX_DAIS];
- int rx_port_value[WSA_MACRO_RX_MAX];
- char __iomem *wsa_io_base;
- struct platform_device *pdev_child_devices
- [WSA_MACRO_CHILD_DEVICES_MAX];
- int child_count;
- int ear_spkr_gain;
- int wsa_spkrrecv;
- int spkr_gain_offset;
- int spkr_mode;
- int is_softclip_on[WSA_MACRO_SOFTCLIP_MAX];
- int softclip_clk_users[WSA_MACRO_SOFTCLIP_MAX];
- struct wsa_macro_bcl_pmic_params bcl_pmic_params;
- char __iomem *mclk_mode_muxsel;
- u16 default_clk_id;
- u32 pcm_rate_vi;
- int wsa_digital_mute_status[WSA_MACRO_RX_MAX];
- };
- static int wsa_macro_config_ear_spkr_gain(struct snd_soc_component *component,
- struct wsa_macro_priv *wsa_priv,
- int event, int gain_reg);
- static struct snd_soc_dai_driver wsa_macro_dai[];
- static const DECLARE_TLV_DB_SCALE(digital_gain, 0, 1, 0);
- static const char *const rx_text[] = {
- "ZERO", "RX0", "RX1", "RX_MIX0", "RX_MIX1", "DEC0", "DEC1"
- };
- static const char *const rx_mix_text[] = {
- "ZERO", "RX0", "RX1", "RX_MIX0", "RX_MIX1"
- };
- static const char *const rx_mix_ec_text[] = {
- "ZERO", "RX_MIX_TX0", "RX_MIX_TX1"
- };
- static const char *const rx_mux_text[] = {
- "ZERO", "AIF1_PB", "AIF_MIX1_PB"
- };
- static const char *const rx_sidetone_mix_text[] = {
- "ZERO", "SRC0"
- };
- static const char * const wsa_macro_ear_spkr_pa_gain_text[] = {
- "G_DEFAULT", "G_0_DB", "G_1_DB", "G_2_DB", "G_3_DB",
- "G_4_DB", "G_5_DB", "G_6_DB"
- };
- static const char * const wsa_macro_speaker_boost_stage_text[] = {
- "NO_MAX_STATE", "MAX_STATE_1", "MAX_STATE_2"
- };
- static const char * const wsa_macro_vbat_bcl_gsm_mode_text[] = {
- "OFF", "ON"
- };
- static const struct snd_kcontrol_new wsa_int0_vbat_mix_switch[] = {
- SOC_DAPM_SINGLE("WSA RX0 VBAT Enable", SND_SOC_NOPM, 0, 1, 0)
- };
- static const struct snd_kcontrol_new wsa_int1_vbat_mix_switch[] = {
- SOC_DAPM_SINGLE("WSA RX1 VBAT Enable", SND_SOC_NOPM, 0, 1, 0)
- };
- static const char *const wsa_macro_ear_spkrrecv_text[] = {
- "OFF", "ON"
- };
- static SOC_ENUM_SINGLE_EXT_DECL(wsa_macro_ear_spkrrecv_enum,
- wsa_macro_ear_spkrrecv_text);
- static SOC_ENUM_SINGLE_EXT_DECL(wsa_macro_ear_spkr_pa_gain_enum,
- wsa_macro_ear_spkr_pa_gain_text);
- static SOC_ENUM_SINGLE_EXT_DECL(wsa_macro_spkr_boost_stage_enum,
- wsa_macro_speaker_boost_stage_text);
- static SOC_ENUM_SINGLE_EXT_DECL(wsa_macro_vbat_bcl_gsm_mode_enum,
- wsa_macro_vbat_bcl_gsm_mode_text);
- /* RX INT0 */
- static const struct soc_enum rx0_prim_inp0_chain_enum =
- SOC_ENUM_SINGLE(BOLERO_CDC_WSA_RX_INP_MUX_RX_INT0_CFG0,
- 0, 7, rx_text);
- static const struct soc_enum rx0_prim_inp1_chain_enum =
- SOC_ENUM_SINGLE(BOLERO_CDC_WSA_RX_INP_MUX_RX_INT0_CFG0,
- 3, 7, rx_text);
- static const struct soc_enum rx0_prim_inp2_chain_enum =
- SOC_ENUM_SINGLE(BOLERO_CDC_WSA_RX_INP_MUX_RX_INT0_CFG1,
- 3, 7, rx_text);
- static const struct soc_enum rx0_mix_chain_enum =
- SOC_ENUM_SINGLE(BOLERO_CDC_WSA_RX_INP_MUX_RX_INT0_CFG1,
- 0, 5, rx_mix_text);
- static const struct soc_enum rx0_sidetone_mix_enum =
- SOC_ENUM_SINGLE(SND_SOC_NOPM, 0, 2, rx_sidetone_mix_text);
- static const struct snd_kcontrol_new rx0_prim_inp0_mux =
- SOC_DAPM_ENUM("WSA_RX0 INP0 Mux", rx0_prim_inp0_chain_enum);
- static const struct snd_kcontrol_new rx0_prim_inp1_mux =
- SOC_DAPM_ENUM("WSA_RX0 INP1 Mux", rx0_prim_inp1_chain_enum);
- static const struct snd_kcontrol_new rx0_prim_inp2_mux =
- SOC_DAPM_ENUM("WSA_RX0 INP2 Mux", rx0_prim_inp2_chain_enum);
- static const struct snd_kcontrol_new rx0_mix_mux =
- SOC_DAPM_ENUM("WSA_RX0 MIX Mux", rx0_mix_chain_enum);
- static const struct snd_kcontrol_new rx0_sidetone_mix_mux =
- SOC_DAPM_ENUM("WSA_RX0 SIDETONE MIX Mux", rx0_sidetone_mix_enum);
- /* RX INT1 */
- static const struct soc_enum rx1_prim_inp0_chain_enum =
- SOC_ENUM_SINGLE(BOLERO_CDC_WSA_RX_INP_MUX_RX_INT1_CFG0,
- 0, 7, rx_text);
- static const struct soc_enum rx1_prim_inp1_chain_enum =
- SOC_ENUM_SINGLE(BOLERO_CDC_WSA_RX_INP_MUX_RX_INT1_CFG0,
- 3, 7, rx_text);
- static const struct soc_enum rx1_prim_inp2_chain_enum =
- SOC_ENUM_SINGLE(BOLERO_CDC_WSA_RX_INP_MUX_RX_INT1_CFG1,
- 3, 7, rx_text);
- static const struct soc_enum rx1_mix_chain_enum =
- SOC_ENUM_SINGLE(BOLERO_CDC_WSA_RX_INP_MUX_RX_INT1_CFG1,
- 0, 5, rx_mix_text);
- static const struct snd_kcontrol_new rx1_prim_inp0_mux =
- SOC_DAPM_ENUM("WSA_RX1 INP0 Mux", rx1_prim_inp0_chain_enum);
- static const struct snd_kcontrol_new rx1_prim_inp1_mux =
- SOC_DAPM_ENUM("WSA_RX1 INP1 Mux", rx1_prim_inp1_chain_enum);
- static const struct snd_kcontrol_new rx1_prim_inp2_mux =
- SOC_DAPM_ENUM("WSA_RX1 INP2 Mux", rx1_prim_inp2_chain_enum);
- static const struct snd_kcontrol_new rx1_mix_mux =
- SOC_DAPM_ENUM("WSA_RX1 MIX Mux", rx1_mix_chain_enum);
- static const struct soc_enum rx_mix_ec0_enum =
- SOC_ENUM_SINGLE(BOLERO_CDC_WSA_RX_INP_MUX_RX_MIX_CFG0,
- 0, 3, rx_mix_ec_text);
- static const struct soc_enum rx_mix_ec1_enum =
- SOC_ENUM_SINGLE(BOLERO_CDC_WSA_RX_INP_MUX_RX_MIX_CFG0,
- 3, 3, rx_mix_ec_text);
- static const struct snd_kcontrol_new rx_mix_ec0_mux =
- SOC_DAPM_ENUM("WSA RX_MIX EC0_Mux", rx_mix_ec0_enum);
- static const struct snd_kcontrol_new rx_mix_ec1_mux =
- SOC_DAPM_ENUM("WSA RX_MIX EC1_Mux", rx_mix_ec1_enum);
- static struct snd_soc_dai_ops wsa_macro_dai_ops = {
- .hw_params = wsa_macro_hw_params,
- .get_channel_map = wsa_macro_get_channel_map,
- .mute_stream = wsa_macro_mute_stream,
- };
- static struct snd_soc_dai_driver wsa_macro_dai[] = {
- {
- .name = "wsa_macro_rx1",
- .id = WSA_MACRO_AIF1_PB,
- .playback = {
- .stream_name = "WSA_AIF1 Playback",
- .rates = WSA_MACRO_RX_RATES,
- .formats = WSA_MACRO_RX_FORMATS,
- .rate_max = 384000,
- .rate_min = 8000,
- .channels_min = 1,
- .channels_max = 2,
- },
- .ops = &wsa_macro_dai_ops,
- },
- {
- .name = "wsa_macro_rx_mix",
- .id = WSA_MACRO_AIF_MIX1_PB,
- .playback = {
- .stream_name = "WSA_AIF_MIX1 Playback",
- .rates = WSA_MACRO_RX_MIX_RATES,
- .formats = WSA_MACRO_RX_FORMATS,
- .rate_max = 192000,
- .rate_min = 48000,
- .channels_min = 1,
- .channels_max = 2,
- },
- .ops = &wsa_macro_dai_ops,
- },
- {
- .name = "wsa_macro_vifeedback",
- .id = WSA_MACRO_AIF_VI,
- .capture = {
- .stream_name = "WSA_AIF_VI Capture",
- .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_48000,
- .formats = WSA_MACRO_RX_FORMATS,
- .rate_max = 48000,
- .rate_min = 8000,
- .channels_min = 1,
- .channels_max = 4,
- },
- .ops = &wsa_macro_dai_ops,
- },
- {
- .name = "wsa_macro_echo",
- .id = WSA_MACRO_AIF_ECHO,
- .capture = {
- .stream_name = "WSA_AIF_ECHO Capture",
- .rates = WSA_MACRO_ECHO_RATES,
- .formats = WSA_MACRO_ECHO_FORMATS,
- .rate_max = 48000,
- .rate_min = 8000,
- .channels_min = 1,
- .channels_max = 2,
- },
- .ops = &wsa_macro_dai_ops,
- },
- };
- static const struct wsa_macro_reg_mask_val wsa_macro_spkr_default[] = {
- {BOLERO_CDC_WSA_COMPANDER0_CTL3, 0x80, 0x80},
- {BOLERO_CDC_WSA_COMPANDER1_CTL3, 0x80, 0x80},
- {BOLERO_CDC_WSA_COMPANDER0_CTL7, 0x01, 0x01},
- {BOLERO_CDC_WSA_COMPANDER1_CTL7, 0x01, 0x01},
- {BOLERO_CDC_WSA_BOOST0_BOOST_CTL, 0x7C, 0x58},
- {BOLERO_CDC_WSA_BOOST1_BOOST_CTL, 0x7C, 0x58},
- };
- static const struct wsa_macro_reg_mask_val wsa_macro_spkr_mode1[] = {
- {BOLERO_CDC_WSA_COMPANDER0_CTL3, 0x80, 0x00},
- {BOLERO_CDC_WSA_COMPANDER1_CTL3, 0x80, 0x00},
- {BOLERO_CDC_WSA_COMPANDER0_CTL7, 0x01, 0x00},
- {BOLERO_CDC_WSA_COMPANDER1_CTL7, 0x01, 0x00},
- {BOLERO_CDC_WSA_BOOST0_BOOST_CTL, 0x7C, 0x44},
- {BOLERO_CDC_WSA_BOOST1_BOOST_CTL, 0x7C, 0x44},
- };
- static bool wsa_macro_get_data(struct snd_soc_component *component,
- struct device **wsa_dev,
- struct wsa_macro_priv **wsa_priv,
- const char *func_name)
- {
- *wsa_dev = bolero_get_device_ptr(component->dev, WSA_MACRO);
- if (!(*wsa_dev)) {
- dev_err(component->dev,
- "%s: null device for macro!\n", func_name);
- return false;
- }
- *wsa_priv = dev_get_drvdata((*wsa_dev));
- if (!(*wsa_priv) || !(*wsa_priv)->component) {
- dev_err(component->dev,
- "%s: priv is null for macro!\n", func_name);
- return false;
- }
- return true;
- }
- static int wsa_macro_set_port_map(struct snd_soc_component *component,
- u32 usecase, u32 size, void *data)
- {
- struct device *wsa_dev = NULL;
- struct wsa_macro_priv *wsa_priv = NULL;
- struct swrm_port_config port_cfg;
- int ret = 0;
- if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
- return -EINVAL;
- memset(&port_cfg, 0, sizeof(port_cfg));
- port_cfg.uc = usecase;
- port_cfg.size = size;
- port_cfg.params = data;
- if (wsa_priv->swr_ctrl_data)
- ret = swrm_wcd_notify(
- wsa_priv->swr_ctrl_data[0].wsa_swr_pdev,
- SWR_SET_PORT_MAP, &port_cfg);
- return ret;
- }
- /**
- * wsa_macro_set_spkr_gain_offset - offset the speaker path
- * gain with the given offset value.
- *
- * @component: codec instance
- * @offset: Indicates speaker path gain offset value.
- *
- * Returns 0 on success or -EINVAL on error.
- */
- int wsa_macro_set_spkr_gain_offset(struct snd_soc_component *component,
- int offset)
- {
- struct device *wsa_dev = NULL;
- struct wsa_macro_priv *wsa_priv = NULL;
- if (!component) {
- pr_err("%s: NULL component pointer!\n", __func__);
- return -EINVAL;
- }
- if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
- return -EINVAL;
- wsa_priv->spkr_gain_offset = offset;
- return 0;
- }
- EXPORT_SYMBOL(wsa_macro_set_spkr_gain_offset);
- /**
- * wsa_macro_set_spkr_mode - Configures speaker compander and smartboost
- * settings based on speaker mode.
- *
- * @component: codec instance
- * @mode: Indicates speaker configuration mode.
- *
- * Returns 0 on success or -EINVAL on error.
- */
- int wsa_macro_set_spkr_mode(struct snd_soc_component *component, int mode)
- {
- int i;
- const struct wsa_macro_reg_mask_val *regs;
- int size;
- struct device *wsa_dev = NULL;
- struct wsa_macro_priv *wsa_priv = NULL;
- if (!component) {
- pr_err("%s: NULL codec pointer!\n", __func__);
- return -EINVAL;
- }
- if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
- return -EINVAL;
- switch (mode) {
- case WSA_MACRO_SPKR_MODE_1:
- regs = wsa_macro_spkr_mode1;
- size = ARRAY_SIZE(wsa_macro_spkr_mode1);
- break;
- default:
- regs = wsa_macro_spkr_default;
- size = ARRAY_SIZE(wsa_macro_spkr_default);
- break;
- }
- wsa_priv->spkr_mode = mode;
- for (i = 0; i < size; i++)
- snd_soc_component_update_bits(component, regs[i].reg,
- regs[i].mask, regs[i].val);
- return 0;
- }
- EXPORT_SYMBOL(wsa_macro_set_spkr_mode);
- static int wsa_macro_set_prim_interpolator_rate(struct snd_soc_dai *dai,
- u8 int_prim_fs_rate_reg_val,
- u32 sample_rate)
- {
- u8 int_1_mix1_inp;
- u32 j, port;
- u16 int_mux_cfg0, int_mux_cfg1;
- u16 int_fs_reg;
- u8 int_mux_cfg0_val, int_mux_cfg1_val;
- u8 inp0_sel, inp1_sel, inp2_sel;
- struct snd_soc_component *component = dai->component;
- struct device *wsa_dev = NULL;
- struct wsa_macro_priv *wsa_priv = NULL;
- if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
- return -EINVAL;
- for_each_set_bit(port, &wsa_priv->active_ch_mask[dai->id],
- WSA_MACRO_RX_MAX) {
- int_1_mix1_inp = port;
- if ((int_1_mix1_inp < WSA_MACRO_RX0) ||
- (int_1_mix1_inp > WSA_MACRO_RX_MIX1)) {
- dev_err(wsa_dev,
- "%s: Invalid RX port, Dai ID is %d\n",
- __func__, dai->id);
- return -EINVAL;
- }
- int_mux_cfg0 = BOLERO_CDC_WSA_RX_INP_MUX_RX_INT0_CFG0;
- /*
- * Loop through all interpolator MUX inputs and find out
- * to which interpolator input, the cdc_dma rx port
- * is connected
- */
- for (j = 0; j < NUM_INTERPOLATORS; j++) {
- int_mux_cfg1 = int_mux_cfg0 + WSA_MACRO_MUX_CFG1_OFFSET;
- int_mux_cfg0_val = snd_soc_component_read(component,
- int_mux_cfg0);
- int_mux_cfg1_val = snd_soc_component_read(component,
- int_mux_cfg1);
- inp0_sel = int_mux_cfg0_val & WSA_MACRO_MUX_INP_MASK1;
- inp1_sel = (int_mux_cfg0_val >>
- WSA_MACRO_MUX_INP_SHFT) &
- WSA_MACRO_MUX_INP_MASK1;
- inp2_sel = (int_mux_cfg1_val >>
- WSA_MACRO_MUX_INP_SHFT) &
- WSA_MACRO_MUX_INP_MASK1;
- if ((inp0_sel == int_1_mix1_inp + INTn_1_INP_SEL_RX0) ||
- (inp1_sel == int_1_mix1_inp + INTn_1_INP_SEL_RX0) ||
- (inp2_sel == int_1_mix1_inp + INTn_1_INP_SEL_RX0)) {
- int_fs_reg = BOLERO_CDC_WSA_RX0_RX_PATH_CTL +
- WSA_MACRO_RX_PATH_OFFSET * j;
- dev_dbg(wsa_dev,
- "%s: AIF_PB DAI(%d) connected to INT%u_1\n",
- __func__, dai->id, j);
- dev_dbg(wsa_dev,
- "%s: set INT%u_1 sample rate to %u\n",
- __func__, j, sample_rate);
- /* sample_rate is in Hz */
- snd_soc_component_update_bits(component,
- int_fs_reg,
- WSA_MACRO_FS_RATE_MASK,
- int_prim_fs_rate_reg_val);
- }
- int_mux_cfg0 += WSA_MACRO_MUX_CFG_OFFSET;
- }
- }
- return 0;
- }
- static int wsa_macro_set_mix_interpolator_rate(struct snd_soc_dai *dai,
- u8 int_mix_fs_rate_reg_val,
- u32 sample_rate)
- {
- u8 int_2_inp;
- u32 j, port;
- u16 int_mux_cfg1, int_fs_reg;
- u8 int_mux_cfg1_val;
- struct snd_soc_component *component = dai->component;
- struct device *wsa_dev = NULL;
- struct wsa_macro_priv *wsa_priv = NULL;
- if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
- return -EINVAL;
- for_each_set_bit(port, &wsa_priv->active_ch_mask[dai->id],
- WSA_MACRO_RX_MAX) {
- int_2_inp = port;
- if ((int_2_inp < WSA_MACRO_RX0) ||
- (int_2_inp > WSA_MACRO_RX_MIX1)) {
- dev_err(wsa_dev,
- "%s: Invalid RX port, Dai ID is %d\n",
- __func__, dai->id);
- return -EINVAL;
- }
- int_mux_cfg1 = BOLERO_CDC_WSA_RX_INP_MUX_RX_INT0_CFG1;
- for (j = 0; j < NUM_INTERPOLATORS; j++) {
- int_mux_cfg1_val = snd_soc_component_read(component,
- int_mux_cfg1) &
- WSA_MACRO_MUX_INP_MASK1;
- if (int_mux_cfg1_val == int_2_inp +
- INTn_2_INP_SEL_RX0) {
- int_fs_reg =
- BOLERO_CDC_WSA_RX0_RX_PATH_MIX_CTL +
- WSA_MACRO_RX_PATH_OFFSET * j;
- dev_dbg(wsa_dev,
- "%s: AIF_PB DAI(%d) connected to INT%u_2\n",
- __func__, dai->id, j);
- dev_dbg(wsa_dev,
- "%s: set INT%u_2 sample rate to %u\n",
- __func__, j, sample_rate);
- snd_soc_component_update_bits(component,
- int_fs_reg,
- WSA_MACRO_FS_RATE_MASK,
- int_mix_fs_rate_reg_val);
- }
- int_mux_cfg1 += WSA_MACRO_MUX_CFG_OFFSET;
- }
- }
- return 0;
- }
- static int wsa_macro_set_interpolator_rate(struct snd_soc_dai *dai,
- u32 sample_rate)
- {
- int rate_val = 0;
- int i, ret;
- /* set mixing path rate */
- for (i = 0; i < ARRAY_SIZE(int_mix_sample_rate_val); i++) {
- if (sample_rate ==
- int_mix_sample_rate_val[i].sample_rate) {
- rate_val =
- int_mix_sample_rate_val[i].rate_val;
- break;
- }
- }
- if ((i == ARRAY_SIZE(int_mix_sample_rate_val)) ||
- (rate_val < 0))
- goto prim_rate;
- ret = wsa_macro_set_mix_interpolator_rate(dai,
- (u8) rate_val, sample_rate);
- prim_rate:
- /* set primary path sample rate */
- for (i = 0; i < ARRAY_SIZE(int_prim_sample_rate_val); i++) {
- if (sample_rate ==
- int_prim_sample_rate_val[i].sample_rate) {
- rate_val =
- int_prim_sample_rate_val[i].rate_val;
- break;
- }
- }
- if ((i == ARRAY_SIZE(int_prim_sample_rate_val)) ||
- (rate_val < 0))
- return -EINVAL;
- ret = wsa_macro_set_prim_interpolator_rate(dai,
- (u8) rate_val, sample_rate);
- return ret;
- }
- static int wsa_macro_hw_params(struct snd_pcm_substream *substream,
- struct snd_pcm_hw_params *params,
- struct snd_soc_dai *dai)
- {
- struct snd_soc_component *component = dai->component;
- int ret;
- struct device *wsa_dev = NULL;
- struct wsa_macro_priv *wsa_priv = NULL;
- if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
- return -EINVAL;
- wsa_priv = dev_get_drvdata(wsa_dev);
- if (!wsa_priv)
- return -EINVAL;
- dev_dbg(component->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 (substream->stream) {
- case SNDRV_PCM_STREAM_PLAYBACK:
- ret = wsa_macro_set_interpolator_rate(dai, params_rate(params));
- if (ret) {
- dev_err(component->dev,
- "%s: cannot set sample rate: %u\n",
- __func__, params_rate(params));
- return ret;
- }
- break;
- case SNDRV_PCM_STREAM_CAPTURE:
- if (dai->id == WSA_MACRO_AIF_VI)
- wsa_priv->pcm_rate_vi = params_rate(params);
- default:
- break;
- }
- return 0;
- }
- static int wsa_macro_get_channel_map(struct snd_soc_dai *dai,
- unsigned int *tx_num, unsigned int *tx_slot,
- unsigned int *rx_num, unsigned int *rx_slot)
- {
- struct snd_soc_component *component = dai->component;
- struct device *wsa_dev = NULL;
- struct wsa_macro_priv *wsa_priv = NULL;
- u16 val = 0, mask = 0, cnt = 0, temp = 0;
- if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
- return -EINVAL;
- wsa_priv = dev_get_drvdata(wsa_dev);
- if (!wsa_priv)
- return -EINVAL;
- switch (dai->id) {
- case WSA_MACRO_AIF_VI:
- *tx_slot = wsa_priv->active_ch_mask[dai->id];
- *tx_num = hweight_long(wsa_priv->active_ch_mask[dai->id]);
- break;
- case WSA_MACRO_AIF1_PB:
- case WSA_MACRO_AIF_MIX1_PB:
- for_each_set_bit(temp, &wsa_priv->active_ch_mask[dai->id],
- WSA_MACRO_RX_MAX) {
- mask |= (1 << temp);
- if (++cnt == WSA_MACRO_MAX_DMA_CH_PER_PORT)
- break;
- }
- if (mask & 0x0C)
- mask = mask >> 0x2;
- *rx_slot = mask;
- *rx_num = cnt;
- break;
- case WSA_MACRO_AIF_ECHO:
- val = snd_soc_component_read(component,
- BOLERO_CDC_WSA_RX_INP_MUX_RX_MIX_CFG0);
- if (val & WSA_MACRO_EC_MIX_TX1_MASK) {
- mask |= 0x2;
- cnt++;
- }
- if (val & WSA_MACRO_EC_MIX_TX0_MASK) {
- mask |= 0x1;
- cnt++;
- }
- *tx_slot = mask;
- *tx_num = cnt;
- break;
- default:
- dev_err(wsa_dev, "%s: Invalid AIF\n", __func__);
- break;
- }
- return 0;
- }
- static int wsa_macro_mute_stream(struct snd_soc_dai *dai, int mute, int stream)
- {
- struct snd_soc_component *component = dai->component;
- struct device *wsa_dev = NULL;
- struct wsa_macro_priv *wsa_priv = NULL;
- uint16_t j = 0, reg = 0, mix_reg = 0, dsm_reg = 0;
- u16 int_mux_cfg0 = 0, int_mux_cfg1 = 0;
- u8 int_mux_cfg0_val = 0, int_mux_cfg1_val = 0;
- bool adie_lb = false;
- if (mute)
- return 0;
- if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
- return -EINVAL;
- switch (dai->id) {
- case WSA_MACRO_AIF1_PB:
- case WSA_MACRO_AIF_MIX1_PB:
- for (j = 0; j < NUM_INTERPOLATORS; j++) {
- reg = BOLERO_CDC_WSA_RX0_RX_PATH_CTL +
- (j * WSA_MACRO_RX_PATH_OFFSET);
- mix_reg = BOLERO_CDC_WSA_RX0_RX_PATH_MIX_CTL +
- (j * WSA_MACRO_RX_PATH_OFFSET);
- dsm_reg = BOLERO_CDC_WSA_RX0_RX_PATH_CTL +
- (j * WSA_MACRO_RX_PATH_OFFSET) +
- WSA_MACRO_RX_PATH_DSMDEM_OFFSET;
- int_mux_cfg0 = BOLERO_CDC_WSA_RX_INP_MUX_RX_INT0_CFG0 + j * 8;
- int_mux_cfg1 = int_mux_cfg0 + 4;
- int_mux_cfg0_val = snd_soc_component_read(component,
- int_mux_cfg0);
- int_mux_cfg1_val = snd_soc_component_read(component,
- int_mux_cfg1);
- if (snd_soc_component_read(component, dsm_reg) & 0x01) {
- if (int_mux_cfg0_val || (int_mux_cfg1_val & 0x38))
- snd_soc_component_update_bits(component, reg,
- 0x20, 0x20);
- if (int_mux_cfg1_val & 0x07) {
- snd_soc_component_update_bits(component, reg,
- 0x20, 0x20);
- snd_soc_component_update_bits(component,
- mix_reg, 0x20, 0x20);
- }
- }
- }
- bolero_wsa_pa_on(wsa_dev, adie_lb);
- break;
- default:
- break;
- }
- return 0;
- }
- static int wsa_macro_mclk_enable(struct wsa_macro_priv *wsa_priv,
- bool mclk_enable, bool dapm)
- {
- struct regmap *regmap = dev_get_regmap(wsa_priv->dev->parent, NULL);
- int ret = 0;
- if (regmap == NULL) {
- dev_err(wsa_priv->dev, "%s: regmap is NULL\n", __func__);
- return -EINVAL;
- }
- dev_dbg(wsa_priv->dev, "%s: mclk_enable = %u, dapm = %d clk_users= %d\n",
- __func__, mclk_enable, dapm, wsa_priv->wsa_mclk_users);
- mutex_lock(&wsa_priv->mclk_lock);
- if (mclk_enable) {
- if (wsa_priv->wsa_mclk_users == 0) {
- ret = bolero_clk_rsc_request_clock(wsa_priv->dev,
- wsa_priv->default_clk_id,
- wsa_priv->default_clk_id,
- true);
- if (ret < 0) {
- dev_err_ratelimited(wsa_priv->dev,
- "%s: wsa request clock enable failed\n",
- __func__);
- goto exit;
- }
- bolero_clk_rsc_fs_gen_request(wsa_priv->dev,
- true);
- regcache_mark_dirty(regmap);
- regcache_sync_region(regmap,
- WSA_START_OFFSET,
- WSA_MAX_OFFSET);
- /* 9.6MHz MCLK, set value 0x00 if other frequency */
- regmap_update_bits(regmap,
- BOLERO_CDC_WSA_TOP_FREQ_MCLK, 0x01, 0x01);
- regmap_update_bits(regmap,
- BOLERO_CDC_WSA_CLK_RST_CTRL_MCLK_CONTROL,
- 0x01, 0x01);
- regmap_update_bits(regmap,
- BOLERO_CDC_WSA_CLK_RST_CTRL_FS_CNT_CONTROL,
- 0x01, 0x01);
- }
- wsa_priv->wsa_mclk_users++;
- } else {
- if (wsa_priv->wsa_mclk_users <= 0) {
- dev_err(wsa_priv->dev, "%s: clock already disabled\n",
- __func__);
- wsa_priv->wsa_mclk_users = 0;
- goto exit;
- }
- wsa_priv->wsa_mclk_users--;
- if (wsa_priv->wsa_mclk_users == 0) {
- regmap_update_bits(regmap,
- BOLERO_CDC_WSA_CLK_RST_CTRL_FS_CNT_CONTROL,
- 0x01, 0x00);
- regmap_update_bits(regmap,
- BOLERO_CDC_WSA_CLK_RST_CTRL_MCLK_CONTROL,
- 0x01, 0x00);
- bolero_clk_rsc_fs_gen_request(wsa_priv->dev,
- false);
- bolero_clk_rsc_request_clock(wsa_priv->dev,
- wsa_priv->default_clk_id,
- wsa_priv->default_clk_id,
- false);
- }
- }
- exit:
- mutex_unlock(&wsa_priv->mclk_lock);
- return ret;
- }
- static int wsa_macro_mclk_event(struct snd_soc_dapm_widget *w,
- struct snd_kcontrol *kcontrol, int event)
- {
- struct snd_soc_component *component =
- snd_soc_dapm_to_component(w->dapm);
- int ret = 0;
- struct device *wsa_dev = NULL;
- struct wsa_macro_priv *wsa_priv = NULL;
- if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
- return -EINVAL;
- dev_dbg(wsa_dev, "%s: event = %d\n", __func__, event);
- switch (event) {
- case SND_SOC_DAPM_PRE_PMU:
- ret = wsa_macro_mclk_enable(wsa_priv, 1, true);
- if (ret)
- wsa_priv->dapm_mclk_enable = false;
- else
- wsa_priv->dapm_mclk_enable = true;
- break;
- case SND_SOC_DAPM_POST_PMD:
- if (wsa_priv->dapm_mclk_enable)
- wsa_macro_mclk_enable(wsa_priv, 0, true);
- break;
- default:
- dev_err(wsa_priv->dev,
- "%s: invalid DAPM event %d\n", __func__, event);
- ret = -EINVAL;
- }
- return ret;
- }
- static int wsa_macro_event_handler(struct snd_soc_component *component,
- u16 event, u32 data)
- {
- struct device *wsa_dev = NULL;
- struct wsa_macro_priv *wsa_priv = NULL;
- int ret = 0;
- if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
- return -EINVAL;
- switch (event) {
- case BOLERO_MACRO_EVT_SSR_DOWN:
- if (wsa_priv->swr_ctrl_data) {
- swrm_wcd_notify(
- wsa_priv->swr_ctrl_data[0].wsa_swr_pdev,
- SWR_DEVICE_SSR_DOWN, NULL);
- }
- if ((!pm_runtime_enabled(wsa_dev) ||
- !pm_runtime_suspended(wsa_dev))) {
- ret = bolero_runtime_suspend(wsa_dev);
- if (!ret) {
- pm_runtime_disable(wsa_dev);
- pm_runtime_set_suspended(wsa_dev);
- pm_runtime_enable(wsa_dev);
- }
- }
- break;
- case BOLERO_MACRO_EVT_PRE_SSR_UP:
- /* enable&disable WSA_CORE_CLK to reset GFMUX reg */
- wsa_macro_core_vote(wsa_priv, true);
- ret = bolero_clk_rsc_request_clock(wsa_priv->dev,
- wsa_priv->default_clk_id,
- WSA_CORE_CLK, true);
- if (ret < 0)
- dev_err_ratelimited(wsa_priv->dev,
- "%s, failed to enable clk, ret:%d\n",
- __func__, ret);
- else
- bolero_clk_rsc_request_clock(wsa_priv->dev,
- wsa_priv->default_clk_id,
- WSA_CORE_CLK, false);
- wsa_macro_core_vote(wsa_priv, false);
- break;
- case BOLERO_MACRO_EVT_SSR_UP:
- /* reset swr after ssr/pdr */
- wsa_priv->reset_swr = true;
- if (wsa_priv->swr_ctrl_data)
- swrm_wcd_notify(
- wsa_priv->swr_ctrl_data[0].wsa_swr_pdev,
- SWR_DEVICE_SSR_UP, NULL);
- break;
- case BOLERO_MACRO_EVT_CLK_RESET:
- bolero_rsc_clk_reset(wsa_dev, WSA_CORE_CLK);
- break;
- }
- return 0;
- }
- static int wsa_macro_enable_vi_feedback(struct snd_soc_dapm_widget *w,
- struct snd_kcontrol *kcontrol,
- int event)
- {
- struct snd_soc_component *component =
- snd_soc_dapm_to_component(w->dapm);
- struct device *wsa_dev = NULL;
- struct wsa_macro_priv *wsa_priv = NULL;
- u8 val = 0x0;
- if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
- return -EINVAL;
- switch (wsa_priv->pcm_rate_vi) {
- case 48000:
- val = 0x04;
- break;
- case 24000:
- val = 0x02;
- break;
- case 8000:
- default:
- val = 0x00;
- break;
- }
- switch (event) {
- case SND_SOC_DAPM_POST_PMU:
- if (test_bit(WSA_MACRO_TX0,
- &wsa_priv->active_ch_mask[WSA_MACRO_AIF_VI])) {
- dev_dbg(wsa_dev, "%s: spkr1 enabled\n", __func__);
- /* Enable V&I sensing */
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_TX0_SPKR_PROT_PATH_CTL,
- 0x20, 0x20);
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_TX1_SPKR_PROT_PATH_CTL,
- 0x20, 0x20);
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_TX0_SPKR_PROT_PATH_CTL,
- 0x0F, val);
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_TX1_SPKR_PROT_PATH_CTL,
- 0x0F, val);
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_TX0_SPKR_PROT_PATH_CTL,
- 0x10, 0x10);
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_TX1_SPKR_PROT_PATH_CTL,
- 0x10, 0x10);
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_TX0_SPKR_PROT_PATH_CTL,
- 0x20, 0x00);
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_TX1_SPKR_PROT_PATH_CTL,
- 0x20, 0x00);
- }
- if (test_bit(WSA_MACRO_TX1,
- &wsa_priv->active_ch_mask[WSA_MACRO_AIF_VI])) {
- dev_dbg(wsa_dev, "%s: spkr2 enabled\n", __func__);
- /* Enable V&I sensing */
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_TX2_SPKR_PROT_PATH_CTL,
- 0x20, 0x20);
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_TX3_SPKR_PROT_PATH_CTL,
- 0x20, 0x20);
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_TX2_SPKR_PROT_PATH_CTL,
- 0x0F, val);
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_TX3_SPKR_PROT_PATH_CTL,
- 0x0F, val);
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_TX2_SPKR_PROT_PATH_CTL,
- 0x10, 0x10);
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_TX3_SPKR_PROT_PATH_CTL,
- 0x10, 0x10);
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_TX2_SPKR_PROT_PATH_CTL,
- 0x20, 0x00);
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_TX3_SPKR_PROT_PATH_CTL,
- 0x20, 0x00);
- }
- break;
- case SND_SOC_DAPM_POST_PMD:
- if (test_bit(WSA_MACRO_TX0,
- &wsa_priv->active_ch_mask[WSA_MACRO_AIF_VI])) {
- /* Disable V&I sensing */
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_TX0_SPKR_PROT_PATH_CTL,
- 0x20, 0x20);
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_TX1_SPKR_PROT_PATH_CTL,
- 0x20, 0x20);
- dev_dbg(wsa_dev, "%s: spkr1 disabled\n", __func__);
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_TX0_SPKR_PROT_PATH_CTL,
- 0x10, 0x00);
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_TX1_SPKR_PROT_PATH_CTL,
- 0x10, 0x00);
- }
- if (test_bit(WSA_MACRO_TX1,
- &wsa_priv->active_ch_mask[WSA_MACRO_AIF_VI])) {
- /* Disable V&I sensing */
- dev_dbg(wsa_dev, "%s: spkr2 disabled\n", __func__);
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_TX2_SPKR_PROT_PATH_CTL,
- 0x20, 0x20);
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_TX3_SPKR_PROT_PATH_CTL,
- 0x20, 0x20);
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_TX2_SPKR_PROT_PATH_CTL,
- 0x10, 0x00);
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_TX3_SPKR_PROT_PATH_CTL,
- 0x10, 0x00);
- }
- break;
- }
- return 0;
- }
- static void wsa_macro_hd2_control(struct snd_soc_component *component,
- u16 reg, int event)
- {
- u16 hd2_scale_reg;
- u16 hd2_enable_reg = 0;
- if (reg == BOLERO_CDC_WSA_RX0_RX_PATH_CTL) {
- hd2_scale_reg = BOLERO_CDC_WSA_RX0_RX_PATH_SEC3;
- hd2_enable_reg = BOLERO_CDC_WSA_RX0_RX_PATH_CFG0;
- }
- if (reg == BOLERO_CDC_WSA_RX1_RX_PATH_CTL) {
- hd2_scale_reg = BOLERO_CDC_WSA_RX1_RX_PATH_SEC3;
- hd2_enable_reg = BOLERO_CDC_WSA_RX1_RX_PATH_CFG0;
- }
- if (hd2_enable_reg && SND_SOC_DAPM_EVENT_ON(event)) {
- snd_soc_component_update_bits(component, hd2_scale_reg,
- 0x3C, 0x10);
- snd_soc_component_update_bits(component, hd2_scale_reg,
- 0x03, 0x01);
- snd_soc_component_update_bits(component, hd2_enable_reg,
- 0x04, 0x04);
- }
- if (hd2_enable_reg && SND_SOC_DAPM_EVENT_OFF(event)) {
- snd_soc_component_update_bits(component, hd2_enable_reg,
- 0x04, 0x00);
- snd_soc_component_update_bits(component, hd2_scale_reg,
- 0x03, 0x00);
- snd_soc_component_update_bits(component, hd2_scale_reg,
- 0x3C, 0x00);
- }
- }
- static int wsa_macro_enable_swr(struct snd_soc_dapm_widget *w,
- struct snd_kcontrol *kcontrol, int event)
- {
- struct snd_soc_component *component =
- snd_soc_dapm_to_component(w->dapm);
- int ch_cnt;
- struct device *wsa_dev = NULL;
- struct wsa_macro_priv *wsa_priv = NULL;
- if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
- return -EINVAL;
- switch (event) {
- case SND_SOC_DAPM_PRE_PMU:
- if (!(strnstr(w->name, "RX0", sizeof("WSA_RX0"))) &&
- !wsa_priv->rx_0_count)
- wsa_priv->rx_0_count++;
- if (!(strnstr(w->name, "RX1", sizeof("WSA_RX1"))) &&
- !wsa_priv->rx_1_count)
- wsa_priv->rx_1_count++;
- ch_cnt = wsa_priv->rx_0_count + wsa_priv->rx_1_count;
- if (wsa_priv->swr_ctrl_data) {
- swrm_wcd_notify(
- wsa_priv->swr_ctrl_data[0].wsa_swr_pdev,
- SWR_DEVICE_UP, NULL);
- swrm_wcd_notify(
- wsa_priv->swr_ctrl_data[0].wsa_swr_pdev,
- SWR_SET_NUM_RX_CH, &ch_cnt);
- }
- break;
- case SND_SOC_DAPM_POST_PMD:
- if (!(strnstr(w->name, "RX0", sizeof("WSA_RX0"))) &&
- wsa_priv->rx_0_count)
- wsa_priv->rx_0_count--;
- if (!(strnstr(w->name, "RX1", sizeof("WSA_RX1"))) &&
- wsa_priv->rx_1_count)
- wsa_priv->rx_1_count--;
- ch_cnt = wsa_priv->rx_0_count + wsa_priv->rx_1_count;
- if (wsa_priv->swr_ctrl_data)
- swrm_wcd_notify(
- wsa_priv->swr_ctrl_data[0].wsa_swr_pdev,
- SWR_SET_NUM_RX_CH, &ch_cnt);
- break;
- }
- dev_dbg(wsa_priv->dev, "%s: current swr ch cnt: %d\n",
- __func__, wsa_priv->rx_0_count + wsa_priv->rx_1_count);
- return 0;
- }
- static int wsa_macro_enable_mix_path(struct snd_soc_dapm_widget *w,
- struct snd_kcontrol *kcontrol, int event)
- {
- struct snd_soc_component *component =
- snd_soc_dapm_to_component(w->dapm);
- u16 gain_reg;
- int offset_val = 0;
- int val = 0;
- dev_dbg(component->dev, "%s %d %s\n", __func__, event, w->name);
- if (!(strcmp(w->name, "WSA_RX0 MIX INP"))) {
- gain_reg = BOLERO_CDC_WSA_RX0_RX_VOL_MIX_CTL;
- } else if (!(strcmp(w->name, "WSA_RX1 MIX INP"))) {
- gain_reg = BOLERO_CDC_WSA_RX1_RX_VOL_MIX_CTL;
- } else {
- dev_err(component->dev, "%s: No gain register avail for %s\n",
- __func__, w->name);
- return 0;
- }
- switch (event) {
- case SND_SOC_DAPM_PRE_PMU:
- wsa_macro_enable_swr(w, kcontrol, event);
- val = snd_soc_component_read(component, gain_reg);
- val += offset_val;
- snd_soc_component_write(component, gain_reg, val);
- break;
- case SND_SOC_DAPM_POST_PMD:
- snd_soc_component_update_bits(component,
- w->reg, 0x20, 0x00);
- wsa_macro_enable_swr(w, kcontrol, event);
- break;
- }
- return 0;
- }
- static int wsa_macro_config_compander(struct snd_soc_component *component,
- int comp, int event)
- {
- u16 comp_ctl0_reg, rx_path_cfg0_reg;
- struct device *wsa_dev = NULL;
- struct wsa_macro_priv *wsa_priv = NULL;
- if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
- return -EINVAL;
- dev_dbg(component->dev, "%s: event %d compander %d, enabled %d\n",
- __func__, event, comp + 1, wsa_priv->comp_enabled[comp]);
- if (!wsa_priv->comp_enabled[comp])
- return 0;
- comp_ctl0_reg = BOLERO_CDC_WSA_COMPANDER0_CTL0 +
- (comp * WSA_MACRO_RX_COMP_OFFSET);
- rx_path_cfg0_reg = BOLERO_CDC_WSA_RX0_RX_PATH_CFG0 +
- (comp * WSA_MACRO_RX_PATH_OFFSET);
- if (SND_SOC_DAPM_EVENT_ON(event)) {
- /* Enable Compander Clock */
- snd_soc_component_update_bits(component, comp_ctl0_reg,
- 0x01, 0x01);
- snd_soc_component_update_bits(component, comp_ctl0_reg,
- 0x02, 0x02);
- snd_soc_component_update_bits(component, comp_ctl0_reg,
- 0x02, 0x00);
- snd_soc_component_update_bits(component, rx_path_cfg0_reg,
- 0x02, 0x02);
- }
- if (SND_SOC_DAPM_EVENT_OFF(event)) {
- snd_soc_component_update_bits(component, comp_ctl0_reg,
- 0x04, 0x04);
- snd_soc_component_update_bits(component, rx_path_cfg0_reg,
- 0x02, 0x00);
- snd_soc_component_update_bits(component, comp_ctl0_reg,
- 0x02, 0x02);
- snd_soc_component_update_bits(component, comp_ctl0_reg,
- 0x02, 0x00);
- snd_soc_component_update_bits(component, comp_ctl0_reg,
- 0x01, 0x00);
- snd_soc_component_update_bits(component, comp_ctl0_reg,
- 0x04, 0x00);
- }
- return 0;
- }
- static void wsa_macro_enable_softclip_clk(struct snd_soc_component *component,
- struct wsa_macro_priv *wsa_priv,
- int path,
- bool enable)
- {
- u16 softclip_clk_reg = BOLERO_CDC_WSA_SOFTCLIP0_CRC +
- (path * WSA_MACRO_RX_SOFTCLIP_OFFSET);
- u8 softclip_mux_mask = (1 << path);
- u8 softclip_mux_value = (1 << path);
- dev_dbg(component->dev, "%s: path %d, enable %d\n",
- __func__, path, enable);
- if (enable) {
- if (wsa_priv->softclip_clk_users[path] == 0) {
- snd_soc_component_update_bits(component,
- softclip_clk_reg, 0x01, 0x01);
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_RX_INP_MUX_SOFTCLIP_CFG0,
- softclip_mux_mask, softclip_mux_value);
- }
- wsa_priv->softclip_clk_users[path]++;
- } else {
- wsa_priv->softclip_clk_users[path]--;
- if (wsa_priv->softclip_clk_users[path] == 0) {
- snd_soc_component_update_bits(component,
- softclip_clk_reg, 0x01, 0x00);
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_RX_INP_MUX_SOFTCLIP_CFG0,
- softclip_mux_mask, 0x00);
- }
- }
- }
- static int wsa_macro_config_softclip(struct snd_soc_component *component,
- int path, int event)
- {
- u16 softclip_ctrl_reg = 0;
- struct device *wsa_dev = NULL;
- struct wsa_macro_priv *wsa_priv = NULL;
- int softclip_path = 0;
- if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
- return -EINVAL;
- if (path == WSA_MACRO_COMP1)
- softclip_path = WSA_MACRO_SOFTCLIP0;
- else if (path == WSA_MACRO_COMP2)
- softclip_path = WSA_MACRO_SOFTCLIP1;
- dev_dbg(component->dev, "%s: event %d path %d, enabled %d\n",
- __func__, event, softclip_path,
- wsa_priv->is_softclip_on[softclip_path]);
- if (!wsa_priv->is_softclip_on[softclip_path])
- return 0;
- softclip_ctrl_reg = BOLERO_CDC_WSA_SOFTCLIP0_SOFTCLIP_CTRL +
- (softclip_path * WSA_MACRO_RX_SOFTCLIP_OFFSET);
- if (SND_SOC_DAPM_EVENT_ON(event)) {
- /* Enable Softclip clock and mux */
- wsa_macro_enable_softclip_clk(component, wsa_priv,
- softclip_path, true);
- /* Enable Softclip control */
- snd_soc_component_update_bits(component, softclip_ctrl_reg,
- 0x01, 0x01);
- }
- if (SND_SOC_DAPM_EVENT_OFF(event)) {
- snd_soc_component_update_bits(component, softclip_ctrl_reg,
- 0x01, 0x00);
- wsa_macro_enable_softclip_clk(component, wsa_priv,
- softclip_path, false);
- }
- return 0;
- }
- static bool wsa_macro_adie_lb(struct snd_soc_component *component,
- int interp_idx)
- {
- u16 int_mux_cfg0 = 0, int_mux_cfg1 = 0;
- u8 int_mux_cfg0_val = 0, int_mux_cfg1_val = 0;
- u8 int_n_inp0 = 0, int_n_inp1 = 0, int_n_inp2 = 0;
- int_mux_cfg0 = BOLERO_CDC_WSA_RX_INP_MUX_RX_INT0_CFG0 + interp_idx * 8;
- int_mux_cfg1 = int_mux_cfg0 + 4;
- int_mux_cfg0_val = snd_soc_component_read(component, int_mux_cfg0);
- int_mux_cfg1_val = snd_soc_component_read(component, int_mux_cfg1);
- int_n_inp0 = int_mux_cfg0_val & 0x0F;
- if (int_n_inp0 == INTn_1_INP_SEL_DEC0 ||
- int_n_inp0 == INTn_1_INP_SEL_DEC1)
- return true;
- int_n_inp1 = int_mux_cfg0_val >> 4;
- if (int_n_inp1 == INTn_1_INP_SEL_DEC0 ||
- int_n_inp1 == INTn_1_INP_SEL_DEC1)
- return true;
- int_n_inp2 = int_mux_cfg1_val >> 4;
- if (int_n_inp2 == INTn_1_INP_SEL_DEC0 ||
- int_n_inp2 == INTn_1_INP_SEL_DEC1)
- return true;
- return false;
- }
- static int wsa_macro_enable_main_path(struct snd_soc_dapm_widget *w,
- struct snd_kcontrol *kcontrol,
- int event)
- {
- struct snd_soc_component *component =
- snd_soc_dapm_to_component(w->dapm);
- u16 reg = 0;
- struct device *wsa_dev = NULL;
- struct wsa_macro_priv *wsa_priv = NULL;
- bool adie_lb = false;
- if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
- return -EINVAL;
- reg = BOLERO_CDC_WSA_RX0_RX_PATH_CTL +
- WSA_MACRO_RX_PATH_OFFSET * w->shift;
- switch (event) {
- case SND_SOC_DAPM_PRE_PMU:
- if (wsa_macro_adie_lb(component, w->shift)) {
- adie_lb = true;
- snd_soc_component_update_bits(component,
- reg, 0x20, 0x20);
- bolero_wsa_pa_on(wsa_dev, adie_lb);
- }
- break;
- default:
- break;
- }
- return 0;
- }
- static int wsa_macro_interp_get_primary_reg(u16 reg, u16 *ind)
- {
- u16 prim_int_reg = 0;
- switch (reg) {
- case BOLERO_CDC_WSA_RX0_RX_PATH_CTL:
- case BOLERO_CDC_WSA_RX0_RX_PATH_MIX_CTL:
- prim_int_reg = BOLERO_CDC_WSA_RX0_RX_PATH_CTL;
- *ind = 0;
- break;
- case BOLERO_CDC_WSA_RX1_RX_PATH_CTL:
- case BOLERO_CDC_WSA_RX1_RX_PATH_MIX_CTL:
- prim_int_reg = BOLERO_CDC_WSA_RX1_RX_PATH_CTL;
- *ind = 1;
- break;
- }
- return prim_int_reg;
- }
- static int wsa_macro_enable_prim_interpolator(
- struct snd_soc_component *component,
- u16 reg, int event)
- {
- u16 prim_int_reg;
- u16 ind = 0;
- struct device *wsa_dev = NULL;
- struct wsa_macro_priv *wsa_priv = NULL;
- if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
- return -EINVAL;
- prim_int_reg = wsa_macro_interp_get_primary_reg(reg, &ind);
- switch (event) {
- case SND_SOC_DAPM_PRE_PMU:
- wsa_priv->prim_int_users[ind]++;
- if (wsa_priv->prim_int_users[ind] == 1) {
- snd_soc_component_update_bits(component,
- prim_int_reg + WSA_MACRO_RX_PATH_CFG3_OFFSET,
- 0x03, 0x03);
- snd_soc_component_update_bits(component, prim_int_reg,
- 0x10, 0x10);
- wsa_macro_hd2_control(component, prim_int_reg, event);
- snd_soc_component_update_bits(component,
- prim_int_reg + WSA_MACRO_RX_PATH_DSMDEM_OFFSET,
- 0x1, 0x1);
- }
- if ((reg != prim_int_reg) &&
- ((snd_soc_component_read(
- component, prim_int_reg)) & 0x10))
- snd_soc_component_update_bits(component, reg,
- 0x10, 0x10);
- break;
- case SND_SOC_DAPM_POST_PMD:
- wsa_priv->prim_int_users[ind]--;
- if (wsa_priv->prim_int_users[ind] == 0) {
- snd_soc_component_update_bits(component, prim_int_reg,
- 1 << 0x5, 0 << 0x5);
- snd_soc_component_update_bits(component,
- prim_int_reg + WSA_MACRO_RX_PATH_DSMDEM_OFFSET,
- 0x1, 0x0);
- snd_soc_component_update_bits(component, prim_int_reg,
- 0x40, 0x40);
- snd_soc_component_update_bits(component, prim_int_reg,
- 0x40, 0x00);
- wsa_macro_hd2_control(component, prim_int_reg, event);
- }
- break;
- }
- dev_dbg(component->dev, "%s: primary interpolator: INT%d, users: %d\n",
- __func__, ind, wsa_priv->prim_int_users[ind]);
- return 0;
- }
- static int wsa_macro_enable_interpolator(struct snd_soc_dapm_widget *w,
- struct snd_kcontrol *kcontrol,
- int event)
- {
- struct snd_soc_component *component =
- snd_soc_dapm_to_component(w->dapm);
- u16 gain_reg;
- u16 reg;
- int val;
- int offset_val = 0;
- struct device *wsa_dev = NULL;
- struct wsa_macro_priv *wsa_priv = NULL;
- if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
- return -EINVAL;
- dev_dbg(component->dev, "%s %d %s\n", __func__, event, w->name);
- if (!(strcmp(w->name, "WSA_RX INT0 INTERP"))) {
- reg = BOLERO_CDC_WSA_RX0_RX_PATH_CTL;
- gain_reg = BOLERO_CDC_WSA_RX0_RX_VOL_CTL;
- } else if (!(strcmp(w->name, "WSA_RX INT1 INTERP"))) {
- reg = BOLERO_CDC_WSA_RX1_RX_PATH_CTL;
- gain_reg = BOLERO_CDC_WSA_RX1_RX_VOL_CTL;
- } else {
- dev_err(component->dev, "%s: Interpolator reg not found\n",
- __func__);
- return -EINVAL;
- }
- switch (event) {
- case SND_SOC_DAPM_PRE_PMU:
- /* Reset if needed */
- wsa_macro_enable_prim_interpolator(component, reg, event);
- break;
- case SND_SOC_DAPM_POST_PMU:
- wsa_macro_config_compander(component, w->shift, event);
- wsa_macro_config_softclip(component, w->shift, event);
- /* apply gain after int clk is enabled */
- if ((wsa_priv->spkr_gain_offset ==
- WSA_MACRO_GAIN_OFFSET_M1P5_DB) &&
- (wsa_priv->comp_enabled[WSA_MACRO_COMP1] ||
- wsa_priv->comp_enabled[WSA_MACRO_COMP2]) &&
- (gain_reg == BOLERO_CDC_WSA_RX0_RX_VOL_CTL ||
- gain_reg == BOLERO_CDC_WSA_RX1_RX_VOL_CTL)) {
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_RX0_RX_PATH_SEC1,
- 0x01, 0x01);
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_RX0_RX_PATH_MIX_SEC0,
- 0x01, 0x01);
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_RX1_RX_PATH_SEC1,
- 0x01, 0x01);
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_RX1_RX_PATH_MIX_SEC0,
- 0x01, 0x01);
- offset_val = -2;
- }
- val = snd_soc_component_read(component, gain_reg);
- val += offset_val;
- snd_soc_component_write(component, gain_reg, val);
- wsa_macro_config_ear_spkr_gain(component, wsa_priv,
- event, gain_reg);
- break;
- case SND_SOC_DAPM_POST_PMD:
- wsa_macro_config_compander(component, w->shift, event);
- wsa_macro_config_softclip(component, w->shift, event);
- wsa_macro_enable_prim_interpolator(component, reg, event);
- if ((wsa_priv->spkr_gain_offset ==
- WSA_MACRO_GAIN_OFFSET_M1P5_DB) &&
- (wsa_priv->comp_enabled[WSA_MACRO_COMP1] ||
- wsa_priv->comp_enabled[WSA_MACRO_COMP2]) &&
- (gain_reg == BOLERO_CDC_WSA_RX0_RX_VOL_CTL ||
- gain_reg == BOLERO_CDC_WSA_RX1_RX_VOL_CTL)) {
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_RX0_RX_PATH_SEC1,
- 0x01, 0x00);
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_RX0_RX_PATH_MIX_SEC0,
- 0x01, 0x00);
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_RX1_RX_PATH_SEC1,
- 0x01, 0x00);
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_RX1_RX_PATH_MIX_SEC0,
- 0x01, 0x00);
- offset_val = 2;
- val = snd_soc_component_read(component, gain_reg);
- val += offset_val;
- snd_soc_component_write(component, gain_reg, val);
- }
- wsa_macro_config_ear_spkr_gain(component, wsa_priv,
- event, gain_reg);
- break;
- }
- return 0;
- }
- static int wsa_macro_config_ear_spkr_gain(struct snd_soc_component *component,
- struct wsa_macro_priv *wsa_priv,
- int event, int gain_reg)
- {
- int comp_gain_offset, val;
- switch (wsa_priv->spkr_mode) {
- /* Compander gain in WSA_MACRO_SPKR_MODE1 case is 12 dB */
- case WSA_MACRO_SPKR_MODE_1:
- comp_gain_offset = -12;
- break;
- /* Default case compander gain is 15 dB */
- default:
- comp_gain_offset = -15;
- break;
- }
- switch (event) {
- case SND_SOC_DAPM_POST_PMU:
- /* Apply ear spkr gain only if compander is enabled */
- if (wsa_priv->comp_enabled[WSA_MACRO_COMP1] &&
- (gain_reg == BOLERO_CDC_WSA_RX0_RX_VOL_CTL) &&
- (wsa_priv->ear_spkr_gain != 0)) {
- /* For example, val is -8(-12+5-1) for 4dB of gain */
- val = comp_gain_offset + wsa_priv->ear_spkr_gain - 1;
- snd_soc_component_write(component, gain_reg, val);
- dev_dbg(wsa_priv->dev, "%s: RX0 Volume %d dB\n",
- __func__, val);
- }
- if(wsa_priv->wsa_spkrrecv) {
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_COMPANDER0_CTL7, 0x01, 0x00);
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_COMPANDER0_CTL3, 0x80, 0x80);
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_RX0_RX_PATH_CFG1, 0x08, 0x00);
- }
- break;
- case SND_SOC_DAPM_POST_PMD:
- /*
- * Reset RX0 volume to 0 dB if compander is enabled and
- * ear_spkr_gain is non-zero.
- */
- if (wsa_priv->comp_enabled[WSA_MACRO_COMP1] &&
- (gain_reg == BOLERO_CDC_WSA_RX0_RX_VOL_CTL) &&
- (wsa_priv->ear_spkr_gain != 0)) {
- snd_soc_component_write(component, gain_reg, 0x0);
- dev_dbg(wsa_priv->dev, "%s: Reset RX0 Volume to 0 dB\n",
- __func__);
- }
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_RX0_RX_PATH_CFG1, 0x08, 0x08);
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_COMPANDER0_CTL7, 0x01, 0x01);
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_COMPANDER0_CTL3, 0x80, 0x00);
- break;
- }
- return 0;
- }
- static int wsa_macro_spk_boost_event(struct snd_soc_dapm_widget *w,
- struct snd_kcontrol *kcontrol,
- int event)
- {
- struct snd_soc_component *component =
- snd_soc_dapm_to_component(w->dapm);
- u16 boost_path_ctl, boost_path_cfg1;
- u16 reg, reg_mix;
- dev_dbg(component->dev, "%s %s %d\n", __func__, w->name, event);
- if (!strcmp(w->name, "WSA_RX INT0 CHAIN")) {
- boost_path_ctl = BOLERO_CDC_WSA_BOOST0_BOOST_PATH_CTL;
- boost_path_cfg1 = BOLERO_CDC_WSA_RX0_RX_PATH_CFG1;
- reg = BOLERO_CDC_WSA_RX0_RX_PATH_CTL;
- reg_mix = BOLERO_CDC_WSA_RX0_RX_PATH_MIX_CTL;
- } else if (!strcmp(w->name, "WSA_RX INT1 CHAIN")) {
- boost_path_ctl = BOLERO_CDC_WSA_BOOST1_BOOST_PATH_CTL;
- boost_path_cfg1 = BOLERO_CDC_WSA_RX1_RX_PATH_CFG1;
- reg = BOLERO_CDC_WSA_RX1_RX_PATH_CTL;
- reg_mix = BOLERO_CDC_WSA_RX1_RX_PATH_MIX_CTL;
- } else {
- dev_err(component->dev, "%s: unknown widget: %s\n",
- __func__, w->name);
- return -EINVAL;
- }
- switch (event) {
- case SND_SOC_DAPM_PRE_PMU:
- snd_soc_component_update_bits(component, boost_path_cfg1,
- 0x01, 0x01);
- snd_soc_component_update_bits(component, boost_path_ctl,
- 0x10, 0x10);
- if ((snd_soc_component_read(component, reg_mix)) & 0x10)
- snd_soc_component_update_bits(component, reg_mix,
- 0x10, 0x00);
- break;
- case SND_SOC_DAPM_POST_PMU:
- snd_soc_component_update_bits(component, reg, 0x10, 0x00);
- break;
- case SND_SOC_DAPM_POST_PMD:
- snd_soc_component_update_bits(component, boost_path_ctl,
- 0x10, 0x00);
- snd_soc_component_update_bits(component, boost_path_cfg1,
- 0x01, 0x00);
- break;
- }
- return 0;
- }
- static int wsa_macro_enable_vbat(struct snd_soc_dapm_widget *w,
- struct snd_kcontrol *kcontrol,
- int event)
- {
- struct snd_soc_component *component =
- snd_soc_dapm_to_component(w->dapm);
- struct device *wsa_dev = NULL;
- struct wsa_macro_priv *wsa_priv = NULL;
- u16 vbat_path_cfg = 0;
- int softclip_path = 0;
- if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
- return -EINVAL;
- dev_dbg(component->dev, "%s %s %d\n", __func__, w->name, event);
- if (!strcmp(w->name, "WSA_RX INT0 VBAT")) {
- vbat_path_cfg = BOLERO_CDC_WSA_RX0_RX_PATH_CFG1;
- softclip_path = WSA_MACRO_SOFTCLIP0;
- } else if (!strcmp(w->name, "WSA_RX INT1 VBAT")) {
- vbat_path_cfg = BOLERO_CDC_WSA_RX1_RX_PATH_CFG1;
- softclip_path = WSA_MACRO_SOFTCLIP1;
- }
- switch (event) {
- case SND_SOC_DAPM_PRE_PMU:
- /* Enable clock for VBAT block */
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_VBAT_BCL_VBAT_PATH_CTL, 0x10, 0x10);
- /* Enable VBAT block */
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_VBAT_BCL_VBAT_CFG, 0x01, 0x01);
- /* Update interpolator with 384K path */
- snd_soc_component_update_bits(component, vbat_path_cfg,
- 0x80, 0x80);
- /* Use attenuation mode */
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_VBAT_BCL_VBAT_CFG, 0x02, 0x00);
- /*
- * BCL block needs softclip clock and mux config to be enabled
- */
- wsa_macro_enable_softclip_clk(component, wsa_priv,
- softclip_path, true);
- /* Enable VBAT at channel level */
- snd_soc_component_update_bits(component, vbat_path_cfg,
- 0x02, 0x02);
- /* Set the ATTK1 gain */
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_VBAT_BCL_VBAT_BCL_GAIN_UPD1,
- 0xFF, 0xFF);
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_VBAT_BCL_VBAT_BCL_GAIN_UPD2,
- 0xFF, 0x03);
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_VBAT_BCL_VBAT_BCL_GAIN_UPD3,
- 0xFF, 0x00);
- /* Set the ATTK2 gain */
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_VBAT_BCL_VBAT_BCL_GAIN_UPD4,
- 0xFF, 0xFF);
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_VBAT_BCL_VBAT_BCL_GAIN_UPD5,
- 0xFF, 0x03);
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_VBAT_BCL_VBAT_BCL_GAIN_UPD6,
- 0xFF, 0x00);
- /* Set the ATTK3 gain */
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_VBAT_BCL_VBAT_BCL_GAIN_UPD7,
- 0xFF, 0xFF);
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_VBAT_BCL_VBAT_BCL_GAIN_UPD8,
- 0xFF, 0x03);
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_VBAT_BCL_VBAT_BCL_GAIN_UPD9,
- 0xFF, 0x00);
- break;
- case SND_SOC_DAPM_POST_PMD:
- snd_soc_component_update_bits(component, vbat_path_cfg,
- 0x80, 0x00);
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_VBAT_BCL_VBAT_CFG,
- 0x02, 0x02);
- snd_soc_component_update_bits(component, vbat_path_cfg,
- 0x02, 0x00);
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_VBAT_BCL_VBAT_BCL_GAIN_UPD1,
- 0xFF, 0x00);
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_VBAT_BCL_VBAT_BCL_GAIN_UPD2,
- 0xFF, 0x00);
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_VBAT_BCL_VBAT_BCL_GAIN_UPD3,
- 0xFF, 0x00);
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_VBAT_BCL_VBAT_BCL_GAIN_UPD4,
- 0xFF, 0x00);
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_VBAT_BCL_VBAT_BCL_GAIN_UPD5,
- 0xFF, 0x00);
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_VBAT_BCL_VBAT_BCL_GAIN_UPD6,
- 0xFF, 0x00);
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_VBAT_BCL_VBAT_BCL_GAIN_UPD7,
- 0xFF, 0x00);
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_VBAT_BCL_VBAT_BCL_GAIN_UPD8,
- 0xFF, 0x00);
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_VBAT_BCL_VBAT_BCL_GAIN_UPD9,
- 0xFF, 0x00);
- wsa_macro_enable_softclip_clk(component, wsa_priv,
- softclip_path, false);
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_VBAT_BCL_VBAT_CFG, 0x01, 0x00);
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_VBAT_BCL_VBAT_PATH_CTL, 0x10, 0x00);
- break;
- default:
- dev_err(wsa_dev, "%s: Invalid event %d\n", __func__, event);
- break;
- }
- return 0;
- }
- static int wsa_macro_enable_echo(struct snd_soc_dapm_widget *w,
- struct snd_kcontrol *kcontrol,
- int event)
- {
- struct snd_soc_component *component =
- snd_soc_dapm_to_component(w->dapm);
- struct device *wsa_dev = NULL;
- struct wsa_macro_priv *wsa_priv = NULL;
- u16 val, ec_tx = 0, ec_hq_reg;
- if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
- return -EINVAL;
- dev_dbg(wsa_dev, "%s %d %s\n", __func__, event, w->name);
- val = snd_soc_component_read(component,
- BOLERO_CDC_WSA_RX_INP_MUX_RX_MIX_CFG0);
- if (!(strcmp(w->name, "WSA RX_MIX EC0_MUX")))
- ec_tx = (val & 0x07) - 1;
- else
- ec_tx = ((val & 0x38) >> 0x3) - 1;
- if (ec_tx < 0 || ec_tx >= (WSA_MACRO_RX1 + 1)) {
- dev_err(wsa_dev, "%s: EC mix control not set correctly\n",
- __func__);
- return -EINVAL;
- }
- if (wsa_priv->ec_hq[ec_tx]) {
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_RX_INP_MUX_RX_MIX_CFG0,
- 0x1 << ec_tx, 0x1 << ec_tx);
- ec_hq_reg = BOLERO_CDC_WSA_EC_HQ0_EC_REF_HQ_PATH_CTL +
- 0x40 * ec_tx;
- snd_soc_component_update_bits(component, ec_hq_reg, 0x01, 0x01);
- ec_hq_reg = BOLERO_CDC_WSA_EC_HQ0_EC_REF_HQ_CFG0 +
- 0x40 * ec_tx;
- /* default set to 48k */
- snd_soc_component_update_bits(component, ec_hq_reg, 0x1E, 0x08);
- }
- return 0;
- }
- static int wsa_macro_get_ec_hq(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_soc_component *component =
- snd_soc_kcontrol_component(kcontrol);
- int ec_tx = ((struct soc_multi_mixer_control *)
- kcontrol->private_value)->shift;
- struct device *wsa_dev = NULL;
- struct wsa_macro_priv *wsa_priv = NULL;
- if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
- return -EINVAL;
- ucontrol->value.integer.value[0] = wsa_priv->ec_hq[ec_tx];
- return 0;
- }
- static int wsa_macro_set_ec_hq(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_soc_component *component =
- snd_soc_kcontrol_component(kcontrol);
- int ec_tx = ((struct soc_multi_mixer_control *)
- kcontrol->private_value)->shift;
- int value = ucontrol->value.integer.value[0];
- struct device *wsa_dev = NULL;
- struct wsa_macro_priv *wsa_priv = NULL;
- if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
- return -EINVAL;
- dev_dbg(wsa_dev, "%s: enable current %d, new %d\n",
- __func__, wsa_priv->ec_hq[ec_tx], value);
- wsa_priv->ec_hq[ec_tx] = value;
- return 0;
- }
- static int wsa_macro_get_rx_mute_status(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_soc_component *component =
- snd_soc_kcontrol_component(kcontrol);
- struct device *wsa_dev = NULL;
- struct wsa_macro_priv *wsa_priv = NULL;
- int wsa_rx_shift = ((struct soc_multi_mixer_control *)
- kcontrol->private_value)->shift;
- if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
- return -EINVAL;
- ucontrol->value.integer.value[0] =
- wsa_priv->wsa_digital_mute_status[wsa_rx_shift];
- return 0;
- }
- static int wsa_macro_set_rx_mute_status(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_soc_component *component =
- snd_soc_kcontrol_component(kcontrol);
- struct device *wsa_dev = NULL;
- struct wsa_macro_priv *wsa_priv = NULL;
- int value = ucontrol->value.integer.value[0];
- int wsa_rx_shift = ((struct soc_multi_mixer_control *)
- kcontrol->private_value)->shift;
- int ret = 0;
- if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
- return -EINVAL;
- pm_runtime_get_sync(wsa_priv->dev);
- switch (wsa_rx_shift) {
- case 0:
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_RX0_RX_PATH_CTL,
- 0x10, value << 4);
- break;
- case 1:
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_RX1_RX_PATH_CTL,
- 0x10, value << 4);
- break;
- case 2:
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_RX0_RX_PATH_MIX_CTL,
- 0x10, value << 4);
- break;
- case 3:
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_RX1_RX_PATH_MIX_CTL,
- 0x10, value << 4);
- break;
- default:
- pr_err("%s: invalid argument rx_shift = %d\n", __func__,
- wsa_rx_shift);
- ret = -EINVAL;
- }
- pm_runtime_mark_last_busy(wsa_priv->dev);
- pm_runtime_put_autosuspend(wsa_priv->dev);
- dev_dbg(component->dev, "%s: WSA Digital Mute RX %d Enable %d\n",
- __func__, wsa_rx_shift, value);
- wsa_priv->wsa_digital_mute_status[wsa_rx_shift] = value;
- return ret;
- }
- static int wsa_macro_get_compander(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_soc_component *component =
- snd_soc_kcontrol_component(kcontrol);
- int comp = ((struct soc_multi_mixer_control *)
- kcontrol->private_value)->shift;
- struct device *wsa_dev = NULL;
- struct wsa_macro_priv *wsa_priv = NULL;
- if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
- return -EINVAL;
- ucontrol->value.integer.value[0] = wsa_priv->comp_enabled[comp];
- return 0;
- }
- static int wsa_macro_set_compander(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_soc_component *component =
- snd_soc_kcontrol_component(kcontrol);
- int comp = ((struct soc_multi_mixer_control *)
- kcontrol->private_value)->shift;
- int value = ucontrol->value.integer.value[0];
- struct device *wsa_dev = NULL;
- struct wsa_macro_priv *wsa_priv = NULL;
- if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
- return -EINVAL;
- dev_dbg(component->dev, "%s: Compander %d enable current %d, new %d\n",
- __func__, comp + 1, wsa_priv->comp_enabled[comp], value);
- wsa_priv->comp_enabled[comp] = value;
- return 0;
- }
- static int wsa_macro_ear_spkrrecv_get(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_soc_component *component =
- snd_soc_kcontrol_component(kcontrol);
- struct device *wsa_dev = NULL;
- struct wsa_macro_priv *wsa_priv = NULL;
- if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
- return -EINVAL;
- ucontrol->value.integer.value[0] = wsa_priv->wsa_spkrrecv;
- dev_dbg(component->dev, "%s: ucontrol->value.integer.value[0] = %ld\n",
- __func__, ucontrol->value.integer.value[0]);
- return 0;
- }
- static int wsa_macro_ear_spkrrecv_put(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_soc_component *component =
- snd_soc_kcontrol_component(kcontrol);
- struct device *wsa_dev = NULL;
- struct wsa_macro_priv *wsa_priv = NULL;
- if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
- return -EINVAL;
- wsa_priv->wsa_spkrrecv = ucontrol->value.integer.value[0];
- dev_dbg(component->dev, "%s:spkrrecv status = %d\n",
- __func__, wsa_priv->wsa_spkrrecv);
- return 0;
- }
- static int wsa_macro_ear_spkr_pa_gain_get(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_soc_component *component =
- snd_soc_kcontrol_component(kcontrol);
- struct device *wsa_dev = NULL;
- struct wsa_macro_priv *wsa_priv = NULL;
- if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
- return -EINVAL;
- ucontrol->value.integer.value[0] = wsa_priv->ear_spkr_gain;
- dev_dbg(component->dev, "%s: ucontrol->value.integer.value[0] = %ld\n",
- __func__, ucontrol->value.integer.value[0]);
- return 0;
- }
- static int wsa_macro_ear_spkr_pa_gain_put(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_soc_component *component =
- snd_soc_kcontrol_component(kcontrol);
- struct device *wsa_dev = NULL;
- struct wsa_macro_priv *wsa_priv = NULL;
- if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
- return -EINVAL;
- wsa_priv->ear_spkr_gain = ucontrol->value.integer.value[0];
- dev_dbg(component->dev, "%s: gain = %d\n", __func__,
- wsa_priv->ear_spkr_gain);
- return 0;
- }
- static int wsa_macro_spkr_left_boost_stage_get(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- u8 bst_state_max = 0;
- struct snd_soc_component *component =
- snd_soc_kcontrol_component(kcontrol);
- bst_state_max = snd_soc_component_read(component,
- BOLERO_CDC_WSA_BOOST0_BOOST_CTL);
- bst_state_max = (bst_state_max & 0x0c) >> 2;
- ucontrol->value.integer.value[0] = bst_state_max;
- dev_dbg(component->dev, "%s: ucontrol->value.integer.value[0] = %ld\n",
- __func__, ucontrol->value.integer.value[0]);
- return 0;
- }
- static int wsa_macro_spkr_left_boost_stage_put(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- u8 bst_state_max;
- struct snd_soc_component *component =
- snd_soc_kcontrol_component(kcontrol);
- dev_dbg(component->dev, "%s: ucontrol->value.integer.value[0] = %ld\n",
- __func__, ucontrol->value.integer.value[0]);
- bst_state_max = ucontrol->value.integer.value[0] << 2;
- /* bolero does not need to limit the boost levels */
- return 0;
- }
- static int wsa_macro_spkr_right_boost_stage_get(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- u8 bst_state_max = 0;
- struct snd_soc_component *component =
- snd_soc_kcontrol_component(kcontrol);
- bst_state_max = snd_soc_component_read(component,
- BOLERO_CDC_WSA_BOOST1_BOOST_CTL);
- bst_state_max = (bst_state_max & 0x0c) >> 2;
- ucontrol->value.integer.value[0] = bst_state_max;
- dev_dbg(component->dev, "%s: ucontrol->value.integer.value[0] = %ld\n",
- __func__, ucontrol->value.integer.value[0]);
- return 0;
- }
- static int wsa_macro_spkr_right_boost_stage_put(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- u8 bst_state_max;
- struct snd_soc_component *component =
- snd_soc_kcontrol_component(kcontrol);
- dev_dbg(component->dev, "%s: ucontrol->value.integer.value[0] = %ld\n",
- __func__, ucontrol->value.integer.value[0]);
- bst_state_max = ucontrol->value.integer.value[0] << 2;
- /* bolero does not need to limit the boost levels */
- return 0;
- }
- static int wsa_macro_rx_mux_get(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_soc_dapm_widget *widget =
- snd_soc_dapm_kcontrol_widget(kcontrol);
- struct snd_soc_component *component =
- snd_soc_dapm_to_component(widget->dapm);
- struct device *wsa_dev = NULL;
- struct wsa_macro_priv *wsa_priv = NULL;
- if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
- return -EINVAL;
- ucontrol->value.integer.value[0] =
- wsa_priv->rx_port_value[widget->shift];
- return 0;
- }
- static int wsa_macro_rx_mux_put(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_soc_dapm_widget *widget =
- snd_soc_dapm_kcontrol_widget(kcontrol);
- struct snd_soc_component *component =
- snd_soc_dapm_to_component(widget->dapm);
- struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
- struct snd_soc_dapm_update *update = NULL;
- u32 rx_port_value = ucontrol->value.integer.value[0];
- u32 bit_input = 0;
- u32 aif_rst;
- struct device *wsa_dev = NULL;
- struct wsa_macro_priv *wsa_priv = NULL;
- if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
- return -EINVAL;
- aif_rst = wsa_priv->rx_port_value[widget->shift];
- if (!rx_port_value) {
- if (aif_rst == 0) {
- dev_err(wsa_dev, "%s: AIF reset already\n", __func__);
- return 0;
- }
- if (aif_rst >= WSA_MACRO_RX_MAX) {
- dev_err(wsa_dev, "%s: Invalid AIF reset\n", __func__);
- return 0;
- }
- }
- wsa_priv->rx_port_value[widget->shift] = rx_port_value;
- bit_input = widget->shift;
- dev_dbg(wsa_dev,
- "%s: mux input: %d, mux output: %d, bit: %d\n",
- __func__, rx_port_value, widget->shift, bit_input);
- switch (rx_port_value) {
- case 0:
- clear_bit(bit_input,
- &wsa_priv->active_ch_mask[aif_rst]);
- break;
- case 1:
- case 2:
- set_bit(bit_input,
- &wsa_priv->active_ch_mask[rx_port_value]);
- break;
- default:
- dev_err(wsa_dev,
- "%s: Invalid AIF_ID for WSA RX MUX %d\n",
- __func__, rx_port_value);
- return -EINVAL;
- }
- snd_soc_dapm_mux_update_power(widget->dapm, kcontrol,
- rx_port_value, e, update);
- return 0;
- }
- static int wsa_macro_vbat_bcl_gsm_mode_func_get(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_soc_component *component =
- snd_soc_kcontrol_component(kcontrol);
- ucontrol->value.integer.value[0] =
- ((snd_soc_component_read(
- component, BOLERO_CDC_WSA_VBAT_BCL_VBAT_CFG) & 0x04) ?
- 1 : 0);
- dev_dbg(component->dev, "%s: value: %lu\n", __func__,
- ucontrol->value.integer.value[0]);
- return 0;
- }
- static int wsa_macro_vbat_bcl_gsm_mode_func_put(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_soc_component *component =
- snd_soc_kcontrol_component(kcontrol);
- dev_dbg(component->dev, "%s: value: %lu\n", __func__,
- ucontrol->value.integer.value[0]);
- /* Set Vbat register configuration for GSM mode bit based on value */
- if (ucontrol->value.integer.value[0])
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_VBAT_BCL_VBAT_CFG,
- 0x04, 0x04);
- else
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_VBAT_BCL_VBAT_CFG,
- 0x04, 0x00);
- return 0;
- }
- static int wsa_macro_soft_clip_enable_get(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_soc_component *component =
- snd_soc_kcontrol_component(kcontrol);
- struct device *wsa_dev = NULL;
- struct wsa_macro_priv *wsa_priv = NULL;
- int path = ((struct soc_multi_mixer_control *)
- kcontrol->private_value)->shift;
- if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
- return -EINVAL;
- ucontrol->value.integer.value[0] = wsa_priv->is_softclip_on[path];
- dev_dbg(component->dev, "%s: ucontrol->value.integer.value[0] = %ld\n",
- __func__, ucontrol->value.integer.value[0]);
- return 0;
- }
- static int wsa_macro_soft_clip_enable_put(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_soc_component *component =
- snd_soc_kcontrol_component(kcontrol);
- struct device *wsa_dev = NULL;
- struct wsa_macro_priv *wsa_priv = NULL;
- int path = ((struct soc_multi_mixer_control *)
- kcontrol->private_value)->shift;
- if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
- return -EINVAL;
- wsa_priv->is_softclip_on[path] = ucontrol->value.integer.value[0];
- dev_dbg(component->dev, "%s: soft clip enable for %d: %d\n", __func__,
- path, wsa_priv->is_softclip_on[path]);
- return 0;
- }
- static const struct snd_kcontrol_new wsa_macro_snd_controls[] = {
- SOC_ENUM_EXT("WSA SPKRRECV", wsa_macro_ear_spkrrecv_enum,
- wsa_macro_ear_spkrrecv_get,
- wsa_macro_ear_spkrrecv_put),
- SOC_ENUM_EXT("EAR SPKR PA Gain", wsa_macro_ear_spkr_pa_gain_enum,
- wsa_macro_ear_spkr_pa_gain_get,
- wsa_macro_ear_spkr_pa_gain_put),
- SOC_ENUM_EXT("SPKR Left Boost Max State",
- wsa_macro_spkr_boost_stage_enum,
- wsa_macro_spkr_left_boost_stage_get,
- wsa_macro_spkr_left_boost_stage_put),
- SOC_ENUM_EXT("SPKR Right Boost Max State",
- wsa_macro_spkr_boost_stage_enum,
- wsa_macro_spkr_right_boost_stage_get,
- wsa_macro_spkr_right_boost_stage_put),
- SOC_ENUM_EXT("GSM mode Enable", wsa_macro_vbat_bcl_gsm_mode_enum,
- wsa_macro_vbat_bcl_gsm_mode_func_get,
- wsa_macro_vbat_bcl_gsm_mode_func_put),
- SOC_SINGLE_EXT("WSA_Softclip0 Enable", SND_SOC_NOPM,
- WSA_MACRO_SOFTCLIP0, 1, 0,
- wsa_macro_soft_clip_enable_get,
- wsa_macro_soft_clip_enable_put),
- SOC_SINGLE_EXT("WSA_Softclip1 Enable", SND_SOC_NOPM,
- WSA_MACRO_SOFTCLIP1, 1, 0,
- wsa_macro_soft_clip_enable_get,
- wsa_macro_soft_clip_enable_put),
- SOC_SINGLE_S8_TLV("WSA_RX0 Digital Volume",
- BOLERO_CDC_WSA_RX0_RX_VOL_CTL,
- -84, 40, digital_gain),
- SOC_SINGLE_S8_TLV("WSA_RX1 Digital Volume",
- BOLERO_CDC_WSA_RX1_RX_VOL_CTL,
- -84, 40, digital_gain),
- SOC_SINGLE_EXT("WSA_RX0 Digital Mute", SND_SOC_NOPM, WSA_MACRO_RX0, 1,
- 0, wsa_macro_get_rx_mute_status,
- wsa_macro_set_rx_mute_status),
- SOC_SINGLE_EXT("WSA_RX1 Digital Mute", SND_SOC_NOPM, WSA_MACRO_RX1, 1,
- 0, wsa_macro_get_rx_mute_status,
- wsa_macro_set_rx_mute_status),
- SOC_SINGLE_EXT("WSA_RX0_MIX Digital Mute", SND_SOC_NOPM,
- WSA_MACRO_RX_MIX0, 1, 0, wsa_macro_get_rx_mute_status,
- wsa_macro_set_rx_mute_status),
- SOC_SINGLE_EXT("WSA_RX1_MIX Digital Mute", SND_SOC_NOPM,
- WSA_MACRO_RX_MIX1, 1, 0, wsa_macro_get_rx_mute_status,
- wsa_macro_set_rx_mute_status),
- SOC_SINGLE_EXT("WSA_COMP1 Switch", SND_SOC_NOPM, WSA_MACRO_COMP1, 1, 0,
- wsa_macro_get_compander, wsa_macro_set_compander),
- SOC_SINGLE_EXT("WSA_COMP2 Switch", SND_SOC_NOPM, WSA_MACRO_COMP2, 1, 0,
- wsa_macro_get_compander, wsa_macro_set_compander),
- SOC_SINGLE_EXT("WSA_RX0 EC_HQ Switch", SND_SOC_NOPM, WSA_MACRO_RX0,
- 1, 0, wsa_macro_get_ec_hq, wsa_macro_set_ec_hq),
- SOC_SINGLE_EXT("WSA_RX1 EC_HQ Switch", SND_SOC_NOPM, WSA_MACRO_RX1,
- 1, 0, wsa_macro_get_ec_hq, wsa_macro_set_ec_hq),
- };
- static const struct soc_enum rx_mux_enum =
- SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(rx_mux_text), rx_mux_text);
- static const struct snd_kcontrol_new rx_mux[WSA_MACRO_RX_MAX] = {
- SOC_DAPM_ENUM_EXT("WSA RX0 Mux", rx_mux_enum,
- wsa_macro_rx_mux_get, wsa_macro_rx_mux_put),
- SOC_DAPM_ENUM_EXT("WSA RX1 Mux", rx_mux_enum,
- wsa_macro_rx_mux_get, wsa_macro_rx_mux_put),
- SOC_DAPM_ENUM_EXT("WSA RX_MIX0 Mux", rx_mux_enum,
- wsa_macro_rx_mux_get, wsa_macro_rx_mux_put),
- SOC_DAPM_ENUM_EXT("WSA RX_MIX1 Mux", rx_mux_enum,
- wsa_macro_rx_mux_get, wsa_macro_rx_mux_put),
- };
- static int wsa_macro_vi_feed_mixer_get(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_soc_dapm_widget *widget =
- snd_soc_dapm_kcontrol_widget(kcontrol);
- struct snd_soc_component *component =
- snd_soc_dapm_to_component(widget->dapm);
- struct soc_multi_mixer_control *mixer =
- ((struct soc_multi_mixer_control *)kcontrol->private_value);
- u32 dai_id = widget->shift;
- u32 spk_tx_id = mixer->shift;
- struct device *wsa_dev = NULL;
- struct wsa_macro_priv *wsa_priv = NULL;
- if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
- return -EINVAL;
- if (test_bit(spk_tx_id, &wsa_priv->active_ch_mask[dai_id]))
- ucontrol->value.integer.value[0] = 1;
- else
- ucontrol->value.integer.value[0] = 0;
- return 0;
- }
- static int wsa_macro_vi_feed_mixer_put(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct snd_soc_dapm_widget *widget =
- snd_soc_dapm_kcontrol_widget(kcontrol);
- struct snd_soc_component *component =
- snd_soc_dapm_to_component(widget->dapm);
- struct soc_multi_mixer_control *mixer =
- ((struct soc_multi_mixer_control *)kcontrol->private_value);
- u32 spk_tx_id = mixer->shift;
- u32 enable = ucontrol->value.integer.value[0];
- struct device *wsa_dev = NULL;
- struct wsa_macro_priv *wsa_priv = NULL;
- if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
- return -EINVAL;
- wsa_priv->vi_feed_value = ucontrol->value.integer.value[0];
- if (enable) {
- if (spk_tx_id == WSA_MACRO_TX0 &&
- !test_bit(WSA_MACRO_TX0,
- &wsa_priv->active_ch_mask[WSA_MACRO_AIF_VI])) {
- set_bit(WSA_MACRO_TX0,
- &wsa_priv->active_ch_mask[WSA_MACRO_AIF_VI]);
- }
- if (spk_tx_id == WSA_MACRO_TX1 &&
- !test_bit(WSA_MACRO_TX1,
- &wsa_priv->active_ch_mask[WSA_MACRO_AIF_VI])) {
- set_bit(WSA_MACRO_TX1,
- &wsa_priv->active_ch_mask[WSA_MACRO_AIF_VI]);
- }
- } else {
- if (spk_tx_id == WSA_MACRO_TX0 &&
- test_bit(WSA_MACRO_TX0,
- &wsa_priv->active_ch_mask[WSA_MACRO_AIF_VI])) {
- clear_bit(WSA_MACRO_TX0,
- &wsa_priv->active_ch_mask[WSA_MACRO_AIF_VI]);
- }
- if (spk_tx_id == WSA_MACRO_TX1 &&
- test_bit(WSA_MACRO_TX1,
- &wsa_priv->active_ch_mask[WSA_MACRO_AIF_VI])) {
- clear_bit(WSA_MACRO_TX1,
- &wsa_priv->active_ch_mask[WSA_MACRO_AIF_VI]);
- }
- }
- snd_soc_dapm_mixer_update_power(widget->dapm, kcontrol, enable, NULL);
- return 0;
- }
- static const struct snd_kcontrol_new aif_vi_mixer[] = {
- SOC_SINGLE_EXT("WSA_SPKR_VI_1", SND_SOC_NOPM, WSA_MACRO_TX0, 1, 0,
- wsa_macro_vi_feed_mixer_get,
- wsa_macro_vi_feed_mixer_put),
- SOC_SINGLE_EXT("WSA_SPKR_VI_2", SND_SOC_NOPM, WSA_MACRO_TX1, 1, 0,
- wsa_macro_vi_feed_mixer_get,
- wsa_macro_vi_feed_mixer_put),
- };
- static const struct snd_soc_dapm_widget wsa_macro_dapm_widgets[] = {
- SND_SOC_DAPM_AIF_IN("WSA AIF1 PB", "WSA_AIF1 Playback", 0,
- SND_SOC_NOPM, 0, 0),
- SND_SOC_DAPM_AIF_IN("WSA AIF_MIX1 PB", "WSA_AIF_MIX1 Playback", 0,
- SND_SOC_NOPM, 0, 0),
- SND_SOC_DAPM_AIF_OUT_E("WSA AIF_VI", "WSA_AIF_VI Capture", 0,
- SND_SOC_NOPM, WSA_MACRO_AIF_VI, 0,
- wsa_macro_enable_vi_feedback,
- SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
- SND_SOC_DAPM_AIF_OUT("WSA AIF_ECHO", "WSA_AIF_ECHO Capture", 0,
- SND_SOC_NOPM, 0, 0),
- SND_SOC_DAPM_MIXER("WSA_AIF_VI Mixer", SND_SOC_NOPM, WSA_MACRO_AIF_VI,
- 0, aif_vi_mixer, ARRAY_SIZE(aif_vi_mixer)),
- SND_SOC_DAPM_MUX_E("WSA RX_MIX EC0_MUX", SND_SOC_NOPM,
- WSA_MACRO_EC0_MUX, 0,
- &rx_mix_ec0_mux, wsa_macro_enable_echo,
- SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
- SND_SOC_DAPM_MUX_E("WSA RX_MIX EC1_MUX", SND_SOC_NOPM,
- WSA_MACRO_EC1_MUX, 0,
- &rx_mix_ec1_mux, wsa_macro_enable_echo,
- SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
- SND_SOC_DAPM_MUX("WSA RX0 MUX", SND_SOC_NOPM, WSA_MACRO_RX0, 0,
- &rx_mux[WSA_MACRO_RX0]),
- SND_SOC_DAPM_MUX("WSA RX1 MUX", SND_SOC_NOPM, WSA_MACRO_RX1, 0,
- &rx_mux[WSA_MACRO_RX1]),
- SND_SOC_DAPM_MUX("WSA RX_MIX0 MUX", SND_SOC_NOPM, WSA_MACRO_RX_MIX0, 0,
- &rx_mux[WSA_MACRO_RX_MIX0]),
- SND_SOC_DAPM_MUX("WSA RX_MIX1 MUX", SND_SOC_NOPM, WSA_MACRO_RX_MIX1, 0,
- &rx_mux[WSA_MACRO_RX_MIX1]),
- SND_SOC_DAPM_MIXER("WSA RX0", SND_SOC_NOPM, 0, 0, NULL, 0),
- SND_SOC_DAPM_MIXER("WSA RX1", SND_SOC_NOPM, 0, 0, NULL, 0),
- SND_SOC_DAPM_MIXER("WSA RX_MIX0", SND_SOC_NOPM, 0, 0, NULL, 0),
- SND_SOC_DAPM_MIXER("WSA RX_MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
- SND_SOC_DAPM_MUX_E("WSA_RX0 INP0", SND_SOC_NOPM, 0, 0,
- &rx0_prim_inp0_mux, wsa_macro_enable_swr,
- SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
- SND_SOC_DAPM_MUX_E("WSA_RX0 INP1", SND_SOC_NOPM, 0, 0,
- &rx0_prim_inp1_mux, wsa_macro_enable_swr,
- SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
- SND_SOC_DAPM_MUX_E("WSA_RX0 INP2", SND_SOC_NOPM, 0, 0,
- &rx0_prim_inp2_mux, wsa_macro_enable_swr,
- SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
- SND_SOC_DAPM_MUX_E("WSA_RX0 MIX INP", SND_SOC_NOPM,
- 0, 0, &rx0_mix_mux, wsa_macro_enable_mix_path,
- SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
- SND_SOC_DAPM_MUX_E("WSA_RX1 INP0", SND_SOC_NOPM, 0, 0,
- &rx1_prim_inp0_mux, wsa_macro_enable_swr,
- SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
- SND_SOC_DAPM_MUX_E("WSA_RX1 INP1", SND_SOC_NOPM, 0, 0,
- &rx1_prim_inp1_mux, wsa_macro_enable_swr,
- SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
- SND_SOC_DAPM_MUX_E("WSA_RX1 INP2", SND_SOC_NOPM, 0, 0,
- &rx1_prim_inp2_mux, wsa_macro_enable_swr,
- SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
- SND_SOC_DAPM_MUX_E("WSA_RX1 MIX INP", SND_SOC_NOPM,
- 0, 0, &rx1_mix_mux, wsa_macro_enable_mix_path,
- SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
- SND_SOC_DAPM_PGA_E("WSA_RX INT0 MIX", SND_SOC_NOPM,
- 0, 0, NULL, 0, wsa_macro_enable_main_path,
- SND_SOC_DAPM_PRE_PMU),
- SND_SOC_DAPM_PGA_E("WSA_RX INT1 MIX", SND_SOC_NOPM,
- 1, 0, NULL, 0, wsa_macro_enable_main_path,
- SND_SOC_DAPM_PRE_PMU),
- SND_SOC_DAPM_MIXER("WSA_RX INT0 SEC MIX", SND_SOC_NOPM, 0, 0, NULL, 0),
- SND_SOC_DAPM_MIXER("WSA_RX INT1 SEC MIX", SND_SOC_NOPM, 0, 0, NULL, 0),
- SND_SOC_DAPM_MUX_E("WSA_RX0 INT0 SIDETONE MIX",
- BOLERO_CDC_WSA_RX0_RX_PATH_CFG1, 4, 0,
- &rx0_sidetone_mix_mux, wsa_macro_enable_swr,
- SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
- SND_SOC_DAPM_INPUT("WSA SRC0_INP"),
- SND_SOC_DAPM_INPUT("WSA_TX DEC0_INP"),
- SND_SOC_DAPM_INPUT("WSA_TX DEC1_INP"),
- SND_SOC_DAPM_MIXER_E("WSA_RX INT0 INTERP", SND_SOC_NOPM,
- WSA_MACRO_COMP1, 0, NULL, 0, wsa_macro_enable_interpolator,
- SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
- SND_SOC_DAPM_POST_PMD),
- SND_SOC_DAPM_MIXER_E("WSA_RX INT1 INTERP", SND_SOC_NOPM,
- WSA_MACRO_COMP2, 0, NULL, 0, wsa_macro_enable_interpolator,
- SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
- SND_SOC_DAPM_POST_PMD),
- SND_SOC_DAPM_MIXER_E("WSA_RX INT0 CHAIN", SND_SOC_NOPM, 0, 0,
- NULL, 0, wsa_macro_spk_boost_event,
- SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
- SND_SOC_DAPM_POST_PMD),
- SND_SOC_DAPM_MIXER_E("WSA_RX INT1 CHAIN", SND_SOC_NOPM, 0, 0,
- NULL, 0, wsa_macro_spk_boost_event,
- SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
- SND_SOC_DAPM_POST_PMD),
- SND_SOC_DAPM_MIXER_E("WSA_RX INT0 VBAT", SND_SOC_NOPM,
- 0, 0, wsa_int0_vbat_mix_switch,
- ARRAY_SIZE(wsa_int0_vbat_mix_switch),
- wsa_macro_enable_vbat,
- SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
- SND_SOC_DAPM_MIXER_E("WSA_RX INT1 VBAT", SND_SOC_NOPM,
- 0, 0, wsa_int1_vbat_mix_switch,
- ARRAY_SIZE(wsa_int1_vbat_mix_switch),
- wsa_macro_enable_vbat,
- SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
- SND_SOC_DAPM_INPUT("VIINPUT_WSA"),
- SND_SOC_DAPM_OUTPUT("WSA_SPK1 OUT"),
- SND_SOC_DAPM_OUTPUT("WSA_SPK2 OUT"),
- SND_SOC_DAPM_SUPPLY_S("WSA_MCLK", 0, SND_SOC_NOPM, 0, 0,
- wsa_macro_mclk_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
- };
- static const struct snd_soc_dapm_route wsa_audio_map[] = {
- /* VI Feedback */
- {"WSA_AIF_VI Mixer", "WSA_SPKR_VI_1", "VIINPUT_WSA"},
- {"WSA_AIF_VI Mixer", "WSA_SPKR_VI_2", "VIINPUT_WSA"},
- {"WSA AIF_VI", NULL, "WSA_AIF_VI Mixer"},
- {"WSA AIF_VI", NULL, "WSA_MCLK"},
- {"WSA RX_MIX EC0_MUX", "RX_MIX_TX0", "WSA_RX INT0 SEC MIX"},
- {"WSA RX_MIX EC1_MUX", "RX_MIX_TX0", "WSA_RX INT0 SEC MIX"},
- {"WSA RX_MIX EC0_MUX", "RX_MIX_TX1", "WSA_RX INT1 SEC MIX"},
- {"WSA RX_MIX EC1_MUX", "RX_MIX_TX1", "WSA_RX INT1 SEC MIX"},
- {"WSA AIF_ECHO", NULL, "WSA RX_MIX EC0_MUX"},
- {"WSA AIF_ECHO", NULL, "WSA RX_MIX EC1_MUX"},
- {"WSA AIF_ECHO", NULL, "WSA_MCLK"},
- {"WSA AIF1 PB", NULL, "WSA_MCLK"},
- {"WSA AIF_MIX1 PB", NULL, "WSA_MCLK"},
- {"WSA RX0 MUX", "AIF1_PB", "WSA AIF1 PB"},
- {"WSA RX1 MUX", "AIF1_PB", "WSA AIF1 PB"},
- {"WSA RX_MIX0 MUX", "AIF1_PB", "WSA AIF1 PB"},
- {"WSA RX_MIX1 MUX", "AIF1_PB", "WSA AIF1 PB"},
- {"WSA RX0 MUX", "AIF_MIX1_PB", "WSA AIF_MIX1 PB"},
- {"WSA RX1 MUX", "AIF_MIX1_PB", "WSA AIF_MIX1 PB"},
- {"WSA RX_MIX0 MUX", "AIF_MIX1_PB", "WSA AIF_MIX1 PB"},
- {"WSA RX_MIX1 MUX", "AIF_MIX1_PB", "WSA AIF_MIX1 PB"},
- {"WSA RX0", NULL, "WSA RX0 MUX"},
- {"WSA RX1", NULL, "WSA RX1 MUX"},
- {"WSA RX_MIX0", NULL, "WSA RX_MIX0 MUX"},
- {"WSA RX_MIX1", NULL, "WSA RX_MIX1 MUX"},
- {"WSA_RX0 INP0", "RX0", "WSA RX0"},
- {"WSA_RX0 INP0", "RX1", "WSA RX1"},
- {"WSA_RX0 INP0", "RX_MIX0", "WSA RX_MIX0"},
- {"WSA_RX0 INP0", "RX_MIX1", "WSA RX_MIX1"},
- {"WSA_RX0 INP0", "DEC0", "WSA_TX DEC0_INP"},
- {"WSA_RX0 INP0", "DEC1", "WSA_TX DEC1_INP"},
- {"WSA_RX INT0 MIX", NULL, "WSA_RX0 INP0"},
- {"WSA_RX0 INP1", "RX0", "WSA RX0"},
- {"WSA_RX0 INP1", "RX1", "WSA RX1"},
- {"WSA_RX0 INP1", "RX_MIX0", "WSA RX_MIX0"},
- {"WSA_RX0 INP1", "RX_MIX1", "WSA RX_MIX1"},
- {"WSA_RX0 INP1", "DEC0", "WSA_TX DEC0_INP"},
- {"WSA_RX0 INP1", "DEC1", "WSA_TX DEC1_INP"},
- {"WSA_RX INT0 MIX", NULL, "WSA_RX0 INP1"},
- {"WSA_RX0 INP2", "RX0", "WSA RX0"},
- {"WSA_RX0 INP2", "RX1", "WSA RX1"},
- {"WSA_RX0 INP2", "RX_MIX0", "WSA RX_MIX0"},
- {"WSA_RX0 INP2", "RX_MIX1", "WSA RX_MIX1"},
- {"WSA_RX0 INP2", "DEC0", "WSA_TX DEC0_INP"},
- {"WSA_RX0 INP2", "DEC1", "WSA_TX DEC1_INP"},
- {"WSA_RX INT0 MIX", NULL, "WSA_RX0 INP2"},
- {"WSA_RX0 MIX INP", "RX0", "WSA RX0"},
- {"WSA_RX0 MIX INP", "RX1", "WSA RX1"},
- {"WSA_RX0 MIX INP", "RX_MIX0", "WSA RX_MIX0"},
- {"WSA_RX0 MIX INP", "RX_MIX1", "WSA RX_MIX1"},
- {"WSA_RX INT0 SEC MIX", NULL, "WSA_RX0 MIX INP"},
- {"WSA_RX INT0 SEC MIX", NULL, "WSA_RX INT0 MIX"},
- {"WSA_RX INT0 INTERP", NULL, "WSA_RX INT0 SEC MIX"},
- {"WSA_RX0 INT0 SIDETONE MIX", "SRC0", "WSA SRC0_INP"},
- {"WSA_RX INT0 INTERP", NULL, "WSA_RX0 INT0 SIDETONE MIX"},
- {"WSA_RX INT0 CHAIN", NULL, "WSA_RX INT0 INTERP"},
- {"WSA_RX INT0 VBAT", "WSA RX0 VBAT Enable", "WSA_RX INT0 INTERP"},
- {"WSA_RX INT0 CHAIN", NULL, "WSA_RX INT0 VBAT"},
- {"WSA_SPK1 OUT", NULL, "WSA_RX INT0 CHAIN"},
- {"WSA_SPK1 OUT", NULL, "WSA_MCLK"},
- {"WSA_RX1 INP0", "RX0", "WSA RX0"},
- {"WSA_RX1 INP0", "RX1", "WSA RX1"},
- {"WSA_RX1 INP0", "RX_MIX0", "WSA RX_MIX0"},
- {"WSA_RX1 INP0", "RX_MIX1", "WSA RX_MIX1"},
- {"WSA_RX1 INP0", "DEC0", "WSA_TX DEC0_INP"},
- {"WSA_RX1 INP0", "DEC1", "WSA_TX DEC1_INP"},
- {"WSA_RX INT1 MIX", NULL, "WSA_RX1 INP0"},
- {"WSA_RX1 INP1", "RX0", "WSA RX0"},
- {"WSA_RX1 INP1", "RX1", "WSA RX1"},
- {"WSA_RX1 INP1", "RX_MIX0", "WSA RX_MIX0"},
- {"WSA_RX1 INP1", "RX_MIX1", "WSA RX_MIX1"},
- {"WSA_RX1 INP1", "DEC0", "WSA_TX DEC0_INP"},
- {"WSA_RX1 INP1", "DEC1", "WSA_TX DEC1_INP"},
- {"WSA_RX INT1 MIX", NULL, "WSA_RX1 INP1"},
- {"WSA_RX1 INP2", "RX0", "WSA RX0"},
- {"WSA_RX1 INP2", "RX1", "WSA RX1"},
- {"WSA_RX1 INP2", "RX_MIX0", "WSA RX_MIX0"},
- {"WSA_RX1 INP2", "RX_MIX1", "WSA RX_MIX1"},
- {"WSA_RX1 INP2", "DEC0", "WSA_TX DEC0_INP"},
- {"WSA_RX1 INP2", "DEC1", "WSA_TX DEC1_INP"},
- {"WSA_RX INT1 MIX", NULL, "WSA_RX1 INP2"},
- {"WSA_RX1 MIX INP", "RX0", "WSA RX0"},
- {"WSA_RX1 MIX INP", "RX1", "WSA RX1"},
- {"WSA_RX1 MIX INP", "RX_MIX0", "WSA RX_MIX0"},
- {"WSA_RX1 MIX INP", "RX_MIX1", "WSA RX_MIX1"},
- {"WSA_RX INT1 SEC MIX", NULL, "WSA_RX1 MIX INP"},
- {"WSA_RX INT1 SEC MIX", NULL, "WSA_RX INT1 MIX"},
- {"WSA_RX INT1 INTERP", NULL, "WSA_RX INT1 SEC MIX"},
- {"WSA_RX INT1 VBAT", "WSA RX1 VBAT Enable", "WSA_RX INT1 INTERP"},
- {"WSA_RX INT1 CHAIN", NULL, "WSA_RX INT1 VBAT"},
- {"WSA_RX INT1 CHAIN", NULL, "WSA_RX INT1 INTERP"},
- {"WSA_SPK2 OUT", NULL, "WSA_RX INT1 CHAIN"},
- {"WSA_SPK2 OUT", NULL, "WSA_MCLK"},
- };
- static const struct wsa_macro_reg_mask_val wsa_macro_reg_init[] = {
- {BOLERO_CDC_WSA_BOOST0_BOOST_CFG1, 0x3F, 0x12},
- {BOLERO_CDC_WSA_BOOST0_BOOST_CFG2, 0x1C, 0x08},
- {BOLERO_CDC_WSA_COMPANDER0_CTL7, 0x1E, 0x18},
- {BOLERO_CDC_WSA_BOOST1_BOOST_CFG1, 0x3F, 0x12},
- {BOLERO_CDC_WSA_BOOST1_BOOST_CFG2, 0x1C, 0x08},
- {BOLERO_CDC_WSA_COMPANDER1_CTL7, 0x1E, 0x18},
- {BOLERO_CDC_WSA_BOOST0_BOOST_CTL, 0x70, 0x58},
- {BOLERO_CDC_WSA_BOOST1_BOOST_CTL, 0x70, 0x58},
- {BOLERO_CDC_WSA_RX0_RX_PATH_CFG1, 0x08, 0x08},
- {BOLERO_CDC_WSA_RX1_RX_PATH_CFG1, 0x08, 0x08},
- {BOLERO_CDC_WSA_TOP_TOP_CFG1, 0x02, 0x02},
- {BOLERO_CDC_WSA_TOP_TOP_CFG1, 0x01, 0x01},
- {BOLERO_CDC_WSA_TX0_SPKR_PROT_PATH_CFG0, 0x01, 0x01},
- {BOLERO_CDC_WSA_TX1_SPKR_PROT_PATH_CFG0, 0x01, 0x01},
- {BOLERO_CDC_WSA_TX2_SPKR_PROT_PATH_CFG0, 0x01, 0x01},
- {BOLERO_CDC_WSA_TX3_SPKR_PROT_PATH_CFG0, 0x01, 0x01},
- {BOLERO_CDC_WSA_COMPANDER0_CTL7, 0x01, 0x01},
- {BOLERO_CDC_WSA_COMPANDER1_CTL7, 0x01, 0x01},
- {BOLERO_CDC_WSA_RX0_RX_PATH_CFG0, 0x01, 0x01},
- {BOLERO_CDC_WSA_RX1_RX_PATH_CFG0, 0x01, 0x01},
- {BOLERO_CDC_WSA_RX0_RX_PATH_MIX_CFG, 0x01, 0x01},
- {BOLERO_CDC_WSA_RX1_RX_PATH_MIX_CFG, 0x01, 0x01},
- };
- static void wsa_macro_init_bcl_pmic_reg(struct snd_soc_component *component)
- {
- struct device *wsa_dev = NULL;
- struct wsa_macro_priv *wsa_priv = NULL;
- if (!component) {
- pr_err("%s: NULL component pointer!\n", __func__);
- return;
- }
- if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
- return;
- switch (wsa_priv->bcl_pmic_params.id) {
- case 0:
- /* Enable ID0 to listen to respective PMIC group interrupts */
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_VBAT_BCL_VBAT_DECODE_CTL1, 0x02, 0x02);
- /* Update MC_SID0 */
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_VBAT_BCL_VBAT_DECODE_CFG1, 0x0F,
- wsa_priv->bcl_pmic_params.sid);
- /* Update MC_PPID0 */
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_VBAT_BCL_VBAT_DECODE_CFG2, 0xFF,
- wsa_priv->bcl_pmic_params.ppid);
- break;
- case 1:
- /* Enable ID1 to listen to respective PMIC group interrupts */
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_VBAT_BCL_VBAT_DECODE_CTL1, 0x01, 0x01);
- /* Update MC_SID1 */
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_VBAT_BCL_VBAT_DECODE_CFG3, 0x0F,
- wsa_priv->bcl_pmic_params.sid);
- /* Update MC_PPID1 */
- snd_soc_component_update_bits(component,
- BOLERO_CDC_WSA_VBAT_BCL_VBAT_DECODE_CFG4, 0xFF,
- wsa_priv->bcl_pmic_params.ppid);
- break;
- default:
- dev_err(wsa_dev, "%s: PMIC ID is invalid %d\n",
- __func__, wsa_priv->bcl_pmic_params.id);
- break;
- }
- }
- static void wsa_macro_init_reg(struct snd_soc_component *component)
- {
- int i;
- for (i = 0; i < ARRAY_SIZE(wsa_macro_reg_init); i++)
- snd_soc_component_update_bits(component,
- wsa_macro_reg_init[i].reg,
- wsa_macro_reg_init[i].mask,
- wsa_macro_reg_init[i].val);
- wsa_macro_init_bcl_pmic_reg(component);
- }
- static int wsa_macro_core_vote(void *handle, bool enable)
- {
- int rc = 0;
- struct wsa_macro_priv *wsa_priv = (struct wsa_macro_priv *) handle;
- if (wsa_priv == NULL) {
- pr_err("%s: wsa priv data is NULL\n", __func__);
- return -EINVAL;
- }
- if (enable) {
- pm_runtime_get_sync(wsa_priv->dev);
- if (bolero_check_core_votes(wsa_priv->dev))
- rc = 0;
- else
- rc = -ENOTSYNC;
- } else {
- pm_runtime_put_autosuspend(wsa_priv->dev);
- pm_runtime_mark_last_busy(wsa_priv->dev);
- }
- return rc;
- }
- static int wsa_swrm_clock(void *handle, bool enable)
- {
- struct wsa_macro_priv *wsa_priv = (struct wsa_macro_priv *) handle;
- struct regmap *regmap = dev_get_regmap(wsa_priv->dev->parent, NULL);
- int ret = 0;
- if (regmap == NULL) {
- dev_err(wsa_priv->dev, "%s: regmap is NULL\n", __func__);
- return -EINVAL;
- }
- mutex_lock(&wsa_priv->swr_clk_lock);
- dev_dbg(wsa_priv->dev, "%s: swrm clock %s\n",
- __func__, (enable ? "enable" : "disable"));
- if (enable) {
- pm_runtime_get_sync(wsa_priv->dev);
- if (wsa_priv->swr_clk_users == 0) {
- ret = msm_cdc_pinctrl_select_active_state(
- wsa_priv->wsa_swr_gpio_p);
- if (ret < 0) {
- dev_err_ratelimited(wsa_priv->dev,
- "%s: wsa swr pinctrl enable failed\n",
- __func__);
- pm_runtime_mark_last_busy(wsa_priv->dev);
- pm_runtime_put_autosuspend(wsa_priv->dev);
- goto exit;
- }
- ret = wsa_macro_mclk_enable(wsa_priv, 1, true);
- if (ret < 0) {
- msm_cdc_pinctrl_select_sleep_state(
- wsa_priv->wsa_swr_gpio_p);
- dev_err_ratelimited(wsa_priv->dev,
- "%s: wsa request clock enable failed\n",
- __func__);
- pm_runtime_mark_last_busy(wsa_priv->dev);
- pm_runtime_put_autosuspend(wsa_priv->dev);
- goto exit;
- }
- if (wsa_priv->reset_swr)
- regmap_update_bits(regmap,
- BOLERO_CDC_WSA_CLK_RST_CTRL_SWR_CONTROL,
- 0x02, 0x02);
- regmap_update_bits(regmap,
- BOLERO_CDC_WSA_CLK_RST_CTRL_SWR_CONTROL,
- 0x01, 0x01);
- if (wsa_priv->reset_swr)
- regmap_update_bits(regmap,
- BOLERO_CDC_WSA_CLK_RST_CTRL_SWR_CONTROL,
- 0x02, 0x00);
- wsa_priv->reset_swr = false;
- }
- wsa_priv->swr_clk_users++;
- pm_runtime_mark_last_busy(wsa_priv->dev);
- pm_runtime_put_autosuspend(wsa_priv->dev);
- } else {
- if (wsa_priv->swr_clk_users <= 0) {
- dev_err(wsa_priv->dev, "%s: clock already disabled\n",
- __func__);
- wsa_priv->swr_clk_users = 0;
- goto exit;
- }
- wsa_priv->swr_clk_users--;
- if (wsa_priv->swr_clk_users == 0) {
- regmap_update_bits(regmap,
- BOLERO_CDC_WSA_CLK_RST_CTRL_SWR_CONTROL,
- 0x01, 0x00);
- wsa_macro_mclk_enable(wsa_priv, 0, true);
- ret = msm_cdc_pinctrl_select_sleep_state(
- wsa_priv->wsa_swr_gpio_p);
- if (ret < 0) {
- dev_err_ratelimited(wsa_priv->dev,
- "%s: wsa swr pinctrl disable failed\n",
- __func__);
- goto exit;
- }
- }
- }
- dev_dbg(wsa_priv->dev, "%s: swrm clock users %d\n",
- __func__, wsa_priv->swr_clk_users);
- exit:
- mutex_unlock(&wsa_priv->swr_clk_lock);
- return ret;
- }
- static int wsa_macro_init(struct snd_soc_component *component)
- {
- struct snd_soc_dapm_context *dapm =
- snd_soc_component_get_dapm(component);
- int ret;
- struct device *wsa_dev = NULL;
- struct wsa_macro_priv *wsa_priv = NULL;
- wsa_dev = bolero_get_device_ptr(component->dev, WSA_MACRO);
- if (!wsa_dev) {
- dev_err(component->dev,
- "%s: null device for macro!\n", __func__);
- return -EINVAL;
- }
- wsa_priv = dev_get_drvdata(wsa_dev);
- if (!wsa_priv) {
- dev_err(component->dev,
- "%s: priv is null for macro!\n", __func__);
- return -EINVAL;
- }
- ret = snd_soc_dapm_new_controls(dapm, wsa_macro_dapm_widgets,
- ARRAY_SIZE(wsa_macro_dapm_widgets));
- if (ret < 0) {
- dev_err(wsa_dev, "%s: Failed to add controls\n", __func__);
- return ret;
- }
- ret = snd_soc_dapm_add_routes(dapm, wsa_audio_map,
- ARRAY_SIZE(wsa_audio_map));
- if (ret < 0) {
- dev_err(wsa_dev, "%s: Failed to add routes\n", __func__);
- return ret;
- }
- ret = snd_soc_dapm_new_widgets(dapm->card);
- if (ret < 0) {
- dev_err(wsa_dev, "%s: Failed to add widgets\n", __func__);
- return ret;
- }
- ret = snd_soc_add_component_controls(component, wsa_macro_snd_controls,
- ARRAY_SIZE(wsa_macro_snd_controls));
- if (ret < 0) {
- dev_err(wsa_dev, "%s: Failed to add snd_ctls\n", __func__);
- return ret;
- }
- snd_soc_dapm_ignore_suspend(dapm, "WSA_AIF1 Playback");
- snd_soc_dapm_ignore_suspend(dapm, "WSA_AIF_MIX1 Playback");
- snd_soc_dapm_ignore_suspend(dapm, "WSA_AIF_VI Capture");
- snd_soc_dapm_ignore_suspend(dapm, "WSA_AIF_ECHO Capture");
- snd_soc_dapm_ignore_suspend(dapm, "WSA_SPK1 OUT");
- snd_soc_dapm_ignore_suspend(dapm, "WSA_SPK2 OUT");
- snd_soc_dapm_ignore_suspend(dapm, "VIINPUT_WSA");
- snd_soc_dapm_ignore_suspend(dapm, "WSA SRC0_INP");
- snd_soc_dapm_ignore_suspend(dapm, "WSA_TX DEC0_INP");
- snd_soc_dapm_ignore_suspend(dapm, "WSA_TX DEC1_INP");
- snd_soc_dapm_sync(dapm);
- wsa_priv->component = component;
- wsa_priv->spkr_gain_offset = WSA_MACRO_GAIN_OFFSET_0_DB;
- wsa_macro_init_reg(component);
- return 0;
- }
- static int wsa_macro_deinit(struct snd_soc_component *component)
- {
- struct device *wsa_dev = NULL;
- struct wsa_macro_priv *wsa_priv = NULL;
- if (!wsa_macro_get_data(component, &wsa_dev, &wsa_priv, __func__))
- return -EINVAL;
- wsa_priv->component = NULL;
- return 0;
- }
- static void wsa_macro_add_child_devices(struct work_struct *work)
- {
- struct wsa_macro_priv *wsa_priv;
- struct platform_device *pdev;
- struct device_node *node;
- struct wsa_macro_swr_ctrl_data *swr_ctrl_data = NULL, *temp;
- int ret;
- u16 count = 0, ctrl_num = 0;
- struct wsa_macro_swr_ctrl_platform_data *platdata;
- char plat_dev_name[WSA_MACRO_SWR_STRING_LEN];
- wsa_priv = container_of(work, struct wsa_macro_priv,
- wsa_macro_add_child_devices_work);
- if (!wsa_priv) {
- pr_err("%s: Memory for wsa_priv does not exist\n",
- __func__);
- return;
- }
- if (!wsa_priv->dev || !wsa_priv->dev->of_node) {
- dev_err(wsa_priv->dev,
- "%s: DT node for wsa_priv does not exist\n", __func__);
- return;
- }
- platdata = &wsa_priv->swr_plat_data;
- wsa_priv->child_count = 0;
- for_each_available_child_of_node(wsa_priv->dev->of_node, node) {
- if (strnstr(node->name, "wsa_swr_master",
- strlen("wsa_swr_master")) != NULL)
- strlcpy(plat_dev_name, "wsa_swr_ctrl",
- (WSA_MACRO_SWR_STRING_LEN - 1));
- else if (strnstr(node->name, "msm_cdc_pinctrl",
- strlen("msm_cdc_pinctrl")) != NULL)
- strlcpy(plat_dev_name, node->name,
- (WSA_MACRO_SWR_STRING_LEN - 1));
- else
- continue;
- pdev = platform_device_alloc(plat_dev_name, -1);
- if (!pdev) {
- dev_err(wsa_priv->dev, "%s: pdev memory alloc failed\n",
- __func__);
- ret = -ENOMEM;
- goto err;
- }
- pdev->dev.parent = wsa_priv->dev;
- pdev->dev.of_node = node;
- if (strnstr(node->name, "wsa_swr_master",
- strlen("wsa_swr_master")) != NULL) {
- ret = platform_device_add_data(pdev, platdata,
- sizeof(*platdata));
- if (ret) {
- dev_err(&pdev->dev,
- "%s: cannot add plat data ctrl:%d\n",
- __func__, ctrl_num);
- goto fail_pdev_add;
- }
- temp = krealloc(swr_ctrl_data,
- (ctrl_num + 1) * sizeof(
- struct wsa_macro_swr_ctrl_data),
- GFP_KERNEL);
- if (!temp) {
- dev_err(&pdev->dev, "out of memory\n");
- ret = -ENOMEM;
- goto fail_pdev_add;
- }
- swr_ctrl_data = temp;
- swr_ctrl_data[ctrl_num].wsa_swr_pdev = pdev;
- ctrl_num++;
- dev_dbg(&pdev->dev,
- "%s: Adding soundwire ctrl device(s)\n",
- __func__);
- wsa_priv->swr_ctrl_data = swr_ctrl_data;
- }
- ret = platform_device_add(pdev);
- if (ret) {
- dev_err(&pdev->dev,
- "%s: Cannot add platform device\n",
- __func__);
- goto fail_pdev_add;
- }
- if (wsa_priv->child_count < WSA_MACRO_CHILD_DEVICES_MAX)
- wsa_priv->pdev_child_devices[
- wsa_priv->child_count++] = pdev;
- else
- goto err;
- }
- return;
- fail_pdev_add:
- for (count = 0; count < wsa_priv->child_count; count++)
- platform_device_put(wsa_priv->pdev_child_devices[count]);
- err:
- return;
- }
- static void wsa_macro_init_ops(struct macro_ops *ops,
- char __iomem *wsa_io_base)
- {
- memset(ops, 0, sizeof(struct macro_ops));
- ops->init = wsa_macro_init;
- ops->exit = wsa_macro_deinit;
- ops->io_base = wsa_io_base;
- ops->dai_ptr = wsa_macro_dai;
- ops->num_dais = ARRAY_SIZE(wsa_macro_dai);
- ops->event_handler = wsa_macro_event_handler;
- ops->set_port_map = wsa_macro_set_port_map;
- }
- static int wsa_macro_probe(struct platform_device *pdev)
- {
- struct macro_ops ops;
- struct wsa_macro_priv *wsa_priv;
- u32 wsa_base_addr, default_clk_id;
- char __iomem *wsa_io_base;
- int ret = 0;
- u8 bcl_pmic_params[3];
- u32 is_used_wsa_swr_gpio = 1;
- const char *is_used_wsa_swr_gpio_dt = "qcom,is-used-swr-gpio";
- if (!bolero_is_va_macro_registered(&pdev->dev)) {
- dev_err(&pdev->dev,
- "%s: va-macro not registered yet, defer\n", __func__);
- return -EPROBE_DEFER;
- }
- wsa_priv = devm_kzalloc(&pdev->dev, sizeof(struct wsa_macro_priv),
- GFP_KERNEL);
- if (!wsa_priv)
- return -ENOMEM;
- wsa_priv->dev = &pdev->dev;
- ret = of_property_read_u32(pdev->dev.of_node, "reg",
- &wsa_base_addr);
- if (ret) {
- dev_err(&pdev->dev, "%s: could not find %s entry in dt\n",
- __func__, "reg");
- return ret;
- }
- if (of_find_property(pdev->dev.of_node, is_used_wsa_swr_gpio_dt,
- NULL)) {
- ret = of_property_read_u32(pdev->dev.of_node,
- is_used_wsa_swr_gpio_dt,
- &is_used_wsa_swr_gpio);
- if (ret) {
- dev_err(&pdev->dev, "%s: error reading %s in dt\n",
- __func__, is_used_wsa_swr_gpio_dt);
- is_used_wsa_swr_gpio = 1;
- }
- }
- wsa_priv->wsa_swr_gpio_p = of_parse_phandle(pdev->dev.of_node,
- "qcom,wsa-swr-gpios", 0);
- if (!wsa_priv->wsa_swr_gpio_p && is_used_wsa_swr_gpio) {
- dev_err(&pdev->dev, "%s: swr_gpios handle not provided!\n",
- __func__);
- return -EINVAL;
- }
- if (msm_cdc_pinctrl_get_state(wsa_priv->wsa_swr_gpio_p) < 0 &&
- is_used_wsa_swr_gpio) {
- dev_err(&pdev->dev, "%s: failed to get swr pin state\n",
- __func__);
- return -EPROBE_DEFER;
- }
- msm_cdc_pinctrl_set_wakeup_capable(
- wsa_priv->wsa_swr_gpio_p, false);
- wsa_io_base = devm_ioremap(&pdev->dev,
- wsa_base_addr, WSA_MACRO_MAX_OFFSET);
- if (!wsa_io_base) {
- dev_err(&pdev->dev, "%s: ioremap failed\n", __func__);
- return -EINVAL;
- }
- wsa_priv->wsa_io_base = wsa_io_base;
- wsa_priv->reset_swr = true;
- INIT_WORK(&wsa_priv->wsa_macro_add_child_devices_work,
- wsa_macro_add_child_devices);
- wsa_priv->swr_plat_data.handle = (void *) wsa_priv;
- wsa_priv->swr_plat_data.read = NULL;
- wsa_priv->swr_plat_data.write = NULL;
- wsa_priv->swr_plat_data.bulk_write = NULL;
- wsa_priv->swr_plat_data.clk = wsa_swrm_clock;
- wsa_priv->swr_plat_data.core_vote = wsa_macro_core_vote;
- wsa_priv->swr_plat_data.handle_irq = NULL;
- ret = of_property_read_u32(pdev->dev.of_node, "qcom,default-clk-id",
- &default_clk_id);
- if (ret) {
- dev_err(&pdev->dev, "%s: could not find %s entry in dt\n",
- __func__, "qcom,mux0-clk-id");
- default_clk_id = WSA_CORE_CLK;
- }
- ret = of_property_read_u8_array(pdev->dev.of_node,
- "qcom,wsa-bcl-pmic-params", bcl_pmic_params,
- sizeof(bcl_pmic_params));
- if (ret) {
- dev_dbg(&pdev->dev, "%s: could not find %s entry in dt\n",
- __func__, "qcom,wsa-bcl-pmic-params");
- } else {
- wsa_priv->bcl_pmic_params.id = bcl_pmic_params[0];
- wsa_priv->bcl_pmic_params.sid = bcl_pmic_params[1];
- wsa_priv->bcl_pmic_params.ppid = bcl_pmic_params[2];
- }
- wsa_priv->default_clk_id = default_clk_id;
- dev_set_drvdata(&pdev->dev, wsa_priv);
- mutex_init(&wsa_priv->mclk_lock);
- mutex_init(&wsa_priv->swr_clk_lock);
- wsa_macro_init_ops(&ops, wsa_io_base);
- ops.clk_id_req = wsa_priv->default_clk_id;
- ops.default_clk_id = wsa_priv->default_clk_id;
- ret = bolero_register_macro(&pdev->dev, WSA_MACRO, &ops);
- if (ret < 0) {
- dev_err(&pdev->dev, "%s: register macro failed\n", __func__);
- goto reg_macro_fail;
- }
- pm_runtime_set_autosuspend_delay(&pdev->dev, AUTO_SUSPEND_DELAY);
- pm_runtime_use_autosuspend(&pdev->dev);
- pm_runtime_set_suspended(&pdev->dev);
- pm_suspend_ignore_children(&pdev->dev, true);
- pm_runtime_enable(&pdev->dev);
- schedule_work(&wsa_priv->wsa_macro_add_child_devices_work);
- return ret;
- reg_macro_fail:
- mutex_destroy(&wsa_priv->mclk_lock);
- mutex_destroy(&wsa_priv->swr_clk_lock);
- return ret;
- }
- static int wsa_macro_remove(struct platform_device *pdev)
- {
- struct wsa_macro_priv *wsa_priv;
- u16 count = 0;
- wsa_priv = dev_get_drvdata(&pdev->dev);
- if (!wsa_priv)
- return -EINVAL;
- for (count = 0; count < wsa_priv->child_count &&
- count < WSA_MACRO_CHILD_DEVICES_MAX; count++)
- platform_device_unregister(wsa_priv->pdev_child_devices[count]);
- pm_runtime_disable(&pdev->dev);
- pm_runtime_set_suspended(&pdev->dev);
- bolero_unregister_macro(&pdev->dev, WSA_MACRO);
- mutex_destroy(&wsa_priv->mclk_lock);
- mutex_destroy(&wsa_priv->swr_clk_lock);
- return 0;
- }
- static const struct of_device_id wsa_macro_dt_match[] = {
- {.compatible = "qcom,wsa-macro"},
- {}
- };
- static const struct dev_pm_ops bolero_dev_pm_ops = {
- SET_SYSTEM_SLEEP_PM_OPS(
- pm_runtime_force_suspend,
- pm_runtime_force_resume
- )
- SET_RUNTIME_PM_OPS(
- bolero_runtime_suspend,
- bolero_runtime_resume,
- NULL
- )
- };
- static struct platform_driver wsa_macro_driver = {
- .driver = {
- .name = "wsa_macro",
- .owner = THIS_MODULE,
- .pm = &bolero_dev_pm_ops,
- .of_match_table = wsa_macro_dt_match,
- .suppress_bind_attrs = true,
- },
- .probe = wsa_macro_probe,
- .remove = wsa_macro_remove,
- };
- module_platform_driver(wsa_macro_driver);
- MODULE_DESCRIPTION("WSA macro driver");
- MODULE_LICENSE("GPL v2");
|