hpifunc.c 71 KB

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