hpifunc.c 72.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32

#include "hpi_internal.h"
#include "hpimsginit.h"

#include "hpidebug.h"

struct hpi_handle {
	unsigned int obj_index:12;
	unsigned int obj_type:4;
	unsigned int adapter_index:14;
	unsigned int spare:1;
	unsigned int read_only:1;
};

union handle_word {
	struct hpi_handle h;
	u32 w;
};

u32 hpi_indexes_to_handle(const char c_object, const u16 adapter_index,
	const u16 object_index)
{
	union handle_word handle;

	handle.h.adapter_index = adapter_index;
	handle.h.spare = 0;
	handle.h.read_only = 0;
	handle.h.obj_type = c_object;
	handle.h.obj_index = object_index;
	return handle.w;
}

33
static u16 hpi_handle_indexes(const u32 h, u16 *p1, u16 *p2)
34 35
{
	union handle_word uhandle;
36 37
	if (!h)
		return HPI_ERROR_INVALID_HANDLE;
38

39 40 41 42 43 44 45 46 47 48 49 50 51
	uhandle.w = h;

	*p1 = (u16)uhandle.h.adapter_index;
	if (p2)
		*p2 = (u16)uhandle.h.obj_index;

	return 0;
}

void hpi_handle_to_indexes(const u32 handle, u16 *pw_adapter_index,
	u16 *pw_object_index)
{
	hpi_handle_indexes(handle, pw_adapter_index, pw_object_index);
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
}

char hpi_handle_object(const u32 handle)
{
	union handle_word uhandle;
	uhandle.w = handle;
	return (char)uhandle.h.obj_type;
}

void hpi_format_to_msg(struct hpi_msg_format *pMF,
	const struct hpi_format *pF)
{
	pMF->sample_rate = pF->sample_rate;
	pMF->bit_rate = pF->bit_rate;
	pMF->attributes = pF->attributes;
	pMF->channels = pF->channels;
	pMF->format = pF->format;
}

static void hpi_msg_to_format(struct hpi_format *pF,
	struct hpi_msg_format *pMF)
{
	pF->sample_rate = pMF->sample_rate;
	pF->bit_rate = pMF->bit_rate;
	pF->attributes = pMF->attributes;
	pF->channels = pMF->channels;
	pF->format = pMF->format;
	pF->mode_legacy = 0;
	pF->unused = 0;
}

void hpi_stream_response_to_legacy(struct hpi_stream_res *pSR)
{
	pSR->u.legacy_stream_info.auxiliary_data_available =
		pSR->u.stream_info.auxiliary_data_available;
	pSR->u.legacy_stream_info.state = pSR->u.stream_info.state;
}

90 91
static inline void hpi_send_recvV1(struct hpi_message_header *m,
	struct hpi_response_header *r)
92
{
93
	hpi_send_recv((struct hpi_message *)m, (struct hpi_response *)r);
94 95
}

96
u16 hpi_subsys_get_version_ex(u32 *pversion_ex)
97 98 99 100 101 102 103 104 105 106 107
{
	struct hpi_message hm;
	struct hpi_response hr;

	hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
		HPI_SUBSYS_GET_VERSION);
	hpi_send_recv(&hm, &hr);
	*pversion_ex = hr.u.s.data;
	return hr.error;
}

108 109
u16 hpi_subsys_create_adapter(const struct hpi_resource *p_resource,
	u16 *pw_adapter_index)
110 111 112 113 114 115 116 117 118 119 120 121 122 123
{
	struct hpi_message hm;
	struct hpi_response hr;

	hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
		HPI_SUBSYS_CREATE_ADAPTER);
	hm.u.s.resource = *p_resource;

	hpi_send_recv(&hm, &hr);

	*pw_adapter_index = hr.u.s.adapter_index;
	return hr.error;
}

124
u16 hpi_subsys_delete_adapter(u16 adapter_index)
125 126 127 128 129
{
	struct hpi_message hm;
	struct hpi_response hr;
	hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
		HPI_SUBSYS_DELETE_ADAPTER);
130
	hm.obj_index = adapter_index;
131 132 133 134
	hpi_send_recv(&hm, &hr);
	return hr.error;
}

135
u16 hpi_subsys_get_num_adapters(int *pn_num_adapters)
136 137 138 139 140 141 142 143 144 145
{
	struct hpi_message hm;
	struct hpi_response hr;
	hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
		HPI_SUBSYS_GET_NUM_ADAPTERS);
	hpi_send_recv(&hm, &hr);
	*pn_num_adapters = (int)hr.u.s.num_adapters;
	return hr.error;
}

146 147
u16 hpi_subsys_get_adapter(int iterator, u32 *padapter_index,
	u16 *pw_adapter_type)
148 149 150 151 152
{
	struct hpi_message hm;
	struct hpi_response hr;
	hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
		HPI_SUBSYS_GET_ADAPTER);
153
	hm.obj_index = (u16)iterator;
154 155
	hpi_send_recv(&hm, &hr);
	*padapter_index = (int)hr.u.s.adapter_index;
156 157
	*pw_adapter_type = hr.u.s.adapter_type;

158 159 160
	return hr.error;
}

161
u16 hpi_adapter_open(u16 adapter_index)
162 163 164 165 166 167 168 169 170 171 172 173 174
{
	struct hpi_message hm;
	struct hpi_response hr;
	hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
		HPI_ADAPTER_OPEN);
	hm.adapter_index = adapter_index;

	hpi_send_recv(&hm, &hr);

	return hr.error;

}

175
u16 hpi_adapter_close(u16 adapter_index)
176 177 178 179 180 181 182 183 184 185 186 187
{
	struct hpi_message hm;
	struct hpi_response hr;
	hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
		HPI_ADAPTER_CLOSE);
	hm.adapter_index = adapter_index;

	hpi_send_recv(&hm, &hr);

	return hr.error;
}

188
u16 hpi_adapter_set_mode(u16 adapter_index, u32 adapter_mode)
189
{
190
	return hpi_adapter_set_mode_ex(adapter_index, adapter_mode,
191 192 193
		HPI_ADAPTER_MODE_SET);
}

194 195
u16 hpi_adapter_set_mode_ex(u16 adapter_index, u32 adapter_mode,
	u16 query_or_set)
196 197 198
{
	struct hpi_message hm;
	struct hpi_response hr;
199

200 201 202
	hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
		HPI_ADAPTER_SET_MODE);
	hm.adapter_index = adapter_index;
203 204
	hm.u.ax.mode.adapter_mode = adapter_mode;
	hm.u.ax.mode.query_or_set = query_or_set;
205 206 207 208
	hpi_send_recv(&hm, &hr);
	return hr.error;
}

209
u16 hpi_adapter_get_mode(u16 adapter_index, u32 *padapter_mode)
210 211 212 213 214 215 216 217
{
	struct hpi_message hm;
	struct hpi_response hr;
	hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
		HPI_ADAPTER_GET_MODE);
	hm.adapter_index = adapter_index;
	hpi_send_recv(&hm, &hr);
	if (padapter_mode)
218
		*padapter_mode = hr.u.ax.mode.adapter_mode;
219 220 221
	return hr.error;
}

222 223 224
u16 hpi_adapter_get_info(u16 adapter_index, u16 *pw_num_outstreams,
	u16 *pw_num_instreams, u16 *pw_version, u32 *pserial_number,
	u16 *pw_adapter_type)
225 226 227 228 229 230 231 232 233
{
	struct hpi_message hm;
	struct hpi_response hr;
	hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
		HPI_ADAPTER_GET_INFO);
	hm.adapter_index = adapter_index;

	hpi_send_recv(&hm, &hr);

234 235 236 237 238
	*pw_adapter_type = hr.u.ax.info.adapter_type;
	*pw_num_outstreams = hr.u.ax.info.num_outstreams;
	*pw_num_instreams = hr.u.ax.info.num_instreams;
	*pw_version = hr.u.ax.info.version;
	*pserial_number = hr.u.ax.info.serial_number;
239 240 241
	return hr.error;
}

242 243 244
u16 hpi_adapter_get_module_by_index(u16 adapter_index, u16 module_index,
	u16 *pw_num_outputs, u16 *pw_num_inputs, u16 *pw_version,
	u32 *pserial_number, u16 *pw_module_type, u32 *ph_module)
245 246 247 248 249 250 251 252 253 254 255
{
	struct hpi_message hm;
	struct hpi_response hr;

	hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
		HPI_ADAPTER_MODULE_INFO);
	hm.adapter_index = adapter_index;
	hm.u.ax.module_info.index = module_index;

	hpi_send_recv(&hm, &hr);

256 257 258 259 260
	*pw_module_type = hr.u.ax.info.adapter_type;
	*pw_num_outputs = hr.u.ax.info.num_outstreams;
	*pw_num_inputs = hr.u.ax.info.num_instreams;
	*pw_version = hr.u.ax.info.version;
	*pserial_number = hr.u.ax.info.serial_number;
261 262 263 264 265
	*ph_module = 0;

	return hr.error;
}

266 267 268
u16 hpi_adapter_get_assert2(u16 adapter_index, u16 *p_assert_count,
	char *psz_assert, u32 *p_param1, u32 *p_param2,
	u32 *p_dsp_string_addr, u16 *p_processor_id)
269 270 271 272 273 274 275 276 277
{
	struct hpi_message hm;
	struct hpi_response hr;
	hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
		HPI_ADAPTER_GET_ASSERT);
	hm.adapter_index = adapter_index;

	hpi_send_recv(&hm, &hr);

278
	*p_assert_count = 0;
279 280

	if (!hr.error) {
281 282 283 284 285 286 287 288 289
		*p_assert_count = hr.u.ax.assert.count;

		if (*p_assert_count) {
			*p_param1 = hr.u.ax.assert.p1;
			*p_param2 = hr.u.ax.assert.p2;
			*p_processor_id = hr.u.ax.assert.dsp_index;
			*p_dsp_string_addr = hr.u.ax.assert.dsp_msg_addr;
			memcpy(psz_assert, hr.u.ax.assert.sz_message,
				HPI_STRING_LEN);
290 291 292 293 294 295 296
		} else {
			*psz_assert = 0;
		}
	}
	return hr.error;
}

297
u16 hpi_adapter_test_assert(u16 adapter_index, u16 assert_id)
298 299 300 301 302 303
{
	struct hpi_message hm;
	struct hpi_response hr;
	hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
		HPI_ADAPTER_TEST_ASSERT);
	hm.adapter_index = adapter_index;
304
	hm.u.ax.test_assert.value = assert_id;
305 306 307 308 309 310

	hpi_send_recv(&hm, &hr);

	return hr.error;
}

311
u16 hpi_adapter_enable_capability(u16 adapter_index, u16 capability, u32 key)
312
{
313 314 315
#if 1
	return HPI_ERROR_UNIMPLEMENTED;
#else
316 317 318 319 320
	struct hpi_message hm;
	struct hpi_response hr;
	hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
		HPI_ADAPTER_ENABLE_CAPABILITY);
	hm.adapter_index = adapter_index;
321 322
	hm.u.ax.enable_cap.cap = capability;
	hm.u.ax.enable_cap.key = key;
323 324 325 326

	hpi_send_recv(&hm, &hr);

	return hr.error;
327
#endif
328 329
}

330
u16 hpi_adapter_self_test(u16 adapter_index)
331 332 333 334 335 336 337 338 339 340
{
	struct hpi_message hm;
	struct hpi_response hr;
	hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
		HPI_ADAPTER_SELFTEST);
	hm.adapter_index = adapter_index;
	hpi_send_recv(&hm, &hr);
	return hr.error;
}

341 342
u16 hpi_adapter_debug_read(u16 adapter_index, u32 dsp_address, char *p_buffer,
	int *count_bytes)
343
{
344 345
	struct hpi_msg_adapter_debug_read hm;
	struct hpi_res_adapter_debug_read hr;
346

347 348
	hpi_init_message_responseV1(&hm.h, sizeof(hm), &hr.h, sizeof(hr),
		HPI_OBJ_ADAPTER, HPI_ADAPTER_DEBUG_READ);
349

350 351
	hm.h.adapter_index = adapter_index;
	hm.dsp_address = dsp_address;
352

353 354
	if (*count_bytes > (int)sizeof(hr.bytes))
		*count_bytes = (int)sizeof(hr.bytes);
355

356
	hm.count_bytes = *count_bytes;
357

358
	hpi_send_recvV1(&hm.h, &hr.h);
359

360 361 362 363 364 365
	if (!hr.h.error) {
		int res_bytes = hr.h.size - sizeof(hr.h);
		if (res_bytes > *count_bytes)
			res_bytes = *count_bytes;
		*count_bytes = res_bytes;
		memcpy(p_buffer, &hr.bytes, res_bytes);
366 367
	} else
		*count_bytes = 0;
368 369

	return hr.h.error;
370 371
}

372 373
u16 hpi_adapter_set_property(u16 adapter_index, u16 property, u16 parameter1,
	u16 parameter2)
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388
{
	struct hpi_message hm;
	struct hpi_response hr;
	hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
		HPI_ADAPTER_SET_PROPERTY);
	hm.adapter_index = adapter_index;
	hm.u.ax.property_set.property = property;
	hm.u.ax.property_set.parameter1 = parameter1;
	hm.u.ax.property_set.parameter2 = parameter2;

	hpi_send_recv(&hm, &hr);

	return hr.error;
}

389 390
u16 hpi_adapter_get_property(u16 adapter_index, u16 property,
	u16 *pw_parameter1, u16 *pw_parameter2)
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409
{
	struct hpi_message hm;
	struct hpi_response hr;
	hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
		HPI_ADAPTER_GET_PROPERTY);
	hm.adapter_index = adapter_index;
	hm.u.ax.property_set.property = property;

	hpi_send_recv(&hm, &hr);
	if (!hr.error) {
		if (pw_parameter1)
			*pw_parameter1 = hr.u.ax.property_get.parameter1;
		if (pw_parameter2)
			*pw_parameter2 = hr.u.ax.property_get.parameter2;
	}

	return hr.error;
}

410 411
u16 hpi_adapter_enumerate_property(u16 adapter_index, u16 index,
	u16 what_to_enumerate, u16 property_index, u32 *psetting)
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556
{
	return 0;
}

u16 hpi_format_create(struct hpi_format *p_format, u16 channels, u16 format,
	u32 sample_rate, u32 bit_rate, u32 attributes)
{
	u16 error = 0;
	struct hpi_msg_format fmt;

	switch (channels) {
	case 1:
	case 2:
	case 4:
	case 6:
	case 8:
	case 16:
		break;
	default:
		error = HPI_ERROR_INVALID_CHANNELS;
		return error;
	}
	fmt.channels = channels;

	switch (format) {
	case HPI_FORMAT_PCM16_SIGNED:
	case HPI_FORMAT_PCM24_SIGNED:
	case HPI_FORMAT_PCM32_SIGNED:
	case HPI_FORMAT_PCM32_FLOAT:
	case HPI_FORMAT_PCM16_BIGENDIAN:
	case HPI_FORMAT_PCM8_UNSIGNED:
	case HPI_FORMAT_MPEG_L1:
	case HPI_FORMAT_MPEG_L2:
	case HPI_FORMAT_MPEG_L3:
	case HPI_FORMAT_DOLBY_AC2:
	case HPI_FORMAT_AA_TAGIT1_HITS:
	case HPI_FORMAT_AA_TAGIT1_INSERTS:
	case HPI_FORMAT_RAW_BITSTREAM:
	case HPI_FORMAT_AA_TAGIT1_HITS_EX1:
	case HPI_FORMAT_OEM1:
	case HPI_FORMAT_OEM2:
		break;
	default:
		error = HPI_ERROR_INVALID_FORMAT;
		return error;
	}
	fmt.format = format;

	if (sample_rate < 8000L) {
		error = HPI_ERROR_INCOMPATIBLE_SAMPLERATE;
		sample_rate = 8000L;
	}
	if (sample_rate > 200000L) {
		error = HPI_ERROR_INCOMPATIBLE_SAMPLERATE;
		sample_rate = 200000L;
	}
	fmt.sample_rate = sample_rate;

	switch (format) {
	case HPI_FORMAT_MPEG_L1:
	case HPI_FORMAT_MPEG_L2:
	case HPI_FORMAT_MPEG_L3:
		fmt.bit_rate = bit_rate;
		break;
	case HPI_FORMAT_PCM16_SIGNED:
	case HPI_FORMAT_PCM16_BIGENDIAN:
		fmt.bit_rate = channels * sample_rate * 2;
		break;
	case HPI_FORMAT_PCM32_SIGNED:
	case HPI_FORMAT_PCM32_FLOAT:
		fmt.bit_rate = channels * sample_rate * 4;
		break;
	case HPI_FORMAT_PCM8_UNSIGNED:
		fmt.bit_rate = channels * sample_rate;
		break;
	default:
		fmt.bit_rate = 0;
	}

	switch (format) {
	case HPI_FORMAT_MPEG_L2:
		if ((channels == 1)
			&& (attributes != HPI_MPEG_MODE_DEFAULT)) {
			attributes = HPI_MPEG_MODE_DEFAULT;
			error = HPI_ERROR_INVALID_FORMAT;
		} else if (attributes > HPI_MPEG_MODE_DUALCHANNEL) {
			attributes = HPI_MPEG_MODE_DEFAULT;
			error = HPI_ERROR_INVALID_FORMAT;
		}
		fmt.attributes = attributes;
		break;
	default:
		fmt.attributes = attributes;
	}

	hpi_msg_to_format(p_format, &fmt);
	return error;
}

u16 hpi_stream_estimate_buffer_size(struct hpi_format *p_format,
	u32 host_polling_rate_in_milli_seconds, u32 *recommended_buffer_size)
{

	u32 bytes_per_second;
	u32 size;
	u16 channels;
	struct hpi_format *pF = p_format;

	channels = pF->channels;

	switch (pF->format) {
	case HPI_FORMAT_PCM16_BIGENDIAN:
	case HPI_FORMAT_PCM16_SIGNED:
		bytes_per_second = pF->sample_rate * 2L * channels;
		break;
	case HPI_FORMAT_PCM24_SIGNED:
		bytes_per_second = pF->sample_rate * 3L * channels;
		break;
	case HPI_FORMAT_PCM32_SIGNED:
	case HPI_FORMAT_PCM32_FLOAT:
		bytes_per_second = pF->sample_rate * 4L * channels;
		break;
	case HPI_FORMAT_PCM8_UNSIGNED:
		bytes_per_second = pF->sample_rate * 1L * channels;
		break;
	case HPI_FORMAT_MPEG_L1:
	case HPI_FORMAT_MPEG_L2:
	case HPI_FORMAT_MPEG_L3:
		bytes_per_second = pF->bit_rate / 8L;
		break;
	case HPI_FORMAT_DOLBY_AC2:

		bytes_per_second = 256000L / 8L;
		break;
	default:
		return HPI_ERROR_INVALID_FORMAT;
	}
	size = (bytes_per_second * host_polling_rate_in_milli_seconds * 2) /
		1000L;

	*recommended_buffer_size =
		roundup_pow_of_two(((size + 4095L) & ~4095L));
	return 0;
}

557 558
u16 hpi_outstream_open(u16 adapter_index, u16 outstream_index,
	u32 *ph_outstream)
559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577
{
	struct hpi_message hm;
	struct hpi_response hr;
	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
		HPI_OSTREAM_OPEN);
	hm.adapter_index = adapter_index;
	hm.obj_index = outstream_index;

	hpi_send_recv(&hm, &hr);

	if (hr.error == 0)
		*ph_outstream =
			hpi_indexes_to_handle(HPI_OBJ_OSTREAM, adapter_index,
			outstream_index);
	else
		*ph_outstream = 0;
	return hr.error;
}

578
u16 hpi_outstream_close(u32 h_outstream)
579 580 581 582 583 584
{
	struct hpi_message hm;
	struct hpi_response hr;

	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
		HPI_OSTREAM_HOSTBUFFER_FREE);
585 586 587
	if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;

588 589 590 591
	hpi_send_recv(&hm, &hr);

	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
		HPI_OSTREAM_GROUP_RESET);
592
	hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index);
593 594 595 596
	hpi_send_recv(&hm, &hr);

	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
		HPI_OSTREAM_CLOSE);
597
	hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index);
598 599 600 601 602
	hpi_send_recv(&hm, &hr);

	return hr.error;
}

603 604 605
u16 hpi_outstream_get_info_ex(u32 h_outstream, u16 *pw_state,
	u32 *pbuffer_size, u32 *pdata_to_play, u32 *psamples_played,
	u32 *pauxiliary_data_to_play)
606 607 608 609 610
{
	struct hpi_message hm;
	struct hpi_response hr;
	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
		HPI_OSTREAM_GET_INFO);
611 612
	if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629

	hpi_send_recv(&hm, &hr);

	if (pw_state)
		*pw_state = hr.u.d.u.stream_info.state;
	if (pbuffer_size)
		*pbuffer_size = hr.u.d.u.stream_info.buffer_size;
	if (pdata_to_play)
		*pdata_to_play = hr.u.d.u.stream_info.data_available;
	if (psamples_played)
		*psamples_played = hr.u.d.u.stream_info.samples_transferred;
	if (pauxiliary_data_to_play)
		*pauxiliary_data_to_play =
			hr.u.d.u.stream_info.auxiliary_data_available;
	return hr.error;
}

630 631
u16 hpi_outstream_write_buf(u32 h_outstream, const u8 *pb_data,
	u32 bytes_to_write, const struct hpi_format *p_format)
632 633 634 635 636
{
	struct hpi_message hm;
	struct hpi_response hr;
	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
		HPI_OSTREAM_WRITE);
637 638
	if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
639 640 641 642 643 644 645 646 647 648
	hm.u.d.u.data.pb_data = (u8 *)pb_data;
	hm.u.d.u.data.data_size = bytes_to_write;

	hpi_format_to_msg(&hm.u.d.u.data.format, p_format);

	hpi_send_recv(&hm, &hr);

	return hr.error;
}

649
u16 hpi_outstream_start(u32 h_outstream)
650 651 652 653 654
{
	struct hpi_message hm;
	struct hpi_response hr;
	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
		HPI_OSTREAM_START);
655 656
	if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
657 658 659 660 661 662

	hpi_send_recv(&hm, &hr);

	return hr.error;
}

663
u16 hpi_outstream_wait_start(u32 h_outstream)
664 665 666 667 668
{
	struct hpi_message hm;
	struct hpi_response hr;
	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
		HPI_OSTREAM_WAIT_START);
669 670
	if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
671 672 673 674 675 676

	hpi_send_recv(&hm, &hr);

	return hr.error;
}

677
u16 hpi_outstream_stop(u32 h_outstream)
678 679 680 681 682
{
	struct hpi_message hm;
	struct hpi_response hr;
	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
		HPI_OSTREAM_STOP);
683 684
	if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
685 686 687 688 689 690

	hpi_send_recv(&hm, &hr);

	return hr.error;
}

691
u16 hpi_outstream_sinegen(u32 h_outstream)
692 693 694 695 696
{
	struct hpi_message hm;
	struct hpi_response hr;
	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
		HPI_OSTREAM_SINEGEN);
697 698
	if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
699 700 701 702 703 704

	hpi_send_recv(&hm, &hr);

	return hr.error;
}

705
u16 hpi_outstream_reset(u32 h_outstream)
706 707 708 709 710
{
	struct hpi_message hm;
	struct hpi_response hr;
	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
		HPI_OSTREAM_RESET);
711 712
	if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
713 714 715 716 717 718

	hpi_send_recv(&hm, &hr);

	return hr.error;
}

719
u16 hpi_outstream_query_format(u32 h_outstream, struct hpi_format *p_format)
720 721 722 723 724 725
{
	struct hpi_message hm;
	struct hpi_response hr;

	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
		HPI_OSTREAM_QUERY_FORMAT);
726 727
	if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
728 729 730 731 732 733 734 735

	hpi_format_to_msg(&hm.u.d.u.data.format, p_format);

	hpi_send_recv(&hm, &hr);

	return hr.error;
}

736
u16 hpi_outstream_set_format(u32 h_outstream, struct hpi_format *p_format)
737 738 739 740 741 742
{
	struct hpi_message hm;
	struct hpi_response hr;

	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
		HPI_OSTREAM_SET_FORMAT);
743 744
	if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
745 746 747 748 749 750 751 752

	hpi_format_to_msg(&hm.u.d.u.data.format, p_format);

	hpi_send_recv(&hm, &hr);

	return hr.error;
}

753
u16 hpi_outstream_set_velocity(u32 h_outstream, short velocity)
754 755 756 757 758 759
{
	struct hpi_message hm;
	struct hpi_response hr;

	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
		HPI_OSTREAM_SET_VELOCITY);
760 761
	if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
762 763 764 765 766 767 768
	hm.u.d.u.velocity = velocity;

	hpi_send_recv(&hm, &hr);

	return hr.error;
}

769 770
u16 hpi_outstream_set_punch_in_out(u32 h_outstream, u32 punch_in_sample,
	u32 punch_out_sample)
771 772 773 774 775 776
{
	struct hpi_message hm;
	struct hpi_response hr;

	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
		HPI_OSTREAM_SET_PUNCHINOUT);
777 778
	if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
779 780 781 782 783 784 785 786 787

	hm.u.d.u.pio.punch_in_sample = punch_in_sample;
	hm.u.d.u.pio.punch_out_sample = punch_out_sample;

	hpi_send_recv(&hm, &hr);

	return hr.error;
}

788
u16 hpi_outstream_ancillary_reset(u32 h_outstream, u16 mode)
789 790 791 792 793 794
{
	struct hpi_message hm;
	struct hpi_response hr;

	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
		HPI_OSTREAM_ANC_RESET);
795 796
	if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
797 798 799 800 801
	hm.u.d.u.data.format.channels = mode;
	hpi_send_recv(&hm, &hr);
	return hr.error;
}

802
u16 hpi_outstream_ancillary_get_info(u32 h_outstream, u32 *pframes_available)
803 804 805 806 807 808
{
	struct hpi_message hm;
	struct hpi_response hr;

	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
		HPI_OSTREAM_ANC_GET_INFO);
809 810
	if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
811 812 813 814 815 816 817 818 819 820
	hpi_send_recv(&hm, &hr);
	if (hr.error == 0) {
		if (pframes_available)
			*pframes_available =
				hr.u.d.u.stream_info.data_available /
				sizeof(struct hpi_anc_frame);
	}
	return hr.error;
}

821 822
u16 hpi_outstream_ancillary_read(u32 h_outstream,
	struct hpi_anc_frame *p_anc_frame_buffer,
823 824 825 826 827
	u32 anc_frame_buffer_size_in_bytes,
	u32 number_of_ancillary_frames_to_read)
{
	struct hpi_message hm;
	struct hpi_response hr;
828

829 830
	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
		HPI_OSTREAM_ANC_READ);
831 832
	if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
833 834 835 836 837 838 839
	hm.u.d.u.data.pb_data = (u8 *)p_anc_frame_buffer;
	hm.u.d.u.data.data_size =
		number_of_ancillary_frames_to_read *
		sizeof(struct hpi_anc_frame);
	if (hm.u.d.u.data.data_size <= anc_frame_buffer_size_in_bytes)
		hpi_send_recv(&hm, &hr);
	else
840
		hr.error = HPI_ERROR_INVALID_DATASIZE;
841 842 843
	return hr.error;
}

844
u16 hpi_outstream_set_time_scale(u32 h_outstream, u32 time_scale)
845 846 847 848 849 850
{
	struct hpi_message hm;
	struct hpi_response hr;

	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
		HPI_OSTREAM_SET_TIMESCALE);
851 852
	if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
853 854 855 856 857 858 859 860

	hm.u.d.u.time_scale = time_scale;

	hpi_send_recv(&hm, &hr);

	return hr.error;
}

861
u16 hpi_outstream_host_buffer_allocate(u32 h_outstream, u32 size_in_bytes)
862 863 864 865 866 867
{
	struct hpi_message hm;
	struct hpi_response hr;

	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
		HPI_OSTREAM_HOSTBUFFER_ALLOC);
868 869
	if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
870 871 872 873 874
	hm.u.d.u.data.data_size = size_in_bytes;
	hpi_send_recv(&hm, &hr);
	return hr.error;
}

875
u16 hpi_outstream_host_buffer_get_info(u32 h_outstream, u8 **pp_buffer,
876 877 878 879 880 881 882
	struct hpi_hostbuffer_status **pp_status)
{
	struct hpi_message hm;
	struct hpi_response hr;

	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
		HPI_OSTREAM_HOSTBUFFER_GET_INFO);
883 884
	if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
885 886 887 888 889 890 891 892 893 894 895
	hpi_send_recv(&hm, &hr);

	if (hr.error == 0) {
		if (pp_buffer)
			*pp_buffer = hr.u.d.u.hostbuffer_info.p_buffer;
		if (pp_status)
			*pp_status = hr.u.d.u.hostbuffer_info.p_status;
	}
	return hr.error;
}

896
u16 hpi_outstream_host_buffer_free(u32 h_outstream)
897 898 899 900 901 902
{
	struct hpi_message hm;
	struct hpi_response hr;

	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
		HPI_OSTREAM_HOSTBUFFER_FREE);
903 904
	if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
905 906 907 908
	hpi_send_recv(&hm, &hr);
	return hr.error;
}

909
u16 hpi_outstream_group_add(u32 h_outstream, u32 h_stream)
910 911 912 913 914 915 916 917
{
	struct hpi_message hm;
	struct hpi_response hr;
	u16 adapter;
	char c_obj_type;

	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
		HPI_OSTREAM_GROUP_ADD);
918 919 920 921 922 923 924 925

	if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;

	if (hpi_handle_indexes(h_stream, &adapter,
			&hm.u.d.u.stream.stream_index))
		return HPI_ERROR_INVALID_HANDLE;

926 927 928 929
	c_obj_type = hpi_handle_object(h_stream);
	switch (c_obj_type) {
	case HPI_OBJ_OSTREAM:
	case HPI_OBJ_ISTREAM:
930
		hm.u.d.u.stream.object_type = c_obj_type;
931 932
		break;
	default:
933
		return HPI_ERROR_INVALID_OBJ;
934 935 936 937 938 939 940 941
	}
	if (adapter != hm.adapter_index)
		return HPI_ERROR_NO_INTERADAPTER_GROUPS;

	hpi_send_recv(&hm, &hr);
	return hr.error;
}

942 943
u16 hpi_outstream_group_get_map(u32 h_outstream, u32 *poutstream_map,
	u32 *pinstream_map)
944 945 946 947 948 949
{
	struct hpi_message hm;
	struct hpi_response hr;

	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
		HPI_OSTREAM_GROUP_GETMAP);
950 951
	if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
952 953 954 955 956 957 958 959 960 961
	hpi_send_recv(&hm, &hr);

	if (poutstream_map)
		*poutstream_map = hr.u.d.u.group_info.outstream_group_map;
	if (pinstream_map)
		*pinstream_map = hr.u.d.u.group_info.instream_group_map;

	return hr.error;
}

962
u16 hpi_outstream_group_reset(u32 h_outstream)
963 964 965 966 967 968
{
	struct hpi_message hm;
	struct hpi_response hr;

	hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
		HPI_OSTREAM_GROUP_RESET);
969 970
	if (hpi_handle_indexes(h_outstream, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
971 972 973 974
	hpi_send_recv(&hm, &hr);
	return hr.error;
}

975
u16 hpi_instream_open(u16 adapter_index, u16 instream_index, u32 *ph_instream)
976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996
{
	struct hpi_message hm;
	struct hpi_response hr;

	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
		HPI_ISTREAM_OPEN);
	hm.adapter_index = adapter_index;
	hm.obj_index = instream_index;

	hpi_send_recv(&hm, &hr);

	if (hr.error == 0)
		*ph_instream =
			hpi_indexes_to_handle(HPI_OBJ_ISTREAM, adapter_index,
			instream_index);
	else
		*ph_instream = 0;

	return hr.error;
}

997
u16 hpi_instream_close(u32 h_instream)
998 999 1000 1001 1002 1003
{
	struct hpi_message hm;
	struct hpi_response hr;

	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
		HPI_ISTREAM_HOSTBUFFER_FREE);
1004 1005
	if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
1006 1007 1008 1009
	hpi_send_recv(&hm, &hr);

	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
		HPI_ISTREAM_GROUP_RESET);
1010
	hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index);
1011 1012 1013 1014
	hpi_send_recv(&hm, &hr);

	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
		HPI_ISTREAM_CLOSE);
1015
	hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index);
1016 1017 1018 1019 1020
	hpi_send_recv(&hm, &hr);

	return hr.error;
}

1021 1022
u16 hpi_instream_query_format(u32 h_instream,
	const struct hpi_format *p_format)
1023 1024 1025 1026 1027 1028
{
	struct hpi_message hm;
	struct hpi_response hr;

	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
		HPI_ISTREAM_QUERY_FORMAT);
1029 1030
	if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
1031 1032 1033 1034 1035 1036 1037
	hpi_format_to_msg(&hm.u.d.u.data.format, p_format);

	hpi_send_recv(&hm, &hr);

	return hr.error;
}

1038
u16 hpi_instream_set_format(u32 h_instream, const struct hpi_format *p_format)
1039 1040 1041 1042 1043 1044
{
	struct hpi_message hm;
	struct hpi_response hr;

	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
		HPI_ISTREAM_SET_FORMAT);
1045 1046
	if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
1047 1048 1049 1050 1051 1052 1053
	hpi_format_to_msg(&hm.u.d.u.data.format, p_format);

	hpi_send_recv(&hm, &hr);

	return hr.error;
}

1054
u16 hpi_instream_read_buf(u32 h_instream, u8 *pb_data, u32 bytes_to_read)
1055 1056 1057 1058 1059 1060
{
	struct hpi_message hm;
	struct hpi_response hr;

	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
		HPI_ISTREAM_READ);
1061 1062
	if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
1063 1064 1065 1066 1067 1068 1069 1070
	hm.u.d.u.data.data_size = bytes_to_read;
	hm.u.d.u.data.pb_data = pb_data;

	hpi_send_recv(&hm, &hr);

	return hr.error;
}

1071
u16 hpi_instream_start(u32 h_instream)
1072 1073 1074 1075 1076 1077
{
	struct hpi_message hm;
	struct hpi_response hr;

	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
		HPI_ISTREAM_START);
1078 1079
	if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
1080 1081 1082 1083 1084 1085

	hpi_send_recv(&hm, &hr);

	return hr.error;
}

1086
u16 hpi_instream_wait_start(u32 h_instream)
1087 1088 1089 1090 1091 1092
{
	struct hpi_message hm;
	struct hpi_response hr;

	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
		HPI_ISTREAM_WAIT_START);
1093 1094
	if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
1095 1096 1097 1098 1099 1100

	hpi_send_recv(&hm, &hr);

	return hr.error;
}

1101
u16 hpi_instream_stop(u32 h_instream)
1102 1103 1104 1105 1106 1107
{
	struct hpi_message hm;
	struct hpi_response hr;

	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
		HPI_ISTREAM_STOP);
1108 1109
	if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
1110 1111 1112 1113 1114 1115

	hpi_send_recv(&hm, &hr);

	return hr.error;
}

1116
u16 hpi_instream_reset(u32 h_instream)
1117 1118 1119 1120 1121 1122
{
	struct hpi_message hm;
	struct hpi_response hr;

	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
		HPI_ISTREAM_RESET);
1123 1124
	if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
1125 1126 1127 1128 1129 1130

	hpi_send_recv(&hm, &hr);

	return hr.error;
}

1131 1132 1133
u16 hpi_instream_get_info_ex(u32 h_instream, u16 *pw_state, u32 *pbuffer_size,
	u32 *pdata_recorded, u32 *psamples_recorded,
	u32 *pauxiliary_data_recorded)
1134 1135 1136 1137 1138
{
	struct hpi_message hm;
	struct hpi_response hr;
	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
		HPI_ISTREAM_GET_INFO);
1139 1140
	if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157

	hpi_send_recv(&hm, &hr);

	if (pw_state)
		*pw_state = hr.u.d.u.stream_info.state;
	if (pbuffer_size)
		*pbuffer_size = hr.u.d.u.stream_info.buffer_size;
	if (pdata_recorded)
		*pdata_recorded = hr.u.d.u.stream_info.data_available;
	if (psamples_recorded)
		*psamples_recorded = hr.u.d.u.stream_info.samples_transferred;
	if (pauxiliary_data_recorded)
		*pauxiliary_data_recorded =
			hr.u.d.u.stream_info.auxiliary_data_available;
	return hr.error;
}

1158 1159
u16 hpi_instream_ancillary_reset(u32 h_instream, u16 bytes_per_frame,
	u16 mode, u16 alignment, u16 idle_bit)
1160 1161 1162 1163 1164
{
	struct hpi_message hm;
	struct hpi_response hr;
	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
		HPI_ISTREAM_ANC_RESET);
1165 1166
	if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
1167 1168 1169 1170 1171 1172 1173
	hm.u.d.u.data.format.attributes = bytes_per_frame;
	hm.u.d.u.data.format.format = (mode << 8) | (alignment & 0xff);
	hm.u.d.u.data.format.channels = idle_bit;
	hpi_send_recv(&hm, &hr);
	return hr.error;
}

1174
u16 hpi_instream_ancillary_get_info(u32 h_instream, u32 *pframe_space)
1175 1176 1177 1178 1179
{
	struct hpi_message hm;
	struct hpi_response hr;
	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
		HPI_ISTREAM_ANC_GET_INFO);
1180 1181
	if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
1182 1183 1184 1185 1186 1187 1188 1189 1190
	hpi_send_recv(&hm, &hr);
	if (pframe_space)
		*pframe_space =
			(hr.u.d.u.stream_info.buffer_size -
			hr.u.d.u.stream_info.data_available) /
			sizeof(struct hpi_anc_frame);
	return hr.error;
}

1191 1192
u16 hpi_instream_ancillary_write(u32 h_instream,
	const struct hpi_anc_frame *p_anc_frame_buffer,
1193 1194 1195 1196 1197 1198 1199 1200
	u32 anc_frame_buffer_size_in_bytes,
	u32 number_of_ancillary_frames_to_write)
{
	struct hpi_message hm;
	struct hpi_response hr;

	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
		HPI_ISTREAM_ANC_WRITE);
1201 1202
	if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
1203 1204 1205 1206 1207 1208 1209
	hm.u.d.u.data.pb_data = (u8 *)p_anc_frame_buffer;
	hm.u.d.u.data.data_size =
		number_of_ancillary_frames_to_write *
		sizeof(struct hpi_anc_frame);
	if (hm.u.d.u.data.data_size <= anc_frame_buffer_size_in_bytes)
		hpi_send_recv(&hm, &hr);
	else
1210
		hr.error = HPI_ERROR_INVALID_DATASIZE;
1211 1212 1213
	return hr.error;
}

1214
u16 hpi_instream_host_buffer_allocate(u32 h_instream, u32 size_in_bytes)
1215 1216 1217 1218 1219 1220 1221
{

	struct hpi_message hm;
	struct hpi_response hr;

	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
		HPI_ISTREAM_HOSTBUFFER_ALLOC);
1222 1223
	if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
1224 1225 1226 1227 1228
	hm.u.d.u.data.data_size = size_in_bytes;
	hpi_send_recv(&hm, &hr);
	return hr.error;
}

1229
u16 hpi_instream_host_buffer_get_info(u32 h_instream, u8 **pp_buffer,
1230 1231 1232 1233 1234 1235 1236
	struct hpi_hostbuffer_status **pp_status)
{
	struct hpi_message hm;
	struct hpi_response hr;

	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
		HPI_ISTREAM_HOSTBUFFER_GET_INFO);
1237 1238
	if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249
	hpi_send_recv(&hm, &hr);

	if (hr.error == 0) {
		if (pp_buffer)
			*pp_buffer = hr.u.d.u.hostbuffer_info.p_buffer;
		if (pp_status)
			*pp_status = hr.u.d.u.hostbuffer_info.p_status;
	}
	return hr.error;
}

1250
u16 hpi_instream_host_buffer_free(u32 h_instream)
1251 1252 1253 1254 1255 1256 1257
{

	struct hpi_message hm;
	struct hpi_response hr;

	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
		HPI_ISTREAM_HOSTBUFFER_FREE);
1258 1259
	if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
1260 1261 1262 1263
	hpi_send_recv(&hm, &hr);
	return hr.error;
}

1264
u16 hpi_instream_group_add(u32 h_instream, u32 h_stream)
1265 1266 1267 1268 1269 1270 1271 1272 1273
{
	struct hpi_message hm;
	struct hpi_response hr;
	u16 adapter;
	char c_obj_type;

	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
		HPI_ISTREAM_GROUP_ADD);
	hr.error = 0;
1274 1275 1276 1277 1278 1279 1280 1281

	if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;

	if (hpi_handle_indexes(h_stream, &adapter,
			&hm.u.d.u.stream.stream_index))
		return HPI_ERROR_INVALID_HANDLE;

1282 1283 1284 1285 1286
	c_obj_type = hpi_handle_object(h_stream);

	switch (c_obj_type) {
	case HPI_OBJ_OSTREAM:
	case HPI_OBJ_ISTREAM:
1287
		hm.u.d.u.stream.object_type = c_obj_type;
1288 1289
		break;
	default:
1290
		return HPI_ERROR_INVALID_OBJ;
1291 1292 1293 1294 1295 1296 1297 1298 1299
	}

	if (adapter != hm.adapter_index)
		return HPI_ERROR_NO_INTERADAPTER_GROUPS;

	hpi_send_recv(&hm, &hr);
	return hr.error;
}

1300 1301
u16 hpi_instream_group_get_map(u32 h_instream, u32 *poutstream_map,
	u32 *pinstream_map)
1302 1303 1304 1305 1306 1307
{
	struct hpi_message hm;
	struct hpi_response hr;

	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
		HPI_ISTREAM_HOSTBUFFER_FREE);
1308 1309
	if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
1310 1311 1312 1313 1314 1315 1316 1317 1318 1319
	hpi_send_recv(&hm, &hr);

	if (poutstream_map)
		*poutstream_map = hr.u.d.u.group_info.outstream_group_map;
	if (pinstream_map)
		*pinstream_map = hr.u.d.u.group_info.instream_group_map;

	return hr.error;
}

1320
u16 hpi_instream_group_reset(u32 h_instream)
1321 1322 1323 1324 1325 1326
{
	struct hpi_message hm;
	struct hpi_response hr;

	hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
		HPI_ISTREAM_GROUP_RESET);
1327 1328
	if (hpi_handle_indexes(h_instream, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
1329 1330 1331 1332
	hpi_send_recv(&hm, &hr);
	return hr.error;
}

1333
u16 hpi_mixer_open(u16 adapter_index, u32 *ph_mixer)
1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350
{
	struct hpi_message hm;
	struct hpi_response hr;
	hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER, HPI_MIXER_OPEN);
	hm.adapter_index = adapter_index;

	hpi_send_recv(&hm, &hr);

	if (hr.error == 0)
		*ph_mixer =
			hpi_indexes_to_handle(HPI_OBJ_MIXER, adapter_index,
			0);
	else
		*ph_mixer = 0;
	return hr.error;
}

1351
u16 hpi_mixer_close(u32 h_mixer)
1352 1353 1354
{
	struct hpi_message hm;
	struct hpi_response hr;
1355

1356
	hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER, HPI_MIXER_CLOSE);
1357 1358 1359
	if (hpi_handle_indexes(h_mixer, &hm.adapter_index, NULL))
		return HPI_ERROR_INVALID_HANDLE;

1360 1361 1362 1363
	hpi_send_recv(&hm, &hr);
	return hr.error;
}

1364 1365 1366
u16 hpi_mixer_get_control(u32 h_mixer, u16 src_node_type,
	u16 src_node_type_index, u16 dst_node_type, u16 dst_node_type_index,
	u16 control_type, u32 *ph_control)
1367 1368 1369 1370 1371
{
	struct hpi_message hm;
	struct hpi_response hr;
	hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER,
		HPI_MIXER_GET_CONTROL);
1372 1373
	if (hpi_handle_indexes(h_mixer, &hm.adapter_index, NULL))
		return HPI_ERROR_INVALID_HANDLE;
1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390
	hm.u.m.node_type1 = src_node_type;
	hm.u.m.node_index1 = src_node_type_index;
	hm.u.m.node_type2 = dst_node_type;
	hm.u.m.node_index2 = dst_node_type_index;
	hm.u.m.control_type = control_type;

	hpi_send_recv(&hm, &hr);

	if (hr.error == 0)
		*ph_control =
			hpi_indexes_to_handle(HPI_OBJ_CONTROL,
			hm.adapter_index, hr.u.m.control_index);
	else
		*ph_control = 0;
	return hr.error;
}

1391 1392 1393
u16 hpi_mixer_get_control_by_index(u32 h_mixer, u16 control_index,
	u16 *pw_src_node_type, u16 *pw_src_node_index, u16 *pw_dst_node_type,
	u16 *pw_dst_node_index, u16 *pw_control_type, u32 *ph_control)
1394 1395 1396 1397 1398
{
	struct hpi_message hm;
	struct hpi_response hr;
	hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER,
		HPI_MIXER_GET_CONTROL_BY_INDEX);
1399 1400
	if (hpi_handle_indexes(h_mixer, &hm.adapter_index, NULL))
		return HPI_ERROR_INVALID_HANDLE;
1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424
	hm.u.m.control_index = control_index;
	hpi_send_recv(&hm, &hr);

	if (pw_src_node_type) {
		*pw_src_node_type =
			hr.u.m.src_node_type + HPI_SOURCENODE_NONE;
		*pw_src_node_index = hr.u.m.src_node_index;
		*pw_dst_node_type = hr.u.m.dst_node_type + HPI_DESTNODE_NONE;
		*pw_dst_node_index = hr.u.m.dst_node_index;
	}
	if (pw_control_type)
		*pw_control_type = hr.u.m.control_index;

	if (ph_control) {
		if (hr.error == 0)
			*ph_control =
				hpi_indexes_to_handle(HPI_OBJ_CONTROL,
				hm.adapter_index, control_index);
		else
			*ph_control = 0;
	}
	return hr.error;
}

1425 1426
u16 hpi_mixer_store(u32 h_mixer, enum HPI_MIXER_STORE_COMMAND command,
	u16 index)
1427 1428 1429 1430
{
	struct hpi_message hm;
	struct hpi_response hr;
	hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER, HPI_MIXER_STORE);
1431 1432
	if (hpi_handle_indexes(h_mixer, &hm.adapter_index, NULL))
		return HPI_ERROR_INVALID_HANDLE;
1433 1434 1435 1436 1437 1438 1439
	hm.u.mx.store.command = command;
	hm.u.mx.store.index = index;
	hpi_send_recv(&hm, &hr);
	return hr.error;
}

static
1440 1441
u16 hpi_control_param_set(const u32 h_control, const u16 attrib,
	const u32 param1, const u32 param2)
1442 1443 1444
{
	struct hpi_message hm;
	struct hpi_response hr;
1445

1446 1447
	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
		HPI_CONTROL_SET_STATE);
1448 1449
	if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
1450 1451 1452 1453 1454 1455 1456
	hm.u.c.attribute = attrib;
	hm.u.c.param1 = param1;
	hm.u.c.param2 = param2;
	hpi_send_recv(&hm, &hr);
	return hr.error;
}

1457 1458 1459 1460 1461 1462 1463 1464
static u16 hpi_control_log_set2(u32 h_control, u16 attrib, short sv0,
	short sv1)
{
	struct hpi_message hm;
	struct hpi_response hr;

	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
		HPI_CONTROL_SET_STATE);
1465 1466
	if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
1467 1468 1469 1470 1471 1472 1473
	hm.u.c.attribute = attrib;
	hm.u.c.an_log_value[0] = sv0;
	hm.u.c.an_log_value[1] = sv1;
	hpi_send_recv(&hm, &hr);
	return hr.error;
}

1474
static
1475 1476
u16 hpi_control_param_get(const u32 h_control, const u16 attrib, u32 param1,
	u32 param2, u32 *pparam1, u32 *pparam2)
1477 1478 1479
{
	struct hpi_message hm;
	struct hpi_response hr;
1480

1481 1482
	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
		HPI_CONTROL_GET_STATE);
1483 1484
	if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
1485 1486 1487 1488
	hm.u.c.attribute = attrib;
	hm.u.c.param1 = param1;
	hm.u.c.param2 = param2;
	hpi_send_recv(&hm, &hr);
1489 1490

	*pparam1 = hr.u.c.param1;
1491 1492 1493 1494 1495 1496
	if (pparam2)
		*pparam2 = hr.u.c.param2;

	return hr.error;
}

1497 1498 1499 1500
#define hpi_control_param1_get(h, a, p1) \
		hpi_control_param_get(h, a, 0, 0, p1, NULL)
#define hpi_control_param2_get(h, a, p1, p2) \
		hpi_control_param_get(h, a, 0, 0, p1, p2)
1501

1502 1503
static u16 hpi_control_log_get2(u32 h_control, u16 attrib, short *sv0,
	short *sv1)
1504 1505 1506 1507 1508
{
	struct hpi_message hm;
	struct hpi_response hr;
	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
		HPI_CONTROL_GET_STATE);
1509 1510
	if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
1511 1512 1513 1514 1515 1516 1517 1518
	hm.u.c.attribute = attrib;

	hpi_send_recv(&hm, &hr);
	*sv0 = hr.u.c.an_log_value[0];
	if (sv1)
		*sv1 = hr.u.c.an_log_value[1];
	return hr.error;
}
1519 1520

static
1521
u16 hpi_control_query(const u32 h_control, const u16 attrib, const u32 index,
1522 1523 1524 1525
	const u32 param, u32 *psetting)
{
	struct hpi_message hm;
	struct hpi_response hr;
1526

1527 1528
	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
		HPI_CONTROL_GET_INFO);
1529 1530
	if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541

	hm.u.c.attribute = attrib;
	hm.u.c.param1 = index;
	hm.u.c.param2 = param;

	hpi_send_recv(&hm, &hr);
	*psetting = hr.u.c.param1;

	return hr.error;
}

1542 1543
static u16 hpi_control_get_string(const u32 h_control, const u16 attribute,
	char *psz_string, const u32 string_length)
1544 1545 1546 1547
{
	unsigned int sub_string_index = 0, j = 0;
	char c = 0;
	unsigned int n = 0;
1548
	u16 err = 0;
1549 1550 1551 1552 1553 1554 1555 1556 1557 1558

	if ((string_length < 1) || (string_length > 256))
		return HPI_ERROR_INVALID_CONTROL_VALUE;
	for (sub_string_index = 0; sub_string_index < string_length;
		sub_string_index += 8) {
		struct hpi_message hm;
		struct hpi_response hr;

		hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
			HPI_CONTROL_GET_STATE);
1559 1560 1561
		if (hpi_handle_indexes(h_control, &hm.adapter_index,
				&hm.obj_index))
			return HPI_ERROR_INVALID_HANDLE;
1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572
		hm.u.c.attribute = attribute;
		hm.u.c.param1 = sub_string_index;
		hm.u.c.param2 = 0;
		hpi_send_recv(&hm, &hr);

		if (sub_string_index == 0
			&& (hr.u.cu.chars8.remaining_chars + 8) >
			string_length)
			return HPI_ERROR_INVALID_CONTROL_VALUE;

		if (hr.error) {
1573
			err = hr.error;
1574 1575 1576 1577 1578 1579 1580 1581
			break;
		}
		for (j = 0; j < 8; j++) {
			c = hr.u.cu.chars8.sz_data[j];
			psz_string[sub_string_index + j] = c;
			n++;
			if (n >= string_length) {
				psz_string[string_length - 1] = 0;
1582
				err = HPI_ERROR_INVALID_CONTROL_VALUE;
1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597
				break;
			}
			if (c == 0)
				break;
		}

		if ((hr.u.cu.chars8.remaining_chars == 0)
			&& ((sub_string_index + j) < string_length)
			&& (c != 0)) {
			c = 0;
			psz_string[sub_string_index + j] = c;
		}
		if (c == 0)
			break;
	}
1598
	return err;
1599 1600
}

1601 1602
u16 hpi_aesebu_receiver_query_format(const u32 h_aes_rx, const u32 index,
	u16 *pw_format)
1603 1604 1605 1606
{
	u32 qr;
	u16 err;

1607
	err = hpi_control_query(h_aes_rx, HPI_AESEBURX_FORMAT, index, 0, &qr);
1608 1609 1610 1611
	*pw_format = (u16)qr;
	return err;
}

1612
u16 hpi_aesebu_receiver_set_format(u32 h_control, u16 format)
1613
{
1614 1615
	return hpi_control_param_set(h_control, HPI_AESEBURX_FORMAT, format,
		0);
1616 1617
}

1618
u16 hpi_aesebu_receiver_get_format(u32 h_control, u16 *pw_format)
1619 1620 1621 1622
{
	u16 err;
	u32 param;

1623
	err = hpi_control_param1_get(h_control, HPI_AESEBURX_FORMAT, &param);
1624 1625 1626 1627 1628 1629
	if (!err && pw_format)
		*pw_format = (u16)param;

	return err;
}

1630
u16 hpi_aesebu_receiver_get_sample_rate(u32 h_control, u32 *psample_rate)
1631
{
1632 1633
	return hpi_control_param1_get(h_control, HPI_AESEBURX_SAMPLERATE,
		psample_rate);
1634 1635
}

1636
u16 hpi_aesebu_receiver_get_user_data(u32 h_control, u16 index, u16 *pw_data)
1637 1638 1639 1640 1641
{
	struct hpi_message hm;
	struct hpi_response hr;
	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
		HPI_CONTROL_GET_STATE);
1642 1643
	if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
1644 1645 1646 1647 1648 1649 1650 1651 1652 1653
	hm.u.c.attribute = HPI_AESEBURX_USERDATA;
	hm.u.c.param1 = index;

	hpi_send_recv(&hm, &hr);

	if (pw_data)
		*pw_data = (u16)hr.u.c.param2;
	return hr.error;
}

1654 1655
u16 hpi_aesebu_receiver_get_channel_status(u32 h_control, u16 index,
	u16 *pw_data)
1656 1657 1658 1659 1660
{
	struct hpi_message hm;
	struct hpi_response hr;
	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
		HPI_CONTROL_GET_STATE);
1661 1662
	if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
1663 1664 1665 1666 1667 1668 1669 1670 1671 1672
	hm.u.c.attribute = HPI_AESEBURX_CHANNELSTATUS;
	hm.u.c.param1 = index;

	hpi_send_recv(&hm, &hr);

	if (pw_data)
		*pw_data = (u16)hr.u.c.param2;
	return hr.error;
}

1673
u16 hpi_aesebu_receiver_get_error_status(u32 h_control, u16 *pw_error_data)
1674 1675 1676 1677
{
	u32 error_data = 0;
	u16 error = 0;

1678 1679
	error = hpi_control_param1_get(h_control, HPI_AESEBURX_ERRORSTATUS,
		&error_data);
1680 1681 1682 1683 1684
	if (pw_error_data)
		*pw_error_data = (u16)error_data;
	return error;
}

1685
u16 hpi_aesebu_transmitter_set_sample_rate(u32 h_control, u32 sample_rate)
1686
{
1687 1688
	return hpi_control_param_set(h_control, HPI_AESEBUTX_SAMPLERATE,
		sample_rate, 0);
1689 1690
}

1691
u16 hpi_aesebu_transmitter_set_user_data(u32 h_control, u16 index, u16 data)
1692
{
1693 1694
	return hpi_control_param_set(h_control, HPI_AESEBUTX_USERDATA, index,
		data);
1695 1696
}

1697 1698
u16 hpi_aesebu_transmitter_set_channel_status(u32 h_control, u16 index,
	u16 data)
1699
{
1700 1701
	return hpi_control_param_set(h_control, HPI_AESEBUTX_CHANNELSTATUS,
		index, data);
1702 1703
}

1704 1705
u16 hpi_aesebu_transmitter_get_channel_status(u32 h_control, u16 index,
	u16 *pw_data)
1706 1707 1708 1709
{
	return HPI_ERROR_INVALID_OPERATION;
}

1710 1711
u16 hpi_aesebu_transmitter_query_format(const u32 h_aes_tx, const u32 index,
	u16 *pw_format)
1712 1713 1714 1715
{
	u32 qr;
	u16 err;

1716
	err = hpi_control_query(h_aes_tx, HPI_AESEBUTX_FORMAT, index, 0, &qr);
1717 1718 1719 1720
	*pw_format = (u16)qr;
	return err;
}

1721
u16 hpi_aesebu_transmitter_set_format(u32 h_control, u16 output_format)
1722
{
1723 1724
	return hpi_control_param_set(h_control, HPI_AESEBUTX_FORMAT,
		output_format, 0);
1725 1726
}

1727
u16 hpi_aesebu_transmitter_get_format(u32 h_control, u16 *pw_output_format)
1728 1729 1730 1731
{
	u16 err;
	u32 param;

1732
	err = hpi_control_param1_get(h_control, HPI_AESEBUTX_FORMAT, &param);
1733 1734 1735 1736 1737 1738
	if (!err && pw_output_format)
		*pw_output_format = (u16)param;

	return err;
}

1739
u16 hpi_bitstream_set_clock_edge(u32 h_control, u16 edge_type)
1740
{
1741 1742
	return hpi_control_param_set(h_control, HPI_BITSTREAM_CLOCK_EDGE,
		edge_type, 0);
1743 1744
}

1745
u16 hpi_bitstream_set_data_polarity(u32 h_control, u16 polarity)
1746
{
1747 1748
	return hpi_control_param_set(h_control, HPI_BITSTREAM_DATA_POLARITY,
		polarity, 0);
1749 1750
}

1751 1752
u16 hpi_bitstream_get_activity(u32 h_control, u16 *pw_clk_activity,
	u16 *pw_data_activity)
1753 1754 1755 1756 1757
{
	struct hpi_message hm;
	struct hpi_response hr;
	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
		HPI_CONTROL_GET_STATE);
1758 1759
	if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
1760 1761 1762 1763 1764 1765 1766 1767 1768
	hm.u.c.attribute = HPI_BITSTREAM_ACTIVITY;
	hpi_send_recv(&hm, &hr);
	if (pw_clk_activity)
		*pw_clk_activity = (u16)hr.u.c.param1;
	if (pw_data_activity)
		*pw_data_activity = (u16)hr.u.c.param2;
	return hr.error;
}

1769 1770
u16 hpi_channel_mode_query_mode(const u32 h_mode, const u32 index,
	u16 *pw_mode)
1771 1772 1773 1774
{
	u32 qr;
	u16 err;

1775
	err = hpi_control_query(h_mode, HPI_CHANNEL_MODE_MODE, index, 0, &qr);
1776 1777 1778 1779
	*pw_mode = (u16)qr;
	return err;
}

1780
u16 hpi_channel_mode_set(u32 h_control, u16 mode)
1781
{
1782 1783
	return hpi_control_param_set(h_control, HPI_CHANNEL_MODE_MODE, mode,
		0);
1784 1785
}

1786
u16 hpi_channel_mode_get(u32 h_control, u16 *mode)
1787 1788
{
	u32 mode32 = 0;
1789
	u16 error = hpi_control_param1_get(h_control,
1790 1791 1792 1793 1794 1795
		HPI_CHANNEL_MODE_MODE, &mode32);
	if (mode)
		*mode = (u16)mode32;
	return error;
}

1796 1797
u16 hpi_cobranet_hmi_write(u32 h_control, u32 hmi_address, u32 byte_count,
	u8 *pb_data)
1798 1799 1800
{
	struct hpi_message hm;
	struct hpi_response hr;
1801

1802 1803
	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROLEX,
		HPI_CONTROL_SET_STATE);
1804 1805
	if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822

	hm.u.cx.u.cobranet_data.byte_count = byte_count;
	hm.u.cx.u.cobranet_data.hmi_address = hmi_address;

	if (byte_count <= 8) {
		memcpy(hm.u.cx.u.cobranet_data.data, pb_data, byte_count);
		hm.u.cx.attribute = HPI_COBRANET_SET;
	} else {
		hm.u.cx.u.cobranet_bigdata.pb_data = pb_data;
		hm.u.cx.attribute = HPI_COBRANET_SET_DATA;
	}

	hpi_send_recv(&hm, &hr);

	return hr.error;
}

1823 1824
u16 hpi_cobranet_hmi_read(u32 h_control, u32 hmi_address, u32 max_byte_count,
	u32 *pbyte_count, u8 *pb_data)
1825 1826 1827
{
	struct hpi_message hm;
	struct hpi_response hr;
1828

1829 1830
	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROLEX,
		HPI_CONTROL_GET_STATE);
1831 1832
	if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862

	hm.u.cx.u.cobranet_data.byte_count = max_byte_count;
	hm.u.cx.u.cobranet_data.hmi_address = hmi_address;

	if (max_byte_count <= 8) {
		hm.u.cx.attribute = HPI_COBRANET_GET;
	} else {
		hm.u.cx.u.cobranet_bigdata.pb_data = pb_data;
		hm.u.cx.attribute = HPI_COBRANET_GET_DATA;
	}

	hpi_send_recv(&hm, &hr);
	if (!hr.error && pb_data) {

		*pbyte_count = hr.u.cx.u.cobranet_data.byte_count;

		if (*pbyte_count < max_byte_count)
			max_byte_count = *pbyte_count;

		if (hm.u.cx.attribute == HPI_COBRANET_GET) {
			memcpy(pb_data, hr.u.cx.u.cobranet_data.data,
				max_byte_count);
		} else {

		}

	}
	return hr.error;
}

1863 1864
u16 hpi_cobranet_hmi_get_status(u32 h_control, u32 *pstatus,
	u32 *preadable_size, u32 *pwriteable_size)
1865 1866 1867
{
	struct hpi_message hm;
	struct hpi_response hr;
1868

1869 1870
	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROLEX,
		HPI_CONTROL_GET_STATE);
1871 1872
	if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889

	hm.u.cx.attribute = HPI_COBRANET_GET_STATUS;

	hpi_send_recv(&hm, &hr);
	if (!hr.error) {
		if (pstatus)
			*pstatus = hr.u.cx.u.cobranet_status.status;
		if (preadable_size)
			*preadable_size =
				hr.u.cx.u.cobranet_status.readable_size;
		if (pwriteable_size)
			*pwriteable_size =
				hr.u.cx.u.cobranet_status.writeable_size;
	}
	return hr.error;
}

1890
u16 hpi_cobranet_get_ip_address(u32 h_control, u32 *pdw_ip_address)
1891 1892 1893 1894
{
	u32 byte_count;
	u32 iP;
	u16 error;
1895

1896
	error = hpi_cobranet_hmi_read(h_control,
1897 1898 1899
		HPI_COBRANET_HMI_cobra_ip_mon_currentIP, 4, &byte_count,
		(u8 *)&iP);

1900
	*pdw_ip_address =
1901 1902 1903 1904
		((iP & 0xff000000) >> 8) | ((iP & 0x00ff0000) << 8) | ((iP &
			0x0000ff00) >> 8) | ((iP & 0x000000ff) << 8);

	if (error)
1905
		*pdw_ip_address = 0;
1906 1907 1908 1909 1910

	return error;

}

1911
u16 hpi_cobranet_set_ip_address(u32 h_control, u32 dw_ip_address)
1912 1913 1914 1915
{
	u32 iP;
	u16 error;

1916 1917 1918
	iP = ((dw_ip_address & 0xff000000) >> 8) | ((dw_ip_address &
			0x00ff0000) << 8) | ((dw_ip_address & 0x0000ff00) >>
		8) | ((dw_ip_address & 0x000000ff) << 8);
1919

1920
	error = hpi_cobranet_hmi_write(h_control,
1921 1922 1923 1924 1925 1926
		HPI_COBRANET_HMI_cobra_ip_mon_currentIP, 4, (u8 *)&iP);

	return error;

}

1927
u16 hpi_cobranet_get_static_ip_address(u32 h_control, u32 *pdw_ip_address)
1928 1929 1930 1931
{
	u32 byte_count;
	u32 iP;
	u16 error;
1932
	error = hpi_cobranet_hmi_read(h_control,
1933 1934 1935
		HPI_COBRANET_HMI_cobra_ip_mon_staticIP, 4, &byte_count,
		(u8 *)&iP);

1936
	*pdw_ip_address =
1937 1938 1939 1940
		((iP & 0xff000000) >> 8) | ((iP & 0x00ff0000) << 8) | ((iP &
			0x0000ff00) >> 8) | ((iP & 0x000000ff) << 8);

	if (error)
1941
		*pdw_ip_address = 0;
1942 1943 1944 1945 1946

	return error;

}

1947
u16 hpi_cobranet_set_static_ip_address(u32 h_control, u32 dw_ip_address)
1948 1949 1950 1951
{
	u32 iP;
	u16 error;

1952 1953 1954
	iP = ((dw_ip_address & 0xff000000) >> 8) | ((dw_ip_address &
			0x00ff0000) << 8) | ((dw_ip_address & 0x0000ff00) >>
		8) | ((dw_ip_address & 0x000000ff) << 8);
1955

1956
	error = hpi_cobranet_hmi_write(h_control,
1957 1958 1959 1960 1961 1962
		HPI_COBRANET_HMI_cobra_ip_mon_staticIP, 4, (u8 *)&iP);

	return error;

}

1963 1964
u16 hpi_cobranet_get_macaddress(u32 h_control, u32 *pmAC_MS_bs,
	u32 *pmAC_LS_bs)
1965 1966 1967 1968
{
	u32 byte_count;
	u16 error;
	u32 mAC;
1969

1970
	error = hpi_cobranet_hmi_read(h_control,
1971 1972 1973 1974 1975
		HPI_COBRANET_HMI_cobra_if_phy_address, 4, &byte_count,
		(u8 *)&mAC);
	*pmAC_MS_bs =
		((mAC & 0xff000000) >> 8) | ((mAC & 0x00ff0000) << 8) | ((mAC
			& 0x0000ff00) >> 8) | ((mAC & 0x000000ff) << 8);
1976
	error += hpi_cobranet_hmi_read(h_control,
1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990
		HPI_COBRANET_HMI_cobra_if_phy_address + 1, 4, &byte_count,
		(u8 *)&mAC);
	*pmAC_LS_bs =
		((mAC & 0xff000000) >> 8) | ((mAC & 0x00ff0000) << 8) | ((mAC
			& 0x0000ff00) >> 8) | ((mAC & 0x000000ff) << 8);

	if (error) {
		*pmAC_MS_bs = 0;
		*pmAC_LS_bs = 0;
	}

	return error;
}

1991
u16 hpi_compander_set_enable(u32 h_control, u32 enable)
1992
{
1993 1994
	return hpi_control_param_set(h_control, HPI_GENERIC_ENABLE, enable,
		0);
1995 1996
}

1997
u16 hpi_compander_get_enable(u32 h_control, u32 *enable)
1998
{
1999
	return hpi_control_param1_get(h_control, HPI_GENERIC_ENABLE, enable);
2000 2001
}

2002
u16 hpi_compander_set_makeup_gain(u32 h_control, short makeup_gain0_01dB)
2003 2004 2005 2006 2007
{
	return hpi_control_log_set2(h_control, HPI_COMPANDER_MAKEUPGAIN,
		makeup_gain0_01dB, 0);
}

2008
u16 hpi_compander_get_makeup_gain(u32 h_control, short *makeup_gain0_01dB)
2009
{
2010 2011
	return hpi_control_log_get2(h_control, HPI_COMPANDER_MAKEUPGAIN,
		makeup_gain0_01dB, NULL);
2012 2013
}

2014 2015
u16 hpi_compander_set_attack_time_constant(u32 h_control, unsigned int index,
	u32 attack)
2016
{
2017 2018
	return hpi_control_param_set(h_control, HPI_COMPANDER_ATTACK, attack,
		index);
2019 2020
}

2021 2022
u16 hpi_compander_get_attack_time_constant(u32 h_control, unsigned int index,
	u32 *attack)
2023
{
2024 2025
	return hpi_control_param_get(h_control, HPI_COMPANDER_ATTACK, 0,
		index, attack, NULL);
2026 2027
}

2028 2029
u16 hpi_compander_set_decay_time_constant(u32 h_control, unsigned int index,
	u32 decay)
2030
{
2031 2032
	return hpi_control_param_set(h_control, HPI_COMPANDER_DECAY, decay,
		index);
2033 2034
}

2035 2036
u16 hpi_compander_get_decay_time_constant(u32 h_control, unsigned int index,
	u32 *decay)
2037
{
2038 2039
	return hpi_control_param_get(h_control, HPI_COMPANDER_DECAY, 0, index,
		decay, NULL);
2040 2041 2042

}

2043 2044
u16 hpi_compander_set_threshold(u32 h_control, unsigned int index,
	short threshold0_01dB)
2045 2046 2047
{
	struct hpi_message hm;
	struct hpi_response hr;
2048

2049 2050
	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
		HPI_CONTROL_SET_STATE);
2051 2052
	if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
2053 2054
	hm.u.c.attribute = HPI_COMPANDER_THRESHOLD;
	hm.u.c.param2 = index;
2055 2056 2057 2058 2059 2060 2061
	hm.u.c.an_log_value[0] = threshold0_01dB;

	hpi_send_recv(&hm, &hr);

	return hr.error;
}

2062 2063
u16 hpi_compander_get_threshold(u32 h_control, unsigned int index,
	short *threshold0_01dB)
2064 2065 2066
{
	struct hpi_message hm;
	struct hpi_response hr;
2067

2068 2069
	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
		HPI_CONTROL_GET_STATE);
2070 2071
	if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
2072 2073
	hm.u.c.attribute = HPI_COMPANDER_THRESHOLD;
	hm.u.c.param2 = index;
2074 2075

	hpi_send_recv(&hm, &hr);
2076
	*threshold0_01dB = hr.u.c.an_log_value[0];
2077

2078 2079
	return hr.error;
}
2080

2081
u16 hpi_compander_set_ratio(u32 h_control, u32 index, u32 ratio100)
2082
{
2083 2084
	return hpi_control_param_set(h_control, HPI_COMPANDER_RATIO, ratio100,
		index);
2085
}
2086

2087
u16 hpi_compander_get_ratio(u32 h_control, u32 index, u32 *ratio100)
2088
{
2089 2090
	return hpi_control_param_get(h_control, HPI_COMPANDER_RATIO, 0, index,
		ratio100, NULL);
2091 2092
}

2093 2094
u16 hpi_level_query_range(u32 h_control, short *min_gain_01dB,
	short *max_gain_01dB, short *step_gain_01dB)
2095 2096 2097
{
	struct hpi_message hm;
	struct hpi_response hr;
2098

2099 2100
	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
		HPI_CONTROL_GET_STATE);
2101 2102
	if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119
	hm.u.c.attribute = HPI_LEVEL_RANGE;

	hpi_send_recv(&hm, &hr);
	if (hr.error) {
		hr.u.c.an_log_value[0] = 0;
		hr.u.c.an_log_value[1] = 0;
		hr.u.c.param1 = 0;
	}
	if (min_gain_01dB)
		*min_gain_01dB = hr.u.c.an_log_value[0];
	if (max_gain_01dB)
		*max_gain_01dB = hr.u.c.an_log_value[1];
	if (step_gain_01dB)
		*step_gain_01dB = (short)hr.u.c.param1;
	return hr.error;
}

2120
u16 hpi_level_set_gain(u32 h_control, short an_gain0_01dB[HPI_MAX_CHANNELS]
2121 2122
	)
{
2123 2124
	return hpi_control_log_set2(h_control, HPI_LEVEL_GAIN,
		an_gain0_01dB[0], an_gain0_01dB[1]);
2125 2126
}

2127
u16 hpi_level_get_gain(u32 h_control, short an_gain0_01dB[HPI_MAX_CHANNELS]
2128 2129
	)
{
2130
	return hpi_control_log_get2(h_control, HPI_LEVEL_GAIN,
2131
		&an_gain0_01dB[0], &an_gain0_01dB[1]);
2132 2133
}

2134
u16 hpi_meter_query_channels(const u32 h_meter, u32 *p_channels)
2135
{
2136 2137
	return hpi_control_query(h_meter, HPI_METER_NUM_CHANNELS, 0, 0,
		p_channels);
2138 2139
}

2140
u16 hpi_meter_get_peak(u32 h_control, short an_peakdB[HPI_MAX_CHANNELS]
2141 2142 2143 2144 2145 2146 2147 2148 2149
	)
{
	short i = 0;

	struct hpi_message hm;
	struct hpi_response hr;

	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
		HPI_CONTROL_GET_STATE);
2150 2151
	if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165
	hm.obj_index = hm.obj_index;
	hm.u.c.attribute = HPI_METER_PEAK;

	hpi_send_recv(&hm, &hr);

	if (!hr.error)
		memcpy(an_peakdB, hr.u.c.an_log_value,
			sizeof(short) * HPI_MAX_CHANNELS);
	else
		for (i = 0; i < HPI_MAX_CHANNELS; i++)
			an_peakdB[i] = HPI_METER_MINIMUM;
	return hr.error;
}

2166
u16 hpi_meter_get_rms(u32 h_control, short an_rmsdB[HPI_MAX_CHANNELS]
2167 2168 2169 2170 2171 2172 2173 2174 2175
	)
{
	short i = 0;

	struct hpi_message hm;
	struct hpi_response hr;

	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
		HPI_CONTROL_GET_STATE);
2176 2177
	if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191
	hm.u.c.attribute = HPI_METER_RMS;

	hpi_send_recv(&hm, &hr);

	if (!hr.error)
		memcpy(an_rmsdB, hr.u.c.an_log_value,
			sizeof(short) * HPI_MAX_CHANNELS);
	else
		for (i = 0; i < HPI_MAX_CHANNELS; i++)
			an_rmsdB[i] = HPI_METER_MINIMUM;

	return hr.error;
}

2192
u16 hpi_meter_set_rms_ballistics(u32 h_control, u16 attack, u16 decay)
2193
{
2194 2195
	return hpi_control_param_set(h_control, HPI_METER_RMS_BALLISTICS,
		attack, decay);
2196 2197
}

2198
u16 hpi_meter_get_rms_ballistics(u32 h_control, u16 *pn_attack, u16 *pn_decay)
2199 2200 2201 2202 2203
{
	u32 attack;
	u32 decay;
	u16 error;

2204 2205
	error = hpi_control_param2_get(h_control, HPI_METER_RMS_BALLISTICS,
		&attack, &decay);
2206 2207 2208 2209 2210 2211 2212 2213 2214

	if (pn_attack)
		*pn_attack = (unsigned short)attack;
	if (pn_decay)
		*pn_decay = (unsigned short)decay;

	return error;
}

2215
u16 hpi_meter_set_peak_ballistics(u32 h_control, u16 attack, u16 decay)
2216
{
2217 2218
	return hpi_control_param_set(h_control, HPI_METER_PEAK_BALLISTICS,
		attack, decay);
2219 2220
}

2221 2222
u16 hpi_meter_get_peak_ballistics(u32 h_control, u16 *pn_attack,
	u16 *pn_decay)
2223 2224 2225 2226 2227
{
	u32 attack;
	u32 decay;
	u16 error;

2228 2229
	error = hpi_control_param2_get(h_control, HPI_METER_PEAK_BALLISTICS,
		&attack, &decay);
2230 2231 2232 2233 2234 2235 2236 2237 2238

	if (pn_attack)
		*pn_attack = (short)attack;
	if (pn_decay)
		*pn_decay = (short)decay;

	return error;
}

2239
u16 hpi_microphone_set_phantom_power(u32 h_control, u16 on_off)
2240
{
2241 2242
	return hpi_control_param_set(h_control, HPI_MICROPHONE_PHANTOM_POWER,
		(u32)on_off, 0);
2243 2244
}

2245
u16 hpi_microphone_get_phantom_power(u32 h_control, u16 *pw_on_off)
2246 2247 2248
{
	u16 error = 0;
	u32 on_off = 0;
2249
	error = hpi_control_param1_get(h_control,
2250 2251 2252 2253 2254 2255
		HPI_MICROPHONE_PHANTOM_POWER, &on_off);
	if (pw_on_off)
		*pw_on_off = (u16)on_off;
	return error;
}

2256 2257
u16 hpi_multiplexer_set_source(u32 h_control, u16 source_node_type,
	u16 source_node_index)
2258
{
2259 2260
	return hpi_control_param_set(h_control, HPI_MULTIPLEXER_SOURCE,
		source_node_type, source_node_index);
2261 2262
}

2263 2264
u16 hpi_multiplexer_get_source(u32 h_control, u16 *source_node_type,
	u16 *source_node_index)
2265 2266
{
	u32 node, index;
2267
	u16 error = hpi_control_param2_get(h_control,
2268 2269 2270 2271 2272 2273 2274 2275 2276
		HPI_MULTIPLEXER_SOURCE, &node,
		&index);
	if (source_node_type)
		*source_node_type = (u16)node;
	if (source_node_index)
		*source_node_index = (u16)index;
	return error;
}

2277 2278
u16 hpi_multiplexer_query_source(u32 h_control, u16 index,
	u16 *source_node_type, u16 *source_node_index)
2279 2280 2281 2282 2283
{
	struct hpi_message hm;
	struct hpi_response hr;
	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
		HPI_CONTROL_GET_STATE);
2284 2285
	if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297
	hm.u.c.attribute = HPI_MULTIPLEXER_QUERYSOURCE;
	hm.u.c.param1 = index;

	hpi_send_recv(&hm, &hr);

	if (source_node_type)
		*source_node_type = (u16)hr.u.c.param1;
	if (source_node_index)
		*source_node_index = (u16)hr.u.c.param2;
	return hr.error;
}

2298 2299
u16 hpi_parametric_eq_get_info(u32 h_control, u16 *pw_number_of_bands,
	u16 *pw_on_off)
2300 2301 2302 2303 2304
{
	u32 oB = 0;
	u32 oO = 0;
	u16 error = 0;

2305 2306
	error = hpi_control_param2_get(h_control, HPI_EQUALIZER_NUM_FILTERS,
		&oO, &oB);
2307 2308 2309 2310 2311 2312 2313
	if (pw_number_of_bands)
		*pw_number_of_bands = (u16)oB;
	if (pw_on_off)
		*pw_on_off = (u16)oO;
	return error;
}

2314
u16 hpi_parametric_eq_set_state(u32 h_control, u16 on_off)
2315
{
2316 2317
	return hpi_control_param_set(h_control, HPI_EQUALIZER_NUM_FILTERS,
		on_off, 0);
2318 2319
}

2320 2321
u16 hpi_parametric_eq_get_band(u32 h_control, u16 index, u16 *pn_type,
	u32 *pfrequency_hz, short *pnQ100, short *pn_gain0_01dB)
2322 2323 2324
{
	struct hpi_message hm;
	struct hpi_response hr;
2325

2326 2327
	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
		HPI_CONTROL_GET_STATE);
2328 2329
	if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346
	hm.u.c.attribute = HPI_EQUALIZER_FILTER;
	hm.u.c.param2 = index;

	hpi_send_recv(&hm, &hr);

	if (pfrequency_hz)
		*pfrequency_hz = hr.u.c.param1;
	if (pn_type)
		*pn_type = (u16)(hr.u.c.param2 >> 16);
	if (pnQ100)
		*pnQ100 = hr.u.c.an_log_value[1];
	if (pn_gain0_01dB)
		*pn_gain0_01dB = hr.u.c.an_log_value[0];

	return hr.error;
}

2347 2348
u16 hpi_parametric_eq_set_band(u32 h_control, u16 index, u16 type,
	u32 frequency_hz, short q100, short gain0_01dB)
2349 2350 2351
{
	struct hpi_message hm;
	struct hpi_response hr;
2352

2353 2354
	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
		HPI_CONTROL_SET_STATE);
2355 2356
	if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368

	hm.u.c.param1 = frequency_hz;
	hm.u.c.param2 = (index & 0xFFFFL) + ((u32)type << 16);
	hm.u.c.an_log_value[0] = gain0_01dB;
	hm.u.c.an_log_value[1] = q100;
	hm.u.c.attribute = HPI_EQUALIZER_FILTER;

	hpi_send_recv(&hm, &hr);

	return hr.error;
}

2369
u16 hpi_parametric_eq_get_coeffs(u32 h_control, u16 index, short coeffs[5]
2370 2371 2372 2373
	)
{
	struct hpi_message hm;
	struct hpi_response hr;
2374

2375 2376
	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
		HPI_CONTROL_GET_STATE);
2377 2378
	if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392
	hm.u.c.attribute = HPI_EQUALIZER_COEFFICIENTS;
	hm.u.c.param2 = index;

	hpi_send_recv(&hm, &hr);

	coeffs[0] = (short)hr.u.c.an_log_value[0];
	coeffs[1] = (short)hr.u.c.an_log_value[1];
	coeffs[2] = (short)hr.u.c.param1;
	coeffs[3] = (short)(hr.u.c.param1 >> 16);
	coeffs[4] = (short)hr.u.c.param2;

	return hr.error;
}

2393 2394
u16 hpi_sample_clock_query_source(const u32 h_clock, const u32 index,
	u16 *pw_source)
2395 2396 2397 2398
{
	u32 qr;
	u16 err;

2399 2400
	err = hpi_control_query(h_clock, HPI_SAMPLECLOCK_SOURCE, index, 0,
		&qr);
2401 2402 2403 2404
	*pw_source = (u16)qr;
	return err;
}

2405
u16 hpi_sample_clock_set_source(u32 h_control, u16 source)
2406
{
2407 2408
	return hpi_control_param_set(h_control, HPI_SAMPLECLOCK_SOURCE,
		source, 0);
2409 2410
}

2411
u16 hpi_sample_clock_get_source(u32 h_control, u16 *pw_source)
2412 2413 2414
{
	u16 error = 0;
	u32 source = 0;
2415 2416
	error = hpi_control_param1_get(h_control, HPI_SAMPLECLOCK_SOURCE,
		&source);
2417 2418 2419 2420 2421 2422
	if (!error)
		if (pw_source)
			*pw_source = (u16)source;
	return error;
}

2423 2424
u16 hpi_sample_clock_query_source_index(const u32 h_clock, const u32 index,
	const u32 source, u16 *pw_source_index)
2425 2426 2427 2428
{
	u32 qr;
	u16 err;

2429 2430
	err = hpi_control_query(h_clock, HPI_SAMPLECLOCK_SOURCE_INDEX, index,
		source, &qr);
2431 2432 2433 2434
	*pw_source_index = (u16)qr;
	return err;
}

2435
u16 hpi_sample_clock_set_source_index(u32 h_control, u16 source_index)
2436
{
2437 2438
	return hpi_control_param_set(h_control, HPI_SAMPLECLOCK_SOURCE_INDEX,
		source_index, 0);
2439 2440
}

2441
u16 hpi_sample_clock_get_source_index(u32 h_control, u16 *pw_source_index)
2442 2443 2444
{
	u16 error = 0;
	u32 source_index = 0;
2445
	error = hpi_control_param1_get(h_control,
2446 2447 2448 2449 2450 2451 2452
		HPI_SAMPLECLOCK_SOURCE_INDEX, &source_index);
	if (!error)
		if (pw_source_index)
			*pw_source_index = (u16)source_index;
	return error;
}

2453 2454
u16 hpi_sample_clock_query_local_rate(const u32 h_clock, const u32 index,
	u32 *prate)
2455 2456
{
	u16 err;
2457 2458
	err = hpi_control_query(h_clock, HPI_SAMPLECLOCK_LOCAL_SAMPLERATE,
		index, 0, prate);
2459 2460 2461 2462

	return err;
}

2463
u16 hpi_sample_clock_set_local_rate(u32 h_control, u32 sample_rate)
2464
{
2465
	return hpi_control_param_set(h_control,
2466 2467 2468
		HPI_SAMPLECLOCK_LOCAL_SAMPLERATE, sample_rate, 0);
}

2469
u16 hpi_sample_clock_get_local_rate(u32 h_control, u32 *psample_rate)
2470 2471 2472
{
	u16 error = 0;
	u32 sample_rate = 0;
2473
	error = hpi_control_param1_get(h_control,
2474 2475 2476 2477 2478 2479 2480
		HPI_SAMPLECLOCK_LOCAL_SAMPLERATE, &sample_rate);
	if (!error)
		if (psample_rate)
			*psample_rate = sample_rate;
	return error;
}

2481
u16 hpi_sample_clock_get_sample_rate(u32 h_control, u32 *psample_rate)
2482 2483 2484
{
	u16 error = 0;
	u32 sample_rate = 0;
2485 2486
	error = hpi_control_param1_get(h_control, HPI_SAMPLECLOCK_SAMPLERATE,
		&sample_rate);
2487 2488 2489 2490 2491 2492
	if (!error)
		if (psample_rate)
			*psample_rate = sample_rate;
	return error;
}

2493
u16 hpi_sample_clock_set_auto(u32 h_control, u32 enable)
2494
{
2495 2496
	return hpi_control_param_set(h_control, HPI_SAMPLECLOCK_AUTO, enable,
		0);
2497 2498
}

2499
u16 hpi_sample_clock_get_auto(u32 h_control, u32 *penable)
2500
{
2501 2502
	return hpi_control_param1_get(h_control, HPI_SAMPLECLOCK_AUTO,
		penable);
2503 2504
}

2505
u16 hpi_sample_clock_set_local_rate_lock(u32 h_control, u32 lock)
2506
{
2507 2508
	return hpi_control_param_set(h_control, HPI_SAMPLECLOCK_LOCAL_LOCK,
		lock, 0);
2509 2510
}

2511
u16 hpi_sample_clock_get_local_rate_lock(u32 h_control, u32 *plock)
2512
{
2513 2514
	return hpi_control_param1_get(h_control, HPI_SAMPLECLOCK_LOCAL_LOCK,
		plock);
2515 2516
}

2517
u16 hpi_tone_detector_get_frequency(u32 h_control, u32 index, u32 *frequency)
2518
{
2519 2520
	return hpi_control_param_get(h_control, HPI_TONEDETECTOR_FREQUENCY,
		index, 0, frequency, NULL);
2521 2522
}

2523
u16 hpi_tone_detector_get_state(u32 h_control, u32 *state)
2524
{
2525 2526
	return hpi_control_param1_get(h_control, HPI_TONEDETECTOR_STATE,
		state);
2527 2528
}

2529
u16 hpi_tone_detector_set_enable(u32 h_control, u32 enable)
2530
{
2531 2532
	return hpi_control_param_set(h_control, HPI_GENERIC_ENABLE, enable,
		0);
2533 2534
}

2535
u16 hpi_tone_detector_get_enable(u32 h_control, u32 *enable)
2536
{
2537
	return hpi_control_param1_get(h_control, HPI_GENERIC_ENABLE, enable);
2538 2539
}

2540
u16 hpi_tone_detector_set_event_enable(u32 h_control, u32 event_enable)
2541
{
2542 2543
	return hpi_control_param_set(h_control, HPI_GENERIC_EVENT_ENABLE,
		(u32)event_enable, 0);
2544 2545
}

2546
u16 hpi_tone_detector_get_event_enable(u32 h_control, u32 *event_enable)
2547
{
2548 2549
	return hpi_control_param1_get(h_control, HPI_GENERIC_EVENT_ENABLE,
		event_enable);
2550 2551
}

2552
u16 hpi_tone_detector_set_threshold(u32 h_control, int threshold)
2553
{
2554 2555
	return hpi_control_param_set(h_control, HPI_TONEDETECTOR_THRESHOLD,
		(u32)threshold, 0);
2556 2557
}

2558
u16 hpi_tone_detector_get_threshold(u32 h_control, int *threshold)
2559
{
2560 2561
	return hpi_control_param1_get(h_control, HPI_TONEDETECTOR_THRESHOLD,
		(u32 *)threshold);
2562 2563
}

2564
u16 hpi_silence_detector_get_state(u32 h_control, u32 *state)
2565
{
2566 2567
	return hpi_control_param1_get(h_control, HPI_SILENCEDETECTOR_STATE,
		state);
2568 2569
}

2570
u16 hpi_silence_detector_set_enable(u32 h_control, u32 enable)
2571
{
2572 2573
	return hpi_control_param_set(h_control, HPI_GENERIC_ENABLE, enable,
		0);
2574 2575
}

2576
u16 hpi_silence_detector_get_enable(u32 h_control, u32 *enable)
2577
{
2578
	return hpi_control_param1_get(h_control, HPI_GENERIC_ENABLE, enable);
2579 2580
}

2581
u16 hpi_silence_detector_set_event_enable(u32 h_control, u32 event_enable)
2582
{
2583 2584
	return hpi_control_param_set(h_control, HPI_GENERIC_EVENT_ENABLE,
		event_enable, 0);
2585 2586
}

2587
u16 hpi_silence_detector_get_event_enable(u32 h_control, u32 *event_enable)
2588
{
2589 2590
	return hpi_control_param1_get(h_control, HPI_GENERIC_EVENT_ENABLE,
		event_enable);
2591 2592
}

2593
u16 hpi_silence_detector_set_delay(u32 h_control, u32 delay)
2594
{
2595 2596
	return hpi_control_param_set(h_control, HPI_SILENCEDETECTOR_DELAY,
		delay, 0);
2597 2598
}

2599
u16 hpi_silence_detector_get_delay(u32 h_control, u32 *delay)
2600
{
2601 2602
	return hpi_control_param1_get(h_control, HPI_SILENCEDETECTOR_DELAY,
		delay);
2603 2604
}

2605
u16 hpi_silence_detector_set_threshold(u32 h_control, int threshold)
2606
{
2607 2608
	return hpi_control_param_set(h_control, HPI_SILENCEDETECTOR_THRESHOLD,
		threshold, 0);
2609 2610
}

2611
u16 hpi_silence_detector_get_threshold(u32 h_control, int *threshold)
2612
{
2613
	return hpi_control_param1_get(h_control,
2614
		HPI_SILENCEDETECTOR_THRESHOLD, (u32 *)threshold);
2615 2616
}

2617
u16 hpi_tuner_query_band(const u32 h_tuner, const u32 index, u16 *pw_band)
2618 2619 2620 2621
{
	u32 qr;
	u16 err;

2622
	err = hpi_control_query(h_tuner, HPI_TUNER_BAND, index, 0, &qr);
2623 2624 2625 2626
	*pw_band = (u16)qr;
	return err;
}

2627
u16 hpi_tuner_set_band(u32 h_control, u16 band)
2628
{
2629
	return hpi_control_param_set(h_control, HPI_TUNER_BAND, band, 0);
2630 2631
}

2632
u16 hpi_tuner_get_band(u32 h_control, u16 *pw_band)
2633 2634 2635 2636
{
	u32 band = 0;
	u16 error = 0;

2637
	error = hpi_control_param1_get(h_control, HPI_TUNER_BAND, &band);
2638 2639 2640 2641 2642
	if (pw_band)
		*pw_band = (u16)band;
	return error;
}

2643 2644
u16 hpi_tuner_query_frequency(const u32 h_tuner, const u32 index,
	const u16 band, u32 *pfreq)
2645
{
2646
	return hpi_control_query(h_tuner, HPI_TUNER_FREQ, index, band, pfreq);
2647 2648
}

2649
u16 hpi_tuner_set_frequency(u32 h_control, u32 freq_ink_hz)
2650
{
2651 2652
	return hpi_control_param_set(h_control, HPI_TUNER_FREQ, freq_ink_hz,
		0);
2653 2654
}

2655
u16 hpi_tuner_get_frequency(u32 h_control, u32 *pw_freq_ink_hz)
2656
{
2657
	return hpi_control_param1_get(h_control, HPI_TUNER_FREQ,
2658 2659 2660
		pw_freq_ink_hz);
}

2661
u16 hpi_tuner_query_gain(const u32 h_tuner, const u32 index, u16 *pw_gain)
2662 2663 2664 2665
{
	u32 qr;
	u16 err;

2666
	err = hpi_control_query(h_tuner, HPI_TUNER_BAND, index, 0, &qr);
2667 2668 2669 2670
	*pw_gain = (u16)qr;
	return err;
}

2671
u16 hpi_tuner_set_gain(u32 h_control, short gain)
2672
{
2673
	return hpi_control_param_set(h_control, HPI_TUNER_GAIN, gain, 0);
2674 2675
}

2676
u16 hpi_tuner_get_gain(u32 h_control, short *pn_gain)
2677 2678 2679 2680
{
	u32 gain = 0;
	u16 error = 0;

2681
	error = hpi_control_param1_get(h_control, HPI_TUNER_GAIN, &gain);
2682 2683 2684 2685 2686
	if (pn_gain)
		*pn_gain = (u16)gain;
	return error;
}

2687
u16 hpi_tuner_get_rf_level(u32 h_control, short *pw_level)
2688 2689 2690
{
	struct hpi_message hm;
	struct hpi_response hr;
2691

2692 2693
	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
		HPI_CONTROL_GET_STATE);
2694 2695
	if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
2696
	hm.u.cu.attribute = HPI_TUNER_LEVEL_AVG;
2697 2698
	hpi_send_recv(&hm, &hr);
	if (pw_level)
2699
		*pw_level = hr.u.cu.tuner.s_level;
2700 2701 2702
	return hr.error;
}

2703
u16 hpi_tuner_get_raw_rf_level(u32 h_control, short *pw_level)
2704 2705 2706
{
	struct hpi_message hm;
	struct hpi_response hr;
2707

2708 2709
	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
		HPI_CONTROL_GET_STATE);
2710 2711
	if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
2712
	hm.u.cu.attribute = HPI_TUNER_LEVEL_RAW;
2713 2714
	hpi_send_recv(&hm, &hr);
	if (pw_level)
2715
		*pw_level = hr.u.cu.tuner.s_level;
2716 2717 2718
	return hr.error;
}

2719 2720
u16 hpi_tuner_query_deemphasis(const u32 h_tuner, const u32 index,
	const u16 band, u32 *pdeemphasis)
2721
{
2722 2723
	return hpi_control_query(h_tuner, HPI_TUNER_DEEMPHASIS, index, band,
		pdeemphasis);
2724 2725
}

2726
u16 hpi_tuner_set_deemphasis(u32 h_control, u32 deemphasis)
2727
{
2728 2729
	return hpi_control_param_set(h_control, HPI_TUNER_DEEMPHASIS,
		deemphasis, 0);
2730 2731
}

2732
u16 hpi_tuner_get_deemphasis(u32 h_control, u32 *pdeemphasis)
2733
{
2734 2735
	return hpi_control_param1_get(h_control, HPI_TUNER_DEEMPHASIS,
		pdeemphasis);
2736 2737
}

2738
u16 hpi_tuner_query_program(const u32 h_tuner, u32 *pbitmap_program)
2739
{
2740
	return hpi_control_query(h_tuner, HPI_TUNER_PROGRAM, 0, 0,
2741 2742 2743
		pbitmap_program);
}

2744
u16 hpi_tuner_set_program(u32 h_control, u32 program)
2745
{
2746 2747
	return hpi_control_param_set(h_control, HPI_TUNER_PROGRAM, program,
		0);
2748 2749
}

2750
u16 hpi_tuner_get_program(u32 h_control, u32 *pprogram)
2751
{
2752
	return hpi_control_param1_get(h_control, HPI_TUNER_PROGRAM, pprogram);
2753 2754
}

2755 2756
u16 hpi_tuner_get_hd_radio_dsp_version(u32 h_control, char *psz_dsp_version,
	const u32 string_size)
2757
{
2758
	return hpi_control_get_string(h_control,
2759 2760 2761
		HPI_TUNER_HDRADIO_DSP_VERSION, psz_dsp_version, string_size);
}

2762 2763
u16 hpi_tuner_get_hd_radio_sdk_version(u32 h_control, char *psz_sdk_version,
	const u32 string_size)
2764
{
2765
	return hpi_control_get_string(h_control,
2766 2767 2768
		HPI_TUNER_HDRADIO_SDK_VERSION, psz_sdk_version, string_size);
}

2769
u16 hpi_tuner_get_status(u32 h_control, u16 *pw_status_mask, u16 *pw_status)
2770 2771 2772 2773
{
	u32 status = 0;
	u16 error = 0;

2774
	error = hpi_control_param1_get(h_control, HPI_TUNER_STATUS, &status);
2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786
	if (pw_status) {
		if (!error) {
			*pw_status_mask = (u16)(status >> 16);
			*pw_status = (u16)(status & 0xFFFF);
		} else {
			*pw_status_mask = 0;
			*pw_status = 0;
		}
	}
	return error;
}

2787
u16 hpi_tuner_set_mode(u32 h_control, u32 mode, u32 value)
2788
{
2789
	return hpi_control_param_set(h_control, HPI_TUNER_MODE, mode, value);
2790 2791
}

2792
u16 hpi_tuner_get_mode(u32 h_control, u32 mode, u32 *pn_value)
2793
{
2794 2795
	return hpi_control_param_get(h_control, HPI_TUNER_MODE, mode, 0,
		pn_value, NULL);
2796 2797
}

2798
u16 hpi_tuner_get_hd_radio_signal_quality(u32 h_control, u32 *pquality)
2799
{
2800
	return hpi_control_param1_get(h_control,
2801
		HPI_TUNER_HDRADIO_SIGNAL_QUALITY, pquality);
2802 2803
}

2804
u16 hpi_tuner_get_hd_radio_signal_blend(u32 h_control, u32 *pblend)
2805
{
2806 2807
	return hpi_control_param1_get(h_control, HPI_TUNER_HDRADIO_BLEND,
		pblend);
2808 2809
}

2810
u16 hpi_tuner_set_hd_radio_signal_blend(u32 h_control, const u32 blend)
2811
{
2812 2813
	return hpi_control_param_set(h_control, HPI_TUNER_HDRADIO_BLEND,
		blend, 0);
2814 2815
}

2816
u16 hpi_tuner_get_rds(u32 h_control, char *p_data)
2817 2818 2819
{
	struct hpi_message hm;
	struct hpi_response hr;
2820

2821 2822
	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
		HPI_CONTROL_GET_STATE);
2823 2824
	if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
2825 2826 2827 2828 2829 2830 2831 2832 2833 2834
	hm.u.c.attribute = HPI_TUNER_RDS;
	hpi_send_recv(&hm, &hr);
	if (p_data) {
		*(u32 *)&p_data[0] = hr.u.cu.tuner.rds.data[0];
		*(u32 *)&p_data[4] = hr.u.cu.tuner.rds.data[1];
		*(u32 *)&p_data[8] = hr.u.cu.tuner.rds.bLER;
	}
	return hr.error;
}

2835 2836
u16 hpi_pad_get_channel_name(u32 h_control, char *psz_string,
	const u32 data_length)
2837
{
2838 2839
	return hpi_control_get_string(h_control, HPI_PAD_CHANNEL_NAME,
		psz_string, data_length);
2840 2841
}

2842
u16 hpi_pad_get_artist(u32 h_control, char *psz_string, const u32 data_length)
2843
{
2844 2845
	return hpi_control_get_string(h_control, HPI_PAD_ARTIST, psz_string,
		data_length);
2846 2847
}

2848
u16 hpi_pad_get_title(u32 h_control, char *psz_string, const u32 data_length)
2849
{
2850 2851
	return hpi_control_get_string(h_control, HPI_PAD_TITLE, psz_string,
		data_length);
2852 2853
}

2854 2855
u16 hpi_pad_get_comment(u32 h_control, char *psz_string,
	const u32 data_length)
2856
{
2857 2858
	return hpi_control_get_string(h_control, HPI_PAD_COMMENT, psz_string,
		data_length);
2859 2860
}

2861
u16 hpi_pad_get_program_type(u32 h_control, u32 *ppTY)
2862
{
2863
	return hpi_control_param1_get(h_control, HPI_PAD_PROGRAM_TYPE, ppTY);
2864 2865
}

2866
u16 hpi_pad_get_rdsPI(u32 h_control, u32 *ppI)
2867
{
2868
	return hpi_control_param1_get(h_control, HPI_PAD_PROGRAM_ID, ppI);
2869 2870
}

2871
u16 hpi_volume_query_channels(const u32 h_volume, u32 *p_channels)
2872
{
2873 2874
	return hpi_control_query(h_volume, HPI_VOLUME_NUM_CHANNELS, 0, 0,
		p_channels);
2875 2876
}

2877
u16 hpi_volume_set_gain(u32 h_control, short an_log_gain[HPI_MAX_CHANNELS]
2878 2879
	)
{
2880 2881
	return hpi_control_log_set2(h_control, HPI_VOLUME_GAIN,
		an_log_gain[0], an_log_gain[1]);
2882 2883
}

2884
u16 hpi_volume_get_gain(u32 h_control, short an_log_gain[HPI_MAX_CHANNELS]
2885 2886
	)
{
2887
	return hpi_control_log_get2(h_control, HPI_VOLUME_GAIN,
2888
		&an_log_gain[0], &an_log_gain[1]);
2889 2890
}

2891 2892
u16 hpi_volume_query_range(u32 h_control, short *min_gain_01dB,
	short *max_gain_01dB, short *step_gain_01dB)
2893 2894 2895
{
	struct hpi_message hm;
	struct hpi_response hr;
2896

2897 2898
	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
		HPI_CONTROL_GET_STATE);
2899 2900
	if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917
	hm.u.c.attribute = HPI_VOLUME_RANGE;

	hpi_send_recv(&hm, &hr);
	if (hr.error) {
		hr.u.c.an_log_value[0] = 0;
		hr.u.c.an_log_value[1] = 0;
		hr.u.c.param1 = 0;
	}
	if (min_gain_01dB)
		*min_gain_01dB = hr.u.c.an_log_value[0];
	if (max_gain_01dB)
		*max_gain_01dB = hr.u.c.an_log_value[1];
	if (step_gain_01dB)
		*step_gain_01dB = (short)hr.u.c.param1;
	return hr.error;
}

2918 2919 2920
u16 hpi_volume_auto_fade_profile(u32 h_control,
	short an_stop_gain0_01dB[HPI_MAX_CHANNELS], u32 duration_ms,
	u16 profile)
2921 2922 2923
{
	struct hpi_message hm;
	struct hpi_response hr;
2924

2925 2926
	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
		HPI_CONTROL_SET_STATE);
2927 2928
	if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941

	memcpy(hm.u.c.an_log_value, an_stop_gain0_01dB,
		sizeof(short) * HPI_MAX_CHANNELS);

	hm.u.c.attribute = HPI_VOLUME_AUTOFADE;
	hm.u.c.param1 = duration_ms;
	hm.u.c.param2 = profile;

	hpi_send_recv(&hm, &hr);

	return hr.error;
}

2942
u16 hpi_volume_auto_fade(u32 h_control,
2943 2944
	short an_stop_gain0_01dB[HPI_MAX_CHANNELS], u32 duration_ms)
{
2945 2946
	return hpi_volume_auto_fade_profile(h_control, an_stop_gain0_01dB,
		duration_ms, HPI_VOLUME_AUTOFADE_LOG);
2947 2948
}

2949
u16 hpi_vox_set_threshold(u32 h_control, short an_gain0_01dB)
2950 2951 2952 2953 2954
{
	struct hpi_message hm;
	struct hpi_response hr;
	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
		HPI_CONTROL_SET_STATE);
2955 2956
	if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
2957 2958 2959 2960 2961 2962 2963 2964 2965
	hm.u.c.attribute = HPI_VOX_THRESHOLD;

	hm.u.c.an_log_value[0] = an_gain0_01dB;

	hpi_send_recv(&hm, &hr);

	return hr.error;
}

2966
u16 hpi_vox_get_threshold(u32 h_control, short *an_gain0_01dB)
2967 2968 2969 2970 2971
{
	struct hpi_message hm;
	struct hpi_response hr;
	hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
		HPI_CONTROL_GET_STATE);
2972 2973
	if (hpi_handle_indexes(h_control, &hm.adapter_index, &hm.obj_index))
		return HPI_ERROR_INVALID_HANDLE;
2974 2975 2976 2977 2978 2979 2980 2981
	hm.u.c.attribute = HPI_VOX_THRESHOLD;

	hpi_send_recv(&hm, &hr);

	*an_gain0_01dB = hr.u.c.an_log_value[0];

	return hr.error;
}