Merge branch 'merge' of git://git.kernel.org/pub/scm/linux/kernel/git/benh/powerpc
[zen-stable.git] / sound / pci / asihpi / hpifunc.c
blob7397b169b89f2b626f8dca427006dc96d260a2ce
2 #include "hpi_internal.h"
3 #include "hpimsginit.h"
5 #include "hpidebug.h"
7 struct hpi_handle {
8 unsigned int obj_index:12;
9 unsigned int obj_type:4;
10 unsigned int adapter_index:14;
11 unsigned int spare:1;
12 unsigned int read_only:1;
15 union handle_word {
16 struct hpi_handle h;
17 u32 w;
20 u32 hpi_indexes_to_handle(const char c_object, const u16 adapter_index,
21 const u16 object_index)
23 union handle_word handle;
25 handle.h.adapter_index = adapter_index;
26 handle.h.spare = 0;
27 handle.h.read_only = 0;
28 handle.h.obj_type = c_object;
29 handle.h.obj_index = object_index;
30 return handle.w;
33 static u16 hpi_handle_indexes(const u32 h, u16 *p1, u16 *p2)
35 union handle_word uhandle;
36 if (!h)
37 return HPI_ERROR_INVALID_HANDLE;
39 uhandle.w = h;
41 *p1 = (u16)uhandle.h.adapter_index;
42 if (p2)
43 *p2 = (u16)uhandle.h.obj_index;
45 return 0;
48 void hpi_handle_to_indexes(const u32 handle, u16 *pw_adapter_index,
49 u16 *pw_object_index)
51 hpi_handle_indexes(handle, pw_adapter_index, pw_object_index);
54 char hpi_handle_object(const u32 handle)
56 union handle_word uhandle;
57 uhandle.w = handle;
58 return (char)uhandle.h.obj_type;
61 void hpi_format_to_msg(struct hpi_msg_format *pMF,
62 const struct hpi_format *pF)
64 pMF->sample_rate = pF->sample_rate;
65 pMF->bit_rate = pF->bit_rate;
66 pMF->attributes = pF->attributes;
67 pMF->channels = pF->channels;
68 pMF->format = pF->format;
71 static void hpi_msg_to_format(struct hpi_format *pF,
72 struct hpi_msg_format *pMF)
74 pF->sample_rate = pMF->sample_rate;
75 pF->bit_rate = pMF->bit_rate;
76 pF->attributes = pMF->attributes;
77 pF->channels = pMF->channels;
78 pF->format = pMF->format;
79 pF->mode_legacy = 0;
80 pF->unused = 0;
83 void hpi_stream_response_to_legacy(struct hpi_stream_res *pSR)
85 pSR->u.legacy_stream_info.auxiliary_data_available =
86 pSR->u.stream_info.auxiliary_data_available;
87 pSR->u.legacy_stream_info.state = pSR->u.stream_info.state;
90 static inline void hpi_send_recvV1(struct hpi_message_header *m,
91 struct hpi_response_header *r)
93 hpi_send_recv((struct hpi_message *)m, (struct hpi_response *)r);
96 u16 hpi_subsys_get_version_ex(u32 *pversion_ex)
98 struct hpi_message hm;
99 struct hpi_response hr;
101 hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
102 HPI_SUBSYS_GET_VERSION);
103 hpi_send_recv(&hm, &hr);
104 *pversion_ex = hr.u.s.data;
105 return hr.error;
108 u16 hpi_subsys_get_num_adapters(int *pn_num_adapters)
110 struct hpi_message hm;
111 struct hpi_response hr;
112 hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
113 HPI_SUBSYS_GET_NUM_ADAPTERS);
114 hpi_send_recv(&hm, &hr);
115 *pn_num_adapters = (int)hr.u.s.num_adapters;
116 return hr.error;
119 u16 hpi_subsys_get_adapter(int iterator, u32 *padapter_index,
120 u16 *pw_adapter_type)
122 struct hpi_message hm;
123 struct hpi_response hr;
124 hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
125 HPI_SUBSYS_GET_ADAPTER);
126 hm.obj_index = (u16)iterator;
127 hpi_send_recv(&hm, &hr);
128 *padapter_index = (int)hr.u.s.adapter_index;
129 *pw_adapter_type = hr.u.s.adapter_type;
131 return hr.error;
134 u16 hpi_adapter_open(u16 adapter_index)
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;
142 hpi_send_recv(&hm, &hr);
144 return hr.error;
148 u16 hpi_adapter_close(u16 adapter_index)
150 struct hpi_message hm;
151 struct hpi_response hr;
152 hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
153 HPI_ADAPTER_CLOSE);
154 hm.adapter_index = adapter_index;
156 hpi_send_recv(&hm, &hr);
158 return hr.error;
161 u16 hpi_adapter_set_mode(u16 adapter_index, u32 adapter_mode)
163 return hpi_adapter_set_mode_ex(adapter_index, adapter_mode,
164 HPI_ADAPTER_MODE_SET);
167 u16 hpi_adapter_set_mode_ex(u16 adapter_index, u32 adapter_mode,
168 u16 query_or_set)
170 struct hpi_message hm;
171 struct hpi_response hr;
173 hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
174 HPI_ADAPTER_SET_MODE);
175 hm.adapter_index = adapter_index;
176 hm.u.ax.mode.adapter_mode = adapter_mode;
177 hm.u.ax.mode.query_or_set = query_or_set;
178 hpi_send_recv(&hm, &hr);
179 return hr.error;
182 u16 hpi_adapter_get_mode(u16 adapter_index, u32 *padapter_mode)
184 struct hpi_message hm;
185 struct hpi_response hr;
186 hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
187 HPI_ADAPTER_GET_MODE);
188 hm.adapter_index = adapter_index;
189 hpi_send_recv(&hm, &hr);
190 if (padapter_mode)
191 *padapter_mode = hr.u.ax.mode.adapter_mode;
192 return hr.error;
195 u16 hpi_adapter_get_info(u16 adapter_index, u16 *pw_num_outstreams,
196 u16 *pw_num_instreams, u16 *pw_version, u32 *pserial_number,
197 u16 *pw_adapter_type)
199 struct hpi_message hm;
200 struct hpi_response hr;
201 hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
202 HPI_ADAPTER_GET_INFO);
203 hm.adapter_index = adapter_index;
205 hpi_send_recv(&hm, &hr);
207 *pw_adapter_type = hr.u.ax.info.adapter_type;
208 *pw_num_outstreams = hr.u.ax.info.num_outstreams;
209 *pw_num_instreams = hr.u.ax.info.num_instreams;
210 *pw_version = hr.u.ax.info.version;
211 *pserial_number = hr.u.ax.info.serial_number;
212 return hr.error;
215 u16 hpi_adapter_get_module_by_index(u16 adapter_index, u16 module_index,
216 u16 *pw_num_outputs, u16 *pw_num_inputs, u16 *pw_version,
217 u32 *pserial_number, u16 *pw_module_type, u32 *ph_module)
219 struct hpi_message hm;
220 struct hpi_response hr;
222 hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
223 HPI_ADAPTER_MODULE_INFO);
224 hm.adapter_index = adapter_index;
225 hm.u.ax.module_info.index = module_index;
227 hpi_send_recv(&hm, &hr);
229 *pw_module_type = hr.u.ax.info.adapter_type;
230 *pw_num_outputs = hr.u.ax.info.num_outstreams;
231 *pw_num_inputs = hr.u.ax.info.num_instreams;
232 *pw_version = hr.u.ax.info.version;
233 *pserial_number = hr.u.ax.info.serial_number;
234 *ph_module = 0;
236 return hr.error;
239 u16 hpi_adapter_set_property(u16 adapter_index, u16 property, u16 parameter1,
240 u16 parameter2)
242 struct hpi_message hm;
243 struct hpi_response hr;
244 hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
245 HPI_ADAPTER_SET_PROPERTY);
246 hm.adapter_index = adapter_index;
247 hm.u.ax.property_set.property = property;
248 hm.u.ax.property_set.parameter1 = parameter1;
249 hm.u.ax.property_set.parameter2 = parameter2;
251 hpi_send_recv(&hm, &hr);
253 return hr.error;
256 u16 hpi_adapter_get_property(u16 adapter_index, u16 property,
257 u16 *pw_parameter1, u16 *pw_parameter2)
259 struct hpi_message hm;
260 struct hpi_response hr;
261 hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
262 HPI_ADAPTER_GET_PROPERTY);
263 hm.adapter_index = adapter_index;
264 hm.u.ax.property_set.property = property;
266 hpi_send_recv(&hm, &hr);
267 if (!hr.error) {
268 if (pw_parameter1)
269 *pw_parameter1 = hr.u.ax.property_get.parameter1;
270 if (pw_parameter2)
271 *pw_parameter2 = hr.u.ax.property_get.parameter2;
274 return hr.error;
277 u16 hpi_adapter_enumerate_property(u16 adapter_index, u16 index,
278 u16 what_to_enumerate, u16 property_index, u32 *psetting)
280 return 0;
283 u16 hpi_format_create(struct hpi_format *p_format, u16 channels, u16 format,
284 u32 sample_rate, u32 bit_rate, u32 attributes)
286 u16 err = 0;
287 struct hpi_msg_format fmt;
289 switch (channels) {
290 case 1:
291 case 2:
292 case 4:
293 case 6:
294 case 8:
295 case 16:
296 break;
297 default:
298 err = HPI_ERROR_INVALID_CHANNELS;
299 return err;
301 fmt.channels = channels;
303 switch (format) {
304 case HPI_FORMAT_PCM16_SIGNED:
305 case HPI_FORMAT_PCM24_SIGNED:
306 case HPI_FORMAT_PCM32_SIGNED:
307 case HPI_FORMAT_PCM32_FLOAT:
308 case HPI_FORMAT_PCM16_BIGENDIAN:
309 case HPI_FORMAT_PCM8_UNSIGNED:
310 case HPI_FORMAT_MPEG_L1:
311 case HPI_FORMAT_MPEG_L2:
312 case HPI_FORMAT_MPEG_L3:
313 case HPI_FORMAT_DOLBY_AC2:
314 case HPI_FORMAT_AA_TAGIT1_HITS:
315 case HPI_FORMAT_AA_TAGIT1_INSERTS:
316 case HPI_FORMAT_RAW_BITSTREAM:
317 case HPI_FORMAT_AA_TAGIT1_HITS_EX1:
318 case HPI_FORMAT_OEM1:
319 case HPI_FORMAT_OEM2:
320 break;
321 default:
322 err = HPI_ERROR_INVALID_FORMAT;
323 return err;
325 fmt.format = format;
327 if (sample_rate < 8000L) {
328 err = HPI_ERROR_INCOMPATIBLE_SAMPLERATE;
329 sample_rate = 8000L;
331 if (sample_rate > 200000L) {
332 err = HPI_ERROR_INCOMPATIBLE_SAMPLERATE;
333 sample_rate = 200000L;
335 fmt.sample_rate = sample_rate;
337 switch (format) {
338 case HPI_FORMAT_MPEG_L1:
339 case HPI_FORMAT_MPEG_L2:
340 case HPI_FORMAT_MPEG_L3:
341 fmt.bit_rate = bit_rate;
342 break;
343 case HPI_FORMAT_PCM16_SIGNED:
344 case HPI_FORMAT_PCM16_BIGENDIAN:
345 fmt.bit_rate = channels * sample_rate * 2;
346 break;
347 case HPI_FORMAT_PCM32_SIGNED:
348 case HPI_FORMAT_PCM32_FLOAT:
349 fmt.bit_rate = channels * sample_rate * 4;
350 break;
351 case HPI_FORMAT_PCM8_UNSIGNED:
352 fmt.bit_rate = channels * sample_rate;
353 break;
354 default:
355 fmt.bit_rate = 0;
358 switch (format) {
359 case HPI_FORMAT_MPEG_L2:
360 if ((channels == 1)
361 && (attributes != HPI_MPEG_MODE_DEFAULT)) {
362 attributes = HPI_MPEG_MODE_DEFAULT;
363 err = HPI_ERROR_INVALID_FORMAT;
364 } else if (attributes > HPI_MPEG_MODE_DUALCHANNEL) {
365 attributes = HPI_MPEG_MODE_DEFAULT;
366 err = HPI_ERROR_INVALID_FORMAT;
368 fmt.attributes = attributes;
369 break;
370 default:
371 fmt.attributes = attributes;
374 hpi_msg_to_format(p_format, &fmt);
375 return err;
378 u16 hpi_stream_estimate_buffer_size(struct hpi_format *p_format,
379 u32 host_polling_rate_in_milli_seconds, u32 *recommended_buffer_size)
382 u32 bytes_per_second;
383 u32 size;
384 u16 channels;
385 struct hpi_format *pF = p_format;
387 channels = pF->channels;
389 switch (pF->format) {
390 case HPI_FORMAT_PCM16_BIGENDIAN:
391 case HPI_FORMAT_PCM16_SIGNED:
392 bytes_per_second = pF->sample_rate * 2L * channels;
393 break;
394 case HPI_FORMAT_PCM24_SIGNED:
395 bytes_per_second = pF->sample_rate * 3L * channels;
396 break;
397 case HPI_FORMAT_PCM32_SIGNED:
398 case HPI_FORMAT_PCM32_FLOAT:
399 bytes_per_second = pF->sample_rate * 4L * channels;
400 break;
401 case HPI_FORMAT_PCM8_UNSIGNED:
402 bytes_per_second = pF->sample_rate * 1L * channels;
403 break;
404 case HPI_FORMAT_MPEG_L1:
405 case HPI_FORMAT_MPEG_L2:
406 case HPI_FORMAT_MPEG_L3:
407 bytes_per_second = pF->bit_rate / 8L;
408 break;
409 case HPI_FORMAT_DOLBY_AC2:
411 bytes_per_second = 256000L / 8L;
412 break;
413 default:
414 return HPI_ERROR_INVALID_FORMAT;
416 size = (bytes_per_second * host_polling_rate_in_milli_seconds * 2) /
417 1000L;
419 *recommended_buffer_size =
420 roundup_pow_of_two(((size + 4095L) & ~4095L));
421 return 0;
424 u16 hpi_outstream_open(u16 adapter_index, u16 outstream_index,
425 u32 *ph_outstream)
427 struct hpi_message hm;
428 struct hpi_response hr;
429 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
430 HPI_OSTREAM_OPEN);
431 hm.adapter_index = adapter_index;
432 hm.obj_index = outstream_index;
434 hpi_send_recv(&hm, &hr);
436 if (hr.error == 0)
437 *ph_outstream =
438 hpi_indexes_to_handle(HPI_OBJ_OSTREAM, adapter_index,
439 outstream_index);
440 else
441 *ph_outstream = 0;
442 return hr.error;
445 u16 hpi_outstream_close(u32 h_outstream)
447 struct hpi_message hm;
448 struct hpi_response hr;
450 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
451 HPI_OSTREAM_HOSTBUFFER_FREE);
452 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
453 return HPI_ERROR_INVALID_HANDLE;
455 hpi_send_recv(&hm, &hr);
457 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
458 HPI_OSTREAM_GROUP_RESET);
459 hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index);
460 hpi_send_recv(&hm, &hr);
462 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
463 HPI_OSTREAM_CLOSE);
464 hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index);
465 hpi_send_recv(&hm, &hr);
467 return hr.error;
470 u16 hpi_outstream_get_info_ex(u32 h_outstream, u16 *pw_state,
471 u32 *pbuffer_size, u32 *pdata_to_play, u32 *psamples_played,
472 u32 *pauxiliary_data_to_play)
474 struct hpi_message hm;
475 struct hpi_response hr;
476 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
477 HPI_OSTREAM_GET_INFO);
478 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
479 return HPI_ERROR_INVALID_HANDLE;
481 hpi_send_recv(&hm, &hr);
483 if (pw_state)
484 *pw_state = hr.u.d.u.stream_info.state;
485 if (pbuffer_size)
486 *pbuffer_size = hr.u.d.u.stream_info.buffer_size;
487 if (pdata_to_play)
488 *pdata_to_play = hr.u.d.u.stream_info.data_available;
489 if (psamples_played)
490 *psamples_played = hr.u.d.u.stream_info.samples_transferred;
491 if (pauxiliary_data_to_play)
492 *pauxiliary_data_to_play =
493 hr.u.d.u.stream_info.auxiliary_data_available;
494 return hr.error;
497 u16 hpi_outstream_write_buf(u32 h_outstream, const u8 *pb_data,
498 u32 bytes_to_write, const struct hpi_format *p_format)
500 struct hpi_message hm;
501 struct hpi_response hr;
502 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
503 HPI_OSTREAM_WRITE);
504 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
505 return HPI_ERROR_INVALID_HANDLE;
506 hm.u.d.u.data.pb_data = (u8 *)pb_data;
507 hm.u.d.u.data.data_size = bytes_to_write;
509 hpi_format_to_msg(&hm.u.d.u.data.format, p_format);
511 hpi_send_recv(&hm, &hr);
513 return hr.error;
516 u16 hpi_outstream_start(u32 h_outstream)
518 struct hpi_message hm;
519 struct hpi_response hr;
520 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
521 HPI_OSTREAM_START);
522 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
523 return HPI_ERROR_INVALID_HANDLE;
525 hpi_send_recv(&hm, &hr);
527 return hr.error;
530 u16 hpi_outstream_wait_start(u32 h_outstream)
532 struct hpi_message hm;
533 struct hpi_response hr;
534 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
535 HPI_OSTREAM_WAIT_START);
536 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
537 return HPI_ERROR_INVALID_HANDLE;
539 hpi_send_recv(&hm, &hr);
541 return hr.error;
544 u16 hpi_outstream_stop(u32 h_outstream)
546 struct hpi_message hm;
547 struct hpi_response hr;
548 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
549 HPI_OSTREAM_STOP);
550 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
551 return HPI_ERROR_INVALID_HANDLE;
553 hpi_send_recv(&hm, &hr);
555 return hr.error;
558 u16 hpi_outstream_sinegen(u32 h_outstream)
560 struct hpi_message hm;
561 struct hpi_response hr;
562 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
563 HPI_OSTREAM_SINEGEN);
564 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
565 return HPI_ERROR_INVALID_HANDLE;
567 hpi_send_recv(&hm, &hr);
569 return hr.error;
572 u16 hpi_outstream_reset(u32 h_outstream)
574 struct hpi_message hm;
575 struct hpi_response hr;
576 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
577 HPI_OSTREAM_RESET);
578 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
579 return HPI_ERROR_INVALID_HANDLE;
581 hpi_send_recv(&hm, &hr);
583 return hr.error;
586 u16 hpi_outstream_query_format(u32 h_outstream, struct hpi_format *p_format)
588 struct hpi_message hm;
589 struct hpi_response hr;
591 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
592 HPI_OSTREAM_QUERY_FORMAT);
593 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
594 return HPI_ERROR_INVALID_HANDLE;
596 hpi_format_to_msg(&hm.u.d.u.data.format, p_format);
598 hpi_send_recv(&hm, &hr);
600 return hr.error;
603 u16 hpi_outstream_set_format(u32 h_outstream, struct hpi_format *p_format)
605 struct hpi_message hm;
606 struct hpi_response hr;
608 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
609 HPI_OSTREAM_SET_FORMAT);
610 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
611 return HPI_ERROR_INVALID_HANDLE;
613 hpi_format_to_msg(&hm.u.d.u.data.format, p_format);
615 hpi_send_recv(&hm, &hr);
617 return hr.error;
620 u16 hpi_outstream_set_velocity(u32 h_outstream, short velocity)
622 struct hpi_message hm;
623 struct hpi_response hr;
625 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
626 HPI_OSTREAM_SET_VELOCITY);
627 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
628 return HPI_ERROR_INVALID_HANDLE;
629 hm.u.d.u.velocity = velocity;
631 hpi_send_recv(&hm, &hr);
633 return hr.error;
636 u16 hpi_outstream_set_punch_in_out(u32 h_outstream, u32 punch_in_sample,
637 u32 punch_out_sample)
639 struct hpi_message hm;
640 struct hpi_response hr;
642 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
643 HPI_OSTREAM_SET_PUNCHINOUT);
644 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
645 return HPI_ERROR_INVALID_HANDLE;
647 hm.u.d.u.pio.punch_in_sample = punch_in_sample;
648 hm.u.d.u.pio.punch_out_sample = punch_out_sample;
650 hpi_send_recv(&hm, &hr);
652 return hr.error;
655 u16 hpi_outstream_ancillary_reset(u32 h_outstream, u16 mode)
657 struct hpi_message hm;
658 struct hpi_response hr;
660 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
661 HPI_OSTREAM_ANC_RESET);
662 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
663 return HPI_ERROR_INVALID_HANDLE;
664 hm.u.d.u.data.format.channels = mode;
665 hpi_send_recv(&hm, &hr);
666 return hr.error;
669 u16 hpi_outstream_ancillary_get_info(u32 h_outstream, u32 *pframes_available)
671 struct hpi_message hm;
672 struct hpi_response hr;
674 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
675 HPI_OSTREAM_ANC_GET_INFO);
676 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
677 return HPI_ERROR_INVALID_HANDLE;
678 hpi_send_recv(&hm, &hr);
679 if (hr.error == 0) {
680 if (pframes_available)
681 *pframes_available =
682 hr.u.d.u.stream_info.data_available /
683 sizeof(struct hpi_anc_frame);
685 return hr.error;
688 u16 hpi_outstream_ancillary_read(u32 h_outstream,
689 struct hpi_anc_frame *p_anc_frame_buffer,
690 u32 anc_frame_buffer_size_in_bytes,
691 u32 number_of_ancillary_frames_to_read)
693 struct hpi_message hm;
694 struct hpi_response hr;
696 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
697 HPI_OSTREAM_ANC_READ);
698 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
699 return HPI_ERROR_INVALID_HANDLE;
700 hm.u.d.u.data.pb_data = (u8 *)p_anc_frame_buffer;
701 hm.u.d.u.data.data_size =
702 number_of_ancillary_frames_to_read *
703 sizeof(struct hpi_anc_frame);
704 if (hm.u.d.u.data.data_size <= anc_frame_buffer_size_in_bytes)
705 hpi_send_recv(&hm, &hr);
706 else
707 hr.error = HPI_ERROR_INVALID_DATASIZE;
708 return hr.error;
711 u16 hpi_outstream_set_time_scale(u32 h_outstream, u32 time_scale)
713 struct hpi_message hm;
714 struct hpi_response hr;
716 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
717 HPI_OSTREAM_SET_TIMESCALE);
718 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
719 return HPI_ERROR_INVALID_HANDLE;
721 hm.u.d.u.time_scale = time_scale;
723 hpi_send_recv(&hm, &hr);
725 return hr.error;
728 u16 hpi_outstream_host_buffer_allocate(u32 h_outstream, u32 size_in_bytes)
730 struct hpi_message hm;
731 struct hpi_response hr;
733 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
734 HPI_OSTREAM_HOSTBUFFER_ALLOC);
735 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
736 return HPI_ERROR_INVALID_HANDLE;
737 hm.u.d.u.data.data_size = size_in_bytes;
738 hpi_send_recv(&hm, &hr);
739 return hr.error;
742 u16 hpi_outstream_host_buffer_get_info(u32 h_outstream, u8 **pp_buffer,
743 struct hpi_hostbuffer_status **pp_status)
745 struct hpi_message hm;
746 struct hpi_response hr;
748 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
749 HPI_OSTREAM_HOSTBUFFER_GET_INFO);
750 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
751 return HPI_ERROR_INVALID_HANDLE;
752 hpi_send_recv(&hm, &hr);
754 if (hr.error == 0) {
755 if (pp_buffer)
756 *pp_buffer = hr.u.d.u.hostbuffer_info.p_buffer;
757 if (pp_status)
758 *pp_status = hr.u.d.u.hostbuffer_info.p_status;
760 return hr.error;
763 u16 hpi_outstream_host_buffer_free(u32 h_outstream)
765 struct hpi_message hm;
766 struct hpi_response hr;
768 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
769 HPI_OSTREAM_HOSTBUFFER_FREE);
770 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
771 return HPI_ERROR_INVALID_HANDLE;
772 hpi_send_recv(&hm, &hr);
773 return hr.error;
776 u16 hpi_outstream_group_add(u32 h_outstream, u32 h_stream)
778 struct hpi_message hm;
779 struct hpi_response hr;
780 u16 adapter;
781 char c_obj_type;
783 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
784 HPI_OSTREAM_GROUP_ADD);
786 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
787 return HPI_ERROR_INVALID_HANDLE;
789 if (hpi_handle_indexes(h_stream, &adapter,
790 &hm.u.d.u.stream.stream_index))
791 return HPI_ERROR_INVALID_HANDLE;
793 c_obj_type = hpi_handle_object(h_stream);
794 switch (c_obj_type) {
795 case HPI_OBJ_OSTREAM:
796 case HPI_OBJ_ISTREAM:
797 hm.u.d.u.stream.object_type = c_obj_type;
798 break;
799 default:
800 return HPI_ERROR_INVALID_OBJ;
802 if (adapter != hm.adapter_index)
803 return HPI_ERROR_NO_INTERADAPTER_GROUPS;
805 hpi_send_recv(&hm, &hr);
806 return hr.error;
809 u16 hpi_outstream_group_get_map(u32 h_outstream, u32 *poutstream_map,
810 u32 *pinstream_map)
812 struct hpi_message hm;
813 struct hpi_response hr;
815 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
816 HPI_OSTREAM_GROUP_GETMAP);
817 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
818 return HPI_ERROR_INVALID_HANDLE;
819 hpi_send_recv(&hm, &hr);
821 if (poutstream_map)
822 *poutstream_map = hr.u.d.u.group_info.outstream_group_map;
823 if (pinstream_map)
824 *pinstream_map = hr.u.d.u.group_info.instream_group_map;
826 return hr.error;
829 u16 hpi_outstream_group_reset(u32 h_outstream)
831 struct hpi_message hm;
832 struct hpi_response hr;
834 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
835 HPI_OSTREAM_GROUP_RESET);
836 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
837 return HPI_ERROR_INVALID_HANDLE;
838 hpi_send_recv(&hm, &hr);
839 return hr.error;
842 u16 hpi_instream_open(u16 adapter_index, u16 instream_index, u32 *ph_instream)
844 struct hpi_message hm;
845 struct hpi_response hr;
847 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
848 HPI_ISTREAM_OPEN);
849 hm.adapter_index = adapter_index;
850 hm.obj_index = instream_index;
852 hpi_send_recv(&hm, &hr);
854 if (hr.error == 0)
855 *ph_instream =
856 hpi_indexes_to_handle(HPI_OBJ_ISTREAM, adapter_index,
857 instream_index);
858 else
859 *ph_instream = 0;
861 return hr.error;
864 u16 hpi_instream_close(u32 h_instream)
866 struct hpi_message hm;
867 struct hpi_response hr;
869 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
870 HPI_ISTREAM_HOSTBUFFER_FREE);
871 if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
872 return HPI_ERROR_INVALID_HANDLE;
873 hpi_send_recv(&hm, &hr);
875 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
876 HPI_ISTREAM_GROUP_RESET);
877 hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index);
878 hpi_send_recv(&hm, &hr);
880 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
881 HPI_ISTREAM_CLOSE);
882 hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index);
883 hpi_send_recv(&hm, &hr);
885 return hr.error;
888 u16 hpi_instream_query_format(u32 h_instream,
889 const struct hpi_format *p_format)
891 struct hpi_message hm;
892 struct hpi_response hr;
894 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
895 HPI_ISTREAM_QUERY_FORMAT);
896 if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
897 return HPI_ERROR_INVALID_HANDLE;
898 hpi_format_to_msg(&hm.u.d.u.data.format, p_format);
900 hpi_send_recv(&hm, &hr);
902 return hr.error;
905 u16 hpi_instream_set_format(u32 h_instream, const struct hpi_format *p_format)
907 struct hpi_message hm;
908 struct hpi_response hr;
910 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
911 HPI_ISTREAM_SET_FORMAT);
912 if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
913 return HPI_ERROR_INVALID_HANDLE;
914 hpi_format_to_msg(&hm.u.d.u.data.format, p_format);
916 hpi_send_recv(&hm, &hr);
918 return hr.error;
921 u16 hpi_instream_read_buf(u32 h_instream, u8 *pb_data, u32 bytes_to_read)
923 struct hpi_message hm;
924 struct hpi_response hr;
926 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
927 HPI_ISTREAM_READ);
928 if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
929 return HPI_ERROR_INVALID_HANDLE;
930 hm.u.d.u.data.data_size = bytes_to_read;
931 hm.u.d.u.data.pb_data = pb_data;
933 hpi_send_recv(&hm, &hr);
935 return hr.error;
938 u16 hpi_instream_start(u32 h_instream)
940 struct hpi_message hm;
941 struct hpi_response hr;
943 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
944 HPI_ISTREAM_START);
945 if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
946 return HPI_ERROR_INVALID_HANDLE;
948 hpi_send_recv(&hm, &hr);
950 return hr.error;
953 u16 hpi_instream_wait_start(u32 h_instream)
955 struct hpi_message hm;
956 struct hpi_response hr;
958 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
959 HPI_ISTREAM_WAIT_START);
960 if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
961 return HPI_ERROR_INVALID_HANDLE;
963 hpi_send_recv(&hm, &hr);
965 return hr.error;
968 u16 hpi_instream_stop(u32 h_instream)
970 struct hpi_message hm;
971 struct hpi_response hr;
973 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
974 HPI_ISTREAM_STOP);
975 if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
976 return HPI_ERROR_INVALID_HANDLE;
978 hpi_send_recv(&hm, &hr);
980 return hr.error;
983 u16 hpi_instream_reset(u32 h_instream)
985 struct hpi_message hm;
986 struct hpi_response hr;
988 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
989 HPI_ISTREAM_RESET);
990 if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
991 return HPI_ERROR_INVALID_HANDLE;
993 hpi_send_recv(&hm, &hr);
995 return hr.error;
998 u16 hpi_instream_get_info_ex(u32 h_instream, u16 *pw_state, u32 *pbuffer_size,
999 u32 *pdata_recorded, u32 *psamples_recorded,
1000 u32 *pauxiliary_data_recorded)
1002 struct hpi_message hm;
1003 struct hpi_response hr;
1004 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1005 HPI_ISTREAM_GET_INFO);
1006 if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
1007 return HPI_ERROR_INVALID_HANDLE;
1009 hpi_send_recv(&hm, &hr);
1011 if (pw_state)
1012 *pw_state = hr.u.d.u.stream_info.state;
1013 if (pbuffer_size)
1014 *pbuffer_size = hr.u.d.u.stream_info.buffer_size;
1015 if (pdata_recorded)
1016 *pdata_recorded = hr.u.d.u.stream_info.data_available;
1017 if (psamples_recorded)
1018 *psamples_recorded = hr.u.d.u.stream_info.samples_transferred;
1019 if (pauxiliary_data_recorded)
1020 *pauxiliary_data_recorded =
1021 hr.u.d.u.stream_info.auxiliary_data_available;
1022 return hr.error;
1025 u16 hpi_instream_ancillary_reset(u32 h_instream, u16 bytes_per_frame,
1026 u16 mode, u16 alignment, u16 idle_bit)
1028 struct hpi_message hm;
1029 struct hpi_response hr;
1030 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1031 HPI_ISTREAM_ANC_RESET);
1032 if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
1033 return HPI_ERROR_INVALID_HANDLE;
1034 hm.u.d.u.data.format.attributes = bytes_per_frame;
1035 hm.u.d.u.data.format.format = (mode << 8) | (alignment & 0xff);
1036 hm.u.d.u.data.format.channels = idle_bit;
1037 hpi_send_recv(&hm, &hr);
1038 return hr.error;
1041 u16 hpi_instream_ancillary_get_info(u32 h_instream, u32 *pframe_space)
1043 struct hpi_message hm;
1044 struct hpi_response hr;
1045 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1046 HPI_ISTREAM_ANC_GET_INFO);
1047 if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
1048 return HPI_ERROR_INVALID_HANDLE;
1049 hpi_send_recv(&hm, &hr);
1050 if (pframe_space)
1051 *pframe_space =
1052 (hr.u.d.u.stream_info.buffer_size -
1053 hr.u.d.u.stream_info.data_available) /
1054 sizeof(struct hpi_anc_frame);
1055 return hr.error;
1058 u16 hpi_instream_ancillary_write(u32 h_instream,
1059 const struct hpi_anc_frame *p_anc_frame_buffer,
1060 u32 anc_frame_buffer_size_in_bytes,
1061 u32 number_of_ancillary_frames_to_write)
1063 struct hpi_message hm;
1064 struct hpi_response hr;
1066 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1067 HPI_ISTREAM_ANC_WRITE);
1068 if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
1069 return HPI_ERROR_INVALID_HANDLE;
1070 hm.u.d.u.data.pb_data = (u8 *)p_anc_frame_buffer;
1071 hm.u.d.u.data.data_size =
1072 number_of_ancillary_frames_to_write *
1073 sizeof(struct hpi_anc_frame);
1074 if (hm.u.d.u.data.data_size <= anc_frame_buffer_size_in_bytes)
1075 hpi_send_recv(&hm, &hr);
1076 else
1077 hr.error = HPI_ERROR_INVALID_DATASIZE;
1078 return hr.error;
1081 u16 hpi_instream_host_buffer_allocate(u32 h_instream, u32 size_in_bytes)
1084 struct hpi_message hm;
1085 struct hpi_response hr;
1087 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1088 HPI_ISTREAM_HOSTBUFFER_ALLOC);
1089 if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
1090 return HPI_ERROR_INVALID_HANDLE;
1091 hm.u.d.u.data.data_size = size_in_bytes;
1092 hpi_send_recv(&hm, &hr);
1093 return hr.error;
1096 u16 hpi_instream_host_buffer_get_info(u32 h_instream, u8 **pp_buffer,
1097 struct hpi_hostbuffer_status **pp_status)
1099 struct hpi_message hm;
1100 struct hpi_response hr;
1102 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1103 HPI_ISTREAM_HOSTBUFFER_GET_INFO);
1104 if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
1105 return HPI_ERROR_INVALID_HANDLE;
1106 hpi_send_recv(&hm, &hr);
1108 if (hr.error == 0) {
1109 if (pp_buffer)
1110 *pp_buffer = hr.u.d.u.hostbuffer_info.p_buffer;
1111 if (pp_status)
1112 *pp_status = hr.u.d.u.hostbuffer_info.p_status;
1114 return hr.error;
1117 u16 hpi_instream_host_buffer_free(u32 h_instream)
1120 struct hpi_message hm;
1121 struct hpi_response hr;
1123 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1124 HPI_ISTREAM_HOSTBUFFER_FREE);
1125 if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
1126 return HPI_ERROR_INVALID_HANDLE;
1127 hpi_send_recv(&hm, &hr);
1128 return hr.error;
1131 u16 hpi_instream_group_add(u32 h_instream, u32 h_stream)
1133 struct hpi_message hm;
1134 struct hpi_response hr;
1135 u16 adapter;
1136 char c_obj_type;
1138 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1139 HPI_ISTREAM_GROUP_ADD);
1140 hr.error = 0;
1142 if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
1143 return HPI_ERROR_INVALID_HANDLE;
1145 if (hpi_handle_indexes(h_stream, &adapter,
1146 &hm.u.d.u.stream.stream_index))
1147 return HPI_ERROR_INVALID_HANDLE;
1149 c_obj_type = hpi_handle_object(h_stream);
1151 switch (c_obj_type) {
1152 case HPI_OBJ_OSTREAM:
1153 case HPI_OBJ_ISTREAM:
1154 hm.u.d.u.stream.object_type = c_obj_type;
1155 break;
1156 default:
1157 return HPI_ERROR_INVALID_OBJ;
1160 if (adapter != hm.adapter_index)
1161 return HPI_ERROR_NO_INTERADAPTER_GROUPS;
1163 hpi_send_recv(&hm, &hr);
1164 return hr.error;
1167 u16 hpi_instream_group_get_map(u32 h_instream, u32 *poutstream_map,
1168 u32 *pinstream_map)
1170 struct hpi_message hm;
1171 struct hpi_response hr;
1173 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1174 HPI_ISTREAM_HOSTBUFFER_FREE);
1175 if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
1176 return HPI_ERROR_INVALID_HANDLE;
1177 hpi_send_recv(&hm, &hr);
1179 if (poutstream_map)
1180 *poutstream_map = hr.u.d.u.group_info.outstream_group_map;
1181 if (pinstream_map)
1182 *pinstream_map = hr.u.d.u.group_info.instream_group_map;
1184 return hr.error;
1187 u16 hpi_instream_group_reset(u32 h_instream)
1189 struct hpi_message hm;
1190 struct hpi_response hr;
1192 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1193 HPI_ISTREAM_GROUP_RESET);
1194 if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
1195 return HPI_ERROR_INVALID_HANDLE;
1196 hpi_send_recv(&hm, &hr);
1197 return hr.error;
1200 u16 hpi_mixer_open(u16 adapter_index, u32 *ph_mixer)
1202 struct hpi_message hm;
1203 struct hpi_response hr;
1204 hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER, HPI_MIXER_OPEN);
1205 hm.adapter_index = adapter_index;
1207 hpi_send_recv(&hm, &hr);
1209 if (hr.error == 0)
1210 *ph_mixer =
1211 hpi_indexes_to_handle(HPI_OBJ_MIXER, adapter_index,
1213 else
1214 *ph_mixer = 0;
1215 return hr.error;
1218 u16 hpi_mixer_close(u32 h_mixer)
1220 struct hpi_message hm;
1221 struct hpi_response hr;
1223 hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER, HPI_MIXER_CLOSE);
1224 if (hpi_handle_indexes(h_mixer, &hm.adapter_index, NULL))
1225 return HPI_ERROR_INVALID_HANDLE;
1227 hpi_send_recv(&hm, &hr);
1228 return hr.error;
1231 u16 hpi_mixer_get_control(u32 h_mixer, u16 src_node_type,
1232 u16 src_node_type_index, u16 dst_node_type, u16 dst_node_type_index,
1233 u16 control_type, u32 *ph_control)
1235 struct hpi_message hm;
1236 struct hpi_response hr;
1237 hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER,
1238 HPI_MIXER_GET_CONTROL);
1239 if (hpi_handle_indexes(h_mixer, &hm.adapter_index, NULL))
1240 return HPI_ERROR_INVALID_HANDLE;
1241 hm.u.m.node_type1 = src_node_type;
1242 hm.u.m.node_index1 = src_node_type_index;
1243 hm.u.m.node_type2 = dst_node_type;
1244 hm.u.m.node_index2 = dst_node_type_index;
1245 hm.u.m.control_type = control_type;
1247 hpi_send_recv(&hm, &hr);
1249 if (hr.error == 0)
1250 *ph_control =
1251 hpi_indexes_to_handle(HPI_OBJ_CONTROL,
1252 hm.adapter_index, hr.u.m.control_index);
1253 else
1254 *ph_control = 0;
1255 return hr.error;
1258 u16 hpi_mixer_get_control_by_index(u32 h_mixer, u16 control_index,
1259 u16 *pw_src_node_type, u16 *pw_src_node_index, u16 *pw_dst_node_type,
1260 u16 *pw_dst_node_index, u16 *pw_control_type, u32 *ph_control)
1262 struct hpi_message hm;
1263 struct hpi_response hr;
1264 hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER,
1265 HPI_MIXER_GET_CONTROL_BY_INDEX);
1266 if (hpi_handle_indexes(h_mixer, &hm.adapter_index, NULL))
1267 return HPI_ERROR_INVALID_HANDLE;
1268 hm.u.m.control_index = control_index;
1269 hpi_send_recv(&hm, &hr);
1271 if (pw_src_node_type) {
1272 *pw_src_node_type =
1273 hr.u.m.src_node_type + HPI_SOURCENODE_NONE;
1274 *pw_src_node_index = hr.u.m.src_node_index;
1275 *pw_dst_node_type = hr.u.m.dst_node_type + HPI_DESTNODE_NONE;
1276 *pw_dst_node_index = hr.u.m.dst_node_index;
1278 if (pw_control_type)
1279 *pw_control_type = hr.u.m.control_index;
1281 if (ph_control) {
1282 if (hr.error == 0)
1283 *ph_control =
1284 hpi_indexes_to_handle(HPI_OBJ_CONTROL,
1285 hm.adapter_index, control_index);
1286 else
1287 *ph_control = 0;
1289 return hr.error;
1292 u16 hpi_mixer_store(u32 h_mixer, enum HPI_MIXER_STORE_COMMAND command,
1293 u16 index)
1295 struct hpi_message hm;
1296 struct hpi_response hr;
1297 hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER, HPI_MIXER_STORE);
1298 if (hpi_handle_indexes(h_mixer, &hm.adapter_index, NULL))
1299 return HPI_ERROR_INVALID_HANDLE;
1300 hm.u.mx.store.command = command;
1301 hm.u.mx.store.index = index;
1302 hpi_send_recv(&hm, &hr);
1303 return hr.error;
1306 static
1307 u16 hpi_control_param_set(const u32 h_control, const u16 attrib,
1308 const u32 param1, const u32 param2)
1310 struct hpi_message hm;
1311 struct hpi_response hr;
1313 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
1314 HPI_CONTROL_SET_STATE);
1315 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
1316 return HPI_ERROR_INVALID_HANDLE;
1317 hm.u.c.attribute = attrib;
1318 hm.u.c.param1 = param1;
1319 hm.u.c.param2 = param2;
1320 hpi_send_recv(&hm, &hr);
1321 return hr.error;
1324 static u16 hpi_control_log_set2(u32 h_control, u16 attrib, short sv0,
1325 short sv1)
1327 struct hpi_message hm;
1328 struct hpi_response hr;
1330 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
1331 HPI_CONTROL_SET_STATE);
1332 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
1333 return HPI_ERROR_INVALID_HANDLE;
1334 hm.u.c.attribute = attrib;
1335 hm.u.c.an_log_value[0] = sv0;
1336 hm.u.c.an_log_value[1] = sv1;
1337 hpi_send_recv(&hm, &hr);
1338 return hr.error;
1341 static
1342 u16 hpi_control_param_get(const u32 h_control, const u16 attrib, u32 param1,
1343 u32 param2, u32 *pparam1, u32 *pparam2)
1345 struct hpi_message hm;
1346 struct hpi_response hr;
1348 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
1349 HPI_CONTROL_GET_STATE);
1350 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
1351 return HPI_ERROR_INVALID_HANDLE;
1352 hm.u.c.attribute = attrib;
1353 hm.u.c.param1 = param1;
1354 hm.u.c.param2 = param2;
1355 hpi_send_recv(&hm, &hr);
1357 *pparam1 = hr.u.c.param1;
1358 if (pparam2)
1359 *pparam2 = hr.u.c.param2;
1361 return hr.error;
1364 #define hpi_control_param1_get(h, a, p1) \
1365 hpi_control_param_get(h, a, 0, 0, p1, NULL)
1366 #define hpi_control_param2_get(h, a, p1, p2) \
1367 hpi_control_param_get(h, a, 0, 0, p1, p2)
1369 static u16 hpi_control_log_get2(u32 h_control, u16 attrib, short *sv0,
1370 short *sv1)
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 = attrib;
1380 hpi_send_recv(&hm, &hr);
1381 *sv0 = hr.u.c.an_log_value[0];
1382 if (sv1)
1383 *sv1 = hr.u.c.an_log_value[1];
1384 return hr.error;
1387 static
1388 u16 hpi_control_query(const u32 h_control, const u16 attrib, const u32 index,
1389 const u32 param, u32 *psetting)
1391 struct hpi_message hm;
1392 struct hpi_response hr;
1394 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
1395 HPI_CONTROL_GET_INFO);
1396 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
1397 return HPI_ERROR_INVALID_HANDLE;
1399 hm.u.c.attribute = attrib;
1400 hm.u.c.param1 = index;
1401 hm.u.c.param2 = param;
1403 hpi_send_recv(&hm, &hr);
1404 *psetting = hr.u.c.param1;
1406 return hr.error;
1409 static u16 hpi_control_get_string(const u32 h_control, const u16 attribute,
1410 char *psz_string, const u32 string_length)
1412 unsigned int sub_string_index = 0, j = 0;
1413 char c = 0;
1414 unsigned int n = 0;
1415 u16 err = 0;
1417 if ((string_length < 1) || (string_length > 256))
1418 return HPI_ERROR_INVALID_CONTROL_VALUE;
1419 for (sub_string_index = 0; sub_string_index < string_length;
1420 sub_string_index += 8) {
1421 struct hpi_message hm;
1422 struct hpi_response hr;
1424 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
1425 HPI_CONTROL_GET_STATE);
1426 if (hpi_handle_indexes(h_control, &hm.adapter_index,
1427 &hm.obj_index))
1428 return HPI_ERROR_INVALID_HANDLE;
1429 hm.u.c.attribute = attribute;
1430 hm.u.c.param1 = sub_string_index;
1431 hm.u.c.param2 = 0;
1432 hpi_send_recv(&hm, &hr);
1434 if (sub_string_index == 0
1435 && (hr.u.cu.chars8.remaining_chars + 8) >
1436 string_length)
1437 return HPI_ERROR_INVALID_CONTROL_VALUE;
1439 if (hr.error) {
1440 err = hr.error;
1441 break;
1443 for (j = 0; j < 8; j++) {
1444 c = hr.u.cu.chars8.sz_data[j];
1445 psz_string[sub_string_index + j] = c;
1446 n++;
1447 if (n >= string_length) {
1448 psz_string[string_length - 1] = 0;
1449 err = HPI_ERROR_INVALID_CONTROL_VALUE;
1450 break;
1452 if (c == 0)
1453 break;
1456 if ((hr.u.cu.chars8.remaining_chars == 0)
1457 && ((sub_string_index + j) < string_length)
1458 && (c != 0)) {
1459 c = 0;
1460 psz_string[sub_string_index + j] = c;
1462 if (c == 0)
1463 break;
1465 return err;
1468 u16 hpi_aesebu_receiver_query_format(const u32 h_aes_rx, const u32 index,
1469 u16 *pw_format)
1471 u32 qr;
1472 u16 err;
1474 err = hpi_control_query(h_aes_rx, HPI_AESEBURX_FORMAT, index, 0, &qr);
1475 *pw_format = (u16)qr;
1476 return err;
1479 u16 hpi_aesebu_receiver_set_format(u32 h_control, u16 format)
1481 return hpi_control_param_set(h_control, HPI_AESEBURX_FORMAT, format,
1485 u16 hpi_aesebu_receiver_get_format(u32 h_control, u16 *pw_format)
1487 u16 err;
1488 u32 param;
1490 err = hpi_control_param1_get(h_control, HPI_AESEBURX_FORMAT, &param);
1491 if (!err && pw_format)
1492 *pw_format = (u16)param;
1494 return err;
1497 u16 hpi_aesebu_receiver_get_sample_rate(u32 h_control, u32 *psample_rate)
1499 return hpi_control_param1_get(h_control, HPI_AESEBURX_SAMPLERATE,
1500 psample_rate);
1503 u16 hpi_aesebu_receiver_get_user_data(u32 h_control, u16 index, u16 *pw_data)
1505 struct hpi_message hm;
1506 struct hpi_response hr;
1507 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
1508 HPI_CONTROL_GET_STATE);
1509 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
1510 return HPI_ERROR_INVALID_HANDLE;
1511 hm.u.c.attribute = HPI_AESEBURX_USERDATA;
1512 hm.u.c.param1 = index;
1514 hpi_send_recv(&hm, &hr);
1516 if (pw_data)
1517 *pw_data = (u16)hr.u.c.param2;
1518 return hr.error;
1521 u16 hpi_aesebu_receiver_get_channel_status(u32 h_control, u16 index,
1522 u16 *pw_data)
1524 struct hpi_message hm;
1525 struct hpi_response hr;
1526 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
1527 HPI_CONTROL_GET_STATE);
1528 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
1529 return HPI_ERROR_INVALID_HANDLE;
1530 hm.u.c.attribute = HPI_AESEBURX_CHANNELSTATUS;
1531 hm.u.c.param1 = index;
1533 hpi_send_recv(&hm, &hr);
1535 if (pw_data)
1536 *pw_data = (u16)hr.u.c.param2;
1537 return hr.error;
1540 u16 hpi_aesebu_receiver_get_error_status(u32 h_control, u16 *pw_error_data)
1542 u32 error_data = 0;
1543 u16 err = 0;
1545 err = hpi_control_param1_get(h_control, HPI_AESEBURX_ERRORSTATUS,
1546 &error_data);
1547 if (pw_error_data)
1548 *pw_error_data = (u16)error_data;
1549 return err;
1552 u16 hpi_aesebu_transmitter_set_sample_rate(u32 h_control, u32 sample_rate)
1554 return hpi_control_param_set(h_control, HPI_AESEBUTX_SAMPLERATE,
1555 sample_rate, 0);
1558 u16 hpi_aesebu_transmitter_set_user_data(u32 h_control, u16 index, u16 data)
1560 return hpi_control_param_set(h_control, HPI_AESEBUTX_USERDATA, index,
1561 data);
1564 u16 hpi_aesebu_transmitter_set_channel_status(u32 h_control, u16 index,
1565 u16 data)
1567 return hpi_control_param_set(h_control, HPI_AESEBUTX_CHANNELSTATUS,
1568 index, data);
1571 u16 hpi_aesebu_transmitter_get_channel_status(u32 h_control, u16 index,
1572 u16 *pw_data)
1574 return HPI_ERROR_INVALID_OPERATION;
1577 u16 hpi_aesebu_transmitter_query_format(const u32 h_aes_tx, const u32 index,
1578 u16 *pw_format)
1580 u32 qr;
1581 u16 err;
1583 err = hpi_control_query(h_aes_tx, HPI_AESEBUTX_FORMAT, index, 0, &qr);
1584 *pw_format = (u16)qr;
1585 return err;
1588 u16 hpi_aesebu_transmitter_set_format(u32 h_control, u16 output_format)
1590 return hpi_control_param_set(h_control, HPI_AESEBUTX_FORMAT,
1591 output_format, 0);
1594 u16 hpi_aesebu_transmitter_get_format(u32 h_control, u16 *pw_output_format)
1596 u16 err;
1597 u32 param;
1599 err = hpi_control_param1_get(h_control, HPI_AESEBUTX_FORMAT, &param);
1600 if (!err && pw_output_format)
1601 *pw_output_format = (u16)param;
1603 return err;
1606 u16 hpi_bitstream_set_clock_edge(u32 h_control, u16 edge_type)
1608 return hpi_control_param_set(h_control, HPI_BITSTREAM_CLOCK_EDGE,
1609 edge_type, 0);
1612 u16 hpi_bitstream_set_data_polarity(u32 h_control, u16 polarity)
1614 return hpi_control_param_set(h_control, HPI_BITSTREAM_DATA_POLARITY,
1615 polarity, 0);
1618 u16 hpi_bitstream_get_activity(u32 h_control, u16 *pw_clk_activity,
1619 u16 *pw_data_activity)
1621 struct hpi_message hm;
1622 struct hpi_response hr;
1623 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
1624 HPI_CONTROL_GET_STATE);
1625 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
1626 return HPI_ERROR_INVALID_HANDLE;
1627 hm.u.c.attribute = HPI_BITSTREAM_ACTIVITY;
1628 hpi_send_recv(&hm, &hr);
1629 if (pw_clk_activity)
1630 *pw_clk_activity = (u16)hr.u.c.param1;
1631 if (pw_data_activity)
1632 *pw_data_activity = (u16)hr.u.c.param2;
1633 return hr.error;
1636 u16 hpi_channel_mode_query_mode(const u32 h_mode, const u32 index,
1637 u16 *pw_mode)
1639 u32 qr;
1640 u16 err;
1642 err = hpi_control_query(h_mode, HPI_CHANNEL_MODE_MODE, index, 0, &qr);
1643 *pw_mode = (u16)qr;
1644 return err;
1647 u16 hpi_channel_mode_set(u32 h_control, u16 mode)
1649 return hpi_control_param_set(h_control, HPI_CHANNEL_MODE_MODE, mode,
1653 u16 hpi_channel_mode_get(u32 h_control, u16 *mode)
1655 u32 mode32 = 0;
1656 u16 err = hpi_control_param1_get(h_control,
1657 HPI_CHANNEL_MODE_MODE, &mode32);
1658 if (mode)
1659 *mode = (u16)mode32;
1660 return err;
1663 u16 hpi_cobranet_hmi_write(u32 h_control, u32 hmi_address, u32 byte_count,
1664 u8 *pb_data)
1666 struct hpi_message hm;
1667 struct hpi_response hr;
1669 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROLEX,
1670 HPI_CONTROL_SET_STATE);
1671 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
1672 return HPI_ERROR_INVALID_HANDLE;
1674 hm.u.cx.u.cobranet_data.byte_count = byte_count;
1675 hm.u.cx.u.cobranet_data.hmi_address = hmi_address;
1677 if (byte_count <= 8) {
1678 memcpy(hm.u.cx.u.cobranet_data.data, pb_data, byte_count);
1679 hm.u.cx.attribute = HPI_COBRANET_SET;
1680 } else {
1681 hm.u.cx.u.cobranet_bigdata.pb_data = pb_data;
1682 hm.u.cx.attribute = HPI_COBRANET_SET_DATA;
1685 hpi_send_recv(&hm, &hr);
1687 return hr.error;
1690 u16 hpi_cobranet_hmi_read(u32 h_control, u32 hmi_address, u32 max_byte_count,
1691 u32 *pbyte_count, u8 *pb_data)
1693 struct hpi_message hm;
1694 struct hpi_response hr;
1696 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROLEX,
1697 HPI_CONTROL_GET_STATE);
1698 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
1699 return HPI_ERROR_INVALID_HANDLE;
1701 hm.u.cx.u.cobranet_data.byte_count = max_byte_count;
1702 hm.u.cx.u.cobranet_data.hmi_address = hmi_address;
1704 if (max_byte_count <= 8) {
1705 hm.u.cx.attribute = HPI_COBRANET_GET;
1706 } else {
1707 hm.u.cx.u.cobranet_bigdata.pb_data = pb_data;
1708 hm.u.cx.attribute = HPI_COBRANET_GET_DATA;
1711 hpi_send_recv(&hm, &hr);
1712 if (!hr.error && pb_data) {
1714 *pbyte_count = hr.u.cx.u.cobranet_data.byte_count;
1716 if (*pbyte_count < max_byte_count)
1717 max_byte_count = *pbyte_count;
1719 if (hm.u.cx.attribute == HPI_COBRANET_GET) {
1720 memcpy(pb_data, hr.u.cx.u.cobranet_data.data,
1721 max_byte_count);
1722 } else {
1727 return hr.error;
1730 u16 hpi_cobranet_hmi_get_status(u32 h_control, u32 *pstatus,
1731 u32 *preadable_size, u32 *pwriteable_size)
1733 struct hpi_message hm;
1734 struct hpi_response hr;
1736 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROLEX,
1737 HPI_CONTROL_GET_STATE);
1738 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
1739 return HPI_ERROR_INVALID_HANDLE;
1741 hm.u.cx.attribute = HPI_COBRANET_GET_STATUS;
1743 hpi_send_recv(&hm, &hr);
1744 if (!hr.error) {
1745 if (pstatus)
1746 *pstatus = hr.u.cx.u.cobranet_status.status;
1747 if (preadable_size)
1748 *preadable_size =
1749 hr.u.cx.u.cobranet_status.readable_size;
1750 if (pwriteable_size)
1751 *pwriteable_size =
1752 hr.u.cx.u.cobranet_status.writeable_size;
1754 return hr.error;
1757 u16 hpi_cobranet_get_ip_address(u32 h_control, u32 *pdw_ip_address)
1759 u32 byte_count;
1760 u32 iP;
1761 u16 err;
1763 err = hpi_cobranet_hmi_read(h_control,
1764 HPI_COBRANET_HMI_cobra_ip_mon_currentIP, 4, &byte_count,
1765 (u8 *)&iP);
1767 *pdw_ip_address =
1768 ((iP & 0xff000000) >> 8) | ((iP & 0x00ff0000) << 8) | ((iP &
1769 0x0000ff00) >> 8) | ((iP & 0x000000ff) << 8);
1771 if (err)
1772 *pdw_ip_address = 0;
1774 return err;
1778 u16 hpi_cobranet_set_ip_address(u32 h_control, u32 dw_ip_address)
1780 u32 iP;
1781 u16 err;
1783 iP = ((dw_ip_address & 0xff000000) >> 8) | ((dw_ip_address &
1784 0x00ff0000) << 8) | ((dw_ip_address & 0x0000ff00) >>
1785 8) | ((dw_ip_address & 0x000000ff) << 8);
1787 err = hpi_cobranet_hmi_write(h_control,
1788 HPI_COBRANET_HMI_cobra_ip_mon_currentIP, 4, (u8 *)&iP);
1790 return err;
1794 u16 hpi_cobranet_get_static_ip_address(u32 h_control, u32 *pdw_ip_address)
1796 u32 byte_count;
1797 u32 iP;
1798 u16 err;
1799 err = hpi_cobranet_hmi_read(h_control,
1800 HPI_COBRANET_HMI_cobra_ip_mon_staticIP, 4, &byte_count,
1801 (u8 *)&iP);
1803 *pdw_ip_address =
1804 ((iP & 0xff000000) >> 8) | ((iP & 0x00ff0000) << 8) | ((iP &
1805 0x0000ff00) >> 8) | ((iP & 0x000000ff) << 8);
1807 if (err)
1808 *pdw_ip_address = 0;
1810 return err;
1814 u16 hpi_cobranet_set_static_ip_address(u32 h_control, u32 dw_ip_address)
1816 u32 iP;
1817 u16 err;
1819 iP = ((dw_ip_address & 0xff000000) >> 8) | ((dw_ip_address &
1820 0x00ff0000) << 8) | ((dw_ip_address & 0x0000ff00) >>
1821 8) | ((dw_ip_address & 0x000000ff) << 8);
1823 err = hpi_cobranet_hmi_write(h_control,
1824 HPI_COBRANET_HMI_cobra_ip_mon_staticIP, 4, (u8 *)&iP);
1826 return err;
1830 u16 hpi_cobranet_get_macaddress(u32 h_control, u32 *p_mac_msbs,
1831 u32 *p_mac_lsbs)
1833 u32 byte_count;
1834 u16 err;
1835 u32 mac;
1837 err = hpi_cobranet_hmi_read(h_control,
1838 HPI_COBRANET_HMI_cobra_if_phy_address, 4, &byte_count,
1839 (u8 *)&mac);
1841 if (!err) {
1842 *p_mac_msbs =
1843 ((mac & 0xff000000) >> 8) | ((mac & 0x00ff0000) << 8)
1844 | ((mac & 0x0000ff00) >> 8) | ((mac & 0x000000ff) <<
1847 err = hpi_cobranet_hmi_read(h_control,
1848 HPI_COBRANET_HMI_cobra_if_phy_address + 1, 4,
1849 &byte_count, (u8 *)&mac);
1852 if (!err) {
1853 *p_mac_lsbs =
1854 ((mac & 0xff000000) >> 8) | ((mac & 0x00ff0000) << 8)
1855 | ((mac & 0x0000ff00) >> 8) | ((mac & 0x000000ff) <<
1857 } else {
1858 *p_mac_msbs = 0;
1859 *p_mac_lsbs = 0;
1862 return err;
1865 u16 hpi_compander_set_enable(u32 h_control, u32 enable)
1867 return hpi_control_param_set(h_control, HPI_GENERIC_ENABLE, enable,
1871 u16 hpi_compander_get_enable(u32 h_control, u32 *enable)
1873 return hpi_control_param1_get(h_control, HPI_GENERIC_ENABLE, enable);
1876 u16 hpi_compander_set_makeup_gain(u32 h_control, short makeup_gain0_01dB)
1878 return hpi_control_log_set2(h_control, HPI_COMPANDER_MAKEUPGAIN,
1879 makeup_gain0_01dB, 0);
1882 u16 hpi_compander_get_makeup_gain(u32 h_control, short *makeup_gain0_01dB)
1884 return hpi_control_log_get2(h_control, HPI_COMPANDER_MAKEUPGAIN,
1885 makeup_gain0_01dB, NULL);
1888 u16 hpi_compander_set_attack_time_constant(u32 h_control, unsigned int index,
1889 u32 attack)
1891 return hpi_control_param_set(h_control, HPI_COMPANDER_ATTACK, attack,
1892 index);
1895 u16 hpi_compander_get_attack_time_constant(u32 h_control, unsigned int index,
1896 u32 *attack)
1898 return hpi_control_param_get(h_control, HPI_COMPANDER_ATTACK, 0,
1899 index, attack, NULL);
1902 u16 hpi_compander_set_decay_time_constant(u32 h_control, unsigned int index,
1903 u32 decay)
1905 return hpi_control_param_set(h_control, HPI_COMPANDER_DECAY, decay,
1906 index);
1909 u16 hpi_compander_get_decay_time_constant(u32 h_control, unsigned int index,
1910 u32 *decay)
1912 return hpi_control_param_get(h_control, HPI_COMPANDER_DECAY, 0, index,
1913 decay, NULL);
1917 u16 hpi_compander_set_threshold(u32 h_control, unsigned int index,
1918 short threshold0_01dB)
1920 struct hpi_message hm;
1921 struct hpi_response hr;
1923 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
1924 HPI_CONTROL_SET_STATE);
1925 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
1926 return HPI_ERROR_INVALID_HANDLE;
1927 hm.u.c.attribute = HPI_COMPANDER_THRESHOLD;
1928 hm.u.c.param2 = index;
1929 hm.u.c.an_log_value[0] = threshold0_01dB;
1931 hpi_send_recv(&hm, &hr);
1933 return hr.error;
1936 u16 hpi_compander_get_threshold(u32 h_control, unsigned int index,
1937 short *threshold0_01dB)
1939 struct hpi_message hm;
1940 struct hpi_response hr;
1942 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
1943 HPI_CONTROL_GET_STATE);
1944 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
1945 return HPI_ERROR_INVALID_HANDLE;
1946 hm.u.c.attribute = HPI_COMPANDER_THRESHOLD;
1947 hm.u.c.param2 = index;
1949 hpi_send_recv(&hm, &hr);
1950 *threshold0_01dB = hr.u.c.an_log_value[0];
1952 return hr.error;
1955 u16 hpi_compander_set_ratio(u32 h_control, u32 index, u32 ratio100)
1957 return hpi_control_param_set(h_control, HPI_COMPANDER_RATIO, ratio100,
1958 index);
1961 u16 hpi_compander_get_ratio(u32 h_control, u32 index, u32 *ratio100)
1963 return hpi_control_param_get(h_control, HPI_COMPANDER_RATIO, 0, index,
1964 ratio100, NULL);
1967 u16 hpi_level_query_range(u32 h_control, short *min_gain_01dB,
1968 short *max_gain_01dB, short *step_gain_01dB)
1970 struct hpi_message hm;
1971 struct hpi_response hr;
1973 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
1974 HPI_CONTROL_GET_STATE);
1975 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
1976 return HPI_ERROR_INVALID_HANDLE;
1977 hm.u.c.attribute = HPI_LEVEL_RANGE;
1979 hpi_send_recv(&hm, &hr);
1980 if (hr.error) {
1981 hr.u.c.an_log_value[0] = 0;
1982 hr.u.c.an_log_value[1] = 0;
1983 hr.u.c.param1 = 0;
1985 if (min_gain_01dB)
1986 *min_gain_01dB = hr.u.c.an_log_value[0];
1987 if (max_gain_01dB)
1988 *max_gain_01dB = hr.u.c.an_log_value[1];
1989 if (step_gain_01dB)
1990 *step_gain_01dB = (short)hr.u.c.param1;
1991 return hr.error;
1994 u16 hpi_level_set_gain(u32 h_control, short an_gain0_01dB[HPI_MAX_CHANNELS]
1997 return hpi_control_log_set2(h_control, HPI_LEVEL_GAIN,
1998 an_gain0_01dB[0], an_gain0_01dB[1]);
2001 u16 hpi_level_get_gain(u32 h_control, short an_gain0_01dB[HPI_MAX_CHANNELS]
2004 return hpi_control_log_get2(h_control, HPI_LEVEL_GAIN,
2005 &an_gain0_01dB[0], &an_gain0_01dB[1]);
2008 u16 hpi_meter_query_channels(const u32 h_meter, u32 *p_channels)
2010 return hpi_control_query(h_meter, HPI_METER_NUM_CHANNELS, 0, 0,
2011 p_channels);
2014 u16 hpi_meter_get_peak(u32 h_control, short an_peakdB[HPI_MAX_CHANNELS]
2017 short i = 0;
2019 struct hpi_message hm;
2020 struct hpi_response hr;
2022 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2023 HPI_CONTROL_GET_STATE);
2024 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
2025 return HPI_ERROR_INVALID_HANDLE;
2026 hm.obj_index = hm.obj_index;
2027 hm.u.c.attribute = HPI_METER_PEAK;
2029 hpi_send_recv(&hm, &hr);
2031 if (!hr.error)
2032 memcpy(an_peakdB, hr.u.c.an_log_value,
2033 sizeof(short) * HPI_MAX_CHANNELS);
2034 else
2035 for (i = 0; i < HPI_MAX_CHANNELS; i++)
2036 an_peakdB[i] = HPI_METER_MINIMUM;
2037 return hr.error;
2040 u16 hpi_meter_get_rms(u32 h_control, short an_rmsdB[HPI_MAX_CHANNELS]
2043 short i = 0;
2045 struct hpi_message hm;
2046 struct hpi_response hr;
2048 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2049 HPI_CONTROL_GET_STATE);
2050 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
2051 return HPI_ERROR_INVALID_HANDLE;
2052 hm.u.c.attribute = HPI_METER_RMS;
2054 hpi_send_recv(&hm, &hr);
2056 if (!hr.error)
2057 memcpy(an_rmsdB, hr.u.c.an_log_value,
2058 sizeof(short) * HPI_MAX_CHANNELS);
2059 else
2060 for (i = 0; i < HPI_MAX_CHANNELS; i++)
2061 an_rmsdB[i] = HPI_METER_MINIMUM;
2063 return hr.error;
2066 u16 hpi_meter_set_rms_ballistics(u32 h_control, u16 attack, u16 decay)
2068 return hpi_control_param_set(h_control, HPI_METER_RMS_BALLISTICS,
2069 attack, decay);
2072 u16 hpi_meter_get_rms_ballistics(u32 h_control, u16 *pn_attack, u16 *pn_decay)
2074 u32 attack;
2075 u32 decay;
2076 u16 error;
2078 error = hpi_control_param2_get(h_control, HPI_METER_RMS_BALLISTICS,
2079 &attack, &decay);
2081 if (pn_attack)
2082 *pn_attack = (unsigned short)attack;
2083 if (pn_decay)
2084 *pn_decay = (unsigned short)decay;
2086 return error;
2089 u16 hpi_meter_set_peak_ballistics(u32 h_control, u16 attack, u16 decay)
2091 return hpi_control_param_set(h_control, HPI_METER_PEAK_BALLISTICS,
2092 attack, decay);
2095 u16 hpi_meter_get_peak_ballistics(u32 h_control, u16 *pn_attack,
2096 u16 *pn_decay)
2098 u32 attack;
2099 u32 decay;
2100 u16 error;
2102 error = hpi_control_param2_get(h_control, HPI_METER_PEAK_BALLISTICS,
2103 &attack, &decay);
2105 if (pn_attack)
2106 *pn_attack = (short)attack;
2107 if (pn_decay)
2108 *pn_decay = (short)decay;
2110 return error;
2113 u16 hpi_microphone_set_phantom_power(u32 h_control, u16 on_off)
2115 return hpi_control_param_set(h_control, HPI_MICROPHONE_PHANTOM_POWER,
2116 (u32)on_off, 0);
2119 u16 hpi_microphone_get_phantom_power(u32 h_control, u16 *pw_on_off)
2121 u16 error = 0;
2122 u32 on_off = 0;
2123 error = hpi_control_param1_get(h_control,
2124 HPI_MICROPHONE_PHANTOM_POWER, &on_off);
2125 if (pw_on_off)
2126 *pw_on_off = (u16)on_off;
2127 return error;
2130 u16 hpi_multiplexer_set_source(u32 h_control, u16 source_node_type,
2131 u16 source_node_index)
2133 return hpi_control_param_set(h_control, HPI_MULTIPLEXER_SOURCE,
2134 source_node_type, source_node_index);
2137 u16 hpi_multiplexer_get_source(u32 h_control, u16 *source_node_type,
2138 u16 *source_node_index)
2140 u32 node, index;
2141 u16 err = hpi_control_param2_get(h_control,
2142 HPI_MULTIPLEXER_SOURCE, &node,
2143 &index);
2144 if (source_node_type)
2145 *source_node_type = (u16)node;
2146 if (source_node_index)
2147 *source_node_index = (u16)index;
2148 return err;
2151 u16 hpi_multiplexer_query_source(u32 h_control, u16 index,
2152 u16 *source_node_type, u16 *source_node_index)
2154 struct hpi_message hm;
2155 struct hpi_response hr;
2156 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2157 HPI_CONTROL_GET_STATE);
2158 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
2159 return HPI_ERROR_INVALID_HANDLE;
2160 hm.u.c.attribute = HPI_MULTIPLEXER_QUERYSOURCE;
2161 hm.u.c.param1 = index;
2163 hpi_send_recv(&hm, &hr);
2165 if (source_node_type)
2166 *source_node_type = (u16)hr.u.c.param1;
2167 if (source_node_index)
2168 *source_node_index = (u16)hr.u.c.param2;
2169 return hr.error;
2172 u16 hpi_parametric_eq_get_info(u32 h_control, u16 *pw_number_of_bands,
2173 u16 *pw_on_off)
2175 u32 oB = 0;
2176 u32 oO = 0;
2177 u16 error = 0;
2179 error = hpi_control_param2_get(h_control, HPI_EQUALIZER_NUM_FILTERS,
2180 &oO, &oB);
2181 if (pw_number_of_bands)
2182 *pw_number_of_bands = (u16)oB;
2183 if (pw_on_off)
2184 *pw_on_off = (u16)oO;
2185 return error;
2188 u16 hpi_parametric_eq_set_state(u32 h_control, u16 on_off)
2190 return hpi_control_param_set(h_control, HPI_EQUALIZER_NUM_FILTERS,
2191 on_off, 0);
2194 u16 hpi_parametric_eq_get_band(u32 h_control, u16 index, u16 *pn_type,
2195 u32 *pfrequency_hz, short *pnQ100, short *pn_gain0_01dB)
2197 struct hpi_message hm;
2198 struct hpi_response hr;
2200 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2201 HPI_CONTROL_GET_STATE);
2202 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
2203 return HPI_ERROR_INVALID_HANDLE;
2204 hm.u.c.attribute = HPI_EQUALIZER_FILTER;
2205 hm.u.c.param2 = index;
2207 hpi_send_recv(&hm, &hr);
2209 if (pfrequency_hz)
2210 *pfrequency_hz = hr.u.c.param1;
2211 if (pn_type)
2212 *pn_type = (u16)(hr.u.c.param2 >> 16);
2213 if (pnQ100)
2214 *pnQ100 = hr.u.c.an_log_value[1];
2215 if (pn_gain0_01dB)
2216 *pn_gain0_01dB = hr.u.c.an_log_value[0];
2218 return hr.error;
2221 u16 hpi_parametric_eq_set_band(u32 h_control, u16 index, u16 type,
2222 u32 frequency_hz, short q100, short gain0_01dB)
2224 struct hpi_message hm;
2225 struct hpi_response hr;
2227 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2228 HPI_CONTROL_SET_STATE);
2229 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
2230 return HPI_ERROR_INVALID_HANDLE;
2232 hm.u.c.param1 = frequency_hz;
2233 hm.u.c.param2 = (index & 0xFFFFL) + ((u32)type << 16);
2234 hm.u.c.an_log_value[0] = gain0_01dB;
2235 hm.u.c.an_log_value[1] = q100;
2236 hm.u.c.attribute = HPI_EQUALIZER_FILTER;
2238 hpi_send_recv(&hm, &hr);
2240 return hr.error;
2243 u16 hpi_parametric_eq_get_coeffs(u32 h_control, u16 index, short coeffs[5]
2246 struct hpi_message hm;
2247 struct hpi_response hr;
2249 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2250 HPI_CONTROL_GET_STATE);
2251 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
2252 return HPI_ERROR_INVALID_HANDLE;
2253 hm.u.c.attribute = HPI_EQUALIZER_COEFFICIENTS;
2254 hm.u.c.param2 = index;
2256 hpi_send_recv(&hm, &hr);
2258 coeffs[0] = (short)hr.u.c.an_log_value[0];
2259 coeffs[1] = (short)hr.u.c.an_log_value[1];
2260 coeffs[2] = (short)hr.u.c.param1;
2261 coeffs[3] = (short)(hr.u.c.param1 >> 16);
2262 coeffs[4] = (short)hr.u.c.param2;
2264 return hr.error;
2267 u16 hpi_sample_clock_query_source(const u32 h_clock, const u32 index,
2268 u16 *pw_source)
2270 u32 qr;
2271 u16 err;
2273 err = hpi_control_query(h_clock, HPI_SAMPLECLOCK_SOURCE, index, 0,
2274 &qr);
2275 *pw_source = (u16)qr;
2276 return err;
2279 u16 hpi_sample_clock_set_source(u32 h_control, u16 source)
2281 return hpi_control_param_set(h_control, HPI_SAMPLECLOCK_SOURCE,
2282 source, 0);
2285 u16 hpi_sample_clock_get_source(u32 h_control, u16 *pw_source)
2287 u16 err = 0;
2288 u32 source = 0;
2289 err = hpi_control_param1_get(h_control, HPI_SAMPLECLOCK_SOURCE,
2290 &source);
2291 if (!err)
2292 if (pw_source)
2293 *pw_source = (u16)source;
2294 return err;
2297 u16 hpi_sample_clock_query_source_index(const u32 h_clock, const u32 index,
2298 const u32 source, u16 *pw_source_index)
2300 u32 qr;
2301 u16 err;
2303 err = hpi_control_query(h_clock, HPI_SAMPLECLOCK_SOURCE_INDEX, index,
2304 source, &qr);
2305 *pw_source_index = (u16)qr;
2306 return err;
2309 u16 hpi_sample_clock_set_source_index(u32 h_control, u16 source_index)
2311 return hpi_control_param_set(h_control, HPI_SAMPLECLOCK_SOURCE_INDEX,
2312 source_index, 0);
2315 u16 hpi_sample_clock_get_source_index(u32 h_control, u16 *pw_source_index)
2317 u16 err = 0;
2318 u32 source_index = 0;
2319 err = hpi_control_param1_get(h_control, HPI_SAMPLECLOCK_SOURCE_INDEX,
2320 &source_index);
2321 if (!err)
2322 if (pw_source_index)
2323 *pw_source_index = (u16)source_index;
2324 return err;
2327 u16 hpi_sample_clock_query_local_rate(const u32 h_clock, const u32 index,
2328 u32 *prate)
2330 u16 err;
2331 err = hpi_control_query(h_clock, HPI_SAMPLECLOCK_LOCAL_SAMPLERATE,
2332 index, 0, prate);
2334 return err;
2337 u16 hpi_sample_clock_set_local_rate(u32 h_control, u32 sample_rate)
2339 return hpi_control_param_set(h_control,
2340 HPI_SAMPLECLOCK_LOCAL_SAMPLERATE, sample_rate, 0);
2343 u16 hpi_sample_clock_get_local_rate(u32 h_control, u32 *psample_rate)
2345 u16 err = 0;
2346 u32 sample_rate = 0;
2347 err = hpi_control_param1_get(h_control,
2348 HPI_SAMPLECLOCK_LOCAL_SAMPLERATE, &sample_rate);
2349 if (!err)
2350 if (psample_rate)
2351 *psample_rate = sample_rate;
2352 return err;
2355 u16 hpi_sample_clock_get_sample_rate(u32 h_control, u32 *psample_rate)
2357 u16 err = 0;
2358 u32 sample_rate = 0;
2359 err = hpi_control_param1_get(h_control, HPI_SAMPLECLOCK_SAMPLERATE,
2360 &sample_rate);
2361 if (!err)
2362 if (psample_rate)
2363 *psample_rate = sample_rate;
2364 return err;
2367 u16 hpi_sample_clock_set_auto(u32 h_control, u32 enable)
2369 return hpi_control_param_set(h_control, HPI_SAMPLECLOCK_AUTO, enable,
2373 u16 hpi_sample_clock_get_auto(u32 h_control, u32 *penable)
2375 return hpi_control_param1_get(h_control, HPI_SAMPLECLOCK_AUTO,
2376 penable);
2379 u16 hpi_sample_clock_set_local_rate_lock(u32 h_control, u32 lock)
2381 return hpi_control_param_set(h_control, HPI_SAMPLECLOCK_LOCAL_LOCK,
2382 lock, 0);
2385 u16 hpi_sample_clock_get_local_rate_lock(u32 h_control, u32 *plock)
2387 return hpi_control_param1_get(h_control, HPI_SAMPLECLOCK_LOCAL_LOCK,
2388 plock);
2391 u16 hpi_tone_detector_get_frequency(u32 h_control, u32 index, u32 *frequency)
2393 return hpi_control_param_get(h_control, HPI_TONEDETECTOR_FREQUENCY,
2394 index, 0, frequency, NULL);
2397 u16 hpi_tone_detector_get_state(u32 h_control, u32 *state)
2399 return hpi_control_param1_get(h_control, HPI_TONEDETECTOR_STATE,
2400 state);
2403 u16 hpi_tone_detector_set_enable(u32 h_control, u32 enable)
2405 return hpi_control_param_set(h_control, HPI_GENERIC_ENABLE, enable,
2409 u16 hpi_tone_detector_get_enable(u32 h_control, u32 *enable)
2411 return hpi_control_param1_get(h_control, HPI_GENERIC_ENABLE, enable);
2414 u16 hpi_tone_detector_set_event_enable(u32 h_control, u32 event_enable)
2416 return hpi_control_param_set(h_control, HPI_GENERIC_EVENT_ENABLE,
2417 (u32)event_enable, 0);
2420 u16 hpi_tone_detector_get_event_enable(u32 h_control, u32 *event_enable)
2422 return hpi_control_param1_get(h_control, HPI_GENERIC_EVENT_ENABLE,
2423 event_enable);
2426 u16 hpi_tone_detector_set_threshold(u32 h_control, int threshold)
2428 return hpi_control_param_set(h_control, HPI_TONEDETECTOR_THRESHOLD,
2429 (u32)threshold, 0);
2432 u16 hpi_tone_detector_get_threshold(u32 h_control, int *threshold)
2434 return hpi_control_param1_get(h_control, HPI_TONEDETECTOR_THRESHOLD,
2435 (u32 *)threshold);
2438 u16 hpi_silence_detector_get_state(u32 h_control, u32 *state)
2440 return hpi_control_param1_get(h_control, HPI_SILENCEDETECTOR_STATE,
2441 state);
2444 u16 hpi_silence_detector_set_enable(u32 h_control, u32 enable)
2446 return hpi_control_param_set(h_control, HPI_GENERIC_ENABLE, enable,
2450 u16 hpi_silence_detector_get_enable(u32 h_control, u32 *enable)
2452 return hpi_control_param1_get(h_control, HPI_GENERIC_ENABLE, enable);
2455 u16 hpi_silence_detector_set_event_enable(u32 h_control, u32 event_enable)
2457 return hpi_control_param_set(h_control, HPI_GENERIC_EVENT_ENABLE,
2458 event_enable, 0);
2461 u16 hpi_silence_detector_get_event_enable(u32 h_control, u32 *event_enable)
2463 return hpi_control_param1_get(h_control, HPI_GENERIC_EVENT_ENABLE,
2464 event_enable);
2467 u16 hpi_silence_detector_set_delay(u32 h_control, u32 delay)
2469 return hpi_control_param_set(h_control, HPI_SILENCEDETECTOR_DELAY,
2470 delay, 0);
2473 u16 hpi_silence_detector_get_delay(u32 h_control, u32 *delay)
2475 return hpi_control_param1_get(h_control, HPI_SILENCEDETECTOR_DELAY,
2476 delay);
2479 u16 hpi_silence_detector_set_threshold(u32 h_control, int threshold)
2481 return hpi_control_param_set(h_control, HPI_SILENCEDETECTOR_THRESHOLD,
2482 threshold, 0);
2485 u16 hpi_silence_detector_get_threshold(u32 h_control, int *threshold)
2487 return hpi_control_param1_get(h_control,
2488 HPI_SILENCEDETECTOR_THRESHOLD, (u32 *)threshold);
2491 u16 hpi_tuner_query_band(const u32 h_tuner, const u32 index, u16 *pw_band)
2493 u32 qr;
2494 u16 err;
2496 err = hpi_control_query(h_tuner, HPI_TUNER_BAND, index, 0, &qr);
2497 *pw_band = (u16)qr;
2498 return err;
2501 u16 hpi_tuner_set_band(u32 h_control, u16 band)
2503 return hpi_control_param_set(h_control, HPI_TUNER_BAND, band, 0);
2506 u16 hpi_tuner_get_band(u32 h_control, u16 *pw_band)
2508 u32 band = 0;
2509 u16 error = 0;
2511 error = hpi_control_param1_get(h_control, HPI_TUNER_BAND, &band);
2512 if (pw_band)
2513 *pw_band = (u16)band;
2514 return error;
2517 u16 hpi_tuner_query_frequency(const u32 h_tuner, const u32 index,
2518 const u16 band, u32 *pfreq)
2520 return hpi_control_query(h_tuner, HPI_TUNER_FREQ, index, band, pfreq);
2523 u16 hpi_tuner_set_frequency(u32 h_control, u32 freq_ink_hz)
2525 return hpi_control_param_set(h_control, HPI_TUNER_FREQ, freq_ink_hz,
2529 u16 hpi_tuner_get_frequency(u32 h_control, u32 *pw_freq_ink_hz)
2531 return hpi_control_param1_get(h_control, HPI_TUNER_FREQ,
2532 pw_freq_ink_hz);
2535 u16 hpi_tuner_query_gain(const u32 h_tuner, const u32 index, u16 *pw_gain)
2537 u32 qr;
2538 u16 err;
2540 err = hpi_control_query(h_tuner, HPI_TUNER_BAND, index, 0, &qr);
2541 *pw_gain = (u16)qr;
2542 return err;
2545 u16 hpi_tuner_set_gain(u32 h_control, short gain)
2547 return hpi_control_param_set(h_control, HPI_TUNER_GAIN, gain, 0);
2550 u16 hpi_tuner_get_gain(u32 h_control, short *pn_gain)
2552 u32 gain = 0;
2553 u16 error = 0;
2555 error = hpi_control_param1_get(h_control, HPI_TUNER_GAIN, &gain);
2556 if (pn_gain)
2557 *pn_gain = (u16)gain;
2558 return error;
2561 u16 hpi_tuner_get_rf_level(u32 h_control, short *pw_level)
2563 struct hpi_message hm;
2564 struct hpi_response hr;
2566 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2567 HPI_CONTROL_GET_STATE);
2568 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
2569 return HPI_ERROR_INVALID_HANDLE;
2570 hm.u.cu.attribute = HPI_TUNER_LEVEL_AVG;
2571 hpi_send_recv(&hm, &hr);
2572 if (pw_level)
2573 *pw_level = hr.u.cu.tuner.s_level;
2574 return hr.error;
2577 u16 hpi_tuner_get_raw_rf_level(u32 h_control, short *pw_level)
2579 struct hpi_message hm;
2580 struct hpi_response hr;
2582 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2583 HPI_CONTROL_GET_STATE);
2584 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
2585 return HPI_ERROR_INVALID_HANDLE;
2586 hm.u.cu.attribute = HPI_TUNER_LEVEL_RAW;
2587 hpi_send_recv(&hm, &hr);
2588 if (pw_level)
2589 *pw_level = hr.u.cu.tuner.s_level;
2590 return hr.error;
2593 u16 hpi_tuner_query_deemphasis(const u32 h_tuner, const u32 index,
2594 const u16 band, u32 *pdeemphasis)
2596 return hpi_control_query(h_tuner, HPI_TUNER_DEEMPHASIS, index, band,
2597 pdeemphasis);
2600 u16 hpi_tuner_set_deemphasis(u32 h_control, u32 deemphasis)
2602 return hpi_control_param_set(h_control, HPI_TUNER_DEEMPHASIS,
2603 deemphasis, 0);
2606 u16 hpi_tuner_get_deemphasis(u32 h_control, u32 *pdeemphasis)
2608 return hpi_control_param1_get(h_control, HPI_TUNER_DEEMPHASIS,
2609 pdeemphasis);
2612 u16 hpi_tuner_query_program(const u32 h_tuner, u32 *pbitmap_program)
2614 return hpi_control_query(h_tuner, HPI_TUNER_PROGRAM, 0, 0,
2615 pbitmap_program);
2618 u16 hpi_tuner_set_program(u32 h_control, u32 program)
2620 return hpi_control_param_set(h_control, HPI_TUNER_PROGRAM, program,
2624 u16 hpi_tuner_get_program(u32 h_control, u32 *pprogram)
2626 return hpi_control_param1_get(h_control, HPI_TUNER_PROGRAM, pprogram);
2629 u16 hpi_tuner_get_hd_radio_dsp_version(u32 h_control, char *psz_dsp_version,
2630 const u32 string_size)
2632 return hpi_control_get_string(h_control,
2633 HPI_TUNER_HDRADIO_DSP_VERSION, psz_dsp_version, string_size);
2636 u16 hpi_tuner_get_hd_radio_sdk_version(u32 h_control, char *psz_sdk_version,
2637 const u32 string_size)
2639 return hpi_control_get_string(h_control,
2640 HPI_TUNER_HDRADIO_SDK_VERSION, psz_sdk_version, string_size);
2643 u16 hpi_tuner_get_status(u32 h_control, u16 *pw_status_mask, u16 *pw_status)
2645 u32 status = 0;
2646 u16 error = 0;
2648 error = hpi_control_param1_get(h_control, HPI_TUNER_STATUS, &status);
2649 if (pw_status) {
2650 if (!error) {
2651 *pw_status_mask = (u16)(status >> 16);
2652 *pw_status = (u16)(status & 0xFFFF);
2653 } else {
2654 *pw_status_mask = 0;
2655 *pw_status = 0;
2658 return error;
2661 u16 hpi_tuner_set_mode(u32 h_control, u32 mode, u32 value)
2663 return hpi_control_param_set(h_control, HPI_TUNER_MODE, mode, value);
2666 u16 hpi_tuner_get_mode(u32 h_control, u32 mode, u32 *pn_value)
2668 return hpi_control_param_get(h_control, HPI_TUNER_MODE, mode, 0,
2669 pn_value, NULL);
2672 u16 hpi_tuner_get_hd_radio_signal_quality(u32 h_control, u32 *pquality)
2674 return hpi_control_param1_get(h_control,
2675 HPI_TUNER_HDRADIO_SIGNAL_QUALITY, pquality);
2678 u16 hpi_tuner_get_hd_radio_signal_blend(u32 h_control, u32 *pblend)
2680 return hpi_control_param1_get(h_control, HPI_TUNER_HDRADIO_BLEND,
2681 pblend);
2684 u16 hpi_tuner_set_hd_radio_signal_blend(u32 h_control, const u32 blend)
2686 return hpi_control_param_set(h_control, HPI_TUNER_HDRADIO_BLEND,
2687 blend, 0);
2690 u16 hpi_tuner_get_rds(u32 h_control, char *p_data)
2692 struct hpi_message hm;
2693 struct hpi_response hr;
2695 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2696 HPI_CONTROL_GET_STATE);
2697 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
2698 return HPI_ERROR_INVALID_HANDLE;
2699 hm.u.c.attribute = HPI_TUNER_RDS;
2700 hpi_send_recv(&hm, &hr);
2701 if (p_data) {
2702 *(u32 *)&p_data[0] = hr.u.cu.tuner.rds.data[0];
2703 *(u32 *)&p_data[4] = hr.u.cu.tuner.rds.data[1];
2704 *(u32 *)&p_data[8] = hr.u.cu.tuner.rds.bLER;
2706 return hr.error;
2709 u16 hpi_pad_get_channel_name(u32 h_control, char *psz_string,
2710 const u32 data_length)
2712 return hpi_control_get_string(h_control, HPI_PAD_CHANNEL_NAME,
2713 psz_string, data_length);
2716 u16 hpi_pad_get_artist(u32 h_control, char *psz_string, const u32 data_length)
2718 return hpi_control_get_string(h_control, HPI_PAD_ARTIST, psz_string,
2719 data_length);
2722 u16 hpi_pad_get_title(u32 h_control, char *psz_string, const u32 data_length)
2724 return hpi_control_get_string(h_control, HPI_PAD_TITLE, psz_string,
2725 data_length);
2728 u16 hpi_pad_get_comment(u32 h_control, char *psz_string,
2729 const u32 data_length)
2731 return hpi_control_get_string(h_control, HPI_PAD_COMMENT, psz_string,
2732 data_length);
2735 u16 hpi_pad_get_program_type(u32 h_control, u32 *ppTY)
2737 return hpi_control_param1_get(h_control, HPI_PAD_PROGRAM_TYPE, ppTY);
2740 u16 hpi_pad_get_rdsPI(u32 h_control, u32 *ppI)
2742 return hpi_control_param1_get(h_control, HPI_PAD_PROGRAM_ID, ppI);
2745 u16 hpi_volume_query_channels(const u32 h_volume, u32 *p_channels)
2747 return hpi_control_query(h_volume, HPI_VOLUME_NUM_CHANNELS, 0, 0,
2748 p_channels);
2751 u16 hpi_volume_set_gain(u32 h_control, short an_log_gain[HPI_MAX_CHANNELS]
2754 return hpi_control_log_set2(h_control, HPI_VOLUME_GAIN,
2755 an_log_gain[0], an_log_gain[1]);
2758 u16 hpi_volume_get_gain(u32 h_control, short an_log_gain[HPI_MAX_CHANNELS]
2761 return hpi_control_log_get2(h_control, HPI_VOLUME_GAIN,
2762 &an_log_gain[0], &an_log_gain[1]);
2765 u16 hpi_volume_set_mute(u32 h_control, u32 mute)
2767 return hpi_control_param_set(h_control, HPI_VOLUME_MUTE, mute, 0);
2770 u16 hpi_volume_get_mute(u32 h_control, u32 *mute)
2772 return hpi_control_param1_get(h_control, HPI_VOLUME_MUTE, mute);
2775 u16 hpi_volume_query_range(u32 h_control, short *min_gain_01dB,
2776 short *max_gain_01dB, short *step_gain_01dB)
2778 struct hpi_message hm;
2779 struct hpi_response hr;
2781 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2782 HPI_CONTROL_GET_STATE);
2783 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
2784 return HPI_ERROR_INVALID_HANDLE;
2785 hm.u.c.attribute = HPI_VOLUME_RANGE;
2787 hpi_send_recv(&hm, &hr);
2788 if (hr.error) {
2789 hr.u.c.an_log_value[0] = 0;
2790 hr.u.c.an_log_value[1] = 0;
2791 hr.u.c.param1 = 0;
2793 if (min_gain_01dB)
2794 *min_gain_01dB = hr.u.c.an_log_value[0];
2795 if (max_gain_01dB)
2796 *max_gain_01dB = hr.u.c.an_log_value[1];
2797 if (step_gain_01dB)
2798 *step_gain_01dB = (short)hr.u.c.param1;
2799 return hr.error;
2802 u16 hpi_volume_auto_fade_profile(u32 h_control,
2803 short an_stop_gain0_01dB[HPI_MAX_CHANNELS], u32 duration_ms,
2804 u16 profile)
2806 struct hpi_message hm;
2807 struct hpi_response hr;
2809 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2810 HPI_CONTROL_SET_STATE);
2811 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
2812 return HPI_ERROR_INVALID_HANDLE;
2814 memcpy(hm.u.c.an_log_value, an_stop_gain0_01dB,
2815 sizeof(short) * HPI_MAX_CHANNELS);
2817 hm.u.c.attribute = HPI_VOLUME_AUTOFADE;
2818 hm.u.c.param1 = duration_ms;
2819 hm.u.c.param2 = profile;
2821 hpi_send_recv(&hm, &hr);
2823 return hr.error;
2826 u16 hpi_volume_auto_fade(u32 h_control,
2827 short an_stop_gain0_01dB[HPI_MAX_CHANNELS], u32 duration_ms)
2829 return hpi_volume_auto_fade_profile(h_control, an_stop_gain0_01dB,
2830 duration_ms, HPI_VOLUME_AUTOFADE_LOG);
2833 u16 hpi_vox_set_threshold(u32 h_control, short an_gain0_01dB)
2835 struct hpi_message hm;
2836 struct hpi_response hr;
2837 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2838 HPI_CONTROL_SET_STATE);
2839 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
2840 return HPI_ERROR_INVALID_HANDLE;
2841 hm.u.c.attribute = HPI_VOX_THRESHOLD;
2843 hm.u.c.an_log_value[0] = an_gain0_01dB;
2845 hpi_send_recv(&hm, &hr);
2847 return hr.error;
2850 u16 hpi_vox_get_threshold(u32 h_control, short *an_gain0_01dB)
2852 struct hpi_message hm;
2853 struct hpi_response hr;
2854 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2855 HPI_CONTROL_GET_STATE);
2856 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
2857 return HPI_ERROR_INVALID_HANDLE;
2858 hm.u.c.attribute = HPI_VOX_THRESHOLD;
2860 hpi_send_recv(&hm, &hr);
2862 *an_gain0_01dB = hr.u.c.an_log_value[0];
2864 return hr.error;