es325.c 121 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037
  1. /*
  2. * es325.c -- Audience eS325 ALSA SoC Audio driver
  3. *
  4. * Copyright 2011 Audience, Inc.
  5. *
  6. * Author: Greg Clemson <gclemson@audience.com>
  7. *
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. *
  13. * 1.05 Genisim Tsilker <gtsilker@audience.com>
  14. * - Combine SLIMBus Request - Response (Read - Write)
  15. * in es325_request_response function.
  16. * - Flexible waiting time for es325 response (up to 20 ms).
  17. * - Flexible waiting time for es325 sleep / wakeup (up to 20 ms).
  18. * - In case of sequential "slim_control_ch" requests only last one
  19. * commits "slim_control_ch" (SLIMBus reconfiguration).
  20. * - Add support for DTS (Device Tree Source)
  21. * - Remove unused comments.
  22. * - Remove code related to i2c / i2s supports.
  23. */
  24. #define BUS_TRANSACTIONS
  25. /* Enable FIXED_CONFIG when eS325 is using for Play Back mode */
  26. /* #define FIXED_CONFIG */
  27. #define ES325_SLEEP /* To support sleep/wakeup for ES325 */
  28. #include <linux/module.h>
  29. #include <linux/moduleparam.h>
  30. #include <linux/init.h>
  31. #include <linux/firmware.h>
  32. #include <linux/delay.h>
  33. #include <linux/pm.h>
  34. #include <linux/completion.h>
  35. #include <linux/slimbus/slimbus.h>
  36. #include <linux/gpio.h>
  37. #include <linux/platform_device.h>
  38. #include <linux/regulator/consumer.h>
  39. #include <linux/slab.h>
  40. #include <linux/err.h>
  41. #include <sound/core.h>
  42. #include <sound/pcm.h>
  43. #include <sound/pcm_params.h>
  44. #include <sound/soc.h>
  45. #include <sound/soc-dapm.h>
  46. #include <sound/initval.h>
  47. #include <sound/tlv.h>
  48. #include <linux/kthread.h>
  49. #include <asm/system_info.h>
  50. #ifdef ES325_SLEEP
  51. #include <linux/device.h>
  52. #include <linux/mutex.h>
  53. #include <linux/slimbus/slimbus.h>
  54. #include <linux/timer.h>
  55. #include <linux/workqueue.h>
  56. #endif
  57. #include <linux/vmalloc.h>
  58. #include <linux/file.h>
  59. #include <linux/fs.h>
  60. #include <generated/utsrelease.h>
  61. #include <linux/esxxx.h> /* TODO: common location for i2c and slimbus */
  62. #include "es325.h"
  63. #include "es325-export.h"
  64. #include <linux/clk.h>
  65. #include <linux/of_gpio.h>
  66. #ifdef CONFIG_SND_SOC_ES325_SLIM
  67. #define PREVENT_SLIMBUS_SLEEP_IN_FW_DL
  68. #endif
  69. #define ES325_CMD_ACCESS_WR_MAX 4
  70. #define ES325_CMD_ACCESS_RD_MAX 4
  71. struct es325_cmd_access {
  72. u8 read_msg[ES325_CMD_ACCESS_RD_MAX];
  73. unsigned int read_msg_len;
  74. u8 write_msg[ES325_CMD_ACCESS_WR_MAX];
  75. unsigned int write_msg_len;
  76. unsigned int val_shift;
  77. unsigned int val_max;
  78. };
  79. #include "es325-access.h"
  80. #define ES325_SLIM_CH_RX_OFFSET 152
  81. #define ES325_SLIM_CH_TX_OFFSET 156
  82. #define ES325_SLIM_RX_PORTS 6
  83. #define ES325_SLIM_TX_PORTS 6
  84. #define ES325_SLIM_1_PB 0
  85. #define ES325_SLIM_1_CAP 1
  86. #define ES325_SLIM_2_PB 2
  87. #define ES325_SLIM_2_CAP 3
  88. #define ES325_SLIM_3_PB 4
  89. #define ES325_SLIM_3_CAP 5
  90. #define ES325_SLIM_1_PB_MAX_CHANS 2
  91. #define ES325_SLIM_1_CAP_MAX_CHANS 2
  92. #define ES325_SLIM_2_PB_MAX_CHANS 2
  93. #define ES325_SLIM_2_CAP_MAX_CHANS 2
  94. #define ES325_SLIM_3_PB_MAX_CHANS 2
  95. #define ES325_SLIM_3_CAP_MAX_CHANS 2
  96. #define ES325_SLIM_1_PB_OFFSET 0
  97. #define ES325_SLIM_2_PB_OFFSET 2
  98. #define ES325_SLIM_3_PB_OFFSET 4
  99. #define ES325_SLIM_1_CAP_OFFSET 0
  100. #define ES325_SLIM_2_CAP_OFFSET 2
  101. #define ES325_SLIM_3_CAP_OFFSET 4
  102. #define NARROW_BAND 0
  103. #define WIDE_BAND 1
  104. #define NETWORK_OFFSET 21
  105. #define ES325_NUM_CODEC_SLIM_DAIS 6
  106. int debug_for_dl_firmware = 0;
  107. enum {
  108. BOOT_OK = 0,
  109. BOOT_MSG_ERR,
  110. BOOT_MSG_NACK,
  111. SYNC_MSG_NACK
  112. };
  113. struct es325_slim_dai_data {
  114. unsigned int rate;
  115. unsigned int *ch_num;
  116. unsigned int ch_act;
  117. unsigned int ch_tot;
  118. #ifdef ES325_SLEEP
  119. unsigned int ch_wakeup;
  120. #endif
  121. };
  122. struct es325_slim_ch {
  123. u32 sph;
  124. u32 ch_num;
  125. u16 ch_h;
  126. u16 grph;
  127. };
  128. #define ID(id) (id)
  129. #define ES325_MAX_INVALID_VEQ 0xFFFF
  130. #define ES325_MAX_INVALID_BWE 0xFFFF
  131. #define ES325_MAX_INVALID_TX_NS 0xFFFF
  132. static unsigned int es325_VEQ_enable = ES325_MAX_INVALID_VEQ;
  133. static unsigned int es325_VEQ_enable_new = ES325_MAX_INVALID_VEQ;
  134. static unsigned int es325_BWE_enable = ES325_MAX_INVALID_BWE;
  135. static unsigned int es325_BWE_enable_new = ES325_MAX_INVALID_BWE;
  136. static unsigned int es325_Tx_NS = ES325_MAX_INVALID_TX_NS;
  137. static unsigned int es325_Tx_NS_new = ES325_MAX_INVALID_TX_NS;
  138. #if defined(PREVENT_SLIMBUS_SLEEP_IN_FW_DL)
  139. extern void msm_slim_es325_write_flag_set(int flag);
  140. #endif
  141. /* codec private data */
  142. struct es325_priv {
  143. struct snd_soc_codec *codec;
  144. struct firmware *fw;
  145. struct esxxx_platform_data *pdata;
  146. struct slim_device *intf_client;
  147. struct slim_device *gen0_client;
  148. struct es325_slim_dai_data dai[ES325_NUM_CODEC_SLIM_DAIS];
  149. struct es325_slim_ch slim_rx[ES325_SLIM_RX_PORTS];
  150. struct es325_slim_ch slim_tx[ES325_SLIM_TX_PORTS];
  151. struct mutex wakeup_mutex;
  152. #ifdef ES325_SLEEP
  153. struct mutex pm_mutex; /* Mutex for protecting data structure */
  154. int wakeup_cnt; /* sleep and wakeup count, when reached to 0,
  155. start sleep timer */
  156. int clock_on; /* es325 clock status */
  157. int internal_route_config; /* last configured route config */
  158. int new_internal_route_config; /* new received route config via KControl,
  159. it is written when hw param is received */
  160. int wq_active; /* sleep timer status */
  161. #endif
  162. } es325_priv;
  163. static unsigned int es325_ap_tx1_ch_cnt = 1;
  164. unsigned int es325_tx1_route_enable;
  165. unsigned int es325_rx1_route_enable;
  166. unsigned int es325_rx2_route_enable;
  167. unsigned int FW_not_ready = 1;
  168. static unsigned int uart_enable = 0;
  169. static int es325_slim_rx_port_to_ch[ES325_SLIM_RX_PORTS] = {
  170. 152, 153, 154, 155, 134, 135
  171. };
  172. static int es325_slim_tx_port_to_ch[ES325_SLIM_TX_PORTS] = {
  173. 156, 157, 144, 145, 144, 145
  174. };
  175. static int es325_slim_be_id[ES325_NUM_CODEC_SLIM_DAIS] = {
  176. ES325_SLIM_2_CAP, /* for ES325_SLIM_1_PB tx from es325 */
  177. ES325_SLIM_3_PB, /* for ES325_SLIM_1_CAP rx to es325 */
  178. ES325_SLIM_3_CAP, /* for ES325_SLIM_2_PB tx from es325 */
  179. -1, /* for ES325_SLIM_2_CAP */
  180. -1, /* for ES325_SLIM_3_PB */
  181. -1, /* for ES325_SLIM_3_CAP */
  182. };
  183. #define ES325_INTERNAL_ROUTE_MAX 26
  184. static long es325_internal_route_num;
  185. static int es325_network_type = NARROW_BAND;
  186. /* Audio playback, 1 channel */
  187. static u8 es325_internal_route_audio_playback_1ch[10] = {
  188. 0x90, 0x31, 0x00, 0x07, /* 1 Ch playback 4 Ch pass */
  189. 0x90, 0x31, 0x00, 0x46, /* Algo Preset for 1 Ch playback 4 Ch pass */
  190. 0xff /* terminate */
  191. };
  192. /* Audio playback, 2 channels */
  193. static u8 es325_internal_route_audio_playback_2ch[10] = {
  194. 0x90, 0x31, 0x00, 0x08, /* 2 Ch playback 4 Ch pass */
  195. 0x90, 0x31, 0x00, 0x50, /* Algo Preset for 2 Ch playback 4 Ch pass */
  196. 0xff /* terminate */
  197. };
  198. /* 1-mic Headset NB (SW bypss)*/
  199. static u8 es325_internal_route_1mic_headset[10] = {
  200. 0x90, 0x31, 0x00, 0x01, /* 1 Mic 2 FEOUT MD */
  201. 0x90, 0x31, 0x00, 0x84, /* Algo Preset: 1-mic CT NB */
  202. 0xff /* terminate */
  203. };
  204. /* 1-mic Headset WB (SW bypss)*/
  205. static u8 es325_internal_route_1mic_headset_WB[10] = {
  206. 0x90, 0x31, 0x00, 0x01, /* 1 Mic 2 FEOUT MD */
  207. 0x90, 0x31, 0x00, 0x85, /* Algo Preset: 1-mic CT WB */
  208. 0xff /* terminate */
  209. };
  210. /* 1-mic Speaker NB (1-mic FT)(NS off)(SW bypss) */
  211. static u8 es325_internal_route_1mic_speaker[10] = {
  212. 0x90, 0x31, 0x00, 0x0c, /* 1 Mic 1 FEOUT */
  213. 0x90, 0x31, 0x00, 0x82, /* Algo Preset: 1-mic CT NB */
  214. 0xff /* terminate */
  215. };
  216. /* 1-mic Speaker WB (1-mic FT)(NS off)(SW bypss) */
  217. static u8 es325_internal_route_1mic_speaker_WB[10] = {
  218. 0x90, 0x31, 0x00, 0x0c, /* 1 Mic 1 FEOUT */
  219. 0x90, 0x31, 0x00, 0x83, /* Algo Preset: 1-mic CT WB */
  220. 0xff /* terminate */
  221. };
  222. /* 2-mic Speaker NB (2-mic FT)(NS on) */
  223. static u8 es325_internal_route_2mic_speaker[10] = {
  224. 0x90, 0x31, 0x00, 0x02, /* 2 Mic 1 FEOUT CT */
  225. 0x90, 0x31, 0x00, 0x16, /* Algo Preset for 2 Mic FT NB */
  226. 0xff /* terminate */
  227. };
  228. /* 2-mic Speaker WB (2-mic FT)(NS off) */
  229. static u8 es325_internal_route_2mic_speaker_WB[10] = {
  230. 0x90, 0x31, 0x00, 0x02, /* 2 Mic 1 FEOUT CT */
  231. 0x90, 0x31, 0x00, 0x17, /* Algo Preset for 2 Mic FT WB */
  232. 0xff /* terminate */
  233. };
  234. /* 1-mic Handset NB (1-mic CT)(NS off) */
  235. static u8 es325_internal_route_1mic_handset[10] = {
  236. 0x90, 0x31, 0x00, 0x02, /* 2 Mic 1 FEOUT CT */
  237. 0x90, 0x31, 0x00, 0x18, /* Algo Preset for 2 Mic CT NB */
  238. 0xff /* terminate */
  239. };
  240. /* 1-mic Handset WB (1-mic CT)(NS off) */
  241. static u8 es325_internal_route_1mic_handset_WB[10] = {
  242. 0x90, 0x31, 0x00, 0x02, /* 2 Mic 1 FEOUT CT */
  243. 0x90, 0x31, 0x00, 0x19, /* Algo Preset for 2 Mic CT WB */
  244. 0xff /* terminate */
  245. };
  246. /* 2-mic Handset NB (2-mic CT)(NS on) */
  247. static u8 es325_internal_route_2mic_handset[10] = {
  248. 0x90, 0x31, 0x00, 0x02, /* 2 Mic 1 FEOUT CT */
  249. 0x90, 0x31, 0x00, 0x14, /* Algo Preset for 2 Mic CT NB */
  250. 0xff /* terminate */
  251. };
  252. /* 2-mic Handset WB (2-mic CT)(NS on) */
  253. static u8 es325_internal_route_2mic_handset_WB[10] = {
  254. 0x90, 0x31, 0x00, 0x02, /* 2 Mic 1 FEOUT CT */
  255. 0x90, 0x31, 0x00, 0x15, /* Algo Preset for 2 Mic CT WB */
  256. 0xff /* terminate */
  257. };
  258. /* 1-mic 1-output for Loopback (CT SW bypss) */
  259. static u8 es325_internal_route_rcv_loopback[10] = {
  260. 0x90, 0x31, 0x00, 0x03, /* 1 Mic 1 FEOUT */
  261. 0x90, 0x31, 0x00, 0x83, /* Algo Preset: 1-mic CT WB */
  262. 0xff /* terminate */
  263. };
  264. /* 1-mic 1-output for Loopback (FT SW bypss) */
  265. static u8 es325_internal_route_spk_loopback[10] = {
  266. 0x90, 0x31, 0x00, 0x03, /* 1 Mic 1 FEOUT */
  267. 0x90, 0x31, 0x00, 0x83, /* Algo Preset: 1-mic FT WB */
  268. 0xff /* terminate */
  269. };
  270. /* 1-mic 2-output for Loopback (SW bypss) */
  271. static u8 es325_internal_route_headset_loopback[10] = {
  272. 0x90, 0x31, 0x00, 0x01, /* 1 Mic 2 FEOUT MD */
  273. 0x90, 0x31, 0x00, 0x85, /* Algo Preset: 1-mic WB */
  274. 0xff /* terminate */
  275. };
  276. /* 2-mic ASR */
  277. static u8 es325_internal_route_2mic_ASR[10] = {
  278. 0x90, 0x31, 0x00, 0x6E, /* 2 Mic ASR WB */
  279. 0x90, 0x31, 0x00, 0x70, /* Algo Preset for 2 Mic ASR WB */
  280. 0xff /* terminate */
  281. };
  282. /* TTY HCO - Rx:Handset(1ch), Tx: Main mic(1ch)(SW bypass)*/
  283. static u8 es325_internal_route_TTY_HCO[10] = {
  284. 0x90, 0x31, 0x00, 0x0d, /* 1 Mic 1 FEOUT */
  285. 0x90, 0x31, 0x00, 0x84, /* Algo Preset: 1-mic CT NB */
  286. 0xff /* terminate */
  287. };
  288. /* TTY VCO - Rx:Headset(2ch), Tx: Main mic(1ch)(SW bypass)*/
  289. static u8 es325_internal_route_TTY_VCO[10] = {
  290. 0x90, 0x31, 0x00, 0x01, /* 1 Mic 2 FEOUT MD */
  291. 0x90, 0x31, 0x00, 0x84, /* Algo Preset: 1-mic CT NB */
  292. 0xff /* terminate */
  293. };
  294. /* Audio playback, 1 channel */
  295. static u8 dummy[10] = {
  296. 0x90, 0x31, 0x00, 0x07, /* 1 Ch playback 4 Ch pass */
  297. 0x90, 0x31, 0x00, 0x46, /* Algo Preset for 1 Ch playback 4 Ch pass */
  298. 0xff /* terminate */
  299. };
  300. static u8 es325_internal_route_interview[10] = {
  301. 0x90, 0x31, 0x00, 0x6E,
  302. 0x90, 0x31, 0x00, 0x41, /* 1 Mic 2 FEOUT MD */
  303. 0xff /* terminate */
  304. };
  305. static u8 es325_internal_route_conversation[10] = {
  306. 0x90, 0x31, 0x00, 0x6E,
  307. 0x90, 0x31, 0x00, 0x42, /* 1 Mic 2 FEOUT MD */
  308. 0xff /* terminate */
  309. };
  310. static u8* es325_internal_route_configs[ES325_INTERNAL_ROUTE_MAX] = {
  311. es325_internal_route_1mic_headset, /* [0]: 1-mic Headset NB (SW bypss) */
  312. es325_internal_route_2mic_speaker, /* [1]: 2-mic Speaker NB (2-mic FT)(NS on)*/
  313. es325_internal_route_2mic_handset, /* [2]: 2-mic Handset NB (2-mic CT)(NS on) */
  314. es325_internal_route_1mic_speaker, /* [3]: 1-mic Speaker NB (1-mic FT)(NS off)(SW bypss) */
  315. es325_internal_route_1mic_handset, /* [4]: 1-mic Handset NB (1-mic CT)(NS off) */
  316. es325_internal_route_audio_playback_1ch,/* [5]: Audio playback, 1 channel */
  317. es325_internal_route_audio_playback_2ch,/* [6]: Audio playback, 2 channels */
  318. es325_internal_route_interview, /* [7]: TBD */
  319. es325_internal_route_conversation, /* [8]: TBD */
  320. dummy, /* [9]: TBD */
  321. dummy, /* [10]: TBD */
  322. es325_internal_route_TTY_VCO, /* [11]: TTY VCO - Rx:Headset(2ch), Tx: Main mic(1ch)(SW bypass) */
  323. es325_internal_route_TTY_HCO, /* [12]: TTY HCO - Rx:Handset(1ch), Tx: Main mic(1ch)(SW bypass) */
  324. es325_internal_route_2mic_ASR, /* [13]: 2-mic ASR */
  325. dummy, /* [14]: TBD */
  326. dummy, /* [15]: TBD */
  327. dummy, /* [16]: TBD */
  328. es325_internal_route_rcv_loopback,/* [17]: 1-mic 1-output for Loopback (CT SW bypss) */
  329. es325_internal_route_spk_loopback,/* [18]: 1-mic 1-output for Loopback (FT SW bypss) */
  330. es325_internal_route_headset_loopback,/* [19]: 1-mic 2-output for Loopback (SW bypss) */
  331. dummy, /* [20]: TBD */
  332. es325_internal_route_1mic_headset_WB, /* [21]: 1-mic Headset WB (SW bypss) */
  333. es325_internal_route_2mic_speaker_WB, /* [22]: 2-mic Speaker WB (2-mic FT)(NS on) */
  334. es325_internal_route_2mic_handset_WB, /* [23]: 2-mic Handset WB (2-mic CT)(NS on) */
  335. es325_internal_route_1mic_speaker_WB, /* [24]: 1-mic Speaker WB (1-mic FT)(NS off)(SW bypss) */
  336. es325_internal_route_1mic_handset_WB, /* [25]: 1-mic Handset WB (1-mic CT)(NS off) */
  337. };
  338. #ifdef NOT_USED_CONFIG
  339. /* [3]: 1-mic VOIP (CT) */
  340. {
  341. 0x90, 0x31, 0x00, 0x03, /* 1 Mic 1 FEOUT */
  342. 0x90, 0x31, 0x00, 0x1E, /* Algo Preset for 1 Mic VOIP DV SWB */
  343. 0xff /* terminate */
  344. },
  345. /* [4]: 2-mic VOIP (CT) */
  346. {
  347. 0x90, 0x31, 0x00, 0x04, /* 2 Mic 1 FEOUT */
  348. 0x90, 0x31, 0x00, 0x29, /* Algo Preset for 2 Mic VOIP CT WB */
  349. 0xff /* terminate */
  350. },
  351. /* [5]: Audio playback, 1 channel */
  352. {
  353. 0x90, 0x31, 0x00, 0x07, /* 1 Ch playback 4 Ch pass */
  354. 0x90, 0x31, 0x00, 0x46, /* Algo Preset for 1 Ch playback 4 Ch pass */
  355. 0xff /* terminate */
  356. },
  357. /* [7]: Audio record, 1 channel */
  358. {
  359. 0x90, 0x31, 0x00, 0x09, /* 1 Ch Record 4 Ch pass */
  360. 0x90, 0x31, 0x00, 0x5A, /* Algo Preset for 1 Ch Record 4 Ch pass */
  361. 0xff /* terminate */
  362. },
  363. /* [8]: Audio record, 2 channels */
  364. {
  365. 0x90, 0x31, 0x00, 0x65, /* 2 Ch Record 4 Ch pass */
  366. 0x90, 0x31, 0x00, 0x64, /* Algo Preset for 2 Ch Record 4 Ch pass */
  367. 0xff /* terminate */
  368. },
  369. /* [9]: 2-mic CT ASR */
  370. {
  371. 0x90, 0x31, 0x00, 0x06, /* 2 Mic ASR */
  372. 0x90, 0x31, 0x00, 0x3C, /* Algo Preset for 2 Mic ASR NB */
  373. 0xff /* terminate */
  374. },
  375. /* [10]: 1-mic External ASR */
  376. {
  377. 0x90, 0x31, 0x00, 0x05, /* 1 Mic ASR */
  378. 0x90, 0x31, 0x00, 0x32, /* Algo Preset for 1 Mic ASR NB */
  379. 0xff /* terminate */
  380. },
  381. /* [11]: VOIP Headset(CT) */
  382. {
  383. 0x90, 0x31, 0x00, 0x01, /* 1 Mic Headset */
  384. 0x90, 0x31, 0x00, 0x0b, /* Algo Preset for WB */
  385. 0xff /* terminate */
  386. },
  387. /* [14]: 1-mic DV ASR WB */
  388. {
  389. 0x90, 0x31, 0x00, 0x71, /* 1 Mic DV ASR WB */
  390. 0x90, 0x31, 0x00, 0x73, /* Algo Preset for 1 Mic ASR DV WB */
  391. 0xff /* terminate */
  392. },
  393. /* [15]: 1-mic FT */
  394. {
  395. 0x90, 0x31, 0x00, 0x0c, /* 1 Mic FT */
  396. 0x90, 0x31, 0x00, 0x16, /* Algo Preset for 2 Mic FT */
  397. /* TODO Switch to Algo Preset for 1 Mic FT after testing */
  398. 0xff /* terminate */
  399. },
  400. /* [16]: 1-mic FT WB */
  401. {
  402. 0x90, 0x31, 0x00, 0x0c, /* 1 Mic FT WB */
  403. 0x90, 0x31, 0x00, 0x17, /* Algo Preset for 2 Mic FT WB */
  404. /* TODO Switch to Algo Preset for 1 Mic FT after testing */
  405. 0xff /* terminate */
  406. },
  407. #endif
  408. static struct snd_soc_dai_driver es325_dai[];
  409. #ifdef ES325_SLEEP
  410. void es325_wrapper_sleep_internal(struct work_struct *dummy);
  411. #endif
  412. #ifdef FIXED_CONFIG
  413. static void es325_fixed_config(struct es325_priv *es325);
  414. #endif
  415. static void es325_alloc_slim_rx_chan(struct slim_device *sbdev);
  416. static void es325_alloc_slim_tx_chan(struct slim_device *sbdev);
  417. static int es325_cfg_slim_rx(struct slim_device *sbdev, unsigned int *ch_num,
  418. unsigned int ch_cnt, unsigned int rate, bool commit);
  419. static int es325_cfg_slim_tx(struct slim_device *sbdev, unsigned int *ch_num,
  420. unsigned int ch_cnt, unsigned int rate, bool commit);
  421. static int es325_close_slim_rx(struct slim_device *sbdev, unsigned int *ch_num,
  422. unsigned int ch_cnt);
  423. static int es325_close_slim_tx(struct slim_device *sbdev, unsigned int *ch_num,
  424. unsigned int ch_cnt);
  425. static int es325_rx_ch_num_to_idx(int ch_num);
  426. static int es325_tx_ch_num_to_idx(int ch_num);
  427. static void es325_update_VEQ_enable(void);
  428. static struct platform_device msm_es325_mclk_dev = {
  429. .name = "es325_mclk_dev_pdev",
  430. .id = -1,
  431. .dev = {
  432. .init_name = "es325_mclk_dev",
  433. },
  434. };
  435. static int es325_enable_ext_clk(int enable)
  436. {
  437. int r = 0;
  438. static struct clk *es325_codec_clk;
  439. pr_info("%s: enable=%d\n", __func__, enable);
  440. if (!es325_codec_clk) {
  441. pr_info("%s: clk_get osr_clk\n", __func__);
  442. es325_codec_clk = clk_get(&msm_es325_mclk_dev.dev, "osr_clk");
  443. }
  444. if (enable) {
  445. clk_prepare_enable(es325_codec_clk);
  446. } else {
  447. clk_disable_unprepare(es325_codec_clk);
  448. clk_put(es325_codec_clk);
  449. es325_codec_clk = NULL;
  450. }
  451. return r;
  452. }
  453. static int es325_rx_ch_num_to_idx(int ch_num)
  454. {
  455. int i;
  456. int idx = -1;
  457. for (i = 0; i < ES325_SLIM_RX_PORTS; i++) {
  458. if (ch_num == es325_slim_rx_port_to_ch[i]) {
  459. idx = i;
  460. break;
  461. }
  462. }
  463. return idx;
  464. }
  465. static int es325_tx_ch_num_to_idx(int ch_num)
  466. {
  467. int i;
  468. int idx = -1;
  469. for (i = 0; i < ES325_SLIM_TX_PORTS; i++) {
  470. if (ch_num == es325_slim_tx_port_to_ch[i]) {
  471. idx = i;
  472. break;
  473. }
  474. }
  475. return idx;
  476. }
  477. /* es325 -> codec - alsa playback function */
  478. static int es325_codec_cfg_slim_tx(struct es325_priv *es325, int dai_id, bool commit)
  479. {
  480. int rc;
  481. /* start slim channels associated with id */
  482. rc = es325_cfg_slim_tx(es325->gen0_client, es325->dai[ID(dai_id)].ch_num,
  483. es325->dai[ID(dai_id)].ch_tot, es325->dai[ID(dai_id)].rate, commit);
  484. return rc;
  485. }
  486. /* es325 <- codec - alsa capture function */
  487. static int es325_codec_cfg_slim_rx(struct es325_priv *es325, int dai_id, bool commit)
  488. {
  489. int rc;
  490. /* start slim channels associated with id */
  491. rc = es325_cfg_slim_rx(es325->gen0_client, es325->dai[ID(dai_id)].ch_num,
  492. es325->dai[ID(dai_id)].ch_tot, es325->dai[ID(dai_id)].rate, commit);
  493. return rc;
  494. }
  495. /* es325 -> codec - alsa playback function */
  496. static int es325_codec_close_slim_tx(struct es325_priv *es325, int dai_id)
  497. {
  498. int rc;
  499. /* close slim channels associated with id */
  500. rc = es325_close_slim_tx(es325->gen0_client,
  501. es325->dai[ID(dai_id)].ch_num, es325->dai[ID(dai_id)].ch_tot);
  502. return rc;
  503. }
  504. /* es325 <- codec - alsa capture function */
  505. static int es325_codec_close_slim_rx(struct es325_priv *es325, int dai_id)
  506. {
  507. int rc;
  508. /* close slim channels associated with id */
  509. rc = es325_close_slim_rx(es325->gen0_client,
  510. es325->dai[ID(dai_id)].ch_num, es325->dai[ID(dai_id)].ch_tot);
  511. return rc;
  512. }
  513. static void es325_alloc_slim_rx_chan(struct slim_device *sbdev)
  514. {
  515. struct es325_priv *es325_priv = slim_get_devicedata(sbdev);
  516. struct es325_slim_ch *rx = es325_priv->slim_rx;
  517. int i;
  518. int port_id;
  519. dev_dbg(&sbdev->dev, "+[ES325]=%s()\n", __func__);
  520. for (i = 0; i < ES325_SLIM_RX_PORTS; i++) {
  521. port_id = i;
  522. rx[i].ch_num = es325_slim_rx_port_to_ch[i];
  523. slim_get_slaveport(sbdev->laddr, port_id, &rx[i].sph, SLIM_SINK);
  524. slim_query_ch(sbdev, rx[i].ch_num, &rx[i].ch_h);
  525. dev_dbg(&sbdev->dev,
  526. "=[ES325]=%s(): port_id = %d, ch_num = %d, sph = 0x%08x\n",
  527. __func__, port_id, rx[i].ch_num, rx[i].sph);
  528. }
  529. dev_dbg(&sbdev->dev, "-[ES325]=%s()\n", __func__);
  530. }
  531. static void es325_alloc_slim_tx_chan(struct slim_device *sbdev)
  532. {
  533. struct es325_priv *es325_priv = slim_get_devicedata(sbdev);
  534. struct es325_slim_ch *tx = es325_priv->slim_tx;
  535. int i;
  536. int port_id;
  537. dev_dbg(&sbdev->dev, "+[ES325]=%s()\n", __func__);
  538. for (i = 0; i < ES325_SLIM_TX_PORTS; i++) {
  539. port_id = i + 10; /* ES325_SLIM_RX_PORTS; */
  540. tx[i].ch_num = es325_slim_tx_port_to_ch[i];
  541. slim_get_slaveport(sbdev->laddr, port_id, &tx[i].sph, SLIM_SRC);
  542. slim_query_ch(sbdev, tx[i].ch_num, &tx[i].ch_h);
  543. dev_dbg(&sbdev->dev,
  544. "=[ES325]=%s(): port_id = %d, ch_num = %d, sph = 0x%08x\n",
  545. __func__, port_id, tx[i].ch_num, tx[i].sph);
  546. }
  547. dev_dbg(&sbdev->dev, "-[ES325]=%s()\n", __func__);
  548. }
  549. static int es325_cfg_slim_rx(struct slim_device *sbdev, unsigned int *ch_num,
  550. unsigned int ch_cnt, unsigned int rate, bool commit)
  551. {
  552. struct es325_priv *es325_priv = slim_get_devicedata(sbdev);
  553. struct es325_slim_ch *rx = es325_priv->slim_rx;
  554. u16 grph;
  555. u32 sph[ES325_SLIM_RX_PORTS] = {0};
  556. u16 ch_h[ES325_SLIM_RX_PORTS] = {0};
  557. struct slim_ch prop;
  558. int i;
  559. int idx;
  560. int rc;
  561. dev_dbg(&sbdev->dev, "+[ES325]=%s()\n", __func__);
  562. dev_dbg(&sbdev->dev, "=[ES325]=%s(): ch_cnt = %d, rate = %d\n",
  563. __func__, ch_cnt, rate);
  564. for (i = 0; i < ch_cnt; i++) {
  565. idx = es325_rx_ch_num_to_idx(ch_num[i]);
  566. ch_h[i] = rx[idx].ch_h;
  567. sph[i] = rx[idx].sph;
  568. dev_dbg(&sbdev->dev,
  569. "=[ES325]=%s(): idx = %d, ch_num[i] = %d, ch_h[i] = %d, sph[i] = 0x%08x\n",
  570. __func__, idx, ch_num[i], ch_h[i], sph[i]);
  571. }
  572. prop.prot = SLIM_AUTO_ISO;
  573. prop.baser = SLIM_RATE_4000HZ;
  574. prop.dataf = SLIM_CH_DATAF_NOT_DEFINED;
  575. prop.auxf = SLIM_CH_AUXF_NOT_APPLICABLE;
  576. prop.ratem = (rate/4000);
  577. prop.sampleszbits = 16;
  578. rc = slim_define_ch(sbdev, &prop, ch_h, ch_cnt, true, &grph);
  579. if (rc < 0) {
  580. dev_err(&sbdev->dev, "=[ES325]=%s(): slim_define_ch() failed: %d\n", __func__, rc);
  581. goto slim_define_ch_error;
  582. }
  583. for (i = 0; i < ch_cnt; i++) {
  584. rc = slim_connect_sink(sbdev, &sph[i], 1, ch_h[i]);
  585. if (rc < 0) {
  586. dev_err(&sbdev->dev, "=[ES325]=%s(): slim_connect_sink() failed: %d\n", __func__, rc);
  587. goto slim_connect_sink_error;
  588. }
  589. }
  590. rc = slim_control_ch(sbdev, grph, SLIM_CH_ACTIVATE, true /*commit*/);
  591. if (rc < 0) {
  592. dev_err(&sbdev->dev, "=[ES325]=%s(): slim_control_ch() failed: %d\n", __func__, rc);
  593. goto slim_control_ch_error;
  594. }
  595. for (i = 0; i < ch_cnt; i++) {
  596. idx = es325_rx_ch_num_to_idx(ch_num[i]);
  597. dev_dbg(&sbdev->dev, "=[ES325]=%s(): idx = %d\n", __func__, idx);
  598. rx[idx].grph = grph;
  599. }
  600. dev_dbg(&sbdev->dev, "-[ES325]=%s()\n", __func__);
  601. return rc;
  602. slim_control_ch_error:
  603. slim_connect_sink_error:
  604. es325_close_slim_rx(sbdev, ch_num, ch_cnt);
  605. slim_define_ch_error:
  606. dev_dbg(&sbdev->dev, "-[ES325]=%s() rc = %d\n", __func__, rc);
  607. return rc;
  608. }
  609. static int es325_cfg_slim_tx(struct slim_device *sbdev, unsigned int *ch_num,
  610. unsigned int ch_cnt, unsigned int rate, bool commit)
  611. {
  612. struct es325_priv *es325_priv = slim_get_devicedata(sbdev);
  613. struct es325_slim_ch *tx = es325_priv->slim_tx;
  614. u16 grph;
  615. u32 sph[ES325_SLIM_TX_PORTS] = {0};
  616. u16 ch_h[ES325_SLIM_TX_PORTS] = {0};
  617. struct slim_ch prop;
  618. int i;
  619. int idx;
  620. int rc;
  621. dev_dbg(&sbdev->dev, "+[ES325]=%s()\n", __func__);
  622. dev_dbg(&sbdev->dev, "=[ES325]=%s(): ch_cnt = %d, rate = %d\n", __func__, ch_cnt, rate);
  623. for (i = 0; i < ch_cnt; i++) {
  624. idx = es325_tx_ch_num_to_idx(ch_num[i]);
  625. ch_h[i] = tx[idx].ch_h;
  626. sph[i] = tx[idx].sph;
  627. dev_dbg(&sbdev->dev,
  628. "=[ES325]=%s(): idx = %d ch_num[i] = %d ch_h[i] = %d sph[i] = 0x%08x\n",
  629. __func__, idx, ch_num[i], ch_h[i], sph[i]);
  630. }
  631. prop.prot = SLIM_AUTO_ISO;
  632. prop.baser = SLIM_RATE_4000HZ;
  633. prop.dataf = SLIM_CH_DATAF_NOT_DEFINED;
  634. prop.auxf = SLIM_CH_AUXF_NOT_APPLICABLE;
  635. prop.ratem = (rate/4000);
  636. prop.sampleszbits = 16;
  637. rc = slim_define_ch(sbdev, &prop, ch_h, ch_cnt, true, &grph);
  638. if (rc < 0) {
  639. dev_err(&sbdev->dev, "=[ES325]=%s(): slim_define_ch() failed: %d\n", __func__, rc);
  640. goto slim_define_ch_error;
  641. }
  642. for (i = 0; i < ch_cnt; i++) {
  643. rc = slim_connect_src(sbdev, sph[i], ch_h[i]);
  644. if (rc < 0) {
  645. dev_err(&sbdev->dev, "=[ES325]=%s(): slim_connect_src() failed: %d\n", __func__, rc);
  646. dev_err(&sbdev->dev, "=[ES325]=%s(): ch_num[0] = %d\n", __func__, ch_num[0]);
  647. goto slim_connect_src_error;
  648. }
  649. }
  650. rc = slim_control_ch(sbdev, grph, SLIM_CH_ACTIVATE, true /*commit*/);
  651. if (rc < 0) {
  652. dev_err(&sbdev->dev, "=[ES325]=%s(): slim_control_ch() failed: %d\n", __func__, rc);
  653. goto slim_control_ch_error;
  654. }
  655. for (i = 0; i < ch_cnt; i++) {
  656. idx = es325_tx_ch_num_to_idx(ch_num[i]);
  657. dev_dbg(&sbdev->dev, "=[ES325]=%s(): idx = %d\n", __func__, idx);
  658. tx[idx].grph = grph;
  659. }
  660. dev_dbg(&sbdev->dev, "-[ES325]=%s()\n", __func__);
  661. return rc;
  662. slim_control_ch_error:
  663. slim_connect_src_error:
  664. es325_close_slim_tx(sbdev, ch_num, ch_cnt);
  665. slim_define_ch_error:
  666. dev_dbg(&sbdev->dev, "-[ES325]=%s() rc = %d\n", __func__, rc);
  667. return rc;
  668. }
  669. static int es325_close_slim_rx(struct slim_device *sbdev, unsigned int *ch_num, unsigned int ch_cnt)
  670. {
  671. struct es325_priv *es325_priv = slim_get_devicedata(sbdev);
  672. struct es325_slim_ch *rx = es325_priv->slim_rx;
  673. u16 grph = 0;
  674. u32 sph[ES325_SLIM_RX_PORTS] = {0};
  675. int i;
  676. int idx;
  677. int rc;
  678. dev_dbg(&sbdev->dev, "+[ES325]=%s()\n", __func__);
  679. for (i = 0; i < ch_cnt; i++) {
  680. idx = es325_rx_ch_num_to_idx(ch_num[i]);
  681. sph[i] = rx[idx].sph;
  682. grph = rx[idx].grph;
  683. dev_dbg(&sbdev->dev, "=[ES325]=%s() : sph[%d] = 0x%08x, grph[%d] = 0x%08x\n", __func__, i, sph[i], i, grph);
  684. }
  685. rc = slim_control_ch(sbdev, grph, SLIM_CH_REMOVE, true);
  686. if (rc < 0) {
  687. dev_err(&sbdev->dev, "=[ES325]=%s(): slim_control_ch() failed: %d\n", __func__, rc);
  688. goto slim_control_ch_error;
  689. }
  690. for (i = 0; i < ch_cnt; i++) {
  691. idx = es325_rx_ch_num_to_idx(ch_num[i]);
  692. dev_dbg(&sbdev->dev,"=[ES325]=%s(): idx = %d\n", __func__, idx);
  693. rx[idx].grph = 0;
  694. }
  695. rc = slim_disconnect_ports(sbdev, sph, ch_cnt);
  696. if (rc < 0)
  697. dev_err(&sbdev->dev, "=[ES325]=%s(): slim_disconnect_ports() failed: %d\n", __func__, rc);
  698. dev_dbg(&sbdev->dev, "=[ES325]=%s=close RX channel",__func__);
  699. for (i = 0; i < ch_cnt; i++)
  700. dev_dbg(&sbdev->dev, "[%d]",ch_num[i]);
  701. slim_control_ch_error:
  702. dev_dbg(&sbdev->dev, "-[ES325]=%s()\n", __func__);
  703. return rc;
  704. }
  705. static int es325_close_slim_tx(struct slim_device *sbdev, unsigned int *ch_num, unsigned int ch_cnt)
  706. {
  707. struct es325_priv *es325_priv = slim_get_devicedata(sbdev);
  708. struct es325_slim_ch *tx = es325_priv->slim_tx;
  709. u16 grph = 0;
  710. u32 sph[ES325_SLIM_TX_PORTS] = {0};
  711. int i;
  712. int idx;
  713. int rc;
  714. dev_dbg(&sbdev->dev, "+[ES325]=%s()\n", __func__);
  715. for (i = 0; i < ch_cnt; i++) {
  716. idx = es325_tx_ch_num_to_idx(ch_num[i]);
  717. sph[i] = tx[idx].sph;
  718. grph = tx[idx].grph;
  719. dev_dbg(&sbdev->dev, "=[ES325]=%s() : idx %d ch_num[%d] %d sph[%d] = 0x%08x, grph[%d] = 0x%08x\n",
  720. __func__, idx, i, ch_num[i], i, sph[i], i, grph);
  721. }
  722. rc = slim_control_ch(sbdev, grph, SLIM_CH_REMOVE, true);
  723. if (rc < 0) {
  724. dev_err(&sbdev->dev, "=[ES325]=%s(): slim_connect_sink() failed: %d\n", __func__, rc);
  725. goto slim_control_ch_error;
  726. }
  727. for (i = 0; i < ch_cnt; i++) {
  728. idx = es325_tx_ch_num_to_idx(ch_num[i]);
  729. dev_dbg(&sbdev->dev, "=[ES325]=%s(): ch_num[%d] %d idx = %d\n", __func__, i, ch_num[i], idx);
  730. tx[idx].grph = 0;
  731. }
  732. rc = slim_disconnect_ports(sbdev, sph, ch_cnt);
  733. if (rc < 0)
  734. dev_err(&sbdev->dev, "=[ES325]=%s(): slim_disconnect_ports() failed: %d\n", __func__, rc);
  735. dev_dbg(&sbdev->dev, "=[ES325]=%s() close TX channel",__func__);
  736. for (i = 0; i < ch_cnt; i++)
  737. dev_dbg(&sbdev->dev, "[%d]",ch_num[i]);
  738. slim_control_ch_error:
  739. dev_dbg(&sbdev->dev, "-[ES325]=%s()\n", __func__);
  740. return rc;
  741. }
  742. int es325_remote_cfg_slim_rx(int dai_id)
  743. {
  744. struct es325_priv *es325 = &es325_priv;
  745. struct slim_device *sbdev = es325->gen0_client;
  746. int be_id;
  747. int rc = 0;
  748. dev_dbg(&sbdev->dev, "+[ES325]=%s()\n", __func__);
  749. if(FW_not_ready) {
  750. dev_info(&sbdev->dev, "-[ES325]=%s() eS325 FW not ready, cfg_slim_rx rejected\n", __func__);
  751. return rc;
  752. }
  753. if (dai_id != ES325_SLIM_1_PB && dai_id != ES325_SLIM_2_PB) {
  754. dev_dbg(&sbdev->dev, "-[ES325]=%s() rc = %d\n", __func__, rc);
  755. return rc;
  756. }
  757. /* This is for defending ch_tot is not reset */
  758. if ((es325_rx1_route_enable == 0) && (es325_rx2_route_enable == 0)) {
  759. dev_dbg(&sbdev->dev, "-[ES325]=%s() rc = %d\n", __func__, rc);
  760. return rc;
  761. }
  762. if (es325->dai[ID(dai_id)].ch_tot != 0) {
  763. /* start slim channels associated with id */
  764. rc = es325_cfg_slim_rx(es325->gen0_client, es325->dai[ID(dai_id)].ch_num,
  765. es325->dai[ID(dai_id)].ch_tot, es325->dai[ID(dai_id)].rate, false);
  766. be_id = es325_slim_be_id[ID(dai_id)];
  767. es325->dai[ID(be_id)].ch_tot = es325->dai[ID(dai_id)].ch_tot;
  768. es325->dai[ID(be_id)].rate = es325->dai[ID(dai_id)].rate;
  769. if (be_id == ES325_SLIM_2_CAP) {
  770. es325->dai[ID(be_id)].ch_num[0] = 144;
  771. es325->dai[ID(be_id)].ch_num[1] = 145;
  772. } else if (be_id == ES325_SLIM_3_CAP) {
  773. es325->dai[ID(be_id)].ch_num[0] = 144;
  774. es325->dai[ID(be_id)].ch_num[1] = 145;
  775. }
  776. rc = es325_codec_cfg_slim_tx(es325, be_id, true);
  777. dev_info(&sbdev->dev, "=[ES325]=%s: MDM->>>[%d][%d]ES325[%d][%d]->>>WCD channel mapping\n",
  778. __func__,
  779. es325->dai[ID(dai_id)].ch_num[0],
  780. es325->dai[ID(dai_id)].ch_tot == 1 ? 0 : es325->dai[ID(dai_id)].ch_num[1],
  781. es325->dai[ID(be_id)].ch_num[0],
  782. es325->dai[ID(be_id)].ch_tot == 1 ? 0 : es325->dai[ID(be_id)].ch_num[1]);
  783. }
  784. dev_dbg(&sbdev->dev, "-[ES325]=%s() rc = %d\n", __func__, rc);
  785. return rc;
  786. }
  787. EXPORT_SYMBOL_GPL(es325_remote_cfg_slim_rx);
  788. int es325_remote_cfg_slim_tx(int dai_id)
  789. {
  790. struct es325_priv *es325 = &es325_priv;
  791. struct slim_device *sbdev = es325->gen0_client;
  792. int be_id;
  793. int ch_cnt;
  794. int rc = 0;
  795. dev_dbg(&sbdev->dev, "+[ES325]=%s()\n", __func__);
  796. if (FW_not_ready) {
  797. dev_info(&sbdev->dev, "-[ES325]=%s() eS325 FW not ready, cfg_slim_tx rejected\n", __func__);
  798. return rc;
  799. }
  800. if (dai_id != ES325_SLIM_1_CAP) {
  801. dev_dbg(&sbdev->dev, "-[ES325]=%s() rc = %d\n", __func__, rc);
  802. return rc;
  803. }
  804. /* This is for defending ch_tot is not reset */
  805. if (es325_tx1_route_enable == 0) {
  806. dev_dbg(&sbdev->dev, "-[ES325]=%s() rc = %d\n", __func__, rc);
  807. return rc;
  808. }
  809. if (es325->dai[ID(dai_id)].ch_tot != 0) {
  810. /* start slim channels associated with id */
  811. if (dai_id == ES325_SLIM_1_CAP)
  812. ch_cnt = es325_ap_tx1_ch_cnt;
  813. rc = es325_cfg_slim_tx(es325->gen0_client, es325->dai[ID(dai_id)].ch_num,
  814. ch_cnt, es325->dai[ID(dai_id)].rate, false);
  815. be_id = es325_slim_be_id[ID(dai_id)];
  816. es325->dai[ID(be_id)].ch_tot = es325->dai[ID(dai_id)].ch_tot;
  817. es325->dai[ID(dai_id)].ch_tot = ch_cnt;
  818. es325->dai[ID(be_id)].rate = es325->dai[ID(dai_id)].rate;
  819. if (be_id == ES325_SLIM_3_PB) {
  820. es325->dai[ID(be_id)].ch_num[0] = 134;
  821. es325->dai[ID(be_id)].ch_num[1] = 135;
  822. }
  823. rc = es325_codec_cfg_slim_rx(es325, be_id, true);
  824. dev_info(&sbdev->dev, "=[ES325]=%s: MDM<<<-[%d][%d]ES325[%d][%d]<<<-WCD channel mapping\n",
  825. __func__,
  826. es325->dai[ID(dai_id)].ch_num[0],
  827. es325->dai[ID(dai_id)].ch_tot == 1 ? 0 : es325->dai[ID(dai_id)].ch_num[1],
  828. es325->dai[ID(be_id)].ch_num[0],
  829. es325->dai[ID(be_id)].ch_tot == 1 ? 0 : es325->dai[ID(be_id)].ch_num[1]);
  830. }
  831. dev_dbg(&sbdev->dev, "-[ES325]=%s() rc = %d\n", __func__, rc);
  832. return rc;
  833. }
  834. EXPORT_SYMBOL_GPL(es325_remote_cfg_slim_tx);
  835. int es325_remote_close_slim_rx(int dai_id)
  836. {
  837. struct es325_priv *es325 = &es325_priv;
  838. struct slim_device *sbdev = es325->gen0_client;
  839. int be_id;
  840. int rc = 0;
  841. dev_dbg(&sbdev->dev, "+[ES325]=%s()\n", __func__);
  842. if (dai_id != ES325_SLIM_1_PB && dai_id != ES325_SLIM_2_PB) {
  843. dev_dbg(&sbdev->dev, "-[ES325]=%s() rc = %d\n", __func__, rc);
  844. return rc;
  845. }
  846. if (es325->dai[ID(dai_id)].ch_tot != 0) {
  847. dev_info(&sbdev->dev, "=[ES325]=%s(): dai_id = %d, ch_tot =%d\n",
  848. __func__, dai_id, es325->dai[ID(dai_id)].ch_tot);
  849. es325_close_slim_rx(es325->gen0_client,
  850. es325->dai[ID(dai_id)].ch_num,
  851. es325->dai[ID(dai_id)].ch_tot);
  852. be_id = es325_slim_be_id[ID(dai_id)];
  853. rc = es325_codec_close_slim_tx(es325, be_id);
  854. es325->dai[ID(dai_id)].ch_tot = 0;
  855. #ifdef ES325_SLEEP
  856. es325->dai[ID(be_id)].ch_tot = 0;
  857. #endif
  858. }
  859. dev_dbg(&sbdev->dev, "-[ES325]=%s()\n", __func__);
  860. return rc;
  861. }
  862. EXPORT_SYMBOL_GPL(es325_remote_close_slim_rx);
  863. int es325_remote_close_slim_tx(int dai_id)
  864. {
  865. struct es325_priv *es325 = &es325_priv;
  866. struct slim_device *sbdev = es325->gen0_client;
  867. int be_id;
  868. int rc = 0;
  869. dev_dbg(&sbdev->dev, "+[ES325]=%s()\n", __func__);
  870. if (dai_id != ES325_SLIM_1_CAP) {
  871. dev_dbg(&sbdev->dev, "-[ES325]=%s() rc = %d\n", __func__, rc);
  872. return rc;
  873. }
  874. if (es325->dai[ID(dai_id)].ch_tot != 0) {
  875. dev_info(&sbdev->dev, "=[ES325]=%s() dai_id = %d, ch_tot = %d\n",
  876. __func__, dai_id, es325->dai[ID(dai_id)].ch_tot);
  877. es325_close_slim_tx(es325->gen0_client,
  878. es325->dai[ID(dai_id)].ch_num,
  879. es325->dai[ID(dai_id)].ch_tot);
  880. be_id = es325_slim_be_id[ID(dai_id)];
  881. rc = es325_codec_close_slim_rx(es325, be_id);
  882. es325->dai[ID(dai_id)].ch_tot = 0;
  883. #ifdef ES325_SLEEP
  884. es325->dai[ID(be_id)].ch_tot = 0;
  885. #endif
  886. }
  887. dev_dbg(&sbdev->dev, "-[ES325]=%s()\n", __func__);
  888. return rc;
  889. }
  890. EXPORT_SYMBOL_GPL(es325_remote_close_slim_tx);
  891. static void es325_init_slim_slave(struct slim_device *sbdev)
  892. {
  893. dev_dbg(&sbdev->dev, "+[ES325]=%s()\n", __func__);
  894. es325_alloc_slim_rx_chan(sbdev);
  895. es325_alloc_slim_tx_chan(sbdev);
  896. }
  897. static void msg_to_bus_order(char *msg, int msg_len)
  898. {
  899. char tmp;
  900. for (; msg_len > 0; msg_len -= 4, msg += 4) {
  901. tmp = *(msg + 3);
  902. *(msg + 3) = *(msg);
  903. *(msg) = tmp;
  904. tmp = *(msg + 2);
  905. *(msg + 2) = *(msg + 1);
  906. *(msg + 1) = tmp;
  907. }
  908. }
  909. #ifdef BUS_TRANSACTIONS
  910. #if defined(CONFIG_SND_SOC_ES325_SLIM)
  911. static int es325_slim_read(struct es325_priv *es325, unsigned int offset,
  912. unsigned int width, char *buf, int len, int bus_order);
  913. static int es325_slim_write(struct es325_priv *es325, unsigned int offset,
  914. unsigned int width, char *buf, int len, int bus_order);
  915. #define ES325_BUS_READ(x_es325, x_offset, x_width, x_buf, x_len, x_bus_order) \
  916. es325_slim_read(x_es325, x_offset, x_width, x_buf, x_len, x_bus_order)
  917. #define ES325_BUS_WRITE(x_es325, x_offset, x_width, x_buf, x_len, x_bus_order) \
  918. es325_slim_write(x_es325, x_offset, x_width, x_buf, x_len, x_bus_order)
  919. #else
  920. #error "es325.c - bus infrastructure not defined"
  921. #endif
  922. #else
  923. /* Pretend all read and write operations on the bus are successful -
  924. when no bus is available. */
  925. #define ES325_BUS_READ(e, o, w, b, l, r) (0)
  926. #define ES325_BUS_WRITE(e, o, w, b, l, r) (0)
  927. #endif
  928. #ifdef FIXED_CONFIG
  929. static void es325_fixed_config(struct es325_priv *es325)
  930. {
  931. int rc;
  932. struct slim_device *sbdev = es325->gen0_client;
  933. u8 *msg_ptr = es325_internal_route_configs[5];
  934. while (*msg_ptr != 0xff) {
  935. u8 msg[4];
  936. memcpy(msg, msg_ptr, 4);
  937. rc = ES325_BUS_WRITE(es325, ES325_WRITE_VE_OFFSET,
  938. ES325_WRITE_VE_WIDTH, msg, 4, 1);
  939. if (rc < 0) {
  940. dev_err(&sbdev->dev, "=[ES325]=%s: slim write fail, rc=%d\n",
  941. __func__, rc);
  942. break;
  943. }
  944. dev_dbg(&sbdev->dev, "=[ES325]=%s(): msg = %02x%02x%02x%02x\n", __func__,
  945. msg[3], msg[2], msg[1], msg[0]);
  946. msg_ptr += 4;
  947. }
  948. }
  949. #endif
  950. /*
  951. * Delay for receiving response can be up to 20 ms.
  952. * To minimize waiting time, response is checking
  953. * up to 20 times with 1ms delay.
  954. */
  955. #define MAX_TRIALS 20
  956. #define SMB_DELAY 1000
  957. const char NOT_READY[4] = {0x00, 0x00, 0x00, 0x00};
  958. static int es325_request_response(struct es325_priv *es325,
  959. char *rqst_ptr, int rqst_len, int rqst_order,
  960. char *rspn_ptr, int rspn_len, int rspn_order,
  961. int match, int return_if_fail)
  962. {
  963. int rc = 0;
  964. int i = 0;
  965. int try_write = 1;
  966. char msg[4];
  967. struct slim_device *sbdev = es325->gen0_client;
  968. do {
  969. rc = 0;
  970. if (try_write) {
  971. memcpy(msg, rqst_ptr, 4);
  972. rc = ES325_BUS_WRITE(es325, ES325_WRITE_VE_OFFSET,
  973. ES325_WRITE_VE_WIDTH, msg, 4, rqst_order);
  974. if (rc < 0) {
  975. if (return_if_fail)
  976. break;
  977. else
  978. dev_err(&sbdev->dev, "=[ES325]=%s: slim write fail, rc=%d\n",
  979. __func__, rc);
  980. } else {
  981. try_write = 0;
  982. }
  983. }
  984. usleep_range(SMB_DELAY, SMB_DELAY);
  985. if (rc == 0) {
  986. memset(msg, 0, 4);
  987. rc = ES325_BUS_READ(es325, ES325_READ_VE_OFFSET,
  988. ES325_READ_VE_WIDTH, msg, rspn_len, rspn_order);
  989. if (rc < 0) {
  990. if (return_if_fail)
  991. break;
  992. else
  993. dev_err(&sbdev->dev, "=[ES325]=%s: slim read fail, rc=%d\n",
  994. __func__, rc);
  995. } else {
  996. /* save response */
  997. memcpy(rspn_ptr, msg, rspn_len);
  998. if (memcmp(msg, NOT_READY, 4) != 0) {
  999. rc = 0;
  1000. if (match && (memcmp(rqst_ptr, msg, rspn_len) != 0))
  1001. rc = -1;
  1002. break;
  1003. }
  1004. }
  1005. }
  1006. i++;
  1007. } while (i <= MAX_TRIALS);
  1008. if (i > MAX_TRIALS) {
  1009. dev_err(&sbdev->dev, "=[ES325]=%s(): Request-Response reach MAX_TRIALS (20), fail\n", __func__);
  1010. return -1;
  1011. }
  1012. return rc;
  1013. }
  1014. static int es325_slim_read(struct es325_priv *es325, unsigned int offset,
  1015. unsigned int width, char *buf, int len, int bus_order)
  1016. {
  1017. struct slim_device *sbdev = es325->gen0_client;
  1018. DECLARE_COMPLETION_ONSTACK(read_done);
  1019. struct slim_ele_access msg = {
  1020. .start_offset = offset,
  1021. .num_bytes = width,
  1022. /* .comp = &read_done, */
  1023. .comp = NULL,
  1024. };
  1025. int rc;
  1026. rc = slim_request_val_element(sbdev, &msg, buf, len);
  1027. if (bus_order)
  1028. msg_to_bus_order(buf, len);
  1029. #ifdef DEBUG
  1030. dev_dbg(&sbdev->dev, "=[ES325]%s(): SMB READ: 0x%02x 0x%02x 0x%02x 0x%02x\n",
  1031. __func__, *buf, *(buf+1), *(buf+2), *(buf+3));
  1032. #endif
  1033. return rc;
  1034. }
  1035. static int es325_slim_write(struct es325_priv *es325, unsigned int offset,
  1036. unsigned int width, char *buf, int len, int bus_order)
  1037. {
  1038. struct slim_device *sbdev = es325->gen0_client;
  1039. struct slim_ele_access msg = {
  1040. .start_offset = offset,
  1041. .num_bytes = width,
  1042. .comp = NULL,
  1043. };
  1044. int rc;
  1045. if (bus_order)
  1046. msg_to_bus_order(buf, len);
  1047. rc = slim_change_val_element(sbdev, &msg, buf, len);
  1048. if (rc != 0)
  1049. dev_err(&sbdev->dev, "=[ES325]=%s: slim_write failed rc=%d\n", __func__, rc);
  1050. #ifdef DEBUG
  1051. else
  1052. dev_dbg(&sbdev->dev, "=[ES325]%s(): SMB WRITE: 0x%02x 0x%02x 0x%02x 0x%02x\n",
  1053. __func__, *buf, *(buf+1), *(buf+2), *(buf+3));
  1054. #endif
  1055. return rc;
  1056. }
  1057. static int es325_build_algo_read_msg(char *msg, int *msg_len, unsigned int reg)
  1058. {
  1059. unsigned int index = reg & ES325_ADDR_MASK;
  1060. unsigned int paramid;
  1061. if (index > ARRAY_SIZE(es325_algo_paramid))
  1062. return -EINVAL;
  1063. paramid = es325_algo_paramid[index];
  1064. /* ES325_GET_ALGO_PARAM */
  1065. *msg++ = (ES325_GET_ALGO_PARAM >> 8) & 0x00ff;
  1066. *msg++ = ES325_GET_ALGO_PARAM & 0x00ff;
  1067. /* PARAM ID */
  1068. *msg++ = (paramid >> 8) & 0x00ff;
  1069. *msg++ = paramid & 0x00ff;
  1070. *msg_len = 4;
  1071. return 0;
  1072. }
  1073. static int es325_build_algo_write_msg(char *msg, int *msg_len,
  1074. unsigned int reg, unsigned int value)
  1075. {
  1076. unsigned int index = reg & ES325_ADDR_MASK;
  1077. unsigned int cmd;
  1078. unsigned int paramid;
  1079. if (index > ARRAY_SIZE(es325_algo_paramid))
  1080. return -EINVAL;
  1081. paramid = es325_algo_paramid[index];
  1082. /* ES325_SET_ALGO_PARAMID */
  1083. cmd = ES325_SET_ALGO_PARAMID;
  1084. if (reg & ES325_STAGED_CMD)
  1085. cmd |= ES325_STAGED_MSG_BIT;
  1086. *msg++ = (cmd >> 8) & 0x00ff;
  1087. *msg++ = cmd & 0x00ff;
  1088. /* PARAM ID */
  1089. *msg++ = (paramid >> 8) & 0x00ff;
  1090. *msg++ = paramid & 0x00ff;
  1091. /* ES325_SET_ALGO_PARAM */
  1092. cmd = ES325_SET_ALGO_PARAM;
  1093. if (reg & ES325_STAGED_CMD)
  1094. cmd |= ES325_STAGED_MSG_BIT;
  1095. *msg++ = (cmd >> 8) & 0x00ff;
  1096. *msg++ = cmd & 0x00ff;
  1097. /* value */
  1098. *msg++ = (value >> 8) & 0x00ff;
  1099. *msg++ = value & 0x00ff;
  1100. *msg_len = 8;
  1101. return 0;
  1102. }
  1103. static int es325_build_dev_read_msg(char *msg, int *msg_len, unsigned int reg)
  1104. {
  1105. unsigned int index = reg & ES325_ADDR_MASK;
  1106. unsigned int paramid;
  1107. if (index > ARRAY_SIZE(es325_dev_paramid))
  1108. return -EINVAL;
  1109. paramid = es325_dev_paramid[index];
  1110. /* ES325_GET_DEV_PARAM */
  1111. *msg++ = (ES325_GET_DEV_PARAM >> 8) & 0x00ff;
  1112. *msg++ = ES325_GET_DEV_PARAM & 0x00ff;
  1113. /* PARAM ID */
  1114. *msg++ = (paramid >> 8) & 0x00ff;
  1115. *msg++ = paramid & 0x00ff;
  1116. *msg_len = 4;
  1117. return 0;
  1118. }
  1119. static int es325_build_dev_write_msg(char *msg, int *msg_len,
  1120. unsigned int reg, unsigned int value)
  1121. {
  1122. unsigned int index = reg & ES325_ADDR_MASK;
  1123. unsigned int cmd;
  1124. unsigned int paramid;
  1125. if (index > ARRAY_SIZE(es325_dev_paramid))
  1126. return -EINVAL;
  1127. paramid = es325_dev_paramid[index];
  1128. /* ES325_SET_DEV_PARAMID */
  1129. cmd = ES325_SET_DEV_PARAMID;
  1130. if (reg & ES325_STAGED_CMD)
  1131. cmd |= ES325_STAGED_MSG_BIT;
  1132. *msg++ = (cmd >> 8) & 0x00ff;
  1133. *msg++ = cmd & 0x00ff;
  1134. /* PARAM ID */
  1135. *msg++ = (paramid >> 8) & 0x00ff;
  1136. *msg++ = paramid & 0x00ff;
  1137. /* ES325_SET_DEV_PARAM */
  1138. cmd = ES325_SET_DEV_PARAM;
  1139. if (reg & ES325_STAGED_CMD)
  1140. cmd |= ES325_STAGED_MSG_BIT;
  1141. *msg++ = (cmd >> 8) & 0x00ff;
  1142. *msg++ = cmd & 0x00ff;
  1143. /* value */
  1144. *msg++ = (value >> 8) & 0x00ff;
  1145. *msg++ = value & 0x00ff;
  1146. *msg_len = 8;
  1147. return 0;
  1148. }
  1149. static int es325_build_cmd_read_msg(char *msg, int *msg_len, unsigned int reg)
  1150. {
  1151. unsigned int index = reg & ES325_ADDR_MASK;
  1152. struct es325_cmd_access *cmd_access;
  1153. if (index > ARRAY_SIZE(es325_cmd_access))
  1154. return -EINVAL;
  1155. cmd_access = es325_cmd_access + index;
  1156. *msg_len = cmd_access->read_msg_len;
  1157. memcpy(msg, &cmd_access->read_msg, *msg_len);
  1158. return 0;
  1159. }
  1160. static int es325_build_cmd_write_msg(char *msg, int *msg_len,
  1161. unsigned int reg, unsigned int value)
  1162. {
  1163. unsigned int index = reg & ES325_ADDR_MASK;
  1164. struct es325_cmd_access *cmd_access;
  1165. if (index > ARRAY_SIZE(es325_cmd_access))
  1166. return -EINVAL;
  1167. cmd_access = es325_cmd_access + index;
  1168. *msg_len = cmd_access->write_msg_len;
  1169. memcpy(msg, &cmd_access->write_msg, *msg_len);
  1170. if (reg & ES325_STAGED_CMD)
  1171. *msg |= (1 << 5);
  1172. return 0;
  1173. }
  1174. static unsigned int es325_read(struct snd_soc_codec *codec, unsigned int reg)
  1175. {
  1176. struct es325_priv *es325 = &es325_priv;
  1177. struct slim_device *sbdev = es325->gen0_client;
  1178. unsigned int access = reg & ES325_ACCESS_MASK;
  1179. char msg[16];
  1180. unsigned int msg_len;
  1181. unsigned int value;
  1182. int rc;
  1183. switch (access) {
  1184. case ES325_ALGO_ACCESS:
  1185. rc = es325_build_algo_read_msg(msg, &msg_len, reg);
  1186. break;
  1187. case ES325_DEV_ACCESS:
  1188. rc = es325_build_dev_read_msg(msg, &msg_len, reg);
  1189. break;
  1190. case ES325_CMD_ACCESS:
  1191. rc = es325_build_cmd_read_msg(msg, &msg_len, reg);
  1192. break;
  1193. case ES325_OTHER_ACCESS:
  1194. return 0;
  1195. default:
  1196. rc = -EINVAL;
  1197. break;
  1198. }
  1199. if (rc) {
  1200. dev_err(&sbdev->dev, "=[ES325]= %s(): failed to build read message for address = 0x%04x\n", __func__, reg);
  1201. return rc;
  1202. }
  1203. rc = es325_request_response(es325, msg, msg_len, 1, msg, 4, 1, 0, 0);
  1204. if (rc < 0)
  1205. return rc;
  1206. value = msg[2] << 8 | msg[3];
  1207. return value;
  1208. }
  1209. static int es325_write(struct snd_soc_codec *codec, unsigned int reg, unsigned int value)
  1210. {
  1211. struct es325_priv *es325 = &es325_priv;
  1212. struct slim_device *sbdev = es325->gen0_client;
  1213. unsigned int access = reg & ES325_ACCESS_MASK;
  1214. char msg[16];
  1215. char *msg_ptr;
  1216. int msg_len = 0;
  1217. int i;
  1218. int rc;
  1219. switch (access) {
  1220. case ES325_ALGO_ACCESS:
  1221. rc = es325_build_algo_write_msg(msg, &msg_len, reg, value);
  1222. break;
  1223. case ES325_DEV_ACCESS:
  1224. rc = es325_build_dev_write_msg(msg, &msg_len, reg, value);
  1225. break;
  1226. case ES325_CMD_ACCESS:
  1227. rc = es325_build_cmd_write_msg(msg, &msg_len, reg, value);
  1228. break;
  1229. case ES325_OTHER_ACCESS:
  1230. return 0;
  1231. default:
  1232. rc = -EINVAL;
  1233. break;
  1234. }
  1235. if (rc) {
  1236. dev_err(&sbdev->dev, "=[ES325]= %s(): failed to build write message for address = 0x%04x\n", __func__, reg);
  1237. return rc;
  1238. }
  1239. msg_ptr = msg;
  1240. for (i = msg_len; i > 0; i -= 4, msg_ptr += 4) {
  1241. rc = es325_request_response(es325, msg_ptr, 4, 1, msg_ptr, 4, 1, 0, 0);
  1242. if (rc < 0)
  1243. break;
  1244. }
  1245. return rc;
  1246. }
  1247. static ssize_t es325_route_status_show(struct device *dev, struct device_attribute *attr, char *buf)
  1248. {
  1249. int i;
  1250. int idx;
  1251. ssize_t rc = 0;
  1252. struct es325_priv *es325 = &es325_priv;
  1253. int active;
  1254. char *route_st_names[] = {
  1255. "ACTIVE",
  1256. "MUTING",
  1257. "SWITCHING",
  1258. "UNMUTING",
  1259. "INACTIVE",
  1260. "es325 NO RESPONSE"
  1261. };
  1262. char *status_name[] = {
  1263. "Route Status",
  1264. "Slimbus Ports Raw Status",
  1265. "Slimbus Active Rx Ports",
  1266. "Slimbus Active Tx Ports",
  1267. };
  1268. u8 route_st_req_msg[] = {
  1269. /* Route Status */
  1270. 0x80, 0x4f, 0x00, 0x00,
  1271. };
  1272. u8 port_st_req_msg[] = {
  1273. /* SBUS port State read */
  1274. 0x80, 0x0B, 0x09, 0x12,
  1275. };
  1276. u8 ack_msg[4];
  1277. if (es325_priv.wakeup_cnt == 0)
  1278. return 0;
  1279. /* Read route status */
  1280. if (es325_request_response(es325, route_st_req_msg, 4, 1, ack_msg, 4, 1, 0, 0) < 0) {
  1281. rc = rc + snprintf(buf+rc, PAGE_SIZE - rc,
  1282. "Read Route Status FAIL. SLIMBus error\n");
  1283. return rc;
  1284. }
  1285. dev_info(dev, "=[ES325]=:%s(): ping ack = %02x%02x%02x%02x\n",
  1286. __func__, ack_msg[0], ack_msg[1], ack_msg[2], ack_msg[3]);
  1287. /* Successful response? */
  1288. if ((ack_msg[0] == 0x80) && (ack_msg[1] == 0x4f)) {
  1289. rc = rc + snprintf(buf+rc, PAGE_SIZE - rc,
  1290. "%s = 0x%02x%02x%02x%02x - %s\n",
  1291. status_name[0],
  1292. ack_msg[0], ack_msg[1],
  1293. ack_msg[2], ack_msg[3],
  1294. route_st_names[ack_msg[3]] );
  1295. /* Read Port status */
  1296. if (es325_request_response(es325, port_st_req_msg, 4, 1, ack_msg, 4, 1, 0, 0) < 0) {
  1297. rc = rc + snprintf(buf+rc, PAGE_SIZE - rc,
  1298. "Read Port Status FAIL. SLIMBus error\n");
  1299. return rc;
  1300. }
  1301. dev_info(dev, "=[ES325]= %s(): ping ack = %02x%02x%02x%02x\n",
  1302. __func__, ack_msg[0], ack_msg[1], ack_msg[2], ack_msg[3]);
  1303. if ((ack_msg[0] == 0x80) && (ack_msg[1] == 0x0B)) {
  1304. u16 port_status = (ack_msg[2] << 8) | ack_msg[3];
  1305. rc = rc + snprintf(buf+rc, PAGE_SIZE - rc,
  1306. "%s = 0x%02x%02x%02x%02x \n",
  1307. status_name[1],
  1308. ack_msg[0], ack_msg[1],
  1309. ack_msg[2], ack_msg[3]);
  1310. rc = rc + snprintf(buf+rc, PAGE_SIZE - rc, "%s = ", status_name[2]);
  1311. active = 0;
  1312. for (i = 0; i < 10; i++) {
  1313. idx = (port_status & (1 << i)) >> i;
  1314. if (idx == 1) {
  1315. active = 1;
  1316. rc = rc + snprintf(buf+rc, PAGE_SIZE - rc, "%d ", i);
  1317. }
  1318. }
  1319. if (active == 0)
  1320. rc = rc + snprintf(buf+rc, PAGE_SIZE - rc, "None\n%s = ", status_name[3]);
  1321. else
  1322. rc = rc + snprintf(buf+rc, PAGE_SIZE - rc, "\n%s = ", status_name[3]);
  1323. active = 0;
  1324. for (i = 10; i < 16; i++) {
  1325. idx = (port_status & (1 << i)) >> i;
  1326. if (idx == 1) {
  1327. active = 1;
  1328. rc = rc + snprintf(buf+rc, PAGE_SIZE - rc, "%d ", (i-10));
  1329. }
  1330. }
  1331. if (active == 0)
  1332. rc = rc + snprintf(buf+rc, PAGE_SIZE - rc, "None\n");
  1333. else
  1334. rc = rc + snprintf(buf+rc, PAGE_SIZE - rc, "\n" );
  1335. } else {
  1336. rc = rc + snprintf(buf+rc, PAGE_SIZE - rc,
  1337. "%s = 0x%02x%02x%02x%02x - %s\n",
  1338. status_name[1],
  1339. ack_msg[0], ack_msg[1],
  1340. ack_msg[2], ack_msg[3],
  1341. "Cannot Read!" );
  1342. }
  1343. } else {
  1344. rc = rc + snprintf(buf+rc, PAGE_SIZE - rc,
  1345. "%s = 0x%02x%02x%02x%02x - %s\n",
  1346. status_name[0],
  1347. ack_msg[0], ack_msg[1],
  1348. ack_msg[2], ack_msg[3],
  1349. route_st_names[5] );
  1350. }
  1351. return rc;
  1352. }
  1353. static DEVICE_ATTR(route_status, 0644, es325_route_status_show, NULL);
  1354. /* /sys/devices/fe12f000.slim/es325-gen/route_status */
  1355. static ssize_t es325_route_config_show(struct device *dev, struct device_attribute *attr, char *buf)
  1356. {
  1357. dev_info(dev, "=[ES325]= %s(): route=%ld\n", __func__, es325_internal_route_num);
  1358. return snprintf(buf, PAGE_SIZE, "route=%ld\n", es325_internal_route_num);
  1359. }
  1360. #ifndef ES325_SLEEP
  1361. static void es325_switch_route(long route_index)
  1362. {
  1363. struct es325_priv *es325 = &es325_priv;
  1364. struct slim_device *sbdev = es325->gen0_client;
  1365. u8 msg[4];
  1366. u8 *msg_ptr;
  1367. int rc;
  1368. if (route_index > ES325_INTERNAL_ROUTE_MAX) {
  1369. dev_info(&sbdev->dev, "=[ES325]= %s(): new es325_internal_route = %ld is out of range\n", __func__, route_index);
  1370. return;
  1371. }
  1372. dev_info(&sbdev->dev, "=[ES325]=%s():switch current es325_internal_route = %ld to new route = %ld\n",
  1373. __func__, es325_internal_route_num, route_index);
  1374. es325_internal_route_num = route_index;
  1375. if (es325_network_type != NARROW_BAND) {
  1376. if (es325_internal_route_num >= 0 && es325_internal_route_num < 5)
  1377. es325_internal_route_num += NETWORK_OFFSET;
  1378. }
  1379. msg_ptr = &es325_internal_route_configs[es325_internal_route_num][0];
  1380. while (*msg_ptr != 0xff) {
  1381. memcpy(msg, msg_ptr, 4);
  1382. rc = ES325_BUS_WRITE(es325, ES325_WRITE_VE_OFFSET, ES325_WRITE_VE_WIDTH, msg, 4, 1);
  1383. if (rc < 0) {
  1384. dev_err(&sbdev->dev, "=[ES325]=%s: slim write fail, rc=%d\n",
  1385. __func__, rc);
  1386. break;
  1387. }
  1388. msg_ptr += 4;
  1389. }
  1390. }
  1391. #else
  1392. static void es325_switch_route(void)
  1393. {
  1394. struct es325_priv *es325 = &es325_priv;
  1395. struct slim_device *sbdev = es325->gen0_client;
  1396. u8 msg[4];
  1397. u8 *msg_ptr;
  1398. int rc;
  1399. if (es325_network_type == WIDE_BAND) {
  1400. if (es325->new_internal_route_config >= 0 &&
  1401. es325->new_internal_route_config < 5) {
  1402. es325->new_internal_route_config += NETWORK_OFFSET;
  1403. dev_info(&sbdev->dev, "=[ES325]=%s() adjust wideband offset\n", __func__);
  1404. }
  1405. }
  1406. if (es325_network_type == NARROW_BAND) {
  1407. if (es325->new_internal_route_config >= 0 + NETWORK_OFFSET &&
  1408. es325->new_internal_route_config < 5 + NETWORK_OFFSET) {
  1409. es325->new_internal_route_config -= NETWORK_OFFSET;
  1410. dev_info(&sbdev->dev, "=[ES325]=%s() adjust narrowband offset\n", __func__);
  1411. }
  1412. }
  1413. dev_info(&sbdev->dev, "=[ES325]=%s() switch current es325_internal_route = %d to new route = %d\n",
  1414. __func__, es325->internal_route_config, es325->new_internal_route_config);
  1415. if (es325->new_internal_route_config > ES325_INTERNAL_ROUTE_MAX) {
  1416. dev_info(&sbdev->dev, "=[ES325]=%s(): new es325_internal_route = %d is out of range\n",
  1417. __func__, es325->new_internal_route_config);
  1418. return;
  1419. }
  1420. if (es325->internal_route_config != es325->new_internal_route_config) {
  1421. es325_internal_route_num = es325->new_internal_route_config;
  1422. dev_info(&sbdev->dev, "=[ES325]=%s(): final es325_internal_route_num = %ld\n",
  1423. __func__, es325_internal_route_num);
  1424. msg_ptr = &es325_internal_route_configs[es325_internal_route_num][0];
  1425. while (*msg_ptr != 0xff) {
  1426. memcpy(msg, msg_ptr, 4);
  1427. rc = ES325_BUS_WRITE(es325, ES325_WRITE_VE_OFFSET, ES325_WRITE_VE_WIDTH, msg, 4, 1);
  1428. if (rc < 0)
  1429. dev_err(&sbdev->dev, "=[ES325]=%s: slim write fail, rc=%d\n",
  1430. __func__, rc);
  1431. msg_ptr += 4;
  1432. }
  1433. es325->internal_route_config = es325->new_internal_route_config;
  1434. }
  1435. }
  1436. #endif
  1437. static ssize_t es325_route_config_set(struct device *dev, struct device_attribute *attr,
  1438. const char *buf, size_t count)
  1439. {
  1440. long route_index;
  1441. int rc;
  1442. if (es325_priv.wakeup_cnt == 0)
  1443. return 0;
  1444. dev_info(dev, "=[ES325]=%s():buf = %s\n", __func__, buf);
  1445. rc = kstrtol(buf, 10, &route_index);
  1446. #ifndef ES325_SLEEP
  1447. es325_switch_route(route_index);
  1448. #else
  1449. es325_priv.new_internal_route_config = route_index;
  1450. dev_info(dev, "=[ES325]=%s wakeup_cnt=%d\n", __func__, es325_priv.wakeup_cnt);
  1451. mutex_lock(&es325_priv.pm_mutex);
  1452. if (es325_priv.wakeup_cnt)
  1453. es325_switch_route();
  1454. mutex_unlock(&es325_priv.pm_mutex);
  1455. #endif
  1456. return count;
  1457. }
  1458. static DEVICE_ATTR(route_config, 0644, es325_route_config_show, es325_route_config_set);
  1459. /* /sys/devices/fe12f000.slim/es325-gen/route_config */
  1460. #define SIZE_OF_VERBUF 256
  1461. static ssize_t es325_fw_version_show(struct device *dev, struct device_attribute *attr, char *buf)
  1462. {
  1463. char first_char_msg[4] = {0x90, 0x20, 0x00, 0x00};
  1464. char next_char_msg[4] = {0x80, 0x21, 0x00, 0x00};
  1465. struct es325_priv *es325 = &es325_priv;
  1466. int rc = 0, idx = 0;
  1467. unsigned int imsg = 1; /* force first loop */
  1468. unsigned char bmsg[4];
  1469. char versionbuffer[SIZE_OF_VERBUF];
  1470. char *verbuf = versionbuffer;
  1471. char cmd[4];
  1472. if (es325_priv.wakeup_cnt == 0)
  1473. return 0;
  1474. memset(verbuf,0,SIZE_OF_VERBUF);
  1475. memcpy(cmd, first_char_msg, 4);
  1476. ES325_BUS_WRITE(es325, ES325_WRITE_VE_OFFSET, ES325_WRITE_VE_WIDTH, cmd, 4, 1);
  1477. while ((rc >= 0) && (idx < (SIZE_OF_VERBUF-1)) && (imsg & 0xFF)) {
  1478. memcpy(cmd, next_char_msg, 4);
  1479. rc = es325_request_response(es325, cmd, 4, 1, bmsg, 4, 1, 0, 0);
  1480. if (rc < 0) {
  1481. return snprintf(buf, PAGE_SIZE, "Get FW Version FAIL. SLIMBus error\n");
  1482. }
  1483. imsg = bmsg[3];
  1484. if ((bmsg[0] == 0xFF) && (bmsg[1] == 0xFF)){
  1485. dev_err(dev, "=[ES325]=%s(): No version API on Audience\n", __func__);
  1486. rc = -1;
  1487. } else {
  1488. verbuf[idx++] = (char) (bmsg[3]);
  1489. }
  1490. }
  1491. /* Null terminate the string*/
  1492. verbuf[idx] = '\0';
  1493. dev_info(dev, "=[ES325]=%s(): Audience fw ver %s\n", __func__, verbuf);
  1494. return snprintf(buf, PAGE_SIZE, "FW Version = %s\n",verbuf);
  1495. }
  1496. static DEVICE_ATTR(fw_version, 0644, es325_fw_version_show, NULL);
  1497. /* /sys/devices/fe12f000.slim/es325-gen/fw_version */
  1498. static ssize_t es325_txhex_show(struct device *dev, struct device_attribute *attr, char *buf)
  1499. {
  1500. dev_info(dev, "=[ES325]=%s(): called\n", __func__);
  1501. return 0;
  1502. }
  1503. static ssize_t es325_txhex_set(struct device *dev, struct device_attribute *attr,
  1504. const char *buf, size_t count)
  1505. {
  1506. struct es325_priv *es325 = &es325_priv;
  1507. u8 cmd[128];
  1508. int cmdlen;
  1509. int offset = 0;
  1510. u8 resp[4];
  1511. int rc;
  1512. if (es325_priv.wakeup_cnt == 0)
  1513. return 0;
  1514. dev_dbg(dev, "+[ES325]=%s()\n", __func__);
  1515. dev_dbg(dev, "=[ES325]=%s(): count=%i\n", __func__, count);
  1516. /* No command sequences larger than 128 bytes. */
  1517. BUG_ON(count > (128 * 2) + 1);
  1518. /* Expect a even number of hexadecimal digits terminated by a newline. */
  1519. BUG_ON(!(count & 1));
  1520. rc = hex2bin(cmd, buf, count / 2);
  1521. BUG_ON(rc != 0);
  1522. cmdlen = count / 2;
  1523. dev_dbg(dev, "=[ES325]=%s rc=%d cmdlen=%d\n", __func__, rc, cmdlen);
  1524. while (offset < cmdlen) {
  1525. /* Commands must be written in 4 byte blocks. */
  1526. int wrsize = (cmdlen - offset > 4) ? 4 : cmdlen - offset;
  1527. rc = es325_request_response(es325, &cmd[offset], wrsize, 1, resp, 4, 1, 0, 0);
  1528. if (rc != 0) {
  1529. dev_err(dev, "=[ES325]=%s(): FAIL\n", __func__);
  1530. break;
  1531. } else {
  1532. dev_dbg(dev, "=[ES325]=%s: %02x%02x%02x%02x\n",
  1533. __func__, resp[0], resp[1], resp[2], resp[3]);
  1534. offset += wrsize;
  1535. }
  1536. }
  1537. dev_dbg(dev, "-[ES325]=%s()\n", __func__);
  1538. return count;
  1539. }
  1540. static DEVICE_ATTR(txhex, 0644, es325_txhex_show, es325_txhex_set);
  1541. static ssize_t es325_clock_on_show(struct device *dev, struct device_attribute *attr, char *buf)
  1542. {
  1543. char status[4];
  1544. if (es325_priv.wakeup_cnt == 0)
  1545. return 0;
  1546. dev_dbg(dev, "=[ES325]=%s\n", __func__);
  1547. if(es325_priv.clock_on)
  1548. snprintf(status, sizeof("on"), "%s", "on");
  1549. else
  1550. snprintf(status, sizeof("off"), "%s", "off");
  1551. return snprintf(buf, PAGE_SIZE, "clk_status: %s\n", status);
  1552. }
  1553. static DEVICE_ATTR(clock_on, 0644, es325_clock_on_show, NULL);
  1554. /* /sys/devices/fe12f000.slim/es325-gen/clock_on_status */
  1555. static ssize_t es325_slim_ch_show(struct device *dev, struct device_attribute *attr, char *buf)
  1556. {
  1557. struct es325_priv *priv = &es325_priv;
  1558. struct es325_slim_dai_data* dai = priv->dai;
  1559. int length = 0;
  1560. int i, j;
  1561. if (es325_priv.wakeup_cnt == 0)
  1562. return 0;
  1563. for(i = 0; i < ES325_NUM_CODEC_SLIM_DAIS; i++) {
  1564. length += sprintf(buf+length,"=dai[%d]=rate[%d]=ch_num=",i, dai[i].rate);
  1565. for(j = 0; j < dai[i].ch_tot; j++)
  1566. length += sprintf(buf+length,"[%d]",dai[i].ch_num[j]);
  1567. length += sprintf(buf+length,"%c\n",'=');
  1568. }
  1569. return length;
  1570. }
  1571. static DEVICE_ATTR(slim_ch_status, 0644, es325_slim_ch_show, NULL);
  1572. /* /sys/devices/fe12f000.slim/es325-gen/slim_ch_status */
  1573. static ssize_t es325_reg_show(struct device *dev, struct device_attribute *attr, char *buf)
  1574. {
  1575. int length = 0;
  1576. int i;
  1577. int size = 0;
  1578. if (es325_priv.wakeup_cnt == 0)
  1579. return 0;
  1580. length += sprintf(buf+length,"es325_reg : algo\n");
  1581. size = sizeof(es325_algo_paramid)/sizeof(unsigned short); /* 127 items */
  1582. for(i = ES325_MIC_CONFIG; i < size; i++)
  1583. length += sprintf(buf+length,"0x%04x : 0x%04x\n", i, es325_read(NULL, i));
  1584. length += sprintf(buf+length,"\nes325_reg : dev\n");
  1585. size = sizeof(es325_dev_paramid)/sizeof(unsigned short); /* 49 items */
  1586. for(i = ES325_PORTA_WORD_LEN; i < (size + ES325_PORTA_WORD_LEN); i++)
  1587. length += sprintf(buf+length,"0x%04x : 0x%04x\n", i, es325_read(NULL, i));
  1588. return length;
  1589. }
  1590. static ssize_t es325_reg_write(struct device *dev,
  1591. struct device_attribute *attr, const char *buf, size_t size)
  1592. {
  1593. char tempbuf[32];
  1594. char *start = tempbuf;
  1595. unsigned long reg, value;
  1596. if (es325_priv.wakeup_cnt == 0)
  1597. return 0;
  1598. memcpy(tempbuf, buf, size);
  1599. tempbuf[size] = 0;
  1600. while (*start == ' ')
  1601. start++;
  1602. reg = simple_strtoul(start, &start, 16);
  1603. while (*start == ' ')
  1604. start++;
  1605. if (strict_strtoul(start, 16, &value))
  1606. return -EINVAL;
  1607. es325_write(NULL, reg, value);
  1608. return size;
  1609. }
  1610. static DEVICE_ATTR(es325_reg, 0644, es325_reg_show, es325_reg_write);
  1611. /* /sys/devices/fe12f000.slim/es325-gen/es325_reg */
  1612. static ssize_t es325_cmd_reg_show(struct device *dev, struct device_attribute *attr, char *buf)
  1613. {
  1614. int length = 0;
  1615. int i;
  1616. int size = 0;
  1617. if (es325_priv.wakeup_cnt == 0)
  1618. return 0;
  1619. /* removed 0x2001(first), 0x20d4(end) register read, because of error */
  1620. size = sizeof(es325_cmd_access)/sizeof(struct es325_cmd_access); /* 213 items */
  1621. for(i = ES325_POWER_STATE + 1; i < (size + ES325_POWER_STATE -1); i++)
  1622. length += sprintf(buf+length,"0x%04x : 0x%04x\n", i, es325_read(NULL, i));
  1623. return length;
  1624. }
  1625. static DEVICE_ATTR(es325_cmd_reg, 0644, es325_cmd_reg_show, NULL);
  1626. /* /sys/devices/fe12f000.slim/es325-gen/es325_cmd_reg */
  1627. #define ES325_FW_LOAD_BUF_SZ 4
  1628. static int es325_bootup(struct es325_priv *es325)
  1629. {
  1630. char sync_cmd[] = {
  1631. 0x80, 0x00, 0x00, 0x00 /* expecting response 0x80000000 */
  1632. };
  1633. char resp[4];
  1634. char msg[4];
  1635. unsigned int buf_frames;
  1636. char *buf_ptr;
  1637. int rc;
  1638. struct slim_device *sbdev = es325->gen0_client;
  1639. dev_dbg(&sbdev->dev, "+[ES325]=%s()\n", __func__);
  1640. /* Send boot command */
  1641. memset(msg, 0, 4);
  1642. msg[0] = ES325_BOOT_CMD & 0x00ff;
  1643. msg[1] = ES325_BOOT_CMD >> 8;
  1644. dev_dbg(&sbdev->dev, "=[ES325]=%s(): msg[0] = 0x%02x msg[1] = 0x%02x msg[2] = 0x%02x msg[3] = 0x%02x\n",
  1645. __func__, msg[0], msg[1], msg[2], msg[3]);
  1646. #if defined(PREVENT_SLIMBUS_SLEEP_IN_FW_DL)
  1647. /* Enable es325_write_flag before starting FW downloading */
  1648. msm_slim_es325_write_flag_set(1);
  1649. #endif
  1650. /* Keep SLIMBus CG unchangeable during FW downloading time */
  1651. rc = slim_reservemsg_bw(sbdev, 3072000, true);
  1652. if (rc < 0)
  1653. dev_err(&sbdev->dev, "=[ES325]=%s: SLIMBus reserve BW fail", __func__);
  1654. rc = es325_request_response(es325, msg, 4, 0, msg, 4, 0, 0, 0);
  1655. if (rc < 0) {
  1656. dev_err(&sbdev->dev, "-[ES325]=%s(): firmware load failed", __func__);
  1657. debug_for_dl_firmware = BOOT_MSG_ERR;
  1658. return rc;
  1659. }
  1660. if ((msg[0] != (ES325_BOOT_ACK >> 8)) || (msg[1] != (ES325_BOOT_ACK & 0x00ff))) {
  1661. dev_err(&sbdev->dev, "-[ES325]=%s(): firmware load failed boot ack pattern", __func__);
  1662. debug_for_dl_firmware = BOOT_MSG_NACK;
  1663. return -EIO;
  1664. }
  1665. dev_info(&sbdev->dev, "=[ES325]=%s(): write firmware image\n", __func__);
  1666. /* Send image */
  1667. buf_frames = es325->fw->size / ES325_FW_LOAD_BUF_SZ;
  1668. dev_info(&sbdev->dev, "=[ES325]=%s(): buf_frames = %d", __func__, buf_frames);
  1669. buf_ptr = (char *)es325->fw->data;
  1670. for ( ; buf_frames; --buf_frames, buf_ptr += ES325_FW_LOAD_BUF_SZ) {
  1671. rc = ES325_BUS_WRITE(es325, ES325_WRITE_VE_OFFSET,
  1672. ES325_WRITE_VE_WIDTH, buf_ptr,
  1673. ES325_FW_LOAD_BUF_SZ, 0);
  1674. if (rc < 0) {
  1675. dev_err(&sbdev->dev, "-[ES325]=%s(): firmware load failed, slim write fail, rc=%d\n",
  1676. __func__, rc);
  1677. debug_for_dl_firmware = buf_frames * ES325_FW_LOAD_BUF_SZ;
  1678. return -EIO;
  1679. }
  1680. }
  1681. if (es325->fw->size % ES325_FW_LOAD_BUF_SZ) {
  1682. rc = ES325_BUS_WRITE(es325, ES325_WRITE_VE_OFFSET,
  1683. ES325_WRITE_VE_WIDTH, buf_ptr,
  1684. es325->fw->size % ES325_FW_LOAD_BUF_SZ, 0);
  1685. if (rc < 0) {
  1686. dev_err(&sbdev->dev, "-[ES325]=%s(): firmware load failed, slim write fail, rc=%d\n",
  1687. __func__, rc);
  1688. debug_for_dl_firmware = es325->fw->size % ES325_FW_LOAD_BUF_SZ;
  1689. return -EIO;
  1690. }
  1691. }
  1692. dev_info(&sbdev->dev, "=[ES325]=%s(): write ES325_SYNC_CMD\n", __func__);
  1693. /* the delay for stabilization of downloaded firmware */
  1694. msleep(40);
  1695. rc = es325_request_response(es325, sync_cmd, 4, 1, resp, 4, 1, 1, 0);
  1696. if (rc < 0) {
  1697. dev_err(&sbdev->dev, "-[ES325]=%s(): firmware load failed sync ack failed=0x%02x%02x%02x%02x\n",
  1698. __func__, resp[0], resp[1], resp[2], resp[3]);
  1699. debug_for_dl_firmware = SYNC_MSG_NACK;
  1700. return EIO;
  1701. } else {
  1702. dev_info(&sbdev->dev, "-[ES325]=%s(): firmware load success sync ack good=0x%02x%02x%02x%02x\n",
  1703. __func__, resp[0], resp[1], resp[2], resp[3]);
  1704. FW_not_ready = 0;
  1705. }
  1706. dev_info(&sbdev->dev, "-[ES325]=%s()\n", __func__);
  1707. slim_reservemsg_bw(sbdev, 0, true);
  1708. #if defined(PREVENT_SLIMBUS_SLEEP_IN_FW_DL)
  1709. /* Disable es325_write_flag after FW downloading */
  1710. msm_slim_es325_write_flag_set(0);
  1711. #endif
  1712. return 0;
  1713. }
  1714. static int register_snd_soc(struct es325_priv *priv);
  1715. static int fw_download(void *arg)
  1716. {
  1717. struct es325_priv *priv = (struct es325_priv *)arg;
  1718. int rc;
  1719. pr_info("+[ES325]=%s()\n", __func__);
  1720. pr_info("=[ES325]=%s(): es325 gen0 LA=%d\n", __func__, priv->gen0_client->laddr);
  1721. #ifdef BUS_TRANSACTIONS
  1722. rc = es325_bootup(priv);
  1723. #endif
  1724. pr_info("=[ES325]=%s(): bootup rc=%d\n", __func__, rc);
  1725. pr_info("=[ES325]=%s(): would release firmware here...\n", __func__);
  1726. release_firmware(priv->fw);
  1727. pr_info("=[ES325]=%s(): registering sound soc\n", __func__);
  1728. rc = register_snd_soc(priv);
  1729. pr_info("=[ES325]=%s(): register_snd_soc rc=%d\n", __func__, rc);
  1730. #ifdef FIXED_CONFIG
  1731. es325_fixed_config(priv);
  1732. #endif
  1733. pr_info("=[ES325]=%s(): release module\n", __func__);
  1734. module_put(THIS_MODULE);
  1735. pr_info("-[ES325]=%s()\n", __func__);
  1736. return 0;
  1737. }
  1738. static const char *fw_path[] = {
  1739. "/data"
  1740. };
  1741. /* Don't inline this: 'struct kstat' is biggish */
  1742. static noinline_for_stack long fw_file_size(struct file *file)
  1743. {
  1744. struct kstat st;
  1745. if (vfs_getattr(file->f_path.mnt, file->f_path.dentry, &st))
  1746. return -1;
  1747. if (!S_ISREG(st.mode))
  1748. return -1;
  1749. if (st.size != (long)st.size)
  1750. return -1;
  1751. return st.size;
  1752. }
  1753. static bool fw_read_file_contents(struct file *file, struct firmware *fw)
  1754. {
  1755. long size;
  1756. char *buf;
  1757. size = fw_file_size(file);
  1758. if (size < 0)
  1759. return false;
  1760. buf = vmalloc(size);
  1761. if (!buf)
  1762. return false;
  1763. if (kernel_read(file, 0, buf, size) != size) {
  1764. vfree(buf);
  1765. return false;
  1766. }
  1767. fw->data = buf;
  1768. fw->size = size;
  1769. return true;
  1770. }
  1771. static bool fw_get_filesystem_firmware(struct firmware *fw, const char *name)
  1772. {
  1773. int i;
  1774. bool rc = false;
  1775. char *path = __getname();
  1776. for (i = 0; i < ARRAY_SIZE(fw_path); i++) {
  1777. struct file *file;
  1778. snprintf(path, PATH_MAX, "%s/%s", fw_path[i], name);
  1779. file = filp_open(path, O_RDONLY, 0);
  1780. if (IS_ERR(file))
  1781. continue;
  1782. rc = fw_read_file_contents(file, fw);
  1783. fput(file);
  1784. if (rc)
  1785. break;
  1786. }
  1787. __putname(path);
  1788. return rc;
  1789. }
  1790. static int es325_sleep(struct es325_priv *es325);
  1791. static int es325_wakeup(struct es325_priv *es325);
  1792. static ssize_t es325_firmware_store(struct device *dev, struct device_attribute *attr,
  1793. const char *buf, size_t count)
  1794. {
  1795. unsigned long val;
  1796. int rc;
  1797. const char *name = CONFIG_EXTRA_FIRMWARE;
  1798. rc = kstrtoul(buf, 10, &val);
  1799. if (rc) {
  1800. dev_err(dev, "=[ES325]=%s() err %d\n", __func__, rc);
  1801. return rc;
  1802. }
  1803. if(val == 1) {
  1804. fw_get_filesystem_firmware(es325_priv.fw, name);
  1805. if(es325_priv.fw->data == NULL){
  1806. dev_err(dev, "=[ES325]=%s(): there is no firmware found\n", __func__);
  1807. return count;
  1808. }
  1809. es325_enable_ext_clk(1);
  1810. usleep_range(1000, 1000);
  1811. es325_wakeup(&es325_priv);
  1812. es325_priv.clock_on = 1;
  1813. /* reset the audience chip */
  1814. gpio_set_value(es325_priv.pdata->reset_gpio, 0);
  1815. usleep_range(1000,1000);
  1816. gpio_set_value(es325_priv.pdata->reset_gpio, 1);
  1817. msleep(50);
  1818. /* Get the control for wakeup GPIO */
  1819. mutex_lock(&es325_priv.wakeup_mutex);
  1820. if (uart_enable) {
  1821. gpio_direction_output(es325_priv.pdata->wakeup_gpio, 1);
  1822. usleep_range(5000, 5100);
  1823. }
  1824. /* Make sure wakeup pin is High before wake up */
  1825. gpio_set_value(es325_priv.pdata->wakeup_gpio, 1);
  1826. msleep(50);
  1827. mutex_unlock(&es325_priv.wakeup_mutex);
  1828. es325_bootup(&es325_priv);
  1829. #ifdef FIXED_CONFIG
  1830. es325_fixed_config(&es325_priv);
  1831. #endif
  1832. es325_sleep(&es325_priv);
  1833. es325_enable_ext_clk(0);
  1834. es325_priv.clock_on = 0;
  1835. } else {
  1836. return -EINVAL;
  1837. }
  1838. return count;
  1839. }
  1840. static DEVICE_ATTR(firmware, 0644, NULL, es325_firmware_store);
  1841. static ssize_t es325_uart_set(struct device *dev, struct device_attribute *attr,
  1842. const char *buf, size_t count)
  1843. {
  1844. unsigned int value = 0;
  1845. sscanf(buf, "%d", &value);
  1846. pr_info("%s : [ES325] uart_set = %d\n", __func__, value);
  1847. if (value == 1)
  1848. uart_enable = 1;
  1849. else
  1850. uart_enable = 0;
  1851. return count;
  1852. }
  1853. static DEVICE_ATTR(uart_set, 0644, NULL, es325_uart_set);
  1854. /*
  1855. * es325_sleep algorithm
  1856. *
  1857. * 1. set in 0 possible Smooth Mute time
  1858. * 2. send Power Off command to es325
  1859. * 3. write Sync command to es325
  1860. * 4. if write fail then
  1861. * es325 is in sleep, return 0
  1862. * 5. else wait 1 ms and read response
  1863. * if no response from es325 then
  1864. * es325 is in sleep, return 0
  1865. * else if Sync was write more then 20 times then
  1866. * was reach MAX_WAIT_TO_SLEEP time
  1867. * es325_sleep fail, return -1
  1868. * else goto point 3
  1869. *
  1870. * Note: After es325 switch to sleep mode and
  1871. * Sync write or read fails SLIMBus generates error message.
  1872. * "slim_read failed rc=-5" OR "slim_write failed rc=-5"
  1873. * SLIMBus error message indicates that es325 is in sleep
  1874. */
  1875. static int es325_sleep(struct es325_priv *es325)
  1876. {
  1877. char smooth_rate_cmd[] = {
  1878. 0x90, 0x4e, 0x00, 0x00 /* response not expected */
  1879. };
  1880. char pwr_cmd[] = {
  1881. 0x90, 0x10, 0x00, 0x01 /* response not expected */
  1882. };
  1883. #ifdef DEBUG
  1884. char sync_cmd[] = {
  1885. 0x80, 0x00, 0x00, 0x01 /* expecting response 0x80000001 */
  1886. };
  1887. char resp[4];
  1888. #endif
  1889. int i = 0;
  1890. int rc;
  1891. struct slim_device *sbdev = es325->gen0_client;
  1892. dev_info(&sbdev->dev, "+[ES325]=%s()\n", __func__);
  1893. /* Set Smooth Mute period to 0 ms */
  1894. rc = ES325_BUS_WRITE(es325, ES325_WRITE_VE_OFFSET,
  1895. ES325_WRITE_VE_WIDTH, smooth_rate_cmd, 4, 1);
  1896. if (rc < 0)
  1897. dev_err(&sbdev->dev, "=[ES325]=%s(): Sleep Smooth Mute Set to 0 Fail, rc=%d\n",
  1898. __func__, rc);
  1899. /* write pwr command, es325 to sleep mode */
  1900. do {
  1901. rc = ES325_BUS_WRITE(es325, ES325_WRITE_VE_OFFSET,
  1902. ES325_WRITE_VE_WIDTH, pwr_cmd, 4, 1);
  1903. if (rc == 0) {
  1904. /* wait 20 ms according to spec end return.
  1905. eS325 is sleeping */
  1906. msleep(20);
  1907. break;
  1908. }
  1909. dev_dbg(&sbdev->dev, "=[ES325]=%s(): slim write fail, rc=%d\n", __func__,rc);
  1910. usleep_range(SMB_DELAY, SMB_DELAY);
  1911. i++;
  1912. } while (i <= MAX_TRIALS);
  1913. #ifdef DEBUG
  1914. if (rc == 0) {
  1915. rc = es325_request_response(es325, sync_cmd, 4, 1, resp, 4, 1, 0, 1);
  1916. if (rc < 0)
  1917. rc = 0; /* es325 is sleeping */
  1918. else if (memcmp(sync_cmd, resp, 4))
  1919. dev_err(&sbdev->dev, "=[ES325]=%s: Unexpected response %02x%02x%02x%02x\n",
  1920. __func__, resp[3], resp[2], resp[1], resp[0]);
  1921. }
  1922. #endif
  1923. dev_info(&sbdev->dev, "-[ES325]=%s()\n", __func__);
  1924. return rc;
  1925. }
  1926. /*
  1927. * es325_wakeup algorithm
  1928. *
  1929. * 1. generate es325 wakeup signal
  1930. * 2. wait 30ms
  1931. * 3. write / read Sync command up to 20 times
  1932. * with 1ms delay or until write / read success
  1933. * 4. if write / read fail (wakeup fail) return error code
  1934. * else return 0
  1935. *
  1936. * Note: SLIMBus generates errors for unsucsessfull write / read
  1937. * commands. These errors indicates that es325 not ready yet
  1938. */
  1939. static int es325_wakeup(struct es325_priv *es325)
  1940. {
  1941. char sync_cmd[] = {
  1942. 0x80, 0x00, 0x00, 0x01 /* expecting response 0x80000001 */
  1943. };
  1944. int rc;
  1945. char resp[4];
  1946. struct slim_device *sbdev = es325->gen0_client;
  1947. dev_info(&sbdev->dev, "+[ES325]=%s()\n", __func__);
  1948. /* Get the control for wakeup GPIO */
  1949. mutex_lock(&es325->wakeup_mutex);
  1950. if (uart_enable) {
  1951. gpio_direction_output(es325_priv.pdata->wakeup_gpio, 1);
  1952. usleep_range(5000, 5100);
  1953. }
  1954. /* ASSUMES CLOCK HAS ALREADY BEEN ENABLED AND STABILIZED.
  1955. Follow recommended steps for es325 wakeup
  1956. 1. Set Wakeup pin low ( H->L)
  1957. 2. Set Wakeup pin high (L->H)
  1958. 3. Wait 30 ms <<< delay moves into es325_request_response and
  1959. combines with SYNC request / response delay
  1960. es325 will be ready in time range 1 to 30 ms
  1961. 4. Send sync command */
  1962. #ifdef CONFIG_ES325_UART_WORKAROUND
  1963. #if defined(CONFIG_MACH_HLTESPR) && !defined(CONFIG_ES325_UART_WORKAROUND_ENG_ONLY)
  1964. if (system_rev == 4) {
  1965. pr_info("%s : [ES325] ES325_UART_WORKAROUND system rev = %d\n", __func__, system_rev);
  1966. gpio_tlmm_config(GPIO_CFG(4, 0, GPIO_CFG_INPUT,
  1967. GPIO_CFG_PULL_UP, GPIO_CFG_2MA), 1);
  1968. gpio_tlmm_config(GPIO_CFG(5, 0, GPIO_CFG_INPUT,
  1969. GPIO_CFG_PULL_UP, GPIO_CFG_2MA), 1);
  1970. gpio_set_value(4, 1);
  1971. gpio_set_value(5, 1);
  1972. usleep_range(10000, 10000);
  1973. }
  1974. #elif defined(CONFIG_MACH_HLTEUSC) && defined(CONFIG_ES325_UART_WORKAROUND_ENG_ONLY)
  1975. if (system_rev == 4) {
  1976. pr_info("%s : [ES325] ES325_UART_WORKAROUND system rev = %d\n", __func__, system_rev);
  1977. gpio_tlmm_config(GPIO_CFG(4, 0, GPIO_CFG_INPUT,
  1978. GPIO_CFG_PULL_UP, GPIO_CFG_2MA), 1);
  1979. gpio_tlmm_config(GPIO_CFG(5, 0, GPIO_CFG_INPUT,
  1980. GPIO_CFG_PULL_UP, GPIO_CFG_2MA), 1);
  1981. gpio_set_value(4, 1);
  1982. gpio_set_value(5, 1);
  1983. usleep_range(10000, 10000);
  1984. }
  1985. #elif (defined(CONFIG_MACH_HLTESKT) || defined(CONFIG_MACH_HLTEKTT) || defined(CONFIG_MACH_FRESCOLTESKT) || defined(CONFIG_MACH_FRESCOLTEKTT)) \
  1986. && defined(CONFIG_ES325_UART_WORKAROUND_ENG_ONLY)
  1987. if (system_rev == 5) {
  1988. pr_info("%s : [ES325] ES325_UART_WORKAROUND system rev = %d\n", __func__, system_rev);
  1989. gpio_tlmm_config(GPIO_CFG(4, 0, GPIO_CFG_INPUT,
  1990. GPIO_CFG_PULL_UP, GPIO_CFG_2MA), 1);
  1991. gpio_tlmm_config(GPIO_CFG(5, 0, GPIO_CFG_INPUT,
  1992. GPIO_CFG_PULL_UP, GPIO_CFG_2MA), 1);
  1993. gpio_set_value(4, 1);
  1994. gpio_set_value(5, 1);
  1995. usleep_range(10000, 10000);
  1996. }
  1997. #else
  1998. #endif
  1999. #endif /* CONFIG_ES325_UART_WORKAROUND */
  2000. /* Assert wakeup signal L->H. */
  2001. gpio_set_value(es325->pdata->wakeup_gpio, 0);
  2002. msleep(30);
  2003. rc = es325_request_response(es325, sync_cmd, 4, 1, resp, 4, 1, 1, 0);
  2004. if (rc < 0) {
  2005. dev_info(&sbdev->dev, "=[ES325]=%s(): es325 wakeup FAIL\n", __func__);
  2006. }
  2007. /* Deassert wakeup signal L->H. */
  2008. gpio_set_value(es325->pdata->wakeup_gpio, 1);
  2009. if (uart_enable)
  2010. gpio_direction_input(es325_priv.pdata->wakeup_gpio);
  2011. usleep_range(5000, 5100);
  2012. mutex_unlock(&es325->wakeup_mutex);
  2013. dev_info(&sbdev->dev, "-[ES325]=%s()\n", __func__);
  2014. return rc;
  2015. }
  2016. static int es325_put_control_value(struct snd_kcontrol *kcontrol,
  2017. struct snd_ctl_elem_value *ucontrol)
  2018. {
  2019. struct soc_mixer_control *mc = (struct soc_mixer_control *)kcontrol->private_value;
  2020. unsigned int reg = mc->reg;
  2021. unsigned int value;
  2022. int rc = 0;
  2023. value = ucontrol->value.integer.value[0];
  2024. if(FW_not_ready || es325_priv.wakeup_cnt == 0) {
  2025. pr_info("%s: es325 not ready, return\n", __func__);
  2026. return 0;
  2027. }
  2028. rc = es325_write(NULL, reg, value);
  2029. return 0;
  2030. }
  2031. static int es325_get_control_value(struct snd_kcontrol *kcontrol,
  2032. struct snd_ctl_elem_value *ucontrol)
  2033. {
  2034. struct soc_mixer_control *mc = (struct soc_mixer_control *)kcontrol->private_value;
  2035. unsigned int reg = mc->reg;
  2036. unsigned int value;
  2037. if(FW_not_ready || es325_priv.wakeup_cnt == 0) {
  2038. pr_info("%s: es325 not ready, return\n", __func__);
  2039. ucontrol->value.integer.value[0] = 0;
  2040. return 0;
  2041. }
  2042. value = es325_read(NULL, reg);
  2043. ucontrol->value.integer.value[0] = value;
  2044. return 0;
  2045. }
  2046. static int es325_put_control_enum(struct snd_kcontrol *kcontrol,
  2047. struct snd_ctl_elem_value *ucontrol)
  2048. {
  2049. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  2050. struct es325_priv *es325 = &es325_priv;
  2051. struct slim_device *sbdev = es325->gen0_client;
  2052. unsigned int reg = e->reg;
  2053. unsigned int max = e->max;
  2054. unsigned int value;
  2055. int rc;
  2056. dev_dbg(&sbdev->dev, "=[ES325]=%s(): reg = %d, max = %d\n", __func__, reg, max);
  2057. value = ucontrol->value.enumerated.item[0];
  2058. if(FW_not_ready || es325_priv.wakeup_cnt == 0) {
  2059. pr_info("%s: es325 not ready, return\n", __func__);
  2060. return 0;
  2061. }
  2062. rc = es325_write(NULL, reg, value);
  2063. return 0;
  2064. }
  2065. static int es325_get_control_enum(struct snd_kcontrol *kcontrol,
  2066. struct snd_ctl_elem_value *ucontrol)
  2067. {
  2068. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  2069. struct es325_priv *es325 = &es325_priv;
  2070. struct slim_device *sbdev = es325->gen0_client;
  2071. unsigned int reg = e->reg;
  2072. unsigned int max = e->max;
  2073. unsigned int value;
  2074. if(FW_not_ready || es325_priv.wakeup_cnt == 0) {
  2075. pr_info("%s: es325 not ready, return\n", __func__);
  2076. ucontrol->value.enumerated.item[0] = 0;
  2077. return 0;
  2078. }
  2079. dev_dbg(&sbdev->dev, "=[ES325]=%s(): reg = %d, max = %d\n", __func__, reg, max);
  2080. value = es325_read(NULL, reg);
  2081. ucontrol->value.enumerated.item[0] = value;
  2082. return 0;
  2083. }
  2084. static void es325_update_VEQ_enable(void)
  2085. {
  2086. struct es325_priv *es325 = &es325_priv;
  2087. struct slim_device *sbdev = es325->gen0_client;
  2088. char msg[8] = {0xb0, 0x17, 0x00, 0x09, 0x90, 0x18, 0x00, 0x00}; /*VEQ Disable */
  2089. int rc;
  2090. if (es325_VEQ_enable_new != 0)
  2091. return;
  2092. if (es325_priv.wakeup_cnt) {
  2093. if (es325_VEQ_enable_new)
  2094. msg[7] = 0x01; /* VEQ Enable */
  2095. dev_dbg(&sbdev->dev, "=[ES325]=%s: write=0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x\n",
  2096. __func__, msg[0], msg[1], msg[2], msg[3],
  2097. msg[4], msg[5], msg[6], msg[7]);
  2098. rc = ES325_BUS_WRITE(es325, ES325_WRITE_VE_OFFSET,
  2099. ES325_WRITE_VE_WIDTH, msg, 4, 1);
  2100. if (rc < 0) {
  2101. dev_err(&sbdev->dev, "=[ES325]=%s: slim write fail, rc=%d\n",
  2102. __func__, rc);
  2103. return;
  2104. }
  2105. rc = ES325_BUS_WRITE(es325, ES325_WRITE_VE_OFFSET,
  2106. ES325_WRITE_VE_WIDTH, msg+4, 4, 1);
  2107. if (rc < 0) {
  2108. dev_err(&sbdev->dev, "=[ES325]=%s: slim write fail, rc=%d\n",
  2109. __func__, rc);
  2110. return;
  2111. }
  2112. es325_VEQ_enable = es325_VEQ_enable_new;
  2113. }
  2114. dev_info(&sbdev->dev, "=[ES325]=%s VEQ enable value=%d =\n",__func__,es325_VEQ_enable);
  2115. }
  2116. static int es325_put_VEQ_enable_control(struct snd_kcontrol *kcontrol,
  2117. struct snd_ctl_elem_value *ucontrol)
  2118. {
  2119. es325_VEQ_enable_new = ucontrol->value.integer.value[0];
  2120. return 0;
  2121. }
  2122. static int es325_get_VEQ_enable_control(struct snd_kcontrol *kcontrol,
  2123. struct snd_ctl_elem_value *ucontrol)
  2124. {
  2125. ucontrol->value.integer.value[0] = es325_VEQ_enable_new;
  2126. return 0;
  2127. }
  2128. static void es325_update_BWE_enable(void)
  2129. {
  2130. struct es325_priv *es325 = &es325_priv;
  2131. struct slim_device *sbdev = es325->gen0_client;
  2132. char msg[8] = {0xb0, 0x17, 0x00, 0x4f, 0x90, 0x18, 0x00, 0x00}; /* BWE Off */
  2133. int rc;
  2134. dev_info(&sbdev->dev, "[ES325] %s: curr=%d, new=%d\n", __func__, es325_BWE_enable, es325_BWE_enable_new);
  2135. if (es325_BWE_enable == es325_BWE_enable_new)
  2136. return;
  2137. if (es325_priv.wakeup_cnt) {
  2138. if (es325_BWE_enable_new)
  2139. msg[7] = 0x01; /* BWE On */
  2140. dev_info(&sbdev->dev, "=[ES325]=%s: write=0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x\n",
  2141. __func__, msg[0], msg[1], msg[2], msg[3],
  2142. msg[4], msg[5], msg[6], msg[7]);
  2143. rc = ES325_BUS_WRITE(es325, ES325_WRITE_VE_OFFSET,
  2144. ES325_WRITE_VE_WIDTH, msg, 4, 1);
  2145. if (rc < 0) {
  2146. dev_err(&sbdev->dev, "=[ES325]=%s: slim write fail, rc=%d\n",
  2147. __func__, rc);
  2148. return;
  2149. }
  2150. rc = ES325_BUS_WRITE(es325, ES325_WRITE_VE_OFFSET,
  2151. ES325_WRITE_VE_WIDTH, msg+4, 4, 1);
  2152. if (rc < 0) {
  2153. dev_err(&sbdev->dev, "=[ES325]=%s: slim write fail, rc=%d\n",
  2154. __func__, rc);
  2155. return;
  2156. }
  2157. es325_BWE_enable = es325_BWE_enable_new;
  2158. }
  2159. dev_info(&sbdev->dev, "=[ES325]=%s BWE enable value=%d =\n", __func__, es325_BWE_enable);
  2160. }
  2161. static int es325_put_BWE_enable_control(struct snd_kcontrol *kcontrol,
  2162. struct snd_ctl_elem_value *ucontrol)
  2163. {
  2164. struct es325_priv *es325 = &es325_priv;
  2165. struct slim_device *sbdev = es325->gen0_client;
  2166. dev_info(&sbdev->dev, "=[ES325]=%s: value=%d\n", __func__, es325_BWE_enable_new);
  2167. es325_BWE_enable_new = ucontrol->value.integer.value[0];
  2168. if(FW_not_ready || es325_priv.wakeup_cnt == 0) {
  2169. pr_info("%s: es325 not ready, return\n", __func__);
  2170. return 0;
  2171. }
  2172. es325_update_BWE_enable();
  2173. return 0;
  2174. }
  2175. static int es325_get_BWE_enable_control(struct snd_kcontrol *kcontrol,
  2176. struct snd_ctl_elem_value *ucontrol)
  2177. {
  2178. ucontrol->value.integer.value[0] = es325_BWE_enable_new;
  2179. return 0;
  2180. }
  2181. static void es325_update_Tx_NS(void)
  2182. {
  2183. struct es325_priv *es325 = &es325_priv;
  2184. struct slim_device *sbdev = es325->gen0_client;
  2185. char msg[8] = {0xb0, 0x17, 0x00, 0x4b, 0x90, 0x18, 0x00, 0x00}; /* Tx NS level */
  2186. int rc;
  2187. if (es325_Tx_NS == es325_Tx_NS_new)
  2188. return;
  2189. if (es325_priv.wakeup_cnt) {
  2190. msg[7] = es325_Tx_NS_new;
  2191. dev_dbg(&sbdev->dev, "=[ES325]=%s: write=0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x\n",
  2192. __func__, msg[0], msg[1], msg[2], msg[3],
  2193. msg[4], msg[5], msg[6], msg[7]);
  2194. rc = ES325_BUS_WRITE(es325, ES325_WRITE_VE_OFFSET,
  2195. ES325_WRITE_VE_WIDTH, msg, 4, 1);
  2196. if (rc < 0) {
  2197. dev_err(&sbdev->dev, "=[ES325]=%s: slim write fail, rc=%d\n",
  2198. __func__, rc);
  2199. return;
  2200. }
  2201. rc = ES325_BUS_WRITE(es325, ES325_WRITE_VE_OFFSET,
  2202. ES325_WRITE_VE_WIDTH, msg+4, 4, 1);
  2203. if (rc < 0) {
  2204. dev_err(&sbdev->dev, "=[ES325]=%s: slim write fail, rc=%d\n",
  2205. __func__, rc);
  2206. return;
  2207. }
  2208. es325_Tx_NS = es325_Tx_NS_new;
  2209. }
  2210. dev_info(&sbdev->dev, "=[ES325]=%s Tx Ns value=%d =\n",__func__,es325_Tx_NS);
  2211. }
  2212. static int es325_put_Tx_NS_control(struct snd_kcontrol *kcontrol,
  2213. struct snd_ctl_elem_value *ucontrol)
  2214. {
  2215. es325_Tx_NS_new = ucontrol->value.integer.value[0];
  2216. if(FW_not_ready || es325_priv.wakeup_cnt == 0) {
  2217. pr_info("%s: es325 not ready, return\n", __func__);
  2218. return 0;
  2219. }
  2220. es325_update_Tx_NS();
  2221. return 0;
  2222. }
  2223. static int es325_get_Tx_NS_control(struct snd_kcontrol *kcontrol,
  2224. struct snd_ctl_elem_value *ucontrol)
  2225. {
  2226. ucontrol->value.integer.value[0] = es325_Tx_NS_new;
  2227. return 0;
  2228. }
  2229. static int es325_get_rx1_route_enable_value(struct snd_kcontrol *kcontrol,
  2230. struct snd_ctl_elem_value *ucontrol)
  2231. {
  2232. ucontrol->value.integer.value[0] = es325_rx1_route_enable;
  2233. return 0;
  2234. }
  2235. static int es325_put_rx1_route_enable_value(struct snd_kcontrol *kcontrol,
  2236. struct snd_ctl_elem_value *ucontrol)
  2237. {
  2238. es325_rx1_route_enable = ucontrol->value.integer.value[0];
  2239. return 0;
  2240. }
  2241. static int es325_get_tx1_route_enable_value(struct snd_kcontrol *kcontrol,
  2242. struct snd_ctl_elem_value *ucontrol)
  2243. {
  2244. ucontrol->value.integer.value[0] = es325_tx1_route_enable;
  2245. return 0;
  2246. }
  2247. static int es325_put_tx1_route_enable_value(struct snd_kcontrol *kcontrol,
  2248. struct snd_ctl_elem_value *ucontrol)
  2249. {
  2250. es325_tx1_route_enable = ucontrol->value.integer.value[0];
  2251. return 0;
  2252. }
  2253. static int es325_get_rx2_route_enable_value(struct snd_kcontrol *kcontrol,
  2254. struct snd_ctl_elem_value *ucontrol)
  2255. {
  2256. ucontrol->value.integer.value[0] = es325_rx2_route_enable;
  2257. return 0;
  2258. }
  2259. static int es325_put_rx2_route_enable_value(struct snd_kcontrol *kcontrol,
  2260. struct snd_ctl_elem_value *ucontrol)
  2261. {
  2262. es325_rx2_route_enable = ucontrol->value.integer.value[0];
  2263. return 0;
  2264. }
  2265. int es325_remote_route_enable(struct snd_soc_dai *dai)
  2266. {
  2267. switch (dai->id) {
  2268. case ES325_SLIM_1_PB:
  2269. return es325_rx1_route_enable;
  2270. case ES325_SLIM_1_CAP:
  2271. return es325_tx1_route_enable;
  2272. case ES325_SLIM_2_PB:
  2273. return es325_rx2_route_enable;
  2274. default:
  2275. return 0;
  2276. }
  2277. }
  2278. EXPORT_SYMBOL_GPL(es325_remote_route_enable);
  2279. static int es325_put_internal_route_config(struct snd_kcontrol *kcontrol,
  2280. struct snd_ctl_elem_value *ucontrol)
  2281. {
  2282. #ifdef ES325_SLEEP
  2283. struct es325_priv *es325 = &es325_priv;
  2284. struct slim_device *sbdev = es325->gen0_client;
  2285. dev_info(&sbdev->dev, "=[ES325]=%s(): route = %ld\n", __func__, ucontrol->value.integer.value[0]);
  2286. es325->new_internal_route_config = ucontrol->value.integer.value[0];
  2287. if(FW_not_ready || es325_priv.wakeup_cnt == 0) {
  2288. pr_info("%s: es325 not ready, return\n", __func__);
  2289. return 0;
  2290. }
  2291. if(es325->new_internal_route_config == 5 && es325_priv.wakeup_cnt)
  2292. es325_switch_route();
  2293. #else
  2294. es325_switch_route(ucontrol->value.integer.value[0]);
  2295. #endif
  2296. return 0;
  2297. }
  2298. static int es325_get_internal_route_config(struct snd_kcontrol *kcontrol,
  2299. struct snd_ctl_elem_value *ucontrol)
  2300. {
  2301. #ifndef ES325_SLEEP
  2302. ucontrol->value.integer.value[0] = es325_internal_route_num;
  2303. return 0;
  2304. #else
  2305. struct es325_priv *es325 = &es325_priv;
  2306. struct slim_device *sbdev = es325->gen0_client;
  2307. dev_info(&sbdev->dev, "=[ES325]= %s(): route = %ld\n", __func__, es325_internal_route_num);
  2308. ucontrol->value.integer.value[0] = es325->new_internal_route_config;
  2309. return 0;
  2310. #endif
  2311. }
  2312. static int es325_put_network_type(struct snd_kcontrol *kcontrol,
  2313. struct snd_ctl_elem_value *ucontrol)
  2314. {
  2315. struct es325_priv *es325 = &es325_priv;
  2316. struct slim_device *sbdev = es325->gen0_client;
  2317. int network = ucontrol->value.integer.value[0];
  2318. dev_info(&sbdev->dev, "=[ES325]=%s():new network type = %d\n", __func__, network);
  2319. if (network != NARROW_BAND)
  2320. es325_network_type = WIDE_BAND;
  2321. else
  2322. es325_network_type = NARROW_BAND;
  2323. if(FW_not_ready || es325_priv.wakeup_cnt == 0) {
  2324. pr_info("%s: es325 not ready, return\n", __func__);
  2325. return 0;
  2326. }
  2327. mutex_lock(&es325_priv.pm_mutex);
  2328. if (es325_priv.wakeup_cnt) {
  2329. es325_switch_route();
  2330. }
  2331. mutex_unlock(&es325_priv.pm_mutex);
  2332. return 0;
  2333. }
  2334. static int es325_get_network_type(struct snd_kcontrol *kcontrol,
  2335. struct snd_ctl_elem_value *ucontrol)
  2336. {
  2337. struct es325_priv *es325 = &es325_priv;
  2338. struct slim_device *sbdev = es325->gen0_client;
  2339. ucontrol->value.integer.value[0] = es325_network_type;
  2340. dev_dbg(&sbdev->dev, "=[ES325]= %s(): es325 network type = %d\n", __func__, es325_network_type);
  2341. return 0;
  2342. }
  2343. int es325_set_VEQ_max_gain(int volume)
  2344. {
  2345. struct es325_priv *es325 = &es325_priv;
  2346. struct slim_device *sbdev = es325->gen0_client;
  2347. char msg[4];
  2348. static char cmd_str[8] = {0xb0, 0x17, 0x00, 0x00, 0x90, 0x18, 0x00, 0x00};
  2349. #if defined(CONFIG_MACH_HLTEVZW) || defined(CONFIG_MACH_HLTEUSC)
  2350. /* 8 level Voice Rx volume for VZW */
  2351. static char VEQ_max_gain[8] = {3, 3, 3, 5, 7, 9, 7, 4}; /* index 0 means max volume */
  2352. static char VEQ_adj_gain[8] = {30, 2, 2, 2, 2, 2, 2, 2};
  2353. #elif defined(CONFIG_MACH_HLTETMO)
  2354. static char VEQ_max_gain[6] = {3, 5, 7, 9, 7, 4}; /* index 0 means max volume */
  2355. static char VEQ_adj_gain[6] = {25, 2, 2, 2, 2, 2};
  2356. #elif defined(CONFIG_MACH_HLTEATT) || defined(CONFIG_MACH_HLTEEUR) || defined(CONFIG_MACH_H3GDUOS)
  2357. static char VEQ_max_gain[6] = {3, 5, 7, 9, 7, 4}; /* index 0 means max volume */
  2358. static char VEQ_adj_gain[6] = {25, 2, 2, 2, 2, 2};
  2359. #elif defined(CONFIG_MACH_HLTESPR)
  2360. static char VEQ_max_gain[6] = {5, 5, 7, 9, 7, 4}; /* index 0 means max volume */
  2361. static char VEQ_adj_gain[6] = {30, 2, 2, 2, 2, 2};
  2362. #else
  2363. static char VEQ_max_gain[6] = {3, 5, 7, 9, 7, 4}; /* index 0 means max volume */
  2364. static char VEQ_adj_gain[6] = {0, 0, 0, 0, 0, 0};
  2365. #endif
  2366. int rc;
  2367. dev_info(&sbdev->dev, "=[ES325]=%s: volume=%d, wakeup_cnt =%d\n", __func__,
  2368. volume, es325_priv.wakeup_cnt);
  2369. if (!es325_priv.wakeup_cnt) {
  2370. pr_info("%s: ES325 is sleep. Skip to set the volume.\n", __func__);
  2371. return 0;
  2372. }
  2373. cmd_str[3] = 0x3d; /* VEQ Max Gain ID */
  2374. cmd_str[7] = VEQ_max_gain[volume];
  2375. memcpy(msg, cmd_str, 4);
  2376. dev_dbg(&sbdev->dev, "=[ES325]=%s: write=0x%x, 0x%x, 0x%x, 0x%x\n", __func__, msg[0], msg[1], msg[2], msg[3]);
  2377. rc = ES325_BUS_WRITE(es325, ES325_WRITE_VE_OFFSET, ES325_WRITE_VE_WIDTH, msg, 4, 1);
  2378. if (rc < 0) {
  2379. dev_err(&sbdev->dev, "=[ES325]=%s: slim write fail, rc=%d\n",
  2380. __func__, rc);
  2381. return rc;
  2382. }
  2383. memcpy(msg, cmd_str+4, 4);
  2384. dev_dbg(&sbdev->dev, "=[ES325]=%s: write=0x%x, 0x%x, 0x%x, 0x%x\n", __func__, msg[0], msg[1], msg[2], msg[3]);
  2385. rc = ES325_BUS_WRITE(es325, ES325_WRITE_VE_OFFSET, ES325_WRITE_VE_WIDTH, msg, 4, 1);
  2386. if (rc < 0) {
  2387. dev_err(&sbdev->dev, "=[ES325]=%s: slim write fail, rc=%d\n",
  2388. __func__, rc);
  2389. return rc;
  2390. }
  2391. cmd_str[3] = 0x25; /* VEQ Noise Estimate Adj */
  2392. cmd_str[7] = VEQ_adj_gain[volume];
  2393. memcpy(msg, cmd_str, 4);
  2394. dev_dbg(&sbdev->dev, "=[ES325]=%s: write=0x%x, 0x%x, 0x%x, 0x%x\n", __func__, msg[0], msg[1], msg[2], msg[3]);
  2395. rc = ES325_BUS_WRITE(es325, ES325_WRITE_VE_OFFSET, ES325_WRITE_VE_WIDTH, msg, 4, 1);
  2396. if (rc < 0) {
  2397. dev_err(&sbdev->dev, "=[ES325]=%s: slim write fail, rc=%d\n",
  2398. __func__, rc);
  2399. return rc;
  2400. }
  2401. memcpy(msg, cmd_str+4, 4);
  2402. dev_dbg(&sbdev->dev, "=[ES325]=%s: write=0x%x, 0x%x, 0x%x, 0x%x\n", __func__, msg[0], msg[1], msg[2], msg[3]);
  2403. rc = ES325_BUS_WRITE(es325, ES325_WRITE_VE_OFFSET, ES325_WRITE_VE_WIDTH, msg, 4, 1);
  2404. if (rc < 0) {
  2405. dev_err(&sbdev->dev, "=[ES325]=%s: slim write fail, rc=%d\n",
  2406. __func__, rc);
  2407. return rc;
  2408. }
  2409. return 0;
  2410. }
  2411. EXPORT_SYMBOL_GPL(es325_set_VEQ_max_gain);
  2412. static int es325_ap_put_tx1_ch_cnt(struct snd_kcontrol *kcontrol,
  2413. struct snd_ctl_elem_value *ucontrol)
  2414. {
  2415. struct es325_priv *es325 = &es325_priv;
  2416. struct slim_device *sbdev = es325->gen0_client;
  2417. es325_ap_tx1_ch_cnt = ucontrol->value.enumerated.item[0] + 1;
  2418. dev_dbg(&sbdev->dev, "=[ES325]=%s():tx1 ch cnt = %d\n", __func__, es325_ap_tx1_ch_cnt);
  2419. return 0;
  2420. }
  2421. static int es325_ap_get_tx1_ch_cnt(struct snd_kcontrol *kcontrol,
  2422. struct snd_ctl_elem_value *ucontrol)
  2423. {
  2424. struct es325_priv *es325 = &es325_priv;
  2425. struct slim_device *sbdev = es325->gen0_client;
  2426. dev_dbg(&sbdev->dev, "=[ES325]=%s(): tx1 ch cnt = %d\n", __func__, es325_ap_tx1_ch_cnt);
  2427. ucontrol->value.enumerated.item[0] = es325_internal_route_num - 1;
  2428. return 0;
  2429. }
  2430. static const char * const es325_ap_tx1_ch_cnt_texts[] = {
  2431. "One", "Two"
  2432. };
  2433. static const struct soc_enum es325_ap_tx1_ch_cnt_enum =
  2434. SOC_ENUM_SINGLE(SND_SOC_NOPM, 0, ARRAY_SIZE(es325_ap_tx1_ch_cnt_texts), es325_ap_tx1_ch_cnt_texts);
  2435. /* generic gain translation */
  2436. static int es325_index_to_gain(int min, int step, int index)
  2437. {
  2438. return min + (step * index);
  2439. }
  2440. static int es325_gain_to_index(int min, int step, int gain)
  2441. {
  2442. return (gain - min) / step;
  2443. }
  2444. /* dereverb gain */
  2445. static int es325_put_dereverb_gain_value(struct snd_kcontrol *kcontrol,
  2446. struct snd_ctl_elem_value *ucontrol)
  2447. {
  2448. struct soc_mixer_control *mc = (struct soc_mixer_control *)kcontrol->private_value;
  2449. struct es325_priv *es325 = &es325_priv;
  2450. struct slim_device *sbdev = es325->gen0_client;
  2451. unsigned int reg = mc->reg;
  2452. unsigned int value;
  2453. int rc;
  2454. if(FW_not_ready || es325_priv.wakeup_cnt == 0) {
  2455. pr_info("%s: es325 not ready, return\n", __func__);
  2456. return 0;
  2457. }
  2458. if (ucontrol->value.integer.value[0] <= 12) {
  2459. dev_info(&sbdev->dev, "=[ES325]=%s() ucontrol = %ld\n", __func__, ucontrol->value.integer.value[0]);
  2460. value = es325_index_to_gain(-12, 1, ucontrol->value.integer.value[0]);
  2461. dev_info(&sbdev->dev, "=[ES325]=%s() value = %d\n", __func__, value);
  2462. rc = es325_write(NULL, reg, value);
  2463. }
  2464. return 0;
  2465. }
  2466. static int es325_get_dereverb_gain_value(struct snd_kcontrol *kcontrol,
  2467. struct snd_ctl_elem_value *ucontrol)
  2468. {
  2469. struct soc_mixer_control *mc = (struct soc_mixer_control *)kcontrol->private_value;
  2470. struct es325_priv *es325 = &es325_priv;
  2471. struct slim_device *sbdev = es325->gen0_client;
  2472. unsigned int reg = mc->reg;
  2473. unsigned int value;
  2474. if(FW_not_ready || es325_priv.wakeup_cnt == 0) {
  2475. pr_info("%s: es325 not ready, return\n", __func__);
  2476. ucontrol->value.integer.value[0] = 0;
  2477. return 0;
  2478. }
  2479. value = es325_read(NULL, reg);
  2480. dev_info(&sbdev->dev, "=[ES325]=%s() value = %d\n", __func__, value);
  2481. ucontrol->value.integer.value[0] = es325_gain_to_index(-12, 1, value);
  2482. dev_info(&sbdev->dev, "=[ES325]=%s() ucontrol = %ld\n", __func__, ucontrol->value.integer.value[0]);
  2483. return 0;
  2484. }
  2485. /* bwe high band gain */
  2486. static int es325_put_bwe_high_band_gain_value(struct snd_kcontrol *kcontrol,
  2487. struct snd_ctl_elem_value *ucontrol)
  2488. {
  2489. struct soc_mixer_control *mc = (struct soc_mixer_control *)kcontrol->private_value;
  2490. struct es325_priv *es325 = &es325_priv;
  2491. struct slim_device *sbdev = es325->gen0_client;
  2492. unsigned int reg = mc->reg;
  2493. unsigned int value;
  2494. int rc;
  2495. if(FW_not_ready || es325_priv.wakeup_cnt == 0) {
  2496. pr_info("%s: es325 not ready, return\n", __func__);
  2497. return 0;
  2498. }
  2499. if (ucontrol->value.integer.value[0] <= 30) {
  2500. dev_info(&sbdev->dev, "=[ES325]=%s() ucontrol = %ld\n", __func__, ucontrol->value.integer.value[0]);
  2501. value = es325_index_to_gain(-10, 1, ucontrol->value.integer.value[0]);
  2502. dev_info(&sbdev->dev, "=[ES325]=%s() value = %d\n", __func__, value);
  2503. rc = es325_write(NULL, reg, value);
  2504. }
  2505. return 0;
  2506. }
  2507. static int es325_get_bwe_high_band_gain_value(struct snd_kcontrol *kcontrol,
  2508. struct snd_ctl_elem_value *ucontrol)
  2509. {
  2510. struct soc_mixer_control *mc = (struct soc_mixer_control *)kcontrol->private_value;
  2511. struct es325_priv *es325 = &es325_priv;
  2512. struct slim_device *sbdev = es325->gen0_client;
  2513. unsigned int reg = mc->reg;
  2514. unsigned int value;
  2515. if(FW_not_ready || es325_priv.wakeup_cnt == 0) {
  2516. pr_info("%s: es325 not ready, return\n", __func__);
  2517. ucontrol->value.integer.value[0] = 0;
  2518. return 0;
  2519. }
  2520. value = es325_read(NULL, reg);
  2521. dev_info(&sbdev->dev, "=[ES325]=%s() value = %d\n", __func__, value);
  2522. ucontrol->value.integer.value[0] = es325_gain_to_index(-10, 1, value);
  2523. dev_info(&sbdev->dev, "=[ES325]=%s() ucontrol = %ld\n", __func__, ucontrol->value.integer.value[0]);
  2524. return 0;
  2525. }
  2526. /* bwe max snr */
  2527. static int es325_put_bwe_max_snr_value(struct snd_kcontrol *kcontrol,
  2528. struct snd_ctl_elem_value *ucontrol)
  2529. {
  2530. struct soc_mixer_control *mc = (struct soc_mixer_control *)kcontrol->private_value;
  2531. struct es325_priv *es325 = &es325_priv;
  2532. struct slim_device *sbdev = es325->gen0_client;
  2533. unsigned int reg = mc->reg;
  2534. unsigned int value;
  2535. int rc;
  2536. if(FW_not_ready || es325_priv.wakeup_cnt == 0) {
  2537. pr_info("%s: es325 not ready, return\n", __func__);
  2538. return 0;
  2539. }
  2540. if (ucontrol->value.integer.value[0] <= 70) {
  2541. dev_info(&sbdev->dev, "=[ES325]=%s() ucontrol = %ld\n", __func__, ucontrol->value.integer.value[0]);
  2542. value = es325_index_to_gain(-20, 1, ucontrol->value.integer.value[0]);
  2543. dev_info(&sbdev->dev, "=[ES325]=%s() value = %d\n", __func__, value);
  2544. rc = es325_write(NULL, reg, value);
  2545. }
  2546. return 0;
  2547. }
  2548. static int es325_get_bwe_max_snr_value(struct snd_kcontrol *kcontrol,
  2549. struct snd_ctl_elem_value *ucontrol)
  2550. {
  2551. struct soc_mixer_control *mc = (struct soc_mixer_control *)kcontrol->private_value;
  2552. struct es325_priv *es325 = &es325_priv;
  2553. struct slim_device *sbdev = es325->gen0_client;
  2554. unsigned int reg = mc->reg;
  2555. unsigned int value;
  2556. if(FW_not_ready || es325_priv.wakeup_cnt == 0) {
  2557. pr_info("%s: es325 not ready, return\n", __func__);
  2558. ucontrol->value.integer.value[0] = 0;
  2559. return 0;
  2560. }
  2561. value = es325_read(NULL, reg);
  2562. dev_info(&sbdev->dev, "=[ES325]=%s() value = %d\n", __func__, value);
  2563. ucontrol->value.integer.value[0] = es325_gain_to_index(-20, 1, value);
  2564. dev_info(&sbdev->dev, "=[ES325]=%s() ucontrol = %ld\n", __func__, ucontrol->value.integer.value[0]);
  2565. return 0;
  2566. }
  2567. static const char * const es325_mic_config_texts[] = {
  2568. "CT 2-mic", "FT 2-mic", "DV 1-mic", "EXT 1-mic", "BT 1-mic",
  2569. "CT ASR 2-mic", "FT ASR 2-mic", "EXT ASR 1-mic", "FT ASR 1-mic",
  2570. };
  2571. static const struct soc_enum es325_mic_config_enum =
  2572. SOC_ENUM_SINGLE(ES325_MIC_CONFIG, 0, ARRAY_SIZE(es325_mic_config_texts), es325_mic_config_texts);
  2573. static const char * const es325_aec_mode_texts[] = {
  2574. "Off", "On", "rsvrd2", "rsvrd3", "rsvrd4", "On half-duplex"
  2575. };
  2576. static const struct soc_enum es325_aec_mode_enum =
  2577. SOC_ENUM_SINGLE(ES325_AEC_MODE, 0, ARRAY_SIZE(es325_aec_mode_texts), es325_aec_mode_texts);
  2578. static const char * const es325_algo_rates_text[] = {
  2579. "fs=8khz", "fs=16khz", "fs=24khz", "fs=48khz", "fs=96khz", "fs=192khz"
  2580. };
  2581. static const struct soc_enum es325_algo_sample_rate_enum =
  2582. SOC_ENUM_SINGLE(ES325_ALGO_SAMPLE_RATE, 0, ARRAY_SIZE(es325_algo_rates_text), es325_algo_rates_text);
  2583. static const struct soc_enum es325_algo_mix_rate_enum =
  2584. SOC_ENUM_SINGLE(ES325_MIX_SAMPLE_RATE, 0, ARRAY_SIZE(es325_algo_rates_text), es325_algo_rates_text);
  2585. static const char * const es325_algorithms_text[] = {
  2586. "None", "VP", "Two CHREC", "AUDIO", "Four CHPASS"
  2587. };
  2588. static const struct soc_enum es325_algorithms_enum =
  2589. SOC_ENUM_SINGLE(ES325_ALGO_SAMPLE_RATE, 0, ARRAY_SIZE(es325_algorithms_text), es325_algorithms_text);
  2590. static const char * const es325_off_on_texts[] = {
  2591. "Off", "On"
  2592. };
  2593. static const struct soc_enum es325_veq_enable_enum =
  2594. SOC_ENUM_SINGLE(ES325_VEQ_ENABLE, 0, ARRAY_SIZE(es325_off_on_texts), es325_off_on_texts);
  2595. static const struct soc_enum es325_dereverb_enable_enum =
  2596. SOC_ENUM_SINGLE(ES325_DEREVERB_ENABLE, 0, ARRAY_SIZE(es325_off_on_texts), es325_off_on_texts);
  2597. static const struct soc_enum es325_bwe_enable_enum =
  2598. SOC_ENUM_SINGLE(ES325_BWE_ENABLE, 0, ARRAY_SIZE(es325_off_on_texts), es325_off_on_texts);
  2599. static const struct soc_enum es325_bwe_post_eq_enable_enum =
  2600. SOC_ENUM_SINGLE(ES325_BWE_POST_EQ_ENABLE, 0, ARRAY_SIZE(es325_off_on_texts), es325_off_on_texts);
  2601. static const struct soc_enum es325_algo_processing_enable_enum =
  2602. SOC_ENUM_SINGLE(ES325_ALGO_PROCESSING, 0, ARRAY_SIZE(es325_off_on_texts), es325_off_on_texts);
  2603. static unsigned int es325_power_state;
  2604. static int es325_put_power_state_enum(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  2605. {
  2606. struct es325_priv *es325 = &es325_priv;
  2607. struct slim_device *sbdev = es325->gen0_client;
  2608. dev_info(&sbdev->dev, "=ES325=%s():ucontrol = %d\n", __func__, ucontrol->value.enumerated.item[0]);
  2609. dev_info(&sbdev->dev, "=ES325=%s():power state= %d\n", __func__, es325_power_state);
  2610. if (es325_power_state == ucontrol->value.enumerated.item[0]) {
  2611. dev_info(&sbdev->dev, "=[ES325]=%s():no power state change\n", __func__);
  2612. return 0;
  2613. }
  2614. es325_power_state = ucontrol->value.enumerated.item[0];
  2615. if(FW_not_ready || es325_priv.wakeup_cnt == 0) {
  2616. pr_info("%s: es325 not ready, return\n", __func__);
  2617. return 0;
  2618. }
  2619. if (es325_power_state)
  2620. es325_wrapper_wakeup(0);
  2621. else
  2622. es325_wrapper_sleep(0);
  2623. return 0;
  2624. }
  2625. static int es325_get_power_state_enum(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  2626. {
  2627. struct es325_priv *es325 = &es325_priv;
  2628. struct slim_device *sbdev = es325->gen0_client;
  2629. dev_info(&sbdev->dev, "=[ES325]=%s(): power state = %d\n", __func__, es325_power_state);
  2630. ucontrol->value.enumerated.item[0] = es325_power_state;
  2631. dev_info(&sbdev->dev, "=[ES325]=%s(): ucontrol = %d\n", __func__, ucontrol->value.enumerated.item[0]);
  2632. return 0;
  2633. }
  2634. static const char * const es325_power_state_texts[] = {
  2635. "Sleep", "Active"
  2636. };
  2637. static const struct soc_enum es325_power_state_enum =
  2638. SOC_ENUM_SINGLE(SND_SOC_NOPM, 0, ARRAY_SIZE(es325_power_state_texts), es325_power_state_texts);
  2639. static struct snd_kcontrol_new es325_digital_ext_snd_controls[] = {
  2640. /* commit controls */
  2641. SOC_SINGLE_EXT("ES325 RX1 Enable", SND_SOC_NOPM, 0, 1, 0,
  2642. es325_get_rx1_route_enable_value, es325_put_rx1_route_enable_value),
  2643. SOC_SINGLE_EXT("ES325 TX1 Enable", SND_SOC_NOPM, 0, 1, 0,
  2644. es325_get_tx1_route_enable_value, es325_put_tx1_route_enable_value),
  2645. SOC_SINGLE_EXT("ES325 RX2 Enable", SND_SOC_NOPM, 0, 1, 0,
  2646. es325_get_rx2_route_enable_value, es325_put_rx2_route_enable_value),
  2647. SOC_ENUM_EXT("Mic Config", es325_mic_config_enum,
  2648. es325_get_control_enum, es325_put_control_enum),
  2649. SOC_ENUM_EXT("AEC Mode", es325_aec_mode_enum,
  2650. es325_get_control_enum, es325_put_control_enum),
  2651. SOC_SINGLE_EXT("BWE Enable", SND_SOC_NOPM,0,1,0,
  2652. es325_get_BWE_enable_control, es325_put_BWE_enable_control),
  2653. SOC_SINGLE_EXT("VEQ Enable", SND_SOC_NOPM,0,1,0,
  2654. es325_get_VEQ_enable_control, es325_put_VEQ_enable_control),
  2655. SOC_SINGLE_EXT("ES325 Tx NS", SND_SOC_NOPM, 0, 100, 0,
  2656. es325_get_Tx_NS_control, es325_put_Tx_NS_control),
  2657. SOC_ENUM_EXT("Dereverb Enable", es325_dereverb_enable_enum,
  2658. es325_get_control_enum, es325_put_control_enum),
  2659. SOC_SINGLE_EXT("Dereverb Gain", ES325_DEREVERB_GAIN, 0, 100, 0,
  2660. es325_get_dereverb_gain_value, es325_put_dereverb_gain_value),
  2661. SOC_SINGLE_EXT("BWE High Band Gain", ES325_BWE_HIGH_BAND_GAIN, 0, 100, 0,
  2662. es325_get_bwe_high_band_gain_value, es325_put_bwe_high_band_gain_value),
  2663. SOC_SINGLE_EXT("BWE Max SNR", ES325_BWE_MAX_SNR, 0, 100, 0,
  2664. es325_get_bwe_max_snr_value, es325_put_bwe_max_snr_value),
  2665. SOC_ENUM_EXT("BWE Post EQ Enable", es325_bwe_post_eq_enable_enum,
  2666. es325_get_control_enum, es325_put_control_enum),
  2667. SOC_SINGLE_EXT("SLIMbus Link Multi Channel", ES325_SLIMBUS_LINK_MULTI_CHANNEL, 0, 65535, 0,
  2668. es325_get_control_value, es325_put_control_value),
  2669. SOC_ENUM_EXT("Set Power State", es325_power_state_enum,
  2670. es325_get_power_state_enum, es325_put_power_state_enum),
  2671. SOC_ENUM_EXT("Algorithm Processing", es325_algo_processing_enable_enum,
  2672. es325_get_control_enum, es325_put_control_enum),
  2673. SOC_ENUM_EXT("Algorithm Sample Rate", es325_algo_sample_rate_enum,
  2674. es325_get_control_enum, es325_put_control_enum),
  2675. SOC_ENUM_EXT("Algorithm", es325_algorithms_enum,
  2676. es325_get_control_enum, es325_put_control_enum),
  2677. SOC_ENUM_EXT("Mix Sample Rate", es325_algo_mix_rate_enum,
  2678. es325_get_control_enum, es325_put_control_enum),
  2679. SOC_SINGLE_EXT("Internal Route Config", SND_SOC_NOPM, 0, 100, 0,
  2680. es325_get_internal_route_config, es325_put_internal_route_config),
  2681. SOC_ENUM_EXT("ES325-AP Tx Channels", es325_ap_tx1_ch_cnt_enum,
  2682. es325_ap_get_tx1_ch_cnt, es325_ap_put_tx1_ch_cnt),
  2683. SOC_SINGLE_EXT("Current Network Type", SND_SOC_NOPM, 0, 1, 0,
  2684. es325_get_network_type, es325_put_network_type)
  2685. };
  2686. static int es325_set_bias_level(struct snd_soc_codec *codec, enum snd_soc_bias_level level)
  2687. {
  2688. int rc = 0;
  2689. switch (level) {
  2690. case SND_SOC_BIAS_ON:
  2691. break;
  2692. case SND_SOC_BIAS_PREPARE:
  2693. break;
  2694. case SND_SOC_BIAS_STANDBY:
  2695. break;
  2696. case SND_SOC_BIAS_OFF:
  2697. break;
  2698. }
  2699. codec->dapm.bias_level = level;
  2700. return rc;
  2701. }
  2702. static int es325_slim_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
  2703. {
  2704. int rc = 0;
  2705. /* This callback function may be use
  2706. for the future version of es325 */
  2707. return rc;
  2708. }
  2709. int es325_slim_set_channel_map(struct snd_soc_dai *dai, unsigned int tx_num,
  2710. unsigned int *tx_slot, unsigned int rx_num, unsigned int *rx_slot)
  2711. {
  2712. struct snd_soc_codec *codec = dai->codec;
  2713. struct es325_priv *es325 = &es325_priv;
  2714. int id = dai->id;
  2715. int i;
  2716. int rc = 0;
  2717. dev_dbg(codec->dev, "+[ES325]=%s()==\n", __func__);
  2718. dev_dbg(codec->dev, "=[ES325]=%s(): dai->id = %d\n", __func__, dai->id);
  2719. if (id == ES325_SLIM_1_PB || id == ES325_SLIM_2_PB || id == ES325_SLIM_3_PB) {
  2720. es325->dai[ID(id)].ch_tot = rx_num;
  2721. es325->dai[ID(id)].ch_act = 0;
  2722. dev_dbg(codec->dev, "=[ES325]=%s() id = %d ch_tot = %d\n", __func__, id, rx_num);
  2723. for (i = 0; i < rx_num; i++) {
  2724. es325->dai[ID(id)].ch_num[i] = rx_slot[i];
  2725. dev_dbg(codec->dev, "=[ES325]=%s() rx_slot[] = %d\n", __func__, rx_slot[i]);
  2726. }
  2727. } else if (id == ES325_SLIM_1_CAP || id == ES325_SLIM_2_CAP || id == ES325_SLIM_3_CAP) {
  2728. es325->dai[ID(id)].ch_tot = tx_num;
  2729. es325->dai[ID(id)].ch_act = 0;
  2730. dev_dbg(codec->dev, "=[ES325]=%s() id = %d ch_tot = %d\n", __func__, id, tx_num);
  2731. for (i = 0; i < tx_num; i++) {
  2732. es325->dai[ID(id)].ch_num[i] = tx_slot[i];
  2733. dev_dbg(codec->dev, "=[ES325]=%s() tx_slot[] = %d\n", __func__, tx_slot[i]);
  2734. }
  2735. }
  2736. dev_dbg(codec->dev, "-[ES325]=%s()\n", __func__);
  2737. return rc;
  2738. }
  2739. EXPORT_SYMBOL_GPL(es325_slim_set_channel_map);
  2740. int es325_slim_get_channel_map(struct snd_soc_dai *dai,
  2741. unsigned int *tx_num, unsigned int *tx_slot,
  2742. unsigned int *rx_num, unsigned int *rx_slot)
  2743. {
  2744. struct snd_soc_codec *codec = dai->codec;
  2745. struct es325_priv *es325 = &es325_priv;
  2746. struct es325_slim_ch *rx = es325->slim_rx;
  2747. struct es325_slim_ch *tx = es325->slim_tx;
  2748. int id = dai->id;
  2749. int i;
  2750. int rc = 0;
  2751. dev_dbg(codec->dev, "=[ES325]=%s(): dai->id = %d\n", __func__, dai->id);
  2752. if (id == ES325_SLIM_1_PB) {
  2753. *rx_num = es325_dai[ID(id)].playback.channels_max;
  2754. dev_dbg(codec->dev, "=[ES325]=%s(): *rx_num = %d\n", __func__, *rx_num);
  2755. for (i = 0; i < *rx_num; i++) {
  2756. rx_slot[i] = rx[ES325_SLIM_1_PB_OFFSET + i].ch_num;
  2757. dev_dbg(codec->dev, "=[ES325]=%s(): rx_slot[%d] = %d\n", __func__, i, rx_slot[i]);
  2758. }
  2759. } else if (id == ES325_SLIM_2_PB) {
  2760. *rx_num = es325_dai[ID(id)].playback.channels_max;
  2761. dev_dbg(codec->dev, "=[ES325]=%s(): *rx_num = %d\n", __func__, *rx_num);
  2762. for (i = 0; i < *rx_num; i++) {
  2763. rx_slot[i] = rx[ES325_SLIM_2_PB_OFFSET + i].ch_num;
  2764. dev_dbg(codec->dev, "=[ES325]=%s(): rx_slot[%d] = %d\n", __func__, i, rx_slot[i]);
  2765. }
  2766. } else if (id == ES325_SLIM_3_PB) {
  2767. *rx_num = es325_dai[ID(id)].playback.channels_max;
  2768. dev_dbg(codec->dev, "=[ES325]=%s(): *rx_num = %d\n", __func__, *rx_num);
  2769. for (i = 0; i < *rx_num; i++) {
  2770. rx_slot[i] = rx[ES325_SLIM_3_PB_OFFSET + i].ch_num;
  2771. dev_dbg(codec->dev, "=[ES325]=%s(): rx_slot[%d] = %d\n", __func__, i, rx_slot[i]);
  2772. }
  2773. } else if (id == ES325_SLIM_1_CAP) {
  2774. *tx_num = es325_dai[ID(id)].capture.channels_max;
  2775. dev_dbg(codec->dev, "=[ES325]=%s(): *tx_num = %d\n", __func__, *tx_num);
  2776. for (i = 0; i < *tx_num; i++) {
  2777. tx_slot[i] = tx[ES325_SLIM_1_CAP_OFFSET + i].ch_num;
  2778. dev_dbg(codec->dev, "=[ES325]=%s(): tx_slot[%d] = %d\n", __func__, i, tx_slot[i]);
  2779. }
  2780. } else if (id == ES325_SLIM_2_CAP) {
  2781. *tx_num = es325_dai[ID(id)].capture.channels_max;
  2782. dev_dbg(codec->dev, "=[ES325]=%s(): *tx_num = %d\n", __func__, *tx_num);
  2783. for (i = 0; i < *tx_num; i++) {
  2784. tx_slot[i] = tx[ES325_SLIM_2_CAP_OFFSET + i].ch_num;
  2785. dev_dbg(codec->dev, "=[ES325]=%s(): tx_slot[%d] = %d\n", __func__, i, tx_slot[i]);
  2786. }
  2787. } else if (id == ES325_SLIM_3_CAP) {
  2788. *tx_num = es325_dai[ID(id)].capture.channels_max;
  2789. for (i = 0; i < *tx_num; i++) {
  2790. tx_slot[i] = tx[ES325_SLIM_3_CAP_OFFSET + i].ch_num;
  2791. dev_dbg(codec->dev, "=[ES325]=%s(): tx_slot[%d] = %d\n", __func__, i, tx_slot[i]);
  2792. }
  2793. }
  2794. return rc;
  2795. }
  2796. EXPORT_SYMBOL_GPL(es325_slim_get_channel_map);
  2797. static int es325_slim_set_tristate(struct snd_soc_dai *dai, int tristate)
  2798. {
  2799. int rc = 0;
  2800. /* This callback function may be use
  2801. for the future version of es325 */
  2802. return rc;
  2803. }
  2804. static int es325_slim_port_mute(struct snd_soc_dai *dai, int mute)
  2805. {
  2806. int rc = 0;
  2807. /* This callback function may be use
  2808. for the future version of es325 */
  2809. return rc;
  2810. }
  2811. static int es325_slim_startup(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
  2812. {
  2813. int rc = 0;
  2814. /* This callback function may be use
  2815. for the future version of es325 */
  2816. return rc;
  2817. }
  2818. static void es325_slim_shutdown(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
  2819. {
  2820. /* This callback function may be use
  2821. for the future version of es325 */
  2822. }
  2823. int es325_slim_hw_params(struct snd_pcm_substream *substream,
  2824. struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
  2825. {
  2826. struct snd_soc_codec *codec = dai->codec;
  2827. struct es325_priv *es325 = &es325_priv;
  2828. int id = dai->id;
  2829. int channels;
  2830. int rate;
  2831. int rc = 0;
  2832. dev_info(codec->dev, "+[ES325]=%s()\n", __func__);
  2833. dev_info(codec->dev, "=[ES325]=%s(): stream_name = %s id = %d\n", __func__,
  2834. es325_dai[ID(id)].playback.stream_name, es325_dai[ID(id)].id);
  2835. channels = params_channels(params);
  2836. switch (channels) {
  2837. case 1:
  2838. case 2:
  2839. case 3:
  2840. case 4:
  2841. case 5:
  2842. case 6:
  2843. es325->dai[ID(id)].ch_tot = channels;
  2844. break;
  2845. default:
  2846. dev_err(codec->dev, "=[ES325]=%s(): unsupported number of channels, %d\n", __func__, channels);
  2847. return -EINVAL;
  2848. }
  2849. rate = params_rate(params);
  2850. switch (rate) {
  2851. case 8000:
  2852. case 16000:
  2853. case 32000:
  2854. case 48000:
  2855. es325->dai[ID(id)].rate = rate;
  2856. break;
  2857. default:
  2858. dev_err(codec->dev, "=[ES325]=%s(): unsupported rate, %d\n", __func__, rate);
  2859. return -EINVAL;
  2860. }
  2861. #ifdef ES325_SLEEP
  2862. mutex_lock(&es325_priv.pm_mutex);
  2863. if (es325->wakeup_cnt) {
  2864. es325_switch_route();
  2865. es325_update_VEQ_enable();
  2866. /* es325_update_BWE_enable();*/
  2867. /* es325_update_Tx_NS();*/
  2868. }
  2869. mutex_unlock(&es325_priv.pm_mutex);
  2870. #endif
  2871. dev_info(codec->dev, "-[ES325]=%s()\n", __func__);
  2872. return rc;
  2873. }
  2874. EXPORT_SYMBOL_GPL(es325_slim_hw_params);
  2875. static int es325_slim_hw_free(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
  2876. {
  2877. struct snd_soc_codec *codec = dai->codec;
  2878. int rc = 0;
  2879. dev_dbg(codec->dev, "+[ES325]=%s()\n", __func__);
  2880. dev_dbg(codec->dev, "-[ES325]=%s()\n", __func__);
  2881. return rc;
  2882. }
  2883. static int es325_slim_prepare(struct snd_pcm_substream *substream,
  2884. struct snd_soc_dai *dai)
  2885. {
  2886. int rc = 0;
  2887. /* This callback function may be use
  2888. for the future version of es325 */
  2889. return rc;
  2890. }
  2891. int es325_slim_trigger(struct snd_pcm_substream *substream,
  2892. int cmd, struct snd_soc_dai *dai)
  2893. {
  2894. struct snd_soc_codec *codec = dai->codec;
  2895. int id = dai->id;
  2896. int rc = 0;
  2897. dev_info(codec->dev, "+[ES325]=%s()\n", __func__);
  2898. dev_info(codec->dev, "=[ES325]=%s(): stream_name = %s\n",
  2899. __func__, es325_dai[ID(id)].playback.stream_name);
  2900. dev_info(codec->dev, "=[ES325]=%s(): id = %d\n", __func__, es325_dai[ID(id)].id);
  2901. dev_info(codec->dev, "=[ES325]=%s(): cmd = %d\n", __func__, cmd);
  2902. return rc;
  2903. }
  2904. EXPORT_SYMBOL_GPL(es325_slim_trigger);
  2905. #define ES325_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
  2906. SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 |\
  2907. SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 |\
  2908. SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000)
  2909. #define ES325_SLIMBUS_RATES (SNDRV_PCM_RATE_48000)
  2910. #define ES325_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE |\
  2911. SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE |\
  2912. SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE |\
  2913. SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE)
  2914. #define ES325_SLIMBUS_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE)
  2915. #if defined(CONFIG_SND_SOC_ES325_SLIM)
  2916. static struct snd_soc_dai_ops es325_slim_port_dai_ops = {
  2917. .set_fmt = es325_slim_set_dai_fmt,
  2918. .set_channel_map = es325_slim_set_channel_map,
  2919. .get_channel_map = es325_slim_get_channel_map,
  2920. .set_tristate = es325_slim_set_tristate,
  2921. .digital_mute = es325_slim_port_mute,
  2922. .startup = es325_slim_startup,
  2923. .shutdown = es325_slim_shutdown,
  2924. .hw_params = es325_slim_hw_params,
  2925. .hw_free = es325_slim_hw_free,
  2926. .prepare = es325_slim_prepare,
  2927. .trigger = es325_slim_trigger,
  2928. };
  2929. #endif
  2930. static struct snd_soc_dai_driver es325_dai[] = {
  2931. #if defined(CONFIG_SND_SOC_ES325_SLIM)
  2932. {
  2933. .name = "es325-slim-rx1",
  2934. .id = ES325_SLIM_1_PB,
  2935. .playback = {
  2936. .stream_name = "SLIM_PORT-1 Playback",
  2937. .channels_min = 1,
  2938. .channels_max = 2,
  2939. .rates = ES325_SLIMBUS_RATES,
  2940. .formats = ES325_SLIMBUS_FORMATS,
  2941. },
  2942. .ops = &es325_slim_port_dai_ops,
  2943. },
  2944. {
  2945. .name = "es325-slim-tx1",
  2946. .id = ES325_SLIM_1_CAP,
  2947. .capture = {
  2948. .stream_name = "SLIM_PORT-1 Capture",
  2949. .channels_min = 1,
  2950. .channels_max = 2,
  2951. .rates = ES325_SLIMBUS_RATES,
  2952. .formats = ES325_SLIMBUS_FORMATS,
  2953. },
  2954. .ops = &es325_slim_port_dai_ops,
  2955. },
  2956. {
  2957. .name = "es325-slim-rx2",
  2958. .id = ES325_SLIM_2_PB,
  2959. .playback = {
  2960. .stream_name = "SLIM_PORT-2 Playback",
  2961. .channels_min = 1,
  2962. .channels_max = 2,
  2963. .rates = ES325_SLIMBUS_RATES,
  2964. .formats = ES325_SLIMBUS_FORMATS,
  2965. },
  2966. .ops = &es325_slim_port_dai_ops,
  2967. },
  2968. {
  2969. .name = "es325-slim-tx2",
  2970. .id = ES325_SLIM_2_CAP,
  2971. .capture = {
  2972. .stream_name = "SLIM_PORT-2 Capture",
  2973. .channels_min = 1,
  2974. .channels_max = 2,
  2975. .rates = ES325_SLIMBUS_RATES,
  2976. .formats = ES325_SLIMBUS_FORMATS,
  2977. },
  2978. .ops = &es325_slim_port_dai_ops,
  2979. },
  2980. {
  2981. .name = "es325-slim-rx3",
  2982. .id = ES325_SLIM_3_PB,
  2983. .playback = {
  2984. .stream_name = "SLIM_PORT-3 Playback",
  2985. .channels_min = 1,
  2986. .channels_max = 2,
  2987. .rates = ES325_SLIMBUS_RATES,
  2988. .formats = ES325_SLIMBUS_FORMATS,
  2989. },
  2990. .ops = &es325_slim_port_dai_ops,
  2991. },
  2992. {
  2993. .name = "es325-slim-tx3",
  2994. .id = ES325_SLIM_3_CAP,
  2995. .capture = {
  2996. .stream_name = "SLIM_PORT-3 Capture",
  2997. .channels_min = 1,
  2998. .channels_max = 2,
  2999. .rates = ES325_SLIMBUS_RATES,
  3000. .formats = ES325_SLIMBUS_FORMATS,
  3001. },
  3002. .ops = &es325_slim_port_dai_ops,
  3003. },
  3004. #endif
  3005. };
  3006. #ifdef CONFIG_PM
  3007. static int es325_codec_suspend(struct snd_soc_codec *codec)
  3008. {
  3009. struct es325_priv *es325 = snd_soc_codec_get_drvdata(codec);
  3010. es325_set_bias_level(codec, SND_SOC_BIAS_OFF);
  3011. es325_sleep(es325);
  3012. return 0;
  3013. }
  3014. static int es325_codec_resume(struct snd_soc_codec *codec)
  3015. {
  3016. struct es325_priv *es325 = snd_soc_codec_get_drvdata(codec);
  3017. es325_wakeup(es325);
  3018. es325_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
  3019. return 0;
  3020. }
  3021. #else
  3022. #define es325_codec_suspend NULL
  3023. #define es325_codec_resume NULL
  3024. #endif
  3025. int es325_remote_add_codec_controls(struct snd_soc_codec *codec)
  3026. {
  3027. int rc;
  3028. dev_info(codec->dev, "+[ES325]=%s()\n", __func__);
  3029. dev_info(codec->dev, "=[ES325]=%s(): codec->name = %s\n", __func__, codec->name);
  3030. rc = snd_soc_add_codec_controls(codec, es325_digital_ext_snd_controls,
  3031. ARRAY_SIZE(es325_digital_ext_snd_controls));
  3032. if (rc)
  3033. dev_err(codec->dev, "-[ES325]=%s(): es325_digital_ext_snd_controls failed\n", __func__);
  3034. return rc;
  3035. }
  3036. static int es325_codec_probe(struct snd_soc_codec *codec)
  3037. {
  3038. struct es325_priv *es325 = snd_soc_codec_get_drvdata(codec);
  3039. dev_info(codec->dev, "+[ES325]=%s()\n", __func__);
  3040. dev_info(codec->dev, "=[ES325]=%s(): codec->name = %s codec = 0x%08x es325 = 0x%08x\n",
  3041. __func__, codec->name, (unsigned int)codec, (unsigned int)es325);
  3042. es325->codec = codec;
  3043. codec->control_data = snd_soc_codec_get_drvdata(codec);
  3044. dev_info(codec->dev, "=[ES325]=%s(): codec->control_data = 0x%08x\n",
  3045. __func__, (unsigned int)codec->control_data);
  3046. es325_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
  3047. dev_info(codec->dev, "-[ES325]=%s()\n", __func__);
  3048. return 0;
  3049. }
  3050. static int es325_codec_remove(struct snd_soc_codec *codec)
  3051. {
  3052. struct es325_priv *es325 = snd_soc_codec_get_drvdata(codec);
  3053. es325_set_bias_level(codec, SND_SOC_BIAS_OFF);
  3054. kfree(es325);
  3055. return 0;
  3056. }
  3057. static struct snd_soc_codec_driver soc_codec_dev_es325 = {
  3058. .probe = es325_codec_probe,
  3059. .remove = es325_codec_remove,
  3060. .suspend = es325_codec_suspend,
  3061. .resume = es325_codec_resume,
  3062. .read = es325_read,
  3063. .write = es325_write,
  3064. .set_bias_level = es325_set_bias_level,
  3065. };
  3066. static int es325_slim_device_up(struct slim_device *sbdev);
  3067. static int es325_dt_parse_slim_interface_dev_info(struct device *dev,
  3068. struct slim_device *slim_ifd)
  3069. {
  3070. int rc;
  3071. struct property *prop;
  3072. dev_info(dev, "+[ES325]=%s \n", __func__);
  3073. rc = of_property_read_string(dev->of_node, "es325-slim-ifd", &slim_ifd->name);
  3074. if (rc) {
  3075. dev_info(dev, "=[ES325]=%s() es325-slim-ifd\n : Looking up property in node %s failed",
  3076. __func__, dev->of_node->full_name);
  3077. return -ENODEV;
  3078. }
  3079. prop = of_find_property(dev->of_node, "es325-slim-ifd-elemental-addr", NULL);
  3080. if (!prop) {
  3081. dev_info(dev, "=[ES325]= es325-slim-ifd-elemental-addr\n : Looking up %s property in node %s failed",
  3082. __func__, dev->of_node->full_name);
  3083. return -ENODEV;
  3084. } else if (prop->length != 6) {
  3085. dev_err(dev, "=[ES325]= invalid codec slim ifd addr. addr length = %d\n", prop->length);
  3086. return -ENODEV;
  3087. }
  3088. memcpy(slim_ifd->e_addr, prop->value, 6);
  3089. dev_info(dev, "-[ES325]=%s()\n", __func__);
  3090. return 0;
  3091. }
  3092. static struct esxxx_platform_data *es325_populate_dt_pdata(struct device *dev)
  3093. {
  3094. struct esxxx_platform_data *pdata;
  3095. pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
  3096. if (!pdata) {
  3097. dev_err(dev, "=[ES325]= %s() : could not allocate memory for platform data\n", __func__);
  3098. goto err;
  3099. }
  3100. pdata->reset_gpio = of_get_named_gpio(dev->of_node, "es325-reset-gpio", 0);
  3101. if (pdata->reset_gpio < 0) {
  3102. dev_err(dev, "=[ES325]=%s() : es325-reset-gpio : Looking up property in node %s failed %d\n",
  3103. __func__, dev->of_node->full_name, pdata->reset_gpio);
  3104. goto alloc_err;
  3105. }
  3106. dev_dbg(dev, "%s() : reset gpio %d\n", __func__, pdata->reset_gpio);
  3107. pdata->wakeup_gpio = of_get_named_gpio(dev->of_node, "es325-wakeup-gpio", 0);
  3108. if (pdata->wakeup_gpio < 0) {
  3109. dev_err(dev, "=[ES325]=%s() : es325-wakeup-gpio : Looking up property in node %s failed %d\n",
  3110. __func__, dev->of_node->full_name, pdata->wakeup_gpio);
  3111. goto alloc_err;
  3112. }
  3113. dev_dbg(dev, "=[ES325]=%s(): wakeup gpio %d\n", __func__, pdata->wakeup_gpio);
  3114. return pdata;
  3115. alloc_err:
  3116. devm_kfree(dev, pdata);
  3117. err:
  3118. return NULL;
  3119. }
  3120. static int es325_slim_probe(struct slim_device *sbdev)
  3121. {
  3122. struct esxxx_platform_data *pdata = NULL;
  3123. int rc;
  3124. dev_dbg(&sbdev->dev, "+[ES325]=%s()\n", __func__);
  3125. dev_dbg(&sbdev->dev, "=[ES325]=%s(): sbdev->name = %s es325_priv = 0x%08x\n",
  3126. __func__, sbdev->name, (unsigned int)&es325_priv);
  3127. mutex_lock(&es325_priv.wakeup_mutex);
  3128. if (sbdev->dev.of_node) {
  3129. dev_info(&sbdev->dev, "=[ES325]=%s(): Platform data from device tree\n", __func__);
  3130. pdata = es325_populate_dt_pdata(&sbdev->dev);
  3131. rc = es325_dt_parse_slim_interface_dev_info(&sbdev->dev, &(pdata->intf_device));
  3132. if (rc) {
  3133. dev_info(&sbdev->dev, "=[ES325]=%s(): Error, parsing slim interface\n", __func__);
  3134. devm_kfree(&sbdev->dev, pdata);
  3135. rc = -EINVAL;
  3136. return rc;
  3137. }
  3138. sbdev->dev.platform_data = pdata;
  3139. es325_priv.gen0_client = sbdev;
  3140. es325_priv.intf_client = &(pdata->intf_device);
  3141. }
  3142. slim_set_clientdata(sbdev, &es325_priv);
  3143. if (strcmp(sbdev->name, "es325-ifd") == 0) {
  3144. dev_dbg(&sbdev->dev, "=[ES325]=%s(): interface device probe\n", __func__);
  3145. es325_priv.intf_client = sbdev;
  3146. mutex_unlock(&es325_priv.wakeup_mutex);
  3147. return 0;
  3148. }
  3149. if (strcmp(sbdev->name, "es325-gen") == 0) {
  3150. dev_dbg(&sbdev->dev, "=[ES325]=%s(): generic device probe\n", __func__);
  3151. es325_priv.gen0_client = sbdev;
  3152. }
  3153. if (es325_priv.intf_client == NULL || es325_priv.gen0_client == NULL) {
  3154. dev_dbg(&sbdev->dev, "=[ES325]=%s() incomplete initialization\n", __func__);
  3155. mutex_unlock(&es325_priv.wakeup_mutex);
  3156. return 0;
  3157. }
  3158. if (pdata == NULL) {
  3159. dev_err(&sbdev->dev, "=[ES325]=%s(): pdata is NULL", __func__);
  3160. rc = -EIO;
  3161. mutex_unlock(&es325_priv.wakeup_mutex);
  3162. goto pdata_error;
  3163. }
  3164. rc = device_create_file(&sbdev->dev, &dev_attr_route_status);
  3165. if (rc)
  3166. dev_err(&sbdev->dev, "=[ES325]=%s(): error file sysfs create\n", __func__);
  3167. rc = device_create_file(&sbdev->dev, &dev_attr_route_config);
  3168. if (rc)
  3169. dev_err(&sbdev->dev, "=[ES325]=%s(): error file sysfs create\n", __func__);
  3170. rc = device_create_file(&sbdev->dev, &dev_attr_txhex);
  3171. if (rc)
  3172. dev_err(&sbdev->dev, "=[ES325]=%s(): error file sysfs create\n", __func__);
  3173. rc = device_create_file(&sbdev->dev, &dev_attr_fw_version);
  3174. if (rc)
  3175. dev_err(&sbdev->dev, "=[ES325]=%s(): error file sysfs create\n", __func__);
  3176. rc = device_create_file(&sbdev->dev, &dev_attr_clock_on);
  3177. if (rc)
  3178. dev_err(&sbdev->dev, "=[ES325]=%s(): error file sysfs create\n", __func__);
  3179. rc = device_create_file(&sbdev->dev, &dev_attr_slim_ch_status);
  3180. if (rc)
  3181. dev_err(&sbdev->dev, "=[ES325]=%s(): error file sysfs create\n", __func__);
  3182. rc = device_create_file(&sbdev->dev, &dev_attr_es325_reg);
  3183. if (rc)
  3184. dev_err(&sbdev->dev, "=[ES325]=%s(): error file sysfs create\n", __func__);
  3185. rc = device_create_file(&sbdev->dev, &dev_attr_es325_cmd_reg);
  3186. if (rc)
  3187. dev_err(&sbdev->dev, "=[ES325]=%s(): error file sysfs create\n", __func__);
  3188. rc = device_create_file(&sbdev->dev, &dev_attr_firmware);
  3189. if (rc)
  3190. dev_err(&sbdev->dev, "=[ES325]=%s(): error file firmware create\n", __func__);
  3191. rc = device_create_file(&sbdev->dev, &dev_attr_uart_set);
  3192. if (rc)
  3193. dev_err(&sbdev->dev, "=[ES325]=%s(): error file firmware create\n", __func__);
  3194. dev_dbg(&sbdev->dev, "=[ES325]=%s(): reset_gpio = %d\n", __func__, pdata->reset_gpio);
  3195. rc = gpio_request(pdata->reset_gpio, "es325_reset");
  3196. if (rc < 0) {
  3197. dev_err(&sbdev->dev, "=[ES325]=%s(): es325_reset request failed", __func__);
  3198. goto reset_gpio_request_error;
  3199. }
  3200. rc = gpio_direction_output(pdata->reset_gpio, 1);
  3201. if (rc < 0) {
  3202. dev_err(&sbdev->dev, "=[ES325]=%s(): es325_reset direction failed", __func__);
  3203. goto reset_gpio_direction_error;
  3204. }
  3205. dev_dbg(&sbdev->dev, "=[ES325]=%s(): wakeup_gpio = %d\n", __func__, pdata->wakeup_gpio);
  3206. rc = gpio_request(pdata->wakeup_gpio, "es325_wakeup");
  3207. if (rc < 0) {
  3208. dev_err(&sbdev->dev, "=[ES325]=%s(): es325_wakeup request failed", __func__);
  3209. goto wakeup_gpio_request_error;
  3210. }
  3211. rc = gpio_direction_output(pdata->wakeup_gpio, 1);
  3212. if (rc < 0) {
  3213. dev_err(&sbdev->dev, "=[ES325]=%s(): es325_wakeup direction failed", __func__);
  3214. goto wakeup_gpio_direction_error;
  3215. }
  3216. es325_enable_ext_clk(1);
  3217. es325_priv.pdata = pdata;
  3218. #ifdef ES325_SLEEP
  3219. mutex_init(&es325_priv.pm_mutex);
  3220. es325_priv.internal_route_config = ES325_INTERNAL_ROUTE_MAX;
  3221. es325_priv.new_internal_route_config = ES325_INTERNAL_ROUTE_MAX;
  3222. #endif
  3223. mutex_unlock(&es325_priv.wakeup_mutex);
  3224. dev_info(&sbdev->dev, "-[ES325]=%s()\n", __func__);
  3225. return 0;
  3226. wakeup_gpio_direction_error:
  3227. gpio_free(pdata->wakeup_gpio);
  3228. wakeup_gpio_request_error:
  3229. reset_gpio_direction_error:
  3230. gpio_free(pdata->reset_gpio);
  3231. reset_gpio_request_error:
  3232. pdata_error:
  3233. dev_dbg(&sbdev->dev, "-[ES325]=%s() rc = %d\n", __func__, rc);
  3234. return rc;
  3235. }
  3236. static int register_snd_soc(struct es325_priv *priv)
  3237. {
  3238. int rc;
  3239. int i;
  3240. int ch_cnt;
  3241. struct slim_device *sbdev = priv->gen0_client;
  3242. es325_init_slim_slave(sbdev);
  3243. dev_dbg(&sbdev->dev, "+[ES325]=%s(): name = %s\n", __func__, sbdev->name);
  3244. rc = snd_soc_register_codec(&sbdev->dev, &soc_codec_dev_es325,
  3245. es325_dai, ARRAY_SIZE(es325_dai));
  3246. dev_dbg(&sbdev->dev, "=[ES325]=%s(): rc = snd_soc_regsiter_codec() = %d\n", __func__, rc);
  3247. /* allocate ch_num array for each DAI */
  3248. for (i = 0; i < ARRAY_SIZE(es325_dai); i++) {
  3249. switch (es325_dai[i].id) {
  3250. case ES325_SLIM_1_PB:
  3251. case ES325_SLIM_2_PB:
  3252. case ES325_SLIM_3_PB:
  3253. ch_cnt = es325_dai[i].playback.channels_max;
  3254. break;
  3255. case ES325_SLIM_1_CAP:
  3256. case ES325_SLIM_2_CAP:
  3257. case ES325_SLIM_3_CAP:
  3258. ch_cnt = es325_dai[i].capture.channels_max;
  3259. break;
  3260. default:
  3261. continue;
  3262. }
  3263. es325_priv.dai[i].ch_num = kzalloc((ch_cnt * sizeof(unsigned int)), GFP_KERNEL);
  3264. }
  3265. es325_priv.dai[ES325_SLIM_1_PB].ch_num[0] = 152;
  3266. es325_priv.dai[ES325_SLIM_1_PB].ch_num[1] = 153;
  3267. es325_priv.dai[ES325_SLIM_1_CAP].ch_num[0] = 156;
  3268. es325_priv.dai[ES325_SLIM_1_CAP].ch_num[1] = 157;
  3269. es325_priv.dai[ES325_SLIM_2_PB].ch_num[0] = 154;
  3270. es325_priv.dai[ES325_SLIM_2_PB].ch_num[1] = 155;
  3271. es325_priv.dai[ES325_SLIM_2_CAP].ch_num[0] = 144;
  3272. es325_priv.dai[ES325_SLIM_2_CAP].ch_num[1] = 145;
  3273. es325_priv.dai[ES325_SLIM_3_PB].ch_num[0] = 134;
  3274. es325_priv.dai[ES325_SLIM_3_PB].ch_num[1] = 135;
  3275. es325_priv.dai[ES325_SLIM_3_CAP].ch_num[0] = 144;
  3276. es325_priv.dai[ES325_SLIM_3_CAP].ch_num[1] = 145;
  3277. dev_dbg(&sbdev->dev, "-[ES325]=%s()\n", __func__);
  3278. return rc;
  3279. }
  3280. static int es325_slim_remove(struct slim_device *sbdev)
  3281. {
  3282. struct esxxx_platform_data *pdata = sbdev->dev.platform_data;
  3283. dev_dbg(&sbdev->dev, "+[ES325]=%s()\n", __func__);
  3284. dev_dbg(&sbdev->dev, "=[ES325]=%s(): sbdev->name = %s\n", __func__, sbdev->name);
  3285. gpio_free(pdata->reset_gpio);
  3286. gpio_free(pdata->wakeup_gpio);
  3287. gpio_free(pdata->gpioa_gpio);
  3288. snd_soc_unregister_codec(&sbdev->dev);
  3289. dev_dbg(&sbdev->dev, "-[ES325]=%s()\n", __func__);
  3290. return 0;
  3291. }
  3292. #ifdef ES325_SLEEP
  3293. #define ES325_SLEEP_TIME HZ
  3294. struct delayed_work es325_work;
  3295. struct workqueue_struct *es325_workqueue;
  3296. static int es325_schedule_sleep_workqueue(void)
  3297. {
  3298. struct es325_priv *es325 = &es325_priv;
  3299. struct slim_device *sbdev = es325->gen0_client;
  3300. int rc = queue_delayed_work(es325_workqueue, &es325_work, ES325_SLEEP_TIME);
  3301. if (!rc) {
  3302. dev_err(&sbdev->dev, "=[ES325]=%s delayed work queue failed\n", __func__);
  3303. return -1;
  3304. }
  3305. es325->wq_active = 1;
  3306. return 0;
  3307. }
  3308. static void es325_wrapper_wakeup_internal(void)
  3309. {
  3310. struct es325_priv *es325 = &es325_priv;
  3311. struct slim_device *sbdev = es325->gen0_client;
  3312. dev_info(&sbdev->dev, "+[ES325]=%s()\n", __func__);
  3313. if (!es325->clock_on) {
  3314. dev_info(&sbdev->dev, "=[ES325]=%s enable clock\n", __func__);
  3315. es325_enable_ext_clk(1);
  3316. usleep_range(1000, 1000);
  3317. es325_wakeup(es325);
  3318. es325->clock_on = 1;
  3319. }
  3320. dev_info(&sbdev->dev, "-[ES325]=%s()\n", __func__);
  3321. }
  3322. #endif
  3323. void es325_wrapper_wakeup(struct snd_soc_dai *dai)
  3324. {
  3325. #ifdef ES325_SLEEP
  3326. int rc;
  3327. struct es325_priv *es325 = &es325_priv;
  3328. struct slim_device *sbdev = es325->gen0_client;
  3329. dev_info(&sbdev->dev, "+[ES325]=%s()\n", __func__);
  3330. if(FW_not_ready) {
  3331. dev_info(&sbdev->dev, "=[ES325]=%s AE FW not ready, wakeup suspends, err_msg:%d\n", __func__,debug_for_dl_firmware);
  3332. return;
  3333. }
  3334. dev_dbg(&sbdev->dev, "=[ES325]=%s dai_id=%d ch_wakeup=%d,wakeup_cnt=%d\n",
  3335. __func__, dai->id, es325->dai[ID(dai->id)].ch_wakeup, es325->wakeup_cnt);
  3336. if (!es325_remote_route_enable(dai)) {
  3337. dev_info(&sbdev->dev, "=[ES325]=%s(dai->id = %d) es325 not activated %d %d %d\n",
  3338. __func__, dai->id, es325_rx1_route_enable,
  3339. es325_tx1_route_enable, es325_rx2_route_enable);
  3340. return;
  3341. }
  3342. mutex_lock(&es325_priv.pm_mutex);
  3343. es325->dai[ID(dai->id)].ch_wakeup = 1;
  3344. if (es325->wakeup_cnt) {
  3345. es325->wakeup_cnt++;
  3346. } else {
  3347. es325->wakeup_cnt++;
  3348. if (es325->wq_active) {
  3349. dev_dbg(&sbdev->dev, "=[ES325]=%s delete sleep timer wakeup count=%d\n",
  3350. __func__, es325->wakeup_cnt);
  3351. if (delayed_work_pending(&es325_work)) {
  3352. rc = cancel_delayed_work_sync(&es325_work);
  3353. dev_dbg(&sbdev->dev, "=[ES325]=%s cancel work queue rc=%d\n", __func__, rc);
  3354. }
  3355. es325->wq_active = 0;
  3356. }
  3357. es325_wrapper_wakeup_internal();
  3358. }
  3359. mutex_unlock(&es325_priv.pm_mutex);
  3360. dev_info(&sbdev->dev, "-[ES325]=%s()\n", __func__);
  3361. #endif
  3362. }
  3363. EXPORT_SYMBOL_GPL(es325_wrapper_wakeup);
  3364. #ifdef ES325_SLEEP
  3365. void es325_wrapper_sleep_internal(struct work_struct *dummy)
  3366. {
  3367. struct es325_priv *es325 = &es325_priv;
  3368. struct slim_device *sbdev = es325->gen0_client;
  3369. dev_dbg(&sbdev->dev, "=[ES325]=%s clock_on=%d\n", __func__, es325->clock_on);
  3370. mutex_lock(&es325_priv.pm_mutex);
  3371. es325->wq_active = 0;
  3372. if (es325->wakeup_cnt) {
  3373. dev_info(&sbdev->dev, "=[ES325]=%s wakeup needed before turning off clock[clock on==%d]\n",
  3374. __func__, es325->clock_on);
  3375. } else {
  3376. if (es325->clock_on) {
  3377. es325_sleep(es325);
  3378. dev_info(&sbdev->dev, "=[ES325]=%s disable clock\n", __func__);
  3379. es325_enable_ext_clk(0);
  3380. es325->clock_on = 0;
  3381. }
  3382. }
  3383. /* initialize variable to update ES325 settings when wake-up */
  3384. es325->internal_route_config = ES325_INTERNAL_ROUTE_MAX;
  3385. es325_VEQ_enable = ES325_MAX_INVALID_VEQ;
  3386. es325_BWE_enable = ES325_MAX_INVALID_BWE;
  3387. es325_Tx_NS = ES325_MAX_INVALID_TX_NS;
  3388. #if !(defined(CONFIG_SEC_LOCALE_KOR) || defined(CONFIG_SEC_HLTE_HKTW))
  3389. es325->new_internal_route_config = ES325_INTERNAL_ROUTE_MAX;
  3390. #endif
  3391. es325_VEQ_enable_new = ES325_MAX_INVALID_VEQ;
  3392. es325_BWE_enable_new = ES325_MAX_INVALID_BWE;
  3393. es325_Tx_NS_new = ES325_MAX_INVALID_TX_NS;
  3394. mutex_unlock(&es325_priv.pm_mutex);
  3395. }
  3396. #endif
  3397. void es325_wrapper_sleep(int dai_id)
  3398. {
  3399. #ifdef ES325_SLEEP
  3400. struct es325_priv *es325 = &es325_priv;
  3401. struct slim_device *sbdev = es325->gen0_client;
  3402. dev_dbg(&sbdev->dev, "+[ES325]=%s dai_id=%d ch_wakeup=%d,wakeup_cnt=%d\n",
  3403. __func__, dai_id, es325->dai[ID(dai_id)].ch_wakeup, es325->wakeup_cnt);
  3404. mutex_lock(&es325_priv.pm_mutex);
  3405. /* For dai not using audience */
  3406. if (es325->dai[ID(dai_id)].ch_wakeup == 0) {
  3407. dev_dbg(&sbdev->dev, "=[ES325]=%s dai_id=%d ch_wakeup=%d\n",
  3408. __func__, dai_id, es325->dai[ID(dai_id)].ch_wakeup);
  3409. } else {
  3410. es325->dai[ID(dai_id)].ch_wakeup = 0;
  3411. if (es325->wakeup_cnt)
  3412. es325->wakeup_cnt--;
  3413. if (es325->wakeup_cnt == 0 && !es325->wq_active)
  3414. es325_schedule_sleep_workqueue();
  3415. }
  3416. mutex_unlock(&es325_priv.pm_mutex);
  3417. #endif
  3418. }
  3419. EXPORT_SYMBOL_GPL(es325_wrapper_sleep);
  3420. static int es325_slim_device_up(struct slim_device *sbdev)
  3421. {
  3422. struct es325_priv *es325;
  3423. int rc;
  3424. const char *filename = CONFIG_EXTRA_FIRMWARE;
  3425. dev_info(&sbdev->dev, "+[ES325]=%s: name=%s\n", __func__, sbdev->name);
  3426. dev_info(&sbdev->dev, "=[ES325]=%s: laddr=%d\n", __func__, sbdev->laddr);
  3427. mutex_lock(&es325_priv.wakeup_mutex);
  3428. /* Start the firmware download in the workqueue context. */
  3429. es325 = slim_get_devicedata(sbdev);
  3430. rc = request_firmware((const struct firmware **)&es325->fw,
  3431. filename, &sbdev->dev);
  3432. if (rc) {
  3433. dev_err(&sbdev->dev, "=[ES325]=%s(): request_firmware(%s) failed %d\n", __func__, filename, rc);
  3434. return -1;
  3435. }
  3436. dev_info(&sbdev->dev, "=[ES325]=%s: priv=%p\n", __func__, es325);
  3437. if (strcmp(sbdev->name, "es325-ifd") == 0)
  3438. return 0;
  3439. /* device need time to finish send REPORT_PRESENT messages */
  3440. msleep(50);
  3441. rc = fw_download(es325);
  3442. BUG_ON(rc != 0);
  3443. #ifdef ES325_SLEEP
  3444. if (strcmp(sbdev->name, "es325-gen") == 0) {
  3445. dev_info(&sbdev->dev, "=[ES325]= wrapper %s(): es325-gen\n", __func__);
  3446. es325->clock_on = 1;
  3447. es325_wrapper_sleep_internal(NULL);
  3448. dev_info(&sbdev->dev, "=[ES325]= wrapper %s: es325 sleep default\n", __func__);
  3449. }
  3450. #endif
  3451. mutex_unlock(&es325_priv.wakeup_mutex);
  3452. dev_info(&sbdev->dev, "-[ES325]= wrapper %s: device up complete\n", __func__);
  3453. return rc;
  3454. }
  3455. static const struct slim_device_id es325_slim_id[] = {
  3456. { "es325", 0 },
  3457. { "es325-ifd", 0 },
  3458. { "es325-gen", 0 },
  3459. { }
  3460. };
  3461. static struct slim_driver es325_slim_driver = {
  3462. .driver = {
  3463. .name = "es325_gen_slim",
  3464. .owner = THIS_MODULE,
  3465. },
  3466. .probe = es325_slim_probe,
  3467. .remove = es325_slim_remove,
  3468. .device_up = es325_slim_device_up,
  3469. .id_table = es325_slim_id,
  3470. };
  3471. static __init int es325_init(void)
  3472. {
  3473. int rc = 0;
  3474. pr_info("+[ES325]=%s()\n", __func__);
  3475. memset(&es325_priv, 0, sizeof(es325_priv));
  3476. mutex_init(&es325_priv.wakeup_mutex);
  3477. #ifdef ES325_SLEEP
  3478. es325_workqueue = create_workqueue("ES325");
  3479. if (!es325_workqueue) {
  3480. pr_err("=[ES325]=%s(): can't create workqueue\n", __func__);
  3481. return -1;
  3482. }
  3483. INIT_DELAYED_WORK(&es325_work, es325_wrapper_sleep_internal);
  3484. #endif
  3485. pr_info("=[ES325]=%s(): slim_driver_register()", __func__);
  3486. rc = slim_driver_register(&es325_slim_driver);
  3487. if (rc)
  3488. pr_err("=[ES325]=%s(): Error registering Audience eS325 SLIMbus driver: %d\n",
  3489. __func__, rc);
  3490. pr_info("-[ES325]=%s()\n", __func__);
  3491. return rc;
  3492. }
  3493. module_init(es325_init);
  3494. static __exit void es325_exit(void)
  3495. {
  3496. pr_info("+[ES325]=%s()\n", __func__);
  3497. #ifdef ES325_SLEEP
  3498. if (es325_workqueue)
  3499. destroy_workqueue(es325_workqueue);
  3500. es325_workqueue = NULL;
  3501. #endif
  3502. pr_info("-[ES325]=%s()\n", __func__);
  3503. }
  3504. module_exit(es325_exit);
  3505. MODULE_DESCRIPTION("ASoC ES325 driver");
  3506. MODULE_AUTHOR("Greg Clemson <gclemson@audience.com>");
  3507. MODULE_LICENSE("GPL");
  3508. MODULE_ALIAS("platform:es325-codec");
  3509. MODULE_FIRMWARE(CONFIG_EXTRA_FIRMWARE);