hpifunc.c 70 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include "hpi_internal.h"
  3. #include "hpimsginit.h"
  4. #include "hpidebug.h"
  5. struct hpi_handle {
  6. unsigned int obj_index:12;
  7. unsigned int obj_type:4;
  8. unsigned int adapter_index:14;
  9. unsigned int spare:1;
  10. unsigned int read_only:1;
  11. };
  12. union handle_word {
  13. struct hpi_handle h;
  14. u32 w;
  15. };
  16. u32 hpi_indexes_to_handle(const char c_object, const u16 adapter_index,
  17. const u16 object_index)
  18. {
  19. union handle_word handle;
  20. handle.h.adapter_index = adapter_index;
  21. handle.h.spare = 0;
  22. handle.h.read_only = 0;
  23. handle.h.obj_type = c_object;
  24. handle.h.obj_index = object_index;
  25. return handle.w;
  26. }
  27. static u16 hpi_handle_indexes(const u32 h, u16 *p1, u16 *p2)
  28. {
  29. union handle_word uhandle;
  30. if (!h)
  31. return HPI_ERROR_INVALID_HANDLE;
  32. uhandle.w = h;
  33. *p1 = (u16)uhandle.h.adapter_index;
  34. if (p2)
  35. *p2 = (u16)uhandle.h.obj_index;
  36. return 0;
  37. }
  38. void hpi_handle_to_indexes(const u32 handle, u16 *pw_adapter_index,
  39. u16 *pw_object_index)
  40. {
  41. hpi_handle_indexes(handle, pw_adapter_index, pw_object_index);
  42. }
  43. char hpi_handle_object(const u32 handle)
  44. {
  45. union handle_word uhandle;
  46. uhandle.w = handle;
  47. return (char)uhandle.h.obj_type;
  48. }
  49. void hpi_format_to_msg(struct hpi_msg_format *pMF,
  50. const struct hpi_format *pF)
  51. {
  52. pMF->sample_rate = pF->sample_rate;
  53. pMF->bit_rate = pF->bit_rate;
  54. pMF->attributes = pF->attributes;
  55. pMF->channels = pF->channels;
  56. pMF->format = pF->format;
  57. }
  58. static void hpi_msg_to_format(struct hpi_format *pF,
  59. struct hpi_msg_format *pMF)
  60. {
  61. pF->sample_rate = pMF->sample_rate;
  62. pF->bit_rate = pMF->bit_rate;
  63. pF->attributes = pMF->attributes;
  64. pF->channels = pMF->channels;
  65. pF->format = pMF->format;
  66. pF->mode_legacy = 0;
  67. pF->unused = 0;
  68. }
  69. void hpi_stream_response_to_legacy(struct hpi_stream_res *pSR)
  70. {
  71. pSR->u.legacy_stream_info.auxiliary_data_available =
  72. pSR->u.stream_info.auxiliary_data_available;
  73. pSR->u.legacy_stream_info.state = pSR->u.stream_info.state;
  74. }
  75. static inline void hpi_send_recvV1(struct hpi_message_header *m,
  76. struct hpi_response_header *r)
  77. {
  78. hpi_send_recv((struct hpi_message *)m, (struct hpi_response *)r);
  79. }
  80. u16 hpi_subsys_get_version_ex(u32 *pversion_ex)
  81. {
  82. struct hpi_message hm;
  83. struct hpi_response hr;
  84. hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
  85. HPI_SUBSYS_GET_VERSION);
  86. hpi_send_recv(&hm, &hr);
  87. *pversion_ex = hr.u.s.data;
  88. return hr.error;
  89. }
  90. u16 hpi_subsys_get_num_adapters(int *pn_num_adapters)
  91. {
  92. struct hpi_message hm;
  93. struct hpi_response hr;
  94. hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
  95. HPI_SUBSYS_GET_NUM_ADAPTERS);
  96. hpi_send_recv(&hm, &hr);
  97. *pn_num_adapters = (int)hr.u.s.num_adapters;
  98. return hr.error;
  99. }
  100. u16 hpi_subsys_get_adapter(int iterator, u32 *padapter_index,
  101. u16 *pw_adapter_type)
  102. {
  103. struct hpi_message hm;
  104. struct hpi_response hr;
  105. hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
  106. HPI_SUBSYS_GET_ADAPTER);
  107. hm.obj_index = (u16)iterator;
  108. hpi_send_recv(&hm, &hr);
  109. *padapter_index = (int)hr.u.s.adapter_index;
  110. *pw_adapter_type = hr.u.s.adapter_type;
  111. return hr.error;
  112. }
  113. u16 hpi_adapter_open(u16 adapter_index)
  114. {
  115. struct hpi_message hm;
  116. struct hpi_response hr;
  117. hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
  118. HPI_ADAPTER_OPEN);
  119. hm.adapter_index = adapter_index;
  120. hpi_send_recv(&hm, &hr);
  121. return hr.error;
  122. }
  123. u16 hpi_adapter_close(u16 adapter_index)
  124. {
  125. struct hpi_message hm;
  126. struct hpi_response hr;
  127. hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
  128. HPI_ADAPTER_CLOSE);
  129. hm.adapter_index = adapter_index;
  130. hpi_send_recv(&hm, &hr);
  131. return hr.error;
  132. }
  133. u16 hpi_adapter_set_mode(u16 adapter_index, u32 adapter_mode)
  134. {
  135. return hpi_adapter_set_mode_ex(adapter_index, adapter_mode,
  136. HPI_ADAPTER_MODE_SET);
  137. }
  138. u16 hpi_adapter_set_mode_ex(u16 adapter_index, u32 adapter_mode,
  139. u16 query_or_set)
  140. {
  141. struct hpi_message hm;
  142. struct hpi_response hr;
  143. hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
  144. HPI_ADAPTER_SET_MODE);
  145. hm.adapter_index = adapter_index;
  146. hm.u.ax.mode.adapter_mode = adapter_mode;
  147. hm.u.ax.mode.query_or_set = query_or_set;
  148. hpi_send_recv(&hm, &hr);
  149. return hr.error;
  150. }
  151. u16 hpi_adapter_get_mode(u16 adapter_index, u32 *padapter_mode)
  152. {
  153. struct hpi_message hm;
  154. struct hpi_response hr;
  155. hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
  156. HPI_ADAPTER_GET_MODE);
  157. hm.adapter_index = adapter_index;
  158. hpi_send_recv(&hm, &hr);
  159. if (padapter_mode)
  160. *padapter_mode = hr.u.ax.mode.adapter_mode;
  161. return hr.error;
  162. }
  163. u16 hpi_adapter_get_info(u16 adapter_index, u16 *pw_num_outstreams,
  164. u16 *pw_num_instreams, u16 *pw_version, u32 *pserial_number,
  165. u16 *pw_adapter_type)
  166. {
  167. struct hpi_message hm;
  168. struct hpi_response hr;
  169. hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
  170. HPI_ADAPTER_GET_INFO);
  171. hm.adapter_index = adapter_index;
  172. hpi_send_recv(&hm, &hr);
  173. *pw_adapter_type = hr.u.ax.info.adapter_type;
  174. *pw_num_outstreams = hr.u.ax.info.num_outstreams;
  175. *pw_num_instreams = hr.u.ax.info.num_instreams;
  176. *pw_version = hr.u.ax.info.version;
  177. *pserial_number = hr.u.ax.info.serial_number;
  178. return hr.error;
  179. }
  180. u16 hpi_adapter_get_module_by_index(u16 adapter_index, u16 module_index,
  181. u16 *pw_num_outputs, u16 *pw_num_inputs, u16 *pw_version,
  182. u32 *pserial_number, u16 *pw_module_type, u32 *ph_module)
  183. {
  184. struct hpi_message hm;
  185. struct hpi_response hr;
  186. hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
  187. HPI_ADAPTER_MODULE_INFO);
  188. hm.adapter_index = adapter_index;
  189. hm.u.ax.module_info.index = module_index;
  190. hpi_send_recv(&hm, &hr);
  191. *pw_module_type = hr.u.ax.info.adapter_type;
  192. *pw_num_outputs = hr.u.ax.info.num_outstreams;
  193. *pw_num_inputs = hr.u.ax.info.num_instreams;
  194. *pw_version = hr.u.ax.info.version;
  195. *pserial_number = hr.u.ax.info.serial_number;
  196. *ph_module = 0;
  197. return hr.error;
  198. }
  199. u16 hpi_adapter_set_property(u16 adapter_index, u16 property, u16 parameter1,
  200. u16 parameter2)
  201. {
  202. struct hpi_message hm;
  203. struct hpi_response hr;
  204. hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
  205. HPI_ADAPTER_SET_PROPERTY);
  206. hm.adapter_index = adapter_index;
  207. hm.u.ax.property_set.property = property;
  208. hm.u.ax.property_set.parameter1 = parameter1;
  209. hm.u.ax.property_set.parameter2 = parameter2;
  210. hpi_send_recv(&hm, &hr);
  211. return hr.error;
  212. }
  213. u16 hpi_adapter_get_property(u16 adapter_index, u16 property,
  214. u16 *pw_parameter1, u16 *pw_parameter2)
  215. {
  216. struct hpi_message hm;
  217. struct hpi_response hr;
  218. hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
  219. HPI_ADAPTER_GET_PROPERTY);
  220. hm.adapter_index = adapter_index;
  221. hm.u.ax.property_set.property = property;
  222. hpi_send_recv(&hm, &hr);
  223. if (!hr.error) {
  224. if (pw_parameter1)
  225. *pw_parameter1 = hr.u.ax.property_get.parameter1;
  226. if (pw_parameter2)
  227. *pw_parameter2 = hr.u.ax.property_get.parameter2;
  228. }
  229. return hr.error;
  230. }
  231. u16 hpi_adapter_enumerate_property(u16 adapter_index, u16 index,
  232. u16 what_to_enumerate, u16 property_index, u32 *psetting)
  233. {
  234. return 0;
  235. }
  236. u16 hpi_format_create(struct hpi_format *p_format, u16 channels, u16 format,
  237. u32 sample_rate, u32 bit_rate, u32 attributes)
  238. {
  239. u16 err = 0;
  240. struct hpi_msg_format fmt;
  241. switch (channels) {
  242. case 1:
  243. case 2:
  244. case 4:
  245. case 6:
  246. case 8:
  247. case 16:
  248. break;
  249. default:
  250. err = HPI_ERROR_INVALID_CHANNELS;
  251. return err;
  252. }
  253. fmt.channels = channels;
  254. switch (format) {
  255. case HPI_FORMAT_PCM16_SIGNED:
  256. case HPI_FORMAT_PCM24_SIGNED:
  257. case HPI_FORMAT_PCM32_SIGNED:
  258. case HPI_FORMAT_PCM32_FLOAT:
  259. case HPI_FORMAT_PCM16_BIGENDIAN:
  260. case HPI_FORMAT_PCM8_UNSIGNED:
  261. case HPI_FORMAT_MPEG_L1:
  262. case HPI_FORMAT_MPEG_L2:
  263. case HPI_FORMAT_MPEG_L3:
  264. case HPI_FORMAT_DOLBY_AC2:
  265. case HPI_FORMAT_AA_TAGIT1_HITS:
  266. case HPI_FORMAT_AA_TAGIT1_INSERTS:
  267. case HPI_FORMAT_RAW_BITSTREAM:
  268. case HPI_FORMAT_AA_TAGIT1_HITS_EX1:
  269. case HPI_FORMAT_OEM1:
  270. case HPI_FORMAT_OEM2:
  271. break;
  272. default:
  273. err = HPI_ERROR_INVALID_FORMAT;
  274. return err;
  275. }
  276. fmt.format = format;
  277. if (sample_rate < 8000L) {
  278. err = HPI_ERROR_INCOMPATIBLE_SAMPLERATE;
  279. sample_rate = 8000L;
  280. }
  281. if (sample_rate > 200000L) {
  282. err = HPI_ERROR_INCOMPATIBLE_SAMPLERATE;
  283. sample_rate = 200000L;
  284. }
  285. fmt.sample_rate = sample_rate;
  286. switch (format) {
  287. case HPI_FORMAT_MPEG_L1:
  288. case HPI_FORMAT_MPEG_L2:
  289. case HPI_FORMAT_MPEG_L3:
  290. fmt.bit_rate = bit_rate;
  291. break;
  292. case HPI_FORMAT_PCM16_SIGNED:
  293. case HPI_FORMAT_PCM16_BIGENDIAN:
  294. fmt.bit_rate = channels * sample_rate * 2;
  295. break;
  296. case HPI_FORMAT_PCM32_SIGNED:
  297. case HPI_FORMAT_PCM32_FLOAT:
  298. fmt.bit_rate = channels * sample_rate * 4;
  299. break;
  300. case HPI_FORMAT_PCM8_UNSIGNED:
  301. fmt.bit_rate = channels * sample_rate;
  302. break;
  303. default:
  304. fmt.bit_rate = 0;
  305. }
  306. switch (format) {
  307. case HPI_FORMAT_MPEG_L2:
  308. if ((channels == 1)
  309. && (attributes != HPI_MPEG_MODE_DEFAULT)) {
  310. attributes = HPI_MPEG_MODE_DEFAULT;
  311. err = HPI_ERROR_INVALID_FORMAT;
  312. } else if (attributes > HPI_MPEG_MODE_DUALCHANNEL) {
  313. attributes = HPI_MPEG_MODE_DEFAULT;
  314. err = HPI_ERROR_INVALID_FORMAT;
  315. }
  316. fmt.attributes = attributes;
  317. break;
  318. default:
  319. fmt.attributes = attributes;
  320. }
  321. hpi_msg_to_format(p_format, &fmt);
  322. return err;
  323. }
  324. u16 hpi_stream_estimate_buffer_size(struct hpi_format *p_format,
  325. u32 host_polling_rate_in_milli_seconds, u32 *recommended_buffer_size)
  326. {
  327. u32 bytes_per_second;
  328. u32 size;
  329. u16 channels;
  330. struct hpi_format *pF = p_format;
  331. channels = pF->channels;
  332. switch (pF->format) {
  333. case HPI_FORMAT_PCM16_BIGENDIAN:
  334. case HPI_FORMAT_PCM16_SIGNED:
  335. bytes_per_second = pF->sample_rate * 2L * channels;
  336. break;
  337. case HPI_FORMAT_PCM24_SIGNED:
  338. bytes_per_second = pF->sample_rate * 3L * channels;
  339. break;
  340. case HPI_FORMAT_PCM32_SIGNED:
  341. case HPI_FORMAT_PCM32_FLOAT:
  342. bytes_per_second = pF->sample_rate * 4L * channels;
  343. break;
  344. case HPI_FORMAT_PCM8_UNSIGNED:
  345. bytes_per_second = pF->sample_rate * 1L * channels;
  346. break;
  347. case HPI_FORMAT_MPEG_L1:
  348. case HPI_FORMAT_MPEG_L2:
  349. case HPI_FORMAT_MPEG_L3:
  350. bytes_per_second = pF->bit_rate / 8L;
  351. break;
  352. case HPI_FORMAT_DOLBY_AC2:
  353. bytes_per_second = 256000L / 8L;
  354. break;
  355. default:
  356. return HPI_ERROR_INVALID_FORMAT;
  357. }
  358. size = (bytes_per_second * host_polling_rate_in_milli_seconds * 2) /
  359. 1000L;
  360. *recommended_buffer_size =
  361. roundup_pow_of_two(((size + 4095L) & ~4095L));
  362. return 0;
  363. }
  364. u16 hpi_outstream_open(u16 adapter_index, u16 outstream_index,
  365. u32 *ph_outstream)
  366. {
  367. struct hpi_message hm;
  368. struct hpi_response hr;
  369. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  370. HPI_OSTREAM_OPEN);
  371. hm.adapter_index = adapter_index;
  372. hm.obj_index = outstream_index;
  373. hpi_send_recv(&hm, &hr);
  374. if (hr.error == 0)
  375. *ph_outstream =
  376. hpi_indexes_to_handle(HPI_OBJ_OSTREAM, adapter_index,
  377. outstream_index);
  378. else
  379. *ph_outstream = 0;
  380. return hr.error;
  381. }
  382. u16 hpi_outstream_close(u32 h_outstream)
  383. {
  384. struct hpi_message hm;
  385. struct hpi_response hr;
  386. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  387. HPI_OSTREAM_HOSTBUFFER_FREE);
  388. if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
  389. return HPI_ERROR_INVALID_HANDLE;
  390. hpi_send_recv(&hm, &hr);
  391. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  392. HPI_OSTREAM_GROUP_RESET);
  393. hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index);
  394. hpi_send_recv(&hm, &hr);
  395. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  396. HPI_OSTREAM_CLOSE);
  397. hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index);
  398. hpi_send_recv(&hm, &hr);
  399. return hr.error;
  400. }
  401. u16 hpi_outstream_get_info_ex(u32 h_outstream, u16 *pw_state,
  402. u32 *pbuffer_size, u32 *pdata_to_play, u32 *psamples_played,
  403. u32 *pauxiliary_data_to_play)
  404. {
  405. struct hpi_message hm;
  406. struct hpi_response hr;
  407. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  408. HPI_OSTREAM_GET_INFO);
  409. if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
  410. return HPI_ERROR_INVALID_HANDLE;
  411. hpi_send_recv(&hm, &hr);
  412. if (pw_state)
  413. *pw_state = hr.u.d.u.stream_info.state;
  414. if (pbuffer_size)
  415. *pbuffer_size = hr.u.d.u.stream_info.buffer_size;
  416. if (pdata_to_play)
  417. *pdata_to_play = hr.u.d.u.stream_info.data_available;
  418. if (psamples_played)
  419. *psamples_played = hr.u.d.u.stream_info.samples_transferred;
  420. if (pauxiliary_data_to_play)
  421. *pauxiliary_data_to_play =
  422. hr.u.d.u.stream_info.auxiliary_data_available;
  423. return hr.error;
  424. }
  425. u16 hpi_outstream_write_buf(u32 h_outstream, const u8 *pb_data,
  426. u32 bytes_to_write, const struct hpi_format *p_format)
  427. {
  428. struct hpi_message hm;
  429. struct hpi_response hr;
  430. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  431. HPI_OSTREAM_WRITE);
  432. if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
  433. return HPI_ERROR_INVALID_HANDLE;
  434. hm.u.d.u.data.pb_data = (u8 *)pb_data;
  435. hm.u.d.u.data.data_size = bytes_to_write;
  436. hpi_format_to_msg(&hm.u.d.u.data.format, p_format);
  437. hpi_send_recv(&hm, &hr);
  438. return hr.error;
  439. }
  440. u16 hpi_outstream_start(u32 h_outstream)
  441. {
  442. struct hpi_message hm;
  443. struct hpi_response hr;
  444. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  445. HPI_OSTREAM_START);
  446. if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
  447. return HPI_ERROR_INVALID_HANDLE;
  448. hpi_send_recv(&hm, &hr);
  449. return hr.error;
  450. }
  451. u16 hpi_outstream_wait_start(u32 h_outstream)
  452. {
  453. struct hpi_message hm;
  454. struct hpi_response hr;
  455. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  456. HPI_OSTREAM_WAIT_START);
  457. if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
  458. return HPI_ERROR_INVALID_HANDLE;
  459. hpi_send_recv(&hm, &hr);
  460. return hr.error;
  461. }
  462. u16 hpi_outstream_stop(u32 h_outstream)
  463. {
  464. struct hpi_message hm;
  465. struct hpi_response hr;
  466. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  467. HPI_OSTREAM_STOP);
  468. if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
  469. return HPI_ERROR_INVALID_HANDLE;
  470. hpi_send_recv(&hm, &hr);
  471. return hr.error;
  472. }
  473. u16 hpi_outstream_sinegen(u32 h_outstream)
  474. {
  475. struct hpi_message hm;
  476. struct hpi_response hr;
  477. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  478. HPI_OSTREAM_SINEGEN);
  479. if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
  480. return HPI_ERROR_INVALID_HANDLE;
  481. hpi_send_recv(&hm, &hr);
  482. return hr.error;
  483. }
  484. u16 hpi_outstream_reset(u32 h_outstream)
  485. {
  486. struct hpi_message hm;
  487. struct hpi_response hr;
  488. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  489. HPI_OSTREAM_RESET);
  490. if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
  491. return HPI_ERROR_INVALID_HANDLE;
  492. hpi_send_recv(&hm, &hr);
  493. return hr.error;
  494. }
  495. u16 hpi_outstream_query_format(u32 h_outstream, struct hpi_format *p_format)
  496. {
  497. struct hpi_message hm;
  498. struct hpi_response hr;
  499. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  500. HPI_OSTREAM_QUERY_FORMAT);
  501. if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
  502. return HPI_ERROR_INVALID_HANDLE;
  503. hpi_format_to_msg(&hm.u.d.u.data.format, p_format);
  504. hpi_send_recv(&hm, &hr);
  505. return hr.error;
  506. }
  507. u16 hpi_outstream_set_format(u32 h_outstream, struct hpi_format *p_format)
  508. {
  509. struct hpi_message hm;
  510. struct hpi_response hr;
  511. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  512. HPI_OSTREAM_SET_FORMAT);
  513. if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
  514. return HPI_ERROR_INVALID_HANDLE;
  515. hpi_format_to_msg(&hm.u.d.u.data.format, p_format);
  516. hpi_send_recv(&hm, &hr);
  517. return hr.error;
  518. }
  519. u16 hpi_outstream_set_velocity(u32 h_outstream, short velocity)
  520. {
  521. struct hpi_message hm;
  522. struct hpi_response hr;
  523. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  524. HPI_OSTREAM_SET_VELOCITY);
  525. if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
  526. return HPI_ERROR_INVALID_HANDLE;
  527. hm.u.d.u.velocity = velocity;
  528. hpi_send_recv(&hm, &hr);
  529. return hr.error;
  530. }
  531. u16 hpi_outstream_set_punch_in_out(u32 h_outstream, u32 punch_in_sample,
  532. u32 punch_out_sample)
  533. {
  534. struct hpi_message hm;
  535. struct hpi_response hr;
  536. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  537. HPI_OSTREAM_SET_PUNCHINOUT);
  538. if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
  539. return HPI_ERROR_INVALID_HANDLE;
  540. hm.u.d.u.pio.punch_in_sample = punch_in_sample;
  541. hm.u.d.u.pio.punch_out_sample = punch_out_sample;
  542. hpi_send_recv(&hm, &hr);
  543. return hr.error;
  544. }
  545. u16 hpi_outstream_ancillary_reset(u32 h_outstream, u16 mode)
  546. {
  547. struct hpi_message hm;
  548. struct hpi_response hr;
  549. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  550. HPI_OSTREAM_ANC_RESET);
  551. if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
  552. return HPI_ERROR_INVALID_HANDLE;
  553. hm.u.d.u.data.format.channels = mode;
  554. hpi_send_recv(&hm, &hr);
  555. return hr.error;
  556. }
  557. u16 hpi_outstream_ancillary_get_info(u32 h_outstream, u32 *pframes_available)
  558. {
  559. struct hpi_message hm;
  560. struct hpi_response hr;
  561. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  562. HPI_OSTREAM_ANC_GET_INFO);
  563. if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
  564. return HPI_ERROR_INVALID_HANDLE;
  565. hpi_send_recv(&hm, &hr);
  566. if (hr.error == 0) {
  567. if (pframes_available)
  568. *pframes_available =
  569. hr.u.d.u.stream_info.data_available /
  570. sizeof(struct hpi_anc_frame);
  571. }
  572. return hr.error;
  573. }
  574. u16 hpi_outstream_ancillary_read(u32 h_outstream,
  575. struct hpi_anc_frame *p_anc_frame_buffer,
  576. u32 anc_frame_buffer_size_in_bytes,
  577. u32 number_of_ancillary_frames_to_read)
  578. {
  579. struct hpi_message hm;
  580. struct hpi_response hr;
  581. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  582. HPI_OSTREAM_ANC_READ);
  583. if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
  584. return HPI_ERROR_INVALID_HANDLE;
  585. hm.u.d.u.data.pb_data = (u8 *)p_anc_frame_buffer;
  586. hm.u.d.u.data.data_size =
  587. number_of_ancillary_frames_to_read *
  588. sizeof(struct hpi_anc_frame);
  589. if (hm.u.d.u.data.data_size <= anc_frame_buffer_size_in_bytes)
  590. hpi_send_recv(&hm, &hr);
  591. else
  592. hr.error = HPI_ERROR_INVALID_DATASIZE;
  593. return hr.error;
  594. }
  595. u16 hpi_outstream_set_time_scale(u32 h_outstream, u32 time_scale)
  596. {
  597. struct hpi_message hm;
  598. struct hpi_response hr;
  599. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  600. HPI_OSTREAM_SET_TIMESCALE);
  601. if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
  602. return HPI_ERROR_INVALID_HANDLE;
  603. hm.u.d.u.time_scale = time_scale;
  604. hpi_send_recv(&hm, &hr);
  605. return hr.error;
  606. }
  607. u16 hpi_outstream_host_buffer_allocate(u32 h_outstream, u32 size_in_bytes)
  608. {
  609. struct hpi_message hm;
  610. struct hpi_response hr;
  611. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  612. HPI_OSTREAM_HOSTBUFFER_ALLOC);
  613. if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
  614. return HPI_ERROR_INVALID_HANDLE;
  615. hm.u.d.u.data.data_size = size_in_bytes;
  616. hpi_send_recv(&hm, &hr);
  617. return hr.error;
  618. }
  619. u16 hpi_outstream_host_buffer_get_info(u32 h_outstream, u8 **pp_buffer,
  620. struct hpi_hostbuffer_status **pp_status)
  621. {
  622. struct hpi_message hm;
  623. struct hpi_response hr;
  624. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  625. HPI_OSTREAM_HOSTBUFFER_GET_INFO);
  626. if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
  627. return HPI_ERROR_INVALID_HANDLE;
  628. hpi_send_recv(&hm, &hr);
  629. if (hr.error == 0) {
  630. if (pp_buffer)
  631. *pp_buffer = hr.u.d.u.hostbuffer_info.p_buffer;
  632. if (pp_status)
  633. *pp_status = hr.u.d.u.hostbuffer_info.p_status;
  634. }
  635. return hr.error;
  636. }
  637. u16 hpi_outstream_host_buffer_free(u32 h_outstream)
  638. {
  639. struct hpi_message hm;
  640. struct hpi_response hr;
  641. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  642. HPI_OSTREAM_HOSTBUFFER_FREE);
  643. if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
  644. return HPI_ERROR_INVALID_HANDLE;
  645. hpi_send_recv(&hm, &hr);
  646. return hr.error;
  647. }
  648. u16 hpi_outstream_group_add(u32 h_outstream, u32 h_stream)
  649. {
  650. struct hpi_message hm;
  651. struct hpi_response hr;
  652. u16 adapter;
  653. char c_obj_type;
  654. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  655. HPI_OSTREAM_GROUP_ADD);
  656. if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
  657. return HPI_ERROR_INVALID_HANDLE;
  658. if (hpi_handle_indexes(h_stream, &adapter,
  659. &hm.u.d.u.stream.stream_index))
  660. return HPI_ERROR_INVALID_HANDLE;
  661. c_obj_type = hpi_handle_object(h_stream);
  662. switch (c_obj_type) {
  663. case HPI_OBJ_OSTREAM:
  664. case HPI_OBJ_ISTREAM:
  665. hm.u.d.u.stream.object_type = c_obj_type;
  666. break;
  667. default:
  668. return HPI_ERROR_INVALID_OBJ;
  669. }
  670. if (adapter != hm.adapter_index)
  671. return HPI_ERROR_NO_INTERADAPTER_GROUPS;
  672. hpi_send_recv(&hm, &hr);
  673. return hr.error;
  674. }
  675. u16 hpi_outstream_group_get_map(u32 h_outstream, u32 *poutstream_map,
  676. u32 *pinstream_map)
  677. {
  678. struct hpi_message hm;
  679. struct hpi_response hr;
  680. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  681. HPI_OSTREAM_GROUP_GETMAP);
  682. if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
  683. return HPI_ERROR_INVALID_HANDLE;
  684. hpi_send_recv(&hm, &hr);
  685. if (poutstream_map)
  686. *poutstream_map = hr.u.d.u.group_info.outstream_group_map;
  687. if (pinstream_map)
  688. *pinstream_map = hr.u.d.u.group_info.instream_group_map;
  689. return hr.error;
  690. }
  691. u16 hpi_outstream_group_reset(u32 h_outstream)
  692. {
  693. struct hpi_message hm;
  694. struct hpi_response hr;
  695. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  696. HPI_OSTREAM_GROUP_RESET);
  697. if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
  698. return HPI_ERROR_INVALID_HANDLE;
  699. hpi_send_recv(&hm, &hr);
  700. return hr.error;
  701. }
  702. u16 hpi_instream_open(u16 adapter_index, u16 instream_index, u32 *ph_instream)
  703. {
  704. struct hpi_message hm;
  705. struct hpi_response hr;
  706. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  707. HPI_ISTREAM_OPEN);
  708. hm.adapter_index = adapter_index;
  709. hm.obj_index = instream_index;
  710. hpi_send_recv(&hm, &hr);
  711. if (hr.error == 0)
  712. *ph_instream =
  713. hpi_indexes_to_handle(HPI_OBJ_ISTREAM, adapter_index,
  714. instream_index);
  715. else
  716. *ph_instream = 0;
  717. return hr.error;
  718. }
  719. u16 hpi_instream_close(u32 h_instream)
  720. {
  721. struct hpi_message hm;
  722. struct hpi_response hr;
  723. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  724. HPI_ISTREAM_HOSTBUFFER_FREE);
  725. if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
  726. return HPI_ERROR_INVALID_HANDLE;
  727. hpi_send_recv(&hm, &hr);
  728. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  729. HPI_ISTREAM_GROUP_RESET);
  730. hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index);
  731. hpi_send_recv(&hm, &hr);
  732. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  733. HPI_ISTREAM_CLOSE);
  734. hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index);
  735. hpi_send_recv(&hm, &hr);
  736. return hr.error;
  737. }
  738. u16 hpi_instream_query_format(u32 h_instream,
  739. const struct hpi_format *p_format)
  740. {
  741. struct hpi_message hm;
  742. struct hpi_response hr;
  743. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  744. HPI_ISTREAM_QUERY_FORMAT);
  745. if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
  746. return HPI_ERROR_INVALID_HANDLE;
  747. hpi_format_to_msg(&hm.u.d.u.data.format, p_format);
  748. hpi_send_recv(&hm, &hr);
  749. return hr.error;
  750. }
  751. u16 hpi_instream_set_format(u32 h_instream, const struct hpi_format *p_format)
  752. {
  753. struct hpi_message hm;
  754. struct hpi_response hr;
  755. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  756. HPI_ISTREAM_SET_FORMAT);
  757. if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
  758. return HPI_ERROR_INVALID_HANDLE;
  759. hpi_format_to_msg(&hm.u.d.u.data.format, p_format);
  760. hpi_send_recv(&hm, &hr);
  761. return hr.error;
  762. }
  763. u16 hpi_instream_read_buf(u32 h_instream, u8 *pb_data, u32 bytes_to_read)
  764. {
  765. struct hpi_message hm;
  766. struct hpi_response hr;
  767. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  768. HPI_ISTREAM_READ);
  769. if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
  770. return HPI_ERROR_INVALID_HANDLE;
  771. hm.u.d.u.data.data_size = bytes_to_read;
  772. hm.u.d.u.data.pb_data = pb_data;
  773. hpi_send_recv(&hm, &hr);
  774. return hr.error;
  775. }
  776. u16 hpi_instream_start(u32 h_instream)
  777. {
  778. struct hpi_message hm;
  779. struct hpi_response hr;
  780. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  781. HPI_ISTREAM_START);
  782. if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
  783. return HPI_ERROR_INVALID_HANDLE;
  784. hpi_send_recv(&hm, &hr);
  785. return hr.error;
  786. }
  787. u16 hpi_instream_wait_start(u32 h_instream)
  788. {
  789. struct hpi_message hm;
  790. struct hpi_response hr;
  791. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  792. HPI_ISTREAM_WAIT_START);
  793. if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
  794. return HPI_ERROR_INVALID_HANDLE;
  795. hpi_send_recv(&hm, &hr);
  796. return hr.error;
  797. }
  798. u16 hpi_instream_stop(u32 h_instream)
  799. {
  800. struct hpi_message hm;
  801. struct hpi_response hr;
  802. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  803. HPI_ISTREAM_STOP);
  804. if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
  805. return HPI_ERROR_INVALID_HANDLE;
  806. hpi_send_recv(&hm, &hr);
  807. return hr.error;
  808. }
  809. u16 hpi_instream_reset(u32 h_instream)
  810. {
  811. struct hpi_message hm;
  812. struct hpi_response hr;
  813. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  814. HPI_ISTREAM_RESET);
  815. if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
  816. return HPI_ERROR_INVALID_HANDLE;
  817. hpi_send_recv(&hm, &hr);
  818. return hr.error;
  819. }
  820. u16 hpi_instream_get_info_ex(u32 h_instream, u16 *pw_state, u32 *pbuffer_size,
  821. u32 *pdata_recorded, u32 *psamples_recorded,
  822. u32 *pauxiliary_data_recorded)
  823. {
  824. struct hpi_message hm;
  825. struct hpi_response hr;
  826. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  827. HPI_ISTREAM_GET_INFO);
  828. if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
  829. return HPI_ERROR_INVALID_HANDLE;
  830. hpi_send_recv(&hm, &hr);
  831. if (pw_state)
  832. *pw_state = hr.u.d.u.stream_info.state;
  833. if (pbuffer_size)
  834. *pbuffer_size = hr.u.d.u.stream_info.buffer_size;
  835. if (pdata_recorded)
  836. *pdata_recorded = hr.u.d.u.stream_info.data_available;
  837. if (psamples_recorded)
  838. *psamples_recorded = hr.u.d.u.stream_info.samples_transferred;
  839. if (pauxiliary_data_recorded)
  840. *pauxiliary_data_recorded =
  841. hr.u.d.u.stream_info.auxiliary_data_available;
  842. return hr.error;
  843. }
  844. u16 hpi_instream_ancillary_reset(u32 h_instream, u16 bytes_per_frame,
  845. u16 mode, u16 alignment, u16 idle_bit)
  846. {
  847. struct hpi_message hm;
  848. struct hpi_response hr;
  849. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  850. HPI_ISTREAM_ANC_RESET);
  851. if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
  852. return HPI_ERROR_INVALID_HANDLE;
  853. hm.u.d.u.data.format.attributes = bytes_per_frame;
  854. hm.u.d.u.data.format.format = (mode << 8) | (alignment & 0xff);
  855. hm.u.d.u.data.format.channels = idle_bit;
  856. hpi_send_recv(&hm, &hr);
  857. return hr.error;
  858. }
  859. u16 hpi_instream_ancillary_get_info(u32 h_instream, u32 *pframe_space)
  860. {
  861. struct hpi_message hm;
  862. struct hpi_response hr;
  863. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  864. HPI_ISTREAM_ANC_GET_INFO);
  865. if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
  866. return HPI_ERROR_INVALID_HANDLE;
  867. hpi_send_recv(&hm, &hr);
  868. if (pframe_space)
  869. *pframe_space =
  870. (hr.u.d.u.stream_info.buffer_size -
  871. hr.u.d.u.stream_info.data_available) /
  872. sizeof(struct hpi_anc_frame);
  873. return hr.error;
  874. }
  875. u16 hpi_instream_ancillary_write(u32 h_instream,
  876. const struct hpi_anc_frame *p_anc_frame_buffer,
  877. u32 anc_frame_buffer_size_in_bytes,
  878. u32 number_of_ancillary_frames_to_write)
  879. {
  880. struct hpi_message hm;
  881. struct hpi_response hr;
  882. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  883. HPI_ISTREAM_ANC_WRITE);
  884. if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
  885. return HPI_ERROR_INVALID_HANDLE;
  886. hm.u.d.u.data.pb_data = (u8 *)p_anc_frame_buffer;
  887. hm.u.d.u.data.data_size =
  888. number_of_ancillary_frames_to_write *
  889. sizeof(struct hpi_anc_frame);
  890. if (hm.u.d.u.data.data_size <= anc_frame_buffer_size_in_bytes)
  891. hpi_send_recv(&hm, &hr);
  892. else
  893. hr.error = HPI_ERROR_INVALID_DATASIZE;
  894. return hr.error;
  895. }
  896. u16 hpi_instream_host_buffer_allocate(u32 h_instream, u32 size_in_bytes)
  897. {
  898. struct hpi_message hm;
  899. struct hpi_response hr;
  900. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  901. HPI_ISTREAM_HOSTBUFFER_ALLOC);
  902. if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
  903. return HPI_ERROR_INVALID_HANDLE;
  904. hm.u.d.u.data.data_size = size_in_bytes;
  905. hpi_send_recv(&hm, &hr);
  906. return hr.error;
  907. }
  908. u16 hpi_instream_host_buffer_get_info(u32 h_instream, u8 **pp_buffer,
  909. struct hpi_hostbuffer_status **pp_status)
  910. {
  911. struct hpi_message hm;
  912. struct hpi_response hr;
  913. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  914. HPI_ISTREAM_HOSTBUFFER_GET_INFO);
  915. if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
  916. return HPI_ERROR_INVALID_HANDLE;
  917. hpi_send_recv(&hm, &hr);
  918. if (hr.error == 0) {
  919. if (pp_buffer)
  920. *pp_buffer = hr.u.d.u.hostbuffer_info.p_buffer;
  921. if (pp_status)
  922. *pp_status = hr.u.d.u.hostbuffer_info.p_status;
  923. }
  924. return hr.error;
  925. }
  926. u16 hpi_instream_host_buffer_free(u32 h_instream)
  927. {
  928. struct hpi_message hm;
  929. struct hpi_response hr;
  930. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  931. HPI_ISTREAM_HOSTBUFFER_FREE);
  932. if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
  933. return HPI_ERROR_INVALID_HANDLE;
  934. hpi_send_recv(&hm, &hr);
  935. return hr.error;
  936. }
  937. u16 hpi_instream_group_add(u32 h_instream, u32 h_stream)
  938. {
  939. struct hpi_message hm;
  940. struct hpi_response hr;
  941. u16 adapter;
  942. char c_obj_type;
  943. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  944. HPI_ISTREAM_GROUP_ADD);
  945. hr.error = 0;
  946. if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
  947. return HPI_ERROR_INVALID_HANDLE;
  948. if (hpi_handle_indexes(h_stream, &adapter,
  949. &hm.u.d.u.stream.stream_index))
  950. return HPI_ERROR_INVALID_HANDLE;
  951. c_obj_type = hpi_handle_object(h_stream);
  952. switch (c_obj_type) {
  953. case HPI_OBJ_OSTREAM:
  954. case HPI_OBJ_ISTREAM:
  955. hm.u.d.u.stream.object_type = c_obj_type;
  956. break;
  957. default:
  958. return HPI_ERROR_INVALID_OBJ;
  959. }
  960. if (adapter != hm.adapter_index)
  961. return HPI_ERROR_NO_INTERADAPTER_GROUPS;
  962. hpi_send_recv(&hm, &hr);
  963. return hr.error;
  964. }
  965. u16 hpi_instream_group_get_map(u32 h_instream, u32 *poutstream_map,
  966. u32 *pinstream_map)
  967. {
  968. struct hpi_message hm;
  969. struct hpi_response hr;
  970. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  971. HPI_ISTREAM_HOSTBUFFER_FREE);
  972. if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
  973. return HPI_ERROR_INVALID_HANDLE;
  974. hpi_send_recv(&hm, &hr);
  975. if (poutstream_map)
  976. *poutstream_map = hr.u.d.u.group_info.outstream_group_map;
  977. if (pinstream_map)
  978. *pinstream_map = hr.u.d.u.group_info.instream_group_map;
  979. return hr.error;
  980. }
  981. u16 hpi_instream_group_reset(u32 h_instream)
  982. {
  983. struct hpi_message hm;
  984. struct hpi_response hr;
  985. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  986. HPI_ISTREAM_GROUP_RESET);
  987. if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
  988. return HPI_ERROR_INVALID_HANDLE;
  989. hpi_send_recv(&hm, &hr);
  990. return hr.error;
  991. }
  992. u16 hpi_mixer_open(u16 adapter_index, u32 *ph_mixer)
  993. {
  994. struct hpi_message hm;
  995. struct hpi_response hr;
  996. hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER, HPI_MIXER_OPEN);
  997. hm.adapter_index = adapter_index;
  998. hpi_send_recv(&hm, &hr);
  999. if (hr.error == 0)
  1000. *ph_mixer =
  1001. hpi_indexes_to_handle(HPI_OBJ_MIXER, adapter_index,
  1002. 0);
  1003. else
  1004. *ph_mixer = 0;
  1005. return hr.error;
  1006. }
  1007. u16 hpi_mixer_close(u32 h_mixer)
  1008. {
  1009. struct hpi_message hm;
  1010. struct hpi_response hr;
  1011. hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER, HPI_MIXER_CLOSE);
  1012. if (hpi_handle_indexes(h_mixer, &hm.adapter_index, NULL))
  1013. return HPI_ERROR_INVALID_HANDLE;
  1014. hpi_send_recv(&hm, &hr);
  1015. return hr.error;
  1016. }
  1017. u16 hpi_mixer_get_control(u32 h_mixer, u16 src_node_type,
  1018. u16 src_node_type_index, u16 dst_node_type, u16 dst_node_type_index,
  1019. u16 control_type, u32 *ph_control)
  1020. {
  1021. struct hpi_message hm;
  1022. struct hpi_response hr;
  1023. hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER,
  1024. HPI_MIXER_GET_CONTROL);
  1025. if (hpi_handle_indexes(h_mixer, &hm.adapter_index, NULL))
  1026. return HPI_ERROR_INVALID_HANDLE;
  1027. hm.u.m.node_type1 = src_node_type;
  1028. hm.u.m.node_index1 = src_node_type_index;
  1029. hm.u.m.node_type2 = dst_node_type;
  1030. hm.u.m.node_index2 = dst_node_type_index;
  1031. hm.u.m.control_type = control_type;
  1032. hpi_send_recv(&hm, &hr);
  1033. if (hr.error == 0)
  1034. *ph_control =
  1035. hpi_indexes_to_handle(HPI_OBJ_CONTROL,
  1036. hm.adapter_index, hr.u.m.control_index);
  1037. else
  1038. *ph_control = 0;
  1039. return hr.error;
  1040. }
  1041. u16 hpi_mixer_get_control_by_index(u32 h_mixer, u16 control_index,
  1042. u16 *pw_src_node_type, u16 *pw_src_node_index, u16 *pw_dst_node_type,
  1043. u16 *pw_dst_node_index, u16 *pw_control_type, u32 *ph_control)
  1044. {
  1045. struct hpi_message hm;
  1046. struct hpi_response hr;
  1047. hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER,
  1048. HPI_MIXER_GET_CONTROL_BY_INDEX);
  1049. if (hpi_handle_indexes(h_mixer, &hm.adapter_index, NULL))
  1050. return HPI_ERROR_INVALID_HANDLE;
  1051. hm.u.m.control_index = control_index;
  1052. hpi_send_recv(&hm, &hr);
  1053. if (pw_src_node_type) {
  1054. *pw_src_node_type =
  1055. hr.u.m.src_node_type + HPI_SOURCENODE_NONE;
  1056. *pw_src_node_index = hr.u.m.src_node_index;
  1057. *pw_dst_node_type = hr.u.m.dst_node_type + HPI_DESTNODE_NONE;
  1058. *pw_dst_node_index = hr.u.m.dst_node_index;
  1059. }
  1060. if (pw_control_type)
  1061. *pw_control_type = hr.u.m.control_index;
  1062. if (ph_control) {
  1063. if (hr.error == 0)
  1064. *ph_control =
  1065. hpi_indexes_to_handle(HPI_OBJ_CONTROL,
  1066. hm.adapter_index, control_index);
  1067. else
  1068. *ph_control = 0;
  1069. }
  1070. return hr.error;
  1071. }
  1072. u16 hpi_mixer_store(u32 h_mixer, enum HPI_MIXER_STORE_COMMAND command,
  1073. u16 index)
  1074. {
  1075. struct hpi_message hm;
  1076. struct hpi_response hr;
  1077. hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER, HPI_MIXER_STORE);
  1078. if (hpi_handle_indexes(h_mixer, &hm.adapter_index, NULL))
  1079. return HPI_ERROR_INVALID_HANDLE;
  1080. hm.u.mx.store.command = command;
  1081. hm.u.mx.store.index = index;
  1082. hpi_send_recv(&hm, &hr);
  1083. return hr.error;
  1084. }
  1085. static
  1086. u16 hpi_control_param_set(const u32 h_control, const u16 attrib,
  1087. const u32 param1, const u32 param2)
  1088. {
  1089. struct hpi_message hm;
  1090. struct hpi_response hr;
  1091. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1092. HPI_CONTROL_SET_STATE);
  1093. if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
  1094. return HPI_ERROR_INVALID_HANDLE;
  1095. hm.u.c.attribute = attrib;
  1096. hm.u.c.param1 = param1;
  1097. hm.u.c.param2 = param2;
  1098. hpi_send_recv(&hm, &hr);
  1099. return hr.error;
  1100. }
  1101. static u16 hpi_control_log_set2(u32 h_control, u16 attrib, short sv0,
  1102. short sv1)
  1103. {
  1104. struct hpi_message hm;
  1105. struct hpi_response hr;
  1106. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1107. HPI_CONTROL_SET_STATE);
  1108. if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
  1109. return HPI_ERROR_INVALID_HANDLE;
  1110. hm.u.c.attribute = attrib;
  1111. hm.u.c.an_log_value[0] = sv0;
  1112. hm.u.c.an_log_value[1] = sv1;
  1113. hpi_send_recv(&hm, &hr);
  1114. return hr.error;
  1115. }
  1116. static
  1117. u16 hpi_control_param_get(const u32 h_control, const u16 attrib, u32 param1,
  1118. u32 param2, u32 *pparam1, u32 *pparam2)
  1119. {
  1120. struct hpi_message hm;
  1121. struct hpi_response hr;
  1122. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1123. HPI_CONTROL_GET_STATE);
  1124. if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
  1125. return HPI_ERROR_INVALID_HANDLE;
  1126. hm.u.c.attribute = attrib;
  1127. hm.u.c.param1 = param1;
  1128. hm.u.c.param2 = param2;
  1129. hpi_send_recv(&hm, &hr);
  1130. *pparam1 = hr.u.c.param1;
  1131. if (pparam2)
  1132. *pparam2 = hr.u.c.param2;
  1133. return hr.error;
  1134. }
  1135. #define hpi_control_param1_get(h, a, p1) \
  1136. hpi_control_param_get(h, a, 0, 0, p1, NULL)
  1137. #define hpi_control_param2_get(h, a, p1, p2) \
  1138. hpi_control_param_get(h, a, 0, 0, p1, p2)
  1139. static u16 hpi_control_log_get2(u32 h_control, u16 attrib, short *sv0,
  1140. short *sv1)
  1141. {
  1142. struct hpi_message hm;
  1143. struct hpi_response hr;
  1144. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1145. HPI_CONTROL_GET_STATE);
  1146. if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
  1147. return HPI_ERROR_INVALID_HANDLE;
  1148. hm.u.c.attribute = attrib;
  1149. hpi_send_recv(&hm, &hr);
  1150. *sv0 = hr.u.c.an_log_value[0];
  1151. if (sv1)
  1152. *sv1 = hr.u.c.an_log_value[1];
  1153. return hr.error;
  1154. }
  1155. static
  1156. u16 hpi_control_query(const u32 h_control, const u16 attrib, const u32 index,
  1157. const u32 param, u32 *psetting)
  1158. {
  1159. struct hpi_message hm;
  1160. struct hpi_response hr;
  1161. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1162. HPI_CONTROL_GET_INFO);
  1163. if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
  1164. return HPI_ERROR_INVALID_HANDLE;
  1165. hm.u.c.attribute = attrib;
  1166. hm.u.c.param1 = index;
  1167. hm.u.c.param2 = param;
  1168. hpi_send_recv(&hm, &hr);
  1169. *psetting = hr.u.c.param1;
  1170. return hr.error;
  1171. }
  1172. static u16 hpi_control_get_string(const u32 h_control, const u16 attribute,
  1173. char *psz_string, const u32 string_length)
  1174. {
  1175. unsigned int sub_string_index = 0, j = 0;
  1176. char c = 0;
  1177. unsigned int n = 0;
  1178. u16 err = 0;
  1179. if ((string_length < 1) || (string_length > 256))
  1180. return HPI_ERROR_INVALID_CONTROL_VALUE;
  1181. for (sub_string_index = 0; sub_string_index < string_length;
  1182. sub_string_index += 8) {
  1183. struct hpi_message hm;
  1184. struct hpi_response hr;
  1185. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1186. HPI_CONTROL_GET_STATE);
  1187. if (hpi_handle_indexes(h_control, &hm.adapter_index,
  1188. &hm.obj_index))
  1189. return HPI_ERROR_INVALID_HANDLE;
  1190. hm.u.c.attribute = attribute;
  1191. hm.u.c.param1 = sub_string_index;
  1192. hm.u.c.param2 = 0;
  1193. hpi_send_recv(&hm, &hr);
  1194. if (sub_string_index == 0
  1195. && (hr.u.cu.chars8.remaining_chars + 8) >
  1196. string_length)
  1197. return HPI_ERROR_INVALID_CONTROL_VALUE;
  1198. if (hr.error) {
  1199. err = hr.error;
  1200. break;
  1201. }
  1202. for (j = 0; j < 8; j++) {
  1203. c = hr.u.cu.chars8.sz_data[j];
  1204. psz_string[sub_string_index + j] = c;
  1205. n++;
  1206. if (n >= string_length) {
  1207. psz_string[string_length - 1] = 0;
  1208. err = HPI_ERROR_INVALID_CONTROL_VALUE;
  1209. break;
  1210. }
  1211. if (c == 0)
  1212. break;
  1213. }
  1214. if ((hr.u.cu.chars8.remaining_chars == 0)
  1215. && ((sub_string_index + j) < string_length)
  1216. && (c != 0)) {
  1217. c = 0;
  1218. psz_string[sub_string_index + j] = c;
  1219. }
  1220. if (c == 0)
  1221. break;
  1222. }
  1223. return err;
  1224. }
  1225. u16 hpi_aesebu_receiver_query_format(const u32 h_aes_rx, const u32 index,
  1226. u16 *pw_format)
  1227. {
  1228. u32 qr;
  1229. u16 err;
  1230. err = hpi_control_query(h_aes_rx, HPI_AESEBURX_FORMAT, index, 0, &qr);
  1231. *pw_format = (u16)qr;
  1232. return err;
  1233. }
  1234. u16 hpi_aesebu_receiver_set_format(u32 h_control, u16 format)
  1235. {
  1236. return hpi_control_param_set(h_control, HPI_AESEBURX_FORMAT, format,
  1237. 0);
  1238. }
  1239. u16 hpi_aesebu_receiver_get_format(u32 h_control, u16 *pw_format)
  1240. {
  1241. u16 err;
  1242. u32 param;
  1243. err = hpi_control_param1_get(h_control, HPI_AESEBURX_FORMAT, &param);
  1244. if (!err && pw_format)
  1245. *pw_format = (u16)param;
  1246. return err;
  1247. }
  1248. u16 hpi_aesebu_receiver_get_sample_rate(u32 h_control, u32 *psample_rate)
  1249. {
  1250. return hpi_control_param1_get(h_control, HPI_AESEBURX_SAMPLERATE,
  1251. psample_rate);
  1252. }
  1253. u16 hpi_aesebu_receiver_get_user_data(u32 h_control, u16 index, u16 *pw_data)
  1254. {
  1255. struct hpi_message hm;
  1256. struct hpi_response hr;
  1257. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1258. HPI_CONTROL_GET_STATE);
  1259. if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
  1260. return HPI_ERROR_INVALID_HANDLE;
  1261. hm.u.c.attribute = HPI_AESEBURX_USERDATA;
  1262. hm.u.c.param1 = index;
  1263. hpi_send_recv(&hm, &hr);
  1264. if (pw_data)
  1265. *pw_data = (u16)hr.u.c.param2;
  1266. return hr.error;
  1267. }
  1268. u16 hpi_aesebu_receiver_get_channel_status(u32 h_control, u16 index,
  1269. u16 *pw_data)
  1270. {
  1271. struct hpi_message hm;
  1272. struct hpi_response hr;
  1273. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1274. HPI_CONTROL_GET_STATE);
  1275. if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
  1276. return HPI_ERROR_INVALID_HANDLE;
  1277. hm.u.c.attribute = HPI_AESEBURX_CHANNELSTATUS;
  1278. hm.u.c.param1 = index;
  1279. hpi_send_recv(&hm, &hr);
  1280. if (pw_data)
  1281. *pw_data = (u16)hr.u.c.param2;
  1282. return hr.error;
  1283. }
  1284. u16 hpi_aesebu_receiver_get_error_status(u32 h_control, u16 *pw_error_data)
  1285. {
  1286. u32 error_data = 0;
  1287. u16 err = 0;
  1288. err = hpi_control_param1_get(h_control, HPI_AESEBURX_ERRORSTATUS,
  1289. &error_data);
  1290. if (pw_error_data)
  1291. *pw_error_data = (u16)error_data;
  1292. return err;
  1293. }
  1294. u16 hpi_aesebu_transmitter_set_sample_rate(u32 h_control, u32 sample_rate)
  1295. {
  1296. return hpi_control_param_set(h_control, HPI_AESEBUTX_SAMPLERATE,
  1297. sample_rate, 0);
  1298. }
  1299. u16 hpi_aesebu_transmitter_set_user_data(u32 h_control, u16 index, u16 data)
  1300. {
  1301. return hpi_control_param_set(h_control, HPI_AESEBUTX_USERDATA, index,
  1302. data);
  1303. }
  1304. u16 hpi_aesebu_transmitter_set_channel_status(u32 h_control, u16 index,
  1305. u16 data)
  1306. {
  1307. return hpi_control_param_set(h_control, HPI_AESEBUTX_CHANNELSTATUS,
  1308. index, data);
  1309. }
  1310. u16 hpi_aesebu_transmitter_get_channel_status(u32 h_control, u16 index,
  1311. u16 *pw_data)
  1312. {
  1313. return HPI_ERROR_INVALID_OPERATION;
  1314. }
  1315. u16 hpi_aesebu_transmitter_query_format(const u32 h_aes_tx, const u32 index,
  1316. u16 *pw_format)
  1317. {
  1318. u32 qr;
  1319. u16 err;
  1320. err = hpi_control_query(h_aes_tx, HPI_AESEBUTX_FORMAT, index, 0, &qr);
  1321. *pw_format = (u16)qr;
  1322. return err;
  1323. }
  1324. u16 hpi_aesebu_transmitter_set_format(u32 h_control, u16 output_format)
  1325. {
  1326. return hpi_control_param_set(h_control, HPI_AESEBUTX_FORMAT,
  1327. output_format, 0);
  1328. }
  1329. u16 hpi_aesebu_transmitter_get_format(u32 h_control, u16 *pw_output_format)
  1330. {
  1331. u16 err;
  1332. u32 param;
  1333. err = hpi_control_param1_get(h_control, HPI_AESEBUTX_FORMAT, &param);
  1334. if (!err && pw_output_format)
  1335. *pw_output_format = (u16)param;
  1336. return err;
  1337. }
  1338. u16 hpi_bitstream_set_clock_edge(u32 h_control, u16 edge_type)
  1339. {
  1340. return hpi_control_param_set(h_control, HPI_BITSTREAM_CLOCK_EDGE,
  1341. edge_type, 0);
  1342. }
  1343. u16 hpi_bitstream_set_data_polarity(u32 h_control, u16 polarity)
  1344. {
  1345. return hpi_control_param_set(h_control, HPI_BITSTREAM_DATA_POLARITY,
  1346. polarity, 0);
  1347. }
  1348. u16 hpi_bitstream_get_activity(u32 h_control, u16 *pw_clk_activity,
  1349. u16 *pw_data_activity)
  1350. {
  1351. struct hpi_message hm;
  1352. struct hpi_response hr;
  1353. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1354. HPI_CONTROL_GET_STATE);
  1355. if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
  1356. return HPI_ERROR_INVALID_HANDLE;
  1357. hm.u.c.attribute = HPI_BITSTREAM_ACTIVITY;
  1358. hpi_send_recv(&hm, &hr);
  1359. if (pw_clk_activity)
  1360. *pw_clk_activity = (u16)hr.u.c.param1;
  1361. if (pw_data_activity)
  1362. *pw_data_activity = (u16)hr.u.c.param2;
  1363. return hr.error;
  1364. }
  1365. u16 hpi_channel_mode_query_mode(const u32 h_mode, const u32 index,
  1366. u16 *pw_mode)
  1367. {
  1368. u32 qr;
  1369. u16 err;
  1370. err = hpi_control_query(h_mode, HPI_CHANNEL_MODE_MODE, index, 0, &qr);
  1371. *pw_mode = (u16)qr;
  1372. return err;
  1373. }
  1374. u16 hpi_channel_mode_set(u32 h_control, u16 mode)
  1375. {
  1376. return hpi_control_param_set(h_control, HPI_CHANNEL_MODE_MODE, mode,
  1377. 0);
  1378. }
  1379. u16 hpi_channel_mode_get(u32 h_control, u16 *mode)
  1380. {
  1381. u32 mode32 = 0;
  1382. u16 err = hpi_control_param1_get(h_control,
  1383. HPI_CHANNEL_MODE_MODE, &mode32);
  1384. if (mode)
  1385. *mode = (u16)mode32;
  1386. return err;
  1387. }
  1388. u16 hpi_cobranet_hmi_write(u32 h_control, u32 hmi_address, u32 byte_count,
  1389. u8 *pb_data)
  1390. {
  1391. struct hpi_msg_cobranet_hmiwrite hm;
  1392. struct hpi_response_header hr;
  1393. hpi_init_message_responseV1(&hm.h, sizeof(hm), &hr, sizeof(hr),
  1394. HPI_OBJ_CONTROL, HPI_CONTROL_SET_STATE);
  1395. if (hpi_handle_indexes(h_control, &hm.h.adapter_index,
  1396. &hm.h.obj_index))
  1397. return HPI_ERROR_INVALID_HANDLE;
  1398. if (byte_count > sizeof(hm.bytes))
  1399. return HPI_ERROR_MESSAGE_BUFFER_TOO_SMALL;
  1400. hm.p.attribute = HPI_COBRANET_SET;
  1401. hm.p.byte_count = byte_count;
  1402. hm.p.hmi_address = hmi_address;
  1403. memcpy(hm.bytes, pb_data, byte_count);
  1404. hm.h.size = (u16)(sizeof(hm.h) + sizeof(hm.p) + byte_count);
  1405. hpi_send_recvV1(&hm.h, &hr);
  1406. return hr.error;
  1407. }
  1408. u16 hpi_cobranet_hmi_read(u32 h_control, u32 hmi_address, u32 max_byte_count,
  1409. u32 *pbyte_count, u8 *pb_data)
  1410. {
  1411. struct hpi_msg_cobranet_hmiread hm;
  1412. struct hpi_res_cobranet_hmiread hr;
  1413. hpi_init_message_responseV1(&hm.h, sizeof(hm), &hr.h, sizeof(hr),
  1414. HPI_OBJ_CONTROL, HPI_CONTROL_GET_STATE);
  1415. if (hpi_handle_indexes(h_control, &hm.h.adapter_index,
  1416. &hm.h.obj_index))
  1417. return HPI_ERROR_INVALID_HANDLE;
  1418. if (max_byte_count > sizeof(hr.bytes))
  1419. return HPI_ERROR_RESPONSE_BUFFER_TOO_SMALL;
  1420. hm.p.attribute = HPI_COBRANET_GET;
  1421. hm.p.byte_count = max_byte_count;
  1422. hm.p.hmi_address = hmi_address;
  1423. hpi_send_recvV1(&hm.h, &hr.h);
  1424. if (!hr.h.error && pb_data) {
  1425. if (hr.byte_count > sizeof(hr.bytes))
  1426. return HPI_ERROR_RESPONSE_BUFFER_TOO_SMALL;
  1427. *pbyte_count = hr.byte_count;
  1428. if (hr.byte_count < max_byte_count)
  1429. max_byte_count = *pbyte_count;
  1430. memcpy(pb_data, hr.bytes, max_byte_count);
  1431. }
  1432. return hr.h.error;
  1433. }
  1434. u16 hpi_cobranet_hmi_get_status(u32 h_control, u32 *pstatus,
  1435. u32 *preadable_size, u32 *pwriteable_size)
  1436. {
  1437. struct hpi_message hm;
  1438. struct hpi_response hr;
  1439. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1440. HPI_CONTROL_GET_STATE);
  1441. if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
  1442. return HPI_ERROR_INVALID_HANDLE;
  1443. hm.u.c.attribute = HPI_COBRANET_GET_STATUS;
  1444. hpi_send_recv(&hm, &hr);
  1445. if (!hr.error) {
  1446. if (pstatus)
  1447. *pstatus = hr.u.cu.cobranet.status.status;
  1448. if (preadable_size)
  1449. *preadable_size =
  1450. hr.u.cu.cobranet.status.readable_size;
  1451. if (pwriteable_size)
  1452. *pwriteable_size =
  1453. hr.u.cu.cobranet.status.writeable_size;
  1454. }
  1455. return hr.error;
  1456. }
  1457. u16 hpi_cobranet_get_ip_address(u32 h_control, u32 *pdw_ip_address)
  1458. {
  1459. u32 byte_count;
  1460. u32 iP;
  1461. u16 err;
  1462. err = hpi_cobranet_hmi_read(h_control,
  1463. HPI_COBRANET_HMI_cobra_ip_mon_currentIP, 4, &byte_count,
  1464. (u8 *)&iP);
  1465. *pdw_ip_address =
  1466. ((iP & 0xff000000) >> 8) | ((iP & 0x00ff0000) << 8) | ((iP &
  1467. 0x0000ff00) >> 8) | ((iP & 0x000000ff) << 8);
  1468. if (err)
  1469. *pdw_ip_address = 0;
  1470. return err;
  1471. }
  1472. u16 hpi_cobranet_set_ip_address(u32 h_control, u32 dw_ip_address)
  1473. {
  1474. u32 iP;
  1475. u16 err;
  1476. iP = ((dw_ip_address & 0xff000000) >> 8) | ((dw_ip_address &
  1477. 0x00ff0000) << 8) | ((dw_ip_address & 0x0000ff00) >>
  1478. 8) | ((dw_ip_address & 0x000000ff) << 8);
  1479. err = hpi_cobranet_hmi_write(h_control,
  1480. HPI_COBRANET_HMI_cobra_ip_mon_currentIP, 4, (u8 *)&iP);
  1481. return err;
  1482. }
  1483. u16 hpi_cobranet_get_static_ip_address(u32 h_control, u32 *pdw_ip_address)
  1484. {
  1485. u32 byte_count;
  1486. u32 iP;
  1487. u16 err;
  1488. err = hpi_cobranet_hmi_read(h_control,
  1489. HPI_COBRANET_HMI_cobra_ip_mon_staticIP, 4, &byte_count,
  1490. (u8 *)&iP);
  1491. *pdw_ip_address =
  1492. ((iP & 0xff000000) >> 8) | ((iP & 0x00ff0000) << 8) | ((iP &
  1493. 0x0000ff00) >> 8) | ((iP & 0x000000ff) << 8);
  1494. if (err)
  1495. *pdw_ip_address = 0;
  1496. return err;
  1497. }
  1498. u16 hpi_cobranet_set_static_ip_address(u32 h_control, u32 dw_ip_address)
  1499. {
  1500. u32 iP;
  1501. u16 err;
  1502. iP = ((dw_ip_address & 0xff000000) >> 8) | ((dw_ip_address &
  1503. 0x00ff0000) << 8) | ((dw_ip_address & 0x0000ff00) >>
  1504. 8) | ((dw_ip_address & 0x000000ff) << 8);
  1505. err = hpi_cobranet_hmi_write(h_control,
  1506. HPI_COBRANET_HMI_cobra_ip_mon_staticIP, 4, (u8 *)&iP);
  1507. return err;
  1508. }
  1509. u16 hpi_cobranet_get_macaddress(u32 h_control, u32 *p_mac_msbs,
  1510. u32 *p_mac_lsbs)
  1511. {
  1512. u32 byte_count;
  1513. u16 err;
  1514. u32 mac;
  1515. err = hpi_cobranet_hmi_read(h_control,
  1516. HPI_COBRANET_HMI_cobra_if_phy_address, 4, &byte_count,
  1517. (u8 *)&mac);
  1518. if (!err) {
  1519. *p_mac_msbs =
  1520. ((mac & 0xff000000) >> 8) | ((mac & 0x00ff0000) << 8)
  1521. | ((mac & 0x0000ff00) >> 8) | ((mac & 0x000000ff) <<
  1522. 8);
  1523. err = hpi_cobranet_hmi_read(h_control,
  1524. HPI_COBRANET_HMI_cobra_if_phy_address + 1, 4,
  1525. &byte_count, (u8 *)&mac);
  1526. }
  1527. if (!err) {
  1528. *p_mac_lsbs =
  1529. ((mac & 0xff000000) >> 8) | ((mac & 0x00ff0000) << 8)
  1530. | ((mac & 0x0000ff00) >> 8) | ((mac & 0x000000ff) <<
  1531. 8);
  1532. } else {
  1533. *p_mac_msbs = 0;
  1534. *p_mac_lsbs = 0;
  1535. }
  1536. return err;
  1537. }
  1538. u16 hpi_compander_set_enable(u32 h_control, u32 enable)
  1539. {
  1540. return hpi_control_param_set(h_control, HPI_GENERIC_ENABLE, enable,
  1541. 0);
  1542. }
  1543. u16 hpi_compander_get_enable(u32 h_control, u32 *enable)
  1544. {
  1545. return hpi_control_param1_get(h_control, HPI_GENERIC_ENABLE, enable);
  1546. }
  1547. u16 hpi_compander_set_makeup_gain(u32 h_control, short makeup_gain0_01dB)
  1548. {
  1549. return hpi_control_log_set2(h_control, HPI_COMPANDER_MAKEUPGAIN,
  1550. makeup_gain0_01dB, 0);
  1551. }
  1552. u16 hpi_compander_get_makeup_gain(u32 h_control, short *makeup_gain0_01dB)
  1553. {
  1554. return hpi_control_log_get2(h_control, HPI_COMPANDER_MAKEUPGAIN,
  1555. makeup_gain0_01dB, NULL);
  1556. }
  1557. u16 hpi_compander_set_attack_time_constant(u32 h_control, unsigned int index,
  1558. u32 attack)
  1559. {
  1560. return hpi_control_param_set(h_control, HPI_COMPANDER_ATTACK, attack,
  1561. index);
  1562. }
  1563. u16 hpi_compander_get_attack_time_constant(u32 h_control, unsigned int index,
  1564. u32 *attack)
  1565. {
  1566. return hpi_control_param_get(h_control, HPI_COMPANDER_ATTACK, 0,
  1567. index, attack, NULL);
  1568. }
  1569. u16 hpi_compander_set_decay_time_constant(u32 h_control, unsigned int index,
  1570. u32 decay)
  1571. {
  1572. return hpi_control_param_set(h_control, HPI_COMPANDER_DECAY, decay,
  1573. index);
  1574. }
  1575. u16 hpi_compander_get_decay_time_constant(u32 h_control, unsigned int index,
  1576. u32 *decay)
  1577. {
  1578. return hpi_control_param_get(h_control, HPI_COMPANDER_DECAY, 0, index,
  1579. decay, NULL);
  1580. }
  1581. u16 hpi_compander_set_threshold(u32 h_control, unsigned int index,
  1582. short threshold0_01dB)
  1583. {
  1584. struct hpi_message hm;
  1585. struct hpi_response hr;
  1586. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1587. HPI_CONTROL_SET_STATE);
  1588. if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
  1589. return HPI_ERROR_INVALID_HANDLE;
  1590. hm.u.c.attribute = HPI_COMPANDER_THRESHOLD;
  1591. hm.u.c.param2 = index;
  1592. hm.u.c.an_log_value[0] = threshold0_01dB;
  1593. hpi_send_recv(&hm, &hr);
  1594. return hr.error;
  1595. }
  1596. u16 hpi_compander_get_threshold(u32 h_control, unsigned int index,
  1597. short *threshold0_01dB)
  1598. {
  1599. struct hpi_message hm;
  1600. struct hpi_response hr;
  1601. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1602. HPI_CONTROL_GET_STATE);
  1603. if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
  1604. return HPI_ERROR_INVALID_HANDLE;
  1605. hm.u.c.attribute = HPI_COMPANDER_THRESHOLD;
  1606. hm.u.c.param2 = index;
  1607. hpi_send_recv(&hm, &hr);
  1608. *threshold0_01dB = hr.u.c.an_log_value[0];
  1609. return hr.error;
  1610. }
  1611. u16 hpi_compander_set_ratio(u32 h_control, u32 index, u32 ratio100)
  1612. {
  1613. return hpi_control_param_set(h_control, HPI_COMPANDER_RATIO, ratio100,
  1614. index);
  1615. }
  1616. u16 hpi_compander_get_ratio(u32 h_control, u32 index, u32 *ratio100)
  1617. {
  1618. return hpi_control_param_get(h_control, HPI_COMPANDER_RATIO, 0, index,
  1619. ratio100, NULL);
  1620. }
  1621. u16 hpi_level_query_range(u32 h_control, short *min_gain_01dB,
  1622. short *max_gain_01dB, short *step_gain_01dB)
  1623. {
  1624. struct hpi_message hm;
  1625. struct hpi_response hr;
  1626. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1627. HPI_CONTROL_GET_STATE);
  1628. if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
  1629. return HPI_ERROR_INVALID_HANDLE;
  1630. hm.u.c.attribute = HPI_LEVEL_RANGE;
  1631. hpi_send_recv(&hm, &hr);
  1632. if (hr.error) {
  1633. hr.u.c.an_log_value[0] = 0;
  1634. hr.u.c.an_log_value[1] = 0;
  1635. hr.u.c.param1 = 0;
  1636. }
  1637. if (min_gain_01dB)
  1638. *min_gain_01dB = hr.u.c.an_log_value[0];
  1639. if (max_gain_01dB)
  1640. *max_gain_01dB = hr.u.c.an_log_value[1];
  1641. if (step_gain_01dB)
  1642. *step_gain_01dB = (short)hr.u.c.param1;
  1643. return hr.error;
  1644. }
  1645. u16 hpi_level_set_gain(u32 h_control, short an_gain0_01dB[HPI_MAX_CHANNELS]
  1646. )
  1647. {
  1648. return hpi_control_log_set2(h_control, HPI_LEVEL_GAIN,
  1649. an_gain0_01dB[0], an_gain0_01dB[1]);
  1650. }
  1651. u16 hpi_level_get_gain(u32 h_control, short an_gain0_01dB[HPI_MAX_CHANNELS]
  1652. )
  1653. {
  1654. return hpi_control_log_get2(h_control, HPI_LEVEL_GAIN,
  1655. &an_gain0_01dB[0], &an_gain0_01dB[1]);
  1656. }
  1657. u16 hpi_meter_query_channels(const u32 h_meter, u32 *p_channels)
  1658. {
  1659. return hpi_control_query(h_meter, HPI_METER_NUM_CHANNELS, 0, 0,
  1660. p_channels);
  1661. }
  1662. u16 hpi_meter_get_peak(u32 h_control, short an_peakdB[HPI_MAX_CHANNELS]
  1663. )
  1664. {
  1665. short i = 0;
  1666. struct hpi_message hm;
  1667. struct hpi_response hr;
  1668. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1669. HPI_CONTROL_GET_STATE);
  1670. if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
  1671. return HPI_ERROR_INVALID_HANDLE;
  1672. hm.u.c.attribute = HPI_METER_PEAK;
  1673. hpi_send_recv(&hm, &hr);
  1674. if (!hr.error)
  1675. memcpy(an_peakdB, hr.u.c.an_log_value,
  1676. sizeof(short) * HPI_MAX_CHANNELS);
  1677. else
  1678. for (i = 0; i < HPI_MAX_CHANNELS; i++)
  1679. an_peakdB[i] = HPI_METER_MINIMUM;
  1680. return hr.error;
  1681. }
  1682. u16 hpi_meter_get_rms(u32 h_control, short an_rmsdB[HPI_MAX_CHANNELS]
  1683. )
  1684. {
  1685. short i = 0;
  1686. struct hpi_message hm;
  1687. struct hpi_response hr;
  1688. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1689. HPI_CONTROL_GET_STATE);
  1690. if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
  1691. return HPI_ERROR_INVALID_HANDLE;
  1692. hm.u.c.attribute = HPI_METER_RMS;
  1693. hpi_send_recv(&hm, &hr);
  1694. if (!hr.error)
  1695. memcpy(an_rmsdB, hr.u.c.an_log_value,
  1696. sizeof(short) * HPI_MAX_CHANNELS);
  1697. else
  1698. for (i = 0; i < HPI_MAX_CHANNELS; i++)
  1699. an_rmsdB[i] = HPI_METER_MINIMUM;
  1700. return hr.error;
  1701. }
  1702. u16 hpi_meter_set_rms_ballistics(u32 h_control, u16 attack, u16 decay)
  1703. {
  1704. return hpi_control_param_set(h_control, HPI_METER_RMS_BALLISTICS,
  1705. attack, decay);
  1706. }
  1707. u16 hpi_meter_get_rms_ballistics(u32 h_control, u16 *pn_attack, u16 *pn_decay)
  1708. {
  1709. u32 attack;
  1710. u32 decay;
  1711. u16 error;
  1712. error = hpi_control_param2_get(h_control, HPI_METER_RMS_BALLISTICS,
  1713. &attack, &decay);
  1714. if (pn_attack)
  1715. *pn_attack = (unsigned short)attack;
  1716. if (pn_decay)
  1717. *pn_decay = (unsigned short)decay;
  1718. return error;
  1719. }
  1720. u16 hpi_meter_set_peak_ballistics(u32 h_control, u16 attack, u16 decay)
  1721. {
  1722. return hpi_control_param_set(h_control, HPI_METER_PEAK_BALLISTICS,
  1723. attack, decay);
  1724. }
  1725. u16 hpi_meter_get_peak_ballistics(u32 h_control, u16 *pn_attack,
  1726. u16 *pn_decay)
  1727. {
  1728. u32 attack;
  1729. u32 decay;
  1730. u16 error;
  1731. error = hpi_control_param2_get(h_control, HPI_METER_PEAK_BALLISTICS,
  1732. &attack, &decay);
  1733. if (pn_attack)
  1734. *pn_attack = (short)attack;
  1735. if (pn_decay)
  1736. *pn_decay = (short)decay;
  1737. return error;
  1738. }
  1739. u16 hpi_microphone_set_phantom_power(u32 h_control, u16 on_off)
  1740. {
  1741. return hpi_control_param_set(h_control, HPI_MICROPHONE_PHANTOM_POWER,
  1742. (u32)on_off, 0);
  1743. }
  1744. u16 hpi_microphone_get_phantom_power(u32 h_control, u16 *pw_on_off)
  1745. {
  1746. u16 error = 0;
  1747. u32 on_off = 0;
  1748. error = hpi_control_param1_get(h_control,
  1749. HPI_MICROPHONE_PHANTOM_POWER, &on_off);
  1750. if (pw_on_off)
  1751. *pw_on_off = (u16)on_off;
  1752. return error;
  1753. }
  1754. u16 hpi_multiplexer_set_source(u32 h_control, u16 source_node_type,
  1755. u16 source_node_index)
  1756. {
  1757. return hpi_control_param_set(h_control, HPI_MULTIPLEXER_SOURCE,
  1758. source_node_type, source_node_index);
  1759. }
  1760. u16 hpi_multiplexer_get_source(u32 h_control, u16 *source_node_type,
  1761. u16 *source_node_index)
  1762. {
  1763. u32 node, index;
  1764. u16 err = hpi_control_param2_get(h_control,
  1765. HPI_MULTIPLEXER_SOURCE, &node,
  1766. &index);
  1767. if (source_node_type)
  1768. *source_node_type = (u16)node;
  1769. if (source_node_index)
  1770. *source_node_index = (u16)index;
  1771. return err;
  1772. }
  1773. u16 hpi_multiplexer_query_source(u32 h_control, u16 index,
  1774. u16 *source_node_type, u16 *source_node_index)
  1775. {
  1776. struct hpi_message hm;
  1777. struct hpi_response hr;
  1778. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1779. HPI_CONTROL_GET_STATE);
  1780. if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
  1781. return HPI_ERROR_INVALID_HANDLE;
  1782. hm.u.c.attribute = HPI_MULTIPLEXER_QUERYSOURCE;
  1783. hm.u.c.param1 = index;
  1784. hpi_send_recv(&hm, &hr);
  1785. if (source_node_type)
  1786. *source_node_type = (u16)hr.u.c.param1;
  1787. if (source_node_index)
  1788. *source_node_index = (u16)hr.u.c.param2;
  1789. return hr.error;
  1790. }
  1791. u16 hpi_parametric_eq_get_info(u32 h_control, u16 *pw_number_of_bands,
  1792. u16 *pw_on_off)
  1793. {
  1794. u32 oB = 0;
  1795. u32 oO = 0;
  1796. u16 error = 0;
  1797. error = hpi_control_param2_get(h_control, HPI_EQUALIZER_NUM_FILTERS,
  1798. &oO, &oB);
  1799. if (pw_number_of_bands)
  1800. *pw_number_of_bands = (u16)oB;
  1801. if (pw_on_off)
  1802. *pw_on_off = (u16)oO;
  1803. return error;
  1804. }
  1805. u16 hpi_parametric_eq_set_state(u32 h_control, u16 on_off)
  1806. {
  1807. return hpi_control_param_set(h_control, HPI_EQUALIZER_NUM_FILTERS,
  1808. on_off, 0);
  1809. }
  1810. u16 hpi_parametric_eq_get_band(u32 h_control, u16 index, u16 *pn_type,
  1811. u32 *pfrequency_hz, short *pnQ100, short *pn_gain0_01dB)
  1812. {
  1813. struct hpi_message hm;
  1814. struct hpi_response hr;
  1815. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1816. HPI_CONTROL_GET_STATE);
  1817. if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
  1818. return HPI_ERROR_INVALID_HANDLE;
  1819. hm.u.c.attribute = HPI_EQUALIZER_FILTER;
  1820. hm.u.c.param2 = index;
  1821. hpi_send_recv(&hm, &hr);
  1822. if (pfrequency_hz)
  1823. *pfrequency_hz = hr.u.c.param1;
  1824. if (pn_type)
  1825. *pn_type = (u16)(hr.u.c.param2 >> 16);
  1826. if (pnQ100)
  1827. *pnQ100 = hr.u.c.an_log_value[1];
  1828. if (pn_gain0_01dB)
  1829. *pn_gain0_01dB = hr.u.c.an_log_value[0];
  1830. return hr.error;
  1831. }
  1832. u16 hpi_parametric_eq_set_band(u32 h_control, u16 index, u16 type,
  1833. u32 frequency_hz, short q100, short gain0_01dB)
  1834. {
  1835. struct hpi_message hm;
  1836. struct hpi_response hr;
  1837. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1838. HPI_CONTROL_SET_STATE);
  1839. if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
  1840. return HPI_ERROR_INVALID_HANDLE;
  1841. hm.u.c.param1 = frequency_hz;
  1842. hm.u.c.param2 = (index & 0xFFFFL) + ((u32)type << 16);
  1843. hm.u.c.an_log_value[0] = gain0_01dB;
  1844. hm.u.c.an_log_value[1] = q100;
  1845. hm.u.c.attribute = HPI_EQUALIZER_FILTER;
  1846. hpi_send_recv(&hm, &hr);
  1847. return hr.error;
  1848. }
  1849. u16 hpi_parametric_eq_get_coeffs(u32 h_control, u16 index, short coeffs[5]
  1850. )
  1851. {
  1852. struct hpi_message hm;
  1853. struct hpi_response hr;
  1854. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1855. HPI_CONTROL_GET_STATE);
  1856. if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
  1857. return HPI_ERROR_INVALID_HANDLE;
  1858. hm.u.c.attribute = HPI_EQUALIZER_COEFFICIENTS;
  1859. hm.u.c.param2 = index;
  1860. hpi_send_recv(&hm, &hr);
  1861. coeffs[0] = (short)hr.u.c.an_log_value[0];
  1862. coeffs[1] = (short)hr.u.c.an_log_value[1];
  1863. coeffs[2] = (short)hr.u.c.param1;
  1864. coeffs[3] = (short)(hr.u.c.param1 >> 16);
  1865. coeffs[4] = (short)hr.u.c.param2;
  1866. return hr.error;
  1867. }
  1868. u16 hpi_sample_clock_query_source(const u32 h_clock, const u32 index,
  1869. u16 *pw_source)
  1870. {
  1871. u32 qr;
  1872. u16 err;
  1873. err = hpi_control_query(h_clock, HPI_SAMPLECLOCK_SOURCE, index, 0,
  1874. &qr);
  1875. *pw_source = (u16)qr;
  1876. return err;
  1877. }
  1878. u16 hpi_sample_clock_set_source(u32 h_control, u16 source)
  1879. {
  1880. return hpi_control_param_set(h_control, HPI_SAMPLECLOCK_SOURCE,
  1881. source, 0);
  1882. }
  1883. u16 hpi_sample_clock_get_source(u32 h_control, u16 *pw_source)
  1884. {
  1885. u16 err = 0;
  1886. u32 source = 0;
  1887. err = hpi_control_param1_get(h_control, HPI_SAMPLECLOCK_SOURCE,
  1888. &source);
  1889. if (!err)
  1890. if (pw_source)
  1891. *pw_source = (u16)source;
  1892. return err;
  1893. }
  1894. u16 hpi_sample_clock_query_source_index(const u32 h_clock, const u32 index,
  1895. const u32 source, u16 *pw_source_index)
  1896. {
  1897. u32 qr;
  1898. u16 err;
  1899. err = hpi_control_query(h_clock, HPI_SAMPLECLOCK_SOURCE_INDEX, index,
  1900. source, &qr);
  1901. *pw_source_index = (u16)qr;
  1902. return err;
  1903. }
  1904. u16 hpi_sample_clock_set_source_index(u32 h_control, u16 source_index)
  1905. {
  1906. return hpi_control_param_set(h_control, HPI_SAMPLECLOCK_SOURCE_INDEX,
  1907. source_index, 0);
  1908. }
  1909. u16 hpi_sample_clock_get_source_index(u32 h_control, u16 *pw_source_index)
  1910. {
  1911. u16 err = 0;
  1912. u32 source_index = 0;
  1913. err = hpi_control_param1_get(h_control, HPI_SAMPLECLOCK_SOURCE_INDEX,
  1914. &source_index);
  1915. if (!err)
  1916. if (pw_source_index)
  1917. *pw_source_index = (u16)source_index;
  1918. return err;
  1919. }
  1920. u16 hpi_sample_clock_query_local_rate(const u32 h_clock, const u32 index,
  1921. u32 *prate)
  1922. {
  1923. return hpi_control_query(h_clock, HPI_SAMPLECLOCK_LOCAL_SAMPLERATE,
  1924. index, 0, prate);
  1925. }
  1926. u16 hpi_sample_clock_set_local_rate(u32 h_control, u32 sample_rate)
  1927. {
  1928. return hpi_control_param_set(h_control,
  1929. HPI_SAMPLECLOCK_LOCAL_SAMPLERATE, sample_rate, 0);
  1930. }
  1931. u16 hpi_sample_clock_get_local_rate(u32 h_control, u32 *psample_rate)
  1932. {
  1933. u16 err = 0;
  1934. u32 sample_rate = 0;
  1935. err = hpi_control_param1_get(h_control,
  1936. HPI_SAMPLECLOCK_LOCAL_SAMPLERATE, &sample_rate);
  1937. if (!err)
  1938. if (psample_rate)
  1939. *psample_rate = sample_rate;
  1940. return err;
  1941. }
  1942. u16 hpi_sample_clock_get_sample_rate(u32 h_control, u32 *psample_rate)
  1943. {
  1944. u16 err = 0;
  1945. u32 sample_rate = 0;
  1946. err = hpi_control_param1_get(h_control, HPI_SAMPLECLOCK_SAMPLERATE,
  1947. &sample_rate);
  1948. if (!err)
  1949. if (psample_rate)
  1950. *psample_rate = sample_rate;
  1951. return err;
  1952. }
  1953. u16 hpi_sample_clock_set_auto(u32 h_control, u32 enable)
  1954. {
  1955. return hpi_control_param_set(h_control, HPI_SAMPLECLOCK_AUTO, enable,
  1956. 0);
  1957. }
  1958. u16 hpi_sample_clock_get_auto(u32 h_control, u32 *penable)
  1959. {
  1960. return hpi_control_param1_get(h_control, HPI_SAMPLECLOCK_AUTO,
  1961. penable);
  1962. }
  1963. u16 hpi_sample_clock_set_local_rate_lock(u32 h_control, u32 lock)
  1964. {
  1965. return hpi_control_param_set(h_control, HPI_SAMPLECLOCK_LOCAL_LOCK,
  1966. lock, 0);
  1967. }
  1968. u16 hpi_sample_clock_get_local_rate_lock(u32 h_control, u32 *plock)
  1969. {
  1970. return hpi_control_param1_get(h_control, HPI_SAMPLECLOCK_LOCAL_LOCK,
  1971. plock);
  1972. }
  1973. u16 hpi_tone_detector_get_frequency(u32 h_control, u32 index, u32 *frequency)
  1974. {
  1975. return hpi_control_param_get(h_control, HPI_TONEDETECTOR_FREQUENCY,
  1976. index, 0, frequency, NULL);
  1977. }
  1978. u16 hpi_tone_detector_get_state(u32 h_control, u32 *state)
  1979. {
  1980. return hpi_control_param1_get(h_control, HPI_TONEDETECTOR_STATE,
  1981. state);
  1982. }
  1983. u16 hpi_tone_detector_set_enable(u32 h_control, u32 enable)
  1984. {
  1985. return hpi_control_param_set(h_control, HPI_GENERIC_ENABLE, enable,
  1986. 0);
  1987. }
  1988. u16 hpi_tone_detector_get_enable(u32 h_control, u32 *enable)
  1989. {
  1990. return hpi_control_param1_get(h_control, HPI_GENERIC_ENABLE, enable);
  1991. }
  1992. u16 hpi_tone_detector_set_event_enable(u32 h_control, u32 event_enable)
  1993. {
  1994. return hpi_control_param_set(h_control, HPI_GENERIC_EVENT_ENABLE,
  1995. (u32)event_enable, 0);
  1996. }
  1997. u16 hpi_tone_detector_get_event_enable(u32 h_control, u32 *event_enable)
  1998. {
  1999. return hpi_control_param1_get(h_control, HPI_GENERIC_EVENT_ENABLE,
  2000. event_enable);
  2001. }
  2002. u16 hpi_tone_detector_set_threshold(u32 h_control, int threshold)
  2003. {
  2004. return hpi_control_param_set(h_control, HPI_TONEDETECTOR_THRESHOLD,
  2005. (u32)threshold, 0);
  2006. }
  2007. u16 hpi_tone_detector_get_threshold(u32 h_control, int *threshold)
  2008. {
  2009. return hpi_control_param1_get(h_control, HPI_TONEDETECTOR_THRESHOLD,
  2010. (u32 *)threshold);
  2011. }
  2012. u16 hpi_silence_detector_get_state(u32 h_control, u32 *state)
  2013. {
  2014. return hpi_control_param1_get(h_control, HPI_SILENCEDETECTOR_STATE,
  2015. state);
  2016. }
  2017. u16 hpi_silence_detector_set_enable(u32 h_control, u32 enable)
  2018. {
  2019. return hpi_control_param_set(h_control, HPI_GENERIC_ENABLE, enable,
  2020. 0);
  2021. }
  2022. u16 hpi_silence_detector_get_enable(u32 h_control, u32 *enable)
  2023. {
  2024. return hpi_control_param1_get(h_control, HPI_GENERIC_ENABLE, enable);
  2025. }
  2026. u16 hpi_silence_detector_set_event_enable(u32 h_control, u32 event_enable)
  2027. {
  2028. return hpi_control_param_set(h_control, HPI_GENERIC_EVENT_ENABLE,
  2029. event_enable, 0);
  2030. }
  2031. u16 hpi_silence_detector_get_event_enable(u32 h_control, u32 *event_enable)
  2032. {
  2033. return hpi_control_param1_get(h_control, HPI_GENERIC_EVENT_ENABLE,
  2034. event_enable);
  2035. }
  2036. u16 hpi_silence_detector_set_delay(u32 h_control, u32 delay)
  2037. {
  2038. return hpi_control_param_set(h_control, HPI_SILENCEDETECTOR_DELAY,
  2039. delay, 0);
  2040. }
  2041. u16 hpi_silence_detector_get_delay(u32 h_control, u32 *delay)
  2042. {
  2043. return hpi_control_param1_get(h_control, HPI_SILENCEDETECTOR_DELAY,
  2044. delay);
  2045. }
  2046. u16 hpi_silence_detector_set_threshold(u32 h_control, int threshold)
  2047. {
  2048. return hpi_control_param_set(h_control, HPI_SILENCEDETECTOR_THRESHOLD,
  2049. threshold, 0);
  2050. }
  2051. u16 hpi_silence_detector_get_threshold(u32 h_control, int *threshold)
  2052. {
  2053. return hpi_control_param1_get(h_control,
  2054. HPI_SILENCEDETECTOR_THRESHOLD, (u32 *)threshold);
  2055. }
  2056. u16 hpi_tuner_query_band(const u32 h_tuner, const u32 index, u16 *pw_band)
  2057. {
  2058. u32 qr;
  2059. u16 err;
  2060. err = hpi_control_query(h_tuner, HPI_TUNER_BAND, index, 0, &qr);
  2061. *pw_band = (u16)qr;
  2062. return err;
  2063. }
  2064. u16 hpi_tuner_set_band(u32 h_control, u16 band)
  2065. {
  2066. return hpi_control_param_set(h_control, HPI_TUNER_BAND, band, 0);
  2067. }
  2068. u16 hpi_tuner_get_band(u32 h_control, u16 *pw_band)
  2069. {
  2070. u32 band = 0;
  2071. u16 error = 0;
  2072. error = hpi_control_param1_get(h_control, HPI_TUNER_BAND, &band);
  2073. if (pw_band)
  2074. *pw_band = (u16)band;
  2075. return error;
  2076. }
  2077. u16 hpi_tuner_query_frequency(const u32 h_tuner, const u32 index,
  2078. const u16 band, u32 *pfreq)
  2079. {
  2080. return hpi_control_query(h_tuner, HPI_TUNER_FREQ, index, band, pfreq);
  2081. }
  2082. u16 hpi_tuner_set_frequency(u32 h_control, u32 freq_ink_hz)
  2083. {
  2084. return hpi_control_param_set(h_control, HPI_TUNER_FREQ, freq_ink_hz,
  2085. 0);
  2086. }
  2087. u16 hpi_tuner_get_frequency(u32 h_control, u32 *pw_freq_ink_hz)
  2088. {
  2089. return hpi_control_param1_get(h_control, HPI_TUNER_FREQ,
  2090. pw_freq_ink_hz);
  2091. }
  2092. u16 hpi_tuner_query_gain(const u32 h_tuner, const u32 index, u16 *pw_gain)
  2093. {
  2094. u32 qr;
  2095. u16 err;
  2096. err = hpi_control_query(h_tuner, HPI_TUNER_BAND, index, 0, &qr);
  2097. *pw_gain = (u16)qr;
  2098. return err;
  2099. }
  2100. u16 hpi_tuner_set_gain(u32 h_control, short gain)
  2101. {
  2102. return hpi_control_param_set(h_control, HPI_TUNER_GAIN, gain, 0);
  2103. }
  2104. u16 hpi_tuner_get_gain(u32 h_control, short *pn_gain)
  2105. {
  2106. u32 gain = 0;
  2107. u16 error = 0;
  2108. error = hpi_control_param1_get(h_control, HPI_TUNER_GAIN, &gain);
  2109. if (pn_gain)
  2110. *pn_gain = (u16)gain;
  2111. return error;
  2112. }
  2113. u16 hpi_tuner_get_rf_level(u32 h_control, short *pw_level)
  2114. {
  2115. struct hpi_message hm;
  2116. struct hpi_response hr;
  2117. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  2118. HPI_CONTROL_GET_STATE);
  2119. if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
  2120. return HPI_ERROR_INVALID_HANDLE;
  2121. hm.u.cu.attribute = HPI_TUNER_LEVEL_AVG;
  2122. hpi_send_recv(&hm, &hr);
  2123. if (pw_level)
  2124. *pw_level = hr.u.cu.tuner.s_level;
  2125. return hr.error;
  2126. }
  2127. u16 hpi_tuner_get_raw_rf_level(u32 h_control, short *pw_level)
  2128. {
  2129. struct hpi_message hm;
  2130. struct hpi_response hr;
  2131. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  2132. HPI_CONTROL_GET_STATE);
  2133. if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
  2134. return HPI_ERROR_INVALID_HANDLE;
  2135. hm.u.cu.attribute = HPI_TUNER_LEVEL_RAW;
  2136. hpi_send_recv(&hm, &hr);
  2137. if (pw_level)
  2138. *pw_level = hr.u.cu.tuner.s_level;
  2139. return hr.error;
  2140. }
  2141. u16 hpi_tuner_query_deemphasis(const u32 h_tuner, const u32 index,
  2142. const u16 band, u32 *pdeemphasis)
  2143. {
  2144. return hpi_control_query(h_tuner, HPI_TUNER_DEEMPHASIS, index, band,
  2145. pdeemphasis);
  2146. }
  2147. u16 hpi_tuner_set_deemphasis(u32 h_control, u32 deemphasis)
  2148. {
  2149. return hpi_control_param_set(h_control, HPI_TUNER_DEEMPHASIS,
  2150. deemphasis, 0);
  2151. }
  2152. u16 hpi_tuner_get_deemphasis(u32 h_control, u32 *pdeemphasis)
  2153. {
  2154. return hpi_control_param1_get(h_control, HPI_TUNER_DEEMPHASIS,
  2155. pdeemphasis);
  2156. }
  2157. u16 hpi_tuner_query_program(const u32 h_tuner, u32 *pbitmap_program)
  2158. {
  2159. return hpi_control_query(h_tuner, HPI_TUNER_PROGRAM, 0, 0,
  2160. pbitmap_program);
  2161. }
  2162. u16 hpi_tuner_set_program(u32 h_control, u32 program)
  2163. {
  2164. return hpi_control_param_set(h_control, HPI_TUNER_PROGRAM, program,
  2165. 0);
  2166. }
  2167. u16 hpi_tuner_get_program(u32 h_control, u32 *pprogram)
  2168. {
  2169. return hpi_control_param1_get(h_control, HPI_TUNER_PROGRAM, pprogram);
  2170. }
  2171. u16 hpi_tuner_get_hd_radio_dsp_version(u32 h_control, char *psz_dsp_version,
  2172. const u32 string_size)
  2173. {
  2174. return hpi_control_get_string(h_control,
  2175. HPI_TUNER_HDRADIO_DSP_VERSION, psz_dsp_version, string_size);
  2176. }
  2177. u16 hpi_tuner_get_hd_radio_sdk_version(u32 h_control, char *psz_sdk_version,
  2178. const u32 string_size)
  2179. {
  2180. return hpi_control_get_string(h_control,
  2181. HPI_TUNER_HDRADIO_SDK_VERSION, psz_sdk_version, string_size);
  2182. }
  2183. u16 hpi_tuner_get_status(u32 h_control, u16 *pw_status_mask, u16 *pw_status)
  2184. {
  2185. u32 status = 0;
  2186. u16 error = 0;
  2187. error = hpi_control_param1_get(h_control, HPI_TUNER_STATUS, &status);
  2188. if (pw_status) {
  2189. if (!error) {
  2190. *pw_status_mask = (u16)(status >> 16);
  2191. *pw_status = (u16)(status & 0xFFFF);
  2192. } else {
  2193. *pw_status_mask = 0;
  2194. *pw_status = 0;
  2195. }
  2196. }
  2197. return error;
  2198. }
  2199. u16 hpi_tuner_set_mode(u32 h_control, u32 mode, u32 value)
  2200. {
  2201. return hpi_control_param_set(h_control, HPI_TUNER_MODE, mode, value);
  2202. }
  2203. u16 hpi_tuner_get_mode(u32 h_control, u32 mode, u32 *pn_value)
  2204. {
  2205. return hpi_control_param_get(h_control, HPI_TUNER_MODE, mode, 0,
  2206. pn_value, NULL);
  2207. }
  2208. u16 hpi_tuner_get_hd_radio_signal_quality(u32 h_control, u32 *pquality)
  2209. {
  2210. return hpi_control_param1_get(h_control,
  2211. HPI_TUNER_HDRADIO_SIGNAL_QUALITY, pquality);
  2212. }
  2213. u16 hpi_tuner_get_hd_radio_signal_blend(u32 h_control, u32 *pblend)
  2214. {
  2215. return hpi_control_param1_get(h_control, HPI_TUNER_HDRADIO_BLEND,
  2216. pblend);
  2217. }
  2218. u16 hpi_tuner_set_hd_radio_signal_blend(u32 h_control, const u32 blend)
  2219. {
  2220. return hpi_control_param_set(h_control, HPI_TUNER_HDRADIO_BLEND,
  2221. blend, 0);
  2222. }
  2223. u16 hpi_tuner_get_rds(u32 h_control, char *p_data)
  2224. {
  2225. struct hpi_message hm;
  2226. struct hpi_response hr;
  2227. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  2228. HPI_CONTROL_GET_STATE);
  2229. if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
  2230. return HPI_ERROR_INVALID_HANDLE;
  2231. hm.u.c.attribute = HPI_TUNER_RDS;
  2232. hpi_send_recv(&hm, &hr);
  2233. if (p_data) {
  2234. *(u32 *)&p_data[0] = hr.u.cu.tuner.rds.data[0];
  2235. *(u32 *)&p_data[4] = hr.u.cu.tuner.rds.data[1];
  2236. *(u32 *)&p_data[8] = hr.u.cu.tuner.rds.bLER;
  2237. }
  2238. return hr.error;
  2239. }
  2240. u16 hpi_pad_get_channel_name(u32 h_control, char *psz_string,
  2241. const u32 data_length)
  2242. {
  2243. return hpi_control_get_string(h_control, HPI_PAD_CHANNEL_NAME,
  2244. psz_string, data_length);
  2245. }
  2246. u16 hpi_pad_get_artist(u32 h_control, char *psz_string, const u32 data_length)
  2247. {
  2248. return hpi_control_get_string(h_control, HPI_PAD_ARTIST, psz_string,
  2249. data_length);
  2250. }
  2251. u16 hpi_pad_get_title(u32 h_control, char *psz_string, const u32 data_length)
  2252. {
  2253. return hpi_control_get_string(h_control, HPI_PAD_TITLE, psz_string,
  2254. data_length);
  2255. }
  2256. u16 hpi_pad_get_comment(u32 h_control, char *psz_string,
  2257. const u32 data_length)
  2258. {
  2259. return hpi_control_get_string(h_control, HPI_PAD_COMMENT, psz_string,
  2260. data_length);
  2261. }
  2262. u16 hpi_pad_get_program_type(u32 h_control, u32 *ppTY)
  2263. {
  2264. return hpi_control_param1_get(h_control, HPI_PAD_PROGRAM_TYPE, ppTY);
  2265. }
  2266. u16 hpi_pad_get_rdsPI(u32 h_control, u32 *ppI)
  2267. {
  2268. return hpi_control_param1_get(h_control, HPI_PAD_PROGRAM_ID, ppI);
  2269. }
  2270. u16 hpi_volume_query_channels(const u32 h_volume, u32 *p_channels)
  2271. {
  2272. return hpi_control_query(h_volume, HPI_VOLUME_NUM_CHANNELS, 0, 0,
  2273. p_channels);
  2274. }
  2275. u16 hpi_volume_set_gain(u32 h_control, short an_log_gain[HPI_MAX_CHANNELS]
  2276. )
  2277. {
  2278. return hpi_control_log_set2(h_control, HPI_VOLUME_GAIN,
  2279. an_log_gain[0], an_log_gain[1]);
  2280. }
  2281. u16 hpi_volume_get_gain(u32 h_control, short an_log_gain[HPI_MAX_CHANNELS]
  2282. )
  2283. {
  2284. return hpi_control_log_get2(h_control, HPI_VOLUME_GAIN,
  2285. &an_log_gain[0], &an_log_gain[1]);
  2286. }
  2287. u16 hpi_volume_set_mute(u32 h_control, u32 mute)
  2288. {
  2289. return hpi_control_param_set(h_control, HPI_VOLUME_MUTE, mute, 0);
  2290. }
  2291. u16 hpi_volume_get_mute(u32 h_control, u32 *mute)
  2292. {
  2293. return hpi_control_param1_get(h_control, HPI_VOLUME_MUTE, mute);
  2294. }
  2295. u16 hpi_volume_query_range(u32 h_control, short *min_gain_01dB,
  2296. short *max_gain_01dB, short *step_gain_01dB)
  2297. {
  2298. struct hpi_message hm;
  2299. struct hpi_response hr;
  2300. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  2301. HPI_CONTROL_GET_STATE);
  2302. if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
  2303. return HPI_ERROR_INVALID_HANDLE;
  2304. hm.u.c.attribute = HPI_VOLUME_RANGE;
  2305. hpi_send_recv(&hm, &hr);
  2306. if (hr.error) {
  2307. hr.u.c.an_log_value[0] = 0;
  2308. hr.u.c.an_log_value[1] = 0;
  2309. hr.u.c.param1 = 0;
  2310. }
  2311. if (min_gain_01dB)
  2312. *min_gain_01dB = hr.u.c.an_log_value[0];
  2313. if (max_gain_01dB)
  2314. *max_gain_01dB = hr.u.c.an_log_value[1];
  2315. if (step_gain_01dB)
  2316. *step_gain_01dB = (short)hr.u.c.param1;
  2317. return hr.error;
  2318. }
  2319. u16 hpi_volume_auto_fade_profile(u32 h_control,
  2320. short an_stop_gain0_01dB[HPI_MAX_CHANNELS], u32 duration_ms,
  2321. u16 profile)
  2322. {
  2323. struct hpi_message hm;
  2324. struct hpi_response hr;
  2325. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  2326. HPI_CONTROL_SET_STATE);
  2327. if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
  2328. return HPI_ERROR_INVALID_HANDLE;
  2329. memcpy(hm.u.c.an_log_value, an_stop_gain0_01dB,
  2330. sizeof(short) * HPI_MAX_CHANNELS);
  2331. hm.u.c.attribute = HPI_VOLUME_AUTOFADE;
  2332. hm.u.c.param1 = duration_ms;
  2333. hm.u.c.param2 = profile;
  2334. hpi_send_recv(&hm, &hr);
  2335. return hr.error;
  2336. }
  2337. u16 hpi_volume_auto_fade(u32 h_control,
  2338. short an_stop_gain0_01dB[HPI_MAX_CHANNELS], u32 duration_ms)
  2339. {
  2340. return hpi_volume_auto_fade_profile(h_control, an_stop_gain0_01dB,
  2341. duration_ms, HPI_VOLUME_AUTOFADE_LOG);
  2342. }
  2343. u16 hpi_volume_query_auto_fade_profile(const u32 h_volume, const u32 i,
  2344. u16 *profile)
  2345. {
  2346. u16 e;
  2347. u32 u;
  2348. e = hpi_control_query(h_volume, HPI_VOLUME_AUTOFADE, i, 0, &u);
  2349. *profile = (u16)u;
  2350. return e;
  2351. }
  2352. u16 hpi_vox_set_threshold(u32 h_control, short an_gain0_01dB)
  2353. {
  2354. struct hpi_message hm;
  2355. struct hpi_response hr;
  2356. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  2357. HPI_CONTROL_SET_STATE);
  2358. if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
  2359. return HPI_ERROR_INVALID_HANDLE;
  2360. hm.u.c.attribute = HPI_VOX_THRESHOLD;
  2361. hm.u.c.an_log_value[0] = an_gain0_01dB;
  2362. hpi_send_recv(&hm, &hr);
  2363. return hr.error;
  2364. }
  2365. u16 hpi_vox_get_threshold(u32 h_control, short *an_gain0_01dB)
  2366. {
  2367. struct hpi_message hm;
  2368. struct hpi_response hr;
  2369. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  2370. HPI_CONTROL_GET_STATE);
  2371. if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
  2372. return HPI_ERROR_INVALID_HANDLE;
  2373. hm.u.c.attribute = HPI_VOX_THRESHOLD;
  2374. hpi_send_recv(&hm, &hr);
  2375. *an_gain0_01dB = hr.u.c.an_log_value[0];
  2376. return hr.error;
  2377. }