hpifunc.c 99 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940
  1. #include "hpi_internal.h"
  2. #include "hpimsginit.h"
  3. #include "hpidebug.h"
  4. struct hpi_handle {
  5. unsigned int obj_index:12;
  6. unsigned int obj_type:4;
  7. unsigned int adapter_index:14;
  8. unsigned int spare:1;
  9. unsigned int read_only:1;
  10. };
  11. union handle_word {
  12. struct hpi_handle h;
  13. u32 w;
  14. };
  15. u32 hpi_indexes_to_handle(const char c_object, const u16 adapter_index,
  16. const u16 object_index)
  17. {
  18. union handle_word handle;
  19. handle.h.adapter_index = adapter_index;
  20. handle.h.spare = 0;
  21. handle.h.read_only = 0;
  22. handle.h.obj_type = c_object;
  23. handle.h.obj_index = object_index;
  24. return handle.w;
  25. }
  26. void hpi_handle_to_indexes(const u32 handle, u16 *pw_adapter_index,
  27. u16 *pw_object_index)
  28. {
  29. union handle_word uhandle;
  30. uhandle.w = handle;
  31. if (pw_adapter_index)
  32. *pw_adapter_index = (u16)uhandle.h.adapter_index;
  33. if (pw_object_index)
  34. *pw_object_index = (u16)uhandle.h.obj_index;
  35. }
  36. char hpi_handle_object(const u32 handle)
  37. {
  38. union handle_word uhandle;
  39. uhandle.w = handle;
  40. return (char)uhandle.h.obj_type;
  41. }
  42. #define u32TOINDEX(h, i1) \
  43. do {\
  44. if (h == 0) \
  45. return HPI_ERROR_INVALID_OBJ; \
  46. else \
  47. hpi_handle_to_indexes(h, i1, NULL); \
  48. } while (0)
  49. #define u32TOINDEXES(h, i1, i2) \
  50. do {\
  51. if (h == 0) \
  52. return HPI_ERROR_INVALID_OBJ; \
  53. else \
  54. hpi_handle_to_indexes(h, i1, i2);\
  55. } while (0)
  56. void hpi_format_to_msg(struct hpi_msg_format *pMF,
  57. const struct hpi_format *pF)
  58. {
  59. pMF->sample_rate = pF->sample_rate;
  60. pMF->bit_rate = pF->bit_rate;
  61. pMF->attributes = pF->attributes;
  62. pMF->channels = pF->channels;
  63. pMF->format = pF->format;
  64. }
  65. static void hpi_msg_to_format(struct hpi_format *pF,
  66. struct hpi_msg_format *pMF)
  67. {
  68. pF->sample_rate = pMF->sample_rate;
  69. pF->bit_rate = pMF->bit_rate;
  70. pF->attributes = pMF->attributes;
  71. pF->channels = pMF->channels;
  72. pF->format = pMF->format;
  73. pF->mode_legacy = 0;
  74. pF->unused = 0;
  75. }
  76. void hpi_stream_response_to_legacy(struct hpi_stream_res *pSR)
  77. {
  78. pSR->u.legacy_stream_info.auxiliary_data_available =
  79. pSR->u.stream_info.auxiliary_data_available;
  80. pSR->u.legacy_stream_info.state = pSR->u.stream_info.state;
  81. }
  82. static struct hpi_hsubsys gh_subsys;
  83. struct hpi_hsubsys *hpi_subsys_create(void)
  84. {
  85. struct hpi_message hm;
  86. struct hpi_response hr;
  87. memset(&gh_subsys, 0, sizeof(struct hpi_hsubsys));
  88. {
  89. hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
  90. HPI_SUBSYS_OPEN);
  91. hpi_send_recv(&hm, &hr);
  92. if (hr.error == 0)
  93. return &gh_subsys;
  94. }
  95. return NULL;
  96. }
  97. void hpi_subsys_free(const struct hpi_hsubsys *ph_subsys)
  98. {
  99. struct hpi_message hm;
  100. struct hpi_response hr;
  101. hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
  102. HPI_SUBSYS_CLOSE);
  103. hpi_send_recv(&hm, &hr);
  104. }
  105. u16 hpi_subsys_get_version(const struct hpi_hsubsys *ph_subsys, u32 *pversion)
  106. {
  107. struct hpi_message hm;
  108. struct hpi_response hr;
  109. hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
  110. HPI_SUBSYS_GET_VERSION);
  111. hpi_send_recv(&hm, &hr);
  112. *pversion = hr.u.s.version;
  113. return hr.error;
  114. }
  115. u16 hpi_subsys_get_version_ex(const struct hpi_hsubsys *ph_subsys,
  116. u32 *pversion_ex)
  117. {
  118. struct hpi_message hm;
  119. struct hpi_response hr;
  120. hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
  121. HPI_SUBSYS_GET_VERSION);
  122. hpi_send_recv(&hm, &hr);
  123. *pversion_ex = hr.u.s.data;
  124. return hr.error;
  125. }
  126. u16 hpi_subsys_get_info(const struct hpi_hsubsys *ph_subsys, u32 *pversion,
  127. u16 *pw_num_adapters, u16 aw_adapter_list[], u16 list_length)
  128. {
  129. struct hpi_message hm;
  130. struct hpi_response hr;
  131. hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
  132. HPI_SUBSYS_GET_INFO);
  133. hpi_send_recv(&hm, &hr);
  134. *pversion = hr.u.s.version;
  135. if (list_length > HPI_MAX_ADAPTERS)
  136. memcpy(aw_adapter_list, &hr.u.s.aw_adapter_list,
  137. HPI_MAX_ADAPTERS);
  138. else
  139. memcpy(aw_adapter_list, &hr.u.s.aw_adapter_list, list_length);
  140. *pw_num_adapters = hr.u.s.num_adapters;
  141. return hr.error;
  142. }
  143. u16 hpi_subsys_find_adapters(const struct hpi_hsubsys *ph_subsys,
  144. u16 *pw_num_adapters, u16 aw_adapter_list[], u16 list_length)
  145. {
  146. struct hpi_message hm;
  147. struct hpi_response hr;
  148. hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
  149. HPI_SUBSYS_FIND_ADAPTERS);
  150. hpi_send_recv(&hm, &hr);
  151. if (list_length > HPI_MAX_ADAPTERS) {
  152. memcpy(aw_adapter_list, &hr.u.s.aw_adapter_list,
  153. HPI_MAX_ADAPTERS * sizeof(u16));
  154. memset(&aw_adapter_list[HPI_MAX_ADAPTERS], 0,
  155. (list_length - HPI_MAX_ADAPTERS) * sizeof(u16));
  156. } else
  157. memcpy(aw_adapter_list, &hr.u.s.aw_adapter_list,
  158. list_length * sizeof(u16));
  159. *pw_num_adapters = hr.u.s.num_adapters;
  160. return hr.error;
  161. }
  162. u16 hpi_subsys_create_adapter(const struct hpi_hsubsys *ph_subsys,
  163. const struct hpi_resource *p_resource, u16 *pw_adapter_index)
  164. {
  165. struct hpi_message hm;
  166. struct hpi_response hr;
  167. hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
  168. HPI_SUBSYS_CREATE_ADAPTER);
  169. hm.u.s.resource = *p_resource;
  170. hpi_send_recv(&hm, &hr);
  171. *pw_adapter_index = hr.u.s.adapter_index;
  172. return hr.error;
  173. }
  174. u16 hpi_subsys_delete_adapter(const struct hpi_hsubsys *ph_subsys,
  175. u16 adapter_index)
  176. {
  177. struct hpi_message hm;
  178. struct hpi_response hr;
  179. hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
  180. HPI_SUBSYS_DELETE_ADAPTER);
  181. hm.adapter_index = adapter_index;
  182. hpi_send_recv(&hm, &hr);
  183. return hr.error;
  184. }
  185. u16 hpi_subsys_get_num_adapters(const struct hpi_hsubsys *ph_subsys,
  186. int *pn_num_adapters)
  187. {
  188. struct hpi_message hm;
  189. struct hpi_response hr;
  190. hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
  191. HPI_SUBSYS_GET_NUM_ADAPTERS);
  192. hpi_send_recv(&hm, &hr);
  193. *pn_num_adapters = (int)hr.u.s.num_adapters;
  194. return hr.error;
  195. }
  196. u16 hpi_subsys_get_adapter(const struct hpi_hsubsys *ph_subsys, int iterator,
  197. u32 *padapter_index, u16 *pw_adapter_type)
  198. {
  199. struct hpi_message hm;
  200. struct hpi_response hr;
  201. hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
  202. HPI_SUBSYS_GET_ADAPTER);
  203. hm.adapter_index = (u16)iterator;
  204. hpi_send_recv(&hm, &hr);
  205. *padapter_index = (int)hr.u.s.adapter_index;
  206. *pw_adapter_type = hr.u.s.aw_adapter_list[0];
  207. return hr.error;
  208. }
  209. u16 hpi_subsys_set_host_network_interface(const struct hpi_hsubsys *ph_subsys,
  210. const char *sz_interface)
  211. {
  212. struct hpi_message hm;
  213. struct hpi_response hr;
  214. hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
  215. HPI_SUBSYS_SET_NETWORK_INTERFACE);
  216. if (sz_interface == NULL)
  217. return HPI_ERROR_INVALID_RESOURCE;
  218. hm.u.s.resource.r.net_if = sz_interface;
  219. hpi_send_recv(&hm, &hr);
  220. return hr.error;
  221. }
  222. u16 hpi_adapter_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index)
  223. {
  224. struct hpi_message hm;
  225. struct hpi_response hr;
  226. hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
  227. HPI_ADAPTER_OPEN);
  228. hm.adapter_index = adapter_index;
  229. hpi_send_recv(&hm, &hr);
  230. return hr.error;
  231. }
  232. u16 hpi_adapter_close(const struct hpi_hsubsys *ph_subsys, u16 adapter_index)
  233. {
  234. struct hpi_message hm;
  235. struct hpi_response hr;
  236. hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
  237. HPI_ADAPTER_CLOSE);
  238. hm.adapter_index = adapter_index;
  239. hpi_send_recv(&hm, &hr);
  240. return hr.error;
  241. }
  242. u16 hpi_adapter_set_mode(const struct hpi_hsubsys *ph_subsys,
  243. u16 adapter_index, u32 adapter_mode)
  244. {
  245. return hpi_adapter_set_mode_ex(ph_subsys, adapter_index, adapter_mode,
  246. HPI_ADAPTER_MODE_SET);
  247. }
  248. u16 hpi_adapter_set_mode_ex(const struct hpi_hsubsys *ph_subsys,
  249. u16 adapter_index, u32 adapter_mode, u16 query_or_set)
  250. {
  251. struct hpi_message hm;
  252. struct hpi_response hr;
  253. hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
  254. HPI_ADAPTER_SET_MODE);
  255. hm.adapter_index = adapter_index;
  256. hm.u.a.adapter_mode = adapter_mode;
  257. hm.u.a.assert_id = query_or_set;
  258. hpi_send_recv(&hm, &hr);
  259. return hr.error;
  260. }
  261. u16 hpi_adapter_get_mode(const struct hpi_hsubsys *ph_subsys,
  262. u16 adapter_index, u32 *padapter_mode)
  263. {
  264. struct hpi_message hm;
  265. struct hpi_response hr;
  266. hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
  267. HPI_ADAPTER_GET_MODE);
  268. hm.adapter_index = adapter_index;
  269. hpi_send_recv(&hm, &hr);
  270. if (padapter_mode)
  271. *padapter_mode = hr.u.a.serial_number;
  272. return hr.error;
  273. }
  274. u16 hpi_adapter_get_info(const struct hpi_hsubsys *ph_subsys,
  275. u16 adapter_index, u16 *pw_num_outstreams, u16 *pw_num_instreams,
  276. u16 *pw_version, u32 *pserial_number, u16 *pw_adapter_type)
  277. {
  278. struct hpi_message hm;
  279. struct hpi_response hr;
  280. hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
  281. HPI_ADAPTER_GET_INFO);
  282. hm.adapter_index = adapter_index;
  283. hpi_send_recv(&hm, &hr);
  284. *pw_adapter_type = hr.u.a.adapter_type;
  285. *pw_num_outstreams = hr.u.a.num_outstreams;
  286. *pw_num_instreams = hr.u.a.num_instreams;
  287. *pw_version = hr.u.a.version;
  288. *pserial_number = hr.u.a.serial_number;
  289. return hr.error;
  290. }
  291. u16 hpi_adapter_get_module_by_index(const struct hpi_hsubsys *ph_subsys,
  292. u16 adapter_index, u16 module_index, u16 *pw_num_outputs,
  293. u16 *pw_num_inputs, u16 *pw_version, u32 *pserial_number,
  294. u16 *pw_module_type, u32 *ph_module)
  295. {
  296. struct hpi_message hm;
  297. struct hpi_response hr;
  298. hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
  299. HPI_ADAPTER_MODULE_INFO);
  300. hm.adapter_index = adapter_index;
  301. hm.u.ax.module_info.index = module_index;
  302. hpi_send_recv(&hm, &hr);
  303. *pw_module_type = hr.u.a.adapter_type;
  304. *pw_num_outputs = hr.u.a.num_outstreams;
  305. *pw_num_inputs = hr.u.a.num_instreams;
  306. *pw_version = hr.u.a.version;
  307. *pserial_number = hr.u.a.serial_number;
  308. *ph_module = 0;
  309. return hr.error;
  310. }
  311. u16 hpi_adapter_get_assert(const struct hpi_hsubsys *ph_subsys,
  312. u16 adapter_index, u16 *assert_present, char *psz_assert,
  313. u16 *pw_line_number)
  314. {
  315. struct hpi_message hm;
  316. struct hpi_response hr;
  317. hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
  318. HPI_ADAPTER_GET_ASSERT);
  319. hm.adapter_index = adapter_index;
  320. hpi_send_recv(&hm, &hr);
  321. *assert_present = 0;
  322. if (!hr.error) {
  323. *pw_line_number = (u16)hr.u.a.serial_number;
  324. if (*pw_line_number) {
  325. int i;
  326. char *src = (char *)hr.u.a.sz_adapter_assert;
  327. char *dst = psz_assert;
  328. *assert_present = 1;
  329. for (i = 0; i < HPI_STRING_LEN; i++) {
  330. char c;
  331. c = *src++;
  332. *dst++ = c;
  333. if (c == 0)
  334. break;
  335. }
  336. }
  337. }
  338. return hr.error;
  339. }
  340. u16 hpi_adapter_get_assert_ex(const struct hpi_hsubsys *ph_subsys,
  341. u16 adapter_index, u16 *assert_present, char *psz_assert,
  342. u32 *pline_number, u16 *pw_assert_on_dsp)
  343. {
  344. struct hpi_message hm;
  345. struct hpi_response hr;
  346. hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
  347. HPI_ADAPTER_GET_ASSERT);
  348. hm.adapter_index = adapter_index;
  349. hpi_send_recv(&hm, &hr);
  350. *assert_present = 0;
  351. if (!hr.error) {
  352. *pline_number = hr.u.a.serial_number;
  353. *assert_present = hr.u.a.adapter_type;
  354. *pw_assert_on_dsp = hr.u.a.adapter_index;
  355. if (!*assert_present && *pline_number)
  356. *assert_present = 1;
  357. if (*assert_present) {
  358. int i;
  359. char *src = (char *)hr.u.a.sz_adapter_assert;
  360. char *dst = psz_assert;
  361. for (i = 0; i < HPI_STRING_LEN; i++) {
  362. char c;
  363. c = *src++;
  364. *dst++ = c;
  365. if (c == 0)
  366. break;
  367. }
  368. } else {
  369. *psz_assert = 0;
  370. }
  371. }
  372. return hr.error;
  373. }
  374. u16 hpi_adapter_test_assert(const struct hpi_hsubsys *ph_subsys,
  375. u16 adapter_index, u16 assert_id)
  376. {
  377. struct hpi_message hm;
  378. struct hpi_response hr;
  379. hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
  380. HPI_ADAPTER_TEST_ASSERT);
  381. hm.adapter_index = adapter_index;
  382. hm.u.a.assert_id = assert_id;
  383. hpi_send_recv(&hm, &hr);
  384. return hr.error;
  385. }
  386. u16 hpi_adapter_enable_capability(const struct hpi_hsubsys *ph_subsys,
  387. u16 adapter_index, u16 capability, u32 key)
  388. {
  389. struct hpi_message hm;
  390. struct hpi_response hr;
  391. hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
  392. HPI_ADAPTER_ENABLE_CAPABILITY);
  393. hm.adapter_index = adapter_index;
  394. hm.u.a.assert_id = capability;
  395. hm.u.a.adapter_mode = key;
  396. hpi_send_recv(&hm, &hr);
  397. return hr.error;
  398. }
  399. u16 hpi_adapter_self_test(const struct hpi_hsubsys *ph_subsys,
  400. u16 adapter_index)
  401. {
  402. struct hpi_message hm;
  403. struct hpi_response hr;
  404. hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
  405. HPI_ADAPTER_SELFTEST);
  406. hm.adapter_index = adapter_index;
  407. hpi_send_recv(&hm, &hr);
  408. return hr.error;
  409. }
  410. u16 hpi_adapter_debug_read(const struct hpi_hsubsys *ph_subsys,
  411. u16 adapter_index, u32 dsp_address, char *p_buffer, int *count_bytes)
  412. {
  413. struct hpi_message hm;
  414. struct hpi_response hr;
  415. hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
  416. HPI_ADAPTER_DEBUG_READ);
  417. hr.size = sizeof(hr);
  418. hm.adapter_index = adapter_index;
  419. hm.u.ax.debug_read.dsp_address = dsp_address;
  420. if (*count_bytes > (int)sizeof(hr.u.bytes))
  421. *count_bytes = sizeof(hr.u.bytes);
  422. hm.u.ax.debug_read.count_bytes = *count_bytes;
  423. hpi_send_recv(&hm, &hr);
  424. if (!hr.error) {
  425. *count_bytes = hr.size - 12;
  426. memcpy(p_buffer, &hr.u.bytes, *count_bytes);
  427. } else
  428. *count_bytes = 0;
  429. return hr.error;
  430. }
  431. u16 hpi_adapter_set_property(const struct hpi_hsubsys *ph_subsys,
  432. u16 adapter_index, u16 property, u16 parameter1, u16 parameter2)
  433. {
  434. struct hpi_message hm;
  435. struct hpi_response hr;
  436. hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
  437. HPI_ADAPTER_SET_PROPERTY);
  438. hm.adapter_index = adapter_index;
  439. hm.u.ax.property_set.property = property;
  440. hm.u.ax.property_set.parameter1 = parameter1;
  441. hm.u.ax.property_set.parameter2 = parameter2;
  442. hpi_send_recv(&hm, &hr);
  443. return hr.error;
  444. }
  445. u16 hpi_adapter_get_property(const struct hpi_hsubsys *ph_subsys,
  446. u16 adapter_index, u16 property, u16 *pw_parameter1,
  447. u16 *pw_parameter2)
  448. {
  449. struct hpi_message hm;
  450. struct hpi_response hr;
  451. hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
  452. HPI_ADAPTER_GET_PROPERTY);
  453. hm.adapter_index = adapter_index;
  454. hm.u.ax.property_set.property = property;
  455. hpi_send_recv(&hm, &hr);
  456. if (!hr.error) {
  457. if (pw_parameter1)
  458. *pw_parameter1 = hr.u.ax.property_get.parameter1;
  459. if (pw_parameter2)
  460. *pw_parameter2 = hr.u.ax.property_get.parameter2;
  461. }
  462. return hr.error;
  463. }
  464. u16 hpi_adapter_enumerate_property(const struct hpi_hsubsys *ph_subsys,
  465. u16 adapter_index, u16 index, u16 what_to_enumerate,
  466. u16 property_index, u32 *psetting)
  467. {
  468. return 0;
  469. }
  470. u16 hpi_format_create(struct hpi_format *p_format, u16 channels, u16 format,
  471. u32 sample_rate, u32 bit_rate, u32 attributes)
  472. {
  473. u16 error = 0;
  474. struct hpi_msg_format fmt;
  475. switch (channels) {
  476. case 1:
  477. case 2:
  478. case 4:
  479. case 6:
  480. case 8:
  481. case 16:
  482. break;
  483. default:
  484. error = HPI_ERROR_INVALID_CHANNELS;
  485. return error;
  486. }
  487. fmt.channels = channels;
  488. switch (format) {
  489. case HPI_FORMAT_PCM16_SIGNED:
  490. case HPI_FORMAT_PCM24_SIGNED:
  491. case HPI_FORMAT_PCM32_SIGNED:
  492. case HPI_FORMAT_PCM32_FLOAT:
  493. case HPI_FORMAT_PCM16_BIGENDIAN:
  494. case HPI_FORMAT_PCM8_UNSIGNED:
  495. case HPI_FORMAT_MPEG_L1:
  496. case HPI_FORMAT_MPEG_L2:
  497. case HPI_FORMAT_MPEG_L3:
  498. case HPI_FORMAT_DOLBY_AC2:
  499. case HPI_FORMAT_AA_TAGIT1_HITS:
  500. case HPI_FORMAT_AA_TAGIT1_INSERTS:
  501. case HPI_FORMAT_RAW_BITSTREAM:
  502. case HPI_FORMAT_AA_TAGIT1_HITS_EX1:
  503. case HPI_FORMAT_OEM1:
  504. case HPI_FORMAT_OEM2:
  505. break;
  506. default:
  507. error = HPI_ERROR_INVALID_FORMAT;
  508. return error;
  509. }
  510. fmt.format = format;
  511. if (sample_rate < 8000L) {
  512. error = HPI_ERROR_INCOMPATIBLE_SAMPLERATE;
  513. sample_rate = 8000L;
  514. }
  515. if (sample_rate > 200000L) {
  516. error = HPI_ERROR_INCOMPATIBLE_SAMPLERATE;
  517. sample_rate = 200000L;
  518. }
  519. fmt.sample_rate = sample_rate;
  520. switch (format) {
  521. case HPI_FORMAT_MPEG_L1:
  522. case HPI_FORMAT_MPEG_L2:
  523. case HPI_FORMAT_MPEG_L3:
  524. fmt.bit_rate = bit_rate;
  525. break;
  526. case HPI_FORMAT_PCM16_SIGNED:
  527. case HPI_FORMAT_PCM16_BIGENDIAN:
  528. fmt.bit_rate = channels * sample_rate * 2;
  529. break;
  530. case HPI_FORMAT_PCM32_SIGNED:
  531. case HPI_FORMAT_PCM32_FLOAT:
  532. fmt.bit_rate = channels * sample_rate * 4;
  533. break;
  534. case HPI_FORMAT_PCM8_UNSIGNED:
  535. fmt.bit_rate = channels * sample_rate;
  536. break;
  537. default:
  538. fmt.bit_rate = 0;
  539. }
  540. switch (format) {
  541. case HPI_FORMAT_MPEG_L2:
  542. if ((channels == 1)
  543. && (attributes != HPI_MPEG_MODE_DEFAULT)) {
  544. attributes = HPI_MPEG_MODE_DEFAULT;
  545. error = HPI_ERROR_INVALID_FORMAT;
  546. } else if (attributes > HPI_MPEG_MODE_DUALCHANNEL) {
  547. attributes = HPI_MPEG_MODE_DEFAULT;
  548. error = HPI_ERROR_INVALID_FORMAT;
  549. }
  550. fmt.attributes = attributes;
  551. break;
  552. default:
  553. fmt.attributes = attributes;
  554. }
  555. hpi_msg_to_format(p_format, &fmt);
  556. return error;
  557. }
  558. u16 hpi_stream_estimate_buffer_size(struct hpi_format *p_format,
  559. u32 host_polling_rate_in_milli_seconds, u32 *recommended_buffer_size)
  560. {
  561. u32 bytes_per_second;
  562. u32 size;
  563. u16 channels;
  564. struct hpi_format *pF = p_format;
  565. channels = pF->channels;
  566. switch (pF->format) {
  567. case HPI_FORMAT_PCM16_BIGENDIAN:
  568. case HPI_FORMAT_PCM16_SIGNED:
  569. bytes_per_second = pF->sample_rate * 2L * channels;
  570. break;
  571. case HPI_FORMAT_PCM24_SIGNED:
  572. bytes_per_second = pF->sample_rate * 3L * channels;
  573. break;
  574. case HPI_FORMAT_PCM32_SIGNED:
  575. case HPI_FORMAT_PCM32_FLOAT:
  576. bytes_per_second = pF->sample_rate * 4L * channels;
  577. break;
  578. case HPI_FORMAT_PCM8_UNSIGNED:
  579. bytes_per_second = pF->sample_rate * 1L * channels;
  580. break;
  581. case HPI_FORMAT_MPEG_L1:
  582. case HPI_FORMAT_MPEG_L2:
  583. case HPI_FORMAT_MPEG_L3:
  584. bytes_per_second = pF->bit_rate / 8L;
  585. break;
  586. case HPI_FORMAT_DOLBY_AC2:
  587. bytes_per_second = 256000L / 8L;
  588. break;
  589. default:
  590. return HPI_ERROR_INVALID_FORMAT;
  591. }
  592. size = (bytes_per_second * host_polling_rate_in_milli_seconds * 2) /
  593. 1000L;
  594. *recommended_buffer_size =
  595. roundup_pow_of_two(((size + 4095L) & ~4095L));
  596. return 0;
  597. }
  598. u16 hpi_outstream_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index,
  599. u16 outstream_index, u32 *ph_outstream)
  600. {
  601. struct hpi_message hm;
  602. struct hpi_response hr;
  603. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  604. HPI_OSTREAM_OPEN);
  605. hm.adapter_index = adapter_index;
  606. hm.obj_index = outstream_index;
  607. hpi_send_recv(&hm, &hr);
  608. if (hr.error == 0)
  609. *ph_outstream =
  610. hpi_indexes_to_handle(HPI_OBJ_OSTREAM, adapter_index,
  611. outstream_index);
  612. else
  613. *ph_outstream = 0;
  614. return hr.error;
  615. }
  616. u16 hpi_outstream_close(const struct hpi_hsubsys *ph_subsys, u32 h_outstream)
  617. {
  618. struct hpi_message hm;
  619. struct hpi_response hr;
  620. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  621. HPI_OSTREAM_HOSTBUFFER_FREE);
  622. u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
  623. hpi_send_recv(&hm, &hr);
  624. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  625. HPI_OSTREAM_GROUP_RESET);
  626. u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
  627. hpi_send_recv(&hm, &hr);
  628. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  629. HPI_OSTREAM_CLOSE);
  630. u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
  631. hpi_send_recv(&hm, &hr);
  632. return hr.error;
  633. }
  634. u16 hpi_outstream_get_info_ex(const struct hpi_hsubsys *ph_subsys,
  635. u32 h_outstream, u16 *pw_state, u32 *pbuffer_size, u32 *pdata_to_play,
  636. u32 *psamples_played, u32 *pauxiliary_data_to_play)
  637. {
  638. struct hpi_message hm;
  639. struct hpi_response hr;
  640. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  641. HPI_OSTREAM_GET_INFO);
  642. u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
  643. hpi_send_recv(&hm, &hr);
  644. if (pw_state)
  645. *pw_state = hr.u.d.u.stream_info.state;
  646. if (pbuffer_size)
  647. *pbuffer_size = hr.u.d.u.stream_info.buffer_size;
  648. if (pdata_to_play)
  649. *pdata_to_play = hr.u.d.u.stream_info.data_available;
  650. if (psamples_played)
  651. *psamples_played = hr.u.d.u.stream_info.samples_transferred;
  652. if (pauxiliary_data_to_play)
  653. *pauxiliary_data_to_play =
  654. hr.u.d.u.stream_info.auxiliary_data_available;
  655. return hr.error;
  656. }
  657. u16 hpi_outstream_write_buf(const struct hpi_hsubsys *ph_subsys,
  658. u32 h_outstream, const u8 *pb_data, u32 bytes_to_write,
  659. const struct hpi_format *p_format)
  660. {
  661. struct hpi_message hm;
  662. struct hpi_response hr;
  663. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  664. HPI_OSTREAM_WRITE);
  665. u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
  666. hm.u.d.u.data.pb_data = (u8 *)pb_data;
  667. hm.u.d.u.data.data_size = bytes_to_write;
  668. hpi_format_to_msg(&hm.u.d.u.data.format, p_format);
  669. hpi_send_recv(&hm, &hr);
  670. return hr.error;
  671. }
  672. u16 hpi_outstream_start(const struct hpi_hsubsys *ph_subsys, u32 h_outstream)
  673. {
  674. struct hpi_message hm;
  675. struct hpi_response hr;
  676. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  677. HPI_OSTREAM_START);
  678. u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
  679. hpi_send_recv(&hm, &hr);
  680. return hr.error;
  681. }
  682. u16 hpi_outstream_wait_start(const struct hpi_hsubsys *ph_subsys,
  683. u32 h_outstream)
  684. {
  685. struct hpi_message hm;
  686. struct hpi_response hr;
  687. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  688. HPI_OSTREAM_WAIT_START);
  689. u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
  690. hpi_send_recv(&hm, &hr);
  691. return hr.error;
  692. }
  693. u16 hpi_outstream_stop(const struct hpi_hsubsys *ph_subsys, u32 h_outstream)
  694. {
  695. struct hpi_message hm;
  696. struct hpi_response hr;
  697. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  698. HPI_OSTREAM_STOP);
  699. u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
  700. hpi_send_recv(&hm, &hr);
  701. return hr.error;
  702. }
  703. u16 hpi_outstream_sinegen(const struct hpi_hsubsys *ph_subsys,
  704. u32 h_outstream)
  705. {
  706. struct hpi_message hm;
  707. struct hpi_response hr;
  708. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  709. HPI_OSTREAM_SINEGEN);
  710. u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
  711. hpi_send_recv(&hm, &hr);
  712. return hr.error;
  713. }
  714. u16 hpi_outstream_reset(const struct hpi_hsubsys *ph_subsys, u32 h_outstream)
  715. {
  716. struct hpi_message hm;
  717. struct hpi_response hr;
  718. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  719. HPI_OSTREAM_RESET);
  720. u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
  721. hpi_send_recv(&hm, &hr);
  722. return hr.error;
  723. }
  724. u16 hpi_outstream_query_format(const struct hpi_hsubsys *ph_subsys,
  725. u32 h_outstream, struct hpi_format *p_format)
  726. {
  727. struct hpi_message hm;
  728. struct hpi_response hr;
  729. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  730. HPI_OSTREAM_QUERY_FORMAT);
  731. u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
  732. hpi_format_to_msg(&hm.u.d.u.data.format, p_format);
  733. hpi_send_recv(&hm, &hr);
  734. return hr.error;
  735. }
  736. u16 hpi_outstream_set_format(const struct hpi_hsubsys *ph_subsys,
  737. u32 h_outstream, struct hpi_format *p_format)
  738. {
  739. struct hpi_message hm;
  740. struct hpi_response hr;
  741. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  742. HPI_OSTREAM_SET_FORMAT);
  743. u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
  744. hpi_format_to_msg(&hm.u.d.u.data.format, p_format);
  745. hpi_send_recv(&hm, &hr);
  746. return hr.error;
  747. }
  748. u16 hpi_outstream_set_velocity(const struct hpi_hsubsys *ph_subsys,
  749. u32 h_outstream, short velocity)
  750. {
  751. struct hpi_message hm;
  752. struct hpi_response hr;
  753. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  754. HPI_OSTREAM_SET_VELOCITY);
  755. u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
  756. hm.u.d.u.velocity = velocity;
  757. hpi_send_recv(&hm, &hr);
  758. return hr.error;
  759. }
  760. u16 hpi_outstream_set_punch_in_out(const struct hpi_hsubsys *ph_subsys,
  761. u32 h_outstream, u32 punch_in_sample, u32 punch_out_sample)
  762. {
  763. struct hpi_message hm;
  764. struct hpi_response hr;
  765. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  766. HPI_OSTREAM_SET_PUNCHINOUT);
  767. u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
  768. hm.u.d.u.pio.punch_in_sample = punch_in_sample;
  769. hm.u.d.u.pio.punch_out_sample = punch_out_sample;
  770. hpi_send_recv(&hm, &hr);
  771. return hr.error;
  772. }
  773. u16 hpi_outstream_ancillary_reset(const struct hpi_hsubsys *ph_subsys,
  774. u32 h_outstream, u16 mode)
  775. {
  776. struct hpi_message hm;
  777. struct hpi_response hr;
  778. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  779. HPI_OSTREAM_ANC_RESET);
  780. u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
  781. hm.u.d.u.data.format.channels = mode;
  782. hpi_send_recv(&hm, &hr);
  783. return hr.error;
  784. }
  785. u16 hpi_outstream_ancillary_get_info(const struct hpi_hsubsys *ph_subsys,
  786. u32 h_outstream, u32 *pframes_available)
  787. {
  788. struct hpi_message hm;
  789. struct hpi_response hr;
  790. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  791. HPI_OSTREAM_ANC_GET_INFO);
  792. u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
  793. hpi_send_recv(&hm, &hr);
  794. if (hr.error == 0) {
  795. if (pframes_available)
  796. *pframes_available =
  797. hr.u.d.u.stream_info.data_available /
  798. sizeof(struct hpi_anc_frame);
  799. }
  800. return hr.error;
  801. }
  802. u16 hpi_outstream_ancillary_read(const struct hpi_hsubsys *ph_subsys,
  803. u32 h_outstream, struct hpi_anc_frame *p_anc_frame_buffer,
  804. u32 anc_frame_buffer_size_in_bytes,
  805. u32 number_of_ancillary_frames_to_read)
  806. {
  807. struct hpi_message hm;
  808. struct hpi_response hr;
  809. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  810. HPI_OSTREAM_ANC_READ);
  811. u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
  812. hm.u.d.u.data.pb_data = (u8 *)p_anc_frame_buffer;
  813. hm.u.d.u.data.data_size =
  814. number_of_ancillary_frames_to_read *
  815. sizeof(struct hpi_anc_frame);
  816. if (hm.u.d.u.data.data_size <= anc_frame_buffer_size_in_bytes)
  817. hpi_send_recv(&hm, &hr);
  818. else
  819. hr.error = HPI_ERROR_INVALID_DATA_TRANSFER;
  820. return hr.error;
  821. }
  822. u16 hpi_outstream_set_time_scale(const struct hpi_hsubsys *ph_subsys,
  823. u32 h_outstream, u32 time_scale)
  824. {
  825. struct hpi_message hm;
  826. struct hpi_response hr;
  827. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  828. HPI_OSTREAM_SET_TIMESCALE);
  829. u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
  830. hm.u.d.u.time_scale = time_scale;
  831. hpi_send_recv(&hm, &hr);
  832. return hr.error;
  833. }
  834. u16 hpi_outstream_host_buffer_allocate(const struct hpi_hsubsys *ph_subsys,
  835. u32 h_outstream, u32 size_in_bytes)
  836. {
  837. struct hpi_message hm;
  838. struct hpi_response hr;
  839. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  840. HPI_OSTREAM_HOSTBUFFER_ALLOC);
  841. u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
  842. hm.u.d.u.data.data_size = size_in_bytes;
  843. hpi_send_recv(&hm, &hr);
  844. return hr.error;
  845. }
  846. u16 hpi_outstream_host_buffer_get_info(const struct hpi_hsubsys *ph_subsys,
  847. u32 h_outstream, u8 **pp_buffer,
  848. struct hpi_hostbuffer_status **pp_status)
  849. {
  850. struct hpi_message hm;
  851. struct hpi_response hr;
  852. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  853. HPI_OSTREAM_HOSTBUFFER_GET_INFO);
  854. u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
  855. hpi_send_recv(&hm, &hr);
  856. if (hr.error == 0) {
  857. if (pp_buffer)
  858. *pp_buffer = hr.u.d.u.hostbuffer_info.p_buffer;
  859. if (pp_status)
  860. *pp_status = hr.u.d.u.hostbuffer_info.p_status;
  861. }
  862. return hr.error;
  863. }
  864. u16 hpi_outstream_host_buffer_free(const struct hpi_hsubsys *ph_subsys,
  865. u32 h_outstream)
  866. {
  867. struct hpi_message hm;
  868. struct hpi_response hr;
  869. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  870. HPI_OSTREAM_HOSTBUFFER_FREE);
  871. u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
  872. hpi_send_recv(&hm, &hr);
  873. return hr.error;
  874. }
  875. u16 hpi_outstream_group_add(const struct hpi_hsubsys *ph_subsys,
  876. u32 h_outstream, u32 h_stream)
  877. {
  878. struct hpi_message hm;
  879. struct hpi_response hr;
  880. u16 adapter;
  881. char c_obj_type;
  882. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  883. HPI_OSTREAM_GROUP_ADD);
  884. hr.error = 0;
  885. u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
  886. c_obj_type = hpi_handle_object(h_stream);
  887. switch (c_obj_type) {
  888. case HPI_OBJ_OSTREAM:
  889. hm.u.d.u.stream.object_type = HPI_OBJ_OSTREAM;
  890. u32TOINDEXES(h_stream, &adapter,
  891. &hm.u.d.u.stream.stream_index);
  892. break;
  893. case HPI_OBJ_ISTREAM:
  894. hm.u.d.u.stream.object_type = HPI_OBJ_ISTREAM;
  895. u32TOINDEXES(h_stream, &adapter,
  896. &hm.u.d.u.stream.stream_index);
  897. break;
  898. default:
  899. return HPI_ERROR_INVALID_STREAM;
  900. }
  901. if (adapter != hm.adapter_index)
  902. return HPI_ERROR_NO_INTERADAPTER_GROUPS;
  903. hpi_send_recv(&hm, &hr);
  904. return hr.error;
  905. }
  906. u16 hpi_outstream_group_get_map(const struct hpi_hsubsys *ph_subsys,
  907. u32 h_outstream, u32 *poutstream_map, u32 *pinstream_map)
  908. {
  909. struct hpi_message hm;
  910. struct hpi_response hr;
  911. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  912. HPI_OSTREAM_GROUP_GETMAP);
  913. u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
  914. hpi_send_recv(&hm, &hr);
  915. if (poutstream_map)
  916. *poutstream_map = hr.u.d.u.group_info.outstream_group_map;
  917. if (pinstream_map)
  918. *pinstream_map = hr.u.d.u.group_info.instream_group_map;
  919. return hr.error;
  920. }
  921. u16 hpi_outstream_group_reset(const struct hpi_hsubsys *ph_subsys,
  922. u32 h_outstream)
  923. {
  924. struct hpi_message hm;
  925. struct hpi_response hr;
  926. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  927. HPI_OSTREAM_GROUP_RESET);
  928. u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
  929. hpi_send_recv(&hm, &hr);
  930. return hr.error;
  931. }
  932. u16 hpi_instream_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index,
  933. u16 instream_index, u32 *ph_instream)
  934. {
  935. struct hpi_message hm;
  936. struct hpi_response hr;
  937. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  938. HPI_ISTREAM_OPEN);
  939. hm.adapter_index = adapter_index;
  940. hm.obj_index = instream_index;
  941. hpi_send_recv(&hm, &hr);
  942. if (hr.error == 0)
  943. *ph_instream =
  944. hpi_indexes_to_handle(HPI_OBJ_ISTREAM, adapter_index,
  945. instream_index);
  946. else
  947. *ph_instream = 0;
  948. return hr.error;
  949. }
  950. u16 hpi_instream_close(const struct hpi_hsubsys *ph_subsys, u32 h_instream)
  951. {
  952. struct hpi_message hm;
  953. struct hpi_response hr;
  954. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  955. HPI_ISTREAM_HOSTBUFFER_FREE);
  956. u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
  957. hpi_send_recv(&hm, &hr);
  958. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  959. HPI_ISTREAM_GROUP_RESET);
  960. u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
  961. hpi_send_recv(&hm, &hr);
  962. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  963. HPI_ISTREAM_CLOSE);
  964. u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
  965. hpi_send_recv(&hm, &hr);
  966. return hr.error;
  967. }
  968. u16 hpi_instream_query_format(const struct hpi_hsubsys *ph_subsys,
  969. u32 h_instream, const struct hpi_format *p_format)
  970. {
  971. struct hpi_message hm;
  972. struct hpi_response hr;
  973. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  974. HPI_ISTREAM_QUERY_FORMAT);
  975. u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
  976. hpi_format_to_msg(&hm.u.d.u.data.format, p_format);
  977. hpi_send_recv(&hm, &hr);
  978. return hr.error;
  979. }
  980. u16 hpi_instream_set_format(const struct hpi_hsubsys *ph_subsys,
  981. u32 h_instream, const struct hpi_format *p_format)
  982. {
  983. struct hpi_message hm;
  984. struct hpi_response hr;
  985. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  986. HPI_ISTREAM_SET_FORMAT);
  987. u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
  988. hpi_format_to_msg(&hm.u.d.u.data.format, p_format);
  989. hpi_send_recv(&hm, &hr);
  990. return hr.error;
  991. }
  992. u16 hpi_instream_read_buf(const struct hpi_hsubsys *ph_subsys, u32 h_instream,
  993. u8 *pb_data, u32 bytes_to_read)
  994. {
  995. struct hpi_message hm;
  996. struct hpi_response hr;
  997. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  998. HPI_ISTREAM_READ);
  999. u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
  1000. hm.u.d.u.data.data_size = bytes_to_read;
  1001. hm.u.d.u.data.pb_data = pb_data;
  1002. hpi_send_recv(&hm, &hr);
  1003. return hr.error;
  1004. }
  1005. u16 hpi_instream_start(const struct hpi_hsubsys *ph_subsys, u32 h_instream)
  1006. {
  1007. struct hpi_message hm;
  1008. struct hpi_response hr;
  1009. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  1010. HPI_ISTREAM_START);
  1011. u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
  1012. hpi_send_recv(&hm, &hr);
  1013. return hr.error;
  1014. }
  1015. u16 hpi_instream_wait_start(const struct hpi_hsubsys *ph_subsys,
  1016. u32 h_instream)
  1017. {
  1018. struct hpi_message hm;
  1019. struct hpi_response hr;
  1020. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  1021. HPI_ISTREAM_WAIT_START);
  1022. u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
  1023. hpi_send_recv(&hm, &hr);
  1024. return hr.error;
  1025. }
  1026. u16 hpi_instream_stop(const struct hpi_hsubsys *ph_subsys, u32 h_instream)
  1027. {
  1028. struct hpi_message hm;
  1029. struct hpi_response hr;
  1030. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  1031. HPI_ISTREAM_STOP);
  1032. u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
  1033. hpi_send_recv(&hm, &hr);
  1034. return hr.error;
  1035. }
  1036. u16 hpi_instream_reset(const struct hpi_hsubsys *ph_subsys, u32 h_instream)
  1037. {
  1038. struct hpi_message hm;
  1039. struct hpi_response hr;
  1040. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  1041. HPI_ISTREAM_RESET);
  1042. u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
  1043. hpi_send_recv(&hm, &hr);
  1044. return hr.error;
  1045. }
  1046. u16 hpi_instream_get_info_ex(const struct hpi_hsubsys *ph_subsys,
  1047. u32 h_instream, u16 *pw_state, u32 *pbuffer_size, u32 *pdata_recorded,
  1048. u32 *psamples_recorded, u32 *pauxiliary_data_recorded)
  1049. {
  1050. struct hpi_message hm;
  1051. struct hpi_response hr;
  1052. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  1053. HPI_ISTREAM_GET_INFO);
  1054. u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
  1055. hpi_send_recv(&hm, &hr);
  1056. if (pw_state)
  1057. *pw_state = hr.u.d.u.stream_info.state;
  1058. if (pbuffer_size)
  1059. *pbuffer_size = hr.u.d.u.stream_info.buffer_size;
  1060. if (pdata_recorded)
  1061. *pdata_recorded = hr.u.d.u.stream_info.data_available;
  1062. if (psamples_recorded)
  1063. *psamples_recorded = hr.u.d.u.stream_info.samples_transferred;
  1064. if (pauxiliary_data_recorded)
  1065. *pauxiliary_data_recorded =
  1066. hr.u.d.u.stream_info.auxiliary_data_available;
  1067. return hr.error;
  1068. }
  1069. u16 hpi_instream_ancillary_reset(const struct hpi_hsubsys *ph_subsys,
  1070. u32 h_instream, u16 bytes_per_frame, u16 mode, u16 alignment,
  1071. u16 idle_bit)
  1072. {
  1073. struct hpi_message hm;
  1074. struct hpi_response hr;
  1075. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  1076. HPI_ISTREAM_ANC_RESET);
  1077. u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
  1078. hm.u.d.u.data.format.attributes = bytes_per_frame;
  1079. hm.u.d.u.data.format.format = (mode << 8) | (alignment & 0xff);
  1080. hm.u.d.u.data.format.channels = idle_bit;
  1081. hpi_send_recv(&hm, &hr);
  1082. return hr.error;
  1083. }
  1084. u16 hpi_instream_ancillary_get_info(const struct hpi_hsubsys *ph_subsys,
  1085. u32 h_instream, u32 *pframe_space)
  1086. {
  1087. struct hpi_message hm;
  1088. struct hpi_response hr;
  1089. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  1090. HPI_ISTREAM_ANC_GET_INFO);
  1091. u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
  1092. hpi_send_recv(&hm, &hr);
  1093. if (pframe_space)
  1094. *pframe_space =
  1095. (hr.u.d.u.stream_info.buffer_size -
  1096. hr.u.d.u.stream_info.data_available) /
  1097. sizeof(struct hpi_anc_frame);
  1098. return hr.error;
  1099. }
  1100. u16 hpi_instream_ancillary_write(const struct hpi_hsubsys *ph_subsys,
  1101. u32 h_instream, const struct hpi_anc_frame *p_anc_frame_buffer,
  1102. u32 anc_frame_buffer_size_in_bytes,
  1103. u32 number_of_ancillary_frames_to_write)
  1104. {
  1105. struct hpi_message hm;
  1106. struct hpi_response hr;
  1107. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  1108. HPI_ISTREAM_ANC_WRITE);
  1109. u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
  1110. hm.u.d.u.data.pb_data = (u8 *)p_anc_frame_buffer;
  1111. hm.u.d.u.data.data_size =
  1112. number_of_ancillary_frames_to_write *
  1113. sizeof(struct hpi_anc_frame);
  1114. if (hm.u.d.u.data.data_size <= anc_frame_buffer_size_in_bytes)
  1115. hpi_send_recv(&hm, &hr);
  1116. else
  1117. hr.error = HPI_ERROR_INVALID_DATA_TRANSFER;
  1118. return hr.error;
  1119. }
  1120. u16 hpi_instream_host_buffer_allocate(const struct hpi_hsubsys *ph_subsys,
  1121. u32 h_instream, u32 size_in_bytes)
  1122. {
  1123. struct hpi_message hm;
  1124. struct hpi_response hr;
  1125. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  1126. HPI_ISTREAM_HOSTBUFFER_ALLOC);
  1127. u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
  1128. hm.u.d.u.data.data_size = size_in_bytes;
  1129. hpi_send_recv(&hm, &hr);
  1130. return hr.error;
  1131. }
  1132. u16 hpi_instream_host_buffer_get_info(const struct hpi_hsubsys *ph_subsys,
  1133. u32 h_instream, u8 **pp_buffer,
  1134. struct hpi_hostbuffer_status **pp_status)
  1135. {
  1136. struct hpi_message hm;
  1137. struct hpi_response hr;
  1138. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  1139. HPI_ISTREAM_HOSTBUFFER_GET_INFO);
  1140. u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
  1141. hpi_send_recv(&hm, &hr);
  1142. if (hr.error == 0) {
  1143. if (pp_buffer)
  1144. *pp_buffer = hr.u.d.u.hostbuffer_info.p_buffer;
  1145. if (pp_status)
  1146. *pp_status = hr.u.d.u.hostbuffer_info.p_status;
  1147. }
  1148. return hr.error;
  1149. }
  1150. u16 hpi_instream_host_buffer_free(const struct hpi_hsubsys *ph_subsys,
  1151. u32 h_instream)
  1152. {
  1153. struct hpi_message hm;
  1154. struct hpi_response hr;
  1155. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  1156. HPI_ISTREAM_HOSTBUFFER_FREE);
  1157. u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
  1158. hpi_send_recv(&hm, &hr);
  1159. return hr.error;
  1160. }
  1161. u16 hpi_instream_group_add(const struct hpi_hsubsys *ph_subsys,
  1162. u32 h_instream, u32 h_stream)
  1163. {
  1164. struct hpi_message hm;
  1165. struct hpi_response hr;
  1166. u16 adapter;
  1167. char c_obj_type;
  1168. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  1169. HPI_ISTREAM_GROUP_ADD);
  1170. hr.error = 0;
  1171. u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
  1172. c_obj_type = hpi_handle_object(h_stream);
  1173. switch (c_obj_type) {
  1174. case HPI_OBJ_OSTREAM:
  1175. hm.u.d.u.stream.object_type = HPI_OBJ_OSTREAM;
  1176. u32TOINDEXES(h_stream, &adapter,
  1177. &hm.u.d.u.stream.stream_index);
  1178. break;
  1179. case HPI_OBJ_ISTREAM:
  1180. hm.u.d.u.stream.object_type = HPI_OBJ_ISTREAM;
  1181. u32TOINDEXES(h_stream, &adapter,
  1182. &hm.u.d.u.stream.stream_index);
  1183. break;
  1184. default:
  1185. return HPI_ERROR_INVALID_STREAM;
  1186. }
  1187. if (adapter != hm.adapter_index)
  1188. return HPI_ERROR_NO_INTERADAPTER_GROUPS;
  1189. hpi_send_recv(&hm, &hr);
  1190. return hr.error;
  1191. }
  1192. u16 hpi_instream_group_get_map(const struct hpi_hsubsys *ph_subsys,
  1193. u32 h_instream, u32 *poutstream_map, u32 *pinstream_map)
  1194. {
  1195. struct hpi_message hm;
  1196. struct hpi_response hr;
  1197. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  1198. HPI_ISTREAM_HOSTBUFFER_FREE);
  1199. u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
  1200. hpi_send_recv(&hm, &hr);
  1201. if (poutstream_map)
  1202. *poutstream_map = hr.u.d.u.group_info.outstream_group_map;
  1203. if (pinstream_map)
  1204. *pinstream_map = hr.u.d.u.group_info.instream_group_map;
  1205. return hr.error;
  1206. }
  1207. u16 hpi_instream_group_reset(const struct hpi_hsubsys *ph_subsys,
  1208. u32 h_instream)
  1209. {
  1210. struct hpi_message hm;
  1211. struct hpi_response hr;
  1212. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  1213. HPI_ISTREAM_GROUP_RESET);
  1214. u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
  1215. hpi_send_recv(&hm, &hr);
  1216. return hr.error;
  1217. }
  1218. u16 hpi_mixer_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index,
  1219. u32 *ph_mixer)
  1220. {
  1221. struct hpi_message hm;
  1222. struct hpi_response hr;
  1223. hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER, HPI_MIXER_OPEN);
  1224. hm.adapter_index = adapter_index;
  1225. hpi_send_recv(&hm, &hr);
  1226. if (hr.error == 0)
  1227. *ph_mixer =
  1228. hpi_indexes_to_handle(HPI_OBJ_MIXER, adapter_index,
  1229. 0);
  1230. else
  1231. *ph_mixer = 0;
  1232. return hr.error;
  1233. }
  1234. u16 hpi_mixer_close(const struct hpi_hsubsys *ph_subsys, u32 h_mixer)
  1235. {
  1236. struct hpi_message hm;
  1237. struct hpi_response hr;
  1238. hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER, HPI_MIXER_CLOSE);
  1239. u32TOINDEX(h_mixer, &hm.adapter_index);
  1240. hpi_send_recv(&hm, &hr);
  1241. return hr.error;
  1242. }
  1243. u16 hpi_mixer_get_control(const struct hpi_hsubsys *ph_subsys, u32 h_mixer,
  1244. u16 src_node_type, u16 src_node_type_index, u16 dst_node_type,
  1245. u16 dst_node_type_index, u16 control_type, u32 *ph_control)
  1246. {
  1247. struct hpi_message hm;
  1248. struct hpi_response hr;
  1249. hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER,
  1250. HPI_MIXER_GET_CONTROL);
  1251. u32TOINDEX(h_mixer, &hm.adapter_index);
  1252. hm.u.m.node_type1 = src_node_type;
  1253. hm.u.m.node_index1 = src_node_type_index;
  1254. hm.u.m.node_type2 = dst_node_type;
  1255. hm.u.m.node_index2 = dst_node_type_index;
  1256. hm.u.m.control_type = control_type;
  1257. hpi_send_recv(&hm, &hr);
  1258. if (hr.error == 0)
  1259. *ph_control =
  1260. hpi_indexes_to_handle(HPI_OBJ_CONTROL,
  1261. hm.adapter_index, hr.u.m.control_index);
  1262. else
  1263. *ph_control = 0;
  1264. return hr.error;
  1265. }
  1266. u16 hpi_mixer_get_control_by_index(const struct hpi_hsubsys *ph_subsys,
  1267. u32 h_mixer, u16 control_index, u16 *pw_src_node_type,
  1268. u16 *pw_src_node_index, u16 *pw_dst_node_type, u16 *pw_dst_node_index,
  1269. u16 *pw_control_type, u32 *ph_control)
  1270. {
  1271. struct hpi_message hm;
  1272. struct hpi_response hr;
  1273. hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER,
  1274. HPI_MIXER_GET_CONTROL_BY_INDEX);
  1275. u32TOINDEX(h_mixer, &hm.adapter_index);
  1276. hm.u.m.control_index = control_index;
  1277. hpi_send_recv(&hm, &hr);
  1278. if (pw_src_node_type) {
  1279. *pw_src_node_type =
  1280. hr.u.m.src_node_type + HPI_SOURCENODE_NONE;
  1281. *pw_src_node_index = hr.u.m.src_node_index;
  1282. *pw_dst_node_type = hr.u.m.dst_node_type + HPI_DESTNODE_NONE;
  1283. *pw_dst_node_index = hr.u.m.dst_node_index;
  1284. }
  1285. if (pw_control_type)
  1286. *pw_control_type = hr.u.m.control_index;
  1287. if (ph_control) {
  1288. if (hr.error == 0)
  1289. *ph_control =
  1290. hpi_indexes_to_handle(HPI_OBJ_CONTROL,
  1291. hm.adapter_index, control_index);
  1292. else
  1293. *ph_control = 0;
  1294. }
  1295. return hr.error;
  1296. }
  1297. u16 hpi_mixer_store(const struct hpi_hsubsys *ph_subsys, u32 h_mixer,
  1298. enum HPI_MIXER_STORE_COMMAND command, u16 index)
  1299. {
  1300. struct hpi_message hm;
  1301. struct hpi_response hr;
  1302. hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER, HPI_MIXER_STORE);
  1303. u32TOINDEX(h_mixer, &hm.adapter_index);
  1304. hm.u.mx.store.command = command;
  1305. hm.u.mx.store.index = index;
  1306. hpi_send_recv(&hm, &hr);
  1307. return hr.error;
  1308. }
  1309. static
  1310. u16 hpi_control_param_set(const struct hpi_hsubsys *ph_subsys,
  1311. const u32 h_control, const u16 attrib, const u32 param1,
  1312. const u32 param2)
  1313. {
  1314. struct hpi_message hm;
  1315. struct hpi_response hr;
  1316. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1317. HPI_CONTROL_SET_STATE);
  1318. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  1319. hm.u.c.attribute = attrib;
  1320. hm.u.c.param1 = param1;
  1321. hm.u.c.param2 = param2;
  1322. hpi_send_recv(&hm, &hr);
  1323. return hr.error;
  1324. }
  1325. static u16 hpi_control_log_set2(u32 h_control, u16 attrib, short sv0,
  1326. short sv1)
  1327. {
  1328. struct hpi_message hm;
  1329. struct hpi_response hr;
  1330. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1331. HPI_CONTROL_SET_STATE);
  1332. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  1333. hm.u.c.attribute = attrib;
  1334. hm.u.c.an_log_value[0] = sv0;
  1335. hm.u.c.an_log_value[1] = sv1;
  1336. hpi_send_recv(&hm, &hr);
  1337. return hr.error;
  1338. }
  1339. static
  1340. u16 hpi_control_param_get(const struct hpi_hsubsys *ph_subsys,
  1341. const u32 h_control, const u16 attrib, u32 param1, u32 param2,
  1342. u32 *pparam1, u32 *pparam2)
  1343. {
  1344. struct hpi_message hm;
  1345. struct hpi_response hr;
  1346. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1347. HPI_CONTROL_GET_STATE);
  1348. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  1349. hm.u.c.attribute = attrib;
  1350. hm.u.c.param1 = param1;
  1351. hm.u.c.param2 = param2;
  1352. hpi_send_recv(&hm, &hr);
  1353. *pparam1 = hr.u.c.param1;
  1354. if (pparam2)
  1355. *pparam2 = hr.u.c.param2;
  1356. return hr.error;
  1357. }
  1358. #define hpi_control_param1_get(s, h, a, p1) \
  1359. hpi_control_param_get(s, h, a, 0, 0, p1, NULL)
  1360. #define hpi_control_param2_get(s, h, a, p1, p2) \
  1361. hpi_control_param_get(s, h, a, 0, 0, p1, p2)
  1362. static u16 hpi_control_log_get2(const struct hpi_hsubsys *ph_subsys,
  1363. u32 h_control, u16 attrib, short *sv0, short *sv1)
  1364. {
  1365. struct hpi_message hm;
  1366. struct hpi_response hr;
  1367. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1368. HPI_CONTROL_GET_STATE);
  1369. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  1370. hm.u.c.attribute = attrib;
  1371. hpi_send_recv(&hm, &hr);
  1372. *sv0 = hr.u.c.an_log_value[0];
  1373. if (sv1)
  1374. *sv1 = hr.u.c.an_log_value[1];
  1375. return hr.error;
  1376. }
  1377. static
  1378. u16 hpi_control_query(const struct hpi_hsubsys *ph_subsys,
  1379. const u32 h_control, const u16 attrib, const u32 index,
  1380. const u32 param, u32 *psetting)
  1381. {
  1382. struct hpi_message hm;
  1383. struct hpi_response hr;
  1384. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1385. HPI_CONTROL_GET_INFO);
  1386. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  1387. hm.u.c.attribute = attrib;
  1388. hm.u.c.param1 = index;
  1389. hm.u.c.param2 = param;
  1390. hpi_send_recv(&hm, &hr);
  1391. *psetting = hr.u.c.param1;
  1392. return hr.error;
  1393. }
  1394. static u16 hpi_control_get_string(const u32 h_control, const u16 attribute,
  1395. char *psz_string, const u32 string_length)
  1396. {
  1397. unsigned int sub_string_index = 0, j = 0;
  1398. char c = 0;
  1399. unsigned int n = 0;
  1400. u16 hE = 0;
  1401. if ((string_length < 1) || (string_length > 256))
  1402. return HPI_ERROR_INVALID_CONTROL_VALUE;
  1403. for (sub_string_index = 0; sub_string_index < string_length;
  1404. sub_string_index += 8) {
  1405. struct hpi_message hm;
  1406. struct hpi_response hr;
  1407. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1408. HPI_CONTROL_GET_STATE);
  1409. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  1410. hm.u.c.attribute = attribute;
  1411. hm.u.c.param1 = sub_string_index;
  1412. hm.u.c.param2 = 0;
  1413. hpi_send_recv(&hm, &hr);
  1414. if (sub_string_index == 0
  1415. && (hr.u.cu.chars8.remaining_chars + 8) >
  1416. string_length)
  1417. return HPI_ERROR_INVALID_CONTROL_VALUE;
  1418. if (hr.error) {
  1419. hE = hr.error;
  1420. break;
  1421. }
  1422. for (j = 0; j < 8; j++) {
  1423. c = hr.u.cu.chars8.sz_data[j];
  1424. psz_string[sub_string_index + j] = c;
  1425. n++;
  1426. if (n >= string_length) {
  1427. psz_string[string_length - 1] = 0;
  1428. hE = HPI_ERROR_INVALID_CONTROL_VALUE;
  1429. break;
  1430. }
  1431. if (c == 0)
  1432. break;
  1433. }
  1434. if ((hr.u.cu.chars8.remaining_chars == 0)
  1435. && ((sub_string_index + j) < string_length)
  1436. && (c != 0)) {
  1437. c = 0;
  1438. psz_string[sub_string_index + j] = c;
  1439. }
  1440. if (c == 0)
  1441. break;
  1442. }
  1443. return hE;
  1444. }
  1445. u16 HPI_AESEBU__receiver_query_format(const struct hpi_hsubsys *ph_subsys,
  1446. const u32 h_aes_rx, const u32 index, u16 *pw_format)
  1447. {
  1448. u32 qr;
  1449. u16 err;
  1450. err = hpi_control_query(ph_subsys, h_aes_rx, HPI_AESEBURX_FORMAT,
  1451. index, 0, &qr);
  1452. *pw_format = (u16)qr;
  1453. return err;
  1454. }
  1455. u16 HPI_AESEBU__receiver_set_format(const struct hpi_hsubsys *ph_subsys,
  1456. u32 h_control, u16 format)
  1457. {
  1458. return hpi_control_param_set(ph_subsys, h_control,
  1459. HPI_AESEBURX_FORMAT, format, 0);
  1460. }
  1461. u16 HPI_AESEBU__receiver_get_format(const struct hpi_hsubsys *ph_subsys,
  1462. u32 h_control, u16 *pw_format)
  1463. {
  1464. u16 err;
  1465. u32 param;
  1466. err = hpi_control_param1_get(ph_subsys, h_control,
  1467. HPI_AESEBURX_FORMAT, &param);
  1468. if (!err && pw_format)
  1469. *pw_format = (u16)param;
  1470. return err;
  1471. }
  1472. u16 HPI_AESEBU__receiver_get_sample_rate(const struct hpi_hsubsys *ph_subsys,
  1473. u32 h_control, u32 *psample_rate)
  1474. {
  1475. return hpi_control_param1_get(ph_subsys, h_control,
  1476. HPI_AESEBURX_SAMPLERATE, psample_rate);
  1477. }
  1478. u16 HPI_AESEBU__receiver_get_user_data(const struct hpi_hsubsys *ph_subsys,
  1479. u32 h_control, u16 index, u16 *pw_data)
  1480. {
  1481. struct hpi_message hm;
  1482. struct hpi_response hr;
  1483. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1484. HPI_CONTROL_GET_STATE);
  1485. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  1486. hm.u.c.attribute = HPI_AESEBURX_USERDATA;
  1487. hm.u.c.param1 = index;
  1488. hpi_send_recv(&hm, &hr);
  1489. if (pw_data)
  1490. *pw_data = (u16)hr.u.c.param2;
  1491. return hr.error;
  1492. }
  1493. u16 HPI_AESEBU__receiver_get_channel_status(const struct hpi_hsubsys
  1494. *ph_subsys, u32 h_control, u16 index, u16 *pw_data)
  1495. {
  1496. struct hpi_message hm;
  1497. struct hpi_response hr;
  1498. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1499. HPI_CONTROL_GET_STATE);
  1500. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  1501. hm.u.c.attribute = HPI_AESEBURX_CHANNELSTATUS;
  1502. hm.u.c.param1 = index;
  1503. hpi_send_recv(&hm, &hr);
  1504. if (pw_data)
  1505. *pw_data = (u16)hr.u.c.param2;
  1506. return hr.error;
  1507. }
  1508. u16 HPI_AESEBU__receiver_get_error_status(const struct hpi_hsubsys *ph_subsys,
  1509. u32 h_control, u16 *pw_error_data)
  1510. {
  1511. u32 error_data = 0;
  1512. u16 error = 0;
  1513. error = hpi_control_param1_get(ph_subsys, h_control,
  1514. HPI_AESEBURX_ERRORSTATUS, &error_data);
  1515. if (pw_error_data)
  1516. *pw_error_data = (u16)error_data;
  1517. return error;
  1518. }
  1519. u16 HPI_AESEBU__transmitter_set_sample_rate(const struct hpi_hsubsys
  1520. *ph_subsys, u32 h_control, u32 sample_rate)
  1521. {
  1522. return hpi_control_param_set(ph_subsys, h_control,
  1523. HPI_AESEBUTX_SAMPLERATE, sample_rate, 0);
  1524. }
  1525. u16 HPI_AESEBU__transmitter_set_user_data(const struct hpi_hsubsys *ph_subsys,
  1526. u32 h_control, u16 index, u16 data)
  1527. {
  1528. return hpi_control_param_set(ph_subsys, h_control,
  1529. HPI_AESEBUTX_USERDATA, index, data);
  1530. }
  1531. u16 HPI_AESEBU__transmitter_set_channel_status(const struct hpi_hsubsys
  1532. *ph_subsys, u32 h_control, u16 index, u16 data)
  1533. {
  1534. return hpi_control_param_set(ph_subsys, h_control,
  1535. HPI_AESEBUTX_CHANNELSTATUS, index, data);
  1536. }
  1537. u16 HPI_AESEBU__transmitter_get_channel_status(const struct hpi_hsubsys
  1538. *ph_subsys, u32 h_control, u16 index, u16 *pw_data)
  1539. {
  1540. return HPI_ERROR_INVALID_OPERATION;
  1541. }
  1542. u16 HPI_AESEBU__transmitter_query_format(const struct hpi_hsubsys *ph_subsys,
  1543. const u32 h_aes_tx, const u32 index, u16 *pw_format)
  1544. {
  1545. u32 qr;
  1546. u16 err;
  1547. err = hpi_control_query(ph_subsys, h_aes_tx, HPI_AESEBUTX_FORMAT,
  1548. index, 0, &qr);
  1549. *pw_format = (u16)qr;
  1550. return err;
  1551. }
  1552. u16 HPI_AESEBU__transmitter_set_format(const struct hpi_hsubsys *ph_subsys,
  1553. u32 h_control, u16 output_format)
  1554. {
  1555. return hpi_control_param_set(ph_subsys, h_control,
  1556. HPI_AESEBUTX_FORMAT, output_format, 0);
  1557. }
  1558. u16 HPI_AESEBU__transmitter_get_format(const struct hpi_hsubsys *ph_subsys,
  1559. u32 h_control, u16 *pw_output_format)
  1560. {
  1561. u16 err;
  1562. u32 param;
  1563. err = hpi_control_param1_get(ph_subsys, h_control,
  1564. HPI_AESEBUTX_FORMAT, &param);
  1565. if (!err && pw_output_format)
  1566. *pw_output_format = (u16)param;
  1567. return err;
  1568. }
  1569. u16 hpi_bitstream_set_clock_edge(const struct hpi_hsubsys *ph_subsys,
  1570. u32 h_control, u16 edge_type)
  1571. {
  1572. return hpi_control_param_set(ph_subsys, h_control,
  1573. HPI_BITSTREAM_CLOCK_EDGE, edge_type, 0);
  1574. }
  1575. u16 hpi_bitstream_set_data_polarity(const struct hpi_hsubsys *ph_subsys,
  1576. u32 h_control, u16 polarity)
  1577. {
  1578. return hpi_control_param_set(ph_subsys, h_control,
  1579. HPI_BITSTREAM_DATA_POLARITY, polarity, 0);
  1580. }
  1581. u16 hpi_bitstream_get_activity(const struct hpi_hsubsys *ph_subsys,
  1582. u32 h_control, u16 *pw_clk_activity, u16 *pw_data_activity)
  1583. {
  1584. struct hpi_message hm;
  1585. struct hpi_response hr;
  1586. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1587. HPI_CONTROL_GET_STATE);
  1588. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  1589. hm.u.c.attribute = HPI_BITSTREAM_ACTIVITY;
  1590. hpi_send_recv(&hm, &hr);
  1591. if (pw_clk_activity)
  1592. *pw_clk_activity = (u16)hr.u.c.param1;
  1593. if (pw_data_activity)
  1594. *pw_data_activity = (u16)hr.u.c.param2;
  1595. return hr.error;
  1596. }
  1597. u16 hpi_channel_mode_query_mode(const struct hpi_hsubsys *ph_subsys,
  1598. const u32 h_mode, const u32 index, u16 *pw_mode)
  1599. {
  1600. u32 qr;
  1601. u16 err;
  1602. err = hpi_control_query(ph_subsys, h_mode, HPI_CHANNEL_MODE_MODE,
  1603. index, 0, &qr);
  1604. *pw_mode = (u16)qr;
  1605. return err;
  1606. }
  1607. u16 hpi_channel_mode_set(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  1608. u16 mode)
  1609. {
  1610. return hpi_control_param_set(ph_subsys, h_control,
  1611. HPI_CHANNEL_MODE_MODE, mode, 0);
  1612. }
  1613. u16 hpi_channel_mode_get(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  1614. u16 *mode)
  1615. {
  1616. u32 mode32 = 0;
  1617. u16 error = hpi_control_param1_get(ph_subsys, h_control,
  1618. HPI_CHANNEL_MODE_MODE, &mode32);
  1619. if (mode)
  1620. *mode = (u16)mode32;
  1621. return error;
  1622. }
  1623. u16 hpi_cobranet_hmi_write(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  1624. u32 hmi_address, u32 byte_count, u8 *pb_data)
  1625. {
  1626. struct hpi_message hm;
  1627. struct hpi_response hr;
  1628. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROLEX,
  1629. HPI_CONTROL_SET_STATE);
  1630. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  1631. hm.u.cx.u.cobranet_data.byte_count = byte_count;
  1632. hm.u.cx.u.cobranet_data.hmi_address = hmi_address;
  1633. if (byte_count <= 8) {
  1634. memcpy(hm.u.cx.u.cobranet_data.data, pb_data, byte_count);
  1635. hm.u.cx.attribute = HPI_COBRANET_SET;
  1636. } else {
  1637. hm.u.cx.u.cobranet_bigdata.pb_data = pb_data;
  1638. hm.u.cx.attribute = HPI_COBRANET_SET_DATA;
  1639. }
  1640. hpi_send_recv(&hm, &hr);
  1641. return hr.error;
  1642. }
  1643. u16 hpi_cobranet_hmi_read(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  1644. u32 hmi_address, u32 max_byte_count, u32 *pbyte_count, u8 *pb_data)
  1645. {
  1646. struct hpi_message hm;
  1647. struct hpi_response hr;
  1648. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROLEX,
  1649. HPI_CONTROL_GET_STATE);
  1650. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  1651. hm.u.cx.u.cobranet_data.byte_count = max_byte_count;
  1652. hm.u.cx.u.cobranet_data.hmi_address = hmi_address;
  1653. if (max_byte_count <= 8) {
  1654. hm.u.cx.attribute = HPI_COBRANET_GET;
  1655. } else {
  1656. hm.u.cx.u.cobranet_bigdata.pb_data = pb_data;
  1657. hm.u.cx.attribute = HPI_COBRANET_GET_DATA;
  1658. }
  1659. hpi_send_recv(&hm, &hr);
  1660. if (!hr.error && pb_data) {
  1661. *pbyte_count = hr.u.cx.u.cobranet_data.byte_count;
  1662. if (*pbyte_count < max_byte_count)
  1663. max_byte_count = *pbyte_count;
  1664. if (hm.u.cx.attribute == HPI_COBRANET_GET) {
  1665. memcpy(pb_data, hr.u.cx.u.cobranet_data.data,
  1666. max_byte_count);
  1667. } else {
  1668. }
  1669. }
  1670. return hr.error;
  1671. }
  1672. u16 hpi_cobranet_hmi_get_status(const struct hpi_hsubsys *ph_subsys,
  1673. u32 h_control, u32 *pstatus, u32 *preadable_size,
  1674. u32 *pwriteable_size)
  1675. {
  1676. struct hpi_message hm;
  1677. struct hpi_response hr;
  1678. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROLEX,
  1679. HPI_CONTROL_GET_STATE);
  1680. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  1681. hm.u.cx.attribute = HPI_COBRANET_GET_STATUS;
  1682. hpi_send_recv(&hm, &hr);
  1683. if (!hr.error) {
  1684. if (pstatus)
  1685. *pstatus = hr.u.cx.u.cobranet_status.status;
  1686. if (preadable_size)
  1687. *preadable_size =
  1688. hr.u.cx.u.cobranet_status.readable_size;
  1689. if (pwriteable_size)
  1690. *pwriteable_size =
  1691. hr.u.cx.u.cobranet_status.writeable_size;
  1692. }
  1693. return hr.error;
  1694. }
  1695. u16 hpi_cobranet_getI_paddress(const struct hpi_hsubsys *ph_subsys,
  1696. u32 h_control, u32 *pi_paddress)
  1697. {
  1698. u32 byte_count;
  1699. u32 iP;
  1700. u16 error;
  1701. error = hpi_cobranet_hmi_read(ph_subsys, h_control,
  1702. HPI_COBRANET_HMI_cobra_ip_mon_currentIP, 4, &byte_count,
  1703. (u8 *)&iP);
  1704. *pi_paddress =
  1705. ((iP & 0xff000000) >> 8) | ((iP & 0x00ff0000) << 8) | ((iP &
  1706. 0x0000ff00) >> 8) | ((iP & 0x000000ff) << 8);
  1707. if (error)
  1708. *pi_paddress = 0;
  1709. return error;
  1710. }
  1711. u16 hpi_cobranet_setI_paddress(const struct hpi_hsubsys *ph_subsys,
  1712. u32 h_control, u32 i_paddress)
  1713. {
  1714. u32 iP;
  1715. u16 error;
  1716. iP = ((i_paddress & 0xff000000) >> 8) | ((i_paddress & 0x00ff0000) <<
  1717. 8) | ((i_paddress & 0x0000ff00) >> 8) | ((i_paddress &
  1718. 0x000000ff) << 8);
  1719. error = hpi_cobranet_hmi_write(ph_subsys, h_control,
  1720. HPI_COBRANET_HMI_cobra_ip_mon_currentIP, 4, (u8 *)&iP);
  1721. return error;
  1722. }
  1723. u16 hpi_cobranet_get_staticI_paddress(const struct hpi_hsubsys *ph_subsys,
  1724. u32 h_control, u32 *pi_paddress)
  1725. {
  1726. u32 byte_count;
  1727. u32 iP;
  1728. u16 error;
  1729. error = hpi_cobranet_hmi_read(ph_subsys, h_control,
  1730. HPI_COBRANET_HMI_cobra_ip_mon_staticIP, 4, &byte_count,
  1731. (u8 *)&iP);
  1732. *pi_paddress =
  1733. ((iP & 0xff000000) >> 8) | ((iP & 0x00ff0000) << 8) | ((iP &
  1734. 0x0000ff00) >> 8) | ((iP & 0x000000ff) << 8);
  1735. if (error)
  1736. *pi_paddress = 0;
  1737. return error;
  1738. }
  1739. u16 hpi_cobranet_set_staticI_paddress(const struct hpi_hsubsys *ph_subsys,
  1740. u32 h_control, u32 i_paddress)
  1741. {
  1742. u32 iP;
  1743. u16 error;
  1744. iP = ((i_paddress & 0xff000000) >> 8) | ((i_paddress & 0x00ff0000) <<
  1745. 8) | ((i_paddress & 0x0000ff00) >> 8) | ((i_paddress &
  1746. 0x000000ff) << 8);
  1747. error = hpi_cobranet_hmi_write(ph_subsys, h_control,
  1748. HPI_COBRANET_HMI_cobra_ip_mon_staticIP, 4, (u8 *)&iP);
  1749. return error;
  1750. }
  1751. u16 hpi_cobranet_getMA_caddress(const struct hpi_hsubsys *ph_subsys,
  1752. u32 h_control, u32 *pmAC_MS_bs, u32 *pmAC_LS_bs)
  1753. {
  1754. u32 byte_count;
  1755. u16 error;
  1756. u32 mAC;
  1757. error = hpi_cobranet_hmi_read(ph_subsys, h_control,
  1758. HPI_COBRANET_HMI_cobra_if_phy_address, 4, &byte_count,
  1759. (u8 *)&mAC);
  1760. *pmAC_MS_bs =
  1761. ((mAC & 0xff000000) >> 8) | ((mAC & 0x00ff0000) << 8) | ((mAC
  1762. & 0x0000ff00) >> 8) | ((mAC & 0x000000ff) << 8);
  1763. error += hpi_cobranet_hmi_read(ph_subsys, h_control,
  1764. HPI_COBRANET_HMI_cobra_if_phy_address + 1, 4, &byte_count,
  1765. (u8 *)&mAC);
  1766. *pmAC_LS_bs =
  1767. ((mAC & 0xff000000) >> 8) | ((mAC & 0x00ff0000) << 8) | ((mAC
  1768. & 0x0000ff00) >> 8) | ((mAC & 0x000000ff) << 8);
  1769. if (error) {
  1770. *pmAC_MS_bs = 0;
  1771. *pmAC_LS_bs = 0;
  1772. }
  1773. return error;
  1774. }
  1775. u16 hpi_compander_set_enable(const struct hpi_hsubsys *ph_subsys,
  1776. u32 h_control, u32 enable)
  1777. {
  1778. return hpi_control_param_set(ph_subsys, h_control, HPI_GENERIC_ENABLE,
  1779. enable, 0);
  1780. }
  1781. u16 hpi_compander_get_enable(const struct hpi_hsubsys *ph_subsys,
  1782. u32 h_control, u32 *enable)
  1783. {
  1784. return hpi_control_param1_get(ph_subsys, h_control,
  1785. HPI_GENERIC_ENABLE, enable);
  1786. }
  1787. u16 hpi_compander_set_makeup_gain(const struct hpi_hsubsys *ph_subsys,
  1788. u32 h_control, short makeup_gain0_01dB)
  1789. {
  1790. return hpi_control_log_set2(h_control, HPI_COMPANDER_MAKEUPGAIN,
  1791. makeup_gain0_01dB, 0);
  1792. }
  1793. u16 hpi_compander_get_makeup_gain(const struct hpi_hsubsys *ph_subsys,
  1794. u32 h_control, short *makeup_gain0_01dB)
  1795. {
  1796. return hpi_control_log_get2(ph_subsys, h_control,
  1797. HPI_COMPANDER_MAKEUPGAIN, makeup_gain0_01dB, NULL);
  1798. }
  1799. u16 hpi_compander_set_attack_time_constant(const struct hpi_hsubsys
  1800. *ph_subsys, u32 h_control, unsigned int index, u32 attack)
  1801. {
  1802. return hpi_control_param_set(ph_subsys, h_control,
  1803. HPI_COMPANDER_ATTACK, attack, index);
  1804. }
  1805. u16 hpi_compander_get_attack_time_constant(const struct hpi_hsubsys
  1806. *ph_subsys, u32 h_control, unsigned int index, u32 *attack)
  1807. {
  1808. return hpi_control_param_get(ph_subsys, h_control,
  1809. HPI_COMPANDER_ATTACK, 0, index, attack, NULL);
  1810. }
  1811. u16 hpi_compander_set_decay_time_constant(const struct hpi_hsubsys *ph_subsys,
  1812. u32 h_control, unsigned int index, u32 decay)
  1813. {
  1814. return hpi_control_param_set(ph_subsys, h_control,
  1815. HPI_COMPANDER_DECAY, decay, index);
  1816. }
  1817. u16 hpi_compander_get_decay_time_constant(const struct hpi_hsubsys *ph_subsys,
  1818. u32 h_control, unsigned int index, u32 *decay)
  1819. {
  1820. return hpi_control_param_get(ph_subsys, h_control,
  1821. HPI_COMPANDER_DECAY, 0, index, decay, NULL);
  1822. }
  1823. u16 hpi_compander_set_threshold(const struct hpi_hsubsys *ph_subsys,
  1824. u32 h_control, unsigned int index, short threshold0_01dB)
  1825. {
  1826. struct hpi_message hm;
  1827. struct hpi_response hr;
  1828. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1829. HPI_CONTROL_SET_STATE);
  1830. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  1831. hm.u.c.attribute = HPI_COMPANDER_THRESHOLD;
  1832. hm.u.c.param2 = index;
  1833. hm.u.c.an_log_value[0] = threshold0_01dB;
  1834. hpi_send_recv(&hm, &hr);
  1835. return hr.error;
  1836. }
  1837. u16 hpi_compander_get_threshold(const struct hpi_hsubsys *ph_subsys,
  1838. u32 h_control, unsigned int index, short *threshold0_01dB)
  1839. {
  1840. struct hpi_message hm;
  1841. struct hpi_response hr;
  1842. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1843. HPI_CONTROL_GET_STATE);
  1844. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  1845. hm.u.c.attribute = HPI_COMPANDER_THRESHOLD;
  1846. hm.u.c.param2 = index;
  1847. hpi_send_recv(&hm, &hr);
  1848. *threshold0_01dB = hr.u.c.an_log_value[0];
  1849. return hr.error;
  1850. }
  1851. u16 hpi_compander_set_ratio(const struct hpi_hsubsys *ph_subsys,
  1852. u32 h_control, u32 index, u32 ratio100)
  1853. {
  1854. return hpi_control_param_set(ph_subsys, h_control,
  1855. HPI_COMPANDER_RATIO, ratio100, index);
  1856. }
  1857. u16 hpi_compander_get_ratio(const struct hpi_hsubsys *ph_subsys,
  1858. u32 h_control, u32 index, u32 *ratio100)
  1859. {
  1860. return hpi_control_param_get(ph_subsys, h_control,
  1861. HPI_COMPANDER_RATIO, 0, index, ratio100, NULL);
  1862. }
  1863. u16 hpi_level_query_range(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  1864. short *min_gain_01dB, short *max_gain_01dB, short *step_gain_01dB)
  1865. {
  1866. struct hpi_message hm;
  1867. struct hpi_response hr;
  1868. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1869. HPI_CONTROL_GET_STATE);
  1870. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  1871. hm.u.c.attribute = HPI_LEVEL_RANGE;
  1872. hpi_send_recv(&hm, &hr);
  1873. if (hr.error) {
  1874. hr.u.c.an_log_value[0] = 0;
  1875. hr.u.c.an_log_value[1] = 0;
  1876. hr.u.c.param1 = 0;
  1877. }
  1878. if (min_gain_01dB)
  1879. *min_gain_01dB = hr.u.c.an_log_value[0];
  1880. if (max_gain_01dB)
  1881. *max_gain_01dB = hr.u.c.an_log_value[1];
  1882. if (step_gain_01dB)
  1883. *step_gain_01dB = (short)hr.u.c.param1;
  1884. return hr.error;
  1885. }
  1886. u16 hpi_level_set_gain(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  1887. short an_gain0_01dB[HPI_MAX_CHANNELS]
  1888. )
  1889. {
  1890. return hpi_control_log_set2(h_control, HPI_LEVEL_GAIN,
  1891. an_gain0_01dB[0], an_gain0_01dB[1]);
  1892. }
  1893. u16 hpi_level_get_gain(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  1894. short an_gain0_01dB[HPI_MAX_CHANNELS]
  1895. )
  1896. {
  1897. return hpi_control_log_get2(ph_subsys, h_control, HPI_LEVEL_GAIN,
  1898. &an_gain0_01dB[0], &an_gain0_01dB[1]);
  1899. }
  1900. u16 hpi_meter_query_channels(const struct hpi_hsubsys *ph_subsys,
  1901. const u32 h_meter, u32 *p_channels)
  1902. {
  1903. return hpi_control_query(ph_subsys, h_meter, HPI_METER_NUM_CHANNELS,
  1904. 0, 0, p_channels);
  1905. }
  1906. u16 hpi_meter_get_peak(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  1907. short an_peakdB[HPI_MAX_CHANNELS]
  1908. )
  1909. {
  1910. short i = 0;
  1911. struct hpi_message hm;
  1912. struct hpi_response hr;
  1913. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1914. HPI_CONTROL_GET_STATE);
  1915. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  1916. hm.obj_index = hm.obj_index;
  1917. hm.u.c.attribute = HPI_METER_PEAK;
  1918. hpi_send_recv(&hm, &hr);
  1919. if (!hr.error)
  1920. memcpy(an_peakdB, hr.u.c.an_log_value,
  1921. sizeof(short) * HPI_MAX_CHANNELS);
  1922. else
  1923. for (i = 0; i < HPI_MAX_CHANNELS; i++)
  1924. an_peakdB[i] = HPI_METER_MINIMUM;
  1925. return hr.error;
  1926. }
  1927. u16 hpi_meter_get_rms(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  1928. short an_rmsdB[HPI_MAX_CHANNELS]
  1929. )
  1930. {
  1931. short i = 0;
  1932. struct hpi_message hm;
  1933. struct hpi_response hr;
  1934. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1935. HPI_CONTROL_GET_STATE);
  1936. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  1937. hm.u.c.attribute = HPI_METER_RMS;
  1938. hpi_send_recv(&hm, &hr);
  1939. if (!hr.error)
  1940. memcpy(an_rmsdB, hr.u.c.an_log_value,
  1941. sizeof(short) * HPI_MAX_CHANNELS);
  1942. else
  1943. for (i = 0; i < HPI_MAX_CHANNELS; i++)
  1944. an_rmsdB[i] = HPI_METER_MINIMUM;
  1945. return hr.error;
  1946. }
  1947. u16 hpi_meter_set_rms_ballistics(const struct hpi_hsubsys *ph_subsys,
  1948. u32 h_control, u16 attack, u16 decay)
  1949. {
  1950. return hpi_control_param_set(ph_subsys, h_control,
  1951. HPI_METER_RMS_BALLISTICS, attack, decay);
  1952. }
  1953. u16 hpi_meter_get_rms_ballistics(const struct hpi_hsubsys *ph_subsys,
  1954. u32 h_control, u16 *pn_attack, u16 *pn_decay)
  1955. {
  1956. u32 attack;
  1957. u32 decay;
  1958. u16 error;
  1959. error = hpi_control_param2_get(ph_subsys, h_control,
  1960. HPI_METER_RMS_BALLISTICS, &attack, &decay);
  1961. if (pn_attack)
  1962. *pn_attack = (unsigned short)attack;
  1963. if (pn_decay)
  1964. *pn_decay = (unsigned short)decay;
  1965. return error;
  1966. }
  1967. u16 hpi_meter_set_peak_ballistics(const struct hpi_hsubsys *ph_subsys,
  1968. u32 h_control, u16 attack, u16 decay)
  1969. {
  1970. return hpi_control_param_set(ph_subsys, h_control,
  1971. HPI_METER_PEAK_BALLISTICS, attack, decay);
  1972. }
  1973. u16 hpi_meter_get_peak_ballistics(const struct hpi_hsubsys *ph_subsys,
  1974. u32 h_control, u16 *pn_attack, u16 *pn_decay)
  1975. {
  1976. u32 attack;
  1977. u32 decay;
  1978. u16 error;
  1979. error = hpi_control_param2_get(ph_subsys, h_control,
  1980. HPI_METER_PEAK_BALLISTICS, &attack, &decay);
  1981. if (pn_attack)
  1982. *pn_attack = (short)attack;
  1983. if (pn_decay)
  1984. *pn_decay = (short)decay;
  1985. return error;
  1986. }
  1987. u16 hpi_microphone_set_phantom_power(const struct hpi_hsubsys *ph_subsys,
  1988. u32 h_control, u16 on_off)
  1989. {
  1990. return hpi_control_param_set(ph_subsys, h_control,
  1991. HPI_MICROPHONE_PHANTOM_POWER, (u32)on_off, 0);
  1992. }
  1993. u16 hpi_microphone_get_phantom_power(const struct hpi_hsubsys *ph_subsys,
  1994. u32 h_control, u16 *pw_on_off)
  1995. {
  1996. u16 error = 0;
  1997. u32 on_off = 0;
  1998. error = hpi_control_param1_get(ph_subsys, h_control,
  1999. HPI_MICROPHONE_PHANTOM_POWER, &on_off);
  2000. if (pw_on_off)
  2001. *pw_on_off = (u16)on_off;
  2002. return error;
  2003. }
  2004. u16 hpi_multiplexer_set_source(const struct hpi_hsubsys *ph_subsys,
  2005. u32 h_control, u16 source_node_type, u16 source_node_index)
  2006. {
  2007. return hpi_control_param_set(ph_subsys, h_control,
  2008. HPI_MULTIPLEXER_SOURCE, source_node_type, source_node_index);
  2009. }
  2010. u16 hpi_multiplexer_get_source(const struct hpi_hsubsys *ph_subsys,
  2011. u32 h_control, u16 *source_node_type, u16 *source_node_index)
  2012. {
  2013. u32 node, index;
  2014. u16 error = hpi_control_param2_get(ph_subsys, h_control,
  2015. HPI_MULTIPLEXER_SOURCE, &node,
  2016. &index);
  2017. if (source_node_type)
  2018. *source_node_type = (u16)node;
  2019. if (source_node_index)
  2020. *source_node_index = (u16)index;
  2021. return error;
  2022. }
  2023. u16 hpi_multiplexer_query_source(const struct hpi_hsubsys *ph_subsys,
  2024. u32 h_control, u16 index, u16 *source_node_type,
  2025. u16 *source_node_index)
  2026. {
  2027. struct hpi_message hm;
  2028. struct hpi_response hr;
  2029. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  2030. HPI_CONTROL_GET_STATE);
  2031. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  2032. hm.u.c.attribute = HPI_MULTIPLEXER_QUERYSOURCE;
  2033. hm.u.c.param1 = index;
  2034. hpi_send_recv(&hm, &hr);
  2035. if (source_node_type)
  2036. *source_node_type = (u16)hr.u.c.param1;
  2037. if (source_node_index)
  2038. *source_node_index = (u16)hr.u.c.param2;
  2039. return hr.error;
  2040. }
  2041. u16 hpi_parametricEQ__get_info(const struct hpi_hsubsys *ph_subsys,
  2042. u32 h_control, u16 *pw_number_of_bands, u16 *pw_on_off)
  2043. {
  2044. u32 oB = 0;
  2045. u32 oO = 0;
  2046. u16 error = 0;
  2047. error = hpi_control_param2_get(ph_subsys, h_control,
  2048. HPI_EQUALIZER_NUM_FILTERS, &oO, &oB);
  2049. if (pw_number_of_bands)
  2050. *pw_number_of_bands = (u16)oB;
  2051. if (pw_on_off)
  2052. *pw_on_off = (u16)oO;
  2053. return error;
  2054. }
  2055. u16 hpi_parametricEQ__set_state(const struct hpi_hsubsys *ph_subsys,
  2056. u32 h_control, u16 on_off)
  2057. {
  2058. return hpi_control_param_set(ph_subsys, h_control,
  2059. HPI_EQUALIZER_NUM_FILTERS, on_off, 0);
  2060. }
  2061. u16 hpi_parametricEQ__get_band(const struct hpi_hsubsys *ph_subsys,
  2062. u32 h_control, u16 index, u16 *pn_type, u32 *pfrequency_hz,
  2063. short *pnQ100, short *pn_gain0_01dB)
  2064. {
  2065. struct hpi_message hm;
  2066. struct hpi_response hr;
  2067. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  2068. HPI_CONTROL_GET_STATE);
  2069. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  2070. hm.u.c.attribute = HPI_EQUALIZER_FILTER;
  2071. hm.u.c.param2 = index;
  2072. hpi_send_recv(&hm, &hr);
  2073. if (pfrequency_hz)
  2074. *pfrequency_hz = hr.u.c.param1;
  2075. if (pn_type)
  2076. *pn_type = (u16)(hr.u.c.param2 >> 16);
  2077. if (pnQ100)
  2078. *pnQ100 = hr.u.c.an_log_value[1];
  2079. if (pn_gain0_01dB)
  2080. *pn_gain0_01dB = hr.u.c.an_log_value[0];
  2081. return hr.error;
  2082. }
  2083. u16 hpi_parametricEQ__set_band(const struct hpi_hsubsys *ph_subsys,
  2084. u32 h_control, u16 index, u16 type, u32 frequency_hz, short q100,
  2085. short gain0_01dB)
  2086. {
  2087. struct hpi_message hm;
  2088. struct hpi_response hr;
  2089. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  2090. HPI_CONTROL_SET_STATE);
  2091. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  2092. hm.u.c.param1 = frequency_hz;
  2093. hm.u.c.param2 = (index & 0xFFFFL) + ((u32)type << 16);
  2094. hm.u.c.an_log_value[0] = gain0_01dB;
  2095. hm.u.c.an_log_value[1] = q100;
  2096. hm.u.c.attribute = HPI_EQUALIZER_FILTER;
  2097. hpi_send_recv(&hm, &hr);
  2098. return hr.error;
  2099. }
  2100. u16 hpi_parametricEQ__get_coeffs(const struct hpi_hsubsys *ph_subsys,
  2101. u32 h_control, u16 index, short coeffs[5]
  2102. )
  2103. {
  2104. struct hpi_message hm;
  2105. struct hpi_response hr;
  2106. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  2107. HPI_CONTROL_GET_STATE);
  2108. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  2109. hm.u.c.attribute = HPI_EQUALIZER_COEFFICIENTS;
  2110. hm.u.c.param2 = index;
  2111. hpi_send_recv(&hm, &hr);
  2112. coeffs[0] = (short)hr.u.c.an_log_value[0];
  2113. coeffs[1] = (short)hr.u.c.an_log_value[1];
  2114. coeffs[2] = (short)hr.u.c.param1;
  2115. coeffs[3] = (short)(hr.u.c.param1 >> 16);
  2116. coeffs[4] = (short)hr.u.c.param2;
  2117. return hr.error;
  2118. }
  2119. u16 hpi_sample_clock_query_source(const struct hpi_hsubsys *ph_subsys,
  2120. const u32 h_clock, const u32 index, u16 *pw_source)
  2121. {
  2122. u32 qr;
  2123. u16 err;
  2124. err = hpi_control_query(ph_subsys, h_clock, HPI_SAMPLECLOCK_SOURCE,
  2125. index, 0, &qr);
  2126. *pw_source = (u16)qr;
  2127. return err;
  2128. }
  2129. u16 hpi_sample_clock_set_source(const struct hpi_hsubsys *ph_subsys,
  2130. u32 h_control, u16 source)
  2131. {
  2132. return hpi_control_param_set(ph_subsys, h_control,
  2133. HPI_SAMPLECLOCK_SOURCE, source, 0);
  2134. }
  2135. u16 hpi_sample_clock_get_source(const struct hpi_hsubsys *ph_subsys,
  2136. u32 h_control, u16 *pw_source)
  2137. {
  2138. u16 error = 0;
  2139. u32 source = 0;
  2140. error = hpi_control_param1_get(ph_subsys, h_control,
  2141. HPI_SAMPLECLOCK_SOURCE, &source);
  2142. if (!error)
  2143. if (pw_source)
  2144. *pw_source = (u16)source;
  2145. return error;
  2146. }
  2147. u16 hpi_sample_clock_query_source_index(const struct hpi_hsubsys *ph_subsys,
  2148. const u32 h_clock, const u32 index, const u32 source,
  2149. u16 *pw_source_index)
  2150. {
  2151. u32 qr;
  2152. u16 err;
  2153. err = hpi_control_query(ph_subsys, h_clock,
  2154. HPI_SAMPLECLOCK_SOURCE_INDEX, index, source, &qr);
  2155. *pw_source_index = (u16)qr;
  2156. return err;
  2157. }
  2158. u16 hpi_sample_clock_set_source_index(const struct hpi_hsubsys *ph_subsys,
  2159. u32 h_control, u16 source_index)
  2160. {
  2161. return hpi_control_param_set(ph_subsys, h_control,
  2162. HPI_SAMPLECLOCK_SOURCE_INDEX, source_index, 0);
  2163. }
  2164. u16 hpi_sample_clock_get_source_index(const struct hpi_hsubsys *ph_subsys,
  2165. u32 h_control, u16 *pw_source_index)
  2166. {
  2167. u16 error = 0;
  2168. u32 source_index = 0;
  2169. error = hpi_control_param1_get(ph_subsys, h_control,
  2170. HPI_SAMPLECLOCK_SOURCE_INDEX, &source_index);
  2171. if (!error)
  2172. if (pw_source_index)
  2173. *pw_source_index = (u16)source_index;
  2174. return error;
  2175. }
  2176. u16 hpi_sample_clock_query_local_rate(const struct hpi_hsubsys *ph_subsys,
  2177. const u32 h_clock, const u32 index, u32 *prate)
  2178. {
  2179. u16 err;
  2180. err = hpi_control_query(ph_subsys, h_clock,
  2181. HPI_SAMPLECLOCK_LOCAL_SAMPLERATE, index, 0, prate);
  2182. return err;
  2183. }
  2184. u16 hpi_sample_clock_set_local_rate(const struct hpi_hsubsys *ph_subsys,
  2185. u32 h_control, u32 sample_rate)
  2186. {
  2187. return hpi_control_param_set(ph_subsys, h_control,
  2188. HPI_SAMPLECLOCK_LOCAL_SAMPLERATE, sample_rate, 0);
  2189. }
  2190. u16 hpi_sample_clock_get_local_rate(const struct hpi_hsubsys *ph_subsys,
  2191. u32 h_control, u32 *psample_rate)
  2192. {
  2193. u16 error = 0;
  2194. u32 sample_rate = 0;
  2195. error = hpi_control_param1_get(ph_subsys, h_control,
  2196. HPI_SAMPLECLOCK_LOCAL_SAMPLERATE, &sample_rate);
  2197. if (!error)
  2198. if (psample_rate)
  2199. *psample_rate = sample_rate;
  2200. return error;
  2201. }
  2202. u16 hpi_sample_clock_get_sample_rate(const struct hpi_hsubsys *ph_subsys,
  2203. u32 h_control, u32 *psample_rate)
  2204. {
  2205. u16 error = 0;
  2206. u32 sample_rate = 0;
  2207. error = hpi_control_param1_get(ph_subsys, h_control,
  2208. HPI_SAMPLECLOCK_SAMPLERATE, &sample_rate);
  2209. if (!error)
  2210. if (psample_rate)
  2211. *psample_rate = sample_rate;
  2212. return error;
  2213. }
  2214. u16 hpi_sample_clock_set_auto(const struct hpi_hsubsys *ph_subsys,
  2215. u32 h_control, u32 enable)
  2216. {
  2217. return hpi_control_param_set(ph_subsys, h_control,
  2218. HPI_SAMPLECLOCK_AUTO, enable, 0);
  2219. }
  2220. u16 hpi_sample_clock_get_auto(const struct hpi_hsubsys *ph_subsys,
  2221. u32 h_control, u32 *penable)
  2222. {
  2223. return hpi_control_param1_get(ph_subsys, h_control,
  2224. HPI_SAMPLECLOCK_AUTO, penable);
  2225. }
  2226. u16 hpi_sample_clock_set_local_rate_lock(const struct hpi_hsubsys *ph_subsys,
  2227. u32 h_control, u32 lock)
  2228. {
  2229. return hpi_control_param_set(ph_subsys, h_control,
  2230. HPI_SAMPLECLOCK_LOCAL_LOCK, lock, 0);
  2231. }
  2232. u16 hpi_sample_clock_get_local_rate_lock(const struct hpi_hsubsys *ph_subsys,
  2233. u32 h_control, u32 *plock)
  2234. {
  2235. return hpi_control_param1_get(ph_subsys, h_control,
  2236. HPI_SAMPLECLOCK_LOCAL_LOCK, plock);
  2237. }
  2238. u16 hpi_tone_detector_get_frequency(const struct hpi_hsubsys *ph_subsys,
  2239. u32 h_control, u32 index, u32 *frequency)
  2240. {
  2241. return hpi_control_param_get(ph_subsys, h_control,
  2242. HPI_TONEDETECTOR_FREQUENCY, index, 0, frequency, NULL);
  2243. }
  2244. u16 hpi_tone_detector_get_state(const struct hpi_hsubsys *ph_subsys,
  2245. u32 h_control, u32 *state)
  2246. {
  2247. return hpi_control_param1_get(ph_subsys, h_control,
  2248. HPI_TONEDETECTOR_STATE, state);
  2249. }
  2250. u16 hpi_tone_detector_set_enable(const struct hpi_hsubsys *ph_subsys,
  2251. u32 h_control, u32 enable)
  2252. {
  2253. return hpi_control_param_set(ph_subsys, h_control, HPI_GENERIC_ENABLE,
  2254. (u32)enable, 0);
  2255. }
  2256. u16 hpi_tone_detector_get_enable(const struct hpi_hsubsys *ph_subsys,
  2257. u32 h_control, u32 *enable)
  2258. {
  2259. return hpi_control_param1_get(ph_subsys, h_control,
  2260. HPI_GENERIC_ENABLE, enable);
  2261. }
  2262. u16 hpi_tone_detector_set_event_enable(const struct hpi_hsubsys *ph_subsys,
  2263. u32 h_control, u32 event_enable)
  2264. {
  2265. return hpi_control_param_set(ph_subsys, h_control,
  2266. HPI_GENERIC_EVENT_ENABLE, (u32)event_enable, 0);
  2267. }
  2268. u16 hpi_tone_detector_get_event_enable(const struct hpi_hsubsys *ph_subsys,
  2269. u32 h_control, u32 *event_enable)
  2270. {
  2271. return hpi_control_param1_get(ph_subsys, h_control,
  2272. HPI_GENERIC_EVENT_ENABLE, event_enable);
  2273. }
  2274. u16 hpi_tone_detector_set_threshold(const struct hpi_hsubsys *ph_subsys,
  2275. u32 h_control, int threshold)
  2276. {
  2277. return hpi_control_param_set(ph_subsys, h_control,
  2278. HPI_TONEDETECTOR_THRESHOLD, (u32)threshold, 0);
  2279. }
  2280. u16 hpi_tone_detector_get_threshold(const struct hpi_hsubsys *ph_subsys,
  2281. u32 h_control, int *threshold)
  2282. {
  2283. return hpi_control_param1_get(ph_subsys, h_control,
  2284. HPI_TONEDETECTOR_THRESHOLD, (u32 *)threshold);
  2285. }
  2286. u16 hpi_silence_detector_get_state(const struct hpi_hsubsys *ph_subsys,
  2287. u32 h_control, u32 *state)
  2288. {
  2289. return hpi_control_param1_get(ph_subsys, h_control,
  2290. HPI_SILENCEDETECTOR_STATE, state);
  2291. }
  2292. u16 hpi_silence_detector_set_enable(const struct hpi_hsubsys *ph_subsys,
  2293. u32 h_control, u32 enable)
  2294. {
  2295. return hpi_control_param_set(ph_subsys, h_control, HPI_GENERIC_ENABLE,
  2296. (u32)enable, 0);
  2297. }
  2298. u16 hpi_silence_detector_get_enable(const struct hpi_hsubsys *ph_subsys,
  2299. u32 h_control, u32 *enable)
  2300. {
  2301. return hpi_control_param1_get(ph_subsys, h_control,
  2302. HPI_GENERIC_ENABLE, enable);
  2303. }
  2304. u16 hpi_silence_detector_set_event_enable(const struct hpi_hsubsys *ph_subsys,
  2305. u32 h_control, u32 event_enable)
  2306. {
  2307. return hpi_control_param_set(ph_subsys, h_control,
  2308. HPI_GENERIC_EVENT_ENABLE, event_enable, 0);
  2309. }
  2310. u16 hpi_silence_detector_get_event_enable(const struct hpi_hsubsys *ph_subsys,
  2311. u32 h_control, u32 *event_enable)
  2312. {
  2313. return hpi_control_param1_get(ph_subsys, h_control,
  2314. HPI_GENERIC_EVENT_ENABLE, event_enable);
  2315. }
  2316. u16 hpi_silence_detector_set_delay(const struct hpi_hsubsys *ph_subsys,
  2317. u32 h_control, u32 delay)
  2318. {
  2319. return hpi_control_param_set(ph_subsys, h_control,
  2320. HPI_SILENCEDETECTOR_DELAY, delay, 0);
  2321. }
  2322. u16 hpi_silence_detector_get_delay(const struct hpi_hsubsys *ph_subsys,
  2323. u32 h_control, u32 *delay)
  2324. {
  2325. return hpi_control_param1_get(ph_subsys, h_control,
  2326. HPI_SILENCEDETECTOR_DELAY, delay);
  2327. }
  2328. u16 hpi_silence_detector_set_threshold(const struct hpi_hsubsys *ph_subsys,
  2329. u32 h_control, int threshold)
  2330. {
  2331. return hpi_control_param_set(ph_subsys, h_control,
  2332. HPI_SILENCEDETECTOR_THRESHOLD, threshold, 0);
  2333. }
  2334. u16 hpi_silence_detector_get_threshold(const struct hpi_hsubsys *ph_subsys,
  2335. u32 h_control, int *threshold)
  2336. {
  2337. return hpi_control_param1_get(ph_subsys, h_control,
  2338. HPI_SILENCEDETECTOR_THRESHOLD, (u32 *)threshold);
  2339. }
  2340. u16 hpi_tuner_query_band(const struct hpi_hsubsys *ph_subsys,
  2341. const u32 h_tuner, const u32 index, u16 *pw_band)
  2342. {
  2343. u32 qr;
  2344. u16 err;
  2345. err = hpi_control_query(ph_subsys, h_tuner, HPI_TUNER_BAND, index, 0,
  2346. &qr);
  2347. *pw_band = (u16)qr;
  2348. return err;
  2349. }
  2350. u16 hpi_tuner_set_band(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  2351. u16 band)
  2352. {
  2353. return hpi_control_param_set(ph_subsys, h_control, HPI_TUNER_BAND,
  2354. band, 0);
  2355. }
  2356. u16 hpi_tuner_get_band(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  2357. u16 *pw_band)
  2358. {
  2359. u32 band = 0;
  2360. u16 error = 0;
  2361. error = hpi_control_param1_get(ph_subsys, h_control, HPI_TUNER_BAND,
  2362. &band);
  2363. if (pw_band)
  2364. *pw_band = (u16)band;
  2365. return error;
  2366. }
  2367. u16 hpi_tuner_query_frequency(const struct hpi_hsubsys *ph_subsys,
  2368. const u32 h_tuner, const u32 index, const u16 band, u32 *pfreq)
  2369. {
  2370. return hpi_control_query(ph_subsys, h_tuner, HPI_TUNER_FREQ, index,
  2371. band, pfreq);
  2372. }
  2373. u16 hpi_tuner_set_frequency(const struct hpi_hsubsys *ph_subsys,
  2374. u32 h_control, u32 freq_ink_hz)
  2375. {
  2376. return hpi_control_param_set(ph_subsys, h_control, HPI_TUNER_FREQ,
  2377. freq_ink_hz, 0);
  2378. }
  2379. u16 hpi_tuner_get_frequency(const struct hpi_hsubsys *ph_subsys,
  2380. u32 h_control, u32 *pw_freq_ink_hz)
  2381. {
  2382. return hpi_control_param1_get(ph_subsys, h_control, HPI_TUNER_FREQ,
  2383. pw_freq_ink_hz);
  2384. }
  2385. u16 hpi_tuner_query_gain(const struct hpi_hsubsys *ph_subsys,
  2386. const u32 h_tuner, const u32 index, u16 *pw_gain)
  2387. {
  2388. u32 qr;
  2389. u16 err;
  2390. err = hpi_control_query(ph_subsys, h_tuner, HPI_TUNER_BAND, index, 0,
  2391. &qr);
  2392. *pw_gain = (u16)qr;
  2393. return err;
  2394. }
  2395. u16 hpi_tuner_set_gain(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  2396. short gain)
  2397. {
  2398. return hpi_control_param_set(ph_subsys, h_control, HPI_TUNER_GAIN,
  2399. gain, 0);
  2400. }
  2401. u16 hpi_tuner_get_gain(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  2402. short *pn_gain)
  2403. {
  2404. u32 gain = 0;
  2405. u16 error = 0;
  2406. error = hpi_control_param1_get(ph_subsys, h_control, HPI_TUNER_GAIN,
  2407. &gain);
  2408. if (pn_gain)
  2409. *pn_gain = (u16)gain;
  2410. return error;
  2411. }
  2412. u16 hpi_tuner_getRF_level(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  2413. short *pw_level)
  2414. {
  2415. struct hpi_message hm;
  2416. struct hpi_response hr;
  2417. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  2418. HPI_CONTROL_GET_STATE);
  2419. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  2420. hm.u.c.attribute = HPI_TUNER_LEVEL;
  2421. hm.u.c.param1 = HPI_TUNER_LEVEL_AVERAGE;
  2422. hpi_send_recv(&hm, &hr);
  2423. if (pw_level)
  2424. *pw_level = (short)hr.u.c.param1;
  2425. return hr.error;
  2426. }
  2427. u16 hpi_tuner_get_rawRF_level(const struct hpi_hsubsys *ph_subsys,
  2428. u32 h_control, short *pw_level)
  2429. {
  2430. struct hpi_message hm;
  2431. struct hpi_response hr;
  2432. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  2433. HPI_CONTROL_GET_STATE);
  2434. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  2435. hm.u.c.attribute = HPI_TUNER_LEVEL;
  2436. hm.u.c.param1 = HPI_TUNER_LEVEL_RAW;
  2437. hpi_send_recv(&hm, &hr);
  2438. if (pw_level)
  2439. *pw_level = (short)hr.u.c.param1;
  2440. return hr.error;
  2441. }
  2442. u16 hpi_tuner_query_deemphasis(const struct hpi_hsubsys *ph_subsys,
  2443. const u32 h_tuner, const u32 index, const u16 band, u32 *pdeemphasis)
  2444. {
  2445. return hpi_control_query(ph_subsys, h_tuner, HPI_TUNER_DEEMPHASIS,
  2446. index, band, pdeemphasis);
  2447. }
  2448. u16 hpi_tuner_set_deemphasis(const struct hpi_hsubsys *ph_subsys,
  2449. u32 h_control, u32 deemphasis)
  2450. {
  2451. return hpi_control_param_set(ph_subsys, h_control,
  2452. HPI_TUNER_DEEMPHASIS, deemphasis, 0);
  2453. }
  2454. u16 hpi_tuner_get_deemphasis(const struct hpi_hsubsys *ph_subsys,
  2455. u32 h_control, u32 *pdeemphasis)
  2456. {
  2457. return hpi_control_param1_get(ph_subsys, h_control,
  2458. HPI_TUNER_DEEMPHASIS, pdeemphasis);
  2459. }
  2460. u16 hpi_tuner_query_program(const struct hpi_hsubsys *ph_subsys,
  2461. const u32 h_tuner, u32 *pbitmap_program)
  2462. {
  2463. return hpi_control_query(ph_subsys, h_tuner, HPI_TUNER_PROGRAM, 0, 0,
  2464. pbitmap_program);
  2465. }
  2466. u16 hpi_tuner_set_program(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  2467. u32 program)
  2468. {
  2469. return hpi_control_param_set(ph_subsys, h_control, HPI_TUNER_PROGRAM,
  2470. program, 0);
  2471. }
  2472. u16 hpi_tuner_get_program(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  2473. u32 *pprogram)
  2474. {
  2475. return hpi_control_param1_get(ph_subsys, h_control, HPI_TUNER_PROGRAM,
  2476. pprogram);
  2477. }
  2478. u16 hpi_tuner_get_hd_radio_dsp_version(const struct hpi_hsubsys *ph_subsys,
  2479. u32 h_control, char *psz_dsp_version, const u32 string_size)
  2480. {
  2481. return hpi_control_get_string(h_control,
  2482. HPI_TUNER_HDRADIO_DSP_VERSION, psz_dsp_version, string_size);
  2483. }
  2484. u16 hpi_tuner_get_hd_radio_sdk_version(const struct hpi_hsubsys *ph_subsys,
  2485. u32 h_control, char *psz_sdk_version, const u32 string_size)
  2486. {
  2487. return hpi_control_get_string(h_control,
  2488. HPI_TUNER_HDRADIO_SDK_VERSION, psz_sdk_version, string_size);
  2489. }
  2490. u16 hpi_tuner_get_status(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  2491. u16 *pw_status_mask, u16 *pw_status)
  2492. {
  2493. u32 status = 0;
  2494. u16 error = 0;
  2495. error = hpi_control_param1_get(ph_subsys, h_control, HPI_TUNER_STATUS,
  2496. &status);
  2497. if (pw_status) {
  2498. if (!error) {
  2499. *pw_status_mask = (u16)(status >> 16);
  2500. *pw_status = (u16)(status & 0xFFFF);
  2501. } else {
  2502. *pw_status_mask = 0;
  2503. *pw_status = 0;
  2504. }
  2505. }
  2506. return error;
  2507. }
  2508. u16 hpi_tuner_set_mode(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  2509. u32 mode, u32 value)
  2510. {
  2511. return hpi_control_param_set(ph_subsys, h_control, HPI_TUNER_MODE,
  2512. mode, value);
  2513. }
  2514. u16 hpi_tuner_get_mode(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  2515. u32 mode, u32 *pn_value)
  2516. {
  2517. return hpi_control_param_get(ph_subsys, h_control, HPI_TUNER_MODE,
  2518. mode, 0, pn_value, NULL);
  2519. }
  2520. u16 hpi_tuner_get_hd_radio_signal_quality(const struct hpi_hsubsys *ph_subsys,
  2521. u32 h_control, u32 *pquality)
  2522. {
  2523. return hpi_control_param1_get(ph_subsys, h_control,
  2524. HPI_TUNER_HDRADIO_SIGNAL_QUALITY, pquality);
  2525. }
  2526. u16 hpi_tuner_get_hd_radio_signal_blend(const struct hpi_hsubsys *ph_subsys,
  2527. u32 h_control, u32 *pblend)
  2528. {
  2529. return hpi_control_param1_get(ph_subsys, h_control,
  2530. HPI_TUNER_HDRADIO_BLEND, pblend);
  2531. }
  2532. u16 hpi_tuner_set_hd_radio_signal_blend(const struct hpi_hsubsys *ph_subsys,
  2533. u32 h_control, const u32 blend)
  2534. {
  2535. return hpi_control_param_set(ph_subsys, h_control,
  2536. HPI_TUNER_HDRADIO_BLEND, blend, 0);
  2537. }
  2538. u16 hpi_tuner_getRDS(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  2539. char *p_data)
  2540. {
  2541. struct hpi_message hm;
  2542. struct hpi_response hr;
  2543. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  2544. HPI_CONTROL_GET_STATE);
  2545. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  2546. hm.u.c.attribute = HPI_TUNER_RDS;
  2547. hpi_send_recv(&hm, &hr);
  2548. if (p_data) {
  2549. *(u32 *)&p_data[0] = hr.u.cu.tuner.rds.data[0];
  2550. *(u32 *)&p_data[4] = hr.u.cu.tuner.rds.data[1];
  2551. *(u32 *)&p_data[8] = hr.u.cu.tuner.rds.bLER;
  2552. }
  2553. return hr.error;
  2554. }
  2555. u16 HPI_PAD__get_channel_name(const struct hpi_hsubsys *ph_subsys,
  2556. u32 h_control, char *psz_string, const u32 data_length)
  2557. {
  2558. return hpi_control_get_string(h_control, HPI_PAD_CHANNEL_NAME,
  2559. psz_string, data_length);
  2560. }
  2561. u16 HPI_PAD__get_artist(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  2562. char *psz_string, const u32 data_length)
  2563. {
  2564. return hpi_control_get_string(h_control, HPI_PAD_ARTIST, psz_string,
  2565. data_length);
  2566. }
  2567. u16 HPI_PAD__get_title(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  2568. char *psz_string, const u32 data_length)
  2569. {
  2570. return hpi_control_get_string(h_control, HPI_PAD_TITLE, psz_string,
  2571. data_length);
  2572. }
  2573. u16 HPI_PAD__get_comment(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  2574. char *psz_string, const u32 data_length)
  2575. {
  2576. return hpi_control_get_string(h_control, HPI_PAD_COMMENT, psz_string,
  2577. data_length);
  2578. }
  2579. u16 HPI_PAD__get_program_type(const struct hpi_hsubsys *ph_subsys,
  2580. u32 h_control, u32 *ppTY)
  2581. {
  2582. return hpi_control_param1_get(ph_subsys, h_control,
  2583. HPI_PAD_PROGRAM_TYPE, ppTY);
  2584. }
  2585. u16 HPI_PAD__get_rdsPI(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  2586. u32 *ppI)
  2587. {
  2588. return hpi_control_param1_get(ph_subsys, h_control,
  2589. HPI_PAD_PROGRAM_ID, ppI);
  2590. }
  2591. u16 hpi_volume_query_channels(const struct hpi_hsubsys *ph_subsys,
  2592. const u32 h_volume, u32 *p_channels)
  2593. {
  2594. return hpi_control_query(ph_subsys, h_volume, HPI_VOLUME_NUM_CHANNELS,
  2595. 0, 0, p_channels);
  2596. }
  2597. u16 hpi_volume_set_gain(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  2598. short an_log_gain[HPI_MAX_CHANNELS]
  2599. )
  2600. {
  2601. return hpi_control_log_set2(h_control, HPI_VOLUME_GAIN,
  2602. an_log_gain[0], an_log_gain[1]);
  2603. }
  2604. u16 hpi_volume_get_gain(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  2605. short an_log_gain[HPI_MAX_CHANNELS]
  2606. )
  2607. {
  2608. return hpi_control_log_get2(ph_subsys, h_control, HPI_VOLUME_GAIN,
  2609. &an_log_gain[0], &an_log_gain[1]);
  2610. }
  2611. u16 hpi_volume_query_range(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  2612. short *min_gain_01dB, short *max_gain_01dB, short *step_gain_01dB)
  2613. {
  2614. struct hpi_message hm;
  2615. struct hpi_response hr;
  2616. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  2617. HPI_CONTROL_GET_STATE);
  2618. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  2619. hm.u.c.attribute = HPI_VOLUME_RANGE;
  2620. hpi_send_recv(&hm, &hr);
  2621. if (hr.error) {
  2622. hr.u.c.an_log_value[0] = 0;
  2623. hr.u.c.an_log_value[1] = 0;
  2624. hr.u.c.param1 = 0;
  2625. }
  2626. if (min_gain_01dB)
  2627. *min_gain_01dB = hr.u.c.an_log_value[0];
  2628. if (max_gain_01dB)
  2629. *max_gain_01dB = hr.u.c.an_log_value[1];
  2630. if (step_gain_01dB)
  2631. *step_gain_01dB = (short)hr.u.c.param1;
  2632. return hr.error;
  2633. }
  2634. u16 hpi_volume_auto_fade_profile(const struct hpi_hsubsys *ph_subsys,
  2635. u32 h_control, short an_stop_gain0_01dB[HPI_MAX_CHANNELS],
  2636. u32 duration_ms, u16 profile)
  2637. {
  2638. struct hpi_message hm;
  2639. struct hpi_response hr;
  2640. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  2641. HPI_CONTROL_SET_STATE);
  2642. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  2643. memcpy(hm.u.c.an_log_value, an_stop_gain0_01dB,
  2644. sizeof(short) * HPI_MAX_CHANNELS);
  2645. hm.u.c.attribute = HPI_VOLUME_AUTOFADE;
  2646. hm.u.c.param1 = duration_ms;
  2647. hm.u.c.param2 = profile;
  2648. hpi_send_recv(&hm, &hr);
  2649. return hr.error;
  2650. }
  2651. u16 hpi_volume_auto_fade(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  2652. short an_stop_gain0_01dB[HPI_MAX_CHANNELS], u32 duration_ms)
  2653. {
  2654. return hpi_volume_auto_fade_profile(ph_subsys, h_control,
  2655. an_stop_gain0_01dB, duration_ms, HPI_VOLUME_AUTOFADE_LOG);
  2656. }
  2657. u16 hpi_vox_set_threshold(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  2658. short an_gain0_01dB)
  2659. {
  2660. struct hpi_message hm;
  2661. struct hpi_response hr;
  2662. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  2663. HPI_CONTROL_SET_STATE);
  2664. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  2665. hm.u.c.attribute = HPI_VOX_THRESHOLD;
  2666. hm.u.c.an_log_value[0] = an_gain0_01dB;
  2667. hpi_send_recv(&hm, &hr);
  2668. return hr.error;
  2669. }
  2670. u16 hpi_vox_get_threshold(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  2671. short *an_gain0_01dB)
  2672. {
  2673. struct hpi_message hm;
  2674. struct hpi_response hr;
  2675. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  2676. HPI_CONTROL_GET_STATE);
  2677. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  2678. hm.u.c.attribute = HPI_VOX_THRESHOLD;
  2679. hpi_send_recv(&hm, &hr);
  2680. *an_gain0_01dB = hr.u.c.an_log_value[0];
  2681. return hr.error;
  2682. }
  2683. static size_t strv_packet_size = MIN_STRV_PACKET_SIZE;
  2684. static size_t entity_type_to_size[LAST_ENTITY_TYPE] = {
  2685. 0,
  2686. sizeof(struct hpi_entity),
  2687. sizeof(void *),
  2688. sizeof(int),
  2689. sizeof(float),
  2690. sizeof(double),
  2691. sizeof(char),
  2692. sizeof(char),
  2693. 4 * sizeof(char),
  2694. 16 * sizeof(char),
  2695. 6 * sizeof(char),
  2696. };
  2697. static inline size_t hpi_entity_size(struct hpi_entity *entity_ptr)
  2698. {
  2699. return entity_ptr->header.size;
  2700. }
  2701. static inline size_t hpi_entity_header_size(struct hpi_entity *entity_ptr)
  2702. {
  2703. return sizeof(entity_ptr->header);
  2704. }
  2705. static inline size_t hpi_entity_value_size(struct hpi_entity *entity_ptr)
  2706. {
  2707. return hpi_entity_size(entity_ptr) -
  2708. hpi_entity_header_size(entity_ptr);
  2709. }
  2710. static inline size_t hpi_entity_item_count(struct hpi_entity *entity_ptr)
  2711. {
  2712. return hpi_entity_value_size(entity_ptr) /
  2713. entity_type_to_size[entity_ptr->header.type];
  2714. }
  2715. static inline struct hpi_entity *hpi_entity_ptr_to_next(struct hpi_entity
  2716. *entity_ptr)
  2717. {
  2718. return (void *)(((u8 *)entity_ptr) + hpi_entity_size(entity_ptr));
  2719. }
  2720. static inline u16 hpi_entity_check_type(const enum e_entity_type t)
  2721. {
  2722. if (t >= 0 && t < STR_TYPE_FIELD_MAX)
  2723. return 0;
  2724. return HPI_ERROR_ENTITY_TYPE_INVALID;
  2725. }
  2726. static inline u16 hpi_entity_check_role(const enum e_entity_role r)
  2727. {
  2728. if (r >= 0 && r < STR_ROLE_FIELD_MAX)
  2729. return 0;
  2730. return HPI_ERROR_ENTITY_ROLE_INVALID;
  2731. }
  2732. static u16 hpi_entity_get_next(struct hpi_entity *entity, int recursive_flag,
  2733. void *guard_p, struct hpi_entity **next)
  2734. {
  2735. HPI_DEBUG_ASSERT(entity != NULL);
  2736. HPI_DEBUG_ASSERT(next != NULL);
  2737. HPI_DEBUG_ASSERT(hpi_entity_size(entity) != 0);
  2738. if (guard_p <= (void *)entity) {
  2739. *next = NULL;
  2740. return 0;
  2741. }
  2742. if (recursive_flag && entity->header.type == entity_type_sequence)
  2743. *next = (struct hpi_entity *)entity->value;
  2744. else
  2745. *next = (struct hpi_entity *)hpi_entity_ptr_to_next(entity);
  2746. if (guard_p <= (void *)*next) {
  2747. *next = NULL;
  2748. return 0;
  2749. }
  2750. HPI_DEBUG_ASSERT(guard_p >= (void *)hpi_entity_ptr_to_next(*next));
  2751. return 0;
  2752. }
  2753. u16 hpi_entity_find_next(struct hpi_entity *container_entity,
  2754. enum e_entity_type type, enum e_entity_role role, int recursive_flag,
  2755. struct hpi_entity **current_match)
  2756. {
  2757. struct hpi_entity *tmp = NULL;
  2758. void *guard_p = NULL;
  2759. HPI_DEBUG_ASSERT(container_entity != NULL);
  2760. guard_p = hpi_entity_ptr_to_next(container_entity);
  2761. if (*current_match != NULL)
  2762. hpi_entity_get_next(*current_match, recursive_flag, guard_p,
  2763. &tmp);
  2764. else
  2765. hpi_entity_get_next(container_entity, 1, guard_p, &tmp);
  2766. while (tmp) {
  2767. u16 err;
  2768. HPI_DEBUG_ASSERT((void *)tmp >= (void *)container_entity);
  2769. if ((!type || tmp->header.type == type) && (!role
  2770. || tmp->header.role == role)) {
  2771. *current_match = tmp;
  2772. return 0;
  2773. }
  2774. err = hpi_entity_get_next(tmp, recursive_flag, guard_p,
  2775. current_match);
  2776. if (err)
  2777. return err;
  2778. tmp = *current_match;
  2779. }
  2780. *current_match = NULL;
  2781. return 0;
  2782. }
  2783. void hpi_entity_free(struct hpi_entity *entity)
  2784. {
  2785. kfree(entity);
  2786. }
  2787. static u16 hpi_entity_alloc_and_copy(struct hpi_entity *src,
  2788. struct hpi_entity **dst)
  2789. {
  2790. size_t buf_size;
  2791. HPI_DEBUG_ASSERT(dst != NULL);
  2792. HPI_DEBUG_ASSERT(src != NULL);
  2793. buf_size = hpi_entity_size(src);
  2794. *dst = kmalloc(buf_size, GFP_KERNEL);
  2795. if (*dst == NULL)
  2796. return HPI_ERROR_MEMORY_ALLOC;
  2797. memcpy(*dst, src, buf_size);
  2798. return 0;
  2799. }
  2800. u16 hpi_universal_info(const struct hpi_hsubsys *ph_subsys, u32 hC,
  2801. struct hpi_entity **info)
  2802. {
  2803. struct hpi_msg_strv hm;
  2804. struct hpi_res_strv *phr;
  2805. u16 hpi_err;
  2806. int remaining_attempts = 2;
  2807. size_t resp_packet_size = 1024;
  2808. *info = NULL;
  2809. while (remaining_attempts--) {
  2810. phr = kmalloc(resp_packet_size, GFP_KERNEL);
  2811. HPI_DEBUG_ASSERT(phr != NULL);
  2812. hpi_init_message_responseV1(&hm.h, (u16)sizeof(hm), &phr->h,
  2813. (u16)resp_packet_size, HPI_OBJ_CONTROL,
  2814. HPI_CONTROL_GET_INFO);
  2815. u32TOINDEXES(hC, &hm.h.adapter_index, &hm.h.obj_index);
  2816. hm.strv.header.size = sizeof(hm.strv);
  2817. phr->strv.header.size = resp_packet_size - sizeof(phr->h);
  2818. hpi_send_recv((struct hpi_message *)&hm.h,
  2819. (struct hpi_response *)&phr->h);
  2820. if (phr->h.error == HPI_ERROR_RESPONSE_BUFFER_TOO_SMALL) {
  2821. HPI_DEBUG_ASSERT(phr->h.specific_error >
  2822. MIN_STRV_PACKET_SIZE
  2823. && phr->h.specific_error < 1500);
  2824. resp_packet_size = phr->h.specific_error;
  2825. } else {
  2826. remaining_attempts = 0;
  2827. if (!phr->h.error)
  2828. hpi_entity_alloc_and_copy(&phr->strv, info);
  2829. }
  2830. hpi_err = phr->h.error;
  2831. kfree(phr);
  2832. }
  2833. return hpi_err;
  2834. }
  2835. u16 hpi_universal_get(const struct hpi_hsubsys *ph_subsys, u32 hC,
  2836. struct hpi_entity **value)
  2837. {
  2838. struct hpi_msg_strv hm;
  2839. struct hpi_res_strv *phr;
  2840. u16 hpi_err;
  2841. int remaining_attempts = 2;
  2842. *value = NULL;
  2843. while (remaining_attempts--) {
  2844. phr = kmalloc(strv_packet_size, GFP_KERNEL);
  2845. if (!phr)
  2846. return HPI_ERROR_MEMORY_ALLOC;
  2847. hpi_init_message_responseV1(&hm.h, (u16)sizeof(hm), &phr->h,
  2848. (u16)strv_packet_size, HPI_OBJ_CONTROL,
  2849. HPI_CONTROL_GET_STATE);
  2850. u32TOINDEXES(hC, &hm.h.adapter_index, &hm.h.obj_index);
  2851. hm.strv.header.size = sizeof(hm.strv);
  2852. phr->strv.header.size = strv_packet_size - sizeof(phr->h);
  2853. hpi_send_recv((struct hpi_message *)&hm.h,
  2854. (struct hpi_response *)&phr->h);
  2855. if (phr->h.error == HPI_ERROR_RESPONSE_BUFFER_TOO_SMALL) {
  2856. HPI_DEBUG_ASSERT(phr->h.specific_error >
  2857. MIN_STRV_PACKET_SIZE
  2858. && phr->h.specific_error < 1000);
  2859. strv_packet_size = phr->h.specific_error;
  2860. } else {
  2861. remaining_attempts = 0;
  2862. if (!phr->h.error)
  2863. hpi_entity_alloc_and_copy(&phr->strv, value);
  2864. }
  2865. hpi_err = phr->h.error;
  2866. kfree(phr);
  2867. }
  2868. return hpi_err;
  2869. }
  2870. u16 hpi_universal_set(const struct hpi_hsubsys *ph_subsys, u32 hC,
  2871. struct hpi_entity *value)
  2872. {
  2873. struct hpi_msg_strv *phm;
  2874. struct hpi_res_strv hr;
  2875. phm = kmalloc(sizeof(phm->h) + value->header.size, GFP_KERNEL);
  2876. HPI_DEBUG_ASSERT(phm != NULL);
  2877. hpi_init_message_responseV1(&phm->h,
  2878. sizeof(phm->h) + value->header.size, &hr.h, sizeof(hr),
  2879. HPI_OBJ_CONTROL, HPI_CONTROL_SET_STATE);
  2880. u32TOINDEXES(hC, &phm->h.adapter_index, &phm->h.obj_index);
  2881. hr.strv.header.size = sizeof(hr.strv);
  2882. memcpy(&phm->strv, value, value->header.size);
  2883. hpi_send_recv((struct hpi_message *)&phm->h,
  2884. (struct hpi_response *)&hr.h);
  2885. return hr.h.error;
  2886. }
  2887. u16 hpi_entity_alloc_and_pack(const enum e_entity_type type,
  2888. const size_t item_count, const enum e_entity_role role, void *value,
  2889. struct hpi_entity **entity)
  2890. {
  2891. size_t bytes_to_copy, total_size;
  2892. u16 hE = 0;
  2893. *entity = NULL;
  2894. hE = hpi_entity_check_type(type);
  2895. if (hE)
  2896. return hE;
  2897. HPI_DEBUG_ASSERT(role > entity_role_null && type < LAST_ENTITY_TYPE);
  2898. bytes_to_copy = entity_type_to_size[type] * item_count;
  2899. total_size = hpi_entity_header_size(*entity) + bytes_to_copy;
  2900. HPI_DEBUG_ASSERT(total_size >= hpi_entity_header_size(*entity)
  2901. && total_size < STR_SIZE_FIELD_MAX);
  2902. *entity = kmalloc(total_size, GFP_KERNEL);
  2903. if (*entity == NULL)
  2904. return HPI_ERROR_MEMORY_ALLOC;
  2905. memcpy((*entity)->value, value, bytes_to_copy);
  2906. (*entity)->header.size =
  2907. hpi_entity_header_size(*entity) + bytes_to_copy;
  2908. (*entity)->header.type = type;
  2909. (*entity)->header.role = role;
  2910. return 0;
  2911. }
  2912. u16 hpi_entity_copy_value_from(struct hpi_entity *entity,
  2913. enum e_entity_type type, size_t item_count, void *value_dst_p)
  2914. {
  2915. size_t bytes_to_copy;
  2916. if (entity->header.type != type)
  2917. return HPI_ERROR_ENTITY_TYPE_MISMATCH;
  2918. if (hpi_entity_item_count(entity) != item_count)
  2919. return HPI_ERROR_ENTITY_ITEM_COUNT;
  2920. bytes_to_copy = entity_type_to_size[type] * item_count;
  2921. memcpy(value_dst_p, entity->value, bytes_to_copy);
  2922. return 0;
  2923. }
  2924. u16 hpi_entity_unpack(struct hpi_entity *entity, enum e_entity_type *type,
  2925. size_t *item_count, enum e_entity_role *role, void **value)
  2926. {
  2927. u16 err = 0;
  2928. HPI_DEBUG_ASSERT(entity != NULL);
  2929. if (type)
  2930. *type = entity->header.type;
  2931. if (role)
  2932. *role = entity->header.role;
  2933. if (value)
  2934. *value = entity->value;
  2935. if (item_count != NULL) {
  2936. if (entity->header.type == entity_type_sequence) {
  2937. void *guard_p = hpi_entity_ptr_to_next(entity);
  2938. struct hpi_entity *next = NULL;
  2939. void *contents = entity->value;
  2940. *item_count = 0;
  2941. while (contents < guard_p) {
  2942. (*item_count)++;
  2943. err = hpi_entity_get_next(contents, 0,
  2944. guard_p, &next);
  2945. if (next == NULL || err)
  2946. break;
  2947. contents = next;
  2948. }
  2949. } else {
  2950. *item_count = hpi_entity_item_count(entity);
  2951. }
  2952. }
  2953. return err;
  2954. }
  2955. u16 hpi_gpio_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index,
  2956. u32 *ph_gpio, u16 *pw_number_input_bits, u16 *pw_number_output_bits)
  2957. {
  2958. struct hpi_message hm;
  2959. struct hpi_response hr;
  2960. hpi_init_message_response(&hm, &hr, HPI_OBJ_GPIO, HPI_GPIO_OPEN);
  2961. hm.adapter_index = adapter_index;
  2962. hpi_send_recv(&hm, &hr);
  2963. if (hr.error == 0) {
  2964. *ph_gpio =
  2965. hpi_indexes_to_handle(HPI_OBJ_GPIO, adapter_index, 0);
  2966. if (pw_number_input_bits)
  2967. *pw_number_input_bits = hr.u.l.number_input_bits;
  2968. if (pw_number_output_bits)
  2969. *pw_number_output_bits = hr.u.l.number_output_bits;
  2970. } else
  2971. *ph_gpio = 0;
  2972. return hr.error;
  2973. }
  2974. u16 hpi_gpio_read_bit(const struct hpi_hsubsys *ph_subsys, u32 h_gpio,
  2975. u16 bit_index, u16 *pw_bit_data)
  2976. {
  2977. struct hpi_message hm;
  2978. struct hpi_response hr;
  2979. hpi_init_message_response(&hm, &hr, HPI_OBJ_GPIO, HPI_GPIO_READ_BIT);
  2980. u32TOINDEX(h_gpio, &hm.adapter_index);
  2981. hm.u.l.bit_index = bit_index;
  2982. hpi_send_recv(&hm, &hr);
  2983. *pw_bit_data = hr.u.l.bit_data[0];
  2984. return hr.error;
  2985. }
  2986. u16 hpi_gpio_read_all_bits(const struct hpi_hsubsys *ph_subsys, u32 h_gpio,
  2987. u16 aw_all_bit_data[4]
  2988. )
  2989. {
  2990. struct hpi_message hm;
  2991. struct hpi_response hr;
  2992. hpi_init_message_response(&hm, &hr, HPI_OBJ_GPIO, HPI_GPIO_READ_ALL);
  2993. u32TOINDEX(h_gpio, &hm.adapter_index);
  2994. hpi_send_recv(&hm, &hr);
  2995. if (aw_all_bit_data) {
  2996. aw_all_bit_data[0] = hr.u.l.bit_data[0];
  2997. aw_all_bit_data[1] = hr.u.l.bit_data[1];
  2998. aw_all_bit_data[2] = hr.u.l.bit_data[2];
  2999. aw_all_bit_data[3] = hr.u.l.bit_data[3];
  3000. }
  3001. return hr.error;
  3002. }
  3003. u16 hpi_gpio_write_bit(const struct hpi_hsubsys *ph_subsys, u32 h_gpio,
  3004. u16 bit_index, u16 bit_data)
  3005. {
  3006. struct hpi_message hm;
  3007. struct hpi_response hr;
  3008. hpi_init_message_response(&hm, &hr, HPI_OBJ_GPIO, HPI_GPIO_WRITE_BIT);
  3009. u32TOINDEX(h_gpio, &hm.adapter_index);
  3010. hm.u.l.bit_index = bit_index;
  3011. hm.u.l.bit_data = bit_data;
  3012. hpi_send_recv(&hm, &hr);
  3013. return hr.error;
  3014. }
  3015. u16 hpi_gpio_write_status(const struct hpi_hsubsys *ph_subsys, u32 h_gpio,
  3016. u16 aw_all_bit_data[4]
  3017. )
  3018. {
  3019. struct hpi_message hm;
  3020. struct hpi_response hr;
  3021. hpi_init_message_response(&hm, &hr, HPI_OBJ_GPIO,
  3022. HPI_GPIO_WRITE_STATUS);
  3023. u32TOINDEX(h_gpio, &hm.adapter_index);
  3024. hpi_send_recv(&hm, &hr);
  3025. if (aw_all_bit_data) {
  3026. aw_all_bit_data[0] = hr.u.l.bit_data[0];
  3027. aw_all_bit_data[1] = hr.u.l.bit_data[1];
  3028. aw_all_bit_data[2] = hr.u.l.bit_data[2];
  3029. aw_all_bit_data[3] = hr.u.l.bit_data[3];
  3030. }
  3031. return hr.error;
  3032. }
  3033. u16 hpi_async_event_open(const struct hpi_hsubsys *ph_subsys,
  3034. u16 adapter_index, u32 *ph_async)
  3035. {
  3036. struct hpi_message hm;
  3037. struct hpi_response hr;
  3038. hpi_init_message_response(&hm, &hr, HPI_OBJ_ASYNCEVENT,
  3039. HPI_ASYNCEVENT_OPEN);
  3040. hm.adapter_index = adapter_index;
  3041. hpi_send_recv(&hm, &hr);
  3042. if (hr.error == 0)
  3043. *ph_async =
  3044. hpi_indexes_to_handle(HPI_OBJ_ASYNCEVENT,
  3045. adapter_index, 0);
  3046. else
  3047. *ph_async = 0;
  3048. return hr.error;
  3049. }
  3050. u16 hpi_async_event_close(const struct hpi_hsubsys *ph_subsys, u32 h_async)
  3051. {
  3052. struct hpi_message hm;
  3053. struct hpi_response hr;
  3054. hpi_init_message_response(&hm, &hr, HPI_OBJ_ASYNCEVENT,
  3055. HPI_ASYNCEVENT_OPEN);
  3056. u32TOINDEX(h_async, &hm.adapter_index);
  3057. hpi_send_recv(&hm, &hr);
  3058. return hr.error;
  3059. }
  3060. u16 hpi_async_event_wait(const struct hpi_hsubsys *ph_subsys, u32 h_async,
  3061. u16 maximum_events, struct hpi_async_event *p_events,
  3062. u16 *pw_number_returned)
  3063. {
  3064. return 0;
  3065. }
  3066. u16 hpi_async_event_get_count(const struct hpi_hsubsys *ph_subsys,
  3067. u32 h_async, u16 *pw_count)
  3068. {
  3069. struct hpi_message hm;
  3070. struct hpi_response hr;
  3071. hpi_init_message_response(&hm, &hr, HPI_OBJ_ASYNCEVENT,
  3072. HPI_ASYNCEVENT_GETCOUNT);
  3073. u32TOINDEX(h_async, &hm.adapter_index);
  3074. hpi_send_recv(&hm, &hr);
  3075. if (hr.error == 0)
  3076. if (pw_count)
  3077. *pw_count = hr.u.as.u.count.count;
  3078. return hr.error;
  3079. }
  3080. u16 hpi_async_event_get(const struct hpi_hsubsys *ph_subsys, u32 h_async,
  3081. u16 maximum_events, struct hpi_async_event *p_events,
  3082. u16 *pw_number_returned)
  3083. {
  3084. struct hpi_message hm;
  3085. struct hpi_response hr;
  3086. hpi_init_message_response(&hm, &hr, HPI_OBJ_ASYNCEVENT,
  3087. HPI_ASYNCEVENT_GET);
  3088. u32TOINDEX(h_async, &hm.adapter_index);
  3089. hpi_send_recv(&hm, &hr);
  3090. if (!hr.error) {
  3091. memcpy(p_events, &hr.u.as.u.event,
  3092. sizeof(struct hpi_async_event));
  3093. *pw_number_returned = 1;
  3094. }
  3095. return hr.error;
  3096. }
  3097. u16 hpi_nv_memory_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index,
  3098. u32 *ph_nv_memory, u16 *pw_size_in_bytes)
  3099. {
  3100. struct hpi_message hm;
  3101. struct hpi_response hr;
  3102. hpi_init_message_response(&hm, &hr, HPI_OBJ_NVMEMORY,
  3103. HPI_NVMEMORY_OPEN);
  3104. hm.adapter_index = adapter_index;
  3105. hpi_send_recv(&hm, &hr);
  3106. if (hr.error == 0) {
  3107. *ph_nv_memory =
  3108. hpi_indexes_to_handle(HPI_OBJ_NVMEMORY, adapter_index,
  3109. 0);
  3110. if (pw_size_in_bytes)
  3111. *pw_size_in_bytes = hr.u.n.size_in_bytes;
  3112. } else
  3113. *ph_nv_memory = 0;
  3114. return hr.error;
  3115. }
  3116. u16 hpi_nv_memory_read_byte(const struct hpi_hsubsys *ph_subsys,
  3117. u32 h_nv_memory, u16 index, u16 *pw_data)
  3118. {
  3119. struct hpi_message hm;
  3120. struct hpi_response hr;
  3121. hpi_init_message_response(&hm, &hr, HPI_OBJ_NVMEMORY,
  3122. HPI_NVMEMORY_READ_BYTE);
  3123. u32TOINDEX(h_nv_memory, &hm.adapter_index);
  3124. hm.u.n.address = index;
  3125. hpi_send_recv(&hm, &hr);
  3126. *pw_data = hr.u.n.data;
  3127. return hr.error;
  3128. }
  3129. u16 hpi_nv_memory_write_byte(const struct hpi_hsubsys *ph_subsys,
  3130. u32 h_nv_memory, u16 index, u16 data)
  3131. {
  3132. struct hpi_message hm;
  3133. struct hpi_response hr;
  3134. hpi_init_message_response(&hm, &hr, HPI_OBJ_NVMEMORY,
  3135. HPI_NVMEMORY_WRITE_BYTE);
  3136. u32TOINDEX(h_nv_memory, &hm.adapter_index);
  3137. hm.u.n.address = index;
  3138. hm.u.n.data = data;
  3139. hpi_send_recv(&hm, &hr);
  3140. return hr.error;
  3141. }
  3142. u16 hpi_profile_open_all(const struct hpi_hsubsys *ph_subsys,
  3143. u16 adapter_index, u16 profile_index, u32 *ph_profile,
  3144. u16 *pw_max_profiles)
  3145. {
  3146. struct hpi_message hm;
  3147. struct hpi_response hr;
  3148. hpi_init_message_response(&hm, &hr, HPI_OBJ_PROFILE,
  3149. HPI_PROFILE_OPEN_ALL);
  3150. hm.adapter_index = adapter_index;
  3151. hm.obj_index = profile_index;
  3152. hpi_send_recv(&hm, &hr);
  3153. *pw_max_profiles = hr.u.p.u.o.max_profiles;
  3154. if (hr.error == 0)
  3155. *ph_profile =
  3156. hpi_indexes_to_handle(HPI_OBJ_PROFILE, adapter_index,
  3157. profile_index);
  3158. else
  3159. *ph_profile = 0;
  3160. return hr.error;
  3161. }
  3162. u16 hpi_profile_get(const struct hpi_hsubsys *ph_subsys, u32 h_profile,
  3163. u16 bin_index, u16 *pw_seconds, u32 *pmicro_seconds, u32 *pcall_count,
  3164. u32 *pmax_micro_seconds, u32 *pmin_micro_seconds)
  3165. {
  3166. struct hpi_message hm;
  3167. struct hpi_response hr;
  3168. hpi_init_message_response(&hm, &hr, HPI_OBJ_PROFILE, HPI_PROFILE_GET);
  3169. u32TOINDEXES(h_profile, &hm.adapter_index, &hm.obj_index);
  3170. hm.u.p.bin_index = bin_index;
  3171. hpi_send_recv(&hm, &hr);
  3172. if (pw_seconds)
  3173. *pw_seconds = hr.u.p.u.t.seconds;
  3174. if (pmicro_seconds)
  3175. *pmicro_seconds = hr.u.p.u.t.micro_seconds;
  3176. if (pcall_count)
  3177. *pcall_count = hr.u.p.u.t.call_count;
  3178. if (pmax_micro_seconds)
  3179. *pmax_micro_seconds = hr.u.p.u.t.max_micro_seconds;
  3180. if (pmin_micro_seconds)
  3181. *pmin_micro_seconds = hr.u.p.u.t.min_micro_seconds;
  3182. return hr.error;
  3183. }
  3184. u16 hpi_profile_get_utilization(const struct hpi_hsubsys *ph_subsys,
  3185. u32 h_profile, u32 *putilization)
  3186. {
  3187. struct hpi_message hm;
  3188. struct hpi_response hr;
  3189. hpi_init_message_response(&hm, &hr, HPI_OBJ_PROFILE,
  3190. HPI_PROFILE_GET_UTILIZATION);
  3191. u32TOINDEXES(h_profile, &hm.adapter_index, &hm.obj_index);
  3192. hpi_send_recv(&hm, &hr);
  3193. if (hr.error) {
  3194. if (putilization)
  3195. *putilization = 0;
  3196. } else {
  3197. if (putilization)
  3198. *putilization = hr.u.p.u.t.call_count;
  3199. }
  3200. return hr.error;
  3201. }
  3202. u16 hpi_profile_get_name(const struct hpi_hsubsys *ph_subsys, u32 h_profile,
  3203. u16 bin_index, char *sz_name, u16 name_length)
  3204. {
  3205. struct hpi_message hm;
  3206. struct hpi_response hr;
  3207. hpi_init_message_response(&hm, &hr, HPI_OBJ_PROFILE,
  3208. HPI_PROFILE_GET_NAME);
  3209. u32TOINDEXES(h_profile, &hm.adapter_index, &hm.obj_index);
  3210. hm.u.p.bin_index = bin_index;
  3211. hpi_send_recv(&hm, &hr);
  3212. if (hr.error) {
  3213. if (sz_name)
  3214. strcpy(sz_name, "??");
  3215. } else {
  3216. if (sz_name)
  3217. memcpy(sz_name, (char *)hr.u.p.u.n.sz_name,
  3218. name_length);
  3219. }
  3220. return hr.error;
  3221. }
  3222. u16 hpi_profile_start_all(const struct hpi_hsubsys *ph_subsys, u32 h_profile)
  3223. {
  3224. struct hpi_message hm;
  3225. struct hpi_response hr;
  3226. hpi_init_message_response(&hm, &hr, HPI_OBJ_PROFILE,
  3227. HPI_PROFILE_START_ALL);
  3228. u32TOINDEXES(h_profile, &hm.adapter_index, &hm.obj_index);
  3229. hpi_send_recv(&hm, &hr);
  3230. return hr.error;
  3231. }
  3232. u16 hpi_profile_stop_all(const struct hpi_hsubsys *ph_subsys, u32 h_profile)
  3233. {
  3234. struct hpi_message hm;
  3235. struct hpi_response hr;
  3236. hpi_init_message_response(&hm, &hr, HPI_OBJ_PROFILE,
  3237. HPI_PROFILE_STOP_ALL);
  3238. u32TOINDEXES(h_profile, &hm.adapter_index, &hm.obj_index);
  3239. hpi_send_recv(&hm, &hr);
  3240. return hr.error;
  3241. }
  3242. u16 hpi_watchdog_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index,
  3243. u32 *ph_watchdog)
  3244. {
  3245. struct hpi_message hm;
  3246. struct hpi_response hr;
  3247. hpi_init_message_response(&hm, &hr, HPI_OBJ_WATCHDOG,
  3248. HPI_WATCHDOG_OPEN);
  3249. hm.adapter_index = adapter_index;
  3250. hpi_send_recv(&hm, &hr);
  3251. if (hr.error == 0)
  3252. *ph_watchdog =
  3253. hpi_indexes_to_handle(HPI_OBJ_WATCHDOG, adapter_index,
  3254. 0);
  3255. else
  3256. *ph_watchdog = 0;
  3257. return hr.error;
  3258. }
  3259. u16 hpi_watchdog_set_time(const struct hpi_hsubsys *ph_subsys, u32 h_watchdog,
  3260. u32 time_millisec)
  3261. {
  3262. struct hpi_message hm;
  3263. struct hpi_response hr;
  3264. hpi_init_message_response(&hm, &hr, HPI_OBJ_WATCHDOG,
  3265. HPI_WATCHDOG_SET_TIME);
  3266. u32TOINDEX(h_watchdog, &hm.adapter_index);
  3267. hm.u.w.time_ms = time_millisec;
  3268. hpi_send_recv(&hm, &hr);
  3269. return hr.error;
  3270. }
  3271. u16 hpi_watchdog_ping(const struct hpi_hsubsys *ph_subsys, u32 h_watchdog)
  3272. {
  3273. struct hpi_message hm;
  3274. struct hpi_response hr;
  3275. hpi_init_message_response(&hm, &hr, HPI_OBJ_WATCHDOG,
  3276. HPI_WATCHDOG_PING);
  3277. u32TOINDEX(h_watchdog, &hm.adapter_index);
  3278. hpi_send_recv(&hm, &hr);
  3279. return hr.error;
  3280. }