blob: 53924e4941618110de38e8d4d5a9231ed095e645 [file] [log] [blame]
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001
2#include "hpi_internal.h"
3#include "hpimsginit.h"
4
5#include "hpidebug.h"
6
7struct 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
15union handle_word {
16 struct hpi_handle h;
17 u32 w;
18};
19
20u32 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
Eliot Blennerhassettba944552011-02-10 17:26:04 +130033static 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
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +020048void hpi_handle_to_indexes(const u32 handle, u16 *pw_adapter_index,
49 u16 *pw_object_index)
50{
Eliot Blennerhassettba944552011-02-10 17:26:04 +130051 hpi_handle_indexes(handle, pw_adapter_index, pw_object_index);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +020052}
53
54char 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
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +020061void 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
71static 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
83void 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
Eliot Blennerhassettba944552011-02-10 17:26:04 +130090static inline void hpi_send_recvV1(struct hpi_message_header *m,
91 struct hpi_response_header *r)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +020092{
Eliot Blennerhassettba944552011-02-10 17:26:04 +130093 hpi_send_recv((struct hpi_message *)m, (struct hpi_response *)r);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +020094}
95
Eliot Blennerhassettba944552011-02-10 17:26:04 +130096u16 hpi_subsys_get_version_ex(u32 *pversion_ex)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +020097{
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
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300108u16 hpi_subsys_create_adapter(const struct hpi_resource *p_resource,
109 u16 *pw_adapter_index)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200110{
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
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300124u16 hpi_subsys_delete_adapter(u16 adapter_index)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200125{
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);
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300130 hm.obj_index = adapter_index;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200131 hpi_send_recv(&hm, &hr);
132 return hr.error;
133}
134
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300135u16 hpi_subsys_get_num_adapters(int *pn_num_adapters)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200136{
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
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300146u16 hpi_subsys_get_adapter(int iterator, u32 *padapter_index,
147 u16 *pw_adapter_type)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200148{
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);
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300153 hm.obj_index = (u16)iterator;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200154 hpi_send_recv(&hm, &hr);
155 *padapter_index = (int)hr.u.s.adapter_index;
Eliot Blennerhassett2f918a62011-02-10 17:26:09 +1300156 *pw_adapter_type = hr.u.s.adapter_type;
157
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200158 return hr.error;
159}
160
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300161u16 hpi_adapter_open(u16 adapter_index)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200162{
163 struct hpi_message hm;
164 struct hpi_response hr;
165 hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
166 HPI_ADAPTER_OPEN);
167 hm.adapter_index = adapter_index;
168
169 hpi_send_recv(&hm, &hr);
170
171 return hr.error;
172
173}
174
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300175u16 hpi_adapter_close(u16 adapter_index)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200176{
177 struct hpi_message hm;
178 struct hpi_response hr;
179 hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
180 HPI_ADAPTER_CLOSE);
181 hm.adapter_index = adapter_index;
182
183 hpi_send_recv(&hm, &hr);
184
185 return hr.error;
186}
187
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300188u16 hpi_adapter_set_mode(u16 adapter_index, u32 adapter_mode)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200189{
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300190 return hpi_adapter_set_mode_ex(adapter_index, adapter_mode,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200191 HPI_ADAPTER_MODE_SET);
192}
193
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300194u16 hpi_adapter_set_mode_ex(u16 adapter_index, u32 adapter_mode,
195 u16 query_or_set)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200196{
197 struct hpi_message hm;
198 struct hpi_response hr;
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +1200199
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200200 hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
201 HPI_ADAPTER_SET_MODE);
202 hm.adapter_index = adapter_index;
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300203 hm.u.ax.mode.adapter_mode = adapter_mode;
204 hm.u.ax.mode.query_or_set = query_or_set;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200205 hpi_send_recv(&hm, &hr);
206 return hr.error;
207}
208
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300209u16 hpi_adapter_get_mode(u16 adapter_index, u32 *padapter_mode)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200210{
211 struct hpi_message hm;
212 struct hpi_response hr;
213 hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
214 HPI_ADAPTER_GET_MODE);
215 hm.adapter_index = adapter_index;
216 hpi_send_recv(&hm, &hr);
217 if (padapter_mode)
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300218 *padapter_mode = hr.u.ax.mode.adapter_mode;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200219 return hr.error;
220}
221
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300222u16 hpi_adapter_get_info(u16 adapter_index, u16 *pw_num_outstreams,
223 u16 *pw_num_instreams, u16 *pw_version, u32 *pserial_number,
224 u16 *pw_adapter_type)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200225{
226 struct hpi_message hm;
227 struct hpi_response hr;
228 hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
229 HPI_ADAPTER_GET_INFO);
230 hm.adapter_index = adapter_index;
231
232 hpi_send_recv(&hm, &hr);
233
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300234 *pw_adapter_type = hr.u.ax.info.adapter_type;
235 *pw_num_outstreams = hr.u.ax.info.num_outstreams;
236 *pw_num_instreams = hr.u.ax.info.num_instreams;
237 *pw_version = hr.u.ax.info.version;
238 *pserial_number = hr.u.ax.info.serial_number;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200239 return hr.error;
240}
241
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300242u16 hpi_adapter_get_module_by_index(u16 adapter_index, u16 module_index,
243 u16 *pw_num_outputs, u16 *pw_num_inputs, u16 *pw_version,
244 u32 *pserial_number, u16 *pw_module_type, u32 *ph_module)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200245{
246 struct hpi_message hm;
247 struct hpi_response hr;
248
249 hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
250 HPI_ADAPTER_MODULE_INFO);
251 hm.adapter_index = adapter_index;
252 hm.u.ax.module_info.index = module_index;
253
254 hpi_send_recv(&hm, &hr);
255
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300256 *pw_module_type = hr.u.ax.info.adapter_type;
257 *pw_num_outputs = hr.u.ax.info.num_outstreams;
258 *pw_num_inputs = hr.u.ax.info.num_instreams;
259 *pw_version = hr.u.ax.info.version;
260 *pserial_number = hr.u.ax.info.serial_number;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200261 *ph_module = 0;
262
263 return hr.error;
264}
265
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300266u16 hpi_adapter_get_assert2(u16 adapter_index, u16 *p_assert_count,
267 char *psz_assert, u32 *p_param1, u32 *p_param2,
268 u32 *p_dsp_string_addr, u16 *p_processor_id)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200269{
270 struct hpi_message hm;
271 struct hpi_response hr;
272 hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
273 HPI_ADAPTER_GET_ASSERT);
274 hm.adapter_index = adapter_index;
275
276 hpi_send_recv(&hm, &hr);
277
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300278 *p_assert_count = 0;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200279
280 if (!hr.error) {
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300281 *p_assert_count = hr.u.ax.assert.count;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200282
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300283 if (*p_assert_count) {
284 *p_param1 = hr.u.ax.assert.p1;
285 *p_param2 = hr.u.ax.assert.p2;
286 *p_processor_id = hr.u.ax.assert.dsp_index;
287 *p_dsp_string_addr = hr.u.ax.assert.dsp_msg_addr;
288 memcpy(psz_assert, hr.u.ax.assert.sz_message,
289 HPI_STRING_LEN);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200290 } else {
291 *psz_assert = 0;
292 }
293 }
294 return hr.error;
295}
296
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300297u16 hpi_adapter_test_assert(u16 adapter_index, u16 assert_id)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200298{
299 struct hpi_message hm;
300 struct hpi_response hr;
301 hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
302 HPI_ADAPTER_TEST_ASSERT);
303 hm.adapter_index = adapter_index;
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300304 hm.u.ax.test_assert.value = assert_id;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200305
306 hpi_send_recv(&hm, &hr);
307
308 return hr.error;
309}
310
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300311u16 hpi_adapter_enable_capability(u16 adapter_index, u16 capability, u32 key)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200312{
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300313#if 1
314 return HPI_ERROR_UNIMPLEMENTED;
315#else
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200316 struct hpi_message hm;
317 struct hpi_response hr;
318 hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
319 HPI_ADAPTER_ENABLE_CAPABILITY);
320 hm.adapter_index = adapter_index;
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300321 hm.u.ax.enable_cap.cap = capability;
322 hm.u.ax.enable_cap.key = key;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200323
324 hpi_send_recv(&hm, &hr);
325
326 return hr.error;
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300327#endif
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200328}
329
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300330u16 hpi_adapter_self_test(u16 adapter_index)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200331{
332 struct hpi_message hm;
333 struct hpi_response hr;
334 hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
335 HPI_ADAPTER_SELFTEST);
336 hm.adapter_index = adapter_index;
337 hpi_send_recv(&hm, &hr);
338 return hr.error;
339}
340
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300341u16 hpi_adapter_debug_read(u16 adapter_index, u32 dsp_address, char *p_buffer,
342 int *count_bytes)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200343{
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300344 struct hpi_msg_adapter_debug_read hm;
345 struct hpi_res_adapter_debug_read hr;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200346
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300347 hpi_init_message_responseV1(&hm.h, sizeof(hm), &hr.h, sizeof(hr),
348 HPI_OBJ_ADAPTER, HPI_ADAPTER_DEBUG_READ);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200349
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300350 hm.h.adapter_index = adapter_index;
351 hm.dsp_address = dsp_address;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200352
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300353 if (*count_bytes > (int)sizeof(hr.bytes))
354 *count_bytes = (int)sizeof(hr.bytes);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200355
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300356 hm.count_bytes = *count_bytes;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200357
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300358 hpi_send_recvV1(&hm.h, &hr.h);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200359
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300360 if (!hr.h.error) {
361 int res_bytes = hr.h.size - sizeof(hr.h);
362 if (res_bytes > *count_bytes)
363 res_bytes = *count_bytes;
364 *count_bytes = res_bytes;
365 memcpy(p_buffer, &hr.bytes, res_bytes);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200366 } else
367 *count_bytes = 0;
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300368
369 return hr.h.error;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200370}
371
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300372u16 hpi_adapter_set_property(u16 adapter_index, u16 property, u16 parameter1,
373 u16 parameter2)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200374{
375 struct hpi_message hm;
376 struct hpi_response hr;
377 hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
378 HPI_ADAPTER_SET_PROPERTY);
379 hm.adapter_index = adapter_index;
380 hm.u.ax.property_set.property = property;
381 hm.u.ax.property_set.parameter1 = parameter1;
382 hm.u.ax.property_set.parameter2 = parameter2;
383
384 hpi_send_recv(&hm, &hr);
385
386 return hr.error;
387}
388
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300389u16 hpi_adapter_get_property(u16 adapter_index, u16 property,
390 u16 *pw_parameter1, u16 *pw_parameter2)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200391{
392 struct hpi_message hm;
393 struct hpi_response hr;
394 hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
395 HPI_ADAPTER_GET_PROPERTY);
396 hm.adapter_index = adapter_index;
397 hm.u.ax.property_set.property = property;
398
399 hpi_send_recv(&hm, &hr);
400 if (!hr.error) {
401 if (pw_parameter1)
402 *pw_parameter1 = hr.u.ax.property_get.parameter1;
403 if (pw_parameter2)
404 *pw_parameter2 = hr.u.ax.property_get.parameter2;
405 }
406
407 return hr.error;
408}
409
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300410u16 hpi_adapter_enumerate_property(u16 adapter_index, u16 index,
411 u16 what_to_enumerate, u16 property_index, u32 *psetting)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200412{
413 return 0;
414}
415
416u16 hpi_format_create(struct hpi_format *p_format, u16 channels, u16 format,
417 u32 sample_rate, u32 bit_rate, u32 attributes)
418{
419 u16 error = 0;
420 struct hpi_msg_format fmt;
421
422 switch (channels) {
423 case 1:
424 case 2:
425 case 4:
426 case 6:
427 case 8:
428 case 16:
429 break;
430 default:
431 error = HPI_ERROR_INVALID_CHANNELS;
432 return error;
433 }
434 fmt.channels = channels;
435
436 switch (format) {
437 case HPI_FORMAT_PCM16_SIGNED:
438 case HPI_FORMAT_PCM24_SIGNED:
439 case HPI_FORMAT_PCM32_SIGNED:
440 case HPI_FORMAT_PCM32_FLOAT:
441 case HPI_FORMAT_PCM16_BIGENDIAN:
442 case HPI_FORMAT_PCM8_UNSIGNED:
443 case HPI_FORMAT_MPEG_L1:
444 case HPI_FORMAT_MPEG_L2:
445 case HPI_FORMAT_MPEG_L3:
446 case HPI_FORMAT_DOLBY_AC2:
447 case HPI_FORMAT_AA_TAGIT1_HITS:
448 case HPI_FORMAT_AA_TAGIT1_INSERTS:
449 case HPI_FORMAT_RAW_BITSTREAM:
450 case HPI_FORMAT_AA_TAGIT1_HITS_EX1:
451 case HPI_FORMAT_OEM1:
452 case HPI_FORMAT_OEM2:
453 break;
454 default:
455 error = HPI_ERROR_INVALID_FORMAT;
456 return error;
457 }
458 fmt.format = format;
459
460 if (sample_rate < 8000L) {
461 error = HPI_ERROR_INCOMPATIBLE_SAMPLERATE;
462 sample_rate = 8000L;
463 }
464 if (sample_rate > 200000L) {
465 error = HPI_ERROR_INCOMPATIBLE_SAMPLERATE;
466 sample_rate = 200000L;
467 }
468 fmt.sample_rate = sample_rate;
469
470 switch (format) {
471 case HPI_FORMAT_MPEG_L1:
472 case HPI_FORMAT_MPEG_L2:
473 case HPI_FORMAT_MPEG_L3:
474 fmt.bit_rate = bit_rate;
475 break;
476 case HPI_FORMAT_PCM16_SIGNED:
477 case HPI_FORMAT_PCM16_BIGENDIAN:
478 fmt.bit_rate = channels * sample_rate * 2;
479 break;
480 case HPI_FORMAT_PCM32_SIGNED:
481 case HPI_FORMAT_PCM32_FLOAT:
482 fmt.bit_rate = channels * sample_rate * 4;
483 break;
484 case HPI_FORMAT_PCM8_UNSIGNED:
485 fmt.bit_rate = channels * sample_rate;
486 break;
487 default:
488 fmt.bit_rate = 0;
489 }
490
491 switch (format) {
492 case HPI_FORMAT_MPEG_L2:
493 if ((channels == 1)
494 && (attributes != HPI_MPEG_MODE_DEFAULT)) {
495 attributes = HPI_MPEG_MODE_DEFAULT;
496 error = HPI_ERROR_INVALID_FORMAT;
497 } else if (attributes > HPI_MPEG_MODE_DUALCHANNEL) {
498 attributes = HPI_MPEG_MODE_DEFAULT;
499 error = HPI_ERROR_INVALID_FORMAT;
500 }
501 fmt.attributes = attributes;
502 break;
503 default:
504 fmt.attributes = attributes;
505 }
506
507 hpi_msg_to_format(p_format, &fmt);
508 return error;
509}
510
511u16 hpi_stream_estimate_buffer_size(struct hpi_format *p_format,
512 u32 host_polling_rate_in_milli_seconds, u32 *recommended_buffer_size)
513{
514
515 u32 bytes_per_second;
516 u32 size;
517 u16 channels;
518 struct hpi_format *pF = p_format;
519
520 channels = pF->channels;
521
522 switch (pF->format) {
523 case HPI_FORMAT_PCM16_BIGENDIAN:
524 case HPI_FORMAT_PCM16_SIGNED:
525 bytes_per_second = pF->sample_rate * 2L * channels;
526 break;
527 case HPI_FORMAT_PCM24_SIGNED:
528 bytes_per_second = pF->sample_rate * 3L * channels;
529 break;
530 case HPI_FORMAT_PCM32_SIGNED:
531 case HPI_FORMAT_PCM32_FLOAT:
532 bytes_per_second = pF->sample_rate * 4L * channels;
533 break;
534 case HPI_FORMAT_PCM8_UNSIGNED:
535 bytes_per_second = pF->sample_rate * 1L * channels;
536 break;
537 case HPI_FORMAT_MPEG_L1:
538 case HPI_FORMAT_MPEG_L2:
539 case HPI_FORMAT_MPEG_L3:
540 bytes_per_second = pF->bit_rate / 8L;
541 break;
542 case HPI_FORMAT_DOLBY_AC2:
543
544 bytes_per_second = 256000L / 8L;
545 break;
546 default:
547 return HPI_ERROR_INVALID_FORMAT;
548 }
549 size = (bytes_per_second * host_polling_rate_in_milli_seconds * 2) /
550 1000L;
551
552 *recommended_buffer_size =
553 roundup_pow_of_two(((size + 4095L) & ~4095L));
554 return 0;
555}
556
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300557u16 hpi_outstream_open(u16 adapter_index, u16 outstream_index,
558 u32 *ph_outstream)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200559{
560 struct hpi_message hm;
561 struct hpi_response hr;
562 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
563 HPI_OSTREAM_OPEN);
564 hm.adapter_index = adapter_index;
565 hm.obj_index = outstream_index;
566
567 hpi_send_recv(&hm, &hr);
568
569 if (hr.error == 0)
570 *ph_outstream =
571 hpi_indexes_to_handle(HPI_OBJ_OSTREAM, adapter_index,
572 outstream_index);
573 else
574 *ph_outstream = 0;
575 return hr.error;
576}
577
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300578u16 hpi_outstream_close(u32 h_outstream)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200579{
580 struct hpi_message hm;
581 struct hpi_response hr;
582
583 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
584 HPI_OSTREAM_HOSTBUFFER_FREE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300585 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
586 return HPI_ERROR_INVALID_HANDLE;
587
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200588 hpi_send_recv(&hm, &hr);
589
590 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
591 HPI_OSTREAM_GROUP_RESET);
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300592 hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200593 hpi_send_recv(&hm, &hr);
594
595 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
596 HPI_OSTREAM_CLOSE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300597 hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200598 hpi_send_recv(&hm, &hr);
599
600 return hr.error;
601}
602
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300603u16 hpi_outstream_get_info_ex(u32 h_outstream, u16 *pw_state,
604 u32 *pbuffer_size, u32 *pdata_to_play, u32 *psamples_played,
605 u32 *pauxiliary_data_to_play)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200606{
607 struct hpi_message hm;
608 struct hpi_response hr;
609 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
610 HPI_OSTREAM_GET_INFO);
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300611 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
612 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200613
614 hpi_send_recv(&hm, &hr);
615
616 if (pw_state)
617 *pw_state = hr.u.d.u.stream_info.state;
618 if (pbuffer_size)
619 *pbuffer_size = hr.u.d.u.stream_info.buffer_size;
620 if (pdata_to_play)
621 *pdata_to_play = hr.u.d.u.stream_info.data_available;
622 if (psamples_played)
623 *psamples_played = hr.u.d.u.stream_info.samples_transferred;
624 if (pauxiliary_data_to_play)
625 *pauxiliary_data_to_play =
626 hr.u.d.u.stream_info.auxiliary_data_available;
627 return hr.error;
628}
629
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300630u16 hpi_outstream_write_buf(u32 h_outstream, const u8 *pb_data,
631 u32 bytes_to_write, const struct hpi_format *p_format)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200632{
633 struct hpi_message hm;
634 struct hpi_response hr;
635 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
636 HPI_OSTREAM_WRITE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300637 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
638 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200639 hm.u.d.u.data.pb_data = (u8 *)pb_data;
640 hm.u.d.u.data.data_size = bytes_to_write;
641
642 hpi_format_to_msg(&hm.u.d.u.data.format, p_format);
643
644 hpi_send_recv(&hm, &hr);
645
646 return hr.error;
647}
648
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300649u16 hpi_outstream_start(u32 h_outstream)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200650{
651 struct hpi_message hm;
652 struct hpi_response hr;
653 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
654 HPI_OSTREAM_START);
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300655 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
656 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200657
658 hpi_send_recv(&hm, &hr);
659
660 return hr.error;
661}
662
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300663u16 hpi_outstream_wait_start(u32 h_outstream)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200664{
665 struct hpi_message hm;
666 struct hpi_response hr;
667 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
668 HPI_OSTREAM_WAIT_START);
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300669 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
670 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200671
672 hpi_send_recv(&hm, &hr);
673
674 return hr.error;
675}
676
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300677u16 hpi_outstream_stop(u32 h_outstream)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200678{
679 struct hpi_message hm;
680 struct hpi_response hr;
681 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
682 HPI_OSTREAM_STOP);
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300683 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
684 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200685
686 hpi_send_recv(&hm, &hr);
687
688 return hr.error;
689}
690
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300691u16 hpi_outstream_sinegen(u32 h_outstream)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200692{
693 struct hpi_message hm;
694 struct hpi_response hr;
695 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
696 HPI_OSTREAM_SINEGEN);
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300697 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
698 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200699
700 hpi_send_recv(&hm, &hr);
701
702 return hr.error;
703}
704
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300705u16 hpi_outstream_reset(u32 h_outstream)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200706{
707 struct hpi_message hm;
708 struct hpi_response hr;
709 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
710 HPI_OSTREAM_RESET);
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300711 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
712 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200713
714 hpi_send_recv(&hm, &hr);
715
716 return hr.error;
717}
718
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300719u16 hpi_outstream_query_format(u32 h_outstream, struct hpi_format *p_format)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200720{
721 struct hpi_message hm;
722 struct hpi_response hr;
723
724 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
725 HPI_OSTREAM_QUERY_FORMAT);
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300726 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
727 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200728
729 hpi_format_to_msg(&hm.u.d.u.data.format, p_format);
730
731 hpi_send_recv(&hm, &hr);
732
733 return hr.error;
734}
735
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300736u16 hpi_outstream_set_format(u32 h_outstream, struct hpi_format *p_format)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200737{
738 struct hpi_message hm;
739 struct hpi_response hr;
740
741 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
742 HPI_OSTREAM_SET_FORMAT);
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300743 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
744 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200745
746 hpi_format_to_msg(&hm.u.d.u.data.format, p_format);
747
748 hpi_send_recv(&hm, &hr);
749
750 return hr.error;
751}
752
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300753u16 hpi_outstream_set_velocity(u32 h_outstream, short velocity)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200754{
755 struct hpi_message hm;
756 struct hpi_response hr;
757
758 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
759 HPI_OSTREAM_SET_VELOCITY);
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300760 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
761 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200762 hm.u.d.u.velocity = velocity;
763
764 hpi_send_recv(&hm, &hr);
765
766 return hr.error;
767}
768
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300769u16 hpi_outstream_set_punch_in_out(u32 h_outstream, u32 punch_in_sample,
770 u32 punch_out_sample)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200771{
772 struct hpi_message hm;
773 struct hpi_response hr;
774
775 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
776 HPI_OSTREAM_SET_PUNCHINOUT);
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300777 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
778 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200779
780 hm.u.d.u.pio.punch_in_sample = punch_in_sample;
781 hm.u.d.u.pio.punch_out_sample = punch_out_sample;
782
783 hpi_send_recv(&hm, &hr);
784
785 return hr.error;
786}
787
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300788u16 hpi_outstream_ancillary_reset(u32 h_outstream, u16 mode)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200789{
790 struct hpi_message hm;
791 struct hpi_response hr;
792
793 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
794 HPI_OSTREAM_ANC_RESET);
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300795 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
796 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200797 hm.u.d.u.data.format.channels = mode;
798 hpi_send_recv(&hm, &hr);
799 return hr.error;
800}
801
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300802u16 hpi_outstream_ancillary_get_info(u32 h_outstream, u32 *pframes_available)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200803{
804 struct hpi_message hm;
805 struct hpi_response hr;
806
807 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
808 HPI_OSTREAM_ANC_GET_INFO);
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300809 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
810 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200811 hpi_send_recv(&hm, &hr);
812 if (hr.error == 0) {
813 if (pframes_available)
814 *pframes_available =
815 hr.u.d.u.stream_info.data_available /
816 sizeof(struct hpi_anc_frame);
817 }
818 return hr.error;
819}
820
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300821u16 hpi_outstream_ancillary_read(u32 h_outstream,
822 struct hpi_anc_frame *p_anc_frame_buffer,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200823 u32 anc_frame_buffer_size_in_bytes,
824 u32 number_of_ancillary_frames_to_read)
825{
826 struct hpi_message hm;
827 struct hpi_response hr;
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +1200828
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200829 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
830 HPI_OSTREAM_ANC_READ);
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300831 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
832 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200833 hm.u.d.u.data.pb_data = (u8 *)p_anc_frame_buffer;
834 hm.u.d.u.data.data_size =
835 number_of_ancillary_frames_to_read *
836 sizeof(struct hpi_anc_frame);
837 if (hm.u.d.u.data.data_size <= anc_frame_buffer_size_in_bytes)
838 hpi_send_recv(&hm, &hr);
839 else
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300840 hr.error = HPI_ERROR_INVALID_DATASIZE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200841 return hr.error;
842}
843
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300844u16 hpi_outstream_set_time_scale(u32 h_outstream, u32 time_scale)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200845{
846 struct hpi_message hm;
847 struct hpi_response hr;
848
849 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
850 HPI_OSTREAM_SET_TIMESCALE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300851 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
852 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200853
854 hm.u.d.u.time_scale = time_scale;
855
856 hpi_send_recv(&hm, &hr);
857
858 return hr.error;
859}
860
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300861u16 hpi_outstream_host_buffer_allocate(u32 h_outstream, u32 size_in_bytes)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200862{
863 struct hpi_message hm;
864 struct hpi_response hr;
865
866 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
867 HPI_OSTREAM_HOSTBUFFER_ALLOC);
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300868 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
869 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200870 hm.u.d.u.data.data_size = size_in_bytes;
871 hpi_send_recv(&hm, &hr);
872 return hr.error;
873}
874
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300875u16 hpi_outstream_host_buffer_get_info(u32 h_outstream, u8 **pp_buffer,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200876 struct hpi_hostbuffer_status **pp_status)
877{
878 struct hpi_message hm;
879 struct hpi_response hr;
880
881 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
882 HPI_OSTREAM_HOSTBUFFER_GET_INFO);
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300883 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
884 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200885 hpi_send_recv(&hm, &hr);
886
887 if (hr.error == 0) {
888 if (pp_buffer)
889 *pp_buffer = hr.u.d.u.hostbuffer_info.p_buffer;
890 if (pp_status)
891 *pp_status = hr.u.d.u.hostbuffer_info.p_status;
892 }
893 return hr.error;
894}
895
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300896u16 hpi_outstream_host_buffer_free(u32 h_outstream)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200897{
898 struct hpi_message hm;
899 struct hpi_response hr;
900
901 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
902 HPI_OSTREAM_HOSTBUFFER_FREE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300903 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
904 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200905 hpi_send_recv(&hm, &hr);
906 return hr.error;
907}
908
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300909u16 hpi_outstream_group_add(u32 h_outstream, u32 h_stream)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200910{
911 struct hpi_message hm;
912 struct hpi_response hr;
913 u16 adapter;
914 char c_obj_type;
915
916 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
917 HPI_OSTREAM_GROUP_ADD);
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300918
919 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
920 return HPI_ERROR_INVALID_HANDLE;
921
922 if (hpi_handle_indexes(h_stream, &adapter,
923 &hm.u.d.u.stream.stream_index))
924 return HPI_ERROR_INVALID_HANDLE;
925
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200926 c_obj_type = hpi_handle_object(h_stream);
927 switch (c_obj_type) {
928 case HPI_OBJ_OSTREAM:
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200929 case HPI_OBJ_ISTREAM:
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300930 hm.u.d.u.stream.object_type = c_obj_type;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200931 break;
932 default:
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300933 return HPI_ERROR_INVALID_OBJ;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200934 }
935 if (adapter != hm.adapter_index)
936 return HPI_ERROR_NO_INTERADAPTER_GROUPS;
937
938 hpi_send_recv(&hm, &hr);
939 return hr.error;
940}
941
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300942u16 hpi_outstream_group_get_map(u32 h_outstream, u32 *poutstream_map,
943 u32 *pinstream_map)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200944{
945 struct hpi_message hm;
946 struct hpi_response hr;
947
948 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
949 HPI_OSTREAM_GROUP_GETMAP);
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300950 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
951 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200952 hpi_send_recv(&hm, &hr);
953
954 if (poutstream_map)
955 *poutstream_map = hr.u.d.u.group_info.outstream_group_map;
956 if (pinstream_map)
957 *pinstream_map = hr.u.d.u.group_info.instream_group_map;
958
959 return hr.error;
960}
961
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300962u16 hpi_outstream_group_reset(u32 h_outstream)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200963{
964 struct hpi_message hm;
965 struct hpi_response hr;
966
967 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
968 HPI_OSTREAM_GROUP_RESET);
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300969 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
970 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200971 hpi_send_recv(&hm, &hr);
972 return hr.error;
973}
974
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300975u16 hpi_instream_open(u16 adapter_index, u16 instream_index, u32 *ph_instream)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200976{
977 struct hpi_message hm;
978 struct hpi_response hr;
979
980 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
981 HPI_ISTREAM_OPEN);
982 hm.adapter_index = adapter_index;
983 hm.obj_index = instream_index;
984
985 hpi_send_recv(&hm, &hr);
986
987 if (hr.error == 0)
988 *ph_instream =
989 hpi_indexes_to_handle(HPI_OBJ_ISTREAM, adapter_index,
990 instream_index);
991 else
992 *ph_instream = 0;
993
994 return hr.error;
995}
996
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300997u16 hpi_instream_close(u32 h_instream)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200998{
999 struct hpi_message hm;
1000 struct hpi_response hr;
1001
1002 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1003 HPI_ISTREAM_HOSTBUFFER_FREE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001004 if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
1005 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001006 hpi_send_recv(&hm, &hr);
1007
1008 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1009 HPI_ISTREAM_GROUP_RESET);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001010 hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001011 hpi_send_recv(&hm, &hr);
1012
1013 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1014 HPI_ISTREAM_CLOSE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001015 hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001016 hpi_send_recv(&hm, &hr);
1017
1018 return hr.error;
1019}
1020
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001021u16 hpi_instream_query_format(u32 h_instream,
1022 const struct hpi_format *p_format)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001023{
1024 struct hpi_message hm;
1025 struct hpi_response hr;
1026
1027 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1028 HPI_ISTREAM_QUERY_FORMAT);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001029 if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
1030 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001031 hpi_format_to_msg(&hm.u.d.u.data.format, p_format);
1032
1033 hpi_send_recv(&hm, &hr);
1034
1035 return hr.error;
1036}
1037
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001038u16 hpi_instream_set_format(u32 h_instream, const struct hpi_format *p_format)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001039{
1040 struct hpi_message hm;
1041 struct hpi_response hr;
1042
1043 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1044 HPI_ISTREAM_SET_FORMAT);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001045 if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
1046 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001047 hpi_format_to_msg(&hm.u.d.u.data.format, p_format);
1048
1049 hpi_send_recv(&hm, &hr);
1050
1051 return hr.error;
1052}
1053
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001054u16 hpi_instream_read_buf(u32 h_instream, u8 *pb_data, u32 bytes_to_read)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001055{
1056 struct hpi_message hm;
1057 struct hpi_response hr;
1058
1059 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1060 HPI_ISTREAM_READ);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001061 if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
1062 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001063 hm.u.d.u.data.data_size = bytes_to_read;
1064 hm.u.d.u.data.pb_data = pb_data;
1065
1066 hpi_send_recv(&hm, &hr);
1067
1068 return hr.error;
1069}
1070
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001071u16 hpi_instream_start(u32 h_instream)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001072{
1073 struct hpi_message hm;
1074 struct hpi_response hr;
1075
1076 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1077 HPI_ISTREAM_START);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001078 if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
1079 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001080
1081 hpi_send_recv(&hm, &hr);
1082
1083 return hr.error;
1084}
1085
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001086u16 hpi_instream_wait_start(u32 h_instream)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001087{
1088 struct hpi_message hm;
1089 struct hpi_response hr;
1090
1091 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1092 HPI_ISTREAM_WAIT_START);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001093 if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
1094 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001095
1096 hpi_send_recv(&hm, &hr);
1097
1098 return hr.error;
1099}
1100
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001101u16 hpi_instream_stop(u32 h_instream)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001102{
1103 struct hpi_message hm;
1104 struct hpi_response hr;
1105
1106 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1107 HPI_ISTREAM_STOP);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001108 if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
1109 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001110
1111 hpi_send_recv(&hm, &hr);
1112
1113 return hr.error;
1114}
1115
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001116u16 hpi_instream_reset(u32 h_instream)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001117{
1118 struct hpi_message hm;
1119 struct hpi_response hr;
1120
1121 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1122 HPI_ISTREAM_RESET);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001123 if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
1124 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001125
1126 hpi_send_recv(&hm, &hr);
1127
1128 return hr.error;
1129}
1130
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001131u16 hpi_instream_get_info_ex(u32 h_instream, u16 *pw_state, u32 *pbuffer_size,
1132 u32 *pdata_recorded, u32 *psamples_recorded,
1133 u32 *pauxiliary_data_recorded)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001134{
1135 struct hpi_message hm;
1136 struct hpi_response hr;
1137 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1138 HPI_ISTREAM_GET_INFO);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001139 if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
1140 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001141
1142 hpi_send_recv(&hm, &hr);
1143
1144 if (pw_state)
1145 *pw_state = hr.u.d.u.stream_info.state;
1146 if (pbuffer_size)
1147 *pbuffer_size = hr.u.d.u.stream_info.buffer_size;
1148 if (pdata_recorded)
1149 *pdata_recorded = hr.u.d.u.stream_info.data_available;
1150 if (psamples_recorded)
1151 *psamples_recorded = hr.u.d.u.stream_info.samples_transferred;
1152 if (pauxiliary_data_recorded)
1153 *pauxiliary_data_recorded =
1154 hr.u.d.u.stream_info.auxiliary_data_available;
1155 return hr.error;
1156}
1157
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001158u16 hpi_instream_ancillary_reset(u32 h_instream, u16 bytes_per_frame,
1159 u16 mode, u16 alignment, u16 idle_bit)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001160{
1161 struct hpi_message hm;
1162 struct hpi_response hr;
1163 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1164 HPI_ISTREAM_ANC_RESET);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001165 if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
1166 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001167 hm.u.d.u.data.format.attributes = bytes_per_frame;
1168 hm.u.d.u.data.format.format = (mode << 8) | (alignment & 0xff);
1169 hm.u.d.u.data.format.channels = idle_bit;
1170 hpi_send_recv(&hm, &hr);
1171 return hr.error;
1172}
1173
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001174u16 hpi_instream_ancillary_get_info(u32 h_instream, u32 *pframe_space)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001175{
1176 struct hpi_message hm;
1177 struct hpi_response hr;
1178 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1179 HPI_ISTREAM_ANC_GET_INFO);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001180 if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
1181 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001182 hpi_send_recv(&hm, &hr);
1183 if (pframe_space)
1184 *pframe_space =
1185 (hr.u.d.u.stream_info.buffer_size -
1186 hr.u.d.u.stream_info.data_available) /
1187 sizeof(struct hpi_anc_frame);
1188 return hr.error;
1189}
1190
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001191u16 hpi_instream_ancillary_write(u32 h_instream,
1192 const struct hpi_anc_frame *p_anc_frame_buffer,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001193 u32 anc_frame_buffer_size_in_bytes,
1194 u32 number_of_ancillary_frames_to_write)
1195{
1196 struct hpi_message hm;
1197 struct hpi_response hr;
1198
1199 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1200 HPI_ISTREAM_ANC_WRITE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001201 if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
1202 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001203 hm.u.d.u.data.pb_data = (u8 *)p_anc_frame_buffer;
1204 hm.u.d.u.data.data_size =
1205 number_of_ancillary_frames_to_write *
1206 sizeof(struct hpi_anc_frame);
1207 if (hm.u.d.u.data.data_size <= anc_frame_buffer_size_in_bytes)
1208 hpi_send_recv(&hm, &hr);
1209 else
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001210 hr.error = HPI_ERROR_INVALID_DATASIZE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001211 return hr.error;
1212}
1213
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001214u16 hpi_instream_host_buffer_allocate(u32 h_instream, u32 size_in_bytes)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001215{
1216
1217 struct hpi_message hm;
1218 struct hpi_response hr;
1219
1220 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1221 HPI_ISTREAM_HOSTBUFFER_ALLOC);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001222 if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
1223 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001224 hm.u.d.u.data.data_size = size_in_bytes;
1225 hpi_send_recv(&hm, &hr);
1226 return hr.error;
1227}
1228
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001229u16 hpi_instream_host_buffer_get_info(u32 h_instream, u8 **pp_buffer,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001230 struct hpi_hostbuffer_status **pp_status)
1231{
1232 struct hpi_message hm;
1233 struct hpi_response hr;
1234
1235 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1236 HPI_ISTREAM_HOSTBUFFER_GET_INFO);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001237 if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
1238 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001239 hpi_send_recv(&hm, &hr);
1240
1241 if (hr.error == 0) {
1242 if (pp_buffer)
1243 *pp_buffer = hr.u.d.u.hostbuffer_info.p_buffer;
1244 if (pp_status)
1245 *pp_status = hr.u.d.u.hostbuffer_info.p_status;
1246 }
1247 return hr.error;
1248}
1249
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001250u16 hpi_instream_host_buffer_free(u32 h_instream)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001251{
1252
1253 struct hpi_message hm;
1254 struct hpi_response hr;
1255
1256 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1257 HPI_ISTREAM_HOSTBUFFER_FREE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001258 if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
1259 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001260 hpi_send_recv(&hm, &hr);
1261 return hr.error;
1262}
1263
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001264u16 hpi_instream_group_add(u32 h_instream, u32 h_stream)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001265{
1266 struct hpi_message hm;
1267 struct hpi_response hr;
1268 u16 adapter;
1269 char c_obj_type;
1270
1271 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1272 HPI_ISTREAM_GROUP_ADD);
1273 hr.error = 0;
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001274
1275 if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
1276 return HPI_ERROR_INVALID_HANDLE;
1277
1278 if (hpi_handle_indexes(h_stream, &adapter,
1279 &hm.u.d.u.stream.stream_index))
1280 return HPI_ERROR_INVALID_HANDLE;
1281
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001282 c_obj_type = hpi_handle_object(h_stream);
1283
1284 switch (c_obj_type) {
1285 case HPI_OBJ_OSTREAM:
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001286 case HPI_OBJ_ISTREAM:
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001287 hm.u.d.u.stream.object_type = c_obj_type;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001288 break;
1289 default:
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001290 return HPI_ERROR_INVALID_OBJ;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001291 }
1292
1293 if (adapter != hm.adapter_index)
1294 return HPI_ERROR_NO_INTERADAPTER_GROUPS;
1295
1296 hpi_send_recv(&hm, &hr);
1297 return hr.error;
1298}
1299
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001300u16 hpi_instream_group_get_map(u32 h_instream, u32 *poutstream_map,
1301 u32 *pinstream_map)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001302{
1303 struct hpi_message hm;
1304 struct hpi_response hr;
1305
1306 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1307 HPI_ISTREAM_HOSTBUFFER_FREE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001308 if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
1309 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001310 hpi_send_recv(&hm, &hr);
1311
1312 if (poutstream_map)
1313 *poutstream_map = hr.u.d.u.group_info.outstream_group_map;
1314 if (pinstream_map)
1315 *pinstream_map = hr.u.d.u.group_info.instream_group_map;
1316
1317 return hr.error;
1318}
1319
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001320u16 hpi_instream_group_reset(u32 h_instream)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001321{
1322 struct hpi_message hm;
1323 struct hpi_response hr;
1324
1325 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1326 HPI_ISTREAM_GROUP_RESET);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001327 if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
1328 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001329 hpi_send_recv(&hm, &hr);
1330 return hr.error;
1331}
1332
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001333u16 hpi_mixer_open(u16 adapter_index, u32 *ph_mixer)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001334{
1335 struct hpi_message hm;
1336 struct hpi_response hr;
1337 hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER, HPI_MIXER_OPEN);
1338 hm.adapter_index = adapter_index;
1339
1340 hpi_send_recv(&hm, &hr);
1341
1342 if (hr.error == 0)
1343 *ph_mixer =
1344 hpi_indexes_to_handle(HPI_OBJ_MIXER, adapter_index,
1345 0);
1346 else
1347 *ph_mixer = 0;
1348 return hr.error;
1349}
1350
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001351u16 hpi_mixer_close(u32 h_mixer)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001352{
1353 struct hpi_message hm;
1354 struct hpi_response hr;
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001355
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001356 hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER, HPI_MIXER_CLOSE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001357 if (hpi_handle_indexes(h_mixer, &hm.adapter_index, NULL))
1358 return HPI_ERROR_INVALID_HANDLE;
1359
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001360 hpi_send_recv(&hm, &hr);
1361 return hr.error;
1362}
1363
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001364u16 hpi_mixer_get_control(u32 h_mixer, u16 src_node_type,
1365 u16 src_node_type_index, u16 dst_node_type, u16 dst_node_type_index,
1366 u16 control_type, u32 *ph_control)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001367{
1368 struct hpi_message hm;
1369 struct hpi_response hr;
1370 hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER,
1371 HPI_MIXER_GET_CONTROL);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001372 if (hpi_handle_indexes(h_mixer, &hm.adapter_index, NULL))
1373 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001374 hm.u.m.node_type1 = src_node_type;
1375 hm.u.m.node_index1 = src_node_type_index;
1376 hm.u.m.node_type2 = dst_node_type;
1377 hm.u.m.node_index2 = dst_node_type_index;
1378 hm.u.m.control_type = control_type;
1379
1380 hpi_send_recv(&hm, &hr);
1381
1382 if (hr.error == 0)
1383 *ph_control =
1384 hpi_indexes_to_handle(HPI_OBJ_CONTROL,
1385 hm.adapter_index, hr.u.m.control_index);
1386 else
1387 *ph_control = 0;
1388 return hr.error;
1389}
1390
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001391u16 hpi_mixer_get_control_by_index(u32 h_mixer, u16 control_index,
1392 u16 *pw_src_node_type, u16 *pw_src_node_index, u16 *pw_dst_node_type,
1393 u16 *pw_dst_node_index, u16 *pw_control_type, u32 *ph_control)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001394{
1395 struct hpi_message hm;
1396 struct hpi_response hr;
1397 hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER,
1398 HPI_MIXER_GET_CONTROL_BY_INDEX);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001399 if (hpi_handle_indexes(h_mixer, &hm.adapter_index, NULL))
1400 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001401 hm.u.m.control_index = control_index;
1402 hpi_send_recv(&hm, &hr);
1403
1404 if (pw_src_node_type) {
1405 *pw_src_node_type =
1406 hr.u.m.src_node_type + HPI_SOURCENODE_NONE;
1407 *pw_src_node_index = hr.u.m.src_node_index;
1408 *pw_dst_node_type = hr.u.m.dst_node_type + HPI_DESTNODE_NONE;
1409 *pw_dst_node_index = hr.u.m.dst_node_index;
1410 }
1411 if (pw_control_type)
1412 *pw_control_type = hr.u.m.control_index;
1413
1414 if (ph_control) {
1415 if (hr.error == 0)
1416 *ph_control =
1417 hpi_indexes_to_handle(HPI_OBJ_CONTROL,
1418 hm.adapter_index, control_index);
1419 else
1420 *ph_control = 0;
1421 }
1422 return hr.error;
1423}
1424
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001425u16 hpi_mixer_store(u32 h_mixer, enum HPI_MIXER_STORE_COMMAND command,
1426 u16 index)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001427{
1428 struct hpi_message hm;
1429 struct hpi_response hr;
1430 hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER, HPI_MIXER_STORE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001431 if (hpi_handle_indexes(h_mixer, &hm.adapter_index, NULL))
1432 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001433 hm.u.mx.store.command = command;
1434 hm.u.mx.store.index = index;
1435 hpi_send_recv(&hm, &hr);
1436 return hr.error;
1437}
1438
1439static
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001440u16 hpi_control_param_set(const u32 h_control, const u16 attrib,
1441 const u32 param1, const u32 param2)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001442{
1443 struct hpi_message hm;
1444 struct hpi_response hr;
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12001445
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001446 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
1447 HPI_CONTROL_SET_STATE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001448 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
1449 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001450 hm.u.c.attribute = attrib;
1451 hm.u.c.param1 = param1;
1452 hm.u.c.param2 = param2;
1453 hpi_send_recv(&hm, &hr);
1454 return hr.error;
1455}
1456
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12001457static u16 hpi_control_log_set2(u32 h_control, u16 attrib, short sv0,
1458 short sv1)
1459{
1460 struct hpi_message hm;
1461 struct hpi_response hr;
1462
1463 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
1464 HPI_CONTROL_SET_STATE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001465 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
1466 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12001467 hm.u.c.attribute = attrib;
1468 hm.u.c.an_log_value[0] = sv0;
1469 hm.u.c.an_log_value[1] = sv1;
1470 hpi_send_recv(&hm, &hr);
1471 return hr.error;
1472}
1473
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001474static
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001475u16 hpi_control_param_get(const u32 h_control, const u16 attrib, u32 param1,
1476 u32 param2, u32 *pparam1, u32 *pparam2)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001477{
1478 struct hpi_message hm;
1479 struct hpi_response hr;
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12001480
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001481 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
1482 HPI_CONTROL_GET_STATE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001483 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
1484 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001485 hm.u.c.attribute = attrib;
1486 hm.u.c.param1 = param1;
1487 hm.u.c.param2 = param2;
1488 hpi_send_recv(&hm, &hr);
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12001489
1490 *pparam1 = hr.u.c.param1;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001491 if (pparam2)
1492 *pparam2 = hr.u.c.param2;
1493
1494 return hr.error;
1495}
1496
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001497#define hpi_control_param1_get(h, a, p1) \
1498 hpi_control_param_get(h, a, 0, 0, p1, NULL)
1499#define hpi_control_param2_get(h, a, p1, p2) \
1500 hpi_control_param_get(h, a, 0, 0, p1, p2)
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12001501
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001502static u16 hpi_control_log_get2(u32 h_control, u16 attrib, short *sv0,
1503 short *sv1)
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12001504{
1505 struct hpi_message hm;
1506 struct hpi_response hr;
1507 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
1508 HPI_CONTROL_GET_STATE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001509 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
1510 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12001511 hm.u.c.attribute = attrib;
1512
1513 hpi_send_recv(&hm, &hr);
1514 *sv0 = hr.u.c.an_log_value[0];
1515 if (sv1)
1516 *sv1 = hr.u.c.an_log_value[1];
1517 return hr.error;
1518}
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001519
1520static
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001521u16 hpi_control_query(const u32 h_control, const u16 attrib, const u32 index,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001522 const u32 param, u32 *psetting)
1523{
1524 struct hpi_message hm;
1525 struct hpi_response hr;
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12001526
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001527 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
1528 HPI_CONTROL_GET_INFO);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001529 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
1530 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001531
1532 hm.u.c.attribute = attrib;
1533 hm.u.c.param1 = index;
1534 hm.u.c.param2 = param;
1535
1536 hpi_send_recv(&hm, &hr);
1537 *psetting = hr.u.c.param1;
1538
1539 return hr.error;
1540}
1541
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12001542static u16 hpi_control_get_string(const u32 h_control, const u16 attribute,
1543 char *psz_string, const u32 string_length)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001544{
1545 unsigned int sub_string_index = 0, j = 0;
1546 char c = 0;
1547 unsigned int n = 0;
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13001548 u16 err = 0;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001549
1550 if ((string_length < 1) || (string_length > 256))
1551 return HPI_ERROR_INVALID_CONTROL_VALUE;
1552 for (sub_string_index = 0; sub_string_index < string_length;
1553 sub_string_index += 8) {
1554 struct hpi_message hm;
1555 struct hpi_response hr;
1556
1557 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
1558 HPI_CONTROL_GET_STATE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001559 if (hpi_handle_indexes(h_control, &hm.adapter_index,
1560 &hm.obj_index))
1561 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001562 hm.u.c.attribute = attribute;
1563 hm.u.c.param1 = sub_string_index;
1564 hm.u.c.param2 = 0;
1565 hpi_send_recv(&hm, &hr);
1566
1567 if (sub_string_index == 0
1568 && (hr.u.cu.chars8.remaining_chars + 8) >
1569 string_length)
1570 return HPI_ERROR_INVALID_CONTROL_VALUE;
1571
1572 if (hr.error) {
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13001573 err = hr.error;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001574 break;
1575 }
1576 for (j = 0; j < 8; j++) {
1577 c = hr.u.cu.chars8.sz_data[j];
1578 psz_string[sub_string_index + j] = c;
1579 n++;
1580 if (n >= string_length) {
1581 psz_string[string_length - 1] = 0;
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13001582 err = HPI_ERROR_INVALID_CONTROL_VALUE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001583 break;
1584 }
1585 if (c == 0)
1586 break;
1587 }
1588
1589 if ((hr.u.cu.chars8.remaining_chars == 0)
1590 && ((sub_string_index + j) < string_length)
1591 && (c != 0)) {
1592 c = 0;
1593 psz_string[sub_string_index + j] = c;
1594 }
1595 if (c == 0)
1596 break;
1597 }
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13001598 return err;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001599}
1600
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001601u16 hpi_aesebu_receiver_query_format(const u32 h_aes_rx, const u32 index,
1602 u16 *pw_format)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001603{
1604 u32 qr;
1605 u16 err;
1606
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001607 err = hpi_control_query(h_aes_rx, HPI_AESEBURX_FORMAT, index, 0, &qr);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001608 *pw_format = (u16)qr;
1609 return err;
1610}
1611
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001612u16 hpi_aesebu_receiver_set_format(u32 h_control, u16 format)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001613{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001614 return hpi_control_param_set(h_control, HPI_AESEBURX_FORMAT, format,
1615 0);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001616}
1617
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001618u16 hpi_aesebu_receiver_get_format(u32 h_control, u16 *pw_format)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001619{
1620 u16 err;
1621 u32 param;
1622
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001623 err = hpi_control_param1_get(h_control, HPI_AESEBURX_FORMAT, &param);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001624 if (!err && pw_format)
1625 *pw_format = (u16)param;
1626
1627 return err;
1628}
1629
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001630u16 hpi_aesebu_receiver_get_sample_rate(u32 h_control, u32 *psample_rate)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001631{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001632 return hpi_control_param1_get(h_control, HPI_AESEBURX_SAMPLERATE,
1633 psample_rate);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001634}
1635
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001636u16 hpi_aesebu_receiver_get_user_data(u32 h_control, u16 index, u16 *pw_data)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001637{
1638 struct hpi_message hm;
1639 struct hpi_response hr;
1640 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
1641 HPI_CONTROL_GET_STATE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001642 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
1643 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001644 hm.u.c.attribute = HPI_AESEBURX_USERDATA;
1645 hm.u.c.param1 = index;
1646
1647 hpi_send_recv(&hm, &hr);
1648
1649 if (pw_data)
1650 *pw_data = (u16)hr.u.c.param2;
1651 return hr.error;
1652}
1653
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001654u16 hpi_aesebu_receiver_get_channel_status(u32 h_control, u16 index,
1655 u16 *pw_data)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001656{
1657 struct hpi_message hm;
1658 struct hpi_response hr;
1659 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
1660 HPI_CONTROL_GET_STATE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001661 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
1662 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001663 hm.u.c.attribute = HPI_AESEBURX_CHANNELSTATUS;
1664 hm.u.c.param1 = index;
1665
1666 hpi_send_recv(&hm, &hr);
1667
1668 if (pw_data)
1669 *pw_data = (u16)hr.u.c.param2;
1670 return hr.error;
1671}
1672
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001673u16 hpi_aesebu_receiver_get_error_status(u32 h_control, u16 *pw_error_data)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001674{
1675 u32 error_data = 0;
1676 u16 error = 0;
1677
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001678 error = hpi_control_param1_get(h_control, HPI_AESEBURX_ERRORSTATUS,
1679 &error_data);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001680 if (pw_error_data)
1681 *pw_error_data = (u16)error_data;
1682 return error;
1683}
1684
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001685u16 hpi_aesebu_transmitter_set_sample_rate(u32 h_control, u32 sample_rate)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001686{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001687 return hpi_control_param_set(h_control, HPI_AESEBUTX_SAMPLERATE,
1688 sample_rate, 0);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001689}
1690
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001691u16 hpi_aesebu_transmitter_set_user_data(u32 h_control, u16 index, u16 data)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001692{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001693 return hpi_control_param_set(h_control, HPI_AESEBUTX_USERDATA, index,
1694 data);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001695}
1696
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001697u16 hpi_aesebu_transmitter_set_channel_status(u32 h_control, u16 index,
1698 u16 data)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001699{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001700 return hpi_control_param_set(h_control, HPI_AESEBUTX_CHANNELSTATUS,
1701 index, data);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001702}
1703
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001704u16 hpi_aesebu_transmitter_get_channel_status(u32 h_control, u16 index,
1705 u16 *pw_data)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001706{
1707 return HPI_ERROR_INVALID_OPERATION;
1708}
1709
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001710u16 hpi_aesebu_transmitter_query_format(const u32 h_aes_tx, const u32 index,
1711 u16 *pw_format)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001712{
1713 u32 qr;
1714 u16 err;
1715
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001716 err = hpi_control_query(h_aes_tx, HPI_AESEBUTX_FORMAT, index, 0, &qr);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001717 *pw_format = (u16)qr;
1718 return err;
1719}
1720
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001721u16 hpi_aesebu_transmitter_set_format(u32 h_control, u16 output_format)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001722{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001723 return hpi_control_param_set(h_control, HPI_AESEBUTX_FORMAT,
1724 output_format, 0);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001725}
1726
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001727u16 hpi_aesebu_transmitter_get_format(u32 h_control, u16 *pw_output_format)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001728{
1729 u16 err;
1730 u32 param;
1731
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001732 err = hpi_control_param1_get(h_control, HPI_AESEBUTX_FORMAT, &param);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001733 if (!err && pw_output_format)
1734 *pw_output_format = (u16)param;
1735
1736 return err;
1737}
1738
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001739u16 hpi_bitstream_set_clock_edge(u32 h_control, u16 edge_type)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001740{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001741 return hpi_control_param_set(h_control, HPI_BITSTREAM_CLOCK_EDGE,
1742 edge_type, 0);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001743}
1744
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001745u16 hpi_bitstream_set_data_polarity(u32 h_control, u16 polarity)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001746{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001747 return hpi_control_param_set(h_control, HPI_BITSTREAM_DATA_POLARITY,
1748 polarity, 0);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001749}
1750
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001751u16 hpi_bitstream_get_activity(u32 h_control, u16 *pw_clk_activity,
1752 u16 *pw_data_activity)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001753{
1754 struct hpi_message hm;
1755 struct hpi_response hr;
1756 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
1757 HPI_CONTROL_GET_STATE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001758 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
1759 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001760 hm.u.c.attribute = HPI_BITSTREAM_ACTIVITY;
1761 hpi_send_recv(&hm, &hr);
1762 if (pw_clk_activity)
1763 *pw_clk_activity = (u16)hr.u.c.param1;
1764 if (pw_data_activity)
1765 *pw_data_activity = (u16)hr.u.c.param2;
1766 return hr.error;
1767}
1768
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001769u16 hpi_channel_mode_query_mode(const u32 h_mode, const u32 index,
1770 u16 *pw_mode)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001771{
1772 u32 qr;
1773 u16 err;
1774
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001775 err = hpi_control_query(h_mode, HPI_CHANNEL_MODE_MODE, index, 0, &qr);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001776 *pw_mode = (u16)qr;
1777 return err;
1778}
1779
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001780u16 hpi_channel_mode_set(u32 h_control, u16 mode)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001781{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001782 return hpi_control_param_set(h_control, HPI_CHANNEL_MODE_MODE, mode,
1783 0);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001784}
1785
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001786u16 hpi_channel_mode_get(u32 h_control, u16 *mode)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001787{
1788 u32 mode32 = 0;
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001789 u16 error = hpi_control_param1_get(h_control,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001790 HPI_CHANNEL_MODE_MODE, &mode32);
1791 if (mode)
1792 *mode = (u16)mode32;
1793 return error;
1794}
1795
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001796u16 hpi_cobranet_hmi_write(u32 h_control, u32 hmi_address, u32 byte_count,
1797 u8 *pb_data)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001798{
1799 struct hpi_message hm;
1800 struct hpi_response hr;
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12001801
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001802 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROLEX,
1803 HPI_CONTROL_SET_STATE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001804 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
1805 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001806
1807 hm.u.cx.u.cobranet_data.byte_count = byte_count;
1808 hm.u.cx.u.cobranet_data.hmi_address = hmi_address;
1809
1810 if (byte_count <= 8) {
1811 memcpy(hm.u.cx.u.cobranet_data.data, pb_data, byte_count);
1812 hm.u.cx.attribute = HPI_COBRANET_SET;
1813 } else {
1814 hm.u.cx.u.cobranet_bigdata.pb_data = pb_data;
1815 hm.u.cx.attribute = HPI_COBRANET_SET_DATA;
1816 }
1817
1818 hpi_send_recv(&hm, &hr);
1819
1820 return hr.error;
1821}
1822
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001823u16 hpi_cobranet_hmi_read(u32 h_control, u32 hmi_address, u32 max_byte_count,
1824 u32 *pbyte_count, u8 *pb_data)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001825{
1826 struct hpi_message hm;
1827 struct hpi_response hr;
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12001828
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001829 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROLEX,
1830 HPI_CONTROL_GET_STATE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001831 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
1832 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001833
1834 hm.u.cx.u.cobranet_data.byte_count = max_byte_count;
1835 hm.u.cx.u.cobranet_data.hmi_address = hmi_address;
1836
1837 if (max_byte_count <= 8) {
1838 hm.u.cx.attribute = HPI_COBRANET_GET;
1839 } else {
1840 hm.u.cx.u.cobranet_bigdata.pb_data = pb_data;
1841 hm.u.cx.attribute = HPI_COBRANET_GET_DATA;
1842 }
1843
1844 hpi_send_recv(&hm, &hr);
1845 if (!hr.error && pb_data) {
1846
1847 *pbyte_count = hr.u.cx.u.cobranet_data.byte_count;
1848
1849 if (*pbyte_count < max_byte_count)
1850 max_byte_count = *pbyte_count;
1851
1852 if (hm.u.cx.attribute == HPI_COBRANET_GET) {
1853 memcpy(pb_data, hr.u.cx.u.cobranet_data.data,
1854 max_byte_count);
1855 } else {
1856
1857 }
1858
1859 }
1860 return hr.error;
1861}
1862
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001863u16 hpi_cobranet_hmi_get_status(u32 h_control, u32 *pstatus,
1864 u32 *preadable_size, u32 *pwriteable_size)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001865{
1866 struct hpi_message hm;
1867 struct hpi_response hr;
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12001868
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001869 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROLEX,
1870 HPI_CONTROL_GET_STATE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001871 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
1872 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001873
1874 hm.u.cx.attribute = HPI_COBRANET_GET_STATUS;
1875
1876 hpi_send_recv(&hm, &hr);
1877 if (!hr.error) {
1878 if (pstatus)
1879 *pstatus = hr.u.cx.u.cobranet_status.status;
1880 if (preadable_size)
1881 *preadable_size =
1882 hr.u.cx.u.cobranet_status.readable_size;
1883 if (pwriteable_size)
1884 *pwriteable_size =
1885 hr.u.cx.u.cobranet_status.writeable_size;
1886 }
1887 return hr.error;
1888}
1889
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001890u16 hpi_cobranet_get_ip_address(u32 h_control, u32 *pdw_ip_address)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001891{
1892 u32 byte_count;
1893 u32 iP;
1894 u16 error;
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12001895
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001896 error = hpi_cobranet_hmi_read(h_control,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001897 HPI_COBRANET_HMI_cobra_ip_mon_currentIP, 4, &byte_count,
1898 (u8 *)&iP);
1899
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001900 *pdw_ip_address =
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001901 ((iP & 0xff000000) >> 8) | ((iP & 0x00ff0000) << 8) | ((iP &
1902 0x0000ff00) >> 8) | ((iP & 0x000000ff) << 8);
1903
1904 if (error)
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001905 *pdw_ip_address = 0;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001906
1907 return error;
1908
1909}
1910
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001911u16 hpi_cobranet_set_ip_address(u32 h_control, u32 dw_ip_address)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001912{
1913 u32 iP;
1914 u16 error;
1915
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001916 iP = ((dw_ip_address & 0xff000000) >> 8) | ((dw_ip_address &
1917 0x00ff0000) << 8) | ((dw_ip_address & 0x0000ff00) >>
1918 8) | ((dw_ip_address & 0x000000ff) << 8);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001919
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001920 error = hpi_cobranet_hmi_write(h_control,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001921 HPI_COBRANET_HMI_cobra_ip_mon_currentIP, 4, (u8 *)&iP);
1922
1923 return error;
1924
1925}
1926
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001927u16 hpi_cobranet_get_static_ip_address(u32 h_control, u32 *pdw_ip_address)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001928{
1929 u32 byte_count;
1930 u32 iP;
1931 u16 error;
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001932 error = hpi_cobranet_hmi_read(h_control,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001933 HPI_COBRANET_HMI_cobra_ip_mon_staticIP, 4, &byte_count,
1934 (u8 *)&iP);
1935
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001936 *pdw_ip_address =
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001937 ((iP & 0xff000000) >> 8) | ((iP & 0x00ff0000) << 8) | ((iP &
1938 0x0000ff00) >> 8) | ((iP & 0x000000ff) << 8);
1939
1940 if (error)
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001941 *pdw_ip_address = 0;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001942
1943 return error;
1944
1945}
1946
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001947u16 hpi_cobranet_set_static_ip_address(u32 h_control, u32 dw_ip_address)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001948{
1949 u32 iP;
1950 u16 error;
1951
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001952 iP = ((dw_ip_address & 0xff000000) >> 8) | ((dw_ip_address &
1953 0x00ff0000) << 8) | ((dw_ip_address & 0x0000ff00) >>
1954 8) | ((dw_ip_address & 0x000000ff) << 8);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001955
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001956 error = hpi_cobranet_hmi_write(h_control,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001957 HPI_COBRANET_HMI_cobra_ip_mon_staticIP, 4, (u8 *)&iP);
1958
1959 return error;
1960
1961}
1962
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001963u16 hpi_cobranet_get_macaddress(u32 h_control, u32 *pmAC_MS_bs,
1964 u32 *pmAC_LS_bs)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001965{
1966 u32 byte_count;
1967 u16 error;
1968 u32 mAC;
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12001969
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001970 error = hpi_cobranet_hmi_read(h_control,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001971 HPI_COBRANET_HMI_cobra_if_phy_address, 4, &byte_count,
1972 (u8 *)&mAC);
1973 *pmAC_MS_bs =
1974 ((mAC & 0xff000000) >> 8) | ((mAC & 0x00ff0000) << 8) | ((mAC
1975 & 0x0000ff00) >> 8) | ((mAC & 0x000000ff) << 8);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001976 error += hpi_cobranet_hmi_read(h_control,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001977 HPI_COBRANET_HMI_cobra_if_phy_address + 1, 4, &byte_count,
1978 (u8 *)&mAC);
1979 *pmAC_LS_bs =
1980 ((mAC & 0xff000000) >> 8) | ((mAC & 0x00ff0000) << 8) | ((mAC
1981 & 0x0000ff00) >> 8) | ((mAC & 0x000000ff) << 8);
1982
1983 if (error) {
1984 *pmAC_MS_bs = 0;
1985 *pmAC_LS_bs = 0;
1986 }
1987
1988 return error;
1989}
1990
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001991u16 hpi_compander_set_enable(u32 h_control, u32 enable)
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12001992{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001993 return hpi_control_param_set(h_control, HPI_GENERIC_ENABLE, enable,
1994 0);
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12001995}
1996
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001997u16 hpi_compander_get_enable(u32 h_control, u32 *enable)
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12001998{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001999 return hpi_control_param1_get(h_control, HPI_GENERIC_ENABLE, enable);
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002000}
2001
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002002u16 hpi_compander_set_makeup_gain(u32 h_control, short makeup_gain0_01dB)
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002003{
2004 return hpi_control_log_set2(h_control, HPI_COMPANDER_MAKEUPGAIN,
2005 makeup_gain0_01dB, 0);
2006}
2007
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002008u16 hpi_compander_get_makeup_gain(u32 h_control, short *makeup_gain0_01dB)
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002009{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002010 return hpi_control_log_get2(h_control, HPI_COMPANDER_MAKEUPGAIN,
2011 makeup_gain0_01dB, NULL);
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002012}
2013
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002014u16 hpi_compander_set_attack_time_constant(u32 h_control, unsigned int index,
2015 u32 attack)
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002016{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002017 return hpi_control_param_set(h_control, HPI_COMPANDER_ATTACK, attack,
2018 index);
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002019}
2020
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002021u16 hpi_compander_get_attack_time_constant(u32 h_control, unsigned int index,
2022 u32 *attack)
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002023{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002024 return hpi_control_param_get(h_control, HPI_COMPANDER_ATTACK, 0,
2025 index, attack, NULL);
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002026}
2027
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002028u16 hpi_compander_set_decay_time_constant(u32 h_control, unsigned int index,
2029 u32 decay)
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002030{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002031 return hpi_control_param_set(h_control, HPI_COMPANDER_DECAY, decay,
2032 index);
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002033}
2034
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002035u16 hpi_compander_get_decay_time_constant(u32 h_control, unsigned int index,
2036 u32 *decay)
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002037{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002038 return hpi_control_param_get(h_control, HPI_COMPANDER_DECAY, 0, index,
2039 decay, NULL);
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002040
2041}
2042
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002043u16 hpi_compander_set_threshold(u32 h_control, unsigned int index,
2044 short threshold0_01dB)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002045{
2046 struct hpi_message hm;
2047 struct hpi_response hr;
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002048
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002049 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2050 HPI_CONTROL_SET_STATE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002051 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
2052 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002053 hm.u.c.attribute = HPI_COMPANDER_THRESHOLD;
2054 hm.u.c.param2 = index;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002055 hm.u.c.an_log_value[0] = threshold0_01dB;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002056
2057 hpi_send_recv(&hm, &hr);
2058
2059 return hr.error;
2060}
2061
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002062u16 hpi_compander_get_threshold(u32 h_control, unsigned int index,
2063 short *threshold0_01dB)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002064{
2065 struct hpi_message hm;
2066 struct hpi_response hr;
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002067
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002068 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2069 HPI_CONTROL_GET_STATE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002070 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
2071 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002072 hm.u.c.attribute = HPI_COMPANDER_THRESHOLD;
2073 hm.u.c.param2 = index;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002074
2075 hpi_send_recv(&hm, &hr);
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002076 *threshold0_01dB = hr.u.c.an_log_value[0];
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002077
2078 return hr.error;
2079}
2080
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002081u16 hpi_compander_set_ratio(u32 h_control, u32 index, u32 ratio100)
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002082{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002083 return hpi_control_param_set(h_control, HPI_COMPANDER_RATIO, ratio100,
2084 index);
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002085}
2086
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002087u16 hpi_compander_get_ratio(u32 h_control, u32 index, u32 *ratio100)
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002088{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002089 return hpi_control_param_get(h_control, HPI_COMPANDER_RATIO, 0, index,
2090 ratio100, NULL);
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002091}
2092
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002093u16 hpi_level_query_range(u32 h_control, short *min_gain_01dB,
2094 short *max_gain_01dB, short *step_gain_01dB)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002095{
2096 struct hpi_message hm;
2097 struct hpi_response hr;
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002098
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002099 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2100 HPI_CONTROL_GET_STATE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002101 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
2102 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002103 hm.u.c.attribute = HPI_LEVEL_RANGE;
2104
2105 hpi_send_recv(&hm, &hr);
2106 if (hr.error) {
2107 hr.u.c.an_log_value[0] = 0;
2108 hr.u.c.an_log_value[1] = 0;
2109 hr.u.c.param1 = 0;
2110 }
2111 if (min_gain_01dB)
2112 *min_gain_01dB = hr.u.c.an_log_value[0];
2113 if (max_gain_01dB)
2114 *max_gain_01dB = hr.u.c.an_log_value[1];
2115 if (step_gain_01dB)
2116 *step_gain_01dB = (short)hr.u.c.param1;
2117 return hr.error;
2118}
2119
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002120u16 hpi_level_set_gain(u32 h_control, short an_gain0_01dB[HPI_MAX_CHANNELS]
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002121 )
2122{
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002123 return hpi_control_log_set2(h_control, HPI_LEVEL_GAIN,
2124 an_gain0_01dB[0], an_gain0_01dB[1]);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002125}
2126
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002127u16 hpi_level_get_gain(u32 h_control, short an_gain0_01dB[HPI_MAX_CHANNELS]
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002128 )
2129{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002130 return hpi_control_log_get2(h_control, HPI_LEVEL_GAIN,
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002131 &an_gain0_01dB[0], &an_gain0_01dB[1]);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002132}
2133
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002134u16 hpi_meter_query_channels(const u32 h_meter, u32 *p_channels)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002135{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002136 return hpi_control_query(h_meter, HPI_METER_NUM_CHANNELS, 0, 0,
2137 p_channels);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002138}
2139
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002140u16 hpi_meter_get_peak(u32 h_control, short an_peakdB[HPI_MAX_CHANNELS]
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002141 )
2142{
2143 short i = 0;
2144
2145 struct hpi_message hm;
2146 struct hpi_response hr;
2147
2148 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2149 HPI_CONTROL_GET_STATE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002150 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
2151 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002152 hm.obj_index = hm.obj_index;
2153 hm.u.c.attribute = HPI_METER_PEAK;
2154
2155 hpi_send_recv(&hm, &hr);
2156
2157 if (!hr.error)
2158 memcpy(an_peakdB, hr.u.c.an_log_value,
2159 sizeof(short) * HPI_MAX_CHANNELS);
2160 else
2161 for (i = 0; i < HPI_MAX_CHANNELS; i++)
2162 an_peakdB[i] = HPI_METER_MINIMUM;
2163 return hr.error;
2164}
2165
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002166u16 hpi_meter_get_rms(u32 h_control, short an_rmsdB[HPI_MAX_CHANNELS]
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002167 )
2168{
2169 short i = 0;
2170
2171 struct hpi_message hm;
2172 struct hpi_response hr;
2173
2174 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2175 HPI_CONTROL_GET_STATE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002176 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
2177 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002178 hm.u.c.attribute = HPI_METER_RMS;
2179
2180 hpi_send_recv(&hm, &hr);
2181
2182 if (!hr.error)
2183 memcpy(an_rmsdB, hr.u.c.an_log_value,
2184 sizeof(short) * HPI_MAX_CHANNELS);
2185 else
2186 for (i = 0; i < HPI_MAX_CHANNELS; i++)
2187 an_rmsdB[i] = HPI_METER_MINIMUM;
2188
2189 return hr.error;
2190}
2191
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002192u16 hpi_meter_set_rms_ballistics(u32 h_control, u16 attack, u16 decay)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002193{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002194 return hpi_control_param_set(h_control, HPI_METER_RMS_BALLISTICS,
2195 attack, decay);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002196}
2197
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002198u16 hpi_meter_get_rms_ballistics(u32 h_control, u16 *pn_attack, u16 *pn_decay)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002199{
2200 u32 attack;
2201 u32 decay;
2202 u16 error;
2203
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002204 error = hpi_control_param2_get(h_control, HPI_METER_RMS_BALLISTICS,
2205 &attack, &decay);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002206
2207 if (pn_attack)
2208 *pn_attack = (unsigned short)attack;
2209 if (pn_decay)
2210 *pn_decay = (unsigned short)decay;
2211
2212 return error;
2213}
2214
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002215u16 hpi_meter_set_peak_ballistics(u32 h_control, u16 attack, u16 decay)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002216{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002217 return hpi_control_param_set(h_control, HPI_METER_PEAK_BALLISTICS,
2218 attack, decay);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002219}
2220
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002221u16 hpi_meter_get_peak_ballistics(u32 h_control, u16 *pn_attack,
2222 u16 *pn_decay)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002223{
2224 u32 attack;
2225 u32 decay;
2226 u16 error;
2227
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002228 error = hpi_control_param2_get(h_control, HPI_METER_PEAK_BALLISTICS,
2229 &attack, &decay);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002230
2231 if (pn_attack)
2232 *pn_attack = (short)attack;
2233 if (pn_decay)
2234 *pn_decay = (short)decay;
2235
2236 return error;
2237}
2238
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002239u16 hpi_microphone_set_phantom_power(u32 h_control, u16 on_off)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002240{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002241 return hpi_control_param_set(h_control, HPI_MICROPHONE_PHANTOM_POWER,
2242 (u32)on_off, 0);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002243}
2244
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002245u16 hpi_microphone_get_phantom_power(u32 h_control, u16 *pw_on_off)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002246{
2247 u16 error = 0;
2248 u32 on_off = 0;
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002249 error = hpi_control_param1_get(h_control,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002250 HPI_MICROPHONE_PHANTOM_POWER, &on_off);
2251 if (pw_on_off)
2252 *pw_on_off = (u16)on_off;
2253 return error;
2254}
2255
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002256u16 hpi_multiplexer_set_source(u32 h_control, u16 source_node_type,
2257 u16 source_node_index)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002258{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002259 return hpi_control_param_set(h_control, HPI_MULTIPLEXER_SOURCE,
2260 source_node_type, source_node_index);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002261}
2262
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002263u16 hpi_multiplexer_get_source(u32 h_control, u16 *source_node_type,
2264 u16 *source_node_index)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002265{
2266 u32 node, index;
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002267 u16 error = hpi_control_param2_get(h_control,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002268 HPI_MULTIPLEXER_SOURCE, &node,
2269 &index);
2270 if (source_node_type)
2271 *source_node_type = (u16)node;
2272 if (source_node_index)
2273 *source_node_index = (u16)index;
2274 return error;
2275}
2276
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002277u16 hpi_multiplexer_query_source(u32 h_control, u16 index,
2278 u16 *source_node_type, u16 *source_node_index)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002279{
2280 struct hpi_message hm;
2281 struct hpi_response hr;
2282 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2283 HPI_CONTROL_GET_STATE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002284 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
2285 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002286 hm.u.c.attribute = HPI_MULTIPLEXER_QUERYSOURCE;
2287 hm.u.c.param1 = index;
2288
2289 hpi_send_recv(&hm, &hr);
2290
2291 if (source_node_type)
2292 *source_node_type = (u16)hr.u.c.param1;
2293 if (source_node_index)
2294 *source_node_index = (u16)hr.u.c.param2;
2295 return hr.error;
2296}
2297
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002298u16 hpi_parametric_eq_get_info(u32 h_control, u16 *pw_number_of_bands,
2299 u16 *pw_on_off)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002300{
2301 u32 oB = 0;
2302 u32 oO = 0;
2303 u16 error = 0;
2304
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002305 error = hpi_control_param2_get(h_control, HPI_EQUALIZER_NUM_FILTERS,
2306 &oO, &oB);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002307 if (pw_number_of_bands)
2308 *pw_number_of_bands = (u16)oB;
2309 if (pw_on_off)
2310 *pw_on_off = (u16)oO;
2311 return error;
2312}
2313
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002314u16 hpi_parametric_eq_set_state(u32 h_control, u16 on_off)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002315{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002316 return hpi_control_param_set(h_control, HPI_EQUALIZER_NUM_FILTERS,
2317 on_off, 0);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002318}
2319
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002320u16 hpi_parametric_eq_get_band(u32 h_control, u16 index, u16 *pn_type,
2321 u32 *pfrequency_hz, short *pnQ100, short *pn_gain0_01dB)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002322{
2323 struct hpi_message hm;
2324 struct hpi_response hr;
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002325
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002326 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2327 HPI_CONTROL_GET_STATE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002328 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
2329 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002330 hm.u.c.attribute = HPI_EQUALIZER_FILTER;
2331 hm.u.c.param2 = index;
2332
2333 hpi_send_recv(&hm, &hr);
2334
2335 if (pfrequency_hz)
2336 *pfrequency_hz = hr.u.c.param1;
2337 if (pn_type)
2338 *pn_type = (u16)(hr.u.c.param2 >> 16);
2339 if (pnQ100)
2340 *pnQ100 = hr.u.c.an_log_value[1];
2341 if (pn_gain0_01dB)
2342 *pn_gain0_01dB = hr.u.c.an_log_value[0];
2343
2344 return hr.error;
2345}
2346
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002347u16 hpi_parametric_eq_set_band(u32 h_control, u16 index, u16 type,
2348 u32 frequency_hz, short q100, short gain0_01dB)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002349{
2350 struct hpi_message hm;
2351 struct hpi_response hr;
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002352
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002353 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2354 HPI_CONTROL_SET_STATE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002355 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
2356 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002357
2358 hm.u.c.param1 = frequency_hz;
2359 hm.u.c.param2 = (index & 0xFFFFL) + ((u32)type << 16);
2360 hm.u.c.an_log_value[0] = gain0_01dB;
2361 hm.u.c.an_log_value[1] = q100;
2362 hm.u.c.attribute = HPI_EQUALIZER_FILTER;
2363
2364 hpi_send_recv(&hm, &hr);
2365
2366 return hr.error;
2367}
2368
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002369u16 hpi_parametric_eq_get_coeffs(u32 h_control, u16 index, short coeffs[5]
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002370 )
2371{
2372 struct hpi_message hm;
2373 struct hpi_response hr;
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002374
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002375 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2376 HPI_CONTROL_GET_STATE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002377 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
2378 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002379 hm.u.c.attribute = HPI_EQUALIZER_COEFFICIENTS;
2380 hm.u.c.param2 = index;
2381
2382 hpi_send_recv(&hm, &hr);
2383
2384 coeffs[0] = (short)hr.u.c.an_log_value[0];
2385 coeffs[1] = (short)hr.u.c.an_log_value[1];
2386 coeffs[2] = (short)hr.u.c.param1;
2387 coeffs[3] = (short)(hr.u.c.param1 >> 16);
2388 coeffs[4] = (short)hr.u.c.param2;
2389
2390 return hr.error;
2391}
2392
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002393u16 hpi_sample_clock_query_source(const u32 h_clock, const u32 index,
2394 u16 *pw_source)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002395{
2396 u32 qr;
2397 u16 err;
2398
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002399 err = hpi_control_query(h_clock, HPI_SAMPLECLOCK_SOURCE, index, 0,
2400 &qr);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002401 *pw_source = (u16)qr;
2402 return err;
2403}
2404
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002405u16 hpi_sample_clock_set_source(u32 h_control, u16 source)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002406{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002407 return hpi_control_param_set(h_control, HPI_SAMPLECLOCK_SOURCE,
2408 source, 0);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002409}
2410
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002411u16 hpi_sample_clock_get_source(u32 h_control, u16 *pw_source)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002412{
2413 u16 error = 0;
2414 u32 source = 0;
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002415 error = hpi_control_param1_get(h_control, HPI_SAMPLECLOCK_SOURCE,
2416 &source);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002417 if (!error)
2418 if (pw_source)
2419 *pw_source = (u16)source;
2420 return error;
2421}
2422
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002423u16 hpi_sample_clock_query_source_index(const u32 h_clock, const u32 index,
2424 const u32 source, u16 *pw_source_index)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002425{
2426 u32 qr;
2427 u16 err;
2428
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002429 err = hpi_control_query(h_clock, HPI_SAMPLECLOCK_SOURCE_INDEX, index,
2430 source, &qr);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002431 *pw_source_index = (u16)qr;
2432 return err;
2433}
2434
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002435u16 hpi_sample_clock_set_source_index(u32 h_control, u16 source_index)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002436{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002437 return hpi_control_param_set(h_control, HPI_SAMPLECLOCK_SOURCE_INDEX,
2438 source_index, 0);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002439}
2440
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002441u16 hpi_sample_clock_get_source_index(u32 h_control, u16 *pw_source_index)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002442{
2443 u16 error = 0;
2444 u32 source_index = 0;
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002445 error = hpi_control_param1_get(h_control,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002446 HPI_SAMPLECLOCK_SOURCE_INDEX, &source_index);
2447 if (!error)
2448 if (pw_source_index)
2449 *pw_source_index = (u16)source_index;
2450 return error;
2451}
2452
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002453u16 hpi_sample_clock_query_local_rate(const u32 h_clock, const u32 index,
2454 u32 *prate)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002455{
2456 u16 err;
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002457 err = hpi_control_query(h_clock, HPI_SAMPLECLOCK_LOCAL_SAMPLERATE,
2458 index, 0, prate);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002459
2460 return err;
2461}
2462
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002463u16 hpi_sample_clock_set_local_rate(u32 h_control, u32 sample_rate)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002464{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002465 return hpi_control_param_set(h_control,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002466 HPI_SAMPLECLOCK_LOCAL_SAMPLERATE, sample_rate, 0);
2467}
2468
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002469u16 hpi_sample_clock_get_local_rate(u32 h_control, u32 *psample_rate)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002470{
2471 u16 error = 0;
2472 u32 sample_rate = 0;
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002473 error = hpi_control_param1_get(h_control,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002474 HPI_SAMPLECLOCK_LOCAL_SAMPLERATE, &sample_rate);
2475 if (!error)
2476 if (psample_rate)
2477 *psample_rate = sample_rate;
2478 return error;
2479}
2480
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002481u16 hpi_sample_clock_get_sample_rate(u32 h_control, u32 *psample_rate)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002482{
2483 u16 error = 0;
2484 u32 sample_rate = 0;
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002485 error = hpi_control_param1_get(h_control, HPI_SAMPLECLOCK_SAMPLERATE,
2486 &sample_rate);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002487 if (!error)
2488 if (psample_rate)
2489 *psample_rate = sample_rate;
2490 return error;
2491}
2492
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002493u16 hpi_sample_clock_set_auto(u32 h_control, u32 enable)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002494{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002495 return hpi_control_param_set(h_control, HPI_SAMPLECLOCK_AUTO, enable,
2496 0);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002497}
2498
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002499u16 hpi_sample_clock_get_auto(u32 h_control, u32 *penable)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002500{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002501 return hpi_control_param1_get(h_control, HPI_SAMPLECLOCK_AUTO,
2502 penable);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002503}
2504
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002505u16 hpi_sample_clock_set_local_rate_lock(u32 h_control, u32 lock)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002506{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002507 return hpi_control_param_set(h_control, HPI_SAMPLECLOCK_LOCAL_LOCK,
2508 lock, 0);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002509}
2510
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002511u16 hpi_sample_clock_get_local_rate_lock(u32 h_control, u32 *plock)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002512{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002513 return hpi_control_param1_get(h_control, HPI_SAMPLECLOCK_LOCAL_LOCK,
2514 plock);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002515}
2516
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002517u16 hpi_tone_detector_get_frequency(u32 h_control, u32 index, u32 *frequency)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002518{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002519 return hpi_control_param_get(h_control, HPI_TONEDETECTOR_FREQUENCY,
2520 index, 0, frequency, NULL);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002521}
2522
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002523u16 hpi_tone_detector_get_state(u32 h_control, u32 *state)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002524{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002525 return hpi_control_param1_get(h_control, HPI_TONEDETECTOR_STATE,
2526 state);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002527}
2528
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002529u16 hpi_tone_detector_set_enable(u32 h_control, u32 enable)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002530{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002531 return hpi_control_param_set(h_control, HPI_GENERIC_ENABLE, enable,
2532 0);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002533}
2534
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002535u16 hpi_tone_detector_get_enable(u32 h_control, u32 *enable)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002536{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002537 return hpi_control_param1_get(h_control, HPI_GENERIC_ENABLE, enable);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002538}
2539
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002540u16 hpi_tone_detector_set_event_enable(u32 h_control, u32 event_enable)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002541{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002542 return hpi_control_param_set(h_control, HPI_GENERIC_EVENT_ENABLE,
2543 (u32)event_enable, 0);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002544}
2545
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002546u16 hpi_tone_detector_get_event_enable(u32 h_control, u32 *event_enable)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002547{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002548 return hpi_control_param1_get(h_control, HPI_GENERIC_EVENT_ENABLE,
2549 event_enable);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002550}
2551
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002552u16 hpi_tone_detector_set_threshold(u32 h_control, int threshold)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002553{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002554 return hpi_control_param_set(h_control, HPI_TONEDETECTOR_THRESHOLD,
2555 (u32)threshold, 0);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002556}
2557
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002558u16 hpi_tone_detector_get_threshold(u32 h_control, int *threshold)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002559{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002560 return hpi_control_param1_get(h_control, HPI_TONEDETECTOR_THRESHOLD,
2561 (u32 *)threshold);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002562}
2563
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002564u16 hpi_silence_detector_get_state(u32 h_control, u32 *state)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002565{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002566 return hpi_control_param1_get(h_control, HPI_SILENCEDETECTOR_STATE,
2567 state);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002568}
2569
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002570u16 hpi_silence_detector_set_enable(u32 h_control, u32 enable)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002571{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002572 return hpi_control_param_set(h_control, HPI_GENERIC_ENABLE, enable,
2573 0);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002574}
2575
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002576u16 hpi_silence_detector_get_enable(u32 h_control, u32 *enable)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002577{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002578 return hpi_control_param1_get(h_control, HPI_GENERIC_ENABLE, enable);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002579}
2580
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002581u16 hpi_silence_detector_set_event_enable(u32 h_control, u32 event_enable)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002582{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002583 return hpi_control_param_set(h_control, HPI_GENERIC_EVENT_ENABLE,
2584 event_enable, 0);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002585}
2586
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002587u16 hpi_silence_detector_get_event_enable(u32 h_control, u32 *event_enable)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002588{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002589 return hpi_control_param1_get(h_control, HPI_GENERIC_EVENT_ENABLE,
2590 event_enable);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002591}
2592
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002593u16 hpi_silence_detector_set_delay(u32 h_control, u32 delay)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002594{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002595 return hpi_control_param_set(h_control, HPI_SILENCEDETECTOR_DELAY,
2596 delay, 0);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002597}
2598
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002599u16 hpi_silence_detector_get_delay(u32 h_control, u32 *delay)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002600{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002601 return hpi_control_param1_get(h_control, HPI_SILENCEDETECTOR_DELAY,
2602 delay);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002603}
2604
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002605u16 hpi_silence_detector_set_threshold(u32 h_control, int threshold)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002606{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002607 return hpi_control_param_set(h_control, HPI_SILENCEDETECTOR_THRESHOLD,
2608 threshold, 0);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002609}
2610
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002611u16 hpi_silence_detector_get_threshold(u32 h_control, int *threshold)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002612{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002613 return hpi_control_param1_get(h_control,
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002614 HPI_SILENCEDETECTOR_THRESHOLD, (u32 *)threshold);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002615}
2616
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002617u16 hpi_tuner_query_band(const u32 h_tuner, const u32 index, u16 *pw_band)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002618{
2619 u32 qr;
2620 u16 err;
2621
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002622 err = hpi_control_query(h_tuner, HPI_TUNER_BAND, index, 0, &qr);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002623 *pw_band = (u16)qr;
2624 return err;
2625}
2626
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002627u16 hpi_tuner_set_band(u32 h_control, u16 band)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002628{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002629 return hpi_control_param_set(h_control, HPI_TUNER_BAND, band, 0);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002630}
2631
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002632u16 hpi_tuner_get_band(u32 h_control, u16 *pw_band)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002633{
2634 u32 band = 0;
2635 u16 error = 0;
2636
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002637 error = hpi_control_param1_get(h_control, HPI_TUNER_BAND, &band);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002638 if (pw_band)
2639 *pw_band = (u16)band;
2640 return error;
2641}
2642
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002643u16 hpi_tuner_query_frequency(const u32 h_tuner, const u32 index,
2644 const u16 band, u32 *pfreq)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002645{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002646 return hpi_control_query(h_tuner, HPI_TUNER_FREQ, index, band, pfreq);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002647}
2648
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002649u16 hpi_tuner_set_frequency(u32 h_control, u32 freq_ink_hz)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002650{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002651 return hpi_control_param_set(h_control, HPI_TUNER_FREQ, freq_ink_hz,
2652 0);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002653}
2654
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002655u16 hpi_tuner_get_frequency(u32 h_control, u32 *pw_freq_ink_hz)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002656{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002657 return hpi_control_param1_get(h_control, HPI_TUNER_FREQ,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002658 pw_freq_ink_hz);
2659}
2660
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002661u16 hpi_tuner_query_gain(const u32 h_tuner, const u32 index, u16 *pw_gain)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002662{
2663 u32 qr;
2664 u16 err;
2665
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002666 err = hpi_control_query(h_tuner, HPI_TUNER_BAND, index, 0, &qr);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002667 *pw_gain = (u16)qr;
2668 return err;
2669}
2670
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002671u16 hpi_tuner_set_gain(u32 h_control, short gain)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002672{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002673 return hpi_control_param_set(h_control, HPI_TUNER_GAIN, gain, 0);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002674}
2675
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002676u16 hpi_tuner_get_gain(u32 h_control, short *pn_gain)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002677{
2678 u32 gain = 0;
2679 u16 error = 0;
2680
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002681 error = hpi_control_param1_get(h_control, HPI_TUNER_GAIN, &gain);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002682 if (pn_gain)
2683 *pn_gain = (u16)gain;
2684 return error;
2685}
2686
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002687u16 hpi_tuner_get_rf_level(u32 h_control, short *pw_level)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002688{
2689 struct hpi_message hm;
2690 struct hpi_response hr;
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002691
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002692 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2693 HPI_CONTROL_GET_STATE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002694 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
2695 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13002696 hm.u.cu.attribute = HPI_TUNER_LEVEL_AVG;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002697 hpi_send_recv(&hm, &hr);
2698 if (pw_level)
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13002699 *pw_level = hr.u.cu.tuner.s_level;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002700 return hr.error;
2701}
2702
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002703u16 hpi_tuner_get_raw_rf_level(u32 h_control, short *pw_level)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002704{
2705 struct hpi_message hm;
2706 struct hpi_response hr;
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002707
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002708 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2709 HPI_CONTROL_GET_STATE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002710 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
2711 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13002712 hm.u.cu.attribute = HPI_TUNER_LEVEL_RAW;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002713 hpi_send_recv(&hm, &hr);
2714 if (pw_level)
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13002715 *pw_level = hr.u.cu.tuner.s_level;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002716 return hr.error;
2717}
2718
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002719u16 hpi_tuner_query_deemphasis(const u32 h_tuner, const u32 index,
2720 const u16 band, u32 *pdeemphasis)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002721{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002722 return hpi_control_query(h_tuner, HPI_TUNER_DEEMPHASIS, index, band,
2723 pdeemphasis);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002724}
2725
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002726u16 hpi_tuner_set_deemphasis(u32 h_control, u32 deemphasis)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002727{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002728 return hpi_control_param_set(h_control, HPI_TUNER_DEEMPHASIS,
2729 deemphasis, 0);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002730}
2731
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002732u16 hpi_tuner_get_deemphasis(u32 h_control, u32 *pdeemphasis)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002733{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002734 return hpi_control_param1_get(h_control, HPI_TUNER_DEEMPHASIS,
2735 pdeemphasis);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002736}
2737
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002738u16 hpi_tuner_query_program(const u32 h_tuner, u32 *pbitmap_program)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002739{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002740 return hpi_control_query(h_tuner, HPI_TUNER_PROGRAM, 0, 0,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002741 pbitmap_program);
2742}
2743
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002744u16 hpi_tuner_set_program(u32 h_control, u32 program)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002745{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002746 return hpi_control_param_set(h_control, HPI_TUNER_PROGRAM, program,
2747 0);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002748}
2749
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002750u16 hpi_tuner_get_program(u32 h_control, u32 *pprogram)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002751{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002752 return hpi_control_param1_get(h_control, HPI_TUNER_PROGRAM, pprogram);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002753}
2754
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002755u16 hpi_tuner_get_hd_radio_dsp_version(u32 h_control, char *psz_dsp_version,
2756 const u32 string_size)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002757{
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002758 return hpi_control_get_string(h_control,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002759 HPI_TUNER_HDRADIO_DSP_VERSION, psz_dsp_version, string_size);
2760}
2761
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002762u16 hpi_tuner_get_hd_radio_sdk_version(u32 h_control, char *psz_sdk_version,
2763 const u32 string_size)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002764{
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002765 return hpi_control_get_string(h_control,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002766 HPI_TUNER_HDRADIO_SDK_VERSION, psz_sdk_version, string_size);
2767}
2768
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002769u16 hpi_tuner_get_status(u32 h_control, u16 *pw_status_mask, u16 *pw_status)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002770{
2771 u32 status = 0;
2772 u16 error = 0;
2773
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002774 error = hpi_control_param1_get(h_control, HPI_TUNER_STATUS, &status);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002775 if (pw_status) {
2776 if (!error) {
2777 *pw_status_mask = (u16)(status >> 16);
2778 *pw_status = (u16)(status & 0xFFFF);
2779 } else {
2780 *pw_status_mask = 0;
2781 *pw_status = 0;
2782 }
2783 }
2784 return error;
2785}
2786
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002787u16 hpi_tuner_set_mode(u32 h_control, u32 mode, u32 value)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002788{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002789 return hpi_control_param_set(h_control, HPI_TUNER_MODE, mode, value);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002790}
2791
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002792u16 hpi_tuner_get_mode(u32 h_control, u32 mode, u32 *pn_value)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002793{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002794 return hpi_control_param_get(h_control, HPI_TUNER_MODE, mode, 0,
2795 pn_value, NULL);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002796}
2797
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002798u16 hpi_tuner_get_hd_radio_signal_quality(u32 h_control, u32 *pquality)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002799{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002800 return hpi_control_param1_get(h_control,
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002801 HPI_TUNER_HDRADIO_SIGNAL_QUALITY, pquality);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002802}
2803
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002804u16 hpi_tuner_get_hd_radio_signal_blend(u32 h_control, u32 *pblend)
Eliot Blennerhassett5a498ef2010-05-27 17:53:52 +12002805{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002806 return hpi_control_param1_get(h_control, HPI_TUNER_HDRADIO_BLEND,
2807 pblend);
Eliot Blennerhassett5a498ef2010-05-27 17:53:52 +12002808}
2809
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002810u16 hpi_tuner_set_hd_radio_signal_blend(u32 h_control, const u32 blend)
Eliot Blennerhassett5a498ef2010-05-27 17:53:52 +12002811{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002812 return hpi_control_param_set(h_control, HPI_TUNER_HDRADIO_BLEND,
2813 blend, 0);
Eliot Blennerhassett5a498ef2010-05-27 17:53:52 +12002814}
2815
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002816u16 hpi_tuner_get_rds(u32 h_control, char *p_data)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002817{
2818 struct hpi_message hm;
2819 struct hpi_response hr;
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002820
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002821 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2822 HPI_CONTROL_GET_STATE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002823 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
2824 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002825 hm.u.c.attribute = HPI_TUNER_RDS;
2826 hpi_send_recv(&hm, &hr);
2827 if (p_data) {
2828 *(u32 *)&p_data[0] = hr.u.cu.tuner.rds.data[0];
2829 *(u32 *)&p_data[4] = hr.u.cu.tuner.rds.data[1];
2830 *(u32 *)&p_data[8] = hr.u.cu.tuner.rds.bLER;
2831 }
2832 return hr.error;
2833}
2834
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002835u16 hpi_pad_get_channel_name(u32 h_control, char *psz_string,
2836 const u32 data_length)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002837{
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002838 return hpi_control_get_string(h_control, HPI_PAD_CHANNEL_NAME,
2839 psz_string, data_length);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002840}
2841
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002842u16 hpi_pad_get_artist(u32 h_control, char *psz_string, const u32 data_length)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002843{
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002844 return hpi_control_get_string(h_control, HPI_PAD_ARTIST, psz_string,
2845 data_length);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002846}
2847
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002848u16 hpi_pad_get_title(u32 h_control, char *psz_string, const u32 data_length)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002849{
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002850 return hpi_control_get_string(h_control, HPI_PAD_TITLE, psz_string,
2851 data_length);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002852}
2853
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002854u16 hpi_pad_get_comment(u32 h_control, char *psz_string,
2855 const u32 data_length)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002856{
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002857 return hpi_control_get_string(h_control, HPI_PAD_COMMENT, psz_string,
2858 data_length);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002859}
2860
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002861u16 hpi_pad_get_program_type(u32 h_control, u32 *ppTY)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002862{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002863 return hpi_control_param1_get(h_control, HPI_PAD_PROGRAM_TYPE, ppTY);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002864}
2865
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002866u16 hpi_pad_get_rdsPI(u32 h_control, u32 *ppI)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002867{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002868 return hpi_control_param1_get(h_control, HPI_PAD_PROGRAM_ID, ppI);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002869}
2870
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002871u16 hpi_volume_query_channels(const u32 h_volume, u32 *p_channels)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002872{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002873 return hpi_control_query(h_volume, HPI_VOLUME_NUM_CHANNELS, 0, 0,
2874 p_channels);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002875}
2876
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002877u16 hpi_volume_set_gain(u32 h_control, short an_log_gain[HPI_MAX_CHANNELS]
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002878 )
2879{
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002880 return hpi_control_log_set2(h_control, HPI_VOLUME_GAIN,
2881 an_log_gain[0], an_log_gain[1]);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002882}
2883
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002884u16 hpi_volume_get_gain(u32 h_control, short an_log_gain[HPI_MAX_CHANNELS]
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002885 )
2886{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002887 return hpi_control_log_get2(h_control, HPI_VOLUME_GAIN,
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002888 &an_log_gain[0], &an_log_gain[1]);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002889}
2890
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002891u16 hpi_volume_query_range(u32 h_control, short *min_gain_01dB,
2892 short *max_gain_01dB, short *step_gain_01dB)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002893{
2894 struct hpi_message hm;
2895 struct hpi_response hr;
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002896
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002897 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2898 HPI_CONTROL_GET_STATE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002899 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
2900 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002901 hm.u.c.attribute = HPI_VOLUME_RANGE;
2902
2903 hpi_send_recv(&hm, &hr);
2904 if (hr.error) {
2905 hr.u.c.an_log_value[0] = 0;
2906 hr.u.c.an_log_value[1] = 0;
2907 hr.u.c.param1 = 0;
2908 }
2909 if (min_gain_01dB)
2910 *min_gain_01dB = hr.u.c.an_log_value[0];
2911 if (max_gain_01dB)
2912 *max_gain_01dB = hr.u.c.an_log_value[1];
2913 if (step_gain_01dB)
2914 *step_gain_01dB = (short)hr.u.c.param1;
2915 return hr.error;
2916}
2917
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002918u16 hpi_volume_auto_fade_profile(u32 h_control,
2919 short an_stop_gain0_01dB[HPI_MAX_CHANNELS], u32 duration_ms,
2920 u16 profile)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002921{
2922 struct hpi_message hm;
2923 struct hpi_response hr;
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002924
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002925 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2926 HPI_CONTROL_SET_STATE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002927 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
2928 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002929
2930 memcpy(hm.u.c.an_log_value, an_stop_gain0_01dB,
2931 sizeof(short) * HPI_MAX_CHANNELS);
2932
2933 hm.u.c.attribute = HPI_VOLUME_AUTOFADE;
2934 hm.u.c.param1 = duration_ms;
2935 hm.u.c.param2 = profile;
2936
2937 hpi_send_recv(&hm, &hr);
2938
2939 return hr.error;
2940}
2941
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002942u16 hpi_volume_auto_fade(u32 h_control,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002943 short an_stop_gain0_01dB[HPI_MAX_CHANNELS], u32 duration_ms)
2944{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002945 return hpi_volume_auto_fade_profile(h_control, an_stop_gain0_01dB,
2946 duration_ms, HPI_VOLUME_AUTOFADE_LOG);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002947}
2948
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002949u16 hpi_vox_set_threshold(u32 h_control, short an_gain0_01dB)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002950{
2951 struct hpi_message hm;
2952 struct hpi_response hr;
2953 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2954 HPI_CONTROL_SET_STATE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002955 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
2956 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002957 hm.u.c.attribute = HPI_VOX_THRESHOLD;
2958
2959 hm.u.c.an_log_value[0] = an_gain0_01dB;
2960
2961 hpi_send_recv(&hm, &hr);
2962
2963 return hr.error;
2964}
2965
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002966u16 hpi_vox_get_threshold(u32 h_control, short *an_gain0_01dB)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002967{
2968 struct hpi_message hm;
2969 struct hpi_response hr;
2970 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2971 HPI_CONTROL_GET_STATE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002972 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
2973 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002974 hm.u.c.attribute = HPI_VOX_THRESHOLD;
2975
2976 hpi_send_recv(&hm, &hr);
2977
2978 *an_gain0_01dB = hr.u.c.an_log_value[0];
2979
2980 return hr.error;
2981}