q6voice.c 120 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687
  1. /* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. #include <linux/slab.h>
  13. #include <linux/kthread.h>
  14. #include <linux/kernel.h>
  15. #include <linux/module.h>
  16. #include <linux/uaccess.h>
  17. #include <linux/wait.h>
  18. #include <linux/mutex.h>
  19. #include <asm/mach-types.h>
  20. #include <mach/qdsp6v2/audio_acdb.h>
  21. #include <mach/qdsp6v2/rtac.h>
  22. #include "sound/apr_audio.h"
  23. #include "sound/q6afe.h"
  24. #include "q6voice.h"
  25. #define TIMEOUT_MS 3000
  26. #define CMD_STATUS_SUCCESS 0
  27. #define CMD_STATUS_FAIL 1
  28. #define CAL_BUFFER_SIZE 4096
  29. #define NUM_CVP_CAL_BLOCKS 75
  30. #define NUM_CVS_CAL_BLOCKS 15
  31. #define CVP_CAL_SIZE (NUM_CVP_CAL_BLOCKS * CAL_BUFFER_SIZE)
  32. #define CVS_CAL_SIZE (NUM_CVS_CAL_BLOCKS * CAL_BUFFER_SIZE)
  33. #define VOICE_CAL_BUFFER_SIZE (CVP_CAL_SIZE + CVS_CAL_SIZE)
  34. /* Total cal needed to support concurrent VOIP & VOLTE sessions */
  35. /* Due to memory map issue on Q6 separate memory has to be used */
  36. /* for VOIP & VOLTE */
  37. #define TOTAL_VOICE_CAL_SIZE (NUM_VOICE_CAL_BUFFERS * VOICE_CAL_BUFFER_SIZE)
  38. static struct common_data common;
  39. static int voice_send_enable_vocproc_cmd(struct voice_data *v);
  40. static int voice_send_netid_timing_cmd(struct voice_data *v);
  41. static int voice_send_attach_vocproc_cmd(struct voice_data *v);
  42. static int voice_send_set_device_cmd(struct voice_data *v);
  43. static int voice_send_disable_vocproc_cmd(struct voice_data *v);
  44. static int voice_send_vol_index_cmd(struct voice_data *v);
  45. static int voice_send_cvp_map_memory_cmd(struct voice_data *v,
  46. uint32_t paddr, uint32_t mem_size);
  47. static int voice_send_cvp_unmap_memory_cmd(struct voice_data *v,
  48. uint32_t paddr);
  49. static int voice_send_cvs_map_memory_cmd(struct voice_data *v);
  50. static int voice_send_cvs_unmap_memory_cmd(struct voice_data *v);
  51. static int voice_send_cvs_register_cal_cmd(struct voice_data *v);
  52. static int voice_send_cvs_deregister_cal_cmd(struct voice_data *v);
  53. static int voice_send_cvp_register_cal_cmd(struct voice_data *v);
  54. static int voice_send_cvp_deregister_cal_cmd(struct voice_data *v);
  55. static int voice_send_cvp_register_vol_cal_table_cmd(struct voice_data *v);
  56. static int voice_send_cvp_deregister_vol_cal_table_cmd(struct voice_data *v);
  57. static int voice_send_set_widevoice_enable_cmd(struct voice_data *v);
  58. static int voice_send_set_pp_enable_cmd(struct voice_data *v,
  59. uint32_t module_id, int enable);
  60. static int voice_cvs_stop_playback(struct voice_data *v);
  61. static int voice_cvs_start_playback(struct voice_data *v);
  62. static int voice_cvs_start_record(struct voice_data *v, uint32_t rec_mode);
  63. static int voice_cvs_stop_record(struct voice_data *v);
  64. static int32_t qdsp_mvm_callback(struct apr_client_data *data, void *priv);
  65. static int32_t qdsp_cvs_callback(struct apr_client_data *data, void *priv);
  66. static int32_t qdsp_cvp_callback(struct apr_client_data *data, void *priv);
  67. static int voice_send_set_device_cmd_v2(struct voice_data *v);
  68. static u16 voice_get_mvm_handle(struct voice_data *v)
  69. {
  70. if (v == NULL) {
  71. pr_err("%s: v is NULL\n", __func__);
  72. return 0;
  73. }
  74. pr_debug("%s: mvm_handle %d\n", __func__, v->mvm_handle);
  75. return v->mvm_handle;
  76. }
  77. static void voice_set_mvm_handle(struct voice_data *v, u16 mvm_handle)
  78. {
  79. pr_debug("%s: mvm_handle %d\n", __func__, mvm_handle);
  80. if (v == NULL) {
  81. pr_err("%s: v is NULL\n", __func__);
  82. return;
  83. }
  84. v->mvm_handle = mvm_handle;
  85. }
  86. static u16 voice_get_cvs_handle(struct voice_data *v)
  87. {
  88. if (v == NULL) {
  89. pr_err("%s: v is NULL\n", __func__);
  90. return 0;
  91. }
  92. pr_debug("%s: cvs_handle %d\n", __func__, v->cvs_handle);
  93. return v->cvs_handle;
  94. }
  95. static void voice_set_cvs_handle(struct voice_data *v, u16 cvs_handle)
  96. {
  97. pr_debug("%s: cvs_handle %d\n", __func__, cvs_handle);
  98. if (v == NULL) {
  99. pr_err("%s: v is NULL\n", __func__);
  100. return;
  101. }
  102. v->cvs_handle = cvs_handle;
  103. }
  104. static u16 voice_get_cvp_handle(struct voice_data *v)
  105. {
  106. if (v == NULL) {
  107. pr_err("%s: v is NULL\n", __func__);
  108. return 0;
  109. }
  110. pr_debug("%s: cvp_handle %d\n", __func__, v->cvp_handle);
  111. return v->cvp_handle;
  112. }
  113. static void voice_set_cvp_handle(struct voice_data *v, u16 cvp_handle)
  114. {
  115. pr_debug("%s: cvp_handle %d\n", __func__, cvp_handle);
  116. if (v == NULL) {
  117. pr_err("%s: v is NULL\n", __func__);
  118. return;
  119. }
  120. v->cvp_handle = cvp_handle;
  121. }
  122. char *voc_get_session_name(u16 session_id)
  123. {
  124. char *session_name = NULL;
  125. if (session_id == common.voice[VOC_PATH_PASSIVE].session_id) {
  126. session_name = VOICE_SESSION_NAME;
  127. } else if (session_id ==
  128. common.voice[VOC_PATH_VOLTE_PASSIVE].session_id) {
  129. session_name = VOLTE_SESSION_NAME;
  130. } else if (session_id == common.voice[VOC_PATH_FULL].session_id) {
  131. session_name = VOIP_SESSION_NAME;
  132. }
  133. return session_name;
  134. }
  135. uint16_t voc_get_session_id(char *name)
  136. {
  137. u16 session_id = 0;
  138. if (name != NULL) {
  139. if (!strncmp(name, "Voice session", 13))
  140. session_id = common.voice[VOC_PATH_PASSIVE].session_id;
  141. else if (!strncmp(name, "VoLTE session", 13))
  142. session_id =
  143. common.voice[VOC_PATH_VOLTE_PASSIVE].session_id;
  144. else if (!strncmp(name, "Voice2 session", 14))
  145. session_id =
  146. common.voice[VOC_PATH_VOICE2_PASSIVE].session_id;
  147. else
  148. session_id = common.voice[VOC_PATH_FULL].session_id;
  149. pr_debug("%s: %s has session id 0x%x\n", __func__, name,
  150. session_id);
  151. }
  152. return session_id;
  153. }
  154. static struct voice_data *voice_get_session(u16 session_id)
  155. {
  156. struct voice_data *v = NULL;
  157. if ((session_id >= SESSION_ID_BASE) &&
  158. (session_id < SESSION_ID_BASE + MAX_VOC_SESSIONS)) {
  159. v = &common.voice[session_id - SESSION_ID_BASE];
  160. }
  161. pr_debug("%s: session_id 0x%x session handle 0x%x\n",
  162. __func__, session_id, (unsigned int)v);
  163. return v;
  164. }
  165. static bool is_voice_session(u16 session_id)
  166. {
  167. return (session_id == common.voice[VOC_PATH_PASSIVE].session_id);
  168. }
  169. static bool is_voip_session(u16 session_id)
  170. {
  171. return (session_id == common.voice[VOC_PATH_FULL].session_id);
  172. }
  173. static bool is_volte_session(u16 session_id)
  174. {
  175. return (session_id == common.voice[VOC_PATH_VOLTE_PASSIVE].session_id);
  176. }
  177. static bool is_voice2_session(u16 session_id)
  178. {
  179. return (session_id == common.voice[VOC_PATH_VOICE2_PASSIVE].session_id);
  180. }
  181. /* Only for memory allocated in the voice driver */
  182. /* which includes voip & volte */
  183. static int voice_get_cal_kernel_addr(int16_t session_id, int cal_type,
  184. uint32_t *kvaddr)
  185. {
  186. int i, result = 0;
  187. pr_debug("%s\n", __func__);
  188. if (kvaddr == NULL) {
  189. pr_err("%s: NULL pointer sent to function\n", __func__);
  190. result = -EINVAL;
  191. goto done;
  192. } else if (is_voip_session(session_id)) {
  193. i = VOIP_CAL;
  194. } else if (is_volte_session(session_id)) {
  195. i = VOLTE_CAL;
  196. } else {
  197. result = -EINVAL;
  198. goto done;
  199. }
  200. if (common.voice_cal[i].cal_data[cal_type].kvaddr == 0) {
  201. pr_err("%s: NULL pointer for session_id %d, type %d, cal_type %d\n",
  202. __func__, session_id, i, cal_type);
  203. result = -EFAULT;
  204. goto done;
  205. }
  206. *kvaddr = common.voice_cal[i].cal_data[cal_type].kvaddr;
  207. done:
  208. return result;
  209. }
  210. /* Only for memory allocated in the voice driver */
  211. /* which includes voip & volte */
  212. static int voice_get_cal_phys_addr(int16_t session_id, int cal_type,
  213. uint32_t *paddr)
  214. {
  215. int i, result = 0;
  216. pr_debug("%s\n", __func__);
  217. if (paddr == NULL) {
  218. pr_err("%s: NULL pointer sent to function\n", __func__);
  219. result = -EINVAL;
  220. goto done;
  221. } else if (is_voip_session(session_id)) {
  222. i = VOIP_CAL;
  223. } else if (is_volte_session(session_id)) {
  224. i = VOLTE_CAL;
  225. } else {
  226. result = -EINVAL;
  227. goto done;
  228. }
  229. if (common.voice_cal[i].cal_data[cal_type].paddr == 0) {
  230. pr_err("%s: No addr for session_id %d, type %d, cal_type %d\n",
  231. __func__, session_id, i, cal_type);
  232. result = -EFAULT;
  233. goto done;
  234. }
  235. *paddr = common.voice_cal[i].cal_data[cal_type].paddr;
  236. done:
  237. return result;
  238. }
  239. static int voice_apr_register(void)
  240. {
  241. pr_debug("%s\n", __func__);
  242. mutex_lock(&common.common_lock);
  243. /* register callback to APR */
  244. if (common.apr_q6_mvm == NULL) {
  245. pr_debug("%s: Start to register MVM callback\n", __func__);
  246. common.apr_q6_mvm = apr_register("ADSP", "MVM",
  247. qdsp_mvm_callback,
  248. 0xFFFFFFFF, &common);
  249. if (common.apr_q6_mvm == NULL) {
  250. pr_err("%s: Unable to register MVM\n", __func__);
  251. goto err;
  252. }
  253. }
  254. if (common.apr_q6_cvs == NULL) {
  255. pr_debug("%s: Start to register CVS callback\n", __func__);
  256. common.apr_q6_cvs = apr_register("ADSP", "CVS",
  257. qdsp_cvs_callback,
  258. 0xFFFFFFFF, &common);
  259. if (common.apr_q6_cvs == NULL) {
  260. pr_err("%s: Unable to register CVS\n", __func__);
  261. goto err;
  262. }
  263. rtac_set_voice_handle(RTAC_CVS, common.apr_q6_cvs);
  264. }
  265. if (common.apr_q6_cvp == NULL) {
  266. pr_debug("%s: Start to register CVP callback\n", __func__);
  267. common.apr_q6_cvp = apr_register("ADSP", "CVP",
  268. qdsp_cvp_callback,
  269. 0xFFFFFFFF, &common);
  270. if (common.apr_q6_cvp == NULL) {
  271. pr_err("%s: Unable to register CVP\n", __func__);
  272. goto err;
  273. }
  274. rtac_set_voice_handle(RTAC_CVP, common.apr_q6_cvp);
  275. }
  276. mutex_unlock(&common.common_lock);
  277. return 0;
  278. err:
  279. if (common.apr_q6_cvs != NULL) {
  280. apr_deregister(common.apr_q6_cvs);
  281. common.apr_q6_cvs = NULL;
  282. rtac_set_voice_handle(RTAC_CVS, NULL);
  283. }
  284. if (common.apr_q6_mvm != NULL) {
  285. apr_deregister(common.apr_q6_mvm);
  286. common.apr_q6_mvm = NULL;
  287. }
  288. mutex_unlock(&common.common_lock);
  289. return -ENODEV;
  290. }
  291. static int voice_send_dual_control_cmd(struct voice_data *v)
  292. {
  293. int ret = 0;
  294. struct mvm_modem_dual_control_session_cmd mvm_voice_ctl_cmd;
  295. void *apr_mvm;
  296. u16 mvm_handle;
  297. if (v == NULL) {
  298. pr_err("%s: v is NULL\n", __func__);
  299. return -EINVAL;
  300. }
  301. apr_mvm = common.apr_q6_mvm;
  302. if (!apr_mvm) {
  303. pr_err("%s: apr_mvm is NULL.\n", __func__);
  304. return -EINVAL;
  305. }
  306. pr_debug("%s: VoLTE/Voice2 command to MVM\n", __func__);
  307. if (is_volte_session(v->session_id) ||
  308. is_voice2_session(v->session_id)) {
  309. mvm_handle = voice_get_mvm_handle(v);
  310. mvm_voice_ctl_cmd.hdr.hdr_field = APR_HDR_FIELD(
  311. APR_MSG_TYPE_SEQ_CMD,
  312. APR_HDR_LEN(APR_HDR_SIZE),
  313. APR_PKT_VER);
  314. mvm_voice_ctl_cmd.hdr.pkt_size = APR_PKT_SIZE(
  315. APR_HDR_SIZE,
  316. sizeof(mvm_voice_ctl_cmd) -
  317. APR_HDR_SIZE);
  318. pr_debug("%s: send mvm Voice Ctl pkt size = %d\n",
  319. __func__, mvm_voice_ctl_cmd.hdr.pkt_size);
  320. mvm_voice_ctl_cmd.hdr.src_port = v->session_id;
  321. mvm_voice_ctl_cmd.hdr.dest_port = mvm_handle;
  322. mvm_voice_ctl_cmd.hdr.token = 0;
  323. mvm_voice_ctl_cmd.hdr.opcode =
  324. VSS_IMVM_CMD_SET_POLICY_DUAL_CONTROL;
  325. mvm_voice_ctl_cmd.voice_ctl.enable_flag = true;
  326. v->mvm_state = CMD_STATUS_FAIL;
  327. ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_voice_ctl_cmd);
  328. if (ret < 0) {
  329. pr_err("%s: Error sending MVM Voice CTL CMD\n",
  330. __func__);
  331. ret = -EINVAL;
  332. goto fail;
  333. }
  334. ret = wait_event_timeout(v->mvm_wait,
  335. (v->mvm_state == CMD_STATUS_SUCCESS),
  336. msecs_to_jiffies(TIMEOUT_MS));
  337. if (!ret) {
  338. pr_err("%s: wait_event timeout\n", __func__);
  339. ret = -EINVAL;
  340. goto fail;
  341. }
  342. }
  343. ret = 0;
  344. fail:
  345. return ret;
  346. }
  347. static int voice_create_mvm_cvs_session(struct voice_data *v)
  348. {
  349. int ret = 0;
  350. struct mvm_create_ctl_session_cmd mvm_session_cmd;
  351. struct cvs_create_passive_ctl_session_cmd cvs_session_cmd;
  352. struct cvs_create_full_ctl_session_cmd cvs_full_ctl_cmd;
  353. struct mvm_attach_stream_cmd attach_stream_cmd;
  354. void *apr_mvm, *apr_cvs, *apr_cvp;
  355. u16 mvm_handle, cvs_handle, cvp_handle;
  356. if (v == NULL) {
  357. pr_err("%s: v is NULL\n", __func__);
  358. return -EINVAL;
  359. }
  360. apr_mvm = common.apr_q6_mvm;
  361. apr_cvs = common.apr_q6_cvs;
  362. apr_cvp = common.apr_q6_cvp;
  363. if (!apr_mvm || !apr_cvs || !apr_cvp) {
  364. pr_err("%s: apr_mvm or apr_cvs or apr_cvp is NULL\n", __func__);
  365. return -EINVAL;
  366. }
  367. mvm_handle = voice_get_mvm_handle(v);
  368. cvs_handle = voice_get_cvs_handle(v);
  369. cvp_handle = voice_get_cvp_handle(v);
  370. pr_debug("%s: mvm_hdl=%d, cvs_hdl=%d\n", __func__,
  371. mvm_handle, cvs_handle);
  372. /* send cmd to create mvm session and wait for response */
  373. if (!mvm_handle) {
  374. if (is_voice_session(v->session_id) ||
  375. is_volte_session(v->session_id) ||
  376. is_voice2_session(v->session_id)) {
  377. mvm_session_cmd.hdr.hdr_field = APR_HDR_FIELD(
  378. APR_MSG_TYPE_SEQ_CMD,
  379. APR_HDR_LEN(APR_HDR_SIZE),
  380. APR_PKT_VER);
  381. mvm_session_cmd.hdr.pkt_size = APR_PKT_SIZE(
  382. APR_HDR_SIZE,
  383. sizeof(mvm_session_cmd) -
  384. APR_HDR_SIZE);
  385. pr_debug("%s: send mvm create session pkt size = %d\n",
  386. __func__, mvm_session_cmd.hdr.pkt_size);
  387. mvm_session_cmd.hdr.src_port = v->session_id;
  388. mvm_session_cmd.hdr.dest_port = 0;
  389. mvm_session_cmd.hdr.token = 0;
  390. mvm_session_cmd.hdr.opcode =
  391. VSS_IMVM_CMD_CREATE_PASSIVE_CONTROL_SESSION;
  392. if (is_volte_session(v->session_id)) {
  393. strlcpy(mvm_session_cmd.mvm_session.name,
  394. "default volte voice",
  395. sizeof(mvm_session_cmd.mvm_session.name) - 1);
  396. } else if (is_voice2_session(v->session_id)) {
  397. strlcpy(mvm_session_cmd.mvm_session.name,
  398. "default modem voice2",
  399. sizeof(mvm_session_cmd.mvm_session.name));
  400. } else {
  401. strlcpy(mvm_session_cmd.mvm_session.name,
  402. "default modem voice",
  403. sizeof(mvm_session_cmd.mvm_session.name) - 1);
  404. }
  405. v->mvm_state = CMD_STATUS_FAIL;
  406. ret = apr_send_pkt(apr_mvm,
  407. (uint32_t *) &mvm_session_cmd);
  408. if (ret < 0) {
  409. pr_err("%s: Error sending MVM_CONTROL_SESSION\n",
  410. __func__);
  411. goto fail;
  412. }
  413. ret = wait_event_timeout(v->mvm_wait,
  414. (v->mvm_state == CMD_STATUS_SUCCESS),
  415. msecs_to_jiffies(TIMEOUT_MS));
  416. if (!ret) {
  417. pr_err("%s: wait_event timeout\n", __func__);
  418. goto fail;
  419. }
  420. } else {
  421. pr_debug("%s: creating MVM full ctrl\n", __func__);
  422. mvm_session_cmd.hdr.hdr_field =
  423. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  424. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  425. mvm_session_cmd.hdr.pkt_size =
  426. APR_PKT_SIZE(APR_HDR_SIZE,
  427. sizeof(mvm_session_cmd) -
  428. APR_HDR_SIZE);
  429. mvm_session_cmd.hdr.src_port = v->session_id;
  430. mvm_session_cmd.hdr.dest_port = 0;
  431. mvm_session_cmd.hdr.token = 0;
  432. mvm_session_cmd.hdr.opcode =
  433. VSS_IMVM_CMD_CREATE_FULL_CONTROL_SESSION;
  434. strlcpy(mvm_session_cmd.mvm_session.name,
  435. "default voip",
  436. sizeof(mvm_session_cmd.mvm_session.name));
  437. v->mvm_state = CMD_STATUS_FAIL;
  438. ret = apr_send_pkt(apr_mvm,
  439. (uint32_t *) &mvm_session_cmd);
  440. if (ret < 0) {
  441. pr_err("Fail in sending MVM_CONTROL_SESSION\n");
  442. goto fail;
  443. }
  444. ret = wait_event_timeout(v->mvm_wait,
  445. (v->mvm_state == CMD_STATUS_SUCCESS),
  446. msecs_to_jiffies(TIMEOUT_MS));
  447. if (!ret) {
  448. pr_err("%s: wait_event timeout\n", __func__);
  449. goto fail;
  450. }
  451. }
  452. /* Get the created MVM handle. */
  453. mvm_handle = voice_get_mvm_handle(v);
  454. }
  455. /* send cmd to create cvs session */
  456. if (!cvs_handle) {
  457. if (is_voice_session(v->session_id) ||
  458. is_volte_session(v->session_id) ||
  459. is_voice2_session(v->session_id)) {
  460. pr_debug("%s: creating CVS passive session\n",
  461. __func__);
  462. cvs_session_cmd.hdr.hdr_field = APR_HDR_FIELD(
  463. APR_MSG_TYPE_SEQ_CMD,
  464. APR_HDR_LEN(APR_HDR_SIZE),
  465. APR_PKT_VER);
  466. cvs_session_cmd.hdr.pkt_size =
  467. APR_PKT_SIZE(APR_HDR_SIZE,
  468. sizeof(cvs_session_cmd) -
  469. APR_HDR_SIZE);
  470. cvs_session_cmd.hdr.src_port = v->session_id;
  471. cvs_session_cmd.hdr.dest_port = 0;
  472. cvs_session_cmd.hdr.token = 0;
  473. cvs_session_cmd.hdr.opcode =
  474. VSS_ISTREAM_CMD_CREATE_PASSIVE_CONTROL_SESSION;
  475. if (is_volte_session(v->session_id)) {
  476. strlcpy(cvs_session_cmd.cvs_session.name,
  477. "default volte voice",
  478. sizeof(cvs_session_cmd.cvs_session.name) - 1);
  479. } else if (is_voice2_session(v->session_id)) {
  480. strlcpy(cvs_session_cmd.cvs_session.name,
  481. "default modem voice2",
  482. sizeof(cvs_session_cmd.cvs_session.name));
  483. } else {
  484. strlcpy(cvs_session_cmd.cvs_session.name,
  485. "default modem voice",
  486. sizeof(cvs_session_cmd.cvs_session.name) - 1);
  487. }
  488. v->cvs_state = CMD_STATUS_FAIL;
  489. ret = apr_send_pkt(apr_cvs,
  490. (uint32_t *) &cvs_session_cmd);
  491. if (ret < 0) {
  492. pr_err("Fail in sending STREAM_CONTROL_SESSION\n");
  493. goto fail;
  494. }
  495. ret = wait_event_timeout(v->cvs_wait,
  496. (v->cvs_state == CMD_STATUS_SUCCESS),
  497. msecs_to_jiffies(TIMEOUT_MS));
  498. if (!ret) {
  499. pr_err("%s: wait_event timeout\n", __func__);
  500. goto fail;
  501. }
  502. /* Get the created CVS handle. */
  503. cvs_handle = voice_get_cvs_handle(v);
  504. } else {
  505. pr_debug("%s: creating CVS full session\n", __func__);
  506. cvs_full_ctl_cmd.hdr.hdr_field =
  507. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  508. APR_HDR_LEN(APR_HDR_SIZE),
  509. APR_PKT_VER);
  510. cvs_full_ctl_cmd.hdr.pkt_size =
  511. APR_PKT_SIZE(APR_HDR_SIZE,
  512. sizeof(cvs_full_ctl_cmd) -
  513. APR_HDR_SIZE);
  514. cvs_full_ctl_cmd.hdr.src_port = v->session_id;
  515. cvs_full_ctl_cmd.hdr.dest_port = 0;
  516. cvs_full_ctl_cmd.hdr.token = 0;
  517. cvs_full_ctl_cmd.hdr.opcode =
  518. VSS_ISTREAM_CMD_CREATE_FULL_CONTROL_SESSION;
  519. cvs_full_ctl_cmd.cvs_session.direction = 2;
  520. cvs_full_ctl_cmd.cvs_session.enc_media_type =
  521. common.mvs_info.media_type;
  522. cvs_full_ctl_cmd.cvs_session.dec_media_type =
  523. common.mvs_info.media_type;
  524. cvs_full_ctl_cmd.cvs_session.network_id =
  525. common.mvs_info.network_type;
  526. strlcpy(cvs_full_ctl_cmd.cvs_session.name,
  527. "default q6 voice",
  528. sizeof(cvs_full_ctl_cmd.cvs_session.name));
  529. v->cvs_state = CMD_STATUS_FAIL;
  530. ret = apr_send_pkt(apr_cvs,
  531. (uint32_t *) &cvs_full_ctl_cmd);
  532. if (ret < 0) {
  533. pr_err("%s: Err %d sending CREATE_FULL_CTRL\n",
  534. __func__, ret);
  535. goto fail;
  536. }
  537. ret = wait_event_timeout(v->cvs_wait,
  538. (v->cvs_state == CMD_STATUS_SUCCESS),
  539. msecs_to_jiffies(TIMEOUT_MS));
  540. if (!ret) {
  541. pr_err("%s: wait_event timeout\n", __func__);
  542. goto fail;
  543. }
  544. /* Get the created CVS handle. */
  545. cvs_handle = voice_get_cvs_handle(v);
  546. /* Attach MVM to CVS. */
  547. pr_debug("%s: Attach MVM to stream\n", __func__);
  548. attach_stream_cmd.hdr.hdr_field =
  549. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  550. APR_HDR_LEN(APR_HDR_SIZE),
  551. APR_PKT_VER);
  552. attach_stream_cmd.hdr.pkt_size =
  553. APR_PKT_SIZE(APR_HDR_SIZE,
  554. sizeof(attach_stream_cmd) -
  555. APR_HDR_SIZE);
  556. attach_stream_cmd.hdr.src_port = v->session_id;
  557. attach_stream_cmd.hdr.dest_port = mvm_handle;
  558. attach_stream_cmd.hdr.token = 0;
  559. attach_stream_cmd.hdr.opcode =
  560. VSS_IMVM_CMD_ATTACH_STREAM;
  561. attach_stream_cmd.attach_stream.handle = cvs_handle;
  562. v->mvm_state = CMD_STATUS_FAIL;
  563. ret = apr_send_pkt(apr_mvm,
  564. (uint32_t *) &attach_stream_cmd);
  565. if (ret < 0) {
  566. pr_err("%s: Error %d sending ATTACH_STREAM\n",
  567. __func__, ret);
  568. goto fail;
  569. }
  570. ret = wait_event_timeout(v->mvm_wait,
  571. (v->mvm_state == CMD_STATUS_SUCCESS),
  572. msecs_to_jiffies(TIMEOUT_MS));
  573. if (!ret) {
  574. pr_err("%s: wait_event timeout\n", __func__);
  575. goto fail;
  576. }
  577. }
  578. }
  579. return 0;
  580. fail:
  581. return -EINVAL;
  582. }
  583. static int voice_destroy_mvm_cvs_session(struct voice_data *v)
  584. {
  585. int ret = 0;
  586. struct mvm_detach_stream_cmd detach_stream;
  587. struct apr_hdr mvm_destroy;
  588. struct apr_hdr cvs_destroy;
  589. void *apr_mvm, *apr_cvs;
  590. u16 mvm_handle, cvs_handle;
  591. if (v == NULL) {
  592. pr_err("%s: v is NULL\n", __func__);
  593. return -EINVAL;
  594. }
  595. apr_mvm = common.apr_q6_mvm;
  596. apr_cvs = common.apr_q6_cvs;
  597. if (!apr_mvm || !apr_cvs) {
  598. pr_err("%s: apr_mvm or apr_cvs is NULL\n", __func__);
  599. return -EINVAL;
  600. }
  601. mvm_handle = voice_get_mvm_handle(v);
  602. cvs_handle = voice_get_cvs_handle(v);
  603. /* MVM, CVS sessions are destroyed only for Full control sessions. */
  604. if (is_voip_session(v->session_id)) {
  605. pr_debug("%s: MVM detach stream\n", __func__);
  606. /* Detach voice stream. */
  607. detach_stream.hdr.hdr_field =
  608. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  609. APR_HDR_LEN(APR_HDR_SIZE),
  610. APR_PKT_VER);
  611. detach_stream.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  612. sizeof(detach_stream) - APR_HDR_SIZE);
  613. detach_stream.hdr.src_port = v->session_id;
  614. detach_stream.hdr.dest_port = mvm_handle;
  615. detach_stream.hdr.token = 0;
  616. detach_stream.hdr.opcode = VSS_IMVM_CMD_DETACH_STREAM;
  617. detach_stream.detach_stream.handle = cvs_handle;
  618. v->mvm_state = CMD_STATUS_FAIL;
  619. ret = apr_send_pkt(apr_mvm, (uint32_t *) &detach_stream);
  620. if (ret < 0) {
  621. pr_err("%s: Error %d sending DETACH_STREAM\n",
  622. __func__, ret);
  623. goto fail;
  624. }
  625. ret = wait_event_timeout(v->mvm_wait,
  626. (v->mvm_state == CMD_STATUS_SUCCESS),
  627. msecs_to_jiffies(TIMEOUT_MS));
  628. if (!ret) {
  629. pr_err("%s: wait event timeout\n", __func__);
  630. goto fail;
  631. }
  632. /* Destroy CVS. */
  633. pr_debug("%s: CVS destroy session\n", __func__);
  634. cvs_destroy.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  635. APR_HDR_LEN(APR_HDR_SIZE),
  636. APR_PKT_VER);
  637. cvs_destroy.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  638. sizeof(cvs_destroy) - APR_HDR_SIZE);
  639. cvs_destroy.src_port = v->session_id;
  640. cvs_destroy.dest_port = cvs_handle;
  641. cvs_destroy.token = 0;
  642. cvs_destroy.opcode = APRV2_IBASIC_CMD_DESTROY_SESSION;
  643. v->cvs_state = CMD_STATUS_FAIL;
  644. ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_destroy);
  645. if (ret < 0) {
  646. pr_err("%s: Error %d sending CVS DESTROY\n",
  647. __func__, ret);
  648. goto fail;
  649. }
  650. ret = wait_event_timeout(v->cvs_wait,
  651. (v->cvs_state == CMD_STATUS_SUCCESS),
  652. msecs_to_jiffies(TIMEOUT_MS));
  653. if (!ret) {
  654. pr_err("%s: wait event timeout\n", __func__);
  655. goto fail;
  656. }
  657. cvs_handle = 0;
  658. voice_set_cvs_handle(v, cvs_handle);
  659. /* Destroy MVM. */
  660. pr_debug("MVM destroy session\n");
  661. mvm_destroy.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  662. APR_HDR_LEN(APR_HDR_SIZE),
  663. APR_PKT_VER);
  664. mvm_destroy.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  665. sizeof(mvm_destroy) - APR_HDR_SIZE);
  666. mvm_destroy.src_port = v->session_id;
  667. mvm_destroy.dest_port = mvm_handle;
  668. mvm_destroy.token = 0;
  669. mvm_destroy.opcode = APRV2_IBASIC_CMD_DESTROY_SESSION;
  670. v->mvm_state = CMD_STATUS_FAIL;
  671. ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_destroy);
  672. if (ret < 0) {
  673. pr_err("%s: Error %d sending MVM DESTROY\n",
  674. __func__, ret);
  675. goto fail;
  676. }
  677. ret = wait_event_timeout(v->mvm_wait,
  678. (v->mvm_state == CMD_STATUS_SUCCESS),
  679. msecs_to_jiffies(TIMEOUT_MS));
  680. if (!ret) {
  681. pr_err("%s: wait event timeout\n", __func__);
  682. goto fail;
  683. }
  684. mvm_handle = 0;
  685. voice_set_mvm_handle(v, mvm_handle);
  686. }
  687. return 0;
  688. fail:
  689. return -EINVAL;
  690. }
  691. static int voice_send_tty_mode_cmd(struct voice_data *v)
  692. {
  693. int ret = 0;
  694. struct mvm_set_tty_mode_cmd mvm_tty_mode_cmd;
  695. void *apr_mvm;
  696. u16 mvm_handle;
  697. if (v == NULL) {
  698. pr_err("%s: v is NULL\n", __func__);
  699. return -EINVAL;
  700. }
  701. apr_mvm = common.apr_q6_mvm;
  702. if (!apr_mvm) {
  703. pr_err("%s: apr_mvm is NULL.\n", __func__);
  704. return -EINVAL;
  705. }
  706. mvm_handle = voice_get_mvm_handle(v);
  707. if (v->tty_mode) {
  708. /* send tty mode cmd to mvm */
  709. mvm_tty_mode_cmd.hdr.hdr_field = APR_HDR_FIELD(
  710. APR_MSG_TYPE_SEQ_CMD,
  711. APR_HDR_LEN(APR_HDR_SIZE),
  712. APR_PKT_VER);
  713. mvm_tty_mode_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  714. sizeof(mvm_tty_mode_cmd) -
  715. APR_HDR_SIZE);
  716. pr_debug("%s: pkt size = %d\n",
  717. __func__, mvm_tty_mode_cmd.hdr.pkt_size);
  718. mvm_tty_mode_cmd.hdr.src_port = v->session_id;
  719. mvm_tty_mode_cmd.hdr.dest_port = mvm_handle;
  720. mvm_tty_mode_cmd.hdr.token = 0;
  721. mvm_tty_mode_cmd.hdr.opcode = VSS_ISTREAM_CMD_SET_TTY_MODE;
  722. mvm_tty_mode_cmd.tty_mode.mode = v->tty_mode;
  723. pr_debug("tty mode =%d\n", mvm_tty_mode_cmd.tty_mode.mode);
  724. v->mvm_state = CMD_STATUS_FAIL;
  725. ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_tty_mode_cmd);
  726. if (ret < 0) {
  727. pr_err("%s: Error %d sending SET_TTY_MODE\n",
  728. __func__, ret);
  729. goto fail;
  730. }
  731. ret = wait_event_timeout(v->mvm_wait,
  732. (v->mvm_state == CMD_STATUS_SUCCESS),
  733. msecs_to_jiffies(TIMEOUT_MS));
  734. if (!ret) {
  735. pr_err("%s: wait_event timeout\n", __func__);
  736. goto fail;
  737. }
  738. }
  739. return 0;
  740. fail:
  741. return -EINVAL;
  742. }
  743. static int voice_set_dtx(struct voice_data *v)
  744. {
  745. int ret = 0;
  746. void *apr_cvs;
  747. u16 cvs_handle;
  748. struct cvs_set_enc_dtx_mode_cmd cvs_set_dtx;
  749. if (v == NULL) {
  750. pr_err("%s: v is NULL\n", __func__);
  751. return -EINVAL;
  752. }
  753. apr_cvs = common.apr_q6_cvs;
  754. if (!apr_cvs) {
  755. pr_err("%s: apr_cvs is NULL.\n", __func__);
  756. return -EINVAL;
  757. }
  758. cvs_handle = voice_get_cvs_handle(v);
  759. /* Set DTX */
  760. cvs_set_dtx.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  761. APR_HDR_LEN(APR_HDR_SIZE),
  762. APR_PKT_VER);
  763. cvs_set_dtx.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  764. sizeof(cvs_set_dtx) - APR_HDR_SIZE);
  765. cvs_set_dtx.hdr.src_port = v->session_id;
  766. cvs_set_dtx.hdr.dest_port = cvs_handle;
  767. cvs_set_dtx.hdr.token = 0;
  768. cvs_set_dtx.hdr.opcode = VSS_ISTREAM_CMD_SET_ENC_DTX_MODE;
  769. cvs_set_dtx.dtx_mode.enable = common.mvs_info.dtx_mode;
  770. pr_debug("%s: Setting DTX %d\n", __func__, common.mvs_info.dtx_mode);
  771. v->cvs_state = CMD_STATUS_FAIL;
  772. ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_set_dtx);
  773. if (ret < 0) {
  774. pr_err("%s: Error %d sending SET_DTX\n", __func__, ret);
  775. return -EINVAL;
  776. }
  777. ret = wait_event_timeout(v->cvs_wait,
  778. (v->cvs_state == CMD_STATUS_SUCCESS),
  779. msecs_to_jiffies(TIMEOUT_MS));
  780. if (!ret) {
  781. pr_err("%s: wait_event timeout\n", __func__);
  782. return -EINVAL;
  783. }
  784. return 0;
  785. }
  786. static int voice_send_dtmf_rx_detection_cmd(struct voice_data *v,
  787. uint32_t enable)
  788. {
  789. int ret = 0;
  790. void *apr_cvs;
  791. u16 cvs_handle;
  792. struct cvs_set_rx_dtmf_detection_cmd cvs_dtmf_rx_detection;
  793. if (v == NULL) {
  794. pr_err("%s: v is NULL\n", __func__);
  795. return -EINVAL;
  796. }
  797. apr_cvs = common.apr_q6_cvs;
  798. if (!apr_cvs) {
  799. pr_err("%s: apr_cvs is NULL.\n", __func__);
  800. return -EINVAL;
  801. }
  802. cvs_handle = voice_get_cvs_handle(v);
  803. /* Set SET_DTMF_RX_DETECTION */
  804. cvs_dtmf_rx_detection.hdr.hdr_field =
  805. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  806. APR_HDR_LEN(APR_HDR_SIZE),
  807. APR_PKT_VER);
  808. cvs_dtmf_rx_detection.hdr.pkt_size =
  809. APR_PKT_SIZE(APR_HDR_SIZE,
  810. sizeof(cvs_dtmf_rx_detection) - APR_HDR_SIZE);
  811. cvs_dtmf_rx_detection.hdr.src_port = v->session_id;
  812. cvs_dtmf_rx_detection.hdr.dest_port = cvs_handle;
  813. cvs_dtmf_rx_detection.hdr.token = 0;
  814. cvs_dtmf_rx_detection.hdr.opcode =
  815. VSS_ISTREAM_CMD_SET_RX_DTMF_DETECTION;
  816. cvs_dtmf_rx_detection.cvs_dtmf_det.enable = enable;
  817. v->cvs_state = CMD_STATUS_FAIL;
  818. ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_dtmf_rx_detection);
  819. if (ret < 0) {
  820. pr_err("%s: Error %d sending SET_DTMF_RX_DETECTION\n",
  821. __func__,
  822. ret);
  823. return -EINVAL;
  824. }
  825. ret = wait_event_timeout(v->cvs_wait,
  826. (v->cvs_state == CMD_STATUS_SUCCESS),
  827. msecs_to_jiffies(TIMEOUT_MS));
  828. if (!ret) {
  829. pr_err("%s: wait_event timeout\n", __func__);
  830. return -EINVAL;
  831. }
  832. return ret;
  833. }
  834. void voc_disable_dtmf_det_on_active_sessions(void)
  835. {
  836. struct voice_data *v = NULL;
  837. int i;
  838. for (i = 0; i < MAX_VOC_SESSIONS; i++) {
  839. v = &common.voice[i];
  840. if ((v->dtmf_rx_detect_en) &&
  841. ((v->voc_state == VOC_RUN) ||
  842. (v->voc_state == VOC_CHANGE) ||
  843. (v->voc_state == VOC_STANDBY))) {
  844. pr_debug("disable dtmf det on ses_id=%d\n",
  845. v->session_id);
  846. voice_send_dtmf_rx_detection_cmd(v, 0);
  847. }
  848. }
  849. }
  850. int voc_enable_dtmf_rx_detection(uint16_t session_id, uint32_t enable)
  851. {
  852. struct voice_data *v = voice_get_session(session_id);
  853. int ret = 0;
  854. if (v == NULL) {
  855. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  856. return -EINVAL;
  857. }
  858. mutex_lock(&v->lock);
  859. v->dtmf_rx_detect_en = enable;
  860. if ((v->voc_state == VOC_RUN) ||
  861. (v->voc_state == VOC_CHANGE) ||
  862. (v->voc_state == VOC_STANDBY))
  863. ret = voice_send_dtmf_rx_detection_cmd(v,
  864. v->dtmf_rx_detect_en);
  865. mutex_unlock(&v->lock);
  866. return ret;
  867. }
  868. static int voice_config_cvs_vocoder(struct voice_data *v)
  869. {
  870. int ret = 0;
  871. void *apr_cvs;
  872. u16 cvs_handle;
  873. /* Set media type. */
  874. struct cvs_set_media_type_cmd cvs_set_media_cmd;
  875. if (v == NULL) {
  876. pr_err("%s: v is NULL\n", __func__);
  877. return -EINVAL;
  878. }
  879. apr_cvs = common.apr_q6_cvs;
  880. if (!apr_cvs) {
  881. pr_err("%s: apr_cvs is NULL.\n", __func__);
  882. return -EINVAL;
  883. }
  884. cvs_handle = voice_get_cvs_handle(v);
  885. cvs_set_media_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  886. APR_HDR_LEN(APR_HDR_SIZE),
  887. APR_PKT_VER);
  888. cvs_set_media_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  889. sizeof(cvs_set_media_cmd) - APR_HDR_SIZE);
  890. cvs_set_media_cmd.hdr.src_port = v->session_id;
  891. cvs_set_media_cmd.hdr.dest_port = cvs_handle;
  892. cvs_set_media_cmd.hdr.token = 0;
  893. cvs_set_media_cmd.hdr.opcode = VSS_ISTREAM_CMD_SET_MEDIA_TYPE;
  894. cvs_set_media_cmd.media_type.tx_media_id = common.mvs_info.media_type;
  895. cvs_set_media_cmd.media_type.rx_media_id = common.mvs_info.media_type;
  896. v->cvs_state = CMD_STATUS_FAIL;
  897. ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_set_media_cmd);
  898. if (ret < 0) {
  899. pr_err("%s: Error %d sending SET_MEDIA_TYPE\n",
  900. __func__, ret);
  901. goto fail;
  902. }
  903. ret = wait_event_timeout(v->cvs_wait,
  904. (v->cvs_state == CMD_STATUS_SUCCESS),
  905. msecs_to_jiffies(TIMEOUT_MS));
  906. if (!ret) {
  907. pr_err("%s: wait_event timeout\n", __func__);
  908. goto fail;
  909. }
  910. /* Set encoder properties. */
  911. switch (common.mvs_info.media_type) {
  912. case VSS_MEDIA_ID_EVRC_MODEM:
  913. case VSS_MEDIA_ID_4GV_NB_MODEM:
  914. case VSS_MEDIA_ID_4GV_WB_MODEM: {
  915. struct cvs_set_cdma_enc_minmax_rate_cmd cvs_set_cdma_rate;
  916. pr_debug("Setting EVRC min-max rate\n");
  917. cvs_set_cdma_rate.hdr.hdr_field =
  918. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  919. APR_HDR_LEN(APR_HDR_SIZE),
  920. APR_PKT_VER);
  921. cvs_set_cdma_rate.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  922. sizeof(cvs_set_cdma_rate) - APR_HDR_SIZE);
  923. cvs_set_cdma_rate.hdr.src_port = v->session_id;
  924. cvs_set_cdma_rate.hdr.dest_port = cvs_handle;
  925. cvs_set_cdma_rate.hdr.token = 0;
  926. cvs_set_cdma_rate.hdr.opcode =
  927. VSS_ISTREAM_CMD_CDMA_SET_ENC_MINMAX_RATE;
  928. cvs_set_cdma_rate.cdma_rate.min_rate = common.mvs_info.rate;
  929. cvs_set_cdma_rate.cdma_rate.max_rate = common.mvs_info.rate;
  930. v->cvs_state = CMD_STATUS_FAIL;
  931. ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_set_cdma_rate);
  932. if (ret < 0) {
  933. pr_err("%s: Error %d sending SET_EVRC_MINMAX_RATE\n",
  934. __func__, ret);
  935. goto fail;
  936. }
  937. ret = wait_event_timeout(v->cvs_wait,
  938. (v->cvs_state == CMD_STATUS_SUCCESS),
  939. msecs_to_jiffies(TIMEOUT_MS));
  940. if (!ret) {
  941. pr_err("%s: wait_event timeout\n", __func__);
  942. goto fail;
  943. }
  944. break;
  945. }
  946. case VSS_MEDIA_ID_AMR_NB_MODEM: {
  947. struct cvs_set_amr_enc_rate_cmd cvs_set_amr_rate;
  948. pr_debug("Setting AMR rate\n");
  949. cvs_set_amr_rate.hdr.hdr_field =
  950. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  951. APR_HDR_LEN(APR_HDR_SIZE),
  952. APR_PKT_VER);
  953. cvs_set_amr_rate.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  954. sizeof(cvs_set_amr_rate) - APR_HDR_SIZE);
  955. cvs_set_amr_rate.hdr.src_port = v->session_id;
  956. cvs_set_amr_rate.hdr.dest_port = cvs_handle;
  957. cvs_set_amr_rate.hdr.token = 0;
  958. cvs_set_amr_rate.hdr.opcode =
  959. VSS_ISTREAM_CMD_VOC_AMR_SET_ENC_RATE;
  960. cvs_set_amr_rate.amr_rate.mode = common.mvs_info.rate;
  961. v->cvs_state = CMD_STATUS_FAIL;
  962. ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_set_amr_rate);
  963. if (ret < 0) {
  964. pr_err("%s: Error %d sending SET_AMR_RATE\n",
  965. __func__, ret);
  966. goto fail;
  967. }
  968. ret = wait_event_timeout(v->cvs_wait,
  969. (v->cvs_state == CMD_STATUS_SUCCESS),
  970. msecs_to_jiffies(TIMEOUT_MS));
  971. if (!ret) {
  972. pr_err("%s: wait_event timeout\n", __func__);
  973. goto fail;
  974. }
  975. ret = voice_set_dtx(v);
  976. if (ret < 0)
  977. goto fail;
  978. break;
  979. }
  980. case VSS_MEDIA_ID_AMR_WB_MODEM: {
  981. struct cvs_set_amrwb_enc_rate_cmd cvs_set_amrwb_rate;
  982. pr_debug("Setting AMR WB rate\n");
  983. cvs_set_amrwb_rate.hdr.hdr_field =
  984. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  985. APR_HDR_LEN(APR_HDR_SIZE),
  986. APR_PKT_VER);
  987. cvs_set_amrwb_rate.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  988. sizeof(cvs_set_amrwb_rate) -
  989. APR_HDR_SIZE);
  990. cvs_set_amrwb_rate.hdr.src_port = v->session_id;
  991. cvs_set_amrwb_rate.hdr.dest_port = cvs_handle;
  992. cvs_set_amrwb_rate.hdr.token = 0;
  993. cvs_set_amrwb_rate.hdr.opcode =
  994. VSS_ISTREAM_CMD_VOC_AMRWB_SET_ENC_RATE;
  995. cvs_set_amrwb_rate.amrwb_rate.mode = common.mvs_info.rate;
  996. v->cvs_state = CMD_STATUS_FAIL;
  997. ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_set_amrwb_rate);
  998. if (ret < 0) {
  999. pr_err("%s: Error %d sending SET_AMRWB_RATE\n",
  1000. __func__, ret);
  1001. goto fail;
  1002. }
  1003. ret = wait_event_timeout(v->cvs_wait,
  1004. (v->cvs_state == CMD_STATUS_SUCCESS),
  1005. msecs_to_jiffies(TIMEOUT_MS));
  1006. if (!ret) {
  1007. pr_err("%s: wait_event timeout\n", __func__);
  1008. goto fail;
  1009. }
  1010. ret = voice_set_dtx(v);
  1011. if (ret < 0)
  1012. goto fail;
  1013. break;
  1014. }
  1015. case VSS_MEDIA_ID_G729:
  1016. case VSS_MEDIA_ID_G711_ALAW:
  1017. case VSS_MEDIA_ID_G711_MULAW: {
  1018. ret = voice_set_dtx(v);
  1019. break;
  1020. }
  1021. default:
  1022. /* Do nothing. */
  1023. break;
  1024. }
  1025. return 0;
  1026. fail:
  1027. return -EINVAL;
  1028. }
  1029. static int voice_send_start_voice_cmd(struct voice_data *v)
  1030. {
  1031. struct apr_hdr mvm_start_voice_cmd;
  1032. int ret = 0;
  1033. void *apr_mvm;
  1034. u16 mvm_handle;
  1035. if (v == NULL) {
  1036. pr_err("%s: v is NULL\n", __func__);
  1037. return -EINVAL;
  1038. }
  1039. apr_mvm = common.apr_q6_mvm;
  1040. if (!apr_mvm) {
  1041. pr_err("%s: apr_mvm is NULL.\n", __func__);
  1042. return -EINVAL;
  1043. }
  1044. mvm_handle = voice_get_mvm_handle(v);
  1045. mvm_start_voice_cmd.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1046. APR_HDR_LEN(APR_HDR_SIZE),
  1047. APR_PKT_VER);
  1048. mvm_start_voice_cmd.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1049. sizeof(mvm_start_voice_cmd) - APR_HDR_SIZE);
  1050. pr_debug("send mvm_start_voice_cmd pkt size = %d\n",
  1051. mvm_start_voice_cmd.pkt_size);
  1052. mvm_start_voice_cmd.src_port = v->session_id;
  1053. mvm_start_voice_cmd.dest_port = mvm_handle;
  1054. mvm_start_voice_cmd.token = 0;
  1055. mvm_start_voice_cmd.opcode = VSS_IMVM_CMD_START_VOICE;
  1056. v->mvm_state = CMD_STATUS_FAIL;
  1057. ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_start_voice_cmd);
  1058. if (ret < 0) {
  1059. pr_err("Fail in sending VSS_IMVM_CMD_START_VOICE\n");
  1060. goto fail;
  1061. }
  1062. ret = wait_event_timeout(v->mvm_wait,
  1063. (v->mvm_state == CMD_STATUS_SUCCESS),
  1064. msecs_to_jiffies(TIMEOUT_MS));
  1065. if (!ret) {
  1066. pr_err("%s: wait_event timeout\n", __func__);
  1067. goto fail;
  1068. }
  1069. return 0;
  1070. fail:
  1071. return -EINVAL;
  1072. }
  1073. static int voice_send_disable_vocproc_cmd(struct voice_data *v)
  1074. {
  1075. struct apr_hdr cvp_disable_cmd;
  1076. int ret = 0;
  1077. void *apr_cvp;
  1078. u16 cvp_handle;
  1079. if (v == NULL) {
  1080. pr_err("%s: v is NULL\n", __func__);
  1081. return -EINVAL;
  1082. }
  1083. apr_cvp = common.apr_q6_cvp;
  1084. if (!apr_cvp) {
  1085. pr_err("%s: apr regist failed\n", __func__);
  1086. return -EINVAL;
  1087. }
  1088. cvp_handle = voice_get_cvp_handle(v);
  1089. /* disable vocproc and wait for respose */
  1090. cvp_disable_cmd.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1091. APR_HDR_LEN(APR_HDR_SIZE),
  1092. APR_PKT_VER);
  1093. cvp_disable_cmd.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1094. sizeof(cvp_disable_cmd) - APR_HDR_SIZE);
  1095. pr_debug("cvp_disable_cmd pkt size = %d, cvp_handle=%d\n",
  1096. cvp_disable_cmd.pkt_size, cvp_handle);
  1097. cvp_disable_cmd.src_port = v->session_id;
  1098. cvp_disable_cmd.dest_port = cvp_handle;
  1099. cvp_disable_cmd.token = 0;
  1100. cvp_disable_cmd.opcode = VSS_IVOCPROC_CMD_DISABLE;
  1101. v->cvp_state = CMD_STATUS_FAIL;
  1102. ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_disable_cmd);
  1103. if (ret < 0) {
  1104. pr_err("Fail in sending VSS_IVOCPROC_CMD_DISABLE\n");
  1105. goto fail;
  1106. }
  1107. ret = wait_event_timeout(v->cvp_wait,
  1108. (v->cvp_state == CMD_STATUS_SUCCESS),
  1109. msecs_to_jiffies(TIMEOUT_MS));
  1110. if (!ret) {
  1111. pr_err("%s: wait_event timeout\n", __func__);
  1112. goto fail;
  1113. }
  1114. return 0;
  1115. fail:
  1116. return -EINVAL;
  1117. }
  1118. static void voc_get_tx_rx_topology(struct voice_data *v,
  1119. uint32_t *tx_topology_id,
  1120. uint32_t *rx_topology_id)
  1121. {
  1122. uint32_t tx_id = 0;
  1123. uint32_t rx_id = 0;
  1124. if (v->disable_topology) {
  1125. tx_id = VSS_IVOCPROC_TOPOLOGY_ID_NONE;
  1126. rx_id = VSS_IVOCPROC_TOPOLOGY_ID_NONE;
  1127. } else {
  1128. /* Use default topology if invalid value in ACDB */
  1129. tx_id = get_voice_tx_topology();
  1130. if (tx_id == 0)
  1131. tx_id = VSS_IVOCPROC_TOPOLOGY_ID_TX_SM_ECNS;
  1132. rx_id = get_voice_rx_topology();
  1133. if (rx_id == 0)
  1134. rx_id = VSS_IVOCPROC_TOPOLOGY_ID_RX_DEFAULT;
  1135. }
  1136. *tx_topology_id = tx_id;
  1137. *rx_topology_id = rx_id;
  1138. }
  1139. static int voice_send_set_device_cmd(struct voice_data *v)
  1140. {
  1141. struct cvp_set_device_cmd cvp_setdev_cmd;
  1142. int ret = 0;
  1143. void *apr_cvp;
  1144. u16 cvp_handle;
  1145. if (v == NULL) {
  1146. pr_err("%s: v is NULL\n", __func__);
  1147. return -EINVAL;
  1148. }
  1149. apr_cvp = common.apr_q6_cvp;
  1150. if (!apr_cvp) {
  1151. pr_err("%s: apr_cvp is NULL.\n", __func__);
  1152. return -EINVAL;
  1153. }
  1154. cvp_handle = voice_get_cvp_handle(v);
  1155. /* set device and wait for response */
  1156. cvp_setdev_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1157. APR_HDR_LEN(APR_HDR_SIZE),
  1158. APR_PKT_VER);
  1159. cvp_setdev_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1160. sizeof(cvp_setdev_cmd) - APR_HDR_SIZE);
  1161. pr_debug(" send create cvp setdev, pkt size = %d\n",
  1162. cvp_setdev_cmd.hdr.pkt_size);
  1163. cvp_setdev_cmd.hdr.src_port = v->session_id;
  1164. cvp_setdev_cmd.hdr.dest_port = cvp_handle;
  1165. cvp_setdev_cmd.hdr.token = 0;
  1166. cvp_setdev_cmd.hdr.opcode = VSS_IVOCPROC_CMD_SET_DEVICE;
  1167. voc_get_tx_rx_topology(v, &cvp_setdev_cmd.cvp_set_device.tx_topology_id,
  1168. &cvp_setdev_cmd.cvp_set_device.rx_topology_id);
  1169. cvp_setdev_cmd.cvp_set_device.tx_port_id = v->dev_tx.port_id;
  1170. cvp_setdev_cmd.cvp_set_device.rx_port_id = v->dev_rx.port_id;
  1171. pr_debug("topology=%d , tx_port_id=%d, rx_port_id=%d\n",
  1172. cvp_setdev_cmd.cvp_set_device.tx_topology_id,
  1173. cvp_setdev_cmd.cvp_set_device.tx_port_id,
  1174. cvp_setdev_cmd.cvp_set_device.rx_port_id);
  1175. v->cvp_state = CMD_STATUS_FAIL;
  1176. ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_setdev_cmd);
  1177. if (ret < 0) {
  1178. pr_err("Fail in sending VOCPROC_FULL_CONTROL_SESSION\n");
  1179. goto fail;
  1180. }
  1181. pr_debug("wait for cvp create session event\n");
  1182. ret = wait_event_timeout(v->cvp_wait,
  1183. (v->cvp_state == CMD_STATUS_SUCCESS),
  1184. msecs_to_jiffies(TIMEOUT_MS));
  1185. if (!ret) {
  1186. pr_err("%s: wait_event timeout\n", __func__);
  1187. goto fail;
  1188. }
  1189. return 0;
  1190. fail:
  1191. return -EINVAL;
  1192. }
  1193. static int voice_send_set_device_cmd_v2(struct voice_data *v)
  1194. {
  1195. struct cvp_set_device_cmd_v2 cvp_setdev_cmd_v2;
  1196. int ret = 0;
  1197. void *apr_cvp;
  1198. u16 cvp_handle;
  1199. if (v == NULL) {
  1200. pr_err("%s: v is NULL\n", __func__);
  1201. return -EINVAL;
  1202. }
  1203. apr_cvp = common.apr_q6_cvp;
  1204. if (!apr_cvp) {
  1205. pr_err("%s: apr_cvp is NULL.\n", __func__);
  1206. return -EINVAL;
  1207. }
  1208. cvp_handle = voice_get_cvp_handle(v);
  1209. /* set device and wait for response */
  1210. cvp_setdev_cmd_v2.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1211. APR_HDR_LEN(APR_HDR_SIZE),
  1212. APR_PKT_VER);
  1213. cvp_setdev_cmd_v2.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1214. sizeof(cvp_setdev_cmd_v2) - APR_HDR_SIZE);
  1215. cvp_setdev_cmd_v2.hdr.src_port = v->session_id;
  1216. cvp_setdev_cmd_v2.hdr.dest_port = cvp_handle;
  1217. cvp_setdev_cmd_v2.hdr.token = 0;
  1218. cvp_setdev_cmd_v2.hdr.opcode = VSS_IVOCPROC_CMD_SET_DEVICE_V2;
  1219. voc_get_tx_rx_topology(v,
  1220. &cvp_setdev_cmd_v2.cvp_set_device_v2.tx_topology_id,
  1221. &cvp_setdev_cmd_v2.cvp_set_device_v2.rx_topology_id);
  1222. cvp_setdev_cmd_v2.cvp_set_device_v2.tx_port_id = v->dev_tx.port_id;
  1223. cvp_setdev_cmd_v2.cvp_set_device_v2.rx_port_id = v->dev_rx.port_id;
  1224. if (common.ec_ref_ext == true) {
  1225. cvp_setdev_cmd_v2.cvp_set_device_v2.vocproc_mode =
  1226. VSS_IVOCPROC_VOCPROC_MODE_EC_EXT_MIXING;
  1227. cvp_setdev_cmd_v2.cvp_set_device_v2.ec_ref_port_id =
  1228. common.ec_port_id;
  1229. } else {
  1230. cvp_setdev_cmd_v2.cvp_set_device_v2.vocproc_mode =
  1231. VSS_IVOCPROC_VOCPROC_MODE_EC_INT_MIXING;
  1232. cvp_setdev_cmd_v2.cvp_set_device_v2.ec_ref_port_id =
  1233. VSS_IVOCPROC_PORT_ID_NONE;
  1234. }
  1235. pr_debug("%s:topology=%d , tx_port_id=%d, rx_port_id=%d\n"
  1236. "ec_ref_port_id = %x\n", __func__,
  1237. cvp_setdev_cmd_v2.cvp_set_device_v2.tx_topology_id,
  1238. cvp_setdev_cmd_v2.cvp_set_device_v2.tx_port_id,
  1239. cvp_setdev_cmd_v2.cvp_set_device_v2.rx_port_id,
  1240. cvp_setdev_cmd_v2.cvp_set_device_v2.ec_ref_port_id);
  1241. v->cvp_state = CMD_STATUS_FAIL;
  1242. ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_setdev_cmd_v2);
  1243. if (ret < 0) {
  1244. pr_err("Fail in sending VOCPROC_FULL_CONTROL_SESSION\n");
  1245. goto fail;
  1246. }
  1247. pr_debug("wait for cvp create session event\n");
  1248. ret = wait_event_timeout(v->cvp_wait,
  1249. (v->cvp_state == CMD_STATUS_SUCCESS),
  1250. msecs_to_jiffies(TIMEOUT_MS));
  1251. if (!ret) {
  1252. pr_err("%s: wait_event timeout\n", __func__);
  1253. goto fail;
  1254. }
  1255. return 0;
  1256. fail:
  1257. return -EINVAL;
  1258. }
  1259. static int voice_send_stop_voice_cmd(struct voice_data *v)
  1260. {
  1261. struct apr_hdr mvm_stop_voice_cmd;
  1262. int ret = 0;
  1263. void *apr_mvm;
  1264. u16 mvm_handle;
  1265. if (v == NULL) {
  1266. pr_err("%s: v is NULL\n", __func__);
  1267. return -EINVAL;
  1268. }
  1269. apr_mvm = common.apr_q6_mvm;
  1270. if (!apr_mvm) {
  1271. pr_err("%s: apr_mvm is NULL.\n", __func__);
  1272. return -EINVAL;
  1273. }
  1274. mvm_handle = voice_get_mvm_handle(v);
  1275. mvm_stop_voice_cmd.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1276. APR_HDR_LEN(APR_HDR_SIZE),
  1277. APR_PKT_VER);
  1278. mvm_stop_voice_cmd.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1279. sizeof(mvm_stop_voice_cmd) - APR_HDR_SIZE);
  1280. pr_debug("send mvm_stop_voice_cmd pkt size = %d\n",
  1281. mvm_stop_voice_cmd.pkt_size);
  1282. mvm_stop_voice_cmd.src_port = v->session_id;
  1283. mvm_stop_voice_cmd.dest_port = mvm_handle;
  1284. mvm_stop_voice_cmd.token = 0;
  1285. mvm_stop_voice_cmd.opcode = VSS_IMVM_CMD_STOP_VOICE;
  1286. v->mvm_state = CMD_STATUS_FAIL;
  1287. ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_stop_voice_cmd);
  1288. if (ret < 0) {
  1289. pr_err("Fail in sending VSS_IMVM_CMD_STOP_VOICE\n");
  1290. goto fail;
  1291. }
  1292. ret = wait_event_timeout(v->mvm_wait,
  1293. (v->mvm_state == CMD_STATUS_SUCCESS),
  1294. msecs_to_jiffies(TIMEOUT_MS));
  1295. if (!ret) {
  1296. pr_err("%s: wait_event timeout\n", __func__);
  1297. goto fail;
  1298. }
  1299. return 0;
  1300. fail:
  1301. return -EINVAL;
  1302. }
  1303. static int voice_send_cvs_register_cal_cmd(struct voice_data *v)
  1304. {
  1305. struct cvs_register_cal_data_cmd cvs_reg_cal_cmd;
  1306. struct acdb_cal_block cal_block;
  1307. int ret = 0;
  1308. void *apr_cvs;
  1309. u16 cvs_handle;
  1310. uint32_t cal_paddr = 0;
  1311. uint32_t cal_buf = 0;
  1312. /* get the cvs cal data */
  1313. get_all_vocstrm_cal(&cal_block);
  1314. if (cal_block.cal_size == 0 ||
  1315. cal_block.cal_size > CVS_CAL_SIZE)
  1316. goto fail;
  1317. if (v == NULL) {
  1318. pr_err("%s: v is NULL\n", __func__);
  1319. return -EINVAL;
  1320. }
  1321. apr_cvs = common.apr_q6_cvs;
  1322. if (!apr_cvs) {
  1323. pr_err("%s: apr_cvs is NULL.\n", __func__);
  1324. return -EINVAL;
  1325. }
  1326. if (is_volte_session(v->session_id) ||
  1327. is_voip_session(v->session_id)) {
  1328. ret = voice_get_cal_phys_addr(v->session_id, CVS_CAL,
  1329. &cal_paddr);
  1330. if (ret < 0)
  1331. return ret;
  1332. ret = voice_get_cal_kernel_addr(v->session_id, CVS_CAL,
  1333. &cal_buf);
  1334. if (ret < 0)
  1335. return ret;
  1336. memcpy((void *)cal_buf, (void *)cal_block.cal_kvaddr,
  1337. cal_block.cal_size);
  1338. } else {
  1339. cal_paddr = cal_block.cal_paddr;
  1340. }
  1341. cvs_handle = voice_get_cvs_handle(v);
  1342. /* fill in the header */
  1343. cvs_reg_cal_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1344. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  1345. cvs_reg_cal_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1346. sizeof(cvs_reg_cal_cmd) - APR_HDR_SIZE);
  1347. cvs_reg_cal_cmd.hdr.src_port = v->session_id;
  1348. cvs_reg_cal_cmd.hdr.dest_port = cvs_handle;
  1349. cvs_reg_cal_cmd.hdr.token = 0;
  1350. cvs_reg_cal_cmd.hdr.opcode = VSS_ISTREAM_CMD_REGISTER_CALIBRATION_DATA;
  1351. cvs_reg_cal_cmd.cvs_cal_data.phys_addr = cal_paddr;
  1352. cvs_reg_cal_cmd.cvs_cal_data.mem_size = cal_block.cal_size;
  1353. v->cvs_state = CMD_STATUS_FAIL;
  1354. ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_reg_cal_cmd);
  1355. if (ret < 0) {
  1356. pr_err("Fail: sending cvs cal,\n");
  1357. goto fail;
  1358. }
  1359. ret = wait_event_timeout(v->cvs_wait,
  1360. (v->cvs_state == CMD_STATUS_SUCCESS),
  1361. msecs_to_jiffies(TIMEOUT_MS));
  1362. if (!ret) {
  1363. pr_err("%s: wait_event timeout\n", __func__);
  1364. goto fail;
  1365. }
  1366. return 0;
  1367. fail:
  1368. return -EINVAL;
  1369. }
  1370. static int voice_send_cvs_deregister_cal_cmd(struct voice_data *v)
  1371. {
  1372. struct cvs_deregister_cal_data_cmd cvs_dereg_cal_cmd;
  1373. struct acdb_cal_block cal_block;
  1374. int ret = 0;
  1375. void *apr_cvs;
  1376. u16 cvs_handle;
  1377. get_all_vocstrm_cal(&cal_block);
  1378. if (cal_block.cal_size == 0 ||
  1379. cal_block.cal_size > CVS_CAL_SIZE)
  1380. return 0;
  1381. if (v == NULL) {
  1382. pr_err("%s: v is NULL\n", __func__);
  1383. return -EINVAL;
  1384. }
  1385. apr_cvs = common.apr_q6_cvs;
  1386. if (!apr_cvs) {
  1387. pr_err("%s: apr_cvs is NULL.\n", __func__);
  1388. return -EINVAL;
  1389. }
  1390. cvs_handle = voice_get_cvs_handle(v);
  1391. /* fill in the header */
  1392. cvs_dereg_cal_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1393. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  1394. cvs_dereg_cal_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1395. sizeof(cvs_dereg_cal_cmd) - APR_HDR_SIZE);
  1396. cvs_dereg_cal_cmd.hdr.src_port = v->session_id;
  1397. cvs_dereg_cal_cmd.hdr.dest_port = cvs_handle;
  1398. cvs_dereg_cal_cmd.hdr.token = 0;
  1399. cvs_dereg_cal_cmd.hdr.opcode =
  1400. VSS_ISTREAM_CMD_DEREGISTER_CALIBRATION_DATA;
  1401. v->cvs_state = CMD_STATUS_FAIL;
  1402. ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_dereg_cal_cmd);
  1403. if (ret < 0) {
  1404. pr_err("Fail: sending cvs cal,\n");
  1405. goto fail;
  1406. }
  1407. ret = wait_event_timeout(v->cvs_wait,
  1408. (v->cvs_state == CMD_STATUS_SUCCESS),
  1409. msecs_to_jiffies(TIMEOUT_MS));
  1410. if (!ret) {
  1411. pr_err("%s: wait_event timeout\n", __func__);
  1412. goto fail;
  1413. }
  1414. return 0;
  1415. fail:
  1416. return -EINVAL;
  1417. }
  1418. static int voice_get_cal_paddr_size(struct voice_data *v, uint32_t *cal_paddr,
  1419. uint32_t *cal_size)
  1420. {
  1421. int ret = 0;
  1422. struct acdb_cal_block cal_block;
  1423. /* get all cvp cal data */
  1424. get_all_cvp_cal(&cal_block);
  1425. if (cal_block.cal_size == 0 ||
  1426. cal_block.cal_size > CVP_CAL_SIZE)
  1427. goto fail;
  1428. if (is_volte_session(v->session_id) ||
  1429. is_voip_session(v->session_id)) {
  1430. ret = voice_get_cal_phys_addr(v->session_id, CVP_CAL,
  1431. cal_paddr);
  1432. if (ret < 0)
  1433. return ret;
  1434. } else {
  1435. *cal_paddr = cal_block.cal_paddr;
  1436. }
  1437. if (cal_size)
  1438. *cal_size = cal_block.cal_size;
  1439. return 0;
  1440. fail:
  1441. return -EINVAL;
  1442. }
  1443. static int voice_send_cvp_map_memory_cmd(struct voice_data *v,
  1444. uint32_t paddr, uint32_t mem_size)
  1445. {
  1446. struct vss_map_memory_cmd cvp_map_mem_cmd;
  1447. int ret = 0;
  1448. void *apr_cvp;
  1449. u16 cvp_handle;
  1450. if (v == NULL) {
  1451. pr_err("%s: v is NULL\n", __func__);
  1452. return -EINVAL;
  1453. }
  1454. apr_cvp = common.apr_q6_cvp;
  1455. if (!apr_cvp) {
  1456. pr_err("%s: apr_cvp is NULL.\n", __func__);
  1457. return -EINVAL;
  1458. }
  1459. cvp_handle = voice_get_cvp_handle(v);
  1460. /* fill in the header */
  1461. cvp_map_mem_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1462. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  1463. cvp_map_mem_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1464. sizeof(cvp_map_mem_cmd) - APR_HDR_SIZE);
  1465. cvp_map_mem_cmd.hdr.src_port = v->session_id;
  1466. cvp_map_mem_cmd.hdr.dest_port = cvp_handle;
  1467. cvp_map_mem_cmd.hdr.token = 0;
  1468. cvp_map_mem_cmd.hdr.opcode = VSS_ICOMMON_CMD_MAP_MEMORY;
  1469. pr_debug("%s, phys_addr: 0x%x, mem_size: %d\n", __func__,
  1470. paddr, mem_size);
  1471. cvp_map_mem_cmd.vss_map_mem.phys_addr = paddr;
  1472. cvp_map_mem_cmd.vss_map_mem.mem_size = mem_size;
  1473. cvp_map_mem_cmd.vss_map_mem.mem_pool_id =
  1474. VSS_ICOMMON_MAP_MEMORY_SHMEM8_4K_POOL;
  1475. v->cvp_state = CMD_STATUS_FAIL;
  1476. ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_map_mem_cmd);
  1477. if (ret < 0) {
  1478. pr_err("Fail: mapping cvp memory,\n");
  1479. goto fail;
  1480. }
  1481. ret = wait_event_timeout(v->cvp_wait,
  1482. (v->cvp_state == CMD_STATUS_SUCCESS),
  1483. msecs_to_jiffies(TIMEOUT_MS));
  1484. if (!ret) {
  1485. pr_err("%s: wait_event timeout\n", __func__);
  1486. goto fail;
  1487. }
  1488. return 0;
  1489. fail:
  1490. return -EINVAL;
  1491. }
  1492. static int voice_send_cvp_unmap_memory_cmd(struct voice_data *v,
  1493. uint32_t paddr)
  1494. {
  1495. struct vss_unmap_memory_cmd cvp_unmap_mem_cmd;
  1496. int ret = 0;
  1497. void *apr_cvp;
  1498. u16 cvp_handle;
  1499. if (v == NULL) {
  1500. pr_err("%s: v is NULL\n", __func__);
  1501. return -EINVAL;
  1502. }
  1503. apr_cvp = common.apr_q6_cvp;
  1504. if (!apr_cvp) {
  1505. pr_err("%s: apr_cvp is NULL.\n", __func__);
  1506. return -EINVAL;
  1507. }
  1508. cvp_handle = voice_get_cvp_handle(v);
  1509. /* fill in the header */
  1510. cvp_unmap_mem_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1511. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  1512. cvp_unmap_mem_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1513. sizeof(cvp_unmap_mem_cmd) - APR_HDR_SIZE);
  1514. cvp_unmap_mem_cmd.hdr.src_port = v->session_id;
  1515. cvp_unmap_mem_cmd.hdr.dest_port = cvp_handle;
  1516. cvp_unmap_mem_cmd.hdr.token = 0;
  1517. cvp_unmap_mem_cmd.hdr.opcode = VSS_ICOMMON_CMD_UNMAP_MEMORY;
  1518. cvp_unmap_mem_cmd.vss_unmap_mem.phys_addr = paddr;
  1519. v->cvp_state = CMD_STATUS_FAIL;
  1520. ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_unmap_mem_cmd);
  1521. if (ret < 0) {
  1522. pr_err("Fail: sending cvp cal,\n");
  1523. goto fail;
  1524. }
  1525. ret = wait_event_timeout(v->cvp_wait,
  1526. (v->cvp_state == CMD_STATUS_SUCCESS),
  1527. msecs_to_jiffies(TIMEOUT_MS));
  1528. if (!ret) {
  1529. pr_err("%s: wait_event timeout\n", __func__);
  1530. goto fail;
  1531. }
  1532. return 0;
  1533. fail:
  1534. return -EINVAL;
  1535. }
  1536. static int voice_send_cvs_map_memory_cmd(struct voice_data *v)
  1537. {
  1538. struct vss_map_memory_cmd cvs_map_mem_cmd;
  1539. struct acdb_cal_block cal_block;
  1540. int ret = 0;
  1541. void *apr_cvs;
  1542. u16 cvs_handle;
  1543. uint32_t cal_paddr = 0;
  1544. /* get all cvs cal data */
  1545. get_all_vocstrm_cal(&cal_block);
  1546. if (cal_block.cal_size == 0 ||
  1547. cal_block.cal_size > CVS_CAL_SIZE)
  1548. goto fail;
  1549. if (v == NULL) {
  1550. pr_err("%s: v is NULL\n", __func__);
  1551. return -EINVAL;
  1552. }
  1553. apr_cvs = common.apr_q6_cvs;
  1554. if (!apr_cvs) {
  1555. pr_err("%s: apr_cvs is NULL.\n", __func__);
  1556. return -EINVAL;
  1557. }
  1558. if (is_volte_session(v->session_id) ||
  1559. is_voip_session(v->session_id)) {
  1560. ret = voice_get_cal_phys_addr(v->session_id, CVS_CAL,
  1561. &cal_paddr);
  1562. if (ret < 0)
  1563. return ret;
  1564. } else {
  1565. cal_paddr = cal_block.cal_paddr;
  1566. }
  1567. cvs_handle = voice_get_cvs_handle(v);
  1568. /* fill in the header */
  1569. cvs_map_mem_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1570. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  1571. cvs_map_mem_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1572. sizeof(cvs_map_mem_cmd) - APR_HDR_SIZE);
  1573. cvs_map_mem_cmd.hdr.src_port = v->session_id;
  1574. cvs_map_mem_cmd.hdr.dest_port = cvs_handle;
  1575. cvs_map_mem_cmd.hdr.token = 0;
  1576. cvs_map_mem_cmd.hdr.opcode = VSS_ICOMMON_CMD_MAP_MEMORY;
  1577. pr_debug("%s, phys_addr: 0x%x, mem_size: %d\n", __func__,
  1578. cal_paddr, cal_block.cal_size);
  1579. cvs_map_mem_cmd.vss_map_mem.phys_addr = cal_paddr;
  1580. cvs_map_mem_cmd.vss_map_mem.mem_size = cal_block.cal_size;
  1581. cvs_map_mem_cmd.vss_map_mem.mem_pool_id =
  1582. VSS_ICOMMON_MAP_MEMORY_SHMEM8_4K_POOL;
  1583. v->cvs_state = CMD_STATUS_FAIL;
  1584. ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_map_mem_cmd);
  1585. if (ret < 0) {
  1586. pr_err("Fail: sending cvs cal,\n");
  1587. goto fail;
  1588. }
  1589. ret = wait_event_timeout(v->cvs_wait,
  1590. (v->cvs_state == CMD_STATUS_SUCCESS),
  1591. msecs_to_jiffies(TIMEOUT_MS));
  1592. if (!ret) {
  1593. pr_err("%s: wait_event timeout\n", __func__);
  1594. goto fail;
  1595. }
  1596. return 0;
  1597. fail:
  1598. return -EINVAL;
  1599. }
  1600. static int voice_send_cvs_unmap_memory_cmd(struct voice_data *v)
  1601. {
  1602. struct vss_unmap_memory_cmd cvs_unmap_mem_cmd;
  1603. struct acdb_cal_block cal_block;
  1604. int ret = 0;
  1605. void *apr_cvs;
  1606. u16 cvs_handle;
  1607. uint32_t cal_paddr = 0;
  1608. get_all_vocstrm_cal(&cal_block);
  1609. if (cal_block.cal_size == 0 ||
  1610. cal_block.cal_size > CVS_CAL_SIZE)
  1611. return 0;
  1612. if (v == NULL) {
  1613. pr_err("%s: v is NULL\n", __func__);
  1614. return -EINVAL;
  1615. }
  1616. apr_cvs = common.apr_q6_cvs;
  1617. if (!apr_cvs) {
  1618. pr_err("%s: apr_cvs is NULL.\n", __func__);
  1619. return -EINVAL;
  1620. }
  1621. if (is_volte_session(v->session_id) ||
  1622. is_voip_session(v->session_id)) {
  1623. ret = voice_get_cal_phys_addr(v->session_id, CVS_CAL,
  1624. &cal_paddr);
  1625. if (ret < 0)
  1626. return ret;
  1627. } else {
  1628. cal_paddr = cal_block.cal_paddr;
  1629. }
  1630. cvs_handle = voice_get_cvs_handle(v);
  1631. /* fill in the header */
  1632. cvs_unmap_mem_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1633. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  1634. cvs_unmap_mem_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1635. sizeof(cvs_unmap_mem_cmd) - APR_HDR_SIZE);
  1636. cvs_unmap_mem_cmd.hdr.src_port = v->session_id;
  1637. cvs_unmap_mem_cmd.hdr.dest_port = cvs_handle;
  1638. cvs_unmap_mem_cmd.hdr.token = 0;
  1639. cvs_unmap_mem_cmd.hdr.opcode = VSS_ICOMMON_CMD_UNMAP_MEMORY;
  1640. cvs_unmap_mem_cmd.vss_unmap_mem.phys_addr = cal_paddr;
  1641. v->cvs_state = CMD_STATUS_FAIL;
  1642. ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_unmap_mem_cmd);
  1643. if (ret < 0) {
  1644. pr_err("Fail: sending cvs cal,\n");
  1645. goto fail;
  1646. }
  1647. ret = wait_event_timeout(v->cvs_wait,
  1648. (v->cvs_state == CMD_STATUS_SUCCESS),
  1649. msecs_to_jiffies(TIMEOUT_MS));
  1650. if (!ret) {
  1651. pr_err("%s: wait_event timeout\n", __func__);
  1652. goto fail;
  1653. }
  1654. return 0;
  1655. fail:
  1656. return -EINVAL;
  1657. }
  1658. static int voice_send_cvp_register_cal_cmd(struct voice_data *v)
  1659. {
  1660. struct cvp_register_cal_data_cmd cvp_reg_cal_cmd;
  1661. struct acdb_cal_block cal_block;
  1662. int ret = 0;
  1663. void *apr_cvp;
  1664. u16 cvp_handle;
  1665. uint32_t cal_paddr = 0;
  1666. uint32_t cal_buf = 0;
  1667. /* get the cvp cal data */
  1668. get_all_vocproc_cal(&cal_block);
  1669. if (cal_block.cal_size == 0 ||
  1670. cal_block.cal_size > CVP_CAL_SIZE)
  1671. goto fail;
  1672. if (v == NULL) {
  1673. pr_err("%s: v is NULL\n", __func__);
  1674. return -EINVAL;
  1675. }
  1676. apr_cvp = common.apr_q6_cvp;
  1677. if (!apr_cvp) {
  1678. pr_err("%s: apr_cvp is NULL.\n", __func__);
  1679. return -EINVAL;
  1680. }
  1681. if (is_volte_session(v->session_id) ||
  1682. is_voip_session(v->session_id)) {
  1683. ret = voice_get_cal_phys_addr(v->session_id, CVP_CAL,
  1684. &cal_paddr);
  1685. if (ret < 0)
  1686. return ret;
  1687. ret = voice_get_cal_kernel_addr(v->session_id, CVP_CAL,
  1688. &cal_buf);
  1689. if (ret < 0)
  1690. return ret;
  1691. memcpy((void *)cal_buf, (void *)cal_block.cal_kvaddr,
  1692. cal_block.cal_size);
  1693. } else {
  1694. cal_paddr = cal_block.cal_paddr;
  1695. }
  1696. cvp_handle = voice_get_cvp_handle(v);
  1697. /* fill in the header */
  1698. cvp_reg_cal_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1699. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  1700. cvp_reg_cal_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1701. sizeof(cvp_reg_cal_cmd) - APR_HDR_SIZE);
  1702. cvp_reg_cal_cmd.hdr.src_port = v->session_id;
  1703. cvp_reg_cal_cmd.hdr.dest_port = cvp_handle;
  1704. cvp_reg_cal_cmd.hdr.token = 0;
  1705. cvp_reg_cal_cmd.hdr.opcode = VSS_IVOCPROC_CMD_REGISTER_CALIBRATION_DATA;
  1706. cvp_reg_cal_cmd.cvp_cal_data.phys_addr = cal_paddr;
  1707. cvp_reg_cal_cmd.cvp_cal_data.mem_size = cal_block.cal_size;
  1708. v->cvp_state = CMD_STATUS_FAIL;
  1709. ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_reg_cal_cmd);
  1710. if (ret < 0) {
  1711. pr_err("Fail: sending cvp cal,\n");
  1712. goto fail;
  1713. }
  1714. ret = wait_event_timeout(v->cvp_wait,
  1715. (v->cvp_state == CMD_STATUS_SUCCESS),
  1716. msecs_to_jiffies(TIMEOUT_MS));
  1717. if (!ret) {
  1718. pr_err("%s: wait_event timeout\n", __func__);
  1719. goto fail;
  1720. }
  1721. return 0;
  1722. fail:
  1723. return -EINVAL;
  1724. }
  1725. static int voice_send_cvp_deregister_cal_cmd(struct voice_data *v)
  1726. {
  1727. struct cvp_deregister_cal_data_cmd cvp_dereg_cal_cmd;
  1728. struct acdb_cal_block cal_block;
  1729. int ret = 0;
  1730. void *apr_cvp;
  1731. u16 cvp_handle;
  1732. get_all_vocproc_cal(&cal_block);
  1733. if (cal_block.cal_size == 0 ||
  1734. cal_block.cal_size > CVP_CAL_SIZE)
  1735. return 0;
  1736. if (v == NULL) {
  1737. pr_err("%s: v is NULL\n", __func__);
  1738. return -EINVAL;
  1739. }
  1740. apr_cvp = common.apr_q6_cvp;
  1741. if (!apr_cvp) {
  1742. pr_err("%s: apr_cvp is NULL.\n", __func__);
  1743. return -EINVAL;
  1744. }
  1745. cvp_handle = voice_get_cvp_handle(v);
  1746. /* fill in the header */
  1747. cvp_dereg_cal_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1748. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  1749. cvp_dereg_cal_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1750. sizeof(cvp_dereg_cal_cmd) - APR_HDR_SIZE);
  1751. cvp_dereg_cal_cmd.hdr.src_port = v->session_id;
  1752. cvp_dereg_cal_cmd.hdr.dest_port = cvp_handle;
  1753. cvp_dereg_cal_cmd.hdr.token = 0;
  1754. cvp_dereg_cal_cmd.hdr.opcode =
  1755. VSS_IVOCPROC_CMD_DEREGISTER_CALIBRATION_DATA;
  1756. v->cvp_state = CMD_STATUS_FAIL;
  1757. ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_dereg_cal_cmd);
  1758. if (ret < 0) {
  1759. pr_err("Fail: sending cvp cal,\n");
  1760. goto fail;
  1761. }
  1762. ret = wait_event_timeout(v->cvp_wait,
  1763. (v->cvp_state == CMD_STATUS_SUCCESS),
  1764. msecs_to_jiffies(TIMEOUT_MS));
  1765. if (!ret) {
  1766. pr_err("%s: wait_event timeout\n", __func__);
  1767. goto fail;
  1768. }
  1769. return 0;
  1770. fail:
  1771. return -EINVAL;
  1772. }
  1773. static int voice_send_cvp_register_vol_cal_table_cmd(struct voice_data *v)
  1774. {
  1775. struct cvp_register_vol_cal_table_cmd cvp_reg_cal_tbl_cmd;
  1776. struct acdb_cal_block vol_block;
  1777. struct acdb_cal_block voc_block;
  1778. struct acdb_cal_block cvp_block;
  1779. int ret = 0;
  1780. void *apr_cvp;
  1781. u16 cvp_handle;
  1782. uint32_t cal_paddr = 0;
  1783. uint32_t cal_buf = 0;
  1784. /* get the cvp vol cal data */
  1785. get_all_vocvol_cal(&vol_block);
  1786. get_all_vocproc_cal(&voc_block);
  1787. get_all_cvp_cal(&cvp_block);
  1788. if (vol_block.cal_size == 0 ||
  1789. cvp_block.cal_size > CVP_CAL_SIZE)
  1790. goto fail;
  1791. if (v == NULL) {
  1792. pr_err("%s: v is NULL\n", __func__);
  1793. return -EINVAL;
  1794. }
  1795. apr_cvp = common.apr_q6_cvp;
  1796. if (!apr_cvp) {
  1797. pr_err("%s: apr_cvp is NULL.\n", __func__);
  1798. return -EINVAL;
  1799. }
  1800. if (is_volte_session(v->session_id) ||
  1801. is_voip_session(v->session_id)) {
  1802. ret = voice_get_cal_phys_addr(v->session_id, CVP_CAL,
  1803. &cal_paddr);
  1804. if (ret < 0)
  1805. return ret;
  1806. cal_paddr += voc_block.cal_size;
  1807. ret = voice_get_cal_kernel_addr(v->session_id, CVP_CAL,
  1808. &cal_buf);
  1809. if (ret < 0)
  1810. return ret;
  1811. memcpy((void *)(cal_buf + voc_block.cal_size),
  1812. (void *)vol_block.cal_kvaddr, vol_block.cal_size);
  1813. } else {
  1814. cal_paddr = vol_block.cal_paddr;
  1815. }
  1816. cvp_handle = voice_get_cvp_handle(v);
  1817. /* fill in the header */
  1818. cvp_reg_cal_tbl_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1819. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  1820. cvp_reg_cal_tbl_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1821. sizeof(cvp_reg_cal_tbl_cmd) - APR_HDR_SIZE);
  1822. cvp_reg_cal_tbl_cmd.hdr.src_port = v->session_id;
  1823. cvp_reg_cal_tbl_cmd.hdr.dest_port = cvp_handle;
  1824. cvp_reg_cal_tbl_cmd.hdr.token = 0;
  1825. cvp_reg_cal_tbl_cmd.hdr.opcode =
  1826. VSS_IVOCPROC_CMD_REGISTER_VOLUME_CAL_TABLE;
  1827. cvp_reg_cal_tbl_cmd.cvp_vol_cal_tbl.phys_addr = cal_paddr;
  1828. cvp_reg_cal_tbl_cmd.cvp_vol_cal_tbl.mem_size = vol_block.cal_size;
  1829. v->cvp_state = CMD_STATUS_FAIL;
  1830. ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_reg_cal_tbl_cmd);
  1831. if (ret < 0) {
  1832. pr_err("Fail: sending cvp cal table,\n");
  1833. goto fail;
  1834. }
  1835. ret = wait_event_timeout(v->cvp_wait,
  1836. (v->cvp_state == CMD_STATUS_SUCCESS),
  1837. msecs_to_jiffies(TIMEOUT_MS));
  1838. if (!ret) {
  1839. pr_err("%s: wait_event timeout\n", __func__);
  1840. goto fail;
  1841. }
  1842. return 0;
  1843. fail:
  1844. return -EINVAL;
  1845. }
  1846. static int voice_send_cvp_deregister_vol_cal_table_cmd(struct voice_data *v)
  1847. {
  1848. struct cvp_deregister_vol_cal_table_cmd cvp_dereg_cal_tbl_cmd;
  1849. struct acdb_cal_block cal_block;
  1850. struct acdb_cal_block voc_block;
  1851. int ret = 0;
  1852. void *apr_cvp;
  1853. u16 cvp_handle;
  1854. get_all_vocvol_cal(&cal_block);
  1855. get_all_cvp_cal(&voc_block);
  1856. if (cal_block.cal_size == 0 ||
  1857. voc_block.cal_size > CVP_CAL_SIZE)
  1858. return 0;
  1859. if (v == NULL) {
  1860. pr_err("%s: v is NULL\n", __func__);
  1861. return -EINVAL;
  1862. }
  1863. apr_cvp = common.apr_q6_cvp;
  1864. if (!apr_cvp) {
  1865. pr_err("%s: apr_cvp is NULL.\n", __func__);
  1866. return -EINVAL;
  1867. }
  1868. cvp_handle = voice_get_cvp_handle(v);
  1869. /* fill in the header */
  1870. cvp_dereg_cal_tbl_cmd.hdr.hdr_field = APR_HDR_FIELD(
  1871. APR_MSG_TYPE_SEQ_CMD,
  1872. APR_HDR_LEN(APR_HDR_SIZE),
  1873. APR_PKT_VER);
  1874. cvp_dereg_cal_tbl_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1875. sizeof(cvp_dereg_cal_tbl_cmd) - APR_HDR_SIZE);
  1876. cvp_dereg_cal_tbl_cmd.hdr.src_port = v->session_id;
  1877. cvp_dereg_cal_tbl_cmd.hdr.dest_port = cvp_handle;
  1878. cvp_dereg_cal_tbl_cmd.hdr.token = 0;
  1879. cvp_dereg_cal_tbl_cmd.hdr.opcode =
  1880. VSS_IVOCPROC_CMD_DEREGISTER_VOLUME_CAL_TABLE;
  1881. v->cvp_state = CMD_STATUS_FAIL;
  1882. ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_dereg_cal_tbl_cmd);
  1883. if (ret < 0) {
  1884. pr_err("Fail: sending cvp cal table,\n");
  1885. goto fail;
  1886. }
  1887. ret = wait_event_timeout(v->cvp_wait,
  1888. (v->cvp_state == CMD_STATUS_SUCCESS),
  1889. msecs_to_jiffies(TIMEOUT_MS));
  1890. if (!ret) {
  1891. pr_err("%s: wait_event timeout\n", __func__);
  1892. goto fail;
  1893. }
  1894. return 0;
  1895. fail:
  1896. return -EINVAL;
  1897. }
  1898. static int voice_send_set_widevoice_enable_cmd(struct voice_data *v)
  1899. {
  1900. struct mvm_set_widevoice_enable_cmd mvm_set_wv_cmd;
  1901. int ret = 0;
  1902. void *apr_mvm;
  1903. u16 mvm_handle;
  1904. if (v == NULL) {
  1905. pr_err("%s: v is NULL\n", __func__);
  1906. return -EINVAL;
  1907. }
  1908. apr_mvm = common.apr_q6_mvm;
  1909. if (!apr_mvm) {
  1910. pr_err("%s: apr_mvm is NULL.\n", __func__);
  1911. return -EINVAL;
  1912. }
  1913. mvm_handle = voice_get_mvm_handle(v);
  1914. /* fill in the header */
  1915. mvm_set_wv_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1916. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  1917. mvm_set_wv_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1918. sizeof(mvm_set_wv_cmd) - APR_HDR_SIZE);
  1919. mvm_set_wv_cmd.hdr.src_port = v->session_id;
  1920. mvm_set_wv_cmd.hdr.dest_port = mvm_handle;
  1921. mvm_set_wv_cmd.hdr.token = 0;
  1922. mvm_set_wv_cmd.hdr.opcode = VSS_IWIDEVOICE_CMD_SET_WIDEVOICE;
  1923. mvm_set_wv_cmd.vss_set_wv.enable = v->wv_enable;
  1924. v->mvm_state = CMD_STATUS_FAIL;
  1925. ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_set_wv_cmd);
  1926. if (ret < 0) {
  1927. pr_err("Fail: sending mvm set widevoice enable,\n");
  1928. goto fail;
  1929. }
  1930. ret = wait_event_timeout(v->mvm_wait,
  1931. (v->mvm_state == CMD_STATUS_SUCCESS),
  1932. msecs_to_jiffies(TIMEOUT_MS));
  1933. if (!ret) {
  1934. pr_err("%s: wait_event timeout\n", __func__);
  1935. goto fail;
  1936. }
  1937. return 0;
  1938. fail:
  1939. return -EINVAL;
  1940. }
  1941. static int voice_send_set_pp_enable_cmd(struct voice_data *v,
  1942. uint32_t module_id, int enable)
  1943. {
  1944. struct cvs_set_pp_enable_cmd cvs_set_pp_cmd;
  1945. int ret = 0;
  1946. void *apr_cvs;
  1947. u16 cvs_handle;
  1948. if (v == NULL) {
  1949. pr_err("%s: v is NULL\n", __func__);
  1950. return -EINVAL;
  1951. }
  1952. apr_cvs = common.apr_q6_cvs;
  1953. if (!apr_cvs) {
  1954. pr_err("%s: apr_cvs is NULL.\n", __func__);
  1955. return -EINVAL;
  1956. }
  1957. cvs_handle = voice_get_cvs_handle(v);
  1958. /* fill in the header */
  1959. cvs_set_pp_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  1960. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  1961. cvs_set_pp_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  1962. sizeof(cvs_set_pp_cmd) - APR_HDR_SIZE);
  1963. cvs_set_pp_cmd.hdr.src_port = v->session_id;
  1964. cvs_set_pp_cmd.hdr.dest_port = cvs_handle;
  1965. cvs_set_pp_cmd.hdr.token = 0;
  1966. cvs_set_pp_cmd.hdr.opcode = VSS_ICOMMON_CMD_SET_UI_PROPERTY;
  1967. cvs_set_pp_cmd.vss_set_pp.module_id = module_id;
  1968. cvs_set_pp_cmd.vss_set_pp.param_id = VOICE_PARAM_MOD_ENABLE;
  1969. cvs_set_pp_cmd.vss_set_pp.param_size = MOD_ENABLE_PARAM_LEN;
  1970. cvs_set_pp_cmd.vss_set_pp.reserved = 0;
  1971. cvs_set_pp_cmd.vss_set_pp.enable = enable;
  1972. cvs_set_pp_cmd.vss_set_pp.reserved_field = 0;
  1973. pr_debug("voice_send_set_pp_enable_cmd, module_id=%d, enable=%d\n",
  1974. module_id, enable);
  1975. v->cvs_state = CMD_STATUS_FAIL;
  1976. ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_set_pp_cmd);
  1977. if (ret < 0) {
  1978. pr_err("Fail: sending cvs set slowtalk enable,\n");
  1979. goto fail;
  1980. }
  1981. ret = wait_event_timeout(v->cvs_wait,
  1982. (v->cvs_state == CMD_STATUS_SUCCESS),
  1983. msecs_to_jiffies(TIMEOUT_MS));
  1984. if (!ret) {
  1985. pr_err("%s: wait_event timeout\n", __func__);
  1986. goto fail;
  1987. }
  1988. return 0;
  1989. fail:
  1990. return -EINVAL;
  1991. }
  1992. static int voice_setup_vocproc(struct voice_data *v)
  1993. {
  1994. struct cvp_create_full_ctl_session_cmd cvp_session_cmd;
  1995. int ret = 0;
  1996. void *apr_cvp;
  1997. uint32_t cal_paddr = 0;
  1998. uint32_t cal_size = 0;
  1999. if (v == NULL) {
  2000. pr_err("%s: v is NULL\n", __func__);
  2001. return -EINVAL;
  2002. }
  2003. apr_cvp = common.apr_q6_cvp;
  2004. if (!apr_cvp) {
  2005. pr_err("%s: apr_cvp is NULL.\n", __func__);
  2006. return -EINVAL;
  2007. }
  2008. /* create cvp session and wait for response */
  2009. cvp_session_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2010. APR_HDR_LEN(APR_HDR_SIZE),
  2011. APR_PKT_VER);
  2012. cvp_session_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2013. sizeof(cvp_session_cmd) - APR_HDR_SIZE);
  2014. pr_debug(" send create cvp session, pkt size = %d\n",
  2015. cvp_session_cmd.hdr.pkt_size);
  2016. cvp_session_cmd.hdr.src_port = v->session_id;
  2017. cvp_session_cmd.hdr.dest_port = 0;
  2018. cvp_session_cmd.hdr.token = 0;
  2019. cvp_session_cmd.hdr.opcode =
  2020. VSS_IVOCPROC_CMD_CREATE_FULL_CONTROL_SESSION;
  2021. voc_get_tx_rx_topology(v, &cvp_session_cmd.cvp_session.tx_topology_id,
  2022. &cvp_session_cmd.cvp_session.rx_topology_id);
  2023. cvp_session_cmd.cvp_session.direction = 2; /*tx and rx*/
  2024. cvp_session_cmd.cvp_session.network_id = VSS_NETWORK_ID_DEFAULT;
  2025. cvp_session_cmd.cvp_session.tx_port_id = v->dev_tx.port_id;
  2026. cvp_session_cmd.cvp_session.rx_port_id = v->dev_rx.port_id;
  2027. pr_debug("topology=%d net_id=%d, dir=%d tx_port_id=%d, rx_port_id=%d\n",
  2028. cvp_session_cmd.cvp_session.tx_topology_id,
  2029. cvp_session_cmd.cvp_session.network_id,
  2030. cvp_session_cmd.cvp_session.direction,
  2031. cvp_session_cmd.cvp_session.tx_port_id,
  2032. cvp_session_cmd.cvp_session.rx_port_id);
  2033. v->cvp_state = CMD_STATUS_FAIL;
  2034. ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_session_cmd);
  2035. if (ret < 0) {
  2036. pr_err("Fail in sending VOCPROC_FULL_CONTROL_SESSION\n");
  2037. goto fail;
  2038. }
  2039. ret = wait_event_timeout(v->cvp_wait,
  2040. (v->cvp_state == CMD_STATUS_SUCCESS),
  2041. msecs_to_jiffies(TIMEOUT_MS));
  2042. if (!ret) {
  2043. pr_err("%s: wait_event timeout\n", __func__);
  2044. goto fail;
  2045. }
  2046. if (common.ec_ref_ext == true) {
  2047. ret = voice_send_set_device_cmd_v2(v);
  2048. if (ret < 0) {
  2049. pr_err("%s: set device V2 failed rc =%x\n",
  2050. __func__, ret);
  2051. goto fail;
  2052. }
  2053. }
  2054. /* send cvs cal */
  2055. ret = voice_send_cvs_map_memory_cmd(v);
  2056. if (!ret)
  2057. voice_send_cvs_register_cal_cmd(v);
  2058. /* send cvp and vol cal */
  2059. if (!voice_get_cal_paddr_size(v, &cal_paddr, &cal_size) &&
  2060. !voice_send_cvp_map_memory_cmd(v, cal_paddr, cal_size)) {
  2061. voice_send_cvp_register_cal_cmd(v);
  2062. voice_send_cvp_register_vol_cal_table_cmd(v);
  2063. }
  2064. /* enable vocproc */
  2065. ret = voice_send_enable_vocproc_cmd(v);
  2066. if (ret < 0)
  2067. goto fail;
  2068. /* attach vocproc */
  2069. ret = voice_send_attach_vocproc_cmd(v);
  2070. if (ret < 0)
  2071. goto fail;
  2072. /* send tty mode if tty device is used */
  2073. voice_send_tty_mode_cmd(v);
  2074. /* enable widevoice if wv_enable is set */
  2075. if (v->wv_enable)
  2076. voice_send_set_widevoice_enable_cmd(v);
  2077. /* enable slowtalk if st_enable is set */
  2078. if (v->st_enable)
  2079. voice_send_set_pp_enable_cmd(v, MODULE_ID_VOICE_MODULE_ST,
  2080. v->st_enable);
  2081. voice_send_set_pp_enable_cmd(v, MODULE_ID_VOICE_MODULE_FENS,
  2082. v->fens_enable);
  2083. if (is_voip_session(v->session_id))
  2084. voice_send_netid_timing_cmd(v);
  2085. /* Start in-call music delivery if this feature is enabled */
  2086. if (v->music_info.play_enable)
  2087. voice_cvs_start_playback(v);
  2088. /* Start in-call recording if this feature is enabled */
  2089. if (v->rec_info.rec_enable)
  2090. voice_cvs_start_record(v, v->rec_info.rec_mode);
  2091. if (v->dtmf_rx_detect_en)
  2092. voice_send_dtmf_rx_detection_cmd(v, v->dtmf_rx_detect_en);
  2093. rtac_add_voice(voice_get_cvs_handle(v),
  2094. voice_get_cvp_handle(v),
  2095. v->dev_rx.port_id, v->dev_tx.port_id,
  2096. v->session_id);
  2097. return 0;
  2098. fail:
  2099. return -EINVAL;
  2100. }
  2101. static int voice_send_enable_vocproc_cmd(struct voice_data *v)
  2102. {
  2103. int ret = 0;
  2104. struct apr_hdr cvp_enable_cmd;
  2105. void *apr_cvp;
  2106. u16 cvp_handle;
  2107. if (v == NULL) {
  2108. pr_err("%s: v is NULL\n", __func__);
  2109. return -EINVAL;
  2110. }
  2111. apr_cvp = common.apr_q6_cvp;
  2112. if (!apr_cvp) {
  2113. pr_err("%s: apr_cvp is NULL.\n", __func__);
  2114. return -EINVAL;
  2115. }
  2116. cvp_handle = voice_get_cvp_handle(v);
  2117. /* enable vocproc and wait for respose */
  2118. cvp_enable_cmd.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2119. APR_HDR_LEN(APR_HDR_SIZE),
  2120. APR_PKT_VER);
  2121. cvp_enable_cmd.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2122. sizeof(cvp_enable_cmd) - APR_HDR_SIZE);
  2123. pr_debug("cvp_enable_cmd pkt size = %d, cvp_handle=%d\n",
  2124. cvp_enable_cmd.pkt_size, cvp_handle);
  2125. cvp_enable_cmd.src_port = v->session_id;
  2126. cvp_enable_cmd.dest_port = cvp_handle;
  2127. cvp_enable_cmd.token = 0;
  2128. cvp_enable_cmd.opcode = VSS_IVOCPROC_CMD_ENABLE;
  2129. v->cvp_state = CMD_STATUS_FAIL;
  2130. ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_enable_cmd);
  2131. if (ret < 0) {
  2132. pr_err("Fail in sending VSS_IVOCPROC_CMD_ENABLE\n");
  2133. goto fail;
  2134. }
  2135. ret = wait_event_timeout(v->cvp_wait,
  2136. (v->cvp_state == CMD_STATUS_SUCCESS),
  2137. msecs_to_jiffies(TIMEOUT_MS));
  2138. if (!ret) {
  2139. pr_err("%s: wait_event timeout\n", __func__);
  2140. goto fail;
  2141. }
  2142. return 0;
  2143. fail:
  2144. return -EINVAL;
  2145. }
  2146. static int voice_send_netid_timing_cmd(struct voice_data *v)
  2147. {
  2148. int ret = 0;
  2149. void *apr_mvm;
  2150. u16 mvm_handle;
  2151. struct mvm_set_network_cmd mvm_set_network;
  2152. struct mvm_set_voice_timing_cmd mvm_set_voice_timing;
  2153. if (v == NULL) {
  2154. pr_err("%s: v is NULL\n", __func__);
  2155. return -EINVAL;
  2156. }
  2157. apr_mvm = common.apr_q6_mvm;
  2158. if (!apr_mvm) {
  2159. pr_err("%s: apr_mvm is NULL.\n", __func__);
  2160. return -EINVAL;
  2161. }
  2162. mvm_handle = voice_get_mvm_handle(v);
  2163. ret = voice_config_cvs_vocoder(v);
  2164. if (ret < 0) {
  2165. pr_err("%s: Error %d configuring CVS voc",
  2166. __func__, ret);
  2167. goto fail;
  2168. }
  2169. /* Set network ID. */
  2170. pr_debug("Setting network ID\n");
  2171. mvm_set_network.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2172. APR_HDR_LEN(APR_HDR_SIZE),
  2173. APR_PKT_VER);
  2174. mvm_set_network.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2175. sizeof(mvm_set_network) - APR_HDR_SIZE);
  2176. mvm_set_network.hdr.src_port = v->session_id;
  2177. mvm_set_network.hdr.dest_port = mvm_handle;
  2178. mvm_set_network.hdr.token = 0;
  2179. mvm_set_network.hdr.opcode = VSS_ICOMMON_CMD_SET_NETWORK;
  2180. mvm_set_network.network.network_id = common.mvs_info.network_type;
  2181. v->mvm_state = CMD_STATUS_FAIL;
  2182. ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_set_network);
  2183. if (ret < 0) {
  2184. pr_err("%s: Error %d sending SET_NETWORK\n", __func__, ret);
  2185. goto fail;
  2186. }
  2187. ret = wait_event_timeout(v->mvm_wait,
  2188. (v->mvm_state == CMD_STATUS_SUCCESS),
  2189. msecs_to_jiffies(TIMEOUT_MS));
  2190. if (!ret) {
  2191. pr_err("%s: wait_event timeout\n", __func__);
  2192. goto fail;
  2193. }
  2194. /* Set voice timing. */
  2195. pr_debug("Setting voice timing\n");
  2196. mvm_set_voice_timing.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2197. APR_HDR_LEN(APR_HDR_SIZE),
  2198. APR_PKT_VER);
  2199. mvm_set_voice_timing.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2200. sizeof(mvm_set_voice_timing) -
  2201. APR_HDR_SIZE);
  2202. mvm_set_voice_timing.hdr.src_port = v->session_id;
  2203. mvm_set_voice_timing.hdr.dest_port = mvm_handle;
  2204. mvm_set_voice_timing.hdr.token = 0;
  2205. mvm_set_voice_timing.hdr.opcode = VSS_ICOMMON_CMD_SET_VOICE_TIMING;
  2206. mvm_set_voice_timing.timing.mode = 0;
  2207. mvm_set_voice_timing.timing.enc_offset = 8000;
  2208. mvm_set_voice_timing.timing.dec_req_offset = 3300;
  2209. mvm_set_voice_timing.timing.dec_offset = 8300;
  2210. v->mvm_state = CMD_STATUS_FAIL;
  2211. ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_set_voice_timing);
  2212. if (ret < 0) {
  2213. pr_err("%s: Error %d sending SET_TIMING\n", __func__, ret);
  2214. goto fail;
  2215. }
  2216. ret = wait_event_timeout(v->mvm_wait,
  2217. (v->mvm_state == CMD_STATUS_SUCCESS),
  2218. msecs_to_jiffies(TIMEOUT_MS));
  2219. if (!ret) {
  2220. pr_err("%s: wait_event timeout\n", __func__);
  2221. goto fail;
  2222. }
  2223. return 0;
  2224. fail:
  2225. return -EINVAL;
  2226. }
  2227. static int voice_send_attach_vocproc_cmd(struct voice_data *v)
  2228. {
  2229. int ret = 0;
  2230. struct mvm_attach_vocproc_cmd mvm_a_vocproc_cmd;
  2231. void *apr_mvm;
  2232. u16 mvm_handle, cvp_handle;
  2233. if (v == NULL) {
  2234. pr_err("%s: v is NULL\n", __func__);
  2235. return -EINVAL;
  2236. }
  2237. apr_mvm = common.apr_q6_mvm;
  2238. if (!apr_mvm) {
  2239. pr_err("%s: apr_mvm is NULL.\n", __func__);
  2240. return -EINVAL;
  2241. }
  2242. mvm_handle = voice_get_mvm_handle(v);
  2243. cvp_handle = voice_get_cvp_handle(v);
  2244. /* attach vocproc and wait for response */
  2245. mvm_a_vocproc_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2246. APR_HDR_LEN(APR_HDR_SIZE),
  2247. APR_PKT_VER);
  2248. mvm_a_vocproc_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2249. sizeof(mvm_a_vocproc_cmd) - APR_HDR_SIZE);
  2250. pr_debug("send mvm_a_vocproc_cmd pkt size = %d\n",
  2251. mvm_a_vocproc_cmd.hdr.pkt_size);
  2252. mvm_a_vocproc_cmd.hdr.src_port = v->session_id;
  2253. mvm_a_vocproc_cmd.hdr.dest_port = mvm_handle;
  2254. mvm_a_vocproc_cmd.hdr.token = 0;
  2255. mvm_a_vocproc_cmd.hdr.opcode = VSS_IMVM_CMD_ATTACH_VOCPROC;
  2256. mvm_a_vocproc_cmd.mvm_attach_cvp_handle.handle = cvp_handle;
  2257. v->mvm_state = CMD_STATUS_FAIL;
  2258. ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_a_vocproc_cmd);
  2259. if (ret < 0) {
  2260. pr_err("Fail in sending VSS_IMVM_CMD_ATTACH_VOCPROC\n");
  2261. goto fail;
  2262. }
  2263. ret = wait_event_timeout(v->mvm_wait,
  2264. (v->mvm_state == CMD_STATUS_SUCCESS),
  2265. msecs_to_jiffies(TIMEOUT_MS));
  2266. if (!ret) {
  2267. pr_err("%s: wait_event timeout\n", __func__);
  2268. goto fail;
  2269. }
  2270. return 0;
  2271. fail:
  2272. return -EINVAL;
  2273. }
  2274. static int voice_destroy_vocproc(struct voice_data *v)
  2275. {
  2276. struct mvm_detach_vocproc_cmd mvm_d_vocproc_cmd;
  2277. struct apr_hdr cvp_destroy_session_cmd;
  2278. int ret = 0;
  2279. void *apr_mvm, *apr_cvp;
  2280. u16 mvm_handle, cvp_handle;
  2281. uint32_t paddr = 0;
  2282. if (v == NULL) {
  2283. pr_err("%s: v is NULL\n", __func__);
  2284. return -EINVAL;
  2285. }
  2286. apr_mvm = common.apr_q6_mvm;
  2287. apr_cvp = common.apr_q6_cvp;
  2288. if (!apr_mvm || !apr_cvp) {
  2289. pr_err("%s: apr_mvm or apr_cvp is NULL.\n", __func__);
  2290. return -EINVAL;
  2291. }
  2292. mvm_handle = voice_get_mvm_handle(v);
  2293. cvp_handle = voice_get_cvp_handle(v);
  2294. /* stop playback or recording */
  2295. v->music_info.force = 1;
  2296. voice_cvs_stop_playback(v);
  2297. voice_cvs_stop_record(v);
  2298. /* send stop voice cmd */
  2299. voice_send_stop_voice_cmd(v);
  2300. /* send stop dtmf detecton cmd */
  2301. if (v->dtmf_rx_detect_en)
  2302. voice_send_dtmf_rx_detection_cmd(v, 0);
  2303. /* Clear mute setting */
  2304. v->dev_tx.mute = common.default_mute_val;
  2305. /* clear disable topology setting */
  2306. v->disable_topology = false;
  2307. /* detach VOCPROC and wait for response from mvm */
  2308. mvm_d_vocproc_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2309. APR_HDR_LEN(APR_HDR_SIZE),
  2310. APR_PKT_VER);
  2311. mvm_d_vocproc_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2312. sizeof(mvm_d_vocproc_cmd) - APR_HDR_SIZE);
  2313. pr_debug("mvm_d_vocproc_cmd pkt size = %d\n",
  2314. mvm_d_vocproc_cmd.hdr.pkt_size);
  2315. mvm_d_vocproc_cmd.hdr.src_port = v->session_id;
  2316. mvm_d_vocproc_cmd.hdr.dest_port = mvm_handle;
  2317. mvm_d_vocproc_cmd.hdr.token = 0;
  2318. mvm_d_vocproc_cmd.hdr.opcode = VSS_IMVM_CMD_DETACH_VOCPROC;
  2319. mvm_d_vocproc_cmd.mvm_detach_cvp_handle.handle = cvp_handle;
  2320. v->mvm_state = CMD_STATUS_FAIL;
  2321. ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_d_vocproc_cmd);
  2322. if (ret < 0) {
  2323. pr_err("Fail in sending VSS_IMVM_CMD_DETACH_VOCPROC\n");
  2324. goto fail;
  2325. }
  2326. ret = wait_event_timeout(v->mvm_wait,
  2327. (v->mvm_state == CMD_STATUS_SUCCESS),
  2328. msecs_to_jiffies(TIMEOUT_MS));
  2329. if (!ret) {
  2330. pr_err("%s: wait_event timeout\n", __func__);
  2331. goto fail;
  2332. }
  2333. /* deregister cvp and vol cal */
  2334. voice_send_cvp_deregister_vol_cal_table_cmd(v);
  2335. voice_send_cvp_deregister_cal_cmd(v);
  2336. if (!voice_get_cal_paddr_size(v, &paddr, NULL))
  2337. voice_send_cvp_unmap_memory_cmd(v, paddr);
  2338. /* deregister cvs cal */
  2339. voice_send_cvs_deregister_cal_cmd(v);
  2340. voice_send_cvs_unmap_memory_cmd(v);
  2341. /* destrop cvp session */
  2342. cvp_destroy_session_cmd.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2343. APR_HDR_LEN(APR_HDR_SIZE),
  2344. APR_PKT_VER);
  2345. cvp_destroy_session_cmd.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2346. sizeof(cvp_destroy_session_cmd) - APR_HDR_SIZE);
  2347. pr_debug("cvp_destroy_session_cmd pkt size = %d\n",
  2348. cvp_destroy_session_cmd.pkt_size);
  2349. cvp_destroy_session_cmd.src_port = v->session_id;
  2350. cvp_destroy_session_cmd.dest_port = cvp_handle;
  2351. cvp_destroy_session_cmd.token = 0;
  2352. cvp_destroy_session_cmd.opcode = APRV2_IBASIC_CMD_DESTROY_SESSION;
  2353. v->cvp_state = CMD_STATUS_FAIL;
  2354. ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_destroy_session_cmd);
  2355. if (ret < 0) {
  2356. pr_err("Fail in sending APRV2_IBASIC_CMD_DESTROY_SESSION\n");
  2357. goto fail;
  2358. }
  2359. ret = wait_event_timeout(v->cvp_wait,
  2360. (v->cvp_state == CMD_STATUS_SUCCESS),
  2361. msecs_to_jiffies(TIMEOUT_MS));
  2362. if (!ret) {
  2363. pr_err("%s: wait_event timeout\n", __func__);
  2364. goto fail;
  2365. }
  2366. rtac_remove_voice(voice_get_cvs_handle(v));
  2367. cvp_handle = 0;
  2368. voice_set_cvp_handle(v, cvp_handle);
  2369. return 0;
  2370. fail:
  2371. return -EINVAL;
  2372. }
  2373. static int voice_send_mute_cmd(struct voice_data *v)
  2374. {
  2375. struct cvs_set_mute_cmd cvs_mute_cmd;
  2376. int ret = 0;
  2377. void *apr_cvs;
  2378. u16 cvs_handle;
  2379. if (v == NULL) {
  2380. pr_err("%s: v is NULL\n", __func__);
  2381. return -EINVAL;
  2382. }
  2383. apr_cvs = common.apr_q6_cvs;
  2384. if (!apr_cvs) {
  2385. pr_err("%s: apr_cvs is NULL.\n", __func__);
  2386. return -EINVAL;
  2387. }
  2388. cvs_handle = voice_get_cvs_handle(v);
  2389. /* send mute/unmute to cvs */
  2390. cvs_mute_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2391. APR_HDR_LEN(APR_HDR_SIZE),
  2392. APR_PKT_VER);
  2393. cvs_mute_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2394. sizeof(cvs_mute_cmd) - APR_HDR_SIZE);
  2395. cvs_mute_cmd.hdr.src_port = v->session_id;
  2396. cvs_mute_cmd.hdr.dest_port = cvs_handle;
  2397. cvs_mute_cmd.hdr.token = 0;
  2398. cvs_mute_cmd.hdr.opcode = VSS_ISTREAM_CMD_SET_MUTE;
  2399. cvs_mute_cmd.cvs_set_mute.direction = 0; /*tx*/
  2400. cvs_mute_cmd.cvs_set_mute.mute_flag = v->dev_tx.mute;
  2401. pr_info(" mute value =%d\n", cvs_mute_cmd.cvs_set_mute.mute_flag);
  2402. v->cvs_state = CMD_STATUS_FAIL;
  2403. ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_mute_cmd);
  2404. if (ret < 0) {
  2405. pr_err("Fail: send STREAM SET MUTE\n");
  2406. goto fail;
  2407. }
  2408. ret = wait_event_timeout(v->cvs_wait,
  2409. (v->cvs_state == CMD_STATUS_SUCCESS),
  2410. msecs_to_jiffies(TIMEOUT_MS));
  2411. if (!ret)
  2412. pr_err("%s: wait_event timeout\n", __func__);
  2413. return 0;
  2414. fail:
  2415. return -EINVAL;
  2416. }
  2417. static int voice_send_rx_device_mute_cmd(struct voice_data *v)
  2418. {
  2419. struct cvp_set_mute_cmd cvp_mute_cmd;
  2420. int ret = 0;
  2421. void *apr_cvp;
  2422. u16 cvp_handle;
  2423. if (v == NULL) {
  2424. pr_err("%s: v is NULL\n", __func__);
  2425. return -EINVAL;
  2426. }
  2427. apr_cvp = common.apr_q6_cvp;
  2428. if (!apr_cvp) {
  2429. pr_err("%s: apr_cvp is NULL.\n", __func__);
  2430. return -EINVAL;
  2431. }
  2432. cvp_handle = voice_get_cvp_handle(v);
  2433. cvp_mute_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2434. APR_HDR_LEN(APR_HDR_SIZE),
  2435. APR_PKT_VER);
  2436. cvp_mute_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2437. sizeof(cvp_mute_cmd) - APR_HDR_SIZE);
  2438. cvp_mute_cmd.hdr.src_port = v->session_id;
  2439. cvp_mute_cmd.hdr.dest_port = cvp_handle;
  2440. cvp_mute_cmd.hdr.token = 0;
  2441. cvp_mute_cmd.hdr.opcode = VSS_IVOCPROC_CMD_SET_MUTE;
  2442. cvp_mute_cmd.cvp_set_mute.direction = 1;
  2443. cvp_mute_cmd.cvp_set_mute.mute_flag = v->dev_rx.mute;
  2444. v->cvp_state = CMD_STATUS_FAIL;
  2445. ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_mute_cmd);
  2446. if (ret < 0) {
  2447. pr_err("Fail in sending RX device mute cmd\n");
  2448. return -EINVAL;
  2449. }
  2450. ret = wait_event_timeout(v->cvp_wait,
  2451. (v->cvp_state == CMD_STATUS_SUCCESS),
  2452. msecs_to_jiffies(TIMEOUT_MS));
  2453. if (!ret) {
  2454. pr_err("%s: wait_event timeout\n", __func__);
  2455. return -EINVAL;
  2456. }
  2457. return 0;
  2458. }
  2459. static int voice_send_vol_index_cmd(struct voice_data *v)
  2460. {
  2461. struct cvp_set_rx_volume_index_cmd cvp_vol_cmd;
  2462. int ret = 0;
  2463. void *apr_cvp;
  2464. u16 cvp_handle;
  2465. if (v == NULL) {
  2466. pr_err("%s: v is NULL\n", __func__);
  2467. return -EINVAL;
  2468. }
  2469. apr_cvp = common.apr_q6_cvp;
  2470. if (!apr_cvp) {
  2471. pr_err("%s: apr_cvp is NULL.\n", __func__);
  2472. return -EINVAL;
  2473. }
  2474. cvp_handle = voice_get_cvp_handle(v);
  2475. /* send volume index to cvp */
  2476. cvp_vol_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2477. APR_HDR_LEN(APR_HDR_SIZE),
  2478. APR_PKT_VER);
  2479. cvp_vol_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2480. sizeof(cvp_vol_cmd) - APR_HDR_SIZE);
  2481. cvp_vol_cmd.hdr.src_port = v->session_id;
  2482. cvp_vol_cmd.hdr.dest_port = cvp_handle;
  2483. cvp_vol_cmd.hdr.token = 0;
  2484. cvp_vol_cmd.hdr.opcode = VSS_IVOCPROC_CMD_SET_RX_VOLUME_INDEX;
  2485. cvp_vol_cmd.cvp_set_vol_idx.vol_index = v->dev_rx.volume;
  2486. v->cvp_state = CMD_STATUS_FAIL;
  2487. ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_vol_cmd);
  2488. if (ret < 0) {
  2489. pr_err("Fail in sending RX VOL INDEX\n");
  2490. return -EINVAL;
  2491. }
  2492. ret = wait_event_timeout(v->cvp_wait,
  2493. (v->cvp_state == CMD_STATUS_SUCCESS),
  2494. msecs_to_jiffies(TIMEOUT_MS));
  2495. if (!ret) {
  2496. pr_err("%s: wait_event timeout\n", __func__);
  2497. return -EINVAL;
  2498. }
  2499. return 0;
  2500. }
  2501. static int voice_cvs_start_record(struct voice_data *v, uint32_t rec_mode)
  2502. {
  2503. int ret = 0;
  2504. void *apr_cvs;
  2505. u16 cvs_handle;
  2506. struct cvs_start_record_cmd cvs_start_record;
  2507. if (v == NULL) {
  2508. pr_err("%s: v is NULL\n", __func__);
  2509. return -EINVAL;
  2510. }
  2511. apr_cvs = common.apr_q6_cvs;
  2512. if (!apr_cvs) {
  2513. pr_err("%s: apr_cvs is NULL.\n", __func__);
  2514. return -EINVAL;
  2515. }
  2516. cvs_handle = voice_get_cvs_handle(v);
  2517. if (!v->rec_info.recording) {
  2518. cvs_start_record.hdr.hdr_field = APR_HDR_FIELD(
  2519. APR_MSG_TYPE_SEQ_CMD,
  2520. APR_HDR_LEN(APR_HDR_SIZE),
  2521. APR_PKT_VER);
  2522. cvs_start_record.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2523. sizeof(cvs_start_record) - APR_HDR_SIZE);
  2524. cvs_start_record.hdr.src_port = v->session_id;
  2525. cvs_start_record.hdr.dest_port = cvs_handle;
  2526. cvs_start_record.hdr.token = 0;
  2527. cvs_start_record.hdr.opcode = VSS_ISTREAM_CMD_START_RECORD;
  2528. if (rec_mode == VOC_REC_UPLINK) {
  2529. cvs_start_record.rec_mode.rx_tap_point =
  2530. VSS_TAP_POINT_NONE;
  2531. cvs_start_record.rec_mode.tx_tap_point =
  2532. VSS_TAP_POINT_STREAM_END;
  2533. } else if (rec_mode == VOC_REC_DOWNLINK) {
  2534. cvs_start_record.rec_mode.rx_tap_point =
  2535. VSS_TAP_POINT_STREAM_END;
  2536. cvs_start_record.rec_mode.tx_tap_point =
  2537. VSS_TAP_POINT_NONE;
  2538. } else if (rec_mode == VOC_REC_BOTH) {
  2539. cvs_start_record.rec_mode.rx_tap_point =
  2540. VSS_TAP_POINT_STREAM_END;
  2541. cvs_start_record.rec_mode.tx_tap_point =
  2542. VSS_TAP_POINT_STREAM_END;
  2543. } else {
  2544. pr_err("%s: Invalid in-call rec_mode %d\n", __func__,
  2545. rec_mode);
  2546. ret = -EINVAL;
  2547. goto fail;
  2548. }
  2549. v->cvs_state = CMD_STATUS_FAIL;
  2550. ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_start_record);
  2551. if (ret < 0) {
  2552. pr_err("%s: Error %d sending START_RECORD\n", __func__,
  2553. ret);
  2554. goto fail;
  2555. }
  2556. ret = wait_event_timeout(v->cvs_wait,
  2557. (v->cvs_state == CMD_STATUS_SUCCESS),
  2558. msecs_to_jiffies(TIMEOUT_MS));
  2559. if (!ret) {
  2560. pr_err("%s: wait_event timeout\n", __func__);
  2561. goto fail;
  2562. }
  2563. v->rec_info.recording = 1;
  2564. } else {
  2565. pr_debug("%s: Start record already sent\n", __func__);
  2566. }
  2567. return 0;
  2568. fail:
  2569. return ret;
  2570. }
  2571. static int voice_cvs_stop_record(struct voice_data *v)
  2572. {
  2573. int ret = 0;
  2574. void *apr_cvs;
  2575. u16 cvs_handle;
  2576. struct apr_hdr cvs_stop_record;
  2577. if (v == NULL) {
  2578. pr_err("%s: v is NULL\n", __func__);
  2579. return -EINVAL;
  2580. }
  2581. apr_cvs = common.apr_q6_cvs;
  2582. if (!apr_cvs) {
  2583. pr_err("%s: apr_cvs is NULL.\n", __func__);
  2584. return -EINVAL;
  2585. }
  2586. cvs_handle = voice_get_cvs_handle(v);
  2587. if (v->rec_info.recording) {
  2588. cvs_stop_record.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2589. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  2590. cvs_stop_record.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2591. sizeof(cvs_stop_record) - APR_HDR_SIZE);
  2592. cvs_stop_record.src_port = v->session_id;
  2593. cvs_stop_record.dest_port = cvs_handle;
  2594. cvs_stop_record.token = 0;
  2595. cvs_stop_record.opcode = VSS_ISTREAM_CMD_STOP_RECORD;
  2596. v->cvs_state = CMD_STATUS_FAIL;
  2597. ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_stop_record);
  2598. if (ret < 0) {
  2599. pr_err("%s: Error %d sending STOP_RECORD\n",
  2600. __func__, ret);
  2601. goto fail;
  2602. }
  2603. ret = wait_event_timeout(v->cvs_wait,
  2604. (v->cvs_state == CMD_STATUS_SUCCESS),
  2605. msecs_to_jiffies(TIMEOUT_MS));
  2606. if (!ret) {
  2607. pr_err("%s: wait_event timeout\n", __func__);
  2608. goto fail;
  2609. }
  2610. v->rec_info.recording = 0;
  2611. } else {
  2612. pr_debug("%s: Stop record already sent\n", __func__);
  2613. }
  2614. return 0;
  2615. fail:
  2616. return ret;
  2617. }
  2618. int voc_start_record(uint32_t port_id, uint32_t set)
  2619. {
  2620. int ret = 0;
  2621. int rec_mode = 0;
  2622. u16 cvs_handle;
  2623. int i, rec_set = 0;
  2624. for (i = 0; i < MAX_VOC_SESSIONS; i++) {
  2625. struct voice_data *v = &common.voice[i];
  2626. pr_debug("%s: i:%d port_id: %d, set: %d\n",
  2627. __func__, i, port_id, set);
  2628. mutex_lock(&v->lock);
  2629. rec_mode = v->rec_info.rec_mode;
  2630. rec_set = set;
  2631. if (set) {
  2632. if ((v->rec_route_state.ul_flag != 0) &&
  2633. (v->rec_route_state.dl_flag != 0)) {
  2634. pr_debug("%s: i=%d, rec mode already set.\n",
  2635. __func__, i);
  2636. mutex_unlock(&v->lock);
  2637. if (i < MAX_VOC_SESSIONS)
  2638. continue;
  2639. else
  2640. return 0;
  2641. }
  2642. if (port_id == VOICE_RECORD_TX) {
  2643. if ((v->rec_route_state.ul_flag == 0)
  2644. && (v->rec_route_state.dl_flag == 0)) {
  2645. rec_mode = VOC_REC_UPLINK;
  2646. v->rec_route_state.ul_flag = 1;
  2647. } else if ((v->rec_route_state.ul_flag == 0)
  2648. && (v->rec_route_state.dl_flag != 0)) {
  2649. voice_cvs_stop_record(v);
  2650. rec_mode = VOC_REC_BOTH;
  2651. v->rec_route_state.ul_flag = 1;
  2652. }
  2653. } else if (port_id == VOICE_RECORD_RX) {
  2654. if ((v->rec_route_state.ul_flag == 0)
  2655. && (v->rec_route_state.dl_flag == 0)) {
  2656. rec_mode = VOC_REC_DOWNLINK;
  2657. v->rec_route_state.dl_flag = 1;
  2658. } else if ((v->rec_route_state.ul_flag != 0)
  2659. && (v->rec_route_state.dl_flag == 0)) {
  2660. voice_cvs_stop_record(v);
  2661. rec_mode = VOC_REC_BOTH;
  2662. v->rec_route_state.dl_flag = 1;
  2663. }
  2664. }
  2665. rec_set = 1;
  2666. } else {
  2667. if ((v->rec_route_state.ul_flag == 0) &&
  2668. (v->rec_route_state.dl_flag == 0)) {
  2669. pr_debug("%s: i=%d, rec already stops.\n",
  2670. __func__, i);
  2671. mutex_unlock(&v->lock);
  2672. if (i < MAX_VOC_SESSIONS)
  2673. continue;
  2674. else
  2675. return 0;
  2676. }
  2677. if (port_id == VOICE_RECORD_TX) {
  2678. if ((v->rec_route_state.ul_flag != 0)
  2679. && (v->rec_route_state.dl_flag == 0)) {
  2680. v->rec_route_state.ul_flag = 0;
  2681. rec_set = 0;
  2682. } else if ((v->rec_route_state.ul_flag != 0)
  2683. && (v->rec_route_state.dl_flag != 0)) {
  2684. voice_cvs_stop_record(v);
  2685. v->rec_route_state.ul_flag = 0;
  2686. rec_mode = VOC_REC_DOWNLINK;
  2687. rec_set = 1;
  2688. }
  2689. } else if (port_id == VOICE_RECORD_RX) {
  2690. if ((v->rec_route_state.ul_flag == 0)
  2691. && (v->rec_route_state.dl_flag != 0)) {
  2692. v->rec_route_state.dl_flag = 0;
  2693. rec_set = 0;
  2694. } else if ((v->rec_route_state.ul_flag != 0)
  2695. && (v->rec_route_state.dl_flag != 0)) {
  2696. voice_cvs_stop_record(v);
  2697. v->rec_route_state.dl_flag = 0;
  2698. rec_mode = VOC_REC_UPLINK;
  2699. rec_set = 1;
  2700. }
  2701. }
  2702. }
  2703. pr_debug("%s: i=%d, mode =%d, set =%d\n", __func__,
  2704. i, rec_mode, rec_set);
  2705. cvs_handle = voice_get_cvs_handle(v);
  2706. if (cvs_handle != 0) {
  2707. if (rec_set)
  2708. ret = voice_cvs_start_record(v, rec_mode);
  2709. else
  2710. ret = voice_cvs_stop_record(v);
  2711. }
  2712. /* Cache the value */
  2713. v->rec_info.rec_enable = rec_set;
  2714. v->rec_info.rec_mode = rec_mode;
  2715. mutex_unlock(&v->lock);
  2716. }
  2717. return ret;
  2718. }
  2719. static int voice_cvs_start_playback(struct voice_data *v)
  2720. {
  2721. int ret = 0;
  2722. struct apr_hdr cvs_start_playback;
  2723. void *apr_cvs;
  2724. u16 cvs_handle;
  2725. if (v == NULL) {
  2726. pr_err("%s: v is NULL\n", __func__);
  2727. return -EINVAL;
  2728. }
  2729. apr_cvs = common.apr_q6_cvs;
  2730. if (!apr_cvs) {
  2731. pr_err("%s: apr_cvs is NULL.\n", __func__);
  2732. return -EINVAL;
  2733. }
  2734. cvs_handle = voice_get_cvs_handle(v);
  2735. if (!v->music_info.playing && v->music_info.count) {
  2736. cvs_start_playback.hdr_field = APR_HDR_FIELD(
  2737. APR_MSG_TYPE_SEQ_CMD,
  2738. APR_HDR_LEN(APR_HDR_SIZE),
  2739. APR_PKT_VER);
  2740. cvs_start_playback.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2741. sizeof(cvs_start_playback) - APR_HDR_SIZE);
  2742. cvs_start_playback.src_port = v->session_id;
  2743. cvs_start_playback.dest_port = cvs_handle;
  2744. cvs_start_playback.token = 0;
  2745. cvs_start_playback.opcode = VSS_ISTREAM_CMD_START_PLAYBACK;
  2746. v->cvs_state = CMD_STATUS_FAIL;
  2747. ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_start_playback);
  2748. if (ret < 0) {
  2749. pr_err("%s: Error %d sending START_PLAYBACK\n",
  2750. __func__, ret);
  2751. goto fail;
  2752. }
  2753. ret = wait_event_timeout(v->cvs_wait,
  2754. (v->cvs_state == CMD_STATUS_SUCCESS),
  2755. msecs_to_jiffies(TIMEOUT_MS));
  2756. if (!ret) {
  2757. pr_err("%s: wait_event timeout\n", __func__);
  2758. goto fail;
  2759. }
  2760. v->music_info.playing = 1;
  2761. } else {
  2762. pr_debug("%s: Start playback already sent\n", __func__);
  2763. }
  2764. return 0;
  2765. fail:
  2766. return ret;
  2767. }
  2768. static int voice_cvs_stop_playback(struct voice_data *v)
  2769. {
  2770. int ret = 0;
  2771. struct apr_hdr cvs_stop_playback;
  2772. void *apr_cvs;
  2773. u16 cvs_handle;
  2774. if (v == NULL) {
  2775. pr_err("%s: v is NULL\n", __func__);
  2776. return -EINVAL;
  2777. }
  2778. apr_cvs = common.apr_q6_cvs;
  2779. if (!apr_cvs) {
  2780. pr_err("%s: apr_cvs is NULL.\n", __func__);
  2781. return -EINVAL;
  2782. }
  2783. cvs_handle = voice_get_cvs_handle(v);
  2784. if (v->music_info.playing && ((!v->music_info.count) ||
  2785. (v->music_info.force))) {
  2786. cvs_stop_playback.hdr_field =
  2787. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  2788. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  2789. cvs_stop_playback.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  2790. sizeof(cvs_stop_playback) - APR_HDR_SIZE);
  2791. cvs_stop_playback.src_port = v->session_id;
  2792. cvs_stop_playback.dest_port = cvs_handle;
  2793. cvs_stop_playback.token = 0;
  2794. cvs_stop_playback.opcode = VSS_ISTREAM_CMD_STOP_PLAYBACK;
  2795. v->cvs_state = CMD_STATUS_FAIL;
  2796. ret = apr_send_pkt(apr_cvs, (uint32_t *) &cvs_stop_playback);
  2797. if (ret < 0) {
  2798. pr_err("%s: Error %d sending STOP_PLAYBACK\n",
  2799. __func__, ret);
  2800. goto fail;
  2801. }
  2802. ret = wait_event_timeout(v->cvs_wait,
  2803. (v->cvs_state == CMD_STATUS_SUCCESS),
  2804. msecs_to_jiffies(TIMEOUT_MS));
  2805. if (!ret) {
  2806. pr_err("%s: wait_event timeout\n", __func__);
  2807. goto fail;
  2808. }
  2809. v->music_info.playing = 0;
  2810. v->music_info.force = 0;
  2811. } else {
  2812. pr_debug("%s: Stop playback already sent\n", __func__);
  2813. }
  2814. return 0;
  2815. fail:
  2816. return ret;
  2817. }
  2818. int voc_start_playback(uint32_t set)
  2819. {
  2820. int ret = 0;
  2821. u16 cvs_handle;
  2822. int i;
  2823. for (i = 0; i < MAX_VOC_SESSIONS; i++) {
  2824. struct voice_data *v = &common.voice[i];
  2825. mutex_lock(&v->lock);
  2826. v->music_info.play_enable = set;
  2827. if (set)
  2828. v->music_info.count++;
  2829. else
  2830. v->music_info.count--;
  2831. pr_debug("%s: music_info count =%d\n", __func__,
  2832. v->music_info.count);
  2833. cvs_handle = voice_get_cvs_handle(v);
  2834. if (cvs_handle != 0) {
  2835. if (set)
  2836. ret = voice_cvs_start_playback(v);
  2837. else
  2838. ret = voice_cvs_stop_playback(v);
  2839. }
  2840. mutex_unlock(&v->lock);
  2841. }
  2842. return ret;
  2843. }
  2844. int voc_disable_cvp(uint16_t session_id)
  2845. {
  2846. struct voice_data *v = voice_get_session(session_id);
  2847. uint32_t paddr = 0;
  2848. int ret = 0;
  2849. if (v == NULL) {
  2850. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  2851. return -EINVAL;
  2852. }
  2853. mutex_lock(&v->lock);
  2854. if (v->voc_state == VOC_RUN) {
  2855. if (v->dev_tx.port_id != RT_PROXY_PORT_001_TX &&
  2856. v->dev_rx.port_id != RT_PROXY_PORT_001_RX)
  2857. afe_sidetone(v->dev_tx.port_id, v->dev_rx.port_id,
  2858. 0, 0);
  2859. rtac_remove_voice(voice_get_cvs_handle(v));
  2860. /* send cmd to dsp to disable vocproc */
  2861. ret = voice_send_disable_vocproc_cmd(v);
  2862. if (ret < 0) {
  2863. pr_err("%s: disable vocproc failed\n", __func__);
  2864. goto fail;
  2865. }
  2866. /* deregister cvp and vol cal */
  2867. voice_send_cvp_deregister_vol_cal_table_cmd(v);
  2868. voice_send_cvp_deregister_cal_cmd(v);
  2869. voice_get_cal_paddr_size(v, &paddr, NULL);
  2870. voice_send_cvp_unmap_memory_cmd(v, paddr);
  2871. if (common.ec_ref_ext == true)
  2872. voc_set_ext_ec_ref(AFE_PORT_INVALID, false);
  2873. v->voc_state = VOC_CHANGE;
  2874. }
  2875. fail: mutex_unlock(&v->lock);
  2876. return ret;
  2877. }
  2878. int voc_enable_cvp(uint16_t session_id)
  2879. {
  2880. struct voice_data *v = voice_get_session(session_id);
  2881. struct sidetone_cal sidetone_cal_data;
  2882. uint32_t cal_paddr = 0;
  2883. uint32_t cal_size = 0;
  2884. int ret = 0;
  2885. if (v == NULL) {
  2886. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  2887. return -EINVAL;
  2888. }
  2889. mutex_lock(&v->lock);
  2890. if (v->voc_state == VOC_CHANGE) {
  2891. if (common.ec_ref_ext == true) {
  2892. ret = voice_send_set_device_cmd_v2(v);
  2893. if (ret < 0) {
  2894. pr_err("%s: set device V2 failed\n"
  2895. "rc =%x\n", __func__, ret);
  2896. goto fail;
  2897. }
  2898. } else {
  2899. ret = voice_send_set_device_cmd(v);
  2900. if (ret < 0) {
  2901. pr_err("%s: set device failed rc=%x\n",
  2902. __func__, ret);
  2903. goto fail;
  2904. }
  2905. }
  2906. /* send cvp and vol cal */
  2907. if (!voice_get_cal_paddr_size(v, &cal_paddr, &cal_size) &&
  2908. !voice_send_cvp_map_memory_cmd(v, cal_paddr, cal_size)) {
  2909. voice_send_cvp_register_cal_cmd(v);
  2910. voice_send_cvp_register_vol_cal_table_cmd(v);
  2911. }
  2912. ret = voice_send_enable_vocproc_cmd(v);
  2913. if (ret < 0) {
  2914. pr_err("%s: enable vocproc failed\n", __func__);
  2915. goto fail;
  2916. }
  2917. /* send tty mode if tty device is used */
  2918. voice_send_tty_mode_cmd(v);
  2919. /* enable widevoice if wv_enable is set */
  2920. if (v->wv_enable)
  2921. voice_send_set_widevoice_enable_cmd(v);
  2922. /* enable slowtalk */
  2923. if (v->st_enable)
  2924. voice_send_set_pp_enable_cmd(v,
  2925. MODULE_ID_VOICE_MODULE_ST,
  2926. v->st_enable);
  2927. /* enable FENS */
  2928. if (v->fens_enable)
  2929. voice_send_set_pp_enable_cmd(v,
  2930. MODULE_ID_VOICE_MODULE_FENS,
  2931. v->fens_enable);
  2932. get_sidetone_cal(&sidetone_cal_data);
  2933. if (v->dev_tx.port_id != RT_PROXY_PORT_001_TX &&
  2934. v->dev_rx.port_id != RT_PROXY_PORT_001_RX) {
  2935. ret = afe_sidetone(v->dev_tx.port_id,
  2936. v->dev_rx.port_id,
  2937. sidetone_cal_data.enable,
  2938. sidetone_cal_data.gain);
  2939. if (ret < 0)
  2940. pr_err("%s: AFE command sidetone failed\n",
  2941. __func__);
  2942. }
  2943. rtac_add_voice(voice_get_cvs_handle(v),
  2944. voice_get_cvp_handle(v),
  2945. v->dev_rx.port_id, v->dev_tx.port_id,
  2946. v->session_id);
  2947. v->voc_state = VOC_RUN;
  2948. }
  2949. fail:
  2950. mutex_unlock(&v->lock);
  2951. return ret;
  2952. }
  2953. int voc_disable_topology(uint16_t session_id, uint32_t disable)
  2954. {
  2955. struct voice_data *v = voice_get_session(session_id);
  2956. int ret = 0;
  2957. if (v == NULL) {
  2958. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  2959. return -EINVAL;
  2960. }
  2961. mutex_lock(&v->lock);
  2962. v->disable_topology = disable;
  2963. mutex_unlock(&v->lock);
  2964. return ret;
  2965. }
  2966. int voc_set_tx_mute(uint16_t session_id, uint32_t dir, uint32_t mute)
  2967. {
  2968. struct voice_data *v = voice_get_session(session_id);
  2969. int ret = 0;
  2970. if (v == NULL) {
  2971. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  2972. return -EINVAL;
  2973. }
  2974. mutex_lock(&v->lock);
  2975. v->dev_tx.mute = mute;
  2976. if ((v->voc_state == VOC_RUN) ||
  2977. (v->voc_state == VOC_CHANGE) ||
  2978. (v->voc_state == VOC_STANDBY))
  2979. ret = voice_send_mute_cmd(v);
  2980. mutex_unlock(&v->lock);
  2981. return ret;
  2982. }
  2983. int voc_set_rx_device_mute(uint16_t session_id, uint32_t mute)
  2984. {
  2985. struct voice_data *v = voice_get_session(session_id);
  2986. int ret = 0;
  2987. if (v == NULL) {
  2988. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  2989. return -EINVAL;
  2990. }
  2991. mutex_lock(&v->lock);
  2992. v->dev_rx.mute = mute;
  2993. if (v->voc_state == VOC_RUN)
  2994. ret = voice_send_rx_device_mute_cmd(v);
  2995. mutex_unlock(&v->lock);
  2996. return ret;
  2997. }
  2998. int voc_get_rx_device_mute(uint16_t session_id)
  2999. {
  3000. struct voice_data *v = voice_get_session(session_id);
  3001. int ret = 0;
  3002. if (v == NULL) {
  3003. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  3004. return -EINVAL;
  3005. }
  3006. mutex_lock(&v->lock);
  3007. ret = v->dev_rx.mute;
  3008. mutex_unlock(&v->lock);
  3009. return ret;
  3010. }
  3011. int voc_set_tty_mode(uint16_t session_id, uint8_t tty_mode)
  3012. {
  3013. struct voice_data *v = voice_get_session(session_id);
  3014. int ret = 0;
  3015. if (v == NULL) {
  3016. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  3017. return -EINVAL;
  3018. }
  3019. mutex_lock(&v->lock);
  3020. v->tty_mode = tty_mode;
  3021. mutex_unlock(&v->lock);
  3022. return ret;
  3023. }
  3024. uint8_t voc_get_tty_mode(uint16_t session_id)
  3025. {
  3026. struct voice_data *v = voice_get_session(session_id);
  3027. int ret = 0;
  3028. if (v == NULL) {
  3029. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  3030. return -EINVAL;
  3031. }
  3032. mutex_lock(&v->lock);
  3033. ret = v->tty_mode;
  3034. mutex_unlock(&v->lock);
  3035. return ret;
  3036. }
  3037. int voc_set_widevoice_enable(uint16_t session_id, uint32_t wv_enable)
  3038. {
  3039. struct voice_data *v = voice_get_session(session_id);
  3040. u16 mvm_handle;
  3041. int ret = 0;
  3042. if (v == NULL) {
  3043. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  3044. return -EINVAL;
  3045. }
  3046. mutex_lock(&v->lock);
  3047. v->wv_enable = wv_enable;
  3048. mvm_handle = voice_get_mvm_handle(v);
  3049. if (mvm_handle != 0)
  3050. voice_send_set_widevoice_enable_cmd(v);
  3051. mutex_unlock(&v->lock);
  3052. return ret;
  3053. }
  3054. uint32_t voc_get_widevoice_enable(uint16_t session_id)
  3055. {
  3056. struct voice_data *v = voice_get_session(session_id);
  3057. int ret = 0;
  3058. if (v == NULL) {
  3059. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  3060. return -EINVAL;
  3061. }
  3062. mutex_lock(&v->lock);
  3063. ret = v->wv_enable;
  3064. mutex_unlock(&v->lock);
  3065. return ret;
  3066. }
  3067. int voc_set_pp_enable(uint16_t session_id, uint32_t module_id, uint32_t enable)
  3068. {
  3069. struct voice_data *v = voice_get_session(session_id);
  3070. int ret = 0;
  3071. if (v == NULL) {
  3072. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  3073. return -EINVAL;
  3074. }
  3075. mutex_lock(&v->lock);
  3076. if (module_id == MODULE_ID_VOICE_MODULE_ST)
  3077. v->st_enable = enable;
  3078. else if (module_id == MODULE_ID_VOICE_MODULE_FENS)
  3079. v->fens_enable = enable;
  3080. if (v->voc_state == VOC_RUN) {
  3081. if (module_id == MODULE_ID_VOICE_MODULE_ST)
  3082. ret = voice_send_set_pp_enable_cmd(v,
  3083. MODULE_ID_VOICE_MODULE_ST,
  3084. enable);
  3085. else if (module_id == MODULE_ID_VOICE_MODULE_FENS)
  3086. ret = voice_send_set_pp_enable_cmd(v,
  3087. MODULE_ID_VOICE_MODULE_FENS,
  3088. enable);
  3089. }
  3090. mutex_unlock(&v->lock);
  3091. return ret;
  3092. }
  3093. int voc_get_pp_enable(uint16_t session_id, uint32_t module_id)
  3094. {
  3095. struct voice_data *v = voice_get_session(session_id);
  3096. int ret = 0;
  3097. if (v == NULL) {
  3098. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  3099. return -EINVAL;
  3100. }
  3101. mutex_lock(&v->lock);
  3102. if (module_id == MODULE_ID_VOICE_MODULE_ST)
  3103. ret = v->st_enable;
  3104. else if (module_id == MODULE_ID_VOICE_MODULE_FENS)
  3105. ret = v->fens_enable;
  3106. mutex_unlock(&v->lock);
  3107. return ret;
  3108. }
  3109. int voc_set_rx_vol_index(uint16_t session_id, uint32_t dir, uint32_t vol_idx)
  3110. {
  3111. struct voice_data *v = voice_get_session(session_id);
  3112. int ret = 0;
  3113. if (v == NULL) {
  3114. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  3115. return -EINVAL;
  3116. }
  3117. mutex_lock(&v->lock);
  3118. v->dev_rx.volume = vol_idx;
  3119. if ((v->voc_state == VOC_RUN) ||
  3120. (v->voc_state == VOC_CHANGE) ||
  3121. (v->voc_state == VOC_STANDBY))
  3122. ret = voice_send_vol_index_cmd(v);
  3123. mutex_unlock(&v->lock);
  3124. return ret;
  3125. }
  3126. int voc_set_rxtx_port(uint16_t session_id, uint32_t port_id, uint32_t dev_type)
  3127. {
  3128. struct voice_data *v = voice_get_session(session_id);
  3129. if (v == NULL) {
  3130. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  3131. return -EINVAL;
  3132. }
  3133. pr_debug("%s: port_id=%d, type=%d\n", __func__, port_id, dev_type);
  3134. mutex_lock(&v->lock);
  3135. if (dev_type == DEV_RX)
  3136. v->dev_rx.port_id = port_id;
  3137. else
  3138. v->dev_tx.port_id = port_id;
  3139. mutex_unlock(&v->lock);
  3140. return 0;
  3141. }
  3142. int voc_set_route_flag(uint16_t session_id, uint8_t path_dir, uint8_t set)
  3143. {
  3144. struct voice_data *v = voice_get_session(session_id);
  3145. if (v == NULL) {
  3146. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  3147. return -EINVAL;
  3148. }
  3149. pr_debug("%s: path_dir=%d, set=%d\n", __func__, path_dir, set);
  3150. mutex_lock(&v->lock);
  3151. if (path_dir == RX_PATH)
  3152. v->voc_route_state.rx_route_flag = set;
  3153. else
  3154. v->voc_route_state.tx_route_flag = set;
  3155. mutex_unlock(&v->lock);
  3156. return 0;
  3157. }
  3158. uint8_t voc_get_route_flag(uint16_t session_id, uint8_t path_dir)
  3159. {
  3160. struct voice_data *v = voice_get_session(session_id);
  3161. int ret = 0;
  3162. if (v == NULL) {
  3163. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  3164. return 0;
  3165. }
  3166. mutex_lock(&v->lock);
  3167. if (path_dir == RX_PATH)
  3168. ret = v->voc_route_state.rx_route_flag;
  3169. else
  3170. ret = v->voc_route_state.tx_route_flag;
  3171. mutex_unlock(&v->lock);
  3172. return ret;
  3173. }
  3174. int voc_end_voice_call(uint16_t session_id)
  3175. {
  3176. struct voice_data *v = voice_get_session(session_id);
  3177. int ret = 0;
  3178. if (v == NULL) {
  3179. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  3180. return -EINVAL;
  3181. }
  3182. mutex_lock(&v->lock);
  3183. if (v->voc_state == VOC_RUN || v->voc_state == VOC_STANDBY) {
  3184. if (v->dev_tx.port_id != RT_PROXY_PORT_001_TX &&
  3185. v->dev_rx.port_id != RT_PROXY_PORT_001_RX)
  3186. afe_sidetone(v->dev_tx.port_id, v->dev_rx.port_id,
  3187. 0, 0);
  3188. ret = voice_destroy_vocproc(v);
  3189. if (ret < 0)
  3190. pr_err("%s: destroy voice failed\n", __func__);
  3191. voice_destroy_mvm_cvs_session(v);
  3192. if (common.ec_ref_ext == true)
  3193. voc_set_ext_ec_ref(AFE_PORT_INVALID, false);
  3194. v->voc_state = VOC_RELEASE;
  3195. }
  3196. mutex_unlock(&v->lock);
  3197. return ret;
  3198. }
  3199. int voc_resume_voice_call(uint16_t session_id)
  3200. {
  3201. struct voice_data *v = voice_get_session(session_id);
  3202. struct apr_hdr mvm_start_voice_cmd;
  3203. int ret = 0;
  3204. void *apr_mvm;
  3205. u16 mvm_handle;
  3206. pr_debug("%s:\n", __func__);
  3207. if (v == NULL) {
  3208. pr_err("%s: v is NULL\n", __func__);
  3209. return -EINVAL;
  3210. }
  3211. apr_mvm = common.apr_q6_mvm;
  3212. if (!apr_mvm) {
  3213. pr_err("%s: apr_mvm is NULL.\n", __func__);
  3214. return -EINVAL;
  3215. }
  3216. mvm_handle = voice_get_mvm_handle(v);
  3217. mvm_start_voice_cmd.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  3218. APR_HDR_LEN(APR_HDR_SIZE),
  3219. APR_PKT_VER);
  3220. mvm_start_voice_cmd.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  3221. sizeof(mvm_start_voice_cmd) - APR_HDR_SIZE);
  3222. pr_debug("send mvm_start_voice_cmd pkt size = %d\n",
  3223. mvm_start_voice_cmd.pkt_size);
  3224. mvm_start_voice_cmd.src_port = v->session_id;
  3225. mvm_start_voice_cmd.dest_port = mvm_handle;
  3226. mvm_start_voice_cmd.token = 0;
  3227. mvm_start_voice_cmd.opcode = VSS_IMVM_CMD_START_VOICE;
  3228. v->mvm_state = CMD_STATUS_FAIL;
  3229. ret = apr_send_pkt(apr_mvm, (uint32_t *) &mvm_start_voice_cmd);
  3230. if (ret < 0) {
  3231. pr_err("Fail in sending VSS_IMVM_CMD_START_VOICE\n");
  3232. goto fail;
  3233. }
  3234. v->voc_state = VOC_RUN;
  3235. return 0;
  3236. fail:
  3237. return -EINVAL;
  3238. }
  3239. int voc_start_voice_call(uint16_t session_id)
  3240. {
  3241. struct voice_data *v = voice_get_session(session_id);
  3242. struct sidetone_cal sidetone_cal_data;
  3243. int ret = 0;
  3244. if (v == NULL) {
  3245. pr_err("%s: invalid session_id 0x%x\n", __func__, session_id);
  3246. return -EINVAL;
  3247. }
  3248. mutex_lock(&v->lock);
  3249. if ((v->voc_state == VOC_INIT) ||
  3250. (v->voc_state == VOC_RELEASE)) {
  3251. ret = voice_apr_register();
  3252. if (ret < 0) {
  3253. pr_err("%s: apr register failed\n", __func__);
  3254. goto fail;
  3255. }
  3256. ret = voice_create_mvm_cvs_session(v);
  3257. if (ret < 0) {
  3258. pr_err("create mvm and cvs failed\n");
  3259. goto fail;
  3260. }
  3261. ret = voice_send_dual_control_cmd(v);
  3262. if (ret < 0) {
  3263. pr_err("Err Dual command failed\n");
  3264. goto fail;
  3265. }
  3266. ret = voice_setup_vocproc(v);
  3267. if (ret < 0) {
  3268. pr_err("setup voice failed\n");
  3269. goto fail;
  3270. }
  3271. ret = voice_send_vol_index_cmd(v);
  3272. if (ret < 0)
  3273. pr_err("voice volume failed\n");
  3274. ret = voice_send_mute_cmd(v);
  3275. if (ret < 0)
  3276. pr_err("voice mute failed\n");
  3277. ret = voice_send_start_voice_cmd(v);
  3278. if (ret < 0) {
  3279. pr_err("start voice failed\n");
  3280. goto fail;
  3281. }
  3282. get_sidetone_cal(&sidetone_cal_data);
  3283. if (v->dev_tx.port_id != RT_PROXY_PORT_001_TX &&
  3284. v->dev_rx.port_id != RT_PROXY_PORT_001_RX) {
  3285. ret = afe_sidetone(v->dev_tx.port_id,
  3286. v->dev_rx.port_id,
  3287. sidetone_cal_data.enable,
  3288. sidetone_cal_data.gain);
  3289. if (ret < 0)
  3290. pr_err("AFE command sidetone failed\n");
  3291. }
  3292. v->voc_state = VOC_RUN;
  3293. } else if (v->voc_state == VOC_STANDBY) {
  3294. pr_err("Error: PCM Prepare when in Standby\n");
  3295. ret = -EINVAL;
  3296. goto fail;
  3297. }
  3298. fail: mutex_unlock(&v->lock);
  3299. return ret;
  3300. }
  3301. int voc_standby_voice_call(uint16_t session_id)
  3302. {
  3303. struct voice_data *v = voice_get_session(session_id);
  3304. struct apr_hdr mvm_standby_voice_cmd;
  3305. void *apr_mvm;
  3306. u16 mvm_handle;
  3307. int ret = 0;
  3308. pr_debug("%s: voc state=%d", __func__, v->voc_state);
  3309. if (v == NULL) {
  3310. pr_err("%s: v is NULL\n", __func__);
  3311. return -EINVAL;
  3312. }
  3313. if (v->voc_state == VOC_RUN) {
  3314. apr_mvm = common.apr_q6_mvm;
  3315. if (!apr_mvm) {
  3316. pr_err("%s: apr_mvm is NULL.\n", __func__);
  3317. ret = -EINVAL;
  3318. goto fail;
  3319. }
  3320. mvm_handle = voice_get_mvm_handle(v);
  3321. mvm_standby_voice_cmd.hdr_field =
  3322. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  3323. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  3324. mvm_standby_voice_cmd.pkt_size =
  3325. APR_PKT_SIZE(APR_HDR_SIZE,
  3326. sizeof(mvm_standby_voice_cmd) - APR_HDR_SIZE);
  3327. pr_debug("send mvm_standby_voice_cmd pkt size = %d\n",
  3328. mvm_standby_voice_cmd.pkt_size);
  3329. mvm_standby_voice_cmd.src_port = v->session_id;
  3330. mvm_standby_voice_cmd.dest_port = mvm_handle;
  3331. mvm_standby_voice_cmd.token = 0;
  3332. mvm_standby_voice_cmd.opcode = VSS_IMVM_CMD_STANDBY_VOICE;
  3333. v->mvm_state = CMD_STATUS_FAIL;
  3334. ret = apr_send_pkt(apr_mvm,
  3335. (uint32_t *)&mvm_standby_voice_cmd);
  3336. if (ret < 0) {
  3337. pr_err("Fail in sending VSS_IMVM_CMD_STANDBY_VOICE\n");
  3338. ret = -EINVAL;
  3339. goto fail;
  3340. }
  3341. v->voc_state = VOC_STANDBY;
  3342. }
  3343. fail:
  3344. return ret;
  3345. }
  3346. int voc_set_ext_ec_ref(uint16_t port_id, bool state)
  3347. {
  3348. int ret = 0;
  3349. mutex_lock(&common.common_lock);
  3350. if (state == true) {
  3351. if (port_id == AFE_PORT_INVALID) {
  3352. pr_err("%s: Invalid port id", __func__);
  3353. ret = -EINVAL;
  3354. goto fail;
  3355. }
  3356. common.ec_port_id = port_id;
  3357. common.ec_ref_ext = true;
  3358. } else {
  3359. common.ec_ref_ext = false;
  3360. common.ec_port_id = port_id;
  3361. }
  3362. fail:
  3363. mutex_unlock(&common.common_lock);
  3364. return ret;
  3365. }
  3366. void voc_register_mvs_cb(ul_cb_fn ul_cb,
  3367. dl_cb_fn dl_cb,
  3368. void *private_data)
  3369. {
  3370. common.mvs_info.ul_cb = ul_cb;
  3371. common.mvs_info.dl_cb = dl_cb;
  3372. common.mvs_info.private_data = private_data;
  3373. }
  3374. void voc_register_dtmf_rx_detection_cb(dtmf_rx_det_cb_fn dtmf_rx_ul_cb,
  3375. void *private_data)
  3376. {
  3377. common.dtmf_info.dtmf_rx_ul_cb = dtmf_rx_ul_cb;
  3378. common.dtmf_info.private_data = private_data;
  3379. }
  3380. void voc_register_hpcm_evt_cb(hostpcm_cb_fn hostpcm_cb,
  3381. void *private_data)
  3382. {
  3383. common.hostpcm_info.hostpcm_evt_cb = hostpcm_cb;
  3384. common.hostpcm_info.private_data = private_data;
  3385. }
  3386. void voc_config_vocoder(uint32_t media_type,
  3387. uint32_t rate,
  3388. uint32_t network_type,
  3389. uint32_t dtx_mode)
  3390. {
  3391. common.mvs_info.media_type = media_type;
  3392. common.mvs_info.rate = rate;
  3393. common.mvs_info.network_type = network_type;
  3394. common.mvs_info.dtx_mode = dtx_mode;
  3395. }
  3396. static int32_t qdsp_mvm_callback(struct apr_client_data *data, void *priv)
  3397. {
  3398. uint32_t *ptr = NULL;
  3399. struct common_data *c = NULL;
  3400. struct voice_data *v = NULL;
  3401. int i = 0;
  3402. if ((data == NULL) || (priv == NULL)) {
  3403. pr_err("%s: data or priv is NULL\n", __func__);
  3404. return -EINVAL;
  3405. }
  3406. c = priv;
  3407. pr_debug("%s: session_id 0x%x\n", __func__, data->dest_port);
  3408. v = voice_get_session(data->dest_port);
  3409. if (v == NULL) {
  3410. pr_err("%s: v is NULL\n", __func__);
  3411. return -EINVAL;
  3412. }
  3413. pr_debug("%s: Payload Length = %d, opcode=%x\n", __func__,
  3414. data->payload_size, data->opcode);
  3415. if (data->opcode == RESET_EVENTS) {
  3416. pr_debug("%s: Reset event received in Voice service\n",
  3417. __func__);
  3418. apr_reset(c->apr_q6_mvm);
  3419. c->apr_q6_mvm = NULL;
  3420. /* Sub-system restart is applicable to all sessions. */
  3421. for (i = 0; i < MAX_VOC_SESSIONS; i++)
  3422. c->voice[i].mvm_handle = 0;
  3423. return 0;
  3424. }
  3425. if (data->opcode == APR_BASIC_RSP_RESULT) {
  3426. if (data->payload_size) {
  3427. ptr = data->payload;
  3428. pr_info("%x %x\n", ptr[0], ptr[1]);
  3429. /* ping mvm service ACK */
  3430. switch (ptr[0]) {
  3431. case VSS_IMVM_CMD_CREATE_PASSIVE_CONTROL_SESSION:
  3432. case VSS_IMVM_CMD_CREATE_FULL_CONTROL_SESSION:
  3433. /* Passive session is used for CS call
  3434. * Full session is used for VoIP call. */
  3435. pr_debug("%s: cmd = 0x%x\n", __func__, ptr[0]);
  3436. if (!ptr[1]) {
  3437. pr_debug("%s: MVM handle is %d\n",
  3438. __func__, data->src_port);
  3439. voice_set_mvm_handle(v, data->src_port);
  3440. } else
  3441. pr_err("got NACK for sending \
  3442. MVM create session \n");
  3443. v->mvm_state = CMD_STATUS_SUCCESS;
  3444. wake_up(&v->mvm_wait);
  3445. break;
  3446. case VSS_IMVM_CMD_START_VOICE:
  3447. case VSS_IMVM_CMD_ATTACH_VOCPROC:
  3448. case VSS_IMVM_CMD_STOP_VOICE:
  3449. case VSS_IMVM_CMD_DETACH_VOCPROC:
  3450. case VSS_ISTREAM_CMD_SET_TTY_MODE:
  3451. case APRV2_IBASIC_CMD_DESTROY_SESSION:
  3452. case VSS_IMVM_CMD_ATTACH_STREAM:
  3453. case VSS_IMVM_CMD_DETACH_STREAM:
  3454. case VSS_ICOMMON_CMD_SET_NETWORK:
  3455. case VSS_ICOMMON_CMD_SET_VOICE_TIMING:
  3456. case VSS_IWIDEVOICE_CMD_SET_WIDEVOICE:
  3457. case VSS_IMVM_CMD_SET_POLICY_DUAL_CONTROL:
  3458. case VSS_IMVM_CMD_STANDBY_VOICE:
  3459. pr_debug("%s: cmd = 0x%x\n", __func__, ptr[0]);
  3460. v->mvm_state = CMD_STATUS_SUCCESS;
  3461. wake_up(&v->mvm_wait);
  3462. break;
  3463. default:
  3464. pr_debug("%s: not match cmd = 0x%x\n",
  3465. __func__, ptr[0]);
  3466. break;
  3467. }
  3468. }
  3469. }
  3470. return 0;
  3471. }
  3472. static int32_t qdsp_cvs_callback(struct apr_client_data *data, void *priv)
  3473. {
  3474. uint32_t *ptr = NULL;
  3475. struct common_data *c = NULL;
  3476. struct voice_data *v = NULL;
  3477. int i = 0;
  3478. if ((data == NULL) || (priv == NULL)) {
  3479. pr_err("%s: data or priv is NULL\n", __func__);
  3480. return -EINVAL;
  3481. }
  3482. c = priv;
  3483. pr_debug("%s: session_id 0x%x\n", __func__, data->dest_port);
  3484. v = voice_get_session(data->dest_port);
  3485. if (v == NULL) {
  3486. pr_err("%s: v is NULL\n", __func__);
  3487. return -EINVAL;
  3488. }
  3489. pr_debug("%s: Payload Length = %d, opcode=%x\n", __func__,
  3490. data->payload_size, data->opcode);
  3491. if (data->opcode == RESET_EVENTS) {
  3492. pr_debug("%s: Reset event received in Voice service\n",
  3493. __func__);
  3494. apr_reset(c->apr_q6_cvs);
  3495. c->apr_q6_cvs = NULL;
  3496. /* Sub-system restart is applicable to all sessions. */
  3497. for (i = 0; i < MAX_VOC_SESSIONS; i++)
  3498. c->voice[i].cvs_handle = 0;
  3499. return 0;
  3500. }
  3501. if (data->opcode == APR_BASIC_RSP_RESULT) {
  3502. if (data->payload_size) {
  3503. ptr = data->payload;
  3504. pr_info("%x %x\n", ptr[0], ptr[1]);
  3505. /*response from CVS */
  3506. switch (ptr[0]) {
  3507. case VSS_ISTREAM_CMD_CREATE_PASSIVE_CONTROL_SESSION:
  3508. case VSS_ISTREAM_CMD_CREATE_FULL_CONTROL_SESSION:
  3509. if (!ptr[1]) {
  3510. pr_debug("%s: CVS handle is %d\n",
  3511. __func__, data->src_port);
  3512. voice_set_cvs_handle(v, data->src_port);
  3513. } else
  3514. pr_err("got NACK for sending \
  3515. CVS create session \n");
  3516. v->cvs_state = CMD_STATUS_SUCCESS;
  3517. wake_up(&v->cvs_wait);
  3518. break;
  3519. case VSS_ISTREAM_CMD_SET_MUTE:
  3520. case VSS_ISTREAM_CMD_SET_MEDIA_TYPE:
  3521. case VSS_ISTREAM_CMD_VOC_AMR_SET_ENC_RATE:
  3522. case VSS_ISTREAM_CMD_VOC_AMRWB_SET_ENC_RATE:
  3523. case VSS_ISTREAM_CMD_SET_ENC_DTX_MODE:
  3524. case VSS_ISTREAM_CMD_CDMA_SET_ENC_MINMAX_RATE:
  3525. case APRV2_IBASIC_CMD_DESTROY_SESSION:
  3526. case VSS_ISTREAM_CMD_REGISTER_CALIBRATION_DATA:
  3527. case VSS_ISTREAM_CMD_DEREGISTER_CALIBRATION_DATA:
  3528. case VSS_ICOMMON_CMD_MAP_MEMORY:
  3529. case VSS_ICOMMON_CMD_UNMAP_MEMORY:
  3530. case VSS_ICOMMON_CMD_SET_UI_PROPERTY:
  3531. case VSS_ISTREAM_CMD_START_PLAYBACK:
  3532. case VSS_ISTREAM_CMD_STOP_PLAYBACK:
  3533. case VSS_ISTREAM_CMD_START_RECORD:
  3534. case VSS_ISTREAM_CMD_STOP_RECORD:
  3535. case VSS_ISTREAM_CMD_SET_RX_DTMF_DETECTION:
  3536. pr_debug("%s: cmd = 0x%x\n", __func__, ptr[0]);
  3537. v->cvs_state = CMD_STATUS_SUCCESS;
  3538. wake_up(&v->cvs_wait);
  3539. break;
  3540. case VOICE_CMD_SET_PARAM:
  3541. rtac_make_voice_callback(RTAC_CVS, ptr,
  3542. data->payload_size);
  3543. break;
  3544. default:
  3545. pr_debug("%s: cmd = 0x%x\n", __func__, ptr[0]);
  3546. break;
  3547. }
  3548. }
  3549. } else if (data->opcode == VSS_ISTREAM_EVT_SEND_ENC_BUFFER) {
  3550. uint32_t *voc_pkt = data->payload;
  3551. uint32_t pkt_len = data->payload_size;
  3552. if (voc_pkt != NULL && c->mvs_info.ul_cb != NULL) {
  3553. pr_debug("%s: Media type is 0x%x\n",
  3554. __func__, voc_pkt[0]);
  3555. /* Remove media ID from payload. */
  3556. voc_pkt++;
  3557. pkt_len = pkt_len - 4;
  3558. c->mvs_info.ul_cb((uint8_t *)voc_pkt,
  3559. pkt_len,
  3560. c->mvs_info.private_data);
  3561. } else
  3562. pr_err("%s: voc_pkt is 0x%x ul_cb is 0x%x\n",
  3563. __func__, (unsigned int)voc_pkt,
  3564. (unsigned int) c->mvs_info.ul_cb);
  3565. } else if (data->opcode == VSS_ISTREAM_EVT_REQUEST_DEC_BUFFER) {
  3566. struct cvs_send_dec_buf_cmd send_dec_buf;
  3567. int ret = 0;
  3568. uint32_t pkt_len = 0;
  3569. if (c->mvs_info.dl_cb != NULL) {
  3570. send_dec_buf.dec_buf.media_id = c->mvs_info.media_type;
  3571. c->mvs_info.dl_cb(
  3572. (uint8_t *)&send_dec_buf.dec_buf.packet_data,
  3573. &pkt_len,
  3574. c->mvs_info.private_data);
  3575. send_dec_buf.hdr.hdr_field =
  3576. APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  3577. APR_HDR_LEN(APR_HDR_SIZE),
  3578. APR_PKT_VER);
  3579. send_dec_buf.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  3580. sizeof(send_dec_buf.dec_buf.media_id) + pkt_len);
  3581. send_dec_buf.hdr.src_port = v->session_id;
  3582. send_dec_buf.hdr.dest_port = voice_get_cvs_handle(v);
  3583. send_dec_buf.hdr.token = 0;
  3584. send_dec_buf.hdr.opcode =
  3585. VSS_ISTREAM_EVT_SEND_DEC_BUFFER;
  3586. ret = apr_send_pkt(c->apr_q6_cvs,
  3587. (uint32_t *) &send_dec_buf);
  3588. if (ret < 0) {
  3589. pr_err("%s: Error %d sending DEC_BUF\n",
  3590. __func__, ret);
  3591. goto fail;
  3592. }
  3593. } else
  3594. pr_debug("%s: dl_cb is NULL\n", __func__);
  3595. } else if (data->opcode == VSS_ISTREAM_EVT_SEND_DEC_BUFFER) {
  3596. pr_debug("Send dec buf resp\n");
  3597. } else if (data->opcode == VOICE_EVT_GET_PARAM_ACK) {
  3598. rtac_make_voice_callback(RTAC_CVS, data->payload,
  3599. data->payload_size);
  3600. } else if (data->opcode == VSS_ISTREAM_EVT_RX_DTMF_DETECTED) {
  3601. struct vss_istream_evt_rx_dtmf_detected *dtmf_rx_detected;
  3602. uint32_t *voc_pkt = data->payload;
  3603. uint32_t pkt_len = data->payload_size;
  3604. if ((voc_pkt != NULL) &&
  3605. (pkt_len ==
  3606. sizeof(struct vss_istream_evt_rx_dtmf_detected))) {
  3607. dtmf_rx_detected =
  3608. (struct vss_istream_evt_rx_dtmf_detected *) voc_pkt;
  3609. pr_debug("RX_DTMF_DETECTED low_freq=%d high_freq=%d\n",
  3610. dtmf_rx_detected->low_freq,
  3611. dtmf_rx_detected->high_freq);
  3612. if (c->dtmf_info.dtmf_rx_ul_cb)
  3613. c->dtmf_info.dtmf_rx_ul_cb((uint8_t *)voc_pkt,
  3614. voc_get_session_name(v->session_id),
  3615. c->dtmf_info.private_data);
  3616. } else {
  3617. pr_err("Invalid packet\n");
  3618. }
  3619. } else {
  3620. pr_debug("Unknown opcode 0x%x\n", data->opcode);
  3621. }
  3622. fail:
  3623. return 0;
  3624. }
  3625. static int32_t qdsp_cvp_callback(struct apr_client_data *data, void *priv)
  3626. {
  3627. uint32_t *ptr = NULL;
  3628. struct common_data *c = NULL;
  3629. struct voice_data *v = NULL;
  3630. int i = 0;
  3631. if ((data == NULL) || (priv == NULL)) {
  3632. pr_err("%s: data or priv is NULL\n", __func__);
  3633. return -EINVAL;
  3634. }
  3635. c = priv;
  3636. v = voice_get_session(data->dest_port);
  3637. if (v == NULL) {
  3638. pr_err("%s: v is NULL\n", __func__);
  3639. return -EINVAL;
  3640. }
  3641. pr_debug("%s: Payload Length = %d, opcode=%x\n", __func__,
  3642. data->payload_size, data->opcode);
  3643. if (data->opcode == RESET_EVENTS) {
  3644. pr_debug("%s: Reset event received in Voice service\n",
  3645. __func__);
  3646. apr_reset(c->apr_q6_cvp);
  3647. c->apr_q6_cvp = NULL;
  3648. /* Sub-system restart is applicable to all sessions. */
  3649. for (i = 0; i < MAX_VOC_SESSIONS; i++)
  3650. c->voice[i].cvp_handle = 0;
  3651. return 0;
  3652. }
  3653. if (data->opcode == APR_BASIC_RSP_RESULT) {
  3654. if (data->payload_size) {
  3655. ptr = data->payload;
  3656. pr_info("%x %x\n", ptr[0], ptr[1]);
  3657. switch (ptr[0]) {
  3658. case VSS_IVOCPROC_CMD_CREATE_FULL_CONTROL_SESSION:
  3659. /*response from CVP */
  3660. pr_debug("%s: cmd = 0x%x\n", __func__, ptr[0]);
  3661. if (!ptr[1]) {
  3662. voice_set_cvp_handle(v, data->src_port);
  3663. pr_debug("cvphdl=%d\n", data->src_port);
  3664. } else
  3665. pr_err("got NACK from CVP create \
  3666. session response\n");
  3667. v->cvp_state = CMD_STATUS_SUCCESS;
  3668. wake_up(&v->cvp_wait);
  3669. break;
  3670. case VSS_IVOCPROC_CMD_SET_DEVICE_V2:
  3671. case VSS_IVOCPROC_CMD_SET_DEVICE:
  3672. case VSS_IVOCPROC_CMD_SET_RX_VOLUME_INDEX:
  3673. case VSS_IVOCPROC_CMD_ENABLE:
  3674. case VSS_IVOCPROC_CMD_DISABLE:
  3675. case APRV2_IBASIC_CMD_DESTROY_SESSION:
  3676. case VSS_IVOCPROC_CMD_REGISTER_VOLUME_CAL_TABLE:
  3677. case VSS_IVOCPROC_CMD_DEREGISTER_VOLUME_CAL_TABLE:
  3678. case VSS_IVOCPROC_CMD_REGISTER_CALIBRATION_DATA:
  3679. case VSS_IVOCPROC_CMD_DEREGISTER_CALIBRATION_DATA:
  3680. case VSS_ICOMMON_CMD_MAP_MEMORY:
  3681. case VSS_ICOMMON_CMD_UNMAP_MEMORY:
  3682. case VSS_IVOCPROC_CMD_SET_MUTE:
  3683. case VSS_IVPCM_CMD_START:
  3684. case VSS_IVPCM_CMD_STOP:
  3685. v->cvp_state = CMD_STATUS_SUCCESS;
  3686. wake_up(&v->cvp_wait);
  3687. break;
  3688. case VSS_IVPCM_EVT_PUSH_BUFFER:
  3689. break;
  3690. case VOICE_CMD_SET_PARAM:
  3691. rtac_make_voice_callback(RTAC_CVP, ptr,
  3692. data->payload_size);
  3693. break;
  3694. default:
  3695. pr_debug("%s: not match cmd = 0x%x\n",
  3696. __func__, ptr[0]);
  3697. break;
  3698. }
  3699. }
  3700. } else if (data->opcode == VOICE_EVT_GET_PARAM_ACK) {
  3701. rtac_make_voice_callback(RTAC_CVP, data->payload,
  3702. data->payload_size);
  3703. } else if (data->opcode == VSS_IVPCM_EVT_NOTIFY) {
  3704. struct vss_ivpcm_evt_notify *notify_evt;
  3705. if ((data->payload != NULL) &&
  3706. data->payload_size == sizeof(struct vss_ivpcm_evt_notify)) {
  3707. notify_evt =
  3708. (struct vss_ivpcm_evt_notify *)data->payload;
  3709. c->hostpcm_info.hostpcm_evt_cb(data->payload,
  3710. voc_get_session_name(v->session_id),
  3711. c->hostpcm_info.private_data);
  3712. }
  3713. }
  3714. return 0;
  3715. }
  3716. int voc_send_cvp_vocpcm_push_buf_evt(u16 session_id,
  3717. struct vss_ivpcm_evt_push_buffer *push_buff_evt)
  3718. {
  3719. struct cvp_push_buf_cmd vpcm_push_buf_cmd;
  3720. int ret = 0;
  3721. void *apr_cvp;
  3722. u16 cvp_handle;
  3723. struct voice_data *v = voice_get_session(session_id);
  3724. if (v == NULL) {
  3725. pr_err("%s: v is NULL\n", __func__);
  3726. return -EINVAL;
  3727. }
  3728. apr_cvp = common.apr_q6_cvp;
  3729. if (!apr_cvp) {
  3730. pr_err("%s: apr_cvp is NULL.\n", __func__);
  3731. return -EINVAL;
  3732. }
  3733. cvp_handle = voice_get_cvp_handle(v);
  3734. /* fill in the header */
  3735. vpcm_push_buf_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  3736. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  3737. vpcm_push_buf_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  3738. sizeof(vpcm_push_buf_cmd) - APR_HDR_SIZE);
  3739. vpcm_push_buf_cmd.hdr.src_port = v->session_id;
  3740. vpcm_push_buf_cmd.hdr.dest_port = cvp_handle;
  3741. vpcm_push_buf_cmd.hdr.token = 0;
  3742. vpcm_push_buf_cmd.hdr.opcode = VSS_IVPCM_EVT_PUSH_BUFFER;
  3743. vpcm_push_buf_cmd.vpcm_evt_push_buffer.tap_point =
  3744. push_buff_evt->tap_point;
  3745. vpcm_push_buf_cmd.vpcm_evt_push_buffer.push_buf_mask =
  3746. push_buff_evt->push_buf_mask;
  3747. vpcm_push_buf_cmd.vpcm_evt_push_buffer.out_buf_addr =
  3748. push_buff_evt->out_buf_addr;
  3749. vpcm_push_buf_cmd.vpcm_evt_push_buffer.in_buf_addr =
  3750. push_buff_evt->in_buf_addr;
  3751. vpcm_push_buf_cmd.vpcm_evt_push_buffer.out_buf_size =
  3752. push_buff_evt->out_buf_size;
  3753. vpcm_push_buf_cmd.vpcm_evt_push_buffer.in_buf_size =
  3754. push_buff_evt->in_buf_size;
  3755. vpcm_push_buf_cmd.vpcm_evt_push_buffer.sampling_rate =
  3756. push_buff_evt->sampling_rate;
  3757. vpcm_push_buf_cmd.vpcm_evt_push_buffer.num_in_channels =
  3758. push_buff_evt->num_in_channels;
  3759. ret = apr_send_pkt(apr_cvp, (uint32_t *) &vpcm_push_buf_cmd);
  3760. if (ret < 0) {
  3761. pr_err("Fail: sending vocpcm map memory,\n");
  3762. goto fail;
  3763. }
  3764. return 0;
  3765. fail:
  3766. return -EINVAL;
  3767. }
  3768. int voc_send_cvp_stop_vocpcm(u16 session_id)
  3769. {
  3770. struct cvp_stop_cmd vpcm_stop_cmd;
  3771. int ret = 0;
  3772. void *apr_cvp;
  3773. u16 cvp_handle;
  3774. struct voice_data *v = voice_get_session(session_id);
  3775. if (v == NULL) {
  3776. pr_err("%s: v is NULL\n", __func__);
  3777. return -EINVAL;
  3778. }
  3779. apr_cvp = common.apr_q6_cvp;
  3780. if (!apr_cvp) {
  3781. pr_err("%s: apr_cvp is NULL.\n", __func__);
  3782. return -EINVAL;
  3783. }
  3784. cvp_handle = voice_get_cvp_handle(v);
  3785. /* fill in the header */
  3786. vpcm_stop_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  3787. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  3788. vpcm_stop_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  3789. sizeof(vpcm_stop_cmd) - APR_HDR_SIZE);
  3790. vpcm_stop_cmd.hdr.src_port = v->session_id;
  3791. vpcm_stop_cmd.hdr.dest_port = cvp_handle;
  3792. vpcm_stop_cmd.hdr.token = 0;
  3793. vpcm_stop_cmd.hdr.opcode = VSS_IVPCM_CMD_STOP;
  3794. v->cvp_state = CMD_STATUS_FAIL;
  3795. ret = apr_send_pkt(apr_cvp, (uint32_t *) &vpcm_stop_cmd);
  3796. if (ret < 0) {
  3797. pr_err("Fail: sending vocpcm stop,\n");
  3798. goto fail;
  3799. }
  3800. ret = wait_event_timeout(v->cvp_wait,
  3801. (v->cvp_state == CMD_STATUS_SUCCESS),
  3802. msecs_to_jiffies(TIMEOUT_MS));
  3803. if (!ret) {
  3804. pr_err("%s: wait_event timeout\n", __func__);
  3805. goto fail;
  3806. }
  3807. return 0;
  3808. fail:
  3809. return -EINVAL;
  3810. }
  3811. int voc_send_cvp_start_vocpcm(u16 session_id,
  3812. struct vss_ivpcm_tap_point *vpcm_tp,
  3813. uint32_t no_of_tp)
  3814. {
  3815. struct cvp_start_cmd cvp_start_cmd;
  3816. int ret = 0;
  3817. void *apr_cvp;
  3818. u16 cvp_handle;
  3819. struct voice_data *v = voice_get_session(session_id);
  3820. int i = 0;
  3821. if (v == NULL) {
  3822. pr_err("%s: v is NULL\n", __func__);
  3823. return -EINVAL;
  3824. }
  3825. apr_cvp = common.apr_q6_cvp;
  3826. if (!apr_cvp) {
  3827. pr_err("%s: apr_cvp is NULL.\n", __func__);
  3828. return -EINVAL;
  3829. }
  3830. cvp_handle = voice_get_cvp_handle(v);
  3831. /* fill in the header */
  3832. cvp_start_cmd.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD,
  3833. APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER);
  3834. cvp_start_cmd.hdr.pkt_size = APR_PKT_SIZE(APR_HDR_SIZE,
  3835. sizeof(struct vss_ivpcm_tap_point) * no_of_tp) + sizeof(no_of_tp);
  3836. cvp_start_cmd.hdr.src_port = v->session_id;
  3837. cvp_start_cmd.hdr.dest_port = cvp_handle;
  3838. cvp_start_cmd.hdr.token = 0;
  3839. cvp_start_cmd.hdr.opcode = VSS_IVPCM_CMD_START;
  3840. for (i = 0; i < no_of_tp; i++) {
  3841. cvp_start_cmd.vpcm_start_cmd.tap_points[i].tap_point =
  3842. vpcm_tp[i].tap_point;
  3843. cvp_start_cmd.vpcm_start_cmd.tap_points[i].direction =
  3844. vpcm_tp[i].direction;
  3845. cvp_start_cmd.vpcm_start_cmd.tap_points[i].sampling_rate =
  3846. vpcm_tp[i].sampling_rate;
  3847. cvp_start_cmd.vpcm_start_cmd.tap_points[i].duration = 0;
  3848. }
  3849. cvp_start_cmd.vpcm_start_cmd.num_tap_points = no_of_tp;
  3850. v->cvp_state = CMD_STATUS_FAIL;
  3851. ret = apr_send_pkt(apr_cvp, (uint32_t *) &cvp_start_cmd);
  3852. if (ret < 0) {
  3853. pr_err("Fail: sending vocpcm map memory,\n");
  3854. goto fail;
  3855. }
  3856. ret = wait_event_timeout(v->cvp_wait,
  3857. (v->cvp_state == CMD_STATUS_SUCCESS),
  3858. msecs_to_jiffies(TIMEOUT_MS));
  3859. if (!ret) {
  3860. pr_err("%s: wait_event timeout\n", __func__);
  3861. goto fail;
  3862. }
  3863. return 0;
  3864. fail:
  3865. return -EINVAL;
  3866. }
  3867. int voc_send_cvp_unmap_vocpcm_memory(u16 session_id, uint32_t paddr)
  3868. {
  3869. return voice_send_cvp_unmap_memory_cmd(
  3870. voice_get_session(session_id), paddr);
  3871. }
  3872. int voc_send_cvp_map_vocpcm_memory(u16 session_id,
  3873. uint32_t paddr, uint32_t bufsize)
  3874. {
  3875. return voice_send_cvp_map_memory_cmd(voice_get_session(session_id),
  3876. paddr,
  3877. bufsize);
  3878. }
  3879. static void voice_allocate_shared_memory(void)
  3880. {
  3881. int i, j, result;
  3882. int offset = 0;
  3883. int mem_len;
  3884. unsigned long paddr;
  3885. void *kvptr;
  3886. pr_debug("%s\n", __func__);
  3887. common.ion_client = msm_ion_client_create(UINT_MAX, "q6voice_client");
  3888. if (IS_ERR_OR_NULL((void *)common.ion_client)) {
  3889. pr_err("%s: ION create client failed\n", __func__);
  3890. goto err;
  3891. }
  3892. common.ion_handle = ion_alloc(common.ion_client,
  3893. TOTAL_VOICE_CAL_SIZE,
  3894. SZ_4K, ION_HEAP(ION_AUDIO_HEAP_ID), 0);
  3895. if (IS_ERR_OR_NULL((void *) common.ion_handle)) {
  3896. pr_err("%s: ION memory allocation failed\n",
  3897. __func__);
  3898. goto err_ion_client;
  3899. }
  3900. result = ion_phys(common.ion_client, common.ion_handle,
  3901. &paddr, (size_t *)&mem_len);
  3902. if (result) {
  3903. pr_err("%s: ION Get Physical failed, rc = %d\n",
  3904. __func__, result);
  3905. goto err_ion_handle;
  3906. }
  3907. kvptr = ion_map_kernel(common.ion_client, common.ion_handle);
  3908. if (IS_ERR_OR_NULL(kvptr)) {
  3909. pr_err("%s: ION memory mapping failed\n", __func__);
  3910. goto err_ion_handle;
  3911. }
  3912. /* Make all phys & buf point to the correct address */
  3913. for (i = 0; i < NUM_VOICE_CAL_BUFFERS; i++) {
  3914. for (j = 0; j < NUM_VOICE_CAL_TYPES; j++) {
  3915. common.voice_cal[i].cal_data[j].paddr =
  3916. (uint32_t)(paddr + offset);
  3917. common.voice_cal[i].cal_data[j].kvaddr =
  3918. (uint32_t)((uint8_t *)kvptr + offset);
  3919. if (j == CVP_CAL)
  3920. offset += CVP_CAL_SIZE;
  3921. else
  3922. offset += CVS_CAL_SIZE;
  3923. pr_debug("%s: kernel addr = 0x%x, phys addr = 0x%x\n",
  3924. __func__,
  3925. common.voice_cal[i].cal_data[j].kvaddr,
  3926. common.voice_cal[i].cal_data[j].paddr);
  3927. }
  3928. }
  3929. return;
  3930. err_ion_handle:
  3931. ion_free(common.ion_client, common.ion_handle);
  3932. err_ion_client:
  3933. ion_client_destroy(common.ion_client);
  3934. err:
  3935. return;
  3936. }
  3937. static int __init voice_init(void)
  3938. {
  3939. int rc = 0, i = 0;
  3940. memset(&common, 0, sizeof(struct common_data));
  3941. /* Allocate shared memory */
  3942. voice_allocate_shared_memory();
  3943. /* set default value */
  3944. common.default_mute_val = 0; /* default is un-mute */
  3945. common.default_vol_val = 0;
  3946. common.default_sample_val = 8000;
  3947. common.ec_ref_ext = false;
  3948. /* Initialize MVS info. */
  3949. common.mvs_info.network_type = VSS_NETWORK_ID_DEFAULT;
  3950. mutex_init(&common.common_lock);
  3951. for (i = 0; i < MAX_VOC_SESSIONS; i++) {
  3952. common.voice[i].session_id = SESSION_ID_BASE + i;
  3953. /* initialize dev_rx and dev_tx */
  3954. common.voice[i].dev_rx.volume = common.default_vol_val;
  3955. common.voice[i].dev_rx.mute = 0;
  3956. common.voice[i].dev_tx.mute = common.default_mute_val;
  3957. common.voice[i].dev_tx.port_id = 1;
  3958. common.voice[i].dev_rx.port_id = 0;
  3959. common.voice[i].sidetone_gain = 0x512;
  3960. common.voice[i].dtmf_rx_detect_en = 0;
  3961. common.voice[i].disable_topology = false;
  3962. common.voice[i].voc_state = VOC_INIT;
  3963. init_waitqueue_head(&common.voice[i].mvm_wait);
  3964. init_waitqueue_head(&common.voice[i].cvs_wait);
  3965. init_waitqueue_head(&common.voice[i].cvp_wait);
  3966. mutex_init(&common.voice[i].lock);
  3967. }
  3968. return rc;
  3969. }
  3970. device_initcall(voice_init);