es325_atlantic.c 120 KB

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