hpifunc.c 70 KB

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