blob: 28e98dd9249bbf472bf2cd4bd14e196d6ea50ca3 [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;
156 *pw_adapter_type = hr.u.s.aw_adapter_list[0];
157 return hr.error;
158}
159
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300160u16 hpi_adapter_open(u16 adapter_index)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200161{
162 struct hpi_message hm;
163 struct hpi_response hr;
164 hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
165 HPI_ADAPTER_OPEN);
166 hm.adapter_index = adapter_index;
167
168 hpi_send_recv(&hm, &hr);
169
170 return hr.error;
171
172}
173
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300174u16 hpi_adapter_close(u16 adapter_index)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200175{
176 struct hpi_message hm;
177 struct hpi_response hr;
178 hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
179 HPI_ADAPTER_CLOSE);
180 hm.adapter_index = adapter_index;
181
182 hpi_send_recv(&hm, &hr);
183
184 return hr.error;
185}
186
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300187u16 hpi_adapter_set_mode(u16 adapter_index, u32 adapter_mode)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200188{
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300189 return hpi_adapter_set_mode_ex(adapter_index, adapter_mode,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200190 HPI_ADAPTER_MODE_SET);
191}
192
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300193u16 hpi_adapter_set_mode_ex(u16 adapter_index, u32 adapter_mode,
194 u16 query_or_set)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200195{
196 struct hpi_message hm;
197 struct hpi_response hr;
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +1200198
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200199 hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
200 HPI_ADAPTER_SET_MODE);
201 hm.adapter_index = adapter_index;
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300202 hm.u.ax.mode.adapter_mode = adapter_mode;
203 hm.u.ax.mode.query_or_set = query_or_set;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200204 hpi_send_recv(&hm, &hr);
205 return hr.error;
206}
207
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300208u16 hpi_adapter_get_mode(u16 adapter_index, u32 *padapter_mode)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200209{
210 struct hpi_message hm;
211 struct hpi_response hr;
212 hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
213 HPI_ADAPTER_GET_MODE);
214 hm.adapter_index = adapter_index;
215 hpi_send_recv(&hm, &hr);
216 if (padapter_mode)
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300217 *padapter_mode = hr.u.ax.mode.adapter_mode;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200218 return hr.error;
219}
220
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300221u16 hpi_adapter_get_info(u16 adapter_index, u16 *pw_num_outstreams,
222 u16 *pw_num_instreams, u16 *pw_version, u32 *pserial_number,
223 u16 *pw_adapter_type)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200224{
225 struct hpi_message hm;
226 struct hpi_response hr;
227 hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
228 HPI_ADAPTER_GET_INFO);
229 hm.adapter_index = adapter_index;
230
231 hpi_send_recv(&hm, &hr);
232
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300233 *pw_adapter_type = hr.u.ax.info.adapter_type;
234 *pw_num_outstreams = hr.u.ax.info.num_outstreams;
235 *pw_num_instreams = hr.u.ax.info.num_instreams;
236 *pw_version = hr.u.ax.info.version;
237 *pserial_number = hr.u.ax.info.serial_number;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200238 return hr.error;
239}
240
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300241u16 hpi_adapter_get_module_by_index(u16 adapter_index, u16 module_index,
242 u16 *pw_num_outputs, u16 *pw_num_inputs, u16 *pw_version,
243 u32 *pserial_number, u16 *pw_module_type, u32 *ph_module)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200244{
245 struct hpi_message hm;
246 struct hpi_response hr;
247
248 hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
249 HPI_ADAPTER_MODULE_INFO);
250 hm.adapter_index = adapter_index;
251 hm.u.ax.module_info.index = module_index;
252
253 hpi_send_recv(&hm, &hr);
254
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300255 *pw_module_type = hr.u.ax.info.adapter_type;
256 *pw_num_outputs = hr.u.ax.info.num_outstreams;
257 *pw_num_inputs = hr.u.ax.info.num_instreams;
258 *pw_version = hr.u.ax.info.version;
259 *pserial_number = hr.u.ax.info.serial_number;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200260 *ph_module = 0;
261
262 return hr.error;
263}
264
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300265u16 hpi_adapter_get_assert2(u16 adapter_index, u16 *p_assert_count,
266 char *psz_assert, u32 *p_param1, u32 *p_param2,
267 u32 *p_dsp_string_addr, u16 *p_processor_id)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200268{
269 struct hpi_message hm;
270 struct hpi_response hr;
271 hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
272 HPI_ADAPTER_GET_ASSERT);
273 hm.adapter_index = adapter_index;
274
275 hpi_send_recv(&hm, &hr);
276
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300277 *p_assert_count = 0;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200278
279 if (!hr.error) {
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300280 *p_assert_count = hr.u.ax.assert.count;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200281
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300282 if (*p_assert_count) {
283 *p_param1 = hr.u.ax.assert.p1;
284 *p_param2 = hr.u.ax.assert.p2;
285 *p_processor_id = hr.u.ax.assert.dsp_index;
286 *p_dsp_string_addr = hr.u.ax.assert.dsp_msg_addr;
287 memcpy(psz_assert, hr.u.ax.assert.sz_message,
288 HPI_STRING_LEN);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200289 } else {
290 *psz_assert = 0;
291 }
292 }
293 return hr.error;
294}
295
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300296u16 hpi_adapter_test_assert(u16 adapter_index, u16 assert_id)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200297{
298 struct hpi_message hm;
299 struct hpi_response hr;
300 hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
301 HPI_ADAPTER_TEST_ASSERT);
302 hm.adapter_index = adapter_index;
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300303 hm.u.ax.test_assert.value = assert_id;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200304
305 hpi_send_recv(&hm, &hr);
306
307 return hr.error;
308}
309
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300310u16 hpi_adapter_enable_capability(u16 adapter_index, u16 capability, u32 key)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200311{
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300312#if 1
313 return HPI_ERROR_UNIMPLEMENTED;
314#else
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200315 struct hpi_message hm;
316 struct hpi_response hr;
317 hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
318 HPI_ADAPTER_ENABLE_CAPABILITY);
319 hm.adapter_index = adapter_index;
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300320 hm.u.ax.enable_cap.cap = capability;
321 hm.u.ax.enable_cap.key = key;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200322
323 hpi_send_recv(&hm, &hr);
324
325 return hr.error;
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300326#endif
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200327}
328
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300329u16 hpi_adapter_self_test(u16 adapter_index)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200330{
331 struct hpi_message hm;
332 struct hpi_response hr;
333 hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
334 HPI_ADAPTER_SELFTEST);
335 hm.adapter_index = adapter_index;
336 hpi_send_recv(&hm, &hr);
337 return hr.error;
338}
339
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300340u16 hpi_adapter_debug_read(u16 adapter_index, u32 dsp_address, char *p_buffer,
341 int *count_bytes)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200342{
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300343 struct hpi_msg_adapter_debug_read hm;
344 struct hpi_res_adapter_debug_read hr;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200345
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300346 hpi_init_message_responseV1(&hm.h, sizeof(hm), &hr.h, sizeof(hr),
347 HPI_OBJ_ADAPTER, HPI_ADAPTER_DEBUG_READ);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200348
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300349 hm.h.adapter_index = adapter_index;
350 hm.dsp_address = dsp_address;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200351
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300352 if (*count_bytes > (int)sizeof(hr.bytes))
353 *count_bytes = (int)sizeof(hr.bytes);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200354
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300355 hm.count_bytes = *count_bytes;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200356
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300357 hpi_send_recvV1(&hm.h, &hr.h);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200358
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300359 if (!hr.h.error) {
360 int res_bytes = hr.h.size - sizeof(hr.h);
361 if (res_bytes > *count_bytes)
362 res_bytes = *count_bytes;
363 *count_bytes = res_bytes;
364 memcpy(p_buffer, &hr.bytes, res_bytes);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200365 } else
366 *count_bytes = 0;
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300367
368 return hr.h.error;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200369}
370
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300371u16 hpi_adapter_set_property(u16 adapter_index, u16 property, u16 parameter1,
372 u16 parameter2)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200373{
374 struct hpi_message hm;
375 struct hpi_response hr;
376 hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
377 HPI_ADAPTER_SET_PROPERTY);
378 hm.adapter_index = adapter_index;
379 hm.u.ax.property_set.property = property;
380 hm.u.ax.property_set.parameter1 = parameter1;
381 hm.u.ax.property_set.parameter2 = parameter2;
382
383 hpi_send_recv(&hm, &hr);
384
385 return hr.error;
386}
387
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300388u16 hpi_adapter_get_property(u16 adapter_index, u16 property,
389 u16 *pw_parameter1, u16 *pw_parameter2)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200390{
391 struct hpi_message hm;
392 struct hpi_response hr;
393 hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
394 HPI_ADAPTER_GET_PROPERTY);
395 hm.adapter_index = adapter_index;
396 hm.u.ax.property_set.property = property;
397
398 hpi_send_recv(&hm, &hr);
399 if (!hr.error) {
400 if (pw_parameter1)
401 *pw_parameter1 = hr.u.ax.property_get.parameter1;
402 if (pw_parameter2)
403 *pw_parameter2 = hr.u.ax.property_get.parameter2;
404 }
405
406 return hr.error;
407}
408
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300409u16 hpi_adapter_enumerate_property(u16 adapter_index, u16 index,
410 u16 what_to_enumerate, u16 property_index, u32 *psetting)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200411{
412 return 0;
413}
414
415u16 hpi_format_create(struct hpi_format *p_format, u16 channels, u16 format,
416 u32 sample_rate, u32 bit_rate, u32 attributes)
417{
418 u16 error = 0;
419 struct hpi_msg_format fmt;
420
421 switch (channels) {
422 case 1:
423 case 2:
424 case 4:
425 case 6:
426 case 8:
427 case 16:
428 break;
429 default:
430 error = HPI_ERROR_INVALID_CHANNELS;
431 return error;
432 }
433 fmt.channels = channels;
434
435 switch (format) {
436 case HPI_FORMAT_PCM16_SIGNED:
437 case HPI_FORMAT_PCM24_SIGNED:
438 case HPI_FORMAT_PCM32_SIGNED:
439 case HPI_FORMAT_PCM32_FLOAT:
440 case HPI_FORMAT_PCM16_BIGENDIAN:
441 case HPI_FORMAT_PCM8_UNSIGNED:
442 case HPI_FORMAT_MPEG_L1:
443 case HPI_FORMAT_MPEG_L2:
444 case HPI_FORMAT_MPEG_L3:
445 case HPI_FORMAT_DOLBY_AC2:
446 case HPI_FORMAT_AA_TAGIT1_HITS:
447 case HPI_FORMAT_AA_TAGIT1_INSERTS:
448 case HPI_FORMAT_RAW_BITSTREAM:
449 case HPI_FORMAT_AA_TAGIT1_HITS_EX1:
450 case HPI_FORMAT_OEM1:
451 case HPI_FORMAT_OEM2:
452 break;
453 default:
454 error = HPI_ERROR_INVALID_FORMAT;
455 return error;
456 }
457 fmt.format = format;
458
459 if (sample_rate < 8000L) {
460 error = HPI_ERROR_INCOMPATIBLE_SAMPLERATE;
461 sample_rate = 8000L;
462 }
463 if (sample_rate > 200000L) {
464 error = HPI_ERROR_INCOMPATIBLE_SAMPLERATE;
465 sample_rate = 200000L;
466 }
467 fmt.sample_rate = sample_rate;
468
469 switch (format) {
470 case HPI_FORMAT_MPEG_L1:
471 case HPI_FORMAT_MPEG_L2:
472 case HPI_FORMAT_MPEG_L3:
473 fmt.bit_rate = bit_rate;
474 break;
475 case HPI_FORMAT_PCM16_SIGNED:
476 case HPI_FORMAT_PCM16_BIGENDIAN:
477 fmt.bit_rate = channels * sample_rate * 2;
478 break;
479 case HPI_FORMAT_PCM32_SIGNED:
480 case HPI_FORMAT_PCM32_FLOAT:
481 fmt.bit_rate = channels * sample_rate * 4;
482 break;
483 case HPI_FORMAT_PCM8_UNSIGNED:
484 fmt.bit_rate = channels * sample_rate;
485 break;
486 default:
487 fmt.bit_rate = 0;
488 }
489
490 switch (format) {
491 case HPI_FORMAT_MPEG_L2:
492 if ((channels == 1)
493 && (attributes != HPI_MPEG_MODE_DEFAULT)) {
494 attributes = HPI_MPEG_MODE_DEFAULT;
495 error = HPI_ERROR_INVALID_FORMAT;
496 } else if (attributes > HPI_MPEG_MODE_DUALCHANNEL) {
497 attributes = HPI_MPEG_MODE_DEFAULT;
498 error = HPI_ERROR_INVALID_FORMAT;
499 }
500 fmt.attributes = attributes;
501 break;
502 default:
503 fmt.attributes = attributes;
504 }
505
506 hpi_msg_to_format(p_format, &fmt);
507 return error;
508}
509
510u16 hpi_stream_estimate_buffer_size(struct hpi_format *p_format,
511 u32 host_polling_rate_in_milli_seconds, u32 *recommended_buffer_size)
512{
513
514 u32 bytes_per_second;
515 u32 size;
516 u16 channels;
517 struct hpi_format *pF = p_format;
518
519 channels = pF->channels;
520
521 switch (pF->format) {
522 case HPI_FORMAT_PCM16_BIGENDIAN:
523 case HPI_FORMAT_PCM16_SIGNED:
524 bytes_per_second = pF->sample_rate * 2L * channels;
525 break;
526 case HPI_FORMAT_PCM24_SIGNED:
527 bytes_per_second = pF->sample_rate * 3L * channels;
528 break;
529 case HPI_FORMAT_PCM32_SIGNED:
530 case HPI_FORMAT_PCM32_FLOAT:
531 bytes_per_second = pF->sample_rate * 4L * channels;
532 break;
533 case HPI_FORMAT_PCM8_UNSIGNED:
534 bytes_per_second = pF->sample_rate * 1L * channels;
535 break;
536 case HPI_FORMAT_MPEG_L1:
537 case HPI_FORMAT_MPEG_L2:
538 case HPI_FORMAT_MPEG_L3:
539 bytes_per_second = pF->bit_rate / 8L;
540 break;
541 case HPI_FORMAT_DOLBY_AC2:
542
543 bytes_per_second = 256000L / 8L;
544 break;
545 default:
546 return HPI_ERROR_INVALID_FORMAT;
547 }
548 size = (bytes_per_second * host_polling_rate_in_milli_seconds * 2) /
549 1000L;
550
551 *recommended_buffer_size =
552 roundup_pow_of_two(((size + 4095L) & ~4095L));
553 return 0;
554}
555
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300556u16 hpi_outstream_open(u16 adapter_index, u16 outstream_index,
557 u32 *ph_outstream)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200558{
559 struct hpi_message hm;
560 struct hpi_response hr;
561 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
562 HPI_OSTREAM_OPEN);
563 hm.adapter_index = adapter_index;
564 hm.obj_index = outstream_index;
565
566 hpi_send_recv(&hm, &hr);
567
568 if (hr.error == 0)
569 *ph_outstream =
570 hpi_indexes_to_handle(HPI_OBJ_OSTREAM, adapter_index,
571 outstream_index);
572 else
573 *ph_outstream = 0;
574 return hr.error;
575}
576
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300577u16 hpi_outstream_close(u32 h_outstream)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200578{
579 struct hpi_message hm;
580 struct hpi_response hr;
581
582 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
583 HPI_OSTREAM_HOSTBUFFER_FREE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300584 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
585 return HPI_ERROR_INVALID_HANDLE;
586
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200587 hpi_send_recv(&hm, &hr);
588
589 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
590 HPI_OSTREAM_GROUP_RESET);
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300591 hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200592 hpi_send_recv(&hm, &hr);
593
594 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
595 HPI_OSTREAM_CLOSE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300596 hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200597 hpi_send_recv(&hm, &hr);
598
599 return hr.error;
600}
601
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300602u16 hpi_outstream_get_info_ex(u32 h_outstream, u16 *pw_state,
603 u32 *pbuffer_size, u32 *pdata_to_play, u32 *psamples_played,
604 u32 *pauxiliary_data_to_play)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200605{
606 struct hpi_message hm;
607 struct hpi_response hr;
608 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
609 HPI_OSTREAM_GET_INFO);
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300610 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
611 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200612
613 hpi_send_recv(&hm, &hr);
614
615 if (pw_state)
616 *pw_state = hr.u.d.u.stream_info.state;
617 if (pbuffer_size)
618 *pbuffer_size = hr.u.d.u.stream_info.buffer_size;
619 if (pdata_to_play)
620 *pdata_to_play = hr.u.d.u.stream_info.data_available;
621 if (psamples_played)
622 *psamples_played = hr.u.d.u.stream_info.samples_transferred;
623 if (pauxiliary_data_to_play)
624 *pauxiliary_data_to_play =
625 hr.u.d.u.stream_info.auxiliary_data_available;
626 return hr.error;
627}
628
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300629u16 hpi_outstream_write_buf(u32 h_outstream, const u8 *pb_data,
630 u32 bytes_to_write, const struct hpi_format *p_format)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200631{
632 struct hpi_message hm;
633 struct hpi_response hr;
634 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
635 HPI_OSTREAM_WRITE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300636 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
637 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200638 hm.u.d.u.data.pb_data = (u8 *)pb_data;
639 hm.u.d.u.data.data_size = bytes_to_write;
640
641 hpi_format_to_msg(&hm.u.d.u.data.format, p_format);
642
643 hpi_send_recv(&hm, &hr);
644
645 return hr.error;
646}
647
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300648u16 hpi_outstream_start(u32 h_outstream)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200649{
650 struct hpi_message hm;
651 struct hpi_response hr;
652 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
653 HPI_OSTREAM_START);
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300654 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
655 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200656
657 hpi_send_recv(&hm, &hr);
658
659 return hr.error;
660}
661
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300662u16 hpi_outstream_wait_start(u32 h_outstream)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200663{
664 struct hpi_message hm;
665 struct hpi_response hr;
666 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
667 HPI_OSTREAM_WAIT_START);
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300668 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
669 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200670
671 hpi_send_recv(&hm, &hr);
672
673 return hr.error;
674}
675
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300676u16 hpi_outstream_stop(u32 h_outstream)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200677{
678 struct hpi_message hm;
679 struct hpi_response hr;
680 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
681 HPI_OSTREAM_STOP);
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300682 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
683 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200684
685 hpi_send_recv(&hm, &hr);
686
687 return hr.error;
688}
689
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300690u16 hpi_outstream_sinegen(u32 h_outstream)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200691{
692 struct hpi_message hm;
693 struct hpi_response hr;
694 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
695 HPI_OSTREAM_SINEGEN);
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300696 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
697 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200698
699 hpi_send_recv(&hm, &hr);
700
701 return hr.error;
702}
703
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300704u16 hpi_outstream_reset(u32 h_outstream)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200705{
706 struct hpi_message hm;
707 struct hpi_response hr;
708 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
709 HPI_OSTREAM_RESET);
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300710 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
711 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200712
713 hpi_send_recv(&hm, &hr);
714
715 return hr.error;
716}
717
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300718u16 hpi_outstream_query_format(u32 h_outstream, struct hpi_format *p_format)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200719{
720 struct hpi_message hm;
721 struct hpi_response hr;
722
723 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
724 HPI_OSTREAM_QUERY_FORMAT);
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300725 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
726 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200727
728 hpi_format_to_msg(&hm.u.d.u.data.format, p_format);
729
730 hpi_send_recv(&hm, &hr);
731
732 return hr.error;
733}
734
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300735u16 hpi_outstream_set_format(u32 h_outstream, struct hpi_format *p_format)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200736{
737 struct hpi_message hm;
738 struct hpi_response hr;
739
740 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
741 HPI_OSTREAM_SET_FORMAT);
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300742 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
743 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200744
745 hpi_format_to_msg(&hm.u.d.u.data.format, p_format);
746
747 hpi_send_recv(&hm, &hr);
748
749 return hr.error;
750}
751
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300752u16 hpi_outstream_set_velocity(u32 h_outstream, short velocity)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200753{
754 struct hpi_message hm;
755 struct hpi_response hr;
756
757 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
758 HPI_OSTREAM_SET_VELOCITY);
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300759 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
760 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200761 hm.u.d.u.velocity = velocity;
762
763 hpi_send_recv(&hm, &hr);
764
765 return hr.error;
766}
767
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300768u16 hpi_outstream_set_punch_in_out(u32 h_outstream, u32 punch_in_sample,
769 u32 punch_out_sample)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200770{
771 struct hpi_message hm;
772 struct hpi_response hr;
773
774 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
775 HPI_OSTREAM_SET_PUNCHINOUT);
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300776 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
777 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200778
779 hm.u.d.u.pio.punch_in_sample = punch_in_sample;
780 hm.u.d.u.pio.punch_out_sample = punch_out_sample;
781
782 hpi_send_recv(&hm, &hr);
783
784 return hr.error;
785}
786
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300787u16 hpi_outstream_ancillary_reset(u32 h_outstream, u16 mode)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200788{
789 struct hpi_message hm;
790 struct hpi_response hr;
791
792 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
793 HPI_OSTREAM_ANC_RESET);
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300794 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
795 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200796 hm.u.d.u.data.format.channels = mode;
797 hpi_send_recv(&hm, &hr);
798 return hr.error;
799}
800
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300801u16 hpi_outstream_ancillary_get_info(u32 h_outstream, u32 *pframes_available)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200802{
803 struct hpi_message hm;
804 struct hpi_response hr;
805
806 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
807 HPI_OSTREAM_ANC_GET_INFO);
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300808 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
809 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200810 hpi_send_recv(&hm, &hr);
811 if (hr.error == 0) {
812 if (pframes_available)
813 *pframes_available =
814 hr.u.d.u.stream_info.data_available /
815 sizeof(struct hpi_anc_frame);
816 }
817 return hr.error;
818}
819
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300820u16 hpi_outstream_ancillary_read(u32 h_outstream,
821 struct hpi_anc_frame *p_anc_frame_buffer,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200822 u32 anc_frame_buffer_size_in_bytes,
823 u32 number_of_ancillary_frames_to_read)
824{
825 struct hpi_message hm;
826 struct hpi_response hr;
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +1200827
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200828 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
829 HPI_OSTREAM_ANC_READ);
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300830 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
831 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200832 hm.u.d.u.data.pb_data = (u8 *)p_anc_frame_buffer;
833 hm.u.d.u.data.data_size =
834 number_of_ancillary_frames_to_read *
835 sizeof(struct hpi_anc_frame);
836 if (hm.u.d.u.data.data_size <= anc_frame_buffer_size_in_bytes)
837 hpi_send_recv(&hm, &hr);
838 else
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300839 hr.error = HPI_ERROR_INVALID_DATASIZE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200840 return hr.error;
841}
842
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300843u16 hpi_outstream_set_time_scale(u32 h_outstream, u32 time_scale)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200844{
845 struct hpi_message hm;
846 struct hpi_response hr;
847
848 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
849 HPI_OSTREAM_SET_TIMESCALE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300850 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
851 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200852
853 hm.u.d.u.time_scale = time_scale;
854
855 hpi_send_recv(&hm, &hr);
856
857 return hr.error;
858}
859
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300860u16 hpi_outstream_host_buffer_allocate(u32 h_outstream, u32 size_in_bytes)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200861{
862 struct hpi_message hm;
863 struct hpi_response hr;
864
865 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
866 HPI_OSTREAM_HOSTBUFFER_ALLOC);
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300867 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
868 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200869 hm.u.d.u.data.data_size = size_in_bytes;
870 hpi_send_recv(&hm, &hr);
871 return hr.error;
872}
873
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300874u16 hpi_outstream_host_buffer_get_info(u32 h_outstream, u8 **pp_buffer,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200875 struct hpi_hostbuffer_status **pp_status)
876{
877 struct hpi_message hm;
878 struct hpi_response hr;
879
880 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
881 HPI_OSTREAM_HOSTBUFFER_GET_INFO);
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300882 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
883 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200884 hpi_send_recv(&hm, &hr);
885
886 if (hr.error == 0) {
887 if (pp_buffer)
888 *pp_buffer = hr.u.d.u.hostbuffer_info.p_buffer;
889 if (pp_status)
890 *pp_status = hr.u.d.u.hostbuffer_info.p_status;
891 }
892 return hr.error;
893}
894
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300895u16 hpi_outstream_host_buffer_free(u32 h_outstream)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200896{
897 struct hpi_message hm;
898 struct hpi_response hr;
899
900 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
901 HPI_OSTREAM_HOSTBUFFER_FREE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300902 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
903 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200904 hpi_send_recv(&hm, &hr);
905 return hr.error;
906}
907
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300908u16 hpi_outstream_group_add(u32 h_outstream, u32 h_stream)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200909{
910 struct hpi_message hm;
911 struct hpi_response hr;
912 u16 adapter;
913 char c_obj_type;
914
915 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
916 HPI_OSTREAM_GROUP_ADD);
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300917
918 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
919 return HPI_ERROR_INVALID_HANDLE;
920
921 if (hpi_handle_indexes(h_stream, &adapter,
922 &hm.u.d.u.stream.stream_index))
923 return HPI_ERROR_INVALID_HANDLE;
924
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200925 c_obj_type = hpi_handle_object(h_stream);
926 switch (c_obj_type) {
927 case HPI_OBJ_OSTREAM:
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200928 case HPI_OBJ_ISTREAM:
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300929 hm.u.d.u.stream.object_type = c_obj_type;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200930 break;
931 default:
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300932 return HPI_ERROR_INVALID_OBJ;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200933 }
934 if (adapter != hm.adapter_index)
935 return HPI_ERROR_NO_INTERADAPTER_GROUPS;
936
937 hpi_send_recv(&hm, &hr);
938 return hr.error;
939}
940
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300941u16 hpi_outstream_group_get_map(u32 h_outstream, u32 *poutstream_map,
942 u32 *pinstream_map)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200943{
944 struct hpi_message hm;
945 struct hpi_response hr;
946
947 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
948 HPI_OSTREAM_GROUP_GETMAP);
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300949 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
950 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200951 hpi_send_recv(&hm, &hr);
952
953 if (poutstream_map)
954 *poutstream_map = hr.u.d.u.group_info.outstream_group_map;
955 if (pinstream_map)
956 *pinstream_map = hr.u.d.u.group_info.instream_group_map;
957
958 return hr.error;
959}
960
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300961u16 hpi_outstream_group_reset(u32 h_outstream)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200962{
963 struct hpi_message hm;
964 struct hpi_response hr;
965
966 hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
967 HPI_OSTREAM_GROUP_RESET);
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300968 if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
969 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200970 hpi_send_recv(&hm, &hr);
971 return hr.error;
972}
973
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300974u16 hpi_instream_open(u16 adapter_index, u16 instream_index, u32 *ph_instream)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200975{
976 struct hpi_message hm;
977 struct hpi_response hr;
978
979 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
980 HPI_ISTREAM_OPEN);
981 hm.adapter_index = adapter_index;
982 hm.obj_index = instream_index;
983
984 hpi_send_recv(&hm, &hr);
985
986 if (hr.error == 0)
987 *ph_instream =
988 hpi_indexes_to_handle(HPI_OBJ_ISTREAM, adapter_index,
989 instream_index);
990 else
991 *ph_instream = 0;
992
993 return hr.error;
994}
995
Eliot Blennerhassettba944552011-02-10 17:26:04 +1300996u16 hpi_instream_close(u32 h_instream)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200997{
998 struct hpi_message hm;
999 struct hpi_response hr;
1000
1001 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1002 HPI_ISTREAM_HOSTBUFFER_FREE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001003 if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
1004 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001005 hpi_send_recv(&hm, &hr);
1006
1007 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1008 HPI_ISTREAM_GROUP_RESET);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001009 hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001010 hpi_send_recv(&hm, &hr);
1011
1012 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1013 HPI_ISTREAM_CLOSE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001014 hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001015 hpi_send_recv(&hm, &hr);
1016
1017 return hr.error;
1018}
1019
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001020u16 hpi_instream_query_format(u32 h_instream,
1021 const struct hpi_format *p_format)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001022{
1023 struct hpi_message hm;
1024 struct hpi_response hr;
1025
1026 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1027 HPI_ISTREAM_QUERY_FORMAT);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001028 if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
1029 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001030 hpi_format_to_msg(&hm.u.d.u.data.format, p_format);
1031
1032 hpi_send_recv(&hm, &hr);
1033
1034 return hr.error;
1035}
1036
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001037u16 hpi_instream_set_format(u32 h_instream, const struct hpi_format *p_format)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001038{
1039 struct hpi_message hm;
1040 struct hpi_response hr;
1041
1042 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1043 HPI_ISTREAM_SET_FORMAT);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001044 if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
1045 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001046 hpi_format_to_msg(&hm.u.d.u.data.format, p_format);
1047
1048 hpi_send_recv(&hm, &hr);
1049
1050 return hr.error;
1051}
1052
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001053u16 hpi_instream_read_buf(u32 h_instream, u8 *pb_data, u32 bytes_to_read)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001054{
1055 struct hpi_message hm;
1056 struct hpi_response hr;
1057
1058 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1059 HPI_ISTREAM_READ);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001060 if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
1061 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001062 hm.u.d.u.data.data_size = bytes_to_read;
1063 hm.u.d.u.data.pb_data = pb_data;
1064
1065 hpi_send_recv(&hm, &hr);
1066
1067 return hr.error;
1068}
1069
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001070u16 hpi_instream_start(u32 h_instream)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001071{
1072 struct hpi_message hm;
1073 struct hpi_response hr;
1074
1075 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1076 HPI_ISTREAM_START);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001077 if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
1078 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001079
1080 hpi_send_recv(&hm, &hr);
1081
1082 return hr.error;
1083}
1084
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001085u16 hpi_instream_wait_start(u32 h_instream)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001086{
1087 struct hpi_message hm;
1088 struct hpi_response hr;
1089
1090 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1091 HPI_ISTREAM_WAIT_START);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001092 if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
1093 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001094
1095 hpi_send_recv(&hm, &hr);
1096
1097 return hr.error;
1098}
1099
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001100u16 hpi_instream_stop(u32 h_instream)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001101{
1102 struct hpi_message hm;
1103 struct hpi_response hr;
1104
1105 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1106 HPI_ISTREAM_STOP);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001107 if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
1108 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001109
1110 hpi_send_recv(&hm, &hr);
1111
1112 return hr.error;
1113}
1114
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001115u16 hpi_instream_reset(u32 h_instream)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001116{
1117 struct hpi_message hm;
1118 struct hpi_response hr;
1119
1120 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1121 HPI_ISTREAM_RESET);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001122 if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
1123 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001124
1125 hpi_send_recv(&hm, &hr);
1126
1127 return hr.error;
1128}
1129
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001130u16 hpi_instream_get_info_ex(u32 h_instream, u16 *pw_state, u32 *pbuffer_size,
1131 u32 *pdata_recorded, u32 *psamples_recorded,
1132 u32 *pauxiliary_data_recorded)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001133{
1134 struct hpi_message hm;
1135 struct hpi_response hr;
1136 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1137 HPI_ISTREAM_GET_INFO);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001138 if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
1139 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001140
1141 hpi_send_recv(&hm, &hr);
1142
1143 if (pw_state)
1144 *pw_state = hr.u.d.u.stream_info.state;
1145 if (pbuffer_size)
1146 *pbuffer_size = hr.u.d.u.stream_info.buffer_size;
1147 if (pdata_recorded)
1148 *pdata_recorded = hr.u.d.u.stream_info.data_available;
1149 if (psamples_recorded)
1150 *psamples_recorded = hr.u.d.u.stream_info.samples_transferred;
1151 if (pauxiliary_data_recorded)
1152 *pauxiliary_data_recorded =
1153 hr.u.d.u.stream_info.auxiliary_data_available;
1154 return hr.error;
1155}
1156
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001157u16 hpi_instream_ancillary_reset(u32 h_instream, u16 bytes_per_frame,
1158 u16 mode, u16 alignment, u16 idle_bit)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001159{
1160 struct hpi_message hm;
1161 struct hpi_response hr;
1162 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1163 HPI_ISTREAM_ANC_RESET);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001164 if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
1165 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001166 hm.u.d.u.data.format.attributes = bytes_per_frame;
1167 hm.u.d.u.data.format.format = (mode << 8) | (alignment & 0xff);
1168 hm.u.d.u.data.format.channels = idle_bit;
1169 hpi_send_recv(&hm, &hr);
1170 return hr.error;
1171}
1172
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001173u16 hpi_instream_ancillary_get_info(u32 h_instream, u32 *pframe_space)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001174{
1175 struct hpi_message hm;
1176 struct hpi_response hr;
1177 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1178 HPI_ISTREAM_ANC_GET_INFO);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001179 if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
1180 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001181 hpi_send_recv(&hm, &hr);
1182 if (pframe_space)
1183 *pframe_space =
1184 (hr.u.d.u.stream_info.buffer_size -
1185 hr.u.d.u.stream_info.data_available) /
1186 sizeof(struct hpi_anc_frame);
1187 return hr.error;
1188}
1189
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001190u16 hpi_instream_ancillary_write(u32 h_instream,
1191 const struct hpi_anc_frame *p_anc_frame_buffer,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001192 u32 anc_frame_buffer_size_in_bytes,
1193 u32 number_of_ancillary_frames_to_write)
1194{
1195 struct hpi_message hm;
1196 struct hpi_response hr;
1197
1198 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1199 HPI_ISTREAM_ANC_WRITE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001200 if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
1201 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001202 hm.u.d.u.data.pb_data = (u8 *)p_anc_frame_buffer;
1203 hm.u.d.u.data.data_size =
1204 number_of_ancillary_frames_to_write *
1205 sizeof(struct hpi_anc_frame);
1206 if (hm.u.d.u.data.data_size <= anc_frame_buffer_size_in_bytes)
1207 hpi_send_recv(&hm, &hr);
1208 else
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001209 hr.error = HPI_ERROR_INVALID_DATASIZE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001210 return hr.error;
1211}
1212
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001213u16 hpi_instream_host_buffer_allocate(u32 h_instream, u32 size_in_bytes)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001214{
1215
1216 struct hpi_message hm;
1217 struct hpi_response hr;
1218
1219 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1220 HPI_ISTREAM_HOSTBUFFER_ALLOC);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001221 if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
1222 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001223 hm.u.d.u.data.data_size = size_in_bytes;
1224 hpi_send_recv(&hm, &hr);
1225 return hr.error;
1226}
1227
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001228u16 hpi_instream_host_buffer_get_info(u32 h_instream, u8 **pp_buffer,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001229 struct hpi_hostbuffer_status **pp_status)
1230{
1231 struct hpi_message hm;
1232 struct hpi_response hr;
1233
1234 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1235 HPI_ISTREAM_HOSTBUFFER_GET_INFO);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001236 if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
1237 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001238 hpi_send_recv(&hm, &hr);
1239
1240 if (hr.error == 0) {
1241 if (pp_buffer)
1242 *pp_buffer = hr.u.d.u.hostbuffer_info.p_buffer;
1243 if (pp_status)
1244 *pp_status = hr.u.d.u.hostbuffer_info.p_status;
1245 }
1246 return hr.error;
1247}
1248
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001249u16 hpi_instream_host_buffer_free(u32 h_instream)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001250{
1251
1252 struct hpi_message hm;
1253 struct hpi_response hr;
1254
1255 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1256 HPI_ISTREAM_HOSTBUFFER_FREE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001257 if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
1258 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001259 hpi_send_recv(&hm, &hr);
1260 return hr.error;
1261}
1262
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001263u16 hpi_instream_group_add(u32 h_instream, u32 h_stream)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001264{
1265 struct hpi_message hm;
1266 struct hpi_response hr;
1267 u16 adapter;
1268 char c_obj_type;
1269
1270 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1271 HPI_ISTREAM_GROUP_ADD);
1272 hr.error = 0;
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001273
1274 if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
1275 return HPI_ERROR_INVALID_HANDLE;
1276
1277 if (hpi_handle_indexes(h_stream, &adapter,
1278 &hm.u.d.u.stream.stream_index))
1279 return HPI_ERROR_INVALID_HANDLE;
1280
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001281 c_obj_type = hpi_handle_object(h_stream);
1282
1283 switch (c_obj_type) {
1284 case HPI_OBJ_OSTREAM:
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001285 case HPI_OBJ_ISTREAM:
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001286 hm.u.d.u.stream.object_type = c_obj_type;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001287 break;
1288 default:
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001289 return HPI_ERROR_INVALID_OBJ;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001290 }
1291
1292 if (adapter != hm.adapter_index)
1293 return HPI_ERROR_NO_INTERADAPTER_GROUPS;
1294
1295 hpi_send_recv(&hm, &hr);
1296 return hr.error;
1297}
1298
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001299u16 hpi_instream_group_get_map(u32 h_instream, u32 *poutstream_map,
1300 u32 *pinstream_map)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001301{
1302 struct hpi_message hm;
1303 struct hpi_response hr;
1304
1305 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1306 HPI_ISTREAM_HOSTBUFFER_FREE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001307 if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
1308 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001309 hpi_send_recv(&hm, &hr);
1310
1311 if (poutstream_map)
1312 *poutstream_map = hr.u.d.u.group_info.outstream_group_map;
1313 if (pinstream_map)
1314 *pinstream_map = hr.u.d.u.group_info.instream_group_map;
1315
1316 return hr.error;
1317}
1318
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001319u16 hpi_instream_group_reset(u32 h_instream)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001320{
1321 struct hpi_message hm;
1322 struct hpi_response hr;
1323
1324 hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
1325 HPI_ISTREAM_GROUP_RESET);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001326 if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
1327 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001328 hpi_send_recv(&hm, &hr);
1329 return hr.error;
1330}
1331
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001332u16 hpi_mixer_open(u16 adapter_index, u32 *ph_mixer)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001333{
1334 struct hpi_message hm;
1335 struct hpi_response hr;
1336 hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER, HPI_MIXER_OPEN);
1337 hm.adapter_index = adapter_index;
1338
1339 hpi_send_recv(&hm, &hr);
1340
1341 if (hr.error == 0)
1342 *ph_mixer =
1343 hpi_indexes_to_handle(HPI_OBJ_MIXER, adapter_index,
1344 0);
1345 else
1346 *ph_mixer = 0;
1347 return hr.error;
1348}
1349
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001350u16 hpi_mixer_close(u32 h_mixer)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001351{
1352 struct hpi_message hm;
1353 struct hpi_response hr;
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001354
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001355 hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER, HPI_MIXER_CLOSE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001356 if (hpi_handle_indexes(h_mixer, &hm.adapter_index, NULL))
1357 return HPI_ERROR_INVALID_HANDLE;
1358
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001359 hpi_send_recv(&hm, &hr);
1360 return hr.error;
1361}
1362
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001363u16 hpi_mixer_get_control(u32 h_mixer, u16 src_node_type,
1364 u16 src_node_type_index, u16 dst_node_type, u16 dst_node_type_index,
1365 u16 control_type, u32 *ph_control)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001366{
1367 struct hpi_message hm;
1368 struct hpi_response hr;
1369 hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER,
1370 HPI_MIXER_GET_CONTROL);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001371 if (hpi_handle_indexes(h_mixer, &hm.adapter_index, NULL))
1372 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001373 hm.u.m.node_type1 = src_node_type;
1374 hm.u.m.node_index1 = src_node_type_index;
1375 hm.u.m.node_type2 = dst_node_type;
1376 hm.u.m.node_index2 = dst_node_type_index;
1377 hm.u.m.control_type = control_type;
1378
1379 hpi_send_recv(&hm, &hr);
1380
1381 if (hr.error == 0)
1382 *ph_control =
1383 hpi_indexes_to_handle(HPI_OBJ_CONTROL,
1384 hm.adapter_index, hr.u.m.control_index);
1385 else
1386 *ph_control = 0;
1387 return hr.error;
1388}
1389
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001390u16 hpi_mixer_get_control_by_index(u32 h_mixer, u16 control_index,
1391 u16 *pw_src_node_type, u16 *pw_src_node_index, u16 *pw_dst_node_type,
1392 u16 *pw_dst_node_index, u16 *pw_control_type, u32 *ph_control)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001393{
1394 struct hpi_message hm;
1395 struct hpi_response hr;
1396 hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER,
1397 HPI_MIXER_GET_CONTROL_BY_INDEX);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001398 if (hpi_handle_indexes(h_mixer, &hm.adapter_index, NULL))
1399 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001400 hm.u.m.control_index = control_index;
1401 hpi_send_recv(&hm, &hr);
1402
1403 if (pw_src_node_type) {
1404 *pw_src_node_type =
1405 hr.u.m.src_node_type + HPI_SOURCENODE_NONE;
1406 *pw_src_node_index = hr.u.m.src_node_index;
1407 *pw_dst_node_type = hr.u.m.dst_node_type + HPI_DESTNODE_NONE;
1408 *pw_dst_node_index = hr.u.m.dst_node_index;
1409 }
1410 if (pw_control_type)
1411 *pw_control_type = hr.u.m.control_index;
1412
1413 if (ph_control) {
1414 if (hr.error == 0)
1415 *ph_control =
1416 hpi_indexes_to_handle(HPI_OBJ_CONTROL,
1417 hm.adapter_index, control_index);
1418 else
1419 *ph_control = 0;
1420 }
1421 return hr.error;
1422}
1423
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001424u16 hpi_mixer_store(u32 h_mixer, enum HPI_MIXER_STORE_COMMAND command,
1425 u16 index)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001426{
1427 struct hpi_message hm;
1428 struct hpi_response hr;
1429 hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER, HPI_MIXER_STORE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001430 if (hpi_handle_indexes(h_mixer, &hm.adapter_index, NULL))
1431 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001432 hm.u.mx.store.command = command;
1433 hm.u.mx.store.index = index;
1434 hpi_send_recv(&hm, &hr);
1435 return hr.error;
1436}
1437
1438static
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001439u16 hpi_control_param_set(const u32 h_control, const u16 attrib,
1440 const u32 param1, const u32 param2)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001441{
1442 struct hpi_message hm;
1443 struct hpi_response hr;
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12001444
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001445 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
1446 HPI_CONTROL_SET_STATE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001447 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
1448 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001449 hm.u.c.attribute = attrib;
1450 hm.u.c.param1 = param1;
1451 hm.u.c.param2 = param2;
1452 hpi_send_recv(&hm, &hr);
1453 return hr.error;
1454}
1455
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12001456static u16 hpi_control_log_set2(u32 h_control, u16 attrib, short sv0,
1457 short sv1)
1458{
1459 struct hpi_message hm;
1460 struct hpi_response hr;
1461
1462 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
1463 HPI_CONTROL_SET_STATE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001464 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
1465 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12001466 hm.u.c.attribute = attrib;
1467 hm.u.c.an_log_value[0] = sv0;
1468 hm.u.c.an_log_value[1] = sv1;
1469 hpi_send_recv(&hm, &hr);
1470 return hr.error;
1471}
1472
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001473static
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001474u16 hpi_control_param_get(const u32 h_control, const u16 attrib, u32 param1,
1475 u32 param2, u32 *pparam1, u32 *pparam2)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001476{
1477 struct hpi_message hm;
1478 struct hpi_response hr;
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12001479
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001480 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
1481 HPI_CONTROL_GET_STATE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001482 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
1483 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001484 hm.u.c.attribute = attrib;
1485 hm.u.c.param1 = param1;
1486 hm.u.c.param2 = param2;
1487 hpi_send_recv(&hm, &hr);
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12001488
1489 *pparam1 = hr.u.c.param1;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001490 if (pparam2)
1491 *pparam2 = hr.u.c.param2;
1492
1493 return hr.error;
1494}
1495
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001496#define hpi_control_param1_get(h, a, p1) \
1497 hpi_control_param_get(h, a, 0, 0, p1, NULL)
1498#define hpi_control_param2_get(h, a, p1, p2) \
1499 hpi_control_param_get(h, a, 0, 0, p1, p2)
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12001500
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001501static u16 hpi_control_log_get2(u32 h_control, u16 attrib, short *sv0,
1502 short *sv1)
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12001503{
1504 struct hpi_message hm;
1505 struct hpi_response hr;
1506 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
1507 HPI_CONTROL_GET_STATE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001508 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
1509 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12001510 hm.u.c.attribute = attrib;
1511
1512 hpi_send_recv(&hm, &hr);
1513 *sv0 = hr.u.c.an_log_value[0];
1514 if (sv1)
1515 *sv1 = hr.u.c.an_log_value[1];
1516 return hr.error;
1517}
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001518
1519static
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001520u16 hpi_control_query(const u32 h_control, const u16 attrib, const u32 index,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001521 const u32 param, u32 *psetting)
1522{
1523 struct hpi_message hm;
1524 struct hpi_response hr;
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12001525
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001526 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
1527 HPI_CONTROL_GET_INFO);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001528 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
1529 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001530
1531 hm.u.c.attribute = attrib;
1532 hm.u.c.param1 = index;
1533 hm.u.c.param2 = param;
1534
1535 hpi_send_recv(&hm, &hr);
1536 *psetting = hr.u.c.param1;
1537
1538 return hr.error;
1539}
1540
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12001541static u16 hpi_control_get_string(const u32 h_control, const u16 attribute,
1542 char *psz_string, const u32 string_length)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001543{
1544 unsigned int sub_string_index = 0, j = 0;
1545 char c = 0;
1546 unsigned int n = 0;
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13001547 u16 err = 0;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001548
1549 if ((string_length < 1) || (string_length > 256))
1550 return HPI_ERROR_INVALID_CONTROL_VALUE;
1551 for (sub_string_index = 0; sub_string_index < string_length;
1552 sub_string_index += 8) {
1553 struct hpi_message hm;
1554 struct hpi_response hr;
1555
1556 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
1557 HPI_CONTROL_GET_STATE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001558 if (hpi_handle_indexes(h_control, &hm.adapter_index,
1559 &hm.obj_index))
1560 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001561 hm.u.c.attribute = attribute;
1562 hm.u.c.param1 = sub_string_index;
1563 hm.u.c.param2 = 0;
1564 hpi_send_recv(&hm, &hr);
1565
1566 if (sub_string_index == 0
1567 && (hr.u.cu.chars8.remaining_chars + 8) >
1568 string_length)
1569 return HPI_ERROR_INVALID_CONTROL_VALUE;
1570
1571 if (hr.error) {
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13001572 err = hr.error;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001573 break;
1574 }
1575 for (j = 0; j < 8; j++) {
1576 c = hr.u.cu.chars8.sz_data[j];
1577 psz_string[sub_string_index + j] = c;
1578 n++;
1579 if (n >= string_length) {
1580 psz_string[string_length - 1] = 0;
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13001581 err = HPI_ERROR_INVALID_CONTROL_VALUE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001582 break;
1583 }
1584 if (c == 0)
1585 break;
1586 }
1587
1588 if ((hr.u.cu.chars8.remaining_chars == 0)
1589 && ((sub_string_index + j) < string_length)
1590 && (c != 0)) {
1591 c = 0;
1592 psz_string[sub_string_index + j] = c;
1593 }
1594 if (c == 0)
1595 break;
1596 }
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13001597 return err;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001598}
1599
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001600u16 hpi_aesebu_receiver_query_format(const u32 h_aes_rx, const u32 index,
1601 u16 *pw_format)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001602{
1603 u32 qr;
1604 u16 err;
1605
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001606 err = hpi_control_query(h_aes_rx, HPI_AESEBURX_FORMAT, index, 0, &qr);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001607 *pw_format = (u16)qr;
1608 return err;
1609}
1610
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001611u16 hpi_aesebu_receiver_set_format(u32 h_control, u16 format)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001612{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001613 return hpi_control_param_set(h_control, HPI_AESEBURX_FORMAT, format,
1614 0);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001615}
1616
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001617u16 hpi_aesebu_receiver_get_format(u32 h_control, u16 *pw_format)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001618{
1619 u16 err;
1620 u32 param;
1621
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001622 err = hpi_control_param1_get(h_control, HPI_AESEBURX_FORMAT, &param);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001623 if (!err && pw_format)
1624 *pw_format = (u16)param;
1625
1626 return err;
1627}
1628
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001629u16 hpi_aesebu_receiver_get_sample_rate(u32 h_control, u32 *psample_rate)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001630{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001631 return hpi_control_param1_get(h_control, HPI_AESEBURX_SAMPLERATE,
1632 psample_rate);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001633}
1634
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001635u16 hpi_aesebu_receiver_get_user_data(u32 h_control, u16 index, u16 *pw_data)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001636{
1637 struct hpi_message hm;
1638 struct hpi_response hr;
1639 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
1640 HPI_CONTROL_GET_STATE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001641 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
1642 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001643 hm.u.c.attribute = HPI_AESEBURX_USERDATA;
1644 hm.u.c.param1 = index;
1645
1646 hpi_send_recv(&hm, &hr);
1647
1648 if (pw_data)
1649 *pw_data = (u16)hr.u.c.param2;
1650 return hr.error;
1651}
1652
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001653u16 hpi_aesebu_receiver_get_channel_status(u32 h_control, u16 index,
1654 u16 *pw_data)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001655{
1656 struct hpi_message hm;
1657 struct hpi_response hr;
1658 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
1659 HPI_CONTROL_GET_STATE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001660 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
1661 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001662 hm.u.c.attribute = HPI_AESEBURX_CHANNELSTATUS;
1663 hm.u.c.param1 = index;
1664
1665 hpi_send_recv(&hm, &hr);
1666
1667 if (pw_data)
1668 *pw_data = (u16)hr.u.c.param2;
1669 return hr.error;
1670}
1671
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001672u16 hpi_aesebu_receiver_get_error_status(u32 h_control, u16 *pw_error_data)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001673{
1674 u32 error_data = 0;
1675 u16 error = 0;
1676
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001677 error = hpi_control_param1_get(h_control, HPI_AESEBURX_ERRORSTATUS,
1678 &error_data);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001679 if (pw_error_data)
1680 *pw_error_data = (u16)error_data;
1681 return error;
1682}
1683
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001684u16 hpi_aesebu_transmitter_set_sample_rate(u32 h_control, u32 sample_rate)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001685{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001686 return hpi_control_param_set(h_control, HPI_AESEBUTX_SAMPLERATE,
1687 sample_rate, 0);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001688}
1689
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001690u16 hpi_aesebu_transmitter_set_user_data(u32 h_control, u16 index, u16 data)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001691{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001692 return hpi_control_param_set(h_control, HPI_AESEBUTX_USERDATA, index,
1693 data);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001694}
1695
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001696u16 hpi_aesebu_transmitter_set_channel_status(u32 h_control, u16 index,
1697 u16 data)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001698{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001699 return hpi_control_param_set(h_control, HPI_AESEBUTX_CHANNELSTATUS,
1700 index, data);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001701}
1702
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001703u16 hpi_aesebu_transmitter_get_channel_status(u32 h_control, u16 index,
1704 u16 *pw_data)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001705{
1706 return HPI_ERROR_INVALID_OPERATION;
1707}
1708
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001709u16 hpi_aesebu_transmitter_query_format(const u32 h_aes_tx, const u32 index,
1710 u16 *pw_format)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001711{
1712 u32 qr;
1713 u16 err;
1714
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001715 err = hpi_control_query(h_aes_tx, HPI_AESEBUTX_FORMAT, index, 0, &qr);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001716 *pw_format = (u16)qr;
1717 return err;
1718}
1719
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001720u16 hpi_aesebu_transmitter_set_format(u32 h_control, u16 output_format)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001721{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001722 return hpi_control_param_set(h_control, HPI_AESEBUTX_FORMAT,
1723 output_format, 0);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001724}
1725
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001726u16 hpi_aesebu_transmitter_get_format(u32 h_control, u16 *pw_output_format)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001727{
1728 u16 err;
1729 u32 param;
1730
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001731 err = hpi_control_param1_get(h_control, HPI_AESEBUTX_FORMAT, &param);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001732 if (!err && pw_output_format)
1733 *pw_output_format = (u16)param;
1734
1735 return err;
1736}
1737
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001738u16 hpi_bitstream_set_clock_edge(u32 h_control, u16 edge_type)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001739{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001740 return hpi_control_param_set(h_control, HPI_BITSTREAM_CLOCK_EDGE,
1741 edge_type, 0);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001742}
1743
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001744u16 hpi_bitstream_set_data_polarity(u32 h_control, u16 polarity)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001745{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001746 return hpi_control_param_set(h_control, HPI_BITSTREAM_DATA_POLARITY,
1747 polarity, 0);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001748}
1749
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001750u16 hpi_bitstream_get_activity(u32 h_control, u16 *pw_clk_activity,
1751 u16 *pw_data_activity)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001752{
1753 struct hpi_message hm;
1754 struct hpi_response hr;
1755 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
1756 HPI_CONTROL_GET_STATE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001757 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
1758 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001759 hm.u.c.attribute = HPI_BITSTREAM_ACTIVITY;
1760 hpi_send_recv(&hm, &hr);
1761 if (pw_clk_activity)
1762 *pw_clk_activity = (u16)hr.u.c.param1;
1763 if (pw_data_activity)
1764 *pw_data_activity = (u16)hr.u.c.param2;
1765 return hr.error;
1766}
1767
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001768u16 hpi_channel_mode_query_mode(const u32 h_mode, const u32 index,
1769 u16 *pw_mode)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001770{
1771 u32 qr;
1772 u16 err;
1773
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001774 err = hpi_control_query(h_mode, HPI_CHANNEL_MODE_MODE, index, 0, &qr);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001775 *pw_mode = (u16)qr;
1776 return err;
1777}
1778
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001779u16 hpi_channel_mode_set(u32 h_control, u16 mode)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001780{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001781 return hpi_control_param_set(h_control, HPI_CHANNEL_MODE_MODE, mode,
1782 0);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001783}
1784
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001785u16 hpi_channel_mode_get(u32 h_control, u16 *mode)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001786{
1787 u32 mode32 = 0;
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001788 u16 error = hpi_control_param1_get(h_control,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001789 HPI_CHANNEL_MODE_MODE, &mode32);
1790 if (mode)
1791 *mode = (u16)mode32;
1792 return error;
1793}
1794
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001795u16 hpi_cobranet_hmi_write(u32 h_control, u32 hmi_address, u32 byte_count,
1796 u8 *pb_data)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001797{
1798 struct hpi_message hm;
1799 struct hpi_response hr;
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12001800
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001801 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROLEX,
1802 HPI_CONTROL_SET_STATE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001803 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
1804 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001805
1806 hm.u.cx.u.cobranet_data.byte_count = byte_count;
1807 hm.u.cx.u.cobranet_data.hmi_address = hmi_address;
1808
1809 if (byte_count <= 8) {
1810 memcpy(hm.u.cx.u.cobranet_data.data, pb_data, byte_count);
1811 hm.u.cx.attribute = HPI_COBRANET_SET;
1812 } else {
1813 hm.u.cx.u.cobranet_bigdata.pb_data = pb_data;
1814 hm.u.cx.attribute = HPI_COBRANET_SET_DATA;
1815 }
1816
1817 hpi_send_recv(&hm, &hr);
1818
1819 return hr.error;
1820}
1821
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001822u16 hpi_cobranet_hmi_read(u32 h_control, u32 hmi_address, u32 max_byte_count,
1823 u32 *pbyte_count, u8 *pb_data)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001824{
1825 struct hpi_message hm;
1826 struct hpi_response hr;
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12001827
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001828 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROLEX,
1829 HPI_CONTROL_GET_STATE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001830 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
1831 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001832
1833 hm.u.cx.u.cobranet_data.byte_count = max_byte_count;
1834 hm.u.cx.u.cobranet_data.hmi_address = hmi_address;
1835
1836 if (max_byte_count <= 8) {
1837 hm.u.cx.attribute = HPI_COBRANET_GET;
1838 } else {
1839 hm.u.cx.u.cobranet_bigdata.pb_data = pb_data;
1840 hm.u.cx.attribute = HPI_COBRANET_GET_DATA;
1841 }
1842
1843 hpi_send_recv(&hm, &hr);
1844 if (!hr.error && pb_data) {
1845
1846 *pbyte_count = hr.u.cx.u.cobranet_data.byte_count;
1847
1848 if (*pbyte_count < max_byte_count)
1849 max_byte_count = *pbyte_count;
1850
1851 if (hm.u.cx.attribute == HPI_COBRANET_GET) {
1852 memcpy(pb_data, hr.u.cx.u.cobranet_data.data,
1853 max_byte_count);
1854 } else {
1855
1856 }
1857
1858 }
1859 return hr.error;
1860}
1861
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001862u16 hpi_cobranet_hmi_get_status(u32 h_control, u32 *pstatus,
1863 u32 *preadable_size, u32 *pwriteable_size)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001864{
1865 struct hpi_message hm;
1866 struct hpi_response hr;
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12001867
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001868 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROLEX,
1869 HPI_CONTROL_GET_STATE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001870 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
1871 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001872
1873 hm.u.cx.attribute = HPI_COBRANET_GET_STATUS;
1874
1875 hpi_send_recv(&hm, &hr);
1876 if (!hr.error) {
1877 if (pstatus)
1878 *pstatus = hr.u.cx.u.cobranet_status.status;
1879 if (preadable_size)
1880 *preadable_size =
1881 hr.u.cx.u.cobranet_status.readable_size;
1882 if (pwriteable_size)
1883 *pwriteable_size =
1884 hr.u.cx.u.cobranet_status.writeable_size;
1885 }
1886 return hr.error;
1887}
1888
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001889u16 hpi_cobranet_get_ip_address(u32 h_control, u32 *pdw_ip_address)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001890{
1891 u32 byte_count;
1892 u32 iP;
1893 u16 error;
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12001894
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001895 error = hpi_cobranet_hmi_read(h_control,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001896 HPI_COBRANET_HMI_cobra_ip_mon_currentIP, 4, &byte_count,
1897 (u8 *)&iP);
1898
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001899 *pdw_ip_address =
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001900 ((iP & 0xff000000) >> 8) | ((iP & 0x00ff0000) << 8) | ((iP &
1901 0x0000ff00) >> 8) | ((iP & 0x000000ff) << 8);
1902
1903 if (error)
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001904 *pdw_ip_address = 0;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001905
1906 return error;
1907
1908}
1909
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001910u16 hpi_cobranet_set_ip_address(u32 h_control, u32 dw_ip_address)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001911{
1912 u32 iP;
1913 u16 error;
1914
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001915 iP = ((dw_ip_address & 0xff000000) >> 8) | ((dw_ip_address &
1916 0x00ff0000) << 8) | ((dw_ip_address & 0x0000ff00) >>
1917 8) | ((dw_ip_address & 0x000000ff) << 8);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001918
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001919 error = hpi_cobranet_hmi_write(h_control,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001920 HPI_COBRANET_HMI_cobra_ip_mon_currentIP, 4, (u8 *)&iP);
1921
1922 return error;
1923
1924}
1925
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001926u16 hpi_cobranet_get_static_ip_address(u32 h_control, u32 *pdw_ip_address)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001927{
1928 u32 byte_count;
1929 u32 iP;
1930 u16 error;
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001931 error = hpi_cobranet_hmi_read(h_control,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001932 HPI_COBRANET_HMI_cobra_ip_mon_staticIP, 4, &byte_count,
1933 (u8 *)&iP);
1934
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001935 *pdw_ip_address =
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001936 ((iP & 0xff000000) >> 8) | ((iP & 0x00ff0000) << 8) | ((iP &
1937 0x0000ff00) >> 8) | ((iP & 0x000000ff) << 8);
1938
1939 if (error)
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001940 *pdw_ip_address = 0;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001941
1942 return error;
1943
1944}
1945
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001946u16 hpi_cobranet_set_static_ip_address(u32 h_control, u32 dw_ip_address)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001947{
1948 u32 iP;
1949 u16 error;
1950
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001951 iP = ((dw_ip_address & 0xff000000) >> 8) | ((dw_ip_address &
1952 0x00ff0000) << 8) | ((dw_ip_address & 0x0000ff00) >>
1953 8) | ((dw_ip_address & 0x000000ff) << 8);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001954
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001955 error = hpi_cobranet_hmi_write(h_control,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001956 HPI_COBRANET_HMI_cobra_ip_mon_staticIP, 4, (u8 *)&iP);
1957
1958 return error;
1959
1960}
1961
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001962u16 hpi_cobranet_get_macaddress(u32 h_control, u32 *pmAC_MS_bs,
1963 u32 *pmAC_LS_bs)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001964{
1965 u32 byte_count;
1966 u16 error;
1967 u32 mAC;
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12001968
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001969 error = hpi_cobranet_hmi_read(h_control,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001970 HPI_COBRANET_HMI_cobra_if_phy_address, 4, &byte_count,
1971 (u8 *)&mAC);
1972 *pmAC_MS_bs =
1973 ((mAC & 0xff000000) >> 8) | ((mAC & 0x00ff0000) << 8) | ((mAC
1974 & 0x0000ff00) >> 8) | ((mAC & 0x000000ff) << 8);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001975 error += hpi_cobranet_hmi_read(h_control,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001976 HPI_COBRANET_HMI_cobra_if_phy_address + 1, 4, &byte_count,
1977 (u8 *)&mAC);
1978 *pmAC_LS_bs =
1979 ((mAC & 0xff000000) >> 8) | ((mAC & 0x00ff0000) << 8) | ((mAC
1980 & 0x0000ff00) >> 8) | ((mAC & 0x000000ff) << 8);
1981
1982 if (error) {
1983 *pmAC_MS_bs = 0;
1984 *pmAC_LS_bs = 0;
1985 }
1986
1987 return error;
1988}
1989
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001990u16 hpi_compander_set_enable(u32 h_control, u32 enable)
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12001991{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001992 return hpi_control_param_set(h_control, HPI_GENERIC_ENABLE, enable,
1993 0);
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12001994}
1995
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001996u16 hpi_compander_get_enable(u32 h_control, u32 *enable)
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12001997{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13001998 return hpi_control_param1_get(h_control, HPI_GENERIC_ENABLE, enable);
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12001999}
2000
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002001u16 hpi_compander_set_makeup_gain(u32 h_control, short makeup_gain0_01dB)
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002002{
2003 return hpi_control_log_set2(h_control, HPI_COMPANDER_MAKEUPGAIN,
2004 makeup_gain0_01dB, 0);
2005}
2006
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002007u16 hpi_compander_get_makeup_gain(u32 h_control, short *makeup_gain0_01dB)
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002008{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002009 return hpi_control_log_get2(h_control, HPI_COMPANDER_MAKEUPGAIN,
2010 makeup_gain0_01dB, NULL);
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002011}
2012
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002013u16 hpi_compander_set_attack_time_constant(u32 h_control, unsigned int index,
2014 u32 attack)
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002015{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002016 return hpi_control_param_set(h_control, HPI_COMPANDER_ATTACK, attack,
2017 index);
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002018}
2019
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002020u16 hpi_compander_get_attack_time_constant(u32 h_control, unsigned int index,
2021 u32 *attack)
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002022{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002023 return hpi_control_param_get(h_control, HPI_COMPANDER_ATTACK, 0,
2024 index, attack, NULL);
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002025}
2026
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002027u16 hpi_compander_set_decay_time_constant(u32 h_control, unsigned int index,
2028 u32 decay)
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002029{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002030 return hpi_control_param_set(h_control, HPI_COMPANDER_DECAY, decay,
2031 index);
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002032}
2033
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002034u16 hpi_compander_get_decay_time_constant(u32 h_control, unsigned int index,
2035 u32 *decay)
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002036{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002037 return hpi_control_param_get(h_control, HPI_COMPANDER_DECAY, 0, index,
2038 decay, NULL);
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002039
2040}
2041
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002042u16 hpi_compander_set_threshold(u32 h_control, unsigned int index,
2043 short threshold0_01dB)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002044{
2045 struct hpi_message hm;
2046 struct hpi_response hr;
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002047
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002048 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2049 HPI_CONTROL_SET_STATE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002050 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
2051 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002052 hm.u.c.attribute = HPI_COMPANDER_THRESHOLD;
2053 hm.u.c.param2 = index;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002054 hm.u.c.an_log_value[0] = threshold0_01dB;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002055
2056 hpi_send_recv(&hm, &hr);
2057
2058 return hr.error;
2059}
2060
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002061u16 hpi_compander_get_threshold(u32 h_control, unsigned int index,
2062 short *threshold0_01dB)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002063{
2064 struct hpi_message hm;
2065 struct hpi_response hr;
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002066
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002067 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2068 HPI_CONTROL_GET_STATE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002069 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
2070 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002071 hm.u.c.attribute = HPI_COMPANDER_THRESHOLD;
2072 hm.u.c.param2 = index;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002073
2074 hpi_send_recv(&hm, &hr);
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002075 *threshold0_01dB = hr.u.c.an_log_value[0];
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002076
2077 return hr.error;
2078}
2079
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002080u16 hpi_compander_set_ratio(u32 h_control, u32 index, u32 ratio100)
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002081{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002082 return hpi_control_param_set(h_control, HPI_COMPANDER_RATIO, ratio100,
2083 index);
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002084}
2085
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002086u16 hpi_compander_get_ratio(u32 h_control, u32 index, u32 *ratio100)
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002087{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002088 return hpi_control_param_get(h_control, HPI_COMPANDER_RATIO, 0, index,
2089 ratio100, NULL);
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002090}
2091
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002092u16 hpi_level_query_range(u32 h_control, short *min_gain_01dB,
2093 short *max_gain_01dB, short *step_gain_01dB)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002094{
2095 struct hpi_message hm;
2096 struct hpi_response hr;
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002097
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002098 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2099 HPI_CONTROL_GET_STATE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002100 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
2101 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002102 hm.u.c.attribute = HPI_LEVEL_RANGE;
2103
2104 hpi_send_recv(&hm, &hr);
2105 if (hr.error) {
2106 hr.u.c.an_log_value[0] = 0;
2107 hr.u.c.an_log_value[1] = 0;
2108 hr.u.c.param1 = 0;
2109 }
2110 if (min_gain_01dB)
2111 *min_gain_01dB = hr.u.c.an_log_value[0];
2112 if (max_gain_01dB)
2113 *max_gain_01dB = hr.u.c.an_log_value[1];
2114 if (step_gain_01dB)
2115 *step_gain_01dB = (short)hr.u.c.param1;
2116 return hr.error;
2117}
2118
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002119u16 hpi_level_set_gain(u32 h_control, short an_gain0_01dB[HPI_MAX_CHANNELS]
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002120 )
2121{
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002122 return hpi_control_log_set2(h_control, HPI_LEVEL_GAIN,
2123 an_gain0_01dB[0], an_gain0_01dB[1]);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002124}
2125
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002126u16 hpi_level_get_gain(u32 h_control, short an_gain0_01dB[HPI_MAX_CHANNELS]
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002127 )
2128{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002129 return hpi_control_log_get2(h_control, HPI_LEVEL_GAIN,
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002130 &an_gain0_01dB[0], &an_gain0_01dB[1]);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002131}
2132
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002133u16 hpi_meter_query_channels(const u32 h_meter, u32 *p_channels)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002134{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002135 return hpi_control_query(h_meter, HPI_METER_NUM_CHANNELS, 0, 0,
2136 p_channels);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002137}
2138
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002139u16 hpi_meter_get_peak(u32 h_control, short an_peakdB[HPI_MAX_CHANNELS]
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002140 )
2141{
2142 short i = 0;
2143
2144 struct hpi_message hm;
2145 struct hpi_response hr;
2146
2147 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2148 HPI_CONTROL_GET_STATE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002149 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
2150 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002151 hm.obj_index = hm.obj_index;
2152 hm.u.c.attribute = HPI_METER_PEAK;
2153
2154 hpi_send_recv(&hm, &hr);
2155
2156 if (!hr.error)
2157 memcpy(an_peakdB, hr.u.c.an_log_value,
2158 sizeof(short) * HPI_MAX_CHANNELS);
2159 else
2160 for (i = 0; i < HPI_MAX_CHANNELS; i++)
2161 an_peakdB[i] = HPI_METER_MINIMUM;
2162 return hr.error;
2163}
2164
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002165u16 hpi_meter_get_rms(u32 h_control, short an_rmsdB[HPI_MAX_CHANNELS]
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002166 )
2167{
2168 short i = 0;
2169
2170 struct hpi_message hm;
2171 struct hpi_response hr;
2172
2173 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2174 HPI_CONTROL_GET_STATE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002175 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
2176 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002177 hm.u.c.attribute = HPI_METER_RMS;
2178
2179 hpi_send_recv(&hm, &hr);
2180
2181 if (!hr.error)
2182 memcpy(an_rmsdB, hr.u.c.an_log_value,
2183 sizeof(short) * HPI_MAX_CHANNELS);
2184 else
2185 for (i = 0; i < HPI_MAX_CHANNELS; i++)
2186 an_rmsdB[i] = HPI_METER_MINIMUM;
2187
2188 return hr.error;
2189}
2190
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002191u16 hpi_meter_set_rms_ballistics(u32 h_control, u16 attack, u16 decay)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002192{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002193 return hpi_control_param_set(h_control, HPI_METER_RMS_BALLISTICS,
2194 attack, decay);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002195}
2196
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002197u16 hpi_meter_get_rms_ballistics(u32 h_control, u16 *pn_attack, u16 *pn_decay)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002198{
2199 u32 attack;
2200 u32 decay;
2201 u16 error;
2202
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002203 error = hpi_control_param2_get(h_control, HPI_METER_RMS_BALLISTICS,
2204 &attack, &decay);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002205
2206 if (pn_attack)
2207 *pn_attack = (unsigned short)attack;
2208 if (pn_decay)
2209 *pn_decay = (unsigned short)decay;
2210
2211 return error;
2212}
2213
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002214u16 hpi_meter_set_peak_ballistics(u32 h_control, u16 attack, u16 decay)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002215{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002216 return hpi_control_param_set(h_control, HPI_METER_PEAK_BALLISTICS,
2217 attack, decay);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002218}
2219
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002220u16 hpi_meter_get_peak_ballistics(u32 h_control, u16 *pn_attack,
2221 u16 *pn_decay)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002222{
2223 u32 attack;
2224 u32 decay;
2225 u16 error;
2226
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002227 error = hpi_control_param2_get(h_control, HPI_METER_PEAK_BALLISTICS,
2228 &attack, &decay);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002229
2230 if (pn_attack)
2231 *pn_attack = (short)attack;
2232 if (pn_decay)
2233 *pn_decay = (short)decay;
2234
2235 return error;
2236}
2237
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002238u16 hpi_microphone_set_phantom_power(u32 h_control, u16 on_off)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002239{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002240 return hpi_control_param_set(h_control, HPI_MICROPHONE_PHANTOM_POWER,
2241 (u32)on_off, 0);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002242}
2243
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002244u16 hpi_microphone_get_phantom_power(u32 h_control, u16 *pw_on_off)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002245{
2246 u16 error = 0;
2247 u32 on_off = 0;
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002248 error = hpi_control_param1_get(h_control,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002249 HPI_MICROPHONE_PHANTOM_POWER, &on_off);
2250 if (pw_on_off)
2251 *pw_on_off = (u16)on_off;
2252 return error;
2253}
2254
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002255u16 hpi_multiplexer_set_source(u32 h_control, u16 source_node_type,
2256 u16 source_node_index)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002257{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002258 return hpi_control_param_set(h_control, HPI_MULTIPLEXER_SOURCE,
2259 source_node_type, source_node_index);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002260}
2261
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002262u16 hpi_multiplexer_get_source(u32 h_control, u16 *source_node_type,
2263 u16 *source_node_index)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002264{
2265 u32 node, index;
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002266 u16 error = hpi_control_param2_get(h_control,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002267 HPI_MULTIPLEXER_SOURCE, &node,
2268 &index);
2269 if (source_node_type)
2270 *source_node_type = (u16)node;
2271 if (source_node_index)
2272 *source_node_index = (u16)index;
2273 return error;
2274}
2275
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002276u16 hpi_multiplexer_query_source(u32 h_control, u16 index,
2277 u16 *source_node_type, u16 *source_node_index)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002278{
2279 struct hpi_message hm;
2280 struct hpi_response hr;
2281 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2282 HPI_CONTROL_GET_STATE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002283 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
2284 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002285 hm.u.c.attribute = HPI_MULTIPLEXER_QUERYSOURCE;
2286 hm.u.c.param1 = index;
2287
2288 hpi_send_recv(&hm, &hr);
2289
2290 if (source_node_type)
2291 *source_node_type = (u16)hr.u.c.param1;
2292 if (source_node_index)
2293 *source_node_index = (u16)hr.u.c.param2;
2294 return hr.error;
2295}
2296
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002297u16 hpi_parametric_eq_get_info(u32 h_control, u16 *pw_number_of_bands,
2298 u16 *pw_on_off)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002299{
2300 u32 oB = 0;
2301 u32 oO = 0;
2302 u16 error = 0;
2303
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002304 error = hpi_control_param2_get(h_control, HPI_EQUALIZER_NUM_FILTERS,
2305 &oO, &oB);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002306 if (pw_number_of_bands)
2307 *pw_number_of_bands = (u16)oB;
2308 if (pw_on_off)
2309 *pw_on_off = (u16)oO;
2310 return error;
2311}
2312
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002313u16 hpi_parametric_eq_set_state(u32 h_control, u16 on_off)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002314{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002315 return hpi_control_param_set(h_control, HPI_EQUALIZER_NUM_FILTERS,
2316 on_off, 0);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002317}
2318
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002319u16 hpi_parametric_eq_get_band(u32 h_control, u16 index, u16 *pn_type,
2320 u32 *pfrequency_hz, short *pnQ100, short *pn_gain0_01dB)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002321{
2322 struct hpi_message hm;
2323 struct hpi_response hr;
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002324
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002325 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2326 HPI_CONTROL_GET_STATE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002327 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
2328 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002329 hm.u.c.attribute = HPI_EQUALIZER_FILTER;
2330 hm.u.c.param2 = index;
2331
2332 hpi_send_recv(&hm, &hr);
2333
2334 if (pfrequency_hz)
2335 *pfrequency_hz = hr.u.c.param1;
2336 if (pn_type)
2337 *pn_type = (u16)(hr.u.c.param2 >> 16);
2338 if (pnQ100)
2339 *pnQ100 = hr.u.c.an_log_value[1];
2340 if (pn_gain0_01dB)
2341 *pn_gain0_01dB = hr.u.c.an_log_value[0];
2342
2343 return hr.error;
2344}
2345
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002346u16 hpi_parametric_eq_set_band(u32 h_control, u16 index, u16 type,
2347 u32 frequency_hz, short q100, short gain0_01dB)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002348{
2349 struct hpi_message hm;
2350 struct hpi_response hr;
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002351
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002352 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2353 HPI_CONTROL_SET_STATE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002354 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
2355 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002356
2357 hm.u.c.param1 = frequency_hz;
2358 hm.u.c.param2 = (index & 0xFFFFL) + ((u32)type << 16);
2359 hm.u.c.an_log_value[0] = gain0_01dB;
2360 hm.u.c.an_log_value[1] = q100;
2361 hm.u.c.attribute = HPI_EQUALIZER_FILTER;
2362
2363 hpi_send_recv(&hm, &hr);
2364
2365 return hr.error;
2366}
2367
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002368u16 hpi_parametric_eq_get_coeffs(u32 h_control, u16 index, short coeffs[5]
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002369 )
2370{
2371 struct hpi_message hm;
2372 struct hpi_response hr;
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002373
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002374 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2375 HPI_CONTROL_GET_STATE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002376 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
2377 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002378 hm.u.c.attribute = HPI_EQUALIZER_COEFFICIENTS;
2379 hm.u.c.param2 = index;
2380
2381 hpi_send_recv(&hm, &hr);
2382
2383 coeffs[0] = (short)hr.u.c.an_log_value[0];
2384 coeffs[1] = (short)hr.u.c.an_log_value[1];
2385 coeffs[2] = (short)hr.u.c.param1;
2386 coeffs[3] = (short)(hr.u.c.param1 >> 16);
2387 coeffs[4] = (short)hr.u.c.param2;
2388
2389 return hr.error;
2390}
2391
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002392u16 hpi_sample_clock_query_source(const u32 h_clock, const u32 index,
2393 u16 *pw_source)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002394{
2395 u32 qr;
2396 u16 err;
2397
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002398 err = hpi_control_query(h_clock, HPI_SAMPLECLOCK_SOURCE, index, 0,
2399 &qr);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002400 *pw_source = (u16)qr;
2401 return err;
2402}
2403
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002404u16 hpi_sample_clock_set_source(u32 h_control, u16 source)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002405{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002406 return hpi_control_param_set(h_control, HPI_SAMPLECLOCK_SOURCE,
2407 source, 0);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002408}
2409
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002410u16 hpi_sample_clock_get_source(u32 h_control, u16 *pw_source)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002411{
2412 u16 error = 0;
2413 u32 source = 0;
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002414 error = hpi_control_param1_get(h_control, HPI_SAMPLECLOCK_SOURCE,
2415 &source);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002416 if (!error)
2417 if (pw_source)
2418 *pw_source = (u16)source;
2419 return error;
2420}
2421
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002422u16 hpi_sample_clock_query_source_index(const u32 h_clock, const u32 index,
2423 const u32 source, u16 *pw_source_index)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002424{
2425 u32 qr;
2426 u16 err;
2427
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002428 err = hpi_control_query(h_clock, HPI_SAMPLECLOCK_SOURCE_INDEX, index,
2429 source, &qr);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002430 *pw_source_index = (u16)qr;
2431 return err;
2432}
2433
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002434u16 hpi_sample_clock_set_source_index(u32 h_control, u16 source_index)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002435{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002436 return hpi_control_param_set(h_control, HPI_SAMPLECLOCK_SOURCE_INDEX,
2437 source_index, 0);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002438}
2439
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002440u16 hpi_sample_clock_get_source_index(u32 h_control, u16 *pw_source_index)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002441{
2442 u16 error = 0;
2443 u32 source_index = 0;
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002444 error = hpi_control_param1_get(h_control,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002445 HPI_SAMPLECLOCK_SOURCE_INDEX, &source_index);
2446 if (!error)
2447 if (pw_source_index)
2448 *pw_source_index = (u16)source_index;
2449 return error;
2450}
2451
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002452u16 hpi_sample_clock_query_local_rate(const u32 h_clock, const u32 index,
2453 u32 *prate)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002454{
2455 u16 err;
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002456 err = hpi_control_query(h_clock, HPI_SAMPLECLOCK_LOCAL_SAMPLERATE,
2457 index, 0, prate);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002458
2459 return err;
2460}
2461
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002462u16 hpi_sample_clock_set_local_rate(u32 h_control, u32 sample_rate)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002463{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002464 return hpi_control_param_set(h_control,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002465 HPI_SAMPLECLOCK_LOCAL_SAMPLERATE, sample_rate, 0);
2466}
2467
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002468u16 hpi_sample_clock_get_local_rate(u32 h_control, u32 *psample_rate)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002469{
2470 u16 error = 0;
2471 u32 sample_rate = 0;
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002472 error = hpi_control_param1_get(h_control,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002473 HPI_SAMPLECLOCK_LOCAL_SAMPLERATE, &sample_rate);
2474 if (!error)
2475 if (psample_rate)
2476 *psample_rate = sample_rate;
2477 return error;
2478}
2479
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002480u16 hpi_sample_clock_get_sample_rate(u32 h_control, u32 *psample_rate)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002481{
2482 u16 error = 0;
2483 u32 sample_rate = 0;
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002484 error = hpi_control_param1_get(h_control, HPI_SAMPLECLOCK_SAMPLERATE,
2485 &sample_rate);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002486 if (!error)
2487 if (psample_rate)
2488 *psample_rate = sample_rate;
2489 return error;
2490}
2491
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002492u16 hpi_sample_clock_set_auto(u32 h_control, u32 enable)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002493{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002494 return hpi_control_param_set(h_control, HPI_SAMPLECLOCK_AUTO, enable,
2495 0);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002496}
2497
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002498u16 hpi_sample_clock_get_auto(u32 h_control, u32 *penable)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002499{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002500 return hpi_control_param1_get(h_control, HPI_SAMPLECLOCK_AUTO,
2501 penable);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002502}
2503
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002504u16 hpi_sample_clock_set_local_rate_lock(u32 h_control, u32 lock)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002505{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002506 return hpi_control_param_set(h_control, HPI_SAMPLECLOCK_LOCAL_LOCK,
2507 lock, 0);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002508}
2509
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002510u16 hpi_sample_clock_get_local_rate_lock(u32 h_control, u32 *plock)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002511{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002512 return hpi_control_param1_get(h_control, HPI_SAMPLECLOCK_LOCAL_LOCK,
2513 plock);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002514}
2515
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002516u16 hpi_tone_detector_get_frequency(u32 h_control, u32 index, u32 *frequency)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002517{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002518 return hpi_control_param_get(h_control, HPI_TONEDETECTOR_FREQUENCY,
2519 index, 0, frequency, NULL);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002520}
2521
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002522u16 hpi_tone_detector_get_state(u32 h_control, u32 *state)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002523{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002524 return hpi_control_param1_get(h_control, HPI_TONEDETECTOR_STATE,
2525 state);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002526}
2527
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002528u16 hpi_tone_detector_set_enable(u32 h_control, u32 enable)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002529{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002530 return hpi_control_param_set(h_control, HPI_GENERIC_ENABLE, enable,
2531 0);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002532}
2533
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002534u16 hpi_tone_detector_get_enable(u32 h_control, u32 *enable)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002535{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002536 return hpi_control_param1_get(h_control, HPI_GENERIC_ENABLE, enable);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002537}
2538
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002539u16 hpi_tone_detector_set_event_enable(u32 h_control, u32 event_enable)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002540{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002541 return hpi_control_param_set(h_control, HPI_GENERIC_EVENT_ENABLE,
2542 (u32)event_enable, 0);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002543}
2544
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002545u16 hpi_tone_detector_get_event_enable(u32 h_control, u32 *event_enable)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002546{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002547 return hpi_control_param1_get(h_control, HPI_GENERIC_EVENT_ENABLE,
2548 event_enable);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002549}
2550
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002551u16 hpi_tone_detector_set_threshold(u32 h_control, int threshold)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002552{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002553 return hpi_control_param_set(h_control, HPI_TONEDETECTOR_THRESHOLD,
2554 (u32)threshold, 0);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002555}
2556
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002557u16 hpi_tone_detector_get_threshold(u32 h_control, int *threshold)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002558{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002559 return hpi_control_param1_get(h_control, HPI_TONEDETECTOR_THRESHOLD,
2560 (u32 *)threshold);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002561}
2562
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002563u16 hpi_silence_detector_get_state(u32 h_control, u32 *state)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002564{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002565 return hpi_control_param1_get(h_control, HPI_SILENCEDETECTOR_STATE,
2566 state);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002567}
2568
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002569u16 hpi_silence_detector_set_enable(u32 h_control, u32 enable)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002570{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002571 return hpi_control_param_set(h_control, HPI_GENERIC_ENABLE, enable,
2572 0);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002573}
2574
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002575u16 hpi_silence_detector_get_enable(u32 h_control, u32 *enable)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002576{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002577 return hpi_control_param1_get(h_control, HPI_GENERIC_ENABLE, enable);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002578}
2579
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002580u16 hpi_silence_detector_set_event_enable(u32 h_control, u32 event_enable)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002581{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002582 return hpi_control_param_set(h_control, HPI_GENERIC_EVENT_ENABLE,
2583 event_enable, 0);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002584}
2585
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002586u16 hpi_silence_detector_get_event_enable(u32 h_control, u32 *event_enable)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002587{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002588 return hpi_control_param1_get(h_control, HPI_GENERIC_EVENT_ENABLE,
2589 event_enable);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002590}
2591
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002592u16 hpi_silence_detector_set_delay(u32 h_control, u32 delay)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002593{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002594 return hpi_control_param_set(h_control, HPI_SILENCEDETECTOR_DELAY,
2595 delay, 0);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002596}
2597
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002598u16 hpi_silence_detector_get_delay(u32 h_control, u32 *delay)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002599{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002600 return hpi_control_param1_get(h_control, HPI_SILENCEDETECTOR_DELAY,
2601 delay);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002602}
2603
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002604u16 hpi_silence_detector_set_threshold(u32 h_control, int threshold)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002605{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002606 return hpi_control_param_set(h_control, HPI_SILENCEDETECTOR_THRESHOLD,
2607 threshold, 0);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002608}
2609
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002610u16 hpi_silence_detector_get_threshold(u32 h_control, int *threshold)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002611{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002612 return hpi_control_param1_get(h_control,
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002613 HPI_SILENCEDETECTOR_THRESHOLD, (u32 *)threshold);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002614}
2615
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002616u16 hpi_tuner_query_band(const u32 h_tuner, const u32 index, u16 *pw_band)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002617{
2618 u32 qr;
2619 u16 err;
2620
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002621 err = hpi_control_query(h_tuner, HPI_TUNER_BAND, index, 0, &qr);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002622 *pw_band = (u16)qr;
2623 return err;
2624}
2625
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002626u16 hpi_tuner_set_band(u32 h_control, u16 band)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002627{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002628 return hpi_control_param_set(h_control, HPI_TUNER_BAND, band, 0);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002629}
2630
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002631u16 hpi_tuner_get_band(u32 h_control, u16 *pw_band)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002632{
2633 u32 band = 0;
2634 u16 error = 0;
2635
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002636 error = hpi_control_param1_get(h_control, HPI_TUNER_BAND, &band);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002637 if (pw_band)
2638 *pw_band = (u16)band;
2639 return error;
2640}
2641
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002642u16 hpi_tuner_query_frequency(const u32 h_tuner, const u32 index,
2643 const u16 band, u32 *pfreq)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002644{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002645 return hpi_control_query(h_tuner, HPI_TUNER_FREQ, index, band, pfreq);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002646}
2647
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002648u16 hpi_tuner_set_frequency(u32 h_control, u32 freq_ink_hz)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002649{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002650 return hpi_control_param_set(h_control, HPI_TUNER_FREQ, freq_ink_hz,
2651 0);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002652}
2653
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002654u16 hpi_tuner_get_frequency(u32 h_control, u32 *pw_freq_ink_hz)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002655{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002656 return hpi_control_param1_get(h_control, HPI_TUNER_FREQ,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002657 pw_freq_ink_hz);
2658}
2659
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002660u16 hpi_tuner_query_gain(const u32 h_tuner, const u32 index, u16 *pw_gain)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002661{
2662 u32 qr;
2663 u16 err;
2664
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002665 err = hpi_control_query(h_tuner, HPI_TUNER_BAND, index, 0, &qr);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002666 *pw_gain = (u16)qr;
2667 return err;
2668}
2669
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002670u16 hpi_tuner_set_gain(u32 h_control, short gain)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002671{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002672 return hpi_control_param_set(h_control, HPI_TUNER_GAIN, gain, 0);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002673}
2674
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002675u16 hpi_tuner_get_gain(u32 h_control, short *pn_gain)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002676{
2677 u32 gain = 0;
2678 u16 error = 0;
2679
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002680 error = hpi_control_param1_get(h_control, HPI_TUNER_GAIN, &gain);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002681 if (pn_gain)
2682 *pn_gain = (u16)gain;
2683 return error;
2684}
2685
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002686u16 hpi_tuner_get_rf_level(u32 h_control, short *pw_level)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002687{
2688 struct hpi_message hm;
2689 struct hpi_response hr;
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002690
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002691 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2692 HPI_CONTROL_GET_STATE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002693 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
2694 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13002695 hm.u.cu.attribute = HPI_TUNER_LEVEL_AVG;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002696 hpi_send_recv(&hm, &hr);
2697 if (pw_level)
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13002698 *pw_level = hr.u.cu.tuner.s_level;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002699 return hr.error;
2700}
2701
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002702u16 hpi_tuner_get_raw_rf_level(u32 h_control, short *pw_level)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002703{
2704 struct hpi_message hm;
2705 struct hpi_response hr;
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002706
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002707 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2708 HPI_CONTROL_GET_STATE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002709 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
2710 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13002711 hm.u.cu.attribute = HPI_TUNER_LEVEL_RAW;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002712 hpi_send_recv(&hm, &hr);
2713 if (pw_level)
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13002714 *pw_level = hr.u.cu.tuner.s_level;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002715 return hr.error;
2716}
2717
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002718u16 hpi_tuner_query_deemphasis(const u32 h_tuner, const u32 index,
2719 const u16 band, u32 *pdeemphasis)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002720{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002721 return hpi_control_query(h_tuner, HPI_TUNER_DEEMPHASIS, index, band,
2722 pdeemphasis);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002723}
2724
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002725u16 hpi_tuner_set_deemphasis(u32 h_control, u32 deemphasis)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002726{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002727 return hpi_control_param_set(h_control, HPI_TUNER_DEEMPHASIS,
2728 deemphasis, 0);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002729}
2730
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002731u16 hpi_tuner_get_deemphasis(u32 h_control, u32 *pdeemphasis)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002732{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002733 return hpi_control_param1_get(h_control, HPI_TUNER_DEEMPHASIS,
2734 pdeemphasis);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002735}
2736
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002737u16 hpi_tuner_query_program(const u32 h_tuner, u32 *pbitmap_program)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002738{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002739 return hpi_control_query(h_tuner, HPI_TUNER_PROGRAM, 0, 0,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002740 pbitmap_program);
2741}
2742
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002743u16 hpi_tuner_set_program(u32 h_control, u32 program)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002744{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002745 return hpi_control_param_set(h_control, HPI_TUNER_PROGRAM, program,
2746 0);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002747}
2748
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002749u16 hpi_tuner_get_program(u32 h_control, u32 *pprogram)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002750{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002751 return hpi_control_param1_get(h_control, HPI_TUNER_PROGRAM, pprogram);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002752}
2753
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002754u16 hpi_tuner_get_hd_radio_dsp_version(u32 h_control, char *psz_dsp_version,
2755 const u32 string_size)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002756{
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002757 return hpi_control_get_string(h_control,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002758 HPI_TUNER_HDRADIO_DSP_VERSION, psz_dsp_version, string_size);
2759}
2760
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002761u16 hpi_tuner_get_hd_radio_sdk_version(u32 h_control, char *psz_sdk_version,
2762 const u32 string_size)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002763{
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002764 return hpi_control_get_string(h_control,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002765 HPI_TUNER_HDRADIO_SDK_VERSION, psz_sdk_version, string_size);
2766}
2767
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002768u16 hpi_tuner_get_status(u32 h_control, u16 *pw_status_mask, u16 *pw_status)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002769{
2770 u32 status = 0;
2771 u16 error = 0;
2772
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002773 error = hpi_control_param1_get(h_control, HPI_TUNER_STATUS, &status);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002774 if (pw_status) {
2775 if (!error) {
2776 *pw_status_mask = (u16)(status >> 16);
2777 *pw_status = (u16)(status & 0xFFFF);
2778 } else {
2779 *pw_status_mask = 0;
2780 *pw_status = 0;
2781 }
2782 }
2783 return error;
2784}
2785
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002786u16 hpi_tuner_set_mode(u32 h_control, u32 mode, u32 value)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002787{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002788 return hpi_control_param_set(h_control, HPI_TUNER_MODE, mode, value);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002789}
2790
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002791u16 hpi_tuner_get_mode(u32 h_control, u32 mode, u32 *pn_value)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002792{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002793 return hpi_control_param_get(h_control, HPI_TUNER_MODE, mode, 0,
2794 pn_value, NULL);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002795}
2796
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002797u16 hpi_tuner_get_hd_radio_signal_quality(u32 h_control, u32 *pquality)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002798{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002799 return hpi_control_param1_get(h_control,
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002800 HPI_TUNER_HDRADIO_SIGNAL_QUALITY, pquality);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002801}
2802
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002803u16 hpi_tuner_get_hd_radio_signal_blend(u32 h_control, u32 *pblend)
Eliot Blennerhassett5a498ef2010-05-27 17:53:52 +12002804{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002805 return hpi_control_param1_get(h_control, HPI_TUNER_HDRADIO_BLEND,
2806 pblend);
Eliot Blennerhassett5a498ef2010-05-27 17:53:52 +12002807}
2808
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002809u16 hpi_tuner_set_hd_radio_signal_blend(u32 h_control, const u32 blend)
Eliot Blennerhassett5a498ef2010-05-27 17:53:52 +12002810{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002811 return hpi_control_param_set(h_control, HPI_TUNER_HDRADIO_BLEND,
2812 blend, 0);
Eliot Blennerhassett5a498ef2010-05-27 17:53:52 +12002813}
2814
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002815u16 hpi_tuner_get_rds(u32 h_control, char *p_data)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002816{
2817 struct hpi_message hm;
2818 struct hpi_response hr;
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002819
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002820 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2821 HPI_CONTROL_GET_STATE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002822 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
2823 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002824 hm.u.c.attribute = HPI_TUNER_RDS;
2825 hpi_send_recv(&hm, &hr);
2826 if (p_data) {
2827 *(u32 *)&p_data[0] = hr.u.cu.tuner.rds.data[0];
2828 *(u32 *)&p_data[4] = hr.u.cu.tuner.rds.data[1];
2829 *(u32 *)&p_data[8] = hr.u.cu.tuner.rds.bLER;
2830 }
2831 return hr.error;
2832}
2833
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002834u16 hpi_pad_get_channel_name(u32 h_control, char *psz_string,
2835 const u32 data_length)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002836{
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002837 return hpi_control_get_string(h_control, HPI_PAD_CHANNEL_NAME,
2838 psz_string, data_length);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002839}
2840
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002841u16 hpi_pad_get_artist(u32 h_control, char *psz_string, const u32 data_length)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002842{
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002843 return hpi_control_get_string(h_control, HPI_PAD_ARTIST, psz_string,
2844 data_length);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002845}
2846
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002847u16 hpi_pad_get_title(u32 h_control, char *psz_string, const u32 data_length)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002848{
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002849 return hpi_control_get_string(h_control, HPI_PAD_TITLE, psz_string,
2850 data_length);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002851}
2852
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002853u16 hpi_pad_get_comment(u32 h_control, char *psz_string,
2854 const u32 data_length)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002855{
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002856 return hpi_control_get_string(h_control, HPI_PAD_COMMENT, psz_string,
2857 data_length);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002858}
2859
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002860u16 hpi_pad_get_program_type(u32 h_control, u32 *ppTY)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002861{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002862 return hpi_control_param1_get(h_control, HPI_PAD_PROGRAM_TYPE, ppTY);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002863}
2864
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002865u16 hpi_pad_get_rdsPI(u32 h_control, u32 *ppI)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002866{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002867 return hpi_control_param1_get(h_control, HPI_PAD_PROGRAM_ID, ppI);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002868}
2869
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002870u16 hpi_volume_query_channels(const u32 h_volume, u32 *p_channels)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002871{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002872 return hpi_control_query(h_volume, HPI_VOLUME_NUM_CHANNELS, 0, 0,
2873 p_channels);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002874}
2875
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002876u16 hpi_volume_set_gain(u32 h_control, short an_log_gain[HPI_MAX_CHANNELS]
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002877 )
2878{
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002879 return hpi_control_log_set2(h_control, HPI_VOLUME_GAIN,
2880 an_log_gain[0], an_log_gain[1]);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002881}
2882
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002883u16 hpi_volume_get_gain(u32 h_control, short an_log_gain[HPI_MAX_CHANNELS]
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002884 )
2885{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002886 return hpi_control_log_get2(h_control, HPI_VOLUME_GAIN,
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002887 &an_log_gain[0], &an_log_gain[1]);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002888}
2889
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002890u16 hpi_volume_query_range(u32 h_control, short *min_gain_01dB,
2891 short *max_gain_01dB, short *step_gain_01dB)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002892{
2893 struct hpi_message hm;
2894 struct hpi_response hr;
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002895
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002896 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2897 HPI_CONTROL_GET_STATE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002898 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
2899 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002900 hm.u.c.attribute = HPI_VOLUME_RANGE;
2901
2902 hpi_send_recv(&hm, &hr);
2903 if (hr.error) {
2904 hr.u.c.an_log_value[0] = 0;
2905 hr.u.c.an_log_value[1] = 0;
2906 hr.u.c.param1 = 0;
2907 }
2908 if (min_gain_01dB)
2909 *min_gain_01dB = hr.u.c.an_log_value[0];
2910 if (max_gain_01dB)
2911 *max_gain_01dB = hr.u.c.an_log_value[1];
2912 if (step_gain_01dB)
2913 *step_gain_01dB = (short)hr.u.c.param1;
2914 return hr.error;
2915}
2916
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002917u16 hpi_volume_auto_fade_profile(u32 h_control,
2918 short an_stop_gain0_01dB[HPI_MAX_CHANNELS], u32 duration_ms,
2919 u16 profile)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002920{
2921 struct hpi_message hm;
2922 struct hpi_response hr;
Eliot Blennerhassett108ccb32010-07-06 08:37:09 +12002923
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002924 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2925 HPI_CONTROL_SET_STATE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002926 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
2927 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002928
2929 memcpy(hm.u.c.an_log_value, an_stop_gain0_01dB,
2930 sizeof(short) * HPI_MAX_CHANNELS);
2931
2932 hm.u.c.attribute = HPI_VOLUME_AUTOFADE;
2933 hm.u.c.param1 = duration_ms;
2934 hm.u.c.param2 = profile;
2935
2936 hpi_send_recv(&hm, &hr);
2937
2938 return hr.error;
2939}
2940
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002941u16 hpi_volume_auto_fade(u32 h_control,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002942 short an_stop_gain0_01dB[HPI_MAX_CHANNELS], u32 duration_ms)
2943{
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002944 return hpi_volume_auto_fade_profile(h_control, an_stop_gain0_01dB,
2945 duration_ms, HPI_VOLUME_AUTOFADE_LOG);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002946}
2947
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002948u16 hpi_vox_set_threshold(u32 h_control, short an_gain0_01dB)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002949{
2950 struct hpi_message hm;
2951 struct hpi_response hr;
2952 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2953 HPI_CONTROL_SET_STATE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002954 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
2955 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002956 hm.u.c.attribute = HPI_VOX_THRESHOLD;
2957
2958 hm.u.c.an_log_value[0] = an_gain0_01dB;
2959
2960 hpi_send_recv(&hm, &hr);
2961
2962 return hr.error;
2963}
2964
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002965u16 hpi_vox_get_threshold(u32 h_control, short *an_gain0_01dB)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002966{
2967 struct hpi_message hm;
2968 struct hpi_response hr;
2969 hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
2970 HPI_CONTROL_GET_STATE);
Eliot Blennerhassettba944552011-02-10 17:26:04 +13002971 if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
2972 return HPI_ERROR_INVALID_HANDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002973 hm.u.c.attribute = HPI_VOX_THRESHOLD;
2974
2975 hpi_send_recv(&hm, &hr);
2976
2977 *an_gain0_01dB = hr.u.c.an_log_value[0];
2978
2979 return hr.error;
2980}