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