hpifunc.c 70 KB

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